Skip to content

Commit be5f657

Browse files
committed
Fix raymarching ray start position (ensure not behind camera)
1 parent 526bcc2 commit be5f657

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Assets/Shaders/DirectVolumeRenderingShader.shader

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,15 @@
159159
// Check if camera is inside AABB
160160
const float3 farPos = ray.startPos + ray.direction * ray.aabbInters.y - float3(0.5f, 0.5f, 0.5f);
161161
float4 clipPos = UnityObjectToClipPos(float4(farPos, 1.0f));
162-
ray.aabbInters += min(clipPos.w, 0.0);
162+
if(unity_OrthoParams.w == 0)
163+
{
164+
float3 viewDir = ObjSpaceViewDir(float4(vertexLocal, 0.0f));
165+
float viewDist = length(viewDir);
166+
if (ray.aabbInters.y > viewDist)
167+
{
168+
ray.aabbInters.y = viewDist;
169+
}
170+
}
163171

164172
ray.endPos = ray.startPos + ray.direction * ray.aabbInters.y;
165173
return ray;

0 commit comments

Comments
 (0)