Merge pull request 'Dodanie działającego skyboxa' (#1) from skybox into master

Reviewed-on: #1
This commit is contained in:
Angelika Iskra 2023-01-14 17:01:09 +01:00
commit 9c7d632ab3
46 changed files with 228 additions and 62 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.

View File

@ -1,64 +1,33 @@
c:\software\vs19\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(513,5): warning MSB8028: The intermediate directory (Debug\) contains files shared from another project (grk-cw9.vcxproj). This can lead to incorrect clean and rebuild behavior. 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 main.cpp
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: "APIENTRY": ponowna definicja makra
J:\GrafikaKomputerowa\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY' C:\Users\Genos\Source\Repos\GRK_Room\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(74,30): warning C4305: 'initializing': truncation from 'double' to 'float' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(95,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(88,38): warning C4305: '=': truncation from 'double' to 'float' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(116,38): warning C4305: "=": obcięcie z "double" do "float"
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(111,16): warning C4305: 'initializing': truncation from 'double' to 'float' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(139,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(159,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(158,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(176,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(250,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(183,108): warning C4305: 'argument': truncation from 'double' to 'T' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(271,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(280,108): warning C4305: "argument": obcięcie z "double" do "T"
with with
[ [
T=float T=float
] ]
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(191,87): warning C4305: 'argument': truncation from 'double' to 'T' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(288,87): warning C4305: "argument": obcięcie z "double" do "T"
with with
[ [
T=float T=float
] ]
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(191,223): warning C4305: 'argument': truncation from 'double' to 'float' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(288,223): warning C4305: "argument": obcięcie z "double" do "float"
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(194,59): warning C4305: 'argument': truncation from 'double' to 'T' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(291,59): warning C4305: "argument": obcięcie z "double" do "T"
with with
[ [
T=float T=float
] ]
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(195,37): warning C4305: 'argument': truncation from 'double' to 'float' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(292,37): warning C4305: "argument": obcięcie z "double" do "float"
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(227,2): warning C4305: 'argument': truncation from 'double' to 'float' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(324,2): warning C4305: "argument": obcięcie z "double" do "float"
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(330,21): warning C4305: '-=': truncation from 'double' to 'float' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(433,21): warning C4305: "-=": obcięcie z "double" do "float"
J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(332,21): warning C4305: '+=': truncation from 'double' to 'float' C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(435,21): warning C4305: "+=": obcięcie z "double" do "float"
Render_Utils.cpp Box.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
Texture.cpp LINK : warning LNK4098: domyślna biblioteka „MSVCRT” powoduje konflikt z innymi bibliotekami; użyj opcji /NODEFAULTLIB:biblioteka
Generating Code... grk-cw9.vcxproj -> C:\Users\Genos\Source\Repos\GRK_Room\Debug\room.exe
image_DXT.c
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_DXT.c(92,9): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
image_helper.c
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(325,1): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(366,58): warning C4244: '=': conversion from 'double' to 'float', possible loss of data
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(373,46): warning C4244: '=': conversion from 'float' to 'int', possible loss of data
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(415,58): warning C4244: '=': conversion from 'double' to 'float', possible loss of data
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(422,62): warning C4244: '=': conversion from 'float' to 'int', possible loss of data
SOIL.c
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\SOIL.c(1719,36): warning C4018: '<=': signed/unsigned mismatch
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\SOIL.c(1729,19): warning C4018: '<': signed/unsigned mismatch
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\SOIL.c(1841,6): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
stb_image_aug.c
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(177,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(251,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(303,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(1557,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(2394,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(2709,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(2995,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(3209,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(3548,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(3644,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(362,19): warning C4018: '>': signed/unsigned mismatch
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(366,19): warning C4018: '>': signed/unsigned mismatch
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(390,19): warning C4018: '<': signed/unsigned mismatch
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(427,19): warning C4018: '<': signed/unsigned mismatch
J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(498,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
Generating Code...
Box.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
grk-cw9.vcxproj -> J:\GrafikaKomputerowa\grk\Debug\room.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project> <Project>
<ProjectOutputs> <ProjectOutputs>
<ProjectOutput> <ProjectOutput>
<FullPath>J:\GrafikaKomputerowa\grk\Debug\room.exe</FullPath> <FullPath>C:\Users\Genos\Source\Repos\GRK_Room\Debug\room.exe</FullPath>
</ProjectOutput> </ProjectOutput>
</ProjectOutputs> </ProjectOutputs>
<ContentFiles /> <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: PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|J:\GrafikaKomputerowa\grk\| Debug|Win32|C:\Users\Genos\Source\Repos\GRK_Room\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -41,6 +41,10 @@
<None Include="shaders\shader_9_1.vert" /> <None Include="shaders\shader_9_1.vert" />
<None Include="shaders\shader_8_sun.frag" /> <None Include="shaders\shader_8_sun.frag" />
<None Include="shaders\shader_8_sun.vert" /> <None Include="shaders\shader_8_sun.vert" />
<None Include="shaders\shader_shadowmapsun.frag" />
<None Include="shaders\shader_shadowmapsun.vert" />
<None Include="shaders\shader_skybox.frag" />
<None Include="shaders\shader_skybox.vert" />
<None Include="shaders\test.frag" /> <None Include="shaders\test.frag" />
<None Include="shaders\test.vert" /> <None Include="shaders\test.vert" />
</ItemGroup> </ItemGroup>

View File

@ -109,5 +109,17 @@
<None Include="shaders\test.vert"> <None Include="shaders\test.vert">
<Filter>Shader Files</Filter> <Filter>Shader Files</Filter>
</None> </None>
<None Include="shaders\shader_skybox.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_skybox.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_shadowmapsun.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_shadowmapsun.frag">
<Filter>Shader Files</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

40
cw 9/models/cube.obj Normal file
View File

@ -0,0 +1,40 @@
# Blender v2.90.0 OBJ File: ''
# www.blender.org
mtllib cube.mtl
o Cube
v -10.000000 -10.000000 10.000000
v -10.000000 10.000000 10.000000
v -10.000000 -10.000000 -10.000000
v -10.000000 10.000000 -10.000000
v 10.000000 -10.000000 10.000000
v 10.000000 10.000000 10.000000
v 10.000000 -10.000000 -10.000000
v 10.000000 10.000000 -10.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.625000 0.500000
vt 0.375000 0.500000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.125000 0.500000
vt 0.125000 0.750000
vt 0.875000 0.500000
vt 0.875000 0.750000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
usemtl _PBR
s 1
f 1/1/1 2/2/1 4/3/1 3/4/1
f 3/4/2 4/3/2 8/5/2 7/6/2
f 7/6/3 8/5/3 6/7/3 5/8/3
f 5/8/4 6/7/4 2/9/4 1/10/4
f 3/11/5 7/6/5 5/8/5 1/12/5
f 8/5/6 4/13/6 2/14/6 6/7/6

View File

@ -0,0 +1,5 @@
#version 430 core
void main()
{
}

View File

@ -0,0 +1,13 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
uniform mat4 viewProjectionMatrix;
uniform mat4 modelMatrix;
void main()
{
gl_Position = viewProjectionMatrix * modelMatrix * vec4(vertexPosition, 1.0);
}

View File

@ -0,0 +1,12 @@
#version 430 core
uniform samplerCube skybox;
in vec3 texCoord;
out vec4 out_color;
void main()
{
out_color = texture(skybox,texCoord);
}

View File

@ -0,0 +1,13 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
uniform mat4 transformation;
out vec3 texCoord;
void main()
{
texCoord = vertexPosition;
gl_Position = transformation * vec4(vertexPosition, 1.0);
}

View File

@ -15,6 +15,9 @@
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include <string> #include <string>
#include "SOIL/SOIL.h"
#include "SOIL/stb_image_aug.h"
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024; const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
int WIDTH = 500, HEIGHT = 500; int WIDTH = 500, HEIGHT = 500;
@ -34,8 +37,24 @@ namespace models {
Core::RenderContext sphereContext; Core::RenderContext sphereContext;
Core::RenderContext windowContext; Core::RenderContext windowContext;
Core::RenderContext testContext; Core::RenderContext testContext;
} }
namespace texture {
GLuint cubemapTexture;
}
Core::RenderContext cubeContext;;
std::vector<std::string> faces =
{
"textures/skybox/right2.jpg",
"textures/skybox/left2.jpg",
"textures/skybox/top2.jpg",
"textures/skybox/bottom2.jpg",
"textures/skybox/front2.jpg",
"textures/skybox/back2.jpg",
};
GLuint depthMapFBO; GLuint depthMapFBO;
GLuint depthMap; GLuint depthMap;
@ -43,6 +62,8 @@ GLuint program;
GLuint programSun; GLuint programSun;
GLuint programTest; GLuint programTest;
GLuint programTex; GLuint programTex;
GLuint programDepth;
GLuint programSkybox;
Core::Shader_Loader shaderLoader; Core::Shader_Loader shaderLoader;
@ -73,6 +94,8 @@ glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0);
glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9)*3; glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9)*3;
float spotlightPhi = 3.14 / 4; 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 scaleToRoom(glm::mat4 mat) glm::mat4 scaleToRoom(glm::mat4 mat)
{ {
@ -111,7 +134,7 @@ glm::mat4 createCameraMatrix()
glm::mat4 createPerspectiveMatrix() glm::mat4 createPerspectiveMatrix()
{ {
glm::mat4 perspectiveMatrix; glm::mat4 perspectiveMatrix;
float n = 0.05; float n = 0.05;
float f = 20.; float f = 20.;
@ -120,16 +143,60 @@ glm::mat4 createPerspectiveMatrix()
perspectiveMatrix = glm::mat4({ perspectiveMatrix = glm::mat4({
1,0.,0.,0., 1,0.,0.,0.,
0.,aspectRatio,0.,0., 0.,aspectRatio,0.,0.,
0.,0.,(f+n) / (n - f),2*f * n / (n - f), 0.,0.,(f + n) / (n - f),2 * f * n / (n - f),
0.,0.,-1.,0., 0.,0.,-1.,0.,
}); });
perspectiveMatrix=glm::transpose(perspectiveMatrix); perspectiveMatrix = glm::transpose(perspectiveMatrix);
return perspectiveMatrix; return perspectiveMatrix;
} }
void loadCubemap(std::vector<std::string> faces)
{
unsigned int textureID;
glGenTextures(1, &texture::cubemapTexture);
glBindTexture(GL_TEXTURE_CUBE_MAP, texture::cubemapTexture);
int w, h;
unsigned char* data;
for (unsigned int i = 0; i < 6; i++)
{
data = SOIL_load_image(faces[i].c_str(), &w, &h, 0, SOIL_LOAD_RGBA);
glTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data
);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
}
void drawObjectDepth(Core::RenderContext& context, glm::mat4 viewProjection, glm::mat4 modelMatrix)
{
glUseProgram(programDepth);
glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjection);
glUniformMatrix4fv(glGetUniformLocation(programDepth, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
Core::DrawContext(context);
}
void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
glDisable(GL_DEPTH_TEST);
glUseProgram(programSkybox);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programSkybox, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform1i(glGetUniformLocation(programSkybox, "skybox"), 0);
Core::DrawContext(context);
glEnable(GL_DEPTH_TEST);
}
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) { void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
@ -157,18 +224,41 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z); glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi); glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi);
Core::DrawContext(context); Core::DrawContext(context);
} }
void initDepthMap() {
glGenFramebuffers(1, &depthMapFBO);
glGenTextures(1, &depthMap);
glBindTexture(GL_TEXTURE_2D, depthMap);
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);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void renderShadowapSun() { void renderShadowapSun() {
float time = glfwGetTime(); float time = glfwGetTime();
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT); glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
//uzupelnij o renderowanie glebokosci do tekstury //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, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, WIDTH, HEIGHT);
@ -182,6 +272,8 @@ void renderScene(GLFWwindow* window)
updateDeltaTime(time); updateDeltaTime(time);
renderShadowapSun(); renderShadowapSun();
drawSkyBox(cubeContext, glm::translate(cameraPos));
//space lamp //space lamp
glUseProgram(programSun); glUseProgram(programSun);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
@ -274,9 +366,15 @@ void init(GLFWwindow* window)
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag"); program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag"); programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag"); programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
programDepth = shaderLoader.CreateProgram("shaders/shader_shadowmapsun.vert", "shaders/shader_shadowmapsun.frag");
programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
loadCubemap(faces);
initDepthMap();
loadModelToContext("./models/sphere.obj", sphereContext); loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/spaceship.obj", shipContext); loadModelToContext("./models/spaceship.obj", shipContext);
loadModelToContext("./models/cube.obj", cubeContext);
loadModelToContext("./models/bed.obj", models::bedContext); loadModelToContext("./models/bed.obj", models::bedContext);

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 882 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 KiB