diff options
Diffstat (limited to 'pbr.cginc')
| -rwxr-xr-x | pbr.cginc | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -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 } |
