I am trying to recreate this shader:

However, I am having trouble as early as 4:40, when I am trying to draw a box to my view with an ImageEffectShader.

My shader looks like this:

```
v2f vert (appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.pos);
o.uv = v.uv;
return o;
}
float2 rayBoxDist (float3 boundsMin, float3 boundsMax, float3 rayOrigin, float3 rayDir)
{
float3 t0 = (boundsMin - rayOrigin) / rayDir;
float3 t1 = (boundsMax - rayOrigin) / rayDir;
float3 tmin = min(t0, t1);
float3 tmax = max(t0, t1);
float distA = max(max(tmin.x, tmin.y), tmin.z);
float distB = min(tmax.x, min(tmax.x, tmax.y));
float distToBox = max(0, distA);
float distInsideBox = max(0, distB - distToBox);
return float2(distToBox, distInsideBox);
}
float3 BoundsMin;
float3 BoundsMax;
float3 CameraPos;
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
float3 rayOrigin = CameraPos;
float3 worldPos = mul(unity_ObjectToWorld, float4(i.pos.xyz, 1)).xyz;
float3 rayDir = normalize(worldPos - CameraPos);
float2 rayBoxInfo = rayBoxDist(BoundsMin, BoundsMax, rayOrigin, rayDir);
float distToBox = rayBoxInfo.x;
float distInsideBox = rayBoxInfo.y;
bool rayBoxHit = distInsideBox > 0;
if (rayBoxHit) {
return col;
}
return float4(0,0,0,1);
}
```

The shader renders an all-black image, indicating that no ray has hit the box.

I have already confirmed that rayBoxDist works with this line of code:

`float2 rayBoxInfo = rayBoxDist(float3(0,0,0), float3(2,2,2), float3(1,1.9,1), 1 / float3(-1,0,0));`

Which returns the expected rayBoxInfo.

I assume that I am somehow confusing different coordinate systems, but I don’t know where my error is.

If I get the world space position of a vertex in the shader, I should be able to infer the view direction, so how can I get the position of a vertex in world space?