Created
December 28, 2021 02:12
-
-
Save ShiftedClock/e070ec2c9ebe85c35642fbe8b84fdf4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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