- Home /
change front color or back color programmatically
I want to change only the front color or back color programmatically. i tried doing it using vertex on the the unity shader particle. but it somehow makes mesh messy and hard to see. so i decided to create my own now i saw a code that has a formula for knowing if vertex is in back or front ( i havent tried it yet though) . now my question is this since using the particle shader makes mesh messy kinda bright looking. how do i create a shader that does the same thing..(particle colors each vertex color just fine). but using the shader below which supports vertex lighting or something did not do the trick.. if you could point me to anything that is close (shaders, codes hopefully not lengthy ones lol) and hopefully easier too. that would be awesome. thanks in advance
var mesh : Mesh = GameObject.Find("Cube2").GetComponent(MeshFilter).mesh;
var rend : Renderer = GameObject.Find("Cube2").GetComponent(Renderer);
rend.material.SetColor ("Main Color", Color.blue);
var vertices : Vector3[] = mesh.vertices;
var colors : Color[] = new Color[vertices.Length];
for (var i = 0; i < vertices.Length;i++)
{
colors[i] = Color.Lerp(Color.blue, Color.blue, vertices[i].y);
}
Shader "VertexLit" { Properties { _Color ("Main Color", Color) = (1,1,1,0.5) _SpecColor ("Spec Color", Color) = (1,1,1,1) _Emission ("Emmisive Color", Color) = (0,0,0,0) _Shininess ("Shininess", Range (0.01, 1)) = 0.7 _MainTex ("Base (RGB)", 2D) = "white" { } }
SubShader {
Pass {
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeparateSpecular On
SetTexture [_MainTex] {
constantColor [_Color]
Combine texture * primary DOUBLE, texture * constant
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613135508im_/https://answers.unity.com/themes/thub/images/avi.jpg)