Skip to content

Commit

Permalink
Merge pull request #2 from CascadianWorks/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
CascadianVR authored Feb 1, 2023
2 parents f345d6a + 29e0953 commit 95e9163
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 136 deletions.
355 changes: 263 additions & 92 deletions CasToonGUI.cs

Large diffs are not rendered by default.

45 changes: 27 additions & 18 deletions CasToonOpaque.shader
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Shader".Cascadian/CasToonOpaque"
_MainColor ("Main Color", Color) = (1,1,1,1)
[Normal] [NoScale] _NormalMap("Normal Map", 2D) = "bump" {}
_NormalStrength("Normal Strength", Range(0,2)) = 1
[Normal] _DetailNormalMap("Detail Normal Map", 2D) = "bump" {}
_DetailNormalStrength("Detail Normal Strength", Range(0,2)) = 1

_ShadowRamp("Shadow Ramp", 2D) = "white" {}
_ShadowColor("Shadow Color", Color) = (0.5,0.5,0.5,1)
Expand Down Expand Up @@ -51,34 +53,33 @@ Shader".Cascadian/CasToonOpaque"
_EmisTex("Emission Map", 2D) = "white" {}
_EmisColor("Emission Color", Color) = (1,1,1,1)
_EmisPower("Emission Power", Float) = 1

_UnlitIntensity("Unlit Intensity", Range(0,1)) = 0.1
_NormFlatten("Normal Flatten", Range(0,1)) = 0.5
_BakedColorContribution("Baked Color Contribution", Range(0,1)) = 1.0

// Emission Scroll
_EmisScrollSpeed("Emission Scroll Frequency", Float) = 1
_EmisScrollFrequency("Emission Scroll Frequency", Float) = 5
_EmisScrollMinBrightness("Emission Scroll Min Brightness", Float) = 0
_EmisScrollMaxBrightness("Emission Scroll Max Brightness", Float) = 1
_EmisScrollSpace("Emission Scroll Transform Space", Float) = 0
// Audio Link
_AudioLink ("AudioLink Texture", 2D) = "black" {}
_Bass ("Bass", Range(0,1)) = 0
_LowMid ("LowMid", Range(0,1)) = 0
_HighMid ("HighMid", Range(0,1)) = 0
_Treble ("Treble", Range(0,1)) = 0
_minAudioBrightness ("Minimum Brightness", Range(0,1)) = 0.5
_audioStrength ("Audio Strength", Range(0,5)) = 1

_UnlitIntensity("Unlit Intensity", Range(0,1)) = 0.1
_NormFlatten("Normal Flatten", Range(0,1)) = 0.5
_BakedColorContribution("Baked Color Contribution", Range(0,1)) = 1.0

// Utilities
// Utilities
_HideMeshMap("Hide Mesh Map", 2D) = "white" {}
[Enum(OFF,0,FRONT,1,BACK,2)] _CullingMode("Culling Mode", int) = 2

_OrificeData("OrificeData", 2D) = "white" {}
_EntryOpenDuration("Entry Trigger Duration", Range( 0 , 1)) = 0.1
_Shape1Depth("Shape 1 Trigger Depth", Range( 0 , 5)) = 0.1
_Shape1Duration("Shape 1 Trigger Duration", Range( 0 , 1)) = 0.1
_Shape2Depth("Shape 2 Trigger Depth", Range( 0 , 5)) = 0.2
_Shape2Duration("Shape 2 Trigger Duration", Range( 0 , 1)) = 0.1
_Shape3Depth("Shape 3 Trigger Depth", Range( 0 , 5)) = 0.3
_Shape3Duration("Shape 3 Trigger Duration", Range( 0 , 1)) = 0.1
_BlendshapePower("Blend Shape Power", Range(0,5)) = 1
_BlendshapeBadScaleFix("Blend Shape Bad Scale Fix", Range(1,100)) = 1
[IntRange] _StencilRef ("Stencil Reference Value", Range(0, 255)) = 0
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilFunction("Stencil Compare Function", Float) = 8
[Enum(UnityEngine.Rendering.StencilOp)] _StencilOp("Stencil Operation", Float) = 0

// Toggle Groups
_rimtog("toggle rimlight", Float) = 0
_mattog("toggle matcap", Float) = 0
_spectog("toggle specular", Float) = 0
Expand All @@ -87,17 +88,25 @@ Shader".Cascadian/CasToonOpaque"
_emistog("toggle emissison", Float) = 0
_emistogscroll("toggle emissison", Float) = 0
_audioLinktog("toggle AudioLink", Float) = 0
_orificetog("toggle Orifice", Float) = 0
}
SubShader
{
Stencil
{
Ref [_StencilRef]
Comp [_StencilFunction]
Pass [_StencilOp]
Fail [_StencilOp]
ZFail [_StencilOp]
}

Pass // Main
{
Tags { "Queue"="Geometry" "RenderType"="Opaque"
"LightMode" = "ForwardBase" "VRCFallback"="Toon"}
LOD 100
Cull [_CullingMode]


CGPROGRAM
#pragma vertex vert
Expand Down
35 changes: 27 additions & 8 deletions CasToonTransparent.shader
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
{
_MainTex ("Color Map", 2D) = "white" {}
_MainColor ("Main Color", Color) = (1,1,1,1)
_Transparency("Transparency", Range(0,1)) = 1
[Normal] [NoScale] _NormalMap("Normal Map", 2D) = "bump" {}
_NormalStrength("Normal Strength", Range(0,2)) = 1
_Transparency("Transparency", Range(0,1)) = 1
[Normal] _DetailNormalMap("Detail Normal Map", 2D) = "bump" {}
_DetailNormalStrength("Detail Normal Strength", Range(0,2)) = 1

_ShadowRamp("Shadow Ramp", 2D) = "white" {}
_ShadowColor("Shadow Color", Color) = (0.5,0.5,0.5,1)
Expand Down Expand Up @@ -50,21 +52,30 @@
_EmisTex("Emission Map", 2D) = "white" {}
_EmisColor("Emission Color", Color) = (1,1,1,1)
_EmisPower("Emission Power", Float) = 1

_UnlitIntensity("Unlit Intensity", Range(0,1)) = 0.1
_NormFlatten("Normal Flatten", Range(0,1)) = 0.5
_BakedColorContribution("Baked Color Contribution", Range(0,1)) = 1.0

// Emission Scroll
_EmisScrollSpeed("Emission Scroll Frequency", Float) = 1
_EmisScrollFrequency("Emission Scroll Frequency", Float) = 1
_EmisScrollMinBrightness("Emission Scroll Min Brightness", Float) = 0
_EmisScrollMaxBrightness("Emission Scroll Max Brightness", Float) = 1
_EmisScrollSpace("Emission Scroll Transform Space", Float) = 0
// Audio Link
_AudioLink ("AudioLink Texture", 2D) = "black" {}
_Bass ("Bass", Range(0,1)) = 0
_LowMid ("LowMid", Range(0,1)) = 0
_HighMid ("HighMid", Range(0,1)) = 0
_Treble ("Treble", Range(0,1)) = 0
_minAudioBrightness ("Minimum Brightness", Range(0,1)) = 0.5
_audioStrength ("Audio Strength", Range(0,5)) = 1

_UnlitIntensity("Unlit Intensity", Range(0,1)) = 0.1
_NormFlatten("Normal Flatten", Range(0,1)) = 0.5
_BakedColorContribution("Baked Color Contribution", Range(0,1)) = 1.0

_HideMeshMap("Hide Mesh Map", 2D) = "white" {}
_HideMeshMap("Hide Mesh Map", 2D) = "white" {}
[Enum(OFF,0,FRONT,1,BACK,2)] _CullingMode("Culling Mode", int) = 2
[IntRange] _StencilRef ("Stencil Reference Value", Range(0, 255)) = 0
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilFunction("Stencil Compare Function", Float) = 8
[Enum(UnityEngine.Rendering.StencilOp)] _StencilOp("Stencil Operation", Float) = 0

_rimtog("toggle rimlight", Float) = 0
_mattog("toggle matcap", Float) = 0
Expand All @@ -86,8 +97,16 @@
BlendOp Add, Max
Blend SrcAlpha OneMinusSrcAlpha, One One

Stencil
{
Ref [_StencilRef]
Comp [_StencilFunction]
Pass [_StencilOp]
Fail [_StencilOp]
ZFail [_StencilOp]
}

LOD 100
LOD 100
Cull [_CullingMode]

Pass
Expand Down
Binary file removed CasToonV0.4.2.unitypackage
Binary file not shown.
Binary file added CasToonV0.4.3.unitypackage
Binary file not shown.
2 changes: 1 addition & 1 deletion GradientEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void OnGUI()

GUILayout.FlexibleSpace();

if (GUILayout.Button("Convert to asset", GUILayout.Height(50)))
if (GUILayout.Button("Save Shadow Ramp", GUILayout.Height(50)))
{
ConvertGradient();
CasToonGUIV2.SetShadowGradient(filenameWithExtension);
Expand Down
56 changes: 39 additions & 17 deletions castoon.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ struct v2f
float3 normal : TEXCOORD1;
float3 wPos : TEXCOORD2;
float3 tbn[3] : TEXCOORD3; //4&5
float3 oPos : TEXCOORD6;
};

// Main Options
sampler2D _MainTex;
float4 _MainTex_ST;
float3 _MainColor;
float _Transparency;
sampler2D _NormalMap;
float _NormalStrength;
float _Transparency;
sampler2D _DetailNormalMap;
float4 _DetailNormalMap_ST;
float _DetailNormalStrength;

// Shadows
sampler2D _ShadowRamp;
Expand Down Expand Up @@ -74,6 +78,19 @@ sampler2D _SpecMaskMap;
sampler2D _EmisTex;
float3 _EmisColor;
float _EmisPower;
// Emission Scroll
float _EmisScrollSpeed;
float _EmisScrollFrequency;
float _EmisScrollMinBrightness;
float _EmisScrollMaxBrightness;
float _EmisScrollSpace;
// Audio Link
float _Bass;
float _LowMid;
float _HighMid;
float _Treble;
float _minAudioBrightness;
float _audioStrength;

// Lighting
float _UnlitIntensity;
Expand All @@ -83,26 +100,20 @@ float _BakedColorContribution;
// Utilities
sampler2D _HideMeshMap;

// Audio Link
float _Bass;
float _LowMid;
float _HighMid;
float _Treble;
float _minAudioBrightness;
float _audioStrength;

// UI folder disables
float _rimtog;
float _mattog;
float _spectog;
float _metaltog;
float _emistog;
float _emistogscroll;
float _audioLinktog;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.oPos = v.vertex;
if (tex2Dlod(_HideMeshMap, v.uv).x < 0.5)
o.vertex.w = 0.0 / 0.0;
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
Expand Down Expand Up @@ -162,6 +173,11 @@ fixed4 frag (v2f i) : SV_Target

float3 norm = UnpackScaleNormal(tex2D(_NormalMap, i.uv), _NormalStrength);
float3 worldNormal = (i.tbn[0] * norm.r + i.tbn[1] * norm.g + i.tbn[2]* norm.b);

float3 detailNorm = UnpackScaleNormal(tex2D(_DetailNormalMap, i.uv * _DetailNormalMap_ST.xy + _DetailNormalMap_ST.zw), _DetailNormalStrength);
float3 detailWorldNormal = (i.tbn[0] * detailNorm.r + i.tbn[1] * detailNorm.g + i.tbn[2]* detailNorm.b);

worldNormal = BlendNormals(worldNormal, detailWorldNormal);

float3 R = reflect(-L, worldNormal);
float3 VRef = normalize(reflect(-worldViewDir, worldNormal));
Expand Down Expand Up @@ -250,7 +266,6 @@ fixed4 frag (v2f i) : SV_Target
spec *= tex2D(_SpecMaskMap, i.uv).xyz;
mainOut = lerp(mainOut + (spec * _SpeccColor.xyz), mainOut, 1 - _SpeccColor.w);
}


//Lighting Options
float3 bakedLight = saturate(ShadeSHPerPixel(L.xyz,_LightColor0, i.vertex.xyz ));
Expand All @@ -260,27 +275,34 @@ fixed4 frag (v2f i) : SV_Target
//Emission
if (_emistog == 1)
{
float emisStrength = 0;
if (_emistogscroll == 1)
{
if (_EmisScrollSpace == 1)
emisStrength = (sin(_Time.y * _EmisScrollSpeed + i.wPos.y * _EmisScrollFrequency) + 1)/2;
else
emisStrength = (sin(_Time.y * _EmisScrollSpeed + i.oPos.y * _EmisScrollFrequency) + 1)/2;

emisStrength = remap(emisStrength,0,1,_EmisScrollMinBrightness,_EmisScrollMaxBrightness);
}

if (_audioLinktog == 1)
{
float4 audioLink;
audioLink.x = AudioLinkLerp( ALPASS_AUDIOLINK + int2( 0 , i.uv.y) ).yyyy;
audioLink.y = AudioLinkLerp( ALPASS_AUDIOLINK + int2( 0 , i.uv.y) + 1).yyyy;
audioLink.z = AudioLinkLerp( ALPASS_AUDIOLINK + int2( 0 , i.uv.y) + 2).yyyy;
audioLink.w = AudioLinkLerp( ALPASS_AUDIOLINK + int2( 0 , i.uv.y) + 3).yyyy;

float emisStrength = 0;

emisStrength += lerp(0,audioLink.x, _Bass);
emisStrength += lerp(0,audioLink.y, _LowMid);
emisStrength += lerp(0,audioLink.z, _HighMid);
emisStrength += lerp(0,audioLink.w, _Treble);

emisStrength = remap(emisStrength, 0, 1, _minAudioBrightness, 1) * _audioStrength;
finalOut = lerp(finalOut, mainOut * _EmisColor * _EmisPower * emisStrength, tex2D(_EmisTex, i.uv).xyz);
}
else
{
finalOut = lerp(finalOut, mainOut * _EmisColor * _EmisPower, tex2D(_EmisTex, i.uv).xyz);
}

finalOut = lerp(finalOut, mainOut * _EmisColor * _EmisPower * emisStrength, tex2D(_EmisTex, i.uv).xyz);
}

#if _IS_TRANSPARENT
Expand Down

0 comments on commit 95e9163

Please sign in to comment.