Shader
This commit is contained in:
36
shaders/ComputeShader.glsl
Normal file
36
shaders/ComputeShader.glsl
Normal file
@ -0,0 +1,36 @@
|
||||
#version 460 core
|
||||
#extension GL_ARB_compute_shader : enable
|
||||
#extension GL_ARB_shader_storage_buffer_object : enable
|
||||
|
||||
struct particle
|
||||
{
|
||||
vec3 pos;
|
||||
vec3 vel;
|
||||
vec3 col;
|
||||
float age;
|
||||
};
|
||||
|
||||
layout(std430, binding=0) buffer particles
|
||||
{
|
||||
particle p[];
|
||||
};
|
||||
|
||||
layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
void main()
|
||||
{
|
||||
uint gid = gl_GlobalInvocationID.x;
|
||||
particle part = p[gid];
|
||||
|
||||
if (part.age > 0)
|
||||
{
|
||||
part.pos += part.vel;
|
||||
part.age -= 0.01f;
|
||||
}
|
||||
else
|
||||
{
|
||||
part.pos = vec3(0, 0, 0);
|
||||
}
|
||||
|
||||
p[gid] = part;
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
#version 460 core
|
||||
|
||||
in vec3 col; // the input variable from the vertex shader (same name and same type)
|
||||
in vec3 col;
|
||||
out vec4 colOut;
|
||||
|
||||
out vec4 outCol;
|
||||
|
||||
void main()
|
||||
void main(void)
|
||||
{
|
||||
outCol = vec4(vertexColor, 1.0);
|
||||
colOut = vec4(col, 1);
|
||||
}
|
8
shaders/GeometryShader.glsl
Normal file
8
shaders/GeometryShader.glsl
Normal file
@ -0,0 +1,8 @@
|
||||
#version 460 core
|
||||
|
||||
layout(points) in;
|
||||
layout(points, max_vertices = 256) out;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
}
|
30
shaders/RenderShader.glsl
Normal file
30
shaders/RenderShader.glsl
Normal file
@ -0,0 +1,30 @@
|
||||
#version 460 core
|
||||
|
||||
layout (points) in;
|
||||
layout (points) out;
|
||||
layout (max_vertices = 40) out;
|
||||
|
||||
in vec3 pos0[];
|
||||
in vec3 vel0[];
|
||||
in vec3 col0[];
|
||||
in float age0[];
|
||||
|
||||
out vec3 posOut;
|
||||
out vec3 velOut;
|
||||
out vec3 colOut;
|
||||
out float ageOut;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (age0[0] < 0)
|
||||
{
|
||||
posOut = vec3(0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
posOut = pos0[0];
|
||||
velOut = vel0[0];
|
||||
colOut = col0[0];
|
||||
ageOut = age0[0] - 0.01f;
|
||||
}
|
||||
}
|
19
shaders/UpdateShader.glsl
Normal file
19
shaders/UpdateShader.glsl
Normal file
@ -0,0 +1,19 @@
|
||||
#version 460 core
|
||||
|
||||
layout (location = 0) in vec3 pos; // the position variable has attribute position 0
|
||||
layout (location = 1) in vec3 vel; // the velocity variable has attribute position 1
|
||||
layout (location = 2) in vec3 col; // the color variable has attribute position 2
|
||||
layout (location = 3) in float age; // the age variable has attribute position 3
|
||||
|
||||
out vec3 pos0;
|
||||
out vec3 vel0;
|
||||
out vec3 col0;
|
||||
out float age0;
|
||||
|
||||
void main()
|
||||
{
|
||||
pos0 = pos;
|
||||
vel0 = vel;
|
||||
col0 = col;
|
||||
age0 = age;
|
||||
}
|
@ -1,26 +1,8 @@
|
||||
#version 460 core
|
||||
|
||||
layout (location = 0) in vec3 pos; // the position variable has attribute position 0
|
||||
layout (location = 1) in vec3 dir; // the direction variable has attribute position 1
|
||||
layout (location = 2) in vec3 col; // the color variable has attribute position 2
|
||||
layout (location = 3) in float age; // the age variable has attribute position 3
|
||||
layout(location=0) in vec3 pos;
|
||||
|
||||
//in vec3 emitterPos; // the emitter pos variable
|
||||
//in float newAge; // the age variable
|
||||
|
||||
out vec3 outCol; // output a color to the fragment shader
|
||||
|
||||
void main()
|
||||
void main(void)
|
||||
{
|
||||
if (age < 0)
|
||||
{
|
||||
pos = emitterPos;
|
||||
age = newAge;
|
||||
}
|
||||
|
||||
age -= 0.1f;
|
||||
vec3 newPos = pos.xyz + dir.xyz;
|
||||
gl_Position = vec4(newPos, 1.0);
|
||||
|
||||
outCol = col; // set ourColor to the input color we got from the vertex data
|
||||
gl_Position = vec4(pos, 0);
|
||||
}
|
Reference in New Issue
Block a user