diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/RenderInitProcs.js')
-rw-r--r-- | js/helper-classes/RDGE/src/core/script/RenderInitProcs.js | 263 |
1 files changed, 263 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/RenderInitProcs.js b/js/helper-classes/RDGE/src/core/script/RenderInitProcs.js new file mode 100644 index 00000000..9d4e0d63 --- /dev/null +++ b/js/helper-classes/RDGE/src/core/script/RenderInitProcs.js | |||
@@ -0,0 +1,263 @@ | |||
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 | renderInitProcDefault = __renderInitProcDefault; | ||
8 | renderInitScreenQuad = __renderInitScreenQuad; | ||
9 | renderInitProcDepthMap = __renderInitProcDepthMap; | ||
10 | renderInitShadowReceiver= __renderInitShadowReceiver; | ||
11 | renderInitShadowProjection = __renderInitShadowProjection; | ||
12 | |||
13 | function __renderInitProcDefault(primSet, vertexData) | ||
14 | { | ||
15 | var material = primSet.material; | ||
16 | |||
17 | //push envMap tex | ||
18 | material.tex.env.push(arrayPeek(material.shader).envMap); | ||
19 | material.tex.envDiff.push(arrayPeek(material.shader).envDiff); | ||
20 | |||
21 | gl.useProgram(arrayPeek(material.shader).shaderHandle); | ||
22 | |||
23 | arrayPeek(material.renderObj).addTexture("layerMap1", 0, UNIFORMTYPE.TEXTURE2D); | ||
24 | arrayPeek(material.renderObj).addTexture("layerMap2", 1, UNIFORMTYPE.TEXTURE2D); | ||
25 | arrayPeek(material.renderObj).addTexture("colorMeMap1", 2, UNIFORMTYPE.TEXTURE2D); | ||
26 | arrayPeek(material.renderObj).addTexture("colorMeMap2", 3, UNIFORMTYPE.TEXTURE2D); | ||
27 | arrayPeek(material.renderObj).addTexture("envMap", 4, UNIFORMTYPE.TEXTURE2D); | ||
28 | arrayPeek(material.renderObj).addTexture("envDiff", 5, UNIFORMTYPE.TEXTURE2D); | ||
29 | |||
30 | arrayPeek(material.renderObj).addTexture("normalMap1", 15, UNIFORMTYPE.TEXTURE2D); | ||
31 | arrayPeek(material.renderObj).addTexture("normalMap2", 6, UNIFORMTYPE.TEXTURE2D); | ||
32 | |||
33 | arrayPeek(material.renderObj).addTexture("stickerMap0", 7, UNIFORMTYPE.TEXTURE2D); | ||
34 | arrayPeek(material.renderObj).addTexture("stickerMap1", 8, UNIFORMTYPE.TEXTURE2D); | ||
35 | arrayPeek(material.renderObj).addTexture("stickerMap2", 9, UNIFORMTYPE.TEXTURE2D); | ||
36 | arrayPeek(material.renderObj).addTexture("stickerMap3", 10, UNIFORMTYPE.TEXTURE2D); | ||
37 | arrayPeek(material.renderObj).addTexture("stickerMap4", 11, UNIFORMTYPE.TEXTURE2D); | ||
38 | arrayPeek(material.renderObj).addTexture("stickerMap5", 12, UNIFORMTYPE.TEXTURE2D); | ||
39 | arrayPeek(material.renderObj).addTexture("stickerMap6", 13, UNIFORMTYPE.TEXTURE2D); | ||
40 | arrayPeek(material.renderObj).addTexture("stickerMap7", 14, UNIFORMTYPE.TEXTURE2D); | ||
41 | |||
42 | arrayPeek(material.renderObj).addUniform("u_normalMatrix", gl.normalMatrix, UNIFORMTYPE.MATRIX4); | ||
43 | arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, UNIFORMTYPE.MATRIX4); | ||
44 | arrayPeek(material.renderObj).addUniform("u_invMvMatrix", gl.invMvMatrix, UNIFORMTYPE.MATRIX4); | ||
45 | |||
46 | arrayPeek(material.renderObj).addUniform("u_stickerMatrix0", primSet.parentMesh.stickers[0], UNIFORMTYPE.MATRIX4); | ||
47 | arrayPeek(material.renderObj).addUniform("u_stickerMatrix1", primSet.parentMesh.stickers[1], UNIFORMTYPE.MATRIX4); | ||
48 | arrayPeek(material.renderObj).addUniform("u_stickerMatrix2", primSet.parentMesh.stickers[2], UNIFORMTYPE.MATRIX4); | ||
49 | arrayPeek(material.renderObj).addUniform("u_stickerMatrix3", primSet.parentMesh.stickers[3], UNIFORMTYPE.MATRIX4); | ||
50 | arrayPeek(material.renderObj).addUniform("u_stickerMatrix4", primSet.parentMesh.stickers[4], UNIFORMTYPE.MATRIX4); | ||
51 | arrayPeek(material.renderObj).addUniform("u_stickerMatrix5", primSet.parentMesh.stickers[5], UNIFORMTYPE.MATRIX4); | ||
52 | arrayPeek(material.renderObj).addUniform("u_stickerMatrix6", primSet.parentMesh.stickers[6], UNIFORMTYPE.MATRIX4); | ||
53 | arrayPeek(material.renderObj).addUniform("u_stickerMatrix7", primSet.parentMesh.stickers[7], UNIFORMTYPE.MATRIX4); | ||
54 | |||
55 | arrayPeek(material.renderObj).addUniform("u_stickerPos0", primSet.parentMesh.stickersPos[0], UNIFORMTYPE.FLOAT3); | ||
56 | arrayPeek(material.renderObj).addUniform("u_stickerPos1", primSet.parentMesh.stickersPos[1], UNIFORMTYPE.FLOAT3); | ||
57 | arrayPeek(material.renderObj).addUniform("u_stickerPos2", primSet.parentMesh.stickersPos[2], UNIFORMTYPE.FLOAT3); | ||
58 | arrayPeek(material.renderObj).addUniform("u_stickerPos3", primSet.parentMesh.stickersPos[3], UNIFORMTYPE.FLOAT3); | ||
59 | arrayPeek(material.renderObj).addUniform("u_stickerPos4", primSet.parentMesh.stickersPos[4], UNIFORMTYPE.FLOAT3); | ||
60 | arrayPeek(material.renderObj).addUniform("u_stickerPos5", primSet.parentMesh.stickersPos[5], UNIFORMTYPE.FLOAT3); | ||
61 | arrayPeek(material.renderObj).addUniform("u_stickerPos6", primSet.parentMesh.stickersPos[6], UNIFORMTYPE.FLOAT3); | ||
62 | arrayPeek(material.renderObj).addUniform("u_stickerPos7", primSet.parentMesh.stickersPos[7], UNIFORMTYPE.FLOAT3); | ||
63 | |||
64 | |||
65 | arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, UNIFORMTYPE.MATRIX4); | ||
66 | |||
67 | arrayPeek(material.renderObj).addUniform("u_fillColor1", material.fillColor[0], UNIFORMTYPE.FLOAT4); | ||
68 | arrayPeek(material.renderObj).addUniform("u_fillColor2", material.fillColor[1], UNIFORMTYPE.FLOAT4); | ||
69 | arrayPeek(material.renderObj).addUniform("u_skinColor", material.fillColor[2], UNIFORMTYPE.FLOAT4); | ||
70 | |||
71 | |||
72 | // debug--- | ||
73 | vertexData.vertexObject.name = "vertexObject"; | ||
74 | vertexData.normalObject.name = "normalObject"; | ||
75 | vertexData.texCoordObject.name = "texCoordObject"; | ||
76 | vertexData.indexObject.name = "indexObject"; | ||
77 | //---------- | ||
78 | |||
79 | arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); | ||
80 | arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT); | ||
81 | arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); | ||
82 | arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER); | ||
83 | |||
84 | |||
85 | //} | ||
86 | |||
87 | gl.useProgram(null); | ||
88 | // gl.console.log("Mesh Init done!"); | ||
89 | |||
90 | } | ||
91 | |||
92 | function __renderInitScreenQuad(quad, shader) | ||
93 | { | ||
94 | if(shader == undefined) | ||
95 | { | ||
96 | quad.shader = createShader(gl, 'screenQuad_vShader', 'screenQuad_fShader', [ "vert", "texcoord"]); | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | quad.shader = shader; | ||
101 | } | ||
102 | |||
103 | quad.renderObj = new RenderObject(quad.shader); | ||
104 | |||
105 | quadBuf = getScreenAlignedQuad(); | ||
106 | |||
107 | quad.vertBuffer = quadBuf.vertexObject; | ||
108 | quad.uvBuffer = quadBuf.texCoordObject; | ||
109 | |||
110 | |||
111 | quad.renderObj.addTexture("basemap", 0, UNIFORMTYPE.TEXTURE2D); | ||
112 | |||
113 | var invWidth = (g_width == 0.0) ? 0.0 : 1.0/g_width, invHeight = (g_height == 0.0) ? 0.0 : 1.0/g_height; | ||
114 | quad.renderObj.addUniform("u_inv_viewport_width", invWidth, UNIFORMTYPE.FLOAT); | ||
115 | quad.renderObj.addUniform("u_inv_viewport_height", invHeight, UNIFORMTYPE.FLOAT); | ||
116 | |||
117 | quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); | ||
118 | quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); | ||
119 | } | ||
120 | |||
121 | function __renderInitProcDepthMap(renderObj) | ||
122 | { | ||
123 | renderObj.shader = g_depthShader.shaderHandle;//createShader(gl, depthMapVShader, depthMapFShader, [ "vert", "normal", "texcoord"]); | ||
124 | |||
125 | gl.useProgram(renderObj.shader); | ||
126 | |||
127 | renderObj.addUniform("u_mvpLightMatrix", g_mainLight.mvpMatrix, UNIFORMTYPE.MATRIX4); | ||
128 | //renderObj.addUniform("u_mvpLightMatrixWTF", g_mainLight.mvpMatrix, UNIFORMTYPE.MATRIX4); | ||
129 | // var uni = gl.getUniformLocation(renderObj.shader, "u_mvpLightMatrixWTF"); | ||
130 | // renderObj.addUniform("u_WTF1", g_lightMat[0], UNIFORMTYPE.FLOAT4); | ||
131 | // renderObj.addUniform("u_WTF2", g_lightMat[1], UNIFORMTYPE.FLOAT4); | ||
132 | // renderObj.addUniform("u_WTF3", g_lightMat[2], UNIFORMTYPE.FLOAT4); | ||
133 | // renderObj.addUniform("u_WTF4", g_lightMat[3], UNIFORMTYPE.FLOAT4); | ||
134 | // | ||
135 | // since the uniform data references should not change we can just bind one time | ||
136 | renderObj.bindUniforms(); | ||
137 | |||
138 | gl.useProgram(null); | ||
139 | } | ||
140 | |||
141 | function __renderInitShadowReceiver(primSet, vertexData) | ||
142 | { | ||
143 | // setup passes | ||
144 | primSet.shadowTarget = g_texMan.loadRenderTarget("shadowTarget", 256, 256); | ||
145 | primSet.shadowTargetFinal = g_texMan.loadRenderTarget("shadowTargetFinal", 256, 256); | ||
146 | primSet.screenQuad = new ScreenQuad(primSet.shadowTargetFinal); | ||
147 | primSet.screenQuad.initialize(__renderInitRadialBlur); | ||
148 | |||
149 | // set the target as the shadow to get projcetd | ||
150 | primSet.parentMesh.shadowToProject = primSet.shadowTarget; | ||
151 | |||
152 | //mainSceneQuad = new ScreenQuad(primSet.shadowTarget); | ||
153 | //mainSceneQuad.initialize(renderInitScreenQuad); | ||
154 | |||
155 | var material = primSet.material; | ||
156 | |||
157 | //push envMap tex | ||
158 | material.tex.env.push(arrayPeek(material.shader).envMap); | ||
159 | material.tex.envDiff.push(arrayPeek(material.shader).envDiff); | ||
160 | |||
161 | gl.useProgram(arrayPeek(material.shader).shaderHandle); | ||
162 | |||
163 | arrayPeek(material.renderObj).addTexture("shadowMap", 0, UNIFORMTYPE.TEXTURE2D); | ||
164 | arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, UNIFORMTYPE.MATRIX4); | ||
165 | |||
166 | arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, UNIFORMTYPE.MATRIX4); | ||
167 | |||
168 | arrayPeek(material.renderObj).addUniform("u_shadowBiasMatrix", g_mainLight.shadowMatrix, UNIFORMTYPE.MATRIX4); | ||
169 | arrayPeek(material.renderObj).addUniform("u_vShadowLight", g_mainLight.view, UNIFORMTYPE.MATRIX4); | ||
170 | |||
171 | |||
172 | // debug--- | ||
173 | vertexData.vertexObject.name = "vertexObject"; | ||
174 | vertexData.normalObject.name = "normalObject"; | ||
175 | vertexData.texCoordObject.name = "texCoordObject"; | ||
176 | vertexData.indexObject.name = "indexObject"; | ||
177 | //---------- | ||
178 | |||
179 | arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); | ||
180 | arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT); | ||
181 | arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); | ||
182 | arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER); | ||
183 | |||
184 | |||
185 | //} | ||
186 | |||
187 | gl.useProgram(null); | ||
188 | // gl.console.log("Mesh Init done!"); | ||
189 | |||
190 | //__renderInitShadowProjection(primSet, vertexData); | ||
191 | |||
192 | } | ||
193 | |||
194 | |||
195 | function __renderInitShadowProjection(primSet, vertexData) | ||
196 | { | ||
197 | var material = primSet.material; | ||
198 | |||
199 | //push envMap tex | ||
200 | //material.tex.env.push(arrayPeek(material.shader).envMap); | ||
201 | //material.tex.envDiff.push(arrayPeek(material.shader).envDiff); | ||