Dot worldNormal with _Projector 'forward'?

I’ve got a cgprogram shader that I’m attaching to a projector. Ultimately this is to achieve a specific shader driven lighting effect. I want to do the appropriate dot(N,L) diffuse term that you would typically do with a light, only instead I want to use the forward vector of the projector as L.

I’m attempting to do this by putting a ‘forward’ vector into _Projector space - a la:

float3 projectorForward = normalize(mul(_Projector,float4(0,0,1,1)).xyz);

The reason I’m choosing (0,0,1) is because the projector’s forward axis seems to be down its local +z in unity.

The problem I’m running into is I can’t seem to figure out how to get this back into world space - it seems I have no access to the inverse matrix for _Projector. If I did, I would be trying to compute the world space forward axis vector, and dot that with my IN.worldNormal vector.

First off, does this sound like the right thing to do? And if so - does anyone have any ideas how I can get there efficiently? I don’t want to have to compute the inverse matrix by hand.

Hmm indeed I see that the _Projector matrix is about the only thing we set up while rendering, and it’s a bunch of matrices multiplied together, optimized just for sampling a projected texture given object space coordinates. Going to be a challenge to figure out projector’s direction from that.

I’ll think about adding some more matrices to the projector at some point.

In the meantime, if you know you only have one projector, then I guess you could set a global matrix (or a vector if you only care about direction) from a script, and use that in a shader. E.g. from a script, Shader.SetGlobalVector (“ProjectorForward”, …), and use float4 ProjectorForward in your shader. Not ideal, but might work as a workaround.