summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--3ner.shader1
-rw-r--r--ray_marching.cginc4
-rw-r--r--vertex_deformation.slang8
3 files changed, 7 insertions, 6 deletions
diff --git a/3ner.shader b/3ner.shader
index 8b05bbf..d755f64 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -109,7 +109,6 @@ Shader "yum_food/3ner"
//ifex _Vertex_Deformation_XZ_Tube_Enabled==0
[HideInInspector] m_start_Vertex_Deformation_XZ_Tube("XZ Tube", Float) = 0
[ThryToggle(_VERTEX_DEFORMATION_XZ_TUBE)] _Vertex_Deformation_XZ_Tube_Enabled("Enable", Float) = 0
- // 0.999... limit prevents NaNs which show up at 1.0
_Vertex_Deformation_XZ_Tube_t("t", Range(-1,1)) = 0
[HideInInspector] m_end_Vertex_Deformation_XZ_Tube("XZ Tube", Float) = 0
//endex
diff --git a/ray_marching.cginc b/ray_marching.cginc
index 4c7544e..b13bee0 100644
--- a/ray_marching.cginc
+++ b/ray_marching.cginc
@@ -25,6 +25,7 @@ void GetRoRd(v2f i, out float3 ro, out float3 rd) {
}
void ray_march(inout v2f i) {
+#if defined(_RAY_MARCHING)
float3 ro, rd;
GetRoRd(i, ro, rd);
@@ -50,7 +51,7 @@ void ray_march(inout v2f i) {
#endif
#if defined(_RAY_MARCHING_OVERSTEP)
- d_cur *= _Ray_Marching_Overstepping_Factor;
+ d_cur *= (d_cur > 0 ? _Ray_Marching_Overstepping_Factor : 1.0f);
#endif
d_acc += d_cur;
@@ -78,6 +79,7 @@ void ray_march(inout v2f i) {
i.objPos = lclPos;
i.normal = lclNorm;
i.tangent.xyz = lclTan;
+#endif // _RAY_MARCHING
}
#endif // __RAY_MARCHING_INC
diff --git a/vertex_deformation.slang b/vertex_deformation.slang
index 1af5ec9..36d09fb 100644
--- a/vertex_deformation.slang
+++ b/vertex_deformation.slang
@@ -93,11 +93,11 @@ public float3 plane_to_tube(float3 xyz, no_diff float t) {
float z0 = xyz.z;
float theta = x0 * PI;
- float radius = ((1.0f - z0) / (dabs(t) + 1e-4f)) * sign(t);
+ float phi = z0 * PI;
+ float radius = 1.0f / (dabs(t) + 1e-4f) * sign(t);
- float x = sin(theta / radius) * radius * PI_RCP;
- // The z0 term here is required to make the jacobian invertible.
- float z = z0 + (1.0f - cos(theta / radius)) * radius * PI_RCP;
+ float x = sin(theta / radius) * (radius * PI_RCP - z0);
+ float z = (1.0f - cos(theta / radius)) * (radius * PI_RCP) + cos(theta / radius) * z0;
return float3(x, y0, z);
}