diff --git a/cw_8/src/main.cpp b/cw_8/src/main.cpp index 97a3bb4..5f27d97 100644 --- a/cw_8/src/main.cpp +++ b/cw_8/src/main.cpp @@ -23,7 +23,7 @@ int main(int argc, char** argv) #endif // tworzenie okna za pomoca glfw - GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(900, 900, "FirstWindow", NULL, NULL); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; @@ -34,7 +34,7 @@ int main(int argc, char** argv) // ladowanie OpenGL za pomoca glew glewInit(); - glViewport(0, 0, 500, 500); + glViewport(0, 0, 900, 900); init(window); diff --git a/cw_8/src/projekt.hpp b/cw_8/src/projekt.hpp index 4eec726..c3869dd 100644 --- a/cw_8/src/projekt.hpp +++ b/cw_8/src/projekt.hpp @@ -18,6 +18,7 @@ Core::Shader_Loader shaderLoader; Core::RenderContext shipContext; Core::RenderContext sunContext; Core::RenderContext planetContext; +Core::RenderContext stationContext; namespace texture { @@ -27,22 +28,59 @@ namespace texture { GLuint planet_ao; GLuint planet_normal; GLuint planet_roughness; + GLuint planet_metallic; GLuint mars_albedo; GLuint mars_normal; GLuint mars_ao; + GLuint mars_roughness; + GLuint mars_metallic; GLuint ship_albedo; GLuint ship_normal; GLuint ship_ao; GLuint ship_roughness; + GLuint ship_metallic; + + GLuint jupiter_albedo; + GLuint jupiter_normal; + GLuint jupiter_ao; + GLuint jupiter_roughness; + GLuint jupiter_metallic; + + GLuint venus_albedo; + GLuint venus_ao; + GLuint venus_normal; + GLuint venus_roughness; + GLuint venus_metallic; + + GLuint earth_albedo; + GLuint earth_normal; + GLuint earth_ao; + GLuint earth_roughness; + GLuint earth_metallic; + + GLuint moon_albedo; + GLuint moon_normal; + GLuint moon_ao; + GLuint moon_roughness; + GLuint moon_metallic; + + GLuint station_albedo; + GLuint station_normal; + GLuint station_ao; + GLuint station_roughness; + GLuint station_metallic; } float aspectRatio = 1.f; -glm::vec3 cameraPos = glm::vec3(-4.0f, 0.0f, 0.0f); -glm::vec3 cameraFront = glm::vec3(1.0f, 0.0f, 0.0f); -glm::vec3 cameraUp = glm::vec3(0.0f, 1.0f, 0.0f); +glm::vec3 cameraPos; +glm::vec3 cameraDir; + + +glm::vec3 spaceshipPos = glm::vec3(-4.0f, 0.0f, 0.0f); +glm::vec3 spaceshipDir = glm::vec3(1.0f, 0.0f, 0.0f); //declarations of functions void loadModelToContext(std::string path, Core::RenderContext& context); @@ -54,7 +92,7 @@ glm::mat4 createPerspectiveMatrix(); glm::mat4 createCameraMatrix(); void drawObjectSun(Core::RenderContext& context, glm::mat4 modelMatrix); -void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint ao, GLuint normal, GLuint roughness); +void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint ao, GLuint normal, GLuint roughness, GLuint metallic); void init(GLFWwindow* window) { @@ -73,6 +111,8 @@ void init(GLFWwindow* window) loadModelToContext("./models/sphere.obj", planetContext); + loadModelToContext("./models/station.obj", stationContext); + //load textures here @@ -82,16 +122,43 @@ void init(GLFWwindow* window) texture::planet_ao = Core::LoadTexture("textures/planet/ao.jpg"); texture::planet_normal = Core::LoadTexture("textures/planet/normal.jpg"); texture::planet_roughness = Core::LoadTexture("textures/planet/roughness.jpg"); - + texture::planet_metallic = Core::LoadTexture("textures/planet/metallic.png"); texture::mars_albedo = Core::LoadTexture("textures/mars/albedo.jpg"); texture::mars_normal = Core::LoadTexture("textures/mars/normal.png"); texture::mars_ao = Core::LoadTexture("textures/mars/ao.png"); + texture::mars_roughness = Core::LoadTexture("textures/mars/roughness.png"); + texture::mars_metallic = Core::LoadTexture("textures/mars/metallic.png"); texture::ship_albedo = Core::LoadTexture("textures/ship/albedo.png"); texture::ship_ao = Core::LoadTexture("textures/ship/ao.png"); texture::ship_normal = Core::LoadTexture("textures/ship/normal.png"); texture::ship_roughness = Core::LoadTexture("textures/ship/roughness.png"); + texture::ship_metallic = Core::LoadTexture("textures/ship/metallic.jpg"); + + texture::jupiter_albedo = Core::LoadTexture("textures/jupiter/albedo.png"); + texture::jupiter_normal = Core::LoadTexture("textures/jupiter/normal.png"); + texture::jupiter_ao = Core::LoadTexture("textures/jupiter/ao.png"); + texture::jupiter_roughness = Core::LoadTexture("textures/jupiter/roughness.png"); + texture::jupiter_metallic = Core::LoadTexture("textures/jupiter/metallic.png"); + + texture::earth_albedo = Core::LoadTexture("textures/earth/albedo.png"); + texture::earth_normal = Core::LoadTexture("textures/earth/normal.png"); + texture::earth_roughness = Core::LoadTexture("textures/earth/roughness.png"); + texture::earth_ao = Core::LoadTexture("textures/earth/ao.png"); + texture::earth_metallic = Core::LoadTexture("textures/earth/metallic.png"); + + texture::moon_albedo = Core::LoadTexture("textures/moon/albedo.jpg"); + texture::moon_normal = Core::LoadTexture("textures/moon/normal.jpg"); + texture::moon_roughness = Core::LoadTexture("textures/moon/roughness.jpg"); + texture::moon_ao = Core::LoadTexture("textures/moon/ao.jpg"); + texture::moon_metallic = Core::LoadTexture("textures/moon/metallic.png"); + + texture::station_albedo = Core::LoadTexture("textures/station/albedo.jpg"); + texture::station_normal = Core::LoadTexture("textures/station/normal.png"); + texture::station_roughness = Core::LoadTexture("textures/station/roughness.jpg"); + texture::station_ao = Core::LoadTexture("textures/station/ao.jpg"); + texture::station_metallic = Core::LoadTexture("textures/station/metallic.jpg"); } void renderScene(GLFWwindow* window){ @@ -104,14 +171,33 @@ void renderScene(GLFWwindow* window){ //desired objects go here drawObjectSun(sunContext, glm::scale(glm::vec3(0.1f)) * glm::eulerAngleY(time/10)); - drawObjectPBR(shipContext, glm::translate(cameraPos) * glm::translate(glm::vec3(0.85f, -0.25f, 0.f)) - * glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(0, 0, 1)) - * glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(0, 1, 0)) - * glm::rotate(glm::mat4(1.0f), glm::radians(-5.f), glm::vec3(1, 0, 0)) - * glm::scale(glm::vec3(0.015f)), - texture::ship_albedo, texture::ship_normal, texture::ship_ao, texture::ship_roughness); - drawObjectPBR(planetContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(-2*time), texture::planet_albedo, texture::planet_normal, texture::planet_ao, texture::planet_roughness); - drawObjectPBR(planetContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(-4.f, 0, 0)) * glm::eulerAngleY(-2*time), texture::mars_albedo, texture::mars_normal, texture::mars_ao, 0); + + glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); + glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir)); + + glm::mat4 spaceshipRotationMatrix = glm::mat4({ + spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0, + spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0, + -spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0, + 0.,0.,0.,1., + }); + + drawObjectPBR(shipContext, + glm::translate(spaceshipPos) + * spaceshipRotationMatrix + * glm::translate(glm::vec3(0.f, -0.1f, 0.1f)) + * glm::eulerAngleX(glm::radians(80.f)) + * glm::eulerAngleY(glm::radians(180.f)) + * glm::scale(glm::vec3(0.005f)), + texture::ship_albedo, texture::ship_normal, texture::ship_ao, texture::ship_roughness, texture::ship_metallic); + + drawObjectPBR(planetContext, glm::eulerAngleY(time/3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(-0.5f*time), texture::planet_albedo, texture::planet_normal, texture::planet_ao, texture::planet_roughness, texture::planet_metallic); + drawObjectPBR(planetContext, glm::eulerAngleY(time/3) * glm::translate(glm::vec3(-4.f, 0, 0)) * glm::eulerAngleY(-0.5f*time), texture::mars_albedo, texture::mars_normal, texture::mars_ao, texture::mars_roughness, texture::mars_metallic); + drawObjectPBR(planetContext, glm::eulerAngleY(time/3) * glm::translate(glm::vec3(0, 0, 4.f)) * glm::eulerAngleY(-0.5f*time), texture::jupiter_albedo, texture::jupiter_normal, texture::jupiter_ao, texture::jupiter_roughness, texture::jupiter_metallic); + drawObjectPBR(planetContext, glm::eulerAngleY(time/3) * glm::translate(glm::vec3(0, 0, -4.f)) * glm::eulerAngleY(-0.5f*time), texture::earth_albedo, texture::earth_normal, texture::earth_ao, texture::earth_roughness, texture::earth_metallic); + drawObjectPBR(planetContext, glm::translate(glm::vec3(4.f, 0, 4.f)) * glm::eulerAngleY(-0.5f * time), texture::moon_albedo, texture::moon_normal, texture::moon_ao, texture::moon_roughness, texture::moon_metallic); + + drawObjectPBR(stationContext, glm::translate(glm::vec3(0.f, 3.f, 0.f)) * glm::scale(glm::vec3(0.1f)) * glm::eulerAngleY(time), texture::station_albedo, texture::station_normal, texture::station_ao, texture::station_roughness, texture::station_metallic); //desired objects end here glUseProgram(0); glfwSwapBuffers(window); @@ -124,16 +210,20 @@ void processInput(GLFWwindow* window) float cameraSpeed = 0.1f; if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) - cameraPos += cameraSpeed * cameraFront; + spaceshipPos += cameraSpeed * spaceshipDir; if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) - cameraPos -= cameraSpeed * cameraFront; + spaceshipPos -= cameraSpeed * spaceshipDir; if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) - cameraPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed; + spaceshipDir = glm::vec3(glm::eulerAngleY(cameraSpeed) * glm::vec4(spaceshipDir, 0)); if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) - cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed; + spaceshipDir = glm::vec3(glm::eulerAngleY(-cameraSpeed) * glm::vec4(spaceshipDir, 0)); + + + cameraDir = spaceshipDir; + cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.05f; } -void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint normal, GLuint ao, GLuint roughness) { +void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint albedo, GLuint normal, GLuint ao, GLuint roughness, GLuint metallic) { glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); glm::mat4 transformation = viewProjectionMatrix * modelMatrix; @@ -148,6 +238,7 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint a Core::SetActiveTexture(normal, "normalMap", program, 1); Core::SetActiveTexture(ao, "aoMap", program, 2); Core::SetActiveTexture(roughness, "roughnessMap", program, 3); + Core::SetActiveTexture(metallic, "metallicMap", program, 4); Core::DrawContext(context); } @@ -228,12 +319,12 @@ glm::mat4 createPerspectiveMatrix() glm::mat4 createCameraMatrix() { - glm::vec3 cameraSide = glm::normalize(glm::cross(cameraFront, glm::vec3(0.f, 1.f, 0.f))); - glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraFront)); + glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f))); + glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraDir)); glm::mat4 cameraRotrationMatrix = glm::mat4({ cameraSide.x,cameraSide.y,cameraSide.z,0, cameraUp.x,cameraUp.y,cameraUp.z ,0, - -cameraFront.x,-cameraFront.y,-cameraFront.z,0, + -cameraDir.x,-cameraDir.y,-cameraDir.z,0, 0.,0.,0.,1., }); cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix); diff --git a/cw_8/textures/earth/albedo.png b/cw_8/textures/earth/albedo.png new file mode 100644 index 0000000..c2ccf04 Binary files /dev/null and b/cw_8/textures/earth/albedo.png differ diff --git a/cw_8/textures/earth/ao.png b/cw_8/textures/earth/ao.png new file mode 100644 index 0000000..0d8b5b7 Binary files /dev/null and b/cw_8/textures/earth/ao.png differ diff --git a/cw_8/textures/earth/metallic.png b/cw_8/textures/earth/metallic.png new file mode 100644 index 0000000..1d1644a Binary files /dev/null and b/cw_8/textures/earth/metallic.png differ diff --git a/cw_8/textures/earth/normal.png b/cw_8/textures/earth/normal.png new file mode 100644 index 0000000..25dc4f8 Binary files /dev/null and b/cw_8/textures/earth/normal.png differ diff --git a/cw_8/textures/earth/roughness.png b/cw_8/textures/earth/roughness.png new file mode 100644 index 0000000..a4ea195 Binary files /dev/null and b/cw_8/textures/earth/roughness.png differ diff --git a/cw_8/textures/jupiter/albedo.png b/cw_8/textures/jupiter/albedo.png new file mode 100644 index 0000000..a58760c Binary files /dev/null and b/cw_8/textures/jupiter/albedo.png differ diff --git a/cw_8/textures/jupiter/ao.png b/cw_8/textures/jupiter/ao.png new file mode 100644 index 0000000..0273b9f Binary files /dev/null and b/cw_8/textures/jupiter/ao.png differ diff --git a/cw_8/textures/jupiter/metallic.png b/cw_8/textures/jupiter/metallic.png new file mode 100644 index 0000000..1d1644a Binary files /dev/null and b/cw_8/textures/jupiter/metallic.png differ diff --git a/cw_8/textures/jupiter/normal.png b/cw_8/textures/jupiter/normal.png new file mode 100644 index 0000000..9845949 Binary files /dev/null and b/cw_8/textures/jupiter/normal.png differ diff --git a/cw_8/textures/jupiter/roughness.png b/cw_8/textures/jupiter/roughness.png new file mode 100644 index 0000000..a4ea195 Binary files /dev/null and b/cw_8/textures/jupiter/roughness.png differ diff --git a/cw_8/textures/mars/ao.png b/cw_8/textures/mars/ao.png index 1db8b6a..f629d9b 100644 Binary files a/cw_8/textures/mars/ao.png and b/cw_8/textures/mars/ao.png differ diff --git a/cw_8/textures/mars/metallic.png b/cw_8/textures/mars/metallic.png new file mode 100644 index 0000000..1d1644a Binary files /dev/null and b/cw_8/textures/mars/metallic.png differ diff --git a/cw_8/textures/mars/normal.png b/cw_8/textures/mars/normal.png index 2bb7f1a..615017f 100644 Binary files a/cw_8/textures/mars/normal.png and b/cw_8/textures/mars/normal.png differ diff --git a/cw_8/textures/mars/roughness.png b/cw_8/textures/mars/roughness.png new file mode 100644 index 0000000..a4ea195 Binary files /dev/null and b/cw_8/textures/mars/roughness.png differ diff --git a/cw_8/textures/moon/albedo.jpg b/cw_8/textures/moon/albedo.jpg new file mode 100644 index 0000000..908c6bc Binary files /dev/null and b/cw_8/textures/moon/albedo.jpg differ diff --git a/cw_8/textures/moon/ao.jpg b/cw_8/textures/moon/ao.jpg new file mode 100644 index 0000000..64987d2 Binary files /dev/null and b/cw_8/textures/moon/ao.jpg differ diff --git a/cw_8/textures/moon/metallic.png b/cw_8/textures/moon/metallic.png new file mode 100644 index 0000000..1d1644a Binary files /dev/null and b/cw_8/textures/moon/metallic.png differ diff --git a/cw_8/textures/moon/normal.jpg b/cw_8/textures/moon/normal.jpg new file mode 100644 index 0000000..2f351f8 Binary files /dev/null and b/cw_8/textures/moon/normal.jpg differ diff --git a/cw_8/textures/moon/roughness.jpg b/cw_8/textures/moon/roughness.jpg new file mode 100644 index 0000000..08d33b4 Binary files /dev/null and b/cw_8/textures/moon/roughness.jpg differ diff --git a/cw_8/textures/planet/metallic.png b/cw_8/textures/planet/metallic.png new file mode 100644 index 0000000..1d1644a Binary files /dev/null and b/cw_8/textures/planet/metallic.png differ diff --git a/cw_8/textures/ship/albedo.png b/cw_8/textures/ship/albedo.png index 46341ae..65b8e2d 100644 Binary files a/cw_8/textures/ship/albedo.png and b/cw_8/textures/ship/albedo.png differ diff --git a/cw_8/textures/ship/ao.png b/cw_8/textures/ship/ao.png index 7306c30..5acff8c 100644 Binary files a/cw_8/textures/ship/ao.png and b/cw_8/textures/ship/ao.png differ diff --git a/cw_8/textures/ship/metallic.png b/cw_8/textures/ship/metallic.png new file mode 100644 index 0000000..95d8477 Binary files /dev/null and b/cw_8/textures/ship/metallic.png differ diff --git a/cw_8/textures/ship/normal.png b/cw_8/textures/ship/normal.png index e30cbf7..cbdad44 100644 Binary files a/cw_8/textures/ship/normal.png and b/cw_8/textures/ship/normal.png differ diff --git a/cw_8/textures/ship/roughness.png b/cw_8/textures/ship/roughness.png index 6451ff8..d220185 100644 Binary files a/cw_8/textures/ship/roughness.png and b/cw_8/textures/ship/roughness.png differ diff --git a/cw_8/textures/station/albedo.jpg b/cw_8/textures/station/albedo.jpg new file mode 100644 index 0000000..e71b196 Binary files /dev/null and b/cw_8/textures/station/albedo.jpg differ diff --git a/cw_8/textures/station/ao.jpg b/cw_8/textures/station/ao.jpg new file mode 100644 index 0000000..63869ac Binary files /dev/null and b/cw_8/textures/station/ao.jpg differ diff --git a/cw_8/textures/station/metallic.jpg b/cw_8/textures/station/metallic.jpg new file mode 100644 index 0000000..f91635b Binary files /dev/null and b/cw_8/textures/station/metallic.jpg differ diff --git a/cw_8/textures/station/normal.png b/cw_8/textures/station/normal.png new file mode 100644 index 0000000..4de0437 Binary files /dev/null and b/cw_8/textures/station/normal.png differ diff --git a/cw_8/textures/station/roughness.jpg b/cw_8/textures/station/roughness.jpg new file mode 100644 index 0000000..ed995df Binary files /dev/null and b/cw_8/textures/station/roughness.jpg differ diff --git a/grk-cw.sln b/grk-cw.sln index 124132f..5351dca 100644 --- a/grk-cw.sln +++ b/grk-cw.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.1.32319.34 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw8", "cw_8\grk-cw8.vcxproj", "{6D813233-7D21-4888-944E-8E3CCAC3EFD3}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw4", "..\cw 4\grk-cw4.vcxproj", "{D7858112-9412-4E7E-AB73-A911604592EC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -15,6 +17,10 @@ Global {6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Debug|x86.Build.0 = Debug|Win32 {6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Release|x86.ActiveCfg = Release|Win32 {6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Release|x86.Build.0 = Release|Win32 + {D7858112-9412-4E7E-AB73-A911604592EC}.Debug|x86.ActiveCfg = Debug|Win32 + {D7858112-9412-4E7E-AB73-A911604592EC}.Debug|x86.Build.0 = Debug|Win32 + {D7858112-9412-4E7E-AB73-A911604592EC}.Release|x86.ActiveCfg = Release|Win32 + {D7858112-9412-4E7E-AB73-A911604592EC}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE