diff options
| author | yum <yum.food.vr@gmail.com> | 2026-03-30 15:15:36 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-03-30 15:15:36 -0700 |
| commit | 4d02ae6522509f534beb5b4889bef47f58d19583 (patch) | |
| tree | c752f5eacc63ffc2de65af11a1d18e59070e03ac | |
| parent | f009c086daa3f93de4a3d9ede315e6bc5f0e8d9b (diff) | |
Glitter: parameterize neighbor loop iterations
| -rwxr-xr-x | 3ner.shader | 2 | ||||
| -rw-r--r-- | glitter.cginc | 26 | ||||
| -rwxr-xr-x | globals.cginc | 2 | ||||
| -rwxr-xr-x | lighting.cginc | 4 |
4 files changed, 25 insertions, 9 deletions
diff --git a/3ner.shader b/3ner.shader index 5cc10be..66dfee8 100755 --- a/3ner.shader +++ b/3ner.shader @@ -661,6 +661,8 @@ Shader "yum_food/3ner" [ThryToggle(_GLITTER)] _Glitter_Enabled("Enable", Float) = 0 _Glitter_Amount("Amount", Range(0, 1)) = 0.5 _Glitter_Roughness("Roughness", Range(0.001, 0.1)) = 0.01 + [IntRange] _Glitter_Spatial_Neighbor_Count("Spatial Neighbor Count", Range(1, 4)) = 4 + [IntRange] _Glitter_Angular_Neighbor_Count("Angular Neighbor Count", Range(1, 4)) = 4 _Glitter_Tint("Tint", Color) = (1, 1, 1, 1) [HideInInspector] m_end_Glitter("Glitter", Float) = 0 //endex diff --git a/glitter.cginc b/glitter.cginc index 022b176..0588446 100644 --- a/glitter.cginc +++ b/glitter.cginc @@ -169,9 +169,14 @@ float3 disk_to_ndf_ggx(float2 v_disk, float alpha) { return float3(alpha * hemi.xy, hemi.z) / denom; } +float2 GlitterNeighborOffset(float index) { + return float2(frac(index * 0.5) * 2.0, floor(index * 0.5)) - 0.5; +} + // Algorithm 1 from Kemppinen et. al. float D_Kemppinen(float3 h, float alpha, float glint_alpha, float2 uv, - float2x2 uv_J, float N, float filter_size, out float3 micro_normal) { + float2x2 uv_J, float N, float filter_size, float angular_neighbor_count, + float spatial_neighbor_count, out float3 micro_normal) { float res = sqrt(N); float2 x_s = uv; float3 x_a_and_d = ndf_to_disk_ggx(h, alpha); @@ -199,13 +204,13 @@ float D_Kemppinen(float3 h, float alpha, float glint_alpha, float2 uv, float2 base_i_a = clamp(round(x_a * res_a), 1, res_a-1); [loop] - for (uint j_a = 0; j_a < 4; ++j_a) { - float2 i_a = base_i_a + float2(int2(j_a, j_a/2)%2)-.5; + for (float j_a = 0.0; j_a < angular_neighbor_count; j_a += 1.0) { + float2 i_a = base_i_a + GlitterNeighborOffset(j_a); float2 base_i_s = round(x_s * res_s); [loop] - for (uint j_s = 0; j_s < 4; ++j_s) { - float2 i_s = base_i_s + float2(int2(j_s, j_s/2)%2)-.5; + for (float j_s = 0.0; j_s < spatial_neighbor_count; j_s += 1.0) { + float2 i_s = base_i_s + GlitterNeighborOffset(j_s); float2 g_s = (i_s + Rand2D(i_s, i_a, l, 1u) - .5) / res_s; float2 g_a = (i_a + Rand2D(i_s, i_a, l, 2u) - .5) / res_a; @@ -241,6 +246,7 @@ struct LightGlitter { // Glitter data getter to be run from lighting code. LightGlitter GetGlitterLighting( float glitter_amount, float glitter_roughness, + float glitter_spatial_neighbor_count, float glitter_angular_neighbor_count, float2 uv, float3x3 tbn, float roughness, float3 normal, float3 V, float3 direct_H, float3 indirect_dir) { LightGlitter g; @@ -252,19 +258,23 @@ LightGlitter GetGlitterLighting( float3 direct_H_tangent = mul(direct_H, transpose(tbn)); float3 direct_micro_normal; // unused g.direct_D = D_Kemppinen(direct_H_tangent, roughness, glitter_roughness, - uv, uv_J, N, glitter_filter_size, direct_micro_normal); + uv, uv_J, N, glitter_filter_size, + glitter_angular_neighbor_count, glitter_spatial_neighbor_count, + direct_micro_normal); // Indirect float3 indirect_H = normalize(V + indirect_dir); float3 indirect_H_tangent = mul(indirect_H, transpose(tbn)); float3 indirect_micro_normal; // unused, but required by D_Kemppinen g.indirect_D = D_Kemppinen(indirect_H_tangent, roughness, glitter_roughness, - uv, uv_J, N, glitter_filter_size, indirect_micro_normal); + uv, uv_J, N, glitter_filter_size, + glitter_angular_neighbor_count, glitter_spatial_neighbor_count, + indirect_micro_normal); g.indirect_NoL = max(1e-4, dot(normal, indirect_dir)); g.indirect_LoH = max(1e-4, dot(indirect_dir, indirect_H)); return g; } -#endif +#endif // _GLITTER #endif // __GLITTER_INC diff --git a/globals.cginc b/globals.cginc index 88fb663..d3d8958 100755 --- a/globals.cginc +++ b/globals.cginc @@ -156,6 +156,8 @@ int _Details_UV_Channel; float _Glitter_Amount; float _Glitter_Roughness; float3 _Glitter_Tint; +float _Glitter_Spatial_Neighbor_Count; +float _Glitter_Angular_Neighbor_Count; #endif // _GLITTER #if defined(_UV_SCROLL) diff --git a/lighting.cginc b/lighting.cginc index b6d3f8e..072e8d8 100755 --- a/lighting.cginc +++ b/lighting.cginc @@ -269,7 +269,9 @@ void GetLighting(v2f i, Pbr pbr, out LightData data) { data.indirect.L01g, data.indirect.L01b, data.indirect.dir); - data.glitter = GetGlitterLighting(_Glitter_Amount, _Glitter_Roughness, + data.glitter = GetGlitterLighting( + _Glitter_Amount, _Glitter_Roughness, + _Glitter_Spatial_Neighbor_Count, _Glitter_Angular_Neighbor_Count, i.uv01.xy, pbr.tbn, pbr.roughness, pbr.normal, data.common.V, data.direct.H, glitter_indirect_dir); #endif |
