forked from BilalY/Rasagar
184 lines
4.9 KiB
Plaintext
184 lines
4.9 KiB
Plaintext
#if !(defined(VFX_VARYING_PS_INPUTS) && defined(VFX_VARYING_POSCS))
|
|
#error VFX_VARYING_PS_INPUTS, VFX_VARYING_POSCS must be defined.
|
|
#endif
|
|
|
|
${VFXPerPassInclude}
|
|
${VFXGeneratedBlockFunction}
|
|
|
|
struct vs_input
|
|
{
|
|
VFX_DECLARE_INSTANCE_ID
|
|
};
|
|
|
|
#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);
|
|
|
|
uint index = (id >> 3) + VFX_GET_INSTANCE_ID(i) * 1024;
|
|
|
|
${VFXInitInstancing}
|
|
${VFXLoadGraphValues}
|
|
|
|
${VFXLoadContextData}
|
|
uint systemSeed = contextData.systemSeed;
|
|
uint nbMax = contextData.maxParticleCount;
|
|
|
|
${VFXLoadAttributesOrCull}
|
|
${VFXProcessBlocks}
|
|
|
|
if (!attributes.alive)
|
|
return o;
|
|
|
|
float3 offsets = (float3)0;
|
|
offsets.x = float(id & 1);
|
|
offsets.y = (id & 2) * 0.5f;
|
|
offsets.z = (id & 4) * 0.25f;
|
|
offsets -= 0.5f;
|
|
|
|
${VFXLoadSize}
|
|
|
|
float3x3 rot = GetEulerMatrix(radians(float3(attributes.angleX,attributes.angleY,attributes.angleZ)));
|
|
float4x4 elementToVFX = GetElementToVFXMatrix(
|
|
attributes.axisX,
|
|
attributes.axisY,
|
|
attributes.axisZ,
|
|
rot,
|
|
float3(attributes.pivotX,attributes.pivotY,attributes.pivotZ),
|
|
size3,
|
|
attributes.position);
|
|
|
|
float3 inputVertexPosition = offsets;
|
|
float3 vPos = mul(elementToVFX,float4(inputVertexPosition,1.0f)).xyz;
|
|
float3 vPosWS = TransformPositionVFXToWorld(vPos);
|
|
|
|
#ifdef VFX_VARYING_POSWS
|
|
o.VFX_VARYING_POSWS = vPosWS;
|
|
#endif
|
|
#ifdef VFX_VARYING_OFFSETS
|
|
o.VFX_VARYING_OFFSETS = offsets * 2.0f;
|
|
#endif
|
|
#ifdef VFX_VARYING_FACEID
|
|
o.VFX_VARYING_FACEID = (id & 7) % 5;
|
|
#endif
|
|
#if defined(VFX_VARYING_ROTX) && defined(VFX_VARYING_ROTY)
|
|
rot = mul(transpose(float3x3(attributes.axisX,attributes.axisY,attributes.axisZ)),rot);
|
|
#ifdef VFX_LOCAL_SPACE
|
|
rot = mul((float3x3)VFXGetObjectToWorldMatrix(),rot);
|
|
#endif
|
|
o.VFX_VARYING_ROTX = rot[0];
|
|
o.VFX_VARYING_ROTY = rot[1];
|
|
#endif
|
|
o.VFX_VARYING_POSCS = VFXTransformPositionWorldToClip(vPosWS);
|
|
|
|
${VFXVertexComputeCurrentAndPreviousClipPos}
|
|
|
|
${VFXVertexCommonProcess}
|
|
|
|
|
|
#if USE_UV_SCALE_BIAS && defined(VFX_VARYING_UV_SCALE) && defined(VFX_VARYING_UV_BIAS)
|
|
o.VFX_VARYING_UV_SCALE = uvScale;
|
|
o.VFX_VARYING_UV_BIAS = uvBias;
|
|
#endif
|
|
|
|
#if USE_FLIPBOOK
|
|
${VFXLoadParameter:{flipBookSize}}
|
|
${VFXLoadParameter:{invFlipBookSize}}
|
|
#ifdef VFX_VARYING_TEXINDEX
|
|
o.VFX_VARYING_TEXINDEX = attributes.texIndex;
|
|
#endif
|
|
#ifdef VFX_VARYING_TEXINDEXBLEND
|
|
o.VFX_VARYING_TEXINDEXBLEND = attributes.texIndexBlend;
|
|
#endif
|
|
|
|
#if defined(VFX_VARYING_FLIPBOOKSIZE)
|
|
o.VFX_VARYING_FLIPBOOKSIZE = flipBookSize;
|
|
#endif
|
|
#if defined(VFX_VARYING_INVFLIPBOOKSIZE)
|
|
o.VFX_VARYING_INVFLIPBOOKSIZE = invFlipBookSize;
|
|
#endif
|
|
#ifdef VFX_VARYING_TEXINDEX
|
|
#if USE_FLIPBOOK_MOTIONVECTORS && defined(VFX_VARYING_MOTIONVECTORSCALE)
|
|
${VFXLoadParameter:{motionVectorScale}}
|
|
#if USE_FLIPBOOK_ARRAY_LAYOUT
|
|
o.VFX_VARYING_MOTIONVECTORSCALE = motionVectorScale;
|
|
#else
|
|
o.VFX_VARYING_MOTIONVECTORSCALE = motionVectorScale * invFlipBookSize;
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
${VFXVertexAdditionalProcess}
|
|
|
|
return o;
|
|
}
|
|
|
|
float3 VFXCubeGetLocalNormal(VFX_VARYING_PS_INPUTS i)
|
|
{
|
|
#ifdef VFX_VARYING_OFFSETS
|
|
//float3 s = i.VFX_VARYING_OFFSETS > 0 ? 1.0f : -1.0f;
|
|
//return s * (step(1.0f,s * i.VFX_VARYING_OFFSETS + 1e-5));
|
|
return int3(i.VFX_VARYING_OFFSETS * 1.00001f); // cast uses round_z
|
|
#else
|
|
return 0.0f;
|
|
#endif
|
|
}
|
|
|
|
float3 VFXCubeTransformNormalTS(float3 faceNormal,float3 normal)
|
|
{
|
|
float3x3 tbn = float3x3(faceNormal.zyx,faceNormal.xzy,faceNormal.xyz);
|
|
return mul(tbn,normal);
|
|
}
|
|
|
|
float3 VFXCubeTransformNormalTS(VFX_VARYING_PS_INPUTS i,float3 normal,bool frontFace = true)
|
|
{
|
|
#if defined(VFX_VARYING_OFFSETS) && defined(VFX_VARYING_FACEID)
|
|
float3x3 tbn;
|
|
float3 faceNormal = VFXCubeGetLocalNormal(i);
|
|
if (i.VFX_VARYING_FACEID == 0)
|
|
tbn = float3x3(-faceNormal.zxy,faceNormal.yzx * faceNormal.yzx,faceNormal.xyz);
|
|
else if (i.VFX_VARYING_FACEID == 1)
|
|
tbn = float3x3(faceNormal.yxz, faceNormal.xzy, float3(0, 1, 0));
|
|
else
|
|
tbn = float3x3(faceNormal.yzx, float3(0,1,0),faceNormal.xyz);
|
|
#ifdef USE_DOUBLE_SIDED
|
|
float multiplier = frontFace ? 1.0f : -1.0f;
|
|
tbn[0] *= multiplier;
|
|
tbn[2] *= multiplier;
|
|
#endif
|
|
return mul(tbn, normal);
|
|
#else
|
|
return normal;
|
|
#endif
|
|
}
|
|
|
|
float3 VFXCubeTransformNormalWS(VFX_VARYING_PS_INPUTS i,float3 normal)
|
|
{
|
|
#if defined(VFX_VARYING_ROTX) && defined(VFX_VARYING_ROTY)
|
|
float3x3 rot = float3x3(i.rotX,i.rotY,cross(i.rotX,i.rotY));
|
|
return mul(rot,normal);
|
|
#else
|
|
return normal;
|
|
#endif
|
|
}
|
|
|
|
float2 VFXCubeGetUV(VFX_VARYING_PS_INPUTS i)
|
|
{
|
|
#if defined(VFX_VARYING_OFFSETS) && defined(VFX_VARYING_FACEID)
|
|
float2 uv;
|
|
if (i.VFX_VARYING_FACEID == 0)
|
|
uv = i.VFX_VARYING_OFFSETS.xy * float2(-i.VFX_VARYING_OFFSETS.z,1);
|
|
else if (i.VFX_VARYING_FACEID == 1)
|
|
uv = i.VFX_VARYING_OFFSETS.xz * float2(i.VFX_VARYING_OFFSETS.y,1);
|
|
else
|
|
uv = i.VFX_VARYING_OFFSETS.zy * float2(i.VFX_VARYING_OFFSETS.x,1);
|
|
return uv * 0.5f + 0.5f;
|
|
#else
|
|
return 0.0f;
|
|
#endif
|
|
}
|