ShaderMaterial class

A material rendered with custom shaders. A shader is a small program written in GLSL that runs on the GPU. You may want to use a custom shader if you need to:

  • implement an effect not included with any of the built-in [materials]
  • combine many objects into a single [BufferGeometry] in order to improve performance
There are the following notes to bear in mind when using a `ShaderMaterial`:
  • A `ShaderMaterial` will only be rendered properly by [WebGLRenderer], since the GLSL code in the [link:https://en.wikipedia.org/wiki/Shader#Vertex_shaders vertexShader] and [link:https://en.wikipedia.org/wiki/Shader#Pixel_shaders fragmentShader] properties must be compiled and run on the GPU using WebGL.
  • As of THREE r72, directly assigning attributes in a ShaderMaterial is no longer supported. A [BufferGeometry] instance must be used instead, using [BufferAttribute] instances to define custom attributes.
  • As of THREE r77, [WebGLRenderTarget] or [WebGLCubeRenderTarget] instances are no longer supposed to be used as uniforms. Their [Texture texture] property must be used instead.
  • Built in attributes and uniforms are passed to the shaders along with your code. If you don't want the [WebGLProgram] to add anything to your shader code, you can use [RawShaderMaterial] instead of this class.
  • You can use the directive #pragma unroll_loop_start and #pragma unroll_loop_end in order to unroll a `for` loop in GLSL by the shader preprocessor. The directive has to be placed right above the loop. The loop formatting has to correspond to a defined standard.
    • The loop has to be [link:https://en.wikipedia.org/wiki/Normalized_loop normalized].
    • The loop variable has to be *i*.
    • The value `UNROLLED_LOOP_INDEX` will be replaced with the explicitly value of *i* for the given iteration and can be used in preprocessor statements.
    #pragma unroll_loop_start for ( int i = 0; i < 10; i ++ ) { // ... } #pragma unroll_loop_end
Inheritance
Implementers

Constructors

ShaderMaterial([Map<MaterialProperty, dynamic>? parameters])
parameters - (optional) an object with one or more properties defining the material's appearance. Any property of the material (including any property inherited from Material and MeshStandardMaterial) can be passed in here.
ShaderMaterial.fromMap([Map<String, dynamic>? parameters])

Properties

alphaMap Texture?
getter/setter pairinherited
alphaTest double
getter/setter pairinherited
alphaToCoverage bool
getter/setter pairinherited
aoMap Texture?
getter/setter pairinherited
aoMapIntensity double?
getter/setter pairinherited
attenuationColor ↔ Color?
getter/setter pairinherited
attenuationDistance double?
getter/setter pairinherited
blendDst int
getter/setter pairinherited
blendDstAlpha int?
getter/setter pairinherited
blendEquation int
getter/setter pairinherited
blendEquationAlpha int?
getter/setter pairinherited
blending int
getter/setter pairinherited
blendSrc int
getter/setter pairinherited
blendSrcAlpha int?
getter/setter pairinherited
bumpMap Texture?
getter/setter pairinherited
bumpScale double?
getter/setter pairinherited
clearcoat double
getter/setter pairinherited
clearcoatMap Texture?
getter/setter pairinherited
clearcoatNormalMap Texture?
getter/setter pairinherited
clearcoatNormalScale ↔ Vector2?
getter/setter pairinherited
clearcoatRoughness double?
getter/setter pairinherited
clearcoatRoughnessMap Texture?
getter/setter pairinherited
clipIntersection bool
getter/setter pairinherited
clipping bool?
getter/setter pairinherited
clippingPlanes List<Plane>?
getter/setter pairinherited
clipShadows bool
getter/setter pairinherited
color ↔ Color
getter/setter pairinherited
colorWrite bool
getter/setter pairinherited
combine int?
getter/setter pairinherited
customProgramCacheKey Function
In case onBeforeCompile is used, this callback can be used to identify values of settings used in onBeforeCompile, so three.js can reuse a cached shader or recompile the shader for this material as needed.
getter/setter pairinherited
dashSize double?
getter/setter pairinherited
defaultAttributeValues Map<String, dynamic>?
getter/setter pairinherited
defines Map<String, dynamic>?
getter/setter pairinherited
depthFunc int
getter/setter pairinherited
depthPacking int?
getter/setter pairinherited
depthTest bool
getter/setter pairinherited
depthWrite bool
getter/setter pairinherited
displacementBias double?
getter/setter pairinherited
displacementMap Texture?
getter/setter pairinherited
displacementScale double?
getter/setter pairinherited
dithering bool
getter/setter pairinherited
emissive ↔ Color?
getter/setter pairinherited
emissiveIntensity double
getter/setter pairinherited
emissiveMap Texture?
getter/setter pairinherited
envMap Texture?
getter/setter pairinherited
envMapIntensity double?
getter/setter pairinherited
extensions Map<String, dynamic>?
getter/setter pairinherited
extra Map<String, dynamic>
getter/setter pairinherited
flatShading bool
getter/setter pairinherited
fog bool
getter/setter pairinherited
fragmentShader String?
getter/setter pairinherited
gapSize double?
getter/setter pairinherited
glslVersion String?
getter/setter pairinherited
gradientMap Texture?
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
id int
getter/setter pairinherited
index0AttributeName String?
getter/setter pairinherited
instanced bool
getter/setter pairinherited
ior double?
getter/setter pairinherited
isMaterial bool
getter/setter pairinherited
lightMap Texture?
getter/setter pairinherited
lightMapIntensity double?
getter/setter pairinherited
lights bool?
getter/setter pairinherited
linecap String?
getter/setter pairinherited
linejoin String?
getter/setter pairinherited
linewidth double?
getter/setter pairinherited
map Texture?
getter/setter pairinherited
matcap Texture?
getter/setter pairinherited
metalness double
getter/setter pairinherited
metalnessMap Texture?
getter/setter pairinherited
metalnessNode ↔ dynamic
getter/setter pairinherited
name String
getter/setter pairinherited
needsUpdate bool
no getterinherited
normalMap Texture?
getter/setter pairinherited
normalMapType int?
getter/setter pairinherited
normalNode ↔ dynamic
getter/setter pairinherited
normalScale ↔ Vector2?
getter/setter pairinherited
onBeforeCompile Function?
An optional callback that is executed immediately before the shader program is compiled. This function is called with the shader source code as a parameter. Useful for the modification of built-in materials.
getter/setter pairinherited
onBeforeRender Function?
getter/setter pairinherited
opacity double
getter/setter pairinherited
polygonOffset bool
getter/setter pairinherited
polygonOffsetFactor double
getter/setter pairinherited
polygonOffsetUnits double
getter/setter pairinherited
precision String?
getter/setter pairinherited
premultipliedAlpha bool
getter/setter pairinherited
reflectivity double?
getter/setter pairinherited
refractionRatio double?
getter/setter pairinherited
rotation double
getter/setter pairinherited
roughness double
getter/setter pairinherited
roughnessMap Texture?
getter/setter pairinherited
roughnessNode ↔ dynamic
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scale double?
getter/setter pairinherited
shaderID String
getter/setter pairinherited
shaderid String?
getter/setter pairinherited
shadowSide int?
getter/setter pairinherited
sheen double
getter/setter pairinherited
sheenColor ↔ Color?
getter/setter pairinherited
sheenColorMap Texture?
getter/setter pairinherited
sheenRoughness double
getter/setter pairinherited
sheenRoughnessMap Texture?
getter/setter pairinherited
sheenTintMap Texture?
getter/setter pairinherited
shininess double?
getter/setter pairinherited
side int
getter/setter pairinherited
size double?
getter/setter pairinherited
sizeAttenuation bool
getter/setter pairinherited
specular ↔ Color?
getter/setter pairinherited
specularColor ↔ Color?
getter/setter pairinherited
specularColorMap Texture?
getter/setter pairinherited
specularIntensity double?
getter/setter pairinherited
specularIntensityMap Texture?
getter/setter pairinherited
specularMap Texture?
getter/setter pairinherited
stencilFail int
getter/setter pairinherited
stencilFunc int
getter/setter pairinherited
stencilFuncMask int
getter/setter pairinherited
stencilRef int
getter/setter pairinherited
stencilWrite bool
getter/setter pairinherited
stencilWriteMask int
getter/setter pairinherited
stencilZFail int
getter/setter pairinherited
stencilZPass int
getter/setter pairinherited
thickness double?
getter/setter pairinherited
thicknessMap Texture?
getter/setter pairinherited
toneMapped bool
getter/setter pairinherited
transmission double
getter/setter pairinherited
transmissionMap Texture?
getter/setter pairinherited
transparent bool
getter/setter pairinherited
type String
getter/setter pairinherited
uniforms Map<String, dynamic>
getter/setter pairinherited
uniformsGroups List<UniformsGroup>
getter/setter pair
uniformsNeedUpdate bool?
getter/setter pairinherited
userData Map<String, dynamic>
getter/setter pairinherited
uuid String
getter/setter pairinherited
version int
getter/setter pairinherited
vertexColors bool
getter/setter pairinherited
vertexShader String?
getter/setter pairinherited
vertexTangents bool
getter/setter pairinherited
visible bool
getter/setter pairinherited
wireframe bool
getter/setter pairinherited
wireframeLinecap String?
getter/setter pairinherited
wireframeLinejoin String?
getter/setter pairinherited
wireframeLinewidth double?
getter/setter pairinherited

Methods

addEventListener(String type, Function listener) → void
type - The type of event to listen to.
inherited
clearListeners() → void
Remove all Listeners.
inherited
clone() ShaderMaterial
Return a new material with the same parameters as this material.
override
copy(Material source) ShaderMaterial
Copy the parameters from the passed material into this material.
override
dispatchEvent(Event event) → void
event - The event that gets fired.
inherited
dispose() → void
Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
inherited
getProperty(String propertyName) Object?
inherited
hasEventListener(String type, Function listener) bool
type - The type of event to listen to.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onBuild(dynamic shaderobject, dynamic renderer) → void
inherited
removeEventListener(String type, Function listener) → void
type - The type of the listener that gets removed.
inherited
setProperty(String propertyName, dynamic value) → void
inherited
setValue(MaterialProperty type, dynamic newValue) → void
type - the parameter to change.
inherited
setValueFromString(String key, dynamic newValue) → void
key - String values of the parameter to change.
inherited
setValues(Map<MaterialProperty, dynamic>? values) → void
values - a container with parameters.
inherited
setValuesFromString(Map<String, dynamic>? values) → void
inherited
toJson({Object3dMeta? meta}) Map<String, dynamic>
meta -- object containing metadata such as textures or images for the material.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator []=(String key, dynamic value) → void
inherited