diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index ba7997c60e..2fd42ccacd 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -59,7 +59,7 @@ enum Slot { static const std::string DEFAULT_ALBEDO_SHADER { "vec4 getFragmentColor() {" " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" - " return vec4(pow(frag.diffuse, vec3(1.0 / 2.2)), 1.0);" + " return vec4(pow(frag.albedo, vec3(1.0 / 2.2)), 1.0);" " }" }; @@ -93,7 +93,7 @@ static const std::string DEFAULT_OCCLUSION_SHADER{ static const std::string DEFAULT_EMISSIVE_SHADER{ "vec4 getFragmentColor() {" " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" - " return (frag.mode == FRAG_MODE_SHADED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));" + " return (frag.mode == FRAG_MODE_SHADED ? vec4(pow(texture(specularMap, uv).rgb, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));" " }" }; @@ -107,7 +107,7 @@ static const std::string DEFAULT_UNLIT_SHADER{ static const std::string DEFAULT_LIGHTMAP_SHADER{ "vec4 getFragmentColor() {" " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" - " return (frag.mode == FRAG_MODE_LIGHTMAPPED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));" + " return (frag.mode == FRAG_MODE_LIGHTMAPPED ? vec4(pow(texture(specularMap, uv).rgb, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));" " }" }; diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index 6c020b515f..6b5060cc5f 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -36,11 +36,10 @@ struct DeferredFragment { vec4 position; vec3 normal; float metallic; - vec3 diffuse; + vec3 albedo; float obscurance; - vec3 specular; + vec3 fresnel; float roughness; -// vec3 emissive; int mode; float scattering; float depthVal; @@ -63,7 +62,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { frag.roughness = normalVal.a; // Diffuse color and unpack the mode and the metallicness - frag.diffuse = diffuseVal.xyz; + frag.albedo = diffuseVal.xyz; frag.scattering = 0.0; unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic); @@ -73,14 +72,13 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { if (frag.mode == FRAG_MODE_SCATTERING) { frag.scattering = specularVal.x; - //frag.emissive = vec3(0.0); } if (frag.metallic <= 0.5) { frag.metallic = 0.0; - frag.specular = vec3(0.03); // Default Di-electric fresnel value + frag.fresnel = vec3(0.03); // Default Di-electric fresnel value } else { - frag.specular = vec3(diffuseVal.xyz); + frag.fresnel = vec3(diffuseVal.xyz); frag.metallic = 1.0; } diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index f1f518eee6..cd62a30611 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -53,7 +53,6 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r _fragColor0 = vec4(albedo, packLightmappedMetallic(metallic)); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _fragColor2 = vec4(lightmap, 1.0); - _fragColor3 = vec4(albedo * lightmap, 1.0); } @@ -63,8 +62,7 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) { } _fragColor0 = vec4(color, packUnlit()); _fragColor1 = vec4(packNormal(normal), 1.0); - //_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target - + _fragColor2 = vec4(vec3(0.0), 1.0); _fragColor3 = vec4(color, 1.0); } diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index c8bdff0af6..95cfc1d151 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -31,23 +31,12 @@ Light light = getLight(); vec3 color = vec3(0.0); - -<@if isScattering@> -<@else@> - // color += emissive * isEmissiveEnabled(); -<@endif@> -//color += emissive * isEmissiveEnabled(); - vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value - if (metallic > 0.5) { - fresnel = albedo; - metallic = 1.0; - } <@endfunc@> <@func declareEvalAmbientGlobalColor()@> -vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, float roughness) { +vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, float roughness) { <$prepareGlobalLight()$> color += albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light); return color; @@ -56,21 +45,20 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc <@func declareEvalAmbientSphereGlobalColor(supportScattering)@> -<$declareLightingAmbient(1, 0, 0, supportScattering)$> -<$declareLightingDirectional(supportScattering)$> +<$declareLightingAmbient(1, _SCRIBE_NULL, _SCRIBE_NULL, $supportScattering$)$> +<$declareLightingDirectional($supportScattering$)$> <@if supportScattering@> <$declareDeferredCurvature()$> <@endif@> vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, - vec3 albedo, float metallic, float roughness +vec3 albedo, vec3 fresnel, float metallic, float roughness <@if supportScattering@> , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature -<@endif@> - ) { +<@endif@> ) { - <$prepareGlobalLight(supportScattering)$> + <$prepareGlobalLight($supportScattering$)$> // Ambient vec3 ambientDiffuse; @@ -78,10 +66,9 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature -<@endif@> - ); - color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled(); - color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled(); +<@endif@> ); + color += ambientDiffuse; + color += ambientSpecular; // Directional @@ -90,10 +77,9 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature -<@endif@> - ); - color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); - color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); +<@endif@> ); + color += directionalDiffuse; + color += directionalSpecular; return color; } @@ -103,31 +89,31 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa <@func declareEvalSkyboxGlobalColor(supportScattering)@> -<$declareLightingAmbient(0, 1, 0, supportScattering)$> -<$declareLightingDirectional(supportScattering)$> +<$declareLightingAmbient(_SCRIBE_NULL, 1, _SCRIBE_NULL, $supportScattering$)$> +<$declareLightingDirectional($supportScattering$)$> <@if supportScattering@> <$declareDeferredCurvature()$> <@endif@> vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, - vec3 albedo, float metallic, float roughness + vec3 albedo, vec3 fresnel, float metallic, float roughness <@if supportScattering@> , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature <@endif@> ) { - <$prepareGlobalLight(supportScattering)$> + <$prepareGlobalLight($supportScattering$)$> // Ambient vec3 ambientDiffuse; vec3 ambientSpecular; evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance <@if supportScattering@> - ,scattering, midNormalCurvature, lowNormalCurvature + ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); - color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled(); - color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled(); + color += ambientDiffuse; + color += ambientSpecular; // Directional @@ -138,8 +124,8 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); - color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); - color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled(); + color += directionalDiffuse; + color += directionalSpecular; return color; } @@ -178,7 +164,7 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur <$declareLightingAmbient(1, 1, 1)$> <$declareLightingDirectional()$> -vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 emissive, float roughness, float opacity) { +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()$> color += emissive * isEmissiveEnabled(); @@ -187,16 +173,16 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl vec3 ambientDiffuse; vec3 ambientSpecular; evalLightingAmbient(ambientDiffuse, ambientSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance); - color += ambientDiffuse * isDiffuseEnabled() * isAmbientEnabled(); - color += ambientSpecular * isSpecularEnabled() * isAmbientEnabled() / opacity; + color += ambientDiffuse; + color += ambientSpecular / opacity; // Directional vec3 directionalDiffuse; vec3 directionalSpecular; evalLightingDirectional(directionalDiffuse, directionalSpecular, light, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); - color += directionalDiffuse * isDiffuseEnabled() * isDirectionalEnabled(); - color += directionalSpecular * isSpecularEnabled() * isDirectionalEnabled() / opacity; + color += directionalDiffuse; + color += directionalSpecular / opacity; return color; } diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index d656b3e054..06d103080e 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -7,76 +7,4 @@ // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -!> - -<@def DEFERRED_LIGHTING_SLH@> - - -<@func declareEvalPBRShading()@> - -vec3 fresnelSchlick(vec3 fresnelColor, vec3 lightDir, vec3 halfDir) { - return fresnelColor + (1.0 - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5); -} - -float specularDistribution(float roughness, vec3 normal, vec3 halfDir) { - float ndoth = clamp(dot(halfDir, normal), 0.0, 1.0); - float gloss2 = pow(0.001 + roughness, 4); - float denom = (ndoth * ndoth*(gloss2 - 1) + 1); - float power = gloss2 / (3.14159 * denom * denom); - return power; -} -/* //NOTE: ANother implementation for specularDistribution -float specularDistribution(float roughness, vec3 normal, vec3 halfDir) { - float gloss = exp2(10 * (1.0 - roughness) + 1); - float power = pow(clamp(dot(halfDir, normal), 0.0, 1.0), gloss); - power *= (gloss * 0.125 + 0.25); - return power; -} -*/ - -// Frag Shading returns the diffuse amount as W and the specular rgb as xyz -vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 fresnel, float roughness) { - // Diffuse Lighting - float diffuse = clamp(dot(fragNormal, fragLightDir), 0.0, 1.0); - - // Specular Lighting - vec3 halfDir = normalize(fragEyeDir + fragLightDir); - vec3 fresnelColor = fresnelSchlick(fresnel, fragLightDir,halfDir); - float power = specularDistribution(roughness, fragNormal, halfDir); - vec3 specular = power * fresnelColor * diffuse; - - return vec4(specular, (1.0 - metallic) * diffuse * (1 - fresnelColor.x)); -} -<@endfunc@> - -<@func declareEvalBlinnRShading()@> - -vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float roughness) { - // Diffuse Lighting - float diffuseDot = dot(fragNormal, fragLightDir); - float facingLight = step(0.0, diffuseDot); - float diffuse = diffuseDot * facingLight; - - // Specular Lighting depends on the half vector and the roughness - vec3 halfDir = normalize(fragEyeDir + fragLightDir); - - float gloss = (1.0 - roughness) * 128.0; - glos *= gloss; - float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss); - vec3 reflect = specularPower * specular * diffuse; - - return vec4(reflect, diffuse); -} - -<@endfunc@> - -<$declareEvalPBRShading()$> - -// Return xyz the specular/reflection component and w the diffuse component -vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 specular, float roughness) { - return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, specular, roughness); -} - -<@endif@> !> \ No newline at end of file diff --git a/libraries/render-utils/src/LightAmbient.slh b/libraries/render-utils/src/LightAmbient.slh index e2aa1107df..d40bd921af 100644 --- a/libraries/render-utils/src/LightAmbient.slh +++ b/libraries/render-utils/src/LightAmbient.slh @@ -57,9 +57,9 @@ vec3 evalAmbientSpecularIrradiance(Light light, vec3 fragEyeDir, vec3 fragNormal } <@endfunc@> -<@func declareLightingAmbient(supportAmbientSphere1, supportAmbientMap1, supportIfAmbientMapElseAmbientSphere1, supportScattering)@> +<@func declareLightingAmbient(supportAmbientSphere, supportAmbientMap, supportIfAmbientMapElseAmbientSphere, supportScattering)@> -<$declareEvalAmbientSpecularIrradiance(supportAmbientSphere1, supportAmbientMap1, supportIfAmbientMapElseAmbientSphere1)$> +<$declareEvalAmbientSpecularIrradiance($supportAmbientSphere$, $supportAmbientMap$, $supportIfAmbientMapElseAmbientSphere$)$> <@if supportScattering@> float curvatureAO(in float k) { @@ -74,38 +74,38 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, Light light, vec3 <@endif@> ) { -<@if supportScattering@> + // Diffuse from ambient + diffuse = (1 - metallic) * evalSphericalLight(getLightAmbientSphere(light), normal).xyz; + + // Specular highlight from ambient + specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light); + + +<@if supportScattering@> float ambientOcclusion = curvatureAO(lowNormalCurvature.w * 20.0f) * 0.5f; float ambientOcclusionHF = curvatureAO(midNormalCurvature.w * 8.0f) * 0.5f; ambientOcclusion = min(ambientOcclusion, ambientOcclusionHF); - /* if (showCurvature()) { - diffuse = vec3(ambientOcclusion); - specular = vec3(0.0); - return; - }*/ + obscurance = min(obscurance, ambientOcclusion); + if (scattering * isScatteringEnabled() > 0.0) { - // Diffuse from ambient - diffuse = ambientOcclusion * albedo * evalSphericalLight(getLightAmbientSphere(light), lowNormalCurvature.xyz).xyz *getLightAmbientIntensity(light); + // Diffuse from ambient + diffuse = evalSphericalLight(getLightAmbientSphere(light), lowNormalCurvature.xyz).xyz; - // Specular highlight from ambient - // vec3 specularLighting = evalGlobalSpecularIrradiance(light, fragEyeDir, fragNormal, roughness, fresnel); - // color += specularLighting; - - - // Specular highlight from ambient - // specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light); - specular = vec3(0.0); - -<@else@> - // Diffuse from ambient - diffuse = (1 - metallic) * albedo * evalSphericalLight(getLightAmbientSphere(light), normal).xyz * obscurance * getLightAmbientIntensity(light); - - // Specular highlight from ambient - specular = evalAmbientSpecularIrradiance(light, eyeDir, normal, roughness, fresnel) * obscurance * getLightAmbientIntensity(light); + specular = vec3(0.0); + } <@endif@> + + float lightEnergy = obscurance * getLightAmbientIntensity(light); + + if (isAlbedoEnabled() > 0.0) { + diffuse *= albedo; + } + + diffuse *= lightEnergy * isDiffuseEnabled() * isAmbientEnabled(); + specular *= lightEnergy * isSpecularEnabled() * isAmbientEnabled(); } <@endfunc@> diff --git a/libraries/render-utils/src/LightDirectional.slh b/libraries/render-utils/src/LightDirectional.slh index 6fc27f2250..86eb130491 100644 --- a/libraries/render-utils/src/LightDirectional.slh +++ b/libraries/render-utils/src/LightDirectional.slh @@ -18,18 +18,18 @@ void evalLightingDirectional(out vec3 diffuse, out vec3 specular, Light light, , float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature <@endif@> ) { - - evalFragShading(diffuse, specular, normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness + + // Attenuation + vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light); + + evalFragShading(diffuse, specular, normal, -getLightDirection(light), eyeDir, metallic, fresnel, roughness, albedo <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); - vec3 lightEnergy = shadow * getLightColor(light) * getLightIntensity(light); - - diffuse *= albedo * lightEnergy; - - specular *= lightEnergy; + diffuse *= lightEnergy * isDiffuseEnabled() * isDirectionalEnabled(); + specular *= lightEnergy * isSpecularEnabled() * isDirectionalEnabled(); } <@endfunc@> diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index ab63276004..d13d52d360 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -23,21 +23,19 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, float fragLightDistance = length(fragLightVec); vec3 fragLightDir = fragLightVec / fragLightDistance; - // Eval attenuation + // Eval attenuation float radialAttenuation = evalLightAttenuation(light, fragLightDistance); - vec3 lightEnergy = radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light); // Eval shading - evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness + evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness, albedo <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); - diffuse *= albedo * lightEnergy; - - specular *= lightEnergy; + diffuse *= lightEnergy * isDiffuseEnabled() * isPointEnabled(); + specular *= lightEnergy * isSpecularEnabled() * isPointEnabled(); if (getLightShowContour(light) > 0.0) { // Show edge diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 03a7a6120e..0b66a3e4c1 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -29,15 +29,14 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, vec3 lightEnergy = angularAttenuation * radialAttenuation * shadow * getLightColor(light) * getLightIntensity(light); // Eval shading - evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness + evalFragShading(diffuse, specular, normal, fragLightDir, fragEyeDir, metallic, fresnel, roughness, albedo <@if supportScattering@> ,scattering, midNormalCurvature, lowNormalCurvature <@endif@> ); - diffuse *= albedo * lightEnergy; - - specular *= lightEnergy; + diffuse *= lightEnergy * isDiffuseEnabled() * isSpotEnabled(); + specular *= lightEnergy * isSpecularEnabled() * isSpotEnabled(); if (getLightShowContour(light) > 0.0) { // Show edges diff --git a/libraries/render-utils/src/LightingModel.cpp b/libraries/render-utils/src/LightingModel.cpp index 9e66a9f673..998659308d 100644 --- a/libraries/render-utils/src/LightingModel.cpp +++ b/libraries/render-utils/src/LightingModel.cpp @@ -75,6 +75,14 @@ void LightingModel::setSpecular(bool enable) { bool LightingModel::isSpecularEnabled() const { return (bool)_parametersBuffer.get().enableSpecular; } +void LightingModel::setAlbedo(bool enable) { + if (enable != isAlbedoEnabled()) { + _parametersBuffer.edit().enableAlbedo = (float)enable; + } +} +bool LightingModel::isAlbedoEnabled() const { + return (bool)_parametersBuffer.get().enableAlbedo; +} void LightingModel::setAmbientLight(bool enable) { if (enable != isAmbientLightEnabled()) { @@ -129,6 +137,7 @@ void MakeLightingModel::configure(const Config& config) { _lightingModel->setScattering(config.enableScattering); _lightingModel->setDiffuse(config.enableDiffuse); _lightingModel->setSpecular(config.enableSpecular); + _lightingModel->setAlbedo(config.enableAlbedo); _lightingModel->setAmbientLight(config.enableAmbientLight); _lightingModel->setDirectionalLight(config.enableDirectionalLight); _lightingModel->setPointLight(config.enablePointLight); diff --git a/libraries/render-utils/src/LightingModel.h b/libraries/render-utils/src/LightingModel.h index d8325925fe..9bd982a080 100644 --- a/libraries/render-utils/src/LightingModel.h +++ b/libraries/render-utils/src/LightingModel.h @@ -37,12 +37,14 @@ public: void setScattering(bool enable); bool isScatteringEnabled() const; - void setDiffuse(bool enable); bool isDiffuseEnabled() const; void setSpecular(bool enable); bool isSpecularEnabled() const; + void setAlbedo(bool enable); + bool isAlbedoEnabled() const; + void setAmbientLight(bool enable); bool isAmbientLightEnabled() const; void setDirectionalLight(bool enable); @@ -72,7 +74,7 @@ protected: float enableScattering{ 1.0f }; float enableDiffuse{ 1.0f }; float enableSpecular{ 1.0f }; - float spare; + float enableAlbedo{ 1.0f }; float enableAmbientLight{ 1.0f }; float enableDirectionalLight{ 1.0f }; @@ -103,6 +105,7 @@ class MakeLightingModelConfig : public render::Job::Config { Q_PROPERTY(bool enableScattering MEMBER enableScattering NOTIFY dirty) Q_PROPERTY(bool enableDiffuse MEMBER enableDiffuse NOTIFY dirty) Q_PROPERTY(bool enableSpecular MEMBER enableSpecular NOTIFY dirty) + Q_PROPERTY(bool enableAlbedo MEMBER enableAlbedo NOTIFY dirty) Q_PROPERTY(bool enableAmbientLight MEMBER enableAmbientLight NOTIFY dirty) Q_PROPERTY(bool enableDirectionalLight MEMBER enableDirectionalLight NOTIFY dirty) @@ -122,6 +125,7 @@ public: bool enableScattering{ true }; bool enableDiffuse{ true }; bool enableSpecular{ true }; + bool enableAlbedo{ true }; bool enableAmbientLight{ true }; bool enableDirectionalLight{ true }; diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index 811ceb2412..b8c73f7dab 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -12,10 +12,13 @@ <@def LIGHTING_MODEL_SLH@> <@func declareLightingModel()@> +<@endfunc@> + +<@func declareLightingModelMaster()@> struct LightingModel { vec4 _UnlitShadedEmissiveLightmap; - vec4 _ScatteringDiffuseSpecular; + vec4 _ScatteringDiffuseSpecularAlbedo; vec4 _AmbientDirectionalPointSpot; vec4 _ShowContour; }; @@ -38,13 +41,16 @@ float isLightmapEnabled() { } float isScatteringEnabled() { - return lightingModel._ScatteringDiffuseSpecular.x; + return lightingModel._ScatteringDiffuseSpecularAlbedo.x; } float isDiffuseEnabled() { - return lightingModel._ScatteringDiffuseSpecular.y; + return lightingModel._ScatteringDiffuseSpecularAlbedo.y; } float isSpecularEnabled() { - return lightingModel._ScatteringDiffuseSpecular.z; + return lightingModel._ScatteringDiffuseSpecularAlbedo.z; +} +float isAlbedoEnabled() { + return lightingModel._ScatteringDiffuseSpecularAlbedo.w; } float isAmbientEnabled() { @@ -65,6 +71,7 @@ float isShowContour() { } <@endfunc@> +<$declareLightingModelMaster()$> <@func declareBeckmannSpecular()@> @@ -149,9 +156,12 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float m void evalFragShading(out vec3 diffuse, out vec3 specular, vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, - float metallic, vec3 fresnel, float roughness) { + float metallic, vec3 fresnel, float roughness, vec3 albedo) { vec4 shading = evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, roughness); diffuse = vec3(shading.w); + if (isAlbedoEnabled() > 0.0) { + diffuse *= albedo; + } specular = shading.xyz; } @@ -159,11 +169,12 @@ void evalFragShading(out vec3 diffuse, out vec3 specular, <@include SubsurfaceScattering.slh@> <$declareSubsurfaceScatteringBRDF()$> + void evalFragShading(out vec3 diffuse, out vec3 specular, vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, - float metallic, vec3 fresnel, float roughness, + float metallic, vec3 fresnel, float roughness, vec3 albedo, float scattering, vec4 midNormalCurvature, vec4 lowNormalCurvature) { - if (scattering > 0.0) { + if (scattering * isScatteringEnabled() > 0.0) { vec3 brdf = evalSkinBRDF(fragLightDir, fragNormal, midNormalCurvature.xyz, lowNormalCurvature.xyz, lowNormalCurvature.w); float NdotL = clamp(dot(fragNormal, fragLightDir), 0.0, 1.0); diffuse = mix(vec3(NdotL), brdf, scattering); @@ -174,12 +185,14 @@ void evalFragShading(out vec3 diffuse, out vec3 specular, diffuse *= specularBrdf.y; specular = vec3(specularBrdf.x); - } else { - vec4 shading = evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, specular, roughness); + vec4 shading = evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, fresnel, roughness); diffuse = vec3(shading.w); specular = shading.xyz; } + if (isAlbedoEnabled() > 0.0) { + diffuse *= albedo; + } } diff --git a/libraries/render-utils/src/ToneMappingEffect.cpp b/libraries/render-utils/src/ToneMappingEffect.cpp index b28f271f9d..6a0020edbf 100644 --- a/libraries/render-utils/src/ToneMappingEffect.cpp +++ b/libraries/render-utils/src/ToneMappingEffect.cpp @@ -102,12 +102,18 @@ void ToneMappingEffect::init() { } void ToneMappingEffect::setExposure(float exposure) { - _parametersBuffer.edit()._exposure = exposure; - _parametersBuffer.edit()._twoPowExposure = pow(2.0, exposure); + auto& params = _parametersBuffer.get(); + if (params._exposure != exposure) { + _parametersBuffer.edit()._exposure = exposure; + _parametersBuffer.edit()._twoPowExposure = pow(2.0, exposure); + } } void ToneMappingEffect::setToneCurve(ToneCurve curve) { - _parametersBuffer.edit()._toneCurve = curve; + auto& params = _parametersBuffer.get(); + if (params._toneCurve != curve) { + _parametersBuffer.edit()._toneCurve = curve; + } } void ToneMappingEffect::render(RenderArgs* args) { @@ -149,13 +155,8 @@ void ToneMappingEffect::render(RenderArgs* args) { void ToneMappingDeferred::configure(const Config& config) { - if (config.exposure >= 0.0f) { - _toneMappingEffect.setExposure(config.exposure); - } - - if (config.curve >= 0) { - _toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)config.curve); - } + _toneMappingEffect.setExposure(config.exposure); + _toneMappingEffect.setToneCurve((ToneMappingEffect::ToneCurve)config.curve); } void ToneMappingDeferred::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) { diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h index 3dd212c2dc..a6a08ab87b 100644 --- a/libraries/render-utils/src/ToneMappingEffect.h +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -71,7 +71,7 @@ class ToneMappingConfig : public render::Job::Config { public: ToneMappingConfig() : render::Job::Config(true) {} - void setExposure(float newExposure) { exposure = std::max(0.0f, newExposure); emit dirty(); } + void setExposure(float newExposure) { exposure = newExposure; emit dirty(); } void setCurve(int newCurve) { curve = std::max((int)ToneMappingEffect::None, std::min((int)ToneMappingEffect::Filmic, newCurve)); emit dirty(); } diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 471d12ad3a..5b591cb01f 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -12,6 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + + <@include DeferredBufferRead.slh@> <@include DeferredGlobalLight.slh@> @@ -30,17 +32,8 @@ void main(void) { float shadowAttenuation = 1.0; if (frag.mode == FRAG_MODE_UNLIT) { - // _fragColor = vec4(frag.diffuse, 1.0); discard; } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { - /* vec3 color = evalLightmappedColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0);*/ discard; } else { vec4 midNormalCurvature; @@ -55,9 +48,9 @@ void main(void) { frag.obscurance, frag.position.xyz, frag.normal, - frag.diffuse, + frag.albedo, + frag.fresnel, frag.metallic, - // frag.emissive, frag.roughness, frag.scattering, midNormalCurvature, diff --git a/libraries/render-utils/src/directional_ambient_light_shadow.slf b/libraries/render-utils/src/directional_ambient_light_shadow.slf index 5f257dce5c..d3778c9228 100644 --- a/libraries/render-utils/src/directional_ambient_light_shadow.slf +++ b/libraries/render-utils/src/directional_ambient_light_shadow.slf @@ -30,17 +30,8 @@ void main(void) { float shadowAttenuation = evalShadowAttenuation(worldPos); if (frag.mode == FRAG_MODE_UNLIT) { - // _fragColor = vec4(frag.diffuse, 1.0); discard; } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { - /* vec3 color = evalLightmappedColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0);*/ discard; } else { vec4 midNormalCurvature; @@ -54,9 +45,9 @@ void main(void) { frag.obscurance, frag.position.xyz, frag.normal, - frag.diffuse, + frag.albedo, + frag.fresnel, frag.metallic, - // frag.emissive, frag.roughness, frag.scattering, midNormalCurvature, diff --git a/libraries/render-utils/src/directional_light.slf b/libraries/render-utils/src/directional_light.slf index 7193e34448..cda03b0779 100644 --- a/libraries/render-utils/src/directional_light.slf +++ b/libraries/render-utils/src/directional_light.slf @@ -27,19 +27,9 @@ void main(void) { float shadowAttenuation = 1.0; - // Light mapped or not ? if (frag.mode == FRAG_MODE_UNLIT) { - // _fragColor = vec4(frag.diffuse, 1.0); - discard; + discard; } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { - /* vec3 color = evalLightmappedColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0);*/ discard; } else { vec3 color = evalAmbientGlobalColor( @@ -48,9 +38,9 @@ void main(void) { frag.obscurance, frag.position.xyz, frag.normal, - frag.diffuse, + frag.albedo, + frag.fresnel, frag.metallic, - // frag.emissive, frag.roughness); _fragColor = vec4(color, 1.0); } diff --git a/libraries/render-utils/src/directional_light_shadow.slf b/libraries/render-utils/src/directional_light_shadow.slf index 248f90b733..7f98330f84 100644 --- a/libraries/render-utils/src/directional_light_shadow.slf +++ b/libraries/render-utils/src/directional_light_shadow.slf @@ -29,19 +29,9 @@ void main(void) { vec4 worldPos = getViewInverse() * vec4(frag.position.xyz, 1.0); float shadowAttenuation = evalShadowAttenuation(worldPos); - // Light mapped or not ? if (frag.mode == FRAG_MODE_UNLIT) { - // _fragColor = vec4(frag.diffuse, 1.0); discard; } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { - /* vec3 color = evalLightmappedColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0);*/ discard; } else { vec3 color = evalAmbientGlobalColor( @@ -50,9 +40,9 @@ void main(void) { frag.obscurance, frag.position.xyz, frag.normal, - frag.diffuse, + frag.albedo, + frag.fresnel, frag.metallic, - // frag.emissive, frag.roughness); _fragColor = vec4(color, 1.0); } diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index 01c85672c2..6130c8ac8e 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -29,17 +29,8 @@ void main(void) { // Light mapped or not ? if (frag.mode == FRAG_MODE_UNLIT) { - // _fragColor = vec4(frag.diffuse, 1.0); discard; } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { - /* vec3 color = evalLightmappedColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0);*/ discard; } else { vec4 midNormalCurvature; @@ -53,13 +44,14 @@ void main(void) { frag.obscurance, frag.position.xyz, frag.normal, - frag.diffuse, + frag.albedo, + frag.fresnel, frag.metallic, - // frag.emissive, frag.roughness, frag.scattering, midNormalCurvature, lowNormalCurvature); _fragColor = vec4(color, 1.0); + } } diff --git a/libraries/render-utils/src/directional_skybox_light_shadow.slf b/libraries/render-utils/src/directional_skybox_light_shadow.slf index c87a2d15b2..3ca0f71df5 100644 --- a/libraries/render-utils/src/directional_skybox_light_shadow.slf +++ b/libraries/render-utils/src/directional_skybox_light_shadow.slf @@ -31,17 +31,8 @@ void main(void) { // Light mapped or not ? if (frag.mode == FRAG_MODE_UNLIT) { - // _fragColor = vec4(frag.diffuse, 1.0); discard; } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { - /* vec3 color = evalLightmappedColor( - getViewInverse(), - shadowAttenuation, - frag.obscurance, - frag.normal, - frag.diffuse, - frag.specularVal.xyz); - _fragColor = vec4(color, 1.0);*/ discard; } else { vec4 midNormalCurvature; @@ -55,9 +46,9 @@ void main(void) { frag.obscurance, frag.position.xyz, frag.normal, - frag.diffuse, + frag.albedo, + frag.fresnel, frag.metallic, - //frag.emissive, frag.roughness, frag.scattering, midNormalCurvature, diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 8f62a3a3e0..6cf99a68ef 100755 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -50,11 +50,17 @@ void main(void) { <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; float metallic = getMaterialMetallic(mat); + vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value + if (metallic <= 0.5) { + metallic = 0.0; + } else { + fresnel = albedo; + metallic = 1.0; + } vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - vec3 fragPosition = _position.xyz; vec3 fragNormal = normalize(_normal); @@ -67,6 +73,7 @@ void main(void) { fragPosition, fragNormal, albedo, + fresnel, metallic, emissive, roughness, opacity), diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index 5916c60f22..02a5d0d36c 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -75,9 +75,9 @@ void main(void) { } evalLightingPoint(diffuse, specular, light, fragLightVecLen2.xyz, fragEyeDir, frag.normal, frag.roughness, - frag.metallic, frag.specular, frag.diffuse, 1.0, - frag.scattering * isScatteringEnabled(), midNormalCurvature, lowNormalCurvature); + frag.metallic, frag.fresnel, frag.albedo, 1.0, + frag.scattering, midNormalCurvature, lowNormalCurvature); - _fragColor.rgb += diffuse * isDiffuseEnabled() * isPointEnabled(); - _fragColor.rgb += specular * isSpecularEnabled() * isPointEnabled(); + _fragColor.rgb += diffuse; + _fragColor.rgb += specular; } diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index b9b2be3ebf..3b860e3fb3 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -77,10 +77,10 @@ void main(void) { } evalLightingSpot(diffuse, specular, light, fragLightDirLen.xyzw, cosSpotAngle, fragEyeDir, frag.normal, frag.roughness, - frag.metallic, frag.specular, frag.diffuse, 1.0, - frag.scattering * isScatteringEnabled(), midNormalCurvature, lowNormalCurvature); + frag.metallic, frag.fresnel, frag.albedo, 1.0, + frag.scattering, midNormalCurvature, lowNormalCurvature); - _fragColor.rgb += diffuse * isDiffuseEnabled() * isSpotEnabled(); - _fragColor.rgb += specular * isSpecularEnabled() * isSpotEnabled(); + _fragColor.rgb += diffuse; + _fragColor.rgb += specular; } diff --git a/scripts/developer/utilities/render/debugDeferredLighting.js b/scripts/developer/utilities/render/debugDeferredLighting.js index 710f08d401..b61ac77c19 100644 --- a/scripts/developer/utilities/render/debugDeferredLighting.js +++ b/scripts/developer/utilities/render/debugDeferredLighting.js @@ -11,10 +11,10 @@ // Set up the qml ui var qml = Script.resolvePath('deferredLighting.qml'); var window = new OverlayWindow({ - title: 'Deferred Lighting Pass', + title: 'Lighting', source: qml, - width: 400, height: 100, + width: 400, height: 150, }); -window.setPosition(250, 800); +window.setPosition(250, 800);a window.closed.connect(function() { Script.stop(); }); diff --git a/scripts/developer/utilities/render/debugFramebuffer.js b/scripts/developer/utilities/render/debugFramebuffer.js index e764cf52d8..12a19085c8 100644 --- a/scripts/developer/utilities/render/debugFramebuffer.js +++ b/scripts/developer/utilities/render/debugFramebuffer.js @@ -19,7 +19,7 @@ var qml = Script.resolvePath('framebuffer.qml'); var window = new OverlayWindow({ title: 'Framebuffer Debug', source: qml, - width: 400, height: 400, + width: 400, height: 50, }); window.setPosition(25, 50); window.closed.connect(function() { Script.stop(); }); diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 5a325ae7ce..372f97bf43 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -11,59 +11,91 @@ import QtQuick 2.5 import QtQuick.Controls 1.4 import "configSlider" -Row { +Column { spacing: 8 - Column { - spacing: 10 - Repeater { - model: [ - "Unlit:LightingModel:enableUnlit", - "Shaded:LightingModel:enableShaded", - "Emissive:LightingModel:enableEmissive", - "Lightmap:LightingModel:enableLightmap", - ] - CheckBox { - text: modelData.split(":")[0] - checked: Render.getConfig(modelData.split(":")[1]) - onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } + Row { + spacing: 8 + Column { + spacing: 10 + Repeater { + model: [ + "Unlit:LightingModel:enableUnlit", + "Shaded:LightingModel:enableShaded", + "Emissive:LightingModel:enableEmissive", + "Lightmap:LightingModel:enableLightmap", + ] + CheckBox { + text: modelData.split(":")[0] + checked: Render.getConfig(modelData.split(":")[1]) + onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } + } + } + } + + + Column { + spacing: 10 + Repeater { + model: [ + "Scattering:LightingModel:enableScattering", + "Diffuse:LightingModel:enableDiffuse", + "Specular:LightingModel:enableSpecular", + "Albedo:LightingModel:enableAlbedo", + ] + CheckBox { + text: modelData.split(":")[0] + checked: Render.getConfig(modelData.split(":")[1]) + onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } + } + } + } + + Column { + spacing: 10 + Repeater { + model: [ + "Ambient:LightingModel:enableAmbientLight", + "Directional:LightingModel:enableDirectionalLight", + "Point:LightingModel:enablePointLight", + "Spot:LightingModel:enableSpotLight" + ] + CheckBox { + text: modelData.split(":")[0] + checked: Render.getConfig(modelData.split(":")[1]) + onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } + } } } } - - Column { - spacing: 10 + spacing: 10 Repeater { - model: [ - "Scattering:LightingModel:enableScattering", - "Diffuse:LightingModel:enableDiffuse", - "Specular:LightingModel:enableSpecular", - ] - CheckBox { - text: modelData.split(":")[0] - checked: Render.getConfig(modelData.split(":")[1]) - onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } + model: [ "Tone Mapping exposure:ToneMapping:exposure:5.0:-5.0" + ] + ConfigSlider { + label: qsTr(modelData.split(":")[0]) + integral: false + config: Render.getConfig(modelData.split(":")[1]) + property: modelData.split(":")[2] + max: modelData.split(":")[3] + min: modelData.split(":")[4] } } - } - Column { - spacing: 10 - Repeater { - model: [ - "Ambient:LightingModel:enableAmbientLight", - "Directional:LightingModel:enableDirectionalLight", - "Point:LightingModel:enablePointLight", - "Spot:LightingModel:enableSpotLight" - ] - CheckBox { - text: modelData.split(":")[0] - checked: Render.getConfig(modelData.split(":")[1]) - onCheckedChanged: { Render.getConfig(modelData.split(":")[1])[modelData.split(":")[2]] = checked } + ComboBox { + currentIndex: 1 + model: ListModel { + id: cbItems + ListElement { text: "RGB"; color: "Yellow" } + ListElement { text: "SRGB"; color: "Green" } + ListElement { text: "Reinhard"; color: "Yellow" } + ListElement { text: "Filmic"; color: "White" } } + width: 200 + onCurrentIndexChanged: { Render.getConfig("ToneMapping")["curve"] = currentIndex } } } - } + diff --git a/scripts/developer/utilities/render/framebuffer.qml b/scripts/developer/utilities/render/framebuffer.qml index 48f1550409..65046106dc 100644 --- a/scripts/developer/utilities/render/framebuffer.qml +++ b/scripts/developer/utilities/render/framebuffer.qml @@ -23,51 +23,35 @@ Column { debug.config.mode = mode; } - function setX(x) { - print(x) - - debug.config.size = Vec4({ x: x, y: -1, z: 1, w: 1 }); - } - Slider { - minimumValue: -1.0 - value: debug.config.size.x - onValueChanged: { - debug.setX( value); - } - } - - ExclusiveGroup { id: bufferGroup } - Repeater { - model: [ - "Off", - "Depth", - "Albedo", - "Normal", - "Roughness", - "Metallic", - "Emissive", - "Unlit", - "Occlusion", - "Lightmap", - "Scattering", - "Lighting", - "Shadow", - "Pyramid Depth", - "Curvature", - "NormalCurvature", - "DiffusedCurvature", - "DiffusedNormalCurvature", - "Debug Scattering", - "Ambient Occlusion", - "Ambient Occlusion Blurred", - "Custom Shader" - ] - RadioButton { - text: qsTr(modelData) - exclusiveGroup: bufferGroup - checked: index == 0 - onCheckedChanged: if (checked) debug.setDebugMode(index - 1); + ComboBox { + currentIndex: 0 + model: ListModel { + id: cbItems + ListElement { text: "Off"; color: "Yellow" } + ListElement { text: "Depth"; color: "Green" } + ListElement { text: "Albedo"; color: "Yellow" } + ListElement { text: "Normal"; color: "White" } + ListElement { text: "Roughness"; color: "White" } + ListElement { text: "Metallic"; color: "White" } + ListElement { text: "Emissive"; color: "White" } + ListElement { text: "Unlit"; color: "White" } + ListElement { text: "Occlusion"; color: "White" } + ListElement { text: "Lightmap"; color: "White" } + ListElement { text: "Scattering"; color: "White" } + ListElement { text: "Lighting"; color: "White" } + ListElement { text: "Shadow"; color: "White" } + ListElement { text: "Linear Depth"; color: "White" } + ListElement { text: "Mid Curvature"; color: "White" } + ListElement { text: "Mid Normal"; color: "White" } + ListElement { text: "Low Curvature"; color: "White" } + ListElement { text: "Low Normal"; color: "White" } + ListElement { text: "Debug Scattering"; color: "White" } + ListElement { text: "Ambient Occlusion"; color: "White" } + ListElement { text: "Ambient Occlusion Blurred"; color: "White" } + ListElement { text: "Custom"; color: "White" } } + width: 200 + onCurrentIndexChanged: { debug.setDebugMode(currentIndex - 1) } } } } diff --git a/tools/scribe/src/TextTemplate.cpp b/tools/scribe/src/TextTemplate.cpp index 741ddb6846..1fad1eac02 100755 --- a/tools/scribe/src/TextTemplate.cpp +++ b/tools/scribe/src/TextTemplate.cpp @@ -741,6 +741,7 @@ int TextTemplate::evalBlockGeneration(std::ostream& dst, const BlockPointer& blo std::vector< String > paramCache; paramCache.push_back(""); String val; + bool valIsVar = false; for (int i = 1; i < nbParams; i++) { val = block->command.arguments[i]; if ((val[0] == Tag::VAR) && (val[val.length()-1] == Tag::VAR)) { @@ -748,7 +749,10 @@ int TextTemplate::evalBlockGeneration(std::ostream& dst, const BlockPointer& blo Vars::iterator it = vars.find(val); if (it != vars.end()) { val = (*it).second; + } else { + val = Tag::NULL_VAR; } + valIsVar = true; } Vars::iterator it = vars.find(funcBlock->command.arguments[i]); @@ -759,14 +763,19 @@ int TextTemplate::evalBlockGeneration(std::ostream& dst, const BlockPointer& blo if (val != Tag::NULL_VAR) { vars.insert(Vars::value_type(funcBlock->command.arguments[i], val)); } - paramCache.push_back(""); + + paramCache.push_back(Tag::NULL_VAR); } } generateTree(dst, funcBlock, vars); for (int i = 1; i < nbParams; i++) { - vars[ funcBlock->command.arguments[i] ] = paramCache[i]; + if (paramCache[i] == Tag::NULL_VAR) { + vars.erase(funcBlock->command.arguments[i]); + } else { + vars[funcBlock->command.arguments[i]] = paramCache[i]; + } } } } diff --git a/tools/scribe/src/main.cpp b/tools/scribe/src/main.cpp index b7038e392e..810f6c0f45 100755 --- a/tools/scribe/src/main.cpp +++ b/tools/scribe/src/main.cpp @@ -240,4 +240,5 @@ int main (int argc, char** argv) { } return 0; + }