Merge branch 'master' of https://git.wmi.amu.edu.pl/s473561/Grafika_Komputerowa_Interstellar_Odyssey
This commit is contained in:
commit
40eeb29faa
@ -1,14 +1,17 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
|
|
||||||
float AMBIENT = 0.2;
|
float AMBIENT = 0.6;
|
||||||
float roughness = 0.1;
|
float roughness;
|
||||||
float metalic = 0.8;
|
float metalic;
|
||||||
|
|
||||||
|
|
||||||
uniform vec3 color;
|
uniform vec3 color;
|
||||||
uniform sampler2D colorTexture;
|
uniform sampler2D colorTexture;
|
||||||
uniform sampler2D normalSampler;
|
uniform sampler2D normalSampler;
|
||||||
|
|
||||||
|
uniform sampler2D metalnessTexture;
|
||||||
|
uniform sampler2D roughnessTexture;
|
||||||
|
|
||||||
in vec3 worldPos;
|
in vec3 worldPos;
|
||||||
in vec2 vecTex;
|
in vec2 vecTex;
|
||||||
|
|
||||||
@ -24,6 +27,11 @@ void main()
|
|||||||
vec3 V = (viewDirTS);
|
vec3 V = (viewDirTS);
|
||||||
|
|
||||||
vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
|
vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
|
||||||
|
float metalnessValue = texture2D(metalnessTexture, vecTex).r;
|
||||||
|
float roughnessValue = texture2D(roughnessTexture, vecTex).r;
|
||||||
|
|
||||||
|
roughness =roughnessValue;
|
||||||
|
metalic = metalnessValue;
|
||||||
|
|
||||||
vec3 N = texture2D(normalSampler, vecTex).xyz;
|
vec3 N = texture2D(normalSampler, vecTex).xyz;
|
||||||
N = 2.0 * N - 1.0;
|
N = 2.0 * N - 1.0;
|
||||||
@ -40,7 +48,7 @@ void main()
|
|||||||
float D = (roughness * roughness) / (3.14159 * pow(pow(NdotH * NdotH,2.0) * (roughness * roughness - 1.0) + 1.0, 2.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 ggx1 = NdotV / (NdotV * (1.0 - k) + k);
|
||||||
float ggx2 = NdotL / (NdotL * (1.0 - k) + k);
|
float ggx2 = NdotL / (NdotL * (1.0 - k) + k);
|
||||||
vec3 F0 = vec3(0.04);
|
vec3 F0 = mix(vec3(0.04), vec3(1.0), metalic);
|
||||||
float G = ggx1 * ggx2;
|
float G = ggx1 * ggx2;
|
||||||
vec3 F = F0 + (1.0-F0)*pow(1-dot(V,H),5.0);
|
vec3 F = F0 + (1.0-F0)*pow(1-dot(V,H),5.0);
|
||||||
|
|
||||||
@ -54,8 +62,8 @@ void main()
|
|||||||
|
|
||||||
|
|
||||||
float diffuse=max(0.0001,dot(N,L));
|
float diffuse=max(0.0001,dot(N,L));
|
||||||
vec3 lambertian = max(0.00001, dot(N,L))*textureColor;
|
|
||||||
|
|
||||||
vec3 Final = (kD*textureColor/3.1458993) + specular;
|
|
||||||
outColor = vec4(Final*min(1.0,AMBIENT + diffuse), 1.0);
|
outColor = vec4(BRDF*min(1.0,AMBIENT + diffuse), 1.0);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,9 @@ namespace texture {
|
|||||||
GLuint moonNormal;
|
GLuint moonNormal;
|
||||||
GLuint shipNormal;
|
GLuint shipNormal;
|
||||||
GLuint rustNormal;
|
GLuint rustNormal;
|
||||||
|
|
||||||
|
GLuint metalnessSphere;
|
||||||
|
GLuint roughnessSphere;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,7 +113,7 @@ glm::mat4 createPerspectiveMatrix()
|
|||||||
|
|
||||||
glm::mat4 perspectiveMatrix;
|
glm::mat4 perspectiveMatrix;
|
||||||
float n = 0.05;
|
float n = 0.05;
|
||||||
float f = 20.;
|
float f = 60.;
|
||||||
float a1 = glm::min(aspectRatio, 1.f);
|
float a1 = glm::min(aspectRatio, 1.f);
|
||||||
float a2 = glm::min(1 / aspectRatio, 1.f);
|
float a2 = glm::min(1 / aspectRatio, 1.f);
|
||||||
perspectiveMatrix = glm::mat4({
|
perspectiveMatrix = glm::mat4({
|
||||||
@ -139,18 +142,28 @@ void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::v
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalMapId) {
|
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalMapId, GLuint metalnessTexture, GLuint roughnessTexture) {
|
||||||
glUseProgram(programTex);
|
glUseProgram(programTex);
|
||||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||||
glUniform3f(glGetUniformLocation(programTex, "lightPos"), 0, 0, 0);
|
glUniform3f(glGetUniformLocation(programTex, "lightPos"), 0, 0, 0);
|
||||||
|
|
||||||
Core::SetActiveTexture(normalMapId, "normalSampler", programTex, 1);
|
Core::SetActiveTexture(normalMapId, "normalSampler", programTex, 1);
|
||||||
Core::SetActiveTexture(textureID, "colorTexture", programTex, 0);
|
Core::SetActiveTexture(textureID, "colorTexture", programTex, 0);
|
||||||
|
|
||||||
|
glUniform1i(glGetUniformLocation(programTex, "metalnessTexture"), 2);
|
||||||
|
glUniform1i(glGetUniformLocation(programTex, "roughnessTexture"), 3);
|
||||||
|
|
||||||
|
// Bind metalness and roughness textures to texture units
|
||||||
|
glActiveTexture(GL_TEXTURE2);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, metalnessTexture);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE3);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, roughnessTexture);
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||||
Core::DrawContext(context);
|
Core::DrawContext(context);
|
||||||
|
|
||||||
@ -173,7 +186,7 @@ void drawObjectSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
|
|||||||
void generateAsteroids(glm::vec3 asteroid_Pos, glm::vec3 distance, double step) {
|
void generateAsteroids(glm::vec3 asteroid_Pos, glm::vec3 distance, double step) {
|
||||||
glm::vec3 normalizedDir = glm::normalize(distance);
|
glm::vec3 normalizedDir = glm::normalize(distance);
|
||||||
asteroid_Pos = asteroid_Pos - normalizedDir *step;
|
asteroid_Pos = asteroid_Pos - normalizedDir *step;
|
||||||
drawObjectTexture(sphereContext, glm::translate(asteroid_Pos) * glm::scale(glm::vec3(0.1f)), texture::moon, texture::moonNormal);
|
drawObjectTexture(sphereContext, glm::translate(asteroid_Pos) * glm::scale(glm::vec3(0.1f)), texture::moon, texture::moonNormal, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +201,7 @@ void generatePlanetoidBelt() {
|
|||||||
|
|
||||||
float time = glfwGetTime();
|
float time = glfwGetTime();
|
||||||
|
|
||||||
drawObjectTexture(sphereContext,glm::eulerAngleY(time / 5) * glm::translate(glm::vec3(x, y, z)) * glm::scale(glm::vec3(pScale)), texture::moon, texture::moonNormal);
|
drawObjectTexture(sphereContext,glm::eulerAngleY(time / 5) * glm::translate(glm::vec3(x, y, z)) * glm::scale(glm::vec3(pScale)), texture::moon, texture::moonNormal, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,19 +231,19 @@ 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::sun, texture::rustNormal);
|
drawObjectTexture(sphereContext, glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::sun, texture::rustNormal, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
|
|
||||||
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, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
drawObjectTexture(sphereContext,
|
drawObjectTexture(sphereContext,
|
||||||
glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(8.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), texture::moon, texture::moonNormal);
|
glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(8.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), texture::moon, texture::moonNormal, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
|
|
||||||
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, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
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, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
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, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
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 / 50000) * glm::translate(glm::vec3(14.f, 0, 0)) * glm::eulerAngleY(time/500000) * glm::scale(glm::vec3(0.9f)), texture::jupiter, texture::rustNormal, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
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, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
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, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
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, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
|
|
||||||
|
|
||||||
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)));
|
||||||
@ -246,8 +259,7 @@ void renderScene(GLFWwindow* window)
|
|||||||
|
|
||||||
drawObjectTexture(shipContext,
|
drawObjectTexture(shipContext,
|
||||||
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::rotate(glm::mat4(), tiltAngle * glm::radians(30.0f), glm::vec3(0, 0, 1)) * glm::scale(glm::vec3(0.1f)),
|
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::rotate(glm::mat4(), tiltAngle * glm::radians(30.0f), glm::vec3(0, 0, 1)) * glm::scale(glm::vec3(0.1f)),
|
||||||
texture::ship, texture::shipNormal
|
texture::ship, texture::shipNormal, texture::metalnessSphere, texture::roughnessSphere);
|
||||||
);
|
|
||||||
//drawObjectTexture(shipContext,
|
//drawObjectTexture(shipContext,
|
||||||
// glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>())*glm::scale(glm::vec3(0.1f)),
|
// glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>())*glm::scale(glm::vec3(0.1f)),
|
||||||
// texture::ship, texture::shipNormal
|
// texture::ship, texture::shipNormal
|
||||||
@ -339,6 +351,9 @@ void init(GLFWwindow* window)
|
|||||||
texture::rustNormal = Core::LoadTexture("textures/rust_normal.jpg");
|
texture::rustNormal = Core::LoadTexture("textures/rust_normal.jpg");
|
||||||
texture::moonNormal = Core::LoadTexture("textures/moon_normal.jpg");
|
texture::moonNormal = Core::LoadTexture("textures/moon_normal.jpg");
|
||||||
|
|
||||||
|
texture::metalnessSphere = Core::LoadTexture("textures/rusty_metal_sheet_diff_2k.jpg");
|
||||||
|
texture::roughnessSphere = Core::LoadTexture("textures/rough_concrete_diff_1k.jpg");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glGenTextures(1, &textureID);
|
glGenTextures(1, &textureID);
|
||||||
@ -423,8 +438,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.005f;
|
float angleSpeed = 0.05f;
|
||||||
float moveSpeed = 0.005f;
|
float moveSpeed = 0.05f;
|
||||||
|
|
||||||
double x = 0.002;
|
double x = 0.002;
|
||||||
|
|
||||||
|
BIN
cw 7/textures/rough_concrete_diff_1k.jpg
Normal file
BIN
cw 7/textures/rough_concrete_diff_1k.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1018 KiB |
BIN
cw 7/textures/rusty_metal_sheet_diff_2k.jpg
Normal file
BIN
cw 7/textures/rusty_metal_sheet_diff_2k.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 MiB |
Loading…
Reference in New Issue
Block a user