Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TSBK03 project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adam Nyberg
TSBK03 project
Commits
e44e4800
Commit
e44e4800
authored
3 weeks ago
by
Adam Nyberg
Browse files
Options
Downloads
Patches
Plain Diff
WIP
parent
6d93e466
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
shaders/depth_normals.frag
+1
-25
1 addition, 25 deletions
shaders/depth_normals.frag
src/spawn_particles.cpp
+1
-1
1 addition, 1 deletion
src/spawn_particles.cpp
with
2 additions
and
26 deletions
shaders/depth_normals.frag
+
1
−
25
View file @
e44e4800
...
...
@@ -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;
//}
...
...
This diff is collapsed.
Click to expand it.
src/spawn_particles.cpp
+
1
−
1
View file @
e44e4800
...
...
@@ -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.0
f
/
3.0
f
)));
index
=
initializeCube
(
0
,
particlesPerAxis
,
-
4
.0
f
,
4.0
f
,
1.0
f
);
index
=
initializeCube
(
0
,
particlesPerAxis
,
0
.0
f
,
4.0
f
,
1.0
f
);
index
=
initializeCube
(
index
,
particlesPerAxis
,
8.0
f
,
4.0
f
,
-
1.0
f
);
break
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment