- Home /
Question by
PixelSpartan · Aug 25, 2018 at 03:01 PM ·
shadergraphicsfunctionparameters
Pass data from "v2f vert(appdata_vert v){}" to "float4 frag(v2f i){}"
So im very new to shaders and im just hacking something together.
In the shader there are 2 functions (vert and frag).
In the vert it calculates "alpha" which is used for fading based on distance. Now i want add a cutout part based on that "alpha" but since the "alpha" is being calculated in vert i dont know how to pass it to frag.
v2f vert(appdata_vert v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
float4 viewPos = mul(UNITY_MATRIX_MV, v.vertex);
//
float alpha = (-viewPos.z - _ProjectionParams.y) / _FadeDistance;
alpha *= alpha;
alpha = min(alpha, 1);
alpha = 1 - alpha; // Pass "alpha" float to frag?
//
o.color = float4(v.color.rgb, v.color.a*alpha);
o.color *= _TintColor * 2;
return o;
}
float4 frag(v2f i) : COLOR{
half4 texcol = tex2D(_MainTex, i.uv);
/* how to pass alpha from vert to this function?
float cutoff = alpha * _Cutoff;
if (texcol.a < cutoff)
texcol.a = 0;
*/
return texcol * i.color;
}
Comment