summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp60
1 files changed, 46 insertions, 14 deletions
diff --git a/main.cpp b/main.cpp
index 8c931c2..daff7ec 100644
--- a/main.cpp
+++ b/main.cpp
@@ -12,11 +12,12 @@
* - Lookup the derivation of the formula for reflecting a vector about a normal. I am doing that for specular lighting, but the learnopengl tutorial
* just uses a glsl reflect formula, and at the time of writing it is also very late so I am not in the mood or position to look into it at present.
* - One of the things I have observed with specular lights is that the circle/specular highlight follows the camera (me) when I move. I would like to figure
-* out a way by which this does not happen and it remains fixed on the object, at the angle at which it hits it. All of this will be made complicated by the fact
+* out a way by which this does not happen and it remains fixed on the object, at the angle at which it hits. All of this will be made complicated by the fact
* that ofcourse everything is actually happening from the cameras' perspective. I would still love to figure this out.
*/
/* @todo:
+ * - Switch to using clang on windows (for simplicity)
*/
@@ -555,12 +556,14 @@ int main(int argc, char* argv[])
"in vec3 fragNormal;\n"
"in vec3 worldPosition;\n"
"out vec4 FragColor;\n"
- "uniform sampler2D smilingTexture;\n"
- "uniform sampler2D containerTexture;\n"
+ "uniform float specularStrength;\n"
+ "uniform float shineFactor;\n"
"uniform vec3 lightPosition;\n"
"uniform vec3 cameraPosition;\n"
"uniform vec4 lightColor;\n"
"uniform vec4 objectColor;\n"
+ "uniform sampler2D smilingTexture;\n"
+ "uniform sampler2D containerTexture;\n"
"void main() {\n"
" float ambientLightStrength = 0.1;\n"
" vec4 ambientLight = ambientLightStrength * lightColor;\n"
@@ -571,11 +574,10 @@ int main(int argc, char* argv[])
" vec4 diffuseLight = diffuseStrength * lightColor;\n"
"\n"
"// @note: Specular calculations\n"
- " float specularStrength = 0.5;\n"
" vec3 viewDir = normalize(cameraPosition - worldPosition);\n"
" vec3 reflectDir = reflect(-lightDir, fragNormal);\n"
" float specularity = max(dot(viewDir, reflectDir), 0.0);\n"
- " float shininess = pow(specularity, 128.0);\n"
+ " float shininess = pow(specularity, shineFactor);\n"
" vec4 specularLight = specularStrength * shininess * lightColor;\n"
" "
"\n"
@@ -822,6 +824,15 @@ int main(int argc, char* argv[])
Vec3 light_location = Vec3{ 0.0, 0.0, 3.0 };
glUseProgram(shader_program);
+ float specular_strength = 0.5;
+ float specular_shine_factor = 32.0;
+
+ int spec_strength_loc = glGetUniformLocation(shader_program, "specularStrength");
+ glUniform1f(spec_strength_loc, specular_strength);
+
+ int shine_factor_loc = glGetUniformLocation(shader_program, "shineFactor");
+ glUniform1f(shine_factor_loc, specular_shine_factor);
+
// texture uniforms
int smiling_loc = glGetUniformLocation(shader_program, "smilingTexture");
glUniform1i(smiling_loc, 0);
@@ -829,7 +840,7 @@ int main(int argc, char* argv[])
int container_loc = glGetUniformLocation(shader_program, "containerTexture");
glUniform1i(container_loc, 1);
- Vec4 light_color = Vec4{1.0, 1.0, 1.0, 1.0};
+ Vec4 light_color = Vec4{0.5, 1.0, 0.5, 1.0};
int light_uniform_loc = glGetUniformLocation(shader_program, "lightColor");
glUniform4fv(light_uniform_loc, 1, light_color.data);
@@ -895,10 +906,13 @@ int main(int argc, char* argv[])
glEnable(GL_DEPTH_TEST);
bool game_running = true;
+
+ bool hold_lshift = false;
bool move_w = false;
bool move_a = false;
bool move_s = false;
bool move_d = false;
+
while(game_running)
{
@@ -922,21 +936,33 @@ int main(int argc, char* argv[])
} break;
case (SDL_KEYDOWN):
{
+ if (ev.key.keysym.sym == SDLK_LSHIFT)
+ {
+ hold_lshift = true;
+ }
if (ev.key.keysym.sym == SDLK_SPACE)
{}
if (ev.key.keysym.sym == SDLK_UP)
{
-#if TESTING_FOV
- FOV += 5.0;
- Mat4 proj = perspective4m(To_Radian(FOV), (float)width / (float)height, 0.1, 100.0);
-#endif
+ if (hold_lshift == true)
+ {
+ specular_strength += 0.1;
+ }
+ else
+ {
+ specular_shine_factor = specular_shine_factor*2.0;
+ }
}
if (ev.key.keysym.sym == SDLK_DOWN)
{
-#if TESTING_FOV
- FOV -= 5.0;
- Mat4 proj = perspective4m(To_Radian(FOV), (float)width / (float)height, 0.1, 100.0);
-#endif
+ if (hold_lshift == true)
+ {
+ specular_strength -= 0.1;
+ }
+ else
+ {
+ specular_shine_factor = specular_shine_factor/2.0;
+ }
}
if (ev.key.keysym.sym == SDLK_w)
{
@@ -957,6 +983,10 @@ int main(int argc, char* argv[])
} break;
case (SDL_KEYUP):
{
+ if (ev.key.keysym.sym == SDLK_LSHIFT)
+ {
+ hold_lshift = false;
+ }
if (ev.key.keysym.sym == SDLK_w)
{
move_w = false;
@@ -1019,6 +1049,8 @@ int main(int argc, char* argv[])
view = camera_create4m(camera_pos, add3v(camera_pos, camera_look), preset_up_dir);
// object shader program stuff
glUseProgram(shader_program);
+ glUniform1f(spec_strength_loc, specular_strength);
+ glUniform1f(shine_factor_loc, specular_shine_factor);
glUniformMatrix4fv(view_loc, 1, GL_TRUE, view.buffer);
glUniform3fv(light_pos_loc, 1, light_location.data);
glUniform3fv(camera_pos_loc, 1, camera_pos.data);