Changed flame function to cosine to be able to rotate it properly. Also changed corresponding parameters.

This commit is contained in:
Faerbit 2015-03-08 23:13:16 +01:00
parent 528108e7bc
commit eda952df70
10 changed files with 35 additions and 29 deletions

View File

@ -75,7 +75,7 @@
<gColour>0.9</gColour>
<bColour>0.3</bColour>
<intensity>4.0</intensity>
<flameOffset>-1.5</flameOffset>
<flameOffset>-0.5</flameOffset>
<flameHeight>1.0</flameHeight>
<flameWidth>1.0</flameWidth>
</light>

View File

@ -29,7 +29,7 @@ function trigger(objectToChange)
local yPos = 25.0
local zPos = 54.5
level:preloadLightPosition(xPos, yPos, zPos)
level:addLightByParameters(0.2, 0.9, 0.0, 4.0, -3.5, 1.3, 2.3)
level:addLightByParameters(0.2, 0.9, 0.0, 4.0, -2.5, 1.3, 2.3)
print("openSecondDoor1")
end
end

View File

@ -29,7 +29,7 @@ function trigger(objectToChange)
local yPos = 25.0
local zPos = 26.5
level:preloadLightPosition(xPos, yPos, zPos)
level:addLightByParameters(0.2, 0.9, 0.0, 4.0, -3.5, 1.3, 2.3)
level:addLightByParameters(0.2, 0.9, 0.0, 4.0, -2.5, 1.3, 2.3)
print("openSecondDoor2")
end
end

View File

@ -29,7 +29,7 @@ function trigger(objectToChange)
local yPos = 25.0
local zPos = 26.5
level:preloadLightPosition(xPos, yPos, zPos)
level:addLightByParameters(0.2, 0.9, 0.0, 4.0, -3.5, 1.3, 2.3)
level:addLightByParameters(0.2, 0.9, 0.0, 4.0, -2.5, 1.3, 2.3)
print("openSecondDoor3")
end
end

View File

@ -38,7 +38,7 @@ function trigger(objectToChange)
local yPos = 25.0
local zPos = 54.5
level:preloadLightPosition(xPos, yPos, zPos)
level:addLightByParameters(0.2, 0.9, 0.0, 4.0, -3.5, 1.3, 2.3)
level:addLightByParameters(0.2, 0.9, 0.0, 4.0, -2.5, 1.3, 2.3)
print("openSecondDoor4")
end
end

View File

@ -12,37 +12,37 @@ in vec3 Color[];
out vec3 fColor;
const float PI = 3.1415926;
const float transition_point_1 = 1.178097;
const float sin_p1_1 = 0.4;
const float sin_p2_1 = 2;
const float ex_p1_1 = 1.093;
const float ex_p2_1 = 1.9996;
const float begin_1 = 0;
const float end_1 = 2.5;
const float transition_point_1 = 0.486946;
const float cos_p1_1 = 0.35;
const float cos_p2_1 = 2.0;
const float ex_p1_1 = -0.193;
const float ex_p2_1 = 2.9426;
const float begin_1 = -0.785398;
const float end_1 = 1.5;
const float transition_point_2 = 1.570796;
const float sin_p1_2 = 0.2;
const float sin_p2_2 = 1.5;
const float ex_p1_2 = 0.4;
const float ex_p2_2 = 1.5;
const float begin_2 = 0;
const float end_2 = 3;
const float transition_point_2 = 0.600598;
const float cos_p1_2 = 0.3;
const float cos_p2_2 = 1.7;
const float ex_p1_2 = -0.19;
const float ex_p2_2 = 2.762;
const float begin_2 = -0.923998;
const float end_2 = 2;
float flickerFunction() {
return pow(0.6*sin(20.0*time), 2) + 0.4;
return pow(sin(20.0*time + gl_in[0].gl_Position.x*gl_in[0].gl_Position.z), 2);
}
float radiusFunction(float x) {
float value_1 = 0.0;
float value_2 = 0.0;
if (x < transition_point_1) {
value_1 = sin_p1_1 * sin(sin_p2_1 * x);
value_1 = cos_p1_1 * cos(cos_p2_1 * x);
}
else {
value_1 = exp(ex_p1_1 - ex_p2_1 * x);
}
if (x < transition_point_2) {
value_2 = sin_p1_2 * sin(sin_p2_2 * x);
value_2 = cos_p1_2 * cos(cos_p2_2 * x);
}
else {
value_2 = exp(ex_p1_2 - ex_p2_2 * x);
@ -53,7 +53,7 @@ float radiusFunction(float x) {
void main() {
fColor = Color[0];
float resolution = 8.0;
float resolution = 6.0;
float this_begin = mix(begin_1, begin_2, flickerFunction());
float this_end = mix(end_1, end_2, flickerFunction());
float step = abs(this_end-this_begin)/resolution/2.0;

View File

@ -1,6 +1,7 @@
#version 150
uniform mat4 viewProjectionMatrix;
uniform vec2 skew;
in vec3 aPosition;
in vec3 aColor;

View File

@ -64,8 +64,8 @@ vec2 poissonDisk[16] = vec2[](
vec2( 0.14383161, -0.14100790 )
);
float flickerFunction() {
return pow(0.6*sin(20.0*time), 2) + 0.4;
float flickerFunction(int index) {
return 0.7*pow(sin(20.0*time + lightSources[index].x*lightSources[index].z), 2) + 0.3;
}
float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias ) {
@ -187,7 +187,7 @@ void main()
vec3 lightVector = normalize(lightSources[i]-vec3(fragPosition));
float intensity = 0.0f;
if (isFlame[i] == true) {
intensity = clamp(exp(-(1/(lightIntensities[i] + flickerFunction()))*distance), 0.0, 1.0);
intensity = clamp(exp(-(1/(lightIntensities[i] + flickerFunction(i)))*distance), 0.0, 1.0);
}
else {
intensity = clamp(exp(-(1/lightIntensities[i])*distance), 0.0, 1.0);

View File

@ -38,16 +38,21 @@ void Flame::render(SharedShaderProgram shader, glm::mat4 viewProjectionMatrix, f
0.0f, tan(skewing.y), 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
if (!withColor) {
modelMatrix = skewMatrixX * skewMatrixZ * glm::scale<float>(size * glm::vec3(1.1f));
modelMatrix = skewMatrixX * skewMatrixZ * glm::scale<float>(size * glm::vec3(1.1f))
* glm::rotate(skewing.x, glm::vec3(1.0f, 0.0f, 0.0f))
* glm::rotate(skewing.y, glm::vec3(0.0f, 0.0f, 1.0f));
}
else {
modelMatrix = skewMatrixX * skewMatrixZ * glm::scale<float>(size);
modelMatrix = skewMatrixX * skewMatrixZ * glm::scale<float>(size)
* glm::rotate(skewing.x, glm::vec3(1.0f, 0.0f, 0.0f))
* glm::rotate(skewing.y, glm::vec3(0.0f, 0.0f, 1.0f));
}
glm::mat4 modelViewProjectionMatrix = viewProjectionMatrix * modelMatrix;
shader->setUniform("modelViewProjectionMatrix", modelViewProjectionMatrix);
shader->setUniform("viewProjectionMatrix", viewProjectionMatrix);
shader->setUniform("withColor", withColor);
shader->setUniform("time", time);
shader->setUniform("skew", skewing);
shader->setUniform("bottom", true);
shader->setUniform("left", true);
vao->render();

View File

@ -292,7 +292,7 @@ void Graphics::render(double time)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//wind
glm::vec2 wind = glm::vec2(-0.4f, 0.3f);
glm::vec2 wind = glm::vec2(0.0f, 0.0f);
//set view and projection matrix
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);