Skip to content

Commit

Permalink
4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
poiyomi committed Sep 19, 2019
1 parent bebdd00 commit 4f4426f
Show file tree
Hide file tree
Showing 64 changed files with 3,076 additions and 1,196 deletions.
4 changes: 2 additions & 2 deletions _PoiyomiToonShader/Shaders/Extras/InvisStencil.shader
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Shader ".poiyomi/Toon/Extras/StencilInvis"
{
properties
{
[HideInInspector] m_StencilPassOptions ("Stencil--button_right={text:Tutorial,action:{type:url,data:https://youtu.be/uniOEpw88jk},hover:YouTube}", Float) = 0
[HideInInspector] m_StencilPassOptions ("Stencil", Float) = 0
[IntRange] _StencilRef ("Stencil Reference Value--hover=The value to be compared against (if Comp is anything else than always) and/or the value to be written to the buffer (if either Pass, Fail or ZFail is set to replace). 0–255 integer.", Range(0, 255)) = 0
//[IntRange] _StencilReadMaskRef ("Stencil ReadMask Value--hover=An 8 bit mask as an 0–255 integer, used when comparing the reference value with the contents of the buffer (referenceValue & readMask) comparisonFunction (stencilBufferValue & readMask). Default: 255.", Range(0, 255)) = 0
//[IntRange] _StencilWriteMaskRef ("Stencil WriteMask Value--hover=An 8 bit mask as an 0–255 integer, used when writing to the buffer. Note that, like other write masks, it specifies which bits of stencil buffer will be affected by write (i.e. WriteMask 0 means that no bits are affected and not that 0 will be written). Default: 255.", Range(0, 255)) = 0
Expand All @@ -11,7 +11,7 @@ Shader ".poiyomi/Toon/Extras/StencilInvis"
[Enum(UnityEngine.Rendering.StencilOp)] _StencilZFailOp ("Stencil ZFail Op--hover=What to do with the contents of the buffer if the stencil test passes, but the depth test fails. Default: keep.", Float) = 0
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilCompareFunction ("Stencil Compare Function--hover=The function used to compare the reference value to the current contents of the buffer. Default: always.", Float) = 8

[HideInInspector] m_miscOptions ("Misc--button_right={text:Tutorial,action:{type:url,data:https://youtu.be/P5KlE9rk9pg},hover:YouTube}", Float) = 0
[HideInInspector] m_renderingOptions ("Rendering Options", Float) = 0
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull--hover=Controls which sides of polygons should be culled (not drawn) Back: Don’t render polygons facing away from the viewer (default). Front: Don’t render polygons facing towards the viewer. Used for turning objects insideout. Off: Disables culling all faces are drawn. Used for special effects.", Float) = 2
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest--hover=How should depth testing be performed. Default is LEqual (draw objects in from or at the distance as existing objects; hide objects behind them).", Float) = 4
[Enum(UnityEngine.Rendering.BlendMode)] _SourceBlend ("Source Blend--hover=When graphics are rendered, after all Shaders have executed and all Textures have been applied, the pixels are written to the screen. How they are combined with what is already there is controlled by the Blend command.", Float) = 5
Expand Down
16 changes: 3 additions & 13 deletions _PoiyomiToonShader/Shaders/Includes/PoiData.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,17 @@
void calculateLightColor()
{
#ifdef FORWARD_BASE_PASS
//poiLight.color = saturate(_LightColor0.rgb) + saturate(ShadeSH9(normalize(unity_SHAr + unity_SHAg + unity_SHAb)));
float3 magic = saturate(ShadeSH9(normalize(unity_SHAr + unity_SHAg + unity_SHAb)));
float3 normalLight = saturate(_LightColor0.rgb);
poiLight.color = magic+normalLight;
poiLight.color = saturate(magic+normalLight);
#else
#if defined(POINT) || defined(SPOT)
poiLight.color = _LightColor0.rgb;
#endif
#endif
}

float3 getCameraForward()
{
#if UNITY_SINGLE_PASS_STEREO
float3 p1 = mul(unity_StereoCameraToWorld[0], float4(0, 0, 1, 1));
float3 p2 = mul(unity_StereoCameraToWorld[0], float4(0, 0, 0, 1));
#else
float3 p1 = mul(unity_CameraToWorld, float4(0, 0, 1, 1));
float3 p2 = mul(unity_CameraToWorld, float4(0, 0, 0, 1));
#endif
return normalize(p2 - p1);
}

float3 CreateBinormal(float3 normal, float3 tangent, float binormalSign)
{
return cross(normal, tangent.xyz) * (binormalSign * unity_WorldTransformParams.w);
Expand All @@ -75,6 +64,7 @@
poiCam.worldPos = _WorldSpaceCameraPos;
poiCam.tangentViewDir = normalize(i.tangentViewDir);
poiCam.distanceToModel = distance(poiMesh.modelPos, poiCam.worldPos);
poiCam.distanceToVert = distance(poiMesh.worldPos, poiCam.worldPos);
}

void calculateTangentData()
Expand Down
83 changes: 40 additions & 43 deletions _PoiyomiToonShader/Shaders/Includes/PoiDebug.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -34,61 +34,58 @@
return;
}

// Lighting
if (_DebugLightingData == 1)
{
finalColor.rgb = poiLight.attenuation;
return;
}
else if(_DebugLightingData == 2)
{
finalColor.rgb = poiLight.directLighting;
return;
}
else if(_DebugLightingData == 3)
{
finalColor.rgb = poiLight.indirectLighting;
return;
}
else if(_DebugLightingData == 4)
{
finalColor.rgb = poiLight.lightMap;
return;
}
else if(_DebugLightingData == 5)
{
finalColor.rgb = poiLight.rampedLightMap;
return;
}
else if(_DebugLightingData == 6)
{
finalColor.rgb = poiLight.finalLighting;
return;
}
else if(_DebugLightingData == 7)
{
finalColor.rgb = poiLight.nDotL;
return;
}
#ifdef POI_LIGHTING
// Lighting
if (_DebugLightingData == 1)
{
finalColor.rgb = poiLight.attenuation;
return;
}
else if(_DebugLightingData == 2)
{
finalColor.rgb = poiLight.directLighting;
return;
}
else if(_DebugLightingData == 3)
{
finalColor.rgb = poiLight.indirectLighting;
return;
}
else if(_DebugLightingData == 4)
{
finalColor.rgb = poiLight.lightMap;
return;
}
else if(_DebugLightingData == 5)
{
finalColor.rgb = poiLight.rampedLightMap;
return;
}
else if(_DebugLightingData == 6)
{
finalColor.rgb = poiLight.finalLighting;
return;
}
else if(_DebugLightingData == 7)
{
finalColor.rgb = poiLight.nDotL;
return;
}
#endif

#ifdef _SPECGLOSSMAP
#ifdef POI_SPECULAR
//specular
if (_DebugSpecularData == 1)
{
finalColor.rgb = finalSpecular;
return;
}
else if(_DebugSpecularData == 2)
{
finalColor.rgb = highTexture;
return;
}
else if(_DebugSpecularData == 3)
{
finalColor.rgb = tangentDirectionMap;
return;
}
else if(_DebugSpecularData == 4)
else if(_DebugSpecularData == 3)
{
finalColor.rgb = shiftTexture;
return;
Expand Down
100 changes: 0 additions & 100 deletions _PoiyomiToonShader/Shaders/Includes/PoiDragNDropLighting.cginc

This file was deleted.

6 changes: 5 additions & 1 deletion _PoiyomiToonShader/Shaders/Includes/PoiEmission.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
}
void applyEmission(inout float4 finalColor)
{
finalColor.rgb += emission;
#ifdef TRANSPARENT
finalColor.rgb += emission * mainTexture.a;
#else
finalColor.rgb += emission;
#endif
}
#endif
11 changes: 6 additions & 5 deletions _PoiyomiToonShader/Shaders/Includes/PoiFrag.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
calculateReflections();
#endif

#ifdef POI_RANDOM
mainTexture.a *= i.angleAlpha;
albedo.a *= i.angleAlpha;
#endif

#ifdef POI_DATA
distanceFade();
#endif
Expand Down Expand Up @@ -99,10 +104,6 @@
applyEnviroRim(finalColor);
#endif

#ifdef DND_POI_LIGHTING
applyDNDLighting(finalColor);
#endif

#ifdef POI_METAL
applyReflections(finalColor, finalColorBeforeLighting);
#endif
Expand Down Expand Up @@ -172,7 +173,7 @@
#ifdef POI_DEBUG
displayDebugInfo(finalColor);
#endif

finalColor.a = max(_ForceOpaque, finalColor.a);
return finalColor;
}
Expand Down
18 changes: 15 additions & 3 deletions _PoiyomiToonShader/Shaders/Includes/PoiHelpers.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ float3 getCameraPosition()
return _WorldSpaceCameraPos;
}

float3 getCameraForward()
{
#if UNITY_SINGLE_PASS_STEREO
float3 p1 = mul(unity_StereoCameraToWorld[0], float4(0, 0, 1, 1));
float3 p2 = mul(unity_StereoCameraToWorld[0], float4(0, 0, 0, 1));
#else
float3 p1 = mul(unity_CameraToWorld, float4(0, 0, 1, 1));
float3 p2 = mul(unity_CameraToWorld, float4(0, 0, 0, 1));
#endif
return normalize(p2 - p1);
}

float3 grayscale_vector_node()
{
return float3(0, 0.3823529, 0.01845836);
Expand Down Expand Up @@ -120,13 +132,13 @@ float4x4 poiRotationMatrixFromAngles(float x, float y, float z)
s, c, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);

return mul(mul(rotateXMatrix, rotateYMatrix), rotateZMatrix);
}

float4x4 poiRotationMatrixFromAngles(float3 angles)
{
float angleX = radians(angles.x);
float angleX = radians(angles.x);
float c = cos(angleX);
float s = sin(angleX);
float4x4 rotateXMatrix = float4x4(1, 0, 0, 0,
Expand All @@ -149,6 +161,6 @@ float4x4 poiRotationMatrixFromAngles(float3 angles)
s, c, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);

return mul(mul(rotateXMatrix, rotateYMatrix), rotateZMatrix);
}
14 changes: 9 additions & 5 deletions _PoiyomiToonShader/Shaders/Includes/PoiLighting.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
float bw_topIndirectLighting = dot(ShadeSH9Plus, grayscale_vector);
float lightDifference = ((bw_topIndirectLighting + bw_lightColor) - bw_bottomIndirectLighting);
poiLight.lightMap = smoothstep(0, lightDifference, bw_directLighting - bw_bottomIndirectLighting);

poiLight.directLighting = lerp(ShadeSH9Plus, poiLight.color, .75);
poiLight.indirectLighting = ShadeSH9Minus;
poiLight.directLighting = saturate(lerp(ShadeSH9Plus, poiLight.color, .75));
poiLight.indirectLighting = saturate(ShadeSH9Minus);

poiLight.rampedLightMap = tex2D(_ToonRamp, poiLight.lightMap * AOMap + _ShadowOffset);

Expand All @@ -99,10 +99,14 @@
}
else if(_LightingType == 1)
{
float3 ramp0 = tex2D(_ToonRamp, float2(1,1));
float3 ramp0 = tex2D(_ToonRamp, float2(1, 1));
poiLight.finalLighting = lerp(ramp0, poiLight.rampedLightMap, _ShadowStrength) * poiLight.directLighting;
}
poiLight.finalLighting = poiLight.finalLighting;
else if(_LightingType == 2)
{
float3 real = ShadeSH9(float4(poiMesh.fragmentNormal, 1));
poiLight.finalLighting = saturate(_LightColor0.rgb * AOMap * lerp(1, poiLight.attenuation, _AttenuationMultiplier) * (poiLight.nDotL * 0.5 + 0.5) + real);
}
}

void calculateLighting()
Expand Down
Loading

0 comments on commit 4f4426f

Please sign in to comment.