Move shaders into glsl and hlsl directories
Move `data/shaders` to `data/shaders/glsl` Move `data/hlsl` to `data/shaders/hlsl` Fix up shader paths in the cpp files to point to the new glsl location. `data/shaders/hlsl/compile.py` still overwrites the glsl .spv files (for now). Issue: #723
This commit is contained in:
parent
cac1d2e850
commit
ca884587a4
1043 changed files with 1207 additions and 1201 deletions
14
data/shaders/glsl/computenbody/particle.frag
Normal file
14
data/shaders/glsl/computenbody/particle.frag
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#version 450
|
||||
|
||||
layout (binding = 0) uniform sampler2D samplerColorMap;
|
||||
layout (binding = 1) uniform sampler2D samplerGradientRamp;
|
||||
|
||||
layout (location = 0) in float inGradientPos;
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main ()
|
||||
{
|
||||
vec3 color = texture(samplerGradientRamp, vec2(inGradientPos, 0.0)).rgb;
|
||||
outFragColor.rgb = texture(samplerColorMap, gl_PointCoord).rgb * color;
|
||||
}
|
||||
BIN
data/shaders/glsl/computenbody/particle.frag.spv
Normal file
BIN
data/shaders/glsl/computenbody/particle.frag.spv
Normal file
Binary file not shown.
32
data/shaders/glsl/computenbody/particle.vert
Normal file
32
data/shaders/glsl/computenbody/particle.vert
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 inPos;
|
||||
layout (location = 1) in vec4 inVel;
|
||||
|
||||
layout (location = 0) out float outGradientPos;
|
||||
|
||||
layout (binding = 2) uniform UBO
|
||||
{
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
vec2 screendim;
|
||||
} ubo;
|
||||
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
float gl_PointSize;
|
||||
};
|
||||
|
||||
void main ()
|
||||
{
|
||||
const float spriteSize = 0.005 * inPos.w; // Point size influenced by mass (stored in inPos.w);
|
||||
|
||||
vec4 eyePos = ubo.modelview * vec4(inPos.x, inPos.y, inPos.z, 1.0);
|
||||
vec4 projectedCorner = ubo.projection * vec4(0.5 * spriteSize, 0.5 * spriteSize, eyePos.z, eyePos.w);
|
||||
gl_PointSize = clamp(ubo.screendim.x * projectedCorner.x / projectedCorner.w, 1.0, 128.0);
|
||||
|
||||
gl_Position = ubo.projection * eyePos;
|
||||
|
||||
outGradientPos = inVel.w;
|
||||
}
|
||||
BIN
data/shaders/glsl/computenbody/particle.vert.spv
Normal file
BIN
data/shaders/glsl/computenbody/particle.vert.spv
Normal file
Binary file not shown.
74
data/shaders/glsl/computenbody/particle_calculate.comp
Normal file
74
data/shaders/glsl/computenbody/particle_calculate.comp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
|
||||
#version 450
|
||||
|
||||
struct Particle
|
||||
{
|
||||
vec4 pos;
|
||||
vec4 vel;
|
||||
};
|
||||
|
||||
// Binding 0 : Position storage buffer
|
||||
layout(std140, binding = 0) buffer Pos
|
||||
{
|
||||
Particle particles[ ];
|
||||
};
|
||||
|
||||
layout (local_size_x = 256) in;
|
||||
|
||||
layout (binding = 1) uniform UBO
|
||||
{
|
||||
float deltaT;
|
||||
int particleCount;
|
||||
} ubo;
|
||||
|
||||
layout (constant_id = 0) const int SHARED_DATA_SIZE = 512;
|
||||
layout (constant_id = 1) const float GRAVITY = 0.002;
|
||||
layout (constant_id = 2) const float POWER = 0.75;
|
||||
layout (constant_id = 3) const float SOFTEN = 0.0075;
|
||||
|
||||
// Share data between computer shader invocations to speed up caluclations
|
||||
shared vec4 sharedData[SHARED_DATA_SIZE];
|
||||
|
||||
void main()
|
||||
{
|
||||
// Current SSBO index
|
||||
uint index = gl_GlobalInvocationID.x;
|
||||
if (index >= ubo.particleCount)
|
||||
return;
|
||||
|
||||
vec4 position = particles[index].pos;
|
||||
vec4 velocity = particles[index].vel;
|
||||
vec4 acceleration = vec4(0.0);
|
||||
|
||||
for (int i = 0; i < ubo.particleCount; i += SHARED_DATA_SIZE)
|
||||
{
|
||||
if (i + gl_LocalInvocationID.x < ubo.particleCount)
|
||||
{
|
||||
sharedData[gl_LocalInvocationID.x] = particles[i + gl_LocalInvocationID.x].pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedData[gl_LocalInvocationID.x] = vec4(0.0);
|
||||
}
|
||||
|
||||
memoryBarrierShared();
|
||||
barrier();
|
||||
|
||||
for (int j = 0; j < gl_WorkGroupSize.x; j++)
|
||||
{
|
||||
vec4 other = sharedData[j];
|
||||
vec3 len = other.xyz - position.xyz;
|
||||
acceleration.xyz += GRAVITY * len * other.w / pow(dot(len, len) + SOFTEN, POWER);
|
||||
}
|
||||
|
||||
memoryBarrierShared();
|
||||
barrier();
|
||||
}
|
||||
|
||||
particles[index].vel.xyz += ubo.deltaT * acceleration.xyz;
|
||||
|
||||
// Gradient texture position
|
||||
particles[index].vel.w += 0.1 * ubo.deltaT;
|
||||
if (particles[index].vel.w > 1.0)
|
||||
particles[index].vel.w -= 1.0;
|
||||
}
|
||||
BIN
data/shaders/glsl/computenbody/particle_calculate.comp.spv
Normal file
BIN
data/shaders/glsl/computenbody/particle_calculate.comp.spv
Normal file
Binary file not shown.
30
data/shaders/glsl/computenbody/particle_integrate.comp
Normal file
30
data/shaders/glsl/computenbody/particle_integrate.comp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#version 450
|
||||
|
||||
struct Particle
|
||||
{
|
||||
vec4 pos;
|
||||
vec4 vel;
|
||||
};
|
||||
|
||||
// Binding 0 : Position storage buffer
|
||||
layout(std140, binding = 0) buffer Pos
|
||||
{
|
||||
Particle particles[ ];
|
||||
};
|
||||
|
||||
layout (local_size_x = 256) in;
|
||||
|
||||
layout (binding = 1) uniform UBO
|
||||
{
|
||||
float deltaT;
|
||||
int particleCount;
|
||||
} ubo;
|
||||
|
||||
void main()
|
||||
{
|
||||
int index = int(gl_GlobalInvocationID);
|
||||
vec4 position = particles[index].pos;
|
||||
vec4 velocity = particles[index].vel;
|
||||
position += ubo.deltaT * velocity;
|
||||
particles[index].pos = position;
|
||||
}
|
||||
BIN
data/shaders/glsl/computenbody/particle_integrate.comp.spv
Normal file
BIN
data/shaders/glsl/computenbody/particle_integrate.comp.spv
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue