Options
All
  • Public
  • Public/Protected
  • All
Menu

Package harp-materials

@here/harp-materials

Overview

This module is a container for the different Materials used by harp.gl based on the definition by three.js. A Material describes the appearance of an object.

Index

References

Namespaces

Enumerations

Classes

Interfaces

Variables

Functions

Object literals

References

CirclePointsMaterial

Re-exports CirclePointsMaterial

CirclePointsMaterialParameters

Re-exports CirclePointsMaterialParameters

CopyMaterial

Re-exports CopyMaterial

CopyShader

Re-exports CopyShader

DEFINE_BOOL_FALSE

Re-exports DEFINE_BOOL_FALSE

DEFINE_BOOL_TRUE

Re-exports DEFINE_BOOL_TRUE

DisplacementFeature

Re-exports DisplacementFeature

DisplacementFeatureMixin

Re-exports DisplacementFeatureMixin

DisplacementFeatureParameters

Re-exports DisplacementFeatureParameters

EdgeMaterial

Re-exports EdgeMaterial

EdgeMaterialParameters

Re-exports EdgeMaterialParameters

ExtrusionFeature

Re-exports ExtrusionFeature

ExtrusionFeatureDefs

Re-exports ExtrusionFeatureDefs

ExtrusionFeatureMixin

Re-exports ExtrusionFeatureMixin

ExtrusionFeatureParameters

Re-exports ExtrusionFeatureParameters

FadingFeature

Re-exports FadingFeature

FadingFeatureMixin

Re-exports FadingFeatureMixin

FadingFeatureParameters

Re-exports FadingFeatureParameters

ForcedBlending

Re-exports ForcedBlending

GroundAtmosphereMaterial

Re-exports GroundAtmosphereMaterial

GroundAtmosphereMaterialParameters

Re-exports GroundAtmosphereMaterialParameters

GroundAtmosphereShader

Re-exports GroundAtmosphereShader

HiddenThreeJSMaterialProperties

Re-exports HiddenThreeJSMaterialProperties

HighPrecisionLineMaterial

Re-exports HighPrecisionLineMaterial

HighPrecisionLineMaterialParameters

Re-exports HighPrecisionLineMaterialParameters

HighPrecisionPointMaterial

Re-exports HighPrecisionPointMaterial

HighPrecisionPointMaterialParameters

Re-exports HighPrecisionPointMaterialParameters

IconMaterial

Re-exports IconMaterial

IconMaterialParameters

Re-exports IconMaterialParameters

LineDashesModes

Re-exports LineDashesModes

LuminosityHighPassShader

Re-exports LuminosityHighPassShader

MSAAMaterial

Re-exports MSAAMaterial

MapMeshBasicMaterial

Re-exports MapMeshBasicMaterial

MapMeshDepthMaterial

Re-exports MapMeshDepthMaterial

MapMeshStandardMaterial

Re-exports MapMeshStandardMaterial

RawShaderMaterial

Re-exports RawShaderMaterial

RawShaderMaterialParameters

Re-exports RawShaderMaterialParameters

RendererMaterialParameters

Re-exports RendererMaterialParameters

SepiaShader

Re-exports SepiaShader

ShadowFeatureParameters

Re-exports ShadowFeatureParameters

SkyAtmosphereMaterial

Re-exports SkyAtmosphereMaterial

SkyAtmosphereMaterialParameters

Re-exports SkyAtmosphereMaterialParameters

SkyAtmosphereShader

Re-exports SkyAtmosphereShader

SolidLineMaterial

Re-exports SolidLineMaterial

SolidLineMaterialParameters

Re-exports SolidLineMaterialParameters

VignetteShader

Re-exports VignetteShader

disableBlending

Re-exports disableBlending

enableBlending

Re-exports enableBlending

enforceBlending

Re-exports enforceBlending

getShaderDefine

Re-exports getShaderDefine

getShaderMaterialDefine

Re-exports getShaderMaterialDefine

hasDisplacementFeature

Re-exports hasDisplacementFeature

hasExtrusionFeature

Re-exports hasExtrusionFeature

insertShaderInclude

Re-exports insertShaderInclude

isHighPrecisionLineMaterial

Re-exports isHighPrecisionLineMaterial

isHighPrecisionPointMaterial

Re-exports isHighPrecisionPointMaterial

setDisplacementMapToMaterial

Re-exports setDisplacementMapToMaterial

setShaderDefine

Re-exports setShaderDefine

setShaderMaterialDefine

Re-exports setShaderMaterialDefine

Variables

Const DEFINE_BOOL_FALSE

DEFINE_BOOL_FALSE: undefined = undefined

Const DEFINE_BOOL_TRUE

DEFINE_BOOL_TRUE: "" = ""

Values for boolean shader defines

Const simpleLightingShadowChunk

simpleLightingShadowChunk: "struct PhysicalMaterial {vec3 diffuseColor;float specularRoughness;vec3 specularColor;};#define DEFAULT_SPECULAR_COEFFICIENT 0.04void RE_Direct_Physical( const in IncidentLight directLight,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight ) {// directLight.color is the light color * shadow, internally three.js uses a step function, so// this value is either the light color or black. in order to lighten up the shadows, we// take add 50% of the color to grey (to give us either pure white or grey) and multiply this to// the material's diffuse color.#if defined(USE_SHADOWMAP)reflectedLight.directDiffuse = (0.5 * directLight.color +vec3(0.5,0.5,0.5)) * material.diffuseColor;#elsereflectedLight.directDiffuse = material.diffuseColor;#endif}void RE_IndirectDiffuse_Physical( const in vec3 irradiance,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight ) {// Disable influence of indirect light (it is handled in the RE_Direct_Physical function)}void RE_IndirectSpecular_Physical( const in vec3 radiance,const in vec3 irradiance,const in vec3 clearcoatRadiance,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight) {// Disable specular reflection of light.}#define RE_Direct RE_Direct_Physical#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical#define RE_IndirectSpecular RE_IndirectSpecular_Physical" = `struct PhysicalMaterial {vec3 diffuseColor;float specularRoughness;vec3 specularColor;};#define DEFAULT_SPECULAR_COEFFICIENT 0.04void RE_Direct_Physical( const in IncidentLight directLight,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight ) {// directLight.color is the light color * shadow, internally three.js uses a step function, so// this value is either the light color or black. in order to lighten up the shadows, we// take add 50% of the color to grey (to give us either pure white or grey) and multiply this to// the material's diffuse color.#if defined(USE_SHADOWMAP)reflectedLight.directDiffuse = (0.5 * directLight.color +vec3(0.5,0.5,0.5)) * material.diffuseColor;#elsereflectedLight.directDiffuse = material.diffuseColor;#endif}void RE_IndirectDiffuse_Physical( const in vec3 irradiance,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight ) {// Disable influence of indirect light (it is handled in the RE_Direct_Physical function)}void RE_IndirectSpecular_Physical( const in vec3 radiance,const in vec3 irradiance,const in vec3 clearcoatRadiance,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight) {// Disable specular reflection of light.}#define RE_Direct RE_Direct_Physical#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical#define RE_IndirectSpecular RE_IndirectSpecular_Physical`

This shader chunk replaces the default lighting in the standard material, the problem with this is that the final pixel color is the addition of the material color and the light, this means that the final map's rendered color is vastly different from that configured by the designers. This chunk removes the extra highlight by providing just two colors, the material color when not in shadow and a reduced color value when in shadow (currently 50% of the material's color).

Functions

disableBlending

  • disableBlending(material: Material | ShaderMaterialParameters & ForcedBlending): void
  • Disable alpha blending using THREE.CustomBlending mode, switches to [[THREE.NormalBlending]].

    note

    Blending mode change does not require material update.

    see

    THREE.Material.needsUpdate.

    see

    enableBlending.

    Parameters

    • material: Material | ShaderMaterialParameters & ForcedBlending

      The material or material parameters to modify.

    Returns void

enableBlending

  • enableBlending(material: Material | ShaderMaterialParameters & ForcedBlending): void
  • Enable alpha blending using THREE.CustomBlending setup.

    Function enables blending using one of predefined modes, for both color and alpha components:

    • Src: [[THREE.SrcAlphaFactor]], Dst: [[THREE.OneMinusSrcAlphaFactor]]
    • Src: [[THREE.OneFactor]], Dst: [[THREE.OneMinusSrcAlphaFactor]] The second blending equation is used when [[THREE.Material.premultipliedAlpha]] is enabled for this material.
    note

    Blending mode change does not require material update.

    see

    THREE.Material.needsUpdate.

    Parameters

    • material: Material | ShaderMaterialParameters & ForcedBlending

      The material or material parameters to modify.

    Returns void

enforceBlending

  • enforceBlending(material: Material | ShaderMaterialParameters & ForcedBlending): void
  • THREE.js is enabling blending only when transparent is true or when a blend mode different than NormalBlending is set. Since we don't want to set transparent to true and mess up the render order we set CustomBlending with the same parameters as the NormalBlending.

    note

    This function should not be used in frame update after material has been passed to WebGL. In such cases use enableBlending instead.

    Parameters

    • material: Material | ShaderMaterialParameters & ForcedBlending

      Material that should use blending

    Returns void

getShaderDefine

  • getShaderDefine(defines: {}, key: string): boolean | number
  • Acquire shader 'define' value from defines map.

    If there is no value under [[key]] specified, function returns false, otherwise result is true or numeric value if there is a number stored.

    Parameters

    • defines: {}

      The defines map.

      • [key: string]: any
    • key: string

      The identifier of the define.

    Returns boolean | number

getShaderMaterialDefine

  • getShaderMaterialDefine(material: ShaderMaterial, key: string, fallbackValue?: boolean | number): boolean | number
  • Acquire value of [[THREE.ShaderMaterial]] GPU shader preprocessor define.

    The semantic used in entire engine assumes that preprocessor defines may have only binary (defined / not defined) or numerical values, this ensures consistency in the shaders and materials code.

    note

    If define with [[key]] is undefined function returns [[false]], if defined but not numerical value it returns [[true]], otherwise returns number.

    see

    setShaderMaterialDefine.

    Parameters

    • material: ShaderMaterial

      The material which shader defines are accessed.

    • key: string

      The define name (identifier).

    • Default value fallbackValue: boolean | number = false

      The value returned when material defines are not initialized yet, specified by default as [[false]], provide your own default if you expect numeric value.

    Returns boolean | number

hasDisplacementFeature

  • hasDisplacementFeature(material: any): material is DisplacementFeature
  • Determines whether a given material supports displacement maps for elevation overlay.

    Parameters

    • material: any

      The material to check.

    Returns material is DisplacementFeature

    Whether the given material supports displacement maps for elevation overlay.

hasExtrusionFeature

  • hasExtrusionFeature(material: any): material is ExtrusionFeature
  • Determines whether a given material supports extrusion.

    Parameters

    • material: any

      The material to check.

    Returns material is ExtrusionFeature

    Whether the given material supports extrusion.

insertShaderInclude

  • insertShaderInclude(shaderContent: string, shaderName: string, insertedShaderName: string, addTab?: undefined | false | true): string
  • Insert shader includes after another shader include.

    Parameters

    • shaderContent: string

      Original string.

    • shaderName: string

      String to append to.

    • insertedShaderName: string

      String to append after string shaderA.

    • Optional addTab: undefined | false | true

      If true, a tab character will be inserted before shaderB.

    Returns string

isHighPrecisionLineMaterial

  • isHighPrecisionLineMaterial(material: object | undefined): material is HighPrecisionLineMaterial

isHighPrecisionPointMaterial

  • isHighPrecisionPointMaterial(material: object | undefined): material is HighPrecisionPointMaterial

setDisplacementMapToMaterial

  • setDisplacementMapToMaterial(displacementMap: DataTexture | null, material: Mesh["material"]): void
  • Sets the displacement map to the given material.

    Parameters

    • displacementMap: DataTexture | null

      Texture representing the elevation data used to overlay the object.

    • material: Mesh["material"]

      The Material to be updated.

    Returns void

setShaderDefine

  • setShaderDefine(defines: {}, key: string, value: boolean | number): boolean
  • Sets new value of 'define' regardless of current value set.

    Update defines map with new key and value, if key is already occupied it overrides its value. Helper function that may be used to setup [[THREE.ShaderMaterialParameters]] before material is create (i.e. in c-tor).

    see

    setShaderMaterialDefine.

    Parameters

    • defines: {}

      Shader defines stored in key-value map.

      • [key: string]: any
    • key: string

      The key used to identify define.

    • value: boolean | number

      The value to be stored.

    Returns boolean

    [[true]] if define has actually changed, false is stayed the same.

setShaderMaterialDefine

  • setShaderMaterialDefine(material: ShaderMaterial, key: string, value: boolean | number): boolean
  • Setup material shader define using two allowable semantics.

    Function accepts two types of values for shader preprocessor define:

    • [[boolean]], simple [[true]] or [[false]] which causes define to be set with empty string, such defines may be handled in the shader using #ifdef semantics:

      #ifdef SOME_DEFINE && !defined(OTHER_DEFINE)
      // do something
      #endif
    • [[number]] which sets define to explicit value. You may use it to enable/disable some code or even set compile time constants affecting shaders math:

      #if SOME_DEFINE_SWITCH && OTHER_DEFINE_SWITCH == 0
      gl_FragColor = vec4(1, 1, 1, DEFINE_ALPHA)
      #endif
    note

    Setting define with false value is not the same as setting is with number value of 0.

    Parameters

    • material: ShaderMaterial

      The [[THREE.ShaderMaterial]] which shader define will be set.

    • key: string

      Name of shader define as used in shader, i.e. USE_FOG, COLOR_ALPHA, etc.

    • value: boolean | number

      The value to be set as number or boolean specifying if preprocessor define should be defined or not.

    Returns boolean

    [[true]] if material has been forced to update (re-compile) due to define changes, return [[false]] whenever define has not been changed.

Object literals

Const CopyShader

CopyShader: object

The base shader to use for {@link @here/harp-mapview#MapView}'s composing passes, like MSAAMaterial.

fragmentShader

fragmentShader: string = `uniform float opacity;uniform sampler2D tDiffuse;varying vec2 vUv;void main() {vec4 texel = texture2D( tDiffuse, vUv );gl_FragColor = opacity * texel;}`

vertexShader

vertexShader: string = `varying vec2 vUv;void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}`

uniforms

uniforms: object

opacity

opacity: object

value

value: number = 1

tDiffuse

tDiffuse: object

value

value: null = null

Const GroundAtmosphereShader

GroundAtmosphereShader: object

GroundAtmosphereShader.

Describes shading of atmosphere as seen from outer space.

fragmentShader

fragmentShader: string = `// Exposure correction gives more subtle gradients on the ground.#define CORRECT_EXPOSURE 1#define FADE_DEPTH 1#define NIGHT_LOCAL 1precision highp float;precision highp int;#ifdef CORRECT_COLORuniform vec3 u_hsvCorrection; // Hue, saturation, brightness#endifuniform vec3 u_atmosphereEnv; // Atmosphere inner and outer radius, camera heightuniform vec3 u_eyePositionWorld;uniform vec3 u_lightDirectionWorld;const float g = -0.95;const float g2 = g * g;varying vec3 v_rayleighColor;varying vec3 v_mieColor;varying vec3 v_vertToCamera;varying vec3 v_vertToOrigin;${AtmosphereShaderChunks.atmosphere_fragment_utils}void main(void){float fInnerRadius = u_atmosphereEnv.x;float fOuterRadius = u_atmosphereEnv.y;float fCameraHeight = u_atmosphereEnv.z;#ifdef DYNAMIC_LIGHTvec3 vLightDir = u_lightDirectionWorld;#elsevec3 vLightDir = u_eyePositionWorld;#endifvLightDir = normalize(vLightDir);// GPU gems mix of ground solution, with custom alpha settingsvec3 cRgb = v_mieColor + 0.25 * v_rayleighColor;// Not needed for HDR frame buffer#if !defined(HDR_FRAME_BUFFER) && defined(CORRECT_EXPOSURE)// Interesting results with exposure factor: 2.0, 3.5, 4.0cRgb = correctExposure(cRgb, 3.0);#endif#ifdef CORRECT_COLORcRgb = correctColor(cRgb, u_hsvCorrection);#endif// Base atmosphere opacityfloat fAtmosphereAlpha = 1.0;// Factor based on the distance of camera atmosphere and ground, results are:// 0.0 = camera on the ground surface,// 1.0 = at the outer edge of the atmosphere.float fDepthFactor = clamp((fCameraHeight - fInnerRadius) /(fOuterRadius - fInnerRadius), 0.0, 1.0);#ifdef FADE_DEPTH// Fade alpha based on the distance of camera between atmosphere layers#ifdef FADE_DEPTH_LINEARfAtmosphereAlpha *= fDepthFactor;#elsefAtmosphereAlpha *= pow(fDepthFactor, 1.5);#endif#endif#if defined(FADE_NIGHT) || defined(DARKEN_NIGHT)#ifdef DYNAMIC_LIGHT// Adjust factor based on time of day, results are:// 0.0 = night,// 1.0 = day.#ifdef NIGHT_GLOBAL// Global night fade based on camera and light orientationfloat fNightFactor = clamp(dot(normalize(u_eyePositionWorld), vLightDir), 0.0, 1.0);fNightFactor = pow(fNightFactor, 0.5);#else // NIGHT_LOCALfloat fNightFactor =clamp(dot(v_vertToOrigin, vLightDir) / length(v_vertToOrigin), 0.0, 1.0);fNightFactor = pow(fNightFactor, 0.8);#endif#elsefloat fNightFactor = 1.0;#endif#endif#ifdef FADE_NIGHT// Adjust alpha for night side of the globefAtmosphereAlpha *= fNightFactor;#endif#ifdef DARKEN_NIGHT// Change the brightness depending on night / day side.// NOTE: Darkening should be rather applied in HSV space, without loss on saturation,// but it is much more GPU consuming.const float minBrightness = 0.5;float fDarkenFactor = clamp(fNightFactor, minBrightness, 1.0);cRgb *= fDarkenFactor;#endif#ifdef EXPOSURE_DEPTH// Control exposure depending from ground distancefloat exposureBoost = 3.0 - fDepthFactor;cRgb = correctExposure(cRgb, exposureBoost);#endif// Experimental fading out of focus point - similar to fresnel effect in top view.// This fade is handy to better expose cartographic/map features in screen center.float fFocusFactor = 1.0 - clamp(dot(normalize(v_vertToCamera), v_vertToOrigin), 0.0, 1.0) + 0.1;fFocusFactor = pow(fFocusFactor, 2.5);fAtmosphereAlpha *= fFocusFactor;// Integrate all featuresgl_FragColor = vec4(cRgb, fAtmosphereAlpha);}`

vertexShader

vertexShader: string = `#define IMPROVE_INTERSECT_PRECISION 1#define IMPROVE_DOT_PRECISION 1precision highp float;precision highp int;attribute vec4 position;// Base mandatory uniformsuniform mat4 u_modelViewProjection;uniform vec3 u_eyePositionWorld;uniform vec3 u_lightDirectionWorld;uniform vec3 u_atmosphereEnv; // Atmosphere inner and outer radius, camera heightuniform vec3 u_hsvCorrection;const float Pi = 3.141592653589793;const float Kr = 0.0025;const float Km = 0.0015;const float Kr4PI = Kr * 4.0 * Pi;const float Km4PI = Km * 4.0 * Pi;const float ESun = 25.0; // should be 15.0const float KmESun = Km * ESun;const float KrESun = Kr * ESun;const vec3 InvWavelength = vec3(1.0 / pow(0.650, 4.0), // Red1.0 / pow(0.570, 4.0), // Green1.0 / pow(0.475, 4.0)); // Blueconst int nSamples = 2;const float fSamples = 2.0;varying vec3 v_rayleighColor;varying vec3 v_mieColor;varying vec3 v_vertToCamera;varying vec3 v_vertToOrigin;${AtmosphereShaderChunks.atmosphere_vertex_utils}//// Computes rayleight and mia atmosphere factors for ground.//// Code based on GPU Gems article.//// Author: Sean O'Neil//// Copyright (c) 2004 Sean O'Neil//// https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering//// Further modifications by HERE.//AtmosphereColor computeGroundAtmosphere(vec3 v3Pos, vec3 vLightDir){// Retrieve environment variablesfloat fInnerRadius = u_atmosphereEnv.x;float fOuterRadius = u_atmosphereEnv.y;float fCameraHeight = u_atmosphereEnv.z;// All that may be moved to const or define(s) at further optimizations:float fScale = 1.0 / (fOuterRadius - fInnerRadius);float fScaleOverScaleDepth = fScale / RayleighScaleDepth;float fCameraHeight2 = fCameraHeight * fCameraHeight;float fOuterRadius2 = fOuterRadius * fOuterRadius;// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)vec3 v3Ray = v3Pos - u_eyePositionWorld;float fFar = length(v3Ray);v3Ray /= fFar;#if !defined(IMPROVE_DOT_PRECISION)vec3 v3Dir = normalize(v3Pos);#endif#ifdef CAMERA_IN_SPACE// Calculate first point of camera ray and sphere intersection.float fNear = getNearSphereIntersect(u_eyePositionWorld, v3Ray, fCameraHeight2, fOuterRadius2);// Make far relative to first atmosphere intersection, setting it to// the length of ray passed through atmospherefFar -= fNear;// Compute the ray's starting position within the atmosphere, then// calculate its scattering offsetvec3 v3Start = u_eyePositionWorld + v3Ray * fNear;float fDepth = exp((fInnerRadius - fOuterRadius) / RayleighScaleDepth);#else // CAMERA_IN_ATMOSPHERE// The ray starts already in atmospherevec3 v3Start = u_eyePositionWorld;// Virtually fNear is just at eye position, so ray passing through atmosphere does not shorten// fFar -= 0.0;float fDepth = exp((fInnerRadius - fCameraHeight) / RayleighScaleDepth);#endif#if defined(IMPROVE_DOT_PRECISION)float fCameraAngle = dot(-v3Ray, v3Pos) / length(v3Pos);#elsefloat fCameraAngle = dot(-v3Ray, v3Dir);#endiffloat fCameraScale = scale(fCameraAngle);#ifdef DYNAMIC_LIGHT// When we want the atmosphere to be uniform over the globe so it is set to 1.0.#if defined(IMPROVE_DOT_PRECISION)// The light angle for given light source may be calculated as:// angle = dot(vLightDir, v3Dir) / length(v3Dir);// where v3Dir holds normalized vertex position, but for precision issues we v3Pos (un-normalized)float fLightAngle = dot(vLightDir, v3Pos) / length(v3Pos);#elsefloat fLightAngle = dot(vLightDir, v3Dir);#endif#elsefloat fLightAngle = 1.0;#endiffloat fLightScale = scale(fLightAngle);float fCameraOffset = fDepth * fCameraScale;float fTemp = (fLightScale + fCameraScale);// Initialize the scattering loop variablesfloat fSampleLength = fFar / fSamples;float fScaledLength = fSampleLength * fScale;vec3 v3SampleRay = v3Ray * fSampleLength;vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;// Now loop through the sample raysvec3 v3BaseColor = vec3(0.0);vec3 v3Attenuate = vec3(0.0);for(int i = 0; i < nSamples; i++){float fHeight = length(v3SamplePoint);float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));float fScatter = fDepth * fTemp - fCameraOffset;// Compute color factorsv3Attenuate = exp(-fScatter * (InvWavelength * Kr4PI + Km4PI));v3BaseColor += v3Attenuate * (fDepth * fScaledLength);// Move to the next pointv3SamplePoint += v3SampleRay;}AtmosphereColor color;color.mie = v3BaseColor * (InvWavelength * KrESun + KmESun);// Calculate the attenuation factor for the groundcolor.rayleigh = v3Attenuate;return color;}void main(void){#ifdef DYNAMIC_LIGHTvec3 vLightDir = u_lightDirectionWorld;#elsevec3 vLightDir = u_eyePositionWorld;#endifvLightDir = normalize(vLightDir);AtmosphereColor atmColor = computeGroundAtmosphere(position.xyz, vLightDir);v_mieColor = atmColor.mie;v_rayleighColor = atmColor.rayleigh;v_vertToCamera = u_eyePositionWorld - position.xyz;v_vertToOrigin = normalize(position.xyz);gl_Position = u_modelViewProjection * position;}`

uniforms

uniforms: object

bottomColor

bottomColor: Uniform = new THREE.Uniform(new THREE.Color(0xffffff))

exponent

exponent: Uniform = new THREE.Uniform(0.6)

fogColor

fogColor: Uniform = new THREE.Uniform(new THREE.Color(0x0077ff))

fogFar

fogFar: Uniform = new THREE.Uniform(new THREE.Color(0xffffff))

fogNear

fogNear: Uniform = new THREE.Uniform(new THREE.Color(0x0077ff))

offset

offset: Uniform = new THREE.Uniform(33.0)

topColor

topColor: Uniform = new THREE.Uniform(new THREE.Color(0x0077ff))

u_atmosphereEnv

u_atmosphereEnv: Uniform = new THREE.Uniform(new THREE.Vector3(// Maximum inner radiusEQUATORIAL_RADIUS * 1.001,// Maximum outer radiusEQUATORIAL_RADIUS * 1.025,// Camera height0))

u_eyePositionWorld

u_eyePositionWorld: Uniform = new THREE.Uniform(new THREE.Vector3())

u_hsvCorrection

u_hsvCorrection: Uniform = new THREE.Uniform(new THREE.Vector3(0, 0, 0))

u_lightDirectionWorld

u_lightDirectionWorld: Uniform = new THREE.Uniform(new THREE.Vector3(0, 1, 0))

u_modelViewProjection

u_modelViewProjection: Uniform = new THREE.Uniform(new THREE.Matrix4())

Const LuminosityHighPassShader

LuminosityHighPassShader: object

The shader used in the [[UnrealBloomPass]] for the bloom/glow effect.

fragmentShader

fragmentShader: string = `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 );}`

vertexShader

vertexShader: string = `varying vec2 vUv;void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );}`

uniforms

uniforms: object

defaultColor

defaultColor: object

value

value: Color = new THREE.Color(0x000000)

defaultOpacity

defaultOpacity: object

value

value: number = 0

luminosityThreshold

luminosityThreshold: object

value

value: number = 1

smoothWidth

smoothWidth: object

value

value: number = 1

tDiffuse

tDiffuse: object

value

value: null = null

Const SepiaShader

SepiaShader: object

SepiaShader.

fragmentShader

fragmentShader: string = `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 );}`

vertexShader

vertexShader: string = `varying vec2 vUv;void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);}`

uniforms

uniforms: object

amount

amount: object

value

value: number = 1

tDiffuse

tDiffuse: object

value

value: null = null

Const SkyAtmosphereShader

SkyAtmosphereShader: object

SkyAtmosphereShader.

Describes shading of atmosphere as seen from outer space.

fragmentShader

fragmentShader: string = `// Because of harsh light distribution the exposure correction is always enabled for the sky.#define CORRECT_EXPOSURE 1precision highp float;precision highp int;#ifdef CORRECT_COLORuniform vec3 u_hsvCorrection; // Hue, saturation, brightness#endifuniform vec3 u_atmosphereEnv; // Atmosphere inner and outer radius, camera heightuniform vec3 u_eyePositionWorld;uniform vec3 u_lightDirectionWorld;const float g = -0.95;const float g2 = g * g;varying vec3 v_rayleighColor;varying vec3 v_mieColor;varying vec3 v_vertToCamera;${AtmosphereShaderChunks.atmosphere_fragment_utils}void main(void){float fInnerRadius = u_atmosphereEnv.x;float fOuterRadius = u_atmosphereEnv.y;float fCameraHeight = u_atmosphereEnv.z;#ifdef DYNAMIC_LIGHTvec3 vLightDir = u_lightDirectionWorld;// Alter alpha based on time of day (0.0 = night , 1.0 = day)float fNightAlpha = clamp(dot(normalize(u_eyePositionWorld), vLightDir), 0.0, 1.0);#elsevec3 vLightDir = u_eyePositionWorld;float fNightAlpha = 1.0;#endifvLightDir = normalize(vLightDir);// NOTE:// For better precision normalization may be added on fragment (for mobile devices)// while in vertex shader may be left un-normalized// dot(vLightDir, normalize(v_vertToCamera)) / length(v_vertToCamera);float fCosAngle = dot(vLightDir, v_vertToCamera) / length(v_vertToCamera);float fRayleighPhase = 0.75 * (1.0 + fCosAngle * fCosAngle);float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCosAngle * fCosAngle) / pow(1.0 + g2 - 2.0 * g * fCosAngle, 1.5);vec3 cRgb = fRayleighPhase * v_rayleighColor + fMiePhase * v_mieColor;// Sky produces very harsh lighting effect so exposure correction is always enabled.#if !defined(HDR_FRAME_BUFFER) && defined(CORRECT_EXPOSURE)// Exposure factor may be exposed to uniform variable.cRgb = correctExposure(cRgb, 2.0);#endif#ifdef CORRECT_COLORcRgb = correctColor(cRgb, u_hsvCorrection);#endif// Alter alpha based on how close the viewer is to the ground (1.0 = on ground, 0.0 = at edge of atmosphere)float fAtmosphereAlpha = clamp((fOuterRadius - fCameraHeight) /(fOuterRadius - fInnerRadius), 0.0, 1.0);fAtmosphereAlpha *= pow(fNightAlpha, 0.5);gl_FragColor = vec4(cRgb, mix(cRgb.b, 1.0, fAtmosphereAlpha));}`

vertexShader

vertexShader: string = `precision highp float;precision highp int;attribute vec4 position;uniform mat4 u_modelViewProjection;uniform vec3 u_eyePositionWorld;uniform vec3 u_lightDirectionWorld;uniform vec3 u_atmosphereEnv; // Atmosphere inner and outer radius, camera heightuniform vec3 u_hsvCorrection;const float Pi = 3.141592653589793;const float Kr = 0.0025;const float Kr4PI = Kr * 4.0 * Pi;const float Km = 0.0015;const float Km4PI = Km * 4.0 * Pi;const float ESun = 15.0; // should be 15.0const float KmESun = Km * ESun;const float KrESun = Kr * ESun;const vec3 InvWavelength = vec3(5.60204474633241, // Red = 1.0 / Math.pow(0.650, 4.0)9.473284437923038, // Green = 1.0 / Math.pow(0.570, 4.0)19.643802610477206); // Blue = 1.0 / Math.pow(0.475, 4.0)const int nSamples = 2;const float fSamples = 2.0;varying vec3 v_rayleighColor;varying vec3 v_mieColor;varying vec3 v_vertToCamera;${AtmosphereShaderChunks.atmosphere_vertex_utils}//// Computes rayleight and mia atmosphere factors for sky.//// Code based on GPU Gems article.//// Author: Sean O'Neil//// Copyright (c) 2004 Sean O'Neil//// https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering//// Further modifications by HERE//AtmosphereColor computeSkyAtmosphere(vec3 v3Pos, vec3 vLightDir){// Unpack attributesfloat fInnerRadius = u_atmosphereEnv.x;float fOuterRadius = u_atmosphereEnv.y;float fCameraHeight = u_atmosphereEnv.z;// All that may be const or define(s) at further optimization:float fScale = 1.0 / (fOuterRadius - fInnerRadius);float fScaleOverScaleDepth = (fScale / RayleighScaleDepth);float fCameraHeight2 = fCameraHeight * fCameraHeight;float fOuterRadius2 = fOuterRadius * fOuterRadius;// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)vec3 v3Ray = v3Pos - u_eyePositionWorld;float fFar = length(v3Ray);v3Ray /= fFar;#ifdef CAMERA_IN_SPACE// Calculate the closest intersection of the ray with the outer// atmosphere, this is the first point of the ray passing through the atmosphere dome.float fNear = getNearSphereIntersect(u_eyePositionWorld, v3Ray, fCameraHeight2, fOuterRadius2);// Make far relative to first atmosphere intersectionfFar -= fNear;// Compute the ray's starting position within the atmosphere, then// calculate its scattering offsetvec3 v3Start = u_eyePositionWorld + v3Ray * fNear;float fStartAngle = dot(v3Ray, v3Start) / fOuterRadius;float fStartDepth = exp(-1.0 / RayleighScaleDepth );float fStartOffset = fStartDepth * scale(fStartAngle);#else // CAMERA_IN_ATMOSPHERE// The ray starts already in atmospherevec3 v3Start = u_eyePositionWorld;float height = length(v3Start);float depth = exp(fScaleOverScaleDepth * (fInnerRadius - fCameraHeight));float fStartAngle = dot(v3Ray, v3Start) / height;float fStartOffset = depth * scale(fStartAngle);#endif// Initialize the scattering loop variablesfloat fSampleLength = fFar / fSamples;float fScaledLength = fSampleLength * fScale;vec3 v3SampleRay = v3Ray * fSampleLength;vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;// Now loop through the sample raysvec3 v3BaseColor = vec3(0.0);vec3 v3Attenuate = vec3(0.0);for(int i=0; i < nSamples; i++){float height = length(v3SamplePoint);float depth = exp(fScaleOverScaleDepth * (fInnerRadius - height));float fLightAngle = dot(vLightDir, v3SamplePoint) / height;float fCameraAngle = dot(v3Ray, v3SamplePoint) / height;float fScatter = (fStartOffset + depth * (scale(fLightAngle) - scale(fCameraAngle)));v3Attenuate = exp(-fScatter * (InvWavelength * Kr4PI + Km4PI));v3BaseColor += v3Attenuate * (depth * fScaledLength);v3SamplePoint += v3SampleRay;}// Scale the Mie and Rayleigh colors and set up output of the functionAtmosphereColor color;color.mie = v3BaseColor * KmESun;color.rayleigh = v3BaseColor * (InvWavelength * KrESun);return color;}void main(void){#ifdef DYNAMIC_LIGHTvec3 vLightDir = u_lightDirectionWorld;#elsevec3 vLightDir = u_eyePositionWorld;#endifvLightDir = normalize(vLightDir);AtmosphereColor atmColor = computeSkyAtmosphere(position.xyz, vLightDir);v_mieColor = atmColor.mie;v_rayleighColor = atmColor.rayleigh;v_vertToCamera = u_eyePositionWorld - position.xyz;gl_Position = u_modelViewProjection * position;}`

uniforms

uniforms: object

bottomColor

bottomColor: Uniform = new THREE.Uniform(new THREE.Color(0xffffff))

exponent

exponent: Uniform = new THREE.Uniform(0.6)

fogColor

fogColor: Uniform = new THREE.Uniform(new THREE.Color(0x0077ff))

fogFar

fogFar: Uniform = new THREE.Uniform(new THREE.Color(0xffffff))

fogNear

fogNear: Uniform = new THREE.Uniform(new THREE.Color(0x0077ff))

offset

offset: Uniform = new THREE.Uniform(33.0)

topColor

topColor: Uniform = new THREE.Uniform(new THREE.Color(0x0077ff))

u_atmosphereEnv

u_atmosphereEnv: Uniform = new THREE.Uniform(new THREE.Vector3(// Maximum inner radiusEQUATORIAL_RADIUS,// Maximum outer radiusEQUATORIAL_RADIUS * 1.025,// Camera height0.0))

u_eyePositionWorld

u_eyePositionWorld: Uniform = new THREE.Uniform(new THREE.Vector3())

u_hsvCorrection

u_hsvCorrection: Uniform = new THREE.Uniform(new THREE.Vector3(0, 0, 0))

u_lightDirectionWorld

u_lightDirectionWorld: Uniform = new THREE.Uniform(new THREE.Vector3(0, 1, 0))

u_modelViewProjection

u_modelViewProjection: Uniform = new THREE.Uniform(new THREE.Matrix4())

Const VignetteShader

VignetteShader: object

VignetteShader.

fragmentShader

fragmentShader: string = `uniform float offset;uniform float darkness;uniform sampler2D tDiffuse;varying vec2 vUv;void main() {vec4 texel = texture2D( tDiffuse, vUv );vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );}`

vertexShader

vertexShader: string = `varying vec2 vUv;void main() {vUv = uv;gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);}`

uniforms

uniforms: object

darkness

darkness: object

value

value: number = 1

offset

offset: object

value

value: number = 1

tDiffuse

tDiffuse: object

value

value: null = null

Generated using TypeDoc