diff --git a/data/shader/skydome.fsh b/data/shader/skydome.fsh index e8e4944..a6f20e7 100644 --- a/data/shader/skydome.fsh +++ b/data/shader/skydome.fsh @@ -6,7 +6,7 @@ in vec4 sunPosition; out vec4 oColor; -uniform sampler2D uTexture; +uniform sampler2D dayTexture; uniform sampler2D nightTexture; uniform float farPlane; uniform vec4 fogColorDay; @@ -67,7 +67,7 @@ vec3 sunColorFunc(float dot) { void main() { vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0); float sunAngle = -dot(normalize(directionalVector), vec3(0.0, 1.0, 0.0)); - vec4 dayColor = texture(uTexture, vTexCoord); + vec4 dayColor = texture(dayTexture, vTexCoord); if (sunAngle >= 0.0) { textureColor = mix(dayColor, texture(nightTexture, vTexCoord), sunAngle); } diff --git a/game/chunk.cc b/game/chunk.cc index cb57cfe..1180ceb 100644 --- a/game/chunk.cc +++ b/game/chunk.cc @@ -9,10 +9,10 @@ Chunk::~Chunk() { } } -void Chunk::render(SharedShaderProgram shader, bool lightingPass, bool texturePass, +void Chunk::render(SharedShaderProgram shader, bool lightingPass, glm::mat4* viewProjcetionMatrix, std::vector* additionalMatrices) { for(unsigned int i = 0; irender(shader, lightingPass, texturePass, viewProjcetionMatrix, additionalMatrices); + objects.at(i)->render(shader, lightingPass, viewProjcetionMatrix, additionalMatrices); } } diff --git a/game/chunk.hh b/game/chunk.hh index 8184fc2..81f11db 100644 --- a/game/chunk.hh +++ b/game/chunk.hh @@ -9,7 +9,7 @@ class Chunk { public: Chunk(); ~Chunk(); - void render(SharedShaderProgram shader, bool lightingPass, bool texturePass, + void render(SharedShaderProgram shader, bool lightingPass, glm::mat4* viewProjcetionMatrix, std::vector* additionalMatrices=0); void addObject(Object* object); void sortObjects(int textureCount); diff --git a/game/graphics.cc b/game/graphics.cc index ab458ca..a773c01 100644 --- a/game/graphics.cc +++ b/game/graphics.cc @@ -241,12 +241,13 @@ void Graphics::bindTextureUnits(){ flamePostShader->setTexture("light_fbo", light_fbo_color_texture, textureCount + 15); skydomeShader->use(); - skydomeShader->setTexture("nightTexture", level->getSkydome()->getNightTexture()->getReference(), textureCount + 16); + skydomeShader->setTexture("dayTexture", level->getSkydome()->getDayTexture(), textureCount + 16); + skydomeShader->setTexture("nightTexture", level->getSkydome()->getNightTexture(), textureCount + 17); loadingShader->use(); - loadingShader->setTexture("screen", loadingScreen, textureCount + 17); - loadingShader->setTexture("screenContinue", loadingContinueScreen, textureCount + 18); - printf("This application used %d texture units.\n", textureCount + 18); + loadingShader->setTexture("screen", loadingScreen, textureCount + 18); + loadingShader->setTexture("screenContinue", loadingContinueScreen, textureCount + 19); + printf("This application used %d texture units.\n", textureCount + 19); } void Graphics::renderLoadingScreen() { @@ -437,7 +438,7 @@ void Graphics::render(double time) // set fog Parameters skydomeShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition()); skydomeShader->setUniform("directionalVector", level->getDirectionalLight()->getPosition()); - level->getSkydome()->render(skydomeShader, false, true, &lightingViewProjectionMatrix); + level->getSkydome()->render(skydomeShader, false, &lightingViewProjectionMatrix); lightingShader->use(); @@ -492,7 +493,7 @@ void Graphics::render(double time) lightingShader->setUniform("shininess", material->getShininess()); } for(unsigned int k = 0; kat(i).size(); k++) { - renderQueue.at(j)->at(i).at(k)->render(lightingShader, true, false, &lightingViewProjectionMatrix, &depthBiasVPs); + renderQueue.at(j)->at(i).at(k)->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs); } } } @@ -511,7 +512,7 @@ void Graphics::render(double time) lightingShader->setUniform("diffuseFactor", material->getDiffuseFactor()); lightingShader->setUniform("specularFactor", material->getSpecularFactor()); lightingShader->setUniform("shininess", material->getShininess()); - level->getWaterPlane()->render(lightingShader, true, false, &lightingViewProjectionMatrix, &depthBiasVPs); + level->getWaterPlane()->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs); } renderQueue.clear(); } diff --git a/game/level.cc b/game/level.cc index 6ddeddc..4f6149d 100644 --- a/game/level.cc +++ b/game/level.cc @@ -220,19 +220,19 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, for(unsigned int i = xStart; i<=xEnd; i++) { for(unsigned int j = zStart; j<=zEnd; j++) { if (lightingPass) { - chunks.at(i).at(j).render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); + chunks.at(i).at(j).render(shader, lightingPass, viewProjectionMatrix, shadowVPs); } else { - chunks.at(i).at(j).render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs); + chunks.at(i).at(j).render(shader, lightingPass, viewProjectionMatrix, shadowVPs); } } } for (unsigned int i = 0; irender(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); + crossChunkObjects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs); } else { - crossChunkObjects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs); + crossChunkObjects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs); } } } diff --git a/game/loader.cc b/game/loader.cc index f372682..9b9d897 100644 --- a/game/loader.cc +++ b/game/loader.cc @@ -123,15 +123,13 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa std::cout << "The texture file " << skydomeTexturePath << " does not exist." << std::endl; exit(-1); } - Material skydomeMaterial = Material(skydomeTexture, 1.0f, 0.0f, 0.0f, 0.0f); std::string nightTexture = queryString(skydomeElement, "nightTexture"); std::string nightTexturePath = "../" + globalTexturePath + nightTexture; if(stat(nightTexturePath.c_str(), &buf) != 0){ std::cout << "The texture file " << nightTexturePath << " does not exist." << std::endl; exit(-1); } - Material nightMaterial = Material(nightTexture, 1.0f, 0.0f, 0.0f, 0.0f); - Skydome skydomeObject = Skydome(skydomeModel, skydomeMaterial, nightMaterial); + Skydome skydomeObject = Skydome(skydomeModel, skydomeTexture, nightTexture); level->setSkydomeObject(skydomeObject); //load the waterPlane diff --git a/game/object.cc b/game/object.cc index 721fd3e..f7a5e39 100644 --- a/game/object.cc +++ b/game/object.cc @@ -14,22 +14,13 @@ Object::~Object() { } void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, - bool texturePass, glm::mat4* viewProjectionMatrix, + glm::mat4* viewProjectionMatrix, std::vector* additionalMatrices) { if (!renderable) { return; } glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale(glm::vec3(model.getScale())); - if(texturePass) { - if (material.isMoving()) { - shader->setUniform("movingTexture", true); - } - else { - shader->setUniform("movingTexture", false); - } - shader->setUniform("uTexture", material.getTextureUnit()); - shader->setUniform("modelMatrix", modelMatrix); - } + shader->setUniform("modelMatrix", modelMatrix); if (lightingPass) { // set model matrix shader->setUniform("modelMatrix", modelMatrix); diff --git a/game/object.hh b/game/object.hh index 1b9ff59..9b8183a 100644 --- a/game/object.hh +++ b/game/object.hh @@ -16,7 +16,7 @@ class Object : public Entity { Object(); ~Object(); void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, - bool texturePass, glm::mat4* viewProjcetionMatrix, + glm::mat4* viewProjcetionMatrix, std::vector* additionalMatrices=0); Material* getMaterial(); private: diff --git a/game/skydome.cc b/game/skydome.cc index b1fc220..3e41beb 100644 --- a/game/skydome.cc +++ b/game/skydome.cc @@ -1,13 +1,19 @@ #include "skydome.hh" +#include -Skydome::Skydome(Model model, Material material, Material nightTexture) : - Object(model, material, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), true){ - this->nightTexture = nightTexture; +Skydome::Skydome(Model model, string dayTexturePath, string nightTexturePath) : + Object(model, Material(), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), true) { + this->dayTexture = Texture2DFileManager::the()->get(Texture2DCreator(dayTexturePath)); + this->nightTexture = Texture2DFileManager::the()->get(Texture2DCreator(nightTexturePath)); } Skydome::Skydome() { } -Material* Skydome::getNightTexture() { - return &nightTexture; +SharedTexture2D Skydome::getDayTexture() { + return dayTexture; +} + +SharedTexture2D Skydome::getNightTexture() { + return nightTexture; } diff --git a/game/skydome.hh b/game/skydome.hh index 3cd82b2..18fdcb2 100644 --- a/game/skydome.hh +++ b/game/skydome.hh @@ -1,11 +1,18 @@ #pragma once #include "object.hh" +#include -class Skydome : public Object { +using namespace ACGL::OpenGL; +using namespace std; + +class Skydome : public Object{ public: - Skydome(Model model, Material material, Material nightTexture); + Skydome(Model model, string dayTexturePath, string nightTexturePath); Skydome(); - Material* getNightTexture(); + SharedTexture2D getNightTexture(); + SharedTexture2D getDayTexture(); private: - Material nightTexture; + SharedTexture2D nightTexture; + SharedTexture2D dayTexture; + };