Merge branch 'master' of github.com:Faerbit/swp

This commit is contained in:
Jasper 2014-12-15 16:04:36 +01:00
commit 9964b9be34
9 changed files with 78 additions and 32 deletions

View File

@ -163,9 +163,10 @@
<diffuseFactor>0.6</diffuseFactor>
<specularFactor>0.4</specularFactor>
<shininess>2.0</shininess>
<physicType>TriangleMesh</physicType>
<dampningL>0.5</dampningL>
<dampningA>0.5</dampningA>
<physicType>Box</physicType>
<width>0.5</width>
<height>0.5</height>
<length>0.5</length>
</objectData>
<objectData>

BIN
Levels/heightmapLvl1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -13,6 +13,7 @@ uniform sampler2D uTexture;
uniform sampler2DShadow shadowMap_near;
uniform sampler2DShadow shadowMap_middle;
uniform sampler2DShadow shadowMap_far;
uniform samplerCubeShadow shadowMap_cube;
uniform vec3 ambientColor;
uniform float ambientFactor;
uniform float diffuseFactor;
@ -49,7 +50,7 @@ vec2 poissonDisk[16] = vec2[](
vec2( 0.14383161, -0.14100790 )
);
float sampleShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
float visibility = 1.0;
float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0)));
bias = clamp(bias, 0.0, 0.01);
@ -68,6 +69,11 @@ float sampleShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
return visibility;
}
float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) {
float bias = 0.005;
return texture(shadowMap, vec4(lightDirection.xyz , length(lightDirection) - bias));
}
float distanceToBorder(vec2 vector) {
float xDistance = min(vector.x, 1.0-vector.x);
float yDistance = min(vector.y, 1.0-vector.y);
@ -92,8 +98,10 @@ void main()
}
// point lights
float visibility = 1.0;
for(int i = 0; i<lightCount; i++) {
float distance = distance(lightSources[i], vec3(fragPosition));
vec3 lightDirection = vec3(fragPosition) - lightSources[i];
float distance = length(lightDirection);
// only take lights into account with meaningful contribution
if (distance > 0.001f) {
vec3 lightVector = normalize(lightSources[i]-vec3(fragPosition));
@ -103,21 +111,21 @@ void main()
vec3 cameraVector = normalize(camera - vec3(fragPosition));
specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
*specularFactor*intensity*lightColors[i];
visibility = samplePointShadow(shadowMap_cube, lightDirection);
}
}
// shadows
float visibility = 1.0;
if (distanceToBorder(shadowCoord_middle.xy) <= 0.5 && distanceToBorder(shadowCoord_middle.xy) > 0.0) {
if (distanceToBorder(shadowCoord_near.xy) <= 0.5 && distanceToBorder(shadowCoord_near.xy) > 0.0) {
visibility = sampleShadow(shadowMap_near, shadowCoord_near);
visibility *= sampleDirectionalShadow(shadowMap_near, shadowCoord_near);
}
else {
visibility = sampleShadow(shadowMap_middle, shadowCoord_middle);
visibility *= sampleDirectionalShadow(shadowMap_middle, shadowCoord_middle);
}
}
else {
visibility = sampleShadow(shadowMap_far, shadowCoord_far);
visibility *= sampleDirectionalShadow(shadowMap_far, shadowCoord_far);
}
specularColor *= visibility;

View File

@ -2,7 +2,7 @@
uniform mat4 modelMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 shadowMVPs[35];
uniform mat4 shadowMVPs[5];
in vec3 aPosition;
in vec3 aNormal;

View File

@ -70,8 +70,10 @@ void Graphics::init(Level* level) {
framebuffer_far->setDepthTexture(depthTexture_far);
framebuffer_far->validate();
depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(level->getLights()->size());
for (unsigned int i = 0; i<depth_cubeMaps.size(); i++) {
/*depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(level->getLights()->size());
for (unsigned int i = 0; i<depth_cubeMaps.size(); i++) {*/
depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(1);
for (unsigned int i = 0; i<1; i++) {
depth_cubeMaps.at(i) = SharedTextureCubeMap(new TextureCubeMap(glm::vec2(cube_size, cube_size), GL_DEPTH_COMPONENT16));
depth_cubeMaps.at(i)->setMinFilter(GL_NEAREST);
depth_cubeMaps.at(i)->setMagFilter(GL_NEAREST);
@ -102,14 +104,14 @@ void Graphics::render()
glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, -1.0f)};
framebuffer_cube->bind();
for (unsigned int i_pointlight = 0; i_pointlight<level->getLights()->size(); i_pointlight++) {
//for (unsigned int i_pointlight = 0; i_pointlight<level->getLights()->size(); i_pointlight++) {
for (unsigned int i_pointlight = 0; i_pointlight<1; i_pointlight++) {
// render each side of the cube
for (int i_face = 0; i_face<6; i_face++) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i_face, depth_cubeMaps.at(i_pointlight)->getObjectName(), 0);
glClear(GL_DEPTH_BUFFER_BIT);
glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * glm::lookAt(level->getLights()->at(i_pointlight).getPosition(),
level->getLights()->at(i_pointlight).getPosition() + looking_directions[i_face], glm::vec3(0.0f, 1.0f, 0.0f));
depthShader->setUniform("viewProjectionMatrix", depthViewProjectionMatrix_face);
level->render(depthShader, false, &depthViewProjectionMatrix_face);
if (!framebuffer_cube->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
@ -182,6 +184,8 @@ void Graphics::render()
}
glUniform1fv(lightingShader->getUniformLocation("lightIntensities"),
sizeof(lightIntensities), (GLfloat*) lightIntensities);
lightingShader->setTexture("shadowMap_cube", depth_cubeMaps.at(0), 4);
}
// set directional Light
if(level->getDirectionalLight()) {

View File

@ -149,7 +149,7 @@ void Level::load() {
}
std::string dataModelPath = charDataModelPath;
//objectData found
if(dataModelPath == modelPath){
if(dataModelPath.compare(modelPath) == 0){
//create the object
float ambientFactor, diffuseFactor, specularFactor, shininess;
errorCheck(objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor));
@ -237,24 +237,24 @@ void Level::load() {
}//iterating over all objects of the composition
//iterate over all lights of the composition
XMLElement* light = composition->FirstChildElement("light");
for(; light; light=light->NextSiblingElement("light")){
XMLElement* xmlLight = composition->FirstChildElement("light");
for(; xmlLight; xmlLight=xmlLight->NextSiblingElement("light")){
glm::vec3 compRot, lightOffset, lightColour;
float compScale, compXPos, compYOffset, compZPos, lightIntensity;
errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
errorCheck(light->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0]));
errorCheck(light->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1]));
errorCheck(light->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2]));
errorCheck(xmlLight->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0]));
errorCheck(xmlLight->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1]));
errorCheck(xmlLight->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2]));
errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
errorCheck(thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]));
errorCheck(thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]));
errorCheck(thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]));
errorCheck(light->FirstChildElement("rColour")->QueryFloatText(&lightColour[0]));
errorCheck(light->FirstChildElement("gColour")->QueryFloatText(&lightColour[1]));
errorCheck(light->FirstChildElement("bColour")->QueryFloatText(&lightColour[2]));
errorCheck(light->FirstChildElement("intensity")->QueryFloatText(&lightIntensity));
errorCheck(xmlLight->FirstChildElement("rColour")->QueryFloatText(&lightColour[0]));
errorCheck(xmlLight->FirstChildElement("gColour")->QueryFloatText(&lightColour[1]));
errorCheck(xmlLight->FirstChildElement("bColour")->QueryFloatText(&lightColour[2]));
errorCheck(xmlLight->FirstChildElement("intensity")->QueryFloatText(&lightIntensity));
glm::vec3 compPos = glm::vec3(compXPos,
compYOffset+terrain.getHeightmap()[int(compXPos-0.5+0.5*terrain.getHeightmapHeight())]
[int(compZPos-0.5+0.5*terrain.getHeightmapWidth())],
@ -273,15 +273,32 @@ void Level::load() {
}//iterating over all compositions in Level.xml
//load triggers
XMLElement* trigger = doc->FirstChildElement("trigger");
for(; trigger; trigger=trigger->NextSiblingElement("trigger")){
const char* charName = trigger->FirstChildElement("name")->GetText();
XMLElement* xmlTrigger = doc->FirstChildElement("trigger");
for(; xmlTrigger; xmlTrigger=xmlTrigger->NextSiblingElement("trigger")){
const char* charName = xmlTrigger->FirstChildElement("name")->GetText();
if(charName == NULL){
printf("XMLError: No name found for a trigger.\n");
}
std::string name = charName;
if (name.compare("-") != 0){
//TODO add triggers
float xPos, yPos, zPos, distance;
std::vector<float> position;
bool isBigger;
int idGreen, idBlue, objectNum;
errorCheck(xmlTrigger->FirstChildElement("xPosition")->QueryFloatText(&xPos));
errorCheck(xmlTrigger->FirstChildElement("yPosition")->QueryFloatText(&yPos));
errorCheck(xmlTrigger->FirstChildElement("zPosition")->QueryFloatText(&zPos));
errorCheck(xmlTrigger->FirstChildElement("distance")->QueryFloatText(&distance));
position.push_back(xPos);
position.push_back(yPos);
position.push_back(zPos);
errorCheck(xmlTrigger->FirstChildElement("isBiggerThan")->QueryBoolText(&isBigger));
errorCheck(xmlTrigger->FirstChildElement("idGreen")->QueryIntText(&idGreen));
errorCheck(xmlTrigger->FirstChildElement("idBlue")->QueryIntText(&idBlue));
errorCheck(xmlTrigger->FirstChildElement("objectNum")->QueryIntText(&objectNum));
//TODO find the object
//Trigger trigger = Trigger::Trigger(position, distance, isBigger, Object* object, void (*functionPointer)());
//triggers.push_back(trigger);
}
}

View File

@ -10,6 +10,7 @@
#include "camera.hh"
#include "physics.hh"
#include "tinyxml2.hh"
#include "trigger.hh"
class Level {
public:
@ -34,6 +35,7 @@ class Level {
std::vector<Object*> objects;
std::vector<Object*> physicObjects;
std::vector<Light> lights;
std::vector<Trigger> triggers;
glm::vec3 ambientLight;
glm::vec4 fogColour;
Light directionalLight;

View File

@ -1,7 +1,11 @@
#include "trigger.hh"
Trigger::Trigger(std::vector<float> position, float distance, bool isBigger, int objectIndex, int functionPointer) {
Trigger::Trigger(std::vector<float> position, float distance, bool isBigger, Object* object, void (*functionPointer)()) {
this->position=position;
this->distance=distance;
this->isBigger=isBigger;
this->object=object;
this->functionPointer=functionPointer;
}
Trigger::Trigger(){
@ -9,3 +13,7 @@ Trigger::Trigger(){
Trigger::~Trigger(){
}
void Trigger::triggerUpdate(){
}

View File

@ -2,14 +2,20 @@
#define TRIGGER_HH_INCLUDED
#include <vector>
#include "object.hh"
class Trigger {
public:
Trigger(std::vector<float> position, float distance, bool isBigger, int objectIndex, int functionPointer);
Trigger(std::vector<float> position, float distance, bool isBigger, Object* object, void (*functionPointer)());
Trigger();
~Trigger();
void triggerUpdate();
private:
std::vector<float> position;
float distance;
bool isBigger;
Object* object;
void (*functionPointer)();
};
#endif