mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 12:15:13 +02:00
Just making debugging easier
This commit is contained in:
parent
ea26921bd1
commit
6ec6ccfec1
3 changed files with 85 additions and 18 deletions
|
@ -172,7 +172,7 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
|
|||
*/
|
||||
|
||||
#include "taa_frag.h"
|
||||
#include "fxaa_blend_frag.h"
|
||||
#include "taa_blend_frag.h"
|
||||
|
||||
|
||||
|
||||
|
@ -180,6 +180,8 @@ const int AntialiasingPass_FrameTransformSlot = 0;
|
|||
const int AntialiasingPass_HistoryMapSlot = 0;
|
||||
const int AntialiasingPass_SourceMapSlot = 1;
|
||||
const int AntialiasingPass_VelocityMapSlot = 2;
|
||||
const int AntialiasingPass_CurrentMapSlot = 3;
|
||||
|
||||
|
||||
Antialiasing::Antialiasing() {
|
||||
}
|
||||
|
@ -220,16 +222,20 @@ const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline() {
|
|||
const gpu::PipelinePointer& Antialiasing::getBlendPipeline() {
|
||||
if (!_blendPipeline) {
|
||||
auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS();
|
||||
auto ps = gpu::Shader::createPixel(std::string(fxaa_blend_frag));
|
||||
auto ps = gpu::Shader::createPixel(std::string(taa_blend_frag));
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("colorTexture"), 0));
|
||||
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("currentMap"), AntialiasingPass_CurrentMapSlot));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("historyMap"), AntialiasingPass_HistoryMapSlot));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), AntialiasingPass_SourceMapSlot));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("velocityMap"), AntialiasingPass_VelocityMapSlot));
|
||||
|
||||
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
// PrepareStencil::testMask(*state);
|
||||
PrepareStencil::testMask(*state);
|
||||
|
||||
|
||||
// Good to go add the brand new pipeline
|
||||
|
@ -297,10 +303,17 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
|
|||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
// Blend step
|
||||
batch.setResourceTexture(0, _antialiasingTexture[currentFrame]);
|
||||
batch.setResourceTexture(AntialiasingPass_CurrentMapSlot, _antialiasingTexture[currentFrame]);
|
||||
|
||||
batch.setFramebuffer(sourceBuffer);
|
||||
batch.setPipeline(getBlendPipeline());
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
batch.setResourceTexture(AntialiasingPass_HistoryMapSlot, nullptr);
|
||||
batch.setResourceTexture(AntialiasingPass_SourceMapSlot, nullptr);
|
||||
batch.setResourceTexture(AntialiasingPass_VelocityMapSlot, nullptr);
|
||||
batch.setResourceTexture(AntialiasingPass_CurrentMapSlot, nullptr);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -44,21 +44,14 @@ void main() {
|
|||
|
||||
vec2 velocity = rawVelocity;
|
||||
vec2 prevTexCoord = varTexCoord0 - params.motionScale * velocity;
|
||||
|
||||
vec3 prevColor = currentColor;
|
||||
|
||||
prevTexCoord = clamp(prevTexCoord, vec2(0.1), vec2(0.9));
|
||||
vec3 prevColor = texture(historyMap, prevTexCoord).xyz;
|
||||
if (any(lessThan(prevTexCoord, vec2(0.0)) || any(greaterThan(prevTexCoord, vec2(1.0))) {
|
||||
prevColor = texture(historyMap, prevTexCoord).xyz;
|
||||
}
|
||||
|
||||
vec3 newColor = mix(prevColor, currentColor, params.blend);
|
||||
|
||||
outFragColor = vec4(newColor, 1.0);
|
||||
|
||||
if (abs(varTexCoord0.x - params.debugX) < (1.0 / 2048.0)) {
|
||||
outFragColor.rgb = vec3(1.0, 1.0, 0.0);
|
||||
}
|
||||
if (varTexCoord0.x < params.debugX) {
|
||||
outFragColor = vec4(currentColor, 1.0);
|
||||
if (dot(velocity, velocity) > 0.0001) {
|
||||
outFragColor = vec4(0.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
61
libraries/render-utils/src/taa_blend.slf
Normal file
61
libraries/render-utils/src/taa_blend.slf
Normal file
|
@ -0,0 +1,61 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// taa_blend.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Sam Gateau on 8/17/2017
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
uniform sampler2D currentMap;
|
||||
uniform sampler2D colorMap;
|
||||
uniform sampler2D historyMap;
|
||||
uniform sampler2D velocityMap;
|
||||
|
||||
in vec2 varTexCoord0;
|
||||
layout(location = 0) out vec4 outFragColor;
|
||||
|
||||
struct TAAParams
|
||||
{
|
||||
float debugX;
|
||||
float blend;
|
||||
float motionScale;
|
||||
float spareB;
|
||||
};
|
||||
|
||||
layout(std140) uniform taaParamsBuffer {
|
||||
TAAParams params;
|
||||
};
|
||||
|
||||
void main(void) {
|
||||
outFragColor = texture(currentMap, varTexCoord0);
|
||||
|
||||
if (varTexCoord0.x > params.debugX) {
|
||||
return;
|
||||
}
|
||||
|
||||
vec3 sourceColor = texture(colorMap, varTexCoord0).xyz;
|
||||
|
||||
vec2 velocity = texture(velocityMap, varTexCoord0).xy;
|
||||
vec2 prevTexCoord = varTexCoord0 - params.motionScale * velocity;
|
||||
|
||||
outFragColor = vec4(sourceColor, 1.0);
|
||||
|
||||
if (abs(varTexCoord0.x - params.debugX) < (1.0 / 2048.0)) {
|
||||
outFragColor.rgb = vec3(1.0, 1.0, 0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dot(velocity, velocity) > 0.0001) {
|
||||
outFragColor = vec4(0.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue