three#ShaderMaterial JavaScript Examples
The following examples show how to use
three#ShaderMaterial.
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: Map.js From BlueMapWeb with MIT License | 6 votes |
/**
* Creates a lowres Material
* @param vertexShader {string}
* @param fragmentShader {string}
* @param uniforms {object}
* @returns {ShaderMaterial} the hires Material
*/
createLowresMaterial(vertexShader, fragmentShader, uniforms) {
return new ShaderMaterial({
uniforms: uniforms,
vertexShader: vertexShader,
fragmentShader: fragmentShader,
transparent: false,
depthWrite: true,
depthTest: true,
vertexColors: VertexColors,
side: FrontSide,
wireframe: false
});
}
Example #2
Source File: Waterpass.js From r3f-website with MIT License | 6 votes |
WaterPass = function(dt_size) {
Pass.call(this)
if (WaterShader === undefined) console.error('THREE.WaterPass relies on THREE.WaterShader')
var shader = WaterShader
this.uniforms = UniformsUtils.clone(shader.uniforms)
if (dt_size === undefined) dt_size = 64
this.uniforms['resolution'].value = new Vector2(dt_size, dt_size)
this.material = new ShaderMaterial({
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
})
this.camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1)
this.scene = new Scene()
this.quad = new Mesh(new PlaneBufferGeometry(2, 2), null)
this.quad.frustumCulled = false // Avoid getting clipped
this.scene.add(this.quad)
this.factor = 0
this.time = 0
}
Example #3
Source File: Glitchpass.js From r3f-website with MIT License | 6 votes |
GlitchPass = function(dt_size) {
Pass.call(this)
if (DigitalGlitch === undefined) console.error('THREE.GlitchPass relies on THREE.DigitalGlitch')
var shader = DigitalGlitch
this.uniforms = UniformsUtils.clone(shader.uniforms)
if (dt_size === undefined) dt_size = 64
this.uniforms['tDisp'].value = this.generateHeightmap(dt_size)
this.material = new ShaderMaterial({
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
})
this.camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1)
this.scene = new Scene()
this.quad = new Mesh(new PlaneBufferGeometry(2, 2), null)
this.quad.frustumCulled = false // Avoid getting clipped
this.scene.add(this.quad)
this.factor = 0
}
Example #4
Source File: TexturePass.js From Computer-Graphics with MIT License | 6 votes |
constructor( map, opacity ) {
super();
if ( CopyShader === undefined ) console.error( 'THREE.TexturePass relies on CopyShader' );
const shader = CopyShader;
this.map = map;
this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
this.uniforms = UniformsUtils.clone( shader.uniforms );
this.material = new ShaderMaterial( {
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
depthTest: false,
depthWrite: false
} );
this.needsSwap = false;
this.fsQuad = new FullScreenQuad( null );
}
Example #5
Source File: SavePass.js From Computer-Graphics with MIT License | 6 votes |
constructor( renderTarget ) {
super();
if ( CopyShader === undefined ) console.error( 'THREE.SavePass relies on CopyShader' );
const shader = CopyShader;
this.textureID = 'tDiffuse';
this.uniforms = UniformsUtils.clone( shader.uniforms );
this.material = new ShaderMaterial( {
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
} );
this.renderTarget = renderTarget;
if ( this.renderTarget === undefined ) {
this.renderTarget = new WebGLRenderTarget( window.innerWidth, window.innerHeight );
this.renderTarget.texture.name = 'SavePass.rt';
}
this.needsSwap = false;
this.fsQuad = new FullScreenQuad( this.material );
}
Example #6
Source File: SSAARenderPass.js From Computer-Graphics with MIT License | 6 votes |
constructor( scene, camera, clearColor, clearAlpha ) {
super();
this.scene = scene;
this.camera = camera;
this.sampleLevel = 4; // specified as n, where the number of samples is 2^n, so sampleLevel = 4, is 2^4 samples, 16.
this.unbiased = true;
// as we need to clear the buffer in this pass, clearColor must be set to something, defaults to black.
this.clearColor = ( clearColor !== undefined ) ? clearColor : 0x000000;
this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
this._oldClearColor = new Color();
if ( CopyShader === undefined ) console.error( 'THREE.SSAARenderPass relies on CopyShader' );
const copyShader = CopyShader;
this.copyUniforms = UniformsUtils.clone( copyShader.uniforms );
this.copyMaterial = new ShaderMaterial( {
uniforms: this.copyUniforms,
vertexShader: copyShader.vertexShader,
fragmentShader: copyShader.fragmentShader,
premultipliedAlpha: true,
transparent: true,
blending: AdditiveBlending,
depthTest: false,
depthWrite: false
} );
this.fsQuad = new FullScreenQuad( this.copyMaterial );
}
Example #7
Source File: HalftonePass.js From Computer-Graphics with MIT License | 6 votes |
constructor( width, height, params ) {
super();
if ( HalftoneShader === undefined ) {
console.error( 'THREE.HalftonePass requires HalftoneShader' );
}
this.uniforms = UniformsUtils.clone( HalftoneShader.uniforms );
this.material = new ShaderMaterial( {
uniforms: this.uniforms,
fragmentShader: HalftoneShader.fragmentShader,
vertexShader: HalftoneShader.vertexShader
} );
// set params
this.uniforms.width.value = width;
this.uniforms.height.value = height;
for ( const key in params ) {
if ( params.hasOwnProperty( key ) && this.uniforms.hasOwnProperty( key ) ) {
this.uniforms[ key ].value = params[ key ];
}
}
this.fsQuad = new FullScreenQuad( this.material );
}
Example #8
Source File: GlitchPass.js From Computer-Graphics with MIT License | 6 votes |
constructor( dt_size = 64 ) {
super();
if ( DigitalGlitch === undefined ) console.error( 'THREE.GlitchPass relies on DigitalGlitch' );
const shader = DigitalGlitch;
this.uniforms = UniformsUtils.clone( shader.uniforms );
this.uniforms[ 'tDisp' ].value = this.generateHeightmap( dt_size );
this.material = new ShaderMaterial( {
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
} );
this.fsQuad = new FullScreenQuad( this.material );
this.goWild = false;
this.curF = 0;
this.generateTrigger();
}
Example #9
Source File: FilmPass.js From Computer-Graphics with MIT License | 6 votes |
constructor( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) {
super();
if ( FilmShader === undefined ) console.error( 'THREE.FilmPass relies on FilmShader' );
const shader = FilmShader;
this.uniforms = UniformsUtils.clone( shader.uniforms );
this.material = new ShaderMaterial( {
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
} );
if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale;
if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity;
if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity;
if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount;
this.fsQuad = new FullScreenQuad( this.material );
}
Example #10
Source File: DotScreenPass.js From Computer-Graphics with MIT License | 6 votes |
constructor( center, angle, scale ) {
super();
if ( DotScreenShader === undefined ) console.error( 'THREE.DotScreenPass relies on DotScreenShader' );
const shader = DotScreenShader;
this.uniforms = UniformsUtils.clone( shader.uniforms );
if ( center !== undefined ) this.uniforms[ 'center' ].value.copy( center );
if ( angle !== undefined ) this.uniforms[ 'angle' ].value = angle;
if ( scale !== undefined ) this.uniforms[ 'scale' ].value = scale;
this.material = new ShaderMaterial( {
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader
} );
this.fsQuad = new FullScreenQuad( this.material );
}
Example #11
Source File: CubeTexturePass.js From Computer-Graphics with MIT License | 6 votes |
constructor( camera, envMap, opacity = 1 ) {
super();
this.camera = camera;
this.needsSwap = false;
this.cubeShader = ShaderLib[ 'cube' ];
this.cubeMesh = new Mesh(
new BoxGeometry( 10, 10, 10 ),
new ShaderMaterial( {
uniforms: UniformsUtils.clone( this.cubeShader.uniforms ),
vertexShader: this.cubeShader.vertexShader,
fragmentShader: this.cubeShader.fragmentShader,
depthTest: false,
depthWrite: false,
side: BackSide
} )
);
Object.defineProperty( this.cubeMesh.material, 'envMap', {
get: function () {
return this.uniforms.envMap.value;
}
} );
this.envMap = envMap;
this.opacity = opacity;
this.cubeScene = new Scene();
this.cubeCamera = new PerspectiveCamera();
this.cubeScene.add( this.cubeMesh );
}
Example #12
Source File: ShaderPass.js From threejs-tutorial with MIT License | 6 votes |
ShaderPass = function (shader, textureID) {
Pass.call(this);
this.textureID = textureID !== undefined ? textureID : "tDiffuse";
if (shader instanceof ShaderMaterial) {
this.uniforms = shader.uniforms;
this.material = shader;
} else if (shader) {
this.uniforms = UniformsUtils.clone(shader.uniforms);
this.material = new ShaderMaterial({
defines: Object.assign({}, shader.defines),
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
});
}
this.fsQuad = new Pass.FullScreenQuad(this.material);
}
Example #13
Source File: SavePass.js From threejs-tutorial with MIT License | 6 votes |
SavePass = function (renderTarget) {
Pass.call(this);
if (CopyShader === undefined)
console.error("SavePass relies on CopyShader");
var shader = CopyShader;
this.textureID = "tDiffuse";
this.uniforms = UniformsUtils.clone(shader.uniforms);
this.material = new ShaderMaterial({
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
});
this.renderTarget = renderTarget;
if (this.renderTarget === undefined) {
this.renderTarget = new WebGLRenderTarget(
window.innerWidth,
window.innerHeight,
{
minFilter: LinearFilter,
magFilter: LinearFilter,
format: RGBFormat,
stencilBuffer: false,
}
);
this.renderTarget.texture.name = "SavePass.rt";
}
this.needsSwap = false;
this.fsQuad = new Pass.FullScreenQuad(this.material);
}
Example #14
Source File: CubeTexturePass.js From threejs-tutorial with MIT License | 6 votes |
CubeTexturePass = function (camera, envMap, opacity) {
Pass.call(this);
this.camera = camera;
this.needsSwap = false;
this.cubeShader = ShaderLib["cube"];
this.cubeMesh = new Mesh(
new BoxBufferGeometry(10, 10, 10),
new ShaderMaterial({
uniforms: this.cubeShader.uniforms,
vertexShader: this.cubeShader.vertexShader,
fragmentShader: this.cubeShader.fragmentShader,
depthTest: false,
depthWrite: false,
side: BackSide,
})
);
Object.defineProperty(this.cubeMesh.material, "envMap", {
get: function () {
return this.uniforms.envMap.value;
},
});
this.envMap = envMap;
this.opacity = opacity !== undefined ? opacity : 1.0;
this.cubeScene = new Scene();
this.cubeCamera = new PerspectiveCamera();
this.cubeScene.add(this.cubeMesh);
}
Example #15
Source File: QuadTextureMaterial.js From map33.js with MIT License | 6 votes |
QuadTextureMaterial = (urls) => {
return Promise.all(urls.map(url => loader.loadAsync(url))).then(maps => {
return new ShaderMaterial({
uniforms: {
mapNW: {value: maps[0]},
mapSW: {value: maps[1]},
mapNE: {value: maps[2]},
mapSE: {value: maps[3]},
...UniformsLib.common,
...UniformsLib.lights,
...UniformsLib.fog,
},
vertexShader,
fragmentShader,
defines: {
USE_MAP: true,
USE_UV: true,
},
lights: true,
fog: true,
})
})
}
Example #16
Source File: skybox.js From architect3d with MIT License | 6 votes |
setEnvironmentMap(url)
{
var scope = this;
scope.texture.load(url, function (t)
{
var textureUniform = {type: 't', value: t};
var uniforms = {texture: textureUniform};
scope.skyMat = new ShaderMaterial({vertexShader: scope.vertexShader, fragmentShader: scope.fragmentShader, uniforms: uniforms, side: DoubleSide});
scope.toggleEnvironment(scope.useEnvironment);
}, undefined, function()
{
console.log('ERROR LOADEING FILE');
});
}
Example #17
Source File: ExtrudeMarker.js From BlueMapWeb with MIT License | 6 votes |
/**
* @param shape {Shape}
*/
constructor(shape) {
let geometry = ExtrudeMarkerFill.createGeometry(shape);
let material = new ShaderMaterial({
vertexShader: MARKER_FILL_VERTEX_SHADER,
fragmentShader: MARKER_FILL_FRAGMENT_SHADER,
side: DoubleSide,
depthTest: true,
transparent: true,
uniforms: {
markerColor: { value: new Color() },
markerOpacity: { value: 0 },
fadeDistanceMin: { value: 0 },
fadeDistanceMax: { value: Number.MAX_VALUE },
}
});
super(geometry, material);
}
Example #18
Source File: ShapeMarker.js From BlueMapWeb with MIT License | 6 votes |
/**
* @param shape {Shape}
*/
constructor(shape) {
let geometry = ShapeMarkerFill.createGeometry(shape);
let material = new ShaderMaterial({
vertexShader: MARKER_FILL_VERTEX_SHADER,
fragmentShader: MARKER_FILL_FRAGMENT_SHADER,
side: DoubleSide,
depthTest: true,
transparent: true,
uniforms: {
markerColor: { value: new Color() },
markerOpacity: { value: 0 },
fadeDistanceMin: { value: 0 },
fadeDistanceMax: { value: Number.MAX_VALUE },
}
});
super(geometry, material);
}
Example #19
Source File: Sky.js From canvas with Apache License 2.0 | 6 votes |
Sky = function () {
var shader = Sky.SkyShader;
var material = new ShaderMaterial( {
fragmentShader: shader.fragmentShader,
vertexShader: shader.vertexShader,
uniforms: UniformsUtils.clone( shader.uniforms ),
side: BackSide,
depthWrite: false
} );
Mesh.call( this, new BoxBufferGeometry( 1, 1, 1 ), material );
}
Example #20
Source File: SkyboxScene.js From BlueMapWeb with MIT License | 6 votes |
constructor(uniforms) {
super();
this.autoUpdate = false;
Object.defineProperty(this, 'isSkyboxScene', {value: true});
let geometry = new SphereGeometry(1, 40, 5);
let material = new ShaderMaterial({
uniforms: uniforms,
vertexShader: SKY_VERTEX_SHADER,
fragmentShader: SKY_FRAGMENT_SHADER,
side: BackSide
});
let skybox = new Mesh(geometry, material);
this.add(skybox);
}
Example #21
Source File: ShaderPass.js From AudioPlayer with MIT License | 6 votes |
ShaderPass = function (shader, textureID) {
Pass.call(this);
this.textureID = textureID !== undefined ? textureID : "tDiffuse";
if (shader instanceof ShaderMaterial) {
this.uniforms = shader.uniforms;
this.material = shader;
} else if (shader) {
this.uniforms = UniformsUtils.clone(shader.uniforms);
this.material = new ShaderMaterial({
defines: Object.assign({}, shader.defines),
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
});
}
this.fsQuad = new Pass.FullScreenQuad(this.material);
}
Example #22
Source File: LineMaterial.js From BlueMapWeb with MIT License | 5 votes |
LineMaterial.prototype = Object.create( ShaderMaterial.prototype );
Example #23
Source File: Map.js From BlueMapWeb with MIT License | 5 votes |
/**
* Creates a hires Material with the given textures
* @param vertexShader {string}
* @param fragmentShader {string}
* @param uniforms {object}
* @param textures {{
* resourcePath: string,
* color: number[],
* halfTransparent: boolean,
* texture: string
* }[]} the textures-data
* @returns {ShaderMaterial[]} the hires Material (array because its a multi-material)
*/
createHiresMaterial(vertexShader, fragmentShader, uniforms, textures) {
let materials = [];
if (!Array.isArray(textures)) throw new Error("Invalid texture.json: 'textures' is not an array!")
for (let i = 0; i < textures.length; i++) {
let textureSettings = textures[i];
let color = textureSettings.color;
if (!Array.isArray(color) || color.length < 4){
color = [0, 0, 0, 0];
}
let opaque = color[3] === 1;
let transparent = !!textureSettings.halfTransparent;
let texture = new Texture();
texture.image = stringToImage(textureSettings.texture);
texture.anisotropy = 1;
texture.generateMipmaps = opaque || transparent;
texture.magFilter = NearestFilter;
texture.minFilter = texture.generateMipmaps ? NearestMipMapLinearFilter : NearestFilter;
texture.wrapS = ClampToEdgeWrapping;
texture.wrapT = ClampToEdgeWrapping;
texture.flipY = false;
texture.flatShading = true;
texture.image.addEventListener("load", () => texture.needsUpdate = true);
this.loadedTextures.push(texture);
let material = new ShaderMaterial({
uniforms: {
...uniforms,
textureImage: {
type: 't',
value: texture
},
transparent: { value: transparent }
},
vertexShader: vertexShader,
fragmentShader: fragmentShader,
transparent: transparent,
depthWrite: true,
depthTest: true,
vertexColors: VertexColors,
side: FrontSide,
wireframe: false,
});
material.needsUpdate = true;
materials[i] = material;
}
return materials;
}
Example #24
Source File: Map.js From BlueMapWeb with MIT License | 5 votes |
/**
* @param id {string}
* @param dataUrl {string}
* @param events {EventTarget}
*/
constructor(id, dataUrl, events = null) {
Object.defineProperty( this, 'isMap', { value: true } );
this.events = events;
this.data = {
id: id,
sorting: 0,
dataUrl: dataUrl,
settingsUrl: dataUrl + "settings.json",
texturesUrl: dataUrl + "textures.json",
name: id,
startPos: {x: 0, z: 0},
skyColor: new Color(),
ambientLight: 0,
hires: {
tileSize: {x: 32, z: 32},
scale: {x: 1, z: 1},
translate: {x: 2, z: 2}
},
lowres: {
tileSize: {x: 32, z: 32},
scale: {x: 1, z: 1},
translate: {x: 2, z: 2}
}
};
this.raycaster = new Raycaster();
/** @type {ShaderMaterial[]} */
this.hiresMaterial = null;
/** @type {ShaderMaterial} */
this.lowresMaterial = null;
/** @type {Texture[]} */
this.loadedTextures = [];
/** @type {TileManager} */
this.hiresTileManager = null;
/** @type {TileManager} */
this.lowresTileManager = null;
}
Example #25
Source File: OutlinePass.js From Computer-Graphics with MIT License | 5 votes |
getOverlayMaterial() {
return new ShaderMaterial( {
uniforms: {
'maskTexture': { value: null },
'edgeTexture1': { value: null },
'edgeTexture2': { value: null },
'patternTexture': { value: null },
'edgeStrength': { value: 1.0 },
'edgeGlow': { value: 1.0 },
'usePatternTexture': { value: 0.0 }
},
vertexShader:
`varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,
fragmentShader:
`varying vec2 vUv;
uniform sampler2D maskTexture;
uniform sampler2D edgeTexture1;
uniform sampler2D edgeTexture2;
uniform sampler2D patternTexture;
uniform float edgeStrength;
uniform float edgeGlow;
uniform bool usePatternTexture;
void main() {
vec4 edgeValue1 = texture2D(edgeTexture1, vUv);
vec4 edgeValue2 = texture2D(edgeTexture2, vUv);
vec4 maskColor = texture2D(maskTexture, vUv);
vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);
float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;
vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;
vec4 finalColor = edgeStrength * maskColor.r * edgeValue;
if(usePatternTexture)
finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);
gl_FragColor = finalColor;
}`,
blending: AdditiveBlending,
depthTest: false,
depthWrite: false,
transparent: true
} );
}
Example #26
Source File: OutlinePass.js From Computer-Graphics with MIT License | 5 votes |
getSeperableBlurMaterial( maxRadius ) {
return new ShaderMaterial( {
defines: {
'MAX_RADIUS': maxRadius,
},
uniforms: {
'colorTexture': { value: null },
'texSize': { value: new Vector2( 0.5, 0.5 ) },
'direction': { value: new Vector2( 0.5, 0.5 ) },
'kernelRadius': { value: 1.0 }
},
vertexShader:
`varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,
fragmentShader:
`#include <common>
varying vec2 vUv;
uniform sampler2D colorTexture;
uniform vec2 texSize;
uniform vec2 direction;
uniform float kernelRadius;
float gaussianPdf(in float x, in float sigma) {
return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;
}
void main() {
vec2 invSize = 1.0 / texSize;
float weightSum = gaussianPdf(0.0, kernelRadius);
vec4 diffuseSum = texture2D( colorTexture, vUv) * weightSum;
vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);
vec2 uvOffset = delta;
for( int i = 1; i <= MAX_RADIUS; i ++ ) {
float w = gaussianPdf(uvOffset.x, kernelRadius);
vec4 sample1 = texture2D( colorTexture, vUv + uvOffset);
vec4 sample2 = texture2D( colorTexture, vUv - uvOffset);
diffuseSum += ((sample1 + sample2) * w);
weightSum += (2.0 * w);
uvOffset += delta;
}
gl_FragColor = diffuseSum/weightSum;
}`
} );
}
Example #27
Source File: OutlinePass.js From Computer-Graphics with MIT License | 5 votes |
getEdgeDetectionMaterial() {
return new ShaderMaterial( {
uniforms: {
'maskTexture': { value: null },
'texSize': { value: new Vector2( 0.5, 0.5 ) },
'visibleEdgeColor': { value: new Vector3( 1.0, 1.0, 1.0 ) },
'hiddenEdgeColor': { value: new Vector3( 1.0, 1.0, 1.0 ) },
},
vertexShader:
`varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,
fragmentShader:
`varying vec2 vUv;
uniform sampler2D maskTexture;
uniform vec2 texSize;
uniform vec3 visibleEdgeColor;
uniform vec3 hiddenEdgeColor;
void main() {
vec2 invSize = 1.0 / texSize;
vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);
vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);
vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);
vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);
vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);
float diff1 = (c1.r - c2.r)*0.5;
float diff2 = (c3.r - c4.r)*0.5;
float d = length( vec2(diff1, diff2) );
float a1 = min(c1.g, c2.g);
float a2 = min(c3.g, c4.g);
float visibilityFactor = min(a1, a2);
vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;
gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);
}`
} );
}
Example #28
Source File: OutlinePass.js From Computer-Graphics with MIT License | 5 votes |
getPrepareMaskMaterial() {
return new ShaderMaterial( {
uniforms: {
'depthTexture': { value: null },
'cameraNearFar': { value: new Vector2( 0.5, 0.5 ) },
'textureMatrix': { value: null }
},
vertexShader:
`#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
varying vec4 projTexCoord;
varying vec4 vPosition;
uniform mat4 textureMatrix;
void main() {
#include <skinbase_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
vPosition = mvPosition;
vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );
projTexCoord = textureMatrix * worldPosition;
}`,
fragmentShader:
`#include <packing>
varying vec4 vPosition;
varying vec4 projTexCoord;
uniform sampler2D depthTexture;
uniform vec2 cameraNearFar;
void main() {
float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));
float viewZ = - DEPTH_TO_VIEW_Z( depth, cameraNearFar.x, cameraNearFar.y );
float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;
gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);
}`
} );
}
Example #29
Source File: skybox.js From architect3d with MIT License | 5 votes |
constructor(scene, renderer)
{
super();
this.defaultEnvironment = 'rooms/textures/envs/Garden.png';
this.useEnvironment = false;
this.topColor = 0x92b2ce;//0xe9e9e9; //0xf9f9f9;//0x565e63
this.bottomColor = 0xffffff;//0xD8ECF9
this.verticalOffset = 400;
this.exponent = 0.5;
var uniforms = {topColor: {type: 'c',value: new Color(this.topColor)},bottomColor: {type: 'c',value: new Color(this.bottomColor)},offset: {type: 'f',value: this.verticalOffset}, exponent: {type:'f', value: this.exponent}};
this.scene = scene;
this.renderer = renderer;
this.sphereRadius = 4000;
this.widthSegments = 32;
this.heightSegments = 15;
this.sky = null;
this.plainVertexShader = ['varying vec3 vWorldPosition;','void main() {','vec4 worldPosition = modelMatrix * vec4( position, 1.0 );','vWorldPosition = worldPosition.xyz;','gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0 );','}'].join('\n');
this.plainFragmentShader = ['uniform vec3 bottomColor;','uniform vec3 topColor;','uniform float offset;','uniform float exponent;','varying vec3 vWorldPosition;','void main() {',' float h = normalize( vWorldPosition + offset ).y;',' gl_FragColor = vec4( mix( bottomColor, topColor, max( pow( max(h, 0.0 ), exponent ), 0.0 ) ), 1.0 );','}'].join('\n');
this.vertexShader = ['varying vec2 vUV;','void main() {',' vUV=uv;',' vec4 pos = vec4(position, 1.0);', ' gl_Position = projectionMatrix * modelViewMatrix * pos;','}'].join('\n');
this.fragmentShader = ['uniform sampler2D texture;', 'varying vec2 vUV;', 'void main() { ', 'vec4 sample = texture2D(texture, vUV);', 'gl_FragColor = vec4(sample.xyz, sample.w);' ,'}'].join('\n');
this.texture = new TextureLoader();
this.plainSkyMat = new ShaderMaterial({vertexShader: this.plainVertexShader,fragmentShader: this.plainFragmentShader,uniforms: uniforms, side: DoubleSide});
this.skyMat = undefined;
this.skyGeo = new SphereGeometry(this.sphereRadius, this.widthSegments, this.heightSegments);
this.sky = new Mesh(this.skyGeo, this.skyMat);
// this.sky.position.x += this.sphereRadius*0.5;
var groundT = new TextureLoader().load('rooms/textures/Ground_4K.jpg', function(){});
groundT.wrapS = groundT.wrapT = RepeatWrapping;
groundT.repeat.set(10,10);
// var uniforms2 = {topColor: {type: 'c',value: new Color(0xFFFFFF)},bottomColor: {type: 'c',value: new Color(0x999999)},offset: {type: 'f',value: this.verticalOffset}, exponent: {type:'f', value: this.exponent}};
this.groundGeo = new PlaneGeometry(10000, 10000, 10);
this.groundMat = new MeshBasicMaterial({color: 0xEAEAEA, side: DoubleSide, map:groundT });
this.ground = new Mesh(this.groundGeo, this.groundMat);
this.ground.rotateX(-Math.PI * 0.5);
this.ground.position.y = -1;
this.groundSceneReflector = new GroundSceneReflector(this.ground, this.renderer, this.scene,{textureOne:'rooms/textures/Ground_4K.jpg', textureTwo:'rooms/textures/GroundRough.jpg', wrapOne:{x:40, y:40}, wrapTwo:{x:50, y:50}, textureWidth: 512, textureHeight: 512, intensity: 0.1, blendIntensity: 0.05});
this.scene.add(this.sky);
this.scene.add(this.ground);
var axesHelper = new AxesHelper( 100 );
this.scene.add( axesHelper );
this.init();
}