From 22cbc9644b79df60b3f6336f9563debd47fb3ea1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 28 Jun 2012 11:44:15 -0700 Subject: Added capability to split a mesh into multiiple parts to avoid buffer overflow situations. --- assets/shaders/Flag.vert.glsl | 3 ++- assets/shaders/Pulse.frag.glsl | 1 + assets/shaders/test_fshader_full.glsl | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'assets') diff --git a/assets/shaders/Flag.vert.glsl b/assets/shaders/Flag.vert.glsl index 1c842cb0..8ba00922 100644 --- a/assets/shaders/Flag.vert.glsl +++ b/assets/shaders/Flag.vert.glsl @@ -35,7 +35,8 @@ void main() const float pi = 3.14159; float angle = time; - v_uv = texcoord; + v_uv.x = texcoord.x; + v_uv.y = texcoord.y; float x = 2.0*pi*texcoord.x/u_waveWidth; float y = 2.0*pi*texcoord.y; diff --git a/assets/shaders/Pulse.frag.glsl b/assets/shaders/Pulse.frag.glsl index 9aeb05c9..b717d359 100644 --- a/assets/shaders/Pulse.frag.glsl +++ b/assets/shaders/Pulse.frag.glsl @@ -22,6 +22,7 @@ void main(void) float cLength = length(cPos); vec2 uv = gl_FragCoord.xy/u_resolution.xy+(cPos/cLength)*sin(cLength/30.0-time*10.0)/25.0; + uv.y = 1.0 - uv.y; vec3 col = texture2D(u_tex0,uv).xyz*50.0/cLength; gl_FragColor = vec4(col,1.0); diff --git a/assets/shaders/test_fshader_full.glsl b/assets/shaders/test_fshader_full.glsl index ef721b39..0ea3cf1b 100755 --- a/assets/shaders/test_fshader_full.glsl +++ b/assets/shaders/test_fshader_full.glsl @@ -38,7 +38,7 @@ varying vec3 vEyePos; void main() { - vec4 colMapTexel = vec4(texture2D(colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); + vec4 colMapTexel = vec4(texture2D(colMap, vec2(vNormal.w, 1.0 - vECPos.w)).rgb, 1.0); // normal mapping vec3 normal = normalize(vNormal.xyz); -- cgit v1.2.3 From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- assets/canvas-runtime.js | 4052 +++++++++++++++---------------- assets/shaders/Basic.vert.glsl | 6 +- assets/shaders/BasicTex.frag.glsl | 2 +- assets/shaders/Cloud.frag.glsl | 6 +- assets/shaders/Cloud.vert.glsl | 28 +- assets/shaders/Flag.vert.glsl | 22 +- assets/shaders/Taper.vert.glsl | 152 +- assets/shaders/TwistVert.frag.glsl | 8 +- assets/shaders/TwistVert.vert.glsl | 84 +- assets/shaders/linearGradient.frag.glsl | 68 +- assets/shaders/linearGradient.vert.glsl | 30 +- assets/shaders/radialGradient.frag.glsl | 70 +- assets/shaders/radialGradient.vert.glsl | 8 +- assets/shaders/test_fshader.glsl | 18 +- assets/shaders/test_fshader_full.glsl | 8 +- assets/shaders/test_vshader.glsl | 60 +- assets/shaders/ub_fshader.glsl | 414 ++-- assets/shaders/ub_vshader.glsl | 232 +- 18 files changed, 2634 insertions(+), 2634 deletions(-) (limited to 'assets') diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index ce392f34..42d90333 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js @@ -36,42 +36,42 @@ var NinjaCvsRt = NinjaCvsRt || {}; window.addEventListener('load', loadCanvasData, false); //Load data function (on document loaded) function loadCanvasData (e) { - //Cleaning up events - window.removeEventListener('load', loadCanvasData, false); + //Cleaning up events + window.removeEventListener('load', loadCanvasData, false); //Getting tag with data, MUST contain attribute var xhr, tag = document.querySelectorAll(['script[data-ninja-canvas-lib]'])[0]; - //Checking for data to be external file - if (tag.getAttribute('data-ninja-canvas-json') !== null) { - //Loading JSON data - xhr = new XMLHttpRequest(); + //Checking for data to be external file + if (tag.getAttribute('data-ninja-canvas-json') !== null) { + //Loading JSON data + xhr = new XMLHttpRequest(); xhr.open("GET", tag.getAttribute('data-ninja-canvas-json'), false); xhr.send(); - //Checking for data - if (xhr.readyState === 4) { - //Calling method to initialize all webGL/canvas(es) - NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), xhr.response); - } else { - //TODO: Add error for users - } - } else {//Data in document itself - //Calling method to initialize all webGL/canvas(es) - NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), document.querySelectorAll(['script[data-ninja-canvas]'])[0].innerHTML); - } + //Checking for data + if (xhr.readyState === 4) { + //Calling method to initialize all webGL/canvas(es) + NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), xhr.response); + } else { + //TODO: Add error for users + } + } else {//Data in document itself + //Calling method to initialize all webGL/canvas(es) + NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), document.querySelectorAll(['script[data-ninja-canvas]'])[0].innerHTML); + } } /////////////////////////////////////////////////////////////////////// //Loading webGL/canvas data NinjaCvsRt.initWebGl = function (rootElement, directory, data) { - var cvsDataMngr, ninjaWebGlData = JSON.parse((data.replace('(', '')).replace(')', '')); - if (ninjaWebGlData && ninjaWebGlData.data) { - for (var n=0; ninjaWebGlData.data[n]; n++) { - ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]); - } - } - //Creating data manager - cvsDataMngr = Object.create(NinjaCvsRt.CanvasDataManager, {}); - //Loading data to canvas(es) - cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); + var cvsDataMngr, ninjaWebGlData = JSON.parse((data.replace('(', '')).replace(')', '')); + if (ninjaWebGlData && ninjaWebGlData.data) { + for (var n=0; ninjaWebGlData.data[n]; n++) { + ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]); + } + } + //Creating data manager + cvsDataMngr = Object.create(NinjaCvsRt.CanvasDataManager, {}); + //Loading data to canvas(es) + cvsDataMngr.loadGLData(rootElement, ninjaWebGlData.data, directory); }; /////////////////////////////////////////////////////////////////////// @@ -80,64 +80,64 @@ NinjaCvsRt.initWebGl = function (rootElement, directory, data) { /////////////////////////////////////////////////////////////////////// NinjaCvsRt.CanvasDataManager = Object.create(Object.prototype, { - loadGLData: { - value: function(root, valueArray, assetPath) { - if (assetPath) - this._assetPath = assetPath.slice(); - - var value = valueArray; - var nWorlds = value.length; - for (var i=0; i= 0.001) - { - var scale = len/sum; - rtnVec = []; - for (i = 0; i= 0.001) + { + var scale = len/sum; + rtnVec = []; + for (i = 0; i minDimen) tlRad = minDimen; - if (blRad > minDimen) blRad = minDimen; - if (brRad > minDimen) brRad = minDimen; - if (trRad > minDimen) trRad = minDimen; - - var world = this.getWorld(); - var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); - var cop = [0.5*vpw, 0.5*vph, 0.0]; - var xCtr = cop[0] + this._xOffset, yCtr = cop[1] - this._yOffset; - var xLeft = xCtr - 0.5*this._width, yTop = yCtr - 0.5*this._height; - var xDist = cop[0] - xLeft, yDist = cop[1] - yTop; - var xOff = 0.5*vpw - xDist, yOff = 0.5*vph - yDist; - - if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) - { - ctx.rect(pt[0]+xOff, pt[1]+yOff, width - 2*inset, height - 2*inset); - } - else - { - // get the top left point - rad = tlRad - inset; - if (rad < 0) rad = 0; - pt[1] += rad; - if (Math.abs(rad) < 0.001) pt[1] = inset; - ctx.moveTo( pt[0]+xOff, pt[1]+yOff ); - - // get the bottom left point - pt = [inset, height - inset]; - rad = blRad - inset; - if (rad < 0) rad = 0; - pt[1] -= rad; - ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); - - // get the bottom left curve - if (rad > 0.001) - ctx.quadraticCurveTo( inset+xOff, height-inset+yOff, inset+rad+xOff, height-inset+yOff ); - - // do the bottom of the rectangle - pt = [width - inset, height - inset]; - rad = brRad - inset; - if (rad < 0) rad = 0; - pt[0] -= rad; - ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); - - // get the bottom right arc - if (rad > 0.001) - ctx.quadraticCurveTo( width-inset+xOff, height-inset+yOff, width-inset+xOff, height-inset-rad+yOff ); - - // get the right of the rectangle - pt = [width - inset, inset]; - rad = trRad - inset; - if (rad < 0) rad = 0; - pt[1] += rad; - ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); - - // do the top right corner - if (rad > 0.001) - ctx.quadraticCurveTo( width-inset+xOff, inset+yOff, width-inset-rad+xOff, inset+yOff ); - - // do the top of the rectangle - pt = [inset, inset]; - rad = tlRad - inset; - if (rad < 0) rad = 0; - pt[0] += rad; - ctx.lineTo( pt[0]+xOff, pt[1]+yOff); - - // do the top left corner - if (rad > 0.001) - ctx.quadraticCurveTo( inset+xOff, inset+yOff, inset+xOff, inset+rad+yOff ); - else - ctx.lineTo( inset+xOff, 2*inset+yOff ); - } - } - }, - - render: { - value: function() { - // get the world - var world = this.getWorld(); - if (!world) throw( "null world in rectangle render" ); - - // get the context - var ctx = world.get2DContext(); - if (!ctx) return; - - // get some dimensions - var lw = this._strokeWidth; - var w = world.getViewportWidth(), - h = world.getViewportHeight(); - - var c, - inset, - gradient, - colors, - len, - n, - position, - cs; - // render the fill - ctx.beginPath(); - if (this._fillColor) { - inset = Math.ceil( lw ) - 0.5; - - if(this._fillColor.gradientMode) { - if(this._fillColor.gradientMode === "radial") { - var ww = w - 2*lw, hh = h - 2*lw; - gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(ww, hh)/2); - } else { - gradient = ctx.createLinearGradient(inset, h/2, w-inset, h/2); - } - colors = this._fillColor.color; - - len = colors.length; - - for(n=0; n minDimen) tlRad = minDimen; + if (blRad > minDimen) blRad = minDimen; + if (brRad > minDimen) brRad = minDimen; + if (trRad > minDimen) trRad = minDimen; + + var world = this.getWorld(); + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var cop = [0.5*vpw, 0.5*vph, 0.0]; + var xCtr = cop[0] + this._xOffset, yCtr = cop[1] - this._yOffset; + var xLeft = xCtr - 0.5*this._width, yTop = yCtr - 0.5*this._height; + var xDist = cop[0] - xLeft, yDist = cop[1] - yTop; + var xOff = 0.5*vpw - xDist, yOff = 0.5*vph - yDist; + + if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) + { + ctx.rect(pt[0]+xOff, pt[1]+yOff, width - 2*inset, height - 2*inset); + } + else + { + // get the top left point + rad = tlRad - inset; + if (rad < 0) rad = 0; + pt[1] += rad; + if (Math.abs(rad) < 0.001) pt[1] = inset; + ctx.moveTo( pt[0]+xOff, pt[1]+yOff ); + + // get the bottom left point + pt = [inset, height - inset]; + rad = blRad - inset; + if (rad < 0) rad = 0; + pt[1] -= rad; + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); + + // get the bottom left curve + if (rad > 0.001) + ctx.quadraticCurveTo( inset+xOff, height-inset+yOff, inset+rad+xOff, height-inset+yOff ); + + // do the bottom of the rectangle + pt = [width - inset, height - inset]; + rad = brRad - inset; + if (rad < 0) rad = 0; + pt[0] -= rad; + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); + + // get the bottom right arc + if (rad > 0.001) + ctx.quadraticCurveTo( width-inset+xOff, height-inset+yOff, width-inset+xOff, height-inset-rad+yOff ); + + // get the right of the rectangle + pt = [width - inset, inset]; + rad = trRad - inset; + if (rad < 0) rad = 0; + pt[1] += rad; + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); + + // do the top right corner + if (rad > 0.001) + ctx.quadraticCurveTo( width-inset+xOff, inset+yOff, width-inset-rad+xOff, inset+yOff ); + + // do the top of the rectangle + pt = [inset, inset]; + rad = tlRad - inset; + if (rad < 0) rad = 0; + pt[0] += rad; + ctx.lineTo( pt[0]+xOff, pt[1]+yOff); + + // do the top left corner + if (rad > 0.001) + ctx.quadraticCurveTo( inset+xOff, inset+yOff, inset+xOff, inset+rad+yOff ); + else + ctx.lineTo( inset+xOff, 2*inset+yOff ); + } + } + }, + + render: { + value: function() { + // get the world + var world = this.getWorld(); + if (!world) throw( "null world in rectangle render" ); + + // get the context + var ctx = world.get2DContext(); + if (!ctx) return; + + // get some dimensions + var lw = this._strokeWidth; + var w = world.getViewportWidth(), + h = world.getViewportHeight(); + + var c, + inset, + gradient, + colors, + len, + n, + position, + cs; + // render the fill + ctx.beginPath(); + if (this._fillColor) { + inset = Math.ceil( lw ) - 0.5; + + if(this._fillColor.gradientMode) { + if(this._fillColor.gradientMode === "radial") { + var ww = w - 2*lw, hh = h - 2*lw; + gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(ww, hh)/2); + } else { + gradient = ctx.createLinearGradient(inset, h/2, w-inset, h/2); + } + colors = this._fillColor.color; + + len = colors.length; + + for(n=0; n