aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/fx/ssao.js
diff options
context:
space:
mode:
authorKris Kowal2012-07-06 12:34:53 -0700
committerKris Kowal2012-07-06 15:01:48 -0700
commit3644cb6def4f681c99959e5729e78ea353441fad (patch)
treef8a886f4829e507cc4956db37cff2580cae6003d /js/helper-classes/RDGE/src/core/script/fx/ssao.js
parent04343eda8c2f870b0da55cfdc8003c99fe1cc4de (diff)
downloadninja-3644cb6def4f681c99959e5729e78ea353441fad.tar.gz
Normalize to unix line terminators
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/fx/ssao.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/fx/ssao.js278
1 files changed, 139 insertions, 139 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 39abf523..fc72c817 100755
--- a/js/helper-classes/RDGE/src/core/script/fx/ssao.js
+++ b/js/helper-classes/RDGE/src/core/script/fx/ssao.js
@@ -1,139 +1,139 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility, Inc
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4BSD License.
5 5
6Redistribution and use in source and binary forms, with or without 6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 7modification, are permitted provided that the following conditions are met:
8 8
9 - Redistributions of source code must retain the above copyright notice, 9 - Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 10 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the 12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution. 13 documentation and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors 14 - Neither the name of Motorola Mobility nor the names of its contributors
15 may be used to endorse or promote products derived from this software 15 may be used to endorse or promote products derived from this software
16 without specific prior written permission. 16 without specific prior written permission.
17 17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE. 28POSSIBILITY OF SUCH DAMAGE.
29</copyright> */ 29</copyright> */
30 30
31var RDGE = RDGE || {}; 31var RDGE = RDGE || {};
32RDGE.fx = RDGE.fx || {}; 32RDGE.fx = RDGE.fx || {};
33 33
34/** 34/**
35* Implements SSAO. 35* Implements SSAO.
36* See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 36* See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753
37* @param v2ScreenSize - size of the viewport in window coordinates 37* @param v2ScreenSize - size of the viewport in window coordinates
38*/ 38*/
39RDGE.fx.fxSSAO = function (enHRDepth) { 39RDGE.fx.fxSSAO = function (enHRDepth) {
40 function renderInitSSAO(quad) { 40 function renderInitSSAO(quad) {
41 quad.shader = RDGE.createShader(RDGE.globals.gl, 'ssao_vshader', enHRDepth ? 'ssaohr_fshader' : 'ssao_fshader', ["vert", "texcoord"]); 41 quad.shader = RDGE.createShader(RDGE.globals.gl, 'ssao_vshader', enHRDepth ? 'ssaohr_fshader' : 'ssao_fshader', ["vert", "texcoord"]);
42 quad.renderObj = new RDGE.RenderObject(quad.shader); 42 quad.renderObj = new RDGE.RenderObject(quad.shader);
43 43
44 var quadBuf = getScreenAlignedQuad(); 44 var quadBuf = getScreenAlignedQuad();
45 quad.vertBuffer = quadBuf.vertexObject; 45 quad.vertBuffer = quadBuf.vertexObject;
46 quad.uvBuffer = quadBuf.texCoordObject; 46 quad.uvBuffer = quadBuf.texCoordObject;
47 47
48 quad.renderObj.addTexture("sColMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D); 48 quad.renderObj.addTexture("sColMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D);
49 quad.renderObj.addTexture("sNormDepthMap", 1, RDGE.UNIFORMTYPE.TEXTURE2D); 49 quad.renderObj.addTexture("sNormDepthMap", 1, RDGE.UNIFORMTYPE.TEXTURE2D);
50 quad.renderObj.addTexture("sRandMap", 2, RDGE.UNIFORMTYPE.TEXTURE2D); 50 quad.renderObj.addTexture("sRandMap", 2, RDGE.UNIFORMTYPE.TEXTURE2D);
51 if (enHRDepth) 51 if (enHRDepth)
52 quad.renderObj.addTexture("sHRDepthMap", 3, RDGE.UNIFORMTYPE.TEXTURE2D); 52 quad.renderObj.addTexture("sHRDepthMap", 3, RDGE.UNIFORMTYPE.TEXTURE2D);
53 53
54 quad.renderObj.addBuffers(quad.vertBuffer, RDGE.globals.gl.ARRAY_BUFFER, 3, 0, RDGE.globals.gl.FLOAT); 54 quad.renderObj.addBuffers(quad.vertBuffer, RDGE.globals.gl.ARRAY_BUFFER, 3, 0, RDGE.globals.gl.FLOAT);
55 quad.renderObj.addBuffers(quad.uvBuffer, RDGE.globals.gl.ARRAY_BUFFER, 2, 2, RDGE.globals.gl.FLOAT); 55 quad.renderObj.addBuffers(quad.uvBuffer, RDGE.globals.gl.ARRAY_BUFFER, 2, 2, RDGE.globals.gl.FLOAT);
56 }; 56 };
57 57
58 // Load random normal texture 58 // Load random normal texture
59 this.randTexture = createTexture(RDGE.globals.gl, RDGE.globals.engine._assetPath + "images/random_normal.png"); 59 this.randTexture = createTexture(RDGE.globals.gl, RDGE.globals.engine._assetPath + "images/random_normal.png");
60 RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, this.randTexture); 60 RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, this.randTexture);
61 RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_MIN_FILTER, RDGE.globals.gl.LINEAR); 61 RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_MIN_FILTER, RDGE.globals.gl.LINEAR);
62 RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_S, RDGE.globals.gl.REPEAT); 62 RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_S, RDGE.globals.gl.REPEAT);
63 RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_T, RDGE.globals.gl.REPEAT); 63 RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_T, RDGE.globals.gl.REPEAT);
64 64
65 // Whether or not to use a high res depth texture 65 // Whether or not to use a high res depth texture
66 this.enHRDepth = enHRDepth; 66 this.enHRDepth = enHRDepth;
67 67
68 // Quad for full screen pass 68 // Quad for full screen pass
69 this.ssaoQuad = new RDGE.ScreenQuad(null); 69 this.ssaoQuad = new RDGE.ScreenQuad(null);
70 this.ssaoQuad.initialize(renderInitSSAO); 70 this.ssaoQuad.initialize(renderInitSSAO);
71 71
72 // Set up uniforms 72 // Set up uniforms
73 var activeCam = g_cameraManager.getActiveCamera(); 73 var activeCam = g_cameraManager.getActiveCamera();
74 this.v3FrustumFLT = activeCam.getFTR(); 74 this.v3FrustumFLT = activeCam.getFTR();
75 this.ssaoQuad.renderObj.addUniform("u_frustumFLT", this.v3FrustumFLT, RDGE.UNIFORMTYPE.FLOAT3); 75 this.ssaoQuad.renderObj.addUniform("u_frustumFLT", this.v3FrustumFLT, RDGE.UNIFORMTYPE.FLOAT3);
76 76
77 this.v4ArtVals = [1.0, 1.0, 1.0, 1.0]; 77 this.v4ArtVals = [1.0, 1.0, 1.0, 1.0];
78 this.ssaoQuad.renderObj.addUniform("u_artVals", this.v4ArtVals, RDGE.UNIFORMTYPE.FLOAT4); 78 this.ssaoQuad.renderObj.addUniform("u_artVals", this.v4ArtVals, RDGE.UNIFORMTYPE.FLOAT4);
79 79
80 this.fRandMapSize = 64.0; 80 this.fRandMapSize = 64.0;
81 this.ssaoQuad.renderObj.addUniform("u_randMapSize", this.fRandMapSize, RDGE.UNIFORMTYPE.FLOAT); 81 this.ssaoQuad.renderObj.addUniform("u_randMapSize", this.fRandMapSize, RDGE.UNIFORMTYPE.FLOAT);
82 82
83 this.v2ScreenSize = [1024, 1024]; 83 this.v2ScreenSize = [1024, 1024];
84 this.ssaoQuad.renderObj.addUniform("u_screenSize", this.v2ScreenSize, RDGE.UNIFORMTYPE.FLOAT2); 84 this.ssaoQuad.renderObj.addUniform("u_screenSize", this.v2ScreenSize, RDGE.UNIFORMTYPE.FLOAT2);
85}; 85};
86 86
87/** 87/**
88* Contributes SSAO to the passed offscreen surface, rendering to another surface. 88* Contributes SSAO to the passed offscreen surface, rendering to another surface.
89* See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 89* See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753
90* @param srcTexColor - color surface of rendered scene 90* @param srcTexColor - color surface of rendered scene
91* @param srcTexNormDepth - screenspace normal+depth surface for scene; {nx, ny, nz, depth} 91* @param srcTexNormDepth - screenspace normal+depth surface for scene; {nx, ny, nz, depth}
92* @param dstRenderTarget - where to put the result of SSAO 92* @param dstRenderTarget - where to put the result of SSAO
93* @param sampleRadius - 93* @param sampleRadius -
94* @param intensity - 94* @param intensity -
95* @param distScale - 95* @param distScale -
96* @param bias - 96* @param bias -
97*/ 97*/
98RDGE.fx.fxSSAO.prototype.doSSAO = function (srcTexColor, srcTexNormDepth, srcTexHRDepth, dstRenderTarget, sampleRadius, intensity, distScale, bias) { 98RDGE.fx.fxSSAO.prototype.doSSAO = function (srcTexColor, srcTexNormDepth, srcTexHRDepth, dstRenderTarget, sampleRadius, intensity, distScale, bias) {
99 // Set art params and other uniforms 99 // Set art params and other uniforms
100 this.v4ArtVals[0] = sampleRadius; 100 this.v4ArtVals[0] = sampleRadius;
101 this.v4ArtVals[1] = intensity; 101 this.v4ArtVals[1] = intensity;
102 this.v4ArtVals[2] = distScale; 102 this.v4ArtVals[2] = distScale;
103 this.v4ArtVals[3] = bias; 103 this.v4ArtVals[3] = bias;
104 104
105 this.v2ScreenSize[0] = dstRenderTarget ? dstRenderTarget.frameBuffer.width : RDGE.globals.width; 105 this.v2ScreenSize[0] = dstRenderTarget ? dstRenderTarget.frameBuffer.width : RDGE.globals.width;
106 this.v2ScreenSize[1] = dstRenderTarget ? dstRenderTarget.frameBuffer.height : RDGE.globals.height; 106 this.v2ScreenSize[1] = dstRenderTarget ? dstRenderTarget.frameBuffer.height : RDGE.globals.height;
107 107
108 // Do ssao 108 // Do ssao
109 RDGE.globals.gl.bindFramebuffer(RDGE.globals.gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null); 109 RDGE.globals.gl.bindFramebuffer(RDGE.globals.gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null);
110 // gl.viewport(0, 0, 99999, 99999); 110 // gl.viewport(0, 0, 99999, 99999);
111 RDGE.globals.gl.clear(RDGE.globals.gl.COLOR_BUFFER_BIT); 111 RDGE.globals.gl.clear(RDGE.globals.gl.COLOR_BUFFER_BIT);
112 112
113 RDGE.globals.gl.disable(RDGE.globals.gl.DEPTH_TEST); 113 RDGE.globals.gl.disable(RDGE.globals.gl.DEPTH_TEST);
114 114
115 RDGE.globals.gl.useProgram(this.ssaoQuad.shader); 115 RDGE.globals.gl.useProgram(this.ssaoQuad.shader);
116 116
117 this.ssaoQuad.renderObj.bindBuffers(); 117 this.ssaoQuad.renderObj.bindBuffers();
118 this.ssaoQuad.renderObj.bindTextures(); 118 this.ssaoQuad.renderObj.bindTextures();
119 this.ssaoQuad.renderObj.bindUniforms(); 119 this.ssaoQuad.renderObj.bindUniforms();