viewDir changes with o.Normal


I’m trying to write a surface shader that renders a cubemap on the material in worldspace (think:skybox) using:

texCUBE(_skybox, IN.viewDir);

When I do this on a shader that doesnt’t use a normalmap, I get the correct behavior, however, as soon as I try to add o.Normal as an output, viewDir now behaves differently. I guess, instead of using worldspace, it now uses objectspace? Is there any way to convert the objectspace viewDir back into worldspace? I’m having trouble finding any information about this, and unfortunately I’m still pretty much a novice at this kind of vector math :).

Any help on this will be greatly appreciated, thanks!

I got it to work by passing WorldSpaceViewDir from the vertex program,

I’ll share this code snippet just in case anyone googles the same question:

	  #pragma surface surf Lambert vertex:vert

      struct Input {
        float3 worldSpaceViewDir;

      void vert (inout appdata_full v,out Input o)
           o.WorldSpaceViewDir = WorldSpaceViewDir(v.vertex);

In the surface program just use IN.WorldSpaceViewDir instead of IN.viewDir and you should be good to go