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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
</copyright> */
// RDGE namespaces
var RDGE = RDGE || {};
RDGE.renderInitProcDefault = function (primSet, vertexData) {
var material = primSet.material;
//push envMap tex
material.tex.env.push(arrayPeek(material.shader).envMap);
material.tex.envDiff.push(arrayPeek(material.shader).envDiff);
gl.useProgram(arrayPeek(material.shader).shaderHandle);
arrayPeek(material.renderObj).addTexture("layerMap1", 0, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("layerMap2", 1, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("colorMeMap1", 2, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("colorMeMap2", 3, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("envMap", 4, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("envDiff", 5, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("normalMap1", 15, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("normalMap2", 6, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("stickerMap0", 7, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("stickerMap1", 8, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("stickerMap2", 9, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("stickerMap3", 10, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("stickerMap4", 11, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("stickerMap5", 12, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("stickerMap6", 13, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addTexture("stickerMap7", 14, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addUniform("u_normalMatrix", gl.normalMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_invMvMatrix", gl.invMvMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerMatrix0", primSet.parentMesh.stickers[0], RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerMatrix1", primSet.parentMesh.stickers[1], RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerMatrix2", primSet.parentMesh.stickers[2], RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerMatrix3", primSet.parentMesh.stickers[3], RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerMatrix4", primSet.parentMesh.stickers[4], RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerMatrix5", primSet.parentMesh.stickers[5], RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerMatrix6", primSet.parentMesh.stickers[6], RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerMatrix7", primSet.parentMesh.stickers[7], RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_stickerPos0", primSet.parentMesh.stickersPos[0], RDGE.UNIFORMTYPE.FLOAT3);
arrayPeek(material.renderObj).addUniform("u_stickerPos1", primSet.parentMesh.stickersPos[1], RDGE.UNIFORMTYPE.FLOAT3);
arrayPeek(material.renderObj).addUniform("u_stickerPos2", primSet.parentMesh.stickersPos[2], RDGE.UNIFORMTYPE.FLOAT3);
arrayPeek(material.renderObj).addUniform("u_stickerPos3", primSet.parentMesh.stickersPos[3], RDGE.UNIFORMTYPE.FLOAT3);
arrayPeek(material.renderObj).addUniform("u_stickerPos4", primSet.parentMesh.stickersPos[4], RDGE.UNIFORMTYPE.FLOAT3);
arrayPeek(material.renderObj).addUniform("u_stickerPos5", primSet.parentMesh.stickersPos[5], RDGE.UNIFORMTYPE.FLOAT3);
arrayPeek(material.renderObj).addUniform("u_stickerPos6", primSet.parentMesh.stickersPos[6], RDGE.UNIFORMTYPE.FLOAT3);
arrayPeek(material.renderObj).addUniform("u_stickerPos7", primSet.parentMesh.stickersPos[7], RDGE.UNIFORMTYPE.FLOAT3);
arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_fillColor1", material.fillColor[0], RDGE.UNIFORMTYPE.FLOAT4);
arrayPeek(material.renderObj).addUniform("u_fillColor2", material.fillColor[1], RDGE.UNIFORMTYPE.FLOAT4);
arrayPeek(material.renderObj).addUniform("u_skinColor", material.fillColor[2], RDGE.UNIFORMTYPE.FLOAT4);
// debug---
vertexData.vertexObject.name = "vertexObject";
vertexData.normalObject.name = "normalObject";
vertexData.texCoordObject.name = "texCoordObject";
vertexData.indexObject.name = "indexObject";
//----------
arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER);
gl.useProgram(null);
// gl.console.log("Mesh Init done!");
};
RDGE.renderInitScreenQuad = function (quad, shader) {
if (shader == undefined) {
quad.shader = RDGE.createShader(gl, 'screenQuad_vShader', 'screenQuad_fShader', ["vert", "texcoord"]);
}
else {
quad.shader = shader;
}
quad.renderObj = new RDGE.RenderObject(quad.shader);
quadBuf = getScreenAlignedQuad();
quad.vertBuffer = quadBuf.vertexObject;
quad.uvBuffer = quadBuf.texCoordObject;
quad.renderObj.addTexture("basemap", 0, RDGE.UNIFORMTYPE.TEXTURE2D);
var invWidth = (RDGE.globals.width == 0.0) ? 0.0 : 1.0 / RDGE.globals.width, invHeight = (RDGE.globals.height == 0.0) ? 0.0 : 1.0 / RDGE.globals.height;
quad.renderObj.addUniform("u_inv_viewport_width", invWidth, RDGE.UNIFORMTYPE.FLOAT);
quad.renderObj.addUniform("u_inv_viewport_height", invHeight, RDGE.UNIFORMTYPE.FLOAT);
quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT);
quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT);
};
RDGE.renderInitProcDepthMap = function (renderObj) {
renderObj.shader = g_depthShader.shaderHandle; //RDGE.createShader(gl, depthMapVShader, depthMapFShader, [ "vert", "normal", "texcoord"]);
gl.useProgram(renderObj.shader);
renderObj.addUniform("u_mvpLightMatrix", g_mainLight.mvpMatrix, RDGE.UNIFORMTYPE.MATRIX4);
//renderObj.addUniform("u_mvpLightMatrixWTF", g_mainLight.mvpMatrix, RDGE.UNIFORMTYPE.MATRIX4);
// var uni = gl.getUniformLocation(renderObj.shader, "u_mvpLightMatrixWTF");
// renderObj.addUniform("u_WTF1", g_lightMat[0], RDGE.UNIFORMTYPE.FLOAT4);
// renderObj.addUniform("u_WTF2", g_lightMat[1], RDGE.UNIFORMTYPE.FLOAT4);
// renderObj.addUniform("u_WTF3", g_lightMat[2], RDGE.UNIFORMTYPE.FLOAT4);
// renderObj.addUniform("u_WTF4", g_lightMat[3], RDGE.UNIFORMTYPE.FLOAT4);
//
// since the uniform data references should not change we can just bind one time
renderObj.bindUniforms();
gl.useProgram(null);
};
RDGE.renderInitShadowReceiver = function (primSet, vertexData) {
// setup passes
primSet.shadowTarget = g_texMan.loadRenderTarget("shadowTarget", 256, 256);
primSet.shadowTargetFinal = g_texMan.loadRenderTarget("shadowTargetFinal", 256, 256);
primSet.screenQuad = new RDGE.ScreenQuad(primSet.shadowTargetFinal);
primSet.screenQuad.initialize(RDGE.renderInitRadialBlur);
// set the target as the shadow to get projcetd
primSet.parentMesh.shadowToProject = primSet.shadowTarget;
//mainSceneQuad = new RDGE.ScreenQuad(primSet.shadowTarget);
//mainSceneQuad.initialize(renderInitScreenQuad);
var material = primSet.material;
//push envMap tex
material.tex.env.push(arrayPeek(material.shader).envMap);
material.tex.envDiff.push(arrayPeek(material.shader).envDiff);
gl.useProgram(arrayPeek(material.shader).shaderHandle);
arrayPeek(material.renderObj).addTexture("shadowMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_shadowBiasMatrix", g_mainLight.shadowMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_vShadowLight", g_mainLight.view, RDGE.UNIFORMTYPE.MATRIX4);
// debug---
vertexData.vertexObject.name = "vertexObject";
vertexData.normalObject.name = "normalObject";
vertexData.texCoordObject.name = "texCoordObject";
vertexData.indexObject.name = "indexObject";
//----------
arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER);
gl.useProgram(null);
//RDGE.renderInitShadowProjection(primSet, vertexData);
};
RDGE.renderInitShadowProjection = function (primSet, vertexData) {
var material = primSet.material;
//push envMap tex
//material.tex.env.push(arrayPeek(material.shader).envMap);
//material.tex.envDiff.push(arrayPeek(material.shader).envDiff);
gl.useProgram(arrayPeek(material.shader).shaderHandle);
arrayPeek(material.renderObj).addTexture("shadowMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D);
arrayPeek(material.renderObj).addUniform("u_mvMatrix", gl.mvMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_projMatrix", gl.perspectiveMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_shadowBiasMatrix", g_mainLight.shadowMatrix, RDGE.UNIFORMTYPE.MATRIX4);
arrayPeek(material.renderObj).addUniform("u_vShadowLight", g_mainLight.view, RDGE.UNIFORMTYPE.MATRIX4);
// debug---
vertexData.vertexObject.name = "vertexObject";
vertexData.normalObject.name = "normalObject";
vertexData.texCoordObject.name = "texCoordObject";
vertexData.indexObject.name = "indexObject";
//----------
arrayPeek(material.renderObj).addBuffers(vertexData.vertexObject, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.normalObject, gl.ARRAY_BUFFER, 3, 1, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.texCoordObject, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT);
arrayPeek(material.renderObj).addBuffers(vertexData.indexObject, gl.ELEMENT_ARRAY_BUFFER);
gl.useProgram(null);
};
RDGE.renderInitRadialBlur = function(quad, shader) {
if (shader == undefined) {
quad.shader = RDGE.createShader(gl, 'radialBlur_vshader', 'radialBlur_fshader', ["vert", "texcoord"]);
}
else {
quad.shader = shader;
}
quad.renderObj = new RDGE.RenderObject(quad.shader);
quadBuf = getScreenAlignedQuad();
quad.vertBuffer = quadBuf.vertexObject;
quad.uvBuffer = quadBuf.texCoordObject;
quad.renderObj.addTexture("basemap", 0, RDGE.UNIFORMTYPE.TEXTURE2D);
quad.renderObj.addUniform("u_inv_viewport_width", 1.0 / RDGE.globals.width, RDGE.UNIFORMTYPE.FLOAT);
quad.renderObj.addUniform("u_inv_viewport_height", 1.0 / RDGE.globals.height, RDGE.UNIFORMTYPE.FLOAT);
quad.renderObj.addUniform("u_sampRadius", 5.0, RDGE.UNIFORMTYPE.FLOAT);
quad.renderObj.addUniform("u_numSamples", 16, RDGE.UNIFORMTYPE.INT);
quad.renderObj.addUniform("u_mapSize", 256.0, RDGE.UNIFORMTYPE.FLOAT);
quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT);
quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT);
};
|