#ifndef CORE_PARTICLES_INCLUDED
#define CORE_PARTICLES_INCLUDED
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ParticlesInstancing.hlsl"
///
/// Core.Particles.GetParticleColor
/// Particle Color
/// Color
/// VFX/Particles
/// Color
/// Particle, Color
///
///
/// Color
///
///
UNITY_EXPORT_REFLECTION
half4 GetParticleColor(half4 color)
{
#if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
#if !defined(UNITY_PARTICLE_INSTANCE_DATA_NO_COLOR)
UNITY_PARTICLE_INSTANCE_DATA data = unity_ParticleInstanceData[unity_InstanceID];
color = lerp(half4(1.0, 1.0, 1.0, 1.0), color, unity_ParticleUseMeshColors);
color *= half4(UnpackFromR8G8B8A8(data.color));
#endif
#endif
return color;
}
void GetParticleTexcoords(out float2 outputTexcoord, out float3 outputTexcoord2AndBlend, in float4 inputTexcoords, in float inputBlend)
{
#if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
if (unity_ParticleUVShiftData.x != 0.0)
{
UNITY_PARTICLE_INSTANCE_DATA data = unity_ParticleInstanceData[unity_InstanceID];
float numTilesX = unity_ParticleUVShiftData.y;
float2 animScale = unity_ParticleUVShiftData.zw;
#ifdef UNITY_PARTICLE_INSTANCE_DATA_NO_ANIM_FRAME
float sheetIndex = 0.0;
#else
float sheetIndex = data.animFrame;
#endif
float index0 = floor(sheetIndex);
float vIdx0 = floor(index0 / numTilesX);
float uIdx0 = floor(index0 - vIdx0 * numTilesX);
float2 offset0 = float2(uIdx0 * animScale.x, (1.0 - animScale.y) - vIdx0 * animScale.y); // Copied from built-in as is and it looks like upside-down flip
outputTexcoord = inputTexcoords.xy * animScale.xy + offset0.xy;
#ifdef _FLIPBOOKBLENDING_ON
float index1 = floor(sheetIndex + 1.0);
float vIdx1 = floor(index1 / numTilesX);
float uIdx1 = floor(index1 - vIdx1 * numTilesX);
float2 offset1 = float2(uIdx1 * animScale.x, (1.0 - animScale.y) - vIdx1 * animScale.y);
outputTexcoord2AndBlend.xy = inputTexcoords.xy * animScale.xy + offset1.xy;
outputTexcoord2AndBlend.z = frac(sheetIndex);
#endif
}
else
#endif
{
outputTexcoord = inputTexcoords.xy;
#ifdef _FLIPBOOKBLENDING_ON
outputTexcoord2AndBlend.xy = inputTexcoords.zw;
outputTexcoord2AndBlend.z = inputBlend;
#endif
}
#ifndef _FLIPBOOKBLENDING_ON
outputTexcoord2AndBlend.xy = inputTexcoords.xy;
outputTexcoord2AndBlend.z = 0.5;
#endif
}
///
/// Core.Particles.GetParticleTexcoords
/// Flipbook
/// Core.Particles.TexCoords, 10, Particle Texcoords, Mode
/// VFX/Particles
/// Texcoords
/// Particle, Texcoords, UV
///
///
/// UV
///
/// UV0
///
///
/// UV
///
UNITY_EXPORT_REFLECTION
void GetParticleTexcoords(out float2 outputTexcoord, in float2 inputTexcoord)
{
float3 dummyTexcoord2AndBlend = 0.0;
GetParticleTexcoords(outputTexcoord, dummyTexcoord2AndBlend, inputTexcoord.xyxy, 0.0);
}
///
/// Core.Particles.TexCoordsFlipbookBlending
/// Flipbook Blending
/// Core.Particles.TexCoords
/// VFX/Particles
/// Particle, Flipbook, Texcoords, UV
///
///
/// UV
///
///
/// Blend Vertex Stream
///
///
/// UV
///
///
/// UV2
///
///
/// Blend
///
UNITY_EXPORT_REFLECTION
void GetParticleTexcoords(float4 inputTexcoord, float inputBlend, out float2 outputTexcoord, out float2 texcoord2, out float blend)
{
float3 dummyTexcoord2AndBlend = 0.0;
#if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
GetParticleTexcoords(outputTexcoord, dummyTexcoord2AndBlend, inputTexcoord, inputBlend);
#else
outputTexcoord = inputTexcoord.xy;
dummyTexcoord2AndBlend = float3(inputTexcoord.zw, inputBlend);
#endif
texcoord2 = dummyTexcoord2AndBlend.xy;
blend = dummyTexcoord2AndBlend.z;
}
///
/// Core.Particles.AnimFrame
/// Particle Anim Frame
/// VFX/Particles
/// Anim Frame
/// Particle, Anim, Frame
///
UNITY_EXPORT_REFLECTION
void GetParticleAnimFrame(inout float animFrame)
{
#if defined(UNITY_PARTICLE_INSTANCING_ENABLED) && !defined(UNITY_PARTICLE_INSTANCE_DATA_NO_ANIM_FRAME)
UNITY_PARTICLE_INSTANCE_DATA data = unity_ParticleInstanceData[unity_InstanceID];
animFrame = data.animFrame;
#endif
}
#endif // CORE_PARTICLES_INCLUDED