FIxing the jittering projection modification

This commit is contained in:
Sam Gateau 2017-08-30 22:42:55 -07:00
parent 37f440031f
commit 16fbe00ef5
6 changed files with 26 additions and 26 deletions

View file

@ -411,12 +411,11 @@ int JitterSampleConfig::play() {
template <int B> class Halton {
public:
float eval(int index) {
float f = 1.0f;
float r = 0.0f;
float invB = 1.0f / (float)B;
index++;
index++; // Indices start at 1, not 0
while (index > 0) {
f = f * invB;
@ -431,19 +430,9 @@ public:
JitterSample::SampleSequence::SampleSequence(){
// Halton sequence (2,3)
Halton<2> genX;
Halton<3> genY;
offsets[0] = { 1.0f / 2.0f, 1.0f / 3.0f };
offsets[1] = { 1.0f / 4.0f, 2.0f / 3.0f };
offsets[2] = { 3.0f / 4.0f, 1.0f / 9.0f };
offsets[3] = { 1.0f / 8.0f, 4.0f / 9.0f };
offsets[4] = { 5.0f / 8.0f, 7.0f / 9.0f };
offsets[5] = { 3.0f / 8.0f, 2.0f / 9.0f };
offsets[6] = { 7.0f / 8.0f, 5.0f / 9.0f };
offsets[7] = { 1.0f / 16.0f, 8.0f / 9.0f };
for (int i = 0; i < SEQUENCE_LENGTH; i++) {
offsets[i] = glm::vec2(genX.eval(i), genY.eval(i));
}
@ -451,6 +440,7 @@ JitterSample::SampleSequence::SampleSequence(){
for (int i = 0; i < SEQUENCE_LENGTH; i++) {
offsets[i] -= vec2(0.5f);
}
offsets[SEQUENCE_LENGTH] = glm::vec2(0.0f);
}
void JitterSample::configure(const Config& config) {
@ -472,17 +462,17 @@ void JitterSample::run(const render::RenderContextPointer& renderContext, Jitter
auto projMat = viewFrustum.getProjection();
auto theNear = viewFrustum.getNearClip();
auto jit = _scale * jitterBuffer.get().offsets[current];
auto jit = jitterBuffer.get().offsets[current];
auto width = (float) renderContext->args->_viewport.z;
auto height = (float) renderContext->args->_viewport.w;
// auto jx = -4.0 * jit.x / width;
// auto jy = -4.0 * jit.y / height;
auto jx = -2.0 * jit.x / width;
auto jy = -2.0 * jit.y / height;
auto jx = 2.0 * jit.x / width;
auto jy = 2.0 * jit.y / height;
projMat[2][0] += jx * projMat[0][0];
projMat[2][1] += jy * projMat[1][1];
projMat[2][0] += jx;
projMat[2][1] += jy;
viewFrustum.setProjection(projMat);

View file

@ -55,7 +55,7 @@ public:
struct SampleSequence {
SampleSequence();
static const int SEQUENCE_LENGTH{ 16 };
glm::vec2 offsets[SEQUENCE_LENGTH];
glm::vec2 offsets[SEQUENCE_LENGTH + 1];
int sequenceLength{ SEQUENCE_LENGTH };
int currentIndex{ 0 };

View file

@ -22,7 +22,7 @@ void main() {
vec2 fragUV = varTexCoord0;
vec2 texelSize = getInvWidthHeight();
vec2 fragJitterPix = taa_getJitterSample(sequence.currentIndex);
vec2 fragJitterPix = taa_getCurrentJitterSample();
if (taa_unjitter()) {
fragUV -= fragJitterPix * texelSize;
}

View file

@ -15,9 +15,7 @@
const int SEQUENCE_LENGTH = 16;
struct JitterSequence {
vec4 offsets[SEQUENCE_LENGTH / 2];
int sequenceLength;
int currentIndex;
vec4 offsets[(SEQUENCE_LENGTH / 2) + 1];
};
layout(std140) uniform taaJitterBuffer {
JitterSequence sequence;
@ -27,6 +25,18 @@ vec2 taa_getJitterSample(int index) {
return vec2((bool(index & 0x01) ? sequence.offsets[index >> 1].zw : sequence.offsets[index >> 1].xy));
}
int taa_getJitterSequenceLength() {
return int(sequence.offsets[(SEQUENCE_LENGTH / 2)].z);
}
int taa_getCurrentJitterIndex() {
return int(sequence.offsets[(SEQUENCE_LENGTH / 2)].w);
}
vec2 taa_getCurrentJitterSample() {
return taa_getJitterSample(taa_getCurrentJitterIndex());
}
<@include gpu/Color.slh@>
uniform sampler2D depthMap;

View file

@ -28,7 +28,7 @@ void main(void) {
vec2 imageSize = getWidthHeight(0);
vec2 texelSize = getInvWidthHeight();
vec2 fragJitterPix = taa_getJitterSample(sequence.currentIndex);
vec2 fragJitterPix = taa_getCurrentJitterSample();
@ -44,7 +44,7 @@ void main(void) {
vec2 cursorUVRaw = taa_getDebugCursorTexcoord();
vec2 cursorPosRaw = floor(cursorUVRaw * imageSize) + vec2(0.5);
vec3 cursorFrag = taa_findClosestFragment3x3(cursorUVRaw);
vec2 cursorUV = cursorFrag.xy - fragJitterPix * texelSize;
vec2 cursorUV = cursorUVRaw - fragJitterPix * texelSize;
vec2 cursorPos = cursorUV * imageSize;
vec2 cursorVelocity = texture(velocityMap, cursorUV).xy;
vec2 cursorPrevUV = cursorUV - cursorVelocity;
@ -125,10 +125,10 @@ void main(void) {
float niceDotR2 = 4.0;
int sequenceLength = sequence.sequenceLength;
int sequenceLength = taa_getJitterSequenceLength();
for (int s = 0; s < sequenceLength; s++) {
vec2 pixToSampleVec = jitterRegionPos - (vec2(0.5) + taa_getJitterSample(s)) * jitterRegionSize;
float radius2 = (s == sequence.currentIndex ? 4.0 * niceDotR2 : niceDotR2);
float radius2 = (s == taa_getCurrentJitterIndex() ? 4.0 * niceDotR2 : niceDotR2);
float distToSample2 = dot(pixToSampleVec, pixToSampleVec);
if (distToSample2 < radius2) {
outFragColor = vec4(mix( outFragColor.rgb, colorRamp(float(s) / float(sequenceLength)), 1.0 - distToSample2 / radius2), 1.0);