Skip to content

Commit

Permalink
Merge pull request #38 from Xiexe/development
Browse files Browse the repository at this point in the history
Development 3.0.1
  • Loading branch information
Xiexe authored Jun 4, 2021
2 parents fe76d4c + 7af7016 commit 03c635a
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 945 deletions.
2 changes: 1 addition & 1 deletion Editor/XSStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace XSToon3
[InitializeOnLoad]
public class XSStyles : MonoBehaviour
{
public static string ver = "3.0";
public static string ver = "3.0.1";

//Help URLs
public static string mainURL = "https://docs.google.com/document/d/1xJ4PID_nwqVm_UCsO2c2gEdiEoWoCGeM_GDK_L8-aZE/edit#bookmark=id.xh0nk8x7ws1g";
Expand Down
14 changes: 14 additions & 0 deletions Editor/XSToonInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ public class XSToonInspector : ShaderGUI
private MaterialProperty _UseClipsForDissolve = null;
private MaterialProperty _WireColor = null;
private MaterialProperty _WireWidth = null;
private MaterialProperty _SrcBlend = null;
private MaterialProperty _DstBlend = null;
private MaterialProperty _ZWrite = null;


private MaterialProperty _EmissionAudioLinkChannel = null;
private MaterialProperty _ALGradientOnRed = null;
private MaterialProperty _ALGradientOnGreen = null;
private MaterialProperty _ALGradientOnBlue = null;
private MaterialProperty _ALUVWidth = null;

//Experimenting
private MaterialProperty _DissolveBlendPower = null;
Expand Down Expand Up @@ -614,6 +619,7 @@ private void DrawEmissionSettings(MaterialEditor materialEditor, Material materi
{
bool isAudioLink = material.GetInt("_EmissionAudioLinkChannel") > 0;
bool isPackedMapLink = material.GetInt("_EmissionAudioLinkChannel") == 5;
bool isUVBased = material.GetInt("_EmissionAudioLinkChannel") == 6;
materialEditor.ShaderProperty(_EmissionAudioLinkChannel, new GUIContent("Emission Audio Link", "Use Audio Link for Emission Brightness"));

if (!isPackedMapLink)
Expand All @@ -622,6 +628,9 @@ private void DrawEmissionSettings(MaterialEditor materialEditor, Material materi
materialEditor.TextureScaleOffsetProperty(_EmissionMap);
materialEditor.ShaderProperty(_UVSetEmission, new GUIContent("UV Set", "The UV set to use for the Emission Map"), 2);
materialEditor.ShaderProperty(_EmissionToDiffuse, new GUIContent("Tint To Diffuse", "Tints the emission to the Diffuse Color"), 2);
if (isUVBased) {
materialEditor.ShaderProperty(_ALUVWidth, new GUIContent("History Sample Amount", "Controls the amount of Audio Link history to sample."));
}
}
else
{
Expand Down Expand Up @@ -753,8 +762,13 @@ private void DrawAdvancedSettings(MaterialEditor materialEditor, Material materi
materialEditor.ShaderProperty(_StencilComp, _StencilComp.displayName);
materialEditor.ShaderProperty(_StencilOp, _StencilOp.displayName);

XSStyles.Separator();
materialEditor.ShaderProperty(_SrcBlend, new GUIContent("SrcBlend", ""));
materialEditor.ShaderProperty(_DstBlend, new GUIContent("DstBlend", ""));
materialEditor.ShaderProperty(_ZWrite, new GUIContent("ZWrite", ""));
XSStyles.Separator();
materialEditor.RenderQueueField();
XSStyles.Separator();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/XSToonInspector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions Main/CGIncludes/XSDefines.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
struct VertexInput
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float2 uv1 : TEXCOORD1;
centroid float2 uv : TEXCOORD0;
centroid float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float3 normal : NORMAL;
float4 tangent : TANGENT;
Expand All @@ -25,15 +25,15 @@ struct VertexOutput
float4 pos : SV_POSITION;
#endif

float2 uv : TEXCOORD0;
float2 uv1 : TEXCOORD1;
centroid float2 uv : TEXCOORD0;
centroid float2 uv1 : TEXCOORD1;
float3 ntb[3] : TEXCOORD2; //texcoord 3, 4 || Holds World Normal, Tangent, and Bitangent
float4 worldPos : TEXCOORD5;
float4 color : TEXCOORD6;
float3 normal : TEXCOORD8;
float4 screenPos : TEXCOORD9;
float3 objPos : TEXCOORD11;
float2 uv2 : TEXCOORD12;
centroid float2 uv2 : TEXCOORD12;

#if !defined(UNITY_PASS_SHADOWCASTER)
SHADOW_COORDS(7)
Expand Down Expand Up @@ -77,9 +77,10 @@ struct VertexOutput
float4 color : TEXCOORD6;
float4 screenPos : TEXCOORD8;
float3 objPos : TEXCOORD10;
float2 uv2 : TEXCOORD11;

#if defined(Fur)
float layer : TEXCOORD11;
float layer : TEXCOORD12;
#endif

#if !defined(UNITY_PASS_SHADOWCASTER)
Expand Down Expand Up @@ -130,6 +131,7 @@ struct TextureUV
{
half2 uv0;
half2 uv1;
half2 uv2;
half2 albedoUV;
half2 specularMapUV;
half2 metallicGlossMapUV;
Expand Down Expand Up @@ -236,6 +238,7 @@ int _UVSetAlbedo, _UVSetNormal, _UVSetDetNormal,
int _NormalMapMode, _OutlineUVSelect;
int _AlphaToMask;
int _ALGradientOnRed, _ALGradientOnGreen, _ALGradientOnBlue;
int _ALUVWidth;

//!RDPSDefines

Expand Down
3 changes: 2 additions & 1 deletion Main/CGIncludes/XSDefines.cginc.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Main/CGIncludes/XSGeom.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
o.ntb[2] = IN[i].ntb[2];
o.uv = IN[i].uv;
o.uv1 = IN[i].uv1;
o.uv2 = IN[i].uv2;
o.color = float4(IN[i].color.rgb,0); // store if outline in alpha channel of vertex colors | 0 = not an outline
o.screenPos = ComputeScreenPos(o.pos);
o.objPos = normalize(IN[i].vertex);
Expand Down Expand Up @@ -81,6 +82,7 @@
o.ntb[2] = IN[i].ntb[2];
o.uv = IN[i].uv;
o.uv1 = IN[i].uv1;
o.uv2 = IN[i].uv2;
o.color = float4(IN[i].color.rgb, 1); // store if outline in alpha channel of vertex colors | 1 = is an outline
o.screenPos = ComputeScreenPos(o.pos);
o.objPos = normalize(outlinePos);
Expand Down
5 changes: 5 additions & 0 deletions Main/CGIncludes/XSHelperFunctions.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void InitializeTextureUVs(

t.uv0 = i.uv;
t.uv1 = i.uv1;
t.uv2 = i.uv2;

half2 uvSetAlbedo = (_UVSetAlbedo == 0) ? i.uv : i.uv1;
t.albedoUV = TRANSFORM_TEX(uvSetAlbedo, _MainTex);
Expand Down Expand Up @@ -129,6 +130,10 @@ void InitializeTextureUVsMerged(
#endif
inout TextureUV t)
{
t.uv0 = i.uv;
t.uv1 = i.uv1;
t.uv2 = i.uv2;

half2 uvSetAlbedo = (_UVSetAlbedo == 0) ? i.uv : i.uv1;
t.albedoUV = TRANSFORM_TEX(uvSetAlbedo, _MainTex);
t.normalMapUV = t.albedoUV;
Expand Down
16 changes: 13 additions & 3 deletions Main/CGIncludes/XSLighting.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ half4 BRDF_XSLighting(FragmentData i, TextureUV t)

float3 vertexLightDiffuse = 0;
float3 vertexLightSpec = 0;
#if defined(VERTEXLIGHT_ON)
#if defined(VERTEXLIGHT_ON) && !defined(LIGHTMAP_ON)
VertexLightInformation vLight = (VertexLightInformation)0;
float4 vertexLightAtten = float4(0,0,0,0);
float3 vertexLightColor = get4VertexLightsColFalloff(vLight, i.worldPos, i.normal, vertexLightAtten);
Expand All @@ -57,8 +57,18 @@ half4 BRDF_XSLighting(FragmentData i, TextureUV t)
half lightAvg = (dot(indirectDiffuse.rgb, grayscaleVec) + dot(lightCol.rgb, grayscaleVec)) / 2;
half3 envMapBlurred = getEnvMap(i, d, 5, reflView, indirectDiffuse, i.normal);

half4 ramp = calcRamp(i,d);
half4 diffuse = calcDiffuse(i, d, indirectDiffuse, lightCol, ramp);
half4 ramp = 1;
half4 diffuse = 1;
#if defined(LIGHTMAP_ON)
diffuse = i.albedo * getLightmap(t.uv1, i.normal, i.worldPos);
#if defined(DYNAMICLIGHTMAP_ON)
diffuse += getRealtimeLightmap(t.uv2, i.normal);
#endif
#else
ramp = calcRamp(i,d);
diffuse = calcDiffuse(i, d, indirectDiffuse, lightCol, ramp);
#endif

half4 rimLight = calcRimLight(i, d, lightCol, indirectDiffuse, envMapBlurred);
half4 shadowRim = calcShadowRim(i, d, indirectDiffuse);

Expand Down
44 changes: 41 additions & 3 deletions Main/CGIncludes/XSLightingFunctions.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,12 @@ half4 calcOutlineColor(FragmentData i, DotProducts d, half3 indirectDiffuse, hal

half3 calcIndirectDiffuse(FragmentData i)
{// We don't care about anything other than the color from probes for toon lighting.
half3 indirectDiffuse = ShadeSH9(float4(0,0.5,0,1));//half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w);
return indirectDiffuse;
#if !defined(LIGHTMAP_ON)
half3 indirectDiffuse = ShadeSH9(float4(0,0.5,0,1));//half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w);
return indirectDiffuse;
#else
return 0;
#endif
}

half4 calcDiffuse(FragmentData i, DotProducts d, half3 indirectDiffuse, half4 lightCol, half4 ramp)
Expand All @@ -354,6 +358,33 @@ half4 calcDiffuse(FragmentData i, DotProducts d, half3 indirectDiffuse, half4 li
return diffuse;
}

float4 getRealtimeLightmap(float2 uv, float3 worldNormal)
{
float2 realtimeUV = uv * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
float4 bakedCol = UNITY_SAMPLE_TEX2D(unity_DynamicLightmap, realtimeUV);
float3 realtimeLightmap = DecodeRealtimeLightmap(bakedCol);

#ifdef DIRLIGHTMAP_COMBINED
float4 realtimeDirTex = UNITY_SAMPLE_TEX2D_SAMPLER(unity_DynamicDirectionality, unity_DynamicLightmap, realtimeUV);
realtimeLightmap += DecodeDirectionalLightmap (realtimeLightmap, realtimeDirTex, worldNormal);
#endif

return float4(realtimeLightmap.rgb, 1);
}

float4 getLightmap(float2 uv, float3 worldNormal, float3 worldPos)
{
float2 lightmapUV = uv * unity_LightmapST.xy + unity_LightmapST.zw;
float4 bakedColorTex = UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV);
float3 lightMap = DecodeLightmap(bakedColorTex);

#ifdef DIRLIGHTMAP_COMBINED
fixed4 bakedDirTex = UNITY_SAMPLE_TEX2D_SAMPLER (unity_LightmapInd, unity_Lightmap, lightmapUV);
lightMap = DecodeDirectionalLightmap(lightMap, bakedDirTex, worldNormal);
#endif
return float4(lightMap.rgb, 1);
}

//Subsurface Scattering - Based on a 2011 GDC Conference from by Colin Barre-Bresebois & Marc Bouchard
//Modified by Xiexe
half4 calcSubsurfaceScattering(FragmentData i, DotProducts d, half3 lightDir, half3 viewDir, half3 normal, half4 lightCol, half3 indirectDiffuse)
Expand Down Expand Up @@ -391,7 +422,14 @@ half4 calcEmission(FragmentData i, TextureUV t, DotProducts d, half lightAvg)
{
if(_EmissionAudioLinkChannel != 5)
{
int2 aluv = int2(0, (_EmissionAudioLinkChannel-1));
int2 aluv;
if (_EmissionAudioLinkChannel == 6)
{
aluv = int2(t.emissionMapUV.x * _ALUVWidth, t.emissionMapUV.y);
} else
{
aluv = int2(0, (_EmissionAudioLinkChannel-1));
}
float alink = lerp(1, AudioLinkData(aluv).x , saturate(_EmissionAudioLinkChannel));
emission = lerp(i.emissionMap, i.emissionMap * i.diffuseColor.xyzz, _EmissionToDiffuse) * _EmissionColor * alink;
}
Expand Down
3 changes: 2 additions & 1 deletion Main/CGIncludes/XSLightingFunctions.cginc.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Main/CGIncludes/XSVert.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ VertexOutput vert (VertexInput v)
o.ntb[2] = bitangent;
o.uv = v.uv;
o.uv1 = v.uv1;
o.uv2 = v.uv2;
o.color = float4(v.color.rgb, 0); // store if outline in alpha channel of vertex colors | 0 = not an outline
o.normal = v.normal;
o.screenPos = ComputeScreenPos(o.pos);
Expand Down
11 changes: 6 additions & 5 deletions Main/Shaders/XSToon3.0.shader
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@
[Enum(UV1,0,UV2,1)] _UVSetClipMap("Clip Map UVs", Int) = 0
[Enum(UV1,0,UV2,1)] _UVSetDissolve("Dissolve Map UVs", Int) = 0

[Enum(None,0,Bass,1,Low Mids,2,High Mids,3,Treble,4,Packed Map,5)]_EmissionAudioLinkChannel("Emisssion Audio Link Channel", int) = 0
[Enum(None,0,Bass,1,Low Mids,2,High Mids,3,Treble,4,Packed Map,5,UV Based,6)]_EmissionAudioLinkChannel("Emisssion Audio Link Channel", int) = 0
[ToggleUI]_ALGradientOnRed("Gradient Red", Int) = 0
[ToggleUI]_ALGradientOnGreen("Gradient Green", Int) = 0
[ToggleUI]_ALGradientOnBlue("Gradient Blue", Int) = 0
[HDR]_EmissionColor("Emission Color", Color) = (0,0,0,0)
[HDR]_EmissionColor0("Emission Packed Color 1", Color) = (0,0,0,0)
[HDR]_EmissionColor1("Emission Packed Color 2", Color) = (0,0,0,0)
[IntRange]_ALUVWidth("History Sample Amount", Range(0,128)) = 128

_ClipMap("Clip Map", 2D) = "black" {}
_WireColor("Wire Color", Color) = (0,0,0,0)
Expand All @@ -143,9 +144,9 @@
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Comparison", Int) = 0
[Enum(UnityEngine.Rendering.StencilOp)] _StencilOp ("Stencil Operation", Int) = 0

[HideInInspector] _SrcBlend ("__src", int) = 1
[HideInInspector] _DstBlend ("__dst", int) = 0
[HideInInspector] _ZWrite ("__zw", int) = 1
[Enum(UnityEngine.Rendering.BlendMode)]_SrcBlend ("__src", int) = 1
[Enum(UnityEngine.Rendering.BlendMode)]_DstBlend ("__dst", int) = 0
[Enum(Off,0,On,1)]_ZWrite ("__zw", int) = 1
[HideInInspector] _AlphaToMask("__am", int) = 0

_ClipMask("Clip Mask", 2D) = "black" {}
Expand Down Expand Up @@ -280,4 +281,4 @@
}
Fallback "Diffuse"
CustomEditor "XSToon3.XSToonInspector"
}
}
3 changes: 2 additions & 1 deletion Main/Shaders/XSToon3.0.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Main/Shaders/XSToon3.0_Outlined.shader
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@
[Enum(UV1,0,UV2,1)] _UVSetClipMap("Clip Map UVs", Int) = 0
[Enum(UV1,0,UV2,1)] _UVSetDissolve("Dissolve Map UVs", Int) = 0

[Enum(None,0,Bass,1,Low Mids,2,High Mids,3,Treble,4,Packed Map,5)]_EmissionAudioLinkChannel("Emisssion Audio Link Channel", int) = 0
[Enum(None,0,Bass,1,Low Mids,2,High Mids,3,Treble,4,Packed Map,5,UV Based,6)]_EmissionAudioLinkChannel("Emisssion Audio Link Channel", int) = 0
[ToggleUI]_ALGradientOnRed("Gradient Red", Int) = 0
[ToggleUI]_ALGradientOnGreen("Gradient Green", Int) = 0
[ToggleUI]_ALGradientOnBlue("Gradient Blue", Int) = 0
[HDR]_EmissionColor("Emission Color", Color) = (0,0,0,0)
[HDR]_EmissionColor0("Emission Packed Color 1", Color) = (0,0,0,0)
[HDR]_EmissionColor1("Emission Packed Color 2", Color) = (0,0,0,0)
[IntRange]_ALUVWidth("History Sample Amount", Range(0,128)) = 128

_ClipMap("Clip Map", 2D) = "black" {}
_WireColor("Wire Color", Color) = (0,0,0,0)
Expand All @@ -144,9 +145,9 @@
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Comparison", Int) = 0
[Enum(UnityEngine.Rendering.StencilOp)] _StencilOp ("Stencil Operation", Int) = 0

[HideInInspector] _SrcBlend ("__src", int) = 1
[HideInInspector] _DstBlend ("__dst", int) = 0
[HideInInspector] _ZWrite ("__zw", int) = 1
[Enum(UnityEngine.Rendering.BlendMode)]_SrcBlend ("__src", int) = 1
[Enum(UnityEngine.Rendering.BlendMode)]_DstBlend ("__dst", int) = 0
[Enum(Off,0,On,1)]_ZWrite ("__zw", int) = 1
[HideInInspector] _AlphaToMask("__am", int) = 0

_ClipMask("Clip Mask", 2D) = "black" {}
Expand Down
3 changes: 2 additions & 1 deletion Main/Shaders/XSToon3.0_Outlined.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 03c635a

Please sign in to comment.