Skip to content

Commit 35b0014

Browse files
authored
Toggles for water
1 parent 7f432fd commit 35b0014

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

Window.cpp

+37-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ bool SHOW_WATER = true; // Press L to hide/unhide water
3636
bool DEBUG = false; // Use 0 to toggle invincibility, disables bounds collision game over condition
3737
bool SPRAY_PARTICLES = false; // Press F to spray blue particle trails from the ship
3838
int TOON_SHADING = true; // Press P to toggle discretized color shading
39+
int SHOW_REFLECTION = 1; // Press X to toggle reflection
40+
int SHOW_REFRACTION = 1; // Press Z to toggle refraction
3941

4042
// GAME OPTIONS (You may edit these!)
4143
const int ISLAND_NUM = 10; // Default: 10
@@ -57,6 +59,8 @@ Island * tutorial_island; // Used to stop islands from being generated on to
5759
GLuint normal_toggle_var; // Sends information to terrain shader for normals coloring
5860
GLuint toon_toggle_var; // Sends information to toon shader to toggle toon coloring
5961
GLuint uCam_pos; // Sends camera pos information to shader
62+
GLuint sRefract; // Toggle refraction
63+
GLuint sReflect; // Toggle reflection
6064
GLuint uCam_look_at; // Sends camera look_at information to shader
6165
glm::vec3 lastPoint; // Holds last point for mouse/cursor movement
6266
bool place_island = true; // Used to check if two islands are overlapping
@@ -116,7 +120,7 @@ void Window::initialize_objects()
116120
// Water initialization
117121
ocean = new Water();
118122
ocean->toWorld = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f));
119-
ocean->scale(4000.0f, 1.0f, 4000.0f);
123+
ocean->scale(4000.0f, 15.0f, 4000.0f);
120124

121125
// Start clock for water waves
122126
tpf = clock();
@@ -269,6 +273,8 @@ void Window::initialize_objects()
269273
std::cout << " , - Regenerate map into singular islands" << std::endl;
270274
std::cout << " G - Mute sound" << std::endl;
271275
std::cout << " P - Toggle toon coloring" << std::endl;
276+
std::cout << " Z - Toggle water refraction" << std::endl;
277+
std::cout << " X - Toggle water reflection" << std::endl;
272278
}
273279

274280
// Treat this as a destructor function. Delete dynamically allocated memory here.
@@ -599,6 +605,10 @@ void Window::display_callback(GLFWwindow* window)
599605
/********** RENDER WATER **********/
600606
glUseProgram(water_shaderProgram);
601607
// Adjust timer for input into water waves
608+
sRefract = glGetUniformLocation(water_shaderProgram, "show_refract");
609+
glUniform1i(sRefract, SHOW_REFRACTION);
610+
sReflect = glGetUniformLocation(water_shaderProgram, "show_reflect");
611+
glUniform1i(sReflect, SHOW_REFLECTION);
602612
elapsedTime = (float)(clock() - tpf) / CLOCKS_PER_SEC;
603613
if (elapsedTime > 13.0f && go_backwards == false) {
604614
tpf = clock();
@@ -679,6 +689,15 @@ void Window::key_callback(GLFWwindow* window, int key, int scancode, int action,
679689
sound->toggleMuteAll();
680690
}
681691

692+
else if (key == GLFW_KEY_Y) {
693+
if (mods == GLFW_MOD_SHIFT) {
694+
model->translate(0.0f, 3.0f, 0.0f);
695+
}
696+
else {
697+
model->translate(0.0f, -3.0f, 0.0f);
698+
}
699+
}
700+
682701
else if (key == GLFW_KEY_T) {
683702
std::cout << "Regenerating terrain!" << std::endl;
684703
for (int i = 0; i < isles.size(); i++) {
@@ -762,6 +781,23 @@ void Window::key_callback(GLFWwindow* window, int key, int scancode, int action,
762781
}
763782
}
764783

784+
else if (key == GLFW_KEY_Z) {
785+
if (SHOW_REFRACTION == 1) {
786+
SHOW_REFRACTION = 0;
787+
}
788+
else {
789+
SHOW_REFRACTION = 1;
790+
}
791+
}
792+
else if (key == GLFW_KEY_X) {
793+
if (SHOW_REFLECTION == 1) {
794+
SHOW_REFLECTION = 0;
795+
}
796+
else {
797+
SHOW_REFLECTION = 1;
798+
}
799+
}
800+
765801
else if (key == GLFW_KEY_R) {
766802
FREE_CAMERA = false;
767803
GAME_OVER = false;

water_shader.frag

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ uniform sampler2D normalMap;
3030
uniform sampler2D reflectionTexture;
3131
uniform sampler2D refractionTexture;
3232
uniform vec3 LightDirection;
33+
uniform bool show_reflect;
34+
uniform bool show_refract;
35+
3336

3437
//light
3538
vec4 tangent = vec4(1.0, 0.0, 0.0, 0.0);
@@ -81,7 +84,14 @@ void main()
8184

8285
vec3 eye = normalize(worldPosition - camPos);
8386
vec3 refraction = refract(eye, vec3(0.0, 1.0, 0.0), 0.9);
87+
if (!show_refract) {
88+
refraction = vec3(0.0f, 0.0f, 0.0f);
89+
}
90+
8491
vec3 reflection = reflect(eye, vec3(0.0, 1.0, 0.0));
92+
if (!show_reflect) {
93+
reflection = vec3(0.0f, 0.0f, 0.0f);
94+
}
8595

8696
// Projection Coordinates
8797
vec4 tmp = vec4(1.0 / pos.w);
@@ -113,7 +123,7 @@ void main()
113123
refractionColor += depthValue * invertedFresnel;
114124

115125
//color = mix(reflectionColor, refractionColor, 0.2);
116-
color = reflectionColor + refractionColor;
126+
color = (reflectionColor + refractionColor);
117127
//color = reflectionColor;
118128
//color = refractionColor;
119129
//color = vec4(v_texCoord.x,0.0, v_texCoord.y, 1.0);

0 commit comments

Comments
 (0)