Annotations
This commit is contained in:
@@ -17,6 +17,8 @@ bool intersectCube(float3 rayOrigin, float3 rayDirection, float halfExtent, out
|
||||
float3 boxMin = float3(-halfExtent, -halfExtent, -halfExtent);
|
||||
float3 boxMax = float3(halfExtent, halfExtent, halfExtent);
|
||||
|
||||
// Slab intersection: find the ray interval that overlaps all three box
|
||||
// axes, then keep the nearest positive hit.
|
||||
float3 invDir = 1.0 / rayDirection;
|
||||
float3 t0 = (boxMin - rayOrigin) * invDir;
|
||||
float3 t1 = (boxMax - rayOrigin) * invDir;
|
||||
@@ -43,6 +45,8 @@ float2 cubeFaceUv(float3 hitPoint, float halfExtent, float zoom)
|
||||
float2 uv = float2(0.5, 0.5);
|
||||
float safeZoom = max(zoom, 0.001);
|
||||
|
||||
// The dominant coordinate tells which face was hit; the other two axes
|
||||
// become that face's local UVs.
|
||||
if (face.x >= face.y && face.x >= face.z)
|
||||
{
|
||||
uv = hitPoint.x > 0.0
|
||||
@@ -79,6 +83,8 @@ float4 shadeVideo(ShaderContext context)
|
||||
float yaw = spin;
|
||||
float pitch = spin * 0.61 + 0.35;
|
||||
|
||||
// Rotate the camera ray into cube-local space instead of rotating the cube
|
||||
// geometry, which keeps the intersection math axis-aligned.
|
||||
float3 localOrigin = rotateY(rotateX(rayOrigin, -pitch), -yaw);
|
||||
float3 localDirection = rotateY(rotateX(rayDirection, -pitch), -yaw);
|
||||
|
||||
@@ -96,6 +102,8 @@ float4 shadeVideo(ShaderContext context)
|
||||
|
||||
float3 normal;
|
||||
float3 face = abs(localHit);
|
||||
// Reconstruct the face normal from the hit point so lighting follows the
|
||||
// same face choice used for UV lookup.
|
||||
if (face.x >= face.y && face.x >= face.z)
|
||||
normal = float3(sign(localHit.x), 0.0, 0.0);
|
||||
else if (face.y >= face.x && face.y >= face.z)
|
||||
|
||||
Reference in New Issue
Block a user