Gave skydome it's own shader.
This commit is contained in:
parent
db0eda098d
commit
1ec7f05eca
18
data/shader/skydome.fsh
Normal file
18
data/shader/skydome.fsh
Normal file
@ -0,0 +1,18 @@
|
||||
#version 150
|
||||
|
||||
in vec2 vTexCoord;
|
||||
in vec4 fragPosition;
|
||||
|
||||
out vec4 oColor;
|
||||
|
||||
uniform sampler2D uTexture;
|
||||
uniform float farPlane;
|
||||
uniform vec4 fogColor;
|
||||
uniform vec3 cameraCenter;
|
||||
|
||||
void main() {
|
||||
float distanceCameraCenter = distance(cameraCenter, vec3(fragPosition));
|
||||
float fogFactor = clamp((1.0 - ((farPlane - 35.0) -distanceCameraCenter)/30.0), 0.0, 1.0);
|
||||
fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0);
|
||||
oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor);
|
||||
}
|
17
data/shader/skydome.vsh
Normal file
17
data/shader/skydome.vsh
Normal file
@ -0,0 +1,17 @@
|
||||
#version 150
|
||||
|
||||
in vec3 aPosition;
|
||||
in vec3 aNormal;
|
||||
in vec2 aTexCoord;
|
||||
|
||||
uniform mat4 modelMatrix;
|
||||
uniform mat4 modelViewProjectionMatrix;
|
||||
|
||||
out vec2 vTexCoord;
|
||||
out vec4 fragPosition;
|
||||
|
||||
void main() {
|
||||
fragPosition = modelMatrix * vec4(aPosition, 1.0);
|
||||
vTexCoord = aTexCoord;
|
||||
gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
|
||||
}
|
18
graphics.cc
18
graphics.cc
@ -69,6 +69,9 @@ void Graphics::init(Level* level) {
|
||||
// look up all shader files starting with 'phong' and build a ShaderProgram from it:
|
||||
lightingShader = ShaderProgramCreator("phong").attributeLocations(
|
||||
vao->getAttributeLocations()).create();
|
||||
|
||||
skydomeShader = ShaderProgramCreator("skydome").attributeLocations(
|
||||
vao->getAttributeLocations()).create();
|
||||
|
||||
depthShader = ShaderProgramCreator("depth")
|
||||
.attributeLocations(vao->getAttributeLocations()).create();
|
||||
@ -233,6 +236,17 @@ void Graphics::render(double time)
|
||||
// lighting render pass
|
||||
framebuffer_light->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//set view and projection matrix
|
||||
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);
|
||||
|
||||
//render skydome
|
||||
skydomeShader->use();
|
||||
// set fog Parameters
|
||||
skydomeShader->setUniform("farPlane", farPlane);
|
||||
skydomeShader->setUniform("fogColor", level->getFogColour());
|
||||
skydomeShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition());
|
||||
level->getSkydome()->render(skydomeShader, false, true, &lightingViewProjectionMatrix);
|
||||
|
||||
lightingShader->use();
|
||||
|
||||
@ -271,9 +285,6 @@ void Graphics::render(double time)
|
||||
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
||||
lightingShader->setUniform("camera", level->getPhysics()->getCameraPosition());
|
||||
|
||||
//set view and projection matrix
|
||||
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);
|
||||
|
||||
// render the level
|
||||
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
|
||||
|
||||
@ -283,7 +294,6 @@ void Graphics::render(double time)
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
|
||||
// draw with colors
|
||||
flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
|
||||
flameShader->setUniform("modelViewProjectionMatrix", lightingViewProjectionMatrix);
|
||||
|
@ -31,6 +31,7 @@ class Graphics {
|
||||
float farPlane;
|
||||
std::vector<Light> closestLights;
|
||||
SharedShaderProgram lightingShader;
|
||||
SharedShaderProgram skydomeShader;
|
||||
SharedShaderProgram depthCubeShader;
|
||||
SharedShaderProgram depthShader;
|
||||
SharedShaderProgram flameShader;
|
||||
|
12
level.cc
12
level.cc
@ -49,9 +49,11 @@ void Level::load() {
|
||||
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
|
||||
for(unsigned int i = 0; i<objects.size(); i++) {
|
||||
// do not project shadow of skydome
|
||||
if(lightingPass || (objects.at(i) != skydome)) {
|
||||
objects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
|
||||
if (lightingPass) {
|
||||
objects.at(i)->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
|
||||
}
|
||||
else {
|
||||
objects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,3 +244,7 @@ lua_State* Level::getLuaState() {
|
||||
Terrain* Level::getTerrain() {
|
||||
return &terrain;
|
||||
}
|
||||
|
||||
Object* Level::getSkydome() {
|
||||
return skydome;
|
||||
}
|
||||
|
1
level.hh
1
level.hh
@ -36,6 +36,7 @@ class Level {
|
||||
glm::vec4 getFogColour();
|
||||
void setSkydomeSize(float size);
|
||||
float getSkydomeSize();
|
||||
Object* getSkydome();
|
||||
std::vector<Object*>* getObjects();
|
||||
std::vector<Object*>* getPhysicsObjects();
|
||||
void deleteObject(int objectIndex);
|
||||
|
@ -85,7 +85,6 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
||||
Material skydomeMaterial = Material(skydomeTexture, 0.7f, 0.0f, 0.0f, 0.0f);
|
||||
Object* skydomeObject = new Object(skydomeModel, skydomeMaterial, glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f), true);
|
||||
level->addObject(skydomeObject);
|
||||
level->setSkydomeObject(skydomeObject);
|
||||
|
||||
//load lighting parameters
|
||||
|
@ -14,18 +14,22 @@ Object::~Object() {
|
||||
}
|
||||
|
||||
void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* additionalMatrices) {
|
||||
bool texturePass, 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) {
|
||||
shader->setTexture("uTexture", material.getReference(), 0);
|
||||
shader->setUniform("modelMatrix", modelMatrix);
|
||||
}
|
||||
if (lightingPass) {
|
||||
// set lightning parameters for this object
|
||||
shader->setUniform("ambientFactor", material.getAmbientFactor());
|
||||
shader->setUniform("diffuseFactor", material.getDiffuseFactor());
|
||||
shader->setUniform("specularFactor", material.getSpecularFactor());
|
||||
shader->setUniform("shininess", material.getShininess());
|
||||
shader->setTexture("uTexture", material.getReference(), 0);
|
||||
// set model matrix
|
||||
shader->setUniform("modelMatrix", modelMatrix);
|
||||
// set shadowMVPs
|
||||
|
@ -16,7 +16,8 @@ class Object : public Entity {
|
||||
Object();
|
||||
~Object();
|
||||
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices);
|
||||
bool texturePass, glm::mat4* viewProjcetionMatrix,
|
||||
std::vector<glm::mat4>* additionalMatrices=0);
|
||||
private:
|
||||
Model model;
|
||||
Material material;
|
||||
|
Loading…
Reference in New Issue
Block a user