Hello. I am trying to calculate the view direction in a blit pass for a image effect; but I am having some trouble calculating the direction each pixel is looking/pointing. The result I need is a normalized float3.
I tried quite a few different attempts but I guess my matrix math is too weak. The closest I’ve gotten is ```
float3 viewdir = mul(_CameraToWorldMatrix ,float3((.5-o.uv.x)*_AspectRatio,.5-o.uv.y,1));
Thank you bgolus. I reverse engineered keijiro’s project and extracted the tasty bit.
For future reference:
vertex program
{
v2f o;
o.uv = v.uv;
float3 pos = float3(v.uv*2.-1.,1);
o.vertex = pos.xyzz;
o.ray = mul(unity_CameraInvProjection, pos.xyzz ).xyz;
o.ray.x *= -1;
o.ray = mul(unity_CameraToWorld, o.ray.xyz);
return o;
}```
and then just ```float3 viewDir = normalize(i.ray);``` in the fragment program and you will have the viewdir.