From 1daaba6e17d7c4428700e6013614d0bc3eb8a715 Mon Sep 17 00:00:00 2001 From: Nikodem145 Date: Sat, 20 Jan 2024 00:28:55 +0100 Subject: [PATCH] .i. --- cw 7/shaders/shader_5_tex.frag | 38 +++++++++++++++++++++++++++++----- cw 7/src/ex_7_1.hpp | 10 +++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/cw 7/shaders/shader_5_tex.frag b/cw 7/shaders/shader_5_tex.frag index bf0cd90..80f4518 100644 --- a/cw 7/shaders/shader_5_tex.frag +++ b/cw 7/shaders/shader_5_tex.frag @@ -1,6 +1,9 @@ #version 430 core -float AMBIENT = 0.1; +float AMBIENT = 0.3; +float roughness = 0.2; +float metalic = 0.8; + uniform vec3 color; uniform sampler2D colorTexture; @@ -17,7 +20,8 @@ out vec4 outColor; void main() { vec3 normal = vec3(0,0,1); - vec3 lightDir = normalize(lightDirTS); + vec3 L = normalize(lightDirTS- worldPos); + vec3 V = normalize(viewDirTS - worldPos); vec3 textureColor = texture2D(colorTexture, vecTex).xyz; @@ -25,7 +29,31 @@ void main() N = 2.0 * N - 1.0; N = normalize(N); - //float diffuse=max(0,dot(normal,lightDir)); - float diffuse=max(0,dot(N,lightDir)); - outColor = vec4(textureColor*min(1,AMBIENT+diffuse), 1.0); + vec3 H = normalize(L + V); // może trzeba zmienić plus na minus + float NdotH = max(0.0, dot(N, H)); // zamienić kolejność i 00000001 + float NdotL = max(0.0, dot(N, L)); + float NdotV = max(0.0, dot(N, V)); + float VdotH = max(0.0, dot(V, H)); + float k = pow((roughness +1),2.0)/8.0; + + + float D = (roughness * roughness) / (3.14159 * pow(pow(NdotH * NdotH,2.0) * (roughness * roughness - 1.0) + 1.0, 2.0)); + float ggx1 = NdotV / (NdotV * (1.0 - k) + k); + float ggx2 = NdotL / (NdotL * (1.0 - k) + k); + vec3 F0 = vec3(0.04); + float G = ggx1 * ggx2; + vec3 F = F0 + (1.0-F0)*pow(1-VdotH,5.0); + + vec3 specular = (D*G*F)/(4*NdotL*NdotV); + vec3 kD = vec3(1.0) - F; + + vec3 BRDF = kD*(textureColor/3.1458493) + specular; + + + + + + float diffuse=max(0,dot(N,L)); + + outColor = vec4(( textureColor * min(1,AMBIENT+diffuse)), 1.0); } diff --git a/cw 7/src/ex_7_1.hpp b/cw 7/src/ex_7_1.hpp index 5c08ae7..94e9993 100644 --- a/cw 7/src/ex_7_1.hpp +++ b/cw 7/src/ex_7_1.hpp @@ -23,6 +23,7 @@ namespace texture { GLuint moon; GLuint ship; GLuint rust; + GLuint sun; GLuint mars; GLuint mercury; @@ -198,7 +199,7 @@ void renderScene(GLFWwindow* window) drawObjectSkyBox(cubeContext, glm::translate(cameraPos)); - drawObjectTexture(sphereContext, glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::rust, texture::rustNormal); + drawObjectTexture(sphereContext, glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::sun, texture::rustNormal); drawObjectTexture(sphereContext, glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(8.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.3f)), texture::earth, texture::earthNormal); drawObjectTexture(sphereContext, @@ -207,7 +208,7 @@ void renderScene(GLFWwindow* window) drawObjectTexture(sphereContext, glm::eulerAngleY(time) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.15f)), texture::mercury, texture::rustNormal); drawObjectTexture(sphereContext, glm::eulerAngleY(time / 4) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.2f)), texture::mars, texture::rustNormal); drawObjectTexture(sphereContext, glm::eulerAngleY(time / 2) * glm::translate(glm::vec3(6.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.3f)), texture::venus, texture::rustNormal); - drawObjectTexture(sphereContext, glm::eulerAngleY(time / 5) * glm::translate(glm::vec3(14.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.9f)), texture::jupiter, texture::rustNormal); + drawObjectTexture(sphereContext, glm::eulerAngleY(time / 50000) * glm::translate(glm::vec3(14.f, 0, 0)) * glm::eulerAngleY(time/500000) * glm::scale(glm::vec3(0.9f)), texture::jupiter, texture::rustNormal); drawObjectTexture(sphereContext, glm::eulerAngleY(time / 6) * glm::translate(glm::vec3(17.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.9f)), texture::saturn, texture::rustNormal); drawObjectTexture(sphereContext, glm::eulerAngleY(time / 7) * glm::translate(glm::vec3(20.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.6f)), texture::uranus, texture::rustNormal); drawObjectTexture(sphereContext, glm::eulerAngleY(time / 8) * glm::translate(glm::vec3(23.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.6f)), texture::neptune, texture::rustNormal); @@ -313,6 +314,7 @@ void init(GLFWwindow* window) texture::saturn = Core::LoadTexture("textures/8k_saturn.jpg"); texture::uranus = Core::LoadTexture("textures/2k_uranus.jpg"); texture::neptune = Core::LoadTexture("textures/2k_neptune.jpg"); + texture::sun = Core::LoadTexture("textures/2k_sun.jpg"); @@ -399,8 +401,8 @@ void processInput(GLFWwindow* window) { spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); spaceshipUp = glm::vec3(0.f, 1.f, 0.f); - float angleSpeed = 0.01f; - float moveSpeed = 0.01f; + float angleSpeed = 0.05f; + float moveSpeed = 0.05f; glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);