Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions h2d/RenderContext.hx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class RenderContext extends h3d.impl.RenderContext {
cameraStackIndex = 0;
filterStack = [];
filterStackIndex = 0;
#if anti_aliasing
globals.set("global.antiAliasing", 0);
#end
}

override function dispose() {
Expand Down
6 changes: 6 additions & 0 deletions h3d/scene/RenderContext.hx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class RenderContext extends h3d.impl.RenderContext {
@global("global.modelViewInverse") var globalModelViewInverse : h3d.Matrix;
@global("global.previousModelView") var globalPreviousModelView : h3d.Matrix;
@global("global.frame") var globalFrame : Int;
#if anti_aliasing
@global("global.antiAliasing") var globalAntiAliasing : Int;
#end

var allocPool : h3d.pass.PassObject;
var allocFirst : h3d.pass.PassObject;
Expand All @@ -67,6 +70,9 @@ class RenderContext extends h3d.impl.RenderContext {
cachedShaderList = [];
cachedPassObjects = [];
initGlobals();
#if anti_aliasing
globalAntiAliasing = 0;
#end
}

public function setCamera( cam : h3d.Camera ) {
Expand Down
20 changes: 20 additions & 0 deletions h3d/shader/Texture.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class Texture extends hxsl.Shader {
@input var input : {
var uv : Vec2;
};

#if anti_aliasing
@global var global: {
var antiAliasing: Int;
};
#end

@const var additive : Bool;
@const var killAlpha : Bool;
Expand All @@ -22,7 +28,21 @@ class Texture extends hxsl.Shader {
}

function fragment() {
#if anti_aliasing
var c = if (global.antiAliasing == 1) {
var dx = dFdx(input.uv);
var dy = dFdy(input.uv);
var c0 = texture.get(input.uv + 0.25 * dx + 0.25 * dy);
var c1 = texture.get(input.uv + 0.25 * dx - 0.25 * dy);
var c2 = texture.get(input.uv - 0.25 * dx + 0.25 * dy);
var c3 = texture.get(input.uv - 0.25 * dx - 0.25 * dy);
(c0 + c1 + c2 + c3) * 0.25;
} else {
texture.get(calculatedUV);
}
#else
var c = texture.get(calculatedUV);
#end
if( killAlpha && c.a - killAlphaThreshold < 0 ) discard;
if( additive )
pixelColor += c;
Expand Down
Loading