Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiliMilk committed May 29, 2022
2 parents b1c68c1 + 28bffc2 commit 28a311a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
23 changes: 14 additions & 9 deletions Assets/ChiliMilkToonShader/Editor/ToonShaderGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private struct Styles
public static readonly GUIContent OutlineWidth = new GUIContent("OutlineWidth");

//Rim
public static readonly GUIContent BlendRim = new GUIContent("BlendRim");
public static readonly GUIContent RimFlip = new GUIContent("RimFlip");
public static readonly GUIContent RimBlend = new GUIContent("RimBlend");
public static readonly GUIContent RimColor = new GUIContent("RimColor");
public static readonly GUIContent RimPow = new GUIContent("RimPow");
public static readonly GUIContent RimStep = new GUIContent("RimStep");
Expand Down Expand Up @@ -146,9 +147,10 @@ private struct MPropertyNames
public static readonly string UseSmoothNormal = "_UseSmoothNormal";
public static readonly string OutlineColor = "_OutlineColor";
public static readonly string OutlineWidth = "_OutlineWidth";

//Rim
public static readonly string BlendRim = "_BlendRim";
public static readonly string RimFlip = "_RimFlip";
public static readonly string RimBlend = "_RimBlend";
public static readonly string RimColor = "_RimColor";
public static readonly string RimStep = "_RimStep";
public static readonly string RimFeather = "_RimFeather";
Expand Down Expand Up @@ -274,9 +276,10 @@ public enum ShadowType
private MaterialProperty m_UseSmoothNormalProp;
private MaterialProperty m_OutlineColorProp;
private MaterialProperty m_OutlineWidthProp;

//Rim
private MaterialProperty m_BlendRimProp;
private MaterialProperty m_RimFlipProp;
private MaterialProperty m_RimBlendProp;
private MaterialProperty m_RimColorProp;
private MaterialProperty m_RimStepProp;
private MaterialProperty m_RimFeatherProp;
Expand Down Expand Up @@ -361,9 +364,10 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
m_UseSmoothNormalProp = FindProperty(MPropertyNames.UseSmoothNormal, properties, false);
m_OutlineColorProp = FindProperty(MPropertyNames.OutlineColor, properties, false);
m_OutlineWidthProp = FindProperty(MPropertyNames.OutlineWidth, properties, false);

//Rim
m_BlendRimProp = FindProperty(MPropertyNames.BlendRim, properties, false);
m_RimFlipProp = FindProperty(MPropertyNames.RimFlip, properties, false);
m_RimBlendProp = FindProperty(MPropertyNames.RimBlend, properties, false);
m_RimColorProp = FindProperty(MPropertyNames.RimColor, properties, false);
m_RimStepProp = FindProperty(MPropertyNames.RimStep, properties, false);
m_RimFeatherProp = FindProperty(MPropertyNames.RimFeather, properties, false);
Expand Down Expand Up @@ -912,15 +916,16 @@ private void DrawRimProperties(MaterialEditor materialEditor)
{
//Rim
materialEditor.ColorProperty(m_RimColorProp, Styles.RimColor.text);
materialEditor.ShaderProperty(m_RimFlipProp, Styles.RimFlip);
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel += 2;
var blendRim = EditorGUILayout.Slider(Styles.BlendRim, m_BlendRimProp.floatValue, 0f, 1f);
var rimBlend = EditorGUILayout.Slider(Styles.RimBlend, m_RimBlendProp.floatValue, 0f, 1f);
var rimStep = EditorGUILayout.Slider(Styles.RimStep, m_RimStepProp.floatValue, 0f, 1f);
var rimFeather = EditorGUILayout.Slider(Styles.RimFeather, m_RimFeatherProp.floatValue, 0f, 1f);
EditorGUI.indentLevel -= 2;
if (EditorGUI.EndChangeCheck())
{
m_BlendRimProp.floatValue = blendRim;
m_RimBlendProp.floatValue = rimBlend;
m_RimStepProp.floatValue = rimStep;
m_RimFeatherProp.floatValue = rimFeather;
}
Expand Down
7 changes: 5 additions & 2 deletions Assets/ChiliMilkToonShader/Include/ToonInput.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ half _SpecularShift;
half _SpecularShiftIntensity;
float4 _SpecularShiftMap_ST;

half _BlendRim;
half _RimBlend;
half3 _RimColor;
half _RimFlip;
half _RimStep;
half _RimFeather;

Expand Down Expand Up @@ -137,6 +138,7 @@ struct ToonData
half specularFeather;

half3 rimColor;
half rimFlip;
half rimStep;
half rimFeather;
half rimBlend;
Expand Down Expand Up @@ -333,6 +335,7 @@ inline void InitializeToonData(float2 uv, float2 normalizedScreenSpaceUV,float3
outToonData.rimColor = _RimColor;
outToonData.rimStep = _RimStep;
outToonData.rimFeather = _RimFeather;
outToonData.rimBlend = _BlendRim;
outToonData.rimBlend = _RimBlend;
outToonData.rimFlip = _RimFlip;
}
#endif
15 changes: 8 additions & 7 deletions Assets/ChiliMilkToonShader/Include/ToonLighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,14 @@ half3 RampRadianceToon(half3 normalWS, half3 lightDirectionWS, half lightAttenua
#endif
#endif

half3 RimLight(half3 rimColor, half3 normalWS, half3 viewDirectionWS, half rimStep, half rimFeather, half rimBlend, half radiance)
float3 RimLight(half3 rimColor, half3 normalWS, half3 viewDirectionWS, half rimStep, half rimFeather, half rimBlend, half rimFlip, half radiance)
{
half fresnel = (1.0 - saturate(dot(normalWS, viewDirectionWS)));
fresnel = DiffuseRadianceToon(fresnel, rimStep, rimFeather);
half3 color = rimColor * fresnel;
radiance = lerp(radiance, 1 - radiance, rimFlip);
color = lerp(color, color * radiance, rimBlend);

return color;
}

Expand All @@ -193,7 +194,7 @@ half3 MatCapLight(half3 normalWS, half3 viewDirection, half radiance)
}


half3 LightingToon(BRDFDataToon brdfData, SurfaceDataToon surfaceData, InputDataToon inputData, ToonData toonData, Light light)
half3 LightingToon(BRDFDataToon brdfData, SurfaceDataToon surfaceData, InputDataToon inputData, ToonData toonData, Light light, half isMainLight)
{
half lightAttenuation = light.distanceAttenuation * light.shadowAttenuation;
half3 color = half3(0.0h,0.0h,0.0h);
Expand All @@ -216,8 +217,8 @@ half3 LightingToon(BRDFDataToon brdfData, SurfaceDataToon surfaceData, InputData
color += specularColor + diffuseColor;
#endif
#endif
color += RimLight(toonData.rimColor, inputData.normalWS, inputData.viewDirectionWS, toonData.rimStep, toonData.rimFeather,toonData.rimBlend, radiance.x);
color += MatCapLight(inputData.normalWS, inputData.viewDirectionWS, radiance.x);
color += isMainLight * RimLight(toonData.rimColor, inputData.normalWS, inputData.viewDirectionWS, toonData.rimStep, toonData.rimFeather, toonData.rimBlend, toonData.rimFlip ,radiance.x);
color += isMainLight * MatCapLight(inputData.normalWS, inputData.viewDirectionWS, radiance.x);
return color * light.color;
}

Expand All @@ -241,7 +242,7 @@ half4 FragmentLitToon(InputDataToon inputData, SurfaceDataToon surfaceData, Toon
half3 color = GlobalIlluminationToon(brdfData, inputData.bakedGI, toonData.ssao, inputData.normalWS, inputData.viewDirectionWS);
if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
{
color += LightingToon(brdfData, surfaceData, inputData, toonData, mainLight);
color += LightingToon(brdfData, surfaceData, inputData, toonData, mainLight, 1);
}

#ifdef _ADDITIONAL_LIGHTS
Expand All @@ -251,7 +252,7 @@ half4 FragmentLitToon(InputDataToon inputData, SurfaceDataToon surfaceData, Toon
Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask);
if(IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
{
color += LightingToon(brdfData, surfaceData, inputData, toonData, light);
color += LightingToon(brdfData, surfaceData, inputData, toonData, light, 0);
}
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion Assets/ChiliMilkToonShader/Shader/Toon.shader
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
_DiffuseRampV("DiffuseRampV",Range(0.0,1))= 0.0

//Rim
_BlendRim("BlendRim",Range(0.0,1.0)) = 0.0
_RimBlend("RimBlend",Range(0.0,1.0)) = 0.0
[ToggleOff]_RimFlip("RimFlip", Float) = 0.0
_RimColor("RimColor",Color) = (0.0,0.0,0.0,0.0)
_RimStep("RimStep",Range(0.0,1.0)) = 0.5
_RimFeather("RimFeather",Range(0.0,1.0)) = 0.5
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scenes/Test.unity
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1182527277}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2.899, y: 0.531, z: -0.299}
m_LocalPosition: {x: 2.899, y: 0.531, z: -1.129}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down
18 changes: 14 additions & 4 deletions Assets/UnityChan/Material/ChiliMilk_Toon.mat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ Material:
m_Shader: {fileID: 4800000, guid: 1d6e561d2a2bdae46a0884077d1708ba, type: 3}
m_ValidKeywords:
- _ENVIRONMENTREFLECTIONS_OFF
m_InvalidKeywords: []
- _SPECULAR_SETUP
m_InvalidKeywords:
- _ALPHACLIP_OFF
- _CASTHAIRSHADOWMASK_OFF
- _ENABLEHAIRSPECULAR_OFF
- _ENABLEMATCAP_OFF
- _ENABLESTENCIL_OFF
- _INVERSECLIPMASK_OFF
- _RECEIVEHAIRSHADOWMASK_OFF
- _USESMOOTHNORMAL_OFF
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
Expand Down Expand Up @@ -107,7 +116,6 @@ Material:
m_Floats:
- _AlphaClip: 0
- _Blend: 0
- _BlendRim: 0.8
- _BumpScale: 1
- _CastHairShadowMask: 0
- _CastShadowForFace: 0
Expand Down Expand Up @@ -144,7 +152,9 @@ Material:
- _ReceiveShadowMaskForFace: 0
- _ReceiveShadows: 1
- _RenderQueue: 2000
- _RimBlend: 0.82
- _RimFeather: 0
- _RimFlip: 1
- _RimPow: 5.68
- _RimStep: 0.63
- _SSAOStrength: 1
Expand Down Expand Up @@ -172,7 +182,7 @@ Material:
- _Surface: 0
- _SurfaceType: 0
- _UseSmoothNormal: 0
- _WorkflowMode: 1
- _WorkflowMode: 0
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.7075472, g: 0.7075472, b: 0.7075472, a: 1}
Expand All @@ -182,7 +192,7 @@ Material:
- _LeftDirWS: {r: -1, g: 0, b: 0, a: 0}
- _MatCapColor: {r: 0, g: 0, b: 0, a: 0}
- _OutlineColor: {r: 0, g: 0, b: 0, a: 0}
- _RimColor: {r: 1, g: 0, b: 0, a: 1}
- _RimColor: {r: 1, g: 0.45660377, b: 0.45660377, a: 1}
- _Shadow1Color: {r: 0.5283019, g: 0.5283019, b: 0.5283019, a: 0.5}
- _Shadow2Color: {r: 0, g: 0, b: 0, a: 0}
- _SpecColor: {r: 1, g: 1, b: 1, a: 1}
Expand Down

0 comments on commit 28a311a

Please sign in to comment.