From fb0a659c9ca3479fd6799325498b11f074689936 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Mon, 2 Apr 2012 14:57:31 -0700 Subject: -Namespaced all RDGE javascript. -Removed the following unused files from the build script /core/script/fx/blur.js /core/script/fx/ssao.js /core/script/animation.js - Fully removed the following from the build and from source control as they are unused or no longer needed /core/script/util/dbgpanel.js /core/script/util/fpsTracker.js /core/script/util/statTracker.js /core/script/input.js /core/script/TextureManager.js /core/script/ubershader.js --- js/helper-classes/RDGE/src/core/script/fx/blur.js | 283 +++++++++++----------- js/helper-classes/RDGE/src/core/script/fx/ssao.js | 211 ++++++++-------- 2 files changed, 245 insertions(+), 249 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/fx') 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..110ea8e3 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 */ +// RDGE namespaces +var RDGE = RDGE || {}; +RDGE.fx = RDGE.fx || {}; + /** - * Implements a 5x5 blur. - * See http://prideout.net/archive/bloom/ - * @param mipSizes - up to three pow2 mip sizes to be separately blurred - * and combined with the src image, e.g. [256,128,64] - * @param enAuxTexture - true to enable an extra texture to be added to - * the weighted blur mips (see doBlur) - */ -function fxBlur(mipSizes, enAuxTexture) -{ - var separableBlurCombine_fshader = [ +* Implements a 5x5 blur. +* See http://prideout.net/archive/bloom/ +* @param mipSizes - up to three pow2 mip sizes to be separately blurred +* and combined with the src image, e.g. [256,128,64] +* @param enAuxTexture - true to enable an extra texture to be added to +* the weighted blur mips (see doBlur) +*/ +RDGE.fx.fxBlur = function (mipSizes, enAuxTexture) { + var separableBlurCombine_fshader = [ "#ifdef GL_ES", "precision highp float;", "#endif", - + "varying vec2 vTexcoord;", // base tex coord "uniform vec4 vWeights;", // blend weights enAuxTexture ? "uniform sampler2D sTextureAux;" : "", // aux image (unweighted) "uniform sampler2D sTexture1;", // source texture #1 - mipSizes[0] ? "uniform sampler2D sTexture2;" : "", // source texture #2 - mipSizes[1] ? "uniform sampler2D sTexture3;" : "", // source texture #3 - mipSizes[2] ? "uniform sampler2D sTexture4;" : "", // source texture #4 + mipSizes[0] ? "uniform sampler2D sTexture2;" : "", // source texture #2 + mipSizes[1] ? "uniform sampler2D sTexture3;" : "", // source texture #3 + mipSizes[2] ? "uniform sampler2D sTexture4;" : "", // source texture #4 "void main()", "{", "vec4 blurCol = vWeights.x * texture2D(sTexture1, vTexcoord, -32.0);", - mipSizes[0] ? "blurCol += vWeights.y * texture2D(sTexture2, vTexcoord, -32.0);" : "", - mipSizes[1] ? "blurCol += vWeights.z * texture2D(sTexture3, vTexcoord, -32.0);" : "", - mipSizes[2] ? "blurCol += vWeights.w * texture2D(sTexture4, vTexcoord, -32.0);" : "", - + mipSizes[0] ? "blurCol += vWeights.y * texture2D(sTexture2, vTexcoord, -32.0);" : "", + mipSizes[1] ? "blurCol += vWeights.z * texture2D(sTexture3, vTexcoord, -32.0);" : "", + mipSizes[2] ? "blurCol += vWeights.w * texture2D(sTexture4, vTexcoord, -32.0);" : "", + enAuxTexture ? "gl_FragColor = texture2D(sTextureAux, vTexcoord, -32.0) + blurCol;" : "gl_FragColor = blurCol;", "}" ].join("\n"); - function renderInitBlur(quad) - { - quad.shader = createShader(gl, 'separableBlur_vshader', 'separableBlur_fshader', [ "vert", "texcoord"]); - quad.renderObj = new RenderObject(quad.shader); + function renderInitBlur(quad) { + quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', 'separableBlur_fshader', ["vert", "texcoord"]); + quad.renderObj = new RDGE.RenderObject(quad.shader); + + quad.vertBuffer = quadBuf.vertexObject; + quad.uvBuffer = quadBuf.texCoordObject; - quad.vertBuffer = quadBuf.vertexObject; - quad.uvBuffer = quadBuf.texCoordObject; + quad.renderObj.addTexture("sTexture", 0, RDGE.UNIFORMTYPE.TEXTURE2D); - quad.renderObj.addTexture("sTexture", 0, UNIFORMTYPE.TEXTURE2D); + quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); + quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); + } - quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); - quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); - } + function renderInitCombine(quad) { + quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', separableBlurCombine_fshader, ["vert", "texcoord"]); + quad.renderObj = new RDGE.RenderObject(quad.shader); - function renderInitCombine(quad) - { - quad.shader = createShader(gl, 'separableBlur_vshader', separableBlurCombine_fshader, [ "vert", "texcoord"]); - quad.renderObj = new RenderObject(quad.shader); + quad.vertBuffer = quadBuf.vertexObject; + quad.uvBuffer = quadBuf.texCoordObject; - quad.vertBuffer = quadBuf.vertexObject; - quad.uvBuffer = quadBuf.texCoordObject; + quad.renderObj.addTexture("sTexture1", 0, RDGE.UNIFORMTYPE.TEXTURE2D); + quad.renderObj.addTexture("sTexture2", 1, RDGE.UNIFORMTYPE.TEXTURE2D); + quad.renderObj.addTexture("sTexture3", 2, RDGE.UNIFORMTYPE.TEXTURE2D); + quad.renderObj.addTexture("sTexture4", 3, RDGE.UNIFORMTYPE.TEXTURE2D); + quad.renderObj.addTexture("sTextureAux", 4, RDGE.UNIFORMTYPE.TEXTURE2D); - quad.renderObj.addTexture("sTexture1", 0, UNIFORMTYPE.TEXTURE2D); - quad.renderObj.addTexture("sTexture2", 1, UNIFORMTYPE.TEXTURE2D); - quad.renderObj.addTexture("sTexture3", 2, UNIFORMTYPE.TEXTURE2D); - quad.renderObj.addTexture("sTexture4", 3, UNIFORMTYPE.TEXTURE2D); - quad.renderObj.addTexture("sTextureAux", 4, UNIFORMTYPE.TEXTURE2D); + quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); + quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); + } - quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); - quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); - } + // Screen aligned quad geometry + var quadBuf = getScreenAlignedQuad(); - // Screen aligned quad geometry - var quadBuf = getScreenAlignedQuad(); + // Fbos for each mip level; two sets are used to pingpong horizontal and vertical blur + mipSizes = mipSizes || [128, 64, 32]; - // Fbos for each mip level; two sets are used to pingpong horizontal and vertical blur - mipSizes = mipSizes || [128, 64, 32]; + this.fboSet1 = []; + this.fboSet2 = []; - this.fboSet1 = []; - this.fboSet2 = []; + for (var i in mipSizes) { + this.fboSet1.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); + this.fboSet2.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); + } - for(var i in mipSizes) - { - this.fboSet1.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); - this.fboSet2.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); - } + // Blitter for downsampling + this.blitQuad = new RDGE.ScreenQuad(null); + this.blitQuad.initialize(RDGE.renderInitScreenQuad); - // Blitter for downsampling - this.blitQuad = new ScreenQuad(null); - this.blitQuad.initialize(renderInitScreenQuad); + // Blur shader + this.blurQuad = new RDGE.ScreenQuad(null); + this.blurQuad.initialize(renderInitBlur); - // Blur shader - this.blurQuad = new ScreenQuad(null); - this.blurQuad.initialize(renderInitBlur); + this.v3Kernel = [5.0 / 16.0, 6.0 / 16.0, 5.0 / 16.0]; + this.blurQuad.renderObj.addUniform("vCoeffs", this.v3Kernel, RDGE.UNIFORMTYPE.FLOAT3); - this.v3Kernel = [ 5.0 / 16.0, 6.0 / 16.0, 5.0 / 16.0 ]; - this.blurQuad.renderObj.addUniform("vCoeffs", this.v3Kernel, UNIFORMTYPE.FLOAT3); + this.v2Offset = RDGE.vec2.zero(); + this.blurQuad.renderObj.addUniform("vOffset", this.v2Offset, RDGE.UNIFORMTYPE.FLOAT2); - this.v2Offset = vec2.zero(); - this.blurQuad.renderObj.addUniform("vOffset", this.v2Offset, UNIFORMTYPE.FLOAT2); + // Combine/blend shader + this.combineQuad = new RDGE.ScreenQuad(null); + this.combineQuad.initialize(renderInitCombine); - // Combine/blend shader - this.combineQuad = new ScreenQuad(null); - this.combineQuad.initialize(renderInitCombine); - - this.v4Weights = [0.25, 0.25, 0.25, 0.25]; - this.combineQuad.renderObj.addUniform("vWeights", this.v4Weights, UNIFORMTYPE.FLOAT4); -} + this.v4Weights = [0.25, 0.25, 0.25, 0.25]; + this.combineQuad.renderObj.addUniform("vWeights", this.v4Weights, RDGE.UNIFORMTYPE.FLOAT4); +}; /** - * Blurs the passed render target. - * See http://prideout.net/archive/bloom/ - * @param srcTexture - source image to blur - * @param dstRenderTarget - where to put the result of the blur - * @param weights - array of 4 blend weights for the blurred mip levels - * levels in the form [srcTexture-weight, mip0-weight, - * mip1-weight, mip2-weight] - * @param auxTexture - null, else an extra texture to be added to the - * weighted blur mips - */ -fxBlur.prototype.doBlur = function(srcTexture, dstRenderTarget, weights, auxTexture) -{ - // Set weights - this.v4Weights[0] = (weights == undefined) ? 0.25 : weights[0]; - this.v4Weights[1] = (weights == undefined) ? 0.25 : weights[1]; - this.v4Weights[2] = (weights == undefined) ? 0.25 : weights[2]; - this.v4Weights[3] = (weights == undefined) ? 0.25 : weights[3]; - - // Do horizontal blur of fbo set 1 into fbo set 2 - for (var i = 0, fboSrc, fboDst; (fboSrc = srcTexture) && (fboDst = this.fboSet2[i]); i++) - { - gl.bindFramebuffer(gl.FRAMEBUFFER, fboDst.frameBuffer); - gl.viewport(0, 0, fboDst.frameBuffer.width, fboDst.frameBuffer.height); +* Blurs the passed render target. +* See http://prideout.net/archive/bloom/ +* @param srcTexture - source image to blur +* @param dstRenderTarget - where to put the result of the blur +* @param weights - array of 4 blend weights for the blurred mip levels +* levels in the form [srcTexture-weight, mip0-weight, +* mip1-weight, mip2-weight] +* @param auxTexture - null, else an extra texture to be added to the +* weighted blur mips +*/ +RDGE.fx.fxBlur.prototype.doBlur = function (srcTexture, dstRenderTarget, weights, auxTexture) { + // Set weights + this.v4Weights[0] = (weights == undefined) ? 0.25 : weights[0]; + this.v4Weights[1] = (weights == undefined) ? 0.25 : weights[1]; + this.v4Weights[2] = (weights == undefined) ? 0.25 : weights[2]; + this.v4Weights[3] = (weights == undefined) ? 0.25 : weights[3]; + + // Do horizontal blur of fbo set 1 into fbo set 2 + for (var i = 0, fboSrc, fboDst; (fboSrc = srcTexture) && (fboDst = this.fboSet2[i]); i++) { + gl.bindFramebuffer(gl.FRAMEBUFFER, fboDst.frameBuffer); + gl.viewport(0, 0, fboDst.frameBuffer.width, fboDst.frameBuffer.height); + gl.clear(gl.COLOR_BUFFER_BIT); + gl.disable(gl.DEPTH_TEST); + + this.v2Offset[0] = 0.0; + this.v2Offset[1] = 1.2 / fboDst.frameBuffer.width; + + this.blurQuad.texture = fboSrc; + + RDGE.renderProcScreenQuad(this.blurQuad); + } + + // Do vertical blur of fbo set 2 into fbo set 1 + for (var i = 0, fboSrc, fboDst; (fboSrc = this.fboSet2[i]) && (fboDst = this.fboSet1[i]); i++) { + gl.bindFramebuffer(gl.FRAMEBUFFER, fboDst.frameBuffer); + gl.viewport(0, 0, fboDst.frameBuffer.width, fboDst.frameBuffer.height); + gl.clear(gl.COLOR_BUFFER_BIT); + gl.disable(gl.DEPTH_TEST); + + this.v2Offset[0] = 1.2 / fboDst.frameBuffer.width; + this.v2Offset[1] = 0.0; + + this.blurQuad.texture = fboSrc; + + RDGE.renderProcScreenQuad(this.blurQuad); + } + + // Do a weighted combine of the textures in fbo set 1 + gl.bindFramebuffer(gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null); + gl.viewport(0, 0, RDGE.globals.width, RDGE.globals.height); gl.clear(gl.COLOR_BUFFER_BIT); - gl.disable(gl.DEPTH_TEST); - - this.v2Offset[0] = 0.0; - this.v2Offset[1] = 1.2 / fboDst.frameBuffer.width; - - this.blurQuad.texture = fboSrc; - renderProcScreenQuad(this.blurQuad); - } - - // Do vertical blur of fbo set 2 into fbo set 1 - for (var i = 0, fboSrc, fboDst; (fboSrc = this.fboSet2[i]) && (fboDst = this.fboSet1[i]); i++) - { - gl.bindFramebuffer(gl.FRAMEBUFFER, fboDst.frameBuffer); - gl.viewport(0, 0, fboDst.frameBuffer.width, fboDst.frameBuffer.height); - gl.clear(gl.COLOR_BUFFER_BIT); gl.disable(gl.DEPTH_TEST); - this.v2Offset[0] = 1.2 / fboDst.frameBuffer.width; - this.v2Offset[1] = 0.0; - - this.blurQuad.texture = fboSrc; - - renderProcScreenQuad(this.blurQuad); - } - - // Do a weighted combine of the textures in fbo set 1 - gl.bindFramebuffer(gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null); - gl.viewport(0, 0, g_width, g_height); - gl.clear(gl.COLOR_BUFFER_BIT); - - gl.disable(gl.DEPTH_TEST); - - gl.useProgram(this.combineQuad.shader); + gl.useProgram(this.combineQuad.shader); - this.combineQuad.renderObj.bindBuffers(); - this.combineQuad.renderObj.bindTextures(); - this.combineQuad.renderObj.bindUniforms(); + this.combineQuad.renderObj.bindBuffers(); + this.combineQuad.renderObj.bindTextures(); + this.combineQuad.renderObj.bindUniforms(); - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, srcTexture); - gl.activeTexture(gl.TEXTURE1); - gl.bindTexture(gl.TEXTURE_2D, this.fboSet1[0]); - gl.activeTexture(gl.TEXTURE2); - gl.bindTexture(gl.TEXTURE_2D, this.fboSet1[1]); - gl.activeTexture(gl.TEXTURE3); - gl.bindTexture(gl.TEXTURE_2D, this.fboSet1[2]); - gl.activeTexture(gl.TEXTURE4); - gl.bindTexture(gl.TEXTURE_2D, auxTexture); - gl.activeTexture(gl.TEXTURE0); + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, srcTexture); + gl.activeTexture(gl.TEXTURE1); + gl.bindTexture(gl.TEXTURE_2D, this.fboSet1[0]); + gl.activeTexture(gl.TEXTURE2); + gl.bindTexture(gl.TEXTURE_2D, this.fboSet1[1]); + gl.activeTexture(gl.TEXTURE3); + gl.bindTexture(gl.TEXTURE_2D, this.fboSet1[2]); + gl.activeTexture(gl.TEXTURE4); + gl.bindTexture(gl.TEXTURE_2D, auxTexture); + gl.activeTexture(gl.TEXTURE0); - gl.drawArrays(gl.TRIANGLES, 0, 6); + gl.drawArrays(gl.TRIANGLES, 0, 6); - gl.enable(gl.DEPTH_TEST); - gl.useProgram(null); + gl.enable(gl.DEPTH_TEST); + gl.useProgram(null); - return dstRenderTarget; -} + return dstRenderTarget; +}; 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 05793594..24a3c94b 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 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ +var RDGE = RDGE || {}; +RDGE.fx = RDGE.fx || {}; /** - * Implements SSAO. - * See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 - * @param v2ScreenSize - size of the viewport in window coordinates - */ -function fxSSAO(enHRDepth) -{ - function renderInitSSAO(quad) - { - quad.shader = createShader(gl, 'ssao_vshader', enHRDepth ? 'ssaohr_fshader' : 'ssao_fshader', [ "vert", "texcoord"]); - quad.renderObj = new RenderObject(quad.shader); - - var quadBuf = getScreenAlignedQuad(); - quad.vertBuffer = quadBuf.vertexObject; - quad.uvBuffer = quadBuf.texCoordObject; - - quad.renderObj.addTexture("sColMap", 0, UNIFORMTYPE.TEXTURE2D); - quad.renderObj.addTexture("sNormDepthMap", 1, UNIFORMTYPE.TEXTURE2D); - quad.renderObj.addTexture("sRandMap", 2, UNIFORMTYPE.TEXTURE2D); - if (enHRDepth) - quad.renderObj.addTexture("sHRDepthMap", 3, UNIFORMTYPE.TEXTURE2D); - - quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); - quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); - } - - // Load random normal texture - this.randTexture = createTexture(gl, "assets/images/random_normal.png"); - gl.bindTexture(gl.TEXTURE_2D, this.randTexture); - gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.REPEAT); - - // Whether or not to use a high res depth texture - this.enHRDepth = enHRDepth; - - // Quad for full screen pass - this.ssaoQuad = new ScreenQuad(null); - this.ssaoQuad.initialize(renderInitSSAO); - - // Set up uniforms - var activeCam = g_cameraManager.getActiveCamera(); - this.v3FrustumFLT = activeCam.getFTR(); - this.ssaoQuad.renderObj.addUniform("u_frustumFLT", this.v3FrustumFLT, UNIFORMTYPE.FLOAT3); - - this.v4ArtVals = [1.0, 1.0, 1.0, 1.0]; - this.ssaoQuad.renderObj.addUniform("u_artVals", this.v4ArtVals, UNIFORMTYPE.FLOAT4); - - this.fRandMapSize = 64.0; - this.ssaoQuad.renderObj.addUniform("u_randMapSize", this.fRandMapSize, UNIFORMTYPE.FLOAT); - - this.v2ScreenSize = [1024, 1024]; - this.ssaoQuad.renderObj.addUniform("u_screenSize", this.v2ScreenSize, UNIFORMTYPE.FLOAT2); -} +* Implements SSAO. +* See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 +* @param v2ScreenSize - size of the viewport in window coordinates +*/ +RDGE.fx.fxSSAO = function (enHRDepth) { + function renderInitSSAO(quad) { + quad.shader = RDGE.createShader(RDGE.globals.gl, 'ssao_vshader', enHRDepth ? 'ssaohr_fshader' : 'ssao_fshader', ["vert", "texcoord"]); + quad.renderObj = new RDGE.RenderObject(quad.shader); + + var quadBuf = getScreenAlignedQuad(); + quad.vertBuffer = quadBuf.vertexObject; + quad.uvBuffer = quadBuf.texCoordObject; + + quad.renderObj.addTexture("sColMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D); + quad.renderObj.addTexture("sNormDepthMap", 1, RDGE.UNIFORMTYPE.TEXTURE2D); + quad.renderObj.addTexture("sRandMap", 2, RDGE.UNIFORMTYPE.TEXTURE2D); + if (enHRDepth) + quad.renderObj.addTexture("sHRDepthMap", 3, RDGE.UNIFORMTYPE.TEXTURE2D); + + quad.renderObj.addBuffers(quad.vertBuffer, RDGE.globals.gl.ARRAY_BUFFER, 3, 0, RDGE.globals.gl.FLOAT); + quad.renderObj.addBuffers(quad.uvBuffer, RDGE.globals.gl.ARRAY_BUFFER, 2, 2, RDGE.globals.gl.FLOAT); + } + + // Load random normal texture + this.randTexture = createTexture(RDGE.globals.gl, "assets/images/random_normal.png"); + RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, this.randTexture); + RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_MIN_FILTER, RDGE.globals.gl.LINEAR); + RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_S, RDGE.globals.gl.REPEAT); + RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_T, RDGE.globals.gl.REPEAT); + + // Whether or not to use a high res depth texture + this.enHRDepth = enHRDepth; + + // Quad for full screen pass + this.ssaoQuad = new RDGE.ScreenQuad(null); + this.ssaoQuad.initialize(renderInitSSAO); + + // Set up uniforms + var activeCam = g_cameraManager.getActiveCamera(); + this.v3FrustumFLT = activeCam.getFTR(); + this.ssaoQuad.renderObj.addUniform("u_frustumFLT", this.v3FrustumFLT, RDGE.UNIFORMTYPE.FLOAT3); + + this.v4ArtVals = [1.0, 1.0, 1.0, 1.0]; + this.ssaoQuad.renderObj.addUniform("u_artVals", this.v4ArtVals, RDGE.UNIFORMTYPE.FLOAT4); + + this.fRandMapSize = 64.0; + this.ssaoQuad.renderObj.addUniform("u_randMapSize", this.fRandMapSize, RDGE.UNIFORMTYPE.FLOAT); + + this.v2ScreenSize = [1024, 1024]; + this.ssaoQuad.renderObj.addUniform("u_screenSize", this.v2ScreenSize, RDGE.UNIFORMTYPE.FLOAT2); +}; /** - * Contributes SSAO to the passed offscreen surface, rendering to another surface. - * See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 - * @param srcTexColor - color surface of rendered scene - * @param srcTexNormDepth - screenspace normal+depth surface for scene; {nx, ny, nz, depth} - * @param dstRenderTarget - where to put the result of SSAO - * @param sampleRadius - - * @param intensity - - * @param distScale - - * @param bias - - */ -fxSSAO.prototype.doSSAO = function(srcTexColor, srcTexNormDepth, srcTexHRDepth, dstRenderTarget, sampleRadius, intensity, distScale, bias) -{ - // Set art params and other uniforms - this.v4ArtVals[0] = sampleRadius; - this.v4ArtVals[1] = intensity; - this.v4ArtVals[2] = distScale; - this.v4ArtVals[3] = bias; - - this.v2ScreenSize[0] = dstRenderTarget ? dstRenderTarget.frameBuffer.width : g_width; - this.v2ScreenSize[1] = dstRenderTarget ? dstRenderTarget.frameBuffer.height : g_height; - - // Do ssao - gl.bindFramebuffer(gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null); - // gl.viewport(0, 0, 99999, 99999); - gl.clear(gl.COLOR_BUFFER_BIT); - - gl.disable(gl.DEPTH_TEST); - - gl.useProgram(this.ssaoQuad.shader); - - this.ssaoQuad.renderObj.bindBuffers(); - this.ssaoQuad.renderObj.bindTextures(); - this.ssaoQuad.renderObj.bindUniforms(); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, srcTexColor); - gl.activeTexture(gl.TEXTURE1); - gl.bindTexture(gl.TEXTURE_2D, srcTexNormDepth); - gl.activeTexture(gl.TEXTURE2); - gl.bindTexture(gl.TEXTURE_2D, this.randTexture); - if (this.enHRDepth) { - gl.activeTexture(gl.TEXTURE3); - gl.bindTexture(gl.TEXTURE_2D, srcTexHRDepth); - } - gl.activeTexture(gl.TEXTURE0); - - gl.drawArrays(gl.TRIANGLES, 0, 6); - - gl.enable(gl.DEPTH_TEST); - gl.useProgram(null); - - return dstRenderTarget; -} +* Contributes SSAO to the passed offscreen surface, rendering to another surface. +* See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 +* @param srcTexColor - color surface of rendered scene +* @param srcTexNormDepth - screenspace normal+depth surface for scene; {nx, ny, nz, depth} +* @param dstRenderTarget - where to put the result of SSAO +* @param sampleRadius - +* @param intensity - +* @param distScale - +* @param bias - +*/ +RDGE.fx.fxSSAO.prototype.doSSAO = function (srcTexColor, srcTexNormDepth, srcTexHRDepth, dstRenderTarget, sampleRadius, intensity, distScale, bias) { + // Set art params and other uniforms + this.v4ArtVals[0] = sampleRadius; + this.v4ArtVals[1] = intensity; + this.v4ArtVals[2] = distScale; + this.v4ArtVals[3] = bias; + + this.v2ScreenSize[0] = dstRenderTarget ? dstRenderTarget.frameBuffer.width : RDGE.globals.width; + this.v2ScreenSize[1] = dstRenderTarget ? dstRenderTarget.frameBuffer.height : RDGE.globals.height; + + // Do ssao + RDGE.globals.gl.bindFramebuffer(RDGE.globals.gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null); + // gl.viewport(0, 0, 99999, 99999); + RDGE.globals.gl.clear(RDGE.globals.gl.COLOR_BUFFER_BIT); + + RDGE.globals.gl.disable(RDGE.globals.gl.DEPTH_TEST); + + RDGE.globals.gl.useProgram(this.ssaoQuad.shader); + + this.ssaoQuad.renderObj.bindBuffers(); + this.ssaoQuad.renderObj.bindTextures(); + this.ssaoQuad.renderObj.bindUniforms(); + + RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE0); + RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexColor); + RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE1); + RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexNormDepth); + RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE2); + RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, this.randTexture); + if (this.enHRDepth) { + RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE3); + RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexHRDepth); + } + RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE0); + + RDGE.globals.gl.drawArrays(RDGE.globals.gl.TRIANGLES, 0, 6); + + RDGE.globals.gl.enable(RDGE.globals.gl.DEPTH_TEST); + RDGE.globals.gl.useProgram(null); + + return dstRenderTarget; +}; -- cgit v1.2.3 From b4ba63045158e108356e065c1237fb72b56473a5 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Tue, 3 Apr 2012 09:39:38 -0700 Subject: fixed remaining namespace bugs ensuring the use of the RDGE namespace everywhere it is required --- js/helper-classes/RDGE/src/core/script/fx/blur.js | 6 +- js/helper-classes/RDGE/src/core/script/fx/ssao.js | 90 +++++++++++------------ 2 files changed, 48 insertions(+), 48 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/fx') 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 110ea8e3..2a8c2ff1 100755 --- a/js/helper-classes/RDGE/src/core/script/fx/blur.js +++ b/js/helper-classes/RDGE/src/core/script/fx/blur.js @@ -56,7 +56,7 @@ RDGE.fx.fxBlur = function (mipSizes, enAuxTexture) { quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); - } + }; function renderInitCombine(quad) { quad.shader = RDGE.createShader(gl, 'separableBlur_vshader', separableBlurCombine_fshader, ["vert", "texcoord"]); @@ -73,7 +73,7 @@ RDGE.fx.fxBlur = function (mipSizes, enAuxTexture) { quad.renderObj.addBuffers(quad.vertBuffer, gl.ARRAY_BUFFER, 3, 0, gl.FLOAT); quad.renderObj.addBuffers(quad.uvBuffer, gl.ARRAY_BUFFER, 2, 2, gl.FLOAT); - } + }; // Screen aligned quad geometry var quadBuf = getScreenAlignedQuad(); @@ -87,7 +87,7 @@ RDGE.fx.fxBlur = function (mipSizes, enAuxTexture) { for (var i in mipSizes) { this.fboSet1.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); this.fboSet2.push(createRenderTargetTexture(mipSizes[i], mipSizes[i])); - } + }; // Blitter for downsampling this.blitQuad = new RDGE.ScreenQuad(null); 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 5af2859d..2f96aa5b 100755 --- a/js/helper-classes/RDGE/src/core/script/fx/ssao.js +++ b/js/helper-classes/RDGE/src/core/script/fx/ssao.js @@ -8,91 +8,91 @@ var RDGE = RDGE || {}; RDGE.fx = RDGE.fx || {}; /** - * Implements SSAO. - * See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 - * @param v2ScreenSize - size of the viewport in window coordinates - */ +* Implements SSAO. +* See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 +* @param v2ScreenSize - size of the viewport in window coordinates +*/ RDGE.fx.fxSSAO = function (enHRDepth) { function renderInitSSAO(quad) { quad.shader = RDGE.createShader(RDGE.globals.gl, 'ssao_vshader', enHRDepth ? 'ssaohr_fshader' : 'ssao_fshader', ["vert", "texcoord"]); quad.renderObj = new RDGE.RenderObject(quad.shader); - var quadBuf = getScreenAlignedQuad(); - quad.vertBuffer = quadBuf.vertexObject; - quad.uvBuffer = quadBuf.texCoordObject; + var quadBuf = getScreenAlignedQuad(); + quad.vertBuffer = quadBuf.vertexObject; + quad.uvBuffer = quadBuf.texCoordObject; quad.renderObj.addTexture("sColMap", 0, RDGE.UNIFORMTYPE.TEXTURE2D); quad.renderObj.addTexture("sNormDepthMap", 1, RDGE.UNIFORMTYPE.TEXTURE2D); quad.renderObj.addTexture("sRandMap", 2, RDGE.UNIFORMTYPE.TEXTURE2D); - if (enHRDepth) + if (enHRDepth) quad.renderObj.addTexture("sHRDepthMap", 3, RDGE.UNIFORMTYPE.TEXTURE2D); quad.renderObj.addBuffers(quad.vertBuffer, RDGE.globals.gl.ARRAY_BUFFER, 3, 0, RDGE.globals.gl.FLOAT); quad.renderObj.addBuffers(quad.uvBuffer, RDGE.globals.gl.ARRAY_BUFFER, 2, 2, RDGE.globals.gl.FLOAT); - }; - - // Load random normal texture - this.randTexture = createTexture(RDGE.globals.gl, RDGE.globals.engine._assetPath+"images/random_normal.png"); + }; + + // Load random normal texture + this.randTexture = createTexture(RDGE.globals.gl, RDGE.globals.engine._assetPath + "images/random_normal.png"); RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, this.randTexture); RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_MIN_FILTER, RDGE.globals.gl.LINEAR); RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_S, RDGE.globals.gl.REPEAT); RDGE.globals.gl.texParameteri(RDGE.globals.gl.TEXTURE_2D, RDGE.globals.gl.TEXTURE_WRAP_T, RDGE.globals.gl.REPEAT); - // Whether or not to use a high res depth texture - this.enHRDepth = enHRDepth; + // Whether or not to use a high res depth texture + this.enHRDepth = enHRDepth; - // Quad for full screen pass + // Quad for full screen pass this.ssaoQuad = new RDGE.ScreenQuad(null); - this.ssaoQuad.initialize(renderInitSSAO); + this.ssaoQuad.initialize(renderInitSSAO); - // Set up uniforms - var activeCam = g_cameraManager.getActiveCamera(); - this.v3FrustumFLT = activeCam.getFTR(); + // Set up uniforms + var activeCam = g_cameraManager.getActiveCamera(); + this.v3FrustumFLT = activeCam.getFTR(); this.ssaoQuad.renderObj.addUniform("u_frustumFLT", this.v3FrustumFLT, RDGE.UNIFORMTYPE.FLOAT3); - this.v4ArtVals = [1.0, 1.0, 1.0, 1.0]; + this.v4ArtVals = [1.0, 1.0, 1.0, 1.0]; this.ssaoQuad.renderObj.addUniform("u_artVals", this.v4ArtVals, RDGE.UNIFORMTYPE.FLOAT4); - this.fRandMapSize = 64.0; + this.fRandMapSize = 64.0; this.ssaoQuad.renderObj.addUniform("u_randMapSize", this.fRandMapSize, RDGE.UNIFORMTYPE.FLOAT); - this.v2ScreenSize = [1024, 1024]; + this.v2ScreenSize = [1024, 1024]; this.ssaoQuad.renderObj.addUniform("u_screenSize", this.v2ScreenSize, RDGE.UNIFORMTYPE.FLOAT2); }; /** - * Contributes SSAO to the passed offscreen surface, rendering to another surface. - * See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 - * @param srcTexColor - color surface of rendered scene - * @param srcTexNormDepth - screenspace normal+depth surface for scene; {nx, ny, nz, depth} - * @param dstRenderTarget - where to put the result of SSAO - * @param sampleRadius - - * @param intensity - - * @param distScale - - * @param bias - - */ +* Contributes SSAO to the passed offscreen surface, rendering to another surface. +* See http://www.gamedev.net/page/resources/_/reference/programming/140/lighting-and-shading/a-simple-and-practical-approach-to-ssao-r2753 +* @param srcTexColor - color surface of rendered scene +* @param srcTexNormDepth - screenspace normal+depth surface for scene; {nx, ny, nz, depth} +* @param dstRenderTarget - where to put the result of SSAO +* @param sampleRadius - +* @param intensity - +* @param distScale - +* @param bias - +*/ RDGE.fx.fxSSAO.prototype.doSSAO = function (srcTexColor, srcTexNormDepth, srcTexHRDepth, dstRenderTarget, sampleRadius, intensity, distScale, bias) { - // Set art params and other uniforms - this.v4ArtVals[0] = sampleRadius; - this.v4ArtVals[1] = intensity; - this.v4ArtVals[2] = distScale; - this.v4ArtVals[3] = bias; + // Set art params and other uniforms + this.v4ArtVals[0] = sampleRadius; + this.v4ArtVals[1] = intensity; + this.v4ArtVals[2] = distScale; + this.v4ArtVals[3] = bias; this.v2ScreenSize[0] = dstRenderTarget ? dstRenderTarget.frameBuffer.width : RDGE.globals.width; this.v2ScreenSize[1] = dstRenderTarget ? dstRenderTarget.frameBuffer.height : RDGE.globals.height; - // Do ssao + // Do ssao RDGE.globals.gl.bindFramebuffer(RDGE.globals.gl.FRAMEBUFFER, dstRenderTarget ? dstRenderTarget.frameBuffer : null); - // gl.viewport(0, 0, 99999, 99999); + // gl.viewport(0, 0, 99999, 99999); RDGE.globals.gl.clear(RDGE.globals.gl.COLOR_BUFFER_BIT); RDGE.globals.gl.disable(RDGE.globals.gl.DEPTH_TEST); RDGE.globals.gl.useProgram(this.ssaoQuad.shader); - this.ssaoQuad.renderObj.bindBuffers(); - this.ssaoQuad.renderObj.bindTextures(); - this.ssaoQuad.renderObj.bindUniforms(); + this.ssaoQuad.renderObj.bindBuffers(); + this.ssaoQuad.renderObj.bindTextures(); + this.ssaoQuad.renderObj.bindUniforms(); RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE0); RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexColor); @@ -100,10 +100,10 @@ RDGE.fx.fxSSAO.prototype.doSSAO = function (srcTexColor, srcTexNormDepth, srcTex RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexNormDepth); RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE2); RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, this.randTexture); - if (this.enHRDepth) { + if (this.enHRDepth) { RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE3); RDGE.globals.gl.bindTexture(RDGE.globals.gl.TEXTURE_2D, srcTexHRDepth); - } + } RDGE.globals.gl.activeTexture(RDGE.globals.gl.TEXTURE0); RDGE.globals.gl.drawArrays(RDGE.globals.gl.TRIANGLES, 0, 6); @@ -111,5 +111,5 @@ RDGE.fx.fxSSAO.prototype.doSSAO = function (srcTexColor, srcTexNormDepth, srcTex RDGE.globals.gl.enable(RDGE.globals.gl.DEPTH_TEST); RDGE.globals.gl.useProgram(null); - return dstRenderTarget; + return dstRenderTarget; }; -- cgit v1.2.3