فهرست منبع

Merge remote-tracking branch 'remotes/zz85/experimental' into dev

alteredq 14 سال پیش
والد
کامیت
20648b2053
3فایلهای تغییر یافته به همراه122 افزوده شده و 10 حذف شده
  1. 106 1
      examples/js/ShaderExtras.js
  2. 15 8
      examples/webgl_particles_shapes.html
  3. 1 1
      src/extras/core/Path.js

+ 106 - 1
examples/js/ShaderExtras.js

@@ -772,7 +772,7 @@ THREE.ShaderExtras = {
 
 		fragmentShader: [
 
-		"#define ITERATIONS 20.0",
+		"#define ITERATIONS 10.0",
 
 		"uniform sampler2D texture;",
 		"uniform vec2 delta;",
@@ -845,6 +845,111 @@ THREE.ShaderExtras = {
 
 	},
 
+	/* --------------------------------------------------------------------------------------------------
+	//	Vertical and Horizontal blur shaders
+	//	- described in from http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/
+	//		and used in www.cake23.de/traveling-wavefronts-lit-up.html
+	 -------------------------------------------------------------------------------------------------- */
+	
+	
+	'horizontalBlur': {
+
+		uniforms: {
+			"tDiffuse": { type: "t", value: 0, texture: null },
+			"h": { type: "f", value: 1.0/512.0 }
+		},
+
+		vertexShader: [
+
+			"varying vec2 vUv;",
+
+			"void main() {",
+
+				"vUv = vec2( uv.x, 1.0 - uv.y );",
+				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
+
+			"}"
+
+		].join("\n"),
+
+		fragmentShader: [
+		
+			// original shader from http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/
+			// horizontal blur fragment shader
+			"uniform sampler2D tDiffuse;",
+			"varying vec2 vUv;",
+			"uniform float h;",
+			"void main(void)", // fragment
+			"{",
+				//"float h = 1.0/512.0;",
+				"vec4 sum = vec4(0.0);",
+				"sum += texture2D(tDiffuse, vec2(vUv.x - 4.0*h, vUv.y) ) * 0.05;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x - 3.0*h, vUv.y) ) * 0.09;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x - 2.0*h, vUv.y) ) * 0.12;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x - 1.0*h, vUv.y) ) * 0.15;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x + 0.0*h, vUv.y) ) * 0.16;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x + 1.0*h, vUv.y) ) * 0.15;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x + 2.0*h, vUv.y) ) * 0.12;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x + 3.0*h, vUv.y) ) * 0.09;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x + 4.0*h, vUv.y) ) * 0.05;",
+				"gl_FragColor = sum; ",
+			    // "gl_FragColor.xyz = sum.xyz/0.98;", // normalize
+			    // 	"gl_FragColor.a = 1.;",
+			"}"
+			
+
+		].join("\n")
+
+	},
+	
+	'verticalBlur': {
+
+		uniforms: {
+			"tDiffuse": { type: "t", value: 0, texture: null },
+			"v": { type: "f", value: 1.0/512.0 }
+		},
+
+		vertexShader: [
+
+			"varying vec2 vUv;",
+
+			"void main() {",
+
+				"vUv = vec2( uv.x, 1.0 - uv.y );",
+				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
+
+			"}"
+
+		].join("\n"),
+
+		fragmentShader: [
+			"uniform sampler2D tDiffuse;",
+			"varying vec2 vUv;",
+			"uniform float v;",
+			
+			"void main(void)", // fragment
+			"{",
+				//"float v = pixelSize.y;",
+				"vec4 sum = vec4(0.0);",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, - 4.0*v + vUv.y) ) * 0.05;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, - 3.0*v + vUv.y) ) * 0.09;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, - 2.0*v + vUv.y) ) * 0.12;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, - 1.0*v + vUv.y) ) * 0.15;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, + 0.0*v + vUv.y) ) * 0.16;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, + 1.0*v + vUv.y) ) * 0.15;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, + 2.0*v + vUv.y) ) * 0.12;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, + 3.0*v + vUv.y) ) * 0.09;",
+				"sum += texture2D(tDiffuse, vec2(vUv.x, + 4.0*v + vUv.y) ) * 0.05;",
+				"gl_FragColor = sum;",
+			    //"gl_FragColor.xyz = sum.xyz/0.98;",
+				//"gl_FragColor.a = 1.;",
+			"}"
+			
+
+		].join("\n")
+
+	},
+
 	// METHODS
 
 	buildKernel: function( sigma ) {

+ 15 - 8
examples/webgl_particles_shapes.html

@@ -316,8 +316,6 @@
 
 					context.fill();
 
-					//var idata =context.getImageData(0, 0, canvas.width, canvas.height);
-					//document.body.appendChild(canvas);
 					return canvas;
 
 				}
@@ -517,6 +515,13 @@
 				var radius = 15;
 				var blurAmountX = radius / window.innerWidth;
 				var blurAmountY = radius / window.innerHeight;
+				
+				var hblur = new THREE.ShaderPass( THREE.ShaderExtras[ "horizontalBlur" ] );
+				var vblur = new THREE.ShaderPass( THREE.ShaderExtras[ "verticalBlur" ] );
+				
+				hblur.uniforms['h'].value =  1 / window.innerWidth;
+				vblur.uniforms['v'].value =  1 / window.innerHeight;
+				
 
 				effectBlurX.uniforms['delta'].value = new THREE.Vector2( blurAmountX, 0 );
 				effectBlurY.uniforms['delta'].value = new THREE.Vector2( 0, blurAmountY );
@@ -528,14 +533,16 @@
 
 				composer = new THREE.EffectComposer( renderer );
 				composer.addPass( renderScene );
-				//composer.addPass( effectBlurX );
-				//composer.addPass( effectBlurY );
-				//composer.addPass( effectScreen );
-				composer.addPass( effectFocus );
+				//composer.addPass( hblur );
+				//composer.addPass( vblur );
+				composer.addPass( effectBlurX );
+				composer.addPass( effectBlurY ); 
+				//composer.addPass( effectScreen ); 
+				//composer.addPass( effectFocus );
 				//composer.addPass( effectFilm );
 
-				//effectBlurY.renderToScreen = true;
-
+				vblur.renderToScreen = true;
+				effectBlurY.renderToScreen = true;
 				effectFocus.renderToScreen = true;
 				effectScreen.renderToScreen = true;
 				effectFilm.renderToScreen = true;

+ 1 - 1
src/extras/core/Path.js

@@ -123,7 +123,7 @@ THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
 
 	var x0 = lastargs[ lastargs.length - 2 ];
 	var y0 = lastargs[ lastargs.length - 1 ];
-
+//---
 	var npts = [ new THREE.Vector2( x0, y0 ) ];
 	npts =  npts.concat( pts );