mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Better debugging but now trying to check the velocity buffer fetch point
This commit is contained in:
parent
fd957d6b8e
commit
d6e0fd758f
5 changed files with 85 additions and 24 deletions
|
@ -172,11 +172,14 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
|
|||
*/
|
||||
|
||||
#include "taa_frag.h"
|
||||
#include "fxaa_blend_frag.h"
|
||||
#include "taa_blend_frag.h"
|
||||
|
||||
|
||||
|
||||
const int AntialiasingPass_FrameTransformSlot = 0;
|
||||
const int AntialiasingPass_ParamsSlot = 0;
|
||||
const int AntialiasingPass_FrameTransformSlot = 1;
|
||||
|
||||
const int AntialiasingPass_HistoryMapSlot = 0;
|
||||
const int AntialiasingPass_SourceMapSlot = 1;
|
||||
const int AntialiasingPass_VelocityMapSlot = 2;
|
||||
|
@ -202,6 +205,8 @@ const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline() {
|
|||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("taaParamsBuffer"), AntialiasingPass_ParamsSlot));
|
||||
|
||||
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));
|
||||
|
@ -222,15 +227,11 @@ const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline() {
|
|||
const gpu::PipelinePointer& Antialiasing::getBlendPipeline() {
|
||||
if (!_blendPipeline) {
|
||||
auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS();
|
||||
auto ps = gpu::Shader::createPixel(std::string(taa_blend_frag));
|
||||
auto ps = gpu::Shader::createPixel(std::string(fxaa_blend_frag));
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
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));
|
||||
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("colorTexture"), AntialiasingPass_CurrentMapSlot));
|
||||
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
|
||||
|
@ -244,10 +245,39 @@ const gpu::PipelinePointer& Antialiasing::getBlendPipeline() {
|
|||
return _blendPipeline;
|
||||
}
|
||||
|
||||
const gpu::PipelinePointer& Antialiasing::getDebugBlendPipeline() {
|
||||
if (!_debugBlendPipeline) {
|
||||
auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS();
|
||||
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("taaParamsBuffer"), AntialiasingPass_ParamsSlot));
|
||||
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("deferredFrameTransformBuffer"), AntialiasingPass_FrameTransformSlot));
|
||||
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);
|
||||
|
||||
|
||||
// Good to go add the brand new pipeline
|
||||
_debugBlendPipeline = gpu::Pipeline::create(program, state);
|
||||
}
|
||||
return _debugBlendPipeline;
|
||||
}
|
||||
|
||||
void Antialiasing::configure(const Config& config) {
|
||||
_params.edit().debugX = config.debugX;
|
||||
_params.edit().blend = config.blend;
|
||||
_params.edit().velocityScale = config.velocityScale;
|
||||
_params.edit().debugShowVelocityThreshold = config.debugShowVelocityThreshold;
|
||||
}
|
||||
|
||||
|
||||
|
@ -295,19 +325,26 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
|
|||
batch.setResourceTexture(AntialiasingPass_HistoryMapSlot, _antialiasingTexture[prevFrame]);
|
||||
batch.setResourceTexture(AntialiasingPass_SourceMapSlot, sourceBuffer->getRenderBuffer(0));
|
||||
batch.setResourceTexture(AntialiasingPass_VelocityMapSlot, velocityBuffer->getVelocityTexture());
|
||||
batch.setFramebuffer(_antialiasingBuffer[currentFrame]);
|
||||
batch.setPipeline(getAntialiasingPipeline());
|
||||
|
||||
batch.setUniformBuffer(0, _params._buffer);
|
||||
|
||||
batch.setUniformBuffer(AntialiasingPass_ParamsSlot, _params._buffer);
|
||||
batch.setUniformBuffer(AntialiasingPass_FrameTransformSlot, deferredFrameTransform->getFrameTransformBuffer());
|
||||
|
||||
batch.setFramebuffer(_antialiasingBuffer[currentFrame]);
|
||||
batch.setPipeline(getAntialiasingPipeline());
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
// Blend step
|
||||
batch.setResourceTexture(AntialiasingPass_CurrentMapSlot, _antialiasingTexture[currentFrame]);
|
||||
|
||||
batch.setFramebuffer(sourceBuffer);
|
||||
batch.setPipeline(getBlendPipeline());
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
if (_params->debugX <= 0.0) {
|
||||
batch.setPipeline(getBlendPipeline());
|
||||
} else {
|
||||
batch.setPipeline(getDebugBlendPipeline());
|
||||
}
|
||||
batch.setResourceTexture(AntialiasingPass_CurrentMapSlot, _antialiasingTexture[currentFrame]);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
batch.setUniformBuffer(AntialiasingPass_ParamsSlot, nullptr);
|
||||
batch.setUniformBuffer(AntialiasingPass_FrameTransformSlot, nullptr);
|
||||
|
||||
batch.setResourceTexture(AntialiasingPass_HistoryMapSlot, nullptr);
|
||||
batch.setResourceTexture(AntialiasingPass_SourceMapSlot, nullptr);
|
||||
|
|
|
@ -23,6 +23,7 @@ class AntialiasingConfig : public render::Job::Config {
|
|||
Q_PROPERTY(float debugX MEMBER debugX NOTIFY dirty)
|
||||
Q_PROPERTY(float blend MEMBER blend NOTIFY dirty)
|
||||
Q_PROPERTY(float velocityScale MEMBER velocityScale NOTIFY dirty)
|
||||
Q_PROPERTY(float debugShowVelocityThreshold MEMBER debugShowVelocityThreshold NOTIFY dirty)
|
||||
|
||||
public:
|
||||
AntialiasingConfig() : render::Job::Config(true) {}
|
||||
|
@ -30,6 +31,7 @@ public:
|
|||
float debugX{ 0.0f };
|
||||
float blend{ 0.1f };
|
||||
float velocityScale{ 1.0f };
|
||||
float debugShowVelocityThreshold{ 1.0f };
|
||||
|
||||
signals:
|
||||
void dirty();
|
||||
|
@ -40,7 +42,7 @@ struct TAAParams {
|
|||
float debugX{ 0.0f };
|
||||
float blend{ 0.1f };
|
||||
float velocityScale{ 1.0f };
|
||||
float spareB;
|
||||
float debugShowVelocityThreshold{ 1.0f };
|
||||
|
||||
};
|
||||
using TAAParamsBuffer = gpu::StructBuffer<TAAParams>;
|
||||
|
@ -58,6 +60,7 @@ public:
|
|||
|
||||
const gpu::PipelinePointer& getAntialiasingPipeline();
|
||||
const gpu::PipelinePointer& getBlendPipeline();
|
||||
const gpu::PipelinePointer& getDebugBlendPipeline();
|
||||
|
||||
|
||||
|
||||
|
@ -72,6 +75,7 @@ private:
|
|||
|
||||
gpu::PipelinePointer _antialiasingPipeline;
|
||||
gpu::PipelinePointer _blendPipeline;
|
||||
gpu::PipelinePointer _debugBlendPipeline;
|
||||
|
||||
TAAParamsBuffer _params;
|
||||
int _currentFrame{ 0 };
|
||||
|
|
|
@ -30,7 +30,7 @@ struct TAAParams
|
|||
float debugX;
|
||||
float blend;
|
||||
float motionScale;
|
||||
float spareB;
|
||||
float debugShowVelocityThreshold;
|
||||
};
|
||||
|
||||
layout(std140) uniform taaParamsBuffer {
|
||||
|
@ -47,7 +47,7 @@ void main() {
|
|||
|
||||
vec3 prevColor = currentColor;
|
||||
|
||||
if (any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0)))) {
|
||||
if (!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))) {
|
||||
prevColor = texture(historyMap, prevTexCoord).xyz;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
<@include DeferredTransform.slh@>
|
||||
<$declareDeferredFrameTransform()$>
|
||||
|
||||
|
||||
uniform sampler2D currentMap;
|
||||
uniform sampler2D colorMap;
|
||||
|
@ -27,7 +29,7 @@ struct TAAParams
|
|||
float debugX;
|
||||
float blend;
|
||||
float motionScale;
|
||||
float spareB;
|
||||
float debugShowVelocityThreshold;
|
||||
};
|
||||
|
||||
layout(std140) uniform taaParamsBuffer {
|
||||
|
@ -35,25 +37,35 @@ layout(std140) uniform taaParamsBuffer {
|
|||
};
|
||||
|
||||
void main(void) {
|
||||
outFragColor = texture(currentMap, varTexCoord0);
|
||||
vec3 newColor = texture(currentMap, varTexCoord0).xyz;
|
||||
outFragColor = vec4(newColor, 1.0);
|
||||
|
||||
if (varTexCoord0.x > params.debugX) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Pixel being shaded
|
||||
vec3 sourceColor = texture(colorMap, varTexCoord0).xyz;
|
||||
|
||||
vec2 velocity = texture(velocityMap, varTexCoord0).xy;
|
||||
vec2 pixelVelocity = velocity * getWidthHeight(0);
|
||||
vec2 prevTexCoord = varTexCoord0 - params.motionScale * velocity;
|
||||
|
||||
outFragColor = vec4(sourceColor, 1.0);
|
||||
|
||||
if (abs(varTexCoord0.x - params.debugX) < (1.0 / 2048.0)) {
|
||||
if (abs(varTexCoord0.x - params.debugX) < getInvWidthHeight().x) {
|
||||
outFragColor.rgb = vec3(1.0, 1.0, 0.0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dot(velocity, velocity) > 0.0001) {
|
||||
vec3 prevColor = sourceColor;
|
||||
|
||||
if (!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))) {
|
||||
prevColor = texture(historyMap, prevTexCoord).xyz;
|
||||
}
|
||||
outFragColor.xyz = prevColor;
|
||||
|
||||
if (dot(pixelVelocity, pixelVelocity) > (params.debugShowVelocityThreshold * params.debugShowVelocityThreshold)) {
|
||||
outFragColor = vec4(0.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,15 @@ Column {
|
|||
config: Render.getConfig("RenderMainView.Antialiasing")
|
||||
property: "velocityScale"
|
||||
max: 1.0
|
||||
min: -1.0
|
||||
min: 0.0
|
||||
}
|
||||
ConfigSlider {
|
||||
label: qsTr("Debug Velocity Threshold [pix]")
|
||||
integral: false
|
||||
config: Render.getConfig("RenderMainView.Antialiasing")
|
||||
property: "debugShowVelocityThreshold"
|
||||
max: 20
|
||||
min: 0.0
|
||||
}
|
||||
CheckBox {
|
||||
text: "Freeze "
|
||||
|
|
Loading…
Reference in a new issue