Class: ShaderMaterial

ShaderMaterial

new ShaderMaterial(params)

Shader材质

Name Type Description
params object

初始化参数,所有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
shaderCacheId String null inherited

shader cache id

lightType string NONE inherited

光照类型

wireframe boolean false inherited

是否开启网格模式

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 float 1 inherited

法线贴图scale

ignoreTranparent Boolean false inherited

是否忽略透明度

gammaCorrection Boolean false inherited

是否开启 gamma 矫正

usePhysicsLight Boolean false 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

透明度混合目标比例

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 时生效

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

增加基础 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 渲染选项值

clone 当前Material

Returns:
Type Description
Material 返回clone的Material

inherited destroyTextures(renderer){Material}

销毁贴图

Name Type Description
renderer WebGLRenderer
Returns:
Type Description
Material this