Added skybox and refined fog a bit. Fog still needs a lot of work.
This commit is contained in:
parent
b74e56fe7d
commit
c47ed4646d
40
Levels/Geometry/skybox.obj
Normal file
40
Levels/Geometry/skybox.obj
Normal 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
BIN
Levels/Textures/skybox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 MiB |
@ -21,7 +21,7 @@ uniform vec3 lightSources[128];
|
|||||||
uniform vec3 lightColors[128];
|
uniform vec3 lightColors[128];
|
||||||
uniform float lightIntensities[128];
|
uniform float lightIntensities[128];
|
||||||
uniform float fogStart;
|
uniform float fogStart;
|
||||||
uniform vec3 fogColor;
|
uniform vec4 fogColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@ -54,8 +54,9 @@ void main()
|
|||||||
vec3 finalColor = specularColor + diffuseColor + ambientColor;
|
vec3 finalColor = specularColor + diffuseColor + ambientColor;
|
||||||
float distanceCamera = distance(camera, vec3(fragPosition));
|
float distanceCamera = distance(camera, vec3(fragPosition));
|
||||||
float fogFactor = clamp((1.0 - exp(-distanceCamera+fogStart)), 0.0, 1.0);
|
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;
|
vec4 texture = texture(uTexture, vTexCoord).rgba;
|
||||||
oColor = vec4(finalColor, 1.0f)*texture;
|
oColor = vec4(finalColor, 1.0f)*texture;
|
||||||
|
oColor = mix(oColor, fogColor, fogFactor);
|
||||||
}
|
}
|
||||||
|
@ -171,3 +171,7 @@ glm::mat4 Graphics::buildViewMatrix(Level* level) {
|
|||||||
return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()),
|
return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()),
|
||||||
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Graphics::getFarPlane() {
|
||||||
|
return farPlane;
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ class Graphics {
|
|||||||
bool createWindow();
|
bool createWindow();
|
||||||
GLFWwindow* getWindow();
|
GLFWwindow* getWindow();
|
||||||
void setWindowSize(glm::uvec2 windowSize);
|
void setWindowSize(glm::uvec2 windowSize);
|
||||||
|
float getFarPlane();
|
||||||
private:
|
private:
|
||||||
void setGLFWHintsForOpenGLVersion( unsigned int _version );
|
void setGLFWHintsForOpenGLVersion( unsigned int _version );
|
||||||
glm::uvec2 windowSize;
|
glm::uvec2 windowSize;
|
||||||
|
18
level.cc
18
level.cc
@ -5,6 +5,7 @@
|
|||||||
Level::Level(std::string filePath){
|
Level::Level(std::string filePath){
|
||||||
this->filePath = filePath;
|
this->filePath = filePath;
|
||||||
this->terrain = Terrain(filePath + "/terrain");
|
this->terrain = Terrain(filePath + "/terrain");
|
||||||
|
skyboxSize = 50.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Level::Level() {
|
Level::Level() {
|
||||||
@ -31,6 +32,12 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
this->physics.addPlayer(1.25f,0.0f,10.0f,0.0f,1.0f,0);
|
this->physics.addPlayer(1.25f,0.0f,10.0f,0.0f,1.0f,0);
|
||||||
objects.push_back(object);
|
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();
|
//physics.addStaticGroundPlane();
|
||||||
|
|
||||||
Model torchModel = Model("torch.obj", 0.75f);
|
Model torchModel = Model("torch.obj", 0.75f);
|
||||||
@ -54,7 +61,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
|
|
||||||
//set lighting parameters
|
//set lighting parameters
|
||||||
ambientLight = glm::vec3(1.0f, 1.0f, 1.0f);
|
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);
|
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);
|
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);
|
lights.push_back(light);
|
||||||
@ -72,6 +79,7 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
objects.push_back(terrainObject);
|
objects.push_back(terrainObject);
|
||||||
cameraCenter = &objects[0];
|
cameraCenter = &objects[0];
|
||||||
|
skybox = &objects[1];
|
||||||
|
|
||||||
//addTerrainPhysic
|
//addTerrainPhysic
|
||||||
physics.addTerrain(terrain.getHeightmapWidth(), terrain.getHeightmapHeight(), terrain.getHeightmap());
|
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].setPosition(physics.getPos(0));
|
||||||
objects[0].setRotation(physics.getRotation(0));
|
objects[0].setRotation(physics.getRotation(0));
|
||||||
|
skybox->setPosition(glm::vec3(cameraCenter->getPosition().x,
|
||||||
|
0.0f, cameraCenter->getPosition().z));
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Level::getAmbientLight() {
|
glm::vec3 Level::getAmbientLight() {
|
||||||
@ -135,10 +145,14 @@ Light* Level::getDirectionalLight() {
|
|||||||
return &directionalLight;
|
return &directionalLight;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Level::getFogColor() {
|
glm::vec4 Level::getFogColor() {
|
||||||
return fogColor;
|
return fogColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Level::getCameraPosition() {
|
glm::vec3 Level::getCameraPosition() {
|
||||||
return cameraCenter->getPosition() + camera.getVector();
|
return cameraCenter->getPosition() + camera.getVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Level::setSkyboxSize(float size) {
|
||||||
|
skyboxSize = size;
|
||||||
|
}
|
||||||
|
7
level.hh
7
level.hh
@ -24,18 +24,21 @@ class Level {
|
|||||||
Object* getCameraCenter();
|
Object* getCameraCenter();
|
||||||
Camera* getCamera();
|
Camera* getCamera();
|
||||||
glm::vec3 getCameraPosition();
|
glm::vec3 getCameraPosition();
|
||||||
glm::vec3 getFogColor();
|
glm::vec4 getFogColor();
|
||||||
|
void setSkyboxSize(float size);
|
||||||
private:
|
private:
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
std::vector<Object> objects;
|
std::vector<Object> objects;
|
||||||
std::vector<Light> lights;
|
std::vector<Light> lights;
|
||||||
glm::vec3 ambientLight;
|
glm::vec3 ambientLight;
|
||||||
glm::vec3 fogColor;
|
glm::vec4 fogColor;
|
||||||
Light directionalLight;
|
Light directionalLight;
|
||||||
Object* cameraCenter;
|
Object* cameraCenter;
|
||||||
|
Object* skybox;
|
||||||
Physics physics;
|
Physics physics;
|
||||||
Camera camera;
|
Camera camera;
|
||||||
Terrain terrain;
|
Terrain terrain;
|
||||||
|
float skyboxSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
5
main.cc
5
main.cc
@ -17,7 +17,7 @@
|
|||||||
#include <ACGL/Base/Settings.hh>
|
#include <ACGL/Base/Settings.hh>
|
||||||
|
|
||||||
Application::Application() {
|
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() {
|
Graphics* Application::getGraphics() {
|
||||||
@ -34,6 +34,9 @@ ACGL::OpenGL::SharedShaderProgram Application::getShader() {
|
|||||||
|
|
||||||
void Application::init()
|
void Application::init()
|
||||||
{
|
{
|
||||||
|
// set Skybox size
|
||||||
|
level.setSkyboxSize((graphics.getFarPlane()-32.0f)/sqrt(2));
|
||||||
|
|
||||||
// define where shaders and textures can be found:
|
// define where shaders and textures can be found:
|
||||||
ACGL::Base::Settings::the()->setResourcePath("../");
|
ACGL::Base::Settings::the()->setResourcePath("../");
|
||||||
ACGL::Base::Settings::the()->setShaderPath("Shader/");
|
ACGL::Base::Settings::the()->setShaderPath("Shader/");
|
||||||
|
Loading…
Reference in New Issue
Block a user