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

This commit is contained in:
Jasper 2015-03-04 11:16:22 +01:00
commit 0292ab422a
47 changed files with 17467 additions and 20048 deletions

Binary file not shown.

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,19 +69,19 @@ int main( int argc, char *argv[] ){
}
printf("Iterating over the png.\n");
//iterate over all pixels of the image
for(unsigned int rowNum = 0; rowNum < height; rowNum++){
for(unsigned int columnNum = 0; columnNum < width; columnNum++){
for(unsigned int columnNum = 0; columnNum < width; columnNum++){
for(unsigned int rowNum = 0; rowNum < height; rowNum++){
unsigned int pixel = (rowNum*width+columnNum)*4;
//if there is a composition here, adjust the xml and image
if(image[pixel]!=0 && image[pixel]!=255){
if(image[pixel+1]==0 && image[pixel+2]==0){//composition has no ID
std::vector<int> newID;
newID = conv.newComposition(image[pixel], 0.5+rowNum-0.5*height, 0.5+columnNum-0.5*width);
newID = conv.newComposition(image[pixel], 0.5+columnNum-0.5*width, 0.5+rowNum-0.5*height);
idFound[newID[0]][newID[1]] = true;
image[pixel+1] = newID[0];
image[pixel+2] = newID[1];
}else{//composition has an ID
conv.updateComposition(image[pixel+1], image[pixel+2], 0.5+rowNum-0.5*height, 0.5+columnNum-0.5*width);
conv.updateComposition(image[pixel+1], image[pixel+2], 0.5+columnNum-0.5*width, 0.5+rowNum-0.5*height);
idFound[image[pixel+1]][image[pixel+2]] = true;
}
}

View File

@ -1,52 +1,52 @@
# Blender v2.72 (sub 0) OBJ File: 'Gate.blend'
# Blender v2.72 (sub 0) OBJ File: ''
# www.blender.org
o Wall_Cube.001
v 0.537791 -3.045326 3.045326
v 0.537791 -3.045326 -3.045326
v -0.537791 -3.045326 -3.045326
v -0.537791 -3.045326 3.045326
v 0.537791 3.045326 3.045326
o Wall_Cube.000
v 0.537791 3.045326 -3.045326
v -0.537791 3.045326 -3.045326
v 0.537791 -3.045326 -3.045326
v 0.537791 -3.045326 3.045326
v -0.537791 3.045326 3.045326
v -0.537791 -3.045326 3.045326
v -0.537791 -3.045326 -3.045326
v 0.537791 3.045326 3.045326
v -0.537791 3.045326 -3.045326
vt 1.000000 0.000000
vt 1.000000 -1.000000
vt 0.000000 -1.000000
vt 1.000000 -1.000000
vt -1.000000 0.000000
vt -1.000000 -1.000000
vt 0.000000 0.000000
vt 0.039666 1.000166
vt 0.039666 0.000166
vt 0.000334 0.000166
vt 0.039666 0.000166
vt 0.960071 -0.007992
vt 0.959736 0.992008
vt 0.993184 0.992028
vt 0.959736 0.992008
vt 0.002338 0.996941
vt 0.032299 0.996953
vt 0.032522 -0.000041
vt 0.032299 0.996953
vt 0.995477 0.006970
vt 0.952679 0.006970
vt 0.952679 0.987810
vt 0.952679 0.006970
vt 0.000334 1.000166
vt 0.993520 -0.007972
vt 0.002561 -0.000052
vt 0.995477 0.987810
vn -1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 0.000000 0.000000 1.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 -0.000000 1.000000
vn 0.000000 -1.000000 -0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 -1.000000 0.000000
s off
f 6/1/1 2/2/1 1/3/1
f 8/4/2 4/5/2 3/3/2
f 5/6/1 6/1/1 1/3/1
f 7/6/2 8/4/2 3/3/2
f 7/7/3 3/8/3 2/9/3
f 5/10/4 1/11/4 4/12/4
f 2/13/5 3/14/5 4/15/5
f 7/16/6 6/17/6 5/18/6
f 6/19/3 7/7/3 2/9/3
f 8/20/4 5/10/4 4/12/4
f 1/21/5 2/13/5 4/15/5
f 8/22/6 7/16/6 5/18/6
f 1/1/1 3/2/1 2/3/1
f 4/4/2 6/2/2 5/5/2
f 7/6/1 3/2/1 1/1/1
f 8/6/2 6/2/2 4/4/2
f 8/7/3 2/8/3 6/9/3
f 7/10/4 5/11/4 3/12/4
f 2/13/5 5/14/5 6/15/5
f 8/16/6 7/17/6 1/18/6
f 1/19/3 2/8/3 8/7/3
f 4/20/4 5/11/4 7/10/4
f 3/21/5 5/14/5 2/13/5
f 4/22/6 7/17/6 8/16/6

View File

@ -1,54 +1,54 @@
# Blender v2.72 (sub 0) OBJ File: 'SimpleWall.blend'
# Blender v2.72 (sub 0) OBJ File: ''
# www.blender.org
o Wall_Cube.001
v 0.537791 -3.045326 3.045326
v 0.537791 3.045326 -3.045326
v 0.537791 -3.045326 -3.045326
v 0.537791 -3.045326 3.045326
v -0.537791 3.045326 -3.045326
v -0.537791 -3.045326 -3.045326
v -0.537791 3.045326 3.045326
v -0.537791 -3.045326 3.045326
v 0.537791 3.045326 3.045326
v 0.537791 3.045326 -3.045326
v -0.537791 3.045326 -3.045326
v -0.537791 3.045326 3.045326
vt 1.002363 0.998329
vt 1.002363 -0.001671
vt 0.005637 -0.001671
vt 1.002363 -0.001671
vt 0.394169 0.995358
vt 0.394169 -0.004642
vt 0.605831 -0.004642
vt 0.394169 -0.004642
vt -0.003002 0.995358
vt -0.003002 -0.004642
vt 0.996752 -0.004642
vt -0.003002 -0.004642
vt 0.605361 0.992386
vt 0.605361 -0.007614
vt 0.392389 -0.007614
vt 0.605361 -0.007614
vt 0.001396 0.906027
vt 0.001923 0.094175
vt 0.998604 0.093973
vt 0.001923 0.094175
vt 1.000000 0.097080
vt 1.000000 0.902920
vt 0.000000 0.902920
vt 1.000000 0.902920
vt 0.005637 0.998329
vt 0.605831 0.995358
vt 0.996752 0.995358
vt 0.392389 0.992386
vt 0.998077 0.905824
vt 0.000000 0.097080
vn -1.000000 0.000000 0.000000
vn 0.000000 0.000000 1.000000
vn 1.000000 0.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 -0.000000 1.000000
vn 0.000000 -1.000000 -0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 -1.000000 0.000000
s off
f 6/1/1 2/2/1 1/3/1
f 7/4/2 3/5/2 2/6/2
f 8/7/3 4/8/3 3/9/3
f 5/10/4 1/11/4 4/12/4
f 2/13/5 3/14/5 4/15/5
f 7/16/6 6/17/6 5/18/6
f 5/19/1 6/1/1 1/3/1
f 6/20/2 7/4/2 2/6/2
f 7/21/3 8/7/3 3/9/3
f 8/22/4 5/10/4 4/12/4
f 1/23/5 2/13/5 4/15/5
f 8/24/6 7/16/6 5/18/6
f 1/1/1 3/2/1 2/3/1
f 4/4/2 2/5/2 5/6/2
f 6/7/3 5/8/3 7/9/3
f 8/10/4 7/11/4 3/12/4
f 2/13/5 7/14/5 5/15/5
f 4/16/6 8/17/6 1/18/6
f 8/19/1 3/2/1 1/1/1
f 1/20/2 2/5/2 4/4/2
f 4/21/3 5/8/3 6/7/3
f 6/22/4 7/11/4 8/10/4
f 3/23/5 7/14/5 2/13/5
f 6/24/6 8/17/6 4/16/6

File diff suppressed because it is too large Load Diff

View File

@ -69,13 +69,13 @@
</object>
<light>
<xOffset>0.0</xOffset>
<yOffset>2</yOffset>
<yOffset>3</yOffset>
<zOffset>0.0</zOffset>
<rColour>1.0</rColour>
<gColour>1.0</gColour>
<bColour>1.0</bColour>
<gColour>0.9</gColour>
<bColour>0.3</bColour>
<intensity>4.0</intensity>
<flameOffset>-1.2</flameOffset>
<flameOffset>-1.5</flameOffset>
</light>
</composition>
@ -145,7 +145,7 @@
<xRot>0.0</xRot>
<yRot>0.0</yRot>
<zRot>0.0</zRot>
<scale>1.0</scale>
<scale>1.044</scale>
<mass>0.5</mass>
</object>
<object>
@ -226,7 +226,7 @@
<yOffset>20.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>0.0</yRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
@ -243,7 +243,7 @@
<yOffset>20.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<yRot>0.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
@ -264,7 +264,7 @@
<yOffset>20.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>0.0</yRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
@ -314,7 +314,7 @@
<yOffset>20.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<yRot>0.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
@ -364,7 +364,7 @@
<yOffset>25.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>0.0</yRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.48</scale>
<mass>0.0</mass>
@ -381,7 +381,7 @@
<yOffset>25.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<yRot>0.0</yRot>
<zRot>0.0</zRot>
<scale>1.48</scale>
<mass>0.0</mass>
@ -415,7 +415,7 @@
<yOffset>25.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>0.0</yRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>100.0</mass>
@ -432,10 +432,10 @@
<yOffset>25.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<yRot>0.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
<mass>100.0</mass>
</object>
</composition>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -10,9 +10,9 @@ function trigger(objectToChange)
end
local strength = 100
local xPos = 81.5
local yPos = 35
local zPos = 17.5
local xPos = 17.5
local yPos = 33
local zPos = 81.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenFirstDoorUndo = false

View File

@ -10,9 +10,9 @@ function trigger(objectToChange)
end
local strength = 100
local xPos = 81.5
local xPos = 17.5
local yPos = 25
local zPos = 17.5
local zPos = 81.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenFirstDoor = false

View File

@ -0,0 +1,38 @@
local global = require( "global" )
if(global.triggeredOpenSecondDoor1 == nil) then
global.triggeredOpenSecondDoor1 = false
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.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
end
end
print("openSecondDoor1")
end
end

View File

@ -0,0 +1,38 @@
local global = require( "global" )
if(global.triggeredOpenSecondDoor2 == nil) then
global.triggeredOpenSecondDoor2 = false
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.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
end
end
print("openSecondDoor2")
end
end

View File

@ -0,0 +1,38 @@
local global = require( "global" )
if(global.triggeredOpenSecondDoor3 == nil) then
global.triggeredOpenSecondDoor3 = false
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.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
end
end
print("openSecondDoor3")
end
end

View File

@ -0,0 +1,38 @@
local global = require( "global" )
if(global.triggeredOpenSecondDoor4 == nil) then
global.triggeredOpenSecondDoor4 = false
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.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
end
end
print("openSecondDoor4")
end
end

View File

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

View File

@ -0,0 +1,23 @@
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,7 +1,10 @@
#version 150
in vec3 fColor;
out vec4 oColor;
void main() {
oColor = vec4(1.0, 0.0, 0.0, 0.5);
oColor = vec4(fColor, 1.0);
}

View File

@ -2,19 +2,83 @@
uniform mat4 viewProjectionMatrix;
uniform float time;
uniform bool bottom;
uniform bool left;
layout(points) in;
layout(triangle_strip, max_vertices = 3) out;
layout(triangle_strip, max_vertices = 146) out;
in vec3 Color[];
out vec3 fColor;
const float PI = 3.1415926;
const float transition_point = 1.178097;
const float sin_p1 = 0.4;
const float sin_p2 = 2;
const float ex_p1 = 1.093;
const float ex_p2 = 1.9996;
const float begin = 0;
const float end = 2.5;
float radiusFunction(float x) {
if (x < transition_point) {
return sin_p1 * sin(sin_p2 * x);
}
else {
return exp(ex_p1 - ex_p2 * x);
}
}
void main() {
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * vec4(-0.5, 0.0, 0.0, 0.0);
EmitVertex();
fColor = Color[0];
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * vec4(0.5, 0.0, 0.0, 0.0);
EmitVertex();
float resolution = 8.0;
float step = abs(end-begin)/resolution/2.0;
float i = 0.0;
float render_end = 0.0;
if (bottom) {
i = begin;
render_end = (end-begin)/2.0+step;
}
else {
i = (end-begin)/2.0;
render_end = end;
}
for (i; i<render_end; i+=step) {
float downRadius = radiusFunction(i);
float upRadius = radiusFunction(i+step);
float circle_end = 0.0;
int j = 0;
if (left) {
j = 0;
circle_end = resolution/2.0;
}
else {
j = int(resolution/2.0);
circle_end = resolution;
}
for (j; j<circle_end; j++) {
float leftAngle = PI * 2.0 / resolution * j;
float rightAngle = PI * 2.0 / resolution * (j+1);
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * vec4(0.0, 2.0 + sin(time), 0.0, 0.0);
EmitVertex();
vec4 offset = vec4(cos(rightAngle) * downRadius, i, -sin(rightAngle) * downRadius, 0.0);
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
EmitVertex();
offset = vec4(cos(rightAngle) * upRadius, i + step, -sin(rightAngle) * upRadius, 0.0);
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
EmitVertex();
offset = vec4(cos(leftAngle) * downRadius, i, -sin(leftAngle) * downRadius, 0.0);
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
EmitVertex();
offset = vec4(cos(leftAngle) * upRadius, i + step, -sin(leftAngle) * upRadius, 0.0);
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
EmitVertex();
EndPrimitive();
}
}
EndPrimitive();
}

View File

@ -3,7 +3,11 @@
uniform mat4 viewProjectionMatrix;
in vec3 aPosition;
in vec3 aColor;
out vec3 Color;
void main () {
Color = aColor;
gl_Position = viewProjectionMatrix * vec4(aPosition, 1.0);
}

View File

@ -0,0 +1,35 @@
#version 150
in vec2 vTexCoord;
uniform sampler2D flame_fbo;
uniform sampler2D light_fbo;
uniform int windowSizeX;
uniform int windowSizeY;
out vec4 oColor;
const float lookup_offset = 4.0;
void main() {
vec4 color = texture(flame_fbo, vTexCoord).rgba;
if (color == vec4(0.0, 0.0, 0.0, 1.0)) {
oColor = texture(light_fbo, vTexCoord).rgba;
}
else {
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) {
vec4 flame_pixel = texture(flame_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);
vec4 light_pixel = 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);
if (flame_pixel == vec4(0.0, 0.0, 0.0, 1.0)) {
sum += light_pixel;
}
else {
sum += mix(flame_pixel, light_pixel, 0.7);
}
}
}
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

@ -3,12 +3,16 @@
in vec3 vNormal;
in vec2 vTexCoord;
in vec4 fragPosition;
in vec4 shadowCoord;
in vec4 shadowCoord0;
in vec4 shadowCoord1;
in vec4 shadowCoord2;
out vec4 oColor;
uniform sampler2D uTexture;
uniform sampler2DShadow shadowMap;
uniform sampler2DShadow shadowMap_directional0;
uniform sampler2DShadow shadowMap_directional1;
uniform sampler2DShadow shadowMap_directional2;
uniform samplerCubeShadow shadowMap_cube0;
uniform samplerCubeShadow shadowMap_cube1;
uniform samplerCubeShadow shadowMap_cube2;
@ -56,12 +60,13 @@ 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]/700.0, shadowCoord.z - bias)));
visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
}
if (visibility == 1.0-(directionalIntensity/16)*4)
{
@ -69,7 +74,7 @@ float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
}
else if (visibility != 1.0) {
for (int i=0; i<12; i++) {
visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/700.0, shadowCoord.z - bias)));
visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
}
}
return visibility;
@ -82,7 +87,6 @@ float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) {
float compValue = 0.5*(-A*length(lightDirection) + B)/length(lightDirection) + 0.5;
float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0)));
bias = clamp(bias, 0.0, 0.01);
//return texture(shadowMap, vec4(lightDirection , length(lightDirection)/farPlane - bias));
return texture(shadowMap, vec4(lightDirection , compValue - bias));
}
@ -102,7 +106,28 @@ void main()
// direction lighting
if(length(directionalLightVector)>0.0f) {
vec3 directionalVector = normalize(directionalLightVector);
float directionalVisibility = sampleDirectionalShadow(shadowMap, shadowCoord);
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, 0.001);
}
else if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.0) {
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, 0.002);
}
}
else if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.0) {
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, 0.01);
}
diffuseColor += clamp(dot(normalize(vNormal), directionalVector)
*diffuseFactor*directionalIntensity*directionalColor, 0.0, 1.0)*directionalVisibility;
vec3 cameraVector = normalize(camera - vec3(fragPosition));

View File

@ -11,13 +11,17 @@ in vec2 aTexCoord;
out vec3 vNormal;
out vec2 vTexCoord;
out vec4 fragPosition;
out vec4 shadowCoord;
out vec4 shadowCoord0;
out vec4 shadowCoord1;
out vec4 shadowCoord2;
void main()
{
fragPosition = modelMatrix * vec4(aPosition, 1.0);
vNormal = inverse(transpose(mat3(modelMatrix))) * aNormal;
vTexCoord = aTexCoord;
shadowCoord = shadowMVPs[0] * vec4(aPosition, 1.0);
shadowCoord0 = shadowMVPs[0] * vec4(aPosition, 1.0);
shadowCoord1 = shadowMVPs[1] * vec4(aPosition, 1.0);
shadowCoord2 = shadowMVPs[2] * vec4(aPosition, 1.0);
gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 909 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB

View File

@ -2,40 +2,55 @@
from math import pi, sin, cos, exp
from numpy import arange
from collections import namedtuple
# f(x) = p1 * sin(p2 * x)
Result = namedtuple("Result", ["p1", "p2", "error"])
parameter_sin_1=3
parameter_sin_2=0.3
def main():
# f(x) = p1 * sin(p2 * x)
transition_point = (1/parameter_sin_2) * pi * 0.75
parameter_sin_1=2
parameter_sin_2=0.5
sin_value = parameter_sin_1 * sin(parameter_sin_2 * transition_point)
transition_point = (1/parameter_sin_2) * pi * 0.75
derived_sin_value = parameter_sin_1 * parameter_sin_2 * cos(parameter_sin_2 * transition_point)
sin_value = parameter_sin_1 * sin(parameter_sin_2 * transition_point)
#g(x) = e^(p1 - p2 * x)
parameter_ex_p1 = list(arange(0,10, 0.01))
parameter_ex_p2 = list(arange(0, 1, 0.00001))
derived_sin_value = parameter_sin_1 * parameter_sin_2 * cos(parameter_sin_2 * transition_point)
best_parameter_ex_p1 = -1
best_parameter_ex_p2 = -1
value = exp(parameter_ex_p1[0] - parameter_ex_p2[0] * transition_point)
derived_value = - parameter_ex_p2[0] * exp(parameter_ex_p1[0] - parameter_ex_p2[0] * transition_point)
value_error = abs(value - sin_value)
derived_value_error = abs(derived_value - derived_sin_value)
#g(x) = e^(p1 - p2 * x)
result = Result(10, 10, 1)
step = 10
while (result.error > 0.0001):
parameter_ex_p1 = list(arange(result.p1 - step, result.p1 + step, step/10))
parameter_ex_p2 = list(arange(result.p2 - step, result.p2 + step, step/100))
step /= 10
for p1 in parameter_ex_p1:
for p2 in parameter_ex_p2:
value = exp(p1 - p2 * transition_point)
derived_value = - p2 * exp(p1 - p2 * transition_point)
if abs(value - sin_value) < value_error and abs(derived_value - derived_sin_value) < derived_value_error:
value_error = abs(value -sin_value)
derived_value_error = abs(derived_value - derived_sin_value)
best_parameter_ex_p1 = p1
best_parameter_ex_p2 = p2
result = calculate(parameter_ex_p1, parameter_ex_p2, transition_point, sin_value, derived_sin_value)
print("p1: " + str(best_parameter_ex_p1))
print("p2: " + str(best_parameter_ex_p2))
print("value error: " + str(value_error))
print("derived value error: " + str(derived_value_error))
print("sin p1: " + str(parameter_sin_1))
print("sin p2: " + str(parameter_sin_2))
print("transition point: " + str(transition_point))
print("p1: " + str(result.p1))
print("p2: " + str(result.p2))
print("combined error: " + str(result.error))
def calculate(parameter_ex_p1, parameter_ex_p2, transition_point, sin_value, derived_sin_value):
best_parameter_ex_p1 = -1
best_parameter_ex_p2 = -1
best_combined_error = 100
for p1 in parameter_ex_p1:
for p2 in parameter_ex_p2:
value = exp(p1 - p2 * transition_point)
derived_value = - p2 * exp(p1 - p2 * transition_point)
error = abs(value - sin_value)
derived_error = abs(derived_value - derived_sin_value)
combined_error = error + derived_error
if combined_error < best_combined_error:
best_parameter_ex_p1 = p1
best_parameter_ex_p2 = p2
best_combined_error = combined_error
return Result(best_parameter_ex_p1, best_parameter_ex_p2, best_combined_error)
if __name__ == "__main__":
main()

View File

@ -27,6 +27,33 @@ Graphics::Graphics() {
void Graphics::init(Level* level) {
// save Level
this->level = level;
// OpenGL state:
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glEnable( GL_DEPTH_TEST );
glEnable(GL_BLEND);
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;
@ -51,6 +78,7 @@ void Graphics::init(Level* level) {
flame_positions_ab = SharedArrayBuffer(new ArrayBuffer());
flame_positions_ab->defineAttribute("aPosition", GL_FLOAT, 3);
flame_positions_ab->defineAttribute("aColor", GL_FLOAT, 3);
flame_positions = SharedVertexArrayObject(new VertexArrayObject());
flame_positions->setMode(GL_POINTS);
flame_positions->attachAllAttributes(flame_positions_ab);
@ -58,26 +86,43 @@ void Graphics::init(Level* level) {
flameShader = ShaderProgramCreator("flame")
.attributeLocations(flame_positions->getAttributeLocations()).create();
depthTexture = SharedTexture2D( new Texture2D(windowSize, GL_DEPTH_COMPONENT24));
depthTexture->setMinFilter(GL_NEAREST);
depthTexture->setMagFilter(GL_NEAREST);
depthTexture->setWrapS(GL_CLAMP_TO_EDGE);
depthTexture->setWrapT(GL_CLAMP_TO_EDGE);
depthTexture->setCompareMode(GL_COMPARE_REF_TO_TEXTURE);
framebuffer = SharedFrameBufferObject(new FrameBufferObject());
framebuffer->setDepthTexture(depthTexture);
framebuffer->validate();
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 < 12) {
printf("You need at least 12 texture units to run this application. Exiting\n");
if (number_of_texture_units < 16) {
printf("You need at least 16 texture units to run this application. Exiting\n");
exit(-1);
}
// always generate and bind 32 cube maps, because otherwise the shader won't work
depth_directionalMaps = std::vector<SharedTexture2D>(3);
framebuffer_directional = std::vector<SharedFrameBufferObject>(3);
for (unsigned int i = 0; i<depth_directionalMaps.size(); i++) {
depth_directionalMaps.at(i) = SharedTexture2D( new Texture2D(windowSize, GL_DEPTH_COMPONENT24));
depth_directionalMaps.at(i)->setMinFilter(GL_NEAREST);
depth_directionalMaps.at(i)->setMagFilter(GL_NEAREST);
depth_directionalMaps.at(i)->setWrapS(GL_CLAMP_TO_EDGE);
depth_directionalMaps.at(i)->setWrapT(GL_CLAMP_TO_EDGE);
depth_directionalMaps.at(i)->setCompareMode(GL_COMPARE_REF_TO_TEXTURE);
}
for (unsigned int i = 0; i<framebuffer_directional.size(); i++) {
framebuffer_directional.at(i) = SharedFrameBufferObject(new FrameBufferObject());
framebuffer_directional.at(i)->setDepthTexture(depth_directionalMaps.at(i));
framebuffer_directional.at(i)->validate();
}
lightingShader->use();
for (unsigned int i = 0; i<depth_directionalMaps.size(); i++) {
// start with texture unit 1 because the first is reserved for the texture
lightingShader->setTexture("shadowMap_directional" + std::to_string(i), depth_directionalMaps.at(i), i+1);
}
// always generate and bind 10 cube maps, because otherwise the shader won't work
depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(10);
for (unsigned int i = 0; i<depth_cubeMaps.size(); i++) {
depth_cubeMaps.at(i) = SharedTextureCubeMap(new TextureCubeMap(glm::vec2(cube_size, cube_size), GL_DEPTH_COMPONENT24));
@ -90,16 +135,51 @@ void Graphics::init(Level* level) {
framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject());
lightingShader->use();
lightingShader->setTexture("shadowMap", depthTexture, 1);
if (level->getLights()->size() > 0) {
for(unsigned int i = 0; i<depth_cubeMaps.size(); i++){
// start with texture unit 2 because the first two are used by the texture and the directional shadow map
lightingShader->setTexture("shadowMap_cube" + std::to_string(i), depth_cubeMaps.at(i), i+2);
// 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);
}
}
flame_fbo_color_texture = SharedTexture2D(new Texture2D(windowSize, GL_RGBA8));
flame_fbo_color_texture->setMinFilter(GL_NEAREST);
flame_fbo_color_texture->setMagFilter(GL_NEAREST);
flame_fbo_color_texture->setWrapS(GL_CLAMP_TO_BORDER);
flame_fbo_color_texture->setWrapT(GL_CLAMP_TO_BORDER);
flame_fbo_depth_texture = SharedTexture2D(new Texture2D(windowSize, GL_DEPTH_COMPONENT24));
flame_fbo_depth_texture->setMinFilter(GL_NEAREST);
flame_fbo_depth_texture->setMagFilter(GL_NEAREST);
flame_fbo_depth_texture->setWrapS(GL_CLAMP_TO_BORDER);
flame_fbo_depth_texture->setWrapT(GL_CLAMP_TO_BORDER);
framebuffer_flames = SharedFrameBufferObject(new FrameBufferObject());
framebuffer_flames->attachColorTexture("oColor", flame_fbo_color_texture);
framebuffer_flames->setDepthTexture(flame_fbo_depth_texture);
framebuffer_flames->setClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
framebuffer_flames->validate();
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_DEPTH_COMPONENT24));
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("flame_fbo", flame_fbo_color_texture, 15);
flamePostShader->setTexture("light_fbo", light_fbo_color_texture, 16);
flamePostShader->setUniform("windowSizeX", int(windowSize.x));
flamePostShader->setUniform("windowSizeY", int(windowSize.y));
updateClosestLights();
}
@ -137,23 +217,38 @@ void Graphics::render(double time)
}
}
}
// render depth texture for sun
// render depth textures for sun
depthShader->use();
glViewport(0, 0, windowSize.x, windowSize.y);
// far pass
framebuffer->bind();
glClear(GL_DEPTH_BUFFER_BIT);
std::vector<glm::mat4> depthViewProjectionMatrices = std::vector<glm::mat4>(framebuffer_directional.size());
glm::vec3 sunVector = (level->getCameraCenter()->getPosition() + level->getDirectionalLight()->getPosition());
glm::mat4 depthViewProjectionMatrix = glm::ortho<float>(-farPlane/1.5f, farPlane/1.5f, -farPlane/1.5f, farPlane/1.5f, -farPlane/1.5f, farPlane/1.5f) *
glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
level->render(depthShader, false, &depthViewProjectionMatrix);
if (!framebuffer->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
for (unsigned int i = 0; i<framebuffer_directional.size(); i++) {
framebuffer_directional.at(i)->bind();
glClear(GL_DEPTH_BUFFER_BIT);
float projection_size = 0.0f;
switch(i) {
case 0:
projection_size = 10.0f;
break;
case 1:
projection_size = 30.0f;
break;
case 2:
projection_size = farPlane/1.5f;
break;
}
depthViewProjectionMatrices.at(i) = glm::ortho<float>(-projection_size, projection_size, -projection_size, projection_size, -farPlane/1.5f, farPlane/1.5f) *
glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
level->render(depthShader, false, &depthViewProjectionMatrices.at(i));
if (!framebuffer_directional.at(i)->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
}
}
// final render pass
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// lighting render pass
framebuffer_light->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
lightingShader->use();
@ -172,12 +267,17 @@ void Graphics::render(double time)
// convert texture to homogenouse coordinates
glm::mat4 biasMatrix(
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0
);
glm::mat4 depthBiasVP = biasMatrix*depthViewProjectionMatrix;
std::vector<glm::mat4> depthBiasVPs = std::vector<glm::mat4>(depthViewProjectionMatrices.size());
for (unsigned int i = 0; i<depthBiasVPs.size(); i++) {
depthBiasVPs.at(i) = biasMatrix * depthViewProjectionMatrices.at(i);
}
lightingShader->setUniform("farPlane", farPlane);
// set fog Parameters
@ -191,17 +291,39 @@ void Graphics::render(double time)
//set view and projection matrix
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);
std::vector<glm::mat4> shadowVPs = std::vector<glm::mat4>();
shadowVPs.push_back(depthBiasVP);
// render the level
level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs);
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
// cull faces to get consistent color while using alpha
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// draw flames on top
framebuffer_flames->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
flameShader->use();
flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
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();
glDisable(GL_CULL_FACE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
flamePostShader->use();
fullscreen_quad->render();
}
bool Graphics::compareLightDistances(Light a, Light b) {
@ -262,22 +384,32 @@ void Graphics::updateLights() {
lightingShader->setUniform("directionalIntensity",
level->getDirectionalLight()->getIntensity());
}
float flamePositionsData[closestLights.size() * 3] = {};
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) {
flamePositionsData[flameIndex + 0] = closestLights.at(i).getPosition().x;
flamePositionsData[flameIndex + 1] = closestLights.at(i).getPosition().y + closestLights.at(i).getFlameYOffset();
flamePositionsData[flameIndex + 2] = closestLights.at(i).getPosition().z;
flameIndex+=3;
flameData[flameIndex + 0] = closestLights.at(i).getPosition().x;
flameData[flameIndex + 1] = closestLights.at(i).getPosition().y + closestLights.at(i).getFlameYOffset();
flameData[flameIndex + 2] = closestLights.at(i).getPosition().z;
flameData[flameIndex + 3] = closestLights.at(i).getColour().r;
flameData[flameIndex + 3] = closestLights.at(i).getColour().r;
flameData[flameIndex + 4] = closestLights.at(i).getColour().g;
flameData[flameIndex + 5] = closestLights.at(i).getColour().b;
flameIndex+=6;
}
}
flame_positions_ab->setDataElements(flameIndex, flamePositionsData);
flame_positions_ab->setDataElements(flameIndex, flameData);
}
void Graphics::resize(glm::uvec2 windowSize) {
this->windowSize = windowSize;
depthTexture->resize(glm::vec2(windowSize.x, windowSize.y));
for (unsigned int i = 0; i<depth_directionalMaps.size(); i++) {
depth_directionalMaps.at(i)->resize(glm::vec2(windowSize.x, windowSize.y));
}
flame_fbo_color_texture->resize(windowSize);
flame_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,25 @@ 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;
ACGL::OpenGL::SharedTexture2D depthTexture;
ACGL::OpenGL::SharedFrameBufferObject framebuffer;
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_flames;
SharedTexture2D flame_fbo_color_texture;
SharedTexture2D flame_fbo_depth_texture;
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

@ -56,8 +56,8 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
}
}
void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool sPressed, bool dPressed,bool kPressed, bool lPressed) {
physics.takeUpdateStep(runTime);
void Level::update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool sPressed, bool dPressed,bool kPressed, bool lPressed) {
physics.takeUpdateStep(runTimeSinceLastUpdate);
// Ignore first two mouse updates, because they are incorrect
// DON'T try to move this functionallity elsewhere
@ -102,9 +102,11 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre
skydome->setPosition(glm::vec3(cameraCenter->getPosition().x,
0.0f, cameraCenter->getPosition().z));
for(unsigned int i = 0; i<triggers.size(); i++) {
triggers.at(i).triggerUpdate();
if (runTime > 2.0f) {
for(unsigned int i = 0; i<triggers.size(); i++) {
triggers.at(i).triggerUpdate();
}
}
}

View File

@ -24,7 +24,7 @@ class Level {
Level();
~Level();
void load();
void update(float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed, bool kPressed, bool lPressed);
void update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed, bool kPressed, bool lPressed);
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs=0);
glm::vec3 getAmbientLight();

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");

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);

12
main.cc
View File

@ -81,7 +81,7 @@ bool createWindow()
setGLFWHintsForOpenGLVersion( ACGL_OPENGL_VERSION );
// activate multisampling (second parameter is the number of samples):
//glfwWindowHint( GLFW_SAMPLES, 8 );
glfwWindowHint( GLFW_SAMPLES, 4);
// request an OpenGL debug context:
glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, true );
@ -126,12 +126,6 @@ int main( int argc, char *argv[] )
// Enable vertical sync (on cards that support it) with parameter 1 - 0 means off
glfwSwapInterval( 0 );
// OpenGL state:
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glEnable( GL_DEPTH_TEST );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
app.init();
int frameCount = 0;
@ -167,13 +161,13 @@ int main( int argc, char *argv[] )
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
glfwSetCursorPos(window, app.getGraphics()->getWindowSize().x/2, app.getGraphics()->getWindowSize().y/2);
app.getLevel()->update(now - lastUpdate,
app.getLevel()->update(now - lastUpdate, now,
glm::vec2((float)ypos-app.getGraphics()->getWindowSize().y/2,
(float)xpos-app.getGraphics()->getWindowSize().x/2),
stateW == GLFW_PRESS,stateA == GLFW_PRESS,stateS == GLFW_PRESS,stateD == GLFW_PRESS,stateK == GLFW_PRESS,stateL == GLFW_PRESS);
}
else {
app.getLevel()->update(now - lastUpdate, glm::vec2(0.0f, 0.0f), false, false, false, false,false,false);
app.getLevel()->update(now - lastUpdate, now, glm::vec2(0.0f, 0.0f), false, false, false, false,false,false);
if (app.isLocked()) {
app.ignoredOneMouseUpdate();
}

View File

@ -18,11 +18,11 @@ void Terrain::load() {
if (error) {
std::cout << "Decoder error " << error << " from Terrain::load: " << lodepng_error_text(error) << std::endl;
}
this->heightmap = new float*[this->heightmapHeight]; //initialize the heightmap
for(unsigned int rowNum = 0; rowNum < this->heightmapHeight; rowNum++){ //read in the heightmap
this->heightmap[rowNum] = new float[this->heightmapWidth];
for(unsigned int columnNum = 0; columnNum < this->heightmapWidth; columnNum++){
this->heightmap[rowNum][columnNum] = (float)(image[(rowNum*heightmapWidth+columnNum)*4]) / 6; //<--heightmap is scaled here
this->heightmap = new float*[this->heightmapWidth]; //initialize the heightmap
for(unsigned int columnNum = 0; columnNum < this->heightmapWidth; columnNum++){ //read in the heightmap
this->heightmap[columnNum] = new float[this->heightmapHeight];
for(unsigned int rowNum = 0; rowNum < this->heightmapHeight; rowNum++){
this->heightmap[columnNum][rowNum] = (float)(image[(rowNum*heightmapWidth+columnNum)*4]) / 6; //<--heightmap is scaled here
}
}
this->makeTriangleMesh();

View File

@ -7,7 +7,7 @@
#include "model.hh"
class Terrain {
public:
Terrain(std::string levelNum);
Terrain(std::string heightmapFilePath);
Terrain();
~Terrain();
void load();

View File

@ -1,4 +1,5 @@
#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) {
this->position=position;
@ -6,6 +7,11 @@ Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* obje
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");