75 lines
2.5 KiB
HLSL
75 lines
2.5 KiB
HLSL
#ifndef UNIVERSAL_PARTICLES_SHADOW_CASTER_PASS_INCLUDED
|
|
#define UNIVERSAL_PARTICLES_SHADOW_CASTER_PASS_INCLUDED
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
|
|
|
float3 _LightDirection;
|
|
float3 _LightPosition;
|
|
|
|
VaryingsShadowCasterParticle ShadowCasterParticlesVertex(AttributesShadowCasterParticle input)
|
|
{
|
|
VaryingsShadowCasterParticle output = (VaryingsShadowCasterParticle)0;
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
|
|
|
float3 positionWS = GetParticleVertexPositionInputs(input.positionOS.xyz).positionWS;
|
|
float3 normalWS = GetParticleVertexNormalInputs(input.normalOS).normalWS;
|
|
|
|
#if _CASTING_PUNCTUAL_LIGHT_SHADOW
|
|
float3 lightDirectionWS = normalize(_LightPosition - positionWS);
|
|
#else
|
|
float3 lightDirectionWS = _LightDirection;
|
|
#endif
|
|
|
|
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
|
|
output.positionCS = ApplyShadowClamping(positionCS);
|
|
|
|
#if defined(_ALPHATEST_ON)
|
|
output.color = GetParticleColor(input.color);
|
|
|
|
#if defined(_FLIPBOOKBLENDING_ON)
|
|
#if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
|
|
GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords.xyxy, 0.0);
|
|
#else
|
|
GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords, input.texcoordBlend);
|
|
#endif
|
|
#else
|
|
GetParticleTexcoords(output.texcoord, input.texcoords.xy);
|
|
#endif
|
|
#endif
|
|
|
|
return output;
|
|
}
|
|
|
|
half4 ShadowCasterParticlesFragment(VaryingsShadowCasterParticle input) : SV_TARGET
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
|
|
|
#if defined(_ALPHATEST_ON)
|
|
float2 uv = input.texcoord;
|
|
half4 vertexColor = input.color;
|
|
half4 baseColor = _BaseColor;
|
|
|
|
#if defined(_FLIPBOOKBLENDING_ON)
|
|
float3 blendUv = input.texcoord2AndBlend;
|
|
#else
|
|
float3 blendUv = float3(0, 0, 0);
|
|
#endif
|
|
|
|
half4 albedo = BlendTexture(UnityBuildTexture2DStructNoScaleNoTexelSize(_BaseMap), uv, blendUv) * baseColor;
|
|
half4 colorAddSubDiff = half4(0, 0, 0, 0);
|
|
#if defined(_COLORADDSUBDIFF_ON)
|
|
colorAddSubDiff = _BaseColorAddSubDiff;
|
|
#endif
|
|
albedo = MixParticleColor(albedo, vertexColor, colorAddSubDiff);
|
|
AlphaDiscard(albedo.a, _Cutoff);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
#endif // UNIVERSAL_PARTICLES_SHADOW_CASTER_PASS_INCLUDED
|