Skip to content
Snippets Groups Projects
Commit e44e4800 authored by Adam Nyberg's avatar Adam Nyberg
Browse files

WIP

parent 6d93e466
No related branches found
No related tags found
No related merge requests found
......@@ -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;
//}
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment