PBR textures

This commit is contained in:
s464921 2023-02-07 17:32:48 +01:00
parent b2cafa61c8
commit 55ed83a124
75 changed files with 67921 additions and 58 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.

BIN
cw 9/Debug/TriangleSoup.obj Normal file

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\jedrz\Desktop\grk\Debug\grk-cw9.exe</FullPath>
<FullPath>C:\Users\jedrz\Desktop\GRK_Project\Debug\grk-cw9.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />

View File

@ -1,47 +1,49 @@
 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\jedrz\Desktop\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(100,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(114,17): warning C4101: "data": lokalna zmienna, do której nie istnieje odwołanie
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(139,38): warning C4305: "=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(168,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(228,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(244,98): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(104,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(118,17): warning C4101: "data": lokalna zmienna, do której nie istnieje odwołanie
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(143,38): warning C4305: "=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(172,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(308,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(324,98): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(247,68): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(327,68): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(290,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(298,108): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(388,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(396,108): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(307,87): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(404,87): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(307,223): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(310,59): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(404,223): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(407,59): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(311,37): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(343,2): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(387,108): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(408,37): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(441,2): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(447,116): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(448,113): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(496,108): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(460,21): warning C4305: "-=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(462,21): warning C4305: "+=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(581,21): warning C4305: "-=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(583,21): warning C4305: "+=": obcięcie z "double" do "float"
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\jedrz\Desktop\grk\Debug\grk-cw9.exe
grk-cw9.vcxproj -> C:\Users\jedrz\Desktop\GRK_Project\Debug\grk-cw9.exe

View File

@ -1,2 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|C:\Users\jedrz\Desktop\grk\|
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.33.31629:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|C:\Users\jedrz\Desktop\GRK_Project\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
cw 9/Debug/vc143.idb Normal file

Binary file not shown.

BIN
cw 9/Debug/vc143.pdb 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.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\jedrz\Desktop\grk\Release\grk-cw9.exe</FullPath>
<FullPath>C:\Users\jedrz\Desktop\GRK_Project\Release\grk-cw9.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />

Binary file not shown.

Binary file not shown.

View File

@ -1,50 +1,52 @@
 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\jedrz\Desktop\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(96,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(110,17): warning C4101: "data": lokalna zmienna, do której nie istnieje odwołanie
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(135,38): warning C4305: "=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(164,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(224,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(240,98): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(104,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(118,17): warning C4101: "data": lokalna zmienna, do której nie istnieje odwołanie
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(143,38): warning C4305: "=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(172,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(308,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(324,98): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(243,68): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(327,68): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(303,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(311,108): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(388,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(396,108): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(319,87): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(404,87): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(319,223): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(322,59): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(404,223): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(407,59): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(323,37): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(355,2): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(403,108): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(408,37): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(441,2): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(447,116): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(448,113): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(496,108): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(479,21): warning C4305: "-=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\grk\cw 9\src\ex_9_1.hpp(481,21): warning C4305: "+=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(581,21): warning C4305: "-=": obcięcie z "double" do "float"
C:\Users\jedrz\Desktop\GRK_Project\cw 9\src\ex_9_1.hpp(583,21): warning C4305: "+=": obcięcie z "double" do "float"
Trwa generowanie kodu
65 of 605 functions (10.7%) were compiled, the rest were copied from previous compilation.
18 functions were new in current compilation
18 functions had inline decision re-evaluated but remain unchanged
4 of 604 functions ( 0.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 -> C:\Users\jedrz\Desktop\grk\Release\grk-cw9.exe
grk-cw9.vcxproj -> C:\Users\jedrz\Desktop\GRK_Project\Release\grk-cw9.exe

View File

@ -1,2 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
Release|Win32|C:\Users\jedrz\Desktop\grk\|
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.33.31629:TargetPlatformVersion=10.0.19041.0:
Release|Win32|C:\Users\jedrz\Desktop\GRK_Project\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
cw 9/Release/vc143.pdb Normal file

Binary file not shown.

View File

@ -47,6 +47,10 @@
<None Include="shaders\shader_shadowap_sun.vert" />
<None Include="shaders\shader_skybox.frag" />
<None Include="shaders\shader_skybox.vert" />
<None Include="shaders\shader_tex.frag" />
<None Include="shaders\shader_tex.vert" />
<None Include="shaders\shader_tex_pbr.frag" />
<None Include="shaders\shader_tex_pbr.vert" />
<None Include="shaders\shader_water.frag" />
<None Include="shaders\shader_water.vert" />
<None Include="shaders\test.frag" />
@ -64,14 +68,14 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">

View File

@ -133,5 +133,17 @@
<None Include="shaders\shader_water.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_tex.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_tex.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_tex_pbr.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_tex_pbr.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

55975
cw 9/models/lantern_obj.obj Normal file

File diff suppressed because it is too large Load Diff

11381
cw 9/models/table.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,139 @@
#version 430 core
float AMBIENT = 0.03;
float PI = 3.14;
uniform sampler2D depthMap;
uniform vec3 cameraPos;
uniform sampler2D colorTexture;
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;
in vec2 vecTex;
out vec4 outColor;
in vec3 viewDirTS;
in vec3 lightDirTS;
in vec3 spotlightDirTS;
in vec3 sunDirTS;
vec3 color;
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()
{
color = texture(colorTexture, vecTex).xyz;
//vec3 normal = vec3(0,0,1);
vec3 normal = normalize(vecNormal);
//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);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
//sun
ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
}

View File

@ -0,0 +1,47 @@
#version 430 core
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;
out vec3 vecNormal;
out vec3 worldPos;
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 vec2 vecTex;
void main()
{
vecTex = vertexTexCoord;
vecTex.y = 1.0 - vecTex.y;
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
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;
}

View File

@ -0,0 +1,145 @@
#version 430 core
float AMBIENT = 0.03;
float PI = 3.14;
uniform sampler2D depthMap;
uniform vec3 cameraPos;
uniform sampler2D colorTexture;
uniform sampler2D metallicTexture;
uniform sampler2D roughnessTexture;
uniform sampler2D aoTexture;
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 exposition;
in vec3 vecNormal;
in vec3 worldPos;
in vec2 vecTex;
out vec4 outColor;
in vec3 viewDirTS;
in vec3 lightDirTS;
in vec3 spotlightDirTS;
in vec3 sunDirTS;
vec3 color;
float metallic;
float roughness;
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()
{
color = texture(colorTexture, vecTex).xyz;
metallic = texture(metallicTexture, vecTex).r;
roughness = texture(roughnessTexture, vecTex).r;
//vec3 normal = vec3(0,0,1);
vec3 normal = normalize(vecNormal);
//vec3 viewDir = normalize(viewDirTS);
vec3 viewDir = normalize(cameraPos-worldPos);
//vec3 lightDir = normalize(lightDirTS);
vec3 lightDir = normalize(lightPos-worldPos);
vec3 ambient = texture(aoTexture, vecTex).xyz*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,normal,viewDir);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
outColor = vec4(texture(colorTexture, vecTex).rgb,1);
}

View File

@ -0,0 +1,52 @@
#version 430 core
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;
out vec3 vecNormal;
out vec3 worldPos;
uniform vec3 lightPos;
uniform vec3 spotlightPos;
uniform vec3 cameraPos;
uniform vec3 sunDir;
uniform sampler2D normalSampler;
out vec3 viewDirTS;
out vec3 lightDirTS;
out vec3 spotlightDirTS;
out vec3 sunDirTS;
out vec2 vecTex;
vec3 normal;
void main()
{
normal = texture(normalSampler, vecTex).rgb;
normal = normalize(normal * 2.0 - 1.0);
vecTex = vertexTexCoord;
vecTex.y = 1.0 - vecTex.y;
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
vecNormal = (modelMatrix* vec4(normal,0)).xyz;
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;
}

View File

@ -37,19 +37,26 @@ namespace models {
Core::RenderContext windowContext;
Core::RenderContext testContext;
Core::RenderContext cubeContext;
Core::RenderContext tableContext;
}
std::vector<std::string> faces = {
"textures/rust.jpg",
"textures/rust.jpg",
"textures/rust.jpg",
"textures/rust.jpg",
"textures/rust.jpg",
"textures/rust.jpg",
"textures/skybox/posx.jpg",
"textures/skybox/negx.jpg",
"textures/skybox/posy.jpg",
"textures/skybox/negy.jpg",
"textures/skybox/posz.jpg",
"textures/skybox/negz.jpg",
};
namespace texture {
GLuint water;
GLuint rust;
GLuint table_albedo;
GLuint table_metallic;
GLuint table_ao;
GLuint table_normal;
GLuint table_roughness;
}
GLuint depthMapFBO;
@ -59,6 +66,7 @@ GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
GLuint programTexPBR;
GLuint programDepth;
GLuint programSkybox;
GLuint programWater;
@ -212,6 +220,84 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
Core::DrawContext(context);
}
void drawObjectTex(Core::RenderContext& context, glm::mat4 modelMatrix, float roughness, float metallic, GLuint texture) {
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);
glUniform3f(glGetUniformLocation(programTex, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
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(programTex, "spotlightPhi"), spotlightPhi);
Core::SetActiveTexture(texture, "colorTexture", programTex, 0);
Core::DrawContext(context);
glm::mat4 lightVP = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
glUniformMatrix4fv(glGetUniformLocation(program, "LightVP"), 1, GL_FALSE, (float*)&lightVP);
Core::SetActiveTexture(depthMap, "depthMap", program, 0);
Core::DrawContext(context);
}
void drawObjectTexPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint roughness, GLuint metallic, GLuint texture, GLuint normal, GLuint ao) {
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programTexPBR, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programTexPBR, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform1f(glGetUniformLocation(programTexPBR, "exposition"), exposition);
//glUniform1f(glGetUniformLocation(programTex, "roughness"), roughness);
//glUniform1f(glGetUniformLocation(programTex, "metallic"), metallic);
//glUniform3f(glGetUniformLocation(programTex, "color"), color.x, color.y, color.z);
glUniform3f(glGetUniformLocation(programTexPBR, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform3f(glGetUniformLocation(programTexPBR, "sunDir"), sunDir.x, sunDir.y, sunDir.z);
glUniform3f(glGetUniformLocation(programTexPBR, "sunColor"), sunColor.x, sunColor.y, sunColor.z);
glUniform3f(glGetUniformLocation(programTexPBR, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
glUniform3f(glGetUniformLocation(programTexPBR, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z);
glUniform3f(glGetUniformLocation(programTexPBR, "spotlightConeDir"), spotlightConeDir.x, spotlightConeDir.y, spotlightConeDir.z);
glUniform3f(glGetUniformLocation(programTexPBR, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z);
glUniform3f(glGetUniformLocation(programTexPBR, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
glUniform1f(glGetUniformLocation(programTexPBR, "spotlightPhi"), spotlightPhi);
Core::SetActiveTexture(texture, "colorTexture", programTexPBR, 0);
Core::SetActiveTexture(metallic, "metallicTexture", programTexPBR, 1);
Core::SetActiveTexture(roughness, "roughnessTexture", programTexPBR, 2);
Core::SetActiveTexture(ao, "aoTexture", programTexPBR, 3);
Core::SetActiveTexture(normal, "normalSampler", programTexPBR,4);
Core::DrawContext(context);
glm::mat4 lightVP = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
glUniformMatrix4fv(glGetUniformLocation(program, "LightVP"), 1, GL_FALSE, (float*)&lightVP);
Core::SetActiveTexture(depthMap, "depthMap", program, 0);
Core::DrawContext(context);
}
void drawObjectDepth(Core::RenderContext context, glm::mat4 viewProjectionMatrix, glm::mat4 modelMatrix) {
glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjectionMatrix);
@ -247,13 +333,14 @@ void renderShadowapSun() {
drawObjectDepth(models::deskContext, lightVP, glm::mat4());
drawObjectDepth(models::doorContext, lightVP, glm::mat4());
drawObjectDepth(models::drawerContext, lightVP, glm::mat4());
drawObjectDepth(models::marbleBustContext, lightVP, glm::mat4());
drawObjectDepth(models::marbleBustContext, lightVP, glm::translate(glm::mat4(), glm::vec3(0, 0, -0.2)));
drawObjectDepth(models::marbleBustContext, lightVP, glm::translate(glm::mat4(), glm::vec3(0, 0, 0.2)));
drawObjectDepth(models::materaceContext, lightVP, glm::mat4());
drawObjectDepth(models::pencilsContext, lightVP, glm::mat4());
drawObjectDepth(models::planeContext, lightVP, glm::mat4());
drawObjectDepth(models::roomContext, lightVP, glm::mat4());
drawObjectDepth(models::windowContext, lightVP, glm::mat4());
drawObjectDepth(models::tableContext, lightVP, glm::mat4());
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT);
@ -327,12 +414,13 @@ void renderScene(GLFWwindow* window)
drawObjectPBR(models::deskContext, glm::mat4(), glm::vec3(0.428691f, 0.08022f, 0.036889f), 0.2f, 0.0f);
drawObjectPBR(models::doorContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
drawObjectPBR(models::drawerContext, glm::mat4(), glm::vec3(0.428691f, 0.08022f, 0.036889f), 0.2f, 0.0f);
drawObjectPBR(models::marbleBustContext, glm::mat4(), glm::vec3(1.f, 1.f, 1.f), 0.5f, 1.0f);
drawObjectPBR(models::materaceContext, glm::mat4(), glm::vec3(0.9f, 0.9f, 0.9f), 0.8f, 0.0f);
drawObjectPBR(models::pencilsContext, glm::mat4(), glm::vec3(0.10039f, 0.018356f, 0.001935f), 0.1f, 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(0.9f, 0.9f, 0.9f), 0.8f, 0.0f);
drawObjectPBR(models::windowContext, glm::mat4(), 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));
@ -357,6 +445,13 @@ void renderScene(GLFWwindow* window)
spotlightPos = spaceshipPos + 0.2 * spaceshipDir;
spotlightConeDir = spaceshipDir;
glUseProgram(programTex);
drawObjectTex(models::marbleBustContext, glm::translate(glm::mat4(), glm::vec3(0, 0, -0.2)), 0.2, 0, texture::rust);
drawObjectTex(models::marbleBustContext, glm::translate(glm::mat4(), glm::vec3(0,0,0.2)), 0, 0.2, texture::rust);
glUseProgram(programTexPBR);
drawObjectTexPBR(models::tableContext, glm::mat4(), texture::table_roughness, texture::table_metallic, texture::table_albedo, texture::table_normal, texture::table_ao);
glUseProgram(programWater);
//drawObjectColorWater(waterContext, glm::translate(glm::mat4(1.0), glm::vec3(0.0, -1.0, 0.0)) * glm::scale(glm::vec3(30.0)), glm::vec3(0.1, 0.1, 0.95), time, texture::water);
drawObjectColorWater(waterContext, glm::mat4(), glm::vec4(0.1, 0.1, 0.95, 0.5), time, texture::water);
@ -410,8 +505,16 @@ void init(GLFWwindow* window)
programDepth = shaderLoader.CreateProgram("shaders/shader_shadowap_sun.vert", "shaders/shader_shadowap_sun.frag");
programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
programWater = shaderLoader.CreateProgram("shaders/shader_water.vert", "shaders/shader_water.frag");
programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
programTexPBR = shaderLoader.CreateProgram("shaders/shader_tex_pbr.vert", "shaders/shader_tex_pbr.frag");
water.readOBJ("./models/plane2.obj");
texture::water = Core::LoadTexture("textures/test.png");
texture::rust = Core::LoadTexture("textures/rust.jpg");
texture::table_albedo = Core::LoadTexture("textures/table_albedo.png");
texture::table_metallic = Core::LoadTexture("textures/table_metallic.png");
texture::table_roughness = Core::LoadTexture("textures/table_roughness.png");
texture::table_ao = Core::LoadTexture("textures/table_ao.png");
texture::table_normal = Core::LoadTexture("textures/table_normal.png");
loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/spaceship.obj", shipContext);
loadModelToContext("./models/bed.obj", models::bedContext);
@ -429,6 +532,7 @@ void init(GLFWwindow* window)
loadModelToContext("./models/window.obj", models::windowContext);
loadModelToContext("./models/test.obj", models::testContext);
loadModelToContext("./models/cube.obj", models::cubeContext);
loadModelToContext("./models/table.obj", models::tableContext);
skyboxTexture = loadSkybox(faces);
drawSkybox(models::cubeContext, transformation, skyboxTexture);

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 845 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 824 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 287 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 MiB

BIN
cw 9/textures/table_ao.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB