ported the University CGI demo from WINDOWS + GLUT + GLEW + GLU + OpenGL 4 to LINUX WAYLAND + EGL + GLES 2 with minimal cuts

This commit is contained in:
beno
2025-07-03 01:26:25 +02:00
commit 6c125fb35e
85 changed files with 91688 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
#version 430 core
//Uniform block containing positions and masses of the attractors
layout (std140, binding = 0) uniform attractor_block
{
vec4 attractor[8]; //xyz = position, w = strength
};
//Process particles in blocks of 128
layout (local_size_x = 1024) in;
//buffers containing the positions and velocities of the particles
layout (rgba32f, binding = 0) uniform imageBuffer velocity_buffer;
layout (rgba32f, binding = 1) uniform imageBuffer start_position_buffer;
layout (rgba32f, binding = 2) uniform imageBuffer end_position_buffer;
//Delta time
uniform float dt;
uniform vec3 nearTopLeft;
uniform vec3 nearBottomRight;
uniform vec3 farTopLeft;
uniform vec3 farBottomRight;
bool insideFrustrum(vec4 point) {
//float zRelative = ((point.z - nearBottomRight.z) / (nearBottomRight.z - farBottomRight.z));
//bool moreLeft = (point.x >= (nearTopLeft.x + (nearTopLeft.x - farTopLeft.x) * zRelative)); // left plane
//bool lessRight = (point.x <= (nearBottomRight.x + (nearBottomRight.x - farBottomRight.x) * zRelative)); // left plane
//bool moreBottom = (point.y >= (nearBottomRight.y + (nearBottomRight.y - farBottomRight.y) * zRelative)); //top plane
//bool lessTop = (point.y <= (nearTopLeft.y + (nearTopLeft.y - farTopLeft.y) * zRelative)); //bottom plane
//return ( (zRelative >= -1.0f) && moreLeft && lessRight && lessTop && moreBottom);
return ((point.x < farBottomRight.x) && (point.x > farTopLeft.x) && (point.y < farTopLeft.y) && (point.y > farBottomRight.y) && (point.z > -1.0));
}
vec4 scaleToZZero(vec4 v){
vec4 newV = v / (1 + v.z);
return newV;
}
void main(void)
{
//read the current position and velocity from the buffers
vec4 vel = imageLoad(velocity_buffer, int(gl_GlobalInvocationID.x));
vec4 pos = imageLoad(start_position_buffer, int(gl_GlobalInvocationID.x));
int i;
bool inFrustrum = true;
float dt2 = dt * dt;
while( inFrustrum && pos.z < 0.0f){
//update position using current velocity * time
pos.xyz += vel.xyz * dt;
//for each attractor... BOTTLENECK
for(i = 0; i < 8; i++)
{
if(attractor[i].w > 0){
//calculate force and update velocity accordingly
vec3 dir = (attractor[i].xyz - pos.xyz);
float dist = dot(dir, dir);
vel.xyz += (dt2 * attractor[i].w * cross(dir, vel.xyz) / (pow(dist, 2)));
}
}
inFrustrum = insideFrustrum(pos);
}
pos = scaleToZZero(pos);
//store the new position back into the buffers
imageStore(end_position_buffer, int(gl_GlobalInvocationID.x), pos);
}

View File

@@ -0,0 +1,24 @@
#version 430 core
layout (location = 0) out vec4 color;
layout(origin_upper_left, pixel_center_integer) in vec4 gl_FragCoord;
in vec4 particleColor;
uniform uint pixelWidth;
void main(void)
{
color = vec4(particleColor.xyz, 1.0f);
/*
color.r *= ((mod(gl_FragCoord.x, 8) != 0) && (mod(gl_FragCoord.y, 8) != 0) && (mod(gl_FragCoord.x, 8) != 1) && (mod(gl_FragCoord.y, 8) != 1))? 0 : 1;
color.g *= ((mod(gl_FragCoord.x, 8) != 2) && (mod(gl_FragCoord.y, 8) != 2) && (mod(gl_FragCoord.x, 8) != 3) && (mod(gl_FragCoord.y, 8) != 3))? 0 : 1;
color.b *= ((mod(gl_FragCoord.x, 8) != 4) && (mod(gl_FragCoord.y, 8) != 4) && (mod(gl_FragCoord.x, 8) != 5) && (mod(gl_FragCoord.y, 8) != 5))? 0 : 1;
*/
float mx = mod(roundEven(gl_FragCoord.x), 4 * pixelWidth);
float my = mod(roundEven(gl_FragCoord.y), 4 * pixelWidth);
color.r *= ((mx < pixelWidth) && (my < pixelWidth * 3)) ? 0.8 : 0.3;
color.g *= ((mx > pixelWidth && mx < pixelWidth * 2) && (my < pixelWidth * 3)) ? 1 : 0.4;
color.b *= ((mx > pixelWidth * 2 && mx < pixelWidth * 3) && (my < pixelWidth * 3)) ? 1 : 0.4;
}

View File

@@ -0,0 +1,17 @@
#version 430 core
layout (location = 0) in vec4 particleData;
//////
layout (location = 2) in vec4 iparticleColor;
out float intensity;
//
out vec4 particleColor;
uniform mat4 mvp;
void main(void)
{
gl_Position = mvp * vec4( particleData.xy, 0, 1);
particleColor = iparticleColor;
}