This commit is contained in:
sfroitzheim 2015-03-04 15:04:32 +01:00
commit 20055d7fc5
23 changed files with 608 additions and 159 deletions

View File

@ -33,7 +33,7 @@ void Application::init()
level.load();
Loader loader = Loader();
loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath);
loader.load(levelXmlFilePath, &level, compositionsPath, scriptPath, geometryPath, texturePath);
graphics.init(&level);
// just in case: check for errors

View File

@ -69,7 +69,7 @@
</object>
<light>
<xOffset>0.0</xOffset>
<yOffset>2</yOffset>
<yOffset>3</yOffset>
<zOffset>0.0</zOffset>
<rColour>1.0</rColour>
<gColour>0.9</gColour>
@ -452,7 +452,7 @@
<yRot>0.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>1.0</mass>
<mass>3.0</mass>
</object>
</composition>

View File

@ -714,18 +714,35 @@
<strength>12.0</strength>
</positionConstraint>
<trigger>
<name>-</name>
<xPosition>0</xPosition>
<yPosition>0</yPosition>
<zPosition>0</zPosition>
<name>openSecondDoor1</name>
<undo>false</undo>
<xPosition>-6.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>51.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>1.0</distance>
<distance>0.2</distance>
<isBiggerThan>true</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openSecondDoor1.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
<trigger>
<name>openSecondDoor1Undo</name>
<undo>true</undo>
<xPosition>-6.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>51.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>-</luaScript>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<luaScript>openSecondDoor1.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition>
@ -750,18 +767,35 @@
<strength>12.0</strength>
</positionConstraint>
<trigger>
<name>-</name>
<xPosition>0</xPosition>
<yPosition>0</yPosition>
<zPosition>0</zPosition>
<name>openSecondDoor3</name>
<undo>false</undo>
<xPosition>-6.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>29.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>1.0</distance>
<distance>0.2</distance>
<isBiggerThan>true</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openSecondDoor3.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
<trigger>
<name>openSecondDoor3Undo</name>
<undo>true</undo>
<xPosition>-6.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>29.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>-</luaScript>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<luaScript>openSecondDoor3.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition>
@ -2410,18 +2444,35 @@
<strength>12.0</strength>
</positionConstraint>
<trigger>
<name>-</name>
<xPosition>0</xPosition>
<yPosition>0</yPosition>
<zPosition>0</zPosition>
<name>openSecondDoor4</name>
<undo>false</undo>
<xPosition>-53.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>51.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>1.0</distance>
<distance>0.2</distance>
<isBiggerThan>true</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openSecondDoor4.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
<trigger>
<name>openSecondDoor4Undo</name>
<undo>true</undo>
<xPosition>-53.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>51.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>-</luaScript>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<luaScript>openSecondDoor4.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition>
@ -2475,18 +2526,35 @@
<strength>12.0</strength>
</positionConstraint>
<trigger>
<name>-</name>
<xPosition>0</xPosition>
<yPosition>0</yPosition>
<zPosition>0</zPosition>
<name>openSecondDoor2</name>
<undo>false</undo>
<xPosition>-53.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>29.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>1.0</distance>
<distance>0.2</distance>
<isBiggerThan>true</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openSecondDoor2.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
<trigger>
<name>openSecondDoor2Undo</name>
<undo>true</undo>
<xPosition>-53.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>29.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>-</luaScript>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<luaScript>openSecondDoor2.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition>
@ -3672,6 +3740,7 @@
</positionConstraint>
<trigger>
<name>openThirdDoor</name>
<undo>false</undo>
<xPosition>-161.5</xPosition>
<yPosition>21.7</yPosition>
<zPosition>67.5</zPosition>
@ -3687,6 +3756,7 @@
</trigger>
<trigger>
<name>openThirdDoorUndo</name>
<undo>true</undo>
<xPosition>-161.5</xPosition>
<yPosition>21.7</yPosition>
<zPosition>67.5</zPosition>
@ -3695,7 +3765,7 @@
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openThirdDoorUndo.lua</luaScript>
<luaScript>openThirdDoor.lua</luaScript>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>178</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
@ -6153,14 +6223,15 @@
<positionConstraint>
<objectNum>0</objectNum>
<xPosition>17.5</xPosition>
<yPosition>22.0</yPosition>
<yPosition>21.8</yPosition>
<zPosition>159.5</zPosition>
<strength>12.0</strength>
</positionConstraint>
<trigger>
<name>openFirstDoor</name>
<undo>false</undo>
<xPosition>17.5</xPosition>
<yPosition>22</yPosition>
<yPosition>21.8</yPosition>
<zPosition>159.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
@ -6174,15 +6245,16 @@
</trigger>
<trigger>
<name>openFirstDoorUndo</name>
<undo>true</undo>
<xPosition>17.5</xPosition>
<yPosition>22</yPosition>
<yPosition>21.8</yPosition>
<zPosition>159.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openFirstDoorUndo.lua</luaScript>
<luaScript>openFirstDoor.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>94</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>

View File

@ -2,6 +2,10 @@ local global = require( "global" )
if(global.triggeredOpenFirstDoor == nil) then
global.triggeredOpenFirstDoor = false
end
if(global.triggeredOpenFirstDoorUndo == nil) then
global.triggeredOpenFirstDoorUndo = true
end
function trigger(objectToChange)
if(global.triggeredOpenFirstDoor == false) then
if(not level) then
@ -21,3 +25,23 @@ function trigger(objectToChange)
print("openFirstDoor")
end
end
function triggerUndo(objectToChange)
if(global.triggeredOpenFirstDoorUndo == false) then
if(not level) then
print("No level found in Lua!")
return
end
local strength = 100
local xPos = 17.5
local yPos = 25
local zPos = 81.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenFirstDoor = false
global.triggeredOpenFirstDoorUndo = true
print("openFirstDoorUndo")
end
end

View File

@ -1,23 +0,0 @@
local global = require( "global" )
if(global.triggeredOpenFirstDoorUndo == nil) then
global.triggeredOpenFirstDoorUndo = true
end
function trigger(objectToChange)
if(global.triggeredOpenFirstDoorUndo == false) then
if(not level) then
print("No level found in Lua!")
return
end
local strength = 100
local xPos = 17.5
local yPos = 25
local zPos = 81.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenFirstDoor = false
global.triggeredOpenFirstDoorUndo = true
print("openFirstDoorUndo")
end
end

View File

@ -0,0 +1,56 @@
local global = require( "global" )
if(global.triggeredOpenSecondDoor1 == nil) then
global.triggeredOpenSecondDoor1 = false
end
if(global.triggeredOpenSecondDoor1Undo == nil) then
global.triggeredOpenSecondDoor1Undo = true
end
function trigger(objectToChange)
if(global.triggeredOpenSecondDoor1 == false) then
if(not level) then
print("No level found in Lua!")
return
end
if(global.openSecondDoorCounter == nil) then
global.openSecondDoorCounter = 0
end
if(global.openSecondDoorCounter == 0) then
global.openSecondDoorCounter = global.openSecondDoorCounter + 1
end
global.triggeredOpenSecondDoor1 = true
if(global.triggeredOpenSecondDoor1 == true and global.triggeredOpenSecondDoor2 == true and global.triggeredOpenSecondDoor3 == true and global.triggeredOpenSecondDoor4 == true) then
if(global.openSecondDoorCounter == 4) then
local strength = 100
local xPos = -81.5
local yPos = 33
local zPos = 4.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
else
global.triggeredOpenSecondDoor1Undo = false
end
end
print("openSecondDoor1")
end
end
function triggerUndo(objectToChange)
if(global.triggeredOpenSecondDoor1Undo == false) then
if(not level) then
print("No level found in Lua!")
return
end
global.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
global.triggeredOpenSecondDoor1Undo = true
print("openSecondDoor1Undo")
end
end

View File

@ -0,0 +1,56 @@
local global = require( "global" )
if(global.triggeredOpenSecondDoor2 == nil) then
global.triggeredOpenSecondDoor2 = false
end
if(global.triggeredOpenSecondDoor2Undo == nil) then
global.triggeredOpenSecondDoor2Undo = true
end
function trigger(objectToChange)
if(global.triggeredOpenSecondDoor2 == false) then
if(not level) then
print("No level found in Lua!")
return
end
if(global.openSecondDoorCounter == nil) then
global.openSecondDoorCounter = 0
end
if(global.openSecondDoorCounter == 1) then
global.openSecondDoorCounter = global.openSecondDoorCounter + 1
end
global.triggeredOpenSecondDoor2 = true
if(global.triggeredOpenSecondDoor1 == true and global.triggeredOpenSecondDoor2 == true and global.triggeredOpenSecondDoor3 == true and global.triggeredOpenSecondDoor4 == true) then
if(global.openSecondDoorCounter == 4) then
local strength = 100
local xPos = -81.5
local yPos = 33
local zPos = 4.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
else
global.triggeredOpenSecondDoor2Undo = false
end
end
print("openSecondDoor2")
end
end
function triggerUndo(objectToChange)
if(global.triggeredOpenSecondDoor2Undo == false) then
if(not level) then
print("No level found in Lua!")
return
end
global.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
global.triggeredOpenSecondDoor2Undo = true
print("openSecondDoor2Undo")
end
end

View File

@ -0,0 +1,56 @@
local global = require( "global" )
if(global.triggeredOpenSecondDoor3 == nil) then
global.triggeredOpenSecondDoor3 = false
end
if(global.triggeredOpenSecondDoor3Undo == nil) then
global.triggeredOpenSecondDoor3Undo = true
end
function trigger(objectToChange)
if(global.triggeredOpenSecondDoor3 == false) then
if(not level) then
print("No level found in Lua!")
return
end
if(global.openSecondDoorCounter == nil) then
global.openSecondDoorCounter = 0
end
if(global.openSecondDoorCounter == 2) then
global.openSecondDoorCounter = global.openSecondDoorCounter + 1
end
global.triggeredOpenSecondDoor3 = true
if(global.triggeredOpenSecondDoor1 == true and global.triggeredOpenSecondDoor2 == true and global.triggeredOpenSecondDoor3 == true and global.triggeredOpenSecondDoor4 == true) then
if(global.openSecondDoorCounter == 4) then
local strength = 100
local xPos = -81.5
local yPos = 33
local zPos = 4.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
else
global.triggeredOpenSecondDoor3Undo = false
end
end
print("openSecondDoor3")
end
end
function triggerUndo(objectToChange)
if(global.triggeredOpenSecondDoor3Undo == false) then
if(not level) then
print("No level found in Lua!")
return
end
global.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
global.triggeredOpenSecondDoor3Undo = true
print("openSecondDoor3Undo")
end
end

View File

@ -0,0 +1,56 @@
local global = require( "global" )
if(global.triggeredOpenSecondDoor4 == nil) then
global.triggeredOpenSecondDoor4 = false
end
if(global.triggeredOpenSecondDoor4Undo == nil) then
global.triggeredOpenSecondDoor4Undo = true
end
function trigger(objectToChange)
if(global.triggeredOpenSecondDoor4 == false) then
if(not level) then
print("No level found in Lua!")
return
end
if(global.openSecondDoorCounter == nil) then
global.openSecondDoorCounter = 0
end
if(global.openSecondDoorCounter == 3) then
global.openSecondDoorCounter = global.openSecondDoorCounter + 1
end
global.triggeredOpenSecondDoor4 = true
if(global.triggeredOpenSecondDoor1 == true and global.triggeredOpenSecondDoor2 == true and global.triggeredOpenSecondDoor3 == true and global.triggeredOpenSecondDoor4 == true) then
if(global.openSecondDoorCounter == 4) then
local strength = 100
local xPos = -81.5
local yPos = 33
local zPos = 4.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
else
global.triggeredOpenSecondDoor4Undo = false
end
end
print("openSecondDoor4")
end
end
function triggerUndo(objectToChange)
if(global.triggeredOpenSecondDoor4Undo == false) then
if(not level) then
print("No level found in Lua!")
return
end
global.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
global.triggeredOpenSecondDoor4Undo = true
print("openSecondDoor4Undo")
end
end

View File

@ -2,6 +2,10 @@ local global = require( "global" )
if(global.triggeredOpenThirdDoor == nil) then
global.triggeredOpenThirdDoor = false
end
if(global.triggeredOpenThirdDoorUndo == nil) then
global.triggeredOpenThirdDoorUndo = true
end
function trigger(objectToChange)
if(global.triggeredOpenThirdDoor == false) then
if(not level) then
@ -21,3 +25,23 @@ function trigger(objectToChange)
print("openThirdDoor")
end
end
function triggerUndo(objectToChange)
if(global.triggeredOpenThirdDoorUndo == false) then
if(not level) then
print("No level found in Lua!")
return
end
local strength = 100
local xPos = -172.5
local yPos = 25
local zPos = 58.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenThirdDoor = false
global.triggeredOpenThirdDoorUndo = true
print("openThirdDoorUndo")
end
end

View File

@ -1,23 +0,0 @@
local global = require( "global" )
if(global.triggeredOpenThirdDoorUndo == nil) then
global.triggeredOpenThirdDoorUndo = true
end
function trigger(objectToChange)
if(global.triggeredOpenThirdDoorUndo == false) then
if(not level) then
print("No level found in Lua!")
return
end
local strength = 100
local xPos = -172.5
local yPos = 25
local zPos = 58.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenThirdDoor = false
global.triggeredOpenThirdDoorUndo = true
print("openThirdDoorUndo")
end
end

View File

@ -1,23 +1,17 @@
#version 150
uniform vec3 camera;
in vec3 fColor;
in GS_OUT {
smooth vec3 normal;
smooth vec3 position;
}fs_in;
out vec4 oColor;
uniform bool withColor;
void main() {
float dotProduct = dot(normalize(fs_in.normal), normalize(camera - fs_in.position));
if (dotProduct < 0.1 && dotProduct > 0.0){
oColor = vec4(1.0, 0.0, 0.0, 0.5);
if (withColor) {
oColor = vec4(fColor, 0.6);
}
else {
oColor = vec4(fColor, 0.5);
oColor = vec4(0.0, 0.0, 0.0, 0.0);
}
}

View File

@ -1,17 +1,12 @@
#version 150
uniform mat4 viewProjectionMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform float time;
uniform bool bottom;
uniform bool left;
layout(points) in;
layout(triangle_strip, max_vertices = 78) out;
out GS_OUT {
smooth vec3 normal;
smooth vec3 position;
}gs_out;
layout(triangle_strip, max_vertices = 146) out;
in vec3 Color[];
out vec3 fColor;
@ -37,7 +32,7 @@ float radiusFunction(float x) {
void main() {
fColor = Color[0];
float resolution = 6.0;
float resolution = 8.0;
float step = abs(end-begin)/resolution/2.0;
float i = 0.0;
float render_end = 0.0;
@ -67,31 +62,19 @@ void main() {
float rightAngle = PI * 2.0 / resolution * (j+1);
vec4 offset = vec4(cos(rightAngle) * downRadius, i, -sin(rightAngle) * downRadius, 0.0);
vec4 position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
gl_Position = position;
gs_out.normal = vec3(position - gl_in[0].gl_Position);
gs_out.position = vec3(position);
gl_Position = gl_in[0].gl_Position + modelViewProjectionMatrix * offset;
EmitVertex();
offset = vec4(cos(rightAngle) * upRadius, i + step, -sin(rightAngle) * upRadius, 0.0);
position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
gl_Position = position;
gs_out.normal = vec3(position - gl_in[0].gl_Position);
gs_out.position = vec3(position);
gl_Position = gl_in[0].gl_Position + modelViewProjectionMatrix * offset;
EmitVertex();
offset = vec4(cos(leftAngle) * downRadius, i, -sin(leftAngle) * downRadius, 0.0);
position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
gl_Position = position;
gs_out.normal = vec3(position - gl_in[0].gl_Position);
gs_out.position = vec3(position);
gl_Position = gl_in[0].gl_Position + modelViewProjectionMatrix * offset;
EmitVertex();
offset = vec4(cos(leftAngle) * upRadius, i + step, -sin(leftAngle) * upRadius, 0.0);
position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
gl_Position = position;
gs_out.normal = vec3(position - gl_in[0].gl_Position);
gs_out.position = vec3(position);
gl_Position = gl_in[0].gl_Position + modelViewProjectionMatrix * offset;
EmitVertex();
EndPrimitive();

View File

@ -0,0 +1,21 @@
#version 150
in vec2 vTexCoord;
uniform sampler2D light_fbo;
uniform int windowSizeX;
uniform int windowSizeY;
out vec4 oColor;
const float lookup_offset = 4.0;
void main() {
vec4 sum = vec4(0.0);
for(float i = -lookup_offset; i<=lookup_offset; i+=1.0) {
for(float j = -lookup_offset; j<=lookup_offset; j+=1.0) {
sum += texture(light_fbo, vec2(vTexCoord.x + i * 1.0/(windowSizeX/2.0), vTexCoord.y + j * 1.0/(windowSizeY/2.0)))/pow(lookup_offset*2+1, 2.0);
}
}
oColor = sum;
}

View File

@ -0,0 +1,11 @@
#version 150
in vec2 aPosition;
in vec2 aTexCoord;
out vec2 vTexCoord;
void main() {
vTexCoord = aTexCoord;
gl_Position = vec4(aPosition, 0.0, 1.0);
}

View File

@ -60,11 +60,11 @@ vec2 poissonDisk[16] = vec2[](
vec2( 0.14383161, -0.14100790 )
);
float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias ) {
float visibility = 1.0;
const float stretching = 650.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, maxBias);
for (int i=0; i<4; i++) {
visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
}
@ -109,24 +109,24 @@ void main()
float directionalVisibility = 1.0f;
if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) {
if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.2) {
directionalVisibility = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0);
directionalVisibility = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001);
}
else if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.0) {
float directionalVisibility0 = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0);
float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1);
float directionalVisibility0 = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001);
float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002);
directionalVisibility = mix(directionalVisibility0, directionalVisibility1, distanceToBorder(shadowCoord0.xy) * 5);
}
else {
directionalVisibility = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1);
directionalVisibility = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002);
}
}
else if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.0) {
float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1);
float directionalVisibility2 = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2);
float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.01);
float directionalVisibility2 = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01);
directionalVisibility = mix(directionalVisibility1, directionalVisibility2, distanceToBorder(shadowCoord1.xy) * 5);
}
else {
directionalVisibility = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2);
directionalVisibility = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01);
}
diffuseColor += clamp(dot(normalize(vNormal), directionalVector)
*diffuseFactor*directionalIntensity*directionalColor, 0.0, 1.0)*directionalVisibility;

View File

@ -35,6 +35,25 @@ void Graphics::init(Level* level) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
glEnable(GL_MULTISAMPLE);
fullscreen_quad_ab = SharedArrayBuffer(new ArrayBuffer());
fullscreen_quad_ab->defineAttribute("aPosition", GL_FLOAT, 2);
fullscreen_quad_ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
float quadData[] = {
-1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 1.0f
};
fullscreen_quad_ab->setDataElements(6, quadData);
fullscreen_quad = SharedVertexArrayObject(new VertexArrayObject);
fullscreen_quad->attachAllAttributes(fullscreen_quad_ab);
// update lights on creation
lastUpdate = -lightUpdateDelay;
@ -67,11 +86,14 @@ void Graphics::init(Level* level) {
flameShader = ShaderProgramCreator("flame")
.attributeLocations(flame_positions->getAttributeLocations()).create();
flamePostShader = ShaderProgramCreator("flame_post")
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units);
printf("Your graphics card supports %d texture units.\n", number_of_texture_units);
// Exit if we need more texture units
if (number_of_texture_units < 14) {
printf("You need at least 14 texture units to run this application. Exiting\n");
if (number_of_texture_units < 15) {
printf("You need at least 15 texture units to run this application. Exiting\n");
exit(-1);
}
@ -113,13 +135,34 @@ void Graphics::init(Level* level) {
framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject());
if (level->getLights()->size() > 0) {
for(unsigned int i = 0; i<depth_cubeMaps.size(); i++){
// start with texture unit 4 because the first four are used by the texture and the directional shadow map
lightingShader->setTexture("shadowMap_cube" + std::to_string(i), depth_cubeMaps.at(i), i+4);
}
}
light_fbo_color_texture = SharedTexture2D(new Texture2D(windowSize, GL_RGBA8));
light_fbo_color_texture->setMinFilter(GL_NEAREST);
light_fbo_color_texture->setMagFilter(GL_NEAREST);
light_fbo_color_texture->setWrapS(GL_CLAMP_TO_BORDER);
light_fbo_color_texture->setWrapT(GL_CLAMP_TO_BORDER);
light_fbo_depth_texture = SharedTexture2D(new Texture2D(windowSize, GL_DEPTH24_STENCIL8));
light_fbo_depth_texture->setMinFilter(GL_NEAREST);
light_fbo_depth_texture->setMagFilter(GL_NEAREST);
light_fbo_depth_texture->setWrapS(GL_CLAMP_TO_BORDER);
light_fbo_depth_texture->setWrapT(GL_CLAMP_TO_BORDER);
framebuffer_light = SharedFrameBufferObject(new FrameBufferObject());
framebuffer_light->attachColorTexture("oColor", light_fbo_color_texture);
framebuffer_light->setDepthTexture(light_fbo_depth_texture);
framebuffer_light->setClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
framebuffer_light->validate();
flamePostShader->use();
flamePostShader->setTexture("light_fbo", light_fbo_color_texture, 15);
flamePostShader->setUniform("windowSizeX", int(windowSize.x));
flamePostShader->setUniform("windowSizeY", int(windowSize.y));
updateClosestLights();
}
@ -187,8 +230,8 @@ void Graphics::render(double time)
}
}
// final render pass
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// lighting render pass
framebuffer_light->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
lightingShader->use();
@ -234,15 +277,18 @@ void Graphics::render(double time)
// render the level
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
// draw flames on top
flameShader->use();
// cull faces to get consistent color while using alpha
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// draw flames on top
flameShader->use();
// draw with colors
flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
flameShader->setUniform("modelViewProjectionMatrix", lightingViewProjectionMatrix);
flameShader->setUniform("withColor", true);
flameShader->setUniform("time", (float) time);
flameShader->setUniform("camera", level->getPhysics()->getCameraPosition());
flameShader->setUniform("bottom", true);
flameShader->setUniform("left", true);
flame_positions->render();
@ -254,7 +300,48 @@ void Graphics::render(double time)
flameShader->setUniform("left", false);
flame_positions->render();
glDepthMask(GL_FALSE);
// draw slightly larger only for stencil buffer to blur edges
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 0xFF); //Set any stencil to 1
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilMask(0xFF);//write to stencil buffer
glClear(GL_STENCIL_BUFFER_BIT);//clear stencil buffer
glm::mat4 modelMatrix = glm::scale(glm::vec3(1.1f));
flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
flameShader->setUniform("modelViewProjectionMatrix", lightingViewProjectionMatrix * modelMatrix);
flameShader->setUniform("withColor", false);
flameShader->setUniform("time", (float) time);
flameShader->setUniform("bottom", true);
flameShader->setUniform("left", true);
flame_positions->render();
flameShader->setUniform("left", false);
flame_positions->render();
flameShader->setUniform("bottom", false);
flameShader->setUniform("left", true);
flame_positions->render();
flameShader->setUniform("left", false);
flame_positions->render();
glStencilFunc(GL_EQUAL, 1, 0xFF); //Pass test if stencil value is 1
glStencilMask(0x00);// don't write to stencil buffer
glDepthMask(GL_TRUE);
glDisable(GL_CULL_FACE);
flamePostShader->use();
fullscreen_quad->render();
glDisable(GL_STENCIL_TEST);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer_light->getObjectName());
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, windowSize.x, windowSize.y, 0, 0, windowSize.x, windowSize.y,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
bool Graphics::compareLightDistances(Light a, Light b) {
@ -315,7 +402,7 @@ void Graphics::updateLights() {
lightingShader->setUniform("directionalIntensity",
level->getDirectionalLight()->getIntensity());
}
float flameData[closestLights.size() * 6] = {};
float* flameData = new float[closestLights.size() * 6];
int flameIndex = 0;
for (unsigned int i = 0; i<closestLights.size(); i++) {
if (closestLights.at(i).getFlameYOffset() != 0.0f) {
@ -337,6 +424,10 @@ void Graphics::resize(glm::uvec2 windowSize) {
for (unsigned int i = 0; i<depth_directionalMaps.size(); i++) {
depth_directionalMaps.at(i)->resize(glm::vec2(windowSize.x, windowSize.y));
}
light_fbo_color_texture->resize(windowSize);
light_fbo_depth_texture->resize(windowSize);
flamePostShader->setUniform("windowSizeX", int(windowSize.x));
flamePostShader->setUniform("windowSizeY", int(windowSize.y));
}
glm::mat4 Graphics::buildViewMatrix(Level* level) {

View File

@ -8,6 +8,8 @@
#include "level.hh"
using namespace ACGL::OpenGL;
class Graphics {
public:
Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane, int cube_size, unsigned int maxShadowRenderCount);
@ -28,16 +30,22 @@ class Graphics {
float nearPlane;
float farPlane;
std::vector<Light> closestLights;
ACGL::OpenGL::SharedShaderProgram lightingShader;
ACGL::OpenGL::SharedShaderProgram depthCubeShader;
ACGL::OpenGL::SharedShaderProgram depthShader;
ACGL::OpenGL::SharedShaderProgram flameShader;
std::vector<ACGL::OpenGL::SharedTexture2D> depth_directionalMaps;
std::vector<ACGL::OpenGL::SharedFrameBufferObject> framebuffer_directional;
std::vector<ACGL::OpenGL::SharedTextureCubeMap> depth_cubeMaps;
ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube;
ACGL::OpenGL::SharedVertexArrayObject flame_positions;
ACGL::OpenGL::SharedArrayBuffer flame_positions_ab;
SharedShaderProgram lightingShader;
SharedShaderProgram depthCubeShader;
SharedShaderProgram depthShader;
SharedShaderProgram flameShader;
SharedShaderProgram flamePostShader;
std::vector<SharedTexture2D> depth_directionalMaps;
std::vector<SharedFrameBufferObject> framebuffer_directional;
std::vector<SharedTextureCubeMap> depth_cubeMaps;
SharedFrameBufferObject framebuffer_cube;
SharedFrameBufferObject framebuffer_light;
SharedTexture2D light_fbo_color_texture;
SharedTexture2D light_fbo_depth_texture;
SharedVertexArrayObject flame_positions;
SharedArrayBuffer flame_positions_ab;
SharedVertexArrayObject fullscreen_quad;
SharedArrayBuffer fullscreen_quad_ab;
int cube_size;
unsigned int maxShadowRenderCount;
Level* level;

View File

@ -31,7 +31,7 @@ void Loader::loadConfig(Application* application) {
application->setLevelXmlPath(queryString(config, "levelXmlPath"));
}
void Loader::load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath) {
void Loader::load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath, std::string globalGeometryPath, std::string globalTexturePath) {
//Loading from xml:
XMLDocument* doc = new XMLDocument();
const char* xmlFile = filePath.c_str();
@ -55,17 +55,33 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
float terrainDiffuseFactor = queryFloat(terrainElement, "diffuseFactor");
float terrainSpecularFactor = queryFloat(terrainElement, "specularFactor");
float terrainShininess = queryFloat(terrainElement, "shininess");
struct stat buf;
std::string terrainTexturePath = "../" + globalTexturePath + terrainTexture;
if(stat(terrainTexturePath.c_str(), &buf) != 0){
std::cout << "The texture file " << terrainTexturePath << " does not exist." << std::endl;
exit(-1);
}
Material terrainMaterial = Material(terrainTexture, terrainAmbientFactor, terrainDiffuseFactor, terrainSpecularFactor, terrainShininess);
Object* terrainObject = new Object(terrainModel, terrainMaterial,
glm::vec3(-0.5*(float)level->getTerrain()->getHeightmapHeight(), 0.0f, -0.5f*(float)level->getTerrain()->getHeightmapWidth()),
glm::vec3(-0.5*((float)level->getTerrain()->getHeightmapHeight()-1), 0.0f, -0.5f*((float)level->getTerrain()->getHeightmapWidth()-1)),
glm::vec3(0.0f, 0.0f, 0.0f), true);
level->addObject(terrainObject);
level->getPhysics()->addTerrain(level->getTerrain()->getHeightmapWidth(), level->getTerrain()->getHeightmapHeight(), level->getTerrain()->getHeightmap());
//load the skydome
XMLElement* skydomeElement = doc->FirstChildElement("skydome");
std::string skydomeTexture = queryString(skydomeElement, "texture");;
std::string skydomeTexture = queryString(skydomeElement, "texture");
std::string skydomePath = "../" + globalGeometryPath + "skydome.obj";
if(stat(skydomePath.c_str(), &buf) != 0){
std::cout << "The object file " << skydomePath << " does not exist." << std::endl;
exit(-1);
}
Model skydomeModel = Model("skydome.obj", level->getSkydomeSize());
std::string skydomeTexturePath = "../" + globalTexturePath + skydomeTexture;
if(stat(skydomeTexturePath.c_str(), &buf) != 0){
std::cout << "The texture file " << skydomeTexturePath << " does not exist." << std::endl;
exit(-1);
}
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);
@ -139,7 +155,17 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
float specularFactor = queryFloat(objectData, "specularFactor");
float shininess = queryFloat(objectData, "shininess");
std::string texturePath = queryString(objectData, "texturePath");
std::string entireTexturePath = "../" + globalTexturePath + texturePath;
if(stat(entireTexturePath.c_str(), &buf) != 0){
std::cout << "The texture file " << entireTexturePath << " does not exist." << std::endl;
exit(-1);
}
material = Material(texturePath, ambientFactor, diffuseFactor, specularFactor, shininess);
std::string entireModelPath = "../" + globalGeometryPath + modelPath;
if(stat(entireModelPath.c_str(), &buf) != 0){
std::cout << "The object file " << entireModelPath << " does not exist." << std::endl;
exit(-1);
}
model = Model(modelPath, objectScale * compScale);
}
float compXPos = queryFloat(thisComposition, "xPos");
@ -299,6 +325,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
float xPos = queryFloat(xmlTrigger, "xPosition");
float yPos = queryFloat(xmlTrigger, "yPosition");
float zPos = queryFloat(xmlTrigger, "zPosition");
bool undo = queryBool(xmlTrigger, "undo");
glm::vec3 position = glm::vec3(xPos, yPos, zPos);
std::string stringTarget = queryString(xmlTrigger, "targetIdGreen");
if (stringTarget.compare("-") != 0){
@ -355,7 +382,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
printf("No Identifier found for an object that was to be changed by a trigger.\n");
}
if (object != 0) {
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, level->getLuaState(), objectToChange, scriptPath);
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, level->getLuaState(), objectToChange, scriptPath, undo);
level->addTrigger(trigger);
}
else {

View File

@ -10,7 +10,7 @@ class Loader {
public:
Loader();
void loadConfig(Application* application);
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath);
void load(std::string filePath, Level* level, std::string compositionsPath, std::string scriptPath, std::string geometryPath, std::string texturePath);
glm::vec3 reloadPlayerPosition(std::string filePath, Level* level);
private:
float queryFloat(XMLElement* element, const char* attribute);

View File

@ -157,7 +157,7 @@ void Physics::addTerrain(int width, int length, float** heightData) //The terrai
info.m_restitution = 0;
btRigidBody* tBody = new btRigidBody(info);
tBody->getWorldTransform().setOrigin(btVector3(-0.5,((float)highest)/2,-0.5)); //we have to move the origin of our rigid body down, because bullet sets the origin (0,0,0) at (width/2, height/2, length/2) in the map the x and z are correct in our level, but y needs to be addapted
tBody->getWorldTransform().setOrigin(btVector3(0,((float)highest)/2,0)); //we have to move the origin of our rigid body down, because bullet sets the origin (0,0,0) at (width/2, height/2, length/2) in the map the x and z are correct in our level, but y needs to be addapted
terrainBody = tBody;
if (world == NULL) {

View File

@ -1,16 +1,23 @@
#include "trigger.hh"
#include <sys/stat.h>
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* luaState, int objectToChange, std::string scriptPath) {
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* luaState, int objectToChange, std::string scriptPath, bool undo) {
this->position=position;
this->distance=distance;
this->isBigger=isBigger;
this->object=object;
this->luaScript= scriptPath + luaScript;
struct stat buf;
if(stat(this->luaScript.c_str(), &buf) != 0){
std::cout << "The lua file " << this->luaScript << " does not exist." << std::endl;
exit(-1);
}
this->luaState = luaState;
if(luaState == nullptr){
printf("The Lua state is NULL in trigger!\n");
}
this->objectToChange = objectToChange;
this->undo = undo;
}
Trigger::Trigger(){
@ -22,11 +29,19 @@ Trigger::~Trigger(){
void Trigger::triggerUpdate(){
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
luaL_dofile(luaState, luaScript.c_str());
luabridge::getGlobal(luaState, "trigger")(objectToChange);
if (undo){
luabridge::getGlobal(luaState, "triggerUndo")(objectToChange);
}else{
luabridge::getGlobal(luaState, "trigger")(objectToChange);
}
}
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
luaL_dofile(luaState, luaScript.c_str());
luabridge::getGlobal(luaState, "trigger")(objectToChange);
if (undo){
luabridge::getGlobal(luaState, "triggerUndo")(objectToChange);
}else{
luabridge::getGlobal(luaState, "trigger")(objectToChange);
}
}
}

View File

@ -14,7 +14,7 @@ class Level;
class Trigger {
public:
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, std::string scriptPath);
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, std::string scriptPath, bool undo);
Trigger();
~Trigger();
void triggerUpdate();
@ -27,6 +27,7 @@ class Trigger {
std::string luaScript;
lua_State* luaState;
int objectToChange;
bool undo;
};
#endif