- Home /
Question by
TommyZakh · Apr 20, 2018 at 05:04 AM ·
shadershadersscreenshader programming
Accessing screenPos in custom light function
Hi, I am trying to create a shader which uses a custom light function as so:
half4 LightingCustom(SurfaceOutputCustom s, half3 lightDir, half atten) {
half NdotL = dot(s.Normal, lightDir);
half4 c;
half light = NdotL * atten;
float4 screenPos;
c.rgb = s.Albedo * _LightColor0.rgb * clamp(ceil(light * _LightSteps + rand(screenPos)) / _LightSteps, 0, 1);
c.a = s.Alpha;
return c;
}
screenPos is not defined in this context, and because the custom lighting functions cannot receive an Input struct, there is no way to get access to screenPos. How would I do this?
Comment
Best Answer
Answer by Remy_Unity · Apr 20, 2018 at 11:32 AM
The input of your lighting function is the SurfaceOutputCustom strucd. You can add a variable "screenPos" in this struct and define it in the Surface function.
Your answer
![](https://koobas.hobune.stream/wayback/20220612161149im_/https://answers.unity.com/themes/thub/images/avi.jpg)