From 2adac241d0c647ae1caae1409ac1f455baccf456 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Thu, 12 Apr 2018 15:11:10 +0200 Subject: [PATCH 01/11] Fixed incorrect fragment to eye dir computation in haze --- .../render-utils/src/DeferredGlobalLight.slh | 6 ++-- .../render-utils/src/ForwardGlobalLight.slh | 2 +- libraries/render-utils/src/Haze.slf | 2 +- libraries/render-utils/src/Haze.slh | 33 ++++++++++--------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 51884ccbee..2ffdad46af 100644 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -240,8 +240,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 - lightDirection // keylight direction vector + invViewMat[3].xyz, // eye position in world coordinates + lightDirection // keylight direction vector in world coordinates ); color = colorV4.rgb; @@ -278,7 +278,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( vec4(color, 1.0), // fragment original color position, // fragment position in eye coordinates surface.eyeDir, // fragment eye vector in world coordinates - invViewMat[3].y, // eye height in world coordinates + invViewMat[3].xyz, // eye position in world coordinates lightDirection // keylight direction vector ); diff --git a/libraries/render-utils/src/ForwardGlobalLight.slh b/libraries/render-utils/src/ForwardGlobalLight.slh index a945acb8c4..2c794bb31c 100644 --- a/libraries/render-utils/src/ForwardGlobalLight.slh +++ b/libraries/render-utils/src/ForwardGlobalLight.slh @@ -234,7 +234,7 @@ 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].xyz, // eye position in world coordinates lightDirection // keylight direction vector ); diff --git a/libraries/render-utils/src/Haze.slf b/libraries/render-utils/src/Haze.slf index e254266350..d63de64b07 100644 --- a/libraries/render-utils/src/Haze.slf +++ b/libraries/render-utils/src/Haze.slf @@ -56,5 +56,5 @@ void main(void) { Light light = getKeyLight(); vec3 lightDirection = getLightDirection(light); - outFragColor = computeHazeColor(fragColor, eyeFragPos.xyz, worldFragPos.xyz, worldEyePos.y, lightDirection); + outFragColor = computeHazeColor(fragColor, eyeFragPos.xyz, worldFragPos.xyz, worldEyePos.xyz, lightDirection); } diff --git a/libraries/render-utils/src/Haze.slh b/libraries/render-utils/src/Haze.slh index 10b493da2c..25a80953b5 100644 --- a/libraries/render-utils/src/Haze.slh +++ b/libraries/render-utils/src/Haze.slh @@ -44,15 +44,15 @@ layout(std140) uniform hazeBuffer { // Input: // color - fragment original color // lightDirection - parameters of the keylight -// worldFragPos - fragment position in world coordinates +// fragWorldPos - 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, vec3 lightDirection, vec3 worldFragPos) { +vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirection, vec3 fragWorldPos) { // 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 // // The distance is computed from the height and the directional light orientation // The distance is limited to height * 1,000, which gives an angle of ~0.057 degrees @@ -79,7 +79,7 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirection, vec3 w // Note that the haze base reference affects only the haze density as function of altitude float hazeDensityDistribution = hazeParams.hazeKeyLightRangeFactor * - exp(-hazeParams.hazeKeyLightAltitudeFactor * (worldFragPos.y - hazeParams.hazeBaseReference)); + exp(-hazeParams.hazeKeyLightAltitudeFactor * (fragWorldPos.y - hazeParams.hazeBaseReference)); float hazeIntegral = hazeDensityDistribution * distance; @@ -93,25 +93,26 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirection, vec3 w // Input: // fragColor - fragment original color -// eyeFragPos - fragment position in eye coordinates -// worldFragPos - fragment position in world coordinates -// worldEyeHeight - eye height in world coordinates +// fragEyePos - fragment position in eye coordinates +// fragWorldPos - fragment position in world coordinates +// eyeWorldPos - 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, vec3 eyeFragPos, vec3 worldFragPos, float worldEyeHeight, vec3 lightDirection) { +vec4 computeHazeColor(vec4 fragColor, vec3 fragEyePos, vec3 fragWorldPos, vec3 eyeWorldPos, vec3 lightDirection) { // Distance to fragment - float distance = length(eyeFragPos); + float distance = length(fragEyePos); + float eyeWorldHeight = eyeWorldPos.y; // Convert haze colour from uniform into a vec4 vec4 hazeColor = vec4(hazeParams.hazeColor, 1.0); // Directional light component is a function of the angle from the eye, between the fragment and the sun - vec3 eyeFragDir = normalize(worldFragPos); + vec3 fragToEyeWorldDir = normalize(fragWorldPos-eyeWorldPos); - float glareComponent = max(0.0, dot(eyeFragDir, -lightDirection)); + float glareComponent = max(0.0, dot(fragToEyeWorldDir, -lightDirection)); float power = min(1.0, pow(glareComponent, hazeParams.hazeGlareBlend)); vec4 glareColor = vec4(hazeParams.hazeGlareColor, 1.0); @@ -134,12 +135,12 @@ vec4 computeHazeColor(vec4 fragColor, vec3 eyeFragPos, vec3 worldFragPos, float // Note that the haze base reference affects only the haze density as function of altitude vec3 hazeDensityDistribution = hazeParams.colorModulationFactor * - exp(-hazeParams.hazeHeightFactor * (worldEyeHeight - hazeParams.hazeBaseReference)); + exp(-hazeParams.hazeHeightFactor * (eyeWorldHeight - hazeParams.hazeBaseReference)); - vec3 hazeIntegral = hazeDensityDistribution * distance; + vec3 hazeIntegral = hazeDensityDistribution * distance; const float slopeThreshold = 0.01; - float deltaHeight = worldFragPos.y - worldEyeHeight; + float deltaHeight = fragWorldPos.y - eyeWorldHeight; if (abs(deltaHeight) > slopeThreshold) { float t = hazeParams.hazeHeightFactor * deltaHeight; hazeIntegral *= (1.0 - exp (-t)) / t; @@ -162,12 +163,12 @@ vec4 computeHazeColor(vec4 fragColor, vec3 eyeFragPos, vec3 worldFragPos, float // Note that the haze base reference affects only the haze density as function of altitude float hazeDensityDistribution = hazeParams.hazeRangeFactor * - exp(-hazeParams.hazeHeightFactor * (worldEyeHeight - hazeParams.hazeBaseReference)); + exp(-hazeParams.hazeHeightFactor * (eyeWorldHeight - hazeParams.hazeBaseReference)); float hazeIntegral = hazeDensityDistribution * distance; const float slopeThreshold = 0.01; - float deltaHeight = worldFragPos.y - worldEyeHeight; + float deltaHeight = fragWorldPos.y - eyeWorldHeight; if (abs(deltaHeight) > slopeThreshold) { float t = hazeParams.hazeHeightFactor * deltaHeight; // Protect from wild values From 190e9313c73019ea20d93f6566500966b46e0645 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Fri, 13 Apr 2018 15:38:55 +0200 Subject: [PATCH 02/11] Sorted out the mix between eye space and world space vectors in translucent object shading --- .../render-utils/src/DeferredGlobalLight.slh | 58 ++++++++++--------- .../render-utils/src/ForwardGlobalLight.slh | 49 ++++++++-------- libraries/render-utils/src/Haze.slf | 10 ++-- libraries/render-utils/src/Haze.slh | 32 +++++----- .../render-utils/src/MaterialTextures.slh | 4 +- .../src/forward_model_normal_map.slf | 10 ++-- .../render-utils/src/model_normal_map.slf | 12 ++-- .../render-utils/src/model_normal_map.slv | 12 ++-- .../render-utils/src/model_translucent.slf | 26 +++++---- .../render-utils/src/model_translucent.slv | 12 ++-- .../src/model_translucent_fade.slf | 30 +++++----- .../src/model_translucent_normal_map.slf | 31 +++++----- .../src/model_translucent_normal_map.slv | 16 ++--- .../src/model_translucent_normal_map_fade.slf | 34 ++++++----- 14 files changed, 174 insertions(+), 162 deletions(-) diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 2ffdad46af..c3ab17f72b 100644 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -32,12 +32,13 @@ vec3 color = vec3(0.0); <@endfunc@> -<@func prepareGlobalLight(isScattering)@> +<@func prepareGlobalLight(positionES, normalWS)@> // prepareGlobalLight // Transform directions to worldspace - vec3 fragNormal = vec3((normal)); - vec3 fragEyeVector = vec3(invViewMat * vec4(-position, 0.0)); - vec3 fragEyeDir = normalize(fragEyeVector); + vec3 fragNormalWS = vec3(<$normalWS$>); + vec3 fragPositionWS = vec3(invViewMat * vec4(<$positionES$>, 1.0)); + vec3 fragEyeVectorWS = invViewMat[3].xyz - fragPositionWS; + vec3 fragEyeDirWS = normalize(fragEyeVectorWS); <$fetchGlobalLight()$> @@ -46,7 +47,7 @@ <@func declareEvalAmbientGlobalColor()@> vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, float roughness) { - <$prepareGlobalLight()$> + <$prepareGlobalLight(position, normal)$> color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(lightAmbient); return color; } @@ -67,14 +68,14 @@ vec3 albedo, vec3 fresnel, float metallic, float roughness , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature <@endif@> ) { - <$prepareGlobalLight($supportScattering$)$> + <$prepareGlobalLight(position, normal)$> - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); @@ -85,7 +86,7 @@ vec3 albedo, vec3 fresnel, float metallic, float roughness // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); @@ -114,14 +115,14 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature <@endif@> ) { - <$prepareGlobalLight($supportScattering$)$> + <$prepareGlobalLight(position, normal)$> - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> @@ -131,7 +132,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> @@ -141,7 +142,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu // Attenuate the light if haze effect selected if ((hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) { - color = computeHazeColorKeyLightAttenuation(color, lightDirection, position); + color = computeHazeColorKeyLightAttenuation(color, lightDirection, fragPositionWS); } return color; @@ -180,9 +181,9 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur <$declareLightingDirectional()$> vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity, vec3 prevLighting) { - <$prepareGlobalLight()$> + <$prepareGlobalLight(position, normal)$> - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); color = prevLighting; color += emissive * isEmissiveEnabled(); @@ -190,14 +191,14 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance); + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation); + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; color += directionalSpecular / opacity; @@ -211,26 +212,27 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl <$declareLightingDirectional()$> vec3 evalGlobalLightingAlphaBlendedWithHaze( - mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, + mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 positionES, vec3 normalWS, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity) { - <$prepareGlobalLight()$> - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + <$prepareGlobalLight(positionES, normalWS)$> + + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); color += emissive * isEmissiveEnabled(); // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance); + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation); + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; color += directionalSpecular / opacity; @@ -238,8 +240,8 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( 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 + positionES, // fragment position in eye coordinates + fragPositionWS, // fragment position in world coordinates invViewMat[3].xyz, // eye position in world coordinates lightDirection // keylight direction vector in world coordinates ); @@ -251,7 +253,7 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( } vec3 evalGlobalLightingAlphaBlendedWithHaze( - mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, + mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 positionES, vec3 positionWS, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, SurfaceData surface, float opacity, vec3 prevLighting) { <$fetchGlobalLight()$> @@ -276,8 +278,8 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( 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 - surface.eyeDir, // fragment eye vector in world coordinates + positionES, // fragment position in eye coordinates + positionWS, // fragment position in world coordinates invViewMat[3].xyz, // eye position in world coordinates lightDirection // keylight direction vector ); diff --git a/libraries/render-utils/src/ForwardGlobalLight.slh b/libraries/render-utils/src/ForwardGlobalLight.slh index 2c794bb31c..3aadb182fa 100644 --- a/libraries/render-utils/src/ForwardGlobalLight.slh +++ b/libraries/render-utils/src/ForwardGlobalLight.slh @@ -21,12 +21,13 @@ <@include LightDirectional.slh@> -<@func prepareGlobalLight(isScattering)@> +<@func prepareGlobalLight(positionES, normalWS)@> // prepareGlobalLight // Transform directions to worldspace - vec3 fragNormal = vec3((normal)); - vec3 fragEyeVector = vec3(invViewMat * vec4(-1.0*position, 0.0)); - vec3 fragEyeDir = normalize(fragEyeVector); + vec3 fragNormalWS = vec3(<$normalWS$>); + vec3 fragPositionWS = vec3(invViewMat * vec4(<$positionES$>, 1.0)); + vec3 fragEyeVectorWS = invViewMat[3].xyz - fragPositionWS; + vec3 fragEyeDirWS = normalize(fragEyeVectorWS); // Get light Light light = getKeyLight(); @@ -42,7 +43,7 @@ <@func declareEvalAmbientGlobalColor()@> vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, float roughness) { - <$prepareGlobalLight()$> + <$prepareGlobalLight(position, normal)$> color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(lightAmbient); return color; } @@ -63,14 +64,14 @@ vec3 albedo, vec3 fresnel, float metallic, float roughness , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature <@endif@> ) { - <$prepareGlobalLight($supportScattering$)$> + <$prepareGlobalLight(position, normal)$> - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); @@ -81,7 +82,7 @@ vec3 albedo, vec3 fresnel, float metallic, float roughness // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); @@ -109,14 +110,14 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature <@endif@> ) { - <$prepareGlobalLight($supportScattering$)$> + <$prepareGlobalLight(position, normal)$> - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> @@ -126,7 +127,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> @@ -137,7 +138,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu // FIXME - temporarily removed until we support it for forward... // Attenuate the light if haze effect selected // if ((hazeParams.hazeMode & HAZE_MODE_IS_KEYLIGHT_ATTENUATED) == HAZE_MODE_IS_KEYLIGHT_ATTENUATED) { - // color = computeHazeColorKeyLightAttenuation(color, lightDirection, position); + // color = computeHazeColorKeyLightAttenuation(color, lightDirection, fragPositionWS); // } return color; @@ -180,23 +181,23 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur <$declareLightingDirectional()$> vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity) { - <$prepareGlobalLight()$> + <$prepareGlobalLight(position, normal)$> - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); color += emissive * isEmissiveEnabled(); // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance); + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation); + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; color += directionalSpecular / opacity; @@ -207,23 +208,23 @@ 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()$> + <$prepareGlobalLight(position, normal)$> - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragEyeDirWS); color += emissive * isEmissiveEnabled(); // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; - evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surface, metallic, fresnel, albedo, obscurance); + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; - evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surface, metallic, fresnel, albedo, shadowAttenuation); + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; color += directionalSpecular / opacity; @@ -232,8 +233,8 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( /* 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 + positionES, // fragment position in eye coordinates + fragPositionWS, // fragment position in world coordinates invViewMat[3].xyz, // eye position in world coordinates lightDirection // keylight direction vector ); diff --git a/libraries/render-utils/src/Haze.slf b/libraries/render-utils/src/Haze.slf index d63de64b07..b9f23fd932 100644 --- a/libraries/render-utils/src/Haze.slf +++ b/libraries/render-utils/src/Haze.slf @@ -47,14 +47,14 @@ void main(void) { } vec4 fragColor = texture(colorMap, varTexCoord0); - vec4 eyeFragPos = unpackPositionFromZeye(varTexCoord0); + vec4 fragPositionES = unpackPositionFromZeye(varTexCoord0); mat4 viewInverse = getViewInverse(); - vec4 worldFragPos = viewInverse * eyeFragPos; - vec4 worldEyePos = viewInverse[3]; + vec4 fragPositionWS = viewInverse * fragPositionES; + vec4 eyePositionWS = viewInverse[3]; Light light = getKeyLight(); - vec3 lightDirection = getLightDirection(light); + vec3 lightDirectionWS = getLightDirection(light); - outFragColor = computeHazeColor(fragColor, eyeFragPos.xyz, worldFragPos.xyz, worldEyePos.xyz, lightDirection); + outFragColor = computeHazeColor(fragColor, fragPositionES.xyz, fragPositionWS.xyz, eyePositionWS.xyz, lightDirectionWS); } diff --git a/libraries/render-utils/src/Haze.slh b/libraries/render-utils/src/Haze.slh index 25a80953b5..a9c8ff829e 100644 --- a/libraries/render-utils/src/Haze.slh +++ b/libraries/render-utils/src/Haze.slh @@ -43,14 +43,14 @@ layout(std140) uniform hazeBuffer { // Input: // color - fragment original color -// lightDirection - parameters of the keylight -// fragWorldPos - fragment position in world coordinates +// lightDirectionWS - parameters of the keylight +// fragPositionWS - 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, vec3 lightDirection, vec3 fragWorldPos) { +vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirectionWS, vec3 fragPositionWS) { // 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 // @@ -65,7 +65,7 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirection, vec3 f } // Note that we need the sine to be positive - float sin_pitch = abs(lightDirection.y); + float sin_pitch = abs(lightDirectionWS.y); float distance; const float minimumSinPitch = 0.001; @@ -79,7 +79,7 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirection, vec3 f // Note that the haze base reference affects only the haze density as function of altitude float hazeDensityDistribution = hazeParams.hazeKeyLightRangeFactor * - exp(-hazeParams.hazeKeyLightAltitudeFactor * (fragWorldPos.y - hazeParams.hazeBaseReference)); + exp(-hazeParams.hazeKeyLightAltitudeFactor * (fragPositionWS.y - hazeParams.hazeBaseReference)); float hazeIntegral = hazeDensityDistribution * distance; @@ -92,27 +92,27 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirection, vec3 f } // Input: -// fragColor - fragment original color -// fragEyePos - fragment position in eye coordinates -// fragWorldPos - fragment position in world coordinates -// eyeWorldPos - eye position in world coordinates +// fragColor - fragment original color +// fragPositionES - fragment position in eye coordinates +// fragPositionWS - fragment position in world coordinates +// eyePositionWS - 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, vec3 fragEyePos, vec3 fragWorldPos, vec3 eyeWorldPos, vec3 lightDirection) { +vec4 computeHazeColor(vec4 fragColor, vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePositionWS, vec3 lightDirectionWS) { // Distance to fragment - float distance = length(fragEyePos); - float eyeWorldHeight = eyeWorldPos.y; + float distance = length(fragPositionES); + float eyeWorldHeight = eyePositionWS.y; // Convert haze colour from uniform into a vec4 vec4 hazeColor = vec4(hazeParams.hazeColor, 1.0); // Directional light component is a function of the angle from the eye, between the fragment and the sun - vec3 fragToEyeWorldDir = normalize(fragWorldPos-eyeWorldPos); + vec3 fragToEyeDirWS = normalize(fragPositionWS - eyePositionWS); - float glareComponent = max(0.0, dot(fragToEyeWorldDir, -lightDirection)); + float glareComponent = max(0.0, dot(fragToEyeDirWS, -lightDirectionWS)); float power = min(1.0, pow(glareComponent, hazeParams.hazeGlareBlend)); vec4 glareColor = vec4(hazeParams.hazeGlareColor, 1.0); @@ -140,7 +140,7 @@ vec4 computeHazeColor(vec4 fragColor, vec3 fragEyePos, vec3 fragWorldPos, vec3 e vec3 hazeIntegral = hazeDensityDistribution * distance; const float slopeThreshold = 0.01; - float deltaHeight = fragWorldPos.y - eyeWorldHeight; + float deltaHeight = fragPositionWS.y - eyeWorldHeight; if (abs(deltaHeight) > slopeThreshold) { float t = hazeParams.hazeHeightFactor * deltaHeight; hazeIntegral *= (1.0 - exp (-t)) / t; @@ -168,7 +168,7 @@ vec4 computeHazeColor(vec4 fragColor, vec3 fragEyePos, vec3 fragWorldPos, vec3 e float hazeIntegral = hazeDensityDistribution * distance; const float slopeThreshold = 0.01; - float deltaHeight = fragWorldPos.y - eyeWorldHeight; + float deltaHeight = fragPositionWS.y - eyeWorldHeight; if (abs(deltaHeight) > slopeThreshold) { float t = hazeParams.hazeHeightFactor * deltaHeight; // Protect from wild values diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh index 26e809e4ba..14e8b0ef07 100644 --- a/libraries/render-utils/src/MaterialTextures.slh +++ b/libraries/render-utils/src/MaterialTextures.slh @@ -228,14 +228,14 @@ vec3 fetchLightmapMap(vec2 uv) { } <@endfunc@> -<@func evalMaterialNormalLOD(fragPos, fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@> +<@func evalMaterialNormalLOD(fragPosES, fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@> { vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz); vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz); vec3 normalizedBitangent = cross(normalizedNormal, normalizedTangent); // attenuate the normal map divergence from the mesh normal based on distance // The attenuation range [20,100] meters from the eye is arbitrary for now - vec3 localNormal = mix(<$fetchedNormal$>, vec3(0.0, 1.0, 0.0), smoothstep(20.0, 100.0, (-<$fragPos$>).z)); + vec3 localNormal = mix(<$fetchedNormal$>, vec3(0.0, 1.0, 0.0), smoothstep(20.0, 100.0, (-<$fragPosES$>).z)); <$normal$> = vec3(normalizedBitangent * localNormal.x + normalizedNormal * localNormal.y + normalizedTangent * localNormal.z); } <@endfunc@> diff --git a/libraries/render-utils/src/forward_model_normal_map.slf b/libraries/render-utils/src/forward_model_normal_map.slf index 0ba464d3f0..ac76e909e4 100644 --- a/libraries/render-utils/src/forward_model_normal_map.slf +++ b/libraries/render-utils/src/forward_model_normal_map.slf @@ -23,11 +23,11 @@ <@include MaterialTextures.slh@> <$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION)$> -in vec4 _position; +in vec4 _positionES; in vec2 _texCoord0; in vec2 _texCoord1; -in vec3 _normal; -in vec3 _tangent; +in vec3 _normalWS; +in vec3 _tangentWS; in vec3 _color; layout(location = 0) out vec4 _fragColor0; @@ -56,9 +56,9 @@ void main(void) { <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; vec3 fresnel = getFresnelF0(metallic, albedo); - vec3 fragPosition = _position.xyz; + vec3 fragPosition = _positionES.xyz; vec3 fragNormal; - <$evalMaterialNormal(normalTex, _normal, _tangent, fragNormal)$> + <$evalMaterialNormal(normalTex, _normalWS, _tangentWS, fragNormal)$> TransformCamera cam = getTransformCamera(); diff --git a/libraries/render-utils/src/model_normal_map.slf b/libraries/render-utils/src/model_normal_map.slf index 49613eca6a..b13377af21 100644 --- a/libraries/render-utils/src/model_normal_map.slf +++ b/libraries/render-utils/src/model_normal_map.slf @@ -19,11 +19,11 @@ <@include MaterialTextures.slh@> <$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION, SCATTERING)$> -in vec4 _position; +in vec4 _positionES; in vec2 _texCoord0; in vec2 _texCoord1; -in vec3 _normal; -in vec3 _tangent; +in vec3 _normalWS; +in vec3 _tangentWS; in vec3 _color; void main(void) { @@ -46,8 +46,8 @@ void main(void) { vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - vec3 fragNormal; - <$evalMaterialNormalLOD(_position, normalTex, _normal, _tangent, fragNormal)$> + vec3 fragNormalWS; + <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> float metallic = getMaterialMetallic(mat); <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; @@ -56,7 +56,7 @@ void main(void) { <$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>; packDeferredFragment( - normalize(fragNormal.xyz), + normalize(fragNormalWS.xyz), opacity, albedo, roughness, diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv index a84f8c5e2a..cc99c6d22d 100644 --- a/libraries/render-utils/src/model_normal_map.slv +++ b/libraries/render-utils/src/model_normal_map.slv @@ -20,11 +20,11 @@ <@include MaterialTextures.slh@> <$declareMaterialTexMapArrayBuffer()$> -out vec4 _position; +out vec4 _positionES; out vec2 _texCoord0; out vec2 _texCoord1; -out vec3 _normal; -out vec3 _tangent; +out vec3 _normalWS; +out vec3 _tangentWS; out vec3 _color; out float _alpha; @@ -40,7 +40,7 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> - <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> - <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangent)$> + <$transformModelToEyeAndClipPos(cam, obj, inPosition, _positionES, gl_Position)$> + <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> + <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangentWS)$> } diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index bac97f2546..f109170068 100644 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -28,9 +28,9 @@ in vec2 _texCoord0; in vec2 _texCoord1; -in vec4 _position; -in vec4 _worldPosition; -in vec3 _normal; +in vec4 _positionES; +in vec4 _positionWS; +in vec3 _normalWS; in vec3 _color; in float _alpha; @@ -58,20 +58,21 @@ void main(void) { vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - vec3 fragPosition = _position.xyz; + vec3 fragPositionES = _positionES.xyz; + vec3 fragPositionWS = _positionWS.xyz; // Lighting is done in world space - vec3 fragNormal = normalize(_normal); + vec3 fragNormalWS = normalize(_normalWS); TransformCamera cam = getTransformCamera(); - vec3 fragEyeVector = vec3(cam._viewInverse * vec4(-fragPosition, 0.0)); - vec3 fragEyeDir = normalize(fragEyeVector); - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + vec3 fragToEyeWS = fragPositionWS - cam._viewInverse[3].xyz; + vec3 fragToEyeDirWS = normalize(fragToEyeWS); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); vec4 localLighting = vec4(0.0); - <$fetchClusterInfo(_worldPosition)$>; + <$fetchClusterInfo(_positionWS)$>; if (hasLocalLights(numLights, clusterPos, dims)) { - localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, surface, + localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS, metallic, fresnel, albedo, 0.0, vec4(0), vec4(0), opacity); } @@ -80,11 +81,12 @@ void main(void) { cam._viewInverse, 1.0, occlusionTex, - fragPosition, + fragPositionES, + fragPositionWS, albedo, fresnel, metallic, emissive, - surface, opacity, localLighting.rgb), + surfaceWS, opacity, localLighting.rgb), opacity); } diff --git a/libraries/render-utils/src/model_translucent.slv b/libraries/render-utils/src/model_translucent.slv index 7a57a4baec..61a1c96ce8 100644 --- a/libraries/render-utils/src/model_translucent.slv +++ b/libraries/render-utils/src/model_translucent.slv @@ -22,9 +22,9 @@ out float _alpha; out vec2 _texCoord0; out vec2 _texCoord1; -out vec4 _position; -out vec4 _worldPosition; -out vec3 _normal; +out vec4 _positionES; +out vec4 _positionWS; +out vec3 _normalWS; out vec3 _color; void main(void) { @@ -38,7 +38,7 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> - <$transformModelToWorldPos(obj, inPosition, _worldPosition)$> - <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> + <$transformModelToEyeAndClipPos(cam, obj, inPosition, _positionES, gl_Position)$> + <$transformModelToWorldPos(obj, inPosition, _positionWS)$> + <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> } diff --git a/libraries/render-utils/src/model_translucent_fade.slf b/libraries/render-utils/src/model_translucent_fade.slf index b81ed06479..47349930de 100644 --- a/libraries/render-utils/src/model_translucent_fade.slf +++ b/libraries/render-utils/src/model_translucent_fade.slf @@ -24,11 +24,11 @@ in vec2 _texCoord0; in vec2 _texCoord1; -in vec4 _position; -in vec3 _normal; +in vec4 _positionES; +in vec4 _positionWS; +in vec3 _normalWS; in vec3 _color; in float _alpha; -in vec4 _worldPosition; out vec4 _fragColor; @@ -37,7 +37,7 @@ void main(void) { FadeObjectParams fadeParams; <$fetchFadeObjectParams(fadeParams)$> - applyFade(fadeParams, _worldPosition.xyz, fadeEmissive); + applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); @@ -60,20 +60,21 @@ void main(void) { vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - vec3 fragPosition = _position.xyz; + vec3 fragPositionES = _positionES.xyz; + vec3 fragPositionWS = _positionWS.xyz; // Lighting is done in world space - vec3 fragNormal = normalize(_normal); + vec3 fragNormalWS = normalize(_normalWS); TransformCamera cam = getTransformCamera(); - vec3 fragEyeVector = vec3(cam._viewInverse * vec4(-fragPosition, 0.0)); - vec3 fragEyeDir = normalize(fragEyeVector); - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + vec3 fragToEyeWS = fragPositionWS - cam._viewInverse[3].xyz; + vec3 fragToEyeDirWS = normalize(fragToEyeWS); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); vec4 localLighting = vec4(0.0); - <$fetchClusterInfo(_worldPosition)$>; + <$fetchClusterInfo(_positionWS)$>; if (hasLocalLights(numLights, clusterPos, dims)) { - localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, surface, + localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS, metallic, fresnel, albedo, 0.0, vec4(0), vec4(0), opacity); } @@ -82,11 +83,12 @@ void main(void) { cam._viewInverse, 1.0, occlusionTex, - fragPosition, + fragPositionES, + fragPositionWS, albedo, fresnel, metallic, - emissive+fadeEmissive, - surface, opacity, localLighting.rgb), + emissive + fadeEmissive, + surfaceWS, opacity, localLighting.rgb), opacity); } diff --git a/libraries/render-utils/src/model_translucent_normal_map.slf b/libraries/render-utils/src/model_translucent_normal_map.slf index 52015660c6..89f5f46f6a 100644 --- a/libraries/render-utils/src/model_translucent_normal_map.slf +++ b/libraries/render-utils/src/model_translucent_normal_map.slf @@ -28,10 +28,10 @@ in vec2 _texCoord0; in vec2 _texCoord1; -in vec4 _position; -in vec4 _worldPosition; -in vec3 _normal; -in vec3 _tangent; +in vec4 _positionES; +in vec4 _positionWS; +in vec3 _normalWS; +in vec3 _tangentWS; in vec3 _color; in float _alpha; @@ -59,20 +59,22 @@ void main(void) { vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - vec3 fragPosition = _position.xyz; - vec3 fragNormal; - <$evalMaterialNormalLOD(_position, normalTex, _normal, _tangent, fragNormal)$> + vec3 fragPositionES = _positionES.xyz; + vec3 fragPositionWS = _positionWS.xyz; + // Lighting is done in world space + vec3 fragNormalWS; + <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> TransformCamera cam = getTransformCamera(); - vec3 fragEyeVector = vec3(cam._viewInverse * vec4(-fragPosition, 0.0)); - vec3 fragEyeDir = normalize(fragEyeVector); - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + vec3 fragToEyeWS = fragPositionWS - cam._viewInverse[3].xyz; + vec3 fragToEyeDirWS = normalize(fragToEyeWS); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); vec4 localLighting = vec4(0.0); - <$fetchClusterInfo(_worldPosition)$>; + <$fetchClusterInfo(_positionWS)$>; if (hasLocalLights(numLights, clusterPos, dims)) { - localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, surface, + localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS, metallic, fresnel, albedo, 0.0, vec4(0), vec4(0), opacity); } @@ -81,11 +83,12 @@ void main(void) { cam._viewInverse, 1.0, occlusionTex, - fragPosition, + fragPositionES, + fragPositionWS, albedo, fresnel, metallic, emissive, - surface, opacity, localLighting.rgb), + surfaceWS, opacity, localLighting.rgb), opacity); } diff --git a/libraries/render-utils/src/model_translucent_normal_map.slv b/libraries/render-utils/src/model_translucent_normal_map.slv index 981a03627b..21d56418c0 100644 --- a/libraries/render-utils/src/model_translucent_normal_map.slv +++ b/libraries/render-utils/src/model_translucent_normal_map.slv @@ -22,10 +22,10 @@ out float _alpha; out vec2 _texCoord0; out vec2 _texCoord1; -out vec4 _position; -out vec4 _worldPosition; -out vec3 _normal; -out vec3 _tangent; +out vec4 _positionES; +out vec4 _positionWS; +out vec3 _normalWS; +out vec3 _tangentWS; out vec3 _color; void main(void) { @@ -39,8 +39,8 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> - <$transformModelToWorldPos(obj, inPosition, _worldPosition)$> - <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> - <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangent)$> + <$transformModelToEyeAndClipPos(cam, obj, inPosition, _positionES, gl_Position)$> + <$transformModelToWorldPos(obj, inPosition, _positionWS)$> + <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> + <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangentWS)$> } diff --git a/libraries/render-utils/src/model_translucent_normal_map_fade.slf b/libraries/render-utils/src/model_translucent_normal_map_fade.slf index c6c0e16812..a87167af63 100644 --- a/libraries/render-utils/src/model_translucent_normal_map_fade.slf +++ b/libraries/render-utils/src/model_translucent_normal_map_fade.slf @@ -31,12 +31,12 @@ in vec2 _texCoord0; in vec2 _texCoord1; -in vec4 _position; -in vec3 _normal; -in vec3 _tangent; +in vec4 _positionES; +in vec3 _normalWS; +in vec3 _tangentWS; in vec3 _color; in float _alpha; -in vec4 _worldPosition; +in vec4 _positionWS; out vec4 _fragColor; @@ -45,7 +45,7 @@ void main(void) { FadeObjectParams fadeParams; <$fetchFadeObjectParams(fadeParams)$> - applyFade(fadeParams, _worldPosition.xyz, fadeEmissive); + applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); int matKey = getMaterialKey(mat); @@ -68,21 +68,22 @@ void main(void) { vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - vec3 fragPosition = _position.xyz; + vec3 fragPositionES = _positionES.xyz; + vec3 fragPositionWS = _positionWS.xyz; // Lighting is done in world space - vec3 fragNormal; - <$evalMaterialNormalLOD(_position, normalTex, _normal, _tangent, fragNormal)$> + vec3 fragNormalWS; + <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> TransformCamera cam = getTransformCamera(); - vec3 fragEyeVector = vec3(cam._viewInverse * vec4(-fragPosition, 0.0)); - vec3 fragEyeDir = normalize(fragEyeVector); - SurfaceData surface = initSurfaceData(roughness, fragNormal, fragEyeDir); + vec3 fragToEyeWS = fragPositionWS - cam._viewInverse[3].xyz; + vec3 fragToEyeDirWS = normalize(fragToEyeWS); + SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); vec4 localLighting = vec4(0.0); - <$fetchClusterInfo(_worldPosition)$>; + <$fetchClusterInfo(_positionWS)$>; if (hasLocalLights(numLights, clusterPos, dims)) { - localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, surface, + localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS, metallic, fresnel, albedo, 0.0, vec4(0), vec4(0), opacity); } @@ -91,11 +92,12 @@ void main(void) { cam._viewInverse, 1.0, occlusionTex, - fragPosition, + fragPositionES, + fragPositionWS, albedo, fresnel, metallic, - emissive+fadeEmissive, - surface, opacity, localLighting.rgb), + emissive + fadeEmissive, + surfaceWS, opacity, localLighting.rgb), opacity); } From 8ef25301cbc0e20419d2f9112a603e15b62f21ee Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Fri, 13 Apr 2018 17:14:19 +0200 Subject: [PATCH 03/11] Fixed some shader program link errors --- libraries/render-utils/src/model_fade.slf | 10 +++++----- libraries/render-utils/src/model_fade.slv | 12 +++++------ .../src/model_normal_map_fade.slf | 20 +++++++++---------- .../src/model_normal_map_fade.slv | 16 +++++++-------- .../src/model_translucent_unlit_fade.slf | 4 ++-- .../render-utils/src/model_unlit_fade.slf | 8 ++++---- .../render-utils/src/skin_model_fade.slv | 12 +++++------ .../render-utils/src/skin_model_fade_dq.slv | 12 +++++------ .../src/skin_model_normal_map.slv | 12 +++++------ .../src/skin_model_normal_map_dq.slv | 12 +++++------ .../src/skin_model_normal_map_fade.slv | 16 +++++++-------- .../src/skin_model_normal_map_fade_dq.slv | 16 +++++++-------- 12 files changed, 75 insertions(+), 75 deletions(-) diff --git a/libraries/render-utils/src/model_fade.slf b/libraries/render-utils/src/model_fade.slf index 577324f97a..432fc0239b 100644 --- a/libraries/render-utils/src/model_fade.slf +++ b/libraries/render-utils/src/model_fade.slf @@ -22,19 +22,19 @@ <@include Fade.slh@> <$declareFadeFragment()$> -in vec4 _position; +in vec4 _positionES; in vec2 _texCoord0; in vec2 _texCoord1; -in vec3 _normal; +in vec3 _normalWS; in vec3 _color; -in vec4 _worldPosition; +in vec4 _positionWS; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; <$fetchFadeObjectParams(fadeParams)$> - applyFade(fadeParams, _worldPosition.xyz, fadeEmissive); + applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); @@ -61,7 +61,7 @@ void main(void) { float scattering = getMaterialScattering(mat); packDeferredFragment( - normalize(_normal), + normalize(_normalWS), opacity, albedo, roughness, diff --git a/libraries/render-utils/src/model_fade.slv b/libraries/render-utils/src/model_fade.slv index 61b8e9e1b6..6e3a8271ce 100644 --- a/libraries/render-utils/src/model_fade.slv +++ b/libraries/render-utils/src/model_fade.slv @@ -22,9 +22,9 @@ out float _alpha; out vec2 _texCoord0; out vec2 _texCoord1; -out vec4 _position; -out vec4 _worldPosition; -out vec3 _normal; +out vec4 _positionES; +out vec4 _positionWS; +out vec3 _normalWS; out vec3 _color; void main(void) { @@ -38,7 +38,7 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> - <$transformModelToWorldPos(obj, inPosition, _worldPosition)$> - <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> + <$transformModelToEyeAndClipPos(cam, obj, inPosition, _positionES, gl_Position)$> + <$transformModelToWorldPos(obj, inPosition, _positionWS)$> + <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> } diff --git a/libraries/render-utils/src/model_normal_map_fade.slf b/libraries/render-utils/src/model_normal_map_fade.slf index bf6222652c..7ece8fea38 100644 --- a/libraries/render-utils/src/model_normal_map_fade.slf +++ b/libraries/render-utils/src/model_normal_map_fade.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// model_normal_specular_map_fade.frag +// model_normal_map_fade.frag // fragment shader // // Created by Olivier Prat on 06/05/17. @@ -22,20 +22,20 @@ <@include Fade.slh@> <$declareFadeFragment()$> -in vec4 _position; +in vec4 _positionES; in vec2 _texCoord0; in vec2 _texCoord1; -in vec3 _normal; -in vec3 _tangent; +in vec3 _normalWS; +in vec3 _tangentWS; in vec3 _color; -in vec4 _worldPosition; +in vec4 _positionWS; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; <$fetchFadeObjectParams(fadeParams)$> - applyFade(fadeParams, _worldPosition.xyz, fadeEmissive); + applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); @@ -56,8 +56,8 @@ void main(void) { vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - vec3 fragNormal; - <$evalMaterialNormalLOD(_position, normalTex, _normal, _tangent, fragNormal)$> + vec3 fragNormalWS; + <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> float metallic = getMaterialMetallic(mat); <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; @@ -65,12 +65,12 @@ void main(void) { float scattering = getMaterialScattering(mat); packDeferredFragment( - normalize(fragNormal.xyz), + normalize(fragNormalWS.xyz), opacity, albedo, roughness, metallic, - emissive+fadeEmissive, + emissive + fadeEmissive, occlusionTex, scattering); } diff --git a/libraries/render-utils/src/model_normal_map_fade.slv b/libraries/render-utils/src/model_normal_map_fade.slv index 6a6142d317..a75087f93d 100644 --- a/libraries/render-utils/src/model_normal_map_fade.slv +++ b/libraries/render-utils/src/model_normal_map_fade.slv @@ -20,12 +20,12 @@ <@include MaterialTextures.slh@> <$declareMaterialTexMapArrayBuffer()$> -out vec4 _position; -out vec4 _worldPosition; +out vec4 _positionES; +out vec4 _positionWS; out vec2 _texCoord0; out vec2 _texCoord1; -out vec3 _normal; -out vec3 _tangent; +out vec3 _normalWS; +out vec3 _tangentWS; out vec3 _color; out float _alpha; @@ -41,8 +41,8 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> - <$transformModelToWorldPos(obj, inPosition, _worldPosition)$> - <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> - <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangent)$> + <$transformModelToEyeAndClipPos(cam, obj, inPosition, _positionES, gl_Position)$> + <$transformModelToWorldPos(obj, inPosition, _positionWS)$> + <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> + <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangentWS)$> } diff --git a/libraries/render-utils/src/model_translucent_unlit_fade.slf b/libraries/render-utils/src/model_translucent_unlit_fade.slf index ea8a912a86..0f7c3366bb 100644 --- a/libraries/render-utils/src/model_translucent_unlit_fade.slf +++ b/libraries/render-utils/src/model_translucent_unlit_fade.slf @@ -24,7 +24,7 @@ in vec2 _texCoord0; in vec3 _color; in float _alpha; -in vec4 _worldPosition; +in vec4 _positionWS; out vec4 _fragColor; @@ -33,7 +33,7 @@ void main(void) { FadeObjectParams fadeParams; <$fetchFadeObjectParams(fadeParams)$> - applyFade(fadeParams, _worldPosition.xyz, fadeEmissive); + applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); diff --git a/libraries/render-utils/src/model_unlit_fade.slf b/libraries/render-utils/src/model_unlit_fade.slf index 50c1681c0d..d8f8cfce38 100644 --- a/libraries/render-utils/src/model_unlit_fade.slf +++ b/libraries/render-utils/src/model_unlit_fade.slf @@ -23,17 +23,17 @@ <$declareMaterialTextures(ALBEDO)$> in vec2 _texCoord0; -in vec3 _normal; +in vec3 _normalWS; in vec3 _color; in float _alpha; -in vec4 _worldPosition; +in vec4 _positionWS; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; <$fetchFadeObjectParams(fadeParams)$> - applyFade(fadeParams, _worldPosition.xyz, fadeEmissive); + applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); @@ -48,7 +48,7 @@ void main(void) { albedo *= _color; albedo += fadeEmissive; packDeferredFragmentUnlit( - normalize(_normal), + normalize(_normalWS), opacity, albedo * isUnlitEnabled()); } diff --git a/libraries/render-utils/src/skin_model_fade.slv b/libraries/render-utils/src/skin_model_fade.slv index 4f459d75f3..6c3df7586d 100644 --- a/libraries/render-utils/src/skin_model_fade.slv +++ b/libraries/render-utils/src/skin_model_fade.slv @@ -23,13 +23,13 @@ <@include MaterialTextures.slh@> <$declareMaterialTexMapArrayBuffer()$> -out vec4 _position; +out vec4 _positionES; out vec2 _texCoord0; out vec2 _texCoord1; -out vec3 _normal; +out vec3 _normalWS; out vec3 _color; out float _alpha; -out vec4 _worldPosition; +out vec4 _positionWS; void main(void) { vec4 position = vec4(0.0, 0.0, 0.0, 0.0); @@ -48,7 +48,7 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> - <$transformModelToWorldPos(obj, position, _worldPosition)$> - <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, _normal.xyz)$> + <$transformModelToEyeAndClipPos(cam, obj, position, _positionES, gl_Position)$> + <$transformModelToWorldPos(obj, position, _positionWS)$> + <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, _normalWS.xyz)$> } diff --git a/libraries/render-utils/src/skin_model_fade_dq.slv b/libraries/render-utils/src/skin_model_fade_dq.slv index 232170d714..9d9ddaeaf8 100644 --- a/libraries/render-utils/src/skin_model_fade_dq.slv +++ b/libraries/render-utils/src/skin_model_fade_dq.slv @@ -23,13 +23,13 @@ <@include MaterialTextures.slh@> <$declareMaterialTexMapArrayBuffer()$> -out vec4 _position; +out vec4 _positionES; out vec2 _texCoord0; out vec2 _texCoord1; -out vec3 _normal; +out vec3 _normalWS; out vec3 _color; out float _alpha; -out vec4 _worldPosition; +out vec4 _positionWS; void main(void) { vec4 position = vec4(0.0, 0.0, 0.0, 0.0); @@ -48,7 +48,7 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> - <$transformModelToWorldPos(obj, position, _worldPosition)$> - <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, _normal.xyz)$> + <$transformModelToEyeAndClipPos(cam, obj, position, _positionES, gl_Position)$> + <$transformModelToWorldPos(obj, position, _positionWS)$> + <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, _normalWS.xyz)$> } diff --git a/libraries/render-utils/src/skin_model_normal_map.slv b/libraries/render-utils/src/skin_model_normal_map.slv index b54c84e5b3..fd3efd087e 100644 --- a/libraries/render-utils/src/skin_model_normal_map.slv +++ b/libraries/render-utils/src/skin_model_normal_map.slv @@ -23,11 +23,11 @@ <@include MaterialTextures.slh@> <$declareMaterialTexMapArrayBuffer()$> -out vec4 _position; +out vec4 _positionES; out vec2 _texCoord0; out vec2 _texCoord1; -out vec3 _normal; -out vec3 _tangent; +out vec3 _normalWS; +out vec3 _tangentWS; out vec3 _color; out float _alpha; @@ -52,10 +52,10 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> + <$transformModelToEyeAndClipPos(cam, obj, position, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$> <$transformModelToWorldDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$> - _normal = interpolatedNormal.xyz; - _tangent = interpolatedTangent.xyz; + _normalWS = interpolatedNormal.xyz; + _tangentWS = interpolatedTangent.xyz; } diff --git a/libraries/render-utils/src/skin_model_normal_map_dq.slv b/libraries/render-utils/src/skin_model_normal_map_dq.slv index b34f68d291..4c56e0d64d 100644 --- a/libraries/render-utils/src/skin_model_normal_map_dq.slv +++ b/libraries/render-utils/src/skin_model_normal_map_dq.slv @@ -23,11 +23,11 @@ <@include MaterialTextures.slh@> <$declareMaterialTexMapArrayBuffer()$> -out vec4 _position; +out vec4 _positionES; out vec2 _texCoord0; out vec2 _texCoord1; -out vec3 _normal; -out vec3 _tangent; +out vec3 _normalWS; +out vec3 _tangentWS; out vec3 _color; out float _alpha; @@ -52,10 +52,10 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> + <$transformModelToEyeAndClipPos(cam, obj, position, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$> <$transformModelToWorldDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$> - _normal = interpolatedNormal.xyz; - _tangent = interpolatedTangent.xyz; + _normalWS = interpolatedNormal.xyz; + _tangentWS = interpolatedTangent.xyz; } diff --git a/libraries/render-utils/src/skin_model_normal_map_fade.slv b/libraries/render-utils/src/skin_model_normal_map_fade.slv index 0e788b81b5..47cc790f70 100644 --- a/libraries/render-utils/src/skin_model_normal_map_fade.slv +++ b/libraries/render-utils/src/skin_model_normal_map_fade.slv @@ -23,14 +23,14 @@ <@include MaterialTextures.slh@> <$declareMaterialTexMapArrayBuffer()$> -out vec4 _position; +out vec4 _positionES; out vec2 _texCoord0; out vec2 _texCoord1; -out vec3 _normal; -out vec3 _tangent; +out vec3 _normalWS; +out vec3 _tangentWS; out vec3 _color; out float _alpha; -out vec4 _worldPosition; +out vec4 _positionWS; void main(void) { vec4 position = vec4(0.0, 0.0, 0.0, 0.0); @@ -53,11 +53,11 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> - <$transformModelToWorldPos(obj, position, _worldPosition)$> + <$transformModelToEyeAndClipPos(cam, obj, position, _positionES, gl_Position)$> + <$transformModelToWorldPos(obj, position, _positionWS)$> <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$> <$transformModelToWorldDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$> - _normal = interpolatedNormal.xyz; - _tangent = interpolatedTangent.xyz; + _normalWS = interpolatedNormal.xyz; + _tangentWS = interpolatedTangent.xyz; } diff --git a/libraries/render-utils/src/skin_model_normal_map_fade_dq.slv b/libraries/render-utils/src/skin_model_normal_map_fade_dq.slv index 230077ba3b..092d7b214f 100644 --- a/libraries/render-utils/src/skin_model_normal_map_fade_dq.slv +++ b/libraries/render-utils/src/skin_model_normal_map_fade_dq.slv @@ -23,14 +23,14 @@ <@include MaterialTextures.slh@> <$declareMaterialTexMapArrayBuffer()$> -out vec4 _position; +out vec4 _positionES; out vec2 _texCoord0; out vec2 _texCoord1; -out vec3 _normal; -out vec3 _tangent; +out vec3 _normalWS; +out vec3 _tangentWS; out vec3 _color; out float _alpha; -out vec4 _worldPosition; +out vec4 _positionWS; void main(void) { vec4 position = vec4(0.0, 0.0, 0.0, 0.0); @@ -53,11 +53,11 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); - <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> - <$transformModelToWorldPos(obj, position, _worldPosition)$> + <$transformModelToEyeAndClipPos(cam, obj, position, _positionES, gl_Position)$> + <$transformModelToWorldPos(obj, position, _positionWS)$> <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$> <$transformModelToWorldDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$> - _normal = interpolatedNormal.xyz; - _tangent = interpolatedTangent.xyz; + _normalWS = interpolatedNormal.xyz; + _tangentWS = interpolatedTangent.xyz; } From 9ad9c070f8e4f83791e3943afe1a3b4f08ee6bc9 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Mon, 16 Apr 2018 08:50:18 +0200 Subject: [PATCH 04/11] Some small shader optimizations --- libraries/render-utils/src/DeferredGlobalLight.slh | 7 ++----- libraries/render-utils/src/ForwardGlobalLight.slh | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index c3ab17f72b..f6c1d290a7 100644 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -20,7 +20,6 @@ <@include LightAmbient.slh@> <@include LightDirectional.slh@> - <@func fetchGlobalLight()@> // Get light Light light = getKeyLight(); @@ -193,14 +192,13 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl vec3 ambientSpecular; evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; - color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; - color += directionalSpecular / opacity; + color += (ambientSpecular + directionalSpecular) / opacity; return color; } @@ -227,14 +225,13 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( vec3 ambientSpecular; evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; - color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; - color += directionalSpecular / opacity; + color += (ambientSpecular + directionalSpecular) / opacity; // Haze if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { diff --git a/libraries/render-utils/src/ForwardGlobalLight.slh b/libraries/render-utils/src/ForwardGlobalLight.slh index 3aadb182fa..84999f347b 100644 --- a/libraries/render-utils/src/ForwardGlobalLight.slh +++ b/libraries/render-utils/src/ForwardGlobalLight.slh @@ -20,7 +20,6 @@ <@include LightAmbient.slh@> <@include LightDirectional.slh@> - <@func prepareGlobalLight(positionES, normalWS)@> // prepareGlobalLight // Transform directions to worldspace @@ -192,14 +191,13 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl vec3 ambientSpecular; evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; - color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; - color += directionalSpecular / opacity; + color += (ambientSpecular + directionalSpecular) / opacity; return color; } @@ -219,14 +217,13 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze( vec3 ambientSpecular; evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, surfaceWS, metallic, fresnel, albedo, obscurance); color += ambientDiffuse; - color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, surfaceWS, metallic, fresnel, albedo, shadowAttenuation); color += directionalDiffuse; - color += directionalSpecular / opacity; + color += (ambientSpecular + directionalSpecular) / opacity; // Haze // FIXME - temporarily removed until we support it for forward... From 6a089be973b240ead39692c073896540ecc4521a Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Mon, 16 Apr 2018 12:15:08 +0200 Subject: [PATCH 05/11] Enabled haze to be vertically inverted (ceiling lower than base) --- libraries/graphics/src/graphics/Haze.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/graphics/src/graphics/Haze.h b/libraries/graphics/src/graphics/Haze.h index c38fadef94..59138319f4 100644 --- a/libraries/graphics/src/graphics/Haze.h +++ b/libraries/graphics/src/graphics/Haze.h @@ -57,7 +57,7 @@ namespace graphics { // limit range and altitude to no less than 1.0 metres static inline float convertHazeRangeToHazeRangeFactor(const float hazeRange) { return -LOG_P_005 / glm::max(hazeRange, 1.0f); } - static inline float convertHazeAltitudeToHazeAltitudeFactor(const float hazeHeight) { return -LOG_P_005 / glm::max(hazeHeight, 1.0f); } + static inline float convertHazeAltitudeToHazeAltitudeFactor(const float hazeHeight) { return -(LOG_P_005 * glm::sign(hazeHeight)) / glm::max(glm::abs(hazeHeight), 1.0f); } // Derivation (s is the proportion of sun blend, a is the angle at which the blend is 50%, solve for m = 0.5 // s = dot(lookAngle, sunAngle) = cos(a) From 93cf399fd6667ea74108af842dd3b81b75d60766 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 16 Apr 2018 15:07:45 -0700 Subject: [PATCH 06/11] Only dismiss letterbox when clicking on grey areas --- .../resources/qml/hifi/LetterboxMessage.qml | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/hifi/LetterboxMessage.qml b/interface/resources/qml/hifi/LetterboxMessage.qml index d88bf1b147..c0f3fa1006 100644 --- a/interface/resources/qml/hifi/LetterboxMessage.qml +++ b/interface/resources/qml/hifi/LetterboxMessage.qml @@ -135,9 +135,46 @@ Item { } } } + // Left gray MouseArea MouseArea { - anchors.fill: parent - acceptedButtons: Qt.LeftButton + anchors.left: parent.left; + anchors.right: textContainer.left; + anchors.top: textContainer.top; + anchors.bottom: textContainer.bottom; + acceptedButtons: Qt.LeftButton; + onClicked: { + letterbox.visible = false; + } + } + // Right gray MouseArea + MouseArea { + anchors.left: textContainer.left; + anchors.right: parent.left; + anchors.top: textContainer.top; + anchors.bottom: textContainer.bottom; + acceptedButtons: Qt.LeftButton; + onClicked: { + letterbox.visible = false; + } + } + // Top gray MouseArea + MouseArea { + anchors.left: parent.left; + anchors.right: parent.right; + anchors.top: parent.top; + anchors.bottom: textContainer.top; + acceptedButtons: Qt.LeftButton; + onClicked: { + letterbox.visible = false; + } + } + // Bottom gray MouseArea + MouseArea { + anchors.left: parent.left; + anchors.right: parent.right; + anchors.top: textContainer.bottom; + anchors.bottom: parent.bottom; + acceptedButtons: Qt.LeftButton; onClicked: { letterbox.visible = false; } From f36a5289c9ac6a79880dc0cc10bb84daf3608929 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 17 Apr 2018 14:33:11 +1200 Subject: [PATCH 07/11] Add Entities materialData JSDoc --- libraries/entities/src/EntityItemProperties.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index f78168b05d..4638b46437 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -695,8 +695,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * @typedef {object} Entities.EntityProperties-Material * @property {string} materialURL="" - URL to a {@link MaterialResource}. If you append ?name to the URL, the * material with that name in the {@link MaterialResource} will be applied to the entity.
- * Alternatively, set the property value to "userData" to use the {@link Entities.EntityProperties|userData} - * entity property to live edit the material resource values. + * Alternatively, set the property value to "materialData" to use the materialData property + * for the {@link MaterialResource} values. * @property {number} priority=0 - The priority for applying the material to its parent. Only the highest priority material is * applied, with materials of the same priority randomly assigned. Materials that come with the model have a priority of * 0. @@ -710,6 +710,9 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * { x: 0, y: 0 }{ x: 1, y: 1 }. * @property {Vec2} materialMappingScale=1,1 - How much to scale the material within the parent's UV-space. * @property {number} materialMappingRot=0 - How much to rotate the material within the parent's UV-space, in degrees. + * @property {string} materialData="" - Used to store {@link MaterialResource} data as a JSON string. You can use + * JSON.parse() to parse the string into a JavaScript object which you can manipulate the properties of, and + * use JSON.stringify() to convert the object into a string to put in the property. * @example Color a sphere using a Material entity. * var entityID = Entities.addEntity({ * type: "Sphere", @@ -722,13 +725,14 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * var materialID = Entities.addEntity({ * type: "Material", * parentID: entityID, - * materialURL: "userData", + * materialURL: "materialData", * priority: 1, - * userData: JSON.stringify({ + * materialData: JSON.stringify({ + * materialVersion: 1, * materials: { * // Can only set albedo on a Shape entity. * // Value overrides entity's "color" property. - * albedo: [1.0, 0, 0] + * albedo: [1.0, 1.0, 0] // Yellow * } * }), * }); From 40e311fe1ee640c68ab87eeae71aa1ffff44e74f Mon Sep 17 00:00:00 2001 From: MiladNazeri Date: Tue, 17 Apr 2018 15:20:05 -0700 Subject: [PATCH 08/11] Fix QT typo --- BUILD_LINUX.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BUILD_LINUX.md b/BUILD_LINUX.md index 64c0e9a643..0daef5ae05 100644 --- a/BUILD_LINUX.md +++ b/BUILD_LINUX.md @@ -11,11 +11,11 @@ Should you choose not to install Qt5 via a package manager that handles dependen ## Ubuntu 16.04 specific build guide ### Prepare environment - +hifiqt5.10.1 Install qt: ```bash -wget http://debian.highfidelity.com/pool/h/hi/hifi-qt5.10.1_5.10.1_amd64.deb -sudo dpkg -i hifi-qt5.10.1_5.10.1_amd64.deb +wget http://debian.highfidelity.com/pool/h/hi/hifiqt5.10.1_5.10.1_amd64.deb +sudo dpkg -i hifiqt5.10.1_5.10.1_amd64.deb ``` Install build dependencies: From e01e7cc7bc3a814d4b11e3c7ce42f1ab33927ffa Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 16 Apr 2018 15:25:04 -0700 Subject: [PATCH 09/11] Be a bit more efficient --- .../resources/qml/hifi/LetterboxMessage.qml | 62 ++++++------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/interface/resources/qml/hifi/LetterboxMessage.qml b/interface/resources/qml/hifi/LetterboxMessage.qml index c0f3fa1006..8a18d88842 100644 --- a/interface/resources/qml/hifi/LetterboxMessage.qml +++ b/interface/resources/qml/hifi/LetterboxMessage.qml @@ -30,6 +30,16 @@ Item { color: "black" opacity: 0.5 radius: popupRadius + + MouseArea { + anchors.fill: parent; + hoverEnabled: true; + acceptedButtons: Qt.LeftButton; + propagateComposedEvents: false; + onClicked: { + letterbox.visible = false; + } + } } Rectangle { id: textContainer; @@ -38,6 +48,14 @@ Item { anchors.centerIn: parent radius: popupRadius color: "white" + + // Prevent dismissing the popup by clicking on the textContainer + MouseArea { + anchors.fill: parent; + hoverEnabled: true; + propagateComposedEvents: false; + } + Item { id: contentContainer width: parent.width - 50 @@ -135,48 +153,4 @@ Item { } } } - // Left gray MouseArea - MouseArea { - anchors.left: parent.left; - anchors.right: textContainer.left; - anchors.top: textContainer.top; - anchors.bottom: textContainer.bottom; - acceptedButtons: Qt.LeftButton; - onClicked: { - letterbox.visible = false; - } - } - // Right gray MouseArea - MouseArea { - anchors.left: textContainer.left; - anchors.right: parent.left; - anchors.top: textContainer.top; - anchors.bottom: textContainer.bottom; - acceptedButtons: Qt.LeftButton; - onClicked: { - letterbox.visible = false; - } - } - // Top gray MouseArea - MouseArea { - anchors.left: parent.left; - anchors.right: parent.right; - anchors.top: parent.top; - anchors.bottom: textContainer.top; - acceptedButtons: Qt.LeftButton; - onClicked: { - letterbox.visible = false; - } - } - // Bottom gray MouseArea - MouseArea { - anchors.left: parent.left; - anchors.right: parent.right; - anchors.top: textContainer.bottom; - anchors.bottom: parent.bottom; - acceptedButtons: Qt.LeftButton; - onClicked: { - letterbox.visible = false; - } - } } From c8bef8651f904343901ff704ec4bbd8446a9435b Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Thu, 19 Apr 2018 10:04:38 +0200 Subject: [PATCH 10/11] Fixed weird specular on hair an teleportation target! Was a stupid mistake... --- libraries/render-utils/src/Haze.slh | 16 ++++++++-------- libraries/render-utils/src/model_translucent.slf | 4 ++-- .../render-utils/src/model_translucent_fade.slf | 2 +- .../src/model_translucent_normal_map.slf | 2 +- .../src/model_translucent_normal_map_fade.slf | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libraries/render-utils/src/Haze.slh b/libraries/render-utils/src/Haze.slh index a9c8ff829e..ab973ba752 100644 --- a/libraries/render-utils/src/Haze.slh +++ b/libraries/render-utils/src/Haze.slh @@ -109,17 +109,17 @@ vec4 computeHazeColor(vec4 fragColor, vec3 fragPositionES, vec3 fragPositionWS, // Convert haze colour from uniform into a vec4 vec4 hazeColor = vec4(hazeParams.hazeColor, 1.0); - // Directional light component is a function of the angle from the eye, between the fragment and the sun - vec3 fragToEyeDirWS = normalize(fragPositionWS - eyePositionWS); - - float glareComponent = max(0.0, dot(fragToEyeDirWS, -lightDirectionWS)); - float power = min(1.0, pow(glareComponent, hazeParams.hazeGlareBlend)); - - vec4 glareColor = vec4(hazeParams.hazeGlareColor, 1.0); - // Use the haze colour for the glare colour, if blend is not enabled vec4 blendedHazeColor; if ((hazeParams.hazeMode & HAZE_MODE_IS_ENABLE_LIGHT_BLEND) == HAZE_MODE_IS_ENABLE_LIGHT_BLEND) { + // Directional light component is a function of the angle from the eye, between the fragment and the sun + vec3 fragToEyeDirWS = normalize(fragPositionWS - eyePositionWS); + + float glareComponent = max(0.0, dot(fragToEyeDirWS, -lightDirectionWS)); + float power = min(1.0, pow(glareComponent, hazeParams.hazeGlareBlend)); + + vec4 glareColor = vec4(hazeParams.hazeGlareColor, 1.0); + blendedHazeColor = mix(hazeColor, glareColor, power); } else { blendedHazeColor = hazeColor; diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index f109170068..71f76c8a8d 100644 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -64,7 +64,7 @@ void main(void) { vec3 fragNormalWS = normalize(_normalWS); TransformCamera cam = getTransformCamera(); - vec3 fragToEyeWS = fragPositionWS - cam._viewInverse[3].xyz; + vec3 fragToEyeWS = cam._viewInverse[3].xyz - fragPositionWS; vec3 fragToEyeDirWS = normalize(fragToEyeWS); SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); @@ -77,7 +77,7 @@ void main(void) { vec4(0), vec4(0), opacity); } - _fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze( + _fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze( cam._viewInverse, 1.0, occlusionTex, diff --git a/libraries/render-utils/src/model_translucent_fade.slf b/libraries/render-utils/src/model_translucent_fade.slf index 47349930de..8b40186448 100644 --- a/libraries/render-utils/src/model_translucent_fade.slf +++ b/libraries/render-utils/src/model_translucent_fade.slf @@ -66,7 +66,7 @@ void main(void) { vec3 fragNormalWS = normalize(_normalWS); TransformCamera cam = getTransformCamera(); - vec3 fragToEyeWS = fragPositionWS - cam._viewInverse[3].xyz; + vec3 fragToEyeWS = cam._viewInverse[3].xyz - fragPositionWS; vec3 fragToEyeDirWS = normalize(fragToEyeWS); SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); diff --git a/libraries/render-utils/src/model_translucent_normal_map.slf b/libraries/render-utils/src/model_translucent_normal_map.slf index 89f5f46f6a..320e883bb0 100644 --- a/libraries/render-utils/src/model_translucent_normal_map.slf +++ b/libraries/render-utils/src/model_translucent_normal_map.slf @@ -66,7 +66,7 @@ void main(void) { <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> TransformCamera cam = getTransformCamera(); - vec3 fragToEyeWS = fragPositionWS - cam._viewInverse[3].xyz; + vec3 fragToEyeWS = cam._viewInverse[3].xyz - fragPositionWS; vec3 fragToEyeDirWS = normalize(fragToEyeWS); SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); diff --git a/libraries/render-utils/src/model_translucent_normal_map_fade.slf b/libraries/render-utils/src/model_translucent_normal_map_fade.slf index a87167af63..0e114f7fdd 100644 --- a/libraries/render-utils/src/model_translucent_normal_map_fade.slf +++ b/libraries/render-utils/src/model_translucent_normal_map_fade.slf @@ -75,7 +75,7 @@ void main(void) { <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> TransformCamera cam = getTransformCamera(); - vec3 fragToEyeWS = fragPositionWS - cam._viewInverse[3].xyz; + vec3 fragToEyeWS = cam._viewInverse[3].xyz - fragPositionWS; vec3 fragToEyeDirWS = normalize(fragToEyeWS); SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); From 764aa0006969d56d579f0e2223dfb5d76b5c3742 Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Thu, 19 Apr 2018 07:33:14 -0700 Subject: [PATCH 11/11] Coding standard fixes --- interface/src/scripting/AudioDevices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/scripting/AudioDevices.cpp b/interface/src/scripting/AudioDevices.cpp index 34a3630b78..ee615cde20 100644 --- a/interface/src/scripting/AudioDevices.cpp +++ b/interface/src/scripting/AudioDevices.cpp @@ -188,7 +188,7 @@ void AudioDeviceList::onDeviceChanged(const QAudioDeviceInfo& device, bool isHMD for (auto i = 0; i < _devices.size(); ++i) { std::shared_ptr device = _devices[i]; - bool &isSelected = isHMD ? device->selectedHMD : device->selectedDesktop; + bool& isSelected = isHMD ? device->selectedHMD : device->selectedDesktop; if (isSelected && device->info != selectedDevice) { isSelected = false; } else if (device->info == selectedDevice) { @@ -259,7 +259,7 @@ void AudioDeviceList::onDevicesChanged(const QList& devices) { foreach(const QAudioDeviceInfo& deviceInfo, devices) { for (bool isHMD : {false, true}) { - auto &backupSelectedDeviceName = isHMD ? _backupSelectedHMDDeviceName : _backupSelectedDesktopDeviceName; + auto& backupSelectedDeviceName = isHMD ? _backupSelectedHMDDeviceName : _backupSelectedDesktopDeviceName; if (deviceInfo.deviceName() == backupSelectedDeviceName) { QAudioDeviceInfo& selectedDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice; selectedDevice = deviceInfo; @@ -278,7 +278,7 @@ void AudioDeviceList::onDevicesChanged(const QList& devices) { for (bool isHMD : {false, true}) { QAudioDeviceInfo& selectedDevice = isHMD ? _selectedHMDDevice : _selectedDesktopDevice; - bool &isSelected = isHMD ? device.selectedHMD : device.selectedDesktop; + bool& isSelected = isHMD ? device.selectedHMD : device.selectedDesktop; if (!selectedDevice.isNull()) { isSelected = (device.info == selectedDevice);