summaryrefslogtreecommitdiffstats
path: root/pbr.cginc
diff options
context:
space:
mode:
Diffstat (limited to 'pbr.cginc')
-rwxr-xr-xpbr.cginc59
1 files changed, 11 insertions, 48 deletions
diff --git a/pbr.cginc b/pbr.cginc
index cc566b4..f6000b8 100755
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -126,9 +126,6 @@ void apply_marble(float3 world_pos, inout float3 albedo) {
#if defined(_MARBLE)
float3 uvw = world_pos * _Marble_Scale;
- float3 noise = 0;
- float gain = 1;
-
float3 offset = 0;
#if defined(_MARBLE_TIME)
offset += _Time[0] * _Marble_Speed * _Marble_Direction;
@@ -139,15 +136,8 @@ void apply_marble(float3 world_pos, inout float3 albedo) {
uvw += offset;
- for (uint ii = 0; ii < _Marble_Octaves; ++ii) {
- noise += _Marble_Noise.Sample(aniso4_trilinear_repeat_s, uvw + noise * _Marble_Strength).rgb * gain;
-
- 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));
+ float3 noise = domain_warp_3d_tex(_Marble_Noise, uvw, _Marble_Strength,
+ _Marble_Octaves, _Marble_Lacunarity, _Marble_Gain);
noise = _Marble_Post_Ramp.Sample(linear_clamp_s, float2(noise.x, 0));
@@ -155,47 +145,20 @@ void apply_marble(float3 world_pos, inout float3 albedo) {
#endif
}
-float3 kintsugi_hash33(float3 p) {
- p = frac(p * float3(0.1031, 0.1030, 0.0973));
- p += dot(p, p.yxz + 33.33);
- return frac((p.xxy + p.yxx) * p.zyx);
-}
-
-float kintsugi_voronoi_edge(float3 x) {
- float3 p = floor(x);
- float3 f = frac(x);
- float d1 = 8.0;
- float d2 = 8.0;
- float3 p1 = 0;
- float3 p2 = 0;
-
- for (int k = -1; k <= 1; k++) {
- for (int j = -1; j <= 1; j++) {
- for (int i = -1; i <= 1; i++) {
- float3 b = float3(i, j, k);
- float3 r = b + kintsugi_hash33(p + b) - f;
- float d = dot(r, r);
- if (d < d1) {
- d2 = d1;
- p2 = p1;
- d1 = d;
- p1 = r;
- } else if (d < d2) {
- d2 = d;
- p2 = r;
- }
- }
- }
- }
- return (d2 - d1) / (2.0 * max(0.0001, length(p2 - p1)));
-}
-
void apply_kintsugi(float3 world_pos, inout float3 albedo, inout float smoothness, inout float metallic) {
#if defined(_KINTSUGI)
float3 uvw = world_pos * _Kintsugi_Scale;
+#if defined(_KINTSUGI_DOMAIN_WARPING)
+ float3 warp = domain_warp_procedural(
+ world_pos * _Kintsugi_Domain_Warping_Scale,
+ _Kintsugi_Domain_Warping_Strength, _Kintsugi_Domain_Warping_Octaves,
+ _Kintsugi_Domain_Warping_Lacunarity, _Kintsugi_Domain_Warping_Gain);
+ uvw += warp;
+#endif
+
#if defined(_KINTSUGI_PROCEDURAL)
- float mask = kintsugi_voronoi_edge(uvw) + 0.5f;
+ float mask = voronoi_edge_distance(uvw) + 0.5f;
#else
float mask = _Kintsugi_Noise.Sample(aniso4_trilinear_repeat_s, uvw);
#endif