Add shadows, add glass, add aquaruim, replace some models

This commit is contained in:
xxxEGOxxx 2023-02-10 19:23:28 +01:00
parent 760ccd368b
commit 35fab0f392
19 changed files with 16383 additions and 8803 deletions

View File

@ -41,6 +41,8 @@
<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_shadow_global_sun.frag" />
<None Include="shaders\shader_shadow_global_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.frag" />

View File

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

File diff suppressed because it is too large Load Diff

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

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

39
cw 9/models/aquarium.obj Normal file
View File

@ -0,0 +1,39 @@
# Blender 3.4.1
# www.blender.org
mtllib aquarium.mtl
o Cube
v -6.815081 0.820323 1.347755
v -6.815081 1.562090 1.347755
v -6.815081 0.820323 0.896444
v -6.815081 1.562090 0.896444
v -6.363512 0.820323 1.347755
v -6.363512 1.562090 1.347755
v -6.363512 0.820323 0.896444
v -6.363512 1.562090 0.896444
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
vt 0.375000 0.000000
vt 0.375000 1.000000
vt 0.125000 0.750000
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
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

7476
cw 9/models/fighter.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -787,19 +787,6 @@ v -6.982596 1.484583 -2.444353
v -6.982596 1.113351 -2.444353 v -6.982596 1.113351 -2.444353
v -6.982596 1.484583 -2.444353 v -6.982596 1.484583 -2.444353
v -6.982596 1.113351 -2.444353 v -6.982596 1.113351 -2.444353
v -7.078547 1.484583 -2.444353
v -7.078547 2.227048 -2.444353
v -7.071580 1.484583 -2.444354
v -7.071580 1.113351 -2.444354
v -7.078448 1.484583 0.062350
v -7.078448 2.227048 0.062350
v -7.079370 1.484583 0.062349
v -7.079368 1.113351 0.062349
v -7.079903 1.113351 0.062349
v -7.079903 1.113351 -2.444353
v -7.079903 1.113351 -1.191002
v -7.115730 2.227048 0.062349
v -7.115729 2.227048 -2.444354
vn -1.0000 -0.0000 0.0007 vn -1.0000 -0.0000 0.0007
vn -0.0038 -0.0000 -1.0000 vn -0.0038 -0.0000 -1.0000
vn 1.0000 -0.0000 -0.0007 vn 1.0000 -0.0000 -0.0007
@ -1655,19 +1642,6 @@ vt 0.500000 0.187500
vt 0.468750 0.187500 vt 0.468750 0.187500
vt 0.500000 0.187500 vt 0.500000 0.187500
vt 0.468750 0.187500 vt 0.468750 0.187500
vt 0.500000 0.187500
vt 0.562500 0.187500
vt 0.500000 0.562500
vt 0.468750 0.562500
vt 0.500000 0.125000
vt 0.562500 0.125000
vt 0.500000 0.625000
vt 0.468750 0.625000
vt 0.468750 0.125000
vt 0.468750 0.187500
vt 0.468750 0.156250
vt 0.562500 0.625000
vt 0.562500 0.562500
s 0 s 0
f 1/1/1 2/4/1 4/9/1 3/7/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 3/7/2 4/9/2 8/14/2 7/13/2
@ -2122,10 +2096,3 @@ f 764/824/8 757/817/8 777/837/8 778/838/8
f 765/825/5 764/824/5 780/840/5 781/841/5 f 765/825/5 764/824/5 780/840/5 781/841/5
f 744/804/6 752/812/6 783/843/6 782/842/6 f 744/804/6 752/812/6 783/843/6 782/842/6
f 782/842/6 783/843/6 785/845/6 784/844/6 f 782/842/6 783/843/6 785/845/6 784/844/6
f 776/836/10 774/834/10 788/848/10 789/849/10
f 748/808/8 744/804/8 786/846/8 787/847/8
f 777/837/8 779/839/8 793/853/8 792/852/8
f 739/797/10 746/806/10 791/851/10 790/850/10
f 750/810/6 753/813/6 796/856/6 794/854/6
f 753/813/6 752/812/6 795/855/6 796/856/6
f 781/841/5 780/840/5 797/857/5 798/858/5

View File

@ -42,6 +42,9 @@ in vec3 spotlightDirTS;
in vec3 sunDirTS; in vec3 sunDirTS;
in vec4 sunSpacePos;
in vec3 test; in vec3 test;
float DistributionGGX(vec3 normal, vec3 H, float roughness){ float DistributionGGX(vec3 normal, vec3 H, float roughness){
@ -104,6 +107,16 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){
return (kD * color / PI + specular) * radiance * NdotL; return (kD * color / PI + specular) * radiance * NdotL;
} }
float calculateShadow() {
vec4 sunSpacePosNormalized = (0.5 * sunSpacePos / (sunSpacePos.w)) + 0.5;
float closestDepth = texture2D(depthMap, sunSpacePosNormalized.xy).x;//r?
float diff = (0.001+closestDepth) - sunSpacePosNormalized.z;//sunSpacePosNormalized.z;
return (0.5*(diff)/abs(diff))+0.5;
}
void main() void main()
{ {
@ -141,7 +154,7 @@ void main()
//ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir); //ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
//sun //sun
ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir); ilumination=ilumination+PBRLight(sunDir,sunColor * calculateShadow(),normal,viewDir);
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1); outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);

View File

@ -12,6 +12,8 @@ uniform mat4 modelMatrix;
out vec3 vecNormal; out vec3 vecNormal;
out vec3 worldPos; out vec3 worldPos;
uniform mat4 LightVP;
uniform vec3 lightPos; uniform vec3 lightPos;
uniform vec3 lightPos2; uniform vec3 lightPos2;
uniform vec3 lightPos3; uniform vec3 lightPos3;
@ -28,6 +30,8 @@ out vec3 sunDirTS;
out vec3 lightDirTS2; out vec3 lightDirTS2;
out vec3 lightDirTS3; out vec3 lightDirTS3;
out vec4 sunSpacePos;
void main() void main()
{ {
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz; worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
@ -50,4 +54,6 @@ void main()
spotlightDirTS = TBN*SL; spotlightDirTS = TBN*SL;
sunDirTS = TBN*sunDir; sunDirTS = TBN*sunDir;
sunSpacePos=LightVP*modelMatrix*vec4(vertexPosition,1);
} }

View File

@ -44,6 +44,9 @@ in vec3 spotlightDirTS;
in vec3 sunDirTS; in vec3 sunDirTS;
in vec4 sunSpacePos;
in vec3 test; in vec3 test;
float DistributionGGX(vec3 normal, vec3 H, float roughness){ float DistributionGGX(vec3 normal, vec3 H, float roughness){
@ -106,6 +109,16 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){
return (kD * texture2D(colorTexture, vecTex).xyz / PI + specular) * radiance * NdotL; return (kD * texture2D(colorTexture, vecTex).xyz / PI + specular) * radiance * NdotL;
} }
float calculateShadow() {
vec4 sunSpacePosNormalized = (0.5 * sunSpacePos / (sunSpacePos.w)) + 0.5;
float closestDepth = texture2D(depthMap, sunSpacePosNormalized.xy).x;//r?
float diff = (0.001+closestDepth) - sunSpacePosNormalized.z;//sunSpacePosNormalized.z;
return (0.5*(diff)/abs(diff))+0.5;
}
void main() void main()
{ {
@ -143,7 +156,7 @@ void main()
//ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir); //ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
//sun //sun
ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir); ilumination=ilumination+PBRLight(sunDir,sunColor * calculateShadow(),normal,viewDir);
//outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1); //outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);

View File

@ -10,6 +10,10 @@ uniform mat4 transformation;
uniform mat4 modelMatrix; uniform mat4 modelMatrix;
uniform float size; uniform float size;
uniform mat4 LightVP;
out vec3 vecNormal; out vec3 vecNormal;
out vec3 worldPos; out vec3 worldPos;
out vec2 vecTex; out vec2 vecTex;
@ -30,6 +34,8 @@ out vec3 sunDirTS;
out vec3 lightDirTS2; out vec3 lightDirTS2;
out vec3 lightDirTS3; out vec3 lightDirTS3;
out vec4 sunSpacePos;
void main() void main()
{ {
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz; worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
@ -52,11 +58,16 @@ void main()
spotlightDirTS = TBN*SL; spotlightDirTS = TBN*SL;
sunDirTS = TBN*sunDir; sunDirTS = TBN*sunDir;
if(size == 5){ if(size == 5){
vecTex = vertexTexCoord * vec2(10,10); vecTex = vertexTexCoord * vec2(15,15);
vecTex.y = 1.0 - vecTex.y;
}
else if(size == 10){
vecTex = vertexTexCoord * vec2(150,150);
vecTex.y = 1.0 - vecTex.y; vecTex.y = 1.0 - vecTex.y;
} }
else{ else{
vecTex = vertexTexCoord; vecTex = vertexTexCoord;
vecTex.y = 1.0 - vecTex.y; vecTex.y = 1.0 - vecTex.y;
} }
sunSpacePos=LightVP*modelMatrix*vec4(vertexPosition,1);
} }

View File

@ -55,12 +55,15 @@ namespace models {
Core::RenderContext door_next_toContext; Core::RenderContext door_next_toContext;
Core::RenderContext door_next_to_doorhandleContext; Core::RenderContext door_next_to_doorhandleContext;
Core::RenderContext aquariumContext;
} }
namespace texture { namespace texture {
GLuint floorTexture; GLuint floorTexture;
GLuint roomTexture; GLuint roomTexture;
GLuint fishTexture; GLuint fishTexture;
GLuint fishRedTexture;
GLuint sofaTexture; GLuint sofaTexture;
GLuint sofaBaseTexture; GLuint sofaBaseTexture;
GLuint door1Texture; GLuint door1Texture;
@ -72,6 +75,8 @@ namespace texture {
GLuint roofTexture; GLuint roofTexture;
GLuint door_next_toTexture; GLuint door_next_toTexture;
GLuint door_next_to_doorhandleTexture; GLuint door_next_to_doorhandleTexture;
GLuint aquariumTexture;
GLuint spaceshipTexture;
} }
GLuint depthMapFBO; GLuint depthMapFBO;
@ -90,15 +95,16 @@ Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext; Core::RenderContext shipContext;
Core::RenderContext sphereContext; Core::RenderContext sphereContext;
glm::vec3 sunPos = glm::vec3(0.f, 0.f, 0.f); //glm::vec3 sunPos = glm::vec3(-4.740971f, 1.149999f, 0.369280f);
glm::vec3 sunDir = glm::vec3(0.f, 4.f, 0.f); glm::vec3 sunPos = glm::vec3(-9.5, 4, -5);
glm::vec3 sunColor = glm::vec3(0.9f, 0.6f, 0.7f) * 0.15; glm::vec3 sunDir = glm::vec3(-1.93633f, 0.351106, -1.003226f);
glm::vec3 sunColor = glm::vec3(0.9f, 0.6f, 0.7f) * 1.15;
glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f); glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f);
glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f); glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f);
glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f); glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.0f);
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f); glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
GLuint VAO,VBO; GLuint VAO,VBO;
@ -107,16 +113,16 @@ float aspectRatio = 1.f;
float exposition = 1.f; float exposition = 1.f;
glm::vec3 lampColor = glm::vec3(0.9f, 0.6f, 0.7f) * 5; glm::vec3 lampColor = glm::vec3(0.9f, 0.6f, 0.7f) * 5;
glm::vec3 lampColor2 = glm::vec3(1.0f, 0.2f, 0.2f) * 5; glm::vec3 lampColor2 = glm::vec3(0, 0, 1) * 5;
glm::vec3 lampColor3 = glm::vec3(1.0f, 0.2f, 0.2f) * 5; glm::vec3 lampColor3 = glm::vec3(0, 0, 1) * 5;
glm::vec3 pointlightPos = glm::vec3(-3.5, 2.8, 0); glm::vec3 pointlightPos = glm::vec3(-300.5, 2.8, -0.0001);
glm::vec3 pointlightPos2 = glm::vec3(4.5, 2.8, 3); glm::vec3 pointlightPos2 = glm::vec3(4.5, 2.8, 3);
glm::vec3 pointlightPos3 = glm::vec3(4.5, 2.8, -2.99); glm::vec3 pointlightPos3 = glm::vec3(4.5, 2.8, -2.99);
glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6) * 30; glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6) * 30;
glm::vec3 pointlightColor2 = glm::vec3(1, 0.2, 0.2) * 20; glm::vec3 pointlightColor2 = glm::vec3(0, 0.2, 1) * 20;
glm::vec3 pointlightColor3 = glm::vec3(1, 0.2, 0.2) * 20; glm::vec3 pointlightColor3 = glm::vec3(0, 0.2, 1) * 20;
glm::vec3 spotlightPos = glm::vec3(0, 0, 0); glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
@ -265,6 +271,14 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
glUniform3f(glGetUniformLocation(program, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z); glUniform3f(glGetUniformLocation(program, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z);
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);
//For shadows
glm::mat4 lightVP = glm::ortho(-10.f, 10.f, -10.f, 10.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::DrawContext(context); Core::DrawContext(context);
} }
@ -278,10 +292,8 @@ void drawObjectPBRWithTexture(Core::RenderContext& context, glm::mat4 modelMatri
glUniform1f(glGetUniformLocation(programTex, "size"), size); glUniform1f(glGetUniformLocation(programTex, "size"), size);
/*glm::mat4 transformation = modelMatrix;*/
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix); glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
//glUniform3f(glGetUniformLocation(programTex, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
glUniform1f(glGetUniformLocation(programTex, "exposition"), exposition); glUniform1f(glGetUniformLocation(programTex, "exposition"), exposition);
@ -310,7 +322,7 @@ void drawObjectPBRWithTexture(Core::RenderContext& context, glm::mat4 modelMatri
glUniform1f(glGetUniformLocation(programTex, "spotlightPhi"), spotlightPhi); glUniform1f(glGetUniformLocation(programTex, "spotlightPhi"), spotlightPhi);
//For shadows //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)); glm::mat4 lightVP = glm::ortho(-10.f, 10.f, -10.f, 10.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
glUniformMatrix4fv(glGetUniformLocation(programTex, "LightVP"), 1, GL_FALSE, (float*)&lightVP); glUniformMatrix4fv(glGetUniformLocation(programTex, "LightVP"), 1, GL_FALSE, (float*)&lightVP);
glUniform1i(glGetUniformLocation(programTex, "depthMap"), 2); glUniform1i(glGetUniformLocation(programTex, "depthMap"), 2);
glActiveTexture(GL_TEXTURE0 + 2); glActiveTexture(GL_TEXTURE0 + 2);
@ -344,7 +356,27 @@ void renderShadowapSun(GLuint depthMapFBO, glm::mat4 lightVP) {
//ustawianie programu //ustawianie programu
glUseProgram(programDepth); glUseProgram(programDepth);
drawObjectDepth(models::sofaBaseContext, lightVP, glm::mat4());
drawObjectDepth(models::sofaContext, lightVP, glm::mat4());
drawObjectDepth(models::fishContext, lightVP, glm::mat4());
drawObjectDepth(models::fish2Context, lightVP, glm::mat4());
drawObjectDepth(models::fish3Context, lightVP, glm::mat4());
drawObjectDepth(models::shelfContext, lightVP, glm::mat4());
drawObjectDepth(models::pencilsContext, lightVP, glm::mat4());
drawObjectDepth(models::aquariumContext, lightVP, glm::mat4());
drawObjectDepth(models::roofContext, lightVP, glm::mat4());
drawObjectDepth(models::landContext, lightVP, glm::mat4());
drawObjectDepth(models::floorContext, lightVP, glm::mat4());
drawObjectDepth(models::marbleBustContext, lightVP, glm::mat4());
drawObjectDepth(models::roomContext, lightVP, glm::mat4());
drawObjectDepth(models::door1Context, lightVP, glm::mat4());
drawObjectDepth(models::door2Context, lightVP, glm::mat4());
drawObjectDepth(models::door3Context, lightVP, glm::mat4());
drawObjectDepth(models::doorContext, lightVP, glm::mat4());
drawObjectDepth(models::doorhandleContext, lightVP, glm::mat4());
drawObjectDepth(models::door_next_toContext, lightVP, glm::mat4());
drawObjectDepth(models::door_next_to_doorhandleContext, lightVP, glm::mat4());
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -401,8 +433,9 @@ void renderScene(GLFWwindow* window)
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
// //
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)); glm::mat4 lightVP = glm::ortho(-10.f, 10.f, -10.f, 10.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
renderShadowapSun(depthMapFBO, lightVPSun);
renderShadowapSun(depthMapFBO, lightVP);
//space lamp //space lamp
glUseProgram(programSun); glUseProgram(programSun);
@ -439,7 +472,7 @@ void renderScene(GLFWwindow* window)
*/ */
//drawObjectPBR(models::bedContext, glm::mat4(), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f); //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); //drawObjectPBR(models::chairContext, glm::mat4(), glm::vec3(0.195239f, 0.37728f, 0.8f), 0.4f, 0.0f);
drawObjectPBR(models::deskContext, glm::mat4(), glm::vec3(0.428691f, 0.08022f, 0.036889f), 0.2f, 0.0f); 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::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::drawerContext, glm::mat4(), glm::vec3(0.428691f, 0.08022f, 0.036889f), 0.2f, 0.0f);
@ -476,12 +509,6 @@ void renderScene(GLFWwindow* window)
0.,0.,0.,1., 0.,0.,0.,1.,
}); });
drawObjectPBR(shipContext,
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)),
glm::vec3(0.3, 0.3, 0.5),
0.2, 1.0
);
if (animal_in_hand) { if (animal_in_hand) {
drawObjectPBR(sphereContext, drawObjectPBR(sphereContext,
glm::translate(spaceshipPos) * glm::translate(glm::vec3(0, 0.06f, 0)) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.05f)), glm::translate(spaceshipPos) * glm::translate(glm::vec3(0, 0.06f, 0)) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.05f)),
@ -511,14 +538,20 @@ void renderScene(GLFWwindow* window)
//draw texture with PBR //draw texture with PBR
drawObjectPBRWithTexture(shipContext,
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)),
texture::spaceshipTexture,
0.2, 1.0, 0
);
drawObjectPBRWithTexture(models::floorContext, glm::mat4(), texture::floorTexture, 0.8f, 0.0f,5); drawObjectPBRWithTexture(models::floorContext, glm::mat4(), texture::floorTexture, 0.8f, 0.0f,5);
drawObjectPBRWithTexture(models::roomContext, glm::mat4(), texture::roomTexture, 0.8f, 0.0f, 5); drawObjectPBRWithTexture(models::roomContext, glm::mat4(), texture::roomTexture, 0.8f, 0.0f, 5);
drawObjectPBRWithTexture(models::fishContext, glm::mat4(), texture::fishTexture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::fishContext, glm::mat4(), texture::fishTexture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::landContext, glm::mat4(), texture::landTexture, 0.5f, 0.0f, 5); drawObjectPBRWithTexture(models::landContext, glm::mat4(), texture::landTexture, 0.5f, 0.0f, 10);
drawObjectPBRWithTexture(models::sofaBaseContext, glm::mat4(), texture::sofaBaseTexture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::sofaBaseContext, glm::mat4(), texture::sofaBaseTexture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::sofaContext, glm::mat4(), texture::sofaTexture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::sofaContext, glm::mat4(), texture::sofaTexture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::roofContext, glm::mat4(), texture::roofTexture, 0.5f, 0.0f, 5); drawObjectPBRWithTexture(models::roofContext, glm::mat4(), texture::roofTexture, 0.8f, 0.0f, 5);
drawObjectPBRWithTexture(models::fish2Context, glm::mat4(), texture::fishTexture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::fish2Context, glm::mat4(), texture::fishRedTexture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::fish3Context, glm::mat4(), texture::fishTexture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::fish3Context, glm::mat4(), texture::fishTexture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::door1Context, glm::mat4(), texture::door1Texture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::door1Context, glm::mat4(), texture::door1Texture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::door2Context, glm::mat4(), texture::door2Texture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::door2Context, glm::mat4(), texture::door2Texture, 0.5f, 0.0f, 0);
@ -526,16 +559,21 @@ void renderScene(GLFWwindow* window)
drawObjectPBRWithTexture(models::doorhandleContext, glm::mat4(), texture::doorhandleTexture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::doorhandleContext, glm::mat4(), texture::doorhandleTexture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::door_next_toContext, glm::mat4(), texture::door_next_toTexture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::door_next_toContext, glm::mat4(), texture::door_next_toTexture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::door_next_to_doorhandleContext, glm::mat4(), texture::door_next_to_doorhandleTexture, 0.5f, 0.0f, 0); drawObjectPBRWithTexture(models::door_next_to_doorhandleContext, glm::mat4(), texture::door_next_to_doorhandleTexture, 0.5f, 0.0f, 0);
drawObjectPBRWithTexture(models::spaceshipContext, glm::mat4(), texture::spaceshipTexture, 0.5f, 0.0f, 0);
//objects with textures that contain transparency should be drawn here (last) //objects with textures that contain transparency should be drawn here (last)
drawObjectPBRWithTexture(models::glassWallContext, glm::mat4(), texture::glassWallTexture, 0.8f, 0.0f, 5); drawObjectPBRWithTexture(models::glassWallContext, glm::mat4(), texture::glassWallTexture, 0.8f, 0.0f, 5);
drawObjectPBRWithTexture(models::aquariumContext, glm::mat4(), texture::aquariumTexture, 0.8f, 0.0f, 5);
//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);
//glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D, depthMap); glBindTexture(GL_TEXTURE_2D, depthMap);
//Core::DrawContext(models::testContext); Core::DrawContext(models::testContext);*/
glUseProgram(0); glUseProgram(0);
glfwSwapBuffers(window); glfwSwapBuffers(window);
@ -565,20 +603,22 @@ void init(GLFWwindow* window)
{ {
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
initDepthMap();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
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_shadow_global_sun.vert", "shaders/shader_shadow_global_sun.frag");
//loading models //loading models
loadModelToContext("./models/sphere.obj", sphereContext); loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/spaceship.obj", shipContext); loadModelToContext("./models/fighter.obj", shipContext);
loadModelToContext("./models/Marble_Bust.obj", models::marbleBustContext); loadModelToContext("./models/Marble_Bust.obj", models::marbleBustContext);
loadModelToContext("./models/Pencils_Cylinder.obj", models::pencilsContext); loadModelToContext("./models/Pencils_Cylinder.obj", models::pencilsContext);
loadModelToContext("./models/plane.obj", models::floorContext); 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/test.obj", models::testContext); loadModelToContext("./models/test.obj", models::testContext);
@ -600,20 +640,24 @@ void init(GLFWwindow* window)
loadModelToContext("./models/door_next_to.obj", models::door_next_toContext); loadModelToContext("./models/door_next_to.obj", models::door_next_toContext);
loadModelToContext("./models/door_next_to_doorhandle.obj", models::door_next_to_doorhandleContext); loadModelToContext("./models/door_next_to_doorhandle.obj", models::door_next_to_doorhandleContext);
loadModelToContext("./models/aquarium.obj", models::aquariumContext);
//loading textures //loading textures
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//textures that contain transparency should be loaded here //textures that contain transparency should be loaded here
texture::glassWallTexture = Core::LoadTexture("textures/glass.png"); texture::glassWallTexture = Core::LoadTexture("textures/glass.png");
texture::aquariumTexture = Core::LoadTexture("textures/glass.png");
glDisable(GL_BLEND); glDisable(GL_BLEND);
programTex = shaderLoader.CreateProgram("shaders/shader_texture.vert", "shaders/shader_texture.frag"); programTex = shaderLoader.CreateProgram("shaders/shader_texture.vert", "shaders/shader_texture.frag");
texture::glassWallTexture = Core::LoadTexture("textures/glass.jpg"); //texture::glassWallTexture = Core::LoadTexture("textures/glass.jpg");
texture::fishTexture = Core::LoadTexture("textures/fish.png"); texture::fishTexture = Core::LoadTexture("textures/fish.png");
texture::fishRedTexture = Core::LoadTexture("textures/fish_red.png");
texture::roomTexture = Core::LoadTexture("textures/roof.jpg"); texture::roomTexture = Core::LoadTexture("textures/roof.jpg");
texture::sofaBaseTexture = Core::LoadTexture("textures/sofa.jpg"); texture::sofaBaseTexture = Core::LoadTexture("textures/sofaa.jpg");
texture::sofaTexture = Core::LoadTexture("textures/sofa.jpg"); texture::sofaTexture = Core::LoadTexture("textures/sofaa.jpg");
texture::landTexture = Core::LoadTexture("textures/grass.jpg"); texture::landTexture = Core::LoadTexture("textures/grass.jpg");
texture::floorTexture = Core::LoadTexture("textures/floor.png"); texture::floorTexture = Core::LoadTexture("textures/floor3.jpg");
texture::roofTexture = Core::LoadTexture("textures/roof.jpg"); texture::roofTexture = Core::LoadTexture("textures/roof.jpg");
texture::door1Texture = Core::LoadTexture("textures/Door.jpg"); texture::door1Texture = Core::LoadTexture("textures/Door.jpg");
texture::door2Texture = Core::LoadTexture("textures/Door.jpg"); texture::door2Texture = Core::LoadTexture("textures/Door.jpg");
@ -621,6 +665,7 @@ void init(GLFWwindow* window)
texture::doorhandleTexture = Core::LoadTexture("textures/Door.jpg"); texture::doorhandleTexture = Core::LoadTexture("textures/Door.jpg");
texture::door_next_toTexture = Core::LoadTexture("textures/Door.jpg"); texture::door_next_toTexture = Core::LoadTexture("textures/Door.jpg");
texture::door_next_to_doorhandleTexture = Core::LoadTexture("textures/Door.jpg"); texture::door_next_to_doorhandleTexture = Core::LoadTexture("textures/Door.jpg");
texture::spaceshipTexture = Core::LoadTexture("textures/spaceship.png");
// //
//prepering skybox //prepering skybox

BIN
cw 9/textures/fish_red.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 KiB

BIN
cw 9/textures/sofaa.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 KiB

BIN
cw 9/textures/spaceship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB