Skip to content

Instantly share code, notes, and snippets.

@ShiftedClock
Created December 28, 2021 02:12
Show Gist options
  • Select an option

  • Save ShiftedClock/e070ec2c9ebe85c35642fbe8b84fdf4e to your computer and use it in GitHub Desktop.

Select an option

Save ShiftedClock/e070ec2c9ebe85c35642fbe8b84fdf4e to your computer and use it in GitHub Desktop.
[numthreads(8,8,1)]
void RayMarchKernel (uint3 id : SV_DispatchThreadID)
{
const float2 uv = float2(id.xy) / screenSize.xy;
const float deviceDepth = LoadCameraDepth(id.xy); // This can be omitted if you're just finding rd
const float z = (1.0 - deviceDepth) * 2.0 - 1.0; // [-1, 1]
const float4 clip = float4(uv * 2.0 - 1.0, z, 1.0); // ([-1, 1], [-1, 1], z, 1)
float4 view = mul(cameraInvProj, clip);
view /= view.w; // perspective correction
const float3 depthPosition = mul(cameraToWorld, view).xyz;
const float jitter = BlueNoise(uv);
float3 rd = normalize(mul(cameraToWorld, float4(view.xyz, 0.0)).xyz);
const float3 ro = cameraPos.xyz + (rd * rayMarchParams.z);
const float maxDist = min(distance(ro, depthPosition), rayMarchParams.w);
// regular raymarching etc.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment