summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-03-15 16:36:46 -0700
committeryum <yum.food.vr@gmail.com>2026-03-15 16:36:46 -0700
commitf607646ad46ead5fc404f4313a901a13b2df466f (patch)
tree1c9cd96a823ccbdf48f93302e63b73a9624773f6
parentc6727a2be7d39323e0be050090114415d969bb49 (diff)
Finish marble rework
-rwxr-xr-x3ner.shader22
-rwxr-xr-xfeatures.cginc1
-rwxr-xr-xglobals.cginc12
-rwxr-xr-xpbr.cginc32
4 files changed, 63 insertions, 4 deletions
diff --git a/3ner.shader b/3ner.shader
index 93e8d07..c4e26f1 100755
--- a/3ner.shader
+++ b/3ner.shader
@@ -986,10 +986,28 @@ Shader "yum_food/3ner"
[HideInInspector] m_start_Marble("Marble", Float) = 0
[ThryToggle(_MARBLE)] _Marble_Enabled("Enable", Float) = 0
_Marble_Noise("Noise", 3D) = "gray" {}
- //[Gradient] _Marble_U_Ramp("U Ramp", 2D) = "white" {}
_Marble_Scale("Scale", Vector) = (1, 1, 1, 0)
_Marble_Strength("Strength", Float) = 1
- _Marble_Octaves("Octaves", Range(1, 10)) = 3
+ [IntRange] _Marble_Octaves("Octaves", Range(1, 10)) = 3
+ _Marble_Lacunarity("Lacunarity", Float) = 2
+ _Marble_Gain("Gain", Float) = 0.5
+ [Gradient] _Marble_Post_Ramp("Post Ramp", 2D) = "white" {}
+
+ //ifex _Marble_Time_Enabled==0
+ [HideInInspector] m_start_Marble_Time("Time", Float) = 0
+ [ThryToggle(_MARBLE_TIME)] _Marble_Time_Enabled("Enable", Float) = 0
+ _Marble_Speed("Speed", Float) = 0.1
+ _Marble_Direction("Direction", Vector) = (1, 1, 1, 0)
+ [HideInInspector] m_end_Marble_Time("Time", Float) = 0
+ //endex
+
+ //ifex _Marble_Offset_Enabled==0
+ [HideInInspector] m_start_Marble_Offset("Offset", Float) = 0
+ [ThryToggle(_MARBLE_OFFSET)] _Marble_Offset_Enabled("Enable", Float) = 0
+ _Marble_Offset("Offset", Vector) = (0, 0, 0, 0)
+ [HideInInspector] m_end_Marble_Offset("Offset", Float) = 0
+ //endex
+
[HideInInspector] m_end_Marble("Marble", Float) = 0
//endex
diff --git a/features.cginc b/features.cginc
index 5938c60..778123b 100755
--- a/features.cginc
+++ b/features.cginc
@@ -11,6 +11,7 @@
//ifex _Marble_Enabled==0
#pragma shader_feature_local _MARBLE
+#pragma shader_feature_local _MARBLE_TIME
//endex
//ifex _Tessellation_Enabled==0
diff --git a/globals.cginc b/globals.cginc
index d926588..c90cebd 100755
--- a/globals.cginc
+++ b/globals.cginc
@@ -86,11 +86,23 @@ float _Bent_Normals_Strength;
#if defined(_MARBLE)
texture3D _Marble_Noise;
//texture2D _Marble_U_Ramp;
+texture2D _Marble_Post_Ramp;
float3 _Marble_Scale;
float _Marble_Octaves;
float _Marble_Strength;
+float _Marble_Lacunarity;
+float _Marble_Gain;
#endif // _MARBLE
+#if defined(_MARBLE_TIME)
+float _Marble_Speed;
+float3 _Marble_Direction;
+#endif // _MARBLE_TIME
+
+#if defined(_MARBLE_OFFSET)
+float3 _Marble_Offset;
+#endif // _MARBLE_OFFSET
+
#if defined(_TESSELLATION)
float _Tessellation_Factor;
float _Tessellation_Frustum_Culling_Bias;
diff --git a/pbr.cginc b/pbr.cginc
index f172a98..dcb94c8 100755
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -125,8 +125,36 @@ void propagateSmoothness(inout Pbr pbr) {
void apply_marble(float3 world_pos, inout float3 albedo) {
#if defined(_MARBLE)
float3 uvw = world_pos * _Marble_Scale;
- float3 noise = _Marble_Noise.Sample(aniso4_trilinear_repeat_s, uvw).rgb;
- albedo = noise.x;
+
+ float3 noises[10];
+
+ float3 noise = 0;
+ float gain = 1;
+
+ float3 offset = 0;
+#if defined(_MARBLE_TIME)
+ offset += _Time[0] * _Marble_Speed * _Marble_Direction;
+#endif
+#if defined(_MARBLE_OFFSET)
+ offset += _Marble_Offset;
+#endif
+
+ uvw += offset;
+
+ for (uint ii = 0; ii < _Marble_Octaves; ++ii) {
+ noises[ii] = _Marble_Noise.Sample(aniso4_trilinear_repeat_s, uvw + noise * _Marble_Strength).rgb * gain;
+ noise += noises[ii];
+
+ uvw *= _Marble_Lacunarity;
+ gain *= _Marble_Gain;
+ }
+
+ // In general, the series 1 + r + ... + r^{n-1} = (1 - r^n) / (1 - r)
+ noise *= (1 - _Marble_Gain) / (1 - pow(_Marble_Gain, _Marble_Octaves));
+
+ noise = _Marble_Post_Ramp.Sample(linear_clamp_s, float2(noise.x, 0));
+
+ albedo = noise;
#endif
}