mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 17:50:38 +02:00
Fix evalSkyboxGlobalColor
This commit is contained in:
parent
fdffd8b6e0
commit
1fbcaea4b4
4 changed files with 49 additions and 73 deletions
|
@ -34,8 +34,9 @@ uniform sampler2D lightingMap;
|
||||||
struct DeferredTransform {
|
struct DeferredTransform {
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
mat4 viewInverse;
|
mat4 viewInverse;
|
||||||
|
float stereoSide;
|
||||||
vec4 stereoSide_spareABC;
|
float skyboxMipmapLevels;
|
||||||
|
vec2 _spareAB;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(std140) uniform deferredTransformBuffer {
|
layout(std140) uniform deferredTransformBuffer {
|
||||||
|
@ -46,10 +47,10 @@ DeferredTransform getDeferredTransform() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getStereoMode(DeferredTransform deferredTransform) {
|
bool getStereoMode(DeferredTransform deferredTransform) {
|
||||||
return (deferredTransform.stereoSide_spareABC.x != 0.0);
|
return (deferredTransform.stereoSide != 0.0);
|
||||||
}
|
}
|
||||||
float getStereoSide(DeferredTransform deferredTransform) {
|
float getStereoSide(DeferredTransform deferredTransform) {
|
||||||
return (deferredTransform.stereoSide_spareABC.x);
|
return (deferredTransform.stereoSide);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 evalEyePositionFromZ(DeferredTransform deferredTransform, float depthVal, vec2 texcoord) {
|
vec4 evalEyePositionFromZ(DeferredTransform deferredTransform, float depthVal, vec2 texcoord) {
|
||||||
|
|
|
@ -11,88 +11,61 @@
|
||||||
<@if not DEFERRED_GLOBAL_LIGHT_SLH@>
|
<@if not DEFERRED_GLOBAL_LIGHT_SLH@>
|
||||||
<@def DEFERRED_GLOBAL_LIGHT_SLH@>
|
<@def DEFERRED_GLOBAL_LIGHT_SLH@>
|
||||||
|
|
||||||
|
<@include model/Light.slh@>
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredLighting.slh@>
|
||||||
|
|
||||||
<@func declareSkyboxMap()@>
|
<@func declareSkyboxMap()@>
|
||||||
|
// declareSkyboxMap
|
||||||
uniform samplerCube skyboxMap;
|
uniform samplerCube skyboxMap;
|
||||||
|
|
||||||
vec4 evalSkyboxLight(vec3 direction, float lod) {
|
vec4 evalSkyboxLight(vec3 direction, float lod) {
|
||||||
// FIXME
|
// textureQueryLevels is not available until #430, so we require explicit lod
|
||||||
//vec4 skytexel = textureLod(skyboxMap, direction, lod * textureQueryLevels(skyboxMap));
|
// float mipmapLevel = lod * textureQueryLevels(skyboxMap);
|
||||||
vec4 skytexel = texture(skyboxMap, direction);
|
return textureLod(skyboxMap, direction, lod);
|
||||||
return skytexel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
// Everything about light
|
<@func prepareGlobalLight()@>
|
||||||
<@include model/Light.slh@>
|
// prepareGlobalLight
|
||||||
|
|
||||||
|
// Transform directions to worldspace
|
||||||
|
vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0));
|
||||||
|
vec3 fragEyeVector = vec3(invViewMat * vec4(-position, 0.0));
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector);
|
||||||
|
|
||||||
|
// Get light
|
||||||
|
Light light = getLight();
|
||||||
|
|
||||||
|
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, vec3(metallic), roughness);
|
||||||
|
color = vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light);
|
||||||
|
color += emissive;
|
||||||
|
<@endfunc@>
|
||||||
|
|
||||||
<@func declareEvalAmbientGlobalColor()@>
|
<@func declareEvalAmbientGlobalColor()@>
|
||||||
vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
|
vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
|
||||||
|
<$prepareGlobalLight()$>
|
||||||
// Need the light now
|
color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light);
|
||||||
Light light = getLight();
|
|
||||||
|
|
||||||
vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0));
|
|
||||||
vec4 fragEyeVector = invViewMat * vec4(-position, 0.0);
|
|
||||||
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
|
||||||
|
|
||||||
vec3 color = albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light);
|
|
||||||
|
|
||||||
|
|
||||||
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, vec3(metallic), roughness);
|
|
||||||
|
|
||||||
color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light);
|
|
||||||
color += emissive;
|
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
<@func declareEvalAmbientSphereGlobalColor()@>
|
<@func declareEvalAmbientSphereGlobalColor()@>
|
||||||
|
|
||||||
|
|
||||||
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
|
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
|
||||||
// Need the light now
|
<$prepareGlobalLight()$>
|
||||||
Light light = getLight();
|
color += albedo * evalSphericalLight(getLightAmbientSphere(light), fragNormal).xyz * obscurance * getLightAmbientIntensity(light);
|
||||||
|
|
||||||
vec3 fragNormal = normalize(vec3(invViewMat * vec4(normal, 0.0)));
|
|
||||||
vec4 fragEyeVector = invViewMat * vec4(-position, 0.0);
|
|
||||||
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
|
||||||
|
|
||||||
vec3 ambientNormal = fragNormal.xyz;
|
|
||||||
|
|
||||||
vec3 color = albedo * evalSphericalLight(getLightAmbientSphere(light), ambientNormal).xyz * obscurance * getLightAmbientIntensity(light);
|
|
||||||
|
|
||||||
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, vec3(metallic), roughness);
|
|
||||||
|
|
||||||
color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light);
|
|
||||||
color += emissive;
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
<@func declareEvalSkyboxGlobalColor()@>
|
<@func declareEvalSkyboxGlobalColor()@>
|
||||||
|
|
||||||
<$declareSkyboxMap()$>
|
<$declareSkyboxMap()$>
|
||||||
|
|
||||||
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
|
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness) {
|
||||||
// Need the light now
|
<$prepareGlobalLight()$>
|
||||||
Light light = getLight();
|
|
||||||
|
|
||||||
vec3 fragNormal = normalize(vec3(invViewMat * vec4(normal, 0.0)));
|
|
||||||
vec4 fragEyeVector = invViewMat * vec4(-position, 0.0);
|
|
||||||
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
|
||||||
|
|
||||||
|
|
||||||
vec3 color = albedo * evalSphericalLight(getLightAmbientSphere(light), fragNormal).xyz * obscurance * getLightAmbientIntensity(light);
|
vec3 direction = -reflect(fragEyeDir, fragNormal);
|
||||||
|
float lod = min(1.0 + floor((1.0 - gloss) * levels), levels);
|
||||||
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, vec3(metallic), roughness);
|
vec4 skyboxLight = evalSkyboxLight(direction, lod);
|
||||||
|
color += albedo * skyboxLight.rgb * skyboxLight.a * obscurance * getLightAmbientIntensity(light);
|
||||||
color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light);
|
|
||||||
color += emissive;
|
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
@ -100,26 +73,26 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
|
||||||
|
|
||||||
<@func declareEvalLightmappedColor()@>
|
<@func declareEvalLightmappedColor()@>
|
||||||
vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 normal, vec3 albedo, vec3 lightmap) {
|
vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 normal, vec3 albedo, vec3 lightmap) {
|
||||||
|
vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 normal, vec3 diffuse, vec3 lightmap) {
|
||||||
Light light = getLight();
|
Light light = getLight();
|
||||||
|
|
||||||
vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0));
|
// Catch normals perpendicular to the projection plane, hence the magic number for the threshold
|
||||||
float diffuseDot = dot(fragNormal, -getLightDirection(light));
|
// It should be just 0, but we have inaccuracy so we overshoot
|
||||||
|
|
||||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
|
||||||
// it should be just 0, but we have innacurracy so we need to overshoot
|
|
||||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||||
|
vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0)); // transform to worldspace
|
||||||
|
float diffuseDot = dot(fragNormal, -getLightDirection(light));
|
||||||
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot);
|
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot);
|
||||||
//float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot);
|
|
||||||
// evaluate the shadow test but only relevant for light facing fragments
|
// Reevaluate the shadow attenuation for light facing fragments
|
||||||
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
||||||
// diffuse light is the lightmap dimmed by shadow
|
|
||||||
|
// Diffuse light is the lightmap dimmed by shadow
|
||||||
vec3 diffuseLight = lightAttenuation * lightmap;
|
vec3 diffuseLight = lightAttenuation * lightmap;
|
||||||
|
|
||||||
// ambient is a tiny percentage of the lightmap and only when in the shadow
|
// Ambient light is the lightmap when in shadow
|
||||||
vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(light);
|
vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(light);
|
||||||
|
|
||||||
return obscurance * albedo * (ambientLight + diffuseLight);
|
return obscurance * albedo * (diffuseLight + ambientLight);
|
||||||
}
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ void main(void) {
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
frag.metallic,
|
frag.metallic,
|
||||||
frag.emissive,
|
frag.emissive,
|
||||||
frag.roughness);
|
frag.roughness,
|
||||||
|
deferredTransform.skyboxMipmapLevels);
|
||||||
|
|
||||||
_fragColor = vec4(color, frag.normalVal.a);
|
_fragColor = vec4(color, frag.normalVal.a);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ void main(void) {
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
frag.metallic,
|
frag.metallic,
|
||||||
frag.emissive,
|
frag.emissive,
|
||||||
frag.roughness);
|
frag.roughness,
|
||||||
|
deferredTransform.skyboxMipmapLevels);
|
||||||
|
|
||||||
_fragColor = vec4(color, frag.normalVal.a);
|
_fragColor = vec4(color, frag.normalVal.a);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue