196 lines
6.9 KiB
GLSL
196 lines
6.9 KiB
GLSL
// Made with Amplify Shader Editor v1.9.7.1
|
|
// Available at the Unity Asset Store - http://u3d.as/y3X
|
|
Shader "Alpha Screen Shadow"
|
|
{
|
|
Properties
|
|
{
|
|
[HideInInspector] _texcoord( "", 2D ) = "white" {}
|
|
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
LOD 0
|
|
|
|
|
|
CGINCLUDE
|
|
#pragma target 3.0
|
|
ENDCG
|
|
Blend Off
|
|
AlphaToMask Off
|
|
Cull Back
|
|
ColorMask RGBA
|
|
ZWrite On
|
|
ZTest LEqual
|
|
Offset 0 , 0
|
|
|
|
|
|
Pass
|
|
{
|
|
Name "Custom RT Update"
|
|
CGPROGRAM
|
|
#define ASE_VERSION 19701
|
|
|
|
#include "UnityCustomRenderTexture.cginc"
|
|
#pragma vertex ASECustomRenderTextureVertexShader
|
|
#pragma fragment frag
|
|
#pragma target 3.0
|
|
|
|
|
|
struct ase_appdata_customrendertexture
|
|
{
|
|
uint vertexID : SV_VertexID;
|
|
|
|
};
|
|
|
|
struct ase_v2f_customrendertexture
|
|
{
|
|
float4 vertex : SV_POSITION;
|
|
float3 localTexcoord : TEXCOORD0; // Texcoord local to the update zone (== globalTexcoord if no partial update zone is specified)
|
|
float3 globalTexcoord : TEXCOORD1; // Texcoord relative to the complete custom texture
|
|
uint primitiveID : TEXCOORD2; // Index of the update zone (correspond to the index in the updateZones of the Custom Texture)
|
|
float3 direction : TEXCOORD3; // For cube textures, direction of the pixel being rendered in the cubemap
|
|
|
|
};
|
|
|
|
uniform sampler2D _NiloToonPrepassBufferTex;
|
|
uniform float4 _NiloToonPrepassBufferTex_ST;
|
|
|
|
|
|
ase_v2f_customrendertexture ASECustomRenderTextureVertexShader(ase_appdata_customrendertexture IN )
|
|
{
|
|
ase_v2f_customrendertexture OUT;
|
|
|
|
#if UNITY_UV_STARTS_AT_TOP
|
|
const float2 vertexPositions[6] =
|
|
{
|
|
{ -1.0f, 1.0f },
|
|
{ -1.0f, -1.0f },
|
|
{ 1.0f, -1.0f },
|
|
{ 1.0f, 1.0f },
|
|
{ -1.0f, 1.0f },
|
|
{ 1.0f, -1.0f }
|
|
};
|
|
|
|
const float2 texCoords[6] =
|
|
{
|
|
{ 0.0f, 0.0f },
|
|
{ 0.0f, 1.0f },
|
|
{ 1.0f, 1.0f },
|
|
{ 1.0f, 0.0f },
|
|
{ 0.0f, 0.0f },
|
|
{ 1.0f, 1.0f }
|
|
};
|
|
#else
|
|
const float2 vertexPositions[6] =
|
|
{
|
|
{ 1.0f, 1.0f },
|
|
{ -1.0f, -1.0f },
|
|
{ -1.0f, 1.0f },
|
|
{ -1.0f, -1.0f },
|
|
{ 1.0f, 1.0f },
|
|
{ 1.0f, -1.0f }
|
|
};
|
|
|
|
const float2 texCoords[6] =
|
|
{
|
|
{ 1.0f, 1.0f },
|
|
{ 0.0f, 0.0f },
|
|
{ 0.0f, 1.0f },
|
|
{ 0.0f, 0.0f },
|
|
{ 1.0f, 1.0f },
|
|
{ 1.0f, 0.0f }
|
|
};
|
|
#endif
|
|
|
|
uint primitiveID = IN.vertexID / 6;
|
|
uint vertexID = IN.vertexID % 6;
|
|
float3 updateZoneCenter = CustomRenderTextureCenters[primitiveID].xyz;
|
|
float3 updateZoneSize = CustomRenderTextureSizesAndRotations[primitiveID].xyz;
|
|
float rotation = CustomRenderTextureSizesAndRotations[primitiveID].w * UNITY_PI / 180.0f;
|
|
|
|
#if !UNITY_UV_STARTS_AT_TOP
|
|
rotation = -rotation;
|
|
#endif
|
|
|
|
// Normalize rect if needed
|
|
if (CustomRenderTextureUpdateSpace > 0.0) // Pixel space
|
|
{
|
|
// Normalize xy because we need it in clip space.
|
|
updateZoneCenter.xy /= _CustomRenderTextureInfo.xy;
|
|
updateZoneSize.xy /= _CustomRenderTextureInfo.xy;
|
|
}
|
|
else // normalized space
|
|
{
|
|
// Un-normalize depth because we need actual slice index for culling
|
|
updateZoneCenter.z *= _CustomRenderTextureInfo.z;
|
|
updateZoneSize.z *= _CustomRenderTextureInfo.z;
|
|
}
|
|
|
|
// Compute rotation
|
|
|
|
// Compute quad vertex position
|
|
float2 clipSpaceCenter = updateZoneCenter.xy * 2.0 - 1.0;
|
|
float2 pos = vertexPositions[vertexID] * updateZoneSize.xy;
|
|
pos = CustomRenderTextureRotate2D(pos, rotation);
|
|
pos.x += clipSpaceCenter.x;
|
|
#if UNITY_UV_STARTS_AT_TOP
|
|
pos.y += clipSpaceCenter.y;
|
|
#else
|
|
pos.y -= clipSpaceCenter.y;
|
|
#endif
|
|
|
|
// For 3D texture, cull quads outside of the update zone
|
|
// This is neeeded in additional to the preliminary minSlice/maxSlice done on the CPU because update zones can be disjointed.
|
|
// ie: slices [1..5] and [10..15] for two differents zones so we need to cull out slices 0 and [6..9]
|
|
if (CustomRenderTextureIs3D > 0.0)
|
|
{
|
|
int minSlice = (int)(updateZoneCenter.z - updateZoneSize.z * 0.5);
|
|
int maxSlice = minSlice + (int)updateZoneSize.z;
|
|
if (_CustomRenderTexture3DSlice < minSlice || _CustomRenderTexture3DSlice >= maxSlice)
|
|
{
|
|
pos.xy = float2(1000.0, 1000.0); // Vertex outside of ncs
|
|
}
|
|
}
|
|
|
|
OUT.vertex = float4(pos, 0.0, 1.0);
|
|
OUT.primitiveID = asuint(CustomRenderTexturePrimitiveIDs[primitiveID]);
|
|
OUT.localTexcoord = float3(texCoords[vertexID], CustomRenderTexture3DTexcoordW);
|
|
OUT.globalTexcoord = float3(pos.xy * 0.5 + 0.5, CustomRenderTexture3DTexcoordW);
|
|
#if UNITY_UV_STARTS_AT_TOP
|
|
OUT.globalTexcoord.y = 1.0 - OUT.globalTexcoord.y;
|
|
#endif
|
|
OUT.direction = CustomRenderTextureComputeCubeDirection(OUT.globalTexcoord.xy);
|
|
|
|
return OUT;
|
|
}
|
|
|
|
float4 frag(ase_v2f_customrendertexture IN ) : COLOR
|
|
{
|
|
float4 finalColor;
|
|
float2 uv_NiloToonPrepassBufferTex = IN.localTexcoord.xy * _NiloToonPrepassBufferTex_ST.xy + _NiloToonPrepassBufferTex_ST.zw;
|
|
float4 tex2DNode2 = tex2D( _NiloToonPrepassBufferTex, uv_NiloToonPrepassBufferTex );
|
|
float4 appendResult3 = (float4(tex2DNode2.g , tex2DNode2.g , tex2DNode2.g , tex2DNode2.g));
|
|
|
|
finalColor = appendResult3;
|
|
return finalColor;
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
CustomEditor "ASEMaterialInspector"
|
|
Fallback Off
|
|
}
|
|
/*ASEBEGIN
|
|
Version=19701
|
|
Node;AmplifyShaderEditor.SamplerNode;2;-528,-144;Inherit;True;Global;_NiloToonPrepassBufferTex;_NiloToonPrepassBufferTex;0;0;Create;True;0;0;0;False;0;False;-1;None;;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;6;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4;FLOAT3;5
|
|
Node;AmplifyShaderEditor.DynamicAppendNode;3;-77,36;Inherit;False;FLOAT4;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;1;False;1;FLOAT4;0
|
|
Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;96,48;Float;False;True;-1;2;ASEMaterialInspector;0;2;Alpha Screen Shadow;32120270d1b3a8746af2aca8bc749736;True;Custom RT Update;0;0;Custom RT Update;1;False;True;0;1;False;;0;False;;0;1;False;;0;False;;True;0;False;;0;False;;False;False;False;False;False;False;False;False;False;True;0;False;;False;True;0;False;;False;True;True;True;True;True;0;False;;False;False;False;False;False;False;False;True;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;False;True;1;False;;True;3;False;;True;True;0;False;;0;False;;True;0;True;2;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;2;False;0;;0;0;Standard;0;0;1;True;False;;False;0
|
|
WireConnection;3;0;2;2
|
|
WireConnection;3;1;2;2
|
|
WireConnection;3;2;2;2
|
|
WireConnection;3;3;2;2
|
|
WireConnection;0;0;3;0
|
|
ASEEND*/
|
|
//CHKSM=24E987DC86272F5393A670C8012CED05AFE73C4B |