diff options
| -rwxr-xr-x | 3ner.shader | 17 | ||||
| -rwxr-xr-x | features.cginc | 6 | ||||
| -rwxr-xr-x | globals.cginc | 11 | ||||
| -rwxr-xr-x | pbr.cginc | 68 |
4 files changed, 96 insertions, 6 deletions
diff --git a/3ner.shader b/3ner.shader index c4e26f1..df3127a 100755 --- a/3ner.shader +++ b/3ner.shader @@ -1011,6 +1011,23 @@ Shader "yum_food/3ner" [HideInInspector] m_end_Marble("Marble", Float) = 0 //endex + //ifex _Kintsugi_Enabled==0 + [HideInInspector] m_start_Kintsugi("Kintsugi", Float) = 0 + [ThryToggle(_KINTSUGI)] _Kintsugi_Enabled("Enable", Float) = 0 + _Kintsugi_Noise("Noise", 3D) = "gray" {} + [ThryToggle(_KINTSUGI_PROCEDURAL)] _Kintsugi_Procedural("Procedural noise", Float) = 0 + [ThryToggle(_KINTSUGI_NOISE_INVERT)] _Kintsugi_Noise_Inverted("Invert noise", Float) = 0 + _Kintsugi_Scale("Scale", Vector) = (1, 1, 1, 0) + + _Kintsugi_Threshold("Threshold", Range(0, 1)) = 0.5 + _Kintsugi_Width("Width", Range(0, 1)) = 0.1 + + [HDR] _Kintsugi_Color("Color", Color) = (1, 1, 1, 1) + _Kintsugi_Smoothness("Smoothness", Range(0, 1)) = 0.5 + _Kintsugi_Metallic("Metallic", Range(0, 1)) = 0.5 + [HideInInspector] m_end_Kintsugi("Kintsugi", Float) = 0 + //endex + [HideInInspector] m_end_Gimmicks("Gimmicks", Float) = 0 //ifex _Tessellation_Enabled==0 diff --git a/features.cginc b/features.cginc index 778123b..f67a855 100755 --- a/features.cginc +++ b/features.cginc @@ -14,6 +14,12 @@ #pragma shader_feature_local _MARBLE_TIME //endex +//ifex _Kintsugi_Enabled==0 +#pragma shader_feature_local _KINTSUGI +#pragma shader_feature_local _KINTSUGI_PROCEDURAL +#pragma shader_feature_local _KINTSUGI_NOISE_INVERT +//endex + //ifex _Tessellation_Enabled==0 #pragma shader_feature_local _TESSELLATION #pragma shader_feature_local _TESSELLATION_HEIGHTMAP_WORLD_SPACE diff --git a/globals.cginc b/globals.cginc index c90cebd..7ad1c3f 100755 --- a/globals.cginc +++ b/globals.cginc @@ -85,7 +85,6 @@ float _Bent_Normals_Strength; #if defined(_MARBLE) texture3D _Marble_Noise; -//texture2D _Marble_U_Ramp; texture2D _Marble_Post_Ramp; float3 _Marble_Scale; float _Marble_Octaves; @@ -103,6 +102,16 @@ float3 _Marble_Direction; float3 _Marble_Offset; #endif // _MARBLE_OFFSET +#if defined(_KINTSUGI) +texture3D _Kintsugi_Noise; +float3 _Kintsugi_Scale; +float _Kintsugi_Threshold; +float _Kintsugi_Width; +float3 _Kintsugi_Color; +float _Kintsugi_Smoothness; +float _Kintsugi_Metallic; +#endif // _KINTSUGI + #if defined(_TESSELLATION) float _Tessellation_Factor; float _Tessellation_Frustum_Culling_Bias; @@ -126,8 +126,6 @@ void apply_marble(float3 world_pos, inout float3 albedo) { #if defined(_MARBLE) float3 uvw = world_pos * _Marble_Scale; - float3 noises[10]; - float3 noise = 0; float gain = 1; @@ -142,8 +140,7 @@ void apply_marble(float3 world_pos, inout float3 albedo) { 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]; + noise += _Marble_Noise.Sample(aniso4_trilinear_repeat_s, uvw + noise * _Marble_Strength).rgb * gain; uvw *= _Marble_Lacunarity; gain *= _Marble_Gain; @@ -158,6 +155,65 @@ 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_PROCEDURAL) + float mask = kintsugi_voronoi_edge(uvw) + 0.5f; +#else + float mask = _Kintsugi_Noise.Sample(aniso4_trilinear_repeat_s, uvw); +#endif + + float width = max(fwidth(mask) * 0.5f, _Kintsugi_Width); + float threshold = _Kintsugi_Threshold; + mask = smoothstep(threshold - width, threshold + width, mask); + +#if defined(_KINTSUGI_NOISE_INVERT) + mask = 1.0f - mask; +#endif // _KINTSUGI_NOISE_INVERT + + albedo = lerp(albedo, _Kintsugi_Color, mask); + smoothness = lerp(smoothness, _Kintsugi_Smoothness, mask); + metallic = lerp(metallic, _Kintsugi_Metallic, mask); +#endif // _KINTSUGI +} + Pbr getPbr(v2f i) { Pbr pbr = (Pbr) 0; @@ -183,7 +239,6 @@ Pbr getPbr(v2f i) { pbr.albedo = _MainTex.Sample(aniso4_trilinear_repeat_s, uv_parallax * _MainTex_ST.xy + _MainTex_ST.zw); pbr.albedo *= _Color; #endif - apply_marble(i.worldPos, pbr.albedo.xyz); float3 normal_tangent = UnpackNormal(_BumpMap.Sample(aniso4_trilinear_repeat_s, uv_parallax * _BumpMap_ST.xy)); normal_tangent.xy *= _BumpScale; @@ -201,6 +256,9 @@ Pbr getPbr(v2f i) { pbr.smoothness = metallic_gloss.a * _Glossiness; pbr.metallic = metallic_gloss.r * _Metallic; + apply_marble(i.worldPos, pbr.albedo.xyz); + apply_kintsugi(i.worldPos, pbr.albedo.xyz, pbr.smoothness, pbr.metallic); + applyDecals(i, pbr, normal_tangent); pbr.normal = normalize(mul(normal_tangent, pbr.tbn)); |
