aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhwc4872012-07-11 09:48:19 -0700
committerhwc4872012-07-11 09:48:19 -0700
commit67dd4bdd47a0324507bed232d22068aa198549fe (patch)
treed0edd34f5f34a3546dc4bdc16cb72c2b98389814
parent61e2ec5052bbff0cfd792ac141f83ee8757416f3 (diff)
downloadninja-67dd4bdd47a0324507bed232d22068aa198549fe.tar.gz
re-wrote the radial blur shader. Changed tolerances in the deformation shaders.
-rw-r--r--assets/shaders/radialBlur.frag.glsl81
-rwxr-xr-xjs/lib/rdge/materials/material.js2
-rw-r--r--js/lib/rdge/materials/taper-material.js2
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js2
4 files changed, 58 insertions, 29 deletions
diff --git a/assets/shaders/radialBlur.frag.glsl b/assets/shaders/radialBlur.frag.glsl
index c4520e58..953e6f07 100644
--- a/assets/shaders/radialBlur.frag.glsl
+++ b/assets/shaders/radialBlur.frag.glsl
@@ -1,46 +1,75 @@
1 1
2/* <copyright>
3Copyright (c) 2012, Motorola Mobility LLC.
4All Rights Reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11
12* Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16* Neither the name of Motorola Mobility LLC nor the names of its
17 contributors may be used to endorse or promote products derived from this
18 software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30POSSIBILITY OF SUCH DAMAGE.
31</copyright> */
32
33#ifdef GL_ES
2precision highp float; 34precision highp float;
35#endif
3 36
4uniform vec2 u_resolution; 37uniform vec2 u_resolution;
5uniform float u_time; 38uniform float u_time;
6uniform float u_speed; 39uniform float u_speed;
7uniform sampler2D u_tex0; 40uniform sampler2D u_tex0;
8 41
9vec3 deform( in vec2 p )
10{
11 vec2 uv;
12
13 float time = u_time * u_speed;
14 vec2 q = vec2( sin(1.1*time+p.x),sin(1.2*time+p.y) );
15
16 float a = atan(q.y,q.x);
17 float r = sqrt(dot(q,q));
18
19 uv.x = sin(0.0+1.0*time)+p.x*sqrt(r*r+1.0);
20 uv.y = sin(0.6+1.1*time)+p.y*sqrt(r*r+1.0);
21
22 return texture2D(u_tex0,uv*.5).xyz;
23}
24 42
25void main(void) 43void main(void)
26{ 44{
27 vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / u_resolution.xy; 45 vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / u_resolution.xy;
28 //vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / vec2(500,500).xy;
29 vec2 s = p; 46 vec2 s = p;
30 47
31 vec3 total = vec3(0.0); 48 float time = u_time * u_speed;
32 vec2 d = (vec2(0.0,0.0)-p)/40.0; 49 float c1 = 1.1*time, c2 = 1.2*time, c3 = 0.6+1.1*time;
33 float w = 1.0; 50 float sc3 = sin(c3), st = sin(time);
34 for( int i=0; i<40; i++ ) 51
52 const float iterCount = 40.0;
53 const int iIterCount = int( iterCount );
54
55 vec3 sum = vec3(0.0);
56 vec2 delta = -p/iterCount;
57 vec2 uv;
58 for( int i=0; i<iIterCount; i++ )
35 { 59 {
36 vec3 res = deform(s); 60 vec2 q = vec2( sin(c1 + s.x), sin(c2 + s.y) );
61 float a = atan(q.y,q.x);
62 float rsq = abs(dot(q,q)) + 1.0;
63 uv.x = st + s.x*rsq;
64 uv.y = sc3 + s.y*rsq;
65 vec3 res = texture2D(u_tex0, uv*.5).xyz;
66
37 res = smoothstep(0.1,1.0,res*res); 67 res = smoothstep(0.1,1.0,res*res);
38 total += w*res; 68 sum += res;
39 w *= .99; 69 s += delta;
40 s += d;
41 } 70 }
42 total /= 40.0; 71 sum /= iterCount;
43 float r = 1.5/(1.0+dot(p,p)); 72 float r = 1.5/(1.0+dot(p,p));
44 73
45 gl_FragColor = vec4( total*r,1.0); 74 gl_FragColor = vec4( sum*r, 1.0);
46} \ No newline at end of file 75} \ No newline at end of file
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index 0f6f6c92..e8571e9d 100755
--- a/js/lib/rdge/materials/material.js
+++ b/js/lib/rdge/materials/material.js
@@ -57,7 +57,7 @@ var Material = function GLMaterial( world ) {
57 // vertex deformation variables 57 // vertex deformation variables
58 this._hasVertexDeformation = false; 58 this._hasVertexDeformation = false;
59 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) 59 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax)
60 this._vertexDeformationTolerance = 0.02; 60 this._vertexDeformationTolerance = 0.1;
61 61
62 // RDGE variables 62 // RDGE variables
63 this._shader = null; 63 this._shader = null;
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js
index 73e344d5..929dffa6 100644
--- a/js/lib/rdge/materials/taper-material.js
+++ b/js/lib/rdge/materials/taper-material.js
@@ -61,7 +61,7 @@ var TaperMaterial = function TaperMaterial()
61 61
62 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 62 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
63 this._hasVertexDeformation = true; 63 this._hasVertexDeformation = true;
64 this._vertexDeformationTolerance = 0.02; // should be a property 64 this._vertexDeformationTolerance = 0.1; // should be a property
65 65
66 this.getVertexDeformationTolerance = function() { return this._propValues[this._propNames[7]]; }; 66 this.getVertexDeformationTolerance = function() { return this._propValues[this._propNames[7]]; };
67 67
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index 57ef23ea..c7e7dcc8 100644
--- a/js/lib/rdge/materials/twist-vert-material.js
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -65,7 +65,7 @@ var TwistVertMaterial = function TwistVertMaterial()
65 65
66 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 66 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
67 this._hasVertexDeformation = true; 67 this._hasVertexDeformation = true;
68 this._vertexDeformationTolerance = 0.02; // should be a property 68 this._vertexDeformationTolerance = 0.1; // should be a property
69 69
70 /////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////
71 // Material Property Accessors 71 // Material Property Accessors