dodanie cieni z latarki drona

This commit is contained in:
Generacja 2023-01-16 17:25:19 +01:00
parent 02aa3da621
commit 5b2786ea1e
29 changed files with 198 additions and 24 deletions

BIN
Release/room.exe Normal file

Binary file not shown.

BIN
Release/room.pdb Normal file

Binary file not shown.

BIN
cw 9/Release/Box.obj Normal file

Binary file not shown.

BIN
cw 9/Release/Camera.obj Normal file

Binary file not shown.

Binary file not shown.

BIN
cw 9/Release/SOIL.obj Normal file

Binary file not shown.

Binary file not shown.

BIN
cw 9/Release/Texture.obj Normal file

Binary file not shown.

46
cw 9/Release/grk-cw9.log Normal file
View File

@ -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

BIN
cw 9/Release/image_DXT.obj Normal file

Binary file not shown.

Binary file not shown.

BIN
cw 9/Release/main.obj Normal file

Binary file not shown.

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\Genos\source\repos\GRK_Room\Release\room.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

BIN
cw 9/Release/room.iobj Normal file

Binary file not shown.

BIN
cw 9/Release/room.ipdb Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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\|

Binary file not shown.

BIN
cw 9/Release/vc142.pdb Normal file

Binary file not shown.

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -54,6 +54,9 @@ std::vector<std::string> 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<std::string> 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<float>()),
// glm::vec3(0.3, 0.3, 0.5)
// );
drawObjectDepth(shipContext,
light,
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * 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)