public void SetColor(Color col) { mb.AddColor("_Color", col); mb.AddColor("_TintColor", col); this.transform.renderer.SetPropertyBlock(mb); }
void Awake() { mb = new MaterialPropertyBlock(); mb.AddColor("_Color", newColor); mb.AddColor("_TintColor", newColor); this.transform.renderer.SetPropertyBlock(mb); }
public override void Render(Matrix matrix, ColorTransform colorTransform, int renderingIndex, int renderingCount, bool visible) { // Ignore null texture #if UNITY_EDITOR m_visible = visible; #endif if (m_context == null || !visible) { return; } Factory factory = m_context.factory; factory.ConvertColorTransform( ref m_colorMult, ref m_colorAdd, colorTransform); if (m_colorMult.a <= 0) { return; } if (m_context.premultipliedAlpha) { m_colorMult.r *= m_colorMult.a; m_colorMult.g *= m_colorMult.a; m_colorMult.b *= m_colorMult.a; } factory.ConvertMatrix(ref m_matrix, matrix, 1, renderingCount - renderingIndex, m_context.height); Factory.MultiplyMatrix(ref m_renderMatrix, factory.gameObject.transform.localToWorldMatrix, m_matrix); m_property.Clear(); m_property.AddColor("_Color", m_colorMult); if (factory.useAdditionalColor) { m_property.AddColor("_AdditionalColor", m_colorAdd); } if (factory.blendMode == (int)Format.Constant.BLEND_MODE_ADD) { if (m_additiveMaterial == null) { m_additiveMaterial = new Material(m_context.material); m_additiveMaterial.shader = ResourceCache.SharedInstance().GetAdditiveShader( m_context.material.shader); } Graphics.DrawMesh(m_context.mesh, m_renderMatrix, m_additiveMaterial, factory.gameObject.layer, factory.camera, 0, m_property); } else { Graphics.DrawMesh(m_context.mesh, m_renderMatrix, m_context.material, factory.gameObject.layer, factory.camera, 0, m_property); } }
public override void Render(Matrix matrix, ColorTransform colorTransform, int renderingIndex, int renderingCount, bool visible) { // Ignore null texture #if UNITY_EDITOR m_visible = visible; #endif if (m_context == null || !visible) { return; } Factory factory = m_context.factory; factory.ConvertColorTransform( ref m_colorMult, ref m_colorAdd, colorTransform); if (m_colorMult.a <= 0) { return; } if (m_context.premultipliedAlpha) { m_colorMult.r *= m_colorMult.a; m_colorMult.g *= m_colorMult.a; m_colorMult.b *= m_colorMult.a; } factory.ConvertMatrix(ref m_matrix, matrix, 1, renderingCount - renderingIndex, m_context.height); Factory.MultiplyMatrix(ref m_renderMatrix, factory.gameObject.transform.localToWorldMatrix, m_matrix); m_property.Clear(); m_property.AddColor(m_colorId, m_colorMult); if (factory.useAdditionalColor) { m_property.AddColor(m_additionalColorId, m_colorAdd); } if (m_blendMode != factory.blendMode) { m_blendMode = factory.blendMode; if (m_material != null) { Material.Destroy(m_material); m_material = null; } m_material = ResourceCache.CreateBlendMaterial( m_context.material, m_context.premultipliedAlpha, m_blendMode); } Material material = m_material == null ? m_context.material : m_material; Graphics.DrawMesh(m_context.mesh, m_renderMatrix, material, factory.gameObject.layer, factory.renderCamera, 0, m_property); }
void Update() { if (animate) { Color currentColor; Color targetColor; if (goToZero) { newColor = originalColor; newColor.a = 0; mb.AddColor(colorType, newColor); this.renderer.material.SetColor(colorType, newColor); this.renderer.SetPropertyBlock(mb); animate = false; goToZero = false; } if (goToColor) { currentColor = this.renderer.material.GetColor(colorType); targetColor = originalColor; if (goToHalf) { targetColor.a = originalColor.a * 0.2f; } newColor = Color.Lerp(currentColor, targetColor, Time.deltaTime * speed / 5f); if (newColor.a > targetColor.a - 0.005f && newColor.a < targetColor.a + 0.005f) { animate = false; /* * if(this.transform.name == "Color" ) * { * Debug.Log ("target col " + targetColor.a); * Debug.Log ("o col " + originalColor.a); * }*/ Fade(); } } else { currentColor = this.renderer.material.GetColor(colorType); targetColor = new Color(originalColor.r, originalColor.g, originalColor.b, 0); newColor = Color.Lerp(currentColor, targetColor, Time.deltaTime * speed); if (newColor.a < 0.005f) { animate = false; Display(); } } mb.AddColor(colorType, newColor); this.renderer.material.SetColor(colorType, newColor); this.renderer.SetPropertyBlock(mb); } }
void Awake() { mb = new MaterialPropertyBlock(); mb.AddColor("_Color", newColor); mb.AddColor("_TintColor", newColor); foreach (Transform child in transform) { child.renderer.SetPropertyBlock(mb); } }
public void SetColor(Color col) { mb = new MaterialPropertyBlock(); mb.AddColor("_Color", col); mb.AddColor("_TintColor", col); foreach (Transform child in transform) { child.renderer.SetPropertyBlock(mb); } }
public void SetColors(Color mainColor, Color specularColor) { var block = new MaterialPropertyBlock(); block.AddColor("_Color", mainColor); block.AddColor("_SpecColor", specularColor); foreach (var r in renderers) { r.SetPropertyBlock(block); } }
public virtual void Render(Matrix4x4 matrix, Color multColor, int layer = 0, Camera camera = null) { if (mEmpty) { return; } mProperty.Clear(); mProperty.AddColor("_Color", multColor); Graphics.DrawMesh( mMesh, matrix, mMaterial, layer, camera, 0, mProperty); }
public void SetColor(Color col) { mb = new MaterialPropertyBlock(); foreach (Transform child in transform) { //col.a = (1-child.localPosition.y*6)/2f; mb.AddColor("_Color", col); mb.AddColor("_TintColor", col); child.renderer.SetPropertyBlock(mb); } }
private void ResetCannonColor(GameObject cannon) { MaterialPropertyBlock props = new MaterialPropertyBlock(); props.AddColor("_Color", InitialCannonColor); cannon.GetComponent <Renderer>().SetPropertyBlock(props); }
static int AddColor(IntPtr L) { int count = LuaDLL.lua_gettop(L); Type[] types0 = { typeof(MaterialPropertyBlock), typeof(int), typeof(Color) }; Type[] types1 = { typeof(MaterialPropertyBlock), typeof(string), typeof(Color) }; if (count == 3 && LuaScriptMgr.CheckTypes(L, types0, 1)) { MaterialPropertyBlock obj = LuaScriptMgr.GetNetObject <MaterialPropertyBlock>(L, 1); int arg0 = (int)LuaScriptMgr.GetNumber(L, 2); Color arg1 = LuaScriptMgr.GetNetObject <Color>(L, 3); obj.AddColor(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); Color arg1 = LuaScriptMgr.GetNetObject <Color>(L, 3); obj.AddColor(arg0, arg1); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: MaterialPropertyBlock.AddColor"); } return(0); }
public void UpdateMesh() { gameObject.SetActive(true); if (buffer.objects == null || buffer.objects.Length != rectangleCount) { buffer.Alloc(rectangleCount); } else { buffer.index = 0; } for (int i = 0; i < rendererCount; ++i) { renderers[i].UpdateMesh(buffer); } if (buffer.modified) { buffer.modified = false; mesh.Clear(true); mesh.vertices = buffer.vertices; mesh.uv = buffer.uv; mesh.triangles = buffer.triangles; mesh.colors32 = buffer.colors32; mesh.RecalculateBounds(); } if (property != null) { property.AddColor(additionalColorId, additionalColor); meshRenderer.SetPropertyBlock(property); } }
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; } }
public void UpdateMesh() { gameObject.SetActive(true); if (buffer.vertices == null || buffer.vertices.Length / 4 != rectangleCount) { buffer.Alloc(rectangleCount); } else { buffer.index = 0; } for (int i = 0; i < rendererCount; ++i) { renderers[i].UpdateMesh(buffer); } buffer.initialized = false; if (buffer.modified) { buffer.modified = false; canvasRenderer.SetVertices(buffer.vertices, rectangleCount * 4); } if (property != null) { property.AddColor(additionalColorId, additionalColor); //meshRenderer.SetPropertyBlock(property); } }
// 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; } }
MaterialPropertyBlock SetupOcclusionPropertyBlock(Light l, float occlusion) { MaterialPropertyBlock propBlock = new MaterialPropertyBlock(); propBlock.Clear(); propBlock.AddColor("_LightColor0", l.intensity * Color.Lerp(l.color, sunColorInShadow, occlusion)); return(propBlock); }
public static void DrawCube(Vector3 position, Quaternion rotation, float size, Color color) { Matrix4x4 mat = Matrix4x4.TRS(position, rotation, size * Vector3.one); MaterialPropertyBlock block = new MaterialPropertyBlock(); block.AddColor("_Color", color); Graphics.DrawMesh(solidCube, mat, material, 0, null, 0, block); }
public static void DrawSphere(Vector3 position, float radius, Color color) { Matrix4x4 mat = Matrix4x4.TRS(position, Quaternion.identity, radius * 0.5f * Vector3.one); MaterialPropertyBlock block = new MaterialPropertyBlock(); block.AddColor("_Color", color); Graphics.DrawMesh(solidSphere, mat, material, 0, null, 0, block); }
public override void Render(Matrix matrix, ColorTransform colorTransform, int renderingIndex, int renderingCount, bool visible) { // Ignore null texture #if UNITY_EDITOR m_visible = visible; #endif if (m_context == null || !visible) { return; } Factory factory = m_context.factory; #if LWF_USE_ADDITIONALCOLOR factory.ConvertColorTransform( ref m_colorMult, ref m_colorAdd, colorTransform); #else factory.ConvertColorTransform(ref m_colorMult, colorTransform); #endif if (m_colorMult.a <= 0) { return; } if (m_context.premultipliedAlpha) { m_colorMult.r *= m_colorMult.a; m_colorMult.g *= m_colorMult.a; m_colorMult.b *= m_colorMult.a; } factory.ConvertMatrix(ref m_matrix, matrix, 1, renderingCount - renderingIndex, m_context.height); Factory.MultiplyMatrix(ref m_renderMatrix, factory.gameObject.transform.localToWorldMatrix, m_matrix); m_property.Clear(); m_property.AddColor("_Color", m_colorMult); #if LWF_USE_ADDITIONALCOLOR m_property.AddColor("_AdditionalColor", m_colorAdd); #endif Graphics.DrawMesh(m_context.mesh, m_renderMatrix, m_context.material, factory.gameObject.layer, factory.camera, 0, m_property); }
void Awake() { mb = new MaterialPropertyBlock(); mb.AddTexture("_MainTex", texture); foreach (Transform child in transform) { defaultColor = child.renderer.material.color; Color newColor = defaultColor; //newColor.a = (1-child.localPosition.y*8)/2f; mb.AddColor("_Color", newColor); mb.AddColor("_TintColor", newColor); child.renderer.SetPropertyBlock(mb); child.renderer.material.SetTexture("_MainTex", texture); } }
public void SetColor(Color c) { if (mpb == null) { mpb = new MaterialPropertyBlock(); } if (meshRenderer) { meshRenderer.GetPropertyBlock(mpb); mpb.AddColor("_Color", c); meshRenderer.SetPropertyBlock(mpb); } }
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); }
protected override void IssueDrawCall() { if (m_cb == null) { m_cb = new CommandBuffer(); m_cb.name = "MPGPLightRenderer"; foreach (var c in m_cameras) { if (c != null) { c.AddCommandBuffer(CameraEvent.AfterLighting, m_cb); } } m_mpb = new MaterialPropertyBlock(); m_mpb.AddColor("_Color", GetLinearColor()); } m_cb.Clear(); if (m_hdr) { m_cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); } else { m_cb.SetRenderTarget(BuiltinRenderTextureType.GBuffer3); } m_mpb.SetColor("_Color", GetLinearColor()); m_mpb.SetFloat("g_size", m_size); m_mpb.SetFloat("_OcculusionStrength", m_occulusion_strength); m_mpb.SetColor("_HeatColor", GetLinearHeatColor()); m_mpb.SetFloat("_HeatThreshold", m_heat_threshold); Matrix4x4 matrix = Matrix4x4.identity; m_actual_materials.ForEach(a => { for (int i = 0; i < m_batch_count; ++i) { m_cb.DrawMesh(m_expanded_mesh, matrix, a[i], 0, 0, m_mpb); } }); }
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; } }
private void ActivateCannon(GameObject cannon, Color c) { MaterialPropertyBlock props = new MaterialPropertyBlock(); props.AddColor("_Color", c); cannon.GetComponent <Renderer>().SetPropertyBlock(props); StartCoroutine(ResetCannonColorLater(cannon, 2)); cannon.GetComponent <AudioSource>().Play(); Vector3 savedAngles = new Vector3(cannon.transform.eulerAngles.x, cannon.transform.eulerAngles.y, cannon.transform.eulerAngles.z); StartCoroutine(ResetCannonAngleLater(cannon, savedAngles, 2)); System.Random random = new System.Random(); int randomAngle = random.Next(CANNON_MIN_RANDOM_ROTATION, CANNON_MAX_RANDOM_ROTATION); cannon.transform.eulerAngles = new Vector3(cannon.transform.eulerAngles.x, cannon.transform.eulerAngles.y + randomAngle, cannon.transform.eulerAngles.z); //random rotation }
//called by editor script to set up data public void MeshLineRender_Ctor() { this.sim = this.GetComponent <IFormLayer>().GetSimulation; this.particleNumCache = sim.numberOfParticles(); this.stringNumCache = sim.numberOfSprings(); meshRenderer = this.GetComponent <MeshRenderer>(); if (meshRenderer == null) { meshRenderer = this.gameObject.AddComponent <MeshRenderer>(); } meshRenderer.receiveShadows = false; meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshRenderer.useLightProbes = false; meshRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; meshRenderer.sharedMaterial = Mtl; meshRenderer.hideFlags = HideFlags.HideInInspector; mpb = new MaterialPropertyBlock(); meshRenderer.GetPropertyBlock(mpb); mpb.AddColor("_Color", color); meshRenderer.SetPropertyBlock(mpb); colorCache = color; if (mesh == null) { mesh = new Mesh(); CreateMesh(); this.particleNumCache = sim.numberOfParticles(); this.stringNumCache = sim.numberOfSprings(); } meshFilter = this.GetComponent <MeshFilter>(); if (meshFilter == null) { meshFilter = this.gameObject.AddComponent <MeshFilter>(); } meshFilter.sharedMesh = mesh; meshFilter.hideFlags = HideFlags.HideInInspector; }
public static void DrawMesh(Mesh mesh, Color color, Vector3 position, Quaternion rotation) { materialProperty.Clear(); materialProperty.AddColor("_Color", color); Graphics.DrawMesh(mesh, position, rotation, unlitColor, 0, null, 0, materialProperty); }