Skip to content
Snippets Groups Projects
Commit 92216f27 authored by Martin Högstedt's avatar Martin Högstedt
Browse files

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
#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[30]; // TODO: Need to manually update size
Ball balls[100]; // 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 < 30; ++i) {
for (int i = 1; i < 100; ++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_position - current_position);
vec3 direction_to_light = normalize(sun - 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)
......
......@@ -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();
......
......@@ -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) / 10.0;
float radius = ((rand() / (float)RAND_MAX) * 0.9 + 0.1) / 50.0;
// pseudo random value between min-radius and max-radius
float pos_x = lerp(x.first, x.second, (rand() / (float)RAND_MAX));
......
......@@ -13,7 +13,7 @@ struct Waterfall : Object {
static GLuint const BINDING_POINT{0};
char const *UNIFORM_BLOCK = "BallBuffer";
static int const NUM_BALLS{30};
static int const NUM_BALLS{100};
// Dimensions of the waterfall
// on the form <min, max>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment