summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-07-18 15:23:14 -0700
committeryum <yum.food.vr@gmail.com>2024-07-18 15:23:14 -0700
commit82b36c1c14013e82e15ca48dc766eb7aa4198e63 (patch)
treedb54ba20a8ac0d795de992dfe41e9777a5795f71
parenta95481afa226d76d671b13515ee2abc59359b87a (diff)
Add individual lighting multipliers
... for direct, indirect x {specular,diffuse}
-rw-r--r--Editor/tooner.cs36
-rw-r--r--MochieStandardBRDF.cginc2
-rw-r--r--globals.cginc3
-rw-r--r--pbr.cginc15
-rw-r--r--tooner.shader4
-rw-r--r--tooner_lighting.cginc22
-rw-r--r--tooner_outline_pass.cginc19
7 files changed, 55 insertions, 46 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index a3af66c..78b9a51 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -1087,11 +1087,6 @@ public class ToonerGUI : ShaderGUI {
}
MaterialProperty bc;
- bc = FindProperty("_Render_Queue_Offset");
- editor.IntegerProperty(
- bc,
- "Render queue offset");
- int queue_offset = bc.intValue;
EditorGUI.BeginChangeCheck();
mode = (RenderingMode) EditorGUILayout.EnumPopup(
@@ -1099,9 +1094,16 @@ public class ToonerGUI : ShaderGUI {
BlendMode src_blend = BlendMode.One;
BlendMode dst_blend = BlendMode.Zero;
bool zwrite = false;
+ EditorGUI.EndChangeCheck();
+ RecordAction("Rendering mode");
- if (EditorGUI.EndChangeCheck()) {
- RecordAction("Rendering mode");
+ bc = FindProperty("_Render_Queue_Offset");
+ editor.IntegerProperty(
+ bc,
+ "Render queue offset");
+ int queue_offset = bc.intValue;
+
+ {
SetKeyword("_RENDERING_CUTOUT", mode == RenderingMode.Cutout);
SetKeyword("_RENDERING_FADE", mode == RenderingMode.Fade);
SetKeyword("_RENDERING_TRANSPARENT", mode == RenderingMode.Transparent);
@@ -1146,6 +1148,7 @@ public class ToonerGUI : ShaderGUI {
zwrite = true;
break;
}
+
foreach (Material m in editor.targets) {
m.renderQueue = ((int) queue) + queue_offset;
m.SetOverrideTag("RenderType", render_type);
@@ -1216,6 +1219,25 @@ public class ToonerGUI : ShaderGUI {
bc,
"Lighting multiplier");
+ {
+ EditorGUI.indentLevel += 1;
+ bc = FindProperty("_Direct_Lighting_Factor");
+ editor.RangeProperty(
+ bc,
+ "Direct multiplier");
+
+ bc = FindProperty("_Indirect_Specular_Lighting_Factor");
+ editor.RangeProperty(
+ bc,
+ "Indirect specular multiplier");
+
+ bc = FindProperty("_Indirect_Diffuse_Lighting_Factor");
+ editor.RangeProperty(
+ bc,
+ "Indirect diffuse multiplier");
+ EditorGUI.indentLevel -= 1;
+ }
+
bc = FindProperty("_Reflection_Probe_Saturation");
editor.RangeProperty(
bc,
diff --git a/MochieStandardBRDF.cginc b/MochieStandardBRDF.cginc
index 515798e..795bbee 100644
--- a/MochieStandardBRDF.cginc
+++ b/MochieStandardBRDF.cginc
@@ -54,7 +54,7 @@ float GSAARoughness(float3 normal, float roughness){
half4 BRDF1_Mochie_PBS (
half3 diffColor, half3 specColor, half oneMinusReflectivity, half smoothness,
- half3 normal, half3 mesh_normal, half3 viewDir, half3 worldPos, half2 screenUVs, half4 screenPos,
+ half3 normal, half3 viewDir, half3 worldPos, half2 screenUVs, half4 screenPos,
half metallic, half thickness, half3 ssColor, half atten, float2 lightmapUV, float3 vertexColor,
UnityLight light, UnityIndirect gi)
{
diff --git a/globals.cginc b/globals.cginc
index 7191b0f..b2d3eec 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -13,6 +13,9 @@ float _Tex_NormalStr;
float _NormalStr;
float _Lighting_Factor;
+float _Direct_Lighting_Factor;
+float _Indirect_Specular_Lighting_Factor;
+float _Indirect_Diffuse_Lighting_Factor;
float _Reflection_Probe_Saturation;
float _Min_Brightness;
float _Max_Brightness;
diff --git a/pbr.cginc b/pbr.cginc
index 4d70bc6..7c9d8ab 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -39,7 +39,6 @@ UNITY_DECLARE_TEXCUBE(_Cubemap);
UnityLight CreateDirectLight(float3 normal, v2f i, out float attenuation)
{
-#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)
@@ -67,9 +66,6 @@ UnityLight CreateDirectLight(float3 normal, v2f i, out float attenuation)
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;
@@ -222,9 +218,9 @@ float4 getLitColor(
}
#endif
- direct_light.color *= _Lighting_Factor;
- indirect_light.specular *= _Lighting_Factor;
- indirect_light.diffuse *= _Lighting_Factor;
+ direct_light.color *= _Lighting_Factor * _Direct_Lighting_Factor;
+ indirect_light.specular *= _Lighting_Factor * _Indirect_Specular_Lighting_Factor;
+ indirect_light.diffuse *= _Lighting_Factor * _Indirect_Diffuse_Lighting_Factor;
if (_Reflection_Probe_Saturation < 1.0) {
indirect_light.specular = RGBtoHSV(indirect_light.specular);
@@ -236,9 +232,7 @@ float4 getLitColor(
}
direct_light.color = clamp(direct_light.color, _Min_Brightness, _Max_Brightness);
- // Diffuse is set low as a hack. Most maps rely on skybox lighting and set
- // diffuse way too high.
- indirect_light.diffuse = clamp(indirect_light.diffuse, _Min_Brightness, _Max_Brightness * 0.5);
+ indirect_light.diffuse = clamp(indirect_light.diffuse, _Min_Brightness, _Max_Brightness);
indirect_light.specular = clamp(indirect_light.specular, _Min_Brightness, _Max_Brightness);
// Apply AO
@@ -255,7 +249,6 @@ float4 getLitColor(
one_minus_reflectivity,
smoothness,
normal,
- i.normal,
view_dir,
i.worldPos,
screenUVs,
diff --git a/tooner.shader b/tooner.shader
index 46d33e3..d68feeb 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -103,6 +103,9 @@ Shader "yum_food/tooner"
_Cubemap("Cubemap", Cube) = "" {}
_Lighting_Factor("Lighting factor", Range(0, 5)) = 1
+ _Direct_Lighting_Factor("Direct lighting factor", Range(0, 5)) = 1
+ _Indirect_Specular_Lighting_Factor("Indirect specular lighting factor", Range(0, 5)) = 1
+ _Indirect_Diffuse_Lighting_Factor("Indirect diffuse lighting factor", Range(0, 5)) = 1
_Reflection_Probe_Saturation("Reflection probe saturation", Range(0, 1)) = 1
_Min_Brightness("Min brightness", Range(0, 1)) = 0
_Max_Brightness("Max brightness", Range(0, 1.5)) = 1
@@ -307,7 +310,6 @@ Shader "yum_food/tooner"
Tags {
"VRCFallback"="ToonCutout"
}
-
Pass {
Tags {
"RenderType"="Opaque"
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index e11f0dc..ec3e22b 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -112,19 +112,17 @@ v2f vert(appdata v)
#if !defined(_SCROLL) && defined(_GIMMICK_SHEAR_LOCATION)
if (_Gimmick_Shear_Location_Enable_Dynamic) {
float3 p = v.vertex.xyz;
+
+ float r = 0.0;
+ float3 sc = lerp(
+ _Gimmick_Shear_Location_Strength.xyz,
+ 1,
+ abs(p) < r);
+
float3x3 shear_matrix = float3x3(
- _Gimmick_Shear_Location_Strength.x, 0, 0,
- 0, _Gimmick_Shear_Location_Strength.y, 0,
- 0, 0, _Gimmick_Shear_Location_Strength.z);
-#if 0
- float3x3 rot_fix, rot_fixi;
- float4x4 ts_fix, ts_fixi;
- getMeshRendererMatrices(/*invert=*/false, rot_fix, ts_fix);
- getMeshRendererMatrices(/*invert=*/true, rot_fixi, ts_fixi);
- if (_Gimmick_Shear_Location_Mesh_Renderer_Fix) {
- p = mul(ts_fixi, float4(p, 1)).xyz;
- }
-#endif
+ sc.x, 0, 0,
+ 0, sc.y, 0,
+ 0, 0, sc.z);
p = mul(shear_matrix, p);
v.vertex.xyz = p;
}
diff --git a/tooner_outline_pass.cginc b/tooner_outline_pass.cginc
index ebc717a..40e725f 100644
--- a/tooner_outline_pass.cginc
+++ b/tooner_outline_pass.cginc
@@ -62,15 +62,10 @@ v2f vert(appdata v)
}
#endif
- float4 worldPos = mul(unity_ObjectToWorld, objPos);
- float3 worldNormal = UnityObjectToWorldNormal(v.normal);
- float4 clipPos = UnityObjectToClipPos(objPos);
- float3 clipNormal = mul((float3x3) UNITY_MATRIX_MVP, v.normal);
-
v2f o;
- o.worldPos = worldPos;
+ o.worldPos = mul(unity_ObjectToWorld, objPos);
o.objPos = objPos;
- o.pos = clipPos;
+ o.pos = UnityObjectToClipPos(objPos);
o.normal = UnityObjectToWorldNormal(v.normal);
o.uv = v.uv0.xy;
#if defined(LIGHTMAP_ON)
@@ -162,10 +157,6 @@ v2f domain(
DOMAIN_INTERP(normal);
//DOMAIN_INTERP(tangent);
- #if defined(VERTEXLIGHT_ON)
- DOMAIN_INTERP(vertexLightColor);
- #endif
-
float4 vertex =
patch[0].pos * baryc.x +
patch[1].pos * baryc.y +
@@ -363,13 +354,13 @@ fixed4 frag (v2f i) : SV_Target
}
#endif
- //float3 flat_normal = normalize(UnpackNormal(float4(128, 128, 255, 255)/255));
- float3 flat_normal = normalize(_WorldSpaceCameraPos - i.worldPos);
float4 vertex_light_color = 0;
float ao = 1;
float4 result = getLitColor(
vertex_light_color,
- albedo, i.worldPos, flat_normal, 0, 0, i.uv, ao, i);
+ albedo, i.worldPos, -i.normal,
+ /*metallic=*/0, /*smoothness=*/0,
+ i.uv, ao, i);
result += albedo * _Outline_Emission_Strength;