diff options
author | Valerio Virgillito | 2012-04-04 15:53:29 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-04-04 15:53:29 -0700 |
commit | e721a7c1009f298a1bd8fea583da14535e039880 (patch) | |
tree | 9415f5ba25ad643df678e561719d2708fd3ead5a /js/helper-classes/RDGE/src/core/script/fx | |
parent | 8482e23cd9b8c4700b5130f2588e5eb24d376536 (diff) | |
parent | 7249d6377c8897b2f9d8115be99717be971a0981 (diff) | |
download | ninja-e721a7c1009f298a1bd8fea583da14535e039880.tar.gz |
Merge pull request #156 from mayhewinator/WorkingBranch
Namespace and code cleanup for RDGE and related files
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/fx')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/fx/blur.js | 283 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/fx/ssao.js | 211 |
2 files changed, 245 insertions, 249 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 7fa24712..2a8c2ff1 100755 --- a/js/helper-classes/RDGE/src/core/script/fx/blur.js +++ b/js/helper-classes/RDGE/src/core/script/fx/blur.js | |||
@@ -5,192 +5,189 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | 7 | ||
8 | // RDGE namespaces | ||
9 | var RDGE = RDGE || {}; | ||
10 | RDGE.fx = RDGE.fx || {}; | ||
11 | |||
8 | /** | 12 | /** |
9 | * Implements a 5x5 blur. | 13 | * Implements a 5x5 blur. |
10 | * See http://prideout.net/archive/bloom/ | 14 | * See http://prideout.net/archive/bloom/ |
11 | * @param mipSizes - up to three pow2 mip sizes to be separately blurred | 15 | * @param mipSizes - up to three pow2 mip sizes to be separately blurred |
12 | * and combined with the src image, e.g. [256,128,64] | 16 | * and combined with the src image, e.g. [256,128,64] |
13 | * @param enAuxTexture - true to enable an extra texture to be added to | 17 | * @param enAuxTexture - true to enable an extra texture to be added to |
14 | * the weighted blur mips (see doBlur) | 18 | * the weighted blur mips (see doBlur) |
15 | */ | 19 | */ |
16 | function fxBlur(mipSizes, enAuxTexture) | 20 | RDGE.fx.fxBlur = function (mipSizes, enAuxTexture) { |
17 | { | 21 | var separableBlurCombine_fshader = [ |
18 | var separableBlurCombine_fshader = [ | ||
19 | "#ifdef GL_ES", | 22 | "#ifdef GL_ES", |
20 | "precision highp float;", | 23 | "precision highp float;", |
21 | "#endif", | 24 | "#endif", |
22 | 25 | ||
23 | "varying vec2 vTexcoord;", // base tex coord | 26 | "varying vec2 vTexcoord;", // base tex coord |
24 | "uniform vec4 vWeights;", // blend weights | 27 | "uniform vec4 vWeights;", // blend weights |
25 | 28 | ||
26 | enAuxTexture ? "uniform sampler2D sTextureAux;" : "", // aux image (unweighted) | 29 | enAuxTexture ? "uniform sampler2D sTextureAux;" : "", // aux image (unweighted) |
27 | "uniform sampler2D sTexture1;", // source texture #1 | 30 | "uniform sampler2D sTexture1;", // source texture #1 |
28 | mipSizes[0] ? "uniform sampler2D sTexture2;" : "", // source texture #2 | 31 | mipSizes[0] ? "uniform sampler2D sTexture2;" : "", // source texture #2 |
29 | mipSizes[1] ? "uniform sampler2D sTexture3;" : "", // source texture #3 | 32 | mipSizes[1] ? "uniform sampler2D sTexture3;" : "", // source texture #3 |
30 | mipSizes[2] ? "uniform sampler2D sTexture4;" : "", // source texture #4 | 33 | mipSizes[2] ? "uniform sampler2D sTexture4;" : "", // source texture #4 |
31 | 34 | ||
32 | "void main()", | 35 | "void main()", |
33 | "{", | 36 | "{", |
34 | "vec4 blurCol = vWeights.x * texture2D(sTexture1, vTexcoord, -32.0);", | 37 | "vec4 blurCol = vWeights.x * texture2D(sTexture1, vTexcoord, -32.0);", |
35 | mipSizes[0] ? "blurCol += vWeights.y * texture2D(sTexture2, vTexcoord, -32.0);" : "", | 38 | mipSizes[0] ? "blurCol += vWeights.y * texture2D(sTexture2, vTexcoord, -32.0);" : "", |
36 | mipSizes[1] ? "blurCol += vWeights.z * texture2D(sTexture3, vTexcoord, -32.0);" : "", | 39 | mipSizes[1] ? "blurCol += vWeights.z * texture2D(sTexture3, vTexcoord, -32.0);" : "", |
37 | mipSizes[2] ? "blurCol += vWeights.w * texture2D(sTexture4, vTexcoord, -32.0);" : "", | 40 | mipSizes[2] ? "blurCol += vWeights.w * texture2D(sTexture4, vTexcoord, -32.0);" : "", |
38 | 41 | ||
39 | enAuxTexture ? "gl_FragColor = texture2D(sTextureAux, vTexcoord, -32.0) + blurCol;" : "gl_FragColor = blurCol;", | 42 | enAuxTexture ? "gl_FragColor = texture2D(sTextureAux, vTexcoord, -32.0) + blurCol;" : "gl_FragColor = blurCol;", |
40 | "}" | 43 | "}" |
41 | 44 | ||
42 | ].join("\n"); | 45 | ].join("\n"); |
43 | 46 | ||
44 | 47 | ||
45 | function renderInitBlur(quad) | 48 | function renderInitBlur(quad) { |
46 | { | 49 | quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', 'separableBlur_fshader', ["vert", "texcoord"]); |
47 | quad.shader = createShader(gl, 'separableBlur_vshader', 'separableBlur_fshader', [ "vert", "texcoord"]); | 50 | quad.renderObj = new RDGE.RenderObject(quad.shader); |
48 | quad.renderObj = new RenderObject(quad.shader); | 51 | |
52 | quad.vertBuffer = quadBuf.vertexObject; | ||
53 | quad.uvBuffer = quadBuf.texCoordObject; | ||
49 | 54 | ||
50 | quad.vertBuffer = quadBuf.vertexObject; | 55 | quad.renderObj.addTexture("sTexture", 0, RDGE.UNIFORMTYPE.TEXTURE2D); |
51 | quad.uvBuffer = quadBuf.texCoordObject; | ||
52 | 56 | ||
53 | quad.renderObj.addTexture("sTexture", 0, UNIFORMTYPE.TEXTURE2D); | 57 | quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); |
58 | quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); | ||
59 | }; | ||
54 | 60 | ||
55 | quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); | 61 | function renderInitCombine(quad) { |
56 | quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); | 62 | quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', separableBlurCombine_fshader, ["vert", "texcoord"]); |
57 | } | 63 | quad.renderObj = new RDGE.RenderObject(quad.shader); |
58 | 64 | ||
59 | function renderInitCombine(quad) | 65 | quad.vertBuffer = quadBuf.vertexObject; |
60 | { | 66 | quad.uvBuffer = quadBuf.texCoordObject; |
61 | quad.shader = createShader(gl, 'separableBlur_vshader', separableBlurCombine_fshader, [ "vert", "texcoord"]); | ||
62 | quad.renderObj = new RenderObject(quad.shader); | ||
63 | 67 | ||
64 | quad.vertBuffer = quadBuf.vertexObject; | 68 | quad.renderObj.addTexture("sTexture1", 0, RDGE.UNIFORMTYPE.TEXTURE2D); |
65 | quad.uvBuffer = quadBuf.texCoordObject; | 69 | quad.renderObj.addTexture("sTexture2", 1, RDGE.UNIFORMTYPE.TEXTURE2D); |
70 | quad.renderObj.addTexture("sTexture3", 2, RDGE.UNIFORMTYPE.TEXTURE2D); | ||
71 | quad.renderObj.addTexture("sTexture4", 3, RDGE.UNIFORMTYPE.TEXTURE2D); | ||
72 | quad.renderObj.addTexture("sTextureAux", 4, RDGE.UNIFORMTYPE.TEXTURE2D); | ||
66 | 73 | ||
67 | quad.renderObj.addTexture("sTexture1", 0, UNIFORMTYPE.TEXTURE2D); | 74 | quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); |
68 | quad.renderObj.addTexture("sTexture2", 1, UNIFORMTYPE.TEXTURE2D); | 75 | quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); |
69 | quad.renderObj.addTexture("sTexture3", 2, UNIFORMTYPE.TEXTURE2D); | 76 | }; |
70 | quad.renderObj.addTexture("sTexture4", 3, UNIFORMTYPE.TEXTURE2D); | ||
71 | quad.renderObj.addTexture("sTextureAux", 4, UNIFORMTYPE.TEXTURE2D); | ||
72 | 77 | ||
73 | quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); | 78 | // Screen aligned quad geometry |
74 | quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); | 79 | var quadBuf = getScreenAlignedQuad(); |
75 | } | ||
76 | 80 | ||
77 | // Screen aligned quad geometry | 81 | // Fbos for each mip level; two sets are used to pingpong horizontal and vertical blur |
78 | var quadBuf = getScreenAlignedQuad(); | 82 | mipSizes = mipSizes || [128, 64, 32]; |
79 | 83 | ||
80 | // Fbos for each mip level; two sets are used to pingpong horizontal and vertical blur | 84 | this.fboSet1 = []; |
81 | mipSizes = mipSizes || [128, 64, 32]; | 85 | this.fboSet2 = []; |
82 | 86 | ||
83 | this.fboSet1 = []; | 87 | for (var i in mipSizes) { |
84 | this.fboSet2 = []; | 88 | this.fboSet1.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); |
89 | this.fboSet2.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); | ||
90 | }; | ||
85 | 91 | ||
86 | for(var i in mipSizes) | 92 | // Blitter for downsampling |
87 | { | 93 | this.blitQuad = new RDGE.ScreenQuad(null); |
88 | this.fboSet1.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); | 94 | this.blitQuad.initialize(RDGE.renderInitScreenQuad); |
89 | this.fboSet2.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); | ||
90 | } | ||
91 | 95 | ||
92 | // Blitter for downsampling | 96 | // Blur shader |
93 | this.blitQuad = new ScreenQuad(null); | 97 | this.blurQuad = new RDGE.ScreenQuad(null); |
94 | this.blitQuad.initialize(renderInitScreenQuad); | 98 | this.blurQuad.initialize(renderInitBlur); |
95 | 99 | ||
96 | // Blur shader | 100 | this.v3Kernel = [5.0 / 16.0, 6.0 / 16.0, 5.0 / 16.0]; |
97 | this.blurQuad = new ScreenQuad(null); | 101 | this.blurQuad.renderObj.addUniform("vCoeffs", this.v3Kernel, RDGE.UNIFORMTYPE.FLOAT3); |
98 | this.blurQuad.initialize(renderInitBlur); | ||
99 | 102 | ||
100 | this.v3Kernel = [ 5.0 / 16.0, 6.0 / 16.0, 5.0 / 16.0 ]; | 103 | this.v2Offset = RDGE.vec2.zero(); |
101 | this.blurQuad.renderObj.addUniform("vCoeffs", this.v3Kernel, UNIFORMTYPE.FLOAT3); | 104 | this.blurQuad.renderObj.addUniform("vOffset", this.v2Offset, RDGE.UNIFORMTYPE.FLOAT2); |
102 | 105 | ||
103 | this.v2Offset = vec2.zero(); | 106 | // Combine/blend shader |
104 | this.blurQuad.renderObj.addUniform("vOffset", this.v2Offset, UNIFORMTYPE.FLOAT2); | 107 | this.combineQuad = new RDGE.ScreenQuad(null); |
108 | this.combineQuad.initialize(renderInitCombine); | ||
105 | 109 | ||
106 | // Combine/blend shader | 110 | this.v4Weights = [0.25, 0.25, 0.25, 0.25]; |
107 | this.combineQuad = new ScreenQuad(null); | 111 | this.combineQuad.renderObj.addUniform("vWeights", this.v4Weights, RDGE.UNIFORMTYPE.FLOAT4); |
108 | this.combineQuad.initialize(renderInitCombine); | 112 | }; |
109 | |||
110 | this.v4Weights = [0.25, 0.25, 0.25, 0.25]; | ||
111 | this.combineQuad.renderObj.addUniform("vWeights", this.v4Weights, UNIFORMTYPE.FLOAT4); | ||
112 | } | ||
113 | 113 | ||
114 | /** | 114 | /** |
115 | * Blurs the passed render target. | 115 | * Blurs the passed render target. |
116 | * See http://prideout.net/archive/bloom/ | 116 | * See http://prideout.net/archive/bloom/ |
117 | * @param srcTexture - source image to blur | 117 | * @param srcTexture - source image to blur |
118 | * @param dstRenderTarget - where to put the result of the blur | 118 | * @param dstRenderTarget - where to put the result of the blur |
119 | * @param weights - array of 4 blend weights for the blurred mip levels | 119 | * @param weights - array of 4 blend weights for the blurred mip levels |
120 | * levels in the form [srcTexture-weight, mip0-weight, | 120 | * levels in the form [srcTexture-weight, mip0-weight, |
121 | * mip1-weight, mip2-weight] | 121 | * mip1-weight, mip2-weight] |
122 | * @param auxTexture - null, else an extra texture to be added to the |