diff --git a/cw 9/grk-cw9.vcxproj b/cw 9/grk-cw9.vcxproj index 4b5b08b..7e6a998 100644 --- a/cw 9/grk-cw9.vcxproj +++ b/cw 9/grk-cw9.vcxproj @@ -57,7 +57,7 @@ {5BACD057-4B83-4CB6-A367-40A10BCE2149} Win32Proj grk-cw9 - 10.0.22000.0 + 10.0.19041.0 grk-cw9 diff --git a/cw 9/shaders/shader_9_1.frag b/cw 9/shaders/shader_9_1.frag index 4ce481b..31d434c 100644 --- a/cw 9/shaders/shader_9_1.frag +++ b/cw 9/shaders/shader_9_1.frag @@ -107,17 +107,18 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){ return (kD * color / PI + specular) * radiance * NdotL; } +// code with chatGPT help float calculateShadow() { vec4 sunSpacePosNormalized = (0.5 * sunSpacePos / (sunSpacePos.w)) + 0.5; - float closestDepth = texture2D(depthMap, sunSpacePosNormalized.xy).x;//r? + float closestDepth = texture2D(depthMap, sunSpacePosNormalized.xy).x; - float diff = (0.001+closestDepth) - sunSpacePosNormalized.z;//sunSpacePosNormalized.z; + float diff = (0.001+closestDepth) - sunSpacePosNormalized.z; return (0.5*(diff)/abs(diff))+0.5; } - +// void main() { //vec3 normal = vec3(0,0,1); diff --git a/cw 9/shaders/shader_texture.frag b/cw 9/shaders/shader_texture.frag index 0958b8f..b58aeea 100644 --- a/cw 9/shaders/shader_texture.frag +++ b/cw 9/shaders/shader_texture.frag @@ -109,16 +109,19 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){ return (kD * texture2D(colorTexture, vecTex).xyz / PI + specular) * radiance * NdotL; } + +// code with chatGPT help float calculateShadow() { vec4 sunSpacePosNormalized = (0.5 * sunSpacePos / (sunSpacePos.w)) + 0.5; - float closestDepth = texture2D(depthMap, sunSpacePosNormalized.xy).x;//r? + float closestDepth = texture2D(depthMap, sunSpacePosNormalized.xy).x; - float diff = (0.001+closestDepth) - sunSpacePosNormalized.z;//sunSpacePosNormalized.z; + float diff = (0.001+closestDepth) - sunSpacePosNormalized.z; return (0.5*(diff)/abs(diff))+0.5; } +// void main() { diff --git a/cw 9/shaders/shader_texture.vert b/cw 9/shaders/shader_texture.vert index b3ef5c2..717f39f 100644 --- a/cw 9/shaders/shader_texture.vert +++ b/cw 9/shaders/shader_texture.vert @@ -58,7 +58,9 @@ void main() spotlightDirTS = TBN*SL; sunDirTS = TBN*sunDir; if(size == 5){ + // code with chatGPT help vecTex = vertexTexCoord * vec2(15,15); + // vecTex.y = 1.0 - vecTex.y; } else if(size == 7){ diff --git a/cw 9/src/ex_9_1.hpp b/cw 9/src/ex_9_1.hpp index c00e657..3988166 100644 --- a/cw 9/src/ex_9_1.hpp +++ b/cw 9/src/ex_9_1.hpp @@ -31,7 +31,7 @@ const float ALIGNMENT_WEIGHT = 1.0f; const float COHESION_WEIGHT = 1.0f; //const unsigned int SHADOW_WIDTH = 16384, SHADOW_HEIGHT = 16384; -const unsigned int SHADOW_WIDTH = 2048, SHADOW_HEIGHT = 2048; +const unsigned int SHADOW_WIDTH = 8192, SHADOW_HEIGHT = 8192; int WIDTH = 500, HEIGHT = 500; @@ -313,7 +313,7 @@ void Terraingen() { } - +// code with chatGPT help //A function to write terrain into a file void WriteOBJ(const std::string& GeneratedTerrain) { // Open the output file @@ -345,7 +345,7 @@ void WriteOBJ(const std::string& GeneratedTerrain) { // Close the output file outFile.close(); } - +// @@ -573,7 +573,7 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z); glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi); - //For shadows + // code with chatGPT help 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); @@ -622,7 +622,7 @@ void drawObjectPBRWithTexture(Core::RenderContext& context, glm::mat4 modelMatri glUniform3f(glGetUniformLocation(programTex, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z); glUniform1f(glGetUniformLocation(programTex, "spotlightPhi"), spotlightPhi); - //For shadows + // code with chatGPT help 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); glUniform1i(glGetUniformLocation(programTex, "depthMap"), 2); @@ -792,9 +792,9 @@ void renderScene(GLFWwindow* window) glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); // - + // code with chatGPT help 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, lightVP); //space lamp @@ -854,7 +854,7 @@ void renderScene(GLFWwindow* window) //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::ProcedurallyGT, glm::mat4(), glm::vec3(0.2f, 0.6f, 1.0f), 0.5f, 0.0f); + drawObjectPBR(models::ProcedurallyGT, glm::mat4(), glm::vec3(1.0f, 1.0f, 0.6f), 0.5f, 0.0f); //drawObjectPBR(models::landContext, glm::mat4(), glm::vec3(0.5f, 0.5f, 0.1f), 0.5f, 0.0f); //drawObjectPBR(models::fishContext, glm::mat4(), glm::vec3(0.7f, 0.2f, 0.1f), 0.5f, 0.0f); @@ -1047,47 +1047,68 @@ void init(GLFWwindow* window) 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); + //model created manually loadModelToContext("./models/fighter.obj", shipContext); loadModelToContext("./models/Marble_Bust.obj", models::marbleBustContext); loadModelToContext("./models/Pencils_Cylinder.obj", models::pencilsContext); + //model created manually loadModelToContext("./models/plane.obj", models::floorContext); + //model created manually loadModelToContext("./models/room.obj", models::roomContext); //loadModelToContext("./models/spaceship.obj", models::spaceshipContext); + //model created manually loadModelToContext("./models/sphere.obj", models::sphereContext); + //model created manually loadModelToContext("./models/test.obj", models::testContext); + //The model is created by modifying the another model loadModelToContext("./models/Sofa_baseCube.obj", models::sofaContext); + //The model is created by modifying the another model 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/DoorCircle.obj", models::doorhandleContext); + //The model is created by modifying the another model loadModelToContext("./models/Shelf.obj", models::shelfContext); loadModelToContext("./models/fish.obj", models::fishContext); loadModelToContext("./models/fish2.obj", models::fish2Context); loadModelToContext("./models/fish3.obj", models::fish3Context); + //model created manually loadModelToContext("./models/Glass_wall.obj", models::glassWallContext); + //model created manually loadModelToContext("./models/land.obj", models::landContext); + //model created manually loadModelToContext("./models/roof.obj", models::roofContext); loadModelToContext("./models/door_next_to.obj", models::door_next_toContext); loadModelToContext("./models/door_next_to_doorhandle.obj", models::door_next_to_doorhandleContext); + //model created manually loadModelToContext("./models/aquarium.obj", models::aquariumContext); + //The model is created by modifying the another model loadModelToContext("./models/plant1.obj", models::plant1Context); + //The model is created by modifying the another model loadModelToContext("./models/plant1dirt.obj", models::plant1DirtContext); + //model created manually loadModelToContext("./models/plant1pot.obj", models::plant1PotContext); + //model created manually loadModelToContext("./models/default_terrain.obj", models::defaultTerrainContext); + //The model is created by modifying the another model loadModelToContext("./models/algae1.obj", models::algae1Context); + //The model is created by modifying the another model loadModelToContext("./models/algae2.obj", models::algae2Context); + //The model is created by modifying the another model loadModelToContext("./models/algae3.obj", models::algae3Context); + //model created manually loadModelToContext("./models/glassWindow.obj", models::glassWindowContext); + //model created manually(by generating) loadModelToContext("./models/GeneratedTerrain.obj", models::ProcedurallyGT);