Simplifing object render method by givin the skydome day texture it's own texture unit.
This commit is contained in:
parent
9b57eb0df1
commit
93f790ec22
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<glm::mat4>* additionalMatrices=0);
|
||||
void addObject(Object* object);
|
||||
void sortObjects(int textureCount);
|
||||
|
@ -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; 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("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();
|
||||
}
|
||||
|
@ -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; i<crossChunkObjects.size(); i++) {
|
||||
if (lightingPass) {
|
||||
crossChunkObjects.at(i)->render(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<glm::mat4>* additionalMatrices) {
|
||||
if (!renderable) {
|
||||
return;
|
||||
}
|
||||
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(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);
|
||||
}
|
||||
if (lightingPass) {
|
||||
// set model matrix
|
||||
shader->setUniform("modelMatrix", modelMatrix);
|
||||
|
@ -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<glm::mat4>* additionalMatrices=0);
|
||||
Material* getMaterial();
|
||||
private:
|
||||
|
@ -1,13 +1,19 @@
|
||||
#include "skydome.hh"
|
||||
#include <ACGL/OpenGL/Creator/Texture2DCreator.hh>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,11 +1,18 @@
|
||||
#pragma once
|
||||
#include "object.hh"
|
||||
#include <ACGL/OpenGL/Objects.hh>
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user