提交 5007d229 编写于 作者: M Mugen87

JSM: Added modules and TS files for most shaders.

上级 0198829e
......@@ -176,11 +176,48 @@
</li>
<li>shaders
<ul>
<li>AfterimageShader</li>
<li>BasicShader</li>
<li>BleachBypassShader</li>
<li>BlendShader</li>
<li>BokehShader</li>
<li>BokehShader2</li>
<li>BrightnessContrastShader</li>
<li>ColorCorrectionShader</li>
<li>ColorifyShader</li>
<li>ConvolutionShader</li>
<li>CopyShader</li>
<li>DepthLimitedBlurShader</li>
<li>DigitalGlitch</li>
<li>DOFMipMapShader</li>
<li>DotScreenShader</li>
<li>FilmShader</li>
<li>FocusShader</li>
<li>FreiChenShader</li>
<li>FresnelShader</li>
<li>FXAAShader</li>
<li>GammaCorrectionShader</li>
<li>HalftoneShader</li>
<li>HorizontalBlurShader</li>
<li>HorizontalTiltShiftShader</li>
<li>HueSaturationShader</li>
<li>KaleidoShader</li>
<li>LuminosityHighPassShader</li>
<li>LuminosityShader</li>
<li>MirrorShader</li>
<li>NormalMapShader</li>
<li>ParallaxShader</li>
<li>PixelShader</li>
<li>RGBShiftShader</li>
<li>SAOShader</li>
<li>SepiaShader</li>
<li>SobelOperatorShader</li>
<li>SSAOShader</li>
<li>TechnicolorShader</li>
<li>UnpackDepthRGBAShader</li>
<li>VerticalBlurShader</li>
<li>VerticalTiltShiftShader</li>
<li>VignetteShader</li>
<li>WaterRefractionShader</li>
</ul>
</li>
......
/**
* TODO
*/
THREE.DepthLimitedBlurShader = {
defines: {
'KERNEL_RADIUS': 4,
......
......@@ -14,14 +14,14 @@ THREE.DigitalGlitch = {
uniforms: {
"tDiffuse": { value: null },//diffuse texture
"tDisp": { value: null },//displacement texture for digital glitch squares
"byp": { value: 0 },//apply the glitch ?
"tDiffuse": { value: null }, //diffuse texture
"tDisp": { value: null }, //displacement texture for digital glitch squares
"byp": { value: 0 }, //apply the glitch ?
"amount": { value: 0.08 },
"angle": { value: 0.02 },
"seed": { value: 0.02 },
"seed_x": { value: 0.02 },//-1,1
"seed_y": { value: 0.02 },//-1,1
"seed_x": { value: 0.02 }, //-1,1
"seed_y": { value: 0.02 }, //-1,1
"distortion_x": { value: 0.5 },
"distortion_y": { value: 0.6 },
"col_s": { value: 0.05 }
......
......@@ -8,7 +8,7 @@
THREE.FocusShader = {
uniforms : {
uniforms: {
"tDiffuse": { value: null },
"screenWidth": { value: 1024 },
......
/**
* TODO
*/
THREE.SAOShader = {
defines: {
'NUM_SAMPLES': 7,
......
import {
Uniform
} from '../../../src/Three';
export interface AfterimageShader {
uniforms: {
damp: Uniform;
tOld: Uniform;
tNew: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author HypnosNova / https://www.threejs.org.cn/gallery/
*
* Afterimage shader
* I created this effect inspired by a demo on codepen:
* https://codepen.io/brunoimbrizi/pen/MoRJaN?page=1&
*/
var AfterimageShader = {
uniforms: {
"damp": { value: 0.96 },
"tOld": { value: null },
"tNew": { value: null }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform float damp;",
"uniform sampler2D tOld;",
"uniform sampler2D tNew;",
"varying vec2 vUv;",
"vec4 when_gt( vec4 x, float y ) {",
"return max( sign( x - y ), 0.0 );",
"}",
"void main() {",
"vec4 texelOld = texture2D( tOld, vUv );",
"vec4 texelNew = texture2D( tNew, vUv );",
"texelOld *= damp * when_gt( texelOld, 0.1 );",
"gl_FragColor = max(texelNew, texelOld);",
"}"
].join( "\n" )
};
export { AfterimageShader };
import {
Uniform
} from '../../../src/Three';
export interface BasicShader {
uniforms: {};
vertexShader: string;
fragmentShader: string;
}
/**
* @author mrdoob / http://www.mrdoob.com
*
* Simple test shader
*/
var BasicShader = {
uniforms: {},
vertexShader: [
"void main() {",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"void main() {",
"gl_FragColor = vec4( 1.0, 0.0, 0.0, 0.5 );",
"}"
].join( "\n" )
};
export { BasicShader };
import {
Uniform
} from '../../../src/Three';
export interface BleachBypassShader {
uniforms: {
tDiffuse: Uniform;
opacity: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Bleach bypass shader [http://en.wikipedia.org/wiki/Bleach_bypass]
* - based on Nvidia example
* http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html#post_bleach_bypass
*/
var BleachBypassShader = {
uniforms: {
"tDiffuse": { value: null },
"opacity": { value: 1.0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform float opacity;",
"uniform sampler2D tDiffuse;",
"varying vec2 vUv;",
"void main() {",
"vec4 base = texture2D( tDiffuse, vUv );",
"vec3 lumCoeff = vec3( 0.25, 0.65, 0.1 );",
"float lum = dot( lumCoeff, base.rgb );",
"vec3 blend = vec3( lum );",
"float L = min( 1.0, max( 0.0, 10.0 * ( lum - 0.45 ) ) );",
"vec3 result1 = 2.0 * base.rgb * blend;",
"vec3 result2 = 1.0 - 2.0 * ( 1.0 - blend ) * ( 1.0 - base.rgb );",
"vec3 newColor = mix( result1, result2, L );",
"float A2 = opacity * base.a;",
"vec3 mixRGB = A2 * newColor.rgb;",
"mixRGB += ( ( 1.0 - A2 ) * base.rgb );",
"gl_FragColor = vec4( mixRGB, base.a );",
"}"
].join( "\n" )
};
export { BleachBypassShader };
import {
Uniform
} from '../../../src/Three';
export interface BlendShader {
uniforms: {
tDiffuse1: Uniform;
tDiffuse2: Uniform;
mixRatio: Uniform;
opacity: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Blend two textures
*/
var BlendShader = {
uniforms: {
"tDiffuse1": { value: null },
"tDiffuse2": { value: null },
"mixRatio": { value: 0.5 },
"opacity": { value: 1.0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform float opacity;",
"uniform float mixRatio;",
"uniform sampler2D tDiffuse1;",
"uniform sampler2D tDiffuse2;",
"varying vec2 vUv;",
"void main() {",
"vec4 texel1 = texture2D( tDiffuse1, vUv );",
"vec4 texel2 = texture2D( tDiffuse2, vUv );",
"gl_FragColor = opacity * mix( texel1, texel2, mixRatio );",
"}"
].join( "\n" )
};
export { BlendShader };
import {
Uniform
} from '../../../src/Three';
export interface BokehShader {
defines: {
DEPTH_PACKING: number;
PERSPECTIVE_CAMERA: number;
}
uniforms: {
tColor: Uniform;
tDepth: Uniform;
focus: Uniform;
aspect: Uniform;
aperture: Uniform;
maxblur: Uniform;
nearClip: Uniform;
farClip: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Depth-of-field shader with bokeh
* ported from GLSL shader by Martins Upitis
* http://artmartinsh.blogspot.com/2010/02/glsl-lens-blur-filter-with-bokeh.html
*/
var BokehShader = {
defines: {
"DEPTH_PACKING": 1,
"PERSPECTIVE_CAMERA": 1,
},
uniforms: {
"tColor": { value: null },
"tDepth": { value: null },
"focus": { value: 1.0 },
"aspect": { value: 1.0 },
"aperture": { value: 0.025 },
"maxblur": { value: 1.0 },
"nearClip": { value: 1.0 },
"farClip": { value: 1000.0 },
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"#include <common>",
"varying vec2 vUv;",
"uniform sampler2D tColor;",
"uniform sampler2D tDepth;",
"uniform float maxblur;", // max blur amount
"uniform float aperture;", // aperture - bigger values for shallower depth of field
"uniform float nearClip;",
"uniform float farClip;",
"uniform float focus;",
"uniform float aspect;",
"#include <packing>",
"float getDepth( const in vec2 screenPosition ) {",
" #if DEPTH_PACKING == 1",
" return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );",
" #else",
" return texture2D( tDepth, screenPosition ).x;",
" #endif",
"}",
"float getViewZ( const in float depth ) {",
" #if PERSPECTIVE_CAMERA == 1",
" return perspectiveDepthToViewZ( depth, nearClip, farClip );",
" #else",
" return orthographicDepthToViewZ( depth, nearClip, farClip );",
" #endif",
"}",
"void main() {",
"vec2 aspectcorrect = vec2( 1.0, aspect );",
"float viewZ = getViewZ( getDepth( vUv ) );",
"float factor = ( focus + viewZ );", // viewZ is <= 0, so this is a difference equation
"vec2 dofblur = vec2 ( clamp( factor * aperture, -maxblur, maxblur ) );",
"vec2 dofblur9 = dofblur * 0.9;",
"vec2 dofblur7 = dofblur * 0.7;",
"vec2 dofblur4 = dofblur * 0.4;",
"vec4 col = vec4( 0.0 );",
"col += texture2D( tColor, vUv.xy );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.15, 0.37 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.37, 0.15 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.40, 0.0 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.37, -0.15 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.15, -0.37 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.15, 0.37 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.37, 0.15 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.37, -0.15 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.15, -0.37 ) * aspectcorrect ) * dofblur );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.15, 0.37 ) * aspectcorrect ) * dofblur9 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.37, 0.15 ) * aspectcorrect ) * dofblur9 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.37, -0.15 ) * aspectcorrect ) * dofblur9 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.15, -0.37 ) * aspectcorrect ) * dofblur9 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.15, 0.37 ) * aspectcorrect ) * dofblur9 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.37, 0.15 ) * aspectcorrect ) * dofblur9 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.37, -0.15 ) * aspectcorrect ) * dofblur9 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.15, -0.37 ) * aspectcorrect ) * dofblur9 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur7 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.40, 0.0 ) * aspectcorrect ) * dofblur7 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur7 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur7 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur7 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur7 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur7 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur7 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur4 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.4, 0.0 ) * aspectcorrect ) * dofblur4 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur4 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur4 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur4 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur4 );",
"col += texture2D( tColor, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur4 );",
"col += texture2D( tColor, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur4 );",
"gl_FragColor = col / 41.0;",
"gl_FragColor.a = 1.0;",
"}"
].join( "\n" )
};
export { BokehShader };
......@@ -29,7 +29,7 @@ export interface BokehShader {
focusCoords: Uniform;
};
vertexShader: string;
fragmentShader:string;
fragmentShader: string;
}
export interface BokehDepthShader {
......@@ -38,5 +38,5 @@ export interface BokehDepthShader {
mFar: Uniform;
};
vertexShader: string;
fragmentShader:string;
fragmentShader: string;
}
import {
Uniform
} from '../../../src/Three';
export interface BrightnessContrastShader {
uniforms: {
tDiffuse: Uniform;
brightness: Uniform;
contrast: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author tapio / http://tapio.github.com/
*
* Brightness and contrast adjustment
* https://github.com/evanw/glfx.js
* brightness: -1 to 1 (-1 is solid black, 0 is no change, and 1 is solid white)
* contrast: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast)
*/
var BrightnessContrastShader = {
uniforms: {
"tDiffuse": { value: null },
"brightness": { value: 0 },
"contrast": { value: 0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform float brightness;",
"uniform float contrast;",
"varying vec2 vUv;",
"void main() {",
"gl_FragColor = texture2D( tDiffuse, vUv );",
"gl_FragColor.rgb += brightness;",
"if (contrast > 0.0) {",
"gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5;",
"} else {",
"gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;",
"}",
"}"
].join( "\n" )
};
export { BrightnessContrastShader };
import {
Uniform
} from '../../../src/Three';
export interface ColorCorrectionShader {
uniforms: {
tDiffuse: Uniform;
powRGB: Uniform;
mulRGB: Uniform;
addRGB: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Color correction
*/
import {
Vector3
} from "../../../build/three.module.js";
var ColorCorrectionShader = {
uniforms: {
"tDiffuse": { value: null },
"powRGB": { value: new Vector3( 2, 2, 2 ) },
"mulRGB": { value: new Vector3( 1, 1, 1 ) },
"addRGB": { value: new Vector3( 0, 0, 0 ) }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform vec3 powRGB;",
"uniform vec3 mulRGB;",
"uniform vec3 addRGB;",
"varying vec2 vUv;",
"void main() {",
"gl_FragColor = texture2D( tDiffuse, vUv );",
"gl_FragColor.rgb = mulRGB * pow( ( gl_FragColor.rgb + addRGB ), powRGB );",
"}"
].join( "\n" )
};
export { ColorCorrectionShader };
import {
Uniform
} from '../../../src/Three';
export interface ColorifyShader {
uniforms: {
tDiffuse: Uniform;
color: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Colorify shader
*/
import {
Color
} from "../../../build/three.module.js";
var ColorifyShader = {
uniforms: {
"tDiffuse": { value: null },
"color": { value: new Color( 0xffffff ) }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform vec3 color;",
"uniform sampler2D tDiffuse;",
"varying vec2 vUv;",
"void main() {",
"vec4 texel = texture2D( tDiffuse, vUv );",
"vec3 luma = vec3( 0.299, 0.587, 0.114 );",
"float v = dot( texel.xyz, luma );",
"gl_FragColor = vec4( v * color, texel.w );",
"}"
].join( "\n" )
};
export { ColorifyShader };
import {
Uniform
} from '../../../src/Three';
export interface ConvolutionShader {
defines: {
KERNEL_SIZE_FLOAT: string;
KERNEL_SIZE_INT: string;
},
uniforms: {
tDiffuse: Uniform;
uImageIncrement: Uniform;
cKernel: Uniform;
};
vertexShader: string;
fragmentShader: string;
buildKernel(sigma: number): number[];
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Convolution shader
* ported from o3d sample to WebGL / GLSL
* http://o3d.googlecode.com/svn/trunk/samples/convolution.html
*/
import {
Vector2
} from "../../../build/three.module.js";
var ConvolutionShader = {
defines: {
"KERNEL_SIZE_FLOAT": "25.0",
"KERNEL_SIZE_INT": "25"
},
uniforms: {
"tDiffuse": { value: null },
"uImageIncrement": { value: new Vector2( 0.001953125, 0.0 ) },
"cKernel": { value: [] }
},
vertexShader: [
"uniform vec2 uImageIncrement;",
"varying vec2 vUv;",
"void main() {",
"vUv = uv - ( ( KERNEL_SIZE_FLOAT - 1.0 ) / 2.0 ) * uImageIncrement;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform float cKernel[ KERNEL_SIZE_INT ];",
"uniform sampler2D tDiffuse;",
"uniform vec2 uImageIncrement;",
"varying vec2 vUv;",
"void main() {",
"vec2 imageCoord = vUv;",
"vec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );",
"for( int i = 0; i < KERNEL_SIZE_INT; i ++ ) {",
"sum += texture2D( tDiffuse, imageCoord ) * cKernel[ i ];",
"imageCoord += uImageIncrement;",
"}",
"gl_FragColor = sum;",
"}"
].join( "\n" ),
buildKernel: function ( sigma ) {
// We lop off the sqrt(2 * pi) * sigma term, since we're going to normalize anyway.
function gauss( x, sigma ) {
return Math.exp( - ( x * x ) / ( 2.0 * sigma * sigma ) );
}
var i, values, sum, halfWidth, kMaxKernelSize = 25, kernelSize = 2 * Math.ceil( sigma * 3.0 ) + 1;
if ( kernelSize > kMaxKernelSize ) kernelSize = kMaxKernelSize;
halfWidth = ( kernelSize - 1 ) * 0.5;
values = new Array( kernelSize );
sum = 0.0;
for ( i = 0; i < kernelSize; ++ i ) {
values[ i ] = gauss( i - halfWidth, sigma );
sum += values[ i ];
}
// normalize the kernel
for ( i = 0; i < kernelSize; ++ i ) values[ i ] /= sum;
return values;
}
};
export { ConvolutionShader };
......@@ -8,5 +8,5 @@ export interface CopyShader {
opacity: Uniform;
};
vertexShader: string;
fragmentShader:string;
fragmentShader: string;
}
import {
Uniform
} from '../../../src/Three';
export interface DOFMipMapShader {
uniforms: {
tColor: Uniform;
tDepth: Uniform;
focus: Uniform;
maxblur: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Depth-of-field shader using mipmaps
* - from Matt Handley @applmak
* - requires power-of-2 sized render target with enabled mipmaps
*/
var DOFMipMapShader = {
uniforms: {
"tColor": { value: null },
"tDepth": { value: null },
"focus": { value: 1.0 },
"maxblur": { value: 1.0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform float focus;",
"uniform float maxblur;",
"uniform sampler2D tColor;",
"uniform sampler2D tDepth;",
"varying vec2 vUv;",
"void main() {",
"vec4 depth = texture2D( tDepth, vUv );",
"float factor = depth.x - focus;",
"vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );",
"gl_FragColor = col;",
"gl_FragColor.a = 1.0;",
"}"
].join( "\n" )
};
export { DOFMipMapShader };
import {
Uniform,
Vector2,
Material
} from '../../../src/Three';
export interface DepthLimitedBlurShader {
defines: {
KERNEL_RADIUS: number;
DEPTH_PACKING: number;
PERSPECTIVE_CAMERA: number;
};
uniforms: {
tDiffuse: Uniform;
size: Uniform;
sampleUvOffsets: Uniform;
sampleWeights: Uniform;
tDepth: Uniform;
cameraNear: Uniform;
cameraFar: Uniform;
depthCutoff: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
export interface BlurShaderUtils {
createSampleWeights(kernelRadius: number, stdDev: number): number[];
createSampleOffsets(kernelRadius: number, uvIncrement: Vector2): Vector2[];
configure(configure: Material, kernelRadius: number, stdDev: number, uvIncrement: Vector2): void;
}
/**
* TODO
*/
import {
Vector2
} from "../../../build/three.module.js";
var DepthLimitedBlurShader = {
defines: {
'KERNEL_RADIUS': 4,
'DEPTH_PACKING': 1,
'PERSPECTIVE_CAMERA': 1
},
uniforms: {
'tDiffuse': { value: null },
'size': { value: new Vector2( 512, 512 ) },
'sampleUvOffsets': { value: [ new Vector2( 0, 0 ) ] },
'sampleWeights': { value: [ 1.0 ] },
'tDepth': { value: null },
'cameraNear': { value: 10 },
'cameraFar': { value: 1000 },
'depthCutoff': { value: 10 },
},
vertexShader: [
"#include <common>",
"uniform vec2 size;",
"varying vec2 vUv;",
"varying vec2 vInvSize;",
"void main() {",
" vUv = uv;",
" vInvSize = 1.0 / size;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"#include <common>",
"#include <packing>",
"uniform sampler2D tDiffuse;",
"uniform sampler2D tDepth;",
"uniform float cameraNear;",
"uniform float cameraFar;",
"uniform float depthCutoff;",
"uniform vec2 sampleUvOffsets[ KERNEL_RADIUS + 1 ];",
"uniform float sampleWeights[ KERNEL_RADIUS + 1 ];",
"varying vec2 vUv;",
"varying vec2 vInvSize;",
"float getDepth( const in vec2 screenPosition ) {",
" #if DEPTH_PACKING == 1",
" return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );",
" #else",
" return texture2D( tDepth, screenPosition ).x;",
" #endif",
"}",
"float getViewZ( const in float depth ) {",
" #if PERSPECTIVE_CAMERA == 1",
" return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );",
" #else",
" return orthographicDepthToViewZ( depth, cameraNear, cameraFar );",
" #endif",
"}",
"void main() {",
" float depth = getDepth( vUv );",
" if( depth >= ( 1.0 - EPSILON ) ) {",
" discard;",
" }",
" float centerViewZ = -getViewZ( depth );",
" bool rBreak = false, lBreak = false;",
" float weightSum = sampleWeights[0];",
" vec4 diffuseSum = texture2D( tDiffuse, vUv ) * weightSum;",
" for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {",
" float sampleWeight = sampleWeights[i];",
" vec2 sampleUvOffset = sampleUvOffsets[i] * vInvSize;",
" vec2 sampleUv = vUv + sampleUvOffset;",
" float viewZ = -getViewZ( getDepth( sampleUv ) );",
" if( abs( viewZ - centerViewZ ) > depthCutoff ) rBreak = true;",
" if( ! rBreak ) {",
" diffuseSum += texture2D( tDiffuse, sampleUv ) * sampleWeight;",
" weightSum += sampleWeight;",
" }",
" sampleUv = vUv - sampleUvOffset;",
" viewZ = -getViewZ( getDepth( sampleUv ) );",
" if( abs( viewZ - centerViewZ ) > depthCutoff ) lBreak = true;",
" if( ! lBreak ) {",
" diffuseSum += texture2D( tDiffuse, sampleUv ) * sampleWeight;",
" weightSum += sampleWeight;",
" }",
" }",
" gl_FragColor = diffuseSum / weightSum;",
"}"
].join( "\n" )
};
var BlurShaderUtils = {
createSampleWeights: function ( kernelRadius, stdDev ) {
var gaussian = function ( x, stdDev ) {
return Math.exp( - ( x * x ) / ( 2.0 * ( stdDev * stdDev ) ) ) / ( Math.sqrt( 2.0 * Math.PI ) * stdDev );
};
var weights = [];
for ( var i = 0; i <= kernelRadius; i ++ ) {
weights.push( gaussian( i, stdDev ) );
}
return weights;
},
createSampleOffsets: function ( kernelRadius, uvIncrement ) {
var offsets = [];
for ( var i = 0; i <= kernelRadius; i ++ ) {
offsets.push( uvIncrement.clone().multiplyScalar( i ) );
}
return offsets;
},
configure: function ( material, kernelRadius, stdDev, uvIncrement ) {
material.defines[ 'KERNEL_RADIUS' ] = kernelRadius;
material.uniforms[ 'sampleUvOffsets' ].value = BlurShaderUtils.createSampleOffsets( kernelRadius, uvIncrement );
material.uniforms[ 'sampleWeights' ].value = BlurShaderUtils.createSampleWeights( kernelRadius, stdDev );
material.needsUpdate = true;
}
};
export { DepthLimitedBlurShader, BlurShaderUtils };
import {
Uniform
} from '../../../src/Three';
export interface DigitalGlitch {
uniforms: {
tDiffuse: Uniform;
tDisp: Uniform;
byp: Uniform;
amount: Uniform;
angle: Uniform;
seed: Uniform;
seed_x: Uniform;
seed_y: Uniform;
distortion_x: Uniform;
distortion_y: Uniform;
col_s: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author felixturner / http://airtight.cc/
*
* RGB Shift Shader
* Shifts red and blue channels from center in opposite directions
* Ported from http://kriss.cx/tom/2009/05/rgb-shift/
* by Tom Butterworth / http://kriss.cx/tom/
*
* amount: shift distance (1 is width of input)
* angle: shift angle in radians
*/
var DigitalGlitch = {
uniforms: {
"tDiffuse": { value: null }, //diffuse texture
"tDisp": { value: null }, //displacement texture for digital glitch squares
"byp": { value: 0 }, //apply the glitch ?
"amount": { value: 0.08 },
"angle": { value: 0.02 },
"seed": { value: 0.02 },
"seed_x": { value: 0.02 }, //-1,1
"seed_y": { value: 0.02 }, //-1,1
"distortion_x": { value: 0.5 },
"distortion_y": { value: 0.6 },
"col_s": { value: 0.05 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform int byp;",//should we apply the glitch ?
"uniform sampler2D tDiffuse;",
"uniform sampler2D tDisp;",
"uniform float amount;",
"uniform float angle;",
"uniform float seed;",
"uniform float seed_x;",
"uniform float seed_y;",
"uniform float distortion_x;",
"uniform float distortion_y;",
"uniform float col_s;",
"varying vec2 vUv;",
"float rand(vec2 co){",
"return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);",
"}",
"void main() {",
"if(byp<1) {",
"vec2 p = vUv;",
"float xs = floor(gl_FragCoord.x / 0.5);",
"float ys = floor(gl_FragCoord.y / 0.5);",
//based on staffantans glitch shader for unity https://github.com/staffantan/unityglitch
"vec4 normal = texture2D (tDisp, p*seed*seed);",
"if(p.y<distortion_x+col_s && p.y>distortion_x-col_s*seed) {",
"if(seed_x>0.){",
"p.y = 1. - (p.y + distortion_y);",
"}",
"else {",
"p.y = distortion_y;",
"}",
"}",
"if(p.x<distortion_y+col_s && p.x>distortion_y-col_s*seed) {",
"if(seed_y>0.){",
"p.x=distortion_x;",
"}",
"else {",
"p.x = 1. - (p.x + distortion_x);",
"}",
"}",
"p.x+=normal.x*seed_x*(seed/5.);",
"p.y+=normal.y*seed_y*(seed/5.);",
//base from RGB shift shader
"vec2 offset = amount * vec2( cos(angle), sin(angle));",
"vec4 cr = texture2D(tDiffuse, p + offset);",
"vec4 cga = texture2D(tDiffuse, p);",
"vec4 cb = texture2D(tDiffuse, p - offset);",
"gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
//add noise
"vec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2);",
"gl_FragColor = gl_FragColor+ snow;",
"}",
"else {",
"gl_FragColor=texture2D (tDiffuse, vUv);",
"}",
"}"
].join( "\n" )
};
export { DigitalGlitch };
......@@ -11,5 +11,5 @@ export interface DotScreenShader {
scale: Uniform;
};
vertexShader: string;
fragmentShader:string;
fragmentShader: string;
}
import {
Uniform
} from '../../../src/Three';
export interface FXAAShader {
uniforms: {
tDiffuse: Uniform;
resolution: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
此差异已折叠。
import {
Uniform
} from '../../../src/Three';
export interface FilmShader {
uniforms: {
tDiffuse: Uniform;
time: Uniform;
nIntensity: Uniform;
sIntensity: Uniform;
sCount: Uniform;
grayscale: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Film grain & scanlines shader
*
* - ported from HLSL to WebGL / GLSL
* http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html
*
* Screen Space Static Postprocessor
*
* Produces an analogue noise overlay similar to a film grain / TV static
*
* Original implementation and noise algorithm
* Pat 'Hawthorne' Shearon
*
* Optimized scanlines + noise version with intensity scaling
* Georg 'Leviathan' Steinrohder
*
* This version is provided under a Creative Commons Attribution 3.0 License
* http://creativecommons.org/licenses/by/3.0/
*/
var FilmShader = {
uniforms: {
"tDiffuse": { value: null },
"time": { value: 0.0 },
"nIntensity": { value: 0.5 },
"sIntensity": { value: 0.05 },
"sCount": { value: 4096 },
"grayscale": { value: 1 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"#include <common>",
// control parameter
"uniform float time;",
"uniform bool grayscale;",
// noise effect intensity value (0 = no effect, 1 = full effect)
"uniform float nIntensity;",
// scanlines effect intensity value (0 = no effect, 1 = full effect)
"uniform float sIntensity;",
// scanlines effect count value (0 = no effect, 4096 = full effect)
"uniform float sCount;",
"uniform sampler2D tDiffuse;",
"varying vec2 vUv;",
"void main() {",
// sample the source
"vec4 cTextureScreen = texture2D( tDiffuse, vUv );",
// make some noise
"float dx = rand( vUv + time );",
// add noise
"vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 );",
// get us a sine and cosine
"vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );",
// add scanlines
"cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;",
// interpolate between source and result by intensity
"cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );",
// convert to grayscale if desired
"if( grayscale ) {",
"cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );",
"}",
"gl_FragColor = vec4( cResult, cTextureScreen.a );",
"}"
].join( "\n" )
};
export { FilmShader };
import {
Uniform
} from '../../../src/Three';
export interface FocusShader {
uniforms: {
tDiffuse: Uniform;
screenWidth: Uniform;
screenHeight: Uniform;
sampleDistance: Uniform;
waveFactor: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @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
*/
var FocusShader = {
uniforms: {
"tDiffuse": { value: null },
"screenWidth": { value: 1024 },
"screenHeight": { value: 1024 },
"sampleDistance": { value: 0.94 },
"waveFactor": { 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" )
};
export { FocusShader };
import {
Uniform
} from '../../../src/Three';
export interface FreiChenShader {
uniforms: {
tDiffuse: Uniform;
aspect: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author zz85 / https://github.com/zz85 | https://www.lab4games.net/zz85/blog
*
* Edge Detection Shader using Frei-Chen filter
* Based on http://rastergrid.com/blog/2011/01/frei-chen-edge-detector
*
* aspect: vec2 of (1/width, 1/height)
*/
import {
Vector2
} from "../../../build/three.module.js";
var FreiChenShader = {
uniforms: {
"tDiffuse": { value: null },
"aspect": { value: new Vector2( 512, 512 ) }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"varying vec2 vUv;",
"uniform vec2 aspect;",
"vec2 texel = vec2(1.0 / aspect.x, 1.0 / aspect.y);",
"mat3 G[9];",
// hard coded matrix values!!!! as suggested in https://github.com/neilmendoza/ofxPostProcessing/blob/master/src/EdgePass.cpp#L45
"const mat3 g0 = mat3( 0.3535533845424652, 0, -0.3535533845424652, 0.5, 0, -0.5, 0.3535533845424652, 0, -0.3535533845424652 );",
"const mat3 g1 = mat3( 0.3535533845424652, 0.5, 0.3535533845424652, 0, 0, 0, -0.3535533845424652, -0.5, -0.3535533845424652 );",
"const mat3 g2 = mat3( 0, 0.3535533845424652, -0.5, -0.3535533845424652, 0, 0.3535533845424652, 0.5, -0.3535533845424652, 0 );",
"const mat3 g3 = mat3( 0.5, -0.3535533845424652, 0, -0.3535533845424652, 0, 0.3535533845424652, 0, 0.3535533845424652, -0.5 );",
"const mat3 g4 = mat3( 0, -0.5, 0, 0.5, 0, 0.5, 0, -0.5, 0 );",
"const mat3 g5 = mat3( -0.5, 0, 0.5, 0, 0, 0, 0.5, 0, -0.5 );",
"const mat3 g6 = mat3( 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.6666666865348816, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204 );",
"const mat3 g7 = mat3( -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, 0.6666666865348816, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408 );",
"const mat3 g8 = mat3( 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408 );",
"void main(void)",
"{",
"G[0] = g0,",
"G[1] = g1,",
"G[2] = g2,",
"G[3] = g3,",
"G[4] = g4,",
"G[5] = g5,",
"G[6] = g6,",
"G[7] = g7,",
"G[8] = g8;",
"mat3 I;",
"float cnv[9];",
"vec3 sample;",
/* fetch the 3x3 neighbourhood and use the RGB vector's length as intensity value */
"for (float i=0.0; i<3.0; i++) {",
"for (float j=0.0; j<3.0; j++) {",
"sample = texture2D(tDiffuse, vUv + texel * vec2(i-1.0,j-1.0) ).rgb;",
"I[int(i)][int(j)] = length(sample);",
"}",
"}",
/* calculate the convolution values for all the masks */
"for (int i=0; i<9; i++) {",
"float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);",
"cnv[i] = dp3 * dp3;",
"}",
"float M = (cnv[0] + cnv[1]) + (cnv[2] + cnv[3]);",
"float S = (cnv[4] + cnv[5]) + (cnv[6] + cnv[7]) + (cnv[8] + M);",
"gl_FragColor = vec4(vec3(sqrt(M/S)), 1.0);",
"}"
].join( "\n" )
};
export { FreiChenShader };
import {
Uniform
} from '../../../src/Three';
export interface FresnelShader {
uniforms: {
mRefractionRatio: Uniform;
mFresnelBias: Uniform;
mFresnelPower: Uniform;
mFresnelScale: Uniform;
tCube: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Based on Nvidia Cg tutorial
*/
var FresnelShader = {
uniforms: {
"mRefractionRatio": { value: 1.02 },
"mFresnelBias": { value: 0.1 },
"mFresnelPower": { value: 2.0 },
"mFresnelScale": { value: 1.0 },
"tCube": { value: null }
},
vertexShader: [
"uniform float mRefractionRatio;",
"uniform float mFresnelBias;",
"uniform float mFresnelScale;",
"uniform float mFresnelPower;",
"varying vec3 vReflect;",
"varying vec3 vRefract[3];",
"varying float vReflectionFactor;",
"void main() {",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
"vec3 worldNormal = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
"vec3 I = worldPosition.xyz - cameraPosition;",
"vReflect = reflect( I, worldNormal );",
"vRefract[0] = refract( normalize( I ), worldNormal, mRefractionRatio );",
"vRefract[1] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.99 );",
"vRefract[2] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.98 );",
"vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), worldNormal ), mFresnelPower );",
"gl_Position = projectionMatrix * mvPosition;",
"}"
].join( "\n" ),
fragmentShader: [
"uniform samplerCube tCube;",
"varying vec3 vReflect;",
"varying vec3 vRefract[3];",
"varying float vReflectionFactor;",
"void main() {",
"vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
"vec4 refractedColor = vec4( 1.0 );",
"refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;",
"refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;",
"refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;",
"gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );",
"}"
].join( "\n" )
};
export { FresnelShader };
import {
Uniform
} from '../../../src/Three';
export interface GammaCorrectionShader {
uniforms: {
tDiffuse: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author WestLangley / http://github.com/WestLangley
*
* Gamma Correction Shader
* http://en.wikipedia.org/wiki/gamma_correction
*/
var GammaCorrectionShader = {
uniforms: {
"tDiffuse": { value: null }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"varying vec2 vUv;",
"void main() {",
"vec4 tex = texture2D( tDiffuse, vec2( vUv.x, vUv.y ) );",
"gl_FragColor = LinearToGamma( tex, float( GAMMA_FACTOR ) );",
"}"
].join( "\n" )
};
export { GammaCorrectionShader };
import {
Uniform
} from '../../../src/Three';
export interface HalftoneShader {
uniforms: {
tDiffuse: Uniform;
shape: Uniform;
radius: Uniform;
rotateR: Uniform;
rotateG: Uniform;
rotateB: Uniform;
scatter: Uniform;
width: Uniform;
height: Uniform;
blending: Uniform;
blendingMode: Uniform;
greyscale: Uniform;
disable: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author meatbags / xavierburrow.com, github/meatbags
*
* RGB Halftone shader for three.js.
* NOTE:
* Shape (1 = Dot, 2 = Ellipse, 3 = Line, 4 = Square)
* Blending Mode (1 = Linear, 2 = Multiply, 3 = Add, 4 = Lighter, 5 = Darker)
*/
var HalftoneShader = {
uniforms: {
"tDiffuse": { value: null },
"shape": { value: 1 },
"radius": { value: 4 },
"rotateR": { value: Math.PI / 12 * 1 },
"rotateG": { value: Math.PI / 12 * 2 },
"rotateB": { value: Math.PI / 12 * 3 },
"scatter": { value: 0 },
"width": { value: 1 },
"height": { value: 1 },
"blending": { value: 1 },
"blendingMode": { value: 1 },
"greyscale": { value: false },
"disable": { value: false }
},
vertexShader: [
"varying vec2 vUV;",
"void main() {",
"vUV = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);",
"}"
].join( "\n" ),
fragmentShader: [
"#define SQRT2_MINUS_ONE 0.41421356",
"#define SQRT2_HALF_MINUS_ONE 0.20710678",
"#define PI2 6.28318531",
"#define SHAPE_DOT 1",
"#define SHAPE_ELLIPSE 2",
"#define SHAPE_LINE 3",
"#define SHAPE_SQUARE 4",
"#define BLENDING_LINEAR 1",
"#define BLENDING_MULTIPLY 2",
"#define BLENDING_ADD 3",
"#define BLENDING_LIGHTER 4",
"#define BLENDING_DARKER 5",
"uniform sampler2D tDiffuse;",
"uniform float radius;",
"uniform float rotateR;",
"uniform float rotateG;",
"uniform float rotateB;",
"uniform float scatter;",
"uniform float width;",
"uniform float height;",
"uniform int shape;",
"uniform bool disable;",
"uniform float blending;",
"uniform int blendingMode;",
"varying vec2 vUV;",
"uniform bool greyscale;",
"const int samples = 8;",
"float blend( float a, float b, float t ) {",
// linear blend
"return a * ( 1.0 - t ) + b * t;",
"}",
"float hypot( float x, float y ) {",
// vector magnitude
"return sqrt( x * x + y * y );",
"}",
"float rand( vec2 seed ){",
// get pseudo-random number
"return fract( sin( dot( seed.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453 );",
"}",
"float distanceToDotRadius( float channel, vec2 coord, vec2 normal, vec2 p, float angle, float rad_max ) {",
// apply shape-specific transforms
"float dist = hypot( coord.x - p.x, coord.y - p.y );",
"float rad = channel;",
"if ( shape == SHAPE_DOT ) {",
"rad = pow( abs( rad ), 1.125 ) * rad_max;",
"} else if ( shape == SHAPE_ELLIPSE ) {",
"rad = pow( abs( rad ), 1.125 ) * rad_max;",
"if ( dist != 0.0 ) {",
"float dot_p = abs( ( p.x - coord.x ) / dist * normal.x + ( p.y - coord.y ) / dist * normal.y );",
"dist = ( dist * ( 1.0 - SQRT2_HALF_MINUS_ONE ) ) + dot_p * dist * SQRT2_MINUS_ONE;",
"}",
"} else if ( shape == SHAPE_LINE ) {",
"rad = pow( abs( rad ), 1.5) * rad_max;",
"float dot_p = ( p.x - coord.x ) * normal.x + ( p.y - coord.y ) * normal.y;",
"dist = hypot( normal.x * dot_p, normal.y * dot_p );",
"} else if ( shape == SHAPE_SQUARE ) {",
"float theta = atan( p.y - coord.y, p.x - coord.x ) - angle;",
"float sin_t = abs( sin( theta ) );",
"float cos_t = abs( cos( theta ) );",
"rad = pow( abs( rad ), 1.4 );",
"rad = rad_max * ( rad + ( ( sin_t > cos_t ) ? rad - sin_t * rad : rad - cos_t * rad ) );",
"}",
"return rad - dist;",
"}",
"struct Cell {",
// grid sample positions
"vec2 normal;",
"vec2 p1;",
"vec2 p2;",
"vec2 p3;",
"vec2 p4;",
"float samp2;",
"float samp1;",
"float samp3;",
"float samp4;",
"};",
"vec4 getSample( vec2 point ) {",
// multi-sampled point
"vec4 tex = texture2D( tDiffuse, vec2( point.x / width, point.y / height ) );",
"float base = rand( vec2( floor( point.x ), floor( point.y ) ) ) * PI2;",
"float step = PI2 / float( samples );",
"float dist = radius * 0.66;",
"for ( int i = 0; i < samples; ++i ) {",
"float r = base + step * float( i );",
"vec2 coord = point + vec2( cos( r ) * dist, sin( r ) * dist );",
"tex += texture2D( tDiffuse, vec2( coord.x / width, coord.y / height ) );",
"}",
"tex /= float( samples ) + 1.0;",
"return tex;",
"}",
"float getDotColour( Cell c, vec2 p, int channel, float angle, float aa ) {",
// get colour for given point
"float dist_c_1, dist_c_2, dist_c_3, dist_c_4, res;",
"if ( channel == 0 ) {",
"c.samp1 = getSample( c.p1 ).r;",
"c.samp2 = getSample( c.p2 ).r;",
"c.samp3 = getSample( c.p3 ).r;",
"c.samp4 = getSample( c.p4 ).r;",
"} else if (channel == 1) {",
"c.samp1 = getSample( c.p1 ).g;",
"c.samp2 = getSample( c.p2 ).g;",
"c.samp3 = getSample( c.p3 ).g;",
"c.samp4 = getSample( c.p4 ).g;",
"} else {",
"c.samp1 = getSample( c.p1 ).b;",
"c.samp3 = getSample( c.p3 ).b;",
"c.samp2 = getSample( c.p2 ).b;",
"c.samp4 = getSample( c.p4 ).b;",
"}",
"dist_c_1 = distanceToDotRadius( c.samp1, c.p1, c.normal, p, angle, radius );",
"dist_c_2 = distanceToDotRadius( c.samp2, c.p2, c.normal, p, angle, radius );",
"dist_c_3 = distanceToDotRadius( c.samp3, c.p3, c.normal, p, angle, radius );",
"dist_c_4 = distanceToDotRadius( c.samp4, c.p4, c.normal, p, angle, radius );",
"res = ( dist_c_1 > 0.0 ) ? clamp( dist_c_1 / aa, 0.0, 1.0 ) : 0.0;",
"res += ( dist_c_2 > 0.0 ) ? clamp( dist_c_2 / aa, 0.0, 1.0 ) : 0.0;",
"res += ( dist_c_3 > 0.0 ) ? clamp( dist_c_3 / aa, 0.0, 1.0 ) : 0.0;",
"res += ( dist_c_4 > 0.0 ) ? clamp( dist_c_4 / aa, 0.0, 1.0 ) : 0.0;",
"res = clamp( res, 0.0, 1.0 );",
"return res;",
"}",
"Cell getReferenceCell( vec2 p, vec2 origin, float grid_angle, float step ) {",
// get containing cell
"Cell c;",
// calc grid
"vec2 n = vec2( cos( grid_angle ), sin( grid_angle ) );",
"float threshold = step * 0.5;",
"float dot_normal = n.x * ( p.x - origin.x ) + n.y * ( p.y - origin.y );",
"float dot_line = -n.y * ( p.x - origin.x ) + n.x * ( p.y - origin.y );",
"vec2 offset = vec2( n.x * dot_normal, n.y * dot_normal );",
"float offset_normal = mod( hypot( offset.x, offset.y ), step );",
"float normal_dir = ( dot_normal < 0.0 ) ? 1.0 : -1.0;",
"float normal_scale = ( ( offset_normal < threshold ) ? -offset_normal : step - offset_normal ) * normal_dir;",
"float offset_line = mod( hypot( ( p.x - offset.x ) - origin.x, ( p.y - offset.y ) - origin.y ), step );",
"float line_dir = ( dot_line < 0.0 ) ? 1.0 : -1.0;",
"float line_scale = ( ( offset_line < threshold ) ? -offset_line : step - offset_line ) * line_dir;",
// get closest corner
"c.normal = n;",
"c.p1.x = p.x - n.x * normal_scale + n.y * line_scale;",
"c.p1.y = p.y - n.y * normal_scale - n.x * line_scale;",
// scatter
"if ( scatter != 0.0 ) {",
"float off_mag = scatter * threshold * 0.5;",
"float off_angle = rand( vec2( floor( c.p1.x ), floor( c.p1.y ) ) ) * PI2;",
"c.p1.x += cos( off_angle ) * off_mag;",
"c.p1.y += sin( off_angle ) * off_mag;",
"}",
// find corners
"float normal_step = normal_dir * ( ( offset_normal < threshold ) ? step : -step );",
"float line_step = line_dir * ( ( offset_line < threshold ) ? step : -step );",
"c.p2.x = c.p1.x - n.x * normal_step;",
"c.p2.y = c.p1.y - n.y * normal_step;",
"c.p3.x = c.p1.x + n.y * line_step;",
"c.p3.y = c.p1.y - n.x * line_step;",
"c.p4.x = c.p1.x - n.x * normal_step + n.y * line_step;",
"c.p4.y = c.p1.y - n.y * normal_step - n.x * line_step;",
"return c;",
"}",
"float blendColour( float a, float b, float t ) {",
// blend colours
"if ( blendingMode == BLENDING_LINEAR ) {",
"return blend( a, b, 1.0 - t );",
"} else if ( blendingMode == BLENDING_ADD ) {",
"return blend( a, min( 1.0, a + b ), t );",
"} else if ( blendingMode == BLENDING_MULTIPLY ) {",
"return blend( a, max( 0.0, a * b ), t );",
"} else if ( blendingMode == BLENDING_LIGHTER ) {",
"return blend( a, max( a, b ), t );",
"} else if ( blendingMode == BLENDING_DARKER ) {",
"return blend( a, min( a, b ), t );",
"} else {",
"return blend( a, b, 1.0 - t );",
"}",
"}",
"void main() {",
"if ( ! disable ) {",
// setup
"vec2 p = vec2( vUV.x * width, vUV.y * height );",
"vec2 origin = vec2( 0, 0 );",
"float aa = ( radius < 2.5 ) ? radius * 0.5 : 1.25;",
// get channel samples
"Cell cell_r = getReferenceCell( p, origin, rotateR, radius );",
"Cell cell_g = getReferenceCell( p, origin, rotateG, radius );",
"Cell cell_b = getReferenceCell( p, origin, rotateB, radius );",
"float r = getDotColour( cell_r, p, 0, rotateR, aa );",
"float g = getDotColour( cell_g, p, 1, rotateG, aa );",
"float b = getDotColour( cell_b, p, 2, rotateB, aa );",
// blend with original
"vec4 colour = texture2D( tDiffuse, vUV );",
"r = blendColour( r, colour.r, blending );",
"g = blendColour( g, colour.g, blending );",
"b = blendColour( b, colour.b, blending );",
"if ( greyscale ) {",
"r = g = b = (r + b + g) / 3.0;",
"}",
"gl_FragColor = vec4( r, g, b, 1.0 );",
"} else {",
"gl_FragColor = texture2D( tDiffuse, vUV );",
"}",
"}"
].join( "\n" )
};
export { HalftoneShader };
import {
Uniform
} from '../../../src/Three';
export interface HorizontalBlurShader {
uniforms: {
tDiffuse: Uniform;
h: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author zz85 / http://www.lab4games.net/zz85/blog
*
* Two pass Gaussian blur filter (horizontal and vertical blur shaders)
* - described in http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/
* and used in http://www.cake23.de/traveling-wavefronts-lit-up.html
*
* - 9 samples per pass
* - standard deviation 2.7
* - "h" and "v" parameters should be set to "1 / width" and "1 / height"
*/
var HorizontalBlurShader = {
uniforms: {
"tDiffuse": { value: null },
"h": { value: 1.0 / 512.0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform float h;",
"varying vec2 vUv;",
"void main() {",
"vec4 sum = vec4( 0.0 );",
"sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * h, vUv.y ) ) * 0.051;",
"sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * h, vUv.y ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * h, vUv.y ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * h, vUv.y ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
"sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * h, vUv.y ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * h, vUv.y ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * h, vUv.y ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * h, vUv.y ) ) * 0.051;",
"gl_FragColor = sum;",
"}"
].join( "\n" )
};
export { HorizontalBlurShader };
import {
Uniform
} from '../../../src/Three';
export interface HorizontalTiltShiftShader {
uniforms: {
tDiffuse: Uniform;
h: Uniform;
r: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Simple fake tilt-shift effect, modulating two pass Gaussian blur (see above) by vertical position
*
* - 9 samples per pass
* - standard deviation 2.7
* - "h" and "v" parameters should be set to "1 / width" and "1 / height"
* - "r" parameter control where "focused" horizontal line lies
*/
var HorizontalTiltShiftShader = {
uniforms: {
"tDiffuse": { value: null },
"h": { value: 1.0 / 512.0 },
"r": { value: 0.35 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform float h;",
"uniform float r;",
"varying vec2 vUv;",
"void main() {",
"vec4 sum = vec4( 0.0 );",
"float hh = h * abs( r - vUv.y );",
"sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * hh, vUv.y ) ) * 0.051;",
"sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * hh, vUv.y ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * hh, vUv.y ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * hh, vUv.y ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;",
"sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * hh, vUv.y ) ) * 0.1531;",
"sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * hh, vUv.y ) ) * 0.12245;",
"sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * hh, vUv.y ) ) * 0.0918;",
"sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * hh, vUv.y ) ) * 0.051;",
"gl_FragColor = sum;",
"}"
].join( "\n" )
};
export { HorizontalTiltShiftShader };
import {
Uniform
} from '../../../src/Three';
export interface HueSaturationShader {
uniforms: {
tDiffuse: Uniform;
hue: Uniform;
saturation: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author tapio / http://tapio.github.com/
*
* Hue and saturation adjustment
* https://github.com/evanw/glfx.js
* hue: -1 to 1 (-1 is 180 degrees in the negative direction, 0 is no change, etc.
* saturation: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast)
*/
var HueSaturationShader = {
uniforms: {
"tDiffuse": { value: null },
"hue": { value: 0 },
"saturation": { value: 0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform float hue;",
"uniform float saturation;",
"varying vec2 vUv;",
"void main() {",
"gl_FragColor = texture2D( tDiffuse, vUv );",
// hue
"float angle = hue * 3.14159265;",
"float s = sin(angle), c = cos(angle);",
"vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0;",
"float len = length(gl_FragColor.rgb);",
"gl_FragColor.rgb = vec3(",
"dot(gl_FragColor.rgb, weights.xyz),",
"dot(gl_FragColor.rgb, weights.zxy),",
"dot(gl_FragColor.rgb, weights.yzx)",
");",
// saturation
"float average = (gl_FragColor.r + gl_FragColor.g + gl_FragColor.b) / 3.0;",
"if (saturation > 0.0) {",
"gl_FragColor.rgb += (average - gl_FragColor.rgb) * (1.0 - 1.0 / (1.001 - saturation));",
"} else {",
"gl_FragColor.rgb += (average - gl_FragColor.rgb) * (-saturation);",
"}",
"}"
].join( "\n" )
};
export { HueSaturationShader };
import {
Uniform
} from '../../../src/Three';
export interface KaleidoShader {
uniforms: {
tDiffuse: Uniform;
sides: Uniform;
angle: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author felixturner / http://airtight.cc/
*
* Kaleidoscope Shader
* Radial reflection around center point
* Ported from: http://pixelshaders.com/editor/
* by Toby Schachman / http://tobyschachman.com/
*
* sides: number of reflections
* angle: initial angle in radians
*/
var KaleidoShader = {
uniforms: {
"tDiffuse": { value: null },
"sides": { value: 6.0 },
"angle": { value: 0.0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform float sides;",
"uniform float angle;",
"varying vec2 vUv;",
"void main() {",
"vec2 p = vUv - 0.5;",
"float r = length(p);",
"float a = atan(p.y, p.x) + angle;",
"float tau = 2. * 3.1416 ;",
"a = mod(a, tau/sides);",
"a = abs(a - tau/sides/2.) ;",
"p = r * vec2(cos(a), sin(a));",
"vec4 color = texture2D(tDiffuse, p + 0.5);",
"gl_FragColor = color;",
"}"
].join( "\n" )
};
export { KaleidoShader };
import {
Uniform
} from '../../../src/Three';
export interface LuminosityHighPassShader {
shaderID: string;
uniforms: {
tDiffuse: Uniform;
luminosityThreshold: Uniform;
smoothWidth: Uniform;
defaultColor: Uniform;
defaultOpacity: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author bhouston / http://clara.io/
*
* Luminosity
* http://en.wikipedia.org/wiki/Luminosity
*/
import {
Color
} from "../../../build/three.module.js";
var LuminosityHighPassShader = {
shaderID: "luminosityHighPass",
uniforms: {
"tDiffuse": { value: null },
"luminosityThreshold": { value: 1.0 },
"smoothWidth": { value: 1.0 },
"defaultColor": { value: new Color( 0x000000 ) },
"defaultOpacity": { value: 0.0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join("\n"),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform vec3 defaultColor;",
"uniform float defaultOpacity;",
"uniform float luminosityThreshold;",
"uniform float smoothWidth;",
"varying vec2 vUv;",
"void main() {",
"vec4 texel = texture2D( tDiffuse, vUv );",
"vec3 luma = vec3( 0.299, 0.587, 0.114 );",
"float v = dot( texel.xyz, luma );",
"vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );",
"float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );",
"gl_FragColor = mix( outputColor, texel, alpha );",
"}"
].join("\n")
};
export { LuminosityHighPassShader };
import {
Uniform
} from '../../../src/Three';
export interface LuminosityShader {
uniforms: {
tDiffuse: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Luminosity
* http://en.wikipedia.org/wiki/Luminosity
*/
var LuminosityShader = {
uniforms: {
"tDiffuse": { value: null }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"#include <common>",
"uniform sampler2D tDiffuse;",
"varying vec2 vUv;",
"void main() {",
"vec4 texel = texture2D( tDiffuse, vUv );",
"float l = linearToRelativeLuminance( texel.rgb );",
"gl_FragColor = vec4( l, l, l, texel.w );",
"}"
].join( "\n" )
};
export { LuminosityShader };
import {
Uniform
} from '../../../src/Three';
export interface MirrorShader {
uniforms: {
tDiffuse: Uniform;
side: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author felixturner / http://airtight.cc/
*
* Mirror Shader
* Copies half the input to the other half
*
* side: side of input to mirror (0 = left, 1 = right, 2 = top, 3 = bottom)
*/
var MirrorShader = {
uniforms: {
"tDiffuse": { value: null },
"side": { value: 1 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform int side;",
"varying vec2 vUv;",
"void main() {",
"vec2 p = vUv;",
"if (side == 0){",
"if (p.x > 0.5) p.x = 1.0 - p.x;",
"}else if (side == 1){",
"if (p.x < 0.5) p.x = 1.0 - p.x;",
"}else if (side == 2){",
"if (p.y < 0.5) p.y = 1.0 - p.y;",
"}else if (side == 3){",
"if (p.y > 0.5) p.y = 1.0 - p.y;",
"} ",
"vec4 color = texture2D(tDiffuse, p);",
"gl_FragColor = color;",
"}"
].join( "\n" )
};
export { MirrorShader };
import {
Uniform
} from '../../../src/Three';
export interface NormalMapShader {
uniforms: {
heightMap: Uniform;
resolution: Uniform;
scale: Uniform;
height: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Normal map shader
* - compute normals from heightmap
*/
import {
Vector2
} from "../../../build/three.module.js";
var NormalMapShader = {
uniforms: {
"heightMap": { value: null },
"resolution": { value: new Vector2( 512, 512 ) },
"scale": { value: new Vector2( 1, 1 ) },
"height": { value: 0.05 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform float height;",
"uniform vec2 resolution;",
"uniform sampler2D heightMap;",
"varying vec2 vUv;",
"void main() {",
"float val = texture2D( heightMap, vUv ).x;",
"float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;",
"float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;",
"gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );",
"}"
].join( "\n" )
};
export { NormalMapShader };
import {
Uniform
} from '../../../src/Three';
export interface ParallaxShader {
modes: {
none: string;
basic: string;
steep: string;
occlusion: string;
relief: string;
};
uniforms: {
bumpMap: Uniform;
map: Uniform;
parallaxScale: Uniform;
parallaxMinLayers: Uniform;
parallaxMaxLayers: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
// Parallax Occlusion shaders from
// http://sunandblackcat.com/tipFullView.php?topicid=28
// No tangent-space transforms logic based on
// http://mmikkelsen3d.blogspot.sk/2012/02/parallaxpoc-mapping-and-no-tangent.html
var ParallaxShader = {
// Ordered from fastest to best quality.
modes: {
none: 'NO_PARALLAX',
basic: 'USE_BASIC_PARALLAX',
steep: 'USE_STEEP_PARALLAX',
occlusion: 'USE_OCLUSION_PARALLAX', // a.k.a. POM
relief: 'USE_RELIEF_PARALLAX'
},
uniforms: {
"bumpMap": { value: null },
"map": { value: null },
"parallaxScale": { value: null },
"parallaxMinLayers": { value: null },
"parallaxMaxLayers": { value: null }
},
vertexShader: [
"varying vec2 vUv;",
"varying vec3 vViewPosition;",
"varying vec3 vNormal;",
"void main() {",
"vUv = uv;",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"vViewPosition = -mvPosition.xyz;",
"vNormal = normalize( normalMatrix * normal );",
"gl_Position = projectionMatrix * mvPosition;",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D bumpMap;",
"uniform sampler2D map;",
"uniform float parallaxScale;",
"uniform float parallaxMinLayers;",
"uniform float parallaxMaxLayers;",
"varying vec2 vUv;",
"varying vec3 vViewPosition;",
"varying vec3 vNormal;",
"#ifdef USE_BASIC_PARALLAX",
"vec2 parallaxMap( in vec3 V ) {",
"float initialHeight = texture2D( bumpMap, vUv ).r;",
// No Offset Limitting: messy, floating output at grazing angles.
//"vec2 texCoordOffset = parallaxScale * V.xy / V.z * initialHeight;",
// Offset Limiting
"vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;",
"return vUv - texCoordOffset;",
"}",
"#else",
"vec2 parallaxMap( in vec3 V ) {",
// Determine number of layers from angle between V and N
"float numLayers = mix( parallaxMaxLayers, parallaxMinLayers, abs( dot( vec3( 0.0, 0.0, 1.0 ), V ) ) );",
"float layerHeight = 1.0 / numLayers;",
"float currentLayerHeight = 0.0;",
// Shift of texture coordinates for each iteration
"vec2 dtex = parallaxScale * V.xy / V.z / numLayers;",
"vec2 currentTextureCoords = vUv;",
"float heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
// while ( heightFromTexture > currentLayerHeight )
// Infinite loops are not well supported. Do a "large" finite
// loop, but not too large, as it slows down some compilers.
"for ( int i = 0; i < 30; i += 1 ) {",
"if ( heightFromTexture <= currentLayerHeight ) {",
"break;",
"}",
"currentLayerHeight += layerHeight;",
// Shift texture coordinates along vector V
"currentTextureCoords -= dtex;",
"heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
"}",
"#ifdef USE_STEEP_PARALLAX",
"return currentTextureCoords;",
"#elif defined( USE_RELIEF_PARALLAX )",
"vec2 deltaTexCoord = dtex / 2.0;",
"float deltaHeight = layerHeight / 2.0;",
// Return to the mid point of previous layer
"currentTextureCoords += deltaTexCoord;",
"currentLayerHeight -= deltaHeight;",
// Binary search to increase precision of Steep Parallax Mapping
"const int numSearches = 5;",
"for ( int i = 0; i < numSearches; i += 1 ) {",
"deltaTexCoord /= 2.0;",
"deltaHeight /= 2.0;",
"heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
// Shift along or against vector V
"if( heightFromTexture > currentLayerHeight ) {", // Below the surface
"currentTextureCoords -= deltaTexCoord;",
"currentLayerHeight += deltaHeight;",
"} else {", // above the surface
"currentTextureCoords += deltaTexCoord;",
"currentLayerHeight -= deltaHeight;",
"}",
"}",
"return currentTextureCoords;",
"#elif defined( USE_OCLUSION_PARALLAX )",
"vec2 prevTCoords = currentTextureCoords + dtex;",
// Heights for linear interpolation
"float nextH = heightFromTexture - currentLayerHeight;",
"float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;",
// Proportions for linear interpolation
"float weight = nextH / ( nextH - prevH );",
// Interpolation of texture coordinates
"return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );",
"#else", // NO_PARALLAX
"return vUv;",
"#endif",
"}",
"#endif",
"vec2 perturbUv( vec3 surfPosition, vec3 surfNormal, vec3 viewPosition ) {",
"vec2 texDx = dFdx( vUv );",
"vec2 texDy = dFdy( vUv );",
"vec3 vSigmaX = dFdx( surfPosition );",
"vec3 vSigmaY = dFdy( surfPosition );",
"vec3 vR1 = cross( vSigmaY, surfNormal );",
"vec3 vR2 = cross( surfNormal, vSigmaX );",
"float fDet = dot( vSigmaX, vR1 );",
"vec2 vProjVscr = ( 1.0 / fDet ) * vec2( dot( vR1, viewPosition ), dot( vR2, viewPosition ) );",
"vec3 vProjVtex;",
"vProjVtex.xy = texDx * vProjVscr.x + texDy * vProjVscr.y;",
"vProjVtex.z = dot( surfNormal, viewPosition );",
"return parallaxMap( vProjVtex );",
"}",
"void main() {",
"vec2 mapUv = perturbUv( -vViewPosition, normalize( vNormal ), normalize( vViewPosition ) );",
"gl_FragColor = texture2D( map, mapUv );",
"}"
].join( "\n" )
};
export { ParallaxShader };
import {
Uniform
} from '../../../src/Three';
export interface PixelShader {
uniforms: {
tDiffuse: Uniform;
resolution: Uniform;
pixelSize: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author wongbryan / http://wongbryan.github.io
*
* Pixelation shader
*/
var PixelShader = {
uniforms: {
"tDiffuse": { value: null },
"resolution": { value: null },
"pixelSize": { value: 1. },
},
vertexShader: [
"varying highp vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform float pixelSize;",
"uniform vec2 resolution;",
"varying highp vec2 vUv;",
"void main(){",
"vec2 dxy = pixelSize / resolution;",
"vec2 coord = dxy * floor( vUv / dxy );",
"gl_FragColor = texture2D(tDiffuse, coord);",
"}"
].join( "\n" )
};
export { PixelShader };
......@@ -9,5 +9,5 @@ export interface RGBShiftShader {
angle: Uniform;
};
vertexShader: string;
fragmentShader:string;
fragmentShader: string;
}
import {
Uniform
} from '../../../src/Three';
export interface SAOShader {
defines: {
NUM_SAMPLES: number;
NUM_RINGS: number;
NORMAL_TEXTURE: number;
DIFFUSE_TEXTURE: number;
DEPTH_PACKING: number;
PERSPECTIVE_CAMERA: number;
};
uniforms: {
tDepth: Uniform;
tDiffuse: Uniform;
tNormal: Uniform;
size: Uniform;
cameraNear: Uniform;
cameraFar: Uniform;
cameraProjectionMatrix: Uniform;
cameraInverseProjectionMatrix: Uniform;
scale: Uniform;
intensity: Uniform;
bias: Uniform;
minResolution: Uniform;
kernelRadius: Uniform;
randomSeed: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* TODO
*/
import {
Matrix4,
Vector2
} from "../../../build/three.module.js";
var SAOShader = {
defines: {
'NUM_SAMPLES': 7,
'NUM_RINGS': 4,
'NORMAL_TEXTURE': 0,
'DIFFUSE_TEXTURE': 0,
'DEPTH_PACKING': 1,
'PERSPECTIVE_CAMERA': 1
},
uniforms: {
'tDepth': { value: null },
'tDiffuse': { value: null },
'tNormal': { value: null },
'size': { value: new Vector2( 512, 512 ) },
'cameraNear': { value: 1 },
'cameraFar': { value: 100 },
'cameraProjectionMatrix': { value: new Matrix4() },
'cameraInverseProjectionMatrix': { value: new Matrix4() },
'scale': { value: 1.0 },
'intensity': { value: 0.1 },
'bias': { value: 0.5 },
'minResolution': { value: 0.0 },
'kernelRadius': { value: 100.0 },
'randomSeed': { value: 0.0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"#include <common>",
"varying vec2 vUv;",
"#if DIFFUSE_TEXTURE == 1",
"uniform sampler2D tDiffuse;",
"#endif",
"uniform sampler2D tDepth;",
"#if NORMAL_TEXTURE == 1",
"uniform sampler2D tNormal;",
"#endif",
"uniform float cameraNear;",
"uniform float cameraFar;",
"uniform mat4 cameraProjectionMatrix;",
"uniform mat4 cameraInverseProjectionMatrix;",
"uniform float scale;",
"uniform float intensity;",
"uniform float bias;",
"uniform float kernelRadius;",
"uniform float minResolution;",
"uniform vec2 size;",
"uniform float randomSeed;",
"// RGBA depth",
"#include <packing>",
"vec4 getDefaultColor( const in vec2 screenPosition ) {",
" #if DIFFUSE_TEXTURE == 1",
" return texture2D( tDiffuse, vUv );",
" #else",
" return vec4( 1.0 );",
" #endif",
"}",
"float getDepth( const in vec2 screenPosition ) {",
" #if DEPTH_PACKING == 1",
" return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );",
" #else",
" return texture2D( tDepth, screenPosition ).x;",
" #endif",
"}",
"float getViewZ( const in float depth ) {",
" #if PERSPECTIVE_CAMERA == 1",
" return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );",
" #else",
" return orthographicDepthToViewZ( depth, cameraNear, cameraFar );",
" #endif",
"}",
"vec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {",
" float clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];",
" vec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );",
" clipPosition *= clipW; // unprojection.",
" return ( cameraInverseProjectionMatrix * clipPosition ).xyz;",
"}",
"vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {",
" #if NORMAL_TEXTURE == 1",
" return unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );",
" #else",
" return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );",
" #endif",
"}",
"float scaleDividedByCameraFar;",
"float minResolutionMultipliedByCameraFar;",
"float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {",
" vec3 viewDelta = sampleViewPosition - centerViewPosition;",
" float viewDistance = length( viewDelta );",
" float scaledScreenDistance = scaleDividedByCameraFar * viewDistance;",
" return max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - bias) / (1.0 + pow2( scaledScreenDistance ) );",
"}",
"// moving costly divides into consts",
"const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );",
"const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );",
"float getAmbientOcclusion( const in vec3 centerViewPosition ) {",
" // precompute some variables require in getOcclusion.",
" scaleDividedByCameraFar = scale / cameraFar;",
" minResolutionMultipliedByCameraFar = minResolution * cameraFar;",
" vec3 centerViewNormal = getViewNormal( centerViewPosition, vUv );",
" // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/",
" float angle = rand( vUv + randomSeed ) * PI2;",
" vec2 radius = vec2( kernelRadius * INV_NUM_SAMPLES ) / size;",
" vec2 radiusStep = radius;",
" float occlusionSum = 0.0;",
" float weightSum = 0.0;",
" for( int i = 0; i < NUM_SAMPLES; i ++ ) {",
" vec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius;",
" radius += radiusStep;",
" angle += ANGLE_STEP;",
" float sampleDepth = getDepth( sampleUv );",
" if( sampleDepth >= ( 1.0 - EPSILON ) ) {",
" continue;",
" }",
" float sampleViewZ = getViewZ( sampleDepth );",
" vec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepth, sampleViewZ );",
" occlusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );",
" weightSum += 1.0;",
" }",
" if( weightSum == 0.0 ) discard;",
" return occlusionSum * ( intensity / weightSum );",
"}",
"void main() {",
" float centerDepth = getDepth( vUv );",
" if( centerDepth >= ( 1.0 - EPSILON ) ) {",
" discard;",
" }",
" float centerViewZ = getViewZ( centerDepth );",
" vec3 viewPosition = getViewPosition( vUv, centerDepth, centerViewZ );",
" float ambientOcclusion = getAmbientOcclusion( viewPosition );",
" gl_FragColor = getDefaultColor( vUv );",
" gl_FragColor.xyz *= 1.0 - ambientOcclusion;",
"}"
].join( "\n" )
};
export { SAOShader };
import {
Uniform
} from '../../../src/Three';
export interface SSAOShader {
defines: {
PERSPECTIVE_CAMERA: number;
KERNEL_SIZE: number;
};
uniforms: {
tDiffuse: Uniform;
tNormal: Uniform;
tDepth: Uniform;
tNoise: Uniform;
kernel: Uniform;
cameraNear: Uniform;
cameraFar: Uniform;
resolution: Uniform;
cameraProjectionMatrix: Uniform;
cameraInverseProjectionMatrix: Uniform;
kernelRadius: Uniform;
minDistance: Uniform;
maxDistance: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
export interface SSAODepthShader {
defines: {
PERSPECTIVE_CAMERA: number;
};
uniforms: {
tDepth: Uniform;
cameraNear: Uniform;
cameraFar: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
export interface SSAOBlurShader {
uniforms: {
tDiffuse: Uniform;
resolution: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author Mugen87 / https://github.com/Mugen87
*
* References:
* http://john-chapman-graphics.blogspot.com/2013/01/ssao-tutorial.html
* https://learnopengl.com/Advanced-Lighting/SSAO
* https://github.com/McNopper/OpenGL/blob/master/Example28/shader/ssao.frag.glsl
*/
import {
Matrix4,
Vector2
} from "../../../build/three.module.js";
var SSAOShader = {
defines: {
"PERSPECTIVE_CAMERA": 1,
"KERNEL_SIZE": 32
},
uniforms: {
"tDiffuse": { value: null },
"tNormal": { value: null },
"tDepth": { value: null },
"tNoise": { value: null },
"kernel": { value: null },
"cameraNear": { value: null },
"cameraFar": { value: null },
"resolution": { value: new Vector2() },
"cameraProjectionMatrix": { value: new Matrix4() },
"cameraInverseProjectionMatrix": { value: new Matrix4() },
"kernelRadius": { value: 8 },
"minDistance": { value: 0.005 },
"maxDistance": { value: 0.05 },
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform sampler2D tNormal;",
"uniform sampler2D tDepth;",
"uniform sampler2D tNoise;",
"uniform vec3 kernel[ KERNEL_SIZE ];",
"uniform vec2 resolution;",
"uniform float cameraNear;",
"uniform float cameraFar;",
"uniform mat4 cameraProjectionMatrix;",
"uniform mat4 cameraInverseProjectionMatrix;",
"uniform float kernelRadius;",
"uniform float minDistance;", // avoid artifacts caused by neighbour fragments with minimal depth difference
"uniform float maxDistance;", // avoid the influence of fragments which are too far away
"varying vec2 vUv;",
"#include <packing>",
"float getDepth( const in vec2 screenPosition ) {",
" return texture2D( tDepth, screenPosition ).x;",
"}",
"float getLinearDepth( const in vec2 screenPosition ) {",
" #if PERSPECTIVE_CAMERA == 1",
" float fragCoordZ = texture2D( tDepth, screenPosition ).x;",
" float viewZ = perspectiveDepthToViewZ( fragCoordZ, cameraNear, cameraFar );",
" return viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );",
" #else",
" return texture2D( depthSampler, coord ).x;",
" #endif",
"}",
"float getViewZ( const in float depth ) {",
" #if PERSPECTIVE_CAMERA == 1",
" return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );",
" #else",
" return orthographicDepthToViewZ( depth, cameraNear, cameraFar );",
" #endif",
"}",
"vec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {",
" float clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];",
" vec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );",
" clipPosition *= clipW; // unprojection.",
" return ( cameraInverseProjectionMatrix * clipPosition ).xyz;",
"}",
"vec3 getViewNormal( const in vec2 screenPosition ) {",
" return unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );",
"}",
"void main() {",
" float depth = getDepth( vUv );",
" float viewZ = getViewZ( depth );",
" vec3 viewPosition = getViewPosition( vUv, depth, viewZ );",
" vec3 viewNormal = getViewNormal( vUv );",
" vec2 noiseScale = vec2( resolution.x / 4.0, resolution.y / 4.0 );",
" vec3 random = texture2D( tNoise, vUv * noiseScale ).xyz;",
// compute matrix used to reorient a kernel vector
" vec3 tangent = normalize( random - viewNormal * dot( random, viewNormal ) );",
" vec3 bitangent = cross( viewNormal, tangent );",
" mat3 kernelMatrix = mat3( tangent, bitangent, viewNormal );",
" float occlusion = 0.0;",
" for ( int i = 0; i < KERNEL_SIZE; i ++ ) {",
" vec3 sampleVector = kernelMatrix * kernel[ i ];", // reorient sample vector in view space
" vec3 samplePoint = viewPosition + ( sampleVector * kernelRadius );", // calculate sample point
" vec4 samplePointNDC = cameraProjectionMatrix * vec4( samplePoint, 1.0 );", // project point and calculate NDC
" samplePointNDC /= samplePointNDC.w;",
" vec2 samplePointUv = samplePointNDC.xy * 0.5 + 0.5;", // compute uv coordinates
" float realDepth = getLinearDepth( samplePointUv );", // get linear depth from depth texture
" float sampleDepth = viewZToOrthographicDepth( samplePoint.z, cameraNear, cameraFar );", // compute linear depth of the sample view Z value
" float delta = sampleDepth - realDepth;",
" if ( delta > minDistance && delta < maxDistance ) {", // if fragment is before sample point, increase occlusion
" occlusion += 1.0;",
" }",
" }",
" occlusion = clamp( occlusion / float( KERNEL_SIZE ), 0.0, 1.0 );",
" gl_FragColor = vec4( vec3( 1.0 - occlusion ), 1.0 );",
"}"
].join( "\n" )
};
var SSAODepthShader = {
defines: {
"PERSPECTIVE_CAMERA": 1
},
uniforms: {
"tDepth": { value: null },
"cameraNear": { value: null },
"cameraFar": { value: null },
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDepth;",
"uniform float cameraNear;",
"uniform float cameraFar;",
"varying vec2 vUv;",
"#include <packing>",
"float getLinearDepth( const in vec2 screenPosition ) {",
" #if PERSPECTIVE_CAMERA == 1",
" float fragCoordZ = texture2D( tDepth, screenPosition ).x;",
" float viewZ = perspectiveDepthToViewZ( fragCoordZ, cameraNear, cameraFar );",
" return viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );",
" #else",
" return texture2D( depthSampler, coord ).x;",
" #endif",
"}",
"void main() {",
" float depth = getLinearDepth( vUv );",
" gl_FragColor = vec4( vec3( 1.0 - depth ), 1.0 );",
"}"
].join( "\n" )
};
var SSAOBlurShader = {
uniforms: {
"tDiffuse": { value: null },
"resolution": { value: new Vector2() }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
" vUv = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform vec2 resolution;",
"varying vec2 vUv;",
"void main() {",
" vec2 texelSize = ( 1.0 / resolution );",
" float result = 0.0;",
" for ( int i = - 2; i <= 2; i ++ ) {",
" for ( int j = - 2; j <= 2; j ++ ) {",
" vec2 offset = ( vec2( float( i ), float( j ) ) ) * texelSize;",
" result += texture2D( tDiffuse, vUv + offset ).r;",
" }",
" }",
" gl_FragColor = vec4( vec3( result / ( 5.0 * 5.0 ) ), 1.0 );",
"}"
].join( "\n" )
};
export { SSAOShader, SSAODepthShader, SSAOBlurShader };
import {
Uniform
} from '../../../src/Three';
export interface SepiaShader {
uniforms: {
tDiffuse: Uniform;
amount: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author alteredq / http://alteredqualia.com/
*
* Sepia tone shader
* based on glfx.js sepia shader
* https://github.com/evanw/glfx.js
*/
var SepiaShader = {
uniforms: {
"tDiffuse": { value: null },
"amount": { value: 1.0 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform float amount;",
"uniform sampler2D tDiffuse;",
"varying vec2 vUv;",
"void main() {",
"vec4 color = texture2D( tDiffuse, vUv );",
"vec3 c = color.rgb;",
"color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );",
"color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );",
"color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );",
"gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );",
"}"
].join( "\n" )
};
export { SepiaShader };
import {
Uniform
} from '../../../src/Three';
export interface SobelOperatorShader {
uniforms: {
tDiffuse: Uniform;
resolution: Uniform;
};
vertexShader: string;
fragmentShader: string;
}
/**
* @author Mugen87 / https://github.com/Mugen87
*
* Sobel Edge Detection (see https://youtu.be/uihBwtPIBxM)
*
* As mentioned in the video the Sobel operator expects a grayscale image as input.
*
*/
import {
Vector2
} from "../../../build/three.module.js";
var SobelOperatorShader = {
uniforms: {
"tDiffuse": { value: null },
"resolution": { value: new Vector2() }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform vec2 resolution;",
"varying vec2 vUv;",
"void main() {",
"vec2 texel = vec2( 1.0 / resolution.x, 1.0 / resolution.y );",
// kernel definition (in glsl matrices are filled in column-major order)
"const mat3 Gx = mat3( -1, -2, -1, 0, 0, 0, 1, 2, 1 );", // x direction kernel
"const mat3 Gy = mat3( -1, 0, 1, -2, 0, 2, -1, 0, 1 );", // y direction kernel
// fetch the 3x3 neighbourhood of a fragment
// first column
"float tx0y0 = texture2D( tDiffuse, vUv + texel * vec2( -1, -1 ) ).r;",
"float tx0y1 = texture2D( tDiffuse, vUv + texel * vec2( -1, 0 ) ).r;",
"float tx0y2 = texture2D( tDiffuse, vUv + texel * vec2( -1, 1 ) ).r;",
// second column
"float tx1y0 = texture2D( tDiffuse, vUv + texel * vec2( 0, -1 ) ).r;",
"float tx1y1 = texture2D( tDiffuse, vUv + texel * vec2( 0, 0 ) ).r;",
"float tx1y2 = texture2D( tDiffuse, vUv + texel * vec2( 0, 1 ) ).r;",
// third column
"float tx2y0 = texture2D( tDiffuse, vUv + texel * vec2( 1, -1 ) ).r;",
"float tx2y1 = texture2D( tDiffuse, vUv + texel * vec2( 1, 0 ) ).r;",
"float tx2y2 = texture2D( tDiffuse, vUv + texel * vec2( 1, 1 ) ).r;",
// gradient value in x direction
"float valueGx = Gx[0][0] * tx0y0 + Gx[1][0] * tx1y0 + Gx[2][0] * tx2y0 + ",
"Gx[0][1] * tx0y1 + Gx[1][1] * tx1y1 + Gx[2][1] * tx2y1 + ",
"Gx[0][2] * tx0y2 + Gx[1][2] * tx1y2 + Gx[2][2] * tx2y2; ",
// gradient value in y direction
"float valueGy = Gy[0][0] * tx0y0 + Gy[1][0] * tx1y0 + Gy[2][0] * tx2y0 + ",
"Gy[0][1] * tx0y1 + Gy[1][1] * tx1y1 + Gy[2][1] * tx2y1 + ",
"Gy[0][2] * tx0y2 + Gy[1][2] * tx1y2 + Gy[2][2] * tx2y2; ",
// magnitute of the total gradient
"float G = sqrt( ( valueGx * valueGx ) + ( valueGy * valueGy ) );",
"gl_FragColor = vec4( vec3( G ), 1 );",
"}"
].join( "\n" )
};
export { SobelOperatorShader };
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册