diff options
author | Valerio Virgillito | 2012-07-09 14:35:44 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-07-09 14:35:44 -0700 |
commit | 84b3327bd92faafab7954b5eb64c7abe24a3fe13 (patch) | |
tree | 3f56cbed2f08c5a81ea79eaf0bcb9bd031d8a627 /js/helper-classes/RDGE/src/core/script/fx/ssao.js | |
parent | c0a42c56f768a873ba637f5b86d5f6a84d4a3312 (diff) | |
parent | 40c6eb2c06b34f65a74d59ef9687251952858bab (diff) | |
download | ninja-84b3327bd92faafab7954b5eb64c7abe24a3fe13.tar.gz |
Merge branch 'normalize' of https://github.com/kriskowal/ninja-internal
Conflicts:
js/components/gradientpicker.reel/gradientpicker.js
js/components/tools-properties/text-properties.reel/text-properties.js
js/document/views/base.js
js/document/views/design.js
js/helper-classes/3D/StageLine.js
js/helper-classes/3D/draw-utils.js
js/lib/drawing/world.js
js/lib/geom/circle.js
js/lib/geom/line.js
js/lib/geom/rectangle.js
js/lib/geom/shape-primitive.js
js/lib/rdge/materials/bump-metal-material.js
js/lib/rdge/materials/flag-material.js
js/lib/rdge/materials/fly-material.js
js/lib/rdge/materials/julia-material.js
js/lib/rdge/materials/keleidoscope-material.js
js/lib/rdge/materials/mandel-material.js
js/lib/rdge/materials/material.js
js/lib/rdge/materials/plasma-material.js
js/lib/rdge/materials/pulse-material.js
js/lib/rdge/materials/radial-gradient-material.js
js/lib/rdge/materials/taper-material.js
js/lib/rdge/materials/twist-vert-material.js
js/lib/rdge/materials/water-material.js
js/panels/Materials/materials-library-panel.reel/materials-library-panel.html
js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
js/panels/Materials/materials-popup.reel/materials-popup.html
js/panels/Materials/materials-popup.reel/materials-popup.js
js/tools/LineTool.js
Signed-off-by: Valerio Virgillito <valerio@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 | 278 |
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 e88beef5..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> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | BSD License. |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 7 | modification, 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 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | 30 | ||
31 | var RDGE = RDGE || {}; | 31 | var RDGE = RDGE || {}; |
32 | RDGE.fx = RDGE.fx || {}; | 32 | RDGE.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 | */ |
39 | RDGE.fx.fxSSAO = function (enHRDepth) { | 39 | RDGE.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 | */ |
98 | RDGE.fx.fxSSAO.prototype.doSSAO = function (srcTexColor, srcTexNormDepth, srcTexHRDepth, dstRenderTarget, sampleRadius, intensity, distScale, bias) { | 98 | RDGE.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 | ||