187 lines
5.6 KiB
HLSL
187 lines
5.6 KiB
HLSL
|
|
||
|
#ifndef URP_UNLIT_FORWARD_PASS_INCLUDED
|
||
|
#define URP_UNLIT_FORWARD_PASS_INCLUDED
|
||
|
|
||
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl"
|
||
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||
|
|
||
|
struct Attributes
|
||
|
{
|
||
|
float4 positionOS : POSITION;
|
||
|
float2 uv : TEXCOORD0;
|
||
|
|
||
|
float3 normalOS : NORMAL;
|
||
|
float4 tangentOS : TANGENT;
|
||
|
|
||
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||
|
};
|
||
|
|
||
|
struct Varyings
|
||
|
{
|
||
|
float2 uv : TEXCOORD0;
|
||
|
float fogCoord : TEXCOORD1;
|
||
|
float4 positionCS : SV_POSITION;
|
||
|
|
||
|
float3 positionWS : TEXCOORD2;
|
||
|
float3 normalWS : TEXCOORD3;
|
||
|
float3 viewDirWS : TEXCOORD4;
|
||
|
|
||
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||
|
UNITY_VERTEX_OUTPUT_STEREO
|
||
|
|
||
|
//Advanced Dissolve
|
||
|
ADVANCED_DISSOLVE_UV(5)
|
||
|
};
|
||
|
|
||
|
void InitializeInputData(Varyings input, out InputData inputData)
|
||
|
{
|
||
|
inputData = (InputData)0;
|
||
|
|
||
|
inputData.positionWS = input.positionWS;
|
||
|
inputData.normalWS = input.normalWS;
|
||
|
inputData.viewDirectionWS = input.viewDirWS;
|
||
|
|
||
|
inputData.shadowCoord = 0;
|
||
|
inputData.fogCoord = 0;
|
||
|
inputData.vertexLighting = half3(0, 0, 0);
|
||
|
inputData.bakedGI = half3(0, 0, 0);
|
||
|
inputData.normalizedScreenSpaceUV = 0;
|
||
|
inputData.shadowMask = half4(1, 1, 1, 1);
|
||
|
}
|
||
|
|
||
|
Varyings UnlitPassVertex(Attributes input)
|
||
|
{
|
||
|
Varyings output = (Varyings)0;
|
||
|
|
||
|
UNITY_SETUP_INSTANCE_ID(input);
|
||
|
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||
|
|
||
|
|
||
|
#if defined(CURVEDWORLD_IS_INSTALLED) && !defined(CURVEDWORLD_DISABLED_ON)
|
||
|
#ifdef CURVEDWORLD_NORMAL_TRANSFORMATION_ON
|
||
|
CURVEDWORLD_TRANSFORM_VERTEX_AND_NORMAL(input.positionOS, input.normalOS, input.tangentOS)
|
||
|
#else
|
||
|
CURVEDWORLD_TRANSFORM_VERTEX(input.positionOS)
|
||
|
#endif
|
||
|
#endif
|
||
|
|
||
|
|
||
|
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||
|
|
||
|
output.positionCS = vertexInput.positionCS;
|
||
|
output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
|
||
|
#if defined(_FOG_FRAGMENT)
|
||
|
output.fogCoord = vertexInput.positionVS.z;
|
||
|
#else
|
||
|
output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z);
|
||
|
#endif
|
||
|
|
||
|
|
||
|
// normalWS and tangentWS already normalize.
|
||
|
// this is required to avoid skewing the direction during interpolation
|
||
|
// also required for per-vertex lighting and SH evaluation
|
||
|
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
|
||
|
half3 viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS);
|
||
|
|
||
|
// already normalized from normal transform to WS.
|
||
|
output.positionWS = vertexInput.positionWS;
|
||
|
output.normalWS = normalInput.normalWS;
|
||
|
output.viewDirWS = viewDirWS;
|
||
|
|
||
|
|
||
|
//Advanced Dissolve
|
||
|
ADVANCED_DISSOLVE_INIT_UV(output, input.uv, output.positionCS)
|
||
|
|
||
|
|
||
|
return output;
|
||
|
}
|
||
|
|
||
|
half4 UnlitPassFragment(Varyings input) : SV_Target
|
||
|
{
|
||
|
UNITY_SETUP_INSTANCE_ID(input);
|
||
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||
|
|
||
|
|
||
|
//Advanced Dissolve////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
#if defined(_AD_STATE_ENABLED)
|
||
|
|
||
|
float4 dissolveBase = 0;
|
||
|
#if defined(_AD_CUTOUT_STANDARD_SOURCE_BASE_ALPHA) || defined(_AD_EDGE_ADDITIONAL_COLOR_BASE_COLOR)
|
||
|
dissolveBase = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv);
|
||
|
dissolveBase.rgb *= _BaseColor.rgb;
|
||
|
#endif
|
||
|
|
||
|
ADVANCED_DISSOLVE_SETUP_CUTOUT_SOURCE_USING_WS(input, dissolveBase, input.positionWS.xyz, input.normalWS.xyz)
|
||
|
|
||
|
#if !defined(_ALPHATEST_ON)
|
||
|
AdvancedDissolveClip(cutoutSource);
|
||
|
#endif
|
||
|
|
||
|
float3 dissolveAlbedo = 0;
|
||
|
float3 dissolveEmission = 0;
|
||
|
float dissolveBlend = AdvancedDissolveAlbedoEmission(cutoutSource, dissolveBase, dissolveAlbedo, dissolveEmission, input.uv);
|
||
|
|
||
|
#endif
|
||
|
//Advanced Dissolve/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
|
||
|
half2 uv = input.uv;
|
||
|
half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv);
|
||
|
half3 color = texColor.rgb * _BaseColor.rgb;
|
||
|
half alpha = texColor.a * _BaseColor.a;
|
||
|
|
||
|
half cutout = _Cutoff;
|
||
|
//Advanced Dissolve/////////////////////////////////////////
|
||
|
#if defined(_AD_STATE_ENABLED)
|
||
|
AdvancedDissolveCalculateAlphaAndClip(cutoutSource, alpha, cutout);
|
||
|
#endif
|
||
|
|
||
|
AlphaDiscard(alpha, cutout);
|
||
|
|
||
|
|
||
|
//Advanced Dissolve/////////////////////////////////////////
|
||
|
#if defined(_AD_STATE_ENABLED)
|
||
|
color.rgb = lerp(color.rgb, dissolveAlbedo, dissolveBlend);
|
||
|
color.rgb += dissolveEmission * dissolveBlend;
|
||
|
#endif
|
||
|
|
||
|
|
||
|
#if defined(_ALPHAPREMULTIPLY_ON)
|
||
|
color *= alpha;
|
||
|
#endif
|
||
|
|
||
|
InputData inputData;
|
||
|
InitializeInputData(input, inputData);
|
||
|
SETUP_DEBUG_TEXTURE_DATA(inputData, input.uv, _BaseMap);
|
||
|
|
||
|
#ifdef _DBUFFER
|
||
|
ApplyDecalToBaseColor(input.positionCS, color);
|
||
|
#endif
|
||
|
|
||
|
#if defined(_FOG_FRAGMENT)
|
||
|
#if (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
|
||
|
float viewZ = -input.fogCoord;
|
||
|
float nearToFarZ = max(viewZ - _ProjectionParams.y, 0);
|
||
|
half fogFactor = ComputeFogFactorZ0ToFar(nearToFarZ);
|
||
|
#else
|
||
|
half fogFactor = 0;
|
||
|
#endif
|
||
|
#else
|
||
|
half fogFactor = input.fogCoord;
|
||
|
#endif
|
||
|
half4 finalColor = UniversalFragmentUnlit(inputData, color, alpha);
|
||
|
|
||
|
#if defined(_SCREEN_SPACE_OCCLUSION) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
||
|
float2 normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
|
||
|
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(normalizedScreenSpaceUV);
|
||
|
finalColor.rgb *= aoFactor.directAmbientOcclusion;
|
||
|
#endif
|
||
|
|
||
|
finalColor.rgb = MixFog(finalColor.rgb, fogFactor);
|
||
|
|
||
|
return finalColor;
|
||
|
}
|
||
|
|
||
|
#endif
|