Created
November 3, 2015 20:10
-
-
Save joeld42/c8dce66eb4b893cac0f1 to your computer and use it in GitHub Desktop.
zbuffer vs depth sorting examples for Luxe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import luxe.Input; | |
import luxe.Color; | |
import phoenix.geometry.CircleGeometry; | |
// NOTE: Using depth sort is reccomended, but if you want to use the | |
// zbuffer in addition (e.g. to mix with custom GL render passes) this | |
// is how to do it | |
// | |
// Add this to the 'build' section of your project.flow file | |
// defines : [ 'use_zbuffer' ], | |
class Main extends luxe.Game { | |
var numCircles = 40; | |
var geoms : Array<CircleGeometry>; | |
override function config(config:luxe.AppConfig) { | |
#if use_zbuffer | |
config.render.depth_bits = 24; | |
config.render.depth = true; | |
#end | |
return config; | |
} //config | |
override function ready() { | |
geoms = new Array<CircleGeometry>(); | |
var hueStep = 360.0 / numCircles; | |
for (i in 0...numCircles) | |
{ | |
var g1 = new CircleGeometry({ | |
r : 50, | |
color : new ColorHSV(i*hueStep,1.0,1.0,1.0), | |
batcher : Luxe.renderer.batcher | |
}); | |
geoms.push(g1); | |
} | |
#if use_zbuffer | |
Luxe.camera.view.set_ortho({ depth_test : true }); | |
#end | |
} //ready | |
override function onkeyup( e:KeyEvent ) { | |
if(e.keycode == Key.escape) { | |
Luxe.shutdown(); | |
} | |
} //onkeyup | |
var rotate = 0.0; | |
override function update(dt:Float) { | |
rotate += dt; | |
var hueStep = 360.0 / numCircles; | |
var angStep = hueStep * (3.14/180.0); | |
for (i in 0...geoms.length) | |
{ | |
var t = rotate + (i*angStep); | |
var g = geoms[i]; | |
g.transform.pos.set_xy( (Luxe.screen.w / 2.0) + Math.cos(t) * 120, | |
(Luxe.screen.h / 2.0) + Math.sin(t) * 120 ); | |
// use screen Y for depth | |
#if use_zbuffer | |
g.transform.pos.z = -g.transform.pos.y; | |
#else | |
g.depth = g.transform.pos.y ; | |
#end | |
} | |
} //update | |
} //Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment