#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 ${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 uint index = (id >> 2) + VFX_GET_INSTANCE_ID(i) * 2048; #elif VFX_PRIMITIVE_OCTAGON uint index = (id >> 3) + VFX_GET_INSTANCE_ID(i) * 1024; #endif ${VFXInitInstancing} ${VFXLoadGraphValues} ${VFXLoadContextData} uint systemSeed = contextData.systemSeed; uint nbMax = contextData.maxParticleCount; ${VFXLoadAttributesOrCull} ${VFXProcessBlocks} #if !HAS_STRIPS if (!attributes.alive) return o; #endif float2 varyingUV = (float2)0.0f; #if VFX_PRIMITIVE_QUAD #if HAS_STRIPS #if VFX_STRIPS_UV_STRECHED varyingUV.x = (float)(relativeIndexInStrip) / (stripData.nextIndex - 1); #elif VFX_STRIPS_UV_PER_SEGMENT varyingUV.x = STRIP_PARTICLE_IN_EDGE; #else ${VFXLoadParameter:{texCoord}} varyingUV.x = texCoord; #endif varyingUV.y = (id & 2) * 0.5f; const float2 vOffsets = float2(0.0f,varyingUV.y - 0.5f); #if VFX_STRIPS_SWAP_UV varyingUV.xy = float2(1.0f - varyingUV.y, varyingUV.x); #endif #else varyingUV.x = float(id & 1); varyingUV.y = (id & 2) * 0.5f; const float2 vOffsets = varyingUV.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]; varyingUV.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; varyingUV.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 #ifdef VFX_VARYING_UV o.VFX_VARYING_UV.xy = varyingUV; #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.xyz = 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; }