using the linear depth buffer and voila

This commit is contained in:
Sam Gateau 2017-08-25 00:25:13 -07:00
parent 914db1d5a6
commit bf982c3a85
6 changed files with 22 additions and 9 deletions

View file

@ -182,9 +182,10 @@ const int AntialiasingPass_FrameTransformSlot = 1;
const int AntialiasingPass_HistoryMapSlot = 0;
const int AntialiasingPass_SourceMapSlot = 1;
const int AntialiasingPass_VelocityMapSlot = 2;
const int AntialiasingPass_NextMapSlot = 3;
const int AntialiasingPass_DepthMapSlot = 3;
const int AntialiasingPass_NextMapSlot = 4;
Antialiasing::Antialiasing() {
}
@ -298,7 +299,8 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
auto& deferredFrameTransform = inputs.get0();
auto& sourceBuffer = inputs.get1();
auto& velocityBuffer = inputs.get2();
auto& linearDepthBuffer = inputs.get2();
auto& velocityBuffer = inputs.get3();
int width = sourceBuffer->getWidth();
int height = sourceBuffer->getHeight();
@ -334,7 +336,7 @@ 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.setResourceTexture(AntialiasingPass_DepthMapSlot, sourceBuffer->getDepthStencilBuffer());
batch.setResourceTexture(AntialiasingPass_DepthMapSlot, linearDepthBuffer->getLinearDepthTexture());
batch.setUniformBuffer(AntialiasingPass_ParamsSlot, _params._buffer);
batch.setUniformBuffer(AntialiasingPass_FrameTransformSlot, deferredFrameTransform->getFrameTransformBuffer());

View file

@ -71,7 +71,7 @@ using TAAParamsBuffer = gpu::StructBuffer<TAAParams>;
class Antialiasing {
public:
using Inputs = render::VaryingSet3<DeferredFrameTransformPointer, gpu::FramebufferPointer, VelocityFramebufferPointer>;
using Inputs = render::VaryingSet4 < DeferredFrameTransformPointer, gpu::FramebufferPointer, LinearDepthFramebufferPointer, VelocityFramebufferPointer > ;
using Config = AntialiasingConfig;
using JobModel = render::Job::ModelI<Antialiasing, Inputs, Config>;

View file

@ -221,7 +221,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
}
// AA job to be revisited
const auto antialiasingInputs = Antialiasing::Inputs(deferredFrameTransform, primaryFramebuffer, velocityBuffer).asVarying();
const auto antialiasingInputs = Antialiasing::Inputs(deferredFrameTransform, primaryFramebuffer, linearDepthTarget, velocityBuffer).asVarying();
task.addJob<Antialiasing>("Antialiasing", antialiasingInputs);

View file

@ -21,12 +21,18 @@ layout(location = 0) out vec4 outFragColor;
void main() {
vec3 fragUV = taa_findClosestFragment3x3(varTexCoord0);
// vec3 fragUV = vec3(varTexCoord0, taa_fetchDepth(varTexCoord0));
vec2 fragVel = taa_fetchVelocityMap(fragUV.xy);
vec3 sourceColor;
vec3 historyColor;
//vec3 nextColor = taa_temporalReprojection(fragUV.xy, fragVel, fragUV.z);
vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV.xy, fragVel, sourceColor, historyColor);
/* vec3 sourceColor = taa_fetchSourceMap(fragUV.xy).xyz;
vec2 prevFragUV = fragUV.xy - fragVel;
vec3 historyColor = sourceColor;
if (!(any(lessThan(prevFragUV, vec2(0.0))) || any(greaterThan(prevFragUV, vec2(1.0))))) {
historyColor = taa_fetchHistoryMap(prevFragUV).xyz;
}*/
vec3 nextColor = mix(historyColor, sourceColor, params.blend);

View file

@ -88,15 +88,15 @@ vec4 taa_fetchNextMap(vec2 uv) {
}
vec2 taa_fetchVelocityMap(vec2 uv) {
return params.motionScale * texture(velocityMap, uv).xy;
return texture(velocityMap, uv).xy;
}
float taa_fetchDepth(vec2 uv) {
return texture(depthMap, vec2(uv), 0).x;
return -texture(depthMap, vec2(uv), 0).x;
}
#define ZCMP_GT(a, b) (a < b)
#define ZCMP_GT(a, b) (a > b)
vec3 taa_findClosestFragment3x3(vec2 uv)
{

View file

@ -21,6 +21,7 @@ void main(void) {
vec3 nextColor = texture(nextMap, varTexCoord0).xyz;
outFragColor = vec4(nextColor, 1.0);
// Pixel being shaded
vec3 sourceColor = texture(sourceMap, varTexCoord0).xyz;
@ -115,6 +116,10 @@ void main(void) {
return;
}
vec3 fragUV = taa_findClosestFragment3x3(varTexCoord0);
outFragColor = vec4((fragUV.xy - varTexCoord0) * imageSize * 0.5 + vec2(0.5), 0.0, 1.0);
return;
outFragColor = vec4(nextColor, 1.0);
vec3 prevColor = nextColor;