mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:38:27 +02:00
Seems to work.
This commit is contained in:
parent
a8a118582d
commit
4433e79c9c
4 changed files with 61 additions and 11 deletions
|
@ -91,6 +91,7 @@ vec3 albedo, vec3 fresnel, float metallic, float roughness
|
||||||
|
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
<@include Haze.slh@>
|
||||||
|
|
||||||
<@func declareEvalSkyboxGlobalColor(supportScattering)@>
|
<@func declareEvalSkyboxGlobalColor(supportScattering)@>
|
||||||
|
|
||||||
|
@ -101,8 +102,6 @@ vec3 albedo, vec3 fresnel, float metallic, float roughness
|
||||||
<$declareDeferredCurvature()$>
|
<$declareDeferredCurvature()$>
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
||||||
<@include Haze.slh@>
|
|
||||||
|
|
||||||
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
|
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
|
||||||
vec3 albedo, vec3 fresnel, float metallic, float roughness
|
vec3 albedo, vec3 fresnel, float metallic, float roughness
|
||||||
<@if supportScattering@>
|
<@if supportScattering@>
|
||||||
|
@ -138,7 +137,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
|
||||||
|
|
||||||
// Attenuate the light if haze effect selected
|
// Attenuate the light if haze effect selected
|
||||||
if ((hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) {
|
if ((hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) {
|
||||||
color = computeHazeColorKeyLightAttenuation(color, directionalLight, invViewMat, position);
|
color = computeHazeColorKeyLightAttenuation(color, directionalLight, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
|
@ -171,9 +170,6 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur
|
||||||
}
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<@func declareEvalGlobalLightingAlphaBlended()@>
|
<@func declareEvalGlobalLightingAlphaBlended()@>
|
||||||
|
|
||||||
<$declareLightingAmbient(1, 1, 1)$>
|
<$declareLightingAmbient(1, 1, 1)$>
|
||||||
|
@ -191,7 +187,6 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl
|
||||||
color += ambientDiffuse;
|
color += ambientDiffuse;
|
||||||
color += ambientSpecular / opacity;
|
color += ambientSpecular / opacity;
|
||||||
|
|
||||||
|
|
||||||
// Directional
|
// Directional
|
||||||
vec3 directionalDiffuse;
|
vec3 directionalDiffuse;
|
||||||
vec3 directionalSpecular;
|
vec3 directionalSpecular;
|
||||||
|
@ -202,6 +197,41 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
|
mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
|
||||||
|
vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity)
|
||||||
|
{
|
||||||
|
<$prepareGlobalLight()$>
|
||||||
|
|
||||||
|
color += emissive * isEmissiveEnabled();
|
||||||
|
|
||||||
|
// Ambient
|
||||||
|
vec3 ambientDiffuse;
|
||||||
|
vec3 ambientSpecular;
|
||||||
|
evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance);
|
||||||
|
color += ambientDiffuse;
|
||||||
|
color += ambientSpecular / opacity;
|
||||||
|
|
||||||
|
// Directional
|
||||||
|
vec3 directionalDiffuse;
|
||||||
|
vec3 directionalSpecular;
|
||||||
|
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation);
|
||||||
|
color += directionalDiffuse;
|
||||||
|
color += directionalSpecular / opacity;
|
||||||
|
|
||||||
|
// Haze
|
||||||
|
if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
||||||
|
vec4 colorV4 = computeHazeColor(
|
||||||
|
vec4(color, 0.0), // fragment original color
|
||||||
|
vec4(position, 0.0), // fragment position in eye coordinates
|
||||||
|
vec4(fragEyeVector, 0.0), // fragment position in world coordinates
|
||||||
|
invViewMat[3]); // eye position in world coordinates
|
||||||
|
|
||||||
|
color = colorV4.rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ void main(void) {
|
||||||
vec4 fragColor = texture(colorMap, varTexCoord0);
|
vec4 fragColor = texture(colorMap, varTexCoord0);
|
||||||
vec4 eyeFragPos = unpackPositionFromZeye(varTexCoord0);
|
vec4 eyeFragPos = unpackPositionFromZeye(varTexCoord0);
|
||||||
vec4 worldFragPos = getViewInverse() * eyeFragPos;
|
vec4 worldFragPos = getViewInverse() * eyeFragPos;
|
||||||
vec3 worldEyePos = getViewInverse()[3].xyz;
|
vec4 worldEyePos = getViewInverse()[3];
|
||||||
|
|
||||||
outFragColor = computeHazeColor(fragColor, eyeFragPos, worldFragPos, worldEyePos);
|
outFragColor = computeHazeColor(fragColor, eyeFragPos, worldFragPos, worldEyePos);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,17 @@ layout(std140) uniform hazeBuffer {
|
||||||
HazeParams hazeParams;
|
HazeParams hazeParams;
|
||||||
};
|
};
|
||||||
|
|
||||||
vec3 computeHazeColorKeyLightAttenuation(vec3 color, Light directionalLight, mat4 invViewMat, vec3 worldFragPos) {
|
|
||||||
|
// Input:
|
||||||
|
// color - fragment original color
|
||||||
|
// directionalLight - parameters of the keylight
|
||||||
|
// worldFragPos - fragment position in world coordinates
|
||||||
|
// Output:
|
||||||
|
// fragment colour after haze effect
|
||||||
|
//
|
||||||
|
// General algorithm taken from http://www.iquilezles.org/www/articles/fog/fog.htm, with permission
|
||||||
|
//
|
||||||
|
vec3 computeHazeColorKeyLightAttenuation(vec3 color, Light directionalLight, vec3 worldFragPos) {
|
||||||
// Directional light attenuation is simulated by assuming the light source is at a fixed height above the
|
// Directional light attenuation is simulated by assuming the light source is at a fixed height above the
|
||||||
// fragment. This height is where the haze density is reduced by 95% from the haze at the fragment's height
|
// fragment. This height is where the haze density is reduced by 95% from the haze at the fragment's height
|
||||||
//
|
//
|
||||||
|
@ -84,7 +94,17 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, Light directionalLight, mat
|
||||||
return mix(color, vec3(0.0, 0.0, 0.0), hazeAmount);
|
return mix(color, vec3(0.0, 0.0, 0.0), hazeAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 computeHazeColor(vec4 fragColor, vec4 eyeFragPos, vec4 worldFragPos, vec3 worldEyePos) {
|
// Input:
|
||||||
|
// fragColor - fragment original color
|
||||||
|
// eyeFragPos - fragment position in eye coordinates
|
||||||
|
// worldFragPos - fragment position in world coordinates
|
||||||
|
// worldEyePos - eye position in world coordinates
|
||||||
|
// Output:
|
||||||
|
// fragment colour after haze effect
|
||||||
|
//
|
||||||
|
// General algorithm taken from http://www.iquilezles.org/www/articles/fog/fog.htm, with permission
|
||||||
|
//
|
||||||
|
vec4 computeHazeColor(vec4 fragColor, vec4 eyeFragPos, vec4 worldFragPos, vec4 worldEyePos) {
|
||||||
// Distance to fragment
|
// Distance to fragment
|
||||||
float distance = length(eyeFragPos.xyz);
|
float distance = length(eyeFragPos.xyz);
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ void main(void) {
|
||||||
|
|
||||||
TransformCamera cam = getTransformCamera();
|
TransformCamera cam = getTransformCamera();
|
||||||
|
|
||||||
_fragColor = vec4(evalGlobalLightingAlphaBlended(
|
_fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
cam._viewInverse,
|
cam._viewInverse,
|
||||||
1.0,
|
1.0,
|
||||||
occlusionTex,
|
occlusionTex,
|
||||||
|
|
Loading…
Reference in a new issue