diff --git a/.vs/grk-project/v16/.suo b/.vs/grk-project/v16/.suo index 8efacd0..d5c2ffa 100644 Binary files a/.vs/grk-project/v16/.suo and b/.vs/grk-project/v16/.suo differ diff --git a/.vs/grk-project/v16/Browse.VC.db b/.vs/grk-project/v16/Browse.VC.db index 1722b03..a0a6eea 100644 Binary files a/.vs/grk-project/v16/Browse.VC.db and b/.vs/grk-project/v16/Browse.VC.db differ diff --git a/Release/room.exe b/Release/room.exe index c125592..c62da53 100644 Binary files a/Release/room.exe and b/Release/room.exe differ diff --git a/Release/room.pdb b/Release/room.pdb index 015992a..fd337a9 100644 Binary files a/Release/room.pdb and b/Release/room.pdb differ diff --git a/cw 9/Release/grk-cw9.log b/cw 9/Release/grk-cw9.log index 8673449..13a0aad 100644 --- a/cw 9/Release/grk-cw9.log +++ b/cw 9/Release/grk-cw9.log @@ -1,34 +1,35 @@  main.cpp C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: "APIENTRY": ponowna definicja makra D:\UAM\Grafika komputerowa\projekt\GRK_Room\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY” -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(118,30): warning C4305: "inicjowanie": obcięcie z "double" do "float" -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(136,38): warning C4305: "=": obcięcie z "double" do "float" -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(159,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(178,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(196,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(288,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(294,96): warning C4305: "argument": obcięcie z "double" do "T" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(120,30): warning C4305: "inicjowanie": obcięcie z "double" do "float" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(138,38): warning C4305: "=": obcięcie z "double" do "float" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(161,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(180,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(198,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(338,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(344,96): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(297,59): warning C4305: "argument": obcięcie z "double" do "T" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(347,59): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(445,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(470,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(487,109): warning C4305: "argument": obcięcie z "double" do "T" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(495,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(520,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(534,109): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(539,2): warning C4305: "argument": obcięcie z "double" do "float" -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(678,21): warning C4305: "-=": obcięcie z "double" do "float" -D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(680,21): warning C4305: "+=": obcięcie z "double" do "float" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(587,2): warning C4305: "argument": obcięcie z "double" do "float" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(727,21): warning C4305: "-=": obcięcie z "double" do "float" +D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(729,21): warning C4305: "+=": obcięcie z "double" do "float" Trwa generowanie kodu - Previous IPDB and IOBJ mismatch, fall back to full compilation. - All 607 functions were compiled because no usable IPDB/IOBJ from previous compilation was found. + 47 of 607 functions ( 7.7%) were compiled, the rest were copied from previous compilation. + 0 functions were new in current compilation + 9 functions had inline decision re-evaluated but remain unchanged Zakończono generowanie kodu grk-cw9.vcxproj -> D:\UAM\Grafika komputerowa\projekt\GRK_Room\Release\room.exe diff --git a/cw 9/Release/main.obj b/cw 9/Release/main.obj index 3024a8f..2481f4d 100644 Binary files a/cw 9/Release/main.obj and b/cw 9/Release/main.obj differ diff --git a/cw 9/Release/room.iobj b/cw 9/Release/room.iobj index 2a1400d..2e646a8 100644 Binary files a/cw 9/Release/room.iobj and b/cw 9/Release/room.iobj differ diff --git a/cw 9/Release/room.ipdb b/cw 9/Release/room.ipdb index 31144cd..f7188a1 100644 Binary files a/cw 9/Release/room.ipdb and b/cw 9/Release/room.ipdb differ diff --git a/cw 9/Release/vc142.pdb b/cw 9/Release/vc142.pdb index 315b00b..76b7bf9 100644 Binary files a/cw 9/Release/vc142.pdb and b/cw 9/Release/vc142.pdb differ diff --git a/cw 9/grk-cw9.vcxproj.user b/cw 9/grk-cw9.vcxproj.user index 0f14913..429333d 100644 --- a/cw 9/grk-cw9.vcxproj.user +++ b/cw 9/grk-cw9.vcxproj.user @@ -1,4 +1,6 @@  - + + true + \ No newline at end of file diff --git a/cw 9/shaders/shader_5_1_tex.frag b/cw 9/shaders/shader_5_1_tex.frag deleted file mode 100644 index 81337d9..0000000 --- a/cw 9/shaders/shader_5_1_tex.frag +++ /dev/null @@ -1,18 +0,0 @@ -#version 430 core - -float AMBIENT = 0.1; - -uniform vec3 color; -uniform vec3 lightPos; - -in vec3 vecNormal; -in vec3 worldPos; - -out vec4 outColor; -void main() -{ - vec3 lightDir = normalize(lightPos-worldPos); - vec3 normal = normalize(vecNormal); - float diffuse=max(0,dot(normal,lightDir)); - outColor = vec4(color*min(1,AMBIENT+diffuse), 1.0); -} diff --git a/cw 9/shaders/shader_5_1_tex.vert b/cw 9/shaders/shader_5_1_tex.vert deleted file mode 100644 index d73af9e..0000000 --- a/cw 9/shaders/shader_5_1_tex.vert +++ /dev/null @@ -1,18 +0,0 @@ -#version 430 core - -layout(location = 0) in vec3 vertexPosition; -layout(location = 1) in vec3 vertexNormal; -layout(location = 2) in vec2 vertexTexCoord; - -uniform mat4 transformation; -uniform mat4 modelMatrix; - -out vec3 vecNormal; -out vec3 worldPos; - -void main() -{ - worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz; - vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz; - gl_Position = transformation * vec4(vertexPosition, 1.0); -} diff --git a/cw 9/shaders/shader_tex.frag b/cw 9/shaders/shader_tex.frag new file mode 100644 index 0000000..a7aa819 --- /dev/null +++ b/cw 9/shaders/shader_tex.frag @@ -0,0 +1,150 @@ +#version 430 core + +float AMBIENT = 0.03; +float PI = 3.14; + +uniform sampler2D depthMapSun; + +uniform vec3 cameraPos; + +uniform vec3 color; + +uniform vec3 sunDir; +uniform vec3 sunColor; + +uniform vec3 lightPos; +uniform vec3 lightColor; + +uniform sampler2D colorTexture; +in vec2 vecTex; + +uniform vec3 spotlightPos; +uniform vec3 spotlightColor; +uniform vec3 spotlightConeDir; +uniform vec3 spotlightPhi; + +uniform float metallic; +uniform float roughness; + +uniform float exposition; + +in vec3 vecNormal; +in vec3 worldPos; + +out vec4 outColor; + + +in vec3 viewDirTS; +in vec3 lightDirTS; +in vec3 spotlightDirTS; +in vec3 sunDirTS; + +in vec4 sunSpacePos; + +in vec3 test; +uniform float time; + +float DistributionGGX(vec3 normal, vec3 H, float roughness){ + float a = roughness*roughness; + float a2 = a*a; + float NdotH = max(dot(normal, H), 0.0); + float NdotH2 = NdotH*NdotH; + + float num = a2; + float denom = (NdotH2 * (a2 - 1.0) + 1.0); + denom = PI * denom * denom; + + return num / denom; +} +float GeometrySchlickGGX(float NdotV, float roughness){ + float r = (roughness + 1.0); + float k = (r*r) / 8.0; + + float num = NdotV; + float denom = NdotV * (1.0 - k) + k; + + return num / denom; +} +float GeometrySmith(vec3 normal, vec3 V, vec3 lightDir, float roughness){ + float NdotV = max(dot(normal, V), 0.0); + float NdotL = max(dot(normal, lightDir), 0.0); + float ggx2 = GeometrySchlickGGX(NdotV, roughness); + float ggx1 = GeometrySchlickGGX(NdotL, roughness); + + return ggx1 * ggx2; +} +vec3 fresnelSchlick(float cosTheta, vec3 F0){ + return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0); +} + +vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){ + float diffuse=max(0,dot(normal,lightDir)); + + //vec3 V = normalize(cameraPos-worldPos); + vec3 F0 = vec3(0.04); + F0 = mix(F0, color, metallic); + + vec3 H = normalize(V + lightDir); + + // cook-torrance brdf + float NDF = DistributionGGX(normal, H, roughness); + float G = GeometrySmith(normal, V, lightDir, roughness); + vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0); + + vec3 kS = F; + vec3 kD = vec3(1.0) - kS; + kD *= 1.0 - metallic; + + vec3 numerator = NDF * G * F; + float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, lightDir), 0.0) + 0.0001; + vec3 specular = numerator / denominator; + + // add to outgoing radiance Lo + float NdotL = max(dot(normal, lightDir), 0.0); + return (kD * color / PI + specular) * radiance * NdotL; +} + + +float calculateShadow() { + + vec4 sunSpacePosNormalized = (0.5 * sunSpacePos / (sunSpacePos.w)) + 0.5; + + float closestDepth = texture2D(depthMapSun, sunSpacePosNormalized.xy).x;//r? + + float diff = (0.001+closestDepth) - sunSpacePosNormalized.z;//sunSpacePosNormalized.z; + + return (0.5*(diff)/abs(diff))+0.5; +} + +void main() +{ + vec3 lightDir = normalize(lightPos-worldPos); + vec3 normal = normalize(vecNormal); + vec3 textureColor = texture2D(colorTexture, vecTex).xyz; + float diffuse=max(0,dot(normal,lightDir)); + + vec3 viewDir = normalize(cameraPos-worldPos); + + vec3 ambient = AMBIENT*color; + vec3 attenuatedlightColor = lightColor/pow(length(lightPos-worldPos),2); + vec3 ilumination; + ilumination = ambient+PBRLight(lightDir,attenuatedlightColor,normal,viewDir); + + //flashlight + //vec3 spotlightDir= normalize(spotlightDirTS); + vec3 spotlightDir= normalize(spotlightPos-worldPos); + + + float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1); + attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2); + ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir); + + //sun + ilumination=ilumination+PBRLight(sunDir, sunColor * calculateShadow(), normal, viewDir); + + //outColor = vec4(textureColor*min(1,AMBIENT+diffuse), 1.0); + //outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1); + + outColor = vec4(textureColor*min(1,AMBIENT+diffuse) - 1*exp(-ilumination*exposition),1); +} + diff --git a/cw 9/shaders/shader_tex.vert b/cw 9/shaders/shader_tex.vert new file mode 100644 index 0000000..25ae2f3 --- /dev/null +++ b/cw 9/shaders/shader_tex.vert @@ -0,0 +1,72 @@ +#version 430 core + +//layout(location = 0) in vec3 vertexPosition; +//layout(location = 1) in vec3 vertexNormal; +//layout(location = 2) in vec2 vertexTexCoord; +// +//uniform mat4 transformation; +//uniform mat4 modelMatrix; +// +//out vec3 vecNormal; +//out vec3 worldPos; +//out vec2 vecTex; +// +//void main() +//{ +// worldPos = (modelMatrix * vec4(vertexPosition, 1)).xyz; +// vecNormal = (modelMatrix * vec4(vertexNormal, 0)).xyz; +// vecTex = vertexTexCoord; +// vecTex.y = 1.0 - vecTex.y; +// gl_Position = transformation * vec4(vertexPosition, 1.0); +//} + +layout(location = 0) in vec3 vertexPosition; +layout(location = 1) in vec3 vertexNormal; +layout(location = 2) in vec2 vertexTexCoord; +layout(location = 3) in vec3 vertexTangent; +layout(location = 4) in vec3 vertexBitangent; + +uniform mat4 transformation; +uniform mat4 modelMatrix; + +uniform mat4 LightVPSun; + +out vec3 vecNormal; +out vec3 worldPos; +out vec2 vecTex; + +uniform vec3 lightPos; +uniform vec3 spotlightPos; +uniform vec3 cameraPos; +uniform vec3 sunDir; + +out vec3 viewDirTS; +out vec3 lightDirTS; +out vec3 spotlightDirTS; +out vec3 sunDirTS; + +out vec4 sunSpacePos; + +void main() +{ + worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz; + vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz; + vecTex = vertexTexCoord; + vecTex.y = 1.0 - vecTex.y; + gl_Position = transformation * vec4(vertexPosition, 1.0); + + vec3 w_tangent = normalize(mat3(modelMatrix)*vertexTangent); + vec3 w_bitangent = normalize(mat3(modelMatrix)*vertexBitangent); + mat3 TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal)); + + vec3 V = normalize(cameraPos-worldPos); + viewDirTS = TBN*V; + vec3 L = normalize(lightPos-worldPos); + lightDirTS = TBN*L; + vec3 SL = normalize(spotlightPos-worldPos); + spotlightDirTS = TBN*SL; + sunDirTS = TBN*sunDir; + + sunSpacePos=LightVPSun*modelMatrix*vec4(vertexPosition,1); + +} \ No newline at end of file diff --git a/cw 9/src/room.hpp b/cw 9/src/room.hpp index 7c4662f..77f44bb 100644 --- a/cw 9/src/room.hpp +++ b/cw 9/src/room.hpp @@ -56,6 +56,8 @@ namespace texture { GLuint earth; GLuint earthNormal; + + GLuint floor; } Core::RenderContext cubeContext; @@ -284,6 +286,54 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec Core::DrawContext(context); } + +void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, glm::vec3 color, float roughness, float metallic) { + 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); + + glUniform1f(glGetUniformLocation(programTex, "exposition"), exposition); + + glUniform1f(glGetUniformLocation(programTex, "roughness"), roughness); + glUniform1f(glGetUniformLocation(programTex, "metallic"), metallic); + glUniform3f(glGetUniformLocation(programTex, "color"), color.x, color.y, color.z); + + glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z); + + glUniform3f(glGetUniformLocation(programTex, "sunDir"), sunDir.x, sunDir.y, sunDir.z); + glUniform3f(glGetUniformLocation(programTex, "sunColor"), sunColor.x, sunColor.y, sunColor.z); + + if (lightOn > 0.0f) + glUniform3f(glGetUniformLocation(programTex, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z); + else + glUniform3f(glGetUniformLocation(programTex, "lightPos"), 1000.f, 1000.f, 1000.f); + glUniform3f(glGetUniformLocation(programTex, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z); + + + glUniform3f(glGetUniformLocation(programTex, "spotlightConeDir"), spotlightConeDir.x, spotlightConeDir.y, spotlightConeDir.z); + glUniform3f(glGetUniformLocation(programTex, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z); + glUniform3f(glGetUniformLocation(programTex, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z); + glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi); + + glActiveTexture(GL_TEXTURE0); + glUniform1i(glGetUniformLocation(programTex, "depthMapSun"), 0); + glBindTexture(GL_TEXTURE_2D, depthMap); + glUniformMatrix4fv(glGetUniformLocation(programTex, "LightVPSun"), 1, GL_FALSE, (float*)&lightVP); + + glActiveTexture(GL_TEXTURE1); + glUniform1i(glGetUniformLocation(programTex, "depthMapShip"), 1); + glBindTexture(GL_TEXTURE_2D, depthMapShip); + glUniformMatrix4fv(glGetUniformLocation(programTex, "lightShipVP"), 1, GL_FALSE, (float*)&lightShipVP); + + Core::SetActiveTexture(textureID, "colorTexture", programTex, 0); + Core::DrawContext(context); + glUseProgram(0); +} + void renderShadowapSun(GLuint depthFBO, glm::mat4 light) { float time = glfwGetTime(); glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT); @@ -469,7 +519,6 @@ void renderScene(GLFWwindow* window) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float time = glfwGetTime(); updateDeltaTime(time); - renderShadowapSun(depthMapFBO, lightVP); renderShadowapSun(depthMapShipFBO, lightShipVP); @@ -479,8 +528,6 @@ void renderScene(GLFWwindow* window) drawSkyBox(cubeContext, glm::translate(cameraPos)); - - if (lightOn > 0.0f) { glUseProgram(programSun); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); @@ -520,6 +567,7 @@ void renderScene(GLFWwindow* window) drawObjectPBR(models::windowContext, glm::eulerAngleY(3.14f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.3f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); drawObjectPBR(models::windowContext, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.45f)) * glm::translate(glm::vec3(-0.6f, 0, -0.25f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + //drawObjectTexture(models::planeContext, glm::mat4(), texture::floor, glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); 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)); @@ -594,8 +642,10 @@ void init(GLFWwindow* window) loadCubemap(faces); initDepthMap(); + programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag"); texture::earth = Core::LoadTexture("textures/room/earth.png"); texture::earthNormal = Core::LoadTexture("textures/room/earth_normalmap.png"); + texture::floor = Core::LoadTexture("textures/floor/floor_wood.jpg"); loadModelToContext("./models/sphere.obj", sphereContext); loadModelToContext("./models/cube.obj", cubeContext); @@ -632,7 +682,6 @@ void init(GLFWwindow* window) initBloom(); initPingPong(); - } void shutdown(GLFWwindow* window) diff --git a/cw 9/textures/floor/floor_wood.jpg b/cw 9/textures/floor/floor_wood.jpg new file mode 100644 index 0000000..d3def4f Binary files /dev/null and b/cw 9/textures/floor/floor_wood.jpg differ