Hi,
I was wondering what “struct Input” is (“tex2D” just needs for some reason to store the uvs, and it does it automatically with _MainTex in the first parameter?), and how do we know the “name” of what we define in the struct input (uv_MainTex etc.)? Is it an information we have to find in the Lambert shader?
For example :
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
}
ENDCG
}
EDIT :
in this example, viewDir takes the viewing angle from Unity… so what’s inside “Input” is also directly connected to our properties outside the shader? I am a bit confused between the two examples :
//...
struct Input {
float2 uv_MainTex;
float2 uv_BumpTex;
float3 viewDir; //We want to get the viewing angle
};
sampler2D _MainTex;
sampler2D _BumpTex;
float4 _RimColor;
float _RimPower;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
o.Normal = UnpackNormal (tex2D (_BumpTex, IN.uv_BumpTex));
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
//...
Thanks
My Noobs guide to shaders on Unity Gems attempts to demystify some of the "magic" things that happen when you defined variables in the input of a surface shader.
– whydoidoit