diff options
| author | yum <yum.food.vr@gmail.com> | 2025-01-20 22:25:00 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-01-20 22:25:00 -0800 |
| commit | e2911359e5acf79beb5c8359145669b96a931ab0 (patch) | |
| tree | bd8bdcb9cd7e3f61f565a68d8d3804c9dd3f7e76 | |
| parent | b679eb398edb5f6ea0ba04860c02f7107a49dd58 (diff) | |
Add vector based ndotl mask to glitter
Useful for environmental modeling.
| -rw-r--r-- | Editor/tooner.cs | 24 | ||||
| -rw-r--r-- | globals.cginc | 4 | ||||
| -rw-r--r-- | tooner.shader | 4 | ||||
| -rw-r--r-- | tooner_lighting.cginc | 24 |
4 files changed, 52 insertions, 4 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index f694e53..d0411e4 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -1381,6 +1381,30 @@ public class ToonerGUI : ShaderGUI { RangeProperty( bc, "UV select"); + + bc = FindProperty("_Glitter_Vector_Mask_Enabled"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Vector mask", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + + if (enabled) { + EditorGUI.indentLevel += 1; + + bc = FindProperty("_Glitter_Vector_Mask_Vector"); + VectorProperty(bc, "Vector"); + bc = FindProperty("_Glitter_Vector_Mask_Power"); + FloatProperty(bc, "Power"); + bc = FindProperty("_Glitter_Vector_Mask_Invert"); + bool inverted = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + inverted = Toggle("Invert", inverted); + EditorGUI.EndChangeCheck(); + bc.floatValue = inverted ? 1.0f : 0.0f; + + EditorGUI.indentLevel -= 1; + } } EditorGUI.indentLevel -= 1; show_ui.RemoveAt(show_ui.Count - 1); diff --git a/globals.cginc b/globals.cginc index 2986138..9af8300 100644 --- a/globals.cginc +++ b/globals.cginc @@ -409,6 +409,10 @@ float _Glitter_Brightness_Lit; float _Glitter_Angle; float _Glitter_Power; float _Glitter_UV_Select; +float _Glitter_Vector_Mask_Enabled; +float3 _Glitter_Vector_Mask_Vector; +float _Glitter_Vector_Mask_Power; +float _Glitter_Vector_Mask_Invert; #endif #if defined(_EXPLODE) diff --git a/tooner.shader b/tooner.shader index 5adbcc6..e6502a8 100644 --- a/tooner.shader +++ b/tooner.shader @@ -438,6 +438,10 @@ Shader "yum_food/tooner" _Glitter_Angle("Glitter angle", Range(0, 90)) = 90 _Glitter_Power("Glitter power", Float) = 30 _Glitter_UV_Select("Glitter UV channel", Range(0, 7)) = 0 + _Glitter_Vector_Mask_Enabled("Glitter vector mask enabled", Float) = 0 + _Glitter_Vector_Mask_Vector("Glitter vector mask vector", Vector) = (1, 0, 0) + _Glitter_Vector_Mask_Power("Glitter vector mask power", Float) = 1 + _Glitter_Vector_Mask_Invert("Glitter vector mask invert", Float) = 0 _Gimmick_Letter_Grid_Enable_Static("Enable letter grid (static)", Float) = 0 _Gimmick_Letter_Grid_Texture("Letter grid texture", 2D) = "black" {} diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 821cb0e..a0a5777 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -454,10 +454,10 @@ void geom(triangle v2f tri_in[3], struct RorschachPBR { float4 albedo; }; -float rorschach_map_sdf(float3 p, float2 e, float3 period, float center_randomization) +float rorschach_map_sdf(float3 p, float2 e, float3 period, float center_randomization, float speed) { float r = _Rorschach_Radius * min(period.x, min(period.y, period.z)); - float st = sin(_Time[1] * _Rorschach_Speed * e.y * e.y + e.x * 3.14159265 * 2); + float st = sin(_Time[1] * speed * e.y * e.y + e.x * 3.14159265 * 2); r *= st; float3 o = float3( (e.x - 0.5) * period.x, @@ -472,6 +472,7 @@ float rorschach_map_dr( float3 period, float3 count, float center_randomization, + float speed, out float3 which ) { @@ -490,7 +491,7 @@ float rorschach_map_dr( float2 e = float2( rand3(rid / 100.0), rand3(rid / 100.0 + 1)); - float cur_d = rorschach_map_sdf(r, e, period, center_randomization); + float cur_d = rorschach_map_sdf(r, e, period, center_randomization, speed); which_tmp = cur_d < d ? rid : which; d = min(d, cur_d); } @@ -507,6 +508,7 @@ struct RorschachParams { float quantization; float alpha_cutoff; float center_randomization; + float speed; }; RorschachPBR get_rorschach(float2 uv, RorschachParams p) @@ -520,7 +522,7 @@ RorschachPBR get_rorschach(float2 uv, RorschachParams p) float3 which; float3 period = float3(1 / (p.count_x+1), 1 / (p.count_y+1), 1); float3 count = float3(p.count_x, p.count_y, 1); - float d = rorschach_map_dr(ro, period, count, p.center_randomization, which); + float d = rorschach_map_dr(ro, period, count, p.center_randomization, p.speed, which); d *= max(p.count_x + 1, p.count_y + 1); @@ -557,6 +559,7 @@ float get_glitter(float2 uv, float3 worldPos, float3 centerCamPos, p.quantization = 1; p.alpha_cutoff = 0.5; p.center_randomization = 1; + p.speed = speed; RorschachPBR result = get_rorschach(uv, p); float glitter = result.albedo.r; @@ -566,6 +569,18 @@ float get_glitter(float2 uv, float3 worldPos, float3 centerCamPos, glitter *= saturate(pow(ndotl / cutoff, power)); } + if (_Glitter_Vector_Mask_Enabled) { + float3 mask_vector = _Glitter_Vector_Mask_Vector; + float power = _Glitter_Vector_Mask_Power; + float invert = _Glitter_Vector_Mask_Invert; + float vector_mask = dot(normal, normalize(mask_vector)); + // Wrap ndotl + vector_mask = (vector_mask + 1) / 2; + vector_mask *= vector_mask; + vector_mask = max(vector_mask, 0); + vector_mask = invert ? 1 - vector_mask : vector_mask; + glitter *= pow(vector_mask, power); + } return glitter; @@ -1077,6 +1092,7 @@ float4 effect(inout v2f i, out float depth) p.quantization = _Rorschach_Quantization; p.alpha_cutoff = _Rorschach_Alpha_Cutoff; p.center_randomization = _Rorschach_Center_Randomization; + p.speed = _Rorschach_Speed; rorschach_albedo = get_rorschach(i.uv0, p).albedo; albedo.rgb = rorschach_albedo.rgb * rorschach_albedo.a + albedo.rgb * (1 - rorschach_albedo.a); albedo.a = saturate(rorschach_albedo.a + albedo.a * (1 - rorschach_albedo.a)); |
