aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/fx/blur.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/fx/blur.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/fx/blur.js435
1 files changed, 218 insertions, 217 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/fx/blur.js b/js/helper-classes/RDGE/src/core/script/fx/blur.js
index f105a391..72fc22ea 100755
--- a/js/helper-classes/RDGE/src/core/script/fx/blur.js
+++ b/js/helper-classes/RDGE/src/core/script/fx/blur.js
@@ -1,217 +1,218 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4
5 5Redistribution and use in source and binary forms, with or without
6Redistribution and use in source and binary forms, with or without 6modification, are permitted provided that the following conditions are met:
7modification, are permitted provided that the following conditions are met: 7
8 8* Redistributions of source code must retain the above copyright notice,
9 - Redistributions of source code must retain the above copyright notice, 9 this list of conditions and the following disclaimer.
10 this list of conditions and the following disclaimer. 10
11 - Redistributions in binary form must reproduce the above copyright 11* Redistributions in binary form must reproduce the above copyright notice,
12 notice, this list of conditions and the following disclaimer in the 12 this list of conditions and the following disclaimer in the documentation
13 documentation and/or other materials provided with the distribution. 13 and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors 14
15 may be used to endorse or promote products derived from this software 15* Neither the name of Motorola Mobility LLC nor the names of its
16 without specific prior written permission. 16 contributors may be used to endorse or promote products derived from this
17 17 software without specific prior written permission.
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28POSSIBILITY OF SUCH DAMAGE. 28ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29</copyright> */ 29POSSIBILITY OF SUCH DAMAGE.
30 30</copyright> */
31 31
32// RDGE namespaces 32
33var RDGE = RDGE || {}; 33// RDGE namespaces
34RDGE.fx = RDGE.fx || {}; 34var RDGE = RDGE || {};
35 35RDGE.fx = RDGE.fx || {};
36/** 36
37* Implements a 5x5 blur. 37/**
38* See http://prideout.net/archive/bloom/ 38* Implements a 5x5 blur.
39* @param mipSizes - up to three pow2 mip sizes to be separately blurred 39* See http://prideout.net/archive/bloom/
40* and combined with the src image, e.g. [256,128,64] 40* @param mipSizes - up to three pow2 mip sizes to be separately blurred
41* @param enAuxTexture - true to enable an extra texture to be added to 41* and combined with the src image, e.g. [256,128,64]
42* the weighted blur mips (see doBlur) 42* @param enAuxTexture - true to enable an extra texture to be added to
43*/ 43* the weighted blur mips (see doBlur)
44RDGE.fx.fxBlur = function (mipSizes, enAuxTexture) { 44*/
45 var separableBlurCombine_fshader = [ 45RDGE.fx.fxBlur = function (mipSizes, enAuxTexture) {
46 "#ifdef GL_ES", 46 var separableBlurCombine_fshader = [
47 "precision highp float;", 47 "#ifdef GL_ES",
48 "#endif", 48 "precision highp float;",
49 49 "#endif",
50 "varying vec2 vTexcoord;", // base tex coord 50
51 "uniform vec4 vWeights;", // blend weights 51 "varying vec2 vTexcoord;", // base tex coord
52 52 "uniform vec4 vWeights;", // blend weights
53 enAuxTexture ? "uniform sampler2D sTextureAux;" : "", // aux image (unweighted) 53
54 "uniform sampler2D sTexture1;", // source texture #1 54 enAuxTexture ? "uniform sampler2D sTextureAux;" : "", // aux image (unweighted)
55 mipSizes[0] ? "uniform sampler2D sTexture2;" : "", // source texture #2 55 "uniform sampler2D sTexture1;", // source texture #1
56 mipSizes[1] ? "uniform sampler2D sTexture3;" : "", // source texture #3 56 mipSizes[0] ? "uniform sampler2D sTexture2;" : "", // source texture #2
57 mipSizes[2] ? "uniform sampler2D sTexture4;" : "", // source texture #4 57 mipSizes[1] ? "uniform sampler2D sTexture3;" : "", // source texture #3
58 58 mipSizes[2] ? "uniform sampler2D sTexture4;" : "", // source texture #4
59 "void main()", 59
60 "{", 60 "void main()",
61 "vec4 blurCol = vWeights.x * texture2D(sTexture1, vTexcoord, -32.0);", 61 "{",
62 mipSizes[0] ? "blurCol += vWeights.y * texture2D(sTexture2, vTexcoord, -32.0);" : "", 62 "vec4 blurCol = vWeights.x * texture2D(sTexture1, vTexcoord, -32.0);",
63 mipSizes[1] ? "blurCol += vWeights.z * texture2D(sTexture3, vTexcoord, -32.0);" : "", 63 mipSizes[0] ? "blurCol += vWeights.y * texture2D(sTexture2, vTexcoord, -32.0);" : "",
64 mipSizes[2] ? "blurCol += vWeights.w * texture2D(sTexture4, vTexcoord, -32.0);" : "", 64 mipSizes[1] ? "blurCol += vWeights.z * texture2D(sTexture3, vTexcoord, -32.0);" : "",
65 65 mipSizes[2] ? "blurCol += vWeights.w * texture2D(sTexture4, vTexcoord, -32.0);" : "",
66 enAuxTexture ? "gl_FragColor = texture2D(sTextureAux, vTexcoord, -32.0) + blurCol;" : "gl_FragColor = blurCol;", 66
67 "}" 67 enAuxTexture ? "gl_FragColor = texture2D(sTextureAux, vTexcoord, -32.0) + blurCol;" : "gl_FragColor = blurCol;",
68 68 "}"
69 ].join("\n"); 69
70 70 ].join("\n");
71 71
72 function renderInitBlur(quad) { 72
73 quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', 'separableBlur_fshader', ["vert", "texcoord"]); 73 function renderInitBlur(quad) {
74 quad.renderObj = new RDGE.RenderObject(quad.shader); 74 quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', 'separableBlur_fshader', ["vert", "texcoord"]);
75 75 quad.renderObj = new RDGE.RenderObject(quad.shader);
76 quad.vertBuffer = quadBuf.vertexObject; 76
77 quad.uvBuffer = quadBuf.texCoordObject; 77 quad.vertBuffer = quadBuf.vertexObject;
78 78 quad.uvBuffer = quadBuf.texCoordObject;
79 quad.renderObj.addTexture("sTexture", 0, RDGE.UNIFORMTYPE.TEXTURE2D); 79
80 80 quad.renderObj.addTexture("sTexture", 0, RDGE.UNIFORMTYPE.TEXTURE2D);
81 quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); 81
82 quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); 82 quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT);
83 }; 83 quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT);
84 84 };
85 function renderInitCombine(quad) { 85
86 quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', separableBlurCombine_fshader, ["vert", "texcoord"]); 86 function renderInitCombine(quad) {
87 quad.renderObj = new RDGE.RenderObject(quad.shader); 87 quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', separableBlurCombine_fshader, ["vert", "texcoord"]);
88 88 quad.renderObj = new RDGE.RenderObject(quad.shader);
89 quad.vertBuffer = quadBuf.vertexObject; 89
90 quad.uvBuffer = quadBuf.texCoordObject; 90 quad.vertBuffer = quadBuf.vertexObject;
91 91 quad.uvBuffer = quadBuf.texCoordObject;
92 quad.renderObj.addTexture("sTexture1", 0, RDGE.UNIFORMTYPE.TEXTURE2D); 92
93 quad.renderObj.addTexture("sTexture2", 1, RDGE.UNIFORMTYPE.TEXTURE2D); 93 quad.renderObj.addTexture("sTexture1", 0, RDGE.UNIFORMTYPE.TEXTURE2D);
94 quad.renderObj.addTexture("sTexture3", 2, RDGE.UNIFORMTYPE.TEXTURE2D); 94 quad.renderObj.addTexture("sTexture2", 1, RDGE.UNIFORMTYPE.TEXTURE2D);
95 quad.renderObj.addTexture("sTexture4", 3, RDGE.UNIFORMTYPE.TEXTURE2D); 95 quad.renderObj.addTexture("sTexture3", 2, RDGE.UNIFORMTYPE.TEXTURE2D);
96 quad.renderObj.addTexture("sTextureAux", 4, RDGE.UNIFORMTYPE.TEXTURE2D); 96 quad.renderObj.addTexture("sTexture4", 3, RDGE.UNIFORMTYPE.TEXTURE2D);
97 97 quad.renderObj.addTexture("sTextureAux", 4, RDGE.UNIFORMTYPE.TEXTURE2D);
98 quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); 98
99 quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); 99 quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT);
100 }; 100 quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT);
101 101 };
102 // Screen aligned quad geometry 102
103 var quadBuf = getScreenAlignedQuad(); 103 // Screen aligned quad geometry
104 104 var quadBuf = getScreenAlignedQuad();
105 // Fbos for each mip level; two sets are used to pingpong horizontal and vertical blur 105
106 mipSizes = mipSizes || [128, 64, 32]; 106 // Fbos for each mip level; two sets are used to pingpong horizontal and vertical blur
107 107 mipSizes = mipSizes || [128, 64, 32];
108 this.fboSet1 = []; 108
109 this.fboSet2 = []; 109 this.fboSet1 = [];
110 110 this.fboSet2 = [];
111 for (var i in mipSizes) { 111
112 this.fboSet1.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); 112 for (var i in mipSizes) {
113 this.fboSet2.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); 113 this.fboSet1.push(createRenderTargetTexture(mipSizes[i], mipSizes[i]));
114 }; 114 this.fboSet2.push(createRenderTargetTexture(mipSizes[i], mipSizes[i]));
115 115 };
116 // Blitter for downsampling 116
117 this.blitQuad = new RDGE.ScreenQuad(null); 117 // Blitter for downsampling
118 this.blitQuad.initialize(RDGE.renderInitScreenQuad); 118 this.blitQuad = new RDGE.ScreenQuad(null);
119 119 this.blitQuad.initialize(RDGE.renderInitScreenQuad);
120 // Blur shader 120
121 this.blurQuad = new RDGE.ScreenQuad(null); 121 // Blur shader
122 this.blurQuad.initialize(renderInitBlur); 122 this.blurQuad = new RDGE.ScreenQuad(null);
123 123 this.blurQuad.initialize(renderInitBlur);
124 this.v3Kernel = [5.0 / 16.0, 6.0 / 16.0, 5.0 / 16.0]; 124
125 this.blurQuad.renderObj.addUniform("vCoeffs", this.v3Kernel, RDGE.UNIFORMTYPE.FLOAT3); 125 this.v3Kernel = [5.0 / 16.0, 6.0 / 16.0, 5.0 / 16.0];
126 126 this.blurQuad.renderObj.addUniform("vCoeffs", this.v3Kernel, RDGE.UNIFORMTYPE.FLOAT3);
127 this.v2Offset = RDGE.vec2.zero(); 127
128 this.blurQuad.renderObj.addUniform("vOffset", this.v2Offset, RDGE.UNIFORMTYPE.FLOAT2); 128 this.v2Offset = RDGE.vec2.zero();
129 129 this.blurQuad.renderObj.addUniform("vOffset", this.v2Offset, RDGE.UNIFORMTYPE.FLOAT2);
130 // Combine/blend shader 130
131 this.combineQuad = new RDGE.ScreenQuad(null); 131 // Combine/blend shader
132