Change the room and objects colors, add some models (shelf, fish, glass wall). Starting implementation of shadows.

This commit is contained in:
xxxEGOxxx 2023-01-31 18:45:44 +01:00
parent 1da5b3928a
commit 192eed80ad
17 changed files with 10038 additions and 4378 deletions

View File

@ -43,6 +43,8 @@
<None Include="shaders\shader_8_sun.vert" />
<None Include="shaders\test.frag" />
<None Include="shaders\test.vert" />
<None Include="shader_shadow_global_sun.frag" />
<None Include="shader_shadow_global_sun.vert" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5BACD057-4B83-4CB6-A367-40A10BCE2149}</ProjectGuid>

View File

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

View File

@ -1,12 +1,32 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org
newmtl Material.009
Ns 0.000000
newmtl Coffee_table
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Kd 0.118056 0.118056 0.118056
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1
illum 2
newmtl Degradable_Metal
Ns 937.375977
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.218182 0.218182 0.218182
Ke 0.000000 0.000000 0.000000
Ni 21.399994
d 1.000000
illum 3
newmtl MDF_Freijó_-_Guararapis
Ns 1000.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.002486 0.007223
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

View File

@ -0,0 +1,2 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org

View File

@ -1,12 +1,2 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org
newmtl None.008
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1

12
cw 9/models/Sofa_base.mtl Normal file
View File

@ -0,0 +1,12 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org
newmtl Material_Wool.jpg.001
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1

View File

@ -1,6 +1,16 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org
newmtl Material.012
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1
newmtl Material_Wool.jpg.001
Ns 0.000000
Ka 1.000000 1.000000 1.000000

32
cw 9/models/desk.mtl Normal file
View File

@ -0,0 +1,32 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org
newmtl Coffee_table
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.118056 0.118056 0.118056
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Degradable_Metal
Ns 937.375977
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.218182 0.218182 0.218182
Ke 0.000000 0.000000 0.000000
Ni 21.399994
d 1.000000
illum 3
newmtl MDF_Freijó_-_Guararapis
Ns 1000.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.002486 0.007223
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

File diff suppressed because it is too large Load Diff

2
cw 9/models/drawer.mtl Normal file
View File

@ -0,0 +1,2 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org

12
cw 9/models/fish.mtl Normal file
View File

@ -0,0 +1,12 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org
newmtl FISH
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1

2
cw 9/models/shelf.mtl Normal file
View File

@ -0,0 +1,2 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org

12
cw 9/models/spaceship.mtl Normal file
View File

@ -0,0 +1,12 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org
newmtl Material.010
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 1

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

@ -35,10 +35,16 @@ namespace models {
Core::RenderContext windowContext;
Core::RenderContext testContext;
Core::RenderContext sofaBaseContext;
Core::RenderContext sofaContext;
Core::RenderContext door1Context;
Core::RenderContext door2Context;
Core::RenderContext door3Context;
Core::RenderContext shelfContext;
Core::RenderContext fishContext;
Core::RenderContext glassWallContext;
}
GLuint depthMapFBO;
@ -48,6 +54,7 @@ GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
GLuint programDepth;
Core::Shader_Loader shaderLoader;
@ -56,7 +63,7 @@ Core::RenderContext sphereContext;
glm::vec3 sunPos = glm::vec3(-0.028716f, 2.06441f, 3.84067f);
glm::vec3 sunDir = glm::vec3(-0.93633f, 0.351106f, 0.003226f);
glm::vec3 sunColor = glm::vec3(0.9f, 0.9f, 0.7f)*5;
glm::vec3 sunColor = glm::vec3(0.9f, 0.6f, 0.7f)*5;
glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f);
glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f);
@ -71,7 +78,7 @@ float aspectRatio = 1.f;
float exposition = 1.f;
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6)*3;
glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6)*5;
glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0);
@ -160,27 +167,64 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
}
void renderShadowapSun() {
void drawObjectDepth(Core::RenderContext context, glm::mat4 viewProjectionMatrix, glm::mat4 modelMatrix) {
glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjectionMatrix);
glUniformMatrix4fv(glGetUniformLocation(programDepth, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
Core::DrawContext(context);
}
void renderShadowapSun(GLuint depthMapFBO, glm::mat4 lightVP) {
float time = glfwGetTime();
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
//uzupelnij o renderowanie glebokosci do tekstury
glUseProgram(programDepth);
//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);
glViewport(0, 0, WIDTH, HEIGHT);
}
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 renderScene(GLFWwindow* window)
{
glClearColor(0.4f, 0.4f, 0.8f, 1.0f);
glEnable(GL_BLEND);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float time = glfwGetTime();
updateDeltaTime(time);
renderShadowapSun();
glm::mat4 lightVPSun = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
renderShadowapSun(depthMapFBO, lightVPSun);
//space lamp
glUseProgram(programSun);
@ -193,11 +237,11 @@ void renderScene(GLFWwindow* window)
glUseProgram(program);
drawObjectPBR(sphereContext, 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)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0);
drawObjectPBR(sphereContext, 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)), glm::vec4(0.2, 0.7, 0.3, 0), 0.3, 0.0);
drawObjectPBR(sphereContext,
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)),
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0);
glm::vec4(0.5, 0.5, 0.5, 0), 0.7, 0.0);
//drawObjectPBR(models::bedContext, glm::mat4(), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f);
drawObjectPBR(models::chairContext, glm::mat4(), glm::vec3(0.195239f, 0.37728f, 0.8f), 0.4f, 0.0f);
@ -207,16 +251,22 @@ void renderScene(GLFWwindow* window)
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::planeContext, glm::mat4(), glm::vec3(0.5f, 0.5f, 0.5f), 0.2f, 0.0f);
drawObjectPBR(models::roomContext, glm::mat4(), glm::vec3(0.8f, 0.8f, 0.8f), 0.8f, 0.0f);
//drawObjectPBR(models::windowContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
drawObjectPBR(models::sofaContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
drawObjectPBR(models::sofaContext, glm::mat4(), glm::vec3(0.4f, 0.4f, 0.4f), 0.5f, 0.0f);
drawObjectPBR(models::sofaBaseContext, glm::mat4(), glm::vec3(0.3f, 0.3f, 0.3f), 0.5f, 0.0f);
drawObjectPBR(models::door1Context, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
drawObjectPBR(models::door2Context, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
drawObjectPBR(models::door1Context, glm::mat4(), glm::vec3(0.4f, 0.4f, 0.4f), 0.2f, 0.0f);
drawObjectPBR(models::door2Context, glm::mat4(), glm::vec3(0.4f, 0.4f, 0.4f), 0.2f, 0.0f);
drawObjectPBR(models::door3Context, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
drawObjectPBR(models::shelfContext, glm::mat4(), glm::vec3(0.2f, 0.2f, 0.2f), 0.5f, 0.0f);
drawObjectPBR(models::fishContext, glm::mat4(), glm::vec3(0.7f, 0.2f, 0.1f), 0.5f, 0.0f);
drawObjectPBR(models::glassWallContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 1.0f, 1.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));
glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
@ -285,8 +335,8 @@ void init(GLFWwindow* window)
loadModelToContext("./models/spaceship.obj", shipContext);
//loadModelToContext("./models/bed.obj", models::bedContext);
loadModelToContext("./models/Chair_Cube.obj", models::chairContext);
loadModelToContext("./models/Desk_Cube.obj", models::deskContext);
//loadModelToContext("./models/Chair_Cube.obj", models::chairContext);
//loadModelToContext("./models/Desk_Cube.obj", models::deskContext);
//loadModelToContext("./models/door.obj", models::doorContext);
//loadModelToContext("./models/drawer.obj", models::drawerContext);
loadModelToContext("./models/Marble_Bust.obj", models::marbleBustContext);
@ -300,10 +350,14 @@ void init(GLFWwindow* window)
//loadModelToContext("./models/test.obj", models::testContext);
loadModelToContext("./models/Sofa_baseCube.obj", models::sofaContext);
loadModelToContext("./models/Sofa_base.obj", models::sofaBaseContext);
loadModelToContext("./models/Door1.obj", models::door1Context);
loadModelToContext("./models/Door2.obj", models::door2Context);
loadModelToContext("./models/Door3.obj", models::door3Context);
loadModelToContext("./models/Shelf.obj", models::shelfContext);
loadModelToContext("./models/fish.obj", models::fishContext);
loadModelToContext("./models/Glass_wall.obj", models::glassWallContext);
}
void shutdown(GLFWwindow* window)
@ -360,7 +414,6 @@ void renderLoop(GLFWwindow* window) {
while (!glfwWindowShouldClose(window))
{
processInput(window);
renderScene(window);
glfwPollEvents();
}

View File

@ -12,8 +12,10 @@
int main(int argc, char** argv)
{
// inicjalizacja glfw
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
@ -39,6 +41,7 @@ int main(int argc, char** argv)
init(window);
// uruchomienie glownej petli
renderLoop(window);
shutdown(window);