diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/scenegraph.js')
-rw-r--r-- | js/helper-classes/RDGE/src/core/script/scenegraph.js | 1123 |
1 files changed, 1123 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/scenegraph.js b/js/helper-classes/RDGE/src/core/script/scenegraph.js new file mode 100644 index 00000000..6814dcbf --- /dev/null +++ b/js/helper-classes/RDGE/src/core/script/scenegraph.js | |||
@@ -0,0 +1,1123 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var g_drawCount = 0; | ||
8 | g_enableFlyCam = false; | ||
9 | |||
10 | g_sceneStats = {}; | ||
11 | g_sceneStats.nodesVisible = new stat("scenegraph", "nodesVisible", 0, null, false); | ||
12 | g_sceneStats.nodesCulled = new stat("scenegraph", "nodesCulled", 0, null, false); | ||
13 | g_sceneStats.nodesVisited = new stat("scenegraph", "nodesVisited", 0, null, false); | ||
14 | g_sceneStats.reset = function() { | ||
15 | g_sceneStats.nodesVisible.value = 0; | ||
16 | g_sceneStats.nodesVisited.value = 0; | ||
17 | g_sceneStats.nodesCulled.value = 0; | ||
18 | }; | ||
19 | |||
20 | // default render proc | ||
21 | // render scene nodes | ||
22 | function DefaultRender() | ||
23 | { | ||
24 | // setup the default shader | ||
25 | this.renderer = g_Engine.getContext().renderer; | ||
26 | //this.shaderProgram = this.renderer.defaultShader; | ||
27 | this.jshaderProgram = new jshader(); | ||
28 | this.jshaderProgram.def = this.renderer.defaultShaderDefintion; | ||
29 | this.jshaderProgram.init(); | ||
30 | } | ||
31 | |||
32 | DefaultRender.prototype.process=function(context,trNode,parent) { | ||
33 | |||
34 | } | ||
35 | |||
36 | function renderObject( trNode, renderCtx, parent) | ||
37 | { | ||
38 | this.node = trNode ? trNode : createTransformNode(); | ||
39 | this.context = renderCtx ? renderCtx : new RenderContext(); | ||
40 | this.parent = parent ? parent : null; | ||
41 | } | ||
42 | |||
43 | |||
44 | // Scene graph contains set of tools for manipulating the graph | ||
45 | function SceneGraph(scene) | ||
46 | { | ||
47 | if(scene == undefined || scene == null) | ||
48 | scene = {}; | ||
49 | |||
50 | this.scene = scene; | ||
51 | |||
52 | if(this.scene.root != undefined) | ||
53 | this.scene = this.scene.root; | ||
54 | else | ||
55 | this.scene = { 'children':[] }; | ||
56 | |||
57 | this.tick = 0; | ||
58 | this.lastTick = -1; | ||
59 | this.frustumCulling = true; | ||
60 | |||
61 | // the main light for the scene - also casts shadows | ||
62 | this.mainLight = new shadowLight(); | ||
63 | |||
64 | this.bckTypes = rdgeConstants.categoryEnumeration; | ||
65 | |||
66 | this.renderList = new Array(this.bckTypes.MAX_CAT); | ||
67 | this.renderList[this.bckTypes.BACKGROUND] = []; //BACKGROUND | ||
68 | this.renderList[this.bckTypes.OPAQUE] = []; //OPAQUE | ||
69 | this.renderList[this.bckTypes.TRANSPARENT] = []; //TRANSPARENT | ||
70 | this.renderList[this.bckTypes.ADDITIVE] = []; //ADDITIVE | ||
71 | this.renderList[this.bckTypes.TRANSLUCENT] = []; //TRANSLUCENT | ||
72 | this.renderList[this.bckTypes.FOREGROUND] = []; //FOREGROUND | ||
73 | |||
74 | // a list of shadow geometry | ||
75 | this.shadowRenderList = []; | ||
76 | |||
77 | // scene traversal functor for creating a culled list of shadow geometry | ||
78 | this.shadowCuller = null; | ||
79 | |||
80 | // define passes to render geometry and handle post-processing | ||
81 | this.defaultPassDef = | ||
82 | { | ||
83 | // a pass can have children that will receive their parents output as input | ||
84 | |||
85 | // this pass renders the depth map to an off-screen target - from the shadow lights view | ||
86 | // you can specify what your output should be | ||
87 | // @param name - this tells jshader's of child passes (which receive the parents output as input) | ||
88 | // what the sampler2d uniform name will be for this output texture | ||
89 | // @param type - the type of output could be tex2d or target | ||
90 | // @param width - optional width of the render target | ||
91 | // @param height - optional height of the render target | ||
92 | // @param mips - optional flag indicating whether the render target will support mip-mapping | ||
93 | |||
94 | // the geometry pass | ||
95 | 'name': "geoPass", | ||
96 | 'geometrySet': "ALL" | ||
97 | // 'outputs':[{ 'name':"u_mainRT", 'type':"target", 'width':1024, 'height':1024, 'mips':false }], | ||
98 | // 'children': | ||
99 | // [ | ||
100 | // // shadow pass | ||
101 | // { | ||
102 | // 'outputs':[{ 'name':"u_shadowDepthMap", 'type':"target", 'width':1024, 'height':1024, 'mips':false }], | ||
103 | // // custom parameter | ||
104 | // 'name':"shadowDepthMap", | ||
105 | // 'shader': rdgeDepthMapShaderDef, | ||
106 | // 'technique':"shadowDepthMap", | ||
107 | // 'geometrySet':"SHADOW", | ||
108 | // 'children': | ||
109 | // [ | ||
110 | // // create shadow rt | ||
111 | // { | ||
112 | // 'outputs':[{ 'name':"u_shadowMap", 'type':"target", 'width':1024, 'height':1024, 'mips':false }], | ||
113 | // 'name':"shadowMap", | ||
114 | // 'shader': rdgeShadowMapShader, | ||
115 | // 'clearColor' : [1.0,1.0,1.0,1.0], | ||
116 | // 'geometrySet':"SHADOW", | ||
117 | // } | ||
118 | // ] | ||
119 | // }, | ||
120 | // // glow pass | ||
121 | // { | ||
122 | // 'outputs':[{ 'name':"sTexture", 'type':"target", 'width':1024, 'height':1024, 'mips':false }], | ||
123 | // 'name':"glowMap", | ||
124 | // 'shader': rdgeGlowMapShader, | ||
125 | // 'clearColor' : [0.0,0.0,0.0,1.0], | ||
126 | // 'technique':"createGlowMap", | ||
127 | // 'geometrySet':"ALL", | ||
128 | // 'children': | ||
129 | // [ | ||
130 | // { // the blur pass at half resolution | ||
131 | // 'name':"blurQuarter", | ||
132 | // 'geometrySet':"SCREEN_QUAD", | ||
133 | // 'shader': rdgeGaussianBlurShader, | ||
134 | // 'outputs':[{ 'name':"sTexture", 'type':"target", 'width':256, 'height':256, 'mips':false }], | ||
135 | // 'children': | ||
136 | // [ | ||
137 | // { // the blur pass at half resolution | ||
138 | // 'name':"blurThreeQuarter", | ||
139 | // 'geometrySet':"SCREEN_QUAD", | ||
140 | // 'shader': rdgeGaussianBlurShader, | ||
141 | // 'outputs':[{ 'name':"sTexture", 'type':"target", 'width':128, 'height':128, 'mips':false }], | ||
142 | // 'children': | ||
143 | // [ | ||
144 | // { // the blur pass at quarter resolution | ||
145 | // 'name':"blurFull", | ||
146 | // 'geometrySet':"SCREEN_QUAD", | ||
147 | // 'shader': rdgeGaussianBlurShader, | ||
148 | // 'outputs':[{ 'name':"u_glowFinal", 'type':"target", 'width':1024, 'height':1024, 'mips':false }] | ||
149 | // } | ||
150 | // ] | ||
151 | // } | ||
152 | // ] | ||
153 | // } | ||
154 | // ] | ||
155 | // }, | ||
156 | // // depth map in view space | ||
157 | // { | ||
158 | // 'name':"depth_map", | ||
159 | // 'shader': rdgeDepthMapShaderDef, | ||
160 | // 'technique': "depthMap", | ||
161 | // 'outputs':[{ 'name':"u_depthMap", 'type':"target", 'width':1024, 'height':1024, 'mips':false }], | ||
162 | // 'geometrySet':"ALL", | ||
163 | // 'children' : | ||
164 | // [ | ||
165 | // // get the normals in view space | ||
166 | // { | ||
167 | // 'name':"normals", | ||
168 | // 'shader': rdgeViewSpaceNormalsShader, | ||
169 | // 'outputs':[{ 'name':"u_normalsRT", 'type':"target", 'width':1024, 'height':1024, 'mips':false }], | ||
170 | // 'geometrySet':"ALL", | ||
171 | // 'children' : | ||
172 | // [ | ||
173 | // // techniques requiring depth and normals in view space go here | ||
174 | // | ||
175 | // // SSAO map | ||
176 | // { | ||
177 | // 'name':"SSAO", | ||
178 | // 'shader': rdgeSSAOShader, | ||
179 | // 'outputs':[{ 'name':"u_ssaoRT", 'type':"target", 'width':1024, 'height':1024, 'mips':false }], | ||
180 | // 'textures':[{ 'type':"tex2d", 'data':"u_depthMap" }], | ||
181 | // 'geometrySet':"SCREEN_QUAD", | ||
182 | // 'preRender': function() | ||
183 | // { | ||
184 | // this.shader.ssao.u_cameraFTR.set(this.renderer.cameraManager().getActiveCamera().getFTR()); | ||
185 | // } | ||
186 | // } | ||
187 | // ] | ||
188 | // } | ||
189 | // ] | ||
190 | // }, | ||
191 | // | ||
192 | // // final pass must always be last in the list | ||
193 | // { | ||
194 | // // this final pass has no output, its shader, however, will render its input (the previous pass's output) | ||
195 | // // to the screen-quad geometry setup under the 'renderList' object | ||
196 | // 'name':"finalPass", | ||
197 | // 'geometrySet':"SCREEN_QUAD", | ||
198 | // 'textures':[{ 'type':"tex2d", 'data':"u_glowFinal" }, { 'type':"tex2d", 'data':"u_ssaoRT" }, { 'type':"tex2d", 'data':"u_shadowMap" }], | ||
199 | // |