提交 402804ac 编写于 作者: G Garrett Johnson

jsm updaets

上级 900da918
......@@ -11,7 +11,7 @@ var CopyShader = {
uniforms: {
"tDiffuse": { value: null },
"opacity": { value: 1.0 }
"opacity": { value: 1.0 }
},
......
......@@ -8,19 +8,19 @@ import {
var DepthLimitedBlurShader = {
defines: {
'KERNEL_RADIUS': 4,
'DEPTH_PACKING': 1,
'PERSPECTIVE_CAMERA': 1
"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 },
"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>",
......@@ -153,9 +153,9 @@ var BlurShaderUtils = {
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.defines[ "KERNEL_RADIUS" ] = kernelRadius;
material.uniforms[ "sampleUvOffsets" ].value = BlurShaderUtils.createSampleOffsets( kernelRadius, uvIncrement );
material.uniforms[ "sampleWeights" ].value = BlurShaderUtils.createSampleWeights( kernelRadius, stdDev );
material.needsUpdate = true;
}
......
......@@ -39,7 +39,7 @@ var DigitalGlitch = {
].join( "\n" ),
fragmentShader: [
"uniform int byp;",//should we apply the glitch ?
"uniform int byp;", //should we apply the glitch ?
"uniform sampler2D tDiffuse;",
"uniform sampler2D tDisp;",
......
......@@ -15,10 +15,10 @@ var DotScreenShader = {
uniforms: {
"tDiffuse": { value: null },
"tSize": { value: new Vector2( 256, 256 ) },
"center": { value: new Vector2( 0.5, 0.5 ) },
"angle": { value: 1.57 },
"scale": { value: 1.0 }
"tSize": { value: new Vector2( 256, 256 ) },
"center": { value: new Vector2( 0.5, 0.5 ) },
"angle": { value: 1.57 },
"scale": { value: 1.0 }
},
......
此差异已折叠。
......@@ -72,25 +72,25 @@ var FilmShader = {
"void main() {",
// sample the source
// sample the source
" vec4 cTextureScreen = texture2D( tDiffuse, vUv );",
// make some noise
// make some noise
" float dx = rand( vUv + time );",
// add noise
// add noise
" vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 );",
// get us a sine and cosine
// get us a sine and cosine
" vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );",
// add scanlines
// add scanlines
" cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;",
// interpolate between source and result by intensity
// interpolate between source and result by intensity
" cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );",
// convert to grayscale if desired
// convert to grayscale if desired
" if( grayscale ) {",
" cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );",
......
......@@ -29,14 +29,14 @@ var HalftoneShader = {
vertexShader: [
"varying vec2 vUV;",
"varying vec2 vUV;",
"void main() {",
"void main() {",
"vUV = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);",
" vUV = uv;",
" gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);",
"}"
"}"
].join( "\n" ),
......
......@@ -45,7 +45,7 @@ var HueSaturationShader = {
" gl_FragColor = texture2D( tDiffuse, vUv );",
// hue
// 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;",
......@@ -56,7 +56,7 @@ var HueSaturationShader = {
" dot(gl_FragColor.rgb, weights.yzx)",
" );",
// saturation
// 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));",
......
......@@ -35,7 +35,7 @@ var LuminosityHighPassShader = {
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
......@@ -63,7 +63,7 @@ var LuminosityHighPassShader = {
"}"
].join("\n")
].join( "\n" )
};
......
......@@ -6,11 +6,11 @@
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'
none: "NO_PARALLAX",
basic: "USE_BASIC_PARALLAX",
steep: "USE_STEEP_PARALLAX",
occlusion: "USE_OCLUSION_PARALLAX", // a.k.a. POM
relief: "USE_RELIEF_PARALLAX"
},
uniforms: {
......@@ -36,7 +36,7 @@ var ParallaxShader = {
"}"
].join( "\n" ),
].join( "\n" ),
fragmentShader: [
"uniform sampler2D bumpMap;",
......@@ -56,10 +56,10 @@ var ParallaxShader = {
" float initialHeight = texture2D( bumpMap, vUv ).r;",
// No Offset Limitting: messy, floating output at grazing angles.
//"vec2 texCoordOffset = parallaxScale * V.xy / V.z * initialHeight;",
// No Offset Limitting: messy, floating output at grazing angles.
//"vec2 texCoordOffset = parallaxScale * V.xy / V.z * initialHeight;",
// Offset Limiting
// Offset Limiting
" vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;",
" return vUv - texCoordOffset;",
......@@ -69,27 +69,27 @@ var ParallaxShader = {
" vec2 parallaxMap( in vec3 V ) {",
// Determine number of layers from angle between V and N
// 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
// 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.
// 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
// Shift texture coordinates along vector V
" currentTextureCoords -= dtex;",
" heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;",
" }",
......@@ -103,18 +103,18 @@ var ParallaxShader = {
" vec2 deltaTexCoord = dtex / 2.0;",
" float deltaHeight = layerHeight / 2.0;",
// Return to the mid point of previous layer
// Return to the mid point of previous layer
" currentTextureCoords += deltaTexCoord;",
" currentLayerHeight -= deltaHeight;",
// Binary search to increase precision of Steep Parallax Mapping
// 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
// Shift along or against vector V
" if( heightFromTexture > currentLayerHeight ) {", // Below the surface
" currentTextureCoords -= deltaTexCoord;",
......@@ -134,14 +134,14 @@ var ParallaxShader = {
" vec2 prevTCoords = currentTextureCoords + dtex;",
// Heights for linear interpolation
// Heights for linear interpolation
" float nextH = heightFromTexture - currentLayerHeight;",
" float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;",
// Proportions for linear interpolation
// Proportions for linear interpolation
" float weight = nextH / ( nextH - prevH );",
// Interpolation of texture coordinates
// Interpolation of texture coordinates
" return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );",
" #else", // NO_PARALLAX
......@@ -179,7 +179,7 @@ var ParallaxShader = {
"}"
].join( "\n" )
].join( "\n" )
};
......
......@@ -9,32 +9,32 @@ import {
var SAOShader = {
defines: {
'NUM_SAMPLES': 7,
'NUM_RINGS': 4,
'NORMAL_TEXTURE': 0,
'DIFFUSE_TEXTURE': 0,
'DEPTH_PACKING': 1,
'PERSPECTIVE_CAMERA': 1
"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 ) },
"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() },
"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 },
"scale": { value: 1.0 },
"intensity": { value: 0.1 },
"bias": { value: 0.5 },
'minResolution': { value: 0.0 },
'kernelRadius': { value: 100.0 },
'randomSeed': { value: 0.0 }
"minResolution": { value: 0.0 },
"kernelRadius": { value: 100.0 },
"randomSeed": { value: 0.0 }
},
vertexShader: [
"varying vec2 vUv;",
......
此差异已折叠。
......@@ -44,44 +44,44 @@ var SobelOperatorShader = {
" vec2 texel = vec2( 1.0 / resolution.x, 1.0 / resolution.y );",
// kernel definition (in glsl matrices are filled in column-major order)
// 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
// fetch the 3x3 neighbourhood of a fragment
// first column
// 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
// 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
// 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
// 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
// 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
// magnitute of the total gradient
" float G = sqrt( ( valueGx * valueGx ) + ( valueGy * valueGy ) );",
......
......@@ -150,7 +150,7 @@ var TerrainShader = {
" vec3 totalDiffuseLight = vec3( 0.0 );",
" vec3 totalSpecularLight = vec3( 0.0 );",
// point lights
// point lights
" #if NUM_POINT_LIGHTS > 0",
......@@ -176,7 +176,7 @@ var TerrainShader = {
" #endif",
// directional lights
// directional lights
" #if NUM_DIR_LIGHTS > 0",
......@@ -200,7 +200,7 @@ var TerrainShader = {
" #endif",
// hemisphere lights
// hemisphere lights
" #if NUM_HEMI_LIGHTS > 0",
......@@ -211,14 +211,14 @@ var TerrainShader = {
" vec3 lVector = hemisphereLightDirection[ i ];",
// diffuse
// diffuse
" float dotProduct = dot( normal, lVector );",
" float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
" totalDiffuseLight += mix( hemisphereLights[ i ].groundColor, hemisphereLights[ i ].skyColor, hemiDiffuseWeight );",
// specular (sky light)
// specular (sky light)
" float hemiSpecularWeight = 0.0;",
......@@ -226,7 +226,7 @@ var TerrainShader = {
" float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
" hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
// specular (ground light)
// specular (ground light)
" vec3 lVectorGround = -lVector;",
......@@ -244,7 +244,7 @@ var TerrainShader = {
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
ShaderChunk[ "fog_fragment" ],
ShaderChunk[ "fog_fragment" ],
"}"
......@@ -280,20 +280,20 @@ var TerrainShader = {
" vNormal = normalize( normalMatrix * normal );",
// tangent and binormal vectors
// tangent and binormal vectors
" vTangent = normalize( normalMatrix * tangent.xyz );",
" vBinormal = cross( vNormal, vTangent ) * tangent.w;",
" vBinormal = normalize( vBinormal );",
// texture coordinates
// texture coordinates
" vUv = uv;",
" vec2 uvBase = uv * uRepeatBase;",
// displacement mapping
// displacement mapping
" #ifdef VERTEX_TEXTURES",
......@@ -318,8 +318,8 @@ var TerrainShader = {
" vec3 normalTex = texture2D( tNormal, uvBase ).xyz * 2.0 - 1.0;",
" vNormal = normalMatrix * normalTex;",
ShaderChunk[ "shadowmap_vertex" ],
ShaderChunk[ "fog_vertex" ],
ShaderChunk[ "shadowmap_vertex" ],
ShaderChunk[ "fog_vertex" ],
"}"
......
......@@ -50,16 +50,16 @@ var ToneMapShader = {
"vec3 ToneMap( vec3 vColor ) {",
" #ifdef ADAPTED_LUMINANCE",
// Get the calculated average luminance
// Get the calculated average luminance
" float fLumAvg = texture2D(luminanceMap, vec2(0.5, 0.5)).r;",
" #else",
" float fLumAvg = averageLuminance;",
" #endif",
// Calculate the luminance of the current pixel
// Calculate the luminance of the current pixel
" float fLumPixel = linearToRelativeLuminance( vColor );",
// Apply the modified operator (Eq. 4)
// Apply the modified operator (Eq. 4)
" float fLumScaled = (fLumPixel * middleGrey) / max( minLuminance, fLumAvg );",
" float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (maxLuminance * maxLuminance)))) / (1.0 + fLumScaled);",
......
......@@ -53,7 +53,7 @@ var TriangleBlurShader = {
" float total = 0.0;",
// randomize the lookup values to hide the fixed number of samples
// randomize the lookup values to hide the fixed number of samples
" float offset = rand( vUv );",
......
......@@ -42,7 +42,7 @@ var VignetteShader = {
"void main() {",
// Eskil's vignette
// Eskil's vignette
" vec4 texel = texture2D( tDiffuse, vUv );",
" vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );",
......
......@@ -9,23 +9,23 @@ var WaterRefractionShader = {
uniforms: {
'color': {
"color": {
value: null
},
'time': {
"time": {
value: 0
},
'tDiffuse': {
"tDiffuse": {
value: null
},
'tDudv': {
"tDudv": {
value: null
},
'textureMatrix': {
"textureMatrix": {
value: null
}
......@@ -33,68 +33,68 @@ var WaterRefractionShader = {
vertexShader: [
'uniform mat4 textureMatrix;',
"uniform mat4 textureMatrix;",
'varying vec2 vUv;',
'varying vec4 vUvRefraction;',
"varying vec2 vUv;",
"varying vec4 vUvRefraction;",
'void main() {',
"void main() {",
' vUv = uv;',
" vUv = uv;",
' vUvRefraction = textureMatrix * vec4( position, 1.0 );',
" vUvRefraction = textureMatrix * vec4( position, 1.0 );",
' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
" gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
'}'
"}"
].join( '\n' ),
].join( "\n" ),
fragmentShader: [
'uniform vec3 color;',
'uniform float time;',
'uniform sampler2D tDiffuse;',
'uniform sampler2D tDudv;',
"uniform vec3 color;",
"uniform float time;",
"uniform sampler2D tDiffuse;",
"uniform sampler2D tDudv;",
'varying vec2 vUv;',
'varying vec4 vUvRefraction;',
"varying vec2 vUv;",
"varying vec4 vUvRefraction;",
'float blendOverlay( float base, float blend ) {',
"float blendOverlay( float base, float blend ) {",
' return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );',
" return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );",
'}',
"}",
'vec3 blendOverlay( vec3 base, vec3 blend ) {',
"vec3 blendOverlay( vec3 base, vec3 blend ) {",
' return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ),blendOverlay( base.b, blend.b ) );',
" return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ),blendOverlay( base.b, blend.b ) );",
'}',
"}",
'void main() {',
"void main() {",
' float waveStrength = 0.1;',
' float waveSpeed = 0.03;',
" float waveStrength = 0.1;",
" float waveSpeed = 0.03;",
// simple distortion (ripple) via dudv map (see https://www.youtube.com/watch?v=6B7IF6GOu7s)
' vec2 distortedUv = texture2D( tDudv, vec2( vUv.x + time * waveSpeed, vUv.y ) ).rg * waveStrength;',
' distortedUv = vUv.xy + vec2( distortedUv.x, distortedUv.y + time * waveSpeed );',
' vec2 distortion = ( texture2D( tDudv, distortedUv ).rg * 2.0 - 1.0 ) * waveStrength;',
" vec2 distortedUv = texture2D( tDudv, vec2( vUv.x + time * waveSpeed, vUv.y ) ).rg * waveStrength;",
" distortedUv = vUv.xy + vec2( distortedUv.x, distortedUv.y + time * waveSpeed );",
" vec2 distortion = ( texture2D( tDudv, distortedUv ).rg * 2.0 - 1.0 ) * waveStrength;",
// new uv coords
' vec4 uv = vec4( vUvRefraction );',
' uv.xy += distortion;',
" vec4 uv = vec4( vUvRefraction );",
" uv.xy += distortion;",
' vec4 base = texture2DProj( tDiffuse, uv );',
" vec4 base = texture2DProj( tDiffuse, uv );",
' gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );',
" gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );",
'}'
"}"
].join( '\n' )
].join( "\n" )
};
export { WaterRefractionShader };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册