mellinoe / veldrid-samples

Sample projects for Veldrid
https://mellinoe.github.io/veldrid-docs/
121 stars 49 forks source link

ComputeParticles are all at bottom of screen #12

Open BinarySpike opened 5 years ago

BinarySpike commented 5 years ago

I cloned the project and did a dotnet run in the ComputeParticles/Desktop folder and all the particles are at the bottom of the screen.

image

This is on Windows 10

BinarySpike commented 5 years ago

Swapping particle x and y in the Vertex shader causes the particles to hang to the left hand size. Looks like Particles[gl_VertexIndex].Position.y is no good.

void main()
            {
                gl_Position = vec4(vec2(Particles[gl_VertexIndex].Position.y, Particles[gl_VertexIndex].Position.x) / vec2(ScreenWidth, ScreenHeight), 0, 1);
                gl_Position.xy = 2 * (gl_Position.xy - vec2(0.5, 0.5));
                fsin_color = Particles[gl_VertexIndex].Color;
            }
BinarySpike commented 5 years ago

Removed Velocity and Color from the ParticleInfo and now it's a proper distribution.

BinarySpike commented 5 years ago

Looks like Particles[index].Color.x is being translated to Particles[index].Position.y by the time it gets to the vertex shader.

This code at the end of of the Compute shader code causes everything to position, animate, and move correctly:

Particles[index].Position = newPos;
Particles[index].Velocity = newVel;
Particles[index].Color.x = pos.y;
TechPizzaDev commented 2 years ago

The correct solution seems to be changing this call: https://github.com/mellinoe/veldrid-samples/blob/0ac284ddc8f62d8d75c8eae88cc1824c320b1caf/src/ComputeParticles/Application/ComputeParticles.cs#L34-L38

BufferDescription.RawBuffer must be set to true to be functionally equivalent to other backends (and correct in general).