From f607646ad46ead5fc404f4313a901a13b2df466f Mon Sep 17 00:00:00 2001 From: yum Date: Sun, 15 Mar 2026 16:36:46 -0700 Subject: Finish marble rework --- pbr.cginc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'pbr.cginc') 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 } -- cgit v1.2.3