summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--3ner.shader8
-rw-r--r--features.cginc4
-rw-r--r--globals.cginc5
-rw-r--r--ray_marching.cginc14
-rw-r--r--ray_marching_maps.slang20
5 files changed, 50 insertions, 1 deletions
diff --git a/3ner.shader b/3ner.shader
index 8d3a577..a6c8af4 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -98,6 +98,14 @@ Shader "yum_food/3ner"
[HideInInspector] m_end_Ray_Marching_Ball("Ball", Float) = 0
//endex
+ //ifex _Ray_Marching_Hexagon_Enabled==0
+ [HideInInspector] m_start_Ray_Marching_Hexagon("Hexagon", Float) = 0
+ [ThryToggle(_RAY_MARCHING_HEXAGON)] _Ray_Marching_Hexagon_Enabled("Enable", Float) = 0
+ _Ray_Marching_Hexagon_Radius("Radius", Range(0,1)) = 0.1
+ _Ray_Marching_Hexagon_Height("Height", Range(0,1)) = 0.1
+ [HideInInspector] m_end_Ray_Marching_Hexagon("Hexagon", Float) = 0
+ //endex
+
[HideInInspector] m_end_Ray_Marching("Ray Marching", Float) = 0
//endex
diff --git a/features.cginc b/features.cginc
index 9b76cd4..d74ef01 100644
--- a/features.cginc
+++ b/features.cginc
@@ -96,4 +96,8 @@
#pragma shader_feature_local _RAY_MARCHING_BALL
//endex
+//ifex _Ray_Marching_Hexagon_Enabled==0
+#pragma shader_feature_local _RAY_MARCHING_HEXAGON
+//endex
+
#endif // __FEATURES_INC
diff --git a/globals.cginc b/globals.cginc
index 181e71f..6e0d71f 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -157,4 +157,9 @@ float _Ray_Marching_Ball_Grid_Count_Z;
float _Ray_Marching_Ball_Radius;
#endif // _RAY_MARCHING_BALL
+#if defined(_RAY_MARCHING_HEXAGON)
+float _Ray_Marching_Hexagon_Radius;
+float _Ray_Marching_Hexagon_Height;
+#endif // _RAY_MARCHING_HEXAGON
+
#endif // __GLOBALS_INC
diff --git a/ray_marching.cginc b/ray_marching.cginc
index 57a3dff..d989dc8 100644
--- a/ray_marching.cginc
+++ b/ray_marching.cginc
@@ -100,6 +100,13 @@ void ray_march(inout v2f i) {
d_cur = min(d_cur, map_ball(p, _Ray_Marching_Ball_Radius));
}
#endif
+#if defined(_RAY_MARCHING_HEXAGON)
+ {
+ float r = _Ray_Marching_Hexagon_Radius;
+ float h = _Ray_Marching_Hexagon_Height;
+ d_cur = min(d_cur, map_hexagon(p, float2(r, h)));
+ }
+#endif
#if defined(_RAY_MARCHING_OVERSTEP)
d_cur *= (d_cur > 0 ? _Ray_Marching_Overstepping_Factor : 1.0f);
@@ -128,6 +135,13 @@ void ray_march(inout v2f i) {
map_ball_normal(r, lclPos, lclNorm, lclTan);
}
#endif
+#if defined(_RAY_MARCHING_HEXAGON)
+ {
+ float r = _Ray_Marching_Hexagon_Radius;
+ float h = _Ray_Marching_Hexagon_Height;
+ map_hexagon_normal(float2(r, h), lclPos, lclNorm, lclTan);
+ }
+#endif
i.objPos = lclPos;
i.normal = lclNorm;
diff --git a/ray_marching_maps.slang b/ray_marching_maps.slang
index 002ef90..1b8fe84 100644
--- a/ray_marching_maps.slang
+++ b/ray_marching_maps.slang
@@ -1,7 +1,6 @@
#ifndef __RAY_MARCHING_MAPS_INC
#define __RAY_MARCHING_MAPS_INC
-
#include "math.cginc"
#include "pema99.cginc"
@@ -42,5 +41,24 @@ public void map_ball_normal(float r, inout float3 xyz, inout float3 normal,
R3R1_RAY_MARCH_NORMALS(xyz, normal, tangent, map_ball, r);
}
+[Differentiable]
+public float map_hexagon(float3 p, no_diff float2 h)
+{
+ float3 q = abs(p);
+
+ const float3 k = float3(-0.8660254, 0.5, 0.57735);
+ p = abs(p);
+ p.xy -= 2.0*min(dot(k.xy, p.xy), 0.0)*k.xy;
+ float2 d = float2(
+ length(p.xy - float2(clamp(p.x, -k.z*h.x, k.z*h.x), h.x))*sign(p.y - h.x),
+ p.z-h.y );
+ return min(max(d.x,d.y),0.0) + length(max(d,0.0));
+}
+
+public void map_hexagon_normal(float2 h, inout float3 xyz, inout float3 normal,
+ inout float3 tangent) {
+ R3R1_RAY_MARCH_NORMALS(xyz, normal, tangent, map_hexagon, h);
+}
+
#endif // __RAY_MARCHING_MAPS_INC