164 lines
6.3 KiB
HLSL
164 lines
6.3 KiB
HLSL
#ifndef UNIVERSAL_PARTICLES_GBUFFER_SIMPLE_LIT_PASS_INCLUDED
|
|
#define UNIVERSAL_PARTICLES_GBUFFER_SIMPLE_LIT_PASS_INCLUDED
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
|
|
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
|
|
|
|
void InitializeInputData(VaryingsParticle input, half3 normalTS, out InputData inputData)
|
|
{
|
|
inputData = (InputData)0;
|
|
|
|
inputData.positionWS = input.positionWS.xyz;
|
|
inputData.positionCS = input.clipPos;
|
|
|
|
#ifdef _NORMALMAP
|
|
half3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w);
|
|
inputData.normalWS = TransformTangentToWorld(normalTS,
|
|
half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
|
|
#else
|
|
half3 viewDirWS = input.viewDirWS;
|
|
inputData.normalWS = input.normalWS;
|
|
#endif
|
|
|
|
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
|
|
|
|
viewDirWS = SafeNormalize(viewDirWS);
|
|
|
|
inputData.viewDirectionWS = viewDirWS;
|
|
|
|
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
|
inputData.shadowCoord = input.shadowCoord;
|
|
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
|
|
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
|
|
#else
|
|
inputData.shadowCoord = float4(0, 0, 0, 0);
|
|
#endif
|
|
|
|
inputData.fogCoord = 0; // not used for deferred shading
|
|
inputData.vertexLighting = half3(0.0h, 0.0h, 0.0h);
|
|
#if !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
|
|
inputData.bakedGI = SAMPLE_GI(input.vertexSH,
|
|
GetAbsolutePositionWS(inputData.positionWS),
|
|
inputData.normalWS,
|
|
inputData.viewDirectionWS,
|
|
input.clipPos.xy,
|
|
input.probeOcclusion,
|
|
inputData.shadowMask);
|
|
#else
|
|
inputData.bakedGI = SampleSHPixel(input.vertexSH, inputData.normalWS);
|
|
#endif
|
|
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.clipPos);
|
|
inputData.shadowMask = half4(1, 1, 1, 1);
|
|
|
|
#if defined(DEBUG_DISPLAY) && !defined(PARTICLES_EDITOR_META_PASS)
|
|
inputData.vertexSH = input.vertexSH;
|
|
#endif
|
|
|
|
#if defined(DEBUG_DISPLAY) && defined(USE_APV_PROBE_OCCLUSION)
|
|
inputData.probeOcclusion = input.probeOcclusion;
|
|
#endif
|
|
}
|
|
|
|
inline void InitializeParticleSimpleLitSurfaceData(VaryingsParticle input, out SurfaceData outSurfaceData)
|
|
{
|
|
outSurfaceData = (SurfaceData)0;
|
|
|
|
ParticleParams particleParams;
|
|
InitParticleParams(input, particleParams);
|
|
|
|
outSurfaceData.normalTS = SampleNormalTS(particleParams.uv, particleParams.blendUv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap));
|
|
half4 albedo = SampleAlbedo(TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap), particleParams);
|
|
outSurfaceData.albedo = AlphaModulate(albedo.rgb, albedo.a);
|
|
outSurfaceData.alpha = albedo.a;
|
|
#if defined(_EMISSION)
|
|
outSurfaceData.emission = BlendTexture(TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap), particleParams.uv, particleParams.blendUv).rgb * _EmissionColor.rgb;
|
|
#else
|
|
outSurfaceData.emission = half3(0, 0, 0);
|
|
#endif
|
|
half4 specularGloss = SampleSpecularSmoothness(particleParams.uv, particleParams.blendUv, albedo.a, _SpecColor, TEXTURE2D_ARGS(_SpecGlossMap, sampler_SpecGlossMap));
|
|
outSurfaceData.specular = specularGloss.rgb;
|
|
outSurfaceData.smoothness = specularGloss.a;
|
|
|
|
#if defined(_DISTORTION_ON)
|
|
outSurfaceData.albedo = Distortion(half4(outSurfaceData.albedo, outSurfaceData.alpha), outSurfaceData.normalTS, _DistortionStrengthScaled, _DistortionBlend, projectedPosition);
|
|
#endif
|
|
|
|
outSurfaceData.metallic = 0.0; // unused
|
|
outSurfaceData.occlusion = 1.0;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// Vertex and Fragment functions //
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
VaryingsParticle ParticlesLitGBufferVertex(AttributesParticle input)
|
|
{
|
|
VaryingsParticle output;
|
|
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
|
|
|
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
|
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
|
|
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(vertexInput.positionWS);
|
|
|
|
#ifdef _NORMALMAP
|
|
output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
|
|
output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
|
|
output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
|
|
#else
|
|
output.normalWS = half3(normalInput.normalWS);
|
|
output.viewDirWS = viewDirWS;
|
|
#endif
|
|
|
|
OUTPUT_SH4(vertexInput.positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), output.vertexSH, output.probeOcclusion);
|
|
|
|
output.positionWS.xyz = vertexInput.positionWS.xyz;
|
|
output.positionWS.w = 0;
|
|
output.clipPos = vertexInput.positionCS;
|
|
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
|
|
|
|
#if defined(_SOFTPARTICLES_ON) || defined(_FADING_ON) || defined(_DISTORTION_ON)
|
|
output.projectedPosition = vertexInput.positionNDC;
|
|
#endif
|
|
|
|
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
|
output.shadowCoord = GetShadowCoord(vertexInput);
|
|
#endif
|
|
|
|
return output;
|
|
}
|
|
|
|
|
|
FragmentOutput ParticlesLitGBufferFragment(VaryingsParticle input)
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
|
|
|
SurfaceData surfaceData;
|
|
InitializeParticleSimpleLitSurfaceData(input, surfaceData);
|
|
|
|
InputData inputData;
|
|
InitializeInputData(input, surfaceData.normalTS, inputData);
|
|
SETUP_DEBUG_TEXTURE_DATA_FOR_TEX(inputData, input.texcoord, _BaseMap);
|
|
|
|
half4 color = half4(inputData.bakedGI * surfaceData.albedo + surfaceData.emission, surfaceData.alpha);
|
|
|
|
return SurfaceDataToGbuffer(surfaceData, inputData, color.rgb, kLightingSimpleLit);
|
|
|
|
}
|
|
|
|
#endif // UNIVERSAL_PARTICLES_GBUFFER_SIMPLE_LIT_PASS_INCLUDED
|