diff --git a/shaders/waterfall.frag b/shaders/waterfall.frag index 704f418fe9de29abc6c1d3efae7a1e787e73c66d..662f4ee8751e9ba9552f50b3fce5def33c71e787 100644 --- a/shaders/waterfall.frag +++ b/shaders/waterfall.frag @@ -1,14 +1,16 @@ #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) diff --git a/src/main.cpp b/src/main.cpp index 813928e1878e31e472b8ae987531bc5ecd650684..587570f20a54a546e45f2d7df7a20b4ec81d1251 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(); diff --git a/src/waterfall.cpp b/src/waterfall.cpp index b1cfa99a8793c11e7556e0671e172db40ff8b9e3..4342d8d5fedb36525e39814f7bf1953ab96d2764 100644 --- a/src/waterfall.cpp +++ b/src/waterfall.cpp @@ -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)); diff --git a/src/waterfall.h b/src/waterfall.h index 76f849ac1fadf9b9c2d39f7d4b38ec3d89ecab30..194c4303f6ff28da8301a9b416cd48690bd82759 100644 --- a/src/waterfall.h +++ b/src/waterfall.h @@ -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>