restored func without pbr;

This commit is contained in:
Angelika Iskra 2023-02-13 01:44:06 +01:00
parent 97e497c932
commit 729e7d4148
41 changed files with 70635 additions and 24 deletions

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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,33 +1,33 @@
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(513,5): warning MSB8028: Katalog pośredni (Debug\) zawiera pliki udostępnione z innego projektu (grk-cw9.vcxproj). Może to spowodować niepoprawne zachowanie podczas oczyszczania i ponownej kompilacji.
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\grafika_proj\GRK_Room\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(180,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(199,38): warning C4305: "=": obcięcie z "double" do "float"
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(222,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(241,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(259,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(347,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(353,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(185,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(204,38): warning C4305: "=": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(227,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(246,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(264,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(400,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(406,96): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(356,59): warning C4305: "argument": obcięcie z "double" do "T"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(409,59): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(505,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(530,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(544,109): warning C4305: "argument": obcięcie z "double" do "T"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(558,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(583,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(597,109): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(791,21): warning C4305: "-=": obcięcie z "double" do "float"
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(793,21): warning C4305: "+=": obcięcie z "double" do "float"
C:\Users\annas\Desktop\grafika_proj\GRK_Room\cw 9\src\room.hpp(803,30): warning C4244: "=": konwersja z "double" do "float", możliwa utrata danych
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(850,21): warning C4305: "-=": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(852,21): warning C4305: "+=": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(862,30): warning C4244: "=": konwersja z "double" do "float", możliwa utrata danych
Box.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
LINK : warning LNK4098: domyślna biblioteka „MSVCRT” powoduje konflikt z innymi bibliotekami; użyj opcji /NODEFAULTLIB:biblioteka
grk-cw9.vcxproj -> C:\Users\annas\Desktop\grafika_proj\GRK_Room\Debug\room.exe
grk-cw9.vcxproj -> D:\UAM\Grafika komputerowa\projekt\GRK_Room\Debug\room.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\annas\Desktop\grafika_proj\GRK_Room\Debug\room.exe</FullPath>
<FullPath>D:\UAM\Grafika komputerowa\projekt\GRK_Room\Debug\room.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|C:\Users\annas\Desktop\grafika_proj\GRK_Room\|
Debug|Win32|D:\UAM\Grafika komputerowa\projekt\GRK_Room\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

12
cw 9/models/car/car2.mtl Normal file
View File

@ -0,0 +1,12 @@
# Blender 3.4.1 MTL File: 'None'
# www.blender.org
newmtl Material.001
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.000000 0.019273
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

22335
cw 9/models/car/car2.obj Normal file

File diff suppressed because it is too large Load Diff

12
cw 9/models/car/car3.mtl Normal file
View File

@ -0,0 +1,12 @@
# Blender 3.4.1 MTL File: 'None'
# www.blender.org
newmtl Material.001
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd D:/UAM/Grafika komputerowa/projekt/GRK_Room/cw 9/textures/red/red.jpg

48022
cw 9/models/car/car3.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,171 @@
#version 430 core
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 BloomColor;
float AMBIENT = 0.03;
float PI = 3.14;
uniform sampler2D depthMap;
uniform sampler2D depthMapShip;
uniform sampler2D colorTexture;
uniform sampler2D normalSampler;
uniform vec3 cameraPos;
uniform vec3 color;
uniform vec3 sunDir;
uniform vec3 sunColor;
uniform vec3 lightPos;
uniform vec3 lightColor;
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 vec3 test;
in vec4 sunSpacePos;
in vec4 shipPos;
in vec2 vecTex;
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;
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;
}
void main()
{
//vec3 normal = vec3(0,0,1);
vec3 normal = normalize(vecNormal);
//color = texture2D(colorTexture, vecTex).xyz;
//vec3 normal = normalize((texture2D(normalSampler, vecTex).xyz) * 2 - 1);
//vec3 viewDir = normalize(viewDirTS);
vec3 viewDir = normalize(cameraPos-worldPos);
//vec3 lightDir = normalize(lightDirTS);
vec3 lightDir = normalize(lightPos-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)*calculateShadow(normal, spotlightDir, shipPos, depthMapShip);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
//sun
ilumination=ilumination+PBRLight(sunDir,sunColor*calculateShadow(normal, spotlightDir, sunSpacePos, depthMap),normal,viewDir);
outColor = vec4(vec3(1.01) - exp(-ilumination*exposition),1);
FragColor = outColor;
// check whether fragment output is higher than threshold, if so output as brightness color
float brightness = dot(FragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
if(brightness > 1.0)
BloomColor = vec4(FragColor.rgb, 1.0);
else
BloomColor = vec4(0.0, 0.0, 0.0, 1.0);
//outColor = vec4(roughness,metallic,0,1);
//outColor = vec4(test;
}

View File

@ -118,6 +118,10 @@ namespace texture {
GLuint redLeather;
GLuint redLeatherNormal;
GLuint redLeatherARM;
GLuint car;
GLuint carNormal;
GLuint carARM;
}
Core::RenderContext cubeContext;
@ -143,6 +147,7 @@ GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
GLuint programNoTex;
GLuint programDepth;
GLuint programSkybox;
GLuint programBlur;
@ -179,7 +184,7 @@ 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(-4.f, 3.f, -2.5f, 5.f, -10.0f, 20.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0)); //
glm::mat4 lightVP = glm::ortho(-10.f, 10.f, -10.f, 10.f, -10.0f, 30.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0)); //
glm::mat4 lightShipVP;
float lastTime = -1.f;
@ -343,6 +348,54 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
Core::DrawContext(context);
}
void drawObjectNoPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
glUseProgram(programNoTex);
glActiveTexture(GL_TEXTURE0);
glUniform1i(glGetUniformLocation(programNoTex, "depthMap"), 0);
glBindTexture(GL_TEXTURE_2D, depthMap);
glUniformMatrix4fv(glGetUniformLocation(programNoTex, "lightVP"), 1, GL_FALSE, (float*)&lightVP);
glActiveTexture(GL_TEXTURE1);
glUniform1i(glGetUniformLocation(programNoTex, "depthMapShip"), 1);
glBindTexture(GL_TEXTURE_2D, depthMapShip);
glUniformMatrix4fv(glGetUniformLocation(programNoTex, "lightShipVP"), 1, GL_FALSE, (float*)&lightShipVP);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programNoTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programNoTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform1f(glGetUniformLocation(programNoTex, "exposition"), exposition);
glUniform1f(glGetUniformLocation(programNoTex, "roughness"), roughness);
glUniform1f(glGetUniformLocation(programNoTex, "metallic"), metallic);
glUniform3f(glGetUniformLocation(programNoTex, "color"), color.x, color.y, color.z);
glUniform3f(glGetUniformLocation(programNoTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform3f(glGetUniformLocation(programNoTex, "sunDir"), sunDir.x, sunDir.y, sunDir.z);
glUniform3f(glGetUniformLocation(programNoTex, "sunColor"), sunColor.x, sunColor.y, sunColor.z);
if (lightOn)
glUniform3f(glGetUniformLocation(programNoTex, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
else
glUniform3f(glGetUniformLocation(programNoTex, "lightPos"), 1000.f, 1000.f, 1000.f);
glUniform3f(glGetUniformLocation(programNoTex, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z);
glUniform3f(glGetUniformLocation(programNoTex, "spotlightConeDir"), spotlightConeDir.x, spotlightConeDir.y, spotlightConeDir.z);
glUniform3f(glGetUniformLocation(programNoTex, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z);
glUniform3f(glGetUniformLocation(programNoTex, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
glUniform1f(glGetUniformLocation(programNoTex, "spotlightPhi"), spotlightPhi);
Core::DrawContext(context);
glUseProgram(program);
}
void renderShadowapSun(GLuint depthFBO, glm::mat4 light) {
float time = glfwGetTime();
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
@ -569,7 +622,8 @@ void renderScene(GLFWwindow* window)
drawObjectPBR(models::bookshelfContext, glm::mat4(), texture::wood, texture::woodNormal, texture::woodARM);
drawObjectPBR(models::lightSwitchContext, glm::mat4(), texture::white, texture::whiteNormal, texture::whiteARM);
drawObjectPBR(models::easelContext, glm::mat4(), texture::wood, texture::woodNormal, texture::woodARM);
drawObjectPBR(models::carContext, glm::translate(carPosTranform), texture::red, texture::redNormal, texture::redARM);
//drawObjectPBR(models::carContext, glm::translate(carPosTranform), texture::car, texture::carNormal, texture::carARM);
drawObjectNoPBR(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)), texture::vase, texture::vaseNormal, texture::vaseARM);
drawObjectPBR(models::couchContext, glm::eulerAngleY(3.14f), texture::redLeather, texture::redLeatherNormal, texture::redLeatherARM);
@ -647,6 +701,7 @@ void init(GLFWwindow* window)
programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
programBlur = shaderLoader.CreateProgram("shaders/shader_blur.vert", "shaders/shader_blur.frag");
programNoTex = shaderLoader.CreateProgram("shaders/shader_no_pbr.vert", "shaders/shader_no_pbr.frag");
loadCubemap(faces);
initDepthMap();
@ -699,9 +754,9 @@ void init(GLFWwindow* window)
texture::whiteNormal = Core::LoadTexture("textures/white/white_normal.png");
texture::whiteARM = Core::LoadTexture("textures/white/white_arm.png");
texture::white = Core::LoadTexture("textures/red/red.png");
texture::whiteNormal = Core::LoadTexture("textures/red/red_normal.png");
texture::whiteARM = Core::LoadTexture("textures/red/red_arm.png");
texture::red = Core::LoadTexture("textures/red/red.png");
texture::redNormal = Core::LoadTexture("textures/red/red_normal.png");
texture::redARM = Core::LoadTexture("textures/red/red_arm.png");
texture::redLeather = Core::LoadTexture("textures/leather/leather_red_03_coll1_4k.png");
texture::redLeatherNormal = Core::LoadTexture("textures/leather/leather_red_03_nor_gl_4k.png");
@ -711,6 +766,10 @@ void init(GLFWwindow* window)
texture::doorNorm = Core::LoadTexture("textures/door/door_norm.jpg");
texture::doorArm = Core::LoadTexture("textures/door/door_arm.jpg");
texture::car = Core::LoadTexture("textures/car/car.jpg");
texture::carNormal = Core::LoadTexture("textures/car/car_normal.png");
texture::carARM = Core::LoadTexture("textures/car/car_arm.jpg");
loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/cube.obj", cubeContext);
@ -738,7 +797,7 @@ void init(GLFWwindow* window)
loadModelToContext("./models/bookshelf/bookshelf.obj", models::bookshelfContext);
loadModelToContext("./models/light_switch/light_switch.obj", models::lightSwitchContext);
loadModelToContext("./models/easel/easel3.obj", models::easelContext);
loadModelToContext("./models/car/car.obj", models::carContext);
loadModelToContext("./models/car/car3.obj", models::carContext);
loadModelToContext("./models/ceramic_vase_02_4k.obj", models::vaseContext);
initDepthMap();

BIN
cw 9/textures/car/car.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 MiB

BIN
cw 9/textures/red/red.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 KiB

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB