fix haze on web entities, deferred and forward

This commit is contained in:
SamGondelman 2019-07-11 14:56:17 -07:00
parent 7793e07eeb
commit 046b25ab67
4 changed files with 56 additions and 22 deletions

View file

@ -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<std::tuple<bool, bool, uint32_t>> 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);
}
}

View file

@ -1 +1 @@
DEFINES translucent:f/forward:f
DEFINES forward

View file

@ -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@>
}

View file

@ -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@>
}