void LateUpdate() { float t = 0.0f; float dt = Time.deltaTime; if (ignoreTimescale == true) { t = Time.realtimeSinceStartup; } else { t = BulletTime.time; } t = t / 20.0f; // To match with Time.x in the shader. softDirection = Vector3.Lerp(softDirection, Vector3.Normalize(lastPos - transform.position), Responsiveness * 30f * dt); lastPos = transform.position; var wind = softDirection * Strength + transform.TransformDirection(ObjectSpaceWind); if (properties == null) { return; } properties.Clear(); properties.AddVector("_Wind", wind.normalized); properties.AddFloat("_T", t); GetComponent <Renderer>().SetPropertyBlock(properties); }
public void OnWillRenderObject() { if (m_MatProps == null) { m_MatProps = new MaterialPropertyBlock(); } Camera cam = Camera.current; cam.depthTextureMode |= DepthTextureMode.Depth; m_MatProps.Clear(); m_MatProps.AddVector("_CameraLocalPos", transform.InverseTransformPoint(cam.transform.position)); m_MatProps.AddMatrix("_CameraToLocal", transform.worldToLocalMatrix * cam.transform.localToWorldMatrix); m_MatProps.AddVector("_Scale", transform.localScale); m_MatProps.AddFloat("_Brightness", m_Brightness); if (Application.isPlaying) { float time = Time.time; m_TimeElapsed += m_Speed * (time - m_LastFrameTime); m_LastFrameTime = time; Shader.SetGlobalFloat("_FireTime", m_StartTime + m_TimeElapsed); } else { Shader.SetGlobalFloat("_FireTime", m_StartTime); } renderer.SetPropertyBlock(m_MatProps); }
//renderer public static void SetBlendWeight(Renderer target, float weight) { #if USE_PROPERTY_BLOCKS #if UNITY_5 && !UNITY_5_0 && !UNITY_5_1 && !UNITY_5_2 if (propBlock == null) { propBlock = new MaterialPropertyBlock(); } target.GetPropertyBlock(propBlock); propBlock.SetFloat("_BlendWeightIBL", weight); target.SetPropertyBlock(propBlock); #else if (propBlock == null) { propBlock = new MaterialPropertyBlock(); } else { propBlock.Clear(); } //NOTE: this expects the property block to be cleared prior to being called or the weight property will accumulate every frame! //MaterialPropertyBlock block = new MaterialPropertyBlock(); target.GetPropertyBlock(propBlock); propBlock.AddFloat("_BlendWeightIBL", weight); target.SetPropertyBlock(propBlock); #endif #else Material[] mats = getTargetMaterials(target); foreach (Material mat in mats) { mat.SetFloat("_BlendWeightIBL", weight); } #endif }
public void AddToMaterialPropertyBlock(MaterialPropertyBlock block) { Node first = this.first; int count = this.count; while (count-- > 0) { switch (first.type) { case PropType.Float: block.AddFloat(first.property, first.value.FLOAT); break; case PropType.Vector: block.AddVector(first.property, first.value.VECTOR); break; case PropType.Color: block.AddColor(first.property, first.value.COLOR); break; case PropType.Matrix: block.AddMatrix(first.property, first.value.MATRIX); break; } first = first.next; } }
static int AddFloat(IntPtr L) { int count = LuaDLL.lua_gettop(L); Type[] types0 = { typeof(MaterialPropertyBlock), typeof(int), typeof(float) }; Type[] types1 = { typeof(MaterialPropertyBlock), typeof(string), typeof(float) }; if (count == 3 && LuaScriptMgr.CheckTypes(L, types0, 1)) { MaterialPropertyBlock obj = LuaScriptMgr.GetNetObject <MaterialPropertyBlock>(L, 1); int arg0 = (int)LuaScriptMgr.GetNumber(L, 2); float arg1 = (float)LuaScriptMgr.GetNumber(L, 3); obj.AddFloat(arg0, arg1); return(0); } else if (count == 3 && LuaScriptMgr.CheckTypes(L, types1, 1)) { MaterialPropertyBlock obj = LuaScriptMgr.GetNetObject <MaterialPropertyBlock>(L, 1); string arg0 = LuaScriptMgr.GetString(L, 2); float arg1 = (float)LuaScriptMgr.GetNumber(L, 3); obj.AddFloat(arg0, arg1); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: MaterialPropertyBlock.AddFloat"); } return(0); }
// Token: 0x06004B62 RID: 19298 RVA: 0x0012667C File Offset: 0x0012487C public void AddToMaterialPropertyBlock(MaterialPropertyBlock block) { global::UIPanelMaterialPropertyBlock.Node next = this.first; int num = this.count; while (num-- > 0) { switch (next.type) { case global::UIPanelMaterialPropertyBlock.PropType.Float: block.AddFloat(next.property, next.value.FLOAT); break; case global::UIPanelMaterialPropertyBlock.PropType.Vector: block.AddVector(next.property, next.value.VECTOR); break; case global::UIPanelMaterialPropertyBlock.PropType.Color: block.AddColor(next.property, next.value.COLOR); break; case global::UIPanelMaterialPropertyBlock.PropType.Matrix: block.AddMatrix(next.property, next.value.MATRIX); break; } next = next.next; } }
public MaterialPropertyBlock CreatePropertiesBlock() { MaterialPropertyBlock material = new MaterialPropertyBlock(); material.AddVector(_idMinBounds, _minBounds); material.AddVector(_idMaxBounds, _maxBounds); material.AddMatrix(_idProjection, _projectionMatrixCached); material.AddMatrix(_idViewWorldLight, _viewWorldLight); material.AddMatrix(_idLocalRotation, _localRotation); material.AddMatrix(_idRotation, _rotation); material.AddColor(_idColorTint, colorTint); material.AddFloat(_idSpotExponent, spotExponent); material.AddFloat(_idConstantAttenuation, constantAttenuation); material.AddFloat(_idLinearAttenuation, linearAttenuation); material.AddFloat(_idQuadraticAttenuation, quadraticAttenuation); material.AddFloat(_idLightMultiplier, lightMultiplier); switch (shadowMode) { case ShadowMode.Realtime: renderer.sharedMaterial.SetTexture("_ShadowTexture", _depthTexture); break; case ShadowMode.Baked: break; case ShadowMode.None: renderer.sharedMaterial.SetTexture("_ShadowTexture", null); break; } #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 float far = camera.farClipPlane; float near = camera.nearClipPlane; float fov = camera.fieldOfView; #else float far = camera.far; float near = camera.near; float fov = camera.fov; #endif material.AddVector(_idLightParams, new Vector4(near, far, far - near, (camera.isOrthoGraphic) ? Mathf.PI : fov * 0.5f * Mathf.Deg2Rad)); return(material); }
// Update is called once per frame void Update() { for (var i = 0; i < numDraw; i++) { //MaterialPropertyBlockを使うと、Materialを新たに作らずに、独自の値をMaterialに渡した状態でDrawMeshできる。 //もとのメッシュ1つ1つを判断するため、_Offsetの値を指定。 mPropBlock.Clear(); mPropBlock.AddFloat("_Offset", i * numInSingleMesh); Graphics.DrawMesh(mesh, transform.position, transform.rotation, drawMat, 0, null, 0, mPropBlock, true); } }
public virtual void OnWillRenderObject() { if (m_mpb == null) { m_mpb = new MaterialPropertyBlock(); m_mpb.AddVector("_Position", Vector4.zero); m_mpb.AddVector("_Rotation", Vector4.zero); m_mpb.AddVector("_Scale", Vector4.one); m_mpb.AddFloat("_LocalTime", m_local_time); m_mpb.AddFloat("_ID", m_id); m_renderer = GetComponent <Renderer>(); m_trans = GetComponent <Transform>(); } var rot = m_trans.rotation; m_mpb.SetVector("_Position", m_trans.position); m_mpb.SetVector("_Rotation", new Vector4(rot.x, rot.y, rot.z, rot.w)); m_mpb.SetVector("_Scale", m_trans.localScale); m_mpb.SetFloat("_LocalTime", m_local_time); m_renderer.SetPropertyBlock(m_mpb); }
void Update() { //float t = BulletTime.time; float t = Time.time; float rnd = mid + BulletTime.Noise1D(t * frequency) * range; _rnd = rnd.ToString(); if (propBlock != null) { propBlock.Clear(); propBlock.AddFloat("_Intensity", rnd); GetComponent <Renderer>().SetPropertyBlock(propBlock); } }
public void AddToMaterialPropertyBlock(MaterialPropertyBlock block) { UIPanelMaterialPropertyBlock.Node node = this.first; int num = this.count; while (true) { int num1 = num; num = num1 - 1; if (num1 <= 0) { break; } switch (node.type) { case UIPanelMaterialPropertyBlock.PropType.Float: { block.AddFloat(node.property, [email protected]); break; } case UIPanelMaterialPropertyBlock.PropType.Vector: { block.AddVector(node.property, [email protected]); break; } case UIPanelMaterialPropertyBlock.PropType.Color: { block.AddColor(node.property, [email protected]); break; } case UIPanelMaterialPropertyBlock.PropType.Matrix: { block.AddMatrix(node.property, [email protected]); break; } } node = node.next; } }