Simplifing object render method by givin the skydome day texture it's own texture unit.

This commit is contained in:
Faerbit 2015-04-12 21:06:59 +02:00
parent 9b57eb0df1
commit 93f790ec22
10 changed files with 43 additions and 40 deletions

View File

@ -6,7 +6,7 @@ in vec4 sunPosition;
out vec4 oColor; out vec4 oColor;
uniform sampler2D uTexture; uniform sampler2D dayTexture;
uniform sampler2D nightTexture; uniform sampler2D nightTexture;
uniform float farPlane; uniform float farPlane;
uniform vec4 fogColorDay; uniform vec4 fogColorDay;
@ -67,7 +67,7 @@ vec3 sunColorFunc(float dot) {
void main() { void main() {
vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0); vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0);
float sunAngle = -dot(normalize(directionalVector), vec3(0.0, 1.0, 0.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) { if (sunAngle >= 0.0) {
textureColor = mix(dayColor, texture(nightTexture, vTexCoord), sunAngle); textureColor = mix(dayColor, texture(nightTexture, vTexCoord), sunAngle);
} }

View File

@ -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<glm::mat4>* additionalMatrices) { glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices) {
for(unsigned int i = 0; i<objects.size(); i++) { for(unsigned int i = 0; i<objects.size(); i++) {
objects.at(i)->render(shader, lightingPass, texturePass, viewProjcetionMatrix, additionalMatrices); objects.at(i)->render(shader, lightingPass, viewProjcetionMatrix, additionalMatrices);
} }
} }

View File

@ -9,7 +9,7 @@ class Chunk {
public: public:
Chunk(); Chunk();
~Chunk(); ~Chunk();
void render(SharedShaderProgram shader, bool lightingPass, bool texturePass, void render(SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices=0); glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices=0);
void addObject(Object* object); void addObject(Object* object);
void sortObjects(int textureCount); void sortObjects(int textureCount);

View File

@ -241,12 +241,13 @@ void Graphics::bindTextureUnits(){
flamePostShader->setTexture("light_fbo", light_fbo_color_texture, textureCount + 15); flamePostShader->setTexture("light_fbo", light_fbo_color_texture, textureCount + 15);
skydomeShader->use(); 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->use();
loadingShader->setTexture("screen", loadingScreen, textureCount + 17); loadingShader->setTexture("screen", loadingScreen, textureCount + 18);
loadingShader->setTexture("screenContinue", loadingContinueScreen, textureCount + 18); loadingShader->setTexture("screenContinue", loadingContinueScreen, textureCount + 19);
printf("This application used %d texture units.\n", textureCount + 18); printf("This application used %d texture units.\n", textureCount + 19);
} }
void Graphics::renderLoadingScreen() { void Graphics::renderLoadingScreen() {
@ -437,7 +438,7 @@ void Graphics::render(double time)
// set fog Parameters // set fog Parameters
skydomeShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition()); skydomeShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition());
skydomeShader->setUniform("directionalVector", level->getDirectionalLight()->getPosition()); skydomeShader->setUniform("directionalVector", level->getDirectionalLight()->getPosition());
level->getSkydome()->render(skydomeShader, false, true, &lightingViewProjectionMatrix); level->getSkydome()->render(skydomeShader, false, &lightingViewProjectionMatrix);
lightingShader->use(); lightingShader->use();
@ -492,7 +493,7 @@ void Graphics::render(double time)
lightingShader->setUniform("shininess", material->getShininess()); lightingShader->setUniform("shininess", material->getShininess());
} }
for(unsigned int k = 0; k<renderQueue.at(j)->at(i).size(); k++) { for(unsigned int k = 0; k<renderQueue.at(j)->at(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("diffuseFactor", material->getDiffuseFactor());
lightingShader->setUniform("specularFactor", material->getSpecularFactor()); lightingShader->setUniform("specularFactor", material->getSpecularFactor());
lightingShader->setUniform("shininess", material->getShininess()); lightingShader->setUniform("shininess", material->getShininess());
level->getWaterPlane()->render(lightingShader, true, false, &lightingViewProjectionMatrix, &depthBiasVPs); level->getWaterPlane()->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
} }
renderQueue.clear(); renderQueue.clear();
} }

View File

@ -220,19 +220,19 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
for(unsigned int i = xStart; i<=xEnd; i++) { for(unsigned int i = xStart; i<=xEnd; i++) {
for(unsigned int j = zStart; j<=zEnd; j++) { for(unsigned int j = zStart; j<=zEnd; j++) {
if (lightingPass) { if (lightingPass) {
chunks.at(i).at(j).render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); chunks.at(i).at(j).render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
} }
else { 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; i<crossChunkObjects.size(); i++) { for (unsigned int i = 0; i<crossChunkObjects.size(); i++) {
if (lightingPass) { if (lightingPass) {
crossChunkObjects.at(i)->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); crossChunkObjects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
} }
else { else {
crossChunkObjects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs); crossChunkObjects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
} }
} }
} }

View File

@ -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; std::cout << "The texture file " << skydomeTexturePath << " does not exist." << std::endl;
exit(-1); exit(-1);
} }
Material skydomeMaterial = Material(skydomeTexture, 1.0f, 0.0f, 0.0f, 0.0f);
std::string nightTexture = queryString(skydomeElement, "nightTexture"); std::string nightTexture = queryString(skydomeElement, "nightTexture");
std::string nightTexturePath = "../" + globalTexturePath + nightTexture; std::string nightTexturePath = "../" + globalTexturePath + nightTexture;
if(stat(nightTexturePath.c_str(), &buf) != 0){ if(stat(nightTexturePath.c_str(), &buf) != 0){
std::cout << "The texture file " << nightTexturePath << " does not exist." << std::endl; std::cout << "The texture file " << nightTexturePath << " does not exist." << std::endl;
exit(-1); exit(-1);
} }
Material nightMaterial = Material(nightTexture, 1.0f, 0.0f, 0.0f, 0.0f); Skydome skydomeObject = Skydome(skydomeModel, skydomeTexture, nightTexture);
Skydome skydomeObject = Skydome(skydomeModel, skydomeMaterial, nightMaterial);
level->setSkydomeObject(skydomeObject); level->setSkydomeObject(skydomeObject);
//load the waterPlane //load the waterPlane

View File

@ -14,22 +14,13 @@ Object::~Object() {
} }
void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
bool texturePass, glm::mat4* viewProjectionMatrix, glm::mat4* viewProjectionMatrix,
std::vector<glm::mat4>* additionalMatrices) { std::vector<glm::mat4>* additionalMatrices) {
if (!renderable) { if (!renderable) {
return; return;
} }
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale())); glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale()));
if(texturePass) { shader->setUniform("modelMatrix", modelMatrix);
if (material.isMoving()) {
shader->setUniform("movingTexture", true);
}
else {
shader->setUniform("movingTexture", false);
}
shader->setUniform("uTexture", material.getTextureUnit());
shader->setUniform("modelMatrix", modelMatrix);
}
if (lightingPass) { if (lightingPass) {
// set model matrix // set model matrix
shader->setUniform("modelMatrix", modelMatrix); shader->setUniform("modelMatrix", modelMatrix);

View File

@ -16,7 +16,7 @@ class Object : public Entity {
Object(); Object();
~Object(); ~Object();
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
bool texturePass, glm::mat4* viewProjcetionMatrix, glm::mat4* viewProjcetionMatrix,
std::vector<glm::mat4>* additionalMatrices=0); std::vector<glm::mat4>* additionalMatrices=0);
Material* getMaterial(); Material* getMaterial();
private: private:

View File

@ -1,13 +1,19 @@
#include "skydome.hh" #include "skydome.hh"
#include <ACGL/OpenGL/Creator/Texture2DCreator.hh>
Skydome::Skydome(Model model, Material material, Material 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){ Object(model, Material(), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), true) {
this->nightTexture = nightTexture; this->dayTexture = Texture2DFileManager::the()->get(Texture2DCreator(dayTexturePath));
this->nightTexture = Texture2DFileManager::the()->get(Texture2DCreator(nightTexturePath));
} }
Skydome::Skydome() { Skydome::Skydome() {
} }
Material* Skydome::getNightTexture() { SharedTexture2D Skydome::getDayTexture() {
return &nightTexture; return dayTexture;
}
SharedTexture2D Skydome::getNightTexture() {
return nightTexture;
} }

View File

@ -1,11 +1,18 @@
#pragma once #pragma once
#include "object.hh" #include "object.hh"
#include <ACGL/OpenGL/Objects.hh>
class Skydome : public Object { using namespace ACGL::OpenGL;
using namespace std;
class Skydome : public Object{
public: public:
Skydome(Model model, Material material, Material nightTexture); Skydome(Model model, string dayTexturePath, string nightTexturePath);
Skydome(); Skydome();
Material* getNightTexture(); SharedTexture2D getNightTexture();
SharedTexture2D getDayTexture();
private: private:
Material nightTexture; SharedTexture2D nightTexture;
SharedTexture2D dayTexture;
}; };