Commit 153b3f02 authored by Dario Seyb's avatar Dario Seyb

reprojection fixes

parent ff20c3cb
......@@ -4,6 +4,9 @@ uniform sampler2D uSamplerColor;
uniform sampler2D uSamplerHistory;
uniform sampler2D uSamplerMotion;
uniform vec2 uOneOverColorSize;
uniform vec2 uOneOverMotionSize;
in vec2 vTexCoord;
out vec4 oColor;
......@@ -21,17 +24,15 @@ void main()
vec3 motion = texture(uSamplerMotion, vTexCoord).xyz;
for(int i = 0; i < 4; i++) {
vec3 motionSample = texture(uSamplerMotion, vTexCoord + SAMPLE_OFFSETS[i]/vec2(1280, 720)).xyz;
vec3 motionSample = texture(uSamplerMotion, vTexCoord + SAMPLE_OFFSETS[i]*uOneOverMotionSize).xyz;
if(motionSample.z < motion.z) {
motion = motionSample;
}
}
vec2 samplePos = vTexCoord-motion.xy;
vec4 history = texture(uSamplerHistory, vTexCoord);
vec4 history = texture(uSamplerHistory, vTexCoord - motion.xy);
float factor = 0.75;
float factor = 0.8;
vec4 current = texture(uSamplerColor, vTexCoord);
......@@ -40,7 +41,7 @@ void main()
for(int x = -1; x <= 1; x++) {
for(int y = -1; y <= 1; y++) {
vec4 sample = texture(uSamplerColor, vTexCoord + vec2(x, y)/vec2(1280, 720));
vec4 sample = texture(uSamplerColor, vTexCoord + vec2(x, y)*uOneOverColorSize);
minNeighbour = min(minNeighbour, sample);
maxNeighbour = max(maxNeighbour, sample);
}
......
......@@ -90,6 +90,8 @@ private:
glm::mat4 aaProj;
uint64_t m_frameIndex = 0;
void render(RenderPass& pass, double interp, double totalTime);
public:
......
......@@ -233,8 +233,6 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
auto windowSize = m_window->getSize();
// Do Camera jitter for TXAA
static int frameIndex = 0;
frameIndex++;
// Halton(2,3)
static const glm::vec3 OFFSETS[8]{
glm::vec3{ 1.0 / 2.0, 1.0 / 3.0, 0 },
......@@ -248,7 +246,7 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
glm::vec3{ 1.0 / 16.0, 8.0 / 9.0, 0 },
};
auto currentOffset = OFFSETS[frameIndex % 8] * 2.0 - 1.0f;
auto currentOffset = OFFSETS[m_frameIndex % 8] * 2 - 1.0f;
currentOffset.x /= gBufferRes.x;
currentOffset.y /= gBufferRes.y;
......@@ -589,6 +587,12 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
m_txaaProg->setTexture("uSamplerMotion", m_motionBuffer, 2);
auto colorSize = glm::vec2(m_secondaryCompositingBuffer->getSize());
m_txaaProg->setUniform("uOneOverColorSize", glm::vec2(1.0) / colorSize);
auto motionSize = glm::vec2(m_motionBuffer->getSize());
m_txaaProg->setUniform("uOneOverMotionSize", glm::vec2(1.0) / motionSize);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // create 2 triangles (defined in shader) with no attributes
if (!pass.renderToTextureOnly) {
......@@ -610,10 +614,11 @@ void RendererSystem::render(RenderPass& pass, double interp, double totalTime) {
pass.compositingTarget = pass.txaaHistory;
pass.txaaHistory = temp;
trans->lastRenderTransform = camTransform;
trans->lastRenderTransform = static_cast<glm::dmat4>(camTransform);
}
void RendererSystem::frame(double interp, double totalTime) {
m_frameIndex++;
m_primaryCompositingBuffer->setClearColor(glm::vec4{ 0, 0, 0, 0 });
m_primaryCompositingBuffer->bind();
......
......@@ -102,7 +102,7 @@ void SceneGraphSystem::prepareDraw(double interp) {
e.unpack<Light, Transform>(light, transform);
auto viewMatrix = glm::lookAt<double>(glm::dvec3(light->dir), { 0.0, 0.0, 0.0 }, glm::dvec3(0.0, 1.0, 0.0));
auto lightVP = glm::ortho<double>(-10, +10, -10, +10, -10, 10) * static_cast<glm::dmat4>(viewMatrix);
auto lightVP = glm::ortho<double>(-7, +7, -7, +7, -7, 7) * static_cast<glm::dmat4>(viewMatrix);
m_renderer->submit({light->color, light->castShadow,light->dir, light->type, transform->lastGlobalTransform, transform->thisGlobalTransform, lightVP, nullptr, nullptr}, light->renderPassIndex);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment