Hey everyone, I would like to know what is the difference between in term of performance, usage and compatibility : Code (CSharp): float3 worldNormal = WorldNormalVector(IN, o.Normal); and Code (CSharp): float3 worldNormal = mul( _Object2World, float4(o.Normal, 0.0)).xyz; Thank you very much !
To be clear the aim is to calculate the worldNormal to use them inside the lighting function of my surface shader but I don't want to pass it using my output values and Code (CSharp): float3 worldNormal = WorldNormalVector(IN, o.Normal); gives good results but I need to use an interpolator to store it to the lighting function. Code (CSharp): float3 worldNormal = mul( _Object2World, float4(o.Normal, 0.0)).xyz; doesn't gives good results but I can calculate it inside the lighting function.
In your second example you're trying to calculate the world normal as if o.Normal were in object space. o.Normal is in tangent space not object space. Tangent -> Object -> World -> etc.. That's why you're getting bad results. When you add worldNormal and INTERNAL_DATA to a surface shader it calculates the rotation matrix in the vertex shader to transform a value from tangent to world space. Those interpolators get passed to the fragment shader (these extra interpolators are normally what causes the errors about too many interpolators if you're already packing a lot of data in!). WorldNormalVector is just a define for a function that uses those interpolators to transform your supplied tangent space value to world space.