Help! Toon/Cubemap shader not affected by camera position

I have a slightly modified toon shader that I am trying to get to look the “same” regardless of where the object is on the screen - effectively, render the cubemap as if it is always facing the camera (even if its not centered on screen).

Currently, the cubemap is just determined with mul(UNITY_MATRIX_MV, v.normal) - I’ve been trying every matrix I can think of but nothing is turning out quite right. I would really appreciate any thoughts anyone had on how it might be pulled off.

I’ve included a screenshot of the shader. Notice that as the ball moves to the left, you are seeing more of the side of the cubemap. Effectively, i want it to look the same as it moves left as it does when its on the right.

thanks!

627759--22398--$Screen shot 2011-07-11 at 9.51.19 PM.png

I got it working by making the matrix outside of the shader:

Quaternion lookRot = Quaternion.LookRotation(Camera.main.transform.position-gameObject.transform.position);

Matrix4x4 m4 = Matrix4x4.TRS(Vector3.one, Quaternion.Inverse(lookRot), Vector3.one);

this.GetComponent().material.SetMatrix(“_Aim”, m4);

But does anyone know if this is possible directly in the shader?

Thanks!

You might be better with a toon ramp, then use float2(dot(s.Normal, viewDir)) as the UV lookup for it. Ensure you clamp the toon ramp’s wrapping in the inspector.

Probably works out a little cheaper than a cubemap, too.