Merge branch 'master' of github.com:Faerbit/swp
This commit is contained in:
commit
7013f7cf71
@ -163,9 +163,10 @@
|
|||||||
<diffuseFactor>0.6</diffuseFactor>
|
<diffuseFactor>0.6</diffuseFactor>
|
||||||
<specularFactor>0.4</specularFactor>
|
<specularFactor>0.4</specularFactor>
|
||||||
<shininess>2.0</shininess>
|
<shininess>2.0</shininess>
|
||||||
<physicType>TriangleMesh</physicType>
|
<physicType>Box</physicType>
|
||||||
<dampningL>0.5</dampningL>
|
<width>0.5</width>
|
||||||
<dampningA>0.5</dampningA>
|
<height>0.5</height>
|
||||||
|
<length>0.5</length>
|
||||||
</objectData>
|
</objectData>
|
||||||
|
|
||||||
<objectData>
|
<objectData>
|
||||||
|
BIN
Levels/heightmapLvl1.png
Normal file
BIN
Levels/heightmapLvl1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
@ -13,6 +13,7 @@ uniform sampler2D uTexture;
|
|||||||
uniform sampler2DShadow shadowMap_near;
|
uniform sampler2DShadow shadowMap_near;
|
||||||
uniform sampler2DShadow shadowMap_middle;
|
uniform sampler2DShadow shadowMap_middle;
|
||||||
uniform sampler2DShadow shadowMap_far;
|
uniform sampler2DShadow shadowMap_far;
|
||||||
|
uniform samplerCubeShadow shadowMap_cube;
|
||||||
uniform vec3 ambientColor;
|
uniform vec3 ambientColor;
|
||||||
uniform float ambientFactor;
|
uniform float ambientFactor;
|
||||||
uniform float diffuseFactor;
|
uniform float diffuseFactor;
|
||||||
@ -49,7 +50,7 @@ vec2 poissonDisk[16] = vec2[](
|
|||||||
vec2( 0.14383161, -0.14100790 )
|
vec2( 0.14383161, -0.14100790 )
|
||||||
);
|
);
|
||||||
|
|
||||||
float sampleShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
|
float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
|
||||||
float visibility = 1.0;
|
float visibility = 1.0;
|
||||||
float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0)));
|
float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0)));
|
||||||
bias = clamp(bias, 0.0, 0.01);
|
bias = clamp(bias, 0.0, 0.01);
|
||||||
@ -68,6 +69,11 @@ float sampleShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
|
|||||||
return visibility;
|
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 distanceToBorder(vec2 vector) {
|
||||||
float xDistance = min(vector.x, 1.0-vector.x);
|
float xDistance = min(vector.x, 1.0-vector.x);
|
||||||
float yDistance = min(vector.y, 1.0-vector.y);
|
float yDistance = min(vector.y, 1.0-vector.y);
|
||||||
@ -92,8 +98,10 @@ void main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// point lights
|
// point lights
|
||||||
|
float visibility = 1.0;
|
||||||
for(int i = 0; i<lightCount; i++) {
|
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
|
// only take lights into account with meaningful contribution
|
||||||
if (distance > 0.001f) {
|
if (distance > 0.001f) {
|
||||||
vec3 lightVector = normalize(lightSources[i]-vec3(fragPosition));
|
vec3 lightVector = normalize(lightSources[i]-vec3(fragPosition));
|
||||||
@ -103,21 +111,21 @@ void main()
|
|||||||
vec3 cameraVector = normalize(camera - vec3(fragPosition));
|
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)
|
specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
|
||||||
*specularFactor*intensity*lightColors[i];
|
*specularFactor*intensity*lightColors[i];
|
||||||
|
visibility = samplePointShadow(shadowMap_cube, lightDirection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shadows
|
// shadows
|
||||||
float visibility = 1.0;
|
|
||||||
if (distanceToBorder(shadowCoord_middle.xy) <= 0.5 && distanceToBorder(shadowCoord_middle.xy) > 0.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) {
|
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 {
|
else {
|
||||||
visibility = sampleShadow(shadowMap_middle, shadowCoord_middle);
|
visibility *= sampleDirectionalShadow(shadowMap_middle, shadowCoord_middle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
visibility = sampleShadow(shadowMap_far, shadowCoord_far);
|
visibility *= sampleDirectionalShadow(shadowMap_far, shadowCoord_far);
|
||||||
}
|
}
|
||||||
|
|
||||||
specularColor *= visibility;
|
specularColor *= visibility;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
uniform mat4 modelViewProjectionMatrix;
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
uniform mat4 shadowMVPs[35];
|
uniform mat4 shadowMVPs[5];
|
||||||
|
|
||||||
in vec3 aPosition;
|
in vec3 aPosition;
|
||||||
in vec3 aNormal;
|
in vec3 aNormal;
|
||||||
|
12
graphics.cc
12
graphics.cc
@ -70,8 +70,10 @@ void Graphics::init(Level* level) {
|
|||||||
framebuffer_far->setDepthTexture(depthTexture_far);
|
framebuffer_far->setDepthTexture(depthTexture_far);
|
||||||
framebuffer_far->validate();
|
framebuffer_far->validate();
|
||||||
|
|
||||||
depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(level->getLights()->size());
|
/*depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(level->getLights()->size());
|
||||||
for (unsigned int i = 0; i<depth_cubeMaps.size(); i++) {
|
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) = SharedTextureCubeMap(new TextureCubeMap(glm::vec2(cube_size, cube_size), GL_DEPTH_COMPONENT16));
|
||||||
depth_cubeMaps.at(i)->setMinFilter(GL_NEAREST);
|
depth_cubeMaps.at(i)->setMinFilter(GL_NEAREST);
|
||||||
depth_cubeMaps.at(i)->setMagFilter(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)};
|
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();
|
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
|
// render each side of the cube
|
||||||
for (int i_face = 0; i_face<6; i_face++) {
|
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);
|
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);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * glm::lookAt(level->getLights()->at(i_pointlight).getPosition(),
|
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));
|
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);
|
level->render(depthShader, false, &depthViewProjectionMatrix_face);
|
||||||
if (!framebuffer_cube->isFrameBufferObjectComplete()) {
|
if (!framebuffer_cube->isFrameBufferObjectComplete()) {
|
||||||
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
||||||
@ -182,6 +184,8 @@ void Graphics::render()
|
|||||||
}
|
}
|
||||||
glUniform1fv(lightingShader->getUniformLocation("lightIntensities"),
|
glUniform1fv(lightingShader->getUniformLocation("lightIntensities"),
|
||||||
sizeof(lightIntensities), (GLfloat*) lightIntensities);
|
sizeof(lightIntensities), (GLfloat*) lightIntensities);
|
||||||
|
|
||||||
|
lightingShader->setTexture("shadowMap_cube", depth_cubeMaps.at(0), 4);
|
||||||
}
|
}
|
||||||
// set directional Light
|
// set directional Light
|
||||||
if(level->getDirectionalLight()) {
|
if(level->getDirectionalLight()) {
|
||||||
|
45
level.cc
45
level.cc
@ -149,7 +149,7 @@ void Level::load() {
|
|||||||
}
|
}
|
||||||
std::string dataModelPath = charDataModelPath;
|
std::string dataModelPath = charDataModelPath;
|
||||||
//objectData found
|
//objectData found
|
||||||
if(dataModelPath == modelPath){
|
if(dataModelPath.compare(modelPath) == 0){
|
||||||
//create the object
|
//create the object
|
||||||
float ambientFactor, diffuseFactor, specularFactor, shininess;
|
float ambientFactor, diffuseFactor, specularFactor, shininess;
|
||||||
errorCheck(objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor));
|
errorCheck(objectData->FirstChildElement("ambientFactor")->QueryFloatText(&ambientFactor));
|
||||||
@ -237,24 +237,24 @@ void Level::load() {
|
|||||||
}//iterating over all objects of the composition
|
}//iterating over all objects of the composition
|
||||||
|
|
||||||
//iterate over all lights of the composition
|
//iterate over all lights of the composition
|
||||||
XMLElement* light = composition->FirstChildElement("light");
|
XMLElement* xmlLight = composition->FirstChildElement("light");
|
||||||
for(; light; light=light->NextSiblingElement("light")){
|
for(; xmlLight; xmlLight=xmlLight->NextSiblingElement("light")){
|
||||||
glm::vec3 compRot, lightOffset, lightColour;
|
glm::vec3 compRot, lightOffset, lightColour;
|
||||||
float compScale, compXPos, compYOffset, compZPos, lightIntensity;
|
float compScale, compXPos, compYOffset, compZPos, lightIntensity;
|
||||||
errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
|
errorCheck(thisComposition->FirstChildElement("scale")->QueryFloatText(&compScale));
|
||||||
errorCheck(light->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0]));
|
errorCheck(xmlLight->FirstChildElement("xOffset")->QueryFloatText(&lightOffset[0]));
|
||||||
errorCheck(light->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1]));
|
errorCheck(xmlLight->FirstChildElement("yOffset")->QueryFloatText(&lightOffset[1]));
|
||||||
errorCheck(light->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2]));
|
errorCheck(xmlLight->FirstChildElement("zOffset")->QueryFloatText(&lightOffset[2]));
|
||||||
errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
|
errorCheck(thisComposition->FirstChildElement("xPos")->QueryFloatText(&compXPos));
|
||||||
errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
|
errorCheck(thisComposition->FirstChildElement("yOffset")->QueryFloatText(&compYOffset));
|
||||||
errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
|
errorCheck(thisComposition->FirstChildElement("zPos")->QueryFloatText(&compZPos));
|
||||||
errorCheck(thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]));
|
errorCheck(thisComposition->FirstChildElement("xRot")->QueryFloatText(&compRot[0]));
|
||||||
errorCheck(thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]));
|
errorCheck(thisComposition->FirstChildElement("yRot")->QueryFloatText(&compRot[1]));
|
||||||
errorCheck(thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]));
|
errorCheck(thisComposition->FirstChildElement("zRot")->QueryFloatText(&compRot[2]));
|
||||||
errorCheck(light->FirstChildElement("rColour")->QueryFloatText(&lightColour[0]));
|
errorCheck(xmlLight->FirstChildElement("rColour")->QueryFloatText(&lightColour[0]));
|
||||||
errorCheck(light->FirstChildElement("gColour")->QueryFloatText(&lightColour[1]));
|
errorCheck(xmlLight->FirstChildElement("gColour")->QueryFloatText(&lightColour[1]));
|
||||||
errorCheck(light->FirstChildElement("bColour")->QueryFloatText(&lightColour[2]));
|
errorCheck(xmlLight->FirstChildElement("bColour")->QueryFloatText(&lightColour[2]));
|
||||||
errorCheck(light->FirstChildElement("intensity")->QueryFloatText(&lightIntensity));
|
errorCheck(xmlLight->FirstChildElement("intensity")->QueryFloatText(&lightIntensity));
|
||||||
glm::vec3 compPos = glm::vec3(compXPos,
|
glm::vec3 compPos = glm::vec3(compXPos,
|
||||||
compYOffset+terrain.getHeightmap()[int(compXPos-0.5+0.5*terrain.getHeightmapHeight())]
|
compYOffset+terrain.getHeightmap()[int(compXPos-0.5+0.5*terrain.getHeightmapHeight())]
|
||||||
[int(compZPos-0.5+0.5*terrain.getHeightmapWidth())],
|
[int(compZPos-0.5+0.5*terrain.getHeightmapWidth())],
|
||||||
@ -273,15 +273,32 @@ void Level::load() {
|
|||||||
}//iterating over all compositions in Level.xml
|
}//iterating over all compositions in Level.xml
|
||||||
|
|
||||||
//load triggers
|
//load triggers
|
||||||
XMLElement* trigger = doc->FirstChildElement("trigger");
|
XMLElement* xmlTrigger = doc->FirstChildElement("trigger");
|
||||||
for(; trigger; trigger=trigger->NextSiblingElement("trigger")){
|
for(; xmlTrigger; xmlTrigger=xmlTrigger->NextSiblingElement("trigger")){
|
||||||
const char* charName = trigger->FirstChildElement("name")->GetText();
|
const char* charName = xmlTrigger->FirstChildElement("name")->GetText();
|
||||||
if(charName == NULL){
|
if(charName == NULL){
|
||||||
printf("XMLError: No name found for a trigger.\n");
|
printf("XMLError: No name found for a trigger.\n");
|
||||||
}
|
}
|
||||||
std::string name = charName;
|
std::string name = charName;
|
||||||
if (name.compare("-") != 0){
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
level.hh
2
level.hh
@ -10,6 +10,7 @@
|
|||||||
#include "camera.hh"
|
#include "camera.hh"
|
||||||
#include "physics.hh"
|
#include "physics.hh"
|
||||||
#include "tinyxml2.hh"
|
#include "tinyxml2.hh"
|
||||||
|
#include "trigger.hh"
|
||||||
|
|
||||||
class Level {
|
class Level {
|
||||||
public:
|
public:
|
||||||
@ -34,6 +35,7 @@ class Level {
|
|||||||
std::vector<Object*> objects;
|
std::vector<Object*> objects;
|
||||||
std::vector<Object*> physicObjects;
|
std::vector<Object*> physicObjects;
|
||||||
std::vector<Light> lights;
|
std::vector<Light> lights;
|
||||||
|
std::vector<Trigger> triggers;
|
||||||
glm::vec3 ambientLight;
|
glm::vec3 ambientLight;
|
||||||
glm::vec4 fogColour;
|
glm::vec4 fogColour;
|
||||||
Light directionalLight;
|
Light directionalLight;
|
||||||
|
12
trigger.cc
12
trigger.cc
@ -1,7 +1,11 @@
|
|||||||
#include "trigger.hh"
|
#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(){
|
Trigger::Trigger(){
|
||||||
@ -9,3 +13,7 @@ Trigger::Trigger(){
|
|||||||
|
|
||||||
Trigger::~Trigger(){
|
Trigger::~Trigger(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Trigger::triggerUpdate(){
|
||||||
|
|
||||||
|
}
|
||||||
|
10
trigger.hh
10
trigger.hh
@ -2,14 +2,20 @@
|
|||||||
#define TRIGGER_HH_INCLUDED
|
#define TRIGGER_HH_INCLUDED
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "object.hh"
|
||||||
|
|
||||||
class Trigger {
|
class Trigger {
|
||||||
public:
|
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();
|
||||||
~Trigger();
|
~Trigger();
|
||||||
|
void triggerUpdate();
|
||||||
private:
|
private:
|
||||||
|
std::vector<float> position;
|
||||||
|
float distance;
|
||||||
|
bool isBigger;
|
||||||
|
Object* object;
|
||||||
|
void (*functionPointer)();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user