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
|
||||
|
||||
float AMBIENT = 0.2;
|
||||
float roughness = 0.1;
|
||||
float metalic = 0.8;
|
||||
float AMBIENT = 0.6;
|
||||
float roughness;
|
||||
float metalic;
|
||||
|
||||
|
||||
uniform vec3 color;
|
||||
uniform sampler2D colorTexture;
|
||||
uniform sampler2D normalSampler;
|
||||
|
||||
uniform sampler2D metalnessTexture;
|
||||
uniform sampler2D roughnessTexture;
|
||||
|
||||
in vec3 worldPos;
|
||||
in vec2 vecTex;
|
||||
|
||||
@ -24,6 +27,11 @@ void main()
|
||||
vec3 V = (viewDirTS);
|
||||
|
||||
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;
|
||||
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 ggx1 = NdotV / (NdotV * (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;
|
||||
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));
|
||||
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 shipNormal;
|
||||
GLuint rustNormal;
|
||||
|
||||
GLuint metalnessSphere;
|
||||
GLuint roughnessSphere;
|
||||
}
|
||||
|
||||
|
||||
@ -110,7 +113,7 @@ glm::mat4 createPerspectiveMatrix()
|
||||
|
||||
glm::mat4 perspectiveMatrix;
|
||||
float n = 0.05;
|
||||
float f = 20.;
|
||||
float f = 60.;
|
||||
float a1 = glm::min(aspectRatio, 1.f);
|
||||
float a2 = glm::min(1 / aspectRatio, 1.f);
|
||||
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);
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
|
||||
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniform3f(glGetUniformLocation(programTex, "lightPos"), 0, 0, 0);
|
||||
|
||||
Core::SetActiveTexture(normalMapId, "normalSampler", programTex, 1);
|
||||
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);
|
||||
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) {
|
||||
glm::vec3 normalizedDir = glm::normalize(distance);
|
||||
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();
|
||||
|
||||
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));
|
||||
|
||||
|
||||
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,
|
||||
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 / 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 / 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);
|
||||
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, 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, 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, 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, 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, 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, texture::metalnessSphere, texture::roughnessSphere);
|
||||
|
||||
|
||||
spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
@ -246,8 +259,7 @@ void renderScene(GLFWwindow* window)
|
||||
|
||||
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)),
|
||||
texture::ship, texture::shipNormal
|
||||
);
|
||||
texture::ship, texture::shipNormal, texture::metalnessSphere, texture::roughnessSphere);
|
||||
//drawObjectTexture(shipContext,
|
||||
// glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>())*glm::scale(glm::vec3(0.1f)),
|
||||
// texture::ship, texture::shipNormal
|
||||
@ -339,6 +351,9 @@ void init(GLFWwindow* window)
|
||||
texture::rustNormal = Core::LoadTexture("textures/rust_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);
|
||||
@ -423,8 +438,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.005f;
|
||||
float moveSpeed = 0.005f;
|
||||
float angleSpeed = 0.05f;
|
||||
float moveSpeed = 0.05f;
|
||||
|
||||
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