diff options
author | Nivesh Rajbhandari | 2012-04-04 17:24:27 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-04 17:24:27 -0700 |
commit | 01cf259da7aaa7d70789d9a7c32111d88b477463 (patch) | |
tree | 0bff3395ac681e5f685d2267f7dbc03a8e32bc4a /js/helper-classes/RDGE/src/core/script/fx/ssao.js | |
parent | 331ea08655245e3532e48bf160d5f68a04d8723f (diff) | |
parent | 13368ca6ebbc13adeafccd898dfffd7ce37cb28a (diff) | |
download | ninja-01cf259da7aaa7d70789d9a7c32111d88b477463.tar.gz |
Merge branch 'refs/heads/ToolFixes' into WebGLMaterials
Conflicts:
js/document/templates/montage-html/default_html.css
js/mediators/element-mediator.js
js/panels/properties.reel/properties.js
js/tools/BrushTool.js
js/tools/LineTool.js
js/tools/PenTool.js
js/tools/SelectionTool.js
js/tools/ShapeTool.js
js/tools/TranslateObject3DTool.js
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/fx/ssao.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/fx/ssao.js | 211 |
1 files changed, 105 insertions, 106 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/fx/ssao.js b/js/helper-classes/RDGE/src/core/script/fx/ssao.js index 9761b02d..2f96aa5b 100755 --- a/js/helper-classes/RDGE/src/core/script/fx/ssao.js +++ b/js/helper-classes/RDGE/src/core/script/fx/ssao.js | |||
@@ -4,113 +4,112 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var RDGE = RDGE || {}; | ||
8 | RDGE.fx = RDGE.fx || {}; | ||
7 | 9 | ||
8 | /** | 10 | /** |
9 | * Implements SSAO. | 11 | * Implements SSAO. |
10 | * See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 | 12 | * See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 |
11 | * @param v2ScreenSize - size of the viewport in window coordinates | 13 | * @param v2ScreenSize - size of the viewport in window coordinates |
12 | */ | 14 | */ |
13 | function fxSSAO(enHRDepth) | 15 | RDGE.fx.fxSSAO = function (enHRDepth) { |
14 | { | 16 | function renderInitSSAO(quad) { |
15 | function renderInitSSAO(quad) | 17 | quad.shader = RDGE.createShader(RDGE.globals.gl, 'ssao_vshader', enHRDepth ? 'ssaohr_fshader' : 'ssao_fshader', ["vert", "texcoord"]); |
16 | { | 18 | quad.renderObj = new RDGE.RenderObject(quad.shader); |
17 | quad.shader = createShader(gl, 'ssao_vshader', enHRDepth ? 'ssaohr_fshader' : 'ssao_fshader', [ "vert", "texcoord"]); | 19 | |
18 | quad.renderObj = new RenderObject(quad.shader); | 20 | var quadBuf = getScreenAlignedQuad(); |
19 | 21 | quad.vertBuffer = quadBuf.vertexObject; | |
20 | var quadBuf = getScreenAlignedQuad(); | 22 | quad.uvBuffer = quadBuf.texCoordObject; |
21 | quad.vertBuffer = quadBuf.vertexObject; | 23 | |
22 | quad.uvBuffer = quadBuf.texCoordObject; | 24 | quad.renderObj.addTexture("sColMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D); |
23 | 25 | quad.renderObj.addTexture("sNormDepthMap", 1, RDGE.UNIFORMTYPE.TEXTURE2D); | |
24 | quad.renderObj.addTexture("sColMap", 0, UNIFORMTYPE.TEXTURE2D); | 26 | quad.renderObj.addTexture("sRandMap", 2, RDGE.UNIFORMTYPE.TEXTURE2D); |
25 | quad.renderObj.addTexture("sNormDepthMap", 1, UNIFORMTYPE.TEXTURE2D); | 27 | if (enHRDepth) |
26 | quad.renderObj.addTexture("sRandMap", 2, UNIFORMTYPE.TEXTURE2D); | 28 | quad.renderObj.addTexture("sHRDepthMap", 3, RDGE.UNIFORMTYPE.TEXTURE2D); |
27 | if (enHRDepth) | 29 | |
28 | quad.renderObj.addTexture("sHRDepthMap", 3, UNIFORMTYPE.TEXTURE2D); | 30 | quad.renderObj.addBuffers(quad.vertBuffer, RDGE.globals.gl.ARRAY_BUFFER, 3, 0, RDGE.globals.gl.FLOAT); |
29 | 31 | quad.renderObj.addBuffers(quad.uvBuffer, RDGE.globals.gl.ARRAY_BUFFER, 2, 2, RDGE.globals.gl.FLOAT); | |
30 | quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); | 32 | }; |
31 | quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); | 33 | |
32 | } | 34 | // Load random normal texture |
33 | 35 | this.randTexture = createTexture(RDGE.globals.gl, RDGE.globals.engine._assetPath + "images/random_normal.png"); | |
34 | // Load random normal texture | 36 | RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, this.randTexture); |
35 | this.randTexture = createTexture(gl, g_Engine._assetPath+"images/random_normal.png"); | 37 | RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_MIN_FILTER, RDGE.globals.gl.LINEAR); |
36 | gl.bindTexture(gl.TEXTURE_2D, this.randTexture); | 38 | RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_S, RDGE.globals.gl.REPEAT); |
37 | gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR); | 39 | RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_T, RDGE.globals.gl.REPEAT); |
38 | gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.REPEAT); | 40 | |
39 | gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.REPEAT); | 41 | // Whether or not to use a high res depth texture |
40 | 42 | this.enHRDepth = enHRDepth; | |
41 | // Whether or not to use a high res depth texture | 43 | |
42 | this.enHRDepth = enHRDepth; | 44 | // Quad for full screen pass |
43 | 45 | this.ssaoQuad = new RDGE.ScreenQuad(null); | |
44 | // Quad for full screen pass | 46 | this.ssaoQuad.initialize(renderInitSSAO); |
45 | this.ssaoQuad = new ScreenQuad(null); | 47 | |
46 | this.ssaoQuad.initialize(renderInitSSAO); | 48 | // Set up uniforms |
47 | 49 | var activeCam = g_cameraManager.getActiveCamera(); | |
48 | // Set up uniforms | 50 | this.v3FrustumFLT = activeCam.getFTR(); |
49 | var activeCam = g_cameraManager.getActiveCamera(); | 51 | this.ssaoQuad.renderObj.addUniform("u_frustumFLT", this.v3FrustumFLT, RDGE.UNIFORMTYPE.FLOAT3); |
50 | this.v3FrustumFLT = activeCam.getFTR(); | 52 | |
51 | this.ssaoQuad.renderObj.addUniform("u_frustumFLT", this.v3FrustumFLT, UNIFORMTYPE.FLOAT3); | 53 | this.v4ArtVals = [1.0, 1.0, 1.0, 1.0]; |
52 | 54 | this.ssaoQuad.renderObj.addUniform("u_artVals", this.v4ArtVals, RDGE.UNIFORMTYPE.FLOAT4); | |
53 | this.v4ArtVals = [1.0, 1.0, 1.0, 1.0]; | 55 | |
54 | this.ssaoQuad.renderObj.addUniform("u_artVals", this.v4ArtVals, UNIFORMTYPE.FLOAT4); | 56 | this.fRandMapSize = 64.0; |
55 | 57 | this.ssaoQuad.renderObj.addUniform("u_randMapSize", this.fRandMapSize, RDGE.UNIFORMTYPE.FLOAT); | |
56 | this.fRandMapSize = 64.0; | 58 | |
57 | this.ssaoQuad.renderObj.addUniform("u_randMapSize", this.fRandMapSize, UNIFORMTYPE.FLOAT); | 59 | this.v2ScreenSize = [1024, 1024]; |
58 | 60 | this.ssaoQuad.renderObj.addUniform("u_screenSize", this.v2ScreenSize, RDGE.UNIFORMTYPE.FLOAT2); | |
59 | this.v2ScreenSize = [1024, 1024]; | 61 | }; |
60 | this.ssaoQuad.renderObj.addUniform("u_screenSize", this.v2ScreenSize, UNIFORMTYPE.FLOAT2); | ||
61 | } | ||
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Contributes SSAO to the passed offscreen surface, rendering to another surface. | 64 | * Contributes SSAO to the passed offscreen surface, rendering to another surface. |
65 | * See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 | 65 | * See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 |
66 | * @param srcTexColor - color surface of rendered scene | 66 | * @param srcTexColor - color surface of rendered scene |
67 | * @param srcTexNormDepth - screenspace normal+depth surface for scene; {nx, ny, nz, depth} | 67 | * @param srcTexNormDepth - screenspace normal+depth surface for scene; {nx, ny, nz, depth} |
68 | * @param dstRenderTarget - where to put the result of SSAO | 68 | * @param dstRenderTarget - where to put the result of SSAO |
69 | * @param sampleRadius - | 69 | * @param sampleRadius - |
70 | * @param intensity - | 70 | * @param intensity - |
71 | * @param distScale - | 71 | * @param distScale - |
72 | * @param bias - | 72 | * @param bias - |
73 | */ | 73 | */ |
74 | fxSSAO.prototype.doSSAO = function(srcTexColor, srcTexNormDepth, srcTexHRDepth, dstRenderTarget, sampleRadius, intensity, distScale, bias) | 74 | RDGE.fx.fxSSAO.prototype.doSSAO = function (srcTexColor, srcTexNormDepth, srcTexHRDepth, dstRenderTarget, sampleRadius, intensity, distScale, bias) { |
75 | { | 75 | // Set art params and other uniforms |
76 | // Set art params and other uniforms | 76 | this.v4ArtVals[0] = sampleRadius; |
77 | this.v4ArtVals[0] = sampleRadius; | 77 | this.v4ArtVals[1] = intensity; |
78 | this.v4ArtVals[1] = intensity; | 78 | this.v4ArtVals[2] = distScale; |
79 | this.v4ArtVals[2] = distScale; | 79 | this.v4ArtVals[3] = bias; |
80 | this.v4ArtVals[3] = bias; | 80 | |
81 | 81 | this.v2ScreenSize[0] = dstRenderTarget ? dstRenderTarget.frameBuffer.width : RDGE.globals.width; | |
82 | this.v2ScreenSize[0] = dstRenderTarget ? dstRenderTarget.frameBuffer.width : g_width; | 82 | this.v2ScreenSize[1] = dstRenderTarget ? dstRenderTarget.frameBuffer.height : RDGE.globals.height; |
83 | this.v2ScreenSize[1] = dstRenderTarget ? dstRenderTarget.frameBuffer.height : g_height; | 83 | |
84 | 84 | // Do ssao | |
85 | // Do ssao | 85 | RDGE.globals.gl.bindFramebuffer(RDGE.globals.gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null); |
86 | gl.bindFramebuffer(gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null); | 86 | // gl.viewport(0, 0, 99999, 99999); |
87 | // gl.viewport(0, 0, 99999, 99999); | 87 | RDGE.globals.gl.clear(RDGE.globals.gl.COLOR_BUFFER_BIT); |
88 | gl.clear(gl.COLOR_BUFFER_BIT); | 88 | |
89 | 89 | RDGE.globals.gl.disable(RDGE.globals.gl.DEPTH_TEST); | |
90 | gl.disable(gl.DEPTH_TEST); | 90 | |
91 | 91 | RDGE.globals.gl.useProgram(this.ssaoQuad.shader); | |
92 | gl.useProgram(this.ssaoQuad.shader); | 92 | |
93 | 93 | this.ssaoQuad.renderObj.bindBuffers(); | |
94 | this.ssaoQuad.renderObj.bindBuffers(); | 94 | this.ssaoQuad.renderObj.bindTextures(); |
95 | this.ssaoQuad.renderObj.bindTextures(); | 95 | this.ssaoQuad.renderObj.bindUniforms(); |
96 | this.ssaoQuad.renderObj.bindUniforms(); | 96 | |
97 | 97 | RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE0); | |
98 | gl.activeTexture(gl.TEXTURE0); | 98 | RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexColor); |
99 | gl.bindTexture(gl.TEXTURE_2D, srcTexColor); | 99 | RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE1); |
100 | gl.activeTexture(gl.TEXTURE1); | 100 | RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexNormDepth); |
101 | gl.bindTexture(gl.TEXTURE_2D, srcTexNormDepth); | 101 | RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE2); |
102 | gl.activeTexture(gl.TEXTURE2); | 102 | RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, this.randTexture); |
103 | gl.bindTexture(gl.TEXTURE_2D, this.randTexture); | 103 | if (this.enHRDepth) { |
104 | if (this.enHRDepth) { | 104 | RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE3); |
105 | gl.activeTexture(gl.TEXTURE3); | 105 | RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexHRDepth); |
106 | gl.bindTexture(gl.TEXTURE_2D, srcTexHRDepth); | 106 | } |
107 | } | 107 | RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE0); |
108 | gl.activeTexture(gl.TEXTURE0); | 108 | |
109 | 109 | RDGE.globals.gl.drawArrays(RDGE.globals.gl.TRIANGLES, 0, 6); | |
110 | gl.drawArrays(gl.TRIANGLES, 0, 6); | 110 | |
111 | 111 | RDGE.globals.gl.enable(RDGE.globals.gl.DEPTH_TEST); | |
112 | gl.enable(gl.DEPTH_TEST); | 112 | RDGE.globals.gl.useProgram(null); |
113 | gl.useProgram(null); | 113 | |
114 | 114 | return dstRenderTarget; | |
115 | return dstRenderTarget; | 115 | }; |
116 | } | ||