- Home /
Surface Shader, run vertex multiple times
How do I run a Surface shader's vertex script multiple times? Essentially putting a For loop inside the vert code.
My vertex code extrudes the verts of a mesh to make a border glow effect. It creates a copy of the verts, moves them back in the z-axis, and offsets the x and y axes so it appears behind/beside the original mesh. It then applies a glow material.
I can only figure out how to run it once, basically setting "x + 5", "y + 0". What I want to do is run the code multiple times, with the X and Y changing each time so it outlines it on all sides.
(For various reasons I can't just expand the scale of the mesh and invert it as you normally would, I've achieved that effect on other meshes but it doesn't work here.)
Edit: to be clear, I'd want the "For" loop passes to be a definable int, so I can control how detailed the border is. Whether it's just a left-right-up-down offset, or a rounded border mesh with 8-16 extrusions.
Here's my actual code, if it helps. Again, what I'd ideally want is some kind of For loop in "void vert". Thanks!
CGPROGRAM
//PROGRAM: Border Outline Glow Effect Walls
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
sampler2D _Illum;
fixed4 _DiffuseColor;
fixed4 _EmissionColor;
float _EmissionGain;
float _EmissionTextureContrast;
float _VXAmount;
float _VXDepth;
struct Input {
float2 uv_MainTex;
float2 uv_Illum;
};
void vert(inout appdata_full v) {
v.vertex.x += v.normal.z * _VXAmount;
v.vertex.y += v.normal.z * _VXAmount;
v.vertex.z += v.normal.z * _VXDepth;
}
void surf (Input IN, inout SurfaceOutput o) {
//fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
//fixed4 c = tex * _DiffuseColor;
fixed4 c = _DiffuseColor;
o.Albedo = c.rgb;
fixed3 emissTex = tex2D(_Illum, IN.uv_Illum).rgb;
float emissL = max(max(emissTex.r, emissTex.g), emissTex.b);
fixed3 emissN = emissTex / (emissL + 0.0001);
emissL = pow(emissL, _EmissionTextureContrast);
emissTex = emissN * emissL;
o.Emission = _EmissionColor * emissTex * (exp(_EmissionGain * 10.0f));
o.Alpha = c.a;
}
ENDCG