Skip to content

Commit 2787219

Browse files
committed
Merge branch 'anti-aliasing-texture' of https://github.com/mc-saw/heaps into anti-aliasing-texture
2 parents 191af35 + c8987c9 commit 2787219

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

h2d/RenderContext.hx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class RenderContext extends h3d.impl.RenderContext {
151151
cameraStackIndex = 0;
152152
filterStack = [];
153153
filterStackIndex = 0;
154+
#if anti_aliasing
155+
globals.set("global.antiAliasing", 0);
156+
#end
154157
}
155158

156159
override function dispose() {

h3d/scene/RenderContext.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class RenderContext extends h3d.impl.RenderContext {
4646
@global("global.modelViewInverse") var globalModelViewInverse : h3d.Matrix;
4747
@global("global.previousModelView") var globalPreviousModelView : h3d.Matrix;
4848
@global("global.frame") var globalFrame : Int;
49+
#if anti_aliasing
50+
@global("global.antiAliasing") var globalAntiAliasing : Int;
51+
#end
4952

5053
var allocPool : h3d.pass.PassObject;
5154
var allocFirst : h3d.pass.PassObject;
@@ -67,6 +70,9 @@ class RenderContext extends h3d.impl.RenderContext {
6770
cachedShaderList = [];
6871
cachedPassObjects = [];
6972
initGlobals();
73+
#if anti_aliasing
74+
globalAntiAliasing = 0;
75+
#end
7076
}
7177

7278
public function setCamera( cam : h3d.Camera ) {

h3d/shader/Texture.hx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ class Texture extends hxsl.Shader {
66
@input var input : {
77
var uv : Vec2;
88
};
9+
10+
#if anti_aliasing
11+
@global var global: {
12+
var antiAliasing: Int;
13+
};
14+
#end
915

1016
@const var additive : Bool;
1117
@const var killAlpha : Bool;
@@ -22,7 +28,21 @@ class Texture extends hxsl.Shader {
2228
}
2329

2430
function fragment() {
31+
#if anti_aliasing
32+
var c = if (global.antiAliasing == 1) {
33+
var dx = dFdx(input.uv);
34+
var dy = dFdy(input.uv);
35+
var c0 = texture.get(input.uv + 0.25 * dx + 0.25 * dy);
36+
var c1 = texture.get(input.uv + 0.25 * dx - 0.25 * dy);
37+
var c2 = texture.get(input.uv - 0.25 * dx + 0.25 * dy);
38+
var c3 = texture.get(input.uv - 0.25 * dx - 0.25 * dy);
39+
(c0 + c1 + c2 + c3) * 0.25;
40+
} else {
41+
texture.get(calculatedUV);
42+
}
43+
#else
2544
var c = texture.get(calculatedUV);
45+
#end
2646
if( killAlpha && c.a - killAlphaThreshold < 0 ) discard;
2747
if( additive )
2848
pixelColor += c;

0 commit comments

Comments
 (0)