288 lines
8.7 KiB
Plaintext
288 lines
8.7 KiB
Plaintext
${VFXBegin:VFXVertexCommonProcess}
|
|
#if VFX_USE_COLOR_CURRENT && defined(VFX_VARYING_COLOR)
|
|
o.VFX_VARYING_COLOR = attributes.color;
|
|
#endif
|
|
#if VFX_USE_ALPHA_CURRENT && defined(VFX_VARYING_ALPHA)
|
|
o.VFX_VARYING_ALPHA = attributes.alpha;
|
|
#endif
|
|
|
|
#ifdef VFX_VARYING_EXPOSUREWEIGHT
|
|
${VFXLoadParameter:{exposureWeight}}
|
|
o.VFX_VARYING_EXPOSUREWEIGHT = exposureWeight;
|
|
#endif
|
|
|
|
#if USE_SOFT_PARTICLE && defined(VFX_VARYING_INVSOFTPARTICLEFADEDISTANCE)
|
|
${VFXLoadParameter:{invSoftParticlesFadeDistance}}
|
|
o.VFX_VARYING_INVSOFTPARTICLEFADEDISTANCE = invSoftParticlesFadeDistance;
|
|
#endif
|
|
|
|
#if (USE_ALPHA_TEST || VFX_FEATURE_MOTION_VECTORS_FORWARD) && (!VFX_SHADERGRAPH || !HAS_SHADERGRAPH_PARAM_ALPHACLIPTHRESHOLD) && defined(VFX_VARYING_ALPHATHRESHOLD)
|
|
${VFXLoadParameter:{alphaThreshold}}
|
|
o.VFX_VARYING_ALPHATHRESHOLD = alphaThreshold;
|
|
#endif
|
|
|
|
#if USE_UV_SCALE_BIAS
|
|
${VFXLoadParameter:{uvScale}}
|
|
${VFXLoadParameter:{uvBias}}
|
|
#if defined (VFX_VARYING_UV)
|
|
o.VFX_VARYING_UV.xy = o.VFX_VARYING_UV.xy * uvScale + uvBias;
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(VFX_VARYING_POSWS)
|
|
o.VFX_VARYING_POSWS = TransformPositionVFXToWorld(vPos);
|
|
#endif
|
|
${VFXEnd}
|
|
|
|
${VFXBegin:VFXLoadSize}
|
|
float3 size3 = float3(attributes.size,attributes.size,attributes.size);
|
|
#if VFX_USE_SCALEX_CURRENT
|
|
size3.x *= attributes.scaleX;
|
|
#endif
|
|
#if VFX_USE_SCALEY_CURRENT
|
|
size3.y *= attributes.scaleY;
|
|
#endif
|
|
#if VFX_USE_SCALEZ_CURRENT
|
|
size3.z *= attributes.scaleZ;
|
|
#endif
|
|
${VFXEnd}
|
|
|
|
${VFXBegin:VFXVertexSetFlipbooksInterpolants}
|
|
#if USE_FLIPBOOK && defined(VFX_VARYING_UV)
|
|
#if USE_FLIPBOOK_ARRAY_LAYOUT
|
|
${VFXLoadParameter:{flipBookSize}}
|
|
VFXUVData uvData = GetUVData(flipBookSize, o.VFX_VARYING_UV.xy, attributes.texIndex);
|
|
o.VFX_VARYING_UV.xyz = uvData.uvs.xyz;
|
|
#if USE_FLIPBOOK_INTERPOLATION && defined(VFX_VARYING_UV) && defined (VFX_VARYING_FRAMEBLEND)
|
|
o.VFX_VARYING_UV.w = uvData.uvs.w;
|
|
o.VFX_VARYING_FRAMEBLEND = uvData.blend;
|
|
#if USE_FLIPBOOK_MOTIONVECTORS && defined(VFX_VARYING_MOTIONVECTORSCALE)
|
|
${VFXLoadParameter:{motionVectorScale}}
|
|
o.VFX_VARYING_MOTIONVECTORSCALE = motionVectorScale;
|
|
#endif
|
|
#endif
|
|
#else
|
|
${VFXLoadParameter:{invFlipBookSize}}
|
|
${VFXLoadParameter:{flipBookSize}}
|
|
VFXUVData uvData = GetUVData(flipBookSize, invFlipBookSize, o.VFX_VARYING_UV.xy, attributes.texIndex);
|
|
o.VFX_VARYING_UV.xy = uvData.uvs.xy;
|
|
#if USE_FLIPBOOK_INTERPOLATION && defined(VFX_VARYING_UV) && defined (VFX_VARYING_FRAMEBLEND)
|
|
o.VFX_VARYING_UV.zw = uvData.uvs.zw;
|
|
o.VFX_VARYING_FRAMEBLEND = uvData.blend;
|
|
#if USE_FLIPBOOK_MOTIONVECTORS && defined(VFX_VARYING_MOTIONVECTORSCALE)
|
|
${VFXLoadParameter:{motionVectorScale}}
|
|
o.VFX_VARYING_MOTIONVECTORSCALE = motionVectorScale * invFlipBookSize;
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
${VFXEnd}
|
|
|
|
${VFXBegin:VFXFragmentCommonFunctions}#include "Packages/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl"${VFXEnd}
|
|
|
|
${VFXBegin:VFXLoadAttributesOrCull}
|
|
uint deadCount = 0;
|
|
#if USE_DEAD_LIST_COUNT
|
|
deadCount = deadListCount.Load(0);
|
|
#endif
|
|
if (index >= asuint(nbMax) - deadCount)
|
|
#if USE_GEOMETRY_SHADER
|
|
return; // cull
|
|
#else
|
|
return o; // cull
|
|
#endif
|
|
|
|
Attributes attributes = (Attributes)0;
|
|
SourceAttributes sourceAttributes = (SourceAttributes)0;
|
|
|
|
#if VFX_HAS_INDIRECT_DRAW
|
|
index = indirectBuffer[index];
|
|
${VFXLoadAttributes}
|
|
#else
|
|
${VFXLoadAttributes:{alive}}
|
|
#if !HAS_STRIPS
|
|
if (!attributes.alive)
|
|
return o;
|
|
#endif
|
|
|
|
${VFXLoadAttributes:{(?!(alive))(\b\w)}}
|
|
#endif
|
|
|
|
// Initialize built-in needed attributes
|
|
#if HAS_STRIPS
|
|
InitStripAttributes(index, attributes, stripData);
|
|
#endif
|
|
${VFXEnd}
|
|
|
|
${VFXBegin:VFXVertexComputeCurrentAndPreviousClipPos}
|
|
#if VFX_FEATURE_MOTION_VECTORS
|
|
#if defined(VFX_VARYING_VELOCITY_CPOS) && defined(VFX_VARYING_VELOCITY_CPOS_PREVIOUS)
|
|
#ifdef VFX_FEATURE_MOTION_VECTORS_VERTS
|
|
uint elementToVFXBaseIndex = index * (VFX_FEATURE_MOTION_VECTORS_VERTS * 2 + 1);
|
|
#else
|
|
uint elementToVFXBaseIndex = index * 13;
|
|
#endif
|
|
uint previousFrameIndex = elementToVFXBufferPrevious.Load(elementToVFXBaseIndex++ << 2);
|
|
o.VFX_VARYING_VELOCITY_CPOS = o.VFX_VARYING_VELOCITY_CPOS_PREVIOUS = float4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
if (asuint(currentFrameIndex) - previousFrameIndex == 1u) //if (dot(previousElementToVFX[0], 1) != 0)
|
|
{
|
|
#ifdef VFX_FEATURE_MOTION_VECTORS_VERTS
|
|
uint2 read = elementToVFXBufferPrevious.Load3((elementToVFXBaseIndex + (id % VFX_FEATURE_MOTION_VECTORS_VERTS) * 2) << 2);
|
|
o.VFX_VARYING_VELOCITY_CPOS_PREVIOUS.xy = asfloat(read);
|
|
o.VFX_VARYING_VELOCITY_CPOS = TransformPositionVFXToNonJitteredClip(vPos);
|
|
o.VFX_VARYING_VELOCITY_CPOS /= o.VFX_VARYING_VELOCITY_CPOS.w;
|
|
#else
|
|
float4x4 previousElementToVFX = (float4x4)0;
|
|
previousElementToVFX[3] = float4(0,0,0,1);
|
|
UNITY_UNROLL
|
|
for (int itIndexMatrixRow = 0; itIndexMatrixRow < 3; ++itIndexMatrixRow)
|
|
{
|
|
uint4 read = elementToVFXBufferPrevious.Load4((elementToVFXBaseIndex + itIndexMatrixRow * 4) << 2);
|
|
previousElementToVFX[itIndexMatrixRow] = asfloat(read);
|
|
}
|
|
float3 oldvPos = mul(previousElementToVFX, float4(inputVertexPosition, 1.0f)).xyz;
|
|
o.VFX_VARYING_VELOCITY_CPOS_PREVIOUS = TransformPositionVFXToPreviousClip(oldvPos);
|
|
o.VFX_VARYING_VELOCITY_CPOS = TransformPositionVFXToNonJitteredClip(vPos);
|
|
#endif
|
|
}
|
|
#endif
|
|
#endif
|
|
${VFXEnd}
|
|
|
|
${VFXBegin:VFXComputeOutputMotionVector}
|
|
float2 velocity = (i.VFX_VARYING_VELOCITY_CPOS.xy/i.VFX_VARYING_VELOCITY_CPOS.w) - (i.VFX_VARYING_VELOCITY_CPOS_PREVIOUS.xy/i.VFX_VARYING_VELOCITY_CPOS_PREVIOUS.w);
|
|
#if UNITY_UV_STARTS_AT_TOP
|
|
velocity.y = -velocity.y;
|
|
#endif
|
|
float4 encodedMotionVector = 0.0f;
|
|
VFXEncodeMotionVector(velocity * 0.5f, encodedMotionVector);
|
|
${VFXEnd}
|
|
|
|
${VFXBegin:VFXApplyColor}
|
|
|
|
float4 color = VFXGetFragmentColor(i);
|
|
|
|
#ifndef VFX_TEXTURE_COLOR
|
|
#define VFX_TEXTURE_COLOR float4(1.0,1.0,1.0,1.0)
|
|
#endif
|
|
|
|
#if VFX_COLORMAPPING_DEFAULT
|
|
o.color = color * VFX_TEXTURE_COLOR;
|
|
#endif
|
|
|
|
#if VFX_COLORMAPPING_GRADIENTMAPPED
|
|
${VFXLoadAttributes:{gradient}}
|
|
o.color = SampleGradient(gradient, VFX_TEXTURE_COLOR.a * color.a) * float4(color.rgb,1.0);
|
|
#endif
|
|
|
|
${VFXEnd}
|
|
|
|
${VFXBegin:VFXPassDepthCommonFragmentUnlit}
|
|
|
|
#ifndef VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH
|
|
#define VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH 0
|
|
#endif
|
|
|
|
#ifdef VFX_SHADERGRAPH
|
|
${SHADERGRAPH_PIXEL_CODE_DEPTHONLY}
|
|
#endif
|
|
|
|
#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
#pragma fragment frag
|
|
void frag(ps_input i
|
|
#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
// We need the depth color as SV_Target0 for alpha to coverage
|
|
, out float4 outDepthColor : SV_Target0
|
|
, out float4 outMotionVector : SV_Target1
|
|
#else
|
|
// When no MSAA, the motion vector is always the first buffer
|
|
, out float4 outMotionVector : SV_Target0
|
|
#endif
|
|
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
, out float4 outDepthColor : SV_Target0
|
|
#else
|
|
, out float4 dummy : SV_Target0
|
|
#endif
|
|
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION
|
|
, out float4 outSelection : SV_Target0
|
|
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SHADOW
|
|
, out float4 dummy : SV_Target0
|
|
#endif
|
|
)
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
|
VFXTransformPSInputs(i);
|
|
${VFXComputeNormalWS}
|
|
|
|
#ifdef VFX_SHADERGRAPH
|
|
${VFXAdditionalInterpolantsPreparation}
|
|
${SHADERGRAPH_PIXEL_CALL_DEPTHONLY}
|
|
float alpha = OUTSG.${SHADERGRAPH_PARAM_ALPHA};
|
|
#else
|
|
float alpha = VFXGetFragmentColor(i).a;
|
|
#if VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH
|
|
alpha *= VFXGetTextureColor(VFX_SAMPLER(mainTexture),i).a;
|
|
#endif
|
|
#endif
|
|
VFXClipFragmentColor(alpha,i);
|
|
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
outDepthColor = i.VFX_VARYING_POSCS.z;
|
|
#if VFX_USE_ALPHA_TO_MASK
|
|
outDepthColor.a = alpha;
|
|
#endif
|
|
#endif
|
|
|
|
#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR
|
|
${VFXComputeOutputMotionVector}
|
|
outMotionVector = encodedMotionVector;
|
|
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION
|
|
outSelection = float4(_ObjectId, _PassValue, 1.0, 1.0);
|
|
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL
|
|
#ifndef WRITE_MSAA_DEPTH
|
|
dummy = (float4)0;
|
|
#endif
|
|
#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SHADOW
|
|
dummy = (float4)0;
|
|
#else
|
|
#error VFX_PASSDEPTH undefined
|
|
#endif
|
|
}
|
|
${VFXEnd}
|
|
|
|
// Strips tangent computation
|
|
${VFXBegin:VFXDeclareGetStripTangent}
|
|
float3 GetParticlePosition(uint index)
|
|
{
|
|
struct Attributes attributes = (Attributes)0;
|
|
${VFXLoadAttributes:{position}}
|
|
return attributes.position;
|
|
}
|
|
|
|
float3 GetStripTangent(float3 currentPos, uint relativeIndex, const StripData stripData)
|
|
{
|
|
float3 prevTangent = (float3)0.0f;
|
|
if (relativeIndex > 0)
|
|
{
|
|
uint prevIndex = GetParticleIndex(relativeIndex - 1,stripData);
|
|
prevTangent = normalize(currentPos - GetParticlePosition(prevIndex));
|
|
}
|
|
|
|
float3 nextTangent = (float3)0.0f;
|
|
if (relativeIndex < stripData.nextIndex - 1)
|
|
{
|
|
uint nextIndex = GetParticleIndex(relativeIndex + 1,stripData);
|
|
nextTangent = normalize(GetParticlePosition(nextIndex) - currentPos);
|
|
}
|
|
|
|
return normalize(prevTangent + nextTangent);
|
|
}
|
|
${VFXEnd}
|
|
|