From 6524bcff2f0aef32157cffe511384f33eb3b86d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berk=20=C3=96zbalc=C4=B1?= Date: Mon, 13 Jan 2020 16:28:05 +0300 Subject: [PATCH] last minute fixes for submission --- assignments/hw3/src/flat.cpp | 8 ++- .../src/shaders/{flat.frag => common.frag} | 0 assignments/hw3/src/shaders/sphere.frag | 51 ------------------- assignments/hw3/src/sphere.cpp | 6 ++- assignments/hw3/src/templates/__base.cpp | 9 +++- assignments/hw3/src/templates/flat.cpp | 6 ++- assignments/hw3/src/templates/sphere.cpp | 2 +- 7 files changed, 23 insertions(+), 59 deletions(-) rename assignments/hw3/src/shaders/{flat.frag => common.frag} (100%) delete mode 100644 assignments/hw3/src/shaders/sphere.frag diff --git a/assignments/hw3/src/flat.cpp b/assignments/hw3/src/flat.cpp index 9f3b4af..92d38e0 100644 --- a/assignments/hw3/src/flat.cpp +++ b/assignments/hw3/src/flat.cpp @@ -31,6 +31,8 @@ // Uncomment the following line to enable debug messages. // #define DEBUG +#define DO_NOT_ADD_GAZE_WHEN_RECALCULATING + GLuint ProgramShaderId; constexpr auto WINDOW_SIZE = 1000; @@ -269,7 +271,9 @@ struct UIState { auto PitchInRadians = glm::radians(Pitch); Camera.Gaze = glm::normalize( +#ifndef DO_NOT_ADD_GAZE_WHEN_RECALCULATING CAMERA_INITIAL.Gaze + +#endif glm::vec3(std::cos(YawInRadians) * std::cos(PitchInRadians), std::sin(PitchInRadians), std::sin(YawInRadians) * std::cos(PitchInRadians))); @@ -479,7 +483,7 @@ class Shader struct HW3Utility { // INPUT PATHS std::string VertexShaderPath = "shaders/flat.vert"; - std::string FragmentShaderPath = "shaders/flat.frag"; + std::string FragmentShaderPath = "shaders/common.frag"; std::string HeightMapPath; std::string TexturePath; @@ -722,7 +726,7 @@ struct HW3Utility { void MainLoop() { while (!glfwWindowShouldClose(Window)) { - auto BGColor = glm::min(1.0f, glm::abs(TheState.Speed) / 5.0f); + constexpr auto BGColor = 0.0f; glClearColor(BGColor, BGColor, BGColor, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/assignments/hw3/src/shaders/flat.frag b/assignments/hw3/src/shaders/common.frag similarity index 100% rename from assignments/hw3/src/shaders/flat.frag rename to assignments/hw3/src/shaders/common.frag diff --git a/assignments/hw3/src/shaders/sphere.frag b/assignments/hw3/src/shaders/sphere.frag deleted file mode 100644 index 69c2714..0000000 --- a/assignments/hw3/src/shaders/sphere.frag +++ /dev/null @@ -1,51 +0,0 @@ -#version 330 core - -out vec4 FragmentColor; - -in vec2 VertexTextureCoordinate; -in vec3 ToCamera; -in vec3 ToLight; -in vec3 VertexNormal; - -uniform float HeightFactor; -uniform float TextureHorizontalShift; -uniform int TextureHeight; -uniform int TextureWidth; -uniform mat4 MVPMatrix; -uniform sampler2D HeightMap; -uniform sampler2D Texture; -uniform vec3 CameraPosition; -uniform vec3 LightPosition; - -void main() -{ - // Inputs - vec4 TextureColor = texture(Texture, VertexTextureCoordinate); - - vec4 AmbientReflectance = vec4(0.25, 0.25, 0.25, 1.00); - vec4 AmbientColor = vec4(0.3, 0.3, 0.3, 1.0); - - vec4 DiffuseReflectance = vec4(1.0, 1.0, 1.0, 1.0); - vec4 DiffuseColor = vec4(1.0, 1.0, 1.0, 1.0); - - vec4 SpecularReflectance = vec4(1.0, 1.0, 1.0, 1.0); - vec4 SpecularColor = vec4(1.0, 1.0, 1.0, 1.0); - float SpecularExponent = 100; - - // Computed values - vec3 AmbientComponent = (AmbientReflectance * AmbientColor).xyz; - - float DiffuseCoeff = max(dot(VertexNormal, ToLight), - 0.0); - vec3 DiffuseComponent = DiffuseCoeff * (DiffuseReflectance * DiffuseColor).xyz; - - vec3 ReflectedLight = reflect(-ToLight, VertexNormal); - float SpecularCoeff = pow(max(dot(ReflectedLight, ToCamera), - 0.0), - SpecularExponent); - vec3 SpecularComponent = SpecularCoeff * (SpecularReflectance * SpecularColor).xyz; - - vec3 TotalComponent = AmbientComponent + DiffuseComponent + SpecularComponent; - vec3 UnclampedFragmentColor = TextureColor.xyz * TotalComponent; - FragmentColor = vec4(clamp(UnclampedFragmentColor, 0.0, 1.0), 1.0); -} diff --git a/assignments/hw3/src/sphere.cpp b/assignments/hw3/src/sphere.cpp index ffe34ff..1c29487 100644 --- a/assignments/hw3/src/sphere.cpp +++ b/assignments/hw3/src/sphere.cpp @@ -266,7 +266,9 @@ struct UIState { auto PitchInRadians = glm::radians(Pitch); Camera.Gaze = glm::normalize( +#ifndef DO_NOT_ADD_GAZE_WHEN_RECALCULATING CAMERA_INITIAL.Gaze + +#endif glm::vec3(std::cos(YawInRadians) * std::cos(PitchInRadians), std::sin(PitchInRadians), std::sin(YawInRadians) * std::cos(PitchInRadians))); @@ -476,7 +478,7 @@ class Shader struct HW3Utility { // INPUT PATHS std::string VertexShaderPath = "shaders/sphere.vert"; - std::string FragmentShaderPath = "shaders/sphere.frag"; + std::string FragmentShaderPath = "shaders/common.frag"; std::string HeightMapPath; std::string TexturePath; @@ -745,7 +747,7 @@ struct HW3Utility { void MainLoop() { while (!glfwWindowShouldClose(Window)) { - auto BGColor = glm::min(1.0f, glm::abs(TheState.Speed) / 5.0f); + constexpr auto BGColor = 0.0f; glClearColor(BGColor, BGColor, BGColor, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/assignments/hw3/src/templates/__base.cpp b/assignments/hw3/src/templates/__base.cpp index 08eaa82..c4d5b99 100644 --- a/assignments/hw3/src/templates/__base.cpp +++ b/assignments/hw3/src/templates/__base.cpp @@ -31,6 +31,9 @@ // Uncomment the following line to enable debug messages. // #define DEBUG +{% block Preamble %} +{% endblock %} + GLuint ProgramShaderId; constexpr auto WINDOW_SIZE = 1000; @@ -267,7 +270,9 @@ struct UIState { auto PitchInRadians = glm::radians(Pitch); Camera.Gaze = glm::normalize( - CAMERA_INITIAL.Gaze + +#ifndef DO_NOT_ADD_GAZE_WHEN_RECALCULATING + CAMERA_INITIAL.Gaze + +#endif glm::vec3(std::cos(YawInRadians) * std::cos(PitchInRadians), std::sin(PitchInRadians), std::sin(YawInRadians) * std::cos(PitchInRadians))); @@ -698,7 +703,7 @@ struct HW3Utility { void MainLoop() { while (!glfwWindowShouldClose(Window)) { - auto BGColor = glm::min(1.0f, glm::abs(TheState.Speed) / 5.0f); + constexpr auto BGColor = 0.0f; glClearColor(BGColor, BGColor, BGColor, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/assignments/hw3/src/templates/flat.cpp b/assignments/hw3/src/templates/flat.cpp index b76e24d..a5bae95 100644 --- a/assignments/hw3/src/templates/flat.cpp +++ b/assignments/hw3/src/templates/flat.cpp @@ -2,11 +2,15 @@ {% block Variant %}flat{% endblock %} {% block VertexShaderPath %}shaders/flat.vert{% endblock %} -{% block FragmentShaderPath %}shaders/flat.frag{% endblock %} +{% block FragmentShaderPath %}shaders/common.frag{% endblock %} {% block HeightFactorInitial %}10.f{% endblock %} {% block PitchInitial %}0.0f{% endblock %}; {% block YawInitial %}90.0f{% endblock %}; +{% block Preamble %} +#define DO_NOT_ADD_GAZE_WHEN_RECALCULATING +{% endblock %} + {% block CameraPosition %} { (float)TextureWidth / 2.0f, diff --git a/assignments/hw3/src/templates/sphere.cpp b/assignments/hw3/src/templates/sphere.cpp index 6386de3..fd9f873 100644 --- a/assignments/hw3/src/templates/sphere.cpp +++ b/assignments/hw3/src/templates/sphere.cpp @@ -2,7 +2,7 @@ {% block Variant %}sphere{% endblock %} {% block VertexShaderPath %}shaders/sphere.vert{% endblock %} -{% block FragmentShaderPath %}shaders/sphere.frag{% endblock %} +{% block FragmentShaderPath %}shaders/common.frag{% endblock %} {% block HeightFactorInitial %}0.0f{% endblock %} {% block PitchInitial %}0.0f{% endblock %}; {% block YawInitial %}90.0f{% endblock %};