-
Notifications
You must be signed in to change notification settings - Fork 335
/
Renderer.hx
85 lines (64 loc) · 2.17 KB
/
Renderer.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package h3d.scene.fwd;
class DepthPass extends h3d.pass.Output {
var depthMapId : Int;
public var enableSky : Bool = false;
public function new() {
super("depth", [PackFloat(Value("output.depth"))]);
depthMapId = hxsl.Globals.allocID("depthMap");
}
override function draw( passes, ?sort ) {
var texture = ctx.textures.allocTarget("depthMap", ctx.engine.width, ctx.engine.height, true);
ctx.engine.pushTarget(texture);
ctx.engine.clear(enableSky ? 0 : 0xFF0000, 1);
super.draw(passes, sort);
ctx.engine.popTarget();
ctx.globals.fastSet(depthMapId, { texture : texture });
}
}
class NormalPass extends h3d.pass.Output {
var normalMapId : Int;
public function new() {
super("normal", [PackNormal(Value("output.normal"))]);
normalMapId = hxsl.Globals.allocID("normalMap");
}
override function draw( passes, ?sort ) {
var texture = ctx.textures.allocTarget("normalMap", ctx.engine.width, ctx.engine.height);
ctx.engine.pushTarget(texture);
ctx.engine.clear(0x808080, 1);
super.draw(passes, sort);
ctx.engine.popTarget();
ctx.globals.fastSet(normalMapId, texture);
}
}
class Renderer extends h3d.scene.Renderer {
var def(get, never) : h3d.pass.Output;
public var depth : h3d.pass.Output = new DepthPass();
public var normal : h3d.pass.Output = new NormalPass();
public var shadow = new h3d.pass.DefaultShadowMap(1024);
public function new() {
super();
defaultPass = new h3d.pass.Output("default");
allPasses = [defaultPass, depth, normal, shadow];
}
inline function get_def() return defaultPass;
// can be overriden for benchmark purposes
function renderPass(p:h3d.pass.Output, passes, ?sort) {
p.draw(passes, sort);
}
override function getPassByName(name:String):h3d.pass.Output {
if( name == "alpha" || name == "additive" )
return defaultPass;
return super.getPassByName(name);
}
override function render() {
if( has("shadow") )
renderPass(shadow,get("shadow"));
if( has("depth") )
renderPass(depth,get("depth"));
if( has("normal") )
renderPass(normal,get("normal"));
renderPass(defaultPass, get("default") );
renderPass(defaultPass, get("alpha"), backToFront );
renderPass(defaultPass, get("additive") );
}
}