useMaterial
useMaterial フックは、PlayCanvas の StandardMaterial インスタンスを作成・管理できます。フックでマテリアルを作成し、<Render/> コンポーネントに適用します。
使い方
フックでマテリアルを作成し、<Render/> に適用し、マテリアルのプロパティを動的に更新できます。
- Demo
- Code
material-example.jsx
// ↑ imports hidden
export const MaterialExample = () => {
const materialProps = useControls(vars);
const material = useMaterial({
useMetalness: true,
glossInvert: true,
...materialProps
});
return (
<Entity>
<Render type="box" material={material} />
</Entity>
);
};
パラメータ
フックは、StandardMaterial クラスのプロパティに近い形のオブジェクトを受け取ります。
パラメータ
| Name | Type | Default |
|---|---|---|
userAttributes? | Map<any, any> | - |
onUpdateShader? | UpdateShaderCallback | undefinedA custom function that will be called after all shader generator properties are collected
and before shader code is generated. This function will receive an object with shader
generator settings (based on current material and scene properties), that you can change and
then return. Returned value will be used instead. This is mostly useful when rendering the
same set of objects, but with different shader variations based on the same material. For
example, you may wish to render a depth or normal pass using textures assigned to the
material, a reflection pass with simpler shaders and so on. These properties are split into
two sections, generic standard material options and lit options. Properties of the standard
material options are StandardMaterialOptions and the options for the lit options are
LitShaderOptions. | - |
shaderOptBuilder? | - | |
alphaFade? | boolean | - |
ambient? | stringThe ambient color of the material. This color value is 3-component (RGB), where each component is between 0 and 1. | - |
anisotropy? | numberIntensity Defines amount of anisotropy. Requires StandardMaterial#enableGGXSpecular is set to true. - When anisotropyIntensity == 0, specular is isotropic. - Specular anisotropy increases as anisotropyIntensity value increases to maximum of 1. | - |
anisotropyIntensity? | numberDefines amount of anisotropy. Requires StandardMaterial#enableGGXSpecular is set to true. - When anisotropyIntensity == 0, specular is isotropic. - Specular anisotropy increases as anisotropyIntensity value increases to maximum of 1. | - |
anisotropyRotation? | numberDefines the rotation (in degrees) of anisotropy. | - |
anisotropyMap? | Texture | nulle main (primary) diffuse map of the material (default is null). | - |
anisotropyMapOffset? | [number, number]Controls the 2D offset of the anisotropy map. Each component is between 0 and 1. | - |
anisotropyMapRotation? | numberControls the 2D rotation (in degrees) of the anisotropy map. | - |
anisotropyMapTiling? | [number, number]Controls the 2D tiling of the anisotropy map. | - |
anisotropyMapUv? | numberAnisotropy map UV channel. | - |
aoIntensity? | numberAmbient occlusion intensity. Defaults to 1. | - |
aoMap? | Texture | nullseMap The main (primary) diffuse map of the material (default is null). | - |
aoMapChannel? | stringColor channel of the main (primary) AO map to use. Can be "r", "g", "b" or "a". | - |
aoMapOffset? | [number, number]Controls the 2D offset of the main (primary) AO map. Each component is between 0 and 1. | - |
aoMapRotation? | numberControls the 2D rotation (in degrees) of the main (primary) AO map. | - |
aoMapTiling? | [number, number]Controls the 2D tiling of the main (primary) AO map. | - |
aoMapUv? | numberMain (primary) AO map UV channel | - |
aoDetailMap? | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
aoDetailMapChannel? | stringColor channels of the detail (secondary) AO map to use. Can be "r", "g", "b" or "a" (default is "g"). | - |
aoDetailMapOffset? | [number, number]Controls the 2D offset of the detail (secondary) AO map. Each component is between 0 and 1. | - |
aoDetailMapRotation? | numberControls the 2D rotation (in degrees) of the detail (secondary) AO map. | - |
aoDetailMapTiling? | [number, number]Controls the 2D tiling of the detail (secondary) AO map. | - |
aoDetailMapUv? | numberDetail (secondary) AO map UV channel. | - |
aoDetailMode? | stringDetermines how the main (primary) and detail (secondary) AO maps are blended together. Can be: - DETAILMODE_MUL: Multiply together the primary and secondary colors. - DETAILMODE_ADD: Add together the primary and secondary colors. - DETAILMODE_SCREEN: Softer version of DETAILMODE_ADD. - DETAILMODE_OVERLAY: Multiplies or screens the colors, depending on the primary color. - DETAILMODE_MIN: Select whichever of the primary and secondary colors is darker, component-wise. - DETAILMODE_MAX: Select whichever of the primary and secondary colors is lighter, component-wise. Defaults to DETAILMODE_MUL. | - |
aoVertexColor? | booleanUse mesh vertex colors for AO. If aoMap is set, it'll be multiplied by vertex colors. | - |
aoVertexColorChannel? | stringVertex color channels to use for AO. Can be "r", "g", "b" or "a". | - |
bumpiness? | numberThe bumpiness of the material. This value scales the assigned main (primary) normal map. It should be normally between 0 (no bump mapping) and 1 (full bump mapping), but can be set to e.g. 2 to give even more pronounced bump effect. | - |
clearCoat? | numberDefines intensity of clearcoat layer from 0 to 1. Clearcoat layer is disabled when clearCoat == 0. Default value is 0 (disabled). | - |
clearCoatBumpiness? | numberThe bumpiness of the clearcoat layer. This value scales the assigned main clearcoat normal map. It should be normally between 0 (no bump mapping) and 1 (full bump mapping), but can be set to e.g. 2 to give even more pronounced bump effect. | - |
clearCoatGlossInvert? | booleanInvert the clearcoat gloss component (default is false). Enabling this flag results in material treating the clear coat gloss members as roughness. | - |
clearCoatGlossMap? | Texture | nullin (primary) diffuse map of the material (default is null). | - |
clearCoatGlossMapChannel? | stringColor channel of the clearcoat gloss map to use. Can be "r", "g", "b" or "a". | - |
clearCoatGlossMapOffset? | [number, number]Controls the 2D offset of the clearcoat gloss map. Each component is between 0 and 1. | - |
clearCoatGlossMapRotation? | numberControls the 2D rotation (in degrees) of the clear coat gloss map. | - |
clearCoatGlossMapTiling? | [number, number]Controls the 2D tiling of the clearcoat gloss map. | - |
clearCoatGlossMapUv? | numberClearcoat gloss map UV channel. | - |
clearCoatGlossVertexColor? | booleanUse mesh vertex colors for clearcoat glossiness. If clearCoatGlossMap is set, it'll be multiplied by vertex colors. | - |
clearCoatGlossVertexColorChannel? | stringVertex color channel to use for clearcoat glossiness. Can be "r", "g", "b" or "a". | - |
clearCoatGloss? | numberDefines the clearcoat glossiness of the clearcoat layer from 0 (rough) to 1 (mirror). | - |
clearCoatMap? | Texture | nullhe main (primary) diffuse map of the material (default is null). | - |
clearCoatMapChannel? | stringColor channel of the clearcoat intensity map to use. Can be "r", "g", "b" or "a". | - |
clearCoatMapOffset? | [number, number]Controls the 2D offset of the clearcoat intensity map. Each component is between 0 and 1. | - |
clearCoatMapRotation? | numberControls the 2D rotation (in degrees) of the clearcoat intensity map. | - |
clearCoatMapTiling? | [number, number]Controls the 2D tiling of the clearcoat intensity map. | - |
clearCoatMapUv? | numberClearcoat intensity map UV channel. | - |
clearCoatNormalMap? | Texture | nulln (primary) diffuse map of the material (default is null). | - |
clearCoatNormalMapOffset? | [number, number]Controls the 2D offset of the main clearcoat normal map. Each component is between 0 and 1. | - |
clearCoatNormalMapRotation? | numberControls the 2D rotation (in degrees) of the main clearcoat map. | - |
clearCoatNormalMapTiling? | [number, number]Controls the 2D tiling of the main clearcoat normal map. | - |
clearCoatNormalMapUv? | numberClearcoat normal map UV channel. | - |
clearCoatVertexColor? | booleanUse mesh vertex colors for clearcoat intensity. If clearCoatMap is set, it'll be multiplied by vertex colors. | - |
clearCoatVertexColorChannel? | stringVertex color channel to use for clearcoat intensity. Can be "r", "g", "b" or "a". | - |
cubeMap? | Texture | nullMap The main (primary) diffuse map of the material (default is null). | - |
cubeMapProjection? | numberThe type of projection applied to the cubeMap property: - CUBEPROJ_NONE: The cube map is treated as if it is infinitely far away. - CUBEPROJ_BOX: Box-projection based on a world space axis-aligned bounding box. Defaults to CUBEPROJ_NONE. | - |
cubeMapProjectionBox? | BoundingBoxThe world space axis-aligned bounding box defining the box-projection used for the cubeMap property. Only used when cubeMapProjection is set to CUBEPROJ_BOX. | - |
diffuse? | stringThe diffuse color of the material. This color value is 3-component (RGB), where each component is between 0 and 1. Defines basic surface color (aka albedo). | - |
diffuseDetailMap? | Texture | nullain (primary) diffuse map of the material (default is null). | - |
diffuseDetailMapChannel? | stringColor channels of the detail (secondary) diffuse map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
diffuseDetailMapOffset? | [number, number]Controls the 2D offset of the detail (secondary) diffuse map. Each component is between 0 and 1. | - |
diffuseDetailMapRotation? | numberControls the 2D rotation (in degrees) of the main (secondary) diffuse map. | - |
diffuseDetailMapTiling? | [number, number]Controls the 2D tiling of the detail (secondary) diffuse map. | - |
diffuseDetailMapUv? | numberDetail (secondary) diffuse map UV channel. | - |
diffuseDetailMode? | stringDetermines how the main (primary) and detail (secondary) diffuse maps are blended together. Can be: - DETAILMODE_MUL: Multiply together the primary and secondary colors. - DETAILMODE_ADD: Add together the primary and secondary colors. - DETAILMODE_SCREEN: Softer version of DETAILMODE_ADD. - DETAILMODE_OVERLAY: Multiplies or screens the colors, depending on the primary color. - DETAILMODE_MIN: Select whichever of the primary and secondary colors is darker, component-wise. - DETAILMODE_MAX: Select whichever of the primary and secondary colors is lighter, component-wise. Defaults to DETAILMODE_MUL. | - |
diffuseMap? | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
diffuseMapChannel? | stringColor channels of the main (primary) diffuse map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
diffuseMapOffset? | [number, number]Controls the 2D offset of the main (primary) diffuse map. Each component is between 0 and 1. | - |
diffuseMapRotation? | numberControls the 2D rotation (in degrees) of the main (primary) diffuse map. | - |
diffuseMapTiling? | [number, number]Controls the 2D tiling of the main (primary) diffuse map. | - |
diffuseMapUv? | numberMain (primary) diffuse map UV channel. | - |
diffuseVertexColor? | booleanMultiply diffuse by the mesh vertex colors. | - |
diffuseVertexColorChannel? | stringVertex color channels to use for diffuse. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
emissive? | stringThe emissive color of the material. This color value is 3-component (RGB), where each component is between 0 and 1. | - |
emissiveIntensity? | numberEmissive color multiplier. | - |
emissiveMap? | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
emissiveMapChannel? | stringColor channels of the emissive map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
emissiveMapOffset? | [number, number]Controls the 2D offset of the emissive map. Each component is between 0 and 1. | - |
emissiveMapRotation? | numberControls the 2D rotation (in degrees) of the emissive map. | - |
emissiveMapTiling? | [number, number]Controls the 2D tiling of the emissive map. | - |
emissiveMapUv? | numberEmissive map UV channel. | - |
emissiveVertexColor? | booleanUse mesh vertex colors for emission. If emissiveMap or emissive are set, they'll be multiplied by vertex colors. | - |
emissiveVertexColorChannel? | stringVertex color channels to use for emission. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
enableGGXSpecular? | booleanEnables GGX specular. Also enables StandardMaterial#anisotropyIntensity parameter to set material anisotropy. | - |
envAtlas? | Texture | nullap The main (primary) diffuse map of the material (default is null). | - |
fresnelModel? | numberDefines the formula used for Fresnel effect. As a side-effect, enabling any Fresnel model changes the way diffuse and reflection components are combined. When Fresnel is off, legacy non energy-conserving combining is used. When it is on, combining behavior is energy-conserving. - FRESNEL_NONE: No Fresnel. - FRESNEL_SCHLICK: Schlick's approximation of Fresnel (recommended). Parameterized by specular color. | - |
gloss? | numberDefines the glossiness of the material from 0 (rough) to 1 (shiny). | - |
glossInvert? | booleanInvert the gloss component (default is false). Enabling this flag results in material treating the gloss members as roughness. | - |
glossMap? | Texture | nullap The main (primary) diffuse map of the material (default is null). | - |
glossMapChannel? | stringColor channel of the gloss map to use. Can be "r", "g", "b" or "a". | - |
glossMapOffset? | [number, number]Controls the 2D offset of the gloss map. Each component is between 0 and 1. | - |
glossMapRotation? | numberControls the 2D rotation (in degrees) of the gloss map. | - |
glossMapTiling? | [number, number]Controls the 2D tiling of the gloss map. | - |
glossMapUv? | numberGloss map UV channel. | - |
glossVertexColor? | booleanUse mesh vertex colors for glossiness. If glossMap is set, it'll be multiplied by vertex colors. | - |
glossVertexColorChannel? | stringVertex color channel to use for glossiness. Can be "r", "g", "b" or "a". | - |
heightMap? | Texture | nullp The main (primary) diffuse map of the material (default is null). | - |
heightMapChannel? | stringColor channel of the height map to use. Can be "r", "g", "b" or "a". | - |
heightMapFactor? | numberHeight map multiplier. Affects the strength of the parallax effect. | - |
heightMapOffset? | [number, number]Controls the 2D offset of the height map. Each component is between 0 and 1. | - |
heightMapRotation? | numberControls the 2D rotation (in degrees) of the height map. | - |
heightMapTiling? | [number, number]Controls the 2D tiling of the height map. | - |
heightMapUv? | numberHeight map UV channel. | - |
lightMap? | Texture | nullap The main (primary) diffuse map of the material (default is null). | - |
lightMapChannel? | stringColor channels of the lightmap to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
lightMapOffset? | [number, number]Controls the 2D offset of the lightmap. Each component is between 0 and 1. | - |
lightMapRotation? | numberControls the 2D rotation (in degrees) of the lightmap. | - |
lightMapTiling? | [number, number]Controls the 2D tiling of the lightmap. | - |
lightMapUv? | numberLightmap UV channel | - |
lightVertexColor? | booleanUse baked vertex lighting. If lightMap is set, it'll be multiplied by vertex colors. | - |
lightVertexColorChannel? | stringVertex color channels to use for baked lighting. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
metalness? | numberDefines how much the surface is metallic. From 0 (dielectric) to 1 (metal). | - |
metalnessMap? | Texture | nullhe main (primary) diffuse map of the material (default is null). | - |
metalnessMapChannel? | stringColor channel of the metalness map to use. Can be "r", "g", "b" or "a". | - |
metalnessMapOffset? | [number, number]Controls the 2D offset of the metalness map. Each component is between 0 and 1. | - |
metalnessMapRotation? | numberControls the 2D rotation (in degrees) of the metalness map. | - |
metalnessMapTiling? | [number, number]Controls the 2D tiling of the metalness map. | - |
metalnessMapUv? | numberMetalness map UV channel. | - |
metalnessVertexColor? | booleanUse mesh vertex colors for metalness. If metalnessMap is set, it'll be multiplied by vertex colors. | - |
metalnessVertexColorChannel? | stringVertex color channel to use for metalness. Can be "r", "g", "b" or "a". | - |
normalDetailMap? | Texture | nullmain (primary) diffuse map of the material (default is null). | - |
normalDetailMapBumpiness? | numberThe bumpiness of the material. This value scales the assigned detail (secondary) normal map. It should be normally between 0 (no bump mapping) and 1 (full bump mapping), but can be set to e.g. 2 to give even more pronounced bump effect. | - |
normalDetailMapOffset? | [number, number]Controls the 2D offset of the detail (secondary) normal map. Each component is between 0 and 1. | - |
normalDetailMapRotation? | numberControls the 2D rotation (in degrees) of the detail (secondary) normal map. | - |
normalDetailMapTiling? | [number, number]Controls the 2D tiling of the detail (secondary) normal map. | - |
normalDetailMapUv? | numberDetail (secondary) normal map UV channel. | - |
normalMap? | Texture | nullp The main (primary) diffuse map of the material (default is null). | - |
normalMapOffset? | [number, number]Controls the 2D offset of the main (primary) normal map. Each component is between 0 and 1. | - |
normalMapRotation? | numberControls the 2D rotation (in degrees) of the main (primary) normal map. | - |
normalMapTiling? | [number, number]Controls the 2D tiling of the main (primary) normal map. | - |
normalMapUv? | numberMain (primary) normal map UV channel. | - |
occludeDirect? | number | - |
occludeSpecular? | numberUses ambient occlusion to darken specular/reflection. It's a hack, because real specular occlusion is view-dependent. However, it can be better than nothing. - SPECOCC_NONE: No specular occlusion - SPECOCC_AO: Use AO directly to occlude specular. - SPECOCC_GLOSSDEPENDENT: Modify AO based on material glossiness/view angle to occlude specular. | - |
occludeSpecularIntensity? | numberControls visibility of specular occlusion. | - |
opacity? | numberThe opacity of the material. This value can be between 0 and 1, where 0 is fully transparent and 1 is fully opaque. If you want the material to be semi-transparent you also need to set the Material#blendType to BLEND_NORMAL, BLEND_ADDITIVE or any other mode. Also note that for most semi-transparent objects you want Material#depthWrite to be false, otherwise they can fully occlude objects behind them. | - |
opacityDither? | stringUsed to specify whether opacity is dithered, which allows transparency without alpha blending. Can be: - DITHER_NONE: Opacity dithering is disabled. - DITHER_BAYER8: Opacity is dithered using a Bayer 8 matrix. - DITHER_BLUENOISE: Opacity is dithered using a blue noise. - DITHER_IGNNOISE: Opacity is dithered using an interleaved gradient noise. Defaults to DITHER_NONE. | - |
opacityShadowDither? | string | - |
opacityFadesSpecular? | booleanUsed to specify whether specular and reflections are faded out using StandardMaterial#opacity . Default is true. When set to false use Material#alphaFade to fade out materials. | - |
opacityMap? | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
opacityMapChannel? | stringColor channel of the opacity map to use. Can be "r", "g", "b" or "a". | - |
opacityMapOffset? | [number, number]Controls the 2D offset of the opacity map. Each component is between 0 and 1. | - |
opacityMapRotation? | numberControls the 2D rotation (in degrees) of the opacity map. | - |
opacityMapTiling? | [number, number]Controls the 2D tiling of the opacity map. | - |
opacityMapUv? | numberOpacity map UV channel. | - |
opacityVertexColor? | booleanUse mesh vertex colors for opacity. If opacityMap is set, it'll be multiplied by vertex colors. | - |
opacityVertexColorChannel? | stringVertex color channels to use for opacity. Can be "r", "g", "b" or "a". | - |
pixelSnap? | booleanAlign vertices to pixel coordinates when rendering. Useful for pixel perfect 2D graphics. | - |
reflectivity? | numberEnvironment map intensity. | - |
refraction? | numberDefines the visibility of refraction. Material can refract the same cube map as used for reflections. | - |
refractionIndex? | numberDefines the index of refraction, i.e. The amount of distortion. The value is calculated as (outerIor / surfaceIor), where inputs are measured indices of refraction, the one around the object and the one of its own surface. In most situations outer medium is air, so outerIor will be approximately 1. Then you only need to do (1.0 / surfaceIor). | - |
dispersion? | numberThe strength of the angular separation of colors (chromatic aberration) transmitting through a volume. Defaults to 0, which is equivalent to no dispersion. | - |
shadowCatcher? | booleanWhen enabled, the material will output accumulated directional shadow value in linear space as the color. | - |
specular? | stringThe specular color of the material. This color value is 3-component (RGB), where each component is between 0 and 1. Defines surface reflection/specular color. Affects specular intensity and tint. | - |
specularMap? | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
specularMapChannel? | stringColor channels of the specular map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
specularMapOffset? | [number, number]Controls the 2D offset of the specular map. Each component is between 0 and 1. | - |
specularMapRotation? | numberControls the 2D rotation (in degrees) of the specular map. | - |
specularMapTiling? | [number, number]Controls the 2D tiling of the specular map. | - |
specularMapUv? | numberSpecular map UV channel. | - |
specularTint? | booleanMultiply specular map and/or specular vertex color by the constant specular value. | - |
specularVertexColor? | booleanUse mesh vertex colors for specular. If specularMap or are specularTint are set, they'll be multiplied by vertex colors. | - |
specularVertexColorChannel? | stringVertex color channels to use for specular. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
specularityFactor? | numberThe factor of specular intensity, used to weight the fresnel and specularity. Default is 1.0. | - |
specularityFactorMap? | Texture | null(primary) diffuse map of the material (default is null). | - |
specularityFactorMapChannel? | stringThe channel used by the specularity factor texture to sample from (default is 'a'). | - |
specularityFactorMapOffset? | [number, number]Controls the 2D offset of the specularity factor map. Each component is between 0 and 1. | - |
specularityFactorMapRotation? | numberControls the 2D rotation (in degrees) of the specularity factor map. | - |
specularityFactorMapTiling? | [number, number]Controls the 2D tiling of the specularity factor map. | - |
specularityFactorMapUv? | numberSpecularity factor map UV channel. | - |
useSheen? | booleanToggle sheen specular effect on/off. | - |
sheen? | stringThe specular color of the sheen (fabric) microfiber structure. This color value is 3-component (RGB), where each component is between 0 and 1. | - |
sheenMap? | Texture | nullap The main (primary) diffuse map of the material (default is null). | - |
sheenMapChannel? | stringColor channels of the sheen map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
sheenMapOffset? | [number, number]Controls the 2D offset of the sheen map. Each component is between 0 and 1. | - |
sheenMapRotation? | numberControls the 2D rotation (in degrees) of the sheen map. | - |
sheenMapTiling? | [number, number]Controls the 2D tiling of the sheen map. | - |
sheenMapUv? | numberSheen map UV channel. | - |
sheenVertexColor? | booleanUse mesh vertex colors for sheen. If sheen map or sheen tint are set, they'll be multiplied by vertex colors. | - |
sheenVertexColorChannel? | string | - |
sphereMap? | Texture | nullp The main (primary) diffuse map of the material (default is null). | - |
twoSidedLighting? | booleanCalculate proper normals (and therefore lighting) on backfaces. | - |
useFog? | booleanApply fogging (as configured in scene settings) | - |
useTonemap? | booleanApply tonemapping (as configured in Scene#rendering or CameraComponent.rendering ). Defaults to true. | - |
useLighting? | booleanApply lighting | - |
useMetalness? | booleanUse metalness properties instead of specular. When enabled, diffuse colors also affect specular instead of the dedicated specular map. This can be used as alternative to specular color to save space. With metalness == 0, the pixel is assumed to be dielectric, and diffuse color is used as normal. With metalness == 1, the pixel is fully metallic, and diffuse color is used as specular color instead. | - |
useMetalnessSpecularColor? | booleanWhen metalness is enabled, use the specular map to apply color tint to specular reflections. at direct angles. | - |
useSkybox? | booleanApply scene skybox as prefiltered environment map | - |
userId? | stringA unique id the user can assign to the material. The engine internally does not use this for
anything, and the user can assign a value to this id for any purpose they like. Defaults to
an empty string. | - |
id? | number | - |
parameters? | {} | - |
alphaTest? | numberThe alpha test reference value to control which fragments are written to the currently
active render target based on alpha value. All fragments with an alpha value of less than
the alphaTest reference value will be discarded. alphaTest defaults to 0 (all fragments
pass). | - |
alphaToCoverage? | booleanEnables or disables alpha to coverage (WebGL2 only). When enabled, and if hardware
anti-aliasing is on, limited order-independent transparency can be achieved. Quality depends
on the number of MSAA samples of the current render target. It can nicely soften edges of
otherwise sharp alpha cutouts, but isn't recommended for large area semi-transparent
surfaces. Note, that you don't need to enable blending to make alpha to coverage work. It
will work without it, just like alphaTest. | - |
cull? | numberControls how triangles are culled based on their face direction with respect to the
viewpoint. Can be:
- CULLFACE_NONE: Do not cull triangles based on face direction.
- CULLFACE_BACK: Cull the back faces of triangles (do not render triangles facing
away from the view point).
- CULLFACE_FRONT: Cull the front faces of triangles (do not render triangles facing
towards the view point).
Defaults to CULLFACE_BACK. | - |
frontFace? | numberControls whether polygons are front- or back-facing by setting a winding
orientation. Can be:
- FRONTFACE_CW: The clock-wise winding.
- FRONTFACE_CCW: The counterclockwise winding.
Defaults to FRONTFACE_CCW. | - |
stencilFront? | StencilParameters | nullStencil parameters for front faces (default is null). | - |
stencilBack? | StencilParameters | nullStencil parameters for back faces (default is null). | - |
shaderChunksVersion? | stringSets the version of the shader chunks.
This should be a string containing the current engine major and minor version (e.g., '2.8'
for engine v2.8.1) and ensures compatibility with the current engine version. When providing
custom shader chunks, set this to the latest supported version. If a future engine release no
longer supports the specified version, a warning will be issued. In that case, update your
shader chunks to match the new format and set this to the latest version accordingly.
Returns the version of the shader chunks. | - |
chunks? | {} | - |
depthBias? | numberSets the offset for the output depth buffer value. Useful for decals to prevent z-fighting.
Typically a small negative value (-0.1) is used to render the mesh slightly closer to the
camera.
Gets the offset for the output depth buffer value. | - |
slopeDepthBias? | numberSets the offset for the output depth buffer value based on the slope of the triangle
relative to the camera.
Gets the offset for the output depth buffer value based on the slope of the triangle
relative to the camera. | - |
dirty? | boolean | - |
redWrite? | booleanSets whether the red channel is written to the color buffer. If true, the red component of
fragments generated by the shader of this material is written to the color buffer of the
currently active render target. If false, the red component will not be written. Defaults to
true.
Gets whether the red channel is written to the color buffer. | - |
greenWrite? | booleanSets whether the green channel is written to the color buffer. If true, the red component of
fragments generated by the shader of this material is written to the color buffer of the
currently active render target. If false, the green component will not be written. Defaults
to true.
Gets whether the green channel is written to the color buffer. | - |
blueWrite? | booleanSets whether the blue channel is written to the color buffer. If true, the red component of
fragments generated by the shader of this material is written to the color buffer of the
currently active render target. If false, the blue component will not be written. Defaults
to true.
Gets whether the blue channel is written to the color buffer. | - |
alphaWrite? | booleanSets whether the alpha channel is written to the color buffer. If true, the red component of
fragments generated by the shader of this material is written to the color buffer of the
currently active render target. If false, the alpha component will not be written. Defaults
to true.
Gets whether the alpha channel is written to the color buffer. | - |
blendState? | BlendStateSets the blend state for this material. Controls how fragment shader outputs are blended
when being written to the currently active render target. This overwrites blending type set
using Material#blendType , and offers more control over blending.
Gets the blend state for this material. | - |
blendType? | numberSets the blend mode for this material. Controls how fragment shader outputs are blended when
being written to the currently active render target. Can be:
- BLEND_SUBTRACTIVE: Subtract the color of the source fragment from the destination
fragment and write the result to the frame buffer.
- BLEND_ADDITIVE: Add the color of the source fragment to the destination fragment
and write the result to the frame buffer.
- BLEND_NORMAL: Enable simple translucency for materials such as glass. This is
equivalent to enabling a source blend mode of BLENDMODE_SRC_ALPHA and a destination
blend mode of BLENDMODE_ONE_MINUS_SRC_ALPHA.
- BLEND_NONE: Disable blending.
- BLEND_PREMULTIPLIED: Similar to BLEND_NORMAL expect the source fragment is
assumed to have already been multiplied by the source alpha value.
- BLEND_MULTIPLICATIVE: Multiply the color of the source fragment by the color of the
destination fragment and write the result to the frame buffer.
- BLEND_ADDITIVEALPHA: Same as BLEND_ADDITIVE except the source RGB is
multiplied by the source alpha.
- BLEND_MULTIPLICATIVE2X: Multiplies colors and doubles the result.
- BLEND_SCREEN: Softer version of additive.
- BLEND_MIN: Minimum color.
- BLEND_MAX: Maximum color.
Defaults to BLEND_NONE.
Gets the blend mode for this material. | - |
depthState? | DepthStateSets the depth state. Note that this can also be done by using Material#depthTest ,
Material#depthFunc and Material#depthWrite .
Gets the depth state. | - |
depthTest? | booleanSets whether depth testing is enabled. If true, fragments generated by the shader of this
material are only written to the current render target if they pass the depth test. If
false, fragments generated by the shader of this material are written to the current render
target regardless of what is in the depth buffer. Defaults to true.
Gets whether depth testing is enabled. | - |
depthFunc? | numberSets the depth test function. Controls how the depth of new fragments is compared against
the current depth contained in the depth buffer. Can be:
- FUNC_NEVER: don't draw
- FUNC_LESS: draw if new depth < depth buffer
- FUNC_EQUAL: draw if new depth == depth buffer
- FUNC_LESSEQUAL: draw if new depth <= depth buffer
- FUNC_GREATER: draw if new depth > depth buffer
- FUNC_NOTEQUAL: draw if new depth != depth buffer
- FUNC_GREATEREQUAL: draw if new depth >= depth buffer
- FUNC_ALWAYS: always draw
Defaults to FUNC_LESSEQUAL.
Gets the depth test function. | - |
depthWrite? | booleanSets whether depth writing is enabled. If true, fragments generated by the shader of this
material write a depth value to the depth buffer of the currently active render target. If
false, no depth value is written. Defaults to true.
Gets whether depth writing is enabled. | - |
戻り値
フックは StandardMaterial インスタンスを返します。Render コンポーネントに適用できます。
| Name | Type | Default |
|---|---|---|
userAttributes | Map<any, any> | - |
onUpdateShader | UpdateShaderCallback | undefinedA custom function that will be called after all shader generator properties are collected
and before shader code is generated. This function will receive an object with shader
generator settings (based on current material and scene properties), that you can change and
then return. Returned value will be used instead. This is mostly useful when rendering the
same set of objects, but with different shader variations based on the same material. For
example, you may wish to render a depth or normal pass using textures assigned to the
material, a reflection pass with simpler shaders and so on. These properties are split into
two sections, generic standard material options and lit options. Properties of the standard
material options are StandardMaterialOptions and the options for the lit options are
LitShaderOptions. | - |
_assetReferences | {} | - |
_activeParams | Set<any> | - |
_activeLightingParams | Set<any> | - |
shaderOptBuilder | - | |
reset | () => void | - |
alphaFade | boolean | - |
ambient | ColorThe ambient color of the material. This color value is 3-component (RGB), where each component is between 0 and 1. | - |
anisotropy | numberIntensity Defines amount of anisotropy. Requires StandardMaterial#enableGGXSpecular is set to true. - When anisotropyIntensity == 0, specular is isotropic. - Specular anisotropy increases as anisotropyIntensity value increases to maximum of 1. | - |
anisotropyIntensity | numberDefines amount of anisotropy. Requires StandardMaterial#enableGGXSpecular is set to true. - When anisotropyIntensity == 0, specular is isotropic. - Specular anisotropy increases as anisotropyIntensity value increases to maximum of 1. | - |
anisotropyRotation | numberDefines the rotation (in degrees) of anisotropy. | - |
anisotropyMap | Texture | nulle main (primary) diffuse map of the material (default is null). | - |
anisotropyMapOffset | Vec2Controls the 2D offset of the anisotropy map. Each component is between 0 and 1. | - |
anisotropyMapRotation | numberControls the 2D rotation (in degrees) of the anisotropy map. | - |
anisotropyMapTiling | Vec2Controls the 2D tiling of the anisotropy map. | - |
anisotropyMapUv | numberAnisotropy map UV channel. | - |
aoIntensity | numberAmbient occlusion intensity. Defaults to 1. | - |
aoMap | Texture | nullseMap The main (primary) diffuse map of the material (default is null). | - |
aoMapChannel | stringColor channel of the main (primary) AO map to use. Can be "r", "g", "b" or "a". | - |
aoMapOffset | Vec2Controls the 2D offset of the main (primary) AO map. Each component is between 0 and 1. | - |
aoMapRotation | numberControls the 2D rotation (in degrees) of the main (primary) AO map. | - |
aoMapTiling | Vec2Controls the 2D tiling of the main (primary) AO map. | - |
aoMapUv | numberMain (primary) AO map UV channel | - |
aoDetailMap | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
aoDetailMapChannel | stringColor channels of the detail (secondary) AO map to use. Can be "r", "g", "b" or "a" (default is "g"). | - |
aoDetailMapOffset | Vec2Controls the 2D offset of the detail (secondary) AO map. Each component is between 0 and 1. | - |
aoDetailMapRotation | numberControls the 2D rotation (in degrees) of the detail (secondary) AO map. | - |
aoDetailMapTiling | Vec2Controls the 2D tiling of the detail (secondary) AO map. | - |
aoDetailMapUv | numberDetail (secondary) AO map UV channel. | - |
aoDetailMode | stringDetermines how the main (primary) and detail (secondary) AO maps are blended together. Can be: - DETAILMODE_MUL: Multiply together the primary and secondary colors. - DETAILMODE_ADD: Add together the primary and secondary colors. - DETAILMODE_SCREEN: Softer version of DETAILMODE_ADD. - DETAILMODE_OVERLAY: Multiplies or screens the colors, depending on the primary color. - DETAILMODE_MIN: Select whichever of the primary and secondary colors is darker, component-wise. - DETAILMODE_MAX: Select whichever of the primary and secondary colors is lighter, component-wise. Defaults to DETAILMODE_MUL. | - |
aoVertexColor | booleanUse mesh vertex colors for AO. If aoMap is set, it'll be multiplied by vertex colors. | - |
aoVertexColorChannel | stringVertex color channels to use for AO. Can be "r", "g", "b" or "a". | - |
bumpiness | numberThe bumpiness of the material. This value scales the assigned main (primary) normal map. It should be normally between 0 (no bump mapping) and 1 (full bump mapping), but can be set to e.g. 2 to give even more pronounced bump effect. | - |
clearCoat | numberDefines intensity of clearcoat layer from 0 to 1. Clearcoat layer is disabled when clearCoat == 0. Default value is 0 (disabled). | - |
clearCoatBumpiness | numberThe bumpiness of the clearcoat layer. This value scales the assigned main clearcoat normal map. It should be normally between 0 (no bump mapping) and 1 (full bump mapping), but can be set to e.g. 2 to give even more pronounced bump effect. | - |
clearCoatGlossInvert | booleanInvert the clearcoat gloss component (default is false). Enabling this flag results in material treating the clear coat gloss members as roughness. | - |
clearCoatGlossMap | Texture | nullin (primary) diffuse map of the material (default is null). | - |
clearCoatGlossMapChannel | stringColor channel of the clearcoat gloss map to use. Can be "r", "g", "b" or "a". | - |
clearCoatGlossMapOffset | Vec2Controls the 2D offset of the clearcoat gloss map. Each component is between 0 and 1. | - |
clearCoatGlossMapRotation | numberControls the 2D rotation (in degrees) of the clear coat gloss map. | - |
clearCoatGlossMapTiling | Vec2Controls the 2D tiling of the clearcoat gloss map. | - |
clearCoatGlossMapUv | numberClearcoat gloss map UV channel. | - |
clearCoatGlossVertexColor | booleanUse mesh vertex colors for clearcoat glossiness. If clearCoatGlossMap is set, it'll be multiplied by vertex colors. | - |
clearCoatGlossVertexColorChannel | stringVertex color channel to use for clearcoat glossiness. Can be "r", "g", "b" or "a". | - |
clearCoatGloss | numberDefines the clearcoat glossiness of the clearcoat layer from 0 (rough) to 1 (mirror). | - |
clearCoatMap | Texture | nullhe main (primary) diffuse map of the material (default is null). | - |
clearCoatMapChannel | stringColor channel of the clearcoat intensity map to use. Can be "r", "g", "b" or "a". | - |
clearCoatMapOffset | Vec2Controls the 2D offset of the clearcoat intensity map. Each component is between 0 and 1. | - |
clearCoatMapRotation | numberControls the 2D rotation (in degrees) of the clearcoat intensity map. | - |
clearCoatMapTiling | Vec2Controls the 2D tiling of the clearcoat intensity map. | - |
clearCoatMapUv | numberClearcoat intensity map UV channel. | - |
clearCoatNormalMap | Texture | nulln (primary) diffuse map of the material (default is null). | - |
clearCoatNormalMapOffset | Vec2Controls the 2D offset of the main clearcoat normal map. Each component is between 0 and 1. | - |
clearCoatNormalMapRotation | numberControls the 2D rotation (in degrees) of the main clearcoat map. | - |
clearCoatNormalMapTiling | Vec2Controls the 2D tiling of the main clearcoat normal map. | - |
clearCoatNormalMapUv | numberClearcoat normal map UV channel. | - |
clearCoatVertexColor | booleanUse mesh vertex colors for clearcoat intensity. If clearCoatMap is set, it'll be multiplied by vertex colors. | - |
clearCoatVertexColorChannel | stringVertex color channel to use for clearcoat intensity. Can be "r", "g", "b" or "a". | - |
cubeMap | Texture | nullMap The main (primary) diffuse map of the material (default is null). | - |
cubeMapProjection | numberThe type of projection applied to the cubeMap property: - CUBEPROJ_NONE: The cube map is treated as if it is infinitely far away. - CUBEPROJ_BOX: Box-projection based on a world space axis-aligned bounding box. Defaults to CUBEPROJ_NONE. | - |
cubeMapProjectionBox | BoundingBoxThe world space axis-aligned bounding box defining the box-projection used for the cubeMap property. Only used when cubeMapProjection is set to CUBEPROJ_BOX. | - |
diffuse | ColorThe diffuse color of the material. This color value is 3-component (RGB), where each component is between 0 and 1. Defines basic surface color (aka albedo). | - |
diffuseDetailMap | Texture | nullain (primary) diffuse map of the material (default is null). | - |
diffuseDetailMapChannel | stringColor channels of the detail (secondary) diffuse map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
diffuseDetailMapOffset | Vec2Controls the 2D offset of the detail (secondary) diffuse map. Each component is between 0 and 1. | - |
diffuseDetailMapRotation | numberControls the 2D rotation (in degrees) of the main (secondary) diffuse map. | - |
diffuseDetailMapTiling | Vec2Controls the 2D tiling of the detail (secondary) diffuse map. | - |
diffuseDetailMapUv | numberDetail (secondary) diffuse map UV channel. | - |
diffuseDetailMode | stringDetermines how the main (primary) and detail (secondary) diffuse maps are blended together. Can be: - DETAILMODE_MUL: Multiply together the primary and secondary colors. - DETAILMODE_ADD: Add together the primary and secondary colors. - DETAILMODE_SCREEN: Softer version of DETAILMODE_ADD. - DETAILMODE_OVERLAY: Multiplies or screens the colors, depending on the primary color. - DETAILMODE_MIN: Select whichever of the primary and secondary colors is darker, component-wise. - DETAILMODE_MAX: Select whichever of the primary and secondary colors is lighter, component-wise. Defaults to DETAILMODE_MUL. | - |
diffuseMap | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
diffuseMapChannel | stringColor channels of the main (primary) diffuse map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
diffuseMapOffset | Vec2Controls the 2D offset of the main (primary) diffuse map. Each component is between 0 and 1. | - |
diffuseMapRotation | numberControls the 2D rotation (in degrees) of the main (primary) diffuse map. | - |
diffuseMapTiling | Vec2Controls the 2D tiling of the main (primary) diffuse map. | - |
diffuseMapUv | numberMain (primary) diffuse map UV channel. | - |
diffuseVertexColor | booleanMultiply diffuse by the mesh vertex colors. | - |
diffuseVertexColorChannel | stringVertex color channels to use for diffuse. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
emissive | ColorThe emissive color of the material. This color value is 3-component (RGB), where each component is between 0 and 1. | - |
emissiveIntensity | numberEmissive color multiplier. | - |
emissiveMap | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
emissiveMapChannel | stringColor channels of the emissive map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
emissiveMapOffset | Vec2Controls the 2D offset of the emissive map. Each component is between 0 and 1. | - |
emissiveMapRotation | numberControls the 2D rotation (in degrees) of the emissive map. | - |
emissiveMapTiling | Vec2Controls the 2D tiling of the emissive map. | - |
emissiveMapUv | numberEmissive map UV channel. | - |
emissiveVertexColor | booleanUse mesh vertex colors for emission. If emissiveMap or emissive are set, they'll be multiplied by vertex colors. | - |
emissiveVertexColorChannel | stringVertex color channels to use for emission. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
enableGGXSpecular | booleanEnables GGX specular. Also enables StandardMaterial#anisotropyIntensity parameter to set material anisotropy. | - |
envAtlas | Texture | nullap The main (primary) diffuse map of the material (default is null). | - |
fresnelModel | numberDefines the formula used for Fresnel effect. As a side-effect, enabling any Fresnel model changes the way diffuse and reflection components are combined. When Fresnel is off, legacy non energy-conserving combining is used. When it is on, combining behavior is energy-conserving. - FRESNEL_NONE: No Fresnel. - FRESNEL_SCHLICK: Schlick's approximation of Fresnel (recommended). Parameterized by specular color. | - |
gloss | numberDefines the glossiness of the material from 0 (rough) to 1 (shiny). | - |
glossInvert | booleanInvert the gloss component (default is false). Enabling this flag results in material treating the gloss members as roughness. | - |
glossMap | Texture | nullap The main (primary) diffuse map of the material (default is null). | - |
glossMapChannel | stringColor channel of the gloss map to use. Can be "r", "g", "b" or "a". | - |
glossMapOffset | Vec2Controls the 2D offset of the gloss map. Each component is between 0 and 1. | - |
glossMapRotation | numberControls the 2D rotation (in degrees) of the gloss map. | - |
glossMapTiling | Vec2Controls the 2D tiling of the gloss map. | - |
glossMapUv | numberGloss map UV channel. | - |
glossVertexColor | booleanUse mesh vertex colors for glossiness. If glossMap is set, it'll be multiplied by vertex colors. | - |
glossVertexColorChannel | stringVertex color channel to use for glossiness. Can be "r", "g", "b" or "a". | - |
heightMap | Texture | nullp The main (primary) diffuse map of the material (default is null). | - |
heightMapChannel | stringColor channel of the height map to use. Can be "r", "g", "b" or "a". | - |
heightMapFactor | numberHeight map multiplier. Affects the strength of the parallax effect. | - |
heightMapOffset | Vec2Controls the 2D offset of the height map. Each component is between 0 and 1. | - |
heightMapRotation | numberControls the 2D rotation (in degrees) of the height map. | - |
heightMapTiling | Vec2Controls the 2D tiling of the height map. | - |
heightMapUv | numberHeight map UV channel. | - |
lightMap | Texture | nullap The main (primary) diffuse map of the material (default is null). | - |
lightMapChannel | stringColor channels of the lightmap to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
lightMapOffset | Vec2Controls the 2D offset of the lightmap. Each component is between 0 and 1. | - |
lightMapRotation | numberControls the 2D rotation (in degrees) of the lightmap. | - |
lightMapTiling | Vec2Controls the 2D tiling of the lightmap. | - |
lightMapUv | numberLightmap UV channel | - |
lightVertexColor | booleanUse baked vertex lighting. If lightMap is set, it'll be multiplied by vertex colors. | - |
lightVertexColorChannel | stringVertex color channels to use for baked lighting. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
metalness | numberDefines how much the surface is metallic. From 0 (dielectric) to 1 (metal). | - |
metalnessMap | Texture | nullhe main (primary) diffuse map of the material (default is null). | - |
metalnessMapChannel | stringColor channel of the metalness map to use. Can be "r", "g", "b" or "a". | - |
metalnessMapOffset | Vec2Controls the 2D offset of the metalness map. Each component is between 0 and 1. | - |
metalnessMapRotation | numberControls the 2D rotation (in degrees) of the metalness map. | - |
metalnessMapTiling | Vec2Controls the 2D tiling of the metalness map. | - |
metalnessMapUv | numberMetalness map UV channel. | - |
metalnessVertexColor | booleanUse mesh vertex colors for metalness. If metalnessMap is set, it'll be multiplied by vertex colors. | - |
metalnessVertexColorChannel | stringVertex color channel to use for metalness. Can be "r", "g", "b" or "a". | - |
normalDetailMap | Texture | nullmain (primary) diffuse map of the material (default is null). | - |
normalDetailMapBumpiness | numberThe bumpiness of the material. This value scales the assigned detail (secondary) normal map. It should be normally between 0 (no bump mapping) and 1 (full bump mapping), but can be set to e.g. 2 to give even more pronounced bump effect. | - |
normalDetailMapOffset | Vec2Controls the 2D offset of the detail (secondary) normal map. Each component is between 0 and 1. | - |
normalDetailMapRotation | numberControls the 2D rotation (in degrees) of the detail (secondary) normal map. | - |
normalDetailMapTiling | Vec2Controls the 2D tiling of the detail (secondary) normal map. | - |
normalDetailMapUv | numberDetail (secondary) normal map UV channel. | - |
normalMap | Texture | nullp The main (primary) diffuse map of the material (default is null). | - |
normalMapOffset | Vec2Controls the 2D offset of the main (primary) normal map. Each component is between 0 and 1. | - |
normalMapRotation | numberControls the 2D rotation (in degrees) of the main (primary) normal map. | - |
normalMapTiling | Vec2Controls the 2D tiling of the main (primary) normal map. | - |
normalMapUv | numberMain (primary) normal map UV channel. | - |
occludeDirect | number | - |
occludeSpecular | numberUses ambient occlusion to darken specular/reflection. It's a hack, because real specular occlusion is view-dependent. However, it can be better than nothing. - SPECOCC_NONE: No specular occlusion - SPECOCC_AO: Use AO directly to occlude specular. - SPECOCC_GLOSSDEPENDENT: Modify AO based on material glossiness/view angle to occlude specular. | - |
occludeSpecularIntensity | numberControls visibility of specular occlusion. | - |
opacity | numberThe opacity of the material. This value can be between 0 and 1, where 0 is fully transparent and 1 is fully opaque. If you want the material to be semi-transparent you also need to set the Material#blendType to BLEND_NORMAL, BLEND_ADDITIVE or any other mode. Also note that for most semi-transparent objects you want Material#depthWrite to be false, otherwise they can fully occlude objects behind them. | - |
opacityDither | stringUsed to specify whether opacity is dithered, which allows transparency without alpha blending. Can be: - DITHER_NONE: Opacity dithering is disabled. - DITHER_BAYER8: Opacity is dithered using a Bayer 8 matrix. - DITHER_BLUENOISE: Opacity is dithered using a blue noise. - DITHER_IGNNOISE: Opacity is dithered using an interleaved gradient noise. Defaults to DITHER_NONE. | - |
opacityShadowDither | string | - |
opacityFadesSpecular | booleanUsed to specify whether specular and reflections are faded out using StandardMaterial#opacity . Default is true. When set to false use Material#alphaFade to fade out materials. | - |
opacityMap | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
opacityMapChannel | stringColor channel of the opacity map to use. Can be "r", "g", "b" or "a". | - |
opacityMapOffset | Vec2Controls the 2D offset of the opacity map. Each component is between 0 and 1. | - |
opacityMapRotation | numberControls the 2D rotation (in degrees) of the opacity map. | - |
opacityMapTiling | Vec2Controls the 2D tiling of the opacity map. | - |
opacityMapUv | numberOpacity map UV channel. | - |
opacityVertexColor | booleanUse mesh vertex colors for opacity. If opacityMap is set, it'll be multiplied by vertex colors. | - |
opacityVertexColorChannel | stringVertex color channels to use for opacity. Can be "r", "g", "b" or "a". | - |
pixelSnap | booleanAlign vertices to pixel coordinates when rendering. Useful for pixel perfect 2D graphics. | - |
reflectivity | numberEnvironment map intensity. | - |
refraction | numberDefines the visibility of refraction. Material can refract the same cube map as used for reflections. | - |
refractionIndex | numberDefines the index of refraction, i.e. The amount of distortion. The value is calculated as (outerIor / surfaceIor), where inputs are measured indices of refraction, the one around the object and the one of its own surface. In most situations outer medium is air, so outerIor will be approximately 1. Then you only need to do (1.0 / surfaceIor). | - |
dispersion | numberThe strength of the angular separation of colors (chromatic aberration) transmitting through a volume. Defaults to 0, which is equivalent to no dispersion. | - |
shadowCatcher | booleanWhen enabled, the material will output accumulated directional shadow value in linear space as the color. | - |
specular | ColorThe specular color of the material. This color value is 3-component (RGB), where each component is between 0 and 1. Defines surface reflection/specular color. Affects specular intensity and tint. | - |
specularMap | Texture | nullThe main (primary) diffuse map of the material (default is null). | - |
specularMapChannel | stringColor channels of the specular map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
specularMapOffset | Vec2Controls the 2D offset of the specular map. Each component is between 0 and 1. | - |
specularMapRotation | numberControls the 2D rotation (in degrees) of the specular map. | - |
specularMapTiling | Vec2Controls the 2D tiling of the specular map. | - |
specularMapUv | numberSpecular map UV channel. | - |
specularTint | booleanMultiply specular map and/or specular vertex color by the constant specular value. | - |
specularVertexColor | booleanUse mesh vertex colors for specular. If specularMap or are specularTint are set, they'll be multiplied by vertex colors. | - |
specularVertexColorChannel | stringVertex color channels to use for specular. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
specularityFactor | numberThe factor of specular intensity, used to weight the fresnel and specularity. Default is 1.0. | - |
specularityFactorMap | Texture | null(primary) diffuse map of the material (default is null). | - |
specularityFactorMapChannel | stringThe channel used by the specularity factor texture to sample from (default is 'a'). | - |
specularityFactorMapOffset | Vec2Controls the 2D offset of the specularity factor map. Each component is between 0 and 1. | - |
specularityFactorMapRotation | numberControls the 2D rotation (in degrees) of the specularity factor map. | - |
specularityFactorMapTiling | Vec2Controls the 2D tiling of the specularity factor map. | - |
specularityFactorMapUv | numberSpecularity factor map UV channel. | - |
useSheen | booleanToggle sheen specular effect on/off. | - |
sheen | ColorThe specular color of the sheen (fabric) microfiber structure. This color value is 3-component (RGB), where each component is between 0 and 1. | - |
sheenMap | Texture | nullap The main (primary) diffuse map of the material (default is null). | - |
sheenMapChannel | stringColor channels of the sheen map to use. Can be "r", "g", "b", "a", "rgb" or any swizzled combination. | - |
sheenMapOffset | Vec2Controls the 2D offset of the sheen map. Each component is between 0 and 1. | - |
sheenMapRotation | numberControls the 2D rotation (in degrees) of the sheen map. | - |
sheenMapTiling | Vec2Controls the 2D tiling of the sheen map. | - |
sheenMapUv | numberSheen map UV channel. | - |
sheenVertexColor | booleanUse mesh vertex colors for sheen. If sheen map or sheen tint are set, they'll be multiplied by vertex colors. | - |
sheenVertexColorChannel | string | - |
sphereMap | Texture | nullp The main (primary) diffuse map of the material (default is null). | - |
twoSidedLighting | booleanCalculate proper normals (and therefore lighting) on backfaces. | - |
useFog | booleanApply fogging (as configured in scene settings) | - |
useTonemap | booleanApply tonemapping (as configured in Scene#rendering or CameraComponent.rendering ). Defaults to true. | - |
useLighting | booleanApply lighting | - |
useMetalness | booleanUse metalness properties instead of specular. When enabled, diffuse colors also affect specular instead of the dedicated specular map. This can be used as alternative to specular color to save space. With metalness == 0, the pixel is assumed to be dielectric, and diffuse color is used as normal. With metalness == 1, the pixel is fully metallic, and diffuse color is used as specular color instead. | - |
useMetalnessSpecularColor | booleanWhen metalness is enabled, use the specular map to apply color tint to specular reflections. at direct angles. | - |
useSkybox | booleanApply scene skybox as prefiltered environment map | - |
_uniformCache | {} | - |
copy | (source: StandardMaterial) => StandardMaterialCopy a `StandardMaterial`. | - |
setAttribute | (name: string, semantic: string) => voidSets a vertex shader attribute on a material. | - |
_setParameter | (name: any, value: any) => void | - |
_setParameters | (parameters: any) => void | - |
_processParameters | (paramsName: any) => void | - |
_updateMap | (p: any) => void | - |
_allocUniform | (name: any, allocFunc: any) => any | - |
getUniform | (name: any, device: any, scene: any) => any | - |
updateEnvUniforms | (device: any, scene: any) => void | - |
meshInstances | anyThe mesh instances referencing this material | - |
name | stringThe name of the material. | - |
userId | stringA unique id the user can assign to the material. The engine internally does not use this for
anything, and the user can assign a value to this id for any purpose they like. Defaults to
an empty string. | - |
id | number | - |
_definesDirty | boolean | - |
parameters | {} | - |
alphaTest | numberThe alpha test reference value to control which fragments are written to the currently
active render target based on alpha value. All fragments with an alpha value of less than
the alphaTest reference value will be discarded. alphaTest defaults to 0 (all fragments
pass). | - |
alphaToCoverage | booleanEnables or disables alpha to coverage (WebGL2 only). When enabled, and if hardware
anti-aliasing is on, limited order-independent transparency can be achieved. Quality depends
on the number of MSAA samples of the current render target. It can nicely soften edges of
otherwise sharp alpha cutouts, but isn't recommended for large area semi-transparent
surfaces. Note, that you don't need to enable blending to make alpha to coverage work. It
will work without it, just like alphaTest. | - |
cull | numberControls how triangles are culled based on their face direction with respect to the
viewpoint. Can be:
- CULLFACE_NONE: Do not cull triangles based on face direction.
- CULLFACE_BACK: Cull the back faces of triangles (do not render triangles facing
away from the view point).
- CULLFACE_FRONT: Cull the front faces of triangles (do not render triangles facing
towards the view point).
Defaults to CULLFACE_BACK. | - |
frontFace | numberControls whether polygons are front- or back-facing by setting a winding
orientation. Can be:
- FRONTFACE_CW: The clock-wise winding.
- FRONTFACE_CCW: The counterclockwise winding.
Defaults to FRONTFACE_CCW. | - |
stencilFront | StencilParameters | nullStencil parameters for front faces (default is null). | - |
stencilBack | StencilParameters | nullStencil parameters for back faces (default is null). | - |
_shaderChunks | any | - |
_oldChunks | {} | - |
_dirtyShader | boolean | - |
getShaderChunks | (shaderLanguage?: string | undefined) => ShaderChunkMapReturns an object containing shader chunks for a specific shader language for the material.
These chunks define custom GLSL or WGSL code used to construct the final shader for the
material. The chunks can be also be included in shaders using the `#include "ChunkName"`
directive.
On the WebGL platform:
- If GLSL chunks are provided, they are used directly.
On the WebGPU platform:
- If WGSL chunks are provided, they are used directly.
- If only GLSL chunks are provided, a GLSL shader is generated and then transpiled to WGSL,
which is less efficient.
To ensure faster shader compilation, it is recommended to provide shader chunks for all
supported platforms.
A simple example on how to override a shader chunk providing emissive color for both GLSL and
WGSL to simply return a red color:
```javascript
material.getShaderChunks(pc.SHADERLANGUAGE_GLSL).set('emissivePS', `
void getEmission() {
dEmission = vec3(1.0, 0.0, 1.0);
}
`);
material.getShaderChunks(pc.SHADERLANGUAGE_WGSL).set('emissivePS', `
fn getEmission() {
dEmission = vec3f(1.0, 0.0, 1.0);
}
`);
// call update to apply the changes
material.update();
``` | - |
shaderChunksVersion | stringSets the version of the shader chunks.
This should be a string containing the current engine major and minor version (e.g., '2.8'
for engine v2.8.1) and ensures compatibility with the current engine version. When providing
custom shader chunks, set this to the latest supported version. If a future engine release no
longer supports the specified version, a warning will be issued. In that case, update your
shader chunks to match the new format and set this to the latest version accordingly.
Returns the version of the shader chunks. | - |
chunks | {} | - |
depthBias | numberSets the offset for the output depth buffer value. Useful for decals to prevent z-fighting.
Typically a small negative value (-0.1) is used to render the mesh slightly closer to the
camera.
Gets the offset for the output depth buffer value. | - |
slopeDepthBias | numberSets the offset for the output depth buffer value based on the slope of the triangle
relative to the camera.
Gets the offset for the output depth buffer value based on the slope of the triangle
relative to the camera. | - |
_shaderVersion | number | - |
_scene | any | - |
dirty | boolean | - |
redWrite | booleanSets whether the red channel is written to the color buffer. If true, the red component of
fragments generated by the shader of this material is written to the color buffer of the
currently active render target. If false, the red component will not be written. Defaults to
true.
Gets whether the red channel is written to the color buffer. | - |
greenWrite | booleanSets whether the green channel is written to the color buffer. If true, the red component of
fragments generated by the shader of this material is written to the color buffer of the
currently active render target. If false, the green component will not be written. Defaults
to true.
Gets whether the green channel is written to the color buffer. | - |
blueWrite | booleanSets whether the blue channel is written to the color buffer. If true, the red component of
fragments generated by the shader of this material is written to the color buffer of the
currently active render target. If false, the blue component will not be written. Defaults
to true.
Gets whether the blue channel is written to the color buffer. | - |
alphaWrite | booleanSets whether the alpha channel is written to the color buffer. If true, the red component of
fragments generated by the shader of this material is written to the color buffer of the
currently active render target. If false, the alpha component will not be written. Defaults
to true.
Gets whether the alpha channel is written to the color buffer. | - |
transparent | boolean | - |
_updateTransparency | () => void | - |
blendState | BlendStateSets the blend state for this material. Controls how fragment shader outputs are blended
when being written to the currently active render target. This overwrites blending type set
using Material#blendType , and offers more control over blending.
Gets the blend state for this material. | - |
blendType | numberSets the blend mode for this material. Controls how fragment shader outputs are blended when
being written to the currently active render target. Can be:
- BLEND_SUBTRACTIVE: Subtract the color of the source fragment from the destination
fragment and write the result to the frame buffer.
- BLEND_ADDITIVE: Add the color of the source fragment to the destination fragment
and write the result to the frame buffer.
- BLEND_NORMAL: Enable simple translucency for materials such as glass. This is
equivalent to enabling a source blend mode of BLENDMODE_SRC_ALPHA and a destination
blend mode of BLENDMODE_ONE_MINUS_SRC_ALPHA.
- BLEND_NONE: Disable blending.
- BLEND_PREMULTIPLIED: Similar to BLEND_NORMAL expect the source fragment is
assumed to have already been multiplied by the source alpha value.
- BLEND_MULTIPLICATIVE: Multiply the color of the source fragment by the color of the
destination fragment and write the result to the frame buffer.
- BLEND_ADDITIVEALPHA: Same as BLEND_ADDITIVE except the source RGB is
multiplied by the source alpha.
- BLEND_MULTIPLICATIVE2X: Multiplies colors and doubles the result.
- BLEND_SCREEN: Softer version of additive.
- BLEND_MIN: Minimum color.
- BLEND_MAX: Maximum color.
Defaults to BLEND_NONE.
Gets the blend mode for this material. | - |
depthState | DepthStateSets the depth state. Note that this can also be done by using Material#depthTest ,
Material#depthFunc and Material#depthWrite .
Gets the depth state. | - |
depthTest | booleanSets whether depth testing is enabled. If true, fragments generated by the shader of this
material are only written to the current render target if they pass the depth test. If
false, fragments generated by the shader of this material are written to the current render
target regardless of what is in the depth buffer. Defaults to true.
Gets whether depth testing is enabled. | - |
depthFunc | numberSets the depth test function. Controls how the depth of new fragments is compared against
the current depth contained in the depth buffer. Can be:
- FUNC_NEVER: don't draw
- FUNC_LESS: draw if new depth < depth buffer
- FUNC_EQUAL: draw if new depth == depth buffer
- FUNC_LESSEQUAL: draw if new depth <= depth buffer
- FUNC_GREATER: draw if new depth > depth buffer
- FUNC_NOTEQUAL: draw if new depth != depth buffer
- FUNC_GREATEREQUAL: draw if new depth >= depth buffer
- FUNC_ALWAYS: always draw
Defaults to FUNC_LESSEQUAL.
Gets the depth test function. | - |
depthWrite | booleanSets whether depth writing is enabled. If true, fragments generated by the shader of this
material write a depth value to the depth buffer of the currently active render target. If
false, no depth value is written. Defaults to true.
Gets whether depth writing is enabled. | - |
clone | () => StandardMaterialClone a material. | - |
_updateMeshInstanceKeys | () => void | - |
updateUniforms | (device: any, scene: any) => void | - |
update | () => voidApplies any changes made to the material's properties. This method should be called after
modifying material properties to ensure the changes take effect.
The method will clear cached shader variants and trigger recompilation if:
- Modified material properties require a different shader variant (e.g., enabling/disabling
textures or other properties that affect shader generation)
- Material-specific shader chunks (from Material#getShaderChunks ) have been modified
- Global shader chunks (from ShaderChunks.get) have been modified
- Material defines have been changed
Note: Shaders are not compiled immediately. Instead, existing shader variants are cleared
and new variants will be compiled on-demand as they are needed for different render passes
(e.g., SHADER_FORWARD, SHADER_SHADOW).
When global shader chunks are modified, `update()` must be called on each material that
should reflect those changes. | - |
clearParameters | () => void | - |
getParameters | () => {} | - |
clearVariants | () => void | - |
getParameter | (name: string) => objectRetrieves the specified shader parameter from a material. | - |
_setParameterSimple | (name: any, data: any) => void | - |
setParameter | (name: string, data: number | Texture | number[] | ArrayBufferView<ArrayBufferLike> | StorageBuffer) => voidSets a shader parameter on a material. | - |
deleteParameter | (name: string) => voidDeletes a shader parameter on a material. | - |
setParameters | (device: any, names: any) => void | - |
setDefine | (name: string, value: string | boolean | undefined) => voidAdds or removes a define on the material. Defines can be used to enable or disable various
parts of the shader code. | - |
getDefine | (name: string) => booleanReturns true if a define is enabled on the material, otherwise false. | - |
destroy | () => voidRemoves this material from the scene and possibly frees up memory from its shaders (if there
are no other materials using it). | - |
さらなる例
高度なプロパティ
StandardMaterial は多くのプロパティを受け付けます。一覧はこちらです。
import { useMaterial } from '@playcanvas/react/hooks'
function AdvancedMaterial() {
const material = useMaterial({
diffuse: 'purple',
opacity: 0.9,
metalness: 0.3,
roughness: 0.4,
emissive: 'yellow',
emissiveIntensity: 0.2,
specular: 'white',
shininess: 50,
reflectivity: 0.8,
clearCoat: 0.5,
clearCoatRoughness: 0.1
})
return <Render type="box" material={material} />
}
テクスチャ付きマテリアル
useTexture フックでテクスチャを読み込み、マテリアルと組み合わせられます。
import { useMaterial } from '@playcanvas/react/hooks'
import { useTexture } from '@playcanvas/react/hooks'
function TexturedMaterialExample() {
const { asset: diffuseMap } = useTexture('diffuse.jpg')
const { asset: normalMap } = useTexture('normal.jpg')
const { asset: roughnessMap } = useTexture('roughness.jpg')
const material = useMaterial({
diffuseMap: diffuseMap?.resource,
normalMap: normalMap?.resource,
roughnessMap: roughnessMap?.resource,
diffuse: 'white',
metalness: 0.5,
roughness: 0.5
})
return <Render type="box" material={material} />
}
マテリアルの共有
複数の render コンポーネント間でマテリアルを簡単に共有できます。
import { useMaterial } from '@playcanvas/react/hooks'
function SharedMaterial() {
const material = useMaterial({
diffuse: 'orange',
metalness: 0.7,
roughness: 0.3
})
return (
<div>
<Render type="box" material={material} />
<Render type="sphere" material={material} />
<Render type="cylinder" material={material} />
</div>
)
}
関連
- useTexture — テクスチャ Asset の読み込み
- Render コンポーネント — render コンポーネントでマテリアルを使う
- StandardMaterial API — PlayCanvas のマテリアルドキュメント