Pass keylight direction as parameter to the shader.

This commit is contained in:
Nissim Hadar 2017-12-19 11:12:27 -08:00
parent de7edc68d4
commit 2c6868b03e
3 changed files with 8 additions and 8 deletions

View file

@ -221,7 +221,8 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
vec4(color, 1.0), // fragment original color
position, // fragment position in eye coordinates
fragEyeVector, // fragment position in world coordinates
invViewMat[3].y // eye height in world coordinates
invViewMat[3].y, // eye height in world coordinates
lightDirection // keylight direction vector
);
color = colorV4.rgb;

View file

@ -53,6 +53,8 @@ void main(void) {
vec4 worldFragPos = viewInverse * eyeFragPos;
vec4 worldEyePos = viewInverse[3];
outFragColor = computeHazeColor(fragColor, eyeFragPos.xyz, worldFragPos.xyz, worldEyePos.y);
}
Light light = getLight();
vec3 lightDirection = getLightDirection(light);
outFragColor = computeHazeColor(fragColor, eyeFragPos.xyz, worldFragPos.xyz, worldEyePos.y, lightDirection);
}

View file

@ -43,7 +43,7 @@ layout(std140) uniform hazeBuffer {
// Input:
// color - fragment original color
// directionalLight - parameters of the keylight
// lightDirection - parameters of the keylight
// worldFragPos - fragment position in world coordinates
// Output:
// fragment colour after haze effect
@ -101,7 +101,7 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirection, vec3 w
//
// General algorithm taken from http://www.iquilezles.org/www/articles/fog/fog.htm, with permission
//
vec4 computeHazeColor(vec4 fragColor, vec3 eyeFragPos, vec3 worldFragPos, float worldEyeHeight) {
vec4 computeHazeColor(vec4 fragColor, vec3 eyeFragPos, vec3 worldFragPos, float worldEyeHeight, vec3 lightDirection) {
// Distance to fragment
float distance = length(eyeFragPos);
@ -111,9 +111,6 @@ vec4 computeHazeColor(vec4 fragColor, vec3 eyeFragPos, vec3 worldFragPos, float
// Directional light component is a function of the angle from the eye, between the fragment and the sun
vec3 eyeFragDir = normalize(worldFragPos);
Light light = getLight();
vec3 lightDirection = getLightDirection(light);
float glareComponent = max(0.0, dot(eyeFragDir, -lightDirection));
float power = min(1.0, pow(glareComponent, hazeParams.hazeGlareBlend));