diff --git a/Release/room.exe b/Release/room.exe
new file mode 100644
index 0000000..3c86649
Binary files /dev/null and b/Release/room.exe differ
diff --git a/Release/room.pdb b/Release/room.pdb
new file mode 100644
index 0000000..b281d92
Binary files /dev/null and b/Release/room.pdb differ
diff --git a/cw 9/Release/Box.obj b/cw 9/Release/Box.obj
new file mode 100644
index 0000000..90a08df
Binary files /dev/null and b/cw 9/Release/Box.obj differ
diff --git a/cw 9/Release/Camera.obj b/cw 9/Release/Camera.obj
new file mode 100644
index 0000000..b5b637e
Binary files /dev/null and b/cw 9/Release/Camera.obj differ
diff --git a/cw 9/Release/Render_Utils.obj b/cw 9/Release/Render_Utils.obj
new file mode 100644
index 0000000..8fdd0c2
Binary files /dev/null and b/cw 9/Release/Render_Utils.obj differ
diff --git a/cw 9/Release/SOIL.obj b/cw 9/Release/SOIL.obj
new file mode 100644
index 0000000..29c6cf5
Binary files /dev/null and b/cw 9/Release/SOIL.obj differ
diff --git a/cw 9/Release/Shader_Loader.obj b/cw 9/Release/Shader_Loader.obj
new file mode 100644
index 0000000..ab38bdd
Binary files /dev/null and b/cw 9/Release/Shader_Loader.obj differ
diff --git a/cw 9/Release/Texture.obj b/cw 9/Release/Texture.obj
new file mode 100644
index 0000000..529bb2b
Binary files /dev/null and b/cw 9/Release/Texture.obj differ
diff --git a/cw 9/Release/grk-cw9.log b/cw 9/Release/grk-cw9.log
new file mode 100644
index 0000000..4b2c6aa
--- /dev/null
+++ b/cw 9/Release/grk-cw9.log
@@ -0,0 +1,46 @@
+ 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\Genos\source\repos\GRK_Room\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(94,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(109,38): warning C4305: "=": obcięcie z "double" do "float"
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(132,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(153,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(172,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(252,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(263,96): warning C4305: "argument": obcięcie z "double" do "T"
+ with
+ [
+ T=float
+ ]
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(267,59): warning C4305: "argument": obcięcie z "double" do "T"
+ with
+ [
+ T=float
+ ]
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(343,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(353,108): warning C4305: "argument": obcięcie z "double" do "T"
+ with
+ [
+ T=float
+ ]
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(361,87): warning C4305: "argument": obcięcie z "double" do "T"
+ with
+ [
+ T=float
+ ]
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(361,223): warning C4305: "argument": obcięcie z "double" do "float"
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(364,59): warning C4305: "argument": obcięcie z "double" do "T"
+ with
+ [
+ T=float
+ ]
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(365,37): warning C4305: "argument": obcięcie z "double" do "float"
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(393,2): warning C4305: "argument": obcięcie z "double" do "float"
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(501,21): warning C4305: "-=": obcięcie z "double" do "float"
+C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(503,21): warning C4305: "+=": obcięcie z "double" do "float"
+ Trwa generowanie kodu
+ 35 of 586 functions ( 6.0%) were compiled, the rest were copied from previous compilation.
+ 0 functions were new in current compilation
+ 15 functions had inline decision re-evaluated but remain unchanged
+ Zakończono generowanie kodu
+ grk-cw9.vcxproj -> C:\Users\Genos\source\repos\GRK_Room\Release\room.exe
diff --git a/cw 9/Release/image_DXT.obj b/cw 9/Release/image_DXT.obj
new file mode 100644
index 0000000..f494786
Binary files /dev/null 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
new file mode 100644
index 0000000..d28c710
Binary files /dev/null and b/cw 9/Release/image_helper.obj differ
diff --git a/cw 9/Release/main.obj b/cw 9/Release/main.obj
new file mode 100644
index 0000000..436a9ec
Binary files /dev/null and b/cw 9/Release/main.obj differ
diff --git a/cw 9/Release/room.exe.recipe b/cw 9/Release/room.exe.recipe
new file mode 100644
index 0000000..9f9c666
--- /dev/null
+++ b/cw 9/Release/room.exe.recipe
@@ -0,0 +1,11 @@
+
+
+
+
+ C:\Users\Genos\source\repos\GRK_Room\Release\room.exe
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cw 9/Release/room.iobj b/cw 9/Release/room.iobj
new file mode 100644
index 0000000..e127328
Binary files /dev/null and b/cw 9/Release/room.iobj differ
diff --git a/cw 9/Release/room.ipdb b/cw 9/Release/room.ipdb
new file mode 100644
index 0000000..b6eb01e
Binary files /dev/null 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
new file mode 100644
index 0000000..46e41cc
Binary files /dev/null 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
new file mode 100644
index 0000000..7161280
Binary files /dev/null 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
new file mode 100644
index 0000000..477c34d
Binary files /dev/null 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
new file mode 100644
index 0000000..4cfa9ec
Binary files /dev/null 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
new file mode 100644
index 0000000..d4b9406
Binary files /dev/null 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
new file mode 100644
index 0000000..c4240e1
Binary files /dev/null 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
new file mode 100644
index 0000000..c94b67f
--- /dev/null
+++ b/cw 9/Release/room.tlog/room.lastbuildstate
@@ -0,0 +1,2 @@
+PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
+Release|Win32|C:\Users\Genos\source\repos\GRK_Room\|
diff --git a/cw 9/Release/stb_image_aug.obj b/cw 9/Release/stb_image_aug.obj
new file mode 100644
index 0000000..fc65a5e
Binary files /dev/null and b/cw 9/Release/stb_image_aug.obj differ
diff --git a/cw 9/Release/vc142.pdb b/cw 9/Release/vc142.pdb
new file mode 100644
index 0000000..1673833
Binary files /dev/null and b/cw 9/Release/vc142.pdb differ
diff --git a/cw 9/shaders/shader_9_1.frag b/cw 9/shaders/shader_9_1.frag
index b7f08bd..abf864b 100644
--- a/cw 9/shaders/shader_9_1.frag
+++ b/cw 9/shaders/shader_9_1.frag
@@ -4,6 +4,7 @@ float AMBIENT = 0.03;
float PI = 3.14;
uniform sampler2D depthMap;
+uniform sampler2D depthMapShip;
uniform vec3 cameraPos;
@@ -38,6 +39,20 @@ in vec3 sunDirTS;
in vec3 test;
+in vec4 sunSpacePos;
+in vec4 shipPos;
+
+float calculateShadow(vec3 normal, vec3 light, vec4 pos, sampler2D depth) {
+ vec4 posNormalized = (pos / pos.w) * 0.5 + 0.5;
+ float closestDepth = texture2D(depth, posNormalized.xy).r;
+
+ //float bias = max(0.03 * (1.0 - dot(normal, light)), 0.003);
+
+ if (closestDepth + 0.003 > posNormalized.z) return 1.0;
+
+ return 0.0;
+}
+
float DistributionGGX(vec3 normal, vec3 H, float roughness){
float a = roughness*roughness;
float a2 = a*a;
@@ -122,11 +137,11 @@ void main()
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
- attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
+ attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2)*calculateShadow(normal, spotlightDir, shipPos, depthMapShip);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
//sun
- ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir);
+ ilumination=ilumination+PBRLight(sunDir,sunColor*calculateShadow(normal, spotlightDir, sunSpacePos, depthMap),normal,viewDir);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
diff --git a/cw 9/shaders/shader_9_1.vert b/cw 9/shaders/shader_9_1.vert
index fce7bb9..ffac9c6 100644
--- a/cw 9/shaders/shader_9_1.vert
+++ b/cw 9/shaders/shader_9_1.vert
@@ -6,6 +6,8 @@ layout(location = 2) in vec2 vertexTexCoord;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
+uniform mat4 lightVP;
+uniform mat4 lightShipVP;
uniform mat4 transformation;
uniform mat4 modelMatrix;
@@ -22,8 +24,14 @@ out vec3 lightDirTS;
out vec3 spotlightDirTS;
out vec3 sunDirTS;
+out vec4 sunSpacePos;
+out vec4 shipPos;
+
void main()
{
+ sunSpacePos = lightVP * modelMatrix * vec4(vertexPosition, 1);
+ shipPos = lightShipVP * modelMatrix * vec4(vertexPosition, 1);
+
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
gl_Position = transformation * vec4(vertexPosition, 1.0);
@@ -39,5 +47,4 @@ void main()
vec3 SL = normalize(spotlightPos-worldPos);
spotlightDirTS = TBN*SL;
sunDirTS = TBN*sunDir;
-
}
diff --git a/cw 9/shaders/test.frag b/cw 9/shaders/test.frag
index 065fd71..86ad462 100644
--- a/cw 9/shaders/test.frag
+++ b/cw 9/shaders/test.frag
@@ -5,8 +5,14 @@ in vec2 tc;
uniform sampler2D depthMap;
+float rescale_z(float z){
+ float n = 0.05;
+ float f = 20.;
+ return (2*n*f/(z*(n-f)+n+f))/f;
+}
+
void main()
{
float depthValue = texture(depthMap, tc).r;
- FragColor = vec4(vec3(depthValue+0.5), 1.0);
+ FragColor = vec4(vec3(rescale_z(depthValue)+0.5), 1.0);
}
\ No newline at end of file
diff --git a/cw 9/shaders/test.vert b/cw 9/shaders/test.vert
index 4184eb4..f1a6f7e 100644
--- a/cw 9/shaders/test.vert
+++ b/cw 9/shaders/test.vert
@@ -10,5 +10,5 @@ out vec2 tc;
void main()
{
tc = vertexTexCoord;
- gl_Position = vec4(vertexPosition*0.9, 1.0);
+ gl_Position = vec4(vertexPosition*0.5, 1.0);
}
diff --git a/cw 9/src/room.hpp b/cw 9/src/room.hpp
index 194c374..8214f84 100644
--- a/cw 9/src/room.hpp
+++ b/cw 9/src/room.hpp
@@ -54,6 +54,9 @@ std::vector faces =
GLuint depthMapFBO;
GLuint depthMap;
+GLuint depthMapShipFBO;
+GLuint depthMapShip;
+
GLuint program;
GLuint programSun;
GLuint programTest;
@@ -90,7 +93,8 @@ glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0);
glm::vec3 spotlightColor = glm::vec3(1.0, 1.0, 1.0)*10;
float spotlightPhi = 3.14 / 4;
-glm::mat4 lightVP = glm::ortho(-10.f, 10.f, -10.f, 10.f, 1.0f, 30.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
+glm::mat4 lightVP = glm::ortho(-3.f, 3.f, -3.f, 3.f, 1.0f, 20.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
+glm::mat4 lightShipVP;
float lastTime = -1.f;
float deltaTime = 0.f;
@@ -142,6 +146,27 @@ glm::mat4 createPerspectiveMatrix()
return perspectiveMatrix;
}
+glm::mat4 createPerspectiveMatrix(float scale)
+{
+
+ glm::mat4 perspectiveMatrix;
+ float n = 0.05;
+ float f = 20.;
+ float a1 = glm::min(aspectRatio, 1.f);
+ float a2 = glm::min(1 / aspectRatio, 1.f);
+ perspectiveMatrix = glm::mat4({
+ 1 * scale,0,0.,0.,
+ 0.,1 * scale,0.,0.,
+ 0.,0.,(f + n) / (n - f),2 * f * n / (n - f),
+ 0.,0.,-1.,0.,
+ });
+
+
+ perspectiveMatrix = glm::transpose(perspectiveMatrix);
+
+ return perspectiveMatrix;
+}
+
void loadCubemap(std::vector faces)
{
unsigned int textureID;
@@ -187,6 +212,15 @@ void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
}
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
+ glActiveTexture(GL_TEXTURE0);
+ glUniform1i(glGetUniformLocation(program, "depthMap"), 0);
+ glBindTexture(GL_TEXTURE_2D, depthMap);
+ glUniformMatrix4fv(glGetUniformLocation(program, "lightVP"), 1, GL_FALSE, (float*)&lightVP);
+
+ glActiveTexture(GL_TEXTURE1);
+ glUniform1i(glGetUniformLocation(program, "depthMapShip"), 1);
+ glBindTexture(GL_TEXTURE_2D, depthMapShip);
+ glUniformMatrix4fv(glGetUniformLocation(program, "lightShipVP"), 1, GL_FALSE, (float*)&lightShipVP);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
@@ -214,8 +248,57 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi);
Core::DrawContext(context);
}
+void renderShadowapSun(GLuint depthFBO, glm::mat4 light) {
+ float time = glfwGetTime();
+ //uzupelnij o renderowanie glebokosci do tekstury
+ //ustawianie przestrzeni rysowania
+ glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
+ //bindowanie FBO
+ glBindFramebuffer(GL_FRAMEBUFFER, depthFBO);
+ //czyszczenie mapy głębokości
+ glClear(GL_DEPTH_BUFFER_BIT);
+ //ustawianie programu
+ glUseProgram(programDepth);
-void initDepthMap() {
+ 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());
+ drawObjectDepth(models::windowContext, light, glm::translate(glm::vec3(-3.35f, 0, 0)));
+
+ 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));
+ glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
+ spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
+ spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
+ -spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0,
+ 0.,0.,0.,1.,
+ });
+
+
+ //drawObjectColor(shipContext,
+ // glm::translate(cameraPos + 1.5 * cameraDir + cameraUp * -0.5f) * inveseCameraRotrationMatrix * glm::eulerAngleY(glm::pi()),
+ // glm::vec3(0.3, 0.3, 0.5)
+ // );
+ drawObjectDepth(shipContext,
+ light,
+ glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi()) * glm::scale(glm::vec3(0.03f))
+ );
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glViewport(0, 0, WIDTH, HEIGHT);
+}
+
+void initDepthMap()
+{
glGenFramebuffers(1, &depthMapFBO);
glGenTextures(1, &depthMap);
glBindTexture(GL_TEXTURE_2D, depthMap);
@@ -233,33 +316,34 @@ void initDepthMap() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
+void initDepthMapShip()
+{
+ glGenFramebuffers(1, &depthMapShipFBO);
+ glGenTextures(1, &depthMapShip);
+ glBindTexture(GL_TEXTURE_2D, depthMapShip);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
+ SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
-void renderShadowapSun() {
- float time = glfwGetTime();
- glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
- //uzupelnij o renderowanie glebokosci do tekstury
-
- //ustawianie przestrzeni rysowania
- glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
- //bindowanie FBO
- glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
- //czyszczenie mapy głębokości
- glClear(GL_DEPTH_BUFFER_BIT);
- //ustawianie programu
- glUseProgram(programDepth);
-
+ glBindFramebuffer(GL_FRAMEBUFFER, depthMapShipFBO);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMapShip, 0);
+ glDrawBuffer(GL_NONE);
+ glReadBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
- glViewport(0, 0, WIDTH, HEIGHT);
}
void renderScene(GLFWwindow* window)
{
+ lightShipVP = createPerspectiveMatrix(0.5) * glm::lookAt(spotlightPos, spotlightPos + spotlightConeDir, glm::vec3(0, 1, 0));
glClearColor(0.4f, 0.4f, 0.8f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float time = glfwGetTime();
updateDeltaTime(time);
- renderShadowapSun();
+ renderShadowapSun(depthMapFBO, lightVP);
+ renderShadowapSun(depthMapShipFBO, lightShipVP);
drawSkyBox(cubeContext, glm::translate(cameraPos));
@@ -373,6 +457,9 @@ void init(GLFWwindow* window)
loadModelToContext("./models/window.obj", models::windowContext);
loadModelToContext("./models/test.obj", models::testContext);
+ initDepthMap();
+ initDepthMapShip();
+
}
void shutdown(GLFWwindow* window)