Capítulo 66 de 859

Chapter 66: Material

Core Idea

Abstract base class for materials.

Materials define the appearance of renderable 3D objects.

Key Concepts

  • allowOverride : boolean: Whether it's possible to override the material with Scene#overrideMaterial or not.
  • alphaHash : boolean: Enables alpha hashed transparency, an alternative to Material#transparent or [Material#alphaTest](Material.htm…
  • alphaTest : number (readonly): Sets the alpha value to be used when running an alpha test. The material will not be rendered if the opacity is lower than this value.
  • alphaToCoverage : boolean: Whether alpha to coverage should be enabled or not. Can only be used with MSAA-enabled contexts (meaning when the renderer was created with…
  • blendAlpha : number: Represents the alpha value of the constant blend color.
  • blendColor : Color: Represents the RGB values of the constant blend color.
  • blendDst : ZeroFactor | OneFactor | SrcColorFactor | OneMinusSrcColorFactor | SrcAlphaFactor | OneMinusSrcAlphaFactor | DstAlphaFactor | OneMinusDstAlphaFactor | DstColorFactor | OneMinusDstColorFactor | SrcAlphaSaturateFactor | ConstantColorFactor | OneMinusConstantColorFactor | ConstantAlphaFactor | OneMinusConstantAlphaFactor: Defines the blending destination factor.
  • blendDstAlpha : ZeroFactor | OneFactor | SrcColorFactor | OneMinusSrcColorFactor | SrcAlphaFactor | OneMinusSrcAlphaFactor | DstAlphaFactor | OneMinusDstAlphaFactor | DstColorFactor | OneMinusDstColorFactor | SrcAlphaSaturateFactor | ConstantColorFactor | OneMinusConstantColorFactor | ConstantAlphaFactor | OneMinusConstantAlphaFactor: Defines the blending destination alpha factor.
  • blendEquation : AddEquation | SubtractEquation | ReverseSubtractEquation | MinEquation | MaxEquation: Defines the blending equation.
  • blendEquationAlpha : AddEquation | SubtractEquation | ReverseSubtractEquation | MinEquation | MaxEquation: Defines the blending equation of the alpha channel.

Reference Tables

Constructor

Signature
new Material() (abstract)

Properties

PropertyDescription
.allowOverride : booleanWhether it's possible to override the material with Scene#overrideMaterial or not.
.alphaHash : booleanEnables alpha hashed transparency, an alternative to Material#transparent or Material#alphaTest. The material will not be rendered if opacity i…
.alphaTest : number (readonly)Sets the alpha value to be used when running an alpha test. The material will not be rendered if the opacity is lower than this value.
.alphaToCoverage : booleanWhether alpha to coverage should be enabled or not. Can only be used with MSAA-enabled contexts (meaning when the renderer was created with antialias parameter set to true). Enabling this will sm…
.blendAlpha : numberRepresents the alpha value of the constant blend color.
.blendColor : ColorRepresents the RGB values of the constant blend color.
`.blendDst : ZeroFactorOneFactor
`.blendDstAlpha : ZeroFactorOneFactor
`.blendEquation : AddEquationSubtractEquation
`.blendEquationAlpha : AddEquationSubtractEquation
`.blendSrc : ZeroFactorOneFactor
`.blendSrcAlpha : ZeroFactorOneFactor
`.blending : NoBlendingNormalBlending
.clipIntersection : booleanChanges the behavior of clipping planes so that only their intersection is clipped, rather than their union.
.clipShadows : booleanDefines whether to clip shadows according to the clipping planes specified on this material.
.clippingPlanes : Array.<Plane>User-defined clipping planes specified as THREE.Plane objects in world space. These planes apply to the objects this material is attached to. Points in space whose signed distance to the plane is neg…
.colorWrite : booleanWhether to render the material's color.
`.depthFunc : NeverDepthAlwaysDepth
.depthTest : booleanWhether to have depth test enabled when rendering this material. When the depth test is disabled, the depth write will also be implicitly disabled.
.depthWrite : booleanWhether rendering this material has any effect on the depth buffer.
.dithering : booleanWhether to apply dithering to the color to remove the appearance of banding.
.forceSinglePass : booleanWhether double-sided, transparent objects should be rendered with a single pass or not.
.id : number (readonly)The ID of the material.
.isMaterial : boolean (readonly)This flag can be used for type testing.
.name : stringThe name of the material.
.needsUpdate : booleanSetting this property to true indicates the engine the material needs to be recompiled.
.opacity : numberDefines how transparent the material is. A value of 0.0 indicates fully transparent, 1.0 is fully opaque.
.polygonOffset : booleanWhether to use polygon offset or not. When enabled, each fragment's depth value will be offset after it is interpolated from the depth values of the appropriate vertices. The offset is added before t…
.polygonOffsetFactor : numberSpecifies a scale factor that is used to create a variable depth offset for each polygon.
.polygonOffsetUnits : numberIs multiplied by an implementation-specific value to create a constant depth offset.
`.precision : 'highp''mediump'
.premultipliedAlpha : booleanWhether to premultiply the alpha (transparency) value.
`.shadowSide : FrontSideBackSide
`.side : FrontSideBackSide
`.stencilFail : ZeroStencilOpKeepStencilOp
`.stencilFunc : NeverStencilFuncLessStencilFunc
.stencilFuncMask : numberThe bit mask to use when comparing against the stencil buffer.
.stencilRef : numberThe value to use when performing stencil comparisons or stencil operations.
.stencilWrite : booleanWhether stencil operations are performed against the stencil buffer. In order to perform writes or comparisons against the stencil buffer this value must be true.
.stencilWriteMask : numberThe bit mask to use when writing to the stencil buffer.
`.stencilZFail : ZeroStencilOpKeepStencilOp
`.stencilZPass : ZeroStencilOpKeepStencilOp
.toneMapped : booleanDefines whether this material is tone mapped according to the renderer's tone mapping setting.
.transparent : booleanDefines whether this material is transparent. This has an effect on rendering as transparent objects need special treatment and are rendered after non-transparent objects.
.type : string (readonly)The type property is used for detecting the object type in context of serialization/deserialization.
.userData : ObjectAn object that can be used to store custom data about the Material. It should not hold references to functions as these will not be cloned.
.uuid : string (readonly)The UUID of the material.
.version : number (readonly)This starts at 0 and counts how many times Material#needsUpdate is set to true.
.vertexColors : booleanIf set to true, vertex colors should be used.
.visible : booleanDefines whether 3D objects using this material are visible.

Methods

MethodDescription
.clone() : MaterialReturns a new material with copied values from this instance.
.copy( source : Material ) : MaterialCopies the values of the given material to this instance.
.customProgramCacheKey() : stringIn case Material#onBeforeCompile is used, this callback can be used to identify values of settings used in onBeforeCompile(), so three.js can reuse a cached shader …
.dispose()Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
.fromJSON( json : Object, textures : Object.<string, Texture> ) : MaterialDeserializes the material from the given JSON.
.onBeforeCompile( shaderobject : Object, renderer : WebGLRenderer )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 ma…
.onBeforeRender( renderer : WebGLRenderer, scene : Scene, camera : Camera, geometry : BufferGeometry, object : Object3D, group : Object )An optional callback that is executed immediately before the material is used to render a 3D object.
.setValues( values : Object )This method can be used to set default values from parameter objects. It is a generic implementation so it can be used with different types of materials.
`.toJSON( meta : Objectstring ) : Object`

Key Takeaways

  1. Material extends: EventDispatcher
  2. Most relevant properties: allowOverride, alphaHash, alphaTest, alphaToCoverage.
  3. Key methods: clone, copy, customProgramCacheKey, dispose.

Connects To