-
new ShaderMaterial(params)
-
Shader材质
Name Type Description params
object optional 初始化参数,所有params都会复制到实例上
Example
const material = new Hilo3d.ShaderMaterial({ attributes:{ a_pos: 'POSITION' }, uniforms:{ u_mat:'MODELVIEWPROJECTION', u_color_b:{ get:function(mesh, material, programInfo){ return Math.random(); } } }, vs:` precision HILO_MAX_VERTEX_PRECISION float; attribute vec3 a_pos; uniform mat4 u_mat; void main(void) { gl_Position = u_mat * vec4(a_pos, 1.0); } `, fs:` precision HILO_MAX_FRAGMENT_PRECISION float; uniform float u_color_b; void main(void) { gl_FragColor = vec4(0.6, 0.8, u_color_b, 1); } ` });
Extends
Members Show Inherited
Name | Type | Default | Description |
---|---|---|---|
isShaderMaterial
|
boolean | true | |
className
|
string | ShaderMaterial | |
vs
|
string |
vertex shader 代码 |
|
fs
|
string |
fragment shader 代码 |
|
useHeaderCache
|
Boolean | true |
是否使用 header cache shader |
getCustomRenderOption
|
function | null |
获取定制的渲染参数 |
isMaterial
|
boolean | true | inherited |
name
|
string |
inherited
name |
|
shaderCacheId
|
string | null |
inherited
shader cache id |
shaderName
|
string | null |
inherited
shader name,会在 shader 中加个 SHADER_NAME 宏,不填用 className 代替。 |
lightType
|
string | NONE |
inherited
光照类型 |
wireframe
|
boolean | false |
inherited
是否开启网格模式 |
frontFace
|
GLenum | CCW |
inherited
front face winding orientation |
depthTest
|
boolean | true |
inherited
是否开启深度测试 |
sampleAlphaToCoverage
|
Boolean | false |
inherited
SAMPLE_ALPHA_TO_COVERAGE |
depthMask
|
boolean | true |
inherited
是否开启depthMask |
depthRange
|
Array | [0, 1] |
inherited
深度测试Range |
depthFunc
|
GLenum | LESS |
inherited
深度测试方法 |
normalMap
|
Texture | null |
inherited
法线贴图 |
parallaxMap
|
Texture | null |
inherited
视差贴图 |
normalMapScale
|
Number | 1 |
inherited
法线贴图scale |
ignoreTranparent
|
Boolean | false |
inherited
是否忽略透明度 |
gammaCorrection
|
Boolean | false |
inherited
是否开启 gamma 矫正 |
usePhysicsLight
|
Boolean | false |
inherited
是否使用物理灯光 |
isDiffuesEnvAndAmbientLightWorkTogether
|
Boolean | false |
inherited
是否环境贴图和环境光同时生效 |
userData
|
any | null |
inherited
用户数据 |
renderOrder
|
Number | 0 |
inherited
渲染顺序数字小的先渲染(透明物体和不透明在不同的队列) |
premultiplyAlpha
|
Boolean | true |
inherited
是否预乘 alpha |
gammaOutput
|
Boolean | false |
inherited
gammaOutput |
gammaFactor
|
Number | 2.2 |
inherited
gamma值 |
castShadows
|
Boolean | true |
inherited
是否投射阴影 |
receiveShadows
|
Boolean | true |
inherited
是否接受阴影 |
uvMatrix
|
Matrix3 |
inherited
uv transform eg:new Matrix3().fromRotationTranslationScale(Math.PI/2, 0, 0, 2, 2) |
|
uvMatrix1
|
Matrix3 |
inherited
uv1 transform eg:new Matrix3().fromRotationTranslationScale(Math.PI/2, 0, 0, 2, 2) |
|
cullFace
|
boolean | true |
inherited
是否开启 CullFace |
cullFaceType
|
GLenum | BACK |
inherited
CullFace 类型 |
side
|
GLenum | FRONT |
inherited
显示面,可选值 FRONT, BACK, FRONT_AND_BACK |
blend
|
boolean | false |
inherited
是否开启颜色混合 |
blendEquation
|
GLenum | FUNC_ADD |
inherited
颜色混合方式 |
blendEquationAlpha
|
GLenum | FUNC_ADD |
inherited
透明度混合方式 |
blendSrc
|
GLenum | ONE |
inherited
颜色混合来源比例 |
blendDst
|
GLenum | ZERO |
inherited
颜色混合目标比例 |
blendSrcAlpha
|
GLenum | ONE |
inherited
透明度混合来源比例 |
blendDstAlpha
|
GLenum | ONE |
inherited
透明度混合目标比例 |
stencilTest
|
boolean | 1 |
inherited
stencilTest |
stencilMask
|
number | 0xff |
inherited
stencilMask |
stencilFunc
|
GLenum | ALWAYS |
inherited
stencilFunc func |
stencilFuncRef
|
number | 1 |
inherited
stencilFunc ref |
stencilFuncMask
|
number | 0xff |
inherited
stencilFunc mask |
stencilOpFail
|
GLenum | KEEP |
inherited
stencilOp fail |
stencilOpZFail
|
GLenum | KEEP |
inherited
stencilOp zfail |
stencilOpZPass
|
GLenum | KEEP |
inherited
stencilOp zpass |
isDirty
|
boolean | false |
inherited
当前是否需要强制更新 |
transparency
|
number | 1 |
inherited
透明度 0~1 |
transparent
|
boolean | false |
inherited
是否需要透明 |
alphaCutoff
|
number | 0 |
inherited
透明度剪裁,如果渲染的颜色透明度大于等于这个值的话渲染为完全不透明,否则渲染为完全透明 |
useHDR
|
Boolean | false |
inherited
是否使用HDR |
exposure
|
Number | 1 |
inherited
曝光度,仅在 useHDR 为 true 时生效 |
enableTextureLod
|
Boolean | false |
inherited
是否开启 texture lod |
enableDrawBuffers
|
Boolean | false |
inherited
是否开启 drawBuffers |
needBasicUnifroms
|
Boolean | true |
inherited
是否需要加基础 uniforms |
needBasicAttributes
|
Boolean | true |
inherited
是否需要加基础 attributes |
id
|
string | inherited | |
uniforms
|
object | {} |
inherited
可以通过指定,semantic来指定值的获取方式,或者自定义get方法 |
attributes
|
object | {} |
inherited
可以通过指定,semantic来指定值的获取方式,或者自定义get方法 |
Methods Show Inherited
-
inherited addBasicAttributes()
-
增加基础 attributes
-
inherited addBasicUniforms()
-
增加基础 uniforms
-
inherited addTextureUniforms(textureUniforms)
-
增加贴图 uniforms
Name Type Description textureUniforms
Object textureName:semanticName 键值对
-
inherited getRenderOption(option){Object}
-
获取渲染选项值
Name Type Default Description option
Object {} optional 渲染选项值
Returns:
Type Description Object 渲染选项值