diff options
| author | yum <yum.food.vr@gmail.com> | 2026-04-05 15:41:21 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-04-05 15:41:25 -0700 |
| commit | 736de84c38db6c6f150daacc3c8d1a0f9c92ecbb (patch) | |
| tree | 71574e4975216f8f406d056f1eb364be07412840 /custom31.cginc | |
| parent | 69f273558ecfded1fcf7c89b238a241859dc625e (diff) | |
c31: Start sketching tangent space raymarcher
Diffstat (limited to 'custom31.cginc')
| -rw-r--r-- | custom31.cginc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/custom31.cginc b/custom31.cginc new file mode 100644 index 0000000..6f29403 --- /dev/null +++ b/custom31.cginc @@ -0,0 +1,54 @@ +#ifndef __CUSTOM31_INC +#define __CUSTOM31_INC + +#include "globals.cginc" +#include "interpolators.cginc" + +float map(float3 p) { + return length(p) - 0.1; +} + +void apply_custom31_world(v2f i, inout Pbr pbr, inout float3 normal_tangent) { +#if defined(_CUSTOM31_WORLD) + // We will raymarch in (tangent, binormal, normal) coordinates. + // Make an expanded homogeneous tbn matrix to support moving back and forth. + // This first incarnation moves from world to tangent. + float4x4 tbn = float4x4( + pbr.tbn[0], 0, + pbr.tbn[1], 0, + pbr.tbn[2], 0, + 0, 0, 0, 1); + tbn = mul(tbn, unity_WorldToObject); + + float3 ro = mul(tbn, float4(i.worldPos, 1)); + float3 rd = normalize(mul((float3x3) tbn, i.worldPos - _WorldSpaceCameraPos)); + + float d_acc = 0; + float d; + const float MIN_DIST = 1e-3; + const float MAX_DIST = 1; + [loop] + for (uint ii = 0; ii < 10; ++ii) { + float3 p = ro + rd * d_acc; + d = map(p); + d_acc += d; + if (d < MIN_DIST) { + break; + } + if (d > MAX_DIST) { + break; + } + } + + if (d < MIN_DIST) { + pbr.albedo.xyz = 1; + } else { + pbr.albedo.xyz = 0; + } + + float3 p = ro + rd * d_acc; + p = mul(float4(p, 1), tbn); +#endif +} + +#endif // __CUSTOM31_INC |
