mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-06 06:12:50 +02:00
fix haze in mirrors
This commit is contained in:
parent
24ed76a5db
commit
05661c6007
5 changed files with 54 additions and 11 deletions
|
@ -31,6 +31,10 @@ namespace gr {
|
|||
using graphics::slot::buffer::Buffer;
|
||||
}
|
||||
|
||||
gpu::PipelinePointer DrawHaze::_hazePipeline = nullptr;
|
||||
gpu::PipelinePointer DrawHaze::_separateHazePipeline = nullptr;
|
||||
gpu::PipelinePointer DrawHaze::_separateHazeBackgroundPipeline = nullptr;
|
||||
|
||||
void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) {
|
||||
const auto hazeFrame = inputs.get0();
|
||||
const auto& hazeStage = renderContext->args->_scene->getStage<HazeStage>();
|
||||
|
@ -55,15 +59,29 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
|||
|
||||
if (!_hazePipeline) {
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render_utils::program::haze);
|
||||
gpu::StatePointer state = std::make_shared<gpu::State>();
|
||||
|
||||
state->setBlendFunction(true,
|
||||
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);
|
||||
auto createState = []() {
|
||||
gpu::StatePointer state = std::make_shared<gpu::State>();
|
||||
state->setBlendFunction(true,
|
||||
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);
|
||||
return state;
|
||||
};
|
||||
|
||||
// Mask out haze on the tablet
|
||||
PrepareStencil::testMask(*state);
|
||||
_hazePipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
||||
auto hazeState = createState();
|
||||
PrepareStencil::testMask(*hazeState);
|
||||
_hazePipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, hazeState));
|
||||
|
||||
// For our separated passes, we perform one pass on anything marked shape, and one on just the background
|
||||
auto hazeSeparatedState = createState();
|
||||
PrepareStencil::testShape(*hazeSeparatedState);
|
||||
_separateHazePipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, hazeSeparatedState));
|
||||
|
||||
gpu::ShaderPointer backgroundProgram = gpu::Shader::createProgram(shader::render_utils::program::haze_background);
|
||||
auto hazeBackgroundSeparatedState = createState();
|
||||
PrepareStencil::testBackground(*hazeBackgroundSeparatedState);
|
||||
_separateHazeBackgroundPipeline = gpu::PipelinePointer(gpu::Pipeline::create(backgroundProgram, hazeBackgroundSeparatedState));
|
||||
}
|
||||
|
||||
auto outputFramebufferSize = glm::ivec2(outputBuffer->getSize());
|
||||
|
@ -77,7 +95,6 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
|||
batch.resetViewTransform();
|
||||
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(outputFramebufferSize, args->_viewport));
|
||||
|
||||
batch.setPipeline(_hazePipeline);
|
||||
batch.setUniformBuffer(graphics::slot::buffer::Buffer::HazeParams, haze->getHazeParametersBuffer());
|
||||
|
||||
batch.setUniformBuffer(ru::Buffer::DeferredFrameTransform, transformBuffer->getFrameTransformBuffer());
|
||||
|
@ -92,6 +109,15 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
|||
}
|
||||
}
|
||||
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
if (!_separateBackgroundPass) {
|
||||
batch.setPipeline(_hazePipeline);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
} else {
|
||||
batch.setPipeline(_separateHazePipeline);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
batch.setPipeline(_separateHazeBackgroundPipeline);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -33,10 +33,16 @@ public:
|
|||
using Inputs = render::VaryingSet6<HazeStage::FramePointer, gpu::FramebufferPointer, LinearDepthFramebufferPointer, DeferredFrameTransformPointer, LightingModelPointer, LightStage::FramePointer>;
|
||||
using JobModel = render::Job::ModelI<DrawHaze, Inputs>;
|
||||
|
||||
DrawHaze(bool separateBackgroundPass) : _separateBackgroundPass(separateBackgroundPass) {}
|
||||
|
||||
void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
|
||||
|
||||
private:
|
||||
gpu::PipelinePointer _hazePipeline;
|
||||
bool _separateBackgroundPass { false };
|
||||
|
||||
static gpu::PipelinePointer _hazePipeline;
|
||||
static gpu::PipelinePointer _separateHazePipeline;
|
||||
static gpu::PipelinePointer _separateHazeBackgroundPipeline;
|
||||
};
|
||||
|
||||
#endif // hifi_render_utils_DrawHaze_h
|
||||
|
|
|
@ -21,10 +21,16 @@
|
|||
|
||||
<@include graphics/Haze.slh@>
|
||||
|
||||
<@if not HIFI_USE_BACKGROUND@>
|
||||
LAYOUT(binding=RENDER_UTILS_TEXTURE_HAZE_LINEAR_DEPTH) uniform sampler2D linearDepthMap;
|
||||
<@endif@>
|
||||
|
||||
vec4 unpackPositionFromZeye(vec2 texcoord) {
|
||||
<@if not HIFI_USE_BACKGROUND@>
|
||||
float Zeye = -texture(linearDepthMap, texcoord).x;
|
||||
<@else@>
|
||||
float Zeye = 1.0; // We just want to get the direction first
|
||||
<@endif@>
|
||||
|
||||
float check = float(isStereo());
|
||||
float check2 = check * float(texcoord.x > 0.5);
|
||||
|
@ -44,8 +50,12 @@ void main(void) {
|
|||
}
|
||||
|
||||
vec4 fragPositionES = unpackPositionFromZeye(varTexCoord0);
|
||||
|
||||
mat4 viewInverse = getViewInverse();
|
||||
|
||||
<@if HIFI_USE_BACKGROUND@>
|
||||
fragPositionES = vec4(-32000.0 * normalize(fragPositionES.xyz), 1.0);
|
||||
<@endif@>
|
||||
|
||||
vec4 fragPositionWS = viewInverse * fragPositionES;
|
||||
vec4 eyePositionWS = viewInverse[3];
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
|
|||
task.addJob<DrawBackgroundStage>("DrawBackgroundDeferred", backgroundInputs);
|
||||
|
||||
const auto drawHazeInputs = render::Varying(DrawHaze::Inputs(hazeFrame, lightingFramebuffer, linearDepthTarget, deferredFrameTransform, lightingModel, lightFrame));
|
||||
task.addJob<DrawHaze>("DrawHazeDeferred", drawHazeInputs);
|
||||
task.addJob<DrawHaze>("DrawHazeDeferred", drawHazeInputs, depth > 0);
|
||||
|
||||
// Render transparent objects forward in LightingBuffer
|
||||
const auto transparentsInputs = RenderTransparentDeferred::Inputs(transparents, hazeFrame, lightFrame, lightingModel, lightClusters, shadowFrame, jitter).asVarying();
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
VERTEX gpu::vertex::DrawViewportQuadTransformTexcoord
|
||||
FRAGMENT Haze
|
||||
DEFINES background:f
|
Loading…
Reference in a new issue