diff --git a/.vs/grk-project/v16/.suo b/.vs/grk-project/v16/.suo index 0f95c6a..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 0b23d05..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 3cb599f..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 465e4a9..fd337a9 100644 Binary files a/Release/room.pdb and b/Release/room.pdb differ diff --git a/cw 9/Release/Box.obj b/cw 9/Release/Box.obj index 19e40bd..683a1fd 100644 Binary files a/cw 9/Release/Box.obj and b/cw 9/Release/Box.obj differ diff --git a/cw 9/Release/Camera.obj b/cw 9/Release/Camera.obj index 82124a9..bae1cd2 100644 Binary files a/cw 9/Release/Camera.obj and b/cw 9/Release/Camera.obj differ diff --git a/cw 9/Release/Render_Utils.obj b/cw 9/Release/Render_Utils.obj index d95fb17..683c7be 100644 Binary files a/cw 9/Release/Render_Utils.obj and b/cw 9/Release/Render_Utils.obj differ diff --git a/cw 9/Release/SOIL.obj b/cw 9/Release/SOIL.obj index d59eedb..5f2ebd0 100644 Binary files a/cw 9/Release/SOIL.obj and b/cw 9/Release/SOIL.obj differ diff --git a/cw 9/Release/Shader_Loader.obj b/cw 9/Release/Shader_Loader.obj index b1a4f1d..abd341e 100644 Binary files a/cw 9/Release/Shader_Loader.obj and b/cw 9/Release/Shader_Loader.obj differ diff --git a/cw 9/Release/Texture.obj b/cw 9/Release/Texture.obj index e1a0075..bcf9008 100644 Binary files a/cw 9/Release/Texture.obj and b/cw 9/Release/Texture.obj differ diff --git a/cw 9/Release/grk-cw9.log b/cw 9/Release/grk-cw9.log index 19208d0..13a0aad 100644 --- a/cw 9/Release/grk-cw9.log +++ b/cw 9/Release/grk-cw9.log @@ -1,35 +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 -C:\Users\annas\Desktop\graf\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY” -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(118,30): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(136,38): warning C4305: "=": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(159,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(178,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(196,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(288,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(294,96): warning C4305: "argument": obcięcie z "double" do "T" +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(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 ] -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(298,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 ] -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(462,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(487,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(504,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 ] -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(560,2): warning C4305: "argument": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(699,21): warning C4305: "-=": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(701,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 - 54 of 607 functions ( 8.9%) were compiled, the rest were copied from previous compilation. + 47 of 607 functions ( 7.7%) were compiled, the rest were copied from previous compilation. 0 functions were new in current compilation - 18 functions had inline decision re-evaluated but remain unchanged + 9 functions had inline decision re-evaluated but remain unchanged Zakończono generowanie kodu - grk-cw9.vcxproj -> C:\Users\annas\Desktop\graf\Release\room.exe + grk-cw9.vcxproj -> D:\UAM\Grafika komputerowa\projekt\GRK_Room\Release\room.exe diff --git a/cw 9/Release/image_DXT.obj b/cw 9/Release/image_DXT.obj index b45e6bd..c3b584e 100644 Binary files a/cw 9/Release/image_DXT.obj and b/cw 9/Release/image_DXT.obj differ diff --git a/cw 9/Release/image_helper.obj b/cw 9/Release/image_helper.obj index b18245d..aa7b907 100644 Binary files a/cw 9/Release/image_helper.obj and b/cw 9/Release/image_helper.obj differ diff --git a/cw 9/Release/main.obj b/cw 9/Release/main.obj index 4e3d410..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.exe.recipe b/cw 9/Release/room.exe.recipe index 7e3233f..7cabe4c 100644 --- a/cw 9/Release/room.exe.recipe +++ b/cw 9/Release/room.exe.recipe @@ -2,7 +2,7 @@ - C:\Users\annas\Desktop\graf\Release\room.exe + D:\UAM\Grafika komputerowa\projekt\GRK_Room\Release\room.exe diff --git a/cw 9/Release/room.iobj b/cw 9/Release/room.iobj index aa25831..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 ea3fb7f..f7188a1 100644 Binary files a/cw 9/Release/room.ipdb and b/cw 9/Release/room.ipdb differ diff --git a/cw 9/Release/room.tlog/CL.command.1.tlog b/cw 9/Release/room.tlog/CL.command.1.tlog index fa2e57e..628412d 100644 Binary files a/cw 9/Release/room.tlog/CL.command.1.tlog and b/cw 9/Release/room.tlog/CL.command.1.tlog differ diff --git a/cw 9/Release/room.tlog/CL.read.1.tlog b/cw 9/Release/room.tlog/CL.read.1.tlog index 27de0e7..56f184f 100644 Binary files a/cw 9/Release/room.tlog/CL.read.1.tlog and b/cw 9/Release/room.tlog/CL.read.1.tlog differ diff --git a/cw 9/Release/room.tlog/CL.write.1.tlog b/cw 9/Release/room.tlog/CL.write.1.tlog index 557ca7c..e58c3c4 100644 Binary files a/cw 9/Release/room.tlog/CL.write.1.tlog and b/cw 9/Release/room.tlog/CL.write.1.tlog differ diff --git a/cw 9/Release/room.tlog/link.command.1.tlog b/cw 9/Release/room.tlog/link.command.1.tlog index 3d87186..02898c0 100644 Binary files a/cw 9/Release/room.tlog/link.command.1.tlog and b/cw 9/Release/room.tlog/link.command.1.tlog differ diff --git a/cw 9/Release/room.tlog/link.read.1.tlog b/cw 9/Release/room.tlog/link.read.1.tlog index 8c4df49..88a9cff 100644 Binary files a/cw 9/Release/room.tlog/link.read.1.tlog and b/cw 9/Release/room.tlog/link.read.1.tlog differ diff --git a/cw 9/Release/room.tlog/link.write.1.tlog b/cw 9/Release/room.tlog/link.write.1.tlog index 42b372f..24237fa 100644 Binary files a/cw 9/Release/room.tlog/link.write.1.tlog and b/cw 9/Release/room.tlog/link.write.1.tlog differ diff --git a/cw 9/Release/room.tlog/room.lastbuildstate b/cw 9/Release/room.tlog/room.lastbuildstate index ba43894..e062306 100644 --- a/cw 9/Release/room.tlog/room.lastbuildstate +++ b/cw 9/Release/room.tlog/room.lastbuildstate @@ -1,2 +1,2 @@ PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0: -Release|Win32|C:\Users\annas\Desktop\graf\| +Release|Win32|D:\UAM\Grafika komputerowa\projekt\GRK_Room\| diff --git a/cw 9/Release/stb_image_aug.obj b/cw 9/Release/stb_image_aug.obj index cdca64e..beae04c 100644 Binary files a/cw 9/Release/stb_image_aug.obj and b/cw 9/Release/stb_image_aug.obj differ diff --git a/cw 9/Release/vc142.pdb b/cw 9/Release/vc142.pdb index aa5c2d6..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 e139f32..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; @@ -107,7 +109,7 @@ unsigned int pingpongBuffer[2]; GLuint VAO,VBO; float aspectRatio = 1.f; -float exposition = 1.f; +float exposition = 3.0f; glm::vec3 pointlightPos = glm::vec3(0, 2, 0); glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6); //cienie z latarki @@ -123,7 +125,7 @@ glm::mat4 lightShipVP; float lastTime = -1.f; float deltaTime = 0.f; -bool lightOn = true; +float lightOn = 1.0f; glm::vec3 carPosTranform = glm::vec3(0, 0, 0); void updateDeltaTime(float time) { @@ -231,7 +233,7 @@ void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) { glUniformMatrix4fv(glGetUniformLocation(programSkybox, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniform1i(glGetUniformLocation(programSkybox, "skybox"), 0); glUniform1f(glGetUniformLocation(programSkybox, "exposition"), exposition); - if (lightOn) + if (lightOn > 0.0f) glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z); else glUniform3f(glGetUniformLocation(program, "lightPos"), 1000.f, 1000.f, 1000.f); @@ -269,7 +271,7 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec glUniform3f(glGetUniformLocation(program, "sunDir"), sunDir.x, sunDir.y, sunDir.z); glUniform3f(glGetUniformLocation(program, "sunColor"), sunColor.x, sunColor.y, sunColor.z); - if (lightOn) + if (lightOn > 0.0f) glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z); else glUniform3f(glGetUniformLocation(program, "lightPos"), 1000.f, 1000.f, 1000.f); @@ -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); @@ -292,38 +342,22 @@ void renderShadowapSun(GLuint depthFBO, glm::mat4 light) { glUseProgram(programDepth); drawObjectDepth(sphereContext, light, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f))); - drawObjectDepth(sphereContext, light, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f))); drawObjectDepth(models::couchContext, light, glm::scale(glm::vec3(0.5f)) * glm::translate(glm::vec3(8.4f, 0, -0.4f)) * glm::eulerAngleY(3.15f)); - - drawObjectDepth(models::coffeeTableContext, light, glm::translate(glm::vec3(2.8f, 0, 0.5f))); - - drawObjectDepth(models::doorContext, light, glm::mat4()); - - drawObjectDepth(models::planeContext, light, glm::mat4()); - - drawObjectDepth(models::roomContext, light, glm::mat4()); - // draw windows drawObjectDepth(models::windowContext, light, glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.2f))); - - drawObjectDepth(models::windowContext, light, glm::eulerAngleY(3.14f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.3f))); - - drawObjectDepth(models::windowContext, light, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.45f)) * glm::translate(glm::vec3(-0.6f, 0, -0.25f))); - drawObjectDepth(models::deskContext, light, glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.9f))); drawObjectDepth(models::displayScreenContext, light, glm::scale(glm::vec3(0.1, 0.1, 0.1)) * glm::translate(glm::vec3(-28.5f, 9.0f, -20.0f))); - drawObjectDepth(models::chairContext, light, glm::scale(glm::vec3(1.0f, 1.2f, 1.0f)) * glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.5f))); drawObjectDepth(models::ps5Context, light, glm::mat4()); drawObjectDepth(models::tvStandContext, light, glm::mat4()); @@ -431,7 +465,6 @@ void initBloom() void initPingPong() { - glGenFramebuffers(2, pingpongFBO); glGenTextures(2, pingpongBuffer); for (unsigned int i = 0; i < 2; i++) @@ -486,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); @@ -496,9 +528,7 @@ void renderScene(GLFWwindow* window) drawSkyBox(cubeContext, glm::translate(cameraPos)); - - - if (lightOn) { + if (lightOn > 0.0f) { glUseProgram(programSun); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); glm::mat4 transformation = viewProjectionMatrix * glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)); @@ -508,16 +538,12 @@ void renderScene(GLFWwindow* window) Core::DrawContext(sphereContext); } - //pingPongBluring(time); glUseProgram(program); - - drawObjectPBR(models::couchContext, glm::scale(glm::vec3(0.5f)) * glm::translate(glm::vec3(8.4f, 0, -0.4f)) * glm::eulerAngleY(3.15f), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f); drawObjectPBR(models::coffeeTableContext, glm::translate(glm::vec3(2.8f, 0, 0.5f)), glm::vec3(1.f, 1.f, 1.f), 0.4f, 0.0f); drawObjectPBR(models::doorContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); drawObjectPBR(models::planeContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); - drawObjectPBR(models::roomContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.8f, 0.0f); drawObjectPBR(models::deskContext, glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.9f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.0f); drawObjectPBR(models::displayScreenContext, glm::scale(glm::vec3(0.1, 0.1, 0.1)) * glm::translate(glm::vec3(-28.5f, 9.0f, -20.0f)), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.3f); @@ -529,17 +555,19 @@ void renderScene(GLFWwindow* window) drawObjectPBR(models::carpetContext, glm::mat4(), glm::vec3(0.6745098039215686f, 0.6352941176470588f, 0.6235294117647059f), 0.0f, 0.2f); drawObjectPBR(models::cabinet1Context, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); drawObjectPBR(models::cabinet2Context, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); - drawObjectPBR(models::lampContext, glm::translate(glm::vec3(0.023f, 0.15f, 0.0f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); + drawObjectPBR(models::lampContext, glm::translate(glm::vec3(0.022f, 0.15f, 0.04f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); drawObjectPBR(models::bookshelfContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); drawObjectPBR(models::lightSwitchContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); drawObjectPBR(models::easelContext, glm::mat4(), glm::vec3(0.6745098039215686f, 0.6352941176470588f, 0.6235294117647059f), 0.0f, 0.2f); drawObjectPBR(models::carContext, glm::translate(carPosTranform), glm::vec3(1.0f, 0.0f, 0.0f), 0.0f, 0.2f); drawObjectPBR(models::vaseContext, glm::translate(glm::vec3(1.1f, 1.41f, -2.2f)), glm::vec3(244.0f / 255.0f, 245.0f / 255.0f, 220.0f / 255.0f), 0.0f, 0.2f); + // draw windows drawObjectPBR(models::windowContext, glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.2f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); 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)); @@ -551,7 +579,6 @@ void renderScene(GLFWwindow* window) }); - //drawObjectPBR(shipContext, drawObjectPBR(models::spaceshipContext, glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi()) * glm::scale(glm::vec3(0.03f)), @@ -615,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); @@ -653,7 +682,6 @@ void init(GLFWwindow* window) initBloom(); initPingPong(); - } void shutdown(GLFWwindow* window) @@ -703,9 +731,13 @@ void processInput(GLFWwindow* window) if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) { printf("spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", spaceshipPos.x, spaceshipPos.y, spaceshipPos.z); printf("spaceshipDir = glm::vec3(%ff, %ff, %ff);\n", spaceshipDir.x, spaceshipDir.y, spaceshipDir.z); + printf("exposition = %ff);\n", exposition); } + if (glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) - lightOn = !lightOn; + lightOn -= 1.0f; + if (glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS) + lightOn += 1.0f; // if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) 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