From 046b25ab67ecdeee8dc2276135afba24b7adb66c Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 11 Jul 2019 14:56:17 -0700 Subject: [PATCH] fix haze on web entities, deferred and forward --- libraries/render-utils/src/GeometryCache.cpp | 16 +++--- .../src/render-utils/web_browser.slp | 2 +- libraries/render-utils/src/web_browser.slf | 50 +++++++++++++++---- libraries/render-utils/src/web_browser.slv | 10 ++-- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 2bd656a664..997f87b8d6 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -2117,22 +2117,24 @@ void GeometryCache::bindWebBrowserProgram(gpu::Batch& batch, bool transparent, b gpu::PipelinePointer GeometryCache::getWebBrowserProgram(bool transparent, bool forward) { if (_webPipelines.empty()) { using namespace shader::render_utils::program; - static const std::vector> keys = { - std::make_tuple(false, false, web_browser), std::make_tuple(false, true, web_browser_forward), - std::make_tuple(true, false, web_browser_translucent), std::make_tuple(true, true, web_browser_forward) // The forward opaque/translucent pipelines are the same for now - }; + const int NUM_WEB_PIPELINES = 4; + for (int i = 0; i < NUM_WEB_PIPELINES; ++i) { + bool transparent = i & 1; + bool forward = i & 2; + + // For any non-opaque or non-deferred pipeline, we use web_browser_forward + auto pipeline = (transparent || forward) ? web_browser_forward : web_browser; - for (auto& key : keys) { gpu::StatePointer state = gpu::StatePointer(new gpu::State()); state->setDepthTest(true, true, gpu::LESS_EQUAL); // FIXME: do we need a testMaskDrawNoAA? PrepareStencil::testMaskDrawShapeNoAA(*state); - state->setBlendFunction(std::get<0>(key), + state->setBlendFunction(transparent, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); state->setCullMode(gpu::State::CULL_NONE); - _webPipelines[{std::get<0>(key), std::get<1>(key)}] = gpu::Pipeline::create(gpu::Shader::createProgram(std::get<2>(key)), state); + _webPipelines[{ transparent, forward }] = gpu::Pipeline::create(gpu::Shader::createProgram(pipeline), state); } } diff --git a/libraries/render-utils/src/render-utils/web_browser.slp b/libraries/render-utils/src/render-utils/web_browser.slp index e9942be5cd..e283f4edcb 100644 --- a/libraries/render-utils/src/render-utils/web_browser.slp +++ b/libraries/render-utils/src/render-utils/web_browser.slp @@ -1 +1 @@ -DEFINES translucent:f/forward:f \ No newline at end of file +DEFINES forward \ No newline at end of file diff --git a/libraries/render-utils/src/web_browser.slf b/libraries/render-utils/src/web_browser.slf index 73745edf9e..f746916d3d 100644 --- a/libraries/render-utils/src/web_browser.slf +++ b/libraries/render-utils/src/web_browser.slf @@ -13,15 +13,27 @@ <@include gpu/Color.slh@> <@include render-utils/ShaderConstants.h@> -<@if not HIFI_USE_FORWARD@> - <@include DeferredBufferWrite.slh@> -<@else@> +<@if HIFI_USE_FORWARD@> + <@include LightingModel.slh@> + <@include graphics/Haze.slh@> + + <@include gpu/Transform.slh@> + <$declareStandardCameraTransform()$> + + <@include graphics/Light.slh@> + <$declareLightBuffer()$> + layout(location=0) out vec4 _fragColor0; +<@else@> + <@include DeferredBufferWrite.slh@> <@endif@> LAYOUT(binding=0) uniform sampler2D webTexture; -<@if not HIFI_USE_FORWARD@> +<@if HIFI_USE_FORWARD@> + layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS; + layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES; +<@else@> layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS; <@endif@> layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; @@ -34,13 +46,29 @@ void main(void) { texel = color_sRGBAToLinear(texel); texel *= _color; -<@if not HIFI_USE_FORWARD@> - <@if not HIFI_USE_TRANSLUCENT@> - packDeferredFragmentUnlit(normalize(_normalWS), 1.0, texel.rgb); - <@else@> - packDeferredFragmentTranslucent(normalize(_normalWS), texel.a, texel.rgb, DEFAULT_ROUGHNESS); - <@endif@> -<@else@> +<@if HIFI_USE_FORWARD@> _fragColor0 = texel; + + if (isHazeEnabled() > 0.0) { + // no light attenuation because we're unlit + + TransformCamera cam = getTransformCamera(); + + Light light = getKeyLight(); + vec3 lightDirectionWS = getLightDirection(light); + + if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { + vec4 hazeColor = computeHazeColor( + _positionES.xyz, + _positionWS.xyz, + cam._viewInverse[3].xyz, + lightDirectionWS + ); + + _fragColor0.xyz = mix(_fragColor0.rgb, hazeColor.rgb, hazeColor.a); + } + } +<@else@> + packDeferredFragmentUnlit(normalize(_normalWS), 1.0, texel.rgb); <@endif@> } diff --git a/libraries/render-utils/src/web_browser.slv b/libraries/render-utils/src/web_browser.slv index d8da7d730b..07b4d7d3d7 100644 --- a/libraries/render-utils/src/web_browser.slv +++ b/libraries/render-utils/src/web_browser.slv @@ -17,7 +17,10 @@ <@include render-utils/ShaderConstants.h@> -<@if not HIFI_USE_FORWARD@> +<@if HIFI_USE_FORWARD@> + layout(location=RENDER_UTILS_ATTR_POSITION_WS) out vec4 _positionWS; + layout(location=RENDER_UTILS_ATTR_POSITION_ES) out vec4 _positionES; +<@else@> layout(location=RENDER_UTILS_ATTR_NORMAL_WS) out vec3 _normalWS; <@endif@> layout(location=RENDER_UTILS_ATTR_COLOR) out vec4 _color; @@ -29,9 +32,10 @@ void main(void) { TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); +<@if HIFI_USE_FORWARD@> + <$transformModelToWorldAndEyeAndClipPos(cam, obj, inPosition, _positionWS, _positionES, gl_Position)$> +<@else@> <$transformModelToClipPos(cam, obj, inPosition, gl_Position)$> - -<@if not HIFI_USE_FORWARD@> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> <@endif@> } \ No newline at end of file