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
92216f27
Commit
92216f27
authored
5 months ago
by
Martin Högstedt
Browse files
Options
Downloads
Patches
Plain Diff
dont know what i did but it is currently working
parent
e34da996
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
shaders/waterfall.frag
+14
-17
14 additions, 17 deletions
shaders/waterfall.frag
src/main.cpp
+2
-0
2 additions, 0 deletions
src/main.cpp
src/waterfall.cpp
+1
-1
1 addition, 1 deletion
src/waterfall.cpp
src/waterfall.h
+1
-1
1 addition, 1 deletion
src/waterfall.h
with
18 additions
and
19 deletions
shaders/waterfall.frag
+
14
−
17
View file @
92216f27
#version 150
const
float
step_size
=
0
.
1
;
const
int
NUMBER_OF_STEPS
=
32
;
const
float
MINIMUM_HIT_DISTANCE
=
0
.
0001
;
const
float
MAXIMUM_TRACE_DISTANCE
=
1000
.
0
;
uniform
int
num_balls
;
const
int
NUMBER_OF_STEPS
=
48
;
const
float
MINIMUM_HIT_DISTANCE
=
0
.
01
;
const
float
MAXIMUM_TRACE_DISTANCE
=
100
.
0
;
in
vec3
world_pos
;
uniform
int
num_balls
;
uniform
vec3
camera_pos
;
uniform
vec3
sun
;
out
vec4
out_Color
;
struct
Ball
{
...
...
@@ -17,7 +19,7 @@ struct Ball {
};
layout
(
std140
)
uniform
BallBuffer
{
Ball
balls
[
3
0
];
// TODO: Need to manually update size
Ball
balls
[
10
0
];
// TODO: Need to manually update size
};
float
distance_from_sphere
(
vec3
pos
,
Ball
ball
)
{
...
...
@@ -34,10 +36,10 @@ float SDF(vec3 position) {
float
min_dist
=
distance_from_sphere
(
position
,
balls
[
0
]);
// TODO: iterate over uniform num_balls
for
(
int
i
=
1
;
i
<
3
0
;
++
i
)
{
for
(
int
i
=
1
;
i
<
10
0
;
++
i
)
{
float
dist
=
distance_from_sphere
(
position
,
balls
[
i
]);
min_dist
=
opSmoothUnion
(
min_dist
,
dist
,
0
.
1
);
min_dist
=
opSmoothUnion
(
min_dist
,
dist
,
0
.
2
);
}
return
min_dist
;
...
...
@@ -64,19 +66,13 @@ vec3 ray_march(vec3 ro, vec3 rd) {
// hit
if
(
min_dist
<
MINIMUM_HIT_DISTANCE
)
{
const
vec3
color
=
vec3
(
0
.
2
,
0
.
3
,
0
.
8
);
const
vec3
color
=
vec3
(
0
.
1
,
0
.
1
,
0
.
6
);
const
vec3
light_position
=
vec3
(
0
,
10
,
0
);
vec3
normal
=
normalize
(
calculate_normal
(
current_position
));
vec3
direction_to_light
=
normalize
(
light_positio
n
-
current_position
);
vec3
direction_to_light
=
normalize
(
su
n
-
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
);
return
color
+
diffuse_intensity
*
vec3
(
1
,
1
,
1
)
*
0
.
7
;
}
if
(
total_distance_traveled
>
MAXIMUM_TRACE_DISTANCE
)
{
...
...
@@ -85,6 +81,7 @@ vec3 ray_march(vec3 ro, vec3 rd) {
total_distance_traveled
+=
min_dist
;
}
discard
;
}
void
main
(
void
)
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
2
−
0
View file @
92216f27
...
...
@@ -23,6 +23,7 @@ struct Scene {
Object
surface
;
Waterfall
waterfall
;
Object
skybox
;
vec3
sun
=
vec3
(
0
,
100
,
0
);
GLuint
skybox_tex
;
...
...
@@ -148,6 +149,7 @@ struct Scene {
GL_TRUE
,
view_matrix
.
m
);
glUniform3f
(
glGetUniformLocation
(
program
,
"camera_pos"
),
pos
.
x
,
pos
.
y
,
pos
.
z
);
glUniform3f
(
glGetUniformLocation
(
program
,
"sun"
),
sun
.
x
,
sun
.
y
,
sun
.
z
);
waterfall
.
draw
();
waterfall
.
move_waterfall_balls
();
...
...
This diff is collapsed.
Click to expand it.
src/waterfall.cpp
+
1
−
1
View file @
92216f27
...
...
@@ -86,7 +86,7 @@ void Waterfall::gen_balls() {
for
(
int
i
{
0
};
i
<
NUM_BALLS
;
++
i
)
{
// pseudo random value between 0.01 and 0.1
float
radius
=
((
rand
()
/
(
float
)
RAND_MAX
)
*
0.9
+
0.1
)
/
1
0.0
;
float
radius
=
((
rand
()
/
(
float
)
RAND_MAX
)
*
0.9
+
0.1
)
/
5
0.0
;
// pseudo random value between min-radius and max-radius
float
pos_x
=
lerp
(
x
.
first
,
x
.
second
,
(
rand
()
/
(
float
)
RAND_MAX
));
...
...
This diff is collapsed.
Click to expand it.
src/waterfall.h
+
1
−
1
View file @
92216f27
...
...
@@ -13,7 +13,7 @@ struct Waterfall : Object {
static
GLuint
const
BINDING_POINT
{
0
};
char
const
*
UNIFORM_BLOCK
=
"BallBuffer"
;
static
int
const
NUM_BALLS
{
3
0
};
static
int
const
NUM_BALLS
{
10
0
};
// Dimensions of the waterfall
// on the form <min, max>
...
...
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