Rasagar/Library/PackageCache/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassGS.template
2024-08-26 23:07:20 +03:00

130 lines
3.3 KiB
Plaintext

#pragma require geometry
#pragma vertex vert
#pragma geometry geom
#define VFX_NON_UNIFORM_SCALE VFX_LOCAL_SPACE
uint vert(uint id : SV_VertexID) : TEXCOORD0
{
return id;
}
#if VFX_PRIMITIVE_TRIANGLE
#define VERTEX_COUNT 3
#elif VFX_PRIMITIVE_QUAD
#define VERTEX_COUNT 4
#elif VFX_PRIMITIVE_OCTAGON
#define VERTEX_COUNT 8
#endif
[maxvertexcount(VERTEX_COUNT)]
void geom(point uint intStream[1] : TEXCOORD0,inout TriangleStream<VFX_VARYING_PS_INPUTS> outStream)
{
uint index = intStream[0];
${VFXLoadAttributesOrCull}
${VFXProcessBlocks}
if (!attributes.alive)
return;
${VFXLoadSize}
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);
VFX_VARYING_PS_INPUTS o = (VFX_VARYING_PS_INPUTS)0;
#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
#ifdef VFX_VARYING_NORMAL
float normalFlip = (size3.x * size3.y * size3.z) < 0 ? -1 : 1;
o.VFX_VARYING_NORMAL = normalFlip * normalize(TransformNormalVFXToWorld(normalize(-transpose(elementToVFX_N)[2].xyz)));
#endif
#ifdef VFX_VARYING_TANGENT
o.VFX_VARYING_TANGENT = normalize(TransformDirectionVFXToWorld(normalize(transpose(elementToVFX)[0].xyz)));
#endif
[unroll]
for (int id = 0; id < VERTEX_COUNT; ++id)
{
float2 varyingUV = (float2)0.0f;
#if VFX_PRIMITIVE_QUAD
varyingUV.x = float(id & 1);
varyingUV.y = (id & 2) * 0.5f;
const float2 vOffsets = varyingUV.xy - 0.5f;
#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];
varyingUV.xy = (vOffsets * kUVScale) + 0.5f;
#elif VFX_PRIMITIVE_OCTAGON
// TODO Not working at the moment. Order of strips has to be fixed
// But need to fine a nice way to know whether a vertex needs displacement or not (cannot use & 1)
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;
varyingUV.xy = vOffsets + 0.5f;
#endif
const float3 vPos = mul(elementToVFX,float4(vOffsets,0.0f,1.0f)).xyz;
o.VFX_VARYING_POSCS = TransformPositionVFXToClip(vPos);
#ifdef VFX_VARYING_UV
o.VFX_VARYING_UV.xy = varyingUV;
#endif
#ifdef VFX_VARYING_BENTFACTORS
${VFXLoadParameter:{normalBendingFactor}}
o.VFX_VARYING_BENTFACTORS = vOffsets * normalBendingFactor;
#endif
${VFXVertexCommonProcess}
${VFXVertexSetFlipbooksInterpolants}
${VFXVertexAdditionalProcess}
outStream.Append(o);
}
}