mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 19:50:38 +02:00
Added SurfaceData mechanism to evalGlobalLight
This commit is contained in:
parent
705b475d0c
commit
8fb863e98c
8 changed files with 60 additions and 18 deletions
|
@ -21,13 +21,7 @@
|
||||||
<@include LightDirectional.slh@>
|
<@include LightDirectional.slh@>
|
||||||
|
|
||||||
|
|
||||||
<@func prepareGlobalLight(isScattering)@>
|
<@func fetchGlobalLight()@>
|
||||||
// prepareGlobalLight
|
|
||||||
// Transform directions to worldspace
|
|
||||||
vec3 fragNormal = vec3((normal));
|
|
||||||
vec3 fragEyeVector = vec3(invViewMat * vec4(-1.0*position, 0.0));
|
|
||||||
vec3 fragEyeDir = normalize(fragEyeVector);
|
|
||||||
|
|
||||||
// Get light
|
// Get light
|
||||||
Light light = getKeyLight();
|
Light light = getKeyLight();
|
||||||
LightAmbient lightAmbient = getLightAmbient();
|
LightAmbient lightAmbient = getLightAmbient();
|
||||||
|
@ -36,6 +30,16 @@
|
||||||
vec3 lightIrradiance = getLightIrradiance(light);
|
vec3 lightIrradiance = getLightIrradiance(light);
|
||||||
|
|
||||||
vec3 color = vec3(0.0);
|
vec3 color = vec3(0.0);
|
||||||
|
<@endfunc@>
|
||||||
|
|
||||||
|
<@func prepareGlobalLight(isScattering)@>
|
||||||
|
// prepareGlobalLight
|
||||||
|
// Transform directions to worldspace
|
||||||
|
vec3 fragNormal = vec3((normal));
|
||||||
|
vec3 fragEyeVector = vec3(invViewMat * vec4(-position, 0.0));
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector);
|
||||||
|
|
||||||
|
<$fetchGlobalLight()$>
|
||||||
|
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
@ -202,12 +206,50 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl
|
||||||
|
|
||||||
vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
|
mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
|
||||||
vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity, vec3 prevLighting)
|
vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity)
|
||||||
{
|
{
|
||||||
<$prepareGlobalLight()$>
|
<$prepareGlobalLight()$>
|
||||||
|
|
||||||
SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir);
|
SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir);
|
||||||
|
|
||||||
|
color += emissive * isEmissiveEnabled();
|
||||||
|
|
||||||
|
// Ambient
|
||||||
|
vec3 ambientDiffuse;
|
||||||
|
vec3 ambientSpecular;
|
||||||
|
evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance);
|
||||||
|
color += ambientDiffuse;
|
||||||
|
color += ambientSpecular / opacity;
|
||||||
|
|
||||||
|
// Directional
|
||||||
|
vec3 directionalDiffuse;
|
||||||
|
vec3 directionalSpecular;
|
||||||
|
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, 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, 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
|
||||||
|
lightDirection // keylight direction vector
|
||||||
|
);
|
||||||
|
|
||||||
|
color = colorV4.rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
|
mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position,
|
||||||
|
vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, SurfaceData surface, float opacity, vec3 prevLighting)
|
||||||
|
{
|
||||||
|
<$fetchGlobalLight()$>
|
||||||
|
|
||||||
color = prevLighting;
|
color = prevLighting;
|
||||||
color += emissive * isEmissiveEnabled();
|
color += emissive * isEmissiveEnabled();
|
||||||
|
|
||||||
|
@ -229,7 +271,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
vec4 colorV4 = computeHazeColor(
|
vec4 colorV4 = computeHazeColor(
|
||||||
vec4(color, 1.0), // fragment original color
|
vec4(color, 1.0), // fragment original color
|
||||||
position, // fragment position in eye coordinates
|
position, // fragment position in eye coordinates
|
||||||
fragEyeVector, // fragment position in world coordinates
|
surface.eyeDir, // fragment eye vector in world coordinates
|
||||||
invViewMat[3].y, // eye height in world coordinates
|
invViewMat[3].y, // eye height in world coordinates
|
||||||
lightDirection // keylight direction vector
|
lightDirection // keylight direction vector
|
||||||
);
|
);
|
||||||
|
|
|
@ -59,6 +59,7 @@ void main(void) {
|
||||||
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
||||||
|
|
||||||
vec3 fragPosition = _position.xyz;
|
vec3 fragPosition = _position.xyz;
|
||||||
|
// Lighting is done in world space
|
||||||
vec3 fragNormal = normalize(_normal);
|
vec3 fragNormal = normalize(_normal);
|
||||||
|
|
||||||
TransformCamera cam = getTransformCamera();
|
TransformCamera cam = getTransformCamera();
|
||||||
|
@ -80,11 +81,10 @@ void main(void) {
|
||||||
1.0,
|
1.0,
|
||||||
occlusionTex,
|
occlusionTex,
|
||||||
fragPosition,
|
fragPosition,
|
||||||
fragNormal,
|
|
||||||
albedo,
|
albedo,
|
||||||
fresnel,
|
fresnel,
|
||||||
metallic,
|
metallic,
|
||||||
emissive,
|
emissive,
|
||||||
roughness, opacity, localLighting.rgb),
|
surface, opacity, localLighting.rgb),
|
||||||
opacity);
|
opacity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,5 +40,5 @@ void main(void) {
|
||||||
TransformObject obj = getTransformObject();
|
TransformObject obj = getTransformObject();
|
||||||
<$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$>
|
<$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$>
|
||||||
<$transformModelToWorldPos(obj, inPosition, _worldPosition)$>
|
<$transformModelToWorldPos(obj, inPosition, _worldPosition)$>
|
||||||
<$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$>
|
<$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$>
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ void main(void) {
|
||||||
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
||||||
|
|
||||||
vec3 fragPosition = _position.xyz;
|
vec3 fragPosition = _position.xyz;
|
||||||
|
// Lighting is done in world space
|
||||||
vec3 fragNormal = normalize(_normal);
|
vec3 fragNormal = normalize(_normal);
|
||||||
|
|
||||||
TransformCamera cam = getTransformCamera();
|
TransformCamera cam = getTransformCamera();
|
||||||
|
@ -89,11 +90,10 @@ void main(void) {
|
||||||
1.0,
|
1.0,
|
||||||
occlusionTex,
|
occlusionTex,
|
||||||
fragPosition,
|
fragPosition,
|
||||||
fragNormal,
|
|
||||||
albedo,
|
albedo,
|
||||||
fresnel,
|
fresnel,
|
||||||
metallic,
|
metallic,
|
||||||
emissive+fadeEmissive,
|
emissive+fadeEmissive,
|
||||||
roughness, opacity, localLighting.rgb),
|
surface, opacity, localLighting.rgb),
|
||||||
opacity);
|
opacity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,5 +40,5 @@ void main(void) {
|
||||||
TransformObject obj = getTransformObject();
|
TransformObject obj = getTransformObject();
|
||||||
<$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$>
|
<$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$>
|
||||||
<$transformModelToWorldPos(obj, inPosition, _worldPosition)$>
|
<$transformModelToWorldPos(obj, inPosition, _worldPosition)$>
|
||||||
<$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$>
|
<$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$>
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ void main(void) {
|
||||||
fresnel,
|
fresnel,
|
||||||
metallic,
|
metallic,
|
||||||
emissive,
|
emissive,
|
||||||
roughness, opacity, vec3(0)),
|
roughness, opacity),
|
||||||
opacity);
|
opacity);
|
||||||
|
|
||||||
// Apply standard tone mapping
|
// Apply standard tone mapping
|
||||||
|
|
|
@ -56,7 +56,7 @@ void main(void) {
|
||||||
0.0,
|
0.0,
|
||||||
vec3(0.0f),
|
vec3(0.0f),
|
||||||
DEFAULT_ROUGHNESS,
|
DEFAULT_ROUGHNESS,
|
||||||
opacity, vec3(0)),
|
opacity),
|
||||||
opacity);
|
opacity);
|
||||||
|
|
||||||
}
|
}
|
|
@ -68,7 +68,7 @@ void main(void) {
|
||||||
0.0f,
|
0.0f,
|
||||||
fadeEmissive,
|
fadeEmissive,
|
||||||
DEFAULT_ROUGHNESS,
|
DEFAULT_ROUGHNESS,
|
||||||
opacity, vec3(0)),
|
opacity),
|
||||||
opacity);
|
opacity);
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue