From e44e480076879373b4c5d055cb0a7715930dec2b Mon Sep 17 00:00:00 2001
From: adany292 <adany292@student.liu.se>
Date: Thu, 27 Mar 2025 12:46:04 +0100
Subject: [PATCH] WIP

---
 shaders/depth_normals.frag | 26 +-------------------------
 src/spawn_particles.cpp    |  2 +-
 2 files changed, 2 insertions(+), 26 deletions(-)

diff --git a/shaders/depth_normals.frag b/shaders/depth_normals.frag
index d550e44..ccbf6fd 100644
--- a/shaders/depth_normals.frag
+++ b/shaders/depth_normals.frag
@@ -18,17 +18,10 @@ uniform float maxDepth;
 // Pixel-size step for neighbor sampling
 uniform vec2 uTexelSize;
 
-//////////////////////////////////////////////////////////
-// Helper: Reconstruct eye-space position from linear depth
-//////////////////////////////////////////////////////////
 vec3 reconstructEyePos(vec2 uv, float depthLin)
 {
-    // 1) Convert [0..1] -> actual eye-space distance
     float dEye = depthLin * (zFar - zNear) + zNear;
 
-    // 2) Compute direction from camera through this UV.
-    //    We'll treat the clip-space z = -1 (the near plane),
-    //    so that we get a direction vector after inverse-projection.
     float xNDC = uv.x * 2.0 - 1.0;
     float yNDC = uv.y * 2.0 - 1.0;
 
@@ -38,51 +31,37 @@ vec3 reconstructEyePos(vec2 uv, float depthLin)
     vec3 dir = eyePos4.xyz / eyePos4.w;
     dir = normalize(dir);
 
-    // 3) Actual position = direction * distance
     return dir * dEye;
 }
 
 void main()
 {
-    //////////////////////////////////
-    // 1) Sample center depth
-    //////////////////////////////////
     float depthLin = texture(uDepthTex, TexCoords).r;
     if (depthLin < 0.0 || depthLin > 1.0 || depthLin > maxDepth) {
         discard;
     }
 
-    // Reconstruct center pixel in eye space
     vec3 centerEye = reconstructEyePos(TexCoords, depthLin);
 
-    //////////////////////////////////
-    // 2) Sample neighbors (x direction)
-    //////////////////////////////////
     vec2 uvLeft  = TexCoords + vec2(-uTexelSize.x, 0.0);
     vec2 uvRight = TexCoords + vec2( uTexelSize.x, 0.0);
 
     float depthL = texture(uDepthTex, uvLeft).r;
     float depthR = texture(uDepthTex, uvRight).r;
 
-    // If invalid neighbors, optionally discard
     if (depthL < 0.0 || depthL > 1.0 || depthL > maxDepth) discard;
     if (depthR < 0.0 || depthR > 1.0 || depthR > maxDepth) discard;
 
     vec3 leftEye  = reconstructEyePos(uvLeft,  depthL);
     vec3 rightEye = reconstructEyePos(uvRight, depthR);
 
-    // partial derivative in x
     vec3 ddx  = rightEye - centerEye;
     vec3 ddx2 = centerEye - leftEye;
 
-    // Optionally pick whichever has smaller Z difference
     if (abs(ddx2.z) < abs(ddx.z)) {
         ddx = ddx2;
     }
 
-    //////////////////////////////////
-    // 3) Sample neighbors (y direction)
-    //////////////////////////////////
     vec2 uvUp = TexCoords + vec2(0.0,  uTexelSize.y);
     vec2 uvDn = TexCoords + vec2(0.0, -uTexelSize.y);
 
@@ -101,12 +80,9 @@ void main()
         ddy = ddy2;
     }
 
-    //////////////////////////////////
-    // 4) Cross partials => normal
-    //////////////////////////////////
     vec3 N = normalize(cross(ddx, ddy));
 
-    // Some folks invert if N.z > 0
+    // Some invert if N.z > 0
     //if (N.z > 0.0) {
     //    N = -N;
     //}
diff --git a/src/spawn_particles.cpp b/src/spawn_particles.cpp
index 9f6672c..2b95131 100644
--- a/src/spawn_particles.cpp
+++ b/src/spawn_particles.cpp
@@ -58,7 +58,7 @@ void initParticles(
             int halfParticles = NUM_PARTICLES / 2; // Split particles evenly between two cubes
             particlesPerAxis = static_cast<int>(ceil(pow(halfParticles, 1.0f / 3.0f)));
 
-            index = initializeCube(0, particlesPerAxis, -4.0f, 4.0f, 1.0f);
+            index = initializeCube(0, particlesPerAxis, 0.0f, 4.0f, 1.0f);
             index = initializeCube(index, particlesPerAxis, 8.0f, 4.0f, -1.0f);
             break;
         }
-- 
GitLab