mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-25 20:33:50 +01:00
92 lines
2.4 KiB
JavaScript
92 lines
2.4 KiB
JavaScript
|
/**
|
||
|
* @author alteredq / http://alteredqualia.com/
|
||
|
*
|
||
|
* Focus shader
|
||
|
* based on PaintEffect postprocess from ro.me
|
||
|
* http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js
|
||
|
*/
|
||
|
|
||
|
THREE.FocusShader = {
|
||
|
|
||
|
uniforms : {
|
||
|
|
||
|
"tDiffuse": { type: "t", value: null },
|
||
|
"screenWidth": { type: "f", value: 1024 },
|
||
|
"screenHeight": { type: "f", value: 1024 },
|
||
|
"sampleDistance": { type: "f", value: 0.94 },
|
||
|
"waveFactor": { type: "f", value: 0.00125 }
|
||
|
|
||
|
},
|
||
|
|
||
|
vertexShader: [
|
||
|
|
||
|
"varying vec2 vUv;",
|
||
|
|
||
|
"void main() {",
|
||
|
|
||
|
"vUv = uv;",
|
||
|
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
|
||
|
|
||
|
"}"
|
||
|
|
||
|
].join("\n"),
|
||
|
|
||
|
fragmentShader: [
|
||
|
|
||
|
"uniform float screenWidth;",
|
||
|
"uniform float screenHeight;",
|
||
|
"uniform float sampleDistance;",
|
||
|
"uniform float waveFactor;",
|
||
|
|
||
|
"uniform sampler2D tDiffuse;",
|
||
|
|
||
|
"varying vec2 vUv;",
|
||
|
|
||
|
"void main() {",
|
||
|
|
||
|
"vec4 color, org, tmp, add;",
|
||
|
"float sample_dist, f;",
|
||
|
"vec2 vin;",
|
||
|
"vec2 uv = vUv;",
|
||
|
|
||
|
"add = color = org = texture2D( tDiffuse, uv );",
|
||
|
|
||
|
"vin = ( uv - vec2( 0.5 ) ) * vec2( 1.4 );",
|
||
|
"sample_dist = dot( vin, vin ) * 2.0;",
|
||
|
|
||
|
"f = ( waveFactor * 100.0 + sample_dist ) * sampleDistance * 4.0;",
|
||
|
|
||
|
"vec2 sampleSize = vec2( 1.0 / screenWidth, 1.0 / screenHeight ) * vec2( f );",
|
||
|
|
||
|
"add += tmp = texture2D( tDiffuse, uv + vec2( 0.111964, 0.993712 ) * sampleSize );",
|
||
|
"if( tmp.b < color.b ) color = tmp;",
|
||
|
|
||
|
"add += tmp = texture2D( tDiffuse, uv + vec2( 0.846724, 0.532032 ) * sampleSize );",
|
||
|
"if( tmp.b < color.b ) color = tmp;",
|
||
|
|
||
|
"add += tmp = texture2D( tDiffuse, uv + vec2( 0.943883, -0.330279 ) * sampleSize );",
|
||
|
"if( tmp.b < color.b ) color = tmp;",
|
||
|
|
||
|
"add += tmp = texture2D( tDiffuse, uv + vec2( 0.330279, -0.943883 ) * sampleSize );",
|
||
|
"if( tmp.b < color.b ) color = tmp;",
|
||
|
|
||
|
"add += tmp = texture2D( tDiffuse, uv + vec2( -0.532032, -0.846724 ) * sampleSize );",
|
||
|
"if( tmp.b < color.b ) color = tmp;",
|
||
|
|
||
|
"add += tmp = texture2D( tDiffuse, uv + vec2( -0.993712, -0.111964 ) * sampleSize );",
|
||
|
"if( tmp.b < color.b ) color = tmp;",
|
||
|
|
||
|
"add += tmp = texture2D( tDiffuse, uv + vec2( -0.707107, 0.707107 ) * sampleSize );",
|
||
|
"if( tmp.b < color.b ) color = tmp;",
|
||
|
|
||
|
"color = color * vec4( 2.0 ) - ( add / vec4( 8.0 ) );",
|
||
|
"color = color + ( add / vec4( 8.0 ) - color ) * ( vec4( 1.0 ) - vec4( sample_dist * 0.5 ) );",
|
||
|
|
||
|
"gl_FragColor = vec4( color.rgb * color.rgb * vec3( 0.95 ) + color.rgb, 1.0 );",
|
||
|
|
||
|
"}"
|
||
|
|
||
|
|
||
|
].join("\n")
|
||
|
};
|