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 | |
| parent | 69f273558ecfded1fcf7c89b238a241859dc625e (diff) | |
c31: Start sketching tangent space raymarcher
| -rwxr-xr-x | 3ner.shader | 14 | ||||
| -rw-r--r-- | custom31.cginc | 54 | ||||
| -rwxr-xr-x | features.cginc | 5 | ||||
| -rwxr-xr-x | globals.cginc | 6 | ||||
| -rwxr-xr-x | pbr.cginc | 4 |
5 files changed, 82 insertions, 1 deletions
diff --git a/3ner.shader b/3ner.shader index 1c3b51a..578db84 100755 --- a/3ner.shader +++ b/3ner.shader @@ -932,6 +932,20 @@ Shader "yum_food/3ner" [HideInInspector] m_end_Logical_Time("Logical Time", Float) = 0 //endex + //ifex _Custom31_World_Enabled==0 + [HideInInspector] m_start_Custom31_World("C31 World Gimmicks", Float) = 0 + [ThryToggle(_CUSTOM31_WORLD)] _Custom31_World_Enabled("Enable", Float) = 0 + + //ifex _Custom31_World_Hexagons_Enabled==0 + [HideInInspector] m_start_Custom31_World_Hexagons("Hexagons", Float) = 0 + [ThryToggle(_CUSTOM31_WORLD_HEXAGONS)] _Custom31_World_Hexagons_Enabled("Enable", Float) = 0 + _Custom31_World_Hexagons_Scale("Scale", Float) = 1 + [HideInInspector] m_end_Custom31_World_Hexagons("Hexagons", Float) = 0 + //endex + + [HideInInspector] m_end_Custom31_World("Custom31 World", Float) = 0 + //endex + //ifex _Vertex_Deformation_Enabled==0 [HideInInspector] m_start_Vertex_Deformation("Vertex Deformation", Float) = 0 [ThryToggle(_VERTEX_DEFORMATION)] _Vertex_Deformation_Enabled("Enable", Float) = 0 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 diff --git a/features.cginc b/features.cginc index 47ee80f..e826c72 100755 --- a/features.cginc +++ b/features.cginc @@ -134,6 +134,11 @@ #pragma shader_feature_local _LOGICAL_TIME //endex +//ifex _Custom31_World_Enabled==0 +#pragma shader_feature_local _CUSTOM31_WORLD +#pragma shader_feature_local _CUSTOM31_WORLD_HEXAGONS +//endex + //ifex _Ray_Marching_Enabled==0 #pragma shader_feature_local _RAY_MARCHING //endex diff --git a/globals.cginc b/globals.cginc index 6974ee0..241bb92 100755 --- a/globals.cginc +++ b/globals.cginc @@ -183,6 +183,12 @@ float _Center_Offset_Factor; float _Logical_Time; #endif // _LOGICAL_TIME +#if defined(_CUSTOM31_WORLD) +#if defined(_CUSTOM31_WORLD_HEXAGONS) +float _Custom31_World_Hexagons_Scale; +#endif // _CUSTOM31_WORLD_HEXAGONS +#endif // _CUSTOM31_WORLD + float getTime() { #if defined(_LOGICAL_TIME) return _Logical_Time; @@ -1,9 +1,10 @@ #ifndef __PBR_INC #define __PBR_INC +#include "burley.cginc" +#include "custom31.cginc" #include "data.cginc" #include "decal.cginc" -#include "burley.cginc" #include "filamented.cginc" #include "instancing.cginc" #include "interpolators.cginc" @@ -284,6 +285,7 @@ Pbr getPbr(v2f i) { apply_letter_grid(i, pbr); apply_burley_tiling(pbr, normal_tangent); apply_triplanar_layers(i.worldPos, i.normal, pbr, normal_tangent); + apply_custom31_world(i, pbr, normal_tangent); applyDecals(i, pbr, normal_tangent); |
