Skip to content

Commit

Permalink
Merge pull request #41 from Xiexe/development
Browse files Browse the repository at this point in the history
V3.0.2
  • Loading branch information
Xiexe authored Jul 14, 2021
2 parents 03c635a + 4dca1a0 commit 7a09d15
Show file tree
Hide file tree
Showing 50 changed files with 1,875 additions and 313 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Main/Patreon.meta
Main/Plugins/Patreon/
Main/Plugins/Patreon.meta
Main/Plugins/*.zip
Main/Plugins/*.zip.meta
Main/Plugins/*.zip.meta
Main/Plugins/RDPS/
2 changes: 1 addition & 1 deletion Editor.meta

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

4 changes: 2 additions & 2 deletions Editor/XSGradientEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private enum Resolutions
public static Material focusedMat;
private Material oldFocusedMat;
private Texture oldTexture;
private string rampProperty = "_Ramp";
public static string rampProperty = "_Ramp";
private ReorderableList grad_index_reorderable;
private bool reorder;
private static GUIContent iconToolbarPlus;
Expand Down Expand Up @@ -480,4 +480,4 @@ void drawHelpText()
}
}
}
}
}
5 changes: 2 additions & 3 deletions Editor/XSGradientEditor.cs.meta

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

7 changes: 5 additions & 2 deletions 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.1";
public static string ver = "3.0.2";

//Help URLs
public static string mainURL = "https://docs.google.com/document/d/1xJ4PID_nwqVm_UCsO2c2gEdiEoWoCGeM_GDK_L8-aZE/edit#bookmark=id.xh0nk8x7ws1g";
Expand Down Expand Up @@ -97,14 +97,17 @@ static public GUIStyle LineStyle
}

//GUI Buttons
static public void CallGradientEditor(Material focusedMat = null)
static public void CallGradientEditor(Material focusedMat = null, string prop = null)
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUI.skin = null;
if (GUILayout.Button("Open Gradient Editor", GUILayout.Width(200), GUILayout.Height(20)))
{
XSGradientEditor.focusedMat = focusedMat;
if (prop != null) {
XSGradientEditor.rampProperty = prop;
}
XSGradientEditor.Init();
}
GUILayout.FlexibleSpace();
Expand Down
5 changes: 2 additions & 3 deletions Editor/XSStyles.cs.meta

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

501 changes: 254 additions & 247 deletions Editor/XSToonInspector.cs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions Main/CGIncludes/XSDefines.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ struct DotProducts
half svdn;
};

struct Directions
{
half3 lightDir;
half3 viewDir;
half3 stereoViewDir;
half3 halfVector;
half3 reflView;
half3 reflLight;
half3 reflViewAniso;
};

struct HookData
{
FragmentData i;
TextureUV t;
Directions dirs;
DotProducts d;
float3 untouchedNormal;
bool isFrontface;
};

struct VertexLightInformation {
float3 Direction[4];
float3 ColorFalloff[4];
Expand Down
27 changes: 23 additions & 4 deletions Main/CGIncludes/XSFrag.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ float4 frag (
i.ntb[2] = -i.ntb[2];
}



FragmentData o = (FragmentData)0; //Populate Surface Fragment Struct
o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color * lerp(1, float4(i.color.rgb, 1), _VertexColorAlbedo);
o.specularMap = UNITY_SAMPLE_TEX2D_SAMPLER(_SpecularMap, _MainTex, t.specularMapUV);
Expand Down Expand Up @@ -92,10 +94,27 @@ float4 frag (
DoFurAlpha(o,t,alpha);
#endif

float4 col = BRDF_XSLighting(o,t);
calcAlpha(o, t, alpha);
calcDissolve(o, col.rgb);
HookData data = (HookData) 0;
data.untouchedNormal = o.normal;
o.tangent = normalize(o.tangent);
o.bitangent = normalize(o.bitangent);
calcNormal(o);
data.i = o;
data.t = t;
data.isFrontface = face;

Directions dirs = GetDirections(o);
DotProducts d = GetDots(dirs, o);
data.dirs = dirs;
data.d = d;
data = PreLightingHook(data);

float4 col = BRDF_XSLighting(data);
calcAlpha(data.i, data.t, alpha);
calcDissolve(data.i, col.rgb);

col = PostLightingHook(col, data);
UNITY_APPLY_FOG(i.fogCoord, col);
return float4(col.rgb, alpha);
#endif
}
}
3 changes: 2 additions & 1 deletion Main/CGIncludes/XSFrag.cginc.meta

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

21 changes: 2 additions & 19 deletions Main/CGIncludes/XSHelperFunctions.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ void calcNormal(inout FragmentData i)
half3 detNMap = UnpackScaleNormal(i.detailNormal, _DetailNormalMapScale);

half3 blendedNormal = lerp(nMap, BlendNormals(nMap, detNMap), i.detailMask.r);
half3 calcedNormal = normalize(blendedNormal.x * i.tangent + blendedNormal.y * i.bitangent + blendedNormal.z * i.normal);

half3 tspace0 = half3(i.tangent.x, i.bitangent.x, i.normal.x);
half3 tspace1 = half3(i.tangent.y, i.bitangent.y, i.normal.y);
half3 tspace2 = half3(i.tangent.z, i.bitangent.z, i.normal.z);

half3 calcedNormal;
calcedNormal.x = dot(tspace0, blendedNormal);
calcedNormal.y = dot(tspace1, blendedNormal);
calcedNormal.z = dot(tspace2, blendedNormal);

calcedNormal = normalize(calcedNormal);
half3 bumpedTangent = cross(i.bitangent, calcedNormal);
half3 bumpedBitangent = cross(calcedNormal, bumpedTangent);

Expand All @@ -27,15 +18,7 @@ void calcNormal(inout FragmentData i)
else
{
float3 vcol = i.color.rgb * 2 - 1;

half3 tspace0 = half3(i.tangent.x, i.bitangent.x, i.normal.x);
half3 tspace1 = half3(i.tangent.y, i.bitangent.y, i.normal.y);
half3 tspace2 = half3(i.tangent.z, i.bitangent.z, i.normal.z);

half3 calcedNormal;
calcedNormal.x = dot(tspace0, vcol);
calcedNormal.y = dot(tspace1, vcol);
calcedNormal.z = dot(tspace2, vcol);
half3 calcedNormal = normalize(vcol.x * i.tangent + vcol.y * i.bitangent + vcol.z * i.normal);;

//calcedNormal = calcedNormal;
i.normal = normalize(calcedNormal);
Expand Down
42 changes: 13 additions & 29 deletions Main/CGIncludes/XSLighting.cginc
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
half4 BRDF_XSLighting(FragmentData i, TextureUV t)
half4 BRDF_XSLighting(HookData data)
{
float3 untouchedNormal = i.normal;
i.tangent = normalize(i.tangent);
i.bitangent = normalize(i.bitangent);
calcNormal(i);
FragmentData i = data.i;
float3 untouchedNormal = data.untouchedNormal;
TextureUV t = data.t;
Directions dirs = data.dirs;
DotProducts d = data.d;

half3 indirectDiffuse = calcIndirectDiffuse(i);
bool lightEnv = any(_WorldSpaceLightPos0.xyz);
half3 lightDir = calcLightDir(i);
half3 viewDir = calcViewDir(i.worldPos);
half3 stereoViewDir = calcStereoViewDir(i.worldPos);
half4 metallicSmoothness = calcMetallicSmoothness(i);
half3 halfVector = normalize(lightDir + viewDir);
half3 reflView = calcReflView(viewDir, i.normal);
half3 reflLight = calcReflLight(lightDir, i.normal);
half3 reflViewAniso = getAnisotropicReflectionVector(viewDir, i.bitangent, i.tangent, i.normal, metallicSmoothness.a, _AnisotropicReflection);

DotProducts d = (DotProducts)0;
d.ndl = dot(i.normal, lightDir);
d.vdn = abs(dot(viewDir, i.normal));
d.vdh = DotClamped(viewDir, halfVector);
d.tdh = dot(i.tangent, halfVector);
d.bdh = dot(i.bitangent, halfVector);
d.ndh = DotClamped(i.normal, halfVector);
d.rdv = saturate(dot(reflLight, float4(-viewDir, 0)));
d.ldh = DotClamped(lightDir, halfVector);
d.svdn = abs(dot(stereoViewDir, i.normal));
half3 reflViewAniso = getAnisotropicReflectionVector(dirs.viewDir, i.bitangent, i.tangent, i.normal, metallicSmoothness.a, _AnisotropicReflection);

i.albedo.rgb = rgb2hsv(i.albedo.rgb);
i.albedo.x += fmod(lerp(0, _Hue, i.hsvMask.r), 360);
Expand All @@ -51,11 +35,11 @@ half4 BRDF_XSLighting(FragmentData i, TextureUV t)
vertexLightDiffuse = getVertexLightsDiffuse(i, vLight);
indirectDiffuse += vertexLightDiffuse;

vertexLightSpec = getVertexLightSpecular(i, d, vLight, i.normal, viewDir, _AnisotropicSpecular) * occlusion;
vertexLightSpec = getVertexLightSpecular(i, d, vLight, i.normal, dirs.viewDir, _AnisotropicSpecular) * occlusion;
#endif

half lightAvg = (dot(indirectDiffuse.rgb, grayscaleVec) + dot(lightCol.rgb, grayscaleVec)) / 2;
half3 envMapBlurred = getEnvMap(i, d, 5, reflView, indirectDiffuse, i.normal);
half3 envMapBlurred = getEnvMap(i, d, 5, dirs.reflView, indirectDiffuse, i.normal);

half4 ramp = 1;
half4 diffuse = 1;
Expand All @@ -74,9 +58,9 @@ half4 BRDF_XSLighting(FragmentData i, TextureUV t)

float3 f0 = 0.16 * _Reflectivity * _Reflectivity * (1.0 - metallicSmoothness.r) + i.diffuseColor * metallicSmoothness.r;
float3 fresnel = F_Schlick(d.vdn, f0);
half3 indirectSpecular = calcIndirectSpecular(i, d, metallicSmoothness, reflViewAniso, indirectDiffuse, viewDir, fresnel, ramp) * occlusion;
half3 directSpecular = calcDirectSpecular(i, d.ndl, d.ndh, d.vdn, d.ldh, lightCol, halfVector, _AnisotropicSpecular) * d.ndl * occlusion * i.attenuation;
half4 subsurface = calcSubsurfaceScattering(i, d, lightDir, viewDir, i.normal, lightCol, indirectDiffuse);
half3 indirectSpecular = calcIndirectSpecular(i, d, metallicSmoothness, reflViewAniso, indirectDiffuse, dirs.viewDir, fresnel, ramp) * occlusion;
half3 directSpecular = calcDirectSpecular(i, d.ndl, d.ndh, d.vdn, d.ldh, lightCol, dirs.halfVector, _AnisotropicSpecular) * d.ndl * occlusion * i.attenuation;
half4 subsurface = calcSubsurfaceScattering(i, d, dirs.lightDir, dirs.viewDir, i.normal, lightCol, indirectDiffuse);
half4 outlineColor = calcOutlineColor(i, d, indirectDiffuse, lightCol);

half lineHalftone = 0;
Expand Down Expand Up @@ -110,7 +94,7 @@ half4 BRDF_XSLighting(FragmentData i, TextureUV t)
col += max(directSpecular.xyzz, rimLight);
col.rgb += max(vertexLightSpec.rgb, rimLight);
col += subsurface;
calcClearcoat(col, i, d, untouchedNormal, indirectDiffuse, lightCol, viewDir, lightDir, ramp);
calcClearcoat(col, i, d, untouchedNormal, indirectDiffuse, lightCol, dirs.viewDir, dirs.lightDir, ramp);
col += calcEmission(i, t, d, lightAvg);
float4 finalColor = lerp(col, outlineColor, i.isOutline) * lerp(1, lineHalftone, _HalftoneLineIntensity * usingLineHalftone);

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

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

27 changes: 27 additions & 0 deletions Main/CGIncludes/XSLightingFunctions.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,30 @@ void calcClearcoat(inout half4 col, FragmentData i, DotProducts d, half3 untouch
col += clearcoat.xyzz;
}
}

Directions GetDirections(FragmentData i)
{
Directions dirs = (Directions) 0;
dirs.lightDir = calcLightDir(i);
dirs.viewDir = calcViewDir(i.worldPos);
dirs.stereoViewDir = calcStereoViewDir(i.worldPos);
dirs.halfVector = normalize(dirs.lightDir + dirs.viewDir);
dirs.reflView = calcReflView(dirs.viewDir, i.normal);
dirs.reflLight = calcReflLight(dirs.lightDir, i.normal);
return dirs;
}

DotProducts GetDots(Directions dirs, FragmentData i)
{
DotProducts d = (DotProducts)0;
d.ndl = dot(i.normal, dirs.lightDir);
d.vdn = abs(dot(dirs.viewDir, i.normal));
d.vdh = DotClamped(dirs.viewDir, dirs.halfVector);
d.tdh = dot(i.tangent, dirs.halfVector);
d.bdh = dot(i.bitangent, dirs.halfVector);
d.ndh = DotClamped(i.normal, dirs.halfVector);
d.rdv = saturate(dot(dirs.reflLight, float4(-dirs.viewDir, 0)));
d.ldh = DotClamped(dirs.lightDir, dirs.halfVector);
d.svdn = abs(dot(dirs.stereoViewDir, i.normal));
return d;
}
4 changes: 4 additions & 0 deletions Main/CGIncludes/XSPostLighting.cginc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
float4 PostLightingHook(float4 finalColor, HookData data)
{
return finalColor;
}
3 changes: 3 additions & 0 deletions Main/CGIncludes/XSPostLighting.cginc.meta

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

4 changes: 4 additions & 0 deletions Main/CGIncludes/XSPreLighting.cginc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HookData PreLightingHook(HookData data)
{
return data;
}
3 changes: 3 additions & 0 deletions Main/CGIncludes/XSPreLighting.cginc.meta

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

8 changes: 8 additions & 0 deletions Main/Plugins/Iridescent.meta

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

3 changes: 3 additions & 0 deletions Main/Plugins/Iridescent/Editor.meta

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

Loading

0 comments on commit 7a09d15

Please sign in to comment.