Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DerSchmale committed Dec 31, 2018
2 parents 90eec07 + d4ca20e commit 37632b1
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 80 deletions.
71 changes: 35 additions & 36 deletions build/helix.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/helix.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/taa/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>Helix example: Temporal Anti-Aliasing</title>

<script src="../../build/helix.js"></script>
<script src="../../build/helix.min.js"></script>
<script src="../../build/helix-io.min.js"></script>
<script src="../js/ProjectTemplates.js"></script>
<script src="../js/OrbitController.js"></script>
Expand Down
5 changes: 3 additions & 2 deletions examples/taa/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function initCamera(camera)
camera.addComponent(controller);

taa = new HX.TAA();
taa.alpha = 0.01;
fxaa = new HX.FXAA();
camera.addComponent(taa);
camera.addComponent(fxaa);
Expand All @@ -90,7 +91,7 @@ function initScene(scene, camera, assetLibrary)
var material = new HX.BasicMaterial();
material.cullMode = HX.CullMode.NONE;
material.metallicness = 1.0;
material.roughness = .01;
material.roughness = .1;
replaceMaterials(model, material, floorMaterial);

scene.startSystem(new HX.FixedLightsSystem());
Expand Down Expand Up @@ -123,5 +124,5 @@ function initGui()

var taaFolder = gui.addFolder("TAA");
taaFolder.add(taa, "alpha").min(0).max(1).step(.001);
taaFolder.add(taa, "gamma").min(0).max(1).step(.001);
taaFolder.add(taa, "gamma").min(0).max(2).step(.001);
}
2 changes: 1 addition & 1 deletion src/helix-core/effect/TAA.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function TAA()
ShaderLibrary.get("taa_fragment.glsl")
);
this._pass.setTexture("historyBuffer", this._historyTexture);
this.alpha = .01;
this.alpha = .1;
this.gamma = 1.0;
}

Expand Down
68 changes: 30 additions & 38 deletions src/helix-core/glsl/post-processing/taa_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void main()
float amount = alpha;

// out of bounds: take new value completely
if (oldUV.x < 0.0 || oldUV.x > 1.0 || oldUV.y < 0.0 || oldUV.y > 1.0)
amount = 1.0;
// if (oldUV.x < 0.0 || oldUV.x > 1.0 || oldUV.y < 0.0 || oldUV.y > 1.0)
// amount = 1.0;

// neighbourhood clamping: the old colour is only considered valid if it's within the bounds of the current neighbours
// https://de45xmedrsdbp.cloudfront.net/Resources/files/TemporalAA_small-59732822.pdf [Karis2014]
Expand All @@ -29,42 +29,34 @@ void main()
vec3 maxBound = max(max(max(max(l, r), t), b), c);

// just treat rgb space as a regular 3D space
if (any(lessThan(old, minBound)) || any(greaterThan(old, maxBound))) {
// variance clipping
// http://developer.download.nvidia.com/gameworks/events/GDC2016/msalvi_temporal_supersampling.pdf
// moments
vec3 m1 = l + r + t + b + c;
vec3 m2 = l * l + r * r + t * t + b * b + c * c;
// variance
vec3 mu = m1 / 5.0;
vec3 sigma = sqrt(m2 / 5.0 - mu * mu);

vec3 d = c - old;

// find relevant AABB planes (those closest to the ray, know this from ray direction)
vec3 planes = mu - sign(d) * gamma * sigma;

// clip to old AABB to make sure it's never bigger
planes = max(planes, minBound);
planes = min(planes, maxBound);


// clip segment [old -> C] against new AABB
// C is always inside AABB
vec3 tm = (planes - old) / d;
vec3 absD = abs(d);

float t = 0.0;

if (absD.x > 0.0003)
t = max(tm.x, t);
if (absD.y > 0.0003)
t = max(tm.y, t);
if (absD.z > 0.0003)
t = max(tm.z, t);

old += t * d;
}
// variance clipping
// http://developer.download.nvidia.com/gameworks/events/GDC2016/msalvi_temporal_supersampling.pdf
// moments
vec3 m1 = l + r + t + b + c;
vec3 m2 = l * l + r * r + t * t + b * b + c * c;
// variance
vec3 mu = m1 / 5.0;
vec3 sigma = sqrt(m2 / 5.0 - mu * mu);

vec3 d = c - old;

// find relevant AABB planes (those closest to the ray, know this from ray direction)
vec3 planes = mu - sign(d) * gamma * sigma;

// clip to old AABB to make sure it's never bigger
planes = max(planes, minBound);
planes = min(planes, maxBound);

// clip segment [old -> C] against new AABB
// C is always inside AABB
vec3 tm = (planes - old) / d;
vec3 absD = abs(d);

float tf = (max(tm.x, tm.y), tm.z);

// if already inside the box, or somehow overshooting target (?)
if (tf >= -0.001 && tf <= 1.001)
old += tf * d;

hx_FragColor.xyz = mix(old, c, amount);
hx_FragColor.w = col.w;
Expand Down
2 changes: 1 addition & 1 deletion src/helix-core/math/Matrix4x4.js
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ Matrix4x4.prototype =
cm[10] *= rcpZ;

quat.fromMatrix(clone);
this.getColumn(3, pos)
this.getColumn(3, pos);

return targetOrPos;
},
Expand Down

0 comments on commit 37632b1

Please sign in to comment.