3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-26 19:35:48 +02:00

Expose Hlaton 16 sequence

This commit is contained in:
samcake 2017-08-30 17:59:06 -07:00
parent af09ae0686
commit 37f440031f
4 changed files with 41 additions and 10 deletions

View file

@ -409,8 +409,32 @@ int JitterSampleConfig::play() {
return _index;
}
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++;
while (index > 0) {
f = f * invB;
r = r + f * (float) (index % B);
index = index / B;
}
return r;
}
};
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 };
@ -421,7 +445,11 @@ JitterSample::SampleSequence::SampleSequence(){
offsets[7] = { 1.0f / 16.0f, 8.0f / 9.0f };
for (int i = 0; i < SEQUENCE_LENGTH; i++) {
offsets[i] = offsets[i] - vec2(0.5f);
offsets[i] = glm::vec2(genX.eval(i), genY.eval(i));
}
for (int i = 0; i < SEQUENCE_LENGTH; i++) {
offsets[i] -= vec2(0.5f);
}
}
@ -448,11 +476,13 @@ void JitterSample::run(const render::RenderContextPointer& renderContext, Jitter
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;
projMat[2][0] += jx;
projMat[2][1] += jy;
// 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;
projMat[2][0] += jx * projMat[0][0];
projMat[2][1] += jy * projMat[1][1];
viewFrustum.setProjection(projMat);

View file

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

View file

@ -13,7 +13,7 @@
<@include DeferredTransform.slh@>
<$declareDeferredFrameTransform()$>
const int SEQUENCE_LENGTH = 8;
const int SEQUENCE_LENGTH = 16;
struct JitterSequence {
vec4 offsets[SEQUENCE_LENGTH / 2];
int sequenceLength;

View file

@ -125,12 +125,13 @@ void main(void) {
float niceDotR2 = 4.0;
for (int s = 0; s < SEQUENCE_LENGTH; s++) {
int sequenceLength = sequence.sequenceLength;
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 distToSample2 = dot(pixToSampleVec, pixToSampleVec);
if (distToSample2 < radius2) {
outFragColor = vec4(mix( outFragColor.rgb, colorRamp(float(s) / float(SEQUENCE_LENGTH)), 1.0 - distToSample2 / radius2), 1.0);
outFragColor = vec4(mix( outFragColor.rgb, colorRamp(float(s) / float(sequenceLength)), 1.0 - distToSample2 / radius2), 1.0);
return;
}
}