diff options
| author | yum <yum.food.vr@gmail.com> | 2024-05-27 23:08:18 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-05-27 23:08:18 -0700 |
| commit | ad79981dfddd3f787011334490d137e0a9a0ffb8 (patch) | |
| tree | f73e287f5ab940f3c70f6768cb372efa27c853be | |
| parent | 47eb460bf49d4512f52eecffa5696eb761a08f83 (diff) | |
Add controls for shadow strength & mipmap selection
| -rw-r--r-- | Editor/tooner.cs | 99 | ||||
| -rw-r--r-- | globals.cginc | 2 | ||||
| -rw-r--r-- | pbr.cginc | 31 | ||||
| -rw-r--r-- | tooner.shader | 3 | ||||
| -rw-r--r-- | tooner_lighting.cginc | 4 |
5 files changed, 92 insertions, 47 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index d60e543..1da2bb9 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -198,36 +198,11 @@ public class ToonerGUI : ShaderGUI { } void DoCubemap() { - MaterialProperty bc = FindProperty("_Cubemap"); - editor.TexturePropertySingleLine( - MakeLabel(bc, "Cubemap"), - bc); - SetKeyword("_CUBEMAP", bc.textureValue); } void DoBrightness() { MaterialProperty bc; - bc = FindProperty("_Min_Brightness"); - editor.RangeProperty( - bc, - "Min brightness"); - - bc = FindProperty("_Max_Brightness"); - editor.RangeProperty( - bc, - "Max brightness"); - - bc = FindProperty("_Ambient_Occlusion"); - editor.TexturePropertySingleLine( - MakeLabel(bc, "Ambient occlusion"), - bc); - SetKeyword("_AMBIENT_OCCLUSION", bc.textureValue); - - if (bc.textureValue) { - bc = FindProperty("_Ambient_Occlusion_Strength"); - editor.RangeProperty(bc, "Ambient occlusion strength"); - } } void DoEmission() { @@ -813,26 +788,68 @@ public class ToonerGUI : ShaderGUI { } } - void DoLTCGI() { -#if LTCGI_INCLUDED - GUILayout.Label($"Available: yes"); + void DoLighting() { + MaterialProperty bc; + bc = FindProperty("_Min_Brightness"); + editor.RangeProperty( + bc, + "Min brightness"); + + bc = FindProperty("_Max_Brightness"); + editor.RangeProperty( + bc, + "Max brightness"); + + bc = FindProperty("_Ambient_Occlusion"); + editor.TexturePropertySingleLine( + MakeLabel(bc, "Ambient occlusion"), + bc); + SetKeyword("_AMBIENT_OCCLUSION", bc.textureValue); + + if (bc.textureValue) { + bc = FindProperty("_Ambient_Occlusion_Strength"); + editor.RangeProperty(bc, "Ambient occlusion strength"); + } + + bc = FindProperty("_Cubemap"); + editor.TexturePropertySingleLine( + MakeLabel(bc, "Cubemap"), + bc); + SetKeyword("_CUBEMAP", bc.textureValue); + + bc = FindProperty("_Shadow_Strength"); + editor.RangeProperty( + bc, + "Shadows strength"); + + bc = FindProperty("_Mip_Multiplier"); + editor.FloatProperty( + bc, + "Mipmap multiplier"); + bc.floatValue = (float) Math.Max(1E-6, bc.floatValue); - MaterialProperty bc = FindProperty("_LTCGI_Enabled"); +#if LTCGI_INCLUDED + bc = FindProperty("_LTCGI_Enabled"); bool enabled = bc.floatValue > 1E-6; EditorGUI.BeginChangeCheck(); - enabled = EditorGUILayout.Toggle("Enable", enabled); + enabled = EditorGUILayout.Toggle("Enable LTCGI", enabled); EditorGUI.EndChangeCheck(); bc.floatValue = enabled ? 1.0f : 0.0f; SetKeyword("_LTCGI", enabled); - bc = FindProperty("_LTCGI_SpecularColor"); - editor.ColorProperty(bc, "Specular color (RGB)"); + if (enabled) { + EditorGUI.indentLevel += 1; + bc = FindProperty("_LTCGI_SpecularColor"); + editor.ColorProperty(bc, "Specular color (RGB)"); + + bc = FindProperty("_LTCGI_DiffuseColor"); + editor.ColorProperty(bc, "Diffuse color (RGB)"); + EditorGUI.indentLevel -= 1; + } +#endif + } - bc = FindProperty("_LTCGI_DiffuseColor"); - editor.ColorProperty(bc, "Diffuse color (RGB)"); -#else - GUILayout.Label($"Available: no"); -#endif // LTCGI_INCLUDED + void DoLTCGI() { } void DoMain() { @@ -848,8 +865,7 @@ public class ToonerGUI : ShaderGUI { GUILayout.Label("Lighting", EditorStyles.boldLabel); EditorGUI.indentLevel += 1; - DoCubemap(); - DoBrightness(); + DoLighting(); EditorGUI.indentLevel -= 1; GUILayout.Label("Emission", EditorStyles.boldLabel); @@ -909,11 +925,6 @@ public class ToonerGUI : ShaderGUI { EditorGUI.indentLevel += 1; DoRendering(); EditorGUI.indentLevel -= 1; - - GUILayout.Label("LTCGI", EditorStyles.boldLabel); - EditorGUI.indentLevel += 1; - DoLTCGI(); - EditorGUI.indentLevel -= 1; } } diff --git a/globals.cginc b/globals.cginc index 5156284..9b6534a 100644 --- a/globals.cginc +++ b/globals.cginc @@ -18,6 +18,8 @@ float _Mesh_Normals_Mode; float _Flatten_Mesh_Normals_Str; float _Confabulate_Normals; +float _Shadow_Strength; +float _Mip_Multiplier; #if defined(_BASECOLOR_MAP) texture2D _MainTex; @@ -12,7 +12,37 @@ UNITY_DECLARE_TEXCUBE(_Cubemap); UnityLight CreateDirectLight(float3 normal, float ao, v2f i) { +#if 1 + // This whole block is yoinked from AutoLight.cginc. I needed a way to + // control shadow strength so I had to duplicate the code. +#if defined(DIRECTIONAL_COOKIE) + DECLARE_LIGHT_COORD(i, i.worldPos); + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = tex2D(_LightTexture0, lightCoord).w; +#elif defined(POINT_COOKIE) + DECLARE_LIGHT_COORD(i, i.worldPos); + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = tex2D(_LightTextureB0, dot(lightCoord, lightCoord).rr).r * + texCUBE(_LightTexture0, lightCoord).w; +#elif defined(DIRECTIONAL) + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = 1; +#elif defined(SPOT) + DECLARE_LIGHT_COORD(i, i.worldPos); + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = (lightCoord.z > 0) * UnitySpotCookie(lightCoord) * UnitySpotAttenuate(lightCoord.xyz); +#elif defined(POINT) + unityShadowCoord3 lightCoord = mul(unity_WorldToLight, unityShadowCoord4(i.worldPos, 1)).xyz; + float shadow = UNITY_SHADOW_ATTENUATION(i, i.worldPos); + float attenuation = tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).r; +#else + float shadow = 1; + float attenuation = 1; +#endif + attenuation *= lerp(1, shadow, _Shadow_Strength); +#else UNITY_LIGHT_ATTENUATION(attenuation, i, i.worldPos); +#endif UnityLight light; light.color = _LightColor0.rgb * attenuation * ao; @@ -22,7 +52,6 @@ UnityLight CreateDirectLight(float3 normal, float ao, v2f i) light.dir = _WorldSpaceLightPos0; #endif - if (round(_Confabulate_Normals)) { light.dir = normal; } diff --git a/tooner.shader b/tooner.shader index fafd215..4c29975 100644 --- a/tooner.shader +++ b/tooner.shader @@ -177,6 +177,9 @@ Shader "yum_food/tooner" _Tess_Dist_Cutoff("Tessellation distance cutoff", Float) = -1.0 _Cutout_Mode("Cutout rendering mode", Float) = 0.0 + + _Shadow_Strength("Shadows strength", Range(0, 1)) = 1.0 + _Mip_Multiplier("Mipmap multiplier", Float) = 1.0 } SubShader { diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 40e67bc..7f7ceb8 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -574,8 +574,8 @@ void applyOverlayNormal(inout float3 raw_normal, PbrOverlay ov, v2f i, float idd float4 effect(inout v2f i) { - float iddx = ddx(i.uv.x); - float iddy = ddx(i.uv.y); + float iddx = ddx(i.uv.x) * _Mip_Multiplier; + float iddy = ddx(i.uv.y) * _Mip_Multiplier; const float3 view_dir = normalize(_WorldSpaceCameraPos - i.worldPos); #if defined(_UVSCROLL) |
