Nimbin[12]?Games / strichmaennchen / commits / 0427880

strichmaennchen git · main

Entropie festival game; first steps, second try

opengl glsl c 3d game entropie · first commit 2025-09-16 · last commit 2025-10-05 (1 year ago) · synced 1 hour ago

C 95% GLSL 4.7%
git clone https://git.christianimmanuel.de/games/strichmaennchen.gitwget https://git.christianimmanuel.de/games/strichmaennchen/archive/strichmaennchen.tar.gz

can stay on non static objects

Christian Immanuel · 2025-09-27 13:34 · 042788096ff67000f75283959833af94a29351f8

 mesh.c                  |   6 ++++++
 object.c                |   9 ++++++++-
 shaders/.basic.frag.swp | Bin 12288 -> 12288 bytes
 shaders/basic.frag      |  12 +++++++-----
 time.c                  |   2 ++
 time.h                  |   2 ++
 6 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/mesh.c b/mesh.c
index 53a3f92..b3f4bfa 100644
--- a/mesh.c
+++ b/mesh.c
@@ -44,6 +44,12 @@ void Mesh_draw(Mesh mesh, struct Renderer *renderer, TransformMatrices* trans_ma
     glUniform3f(locLightColor, time->sunColor.x, time->sunColor.y, time->sunColor.z);
     glUniform3f(locViewPos, viewPos.x, viewPos.y, viewPos.z);
 
+    // set dayFactor
+    GLint locDay = glGetUniformLocation(renderer->shaderProgram, "dayFactor");
+    if (locDay != -1) {
+        glUniform1f(locDay, time->dayFactor);
+    }
+
     // For main pass only (not shadow pass)
     Mat4 lightSpace = mat4_mul(renderer->lightProjection, mat4_mul(renderer->lightView, trans_matrices->model));
     GLint locLightSpace = glGetUniformLocation(renderer->shaderProgram, "lightSpaceMatrix");
diff --git a/object.c b/object.c
index 6a6497b..644e498 100644
--- a/object.c
+++ b/object.c
@@ -159,8 +159,15 @@ void Object_resolveDynamicCollision(Object *obj, Object *other) {
     if (obj->collider.isStatic || other->collider.isStatic) return;
     if (!AABB_overlap(obj, other)) return;
 
-    // 1. Horizontal push direction
     Vec3 delta = vec3_sub(obj->position, other->position);
+    float verticalOverlap = (obj->collider.size.y + other->collider.size.y)/2 - fabs(delta.y);
+    if (delta.y > 0 && verticalOverlap > 0.0f) {
+        Collider_positionGround(obj, other);
+        obj->velocity.x = 0;
+        obj->velocity.z = 0;
+        return;
+    }
+
     delta.y = 0.0f;
     if (vec3_length(delta) == 0) {
         delta.x = 0.01f;
diff --git a/shaders/.basic.frag.swp b/shaders/.basic.frag.swp
index 88af8a7..61ef35c 100644
Binary files a/shaders/.basic.frag.swp and b/shaders/.basic.frag.swp differ
diff --git a/shaders/basic.frag b/shaders/basic.frag
index ba87490..2723775 100644
--- a/shaders/basic.frag
+++ b/shaders/basic.frag
@@ -53,22 +53,24 @@ vec3 lightDirs[4];
 float lightStrengths[4];
 
 lightDirs[0] = normalize(lightDirection); // main sun
-lightStrengths[0] = 1.0;
 lightDirs[1] = normalize(rotateY(lightDirs[0], radians(45.0)));
 lightDirs[2] = normalize(rotateY(lightDirs[0], radians(-45.0)));
 lightDirs[3] = normalize(rotateX(lightDirs[0], radians(45.0)));
-lightStrengths[1] = 0.35 * dayFactor;
-lightStrengths[2] = 0.35 * dayFactor;
-lightStrengths[3] = 0.25 * dayFactor;
+lightStrengths[0] = 1.0;
+lightStrengths[1] = 0.55 * dayFactor;
+lightStrengths[2] = 0.55 * dayFactor;
+lightStrengths[3] = 0.45 * dayFactor;
 
 // Diffuse sum
 vec3 totalDiffuse = vec3(0.0);
 float shadow = ShadowCalculation(FragPosLightSpace);
 for(int i = 0; i < 4; ++i) {
     float diff = max(dot(norm, lightDirs[i]), 0.0);
-    float factor = (i == 0) ? shadow : 1.0;
+    float factor = shadow; // apply same shadow factor to all lights
     totalDiffuse += diff * lightColor * VertexColor * lightStrengths[i] * factor;
 }
+totalDiffuse = min(totalDiffuse, vec3(1.0));
+
 
 // Moon
 vec3 moonDir = normalize(-lightDirection);
diff --git a/time.c b/time.c
index 66b254e..48767ab 100644
--- a/time.c
+++ b/time.c
@@ -86,6 +86,8 @@ void Time_computeSunPosition(Time* t) {
     t->ambientColor.x = 0.1f  + 0.2f * intensity;
     t->ambientColor.y = 0.1f  + 0.2f * intensity;
     t->ambientColor.z = 0.15f + 0.2f * intensity;
+
+    t->dayFactor = intensity;
 }
 
 
diff --git a/time.h b/time.h
index da8f740..15978bc 100644
--- a/time.h
+++ b/time.h
@@ -16,6 +16,8 @@ typedef struct {
     float timeScale;  // speed multiplier (1.0 = real-time, >1 = faster)
     float dayStart;  // 07:00
     float dayEnd; // 21:00
+
+    float dayFactor;
     
     Vec3 sunDirection; // normalized vector
     Vec3 sunColor;     // RGB for sunlight