179 lines
4.7 KiB
Plaintext

#if defined(HAS_STRIPS) && !defined(VFX_PRIMITIVE_QUAD)
#error VFX_PRIMITIVE_QUAD must be defined when HAS_STRIPS is.
#endif
#define VFX_NON_UNIFORM_SCALE VFX_LOCAL_SPACE
struct vs_input
{
VFX_DECLARE_INSTANCE_ID
};
#if HAS_STRIPS
#define PARTICLE_IN_EDGE (id & 1)
${VFXDeclareGetStripTangent}
#endif
#pragma vertex vert
VFX_VARYING_PS_INPUTS vert(uint id : SV_VertexID, vs_input i)
{
VFX_VARYING_PS_INPUTS o = (VFX_VARYING_PS_INPUTS)0;
UNITY_SETUP_INSTANCE_ID(i);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if VFX_PRIMITIVE_TRIANGLE
uint index = id / 3;
#elif VFX_PRIMITIVE_QUAD
#if HAS_STRIPS
id += VFX_GET_INSTANCE_ID(i) * 8192;
const uint vertexPerStripCount = (PARTICLE_PER_STRIP_COUNT - 1) << 2;
const StripData stripData = GetStripDataFromStripIndex(id / vertexPerStripCount, PARTICLE_PER_STRIP_COUNT);
uint relativeIndexInStrip = ((id % vertexPerStripCount) >> 2) + (id & 1); // relative index of particle
uint maxEdgeIndex = relativeIndexInStrip - PARTICLE_IN_EDGE + 1;
if (maxEdgeIndex >= stripData.nextIndex)
return o;
uint index = GetParticleIndex(relativeIndexInStrip, stripData);
#else
uint index = (id >> 2) + VFX_GET_INSTANCE_ID(i) * 2048;
#endif
#elif VFX_PRIMITIVE_OCTAGON
uint index = (id >> 3) + VFX_GET_INSTANCE_ID(i) * 1024;
#endif
${VFXLoadAttributesOrCull}
${VFXProcessBlocks}
#if !HAS_STRIPS
if (!attributes.alive)
return o;
#endif
#if VFX_PRIMITIVE_QUAD
#if HAS_STRIPS
#if VFX_STRIPS_UV_STRECHED
o.VFX_VARYING_UV.x = (float)(relativeIndexInStrip) / (stripData.nextIndex - 1);
#elif VFX_STRIPS_UV_PER_SEGMENT
o.VFX_VARYING_UV.x = PARTICLE_IN_EDGE;
#else
${VFXLoadParameter:{texCoord}}
o.VFX_VARYING_UV.x = texCoord;
#endif
o.VFX_VARYING_UV.y = (id & 2) * 0.5f;
const float2 vOffsets = float2(0.0f,o.VFX_VARYING_UV.y - 0.5f);
#if VFX_STRIPS_SWAP_UV
o.VFX_VARYING_UV.xy = float2(1.0f - o.VFX_VARYING_UV.y, o.VFX_VARYING_UV.x);
#endif
#else
o.VFX_VARYING_UV.x = float(id & 1);
o.VFX_VARYING_UV.y = (id & 2) * 0.5f;
const float2 vOffsets = o.VFX_VARYING_UV.xy - 0.5f;
#endif
#elif VFX_PRIMITIVE_TRIANGLE
const float2 kOffsets[] = {
float2(-0.5f, -0.288675129413604736328125f),
float2(0.0f, 0.57735025882720947265625f),
float2(0.5f, -0.288675129413604736328125f),
};
const float kUVScale = 0.866025388240814208984375f;
const float2 vOffsets = kOffsets[id % 3];
o.VFX_VARYING_UV.xy = (vOffsets * kUVScale) + 0.5f;
#elif VFX_PRIMITIVE_OCTAGON
const float2 kUvs[8] =
{
float2(-0.5f, 0.0f),
float2(-0.5f, 0.5f),
float2(0.0f, 0.5f),
float2(0.5f, 0.5f),
float2(0.5f, 0.0f),
float2(0.5f, -0.5f),
float2(0.0f, -0.5f),
float2(-0.5f, -0.5f),
};
${VFXLoadParameter:{cropFactor}}
cropFactor = id & 1 ? 1.0f - cropFactor : 1.0f;
const float2 vOffsets = kUvs[id & 7] * cropFactor;
o.VFX_VARYING_UV.xy = vOffsets + 0.5f;
#endif
${VFXLoadSize}
#if HAS_STRIPS
size3 += size3 < 0.0f ? -VFX_EPSILON : VFX_EPSILON; // Add an epsilon so that size is never 0 for strips
#endif
const float4x4 elementToVFX = GetElementToVFXMatrix(
attributes.axisX,
attributes.axisY,
attributes.axisZ,
float3(attributes.angleX,attributes.angleY,attributes.angleZ),
float3(attributes.pivotX,attributes.pivotY,attributes.pivotZ),
size3,
attributes.position);
float3 inputVertexPosition = float3(vOffsets, 0.0f);
float3 vPos = mul(elementToVFX,float4(inputVertexPosition, 1.0f)).xyz;
o.VFX_VARYING_POSCS = TransformPositionVFXToClip(vPos);
float3 vPosWS = TransformPositionVFXToWorld(vPos);
#ifdef VFX_VARYING_POSWS
o.VFX_VARYING_POSWS = vPosWS;
#endif
#if VFX_NON_UNIFORM_SCALE
float3x3 elementToVFX_N = GetElementToVFXMatrixNormal(
attributes.axisX,
attributes.axisY,
attributes.axisZ,
float3(attributes.angleX,attributes.angleY,attributes.angleZ),
size3);
#else
float3x3 elementToVFX_N = (float3x3)elementToVFX;
#endif
float3 normalWS = normalize(TransformNormalVFXToWorld((-transpose(elementToVFX_N)[2])));
#ifdef VFX_VARYING_NORMAL
float normalFlip = (size3.x * size3.y * size3.z) < 0 ? -1 : 1;
o.VFX_VARYING_NORMAL = normalFlip * normalWS;
#endif
#ifdef VFX_VARYING_TANGENT
o.VFX_VARYING_TANGENT = normalize(TransformDirectionVFXToWorld(normalize(transpose(elementToVFX)[0].xyz)));
#endif
#ifdef VFX_VARYING_BENTFACTORS
${VFXLoadParameter:{normalBendingFactor}}
#if HAS_STRIPS
#define BENT_FACTOR_MULTIPLIER 2.0f
#else
#define BENT_FACTOR_MULTIPLIER 1.41421353816986083984375f
#endif
o.VFX_VARYING_BENTFACTORS = vOffsets * normalBendingFactor * BENT_FACTOR_MULTIPLIER;
#endif
${VFXVertexComputeCurrentAndPreviousClipPos}
${VFXVertexCommonProcess}
${VFXVertexSetFlipbooksInterpolants}
${VFXVertexAdditionalProcess}
${VFXAdditionalInterpolantsGeneration}
return o;
}