Added flickering to lighting shader.

This commit is contained in:
Faerbit 2015-03-08 01:59:38 +01:00
parent b68015a6c4
commit 93f87cc9c5
2 changed files with 18 additions and 1 deletions

View File

@ -37,6 +37,7 @@ uniform float directionalIntensity;
uniform vec3 lightSources[32]; uniform vec3 lightSources[32];
uniform vec3 lightColors[32]; uniform vec3 lightColors[32];
uniform float lightIntensities[32]; uniform float lightIntensities[32];
uniform bool isFlame[32];
uniform float farPlane; uniform float farPlane;
uniform vec4 fogColor; uniform vec4 fogColor;
uniform vec3 cameraCenter; uniform vec3 cameraCenter;
@ -63,6 +64,10 @@ vec2 poissonDisk[16] = vec2[](
vec2( 0.14383161, -0.14100790 ) vec2( 0.14383161, -0.14100790 )
); );
float flickerFunction() {
return sin(time);
}
float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias ) { float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias ) {
float visibility = 1.0; float visibility = 1.0;
const float stretching = 650.0; const float stretching = 650.0;
@ -178,7 +183,13 @@ void main()
pointVisibility = samplePointShadow(shadowMap_cube9, lightDirection); pointVisibility = samplePointShadow(shadowMap_cube9, lightDirection);
} }
vec3 lightVector = normalize(lightSources[i]-vec3(fragPosition)); 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) diffuseColor += clamp(dot(normalize(vNormal), lightVector)
*diffuseFactor*intensity*lightColors[i], 0.0, 1.0)*pointVisibility; *diffuseFactor*intensity*lightColors[i], 0.0, 1.0)*pointVisibility;
vec3 cameraVector = normalize(camera - vec3(fragPosition)); vec3 cameraVector = normalize(camera - vec3(fragPosition));

View File

@ -440,12 +440,18 @@ void Graphics::updateLights() {
lightingShader->setUniform("directionalIntensity", lightingShader->setUniform("directionalIntensity",
level->getDirectionalLight()->getIntensity()); level->getDirectionalLight()->getIntensity());
} }
bool isFlame[closestLights.size()];
closestFlames = std::vector<Flame*>(); closestFlames = std::vector<Flame*>();
for (unsigned int i = 0; i<closestLights.size(); i++) { for (unsigned int i = 0; i<closestLights.size(); i++) {
if (closestLights.at(i).isFlame()) { if (closestLights.at(i).isFlame()) {
closestFlames.push_back(closestLights.at(i).getFlame()); closestFlames.push_back(closestLights.at(i).getFlame());
isFlame[i] = true;
}
else {
isFlame[i] = false;
} }
} }
glUniform1iv(lightingShader->getUniformLocation("isFlame"), sizeof(isFlame), (GLint*) isFlame);
} }
void Graphics::resize(glm::uvec2 windowSize) { void Graphics::resize(glm::uvec2 windowSize) {