From b953ae878bfd72cf2cfff70da0e8c74148d4bad2 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 8 Mar 2015 01:59:38 +0100 Subject: [PATCH] Added flickering to lighting shader. --- data/shader/phong.fsh | 13 ++++++++++++- graphics.cc | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/data/shader/phong.fsh b/data/shader/phong.fsh index a2ed89e..e22c325 100644 --- a/data/shader/phong.fsh +++ b/data/shader/phong.fsh @@ -37,6 +37,7 @@ uniform float directionalIntensity; uniform vec3 lightSources[32]; uniform vec3 lightColors[32]; uniform float lightIntensities[32]; +uniform bool isFlame[32]; uniform float farPlane; uniform vec4 fogColor; uniform vec3 cameraCenter; @@ -63,6 +64,10 @@ vec2 poissonDisk[16] = vec2[]( vec2( 0.14383161, -0.14100790 ) ); +float flickerFunction() { + return sin(time); +} + float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias ) { float visibility = 1.0; const float stretching = 650.0; @@ -178,7 +183,13 @@ void main() pointVisibility = samplePointShadow(shadowMap_cube9, lightDirection); } vec3 lightVector = normalize(lightSources[i]-vec3(fragPosition)); - float intensity = clamp(exp(-(1/lightIntensities[i])*distance), 0.0, 1.0); + float intensity = 0.0f; + if (isFlame[i] == true) { + intensity = clamp(exp(-(1/(lightIntensities[i] + flickerFunction()))*distance), 0.0, 1.0); + } + else { + intensity = clamp(exp(-(1/lightIntensities[i])*distance), 0.0, 1.0); + } diffuseColor += clamp(dot(normalize(vNormal), lightVector) *diffuseFactor*intensity*lightColors[i], 0.0, 1.0)*pointVisibility; vec3 cameraVector = normalize(camera - vec3(fragPosition)); diff --git a/graphics.cc b/graphics.cc index 3ffd1a7..2310538 100644 --- a/graphics.cc +++ b/graphics.cc @@ -440,12 +440,18 @@ void Graphics::updateLights() { lightingShader->setUniform("directionalIntensity", level->getDirectionalLight()->getIntensity()); } + bool isFlame[closestLights.size()]; closestFlames = std::vector(); for (unsigned int i = 0; igetUniformLocation("isFlame"), sizeof(isFlame), (GLint*) isFlame); } void Graphics::resize(glm::uvec2 windowSize) {