Skip to content

Commit

Permalink
Fixed lighter areas being washed out
Browse files Browse the repository at this point in the history
  • Loading branch information
morerokk committed Nov 19, 2019
1 parent 3622c20 commit 46a8fb9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Shader "NoeNoe/NoeNoe Toon Shader/Advanced/NoeNoe Toon Vertex Offset" {
_Intensity ("Intensity", Range(0, 10)) = 0.8
_Saturation ("Saturation", Range(0, 1)) = 0.65
_Exposure ("Exposure", Range(0, 1)) = 0.6
_ExposureContrast ("Exposure Toon Ramp Contrast", Range(0, 2)) = 1
[Enum(Toon,0,PBR,1,Legacy Toon,2)] _LightingMode ("Lighting Mode", Float) = 0
_NormalMap ("Normal Map", 2D) = "bump" {}
[Enum(None,0,Metallic,1,Specular,2)] _MetallicMode("Metallic Mode", Float) = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Shader "NoeNoe/NoeNoe Toon Shader/Advanced/NoeNoe Toon Eye Tracking" {
_Intensity ("Intensity", Range(0, 10)) = 0.8
_Saturation ("Saturation", Range(0, 1)) = 0.65
_Exposure ("Exposure", Range(0, 1)) = 0.6
_ExposureContrast ("Exposure Toon Ramp Contrast", Range(0, 2)) = 1
[Enum(Toon,0,PBR,1,Legacy Toon,2)] _LightingMode ("Lighting Mode", Float) = 0
_NormalMap ("Normal Map", 2D) = "bump" {}
[Toggle(_ALPHATEST_ON)] _Mode ("Cutout", Float) = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Shader "NoeNoe/NoeNoe Toon Shader/NoeNoe Toon Outline" {
_Intensity ("Intensity", Range(0, 10)) = 0.8
_Saturation ("Saturation", Range(0, 1)) = 0.65
_Exposure ("Exposure", Range(0, 1)) = 0.6
_ExposureContrast ("Exposure Toon Ramp Contrast", Range(0, 2)) = 1
[Enum(Toon,0,PBR,1,Legacy Toon,2)] _LightingMode ("Lighting Mode", Float) = 0
_NormalMap ("Normal Map", 2D) = "bump" {}
[Enum(None,0,Metallic,1,Specular,2)] _MetallicMode("Metallic Mode", Float) = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Shader "NoeNoe/NoeNoe Toon Shader/NoeNoe Toon Ramp Masked" {
_Intensity ("Default Intensity", Range(0, 10)) = 0.8
_Saturation ("Default Saturation", Range(0, 1)) = 0.65
_Exposure ("Exposure", Range(0, 1)) = 0.6
_ExposureContrast ("Exposure Toon Ramp Contrast", Range(0, 2)) = 1
[Enum(Toon,0,PBR,1,Legacy Toon,2)] _LightingMode ("Lighting Mode", Float) = 0
_NormalMap ("Normal Map", 2D) = "bump" {}
[Toggle(_ALPHATEST_ON)] _Mode ("Cutout", Float) = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Shader "NoeNoe/NoeNoe Toon Shader/NoeNoe Toon Transparent" {
_Intensity ("Intensity", Range(0, 10)) = 0.8
_Saturation ("Saturation", Range(0, 1)) = 0.65
_Exposure ("Exposure", Range(0, 1)) = 0.6
_ExposureContrast ("Exposure Toon Ramp Contrast", Range(0, 2)) = 1
[Enum(Toon,0,PBR,1,Legacy Toon,2)] _LightingMode ("Lighting Mode", Float) = 0
_Opacity ("Opacity", Range(0, 1)) = 1
_NormalMap ("Normal Map", 2D) = "bump" {}
Expand Down
1 change: 1 addition & 0 deletions NoeNoe Shaders/NoeNoe Toon Shader/NoeNoe Toon.shader
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Shader "NoeNoe/NoeNoe Toon Shader/NoeNoe Toon" {
_Intensity ("Intensity", Range(0, 10)) = 0.8
_Saturation ("Saturation", Range(0, 1)) = 0.65
_Exposure ("Exposure", Range(0, 1)) = 0.6
_ExposureContrast ("Exposure Toon Ramp Contrast", Range(0, 2)) = 1
[Enum(Toon,0,PBR,1,Legacy Toon,2)] _LightingMode ("Lighting Mode", Float) = 0
_NormalMap ("Normal Map", 2D) = "bump" {}
[Toggle(_ALPHATEST_ON)] _Mode ("Cutout", Float) = 0
Expand Down
21 changes: 20 additions & 1 deletion NoeNoe Shaders/NoeNoe Toon Shader/NoeNoeToonEdits.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ float _WorldLightIntensity;
float _ReceiveShadows;
float3 _EmissionColor;
float _Exposure;
float _ExposureContrast;

#ifdef NOENOETOON_RAMP_MASKING
uniform sampler2D _RampMaskTex;
Expand Down Expand Up @@ -148,6 +149,11 @@ float3 CubemapRotator( float3 Dir , float AngX , float AngY , float AngZ )
return Val;
}

float3 AdjustContrastCurve(float3 color, float contrast) {
return pow(abs(color * 2 - 1), 1 / max(contrast, 0.0001)) * sign(color - 0.5) + 0.5;
}


struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
Expand Down Expand Up @@ -478,7 +484,20 @@ float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
#endif

float3 StaticToonLighting = node_9498.rgb;
float3 finalColor = ((IntensityVar*FlatLighting*Diffuse) > 0.5 ? (1.0-(1.0-2.0*((IntensityVar*FlatLighting*Diffuse)-0.5))*(1.0-lerp(float3(node_424,node_424,node_424),StaticToonLighting,ToonContrast_var))) : (2.0*(IntensityVar*FlatLighting*Diffuse)*lerp(float3(node_424,node_424,node_424),StaticToonLighting,ToonContrast_var)));

#if defined(_LIGHTING_LEGACY_ON)
float3 finalColor = ((IntensityVar*FlatLighting*Diffuse) > 0.5 ? (1.0-(1.0-2.0*((IntensityVar*FlatLighting*Diffuse)-0.5))*(1.0-lerp(float3(node_424,node_424,node_424),StaticToonLighting,ToonContrast_var))) : (2.0*(IntensityVar*FlatLighting*Diffuse)*lerp(float3(node_424,node_424,node_424),StaticToonLighting,ToonContrast_var)));
#else
// Dim the toon ramp effect as the area gets brighter
float toonContrastModifier = saturate(Luminance(IntensityVar*saturate(FlatLighting)*Diffuse));
toonContrastModifier = (1 - toonContrastModifier) * _ExposureContrast;
toonContrastModifier = smoothstep(0.5, 1, toonContrastModifier);

ToonContrast_var *= toonContrastModifier;

//float3 finalColor = ((IntensityVar*FlatLighting*Diffuse) < 0.5 ? (2.0*(IntensityVar*FlatLighting*Diffuse)*lerp(float3(node_424,node_424,node_424),StaticToonLighting,ToonContrast_var)) : (1.0-(1.0-2.0*((IntensityVar*FlatLighting*Diffuse)-0.5))*(1.0-lerp(float3(node_424,node_424,node_424),StaticToonLighting,ToonContrast_var))));
float3 finalColor = (2.0*(IntensityVar*FlatLighting*Diffuse)*lerp(float3(node_424,node_424,node_424),StaticToonLighting,ToonContrast_var));
#endif

#if defined(_LIGHTING_LEGACY_ON)
finalColor = saturate(finalColor);
Expand Down
3 changes: 3 additions & 0 deletions NoeNoe Shaders/Scripts/Editor/NoeNoeToonEditorGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class NoeNoeToonEditorGUI : ShaderGUI
private MaterialProperty intensity = null;
private MaterialProperty saturation = null;
private MaterialProperty exposure = null;
private MaterialProperty exposureToonRampContrast = null;
private MaterialProperty lightMode = null;

//Metallic
Expand Down Expand Up @@ -272,6 +273,7 @@ private void DrawToonLighting()
if(lightMode.floatValue != 2)
{
editor.ShaderProperty(exposure, new GUIContent("Exposure", "Controls the contribution of directional and realtime lights."));
editor.ShaderProperty(exposureToonRampContrast, new GUIContent("Exposure Toon Ramp Contrast", "As this value increases, the intensity of toon ramps on lighter surfaces increases."));
}

if(HasRampMasking())
Expand Down Expand Up @@ -638,6 +640,7 @@ private void FindProperties(MaterialProperty[] props)
intensity = FindProperty("_Intensity", props);
saturation = FindProperty("_Saturation", props);
exposure = FindProperty("_Exposure", props);
exposureToonRampContrast = FindProperty("_ExposureContrast", props);
lightMode = FindProperty("_LightingMode", props);

//Metallic
Expand Down

0 comments on commit 46a8fb9

Please sign in to comment.