three#ShaderChunk JavaScript Examples
The following examples show how to use
three#ShaderChunk.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiresVertexShader.js From BlueMapWeb with MIT License | 6 votes |
HIRES_VERTEX_SHADER = `
#include <common>
${ShaderChunk.logdepthbuf_pars_vertex}
attribute float ao;
attribute float sunlight;
attribute float blocklight;
varying vec3 vPosition;
//varying vec3 vWorldPosition;
varying vec3 vNormal;
varying vec2 vUv;
varying vec3 vColor;
varying float vAo;
varying float vSunlight;
varying float vBlocklight;
//varying float vDistance;
void main() {
vec4 worldPos = modelMatrix * vec4(position, 1);
vec4 viewPos = viewMatrix * worldPos;
vPosition = position;
//vWorldPosition = worldPos.xyz;
vNormal = normal;
vUv = uv;
vColor = color;
vAo = ao;
vSunlight = sunlight;
vBlocklight = blocklight;
//vDistance = -viewPos.z
gl_Position = projectionMatrix * viewPos;
${ShaderChunk.logdepthbuf_vertex}
}
`
Example #2
Source File: LowresVertexShader.js From BlueMapWeb with MIT License | 6 votes |
LOWRES_VERTEX_SHADER = `
#include <common>
${ShaderChunk.logdepthbuf_pars_vertex}
varying vec3 vPosition;
varying vec3 vWorldPosition;
varying vec3 vNormal;
varying vec2 vUv;
varying vec3 vColor;
varying float vDistance;
void main() {
vec4 worldPos = modelMatrix * vec4(position, 1);
vec4 viewPos = viewMatrix * worldPos;
vPosition = position;
vWorldPosition = worldPos.xyz;
vNormal = normal;
vUv = uv;
vColor = color;
vDistance = -viewPos.z;
gl_Position = projectionMatrix * viewPos;
${ShaderChunk.logdepthbuf_vertex}
}
`
Example #3
Source File: MarkerFillVertexShader.js From BlueMapWeb with MIT License | 6 votes |
MARKER_FILL_VERTEX_SHADER = `
#include <common>
${ShaderChunk.logdepthbuf_pars_vertex}
varying vec3 vPosition;
//varying vec3 vWorldPosition;
//varying vec3 vNormal;
//varying vec2 vUv;
//varying vec3 vColor;
varying float vDistance;
void main() {
vec4 worldPos = modelMatrix * vec4(position, 1);
vec4 viewPos = viewMatrix * worldPos;
vPosition = position;
//vWorldPosition = worldPos.xyz;
//vNormal = normal;
//vUv = uv;
//vColor = vec3(1.0);
vDistance = -viewPos.z;
gl_Position = projectionMatrix * viewPos;
${ShaderChunk.logdepthbuf_vertex}
}
`
Example #4
Source File: HiresFragmentShader.js From BlueMapWeb with MIT License | 5 votes |
HIRES_FRAGMENT_SHADER = `
${ShaderChunk.logdepthbuf_pars_fragment}
#ifndef texture
#define texture texture2D
#endif
uniform sampler2D textureImage;
uniform float sunlightStrength;
uniform float ambientLight;
varying vec3 vPosition;
//varying vec3 vWorldPosition;
varying vec3 vNormal;
varying vec2 vUv;
varying vec3 vColor;
varying float vAo;
varying float vSunlight;
varying float vBlocklight;
//varying float vDistance;
void main() {
vec4 color = texture(textureImage, vUv);
if (color.a == 0.0) discard;
//apply vertex-color
color.rgb *= vColor.rgb;
//apply ao
color.rgb *= vAo;
//apply light
float light = mix(vBlocklight, max(vSunlight, vBlocklight), sunlightStrength);
color.rgb *= mix(ambientLight, 1.0, light / 15.0);
gl_FragColor = color;
${ShaderChunk.logdepthbuf_fragment}
}
`
Example #5
Source File: LowresFragmentShader.js From BlueMapWeb with MIT License | 5 votes |
LOWRES_FRAGMENT_SHADER = `
${ShaderChunk.logdepthbuf_pars_fragment}
#ifndef texture
#define texture texture2D
#endif
struct TileMap {
sampler2D map;
float size;
vec2 scale;
vec2 translate;
vec2 pos;
};
uniform float sunlightStrength;
uniform float ambientLight;
uniform TileMap hiresTileMap;
varying vec3 vPosition;
varying vec3 vWorldPosition;
varying vec3 vNormal;
varying vec2 vUv;
varying vec3 vColor;
varying float vDistance;
void main() {
//discard if hires tile is loaded at that position
if (vDistance < 1900.0 && texture(hiresTileMap.map, ((vWorldPosition.xz - hiresTileMap.translate) / hiresTileMap.scale - hiresTileMap.pos) / hiresTileMap.size + 0.5).r >= 1.0) discard;
vec4 color = vec4(vColor, 1.0);
float diff = max(dot(vNormal, vec3(0.3637, 0.7274, 0.5819)), 0.0) * 0.3 + 0.7;
color *= diff;
color *= mix(sunlightStrength, 1.0, ambientLight);
gl_FragColor = color;
${ShaderChunk.logdepthbuf_fragment}
}
`
Example #6
Source File: MarkerFillFragmentShader.js From BlueMapWeb with MIT License | 5 votes |
MARKER_FILL_FRAGMENT_SHADER = `
${ShaderChunk.logdepthbuf_pars_fragment}
#define FLT_MAX 3.402823466e+38
varying vec3 vPosition;
//varying vec3 vWorldPosition;
//varying vec3 vNormal;
//varying vec2 vUv;
//varying vec3 vColor;
varying float vDistance;
uniform vec3 markerColor;
uniform float markerOpacity;
uniform float fadeDistanceMax;
uniform float fadeDistanceMin;
void main() {
vec4 color = vec4(markerColor, markerOpacity);
// distance fading
float fdMax = FLT_MAX;
if ( fadeDistanceMax > 0.0 ) fdMax = fadeDistanceMax;
float minDelta = (vDistance - fadeDistanceMin) / fadeDistanceMin;
float maxDelta = (vDistance - fadeDistanceMax) / (fadeDistanceMax * 0.5);
float distanceOpacity = min(
clamp(minDelta, 0.0, 1.0),
1.0 - clamp(maxDelta + 1.0, 0.0, 1.0)
);
color.a *= distanceOpacity;
// apply vertex-color
//color.rgb *= vColor.rgb;
gl_FragColor = color;
${ShaderChunk.logdepthbuf_fragment}
}
`
Example #7
Source File: SubsurfaceScatteringShader.js From Computer-Graphics with MIT License | 5 votes |
meshphong_frag_head = ShaderChunk[ 'meshphong_frag' ].slice( 0, ShaderChunk[ 'meshphong_frag' ].indexOf( 'void main() {' ) )
Example #8
Source File: SubsurfaceScatteringShader.js From Computer-Graphics with MIT License | 5 votes |
meshphong_frag_body = ShaderChunk[ 'meshphong_frag' ].slice( ShaderChunk[ 'meshphong_frag' ].indexOf( 'void main() {' ) )
Example #9
Source File: SubsurfaceScatteringShader.js From Computer-Graphics with MIT License | 5 votes |
SubsurfaceScatteringShader = {
uniforms: UniformsUtils.merge( [
ShaderLib[ 'phong' ].uniforms,
{
'thicknessMap': { value: null },
'thicknessColor': { value: new Color( 0xffffff ) },
'thicknessDistortion': { value: 0.1 },
'thicknessAmbient': { value: 0.0 },
'thicknessAttenuation': { value: 0.1 },
'thicknessPower': { value: 2.0 },
'thicknessScale': { value: 10.0 }
}
] ),
vertexShader: [
'#define USE_UV',
ShaderChunk[ 'meshphong_vert' ],
].join( '\n' ),
fragmentShader: [
'#define USE_UV',
'#define SUBSURFACE',
meshphong_frag_head,
'uniform sampler2D thicknessMap;',
'uniform float thicknessPower;',
'uniform float thicknessScale;',
'uniform float thicknessDistortion;',
'uniform float thicknessAmbient;',
'uniform float thicknessAttenuation;',
'uniform vec3 thicknessColor;',
'void RE_Direct_Scattering(const in IncidentLight directLight, const in vec2 uv, const in GeometricContext geometry, inout ReflectedLight reflectedLight) {',
' vec3 thickness = thicknessColor * texture2D(thicknessMap, uv).r;',
' vec3 scatteringHalf = normalize(directLight.direction + (geometry.normal * thicknessDistortion));',
' float scatteringDot = pow(saturate(dot(geometry.viewDir, -scatteringHalf)), thicknessPower) * thicknessScale;',
' vec3 scatteringIllu = (scatteringDot + thicknessAmbient) * thickness;',
' reflectedLight.directDiffuse += scatteringIllu * thicknessAttenuation * directLight.color;',
'}',
meshphong_frag_body.replace( '#include <lights_fragment_begin>',
replaceAll(
ShaderChunk[ 'lights_fragment_begin' ],
'RE_Direct( directLight, geometry, material, reflectedLight );',
[
'RE_Direct( directLight, geometry, material, reflectedLight );',
'#if defined( SUBSURFACE ) && defined( USE_UV )',
' RE_Direct_Scattering(directLight, vUv, geometry, reflectedLight);',
'#endif',
].join( '\n' )
),
),
].join( '\n' ),
}