realityplayground-of/zoneb/bin/data/shaders/particles/draw.geom

69 lines
1.3 KiB
Text
Raw Permalink Normal View History

2020-10-31 17:40:31 +00:00
layout (points) in;
2020-10-31 19:24:50 +00:00
layout (line_strip) out;
2020-11-01 15:08:56 +00:00
layout (max_vertices = 4) out;
2020-10-31 17:40:31 +00:00
// OF handled uniforms and attributes.
uniform mat4 projectionMatrix;
2020-10-31 18:47:59 +00:00
uniform float u_time;
uniform int uEnergy;
2020-10-31 17:40:31 +00:00
// App specific uniforms and attributes.
// uniform float uSpriteSize;
in vec4 vPosition[];
2020-10-31 18:47:59 +00:00
in vec4 vPrevPosition[];
2020-10-31 17:40:31 +00:00
in vec2 vTexCoord[];
flat in int vValid[];
out vec2 texCoordVarying;
in vec3 vPos[];
in vec4 vTarget[];
in float vTemperature[];
in float vAge[];
out vec3 gPos;
out vec4 gTarget;
out float gTemperature;
out float gAge;
void main()
{
2020-10-31 18:47:59 +00:00
float uSpriteSize = 1;
2020-10-31 17:40:31 +00:00
texCoordVarying = vTexCoord[0];
gPos = vPos[0];
gTarget = vTarget[0];
gTemperature = vTemperature[0];
gAge = vAge[0];
2020-10-31 19:24:50 +00:00
if(gAge >= 1) return;
2020-10-31 17:40:31 +00:00
for (int i = 0; i < gl_in.length(); ++i)
{
vec3 vOffset;
if(uEnergy > 0) {
2020-11-01 15:08:56 +00:00
if(gAge < 0.005) return;
2020-10-31 19:59:19 +00:00
vOffset = (vPrevPosition[i].xyz - vPosition[i].xyz);
2020-11-01 15:36:07 +00:00
vOffset += normalize(vOffset) * 10;
}
else {
vOffset = vec3(1,0,0);
}
2020-10-31 19:24:50 +00:00
vec4 shiftPos = vec4(vOffset, 0) + vPosition[i];
2020-10-31 17:40:31 +00:00
2020-10-31 19:24:50 +00:00
gl_Position = projectionMatrix * (vPosition[i] + vec4(0.0, 0.0, 0.0, 0.0) * uSpriteSize);
2020-10-31 17:40:31 +00:00
EmitVertex();
2020-10-31 18:47:59 +00:00
if (u_time > 10) { // hack
2020-10-31 19:24:50 +00:00
gl_Position = projectionMatrix * (shiftPos + vec4(0.0, 0.0, 0.0, 0.0) * uSpriteSize);
2020-10-31 18:47:59 +00:00
EmitVertex();
2020-10-31 17:40:31 +00:00
2020-11-01 15:08:56 +00:00
EndPrimitive();
}
2020-10-31 17:40:31 +00:00
EndPrimitive();
}
}