add textures

This commit is contained in:
xxxEGOxxx 2023-02-09 15:33:19 +01:00
parent 1575ad67af
commit 07dd942cdc
14 changed files with 7190 additions and 5320 deletions

View File

@ -43,6 +43,8 @@
<None Include="shaders\shader_8_sun.vert" /> <None Include="shaders\shader_8_sun.vert" />
<None Include="shaders\shader_skybox.frag" /> <None Include="shaders\shader_skybox.frag" />
<None Include="shaders\shader_skybox.vert" /> <None Include="shaders\shader_skybox.vert" />
<None Include="shaders\shader_texture.frag" />
<None Include="shaders\shader_texture.vert" />
<None Include="shaders\test.frag" /> <None Include="shaders\test.frag" />
<None Include="shaders\test.vert" /> <None Include="shaders\test.vert" />
<None Include="shader_shadow_global_sun.frag" /> <None Include="shader_shadow_global_sun.frag" />

View File

@ -114,6 +114,14 @@
</None> </None>
<None Include="shaders\shader_skybox.frag" /> <None Include="shaders\shader_skybox.frag" />
<None Include="shaders\shader_skybox.vert" /> <None Include="shaders\shader_skybox.vert" />
<None Include="shaders\test.frag" /> <None Include="shaders\test.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_texture.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_texture.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

File diff suppressed because it is too large Load Diff

View File

@ -2,38 +2,38 @@
# www.blender.org # www.blender.org
mtllib Door3.mtl mtllib Door3.mtl
o Plane.003 o Plane.003
v -3.646707 1.042882 -4.397258 v -3.506815 1.042882 -4.876167
v -3.646707 1.018917 -4.397258 v -3.506815 1.018917 -4.876167
v -3.644781 1.018917 -4.399785 v -3.506839 1.018917 -4.879344
v -3.644781 1.021039 -4.399785 v -3.506839 1.021039 -4.879344
v -3.640287 1.021903 -4.405682 v -3.506893 1.021903 -4.886758
v -3.640287 1.039032 -4.405682 v -3.506893 1.039032 -4.886758
v -3.644781 1.040839 -4.399785 v -3.506839 1.040839 -4.879344
v -3.644781 1.042882 -4.399785 v -3.506839 1.042882 -4.879344
v -3.642362 1.042882 -4.393945 v -3.501351 1.042882 -4.876207
v -3.642362 1.018917 -4.393945 v -3.501351 1.018917 -4.876207
v -3.638871 1.018917 -4.395281 v -3.499408 1.018917 -4.879399
v -3.640435 1.021039 -4.396473 v -3.501375 1.021039 -4.879385
v -3.639592 1.021903 -4.405152 v -3.506020 1.021903 -4.886765
v -3.639592 1.039032 -4.405152 v -3.506020 1.039032 -4.886765
v -3.640435 1.040839 -4.396473 v -3.501375 1.040839 -4.879385
v -3.638871 1.042882 -4.395280 v -3.499408 1.042882 -4.879399
v -3.642362 1.042882 -4.393945 v -3.501351 1.042882 -4.876207
v -3.642362 1.018917 -4.393945 v -3.501351 1.018917 -4.876207
v -3.638871 1.018917 -4.395281 v -3.499408 1.018917 -4.879399
v -3.640435 1.021039 -4.396473 v -3.501375 1.021039 -4.879385
v -3.639592 1.021903 -4.405152 v -3.506020 1.021903 -4.886765
v -3.639592 1.039032 -4.405152 v -3.506020 1.039032 -4.886765
v -3.640435 1.040839 -4.396473 v -3.501375 1.040839 -4.879385
v -3.638871 1.042882 -4.395280 v -3.499408 1.042882 -4.879399
vn -0.0000 1.0000 -0.0000 vn -0.0000 1.0000 -0.0000
vn -0.6062 -0.0000 0.7953 vn 0.0074 -0.0000 1.0000
vn 0.0702 -0.9933 -0.0921 vn -0.0009 -0.9933 -0.1158
vn 0.6062 -0.0000 -0.7953 vn -0.0074 -0.0000 -1.0000
vn 0.1435 0.9716 -0.1883 vn -0.0017 0.9716 -0.2368
vn -0.0000 -1.0000 -0.0000 vn -0.0000 -1.0000 -0.0000
vn 0.3577 -0.0000 0.9338 vn 0.8544 -0.0000 0.5196
vn 0.9953 -0.0000 0.0967 vn 0.8463 -0.0000 -0.5327
vt 0.603500 0.817600 vt 0.603500 0.817600
vt 0.603700 0.772600 vt 0.603700 0.772600
vt 0.597100 0.770600 vt 0.597100 0.770600

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
# Blender 3.4.1 MTL File: 'Akwarium_room.blend'
# www.blender.org
newmtl Glossy_Reflexion.jpg
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

1729
cw 9/models/doorhandle.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,39 @@
# Blender 3.4.1 # Blender 3.4.1
# www.blender.org # www.blender.org
mtllib plane.mtl mtllib plane.mtl
o Plane o floor
v -6.988060 0.000405 5.147048 v -6.995758 -0.131902 5.109023
v 8.992895 0.000405 5.147048 v -6.995758 0.006152 5.109023
v -6.988060 0.000405 -5.050594 v -6.995758 -0.131902 -4.978487
v 8.992895 0.000405 -5.050594 v -6.995758 0.006152 -4.978487
v 8.952623 -0.131902 5.109023
v 8.952623 0.006152 5.109023
v 8.952623 -0.131902 -4.978487
v 8.952623 0.006152 -4.978487
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 vn -0.0000 1.0000 -0.0000
vt 0.000000 0.000000 vt 0.375000 0.000000
vt 1.000000 0.000000 vt 0.375000 1.000000
vt 0.000000 1.000000 vt 0.125000 0.750000
vt 1.000000 1.000000 vt 0.625000 0.000000
vt 0.625000 1.000000
vt 0.875000 0.750000
vt 0.375000 0.250000
vt 0.125000 0.500000
vt 0.625000 0.250000
vt 0.875000 0.500000
vt 0.375000 0.750000
vt 0.625000 0.750000
vt 0.375000 0.500000
vt 0.625000 0.500000
s 0 s 0
f 1/1/1 2/2/1 4/4/1 3/3/1 f 1/1/1 2/4/1 4/9/1 3/7/1
f 3/7/2 4/9/2 8/14/2 7/13/2
f 7/13/3 8/14/3 6/12/3 5/11/3
f 5/11/4 6/12/4 2/5/4 1/2/4
f 3/8/5 7/13/5 5/11/5 1/3/5
f 8/14/6 4/10/6 2/6/6 6/12/6

View File

@ -0,0 +1,21 @@
#version 430 core
float AMBIENT = 0.1;
uniform vec3 color;
uniform vec3 lightPos;
uniform sampler2D colorTexture;
in vec3 vecNormal;
in vec3 worldPos;
in vec2 vecTex;
out vec4 outColor;
void main()
{
vec3 lightDir = normalize(lightPos-worldPos);
vec3 normal = normalize(vecNormal);
vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
float diffuse=max(0,dot(normal,lightDir));
outColor = vec4(textureColor*min(1,AMBIENT+diffuse), 1.0);
}

View File

@ -0,0 +1,21 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
uniform mat4 transformation;
uniform mat4 modelMatrix;
out vec3 vecNormal;
out vec3 worldPos;
out vec2 vecTex;
void main()
{
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
vecTex = vertexTexCoord;
vecTex.y = 1.0 - vecTex.y;
gl_Position = transformation * vec4(vertexPosition, 1.0);
}

View File

@ -8,7 +8,7 @@
#include "Shader_Loader.h" #include "Shader_Loader.h"
#include "Render_Utils.h" #include "Render_Utils.h"
#include "SOIL.h" #include "SOIL.h"
//#include "Texture.h" #include "Texture.h"
#include "Box.cpp" #include "Box.cpp"
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
@ -29,7 +29,7 @@ namespace models {
Core::RenderContext marbleBustContext; Core::RenderContext marbleBustContext;
Core::RenderContext materaceContext; Core::RenderContext materaceContext;
Core::RenderContext pencilsContext; Core::RenderContext pencilsContext;
Core::RenderContext planeContext; Core::RenderContext floorContext;
Core::RenderContext roomContext; Core::RenderContext roomContext;
Core::RenderContext spaceshipContext; Core::RenderContext spaceshipContext;
Core::RenderContext sphereContext; Core::RenderContext sphereContext;
@ -41,6 +41,7 @@ namespace models {
Core::RenderContext door1Context; Core::RenderContext door1Context;
Core::RenderContext door2Context; Core::RenderContext door2Context;
Core::RenderContext door3Context; Core::RenderContext door3Context;
Core::RenderContext doorhandleContext;
Core::RenderContext shelfContext; Core::RenderContext shelfContext;
@ -48,6 +49,19 @@ namespace models {
Core::RenderContext glassWallContext; Core::RenderContext glassWallContext;
} }
namespace texture {
GLuint floorTexture;
GLuint roomTexture;
GLuint fishTexture;
GLuint sofaTexture;
GLuint sofaBaseTexture;
GLuint door1Texture;
GLuint door2Texture;
GLuint door3Texture;
GLuint doorhandleTexture;
GLuint glassWallTexture;
}
GLuint depthMapFBO; GLuint depthMapFBO;
GLuint depthMap; GLuint depthMap;
@ -77,14 +91,14 @@ GLuint VAO,VBO;
float aspectRatio = 1.f; float aspectRatio = 1.f;
float exposition = 3.f; float exposition = 1.f;
glm::vec3 pointlightPos = glm::vec3(0, 2, 0); glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6)*5; glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6)*10;
glm::vec3 spotlightPos = glm::vec3(0, 0, 0); glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0); glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0);
glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9)*5; glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9)*10;
float spotlightPhi = 3.14 / 4; float spotlightPhi = 3.14 / 4;
float skyboxVertices[] = float skyboxVertices[] =
@ -215,6 +229,49 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
} }
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID) {
glUseProgram(programTex);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
/*glm::mat4 transformation = modelMatrix;*/
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
//glUniform3f(glGetUniformLocation(programTex, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
glUniform1f(glGetUniformLocation(program, "exposition"), exposition);
//glUniform1f(glGetUniformLocation(program, "roughness"), roughness);
//glUniform1f(glGetUniformLocation(program, "metallic"), metallic);
//glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform3f(glGetUniformLocation(program, "sunDir"), sunDir.x, sunDir.y, sunDir.z);
glUniform3f(glGetUniformLocation(program, "sunColor"), sunColor.x, sunColor.y, sunColor.z);
glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
glUniform3f(glGetUniformLocation(program, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z);
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spotlightConeDir.x, spotlightConeDir.y, spotlightConeDir.z);
glUniform3f(glGetUniformLocation(program, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z);
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi);
//For shadows
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);
glUniform1i(glGetUniformLocation(program, "depthMap"), 2);
glActiveTexture(GL_TEXTURE0 + 2);
glBindTexture(GL_TEXTURE_2D, depthMap);
Core::SetActiveTexture(textureID, "colorTexture", programTex, 0);
Core::DrawContext(context);
glUseProgram(0);
}
void drawObjectDepth(Core::RenderContext context, glm::mat4 viewProjectionMatrix, glm::mat4 modelMatrix) { void drawObjectDepth(Core::RenderContext context, glm::mat4 viewProjectionMatrix, glm::mat4 modelMatrix) {
glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjectionMatrix); glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjectionMatrix);
@ -324,7 +381,10 @@ void renderScene(GLFWwindow* window)
drawObjectPBR(models::marbleBustContext, glm::mat4(), glm::vec3(1.f, 1.f, 1.f), 0.5f, 1.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::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::pencilsContext, glm::mat4(), glm::vec3(0.10039f, 0.018356f, 0.001935f), 0.1f, 0.0f);
drawObjectPBR(models::planeContext, glm::mat4(), glm::vec3(0.5f, 0.5f, 0.5f), 0.2f, 0.0f);
drawObjectPBR(models::floorContext, 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::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::windowContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
@ -337,8 +397,9 @@ void renderScene(GLFWwindow* window)
drawObjectPBR(models::shelfContext, glm::mat4(), glm::vec3(0.2f, 0.2f, 0.2f), 0.5f, 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::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); //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 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir)); glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
@ -382,6 +443,12 @@ void renderScene(GLFWwindow* window)
spotlightPos = spaceshipPos + 0.2 * spaceshipDir; spotlightPos = spaceshipPos + 0.2 * spaceshipDir;
spotlightConeDir = spaceshipDir; spotlightConeDir = spaceshipDir;
drawObjectTexture(models::floorContext, glm::mat4(), texture::floorTexture);
drawObjectTexture(models::glassWallContext, glm::mat4(), texture::glassWallTexture);
drawObjectTexture(models::roomContext, glm::mat4(), texture::roomTexture);
drawObjectTexture(models::fishContext, glm::mat4(), texture::fishTexture);
//test depth buffer //test depth buffer
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glUseProgram(programTest); //glUseProgram(programTest);
@ -422,23 +489,16 @@ void init(GLFWwindow* window)
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");
loadModelToContext("./models/sphere.obj", sphereContext); loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/spaceship.obj", shipContext); 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/door.obj", models::doorContext);
//loadModelToContext("./models/drawer.obj", models::drawerContext);
loadModelToContext("./models/Marble_Bust.obj", models::marbleBustContext); loadModelToContext("./models/Marble_Bust.obj", models::marbleBustContext);
//loadModelToContext("./models/materace.obj", models::materaceContext);
loadModelToContext("./models/Pencils_Cylinder.obj", models::pencilsContext); loadModelToContext("./models/Pencils_Cylinder.obj", models::pencilsContext);
loadModelToContext("./models/plane.obj", models::planeContext); loadModelToContext("./models/plane.obj", models::floorContext);
loadModelToContext("./models/room.obj", models::roomContext); loadModelToContext("./models/room.obj", models::roomContext);
loadModelToContext("./models/spaceship.obj", models::spaceshipContext); loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
loadModelToContext("./models/sphere.obj", models::sphereContext); loadModelToContext("./models/sphere.obj", models::sphereContext);
//loadModelToContext("./models/window.obj", models::windowContext); loadModelToContext("./models/test.obj", models::testContext);
//loadModelToContext("./models/test.obj", models::testContext);
loadModelToContext("./models/Sofa_baseCube.obj", models::sofaContext); loadModelToContext("./models/Sofa_baseCube.obj", models::sofaContext);
loadModelToContext("./models/Sofa_base.obj", models::sofaBaseContext); loadModelToContext("./models/Sofa_base.obj", models::sofaBaseContext);
@ -450,6 +510,12 @@ void init(GLFWwindow* window)
loadModelToContext("./models/fish.obj", models::fishContext); loadModelToContext("./models/fish.obj", models::fishContext);
loadModelToContext("./models/Glass_wall.obj", models::glassWallContext); loadModelToContext("./models/Glass_wall.obj", models::glassWallContext);
//loading textures
programTex = shaderLoader.CreateProgram("shaders/shader_texture.vert", "shaders/shader_texture.frag");
texture::glassWallTexture = Core::LoadTexture("textures/sofa.jpg");
//
//prepering skybox //prepering skybox
programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag"); programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
glUseProgram(programSkybox); glUseProgram(programSkybox);

BIN
cw 9/textures/floor.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

View File

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

BIN
cw 9/textures/sofa.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 KiB