summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-08-19 16:04:47 -0700
committeryum <yum.food.vr@gmail.com>2024-08-19 16:04:47 -0700
commitbf9496af5f27d548224689a123e97546fc2053b7 (patch)
tree0110d78690ff0bafd0e1b698c5287badde74a398
parentcc4347e460a445f60e6e5b03d055c65b5cdfdbd6 (diff)
Add HSV, global emissions multiplier
Also bugfix overlays 1-3 ifdefs.
-rw-r--r--Editor/tooner.cs52
-rw-r--r--feature_macros.cginc1
-rw-r--r--globals.cginc10
-rw-r--r--pbr.cginc36
-rw-r--r--tooner.shader8
-rw-r--r--tooner_lighting.cginc43
-rw-r--r--tooner_outline_pass.cginc9
7 files changed, 135 insertions, 24 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index 53bdc46..4e96e61 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -400,6 +400,9 @@ public class ToonerGUI : ShaderGUI {
bc,
bct);
SetKeyword("_EMISSION", bc.textureValue);
+
+ bc = FindProperty("_Global_Emission_Factor");
+ editor.FloatProperty(bc, "Global emissions multiplier");
}
enum MatcapMode {
@@ -721,6 +724,48 @@ public class ToonerGUI : ShaderGUI {
}
}
+ void DoHSV() {
+ MaterialProperty bc;
+
+ bc = FindProperty("_HSV_Enabled");
+ bool enabled = bc.floatValue > 1E-6;
+ EditorGUI.BeginChangeCheck();
+ enabled = EditorGUILayout.Toggle("Enable", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+
+ SetKeyword("_HSV", enabled);
+
+ if (enabled) {
+ bc = FindProperty("_HSV_Mask");
+ editor.TexturePropertySingleLine(
+ MakeLabel(bc, "Mask"),
+ bc);
+
+ if (bc.textureValue) {
+ bc = FindProperty("_HSV_Mask_Invert");
+ enabled = bc.floatValue > 1E-6;
+ EditorGUI.BeginChangeCheck();
+ enabled = EditorGUILayout.Toggle("Invert", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+ }
+
+ bc = FindProperty("_HSV_Hue_Shift");
+ editor.RangeProperty(
+ bc,
+ "Hue shift");
+ bc = FindProperty("_HSV_Sat_Shift");
+ editor.RangeProperty(
+ bc,
+ "Saturation shift");
+ bc = FindProperty("_HSV_Val_Shift");
+ editor.RangeProperty(
+ bc,
+ "Value shift");
+ }
+ }
+
void DoClones() {
MaterialProperty bc;
@@ -1608,11 +1653,16 @@ public class ToonerGUI : ShaderGUI {
DoTessellation();
EditorGUI.indentLevel -= 1;
- GUILayout.Label("Hue shift", EditorStyles.boldLabel);
+ GUILayout.Label("Hue shift (OKLAB)", EditorStyles.boldLabel);
EditorGUI.indentLevel += 1;
DoOKLAB();
EditorGUI.indentLevel -= 1;
+ GUILayout.Label("Hue shift (HSV)", EditorStyles.boldLabel);
+ EditorGUI.indentLevel += 1;
+ DoHSV();
+ EditorGUI.indentLevel -= 1;
+
GUILayout.Label("Clones", EditorStyles.boldLabel);
EditorGUI.indentLevel += 1;
DoClones();
diff --git a/feature_macros.cginc b/feature_macros.cginc
index 432a29d..29d3859 100644
--- a/feature_macros.cginc
+++ b/feature_macros.cginc
@@ -48,6 +48,7 @@
#pragma shader_feature_local _ _RIM_LIGHTING3_SAMPLER_REPEAT
#pragma shader_feature_local _ _RIM_LIGHTING3_SAMPLER_CLAMP
#pragma shader_feature_local _ _OKLAB
+#pragma shader_feature_local _ _HSV
#pragma shader_feature_local _ _CLONES
#pragma shader_feature_local _ _PBR_OVERLAY0
#pragma shader_feature_local _ _PBR_OVERLAY0_BASECOLOR_MAP
diff --git a/globals.cginc b/globals.cginc
index e294bd6..d77b5e9 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -249,6 +249,7 @@ float _Decal3_UV_Select;
texture2D _EmissionTex;
float _EmissionStrength;
#endif
+float _Global_Emission_Factor;
#if defined(_AMBIENT_OCCLUSION)
texture2D _Ambient_Occlusion;
@@ -439,6 +440,15 @@ float _OKLAB_Chroma_Shift;
float _OKLAB_Hue_Shift;
#endif
+#if defined(_HSV)
+float _HSV_Enabled;
+texture2D _HSV_Mask;
+float _HSV_Mask_Invert;
+float _HSV_Hue_Shift;
+float _HSV_Sat_Shift;
+float _HSV_Val_Shift;
+#endif
+
#if defined(_CLONES)
float _Clones_Enabled;
float _Clones_Count;
diff --git a/pbr.cginc b/pbr.cginc
index 5ba9cae..371e82f 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -187,15 +187,26 @@ float4 getLitColor(
albedo.rgb = DiffuseAndSpecularFromMetallic(
albedo, metallic, specular_tint, one_minus_reflectivity);
- float3 view_dir = normalize(_WorldSpaceCameraPos - worldPos);
-
+ const float3 view_dir = normalize(_WorldSpaceCameraPos - worldPos);
uint normals_mode = round(_Mesh_Normals_Mode);
- float3 flat_normal = normalize(
- (1.0 / _Flatten_Mesh_Normals_Str) * normal +
- _Flatten_Mesh_Normals_Str * view_dir);
- float3 spherical_normal = normalize(UnityObjectToWorldNormal(normalize(i.objPos)));
- normal = lerp(normal, flat_normal, normals_mode == 0);
- normal = lerp(normal, spherical_normal, normals_mode == 1);
+ switch (normals_mode) {
+ case 0:
+ {
+ float3 flat_normal = normalize(
+ (1.0 / _Flatten_Mesh_Normals_Str) * normal +
+ _Flatten_Mesh_Normals_Str * view_dir);
+ normal = flat_normal;
+ }
+ break;
+ case 1:
+ {
+ float3 spherical_normal = normalize(UnityObjectToWorldNormal(normalize(i.objPos)));
+ normal = spherical_normal;
+ }
+ break;
+ default:
+ break;
+ }
UnityIndirect indirect_light;
vertexLightColor *= _Vertex_Lighting_Factor;
@@ -207,12 +218,11 @@ float4 getLitColor(
UnityLight direct_light;
direct_light.dir = getDirectLightDirection(i);
direct_light.ndotl = DotClamped(normal, direct_light.dir);
- float shadow_attenuation = getShadowAttenuation(i);
#define POI_LIGHTING
#if defined(POI_LIGHTING)
- direct_light.color = getPoiLightingDirect(normal) * shadow_attenuation;
+ direct_light.color = getPoiLightingDirect(normal);
#else
- direct_light.color = getDirectLightColor() * shadow_attenuation;
+ direct_light.color = getDirectLightColor();
#endif
if (normals_mode == 0) {
@@ -289,6 +299,10 @@ float4 getLitColor(
float3 direct_color = direct_light.color;
direct_light.color *= ao;
+ // Apply shadows
+ float shadow_attenuation = getShadowAttenuation(i);
+ direct_light.color *= shadow_attenuation;
+
float2 screenUVs = 0;
float4 screenPos = 0;
#if 1
diff --git a/tooner.shader b/tooner.shader
index 9ab319b..01f50d1 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -146,6 +146,7 @@ Shader "yum_food/tooner"
[NoScaleOffset] _EmissionTex("Emission map", 2D) = "black" {}
_EmissionStrength("Emission strength", Range(0, 2)) = 0
+ _Global_Emission_Factor("Global emission factor", Float) = 1
[NoScaleOffset] _Tex_NormalStr("Normal texture strength", Range(0, 10)) = 1
@@ -323,6 +324,13 @@ Shader "yum_food/tooner"
_OKLAB_Chroma_Shift("OKLAB chroma shift", Range(-0.37, 0.37)) = 0.0
_OKLAB_Hue_Shift("OKLAB hue shift", Range(0, 6.283185307)) = 0.0
+ _HSV_Enabled("Enable HSV", Float) = 0.0
+ _HSV_Mask("Mask", 2D) = "white" {}
+ _HSV_Mask_Invert("Mask invert", Float) = 0.0
+ _HSV_Hue_Shift("HSV hue shift", Range(0.0, 1.0)) = 0.0
+ _HSV_Sat_Shift("HSV saturation shift", Range(-1.0, 1.0)) = 0.0
+ _HSV_Val_Shift("HSV value shift", Range(-1.0, 1.0)) = 0.0
+
_Clones_Enabled("Enable clones", Float) = 0.0
_Clones_Count("Clones count", Range(0,16)) = 0.0
_Clones_Dist_Cutoff("Clones distance cutoff", Float) = -1.0
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index 0166104..1f840b7 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -885,10 +885,10 @@ void mixOverlayAlbedoRoughnessMetallic(inout float4 albedo,
#if defined(_PBR_OVERLAY1)
#if defined(_PBR_OVERLAY1_MIX_ALPHA_BLEND)
albedo.rgb = lerp(albedo.rgb, ov.ov1_albedo.rgb, a1);
-#if defined(_PBR_OVERLAY0_ROUGHNESS)
+#if defined(_PBR_OVERLAY1_ROUGHNESS)
roughness = lerp(roughness, ov.ov1_roughness, a1);
#endif
-#if defined(_PBR_OVERLAY0_METALLIC)
+#if defined(_PBR_OVERLAY1_METALLIC)
metallic = lerp(metallic, ov.ov1_metallic, a1);
#endif
albedo.a = max(albedo.a, a1);
@@ -904,10 +904,10 @@ void mixOverlayAlbedoRoughnessMetallic(inout float4 albedo,
#if defined(_PBR_OVERLAY2)
#if defined(_PBR_OVERLAY2_MIX_ALPHA_BLEND)
albedo.rgb = lerp(albedo.rgb, ov.ov2_albedo.rgb, ov.ov2_albedo.a);
-#if defined(_PBR_OVERLAY0_ROUGHNESS)
+#if defined(_PBR_OVERLAY2_ROUGHNESS)
roughness = lerp(roughness, ov.ov2_roughness, a2);
#endif
-#if defined(_PBR_OVERLAY0_METALLIC)
+#if defined(_PBR_OVERLAY2_METALLIC)
metallic = lerp(metallic, ov.ov2_metallic, a2);
#endif
albedo.a = max(albedo.a, a2);
@@ -923,10 +923,10 @@ void mixOverlayAlbedoRoughnessMetallic(inout float4 albedo,
#if defined(_PBR_OVERLAY3)
#if defined(_PBR_OVERLAY3_MIX_ALPHA_BLEND)
albedo.rgb = lerp(albedo.rgb, ov.ov3_albedo.rgb, a3);
-#if defined(_PBR_OVERLAY0_ROUGHNESS)
+#if defined(_PBR_OVERLAY3_ROUGHNESS)
roughness = lerp(roughness, ov.ov3_roughness, a3);
#endif
-#if defined(_PBR_OVERLAY0_METALLIC)
+#if defined(_PBR_OVERLAY3_METALLIC)
metallic = lerp(metallic, ov.ov3_metallic, a3);
#endif
albedo.a = max(albedo.a, a3);
@@ -1650,6 +1650,27 @@ float4 effect(inout v2f i)
}
#endif
+#if defined(_HSV)
+ // Do hue shift in perceptually uniform color space so it doesn't look like
+ // shit.
+ float hsv_mask = _HSV_Mask.SampleGrad(linear_repeat_s, i.uv0, iddx, iddy);
+ if (_HSV_Mask_Invert) {
+ hsv_mask = 1 - hsv_mask;
+ }
+ if (hsv_mask > 0.01 &&
+ (_HSV_Hue_Shift > 1E-6 ||
+ abs(_HSV_Sat_Shift) > 1E-6 ||
+ abs(_HSV_Val_Shift) > 1E-6)) {
+ float3 c = albedo.rgb;
+ c = RGBtoHSV(c);
+ c += float3(_HSV_Hue_Shift, _HSV_Sat_Shift, _HSV_Val_Shift);
+ c.x = glsl_mod(c.x, 1.0);
+ c.yz = saturate(c.yz);
+ c = HSVtoRGB(c);
+ albedo.rgb = c;
+ }
+#endif
+
#if defined(_AMBIENT_OCCLUSION)
float ao = _Ambient_Occlusion.SampleGrad(linear_repeat_s, i.uv0, iddx, iddy);
ao = 1 - (1 - ao) * _Ambient_Occlusion_Strength;
@@ -1679,16 +1700,16 @@ float4 effect(inout v2f i)
albedo.a = 1;
#endif
- return float4(lit.rgb + _Gimmick_Flat_Color_Emission, albedo.a);
+ return float4(lit.rgb + _Gimmick_Flat_Color_Emission * _Global_Emission_Factor, albedo.a);
}
#endif
float4 result = lit;
#if defined(_MATCAP0) || defined(_MATCAP1) || defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1)
- result.rgb += matcap_emission;
+ result.rgb += matcap_emission * _Global_Emission_Factor;
#endif
#if defined(_DECAL0) || defined(_DECAL1) || defined(_DECAL2) || defined(_DECAL3)
- result.rgb += decal_emission;
+ result.rgb += decal_emission * _Global_Emission_Factor;
#endif
#if defined(_GLITTER)
float glitter_mask = _Glitter_Mask.SampleGrad(linear_repeat_s, i.uv0, iddx, iddy);
@@ -1699,7 +1720,7 @@ float4 effect(inout v2f i)
#endif
#if defined(_EMISSION)
float emission = _EmissionTex.SampleGrad(linear_repeat_s, i.uv0, iddx, iddy);
- result.rgb += albedo.rgb * emission * _EmissionStrength;
+ result.rgb += albedo.rgb * emission * _EmissionStrength * _Global_Emission_Factor;
#endif
#if defined(_EXPLODE) && defined(_AUDIOLINK)
if (AudioLinkIsAvailable() && _Explode_Phase > 1E-6) {
@@ -1713,7 +1734,7 @@ float4 effect(inout v2f i)
#if defined(_RENDERING_TRANSPARENT) || defined(_RENDERING_TRANSCLIPPING)
result.rgb *= result.a;
#endif
- result.rgb += getOverlayEmission(ov, i, iddx, iddy);
+ result.rgb += getOverlayEmission(ov, i, iddx, iddy) * _Global_Emission_Factor;
return result;
}
diff --git a/tooner_outline_pass.cginc b/tooner_outline_pass.cginc
index abf4da4..0c22133 100644
--- a/tooner_outline_pass.cginc
+++ b/tooner_outline_pass.cginc
@@ -15,6 +15,13 @@
v2f vert(appdata v)
{
+ v2f o;
+
+ UNITY_INITIALIZE_OUTPUT(v2f, o);
+ UNITY_SETUP_INSTANCE_ID(v);
+ UNITY_TRANSFER_INSTANCE_ID(v, o);
+ UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
+
#if defined(_TROCHOID)
{
#define PI 3.14159265
@@ -58,12 +65,12 @@ v2f vert(appdata v)
}
#endif
- v2f o;
o.worldPos = mul(unity_ObjectToWorld, objPos);
o.objPos = objPos;
o.pos = UnityObjectToClipPos(objPos);
o.normal = UnityObjectToWorldNormal(v.normal);
o.uv0 = v.uv0.xy;
+ o.uv2 = v.uv2;
#if defined(LIGHTMAP_ON)
o.lmuv = v.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
#endif