mirror of
https://github.com/overte-org/overte.git
synced 2025-06-24 22:49:42 +02:00
fix haze on web entities, deferred and forward
This commit is contained in:
parent
7793e07eeb
commit
046b25ab67
4 changed files with 56 additions and 22 deletions
|
@ -2117,22 +2117,24 @@ void GeometryCache::bindWebBrowserProgram(gpu::Batch& batch, bool transparent, b
|
||||||
gpu::PipelinePointer GeometryCache::getWebBrowserProgram(bool transparent, bool forward) {
|
gpu::PipelinePointer GeometryCache::getWebBrowserProgram(bool transparent, bool forward) {
|
||||||
if (_webPipelines.empty()) {
|
if (_webPipelines.empty()) {
|
||||||
using namespace shader::render_utils::program;
|
using namespace shader::render_utils::program;
|
||||||
static const std::vector<std::tuple<bool, bool, uint32_t>> keys = {
|
const int NUM_WEB_PIPELINES = 4;
|
||||||
std::make_tuple(false, false, web_browser), std::make_tuple(false, true, web_browser_forward),
|
for (int i = 0; i < NUM_WEB_PIPELINES; ++i) {
|
||||||
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
|
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());
|
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||||
state->setDepthTest(true, true, gpu::LESS_EQUAL);
|
state->setDepthTest(true, true, gpu::LESS_EQUAL);
|
||||||
// FIXME: do we need a testMaskDrawNoAA?
|
// FIXME: do we need a testMaskDrawNoAA?
|
||||||
PrepareStencil::testMaskDrawShapeNoAA(*state);
|
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::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||||
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||||
state->setCullMode(gpu::State::CULL_NONE);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
DEFINES translucent:f/forward:f
|
DEFINES forward
|
|
@ -13,15 +13,27 @@
|
||||||
<@include gpu/Color.slh@>
|
<@include gpu/Color.slh@>
|
||||||
<@include render-utils/ShaderConstants.h@>
|
<@include render-utils/ShaderConstants.h@>
|
||||||
|
|
||||||
<@if not HIFI_USE_FORWARD@>
|
<@if HIFI_USE_FORWARD@>
|
||||||
<@include DeferredBufferWrite.slh@>
|
<@include LightingModel.slh@>
|
||||||
<@else@>
|
<@include graphics/Haze.slh@>
|
||||||
|
|
||||||
|
<@include gpu/Transform.slh@>
|
||||||
|
<$declareStandardCameraTransform()$>
|
||||||
|
|
||||||
|
<@include graphics/Light.slh@>
|
||||||
|
<$declareLightBuffer()$>
|
||||||
|
|
||||||
layout(location=0) out vec4 _fragColor0;
|
layout(location=0) out vec4 _fragColor0;
|
||||||
|
<@else@>
|
||||||
|
<@include DeferredBufferWrite.slh@>
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
||||||
LAYOUT(binding=0) uniform sampler2D webTexture;
|
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;
|
layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS;
|
||||||
<@endif@>
|
<@endif@>
|
||||||
layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color;
|
layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color;
|
||||||
|
@ -34,13 +46,29 @@ void main(void) {
|
||||||
texel = color_sRGBAToLinear(texel);
|
texel = color_sRGBAToLinear(texel);
|
||||||
texel *= _color;
|
texel *= _color;
|
||||||
|
|
||||||
<@if not HIFI_USE_FORWARD@>
|
<@if 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@>
|
|
||||||
_fragColor0 = texel;
|
_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@>
|
<@endif@>
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
|
|
||||||
<@include render-utils/ShaderConstants.h@>
|
<@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;
|
layout(location=RENDER_UTILS_ATTR_NORMAL_WS) out vec3 _normalWS;
|
||||||
<@endif@>
|
<@endif@>
|
||||||
layout(location=RENDER_UTILS_ATTR_COLOR) out vec4 _color;
|
layout(location=RENDER_UTILS_ATTR_COLOR) out vec4 _color;
|
||||||
|
@ -29,9 +32,10 @@ void main(void) {
|
||||||
|
|
||||||
TransformCamera cam = getTransformCamera();
|
TransformCamera cam = getTransformCamera();
|
||||||
TransformObject obj = getTransformObject();
|
TransformObject obj = getTransformObject();
|
||||||
|
<@if HIFI_USE_FORWARD@>
|
||||||
|
<$transformModelToWorldAndEyeAndClipPos(cam, obj, inPosition, _positionWS, _positionES, gl_Position)$>
|
||||||
|
<@else@>
|
||||||
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
|
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
|
||||||
|
|
||||||
<@if not HIFI_USE_FORWARD@>
|
|
||||||
<$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$>
|
<$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$>
|
||||||
<@endif@>
|
<@endif@>
|
||||||
}
|
}
|
Loading…
Reference in a new issue