Added skybox and refined fog a bit. Fog still needs a lot of work.

This commit is contained in:
Faerbit 2014-11-21 02:38:03 +01:00
parent b74e56fe7d
commit c47ed4646d
8 changed files with 73 additions and 7 deletions

View File

@ -0,0 +1,40 @@
# Blender v2.72 (sub 0) OBJ File: 'skybox.blend'
# www.blender.org
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vt 0.250001 0.000001
vt 0.500000 0.000000
vt 0.500001 0.333336
vt 0.250001 0.333335
vt 0.499999 0.999998
vt 0.250001 0.999999
vt 0.250002 0.666669
vt 0.500000 0.666668
vt 0.749998 0.333334
vt 1.000000 0.333334
vt 1.000001 0.666666
vt 0.750005 0.666664
vt 0.000001 0.333334
vt -0.000000 0.666666
vn -0.577300 0.577300 0.577300
vn 0.577300 0.577300 0.577300
vn 0.577300 0.577300 -0.577300
vn -0.577300 0.577300 -0.577300
vn -0.577300 -0.577300 0.577300
vn -0.577300 -0.577300 -0.577300
vn 0.577300 -0.577300 -0.577300
vn 0.577300 -0.577300 0.577300
s 1
f 1/1/1 4/2/2 3/3/3 2/4/4
f 5/5/5 6/6/6 7/7/7 8/8/8
f 1/9/1 2/10/4 6/11/6 5/12/5
f 2/13/4 3/4/3 7/7/7 6/14/6
f 3/4/3 4/3/2 8/8/8 7/7/7
f 5/12/5 8/8/8 4/3/2 1/9/1

BIN
Levels/Textures/skybox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

View File

@ -21,7 +21,7 @@ uniform vec3 lightSources[128];
uniform vec3 lightColors[128];
uniform float lightIntensities[128];
uniform float fogStart;
uniform vec3 fogColor;
uniform vec4 fogColor;
void main()
{
@ -54,8 +54,9 @@ void main()
vec3 finalColor = specularColor + diffuseColor + ambientColor;
float distanceCamera = distance(camera, vec3(fragPosition));
float fogFactor = clamp((1.0 - exp(-distanceCamera+fogStart)), 0.0, 1.0);
finalColor = mix(finalColor, fogColor, fogFactor);
fogFactor = mix(fogFactor, 0.0, clamp((1.0 - exp(-fragPosition.y+20.0)), 0.0, 1.0));
vec4 texture = texture(uTexture, vTexCoord).rgba;
oColor = vec4(finalColor, 1.0f)*texture;
oColor = mix(oColor, fogColor, fogFactor);
}

View File

@ -171,3 +171,7 @@ glm::mat4 Graphics::buildViewMatrix(Level* level) {
return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()),
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
}
float Graphics::getFarPlane() {
return farPlane;
}

View File

@ -18,6 +18,7 @@ class Graphics {
bool createWindow();
GLFWwindow* getWindow();
void setWindowSize(glm::uvec2 windowSize);
float getFarPlane();
private:
void setGLFWHintsForOpenGLVersion( unsigned int _version );
glm::uvec2 windowSize;

View File

@ -5,6 +5,7 @@
Level::Level(std::string filePath){
this->filePath = filePath;
this->terrain = Terrain(filePath + "/terrain");
skyboxSize = 50.0f;
}
Level::Level() {
@ -30,6 +31,12 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
//add player to phy
this->physics.addPlayer(1.25f,0.0f,10.0f,0.0f,1.0f,0);
objects.push_back(object);
Model skyboxModel = Model("skybox.obj", skyboxSize);
Material skyboxMaterial = Material("skybox.png", 0.7f, 0.0f, 0.0f, 0.0f);
Object skyboxObject = Object(skyboxModel, skyboxMaterial, glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(skyboxObject);
//physics.addStaticGroundPlane();
@ -54,7 +61,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
//set lighting parameters
ambientLight = glm::vec3(1.0f, 1.0f, 1.0f);
fogColor = glm::vec3(0.10f, 0.14f, 0.14f);
fogColor = glm::vec4(0.10f, 0.14f, 0.14f, 1.0f);
directionalLight = Light(glm::vec3(-0.5f, 0.0f, -0.5f), glm::vec3(1.0f, 1.0f, 0.0f), 0.4f);
Light light = Light(glm::vec3(-3.0f, 7.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 5.0f);
lights.push_back(light);
@ -72,6 +79,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
glm::vec3(0.0f, 0.0f, 0.0f), shader);
objects.push_back(terrainObject);
cameraCenter = &objects[0];
skybox = &objects[1];
//addTerrainPhysic
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
@ -113,6 +121,8 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
objects[0].setPosition(physics.getPos(0));
objects[0].setRotation(physics.getRotation(0));
skybox->setPosition(glm::vec3(cameraCenter->getPosition().x,
0.0f, cameraCenter->getPosition().z));
}
glm::vec3 Level::getAmbientLight() {
@ -135,10 +145,14 @@ Light* Level::getDirectionalLight() {
return &directionalLight;
}
glm::vec3 Level::getFogColor() {
glm::vec4 Level::getFogColor() {
return fogColor;
}
glm::vec3 Level::getCameraPosition() {
return cameraCenter->getPosition() + camera.getVector();
}
void Level::setSkyboxSize(float size) {
skyboxSize = size;
}

View File

@ -24,18 +24,21 @@ class Level {
Object* getCameraCenter();
Camera* getCamera();
glm::vec3 getCameraPosition();
glm::vec3 getFogColor();
glm::vec4 getFogColor();
void setSkyboxSize(float size);
private:
std::string filePath;
std::vector<Object> objects;
std::vector<Light> lights;
glm::vec3 ambientLight;
glm::vec3 fogColor;
glm::vec4 fogColor;
Light directionalLight;
Object* cameraCenter;
Object* skybox;
Physics physics;
Camera camera;
Terrain terrain;
float skyboxSize;
};
#endif

View File

@ -17,7 +17,7 @@
#include <ACGL/Base/Settings.hh>
Application::Application() {
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f);
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 100.0f);
}
Graphics* Application::getGraphics() {
@ -34,6 +34,9 @@ ACGL::OpenGL::SharedShaderProgram Application::getShader() {
void Application::init()
{
// set Skybox size
level.setSkyboxSize((graphics.getFarPlane()-32.0f)/sqrt(2));
// define where shaders and textures can be found:
ACGL::Base::Settings::the()->setResourcePath("../");
ACGL::Base::Settings::the()->setShaderPath("Shader/");