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
Fabian Johansson
TSBK03 Project
Commits
e34da996
Commit
e34da996
authored
7 months ago
by
Martin Högstedt
Browse files
Options
Downloads
Patches
Plain Diff
accidental bubbles when debugging weird 'aura'
parent
36ab3401
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
shaders/waterfall.frag
+23
-19
23 additions, 19 deletions
shaders/waterfall.frag
with
23 additions
and
19 deletions
shaders/waterfall.frag
+
23
−
19
View file @
e34da996
...
@@ -6,8 +6,6 @@ const float MINIMUM_HIT_DISTANCE = 0.0001;
...
@@ -6,8 +6,6 @@ const float MINIMUM_HIT_DISTANCE = 0.0001;
const
float
MAXIMUM_TRACE_DISTANCE
=
1000
.
0
;
const
float
MAXIMUM_TRACE_DISTANCE
=
1000
.
0
;
uniform
int
num_balls
;
uniform
int
num_balls
;
uniform
float
screenWidth
;
uniform
float
screenHeight
;
in
vec3
world_pos
;
in
vec3
world_pos
;
uniform
vec3
camera_pos
;
uniform
vec3
camera_pos
;
...
@@ -19,7 +17,7 @@ struct Ball {
...
@@ -19,7 +17,7 @@ struct Ball {
};
};
layout
(
std140
)
uniform
BallBuffer
{
layout
(
std140
)
uniform
BallBuffer
{
Ball
balls
[
30
];
// TODO: Need to manually update size
Ball
balls
[
30
];
// TODO: Need to manually update size
};
};
float
distance_from_sphere
(
vec3
pos
,
Ball
ball
)
{
float
distance_from_sphere
(
vec3
pos
,
Ball
ball
)
{
...
@@ -28,25 +26,25 @@ float distance_from_sphere(vec3 pos, Ball ball) {
...
@@ -28,25 +26,25 @@ float distance_from_sphere(vec3 pos, Ball ball) {
// Function taken from: https://iquilezles.org/articles/distfunctions/
// Function taken from: https://iquilezles.org/articles/distfunctions/
float
opSmoothUnion
(
float
d1
,
float
d2
,
float
k
)
{
float
opSmoothUnion
(
float
d1
,
float
d2
,
float
k
)
{
float
h
=
clamp
(
0
.
5
+
0
.
5
*
(
d2
-
d1
)
/
k
,
0
.
0
,
1
.
0
);
float
h
=
clamp
(
0
.
5
+
0
.
5
*
(
d2
-
d1
)
/
k
,
0
.
0
,
1
.
0
);
return
mix
(
d2
,
d1
,
h
)
-
k
*
h
*
(
1
.
0
-
h
);
return
mix
(
d2
,
d1
,
h
)
-
k
*
h
*
(
1
.
0
-
h
);
}
}
float
SDF
(
vec3
position
)
{
float
SDF
(
vec3
position
)
{
float
min_dist
=
distance_from_sphere
(
position
,
balls
[
0
]);
float
min_dist
=
distance_from_sphere
(
position
,
balls
[
0
]);
// TODO: iterate over uniform num_balls
// TODO: iterate over uniform num_balls
for
(
int
i
=
1
;
i
<
30
;
++
i
)
{
for
(
int
i
=
1
;
i
<
30
;
++
i
)
{
float
dist
=
distance_from_sphere
(
position
,
balls
[
i
]);
float
dist
=
distance_from_sphere
(
position
,
balls
[
i
]);
min_dist
=
opSmoothUnion
(
min_dist
,
dist
,
0
.
2
);
min_dist
=
opSmoothUnion
(
min_dist
,
dist
,
0
.
1
);
}
}
return
min_dist
;
return
min_dist
;
}
}
vec3
calculate_normal
(
vec3
position
)
{
vec3
calculate_normal
(
vec3
position
)
{
const
vec3
small_step
=
vec3
(
0
.
001
,
0
,
0
);
const
vec3
small_step
=
vec3
(
0
.
00
0
1
,
0
,
0
);
return
normalize
(
return
normalize
(
vec3
(
vec3
(
SDF
(
position
+
small_step
.
xyy
)
-
SDF
(
position
-
small_step
.
xyy
),
SDF
(
position
+
small_step
.
xyy
)
-
SDF
(
position
-
small_step
.
xyy
),
...
@@ -57,20 +55,28 @@ vec3 calculate_normal(vec3 position) {
...
@@ -57,20 +55,28 @@ vec3 calculate_normal(vec3 position) {
}
}
vec3
ray_march
(
vec3
ro
,
vec3
rd
)
{
vec3
ray_march
(
vec3
ro
,
vec3
rd
)
{
float
total_distance_traveled
=
0
.
0
;
float
total_distance_traveled
=
0
.
0
;
for
(
int
i
=
0
;
i
<
NUMBER_OF_STEPS
;
++
i
)
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_STEPS
;
++
i
)
{
vec3
current_position
=
ro
+
total_distance_traveled
*
rd
;
vec3
current_position
=
ro
+
total_distance_traveled
*
rd
;
float
min_dist
=
SDF
(
current_position
);
float
min_dist
=
SDF
(
current_position
);
// hit
// hit
if
(
min_dist
<
MINIMUM_HIT_DISTANCE
)
{
if
(
min_dist
<
MINIMUM_HIT_DISTANCE
)
{
const
vec3
color
=
vec3
(
0
.
1
,
0
.
2
,
0
.
7
);
const
vec3
color
=
vec3
(
0
.
2
,
0
.
3
,
0
.
8
);
const
vec3
light_position
=
vec3
(
0
,
10
,
0
);
vec3
normal
=
normalize
(
calculate_normal
(
current_position
));
vec3
normal
=
normalize
(
calculate_normal
(
current_position
));
return
color
;
vec3
direction_to_light
=
normalize
(
light_position
-
current_position
);
float
diffuse_intensity
=
max
(
0
.
0
,
dot
(
normal
,
direction_to_light
));
if
(
diffuse_intensity
<
0
.
99
)
{
discard
;
}
//return color + diffuse_intensity * vec3(1, 1, 1) * 0.5;
return
vec3
(
diffuse_intensity
,
diffuse_intensity
,
diffuse_intensity
);
}
}
if
(
total_distance_traveled
>
MAXIMUM_TRACE_DISTANCE
)
{
if
(
total_distance_traveled
>
MAXIMUM_TRACE_DISTANCE
)
{
...
@@ -86,6 +92,4 @@ void main(void)
...
@@ -86,6 +92,4 @@ void main(void)
vec3
dir
=
normalize
(
world_pos
-
camera_pos
);
vec3
dir
=
normalize
(
world_pos
-
camera_pos
);
vec3
shaded_color
=
ray_march
(
world_pos
,
dir
);
vec3
shaded_color
=
ray_march
(
world_pos
,
dir
);
out_Color
=
vec4
(
shaded_color
,
1
.
0
);
out_Color
=
vec4
(
shaded_color
,
1
.
0
);
//out_Color = vec4(gl_FragCoord.x, gl_FragCoord.y, gl_FragCoord.z, 1);
//out_Color = vec4(shade, shade, shade, 0.0);
}
}
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