This commit is contained in:
Nikodem145 2024-01-20 00:28:55 +01:00
parent 6e4a9fbc06
commit 1daaba6e17
2 changed files with 39 additions and 9 deletions

View File

@ -1,6 +1,9 @@
#version 430 core #version 430 core
float AMBIENT = 0.1; float AMBIENT = 0.3;
float roughness = 0.2;
float metalic = 0.8;
uniform vec3 color; uniform vec3 color;
uniform sampler2D colorTexture; uniform sampler2D colorTexture;
@ -17,7 +20,8 @@ out vec4 outColor;
void main() void main()
{ {
vec3 normal = vec3(0,0,1); 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; vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
@ -25,7 +29,31 @@ void main()
N = 2.0 * N - 1.0; N = 2.0 * N - 1.0;
N = normalize(N); N = normalize(N);
//float diffuse=max(0,dot(normal,lightDir)); vec3 H = normalize(L + V); // mo¿e trzeba zmieniæ plus na minus
float diffuse=max(0,dot(N,lightDir)); float NdotH = max(0.0, dot(N, H)); // zamieniæ kolejnoœæ i 00000001
outColor = vec4(textureColor*min(1,AMBIENT+diffuse), 1.0); 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);
} }

View File

@ -23,6 +23,7 @@ namespace texture {
GLuint moon; GLuint moon;
GLuint ship; GLuint ship;
GLuint rust; GLuint rust;
GLuint sun;
GLuint mars; GLuint mars;
GLuint mercury; GLuint mercury;
@ -198,7 +199,7 @@ void renderScene(GLFWwindow* window)
drawObjectSkyBox(cubeContext, glm::translate(cameraPos)); 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, 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, 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) * 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 / 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 / 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 / 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 / 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); 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::saturn = Core::LoadTexture("textures/8k_saturn.jpg");
texture::uranus = Core::LoadTexture("textures/2k_uranus.jpg"); texture::uranus = Core::LoadTexture("textures/2k_uranus.jpg");
texture::neptune = Core::LoadTexture("textures/2k_neptune.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))); spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
spaceshipUp = glm::vec3(0.f, 1.f, 0.f); spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
float angleSpeed = 0.01f; float angleSpeed = 0.05f;
float moveSpeed = 0.01f; float moveSpeed = 0.05f;
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);