_xiaofang/xiaofang/Assets/Obi/Resources/Compute/InstancedParticleRendering.compute
杨号敬 bcc74f0465 add
2024-12-18 02:18:45 +08:00

44 lines
1.2 KiB
Plaintext

#pragma kernel UpdateParticleInstances
#include "PathFrame.cginc"
struct RendererData
{
float4 color;
float radiusScale;
};
StructuredBuffer<int> activeParticles;
StructuredBuffer<RendererData> rendererData;
StructuredBuffer<int> rendererIndex;
StructuredBuffer<float4> renderablePositions;
StructuredBuffer<quaternion> renderableOrientations;
StructuredBuffer<float4> renderableRadii;
StructuredBuffer<float4> colors;
float4x4 solverToWorld;
RWStructuredBuffer<float4x4> instanceTransforms;
RWStructuredBuffer<float4x4> invInstanceTransforms;
RWStructuredBuffer<float4> instanceColors;
uint particleCount;
[numthreads(128, 1, 1)]
void UpdateParticleInstances (uint3 id : SV_DispatchThreadID)
{
unsigned int i = id.x;
if (i >= particleCount) return;
int p = activeParticles[i];
float4x4 tfrm = TRS(renderablePositions[p].xyz,
renderableOrientations[p],
renderableRadii[p].xyz * renderableRadii[p][3] * rendererData[rendererIndex[i]].radiusScale);
instanceTransforms[i] = mul(solverToWorld, tfrm);
instanceColors[i] = colors[p] * rendererData[rendererIndex[i]].color;
invInstanceTransforms[i] = Inverse(instanceTransforms[i]);
}