Files
cocos4/cocos/renderer/core/pass.js
T
Yun Hsiao Wu 1850cabe7b Effect Improvements (#3599)
* default material

* remove effects

* better builtin effects

* builtin primitives

* fix material

* builtin uniforms

* fix percision
2018-12-07 14:38:53 +08:00

127 lines
3.6 KiB
JavaScript

// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
import gfx from '../gfx';
import { PassStage } from './constants';
export default class Pass {
constructor(name) {
this._programName = name;
this._stage = PassStage.DEFAULT;
// cullmode
this._cullMode = gfx.CULL_BACK;
// blending
this._blend = false;
this._blendEq = gfx.BLEND_FUNC_ADD;
this._blendAlphaEq = gfx.BLEND_FUNC_ADD;
this._blendSrc = gfx.BLEND_SRC_ALPHA;
this._blendDst = gfx.BLEND_ONE_MINUS_SRC_ALPHA;
this._blendSrcAlpha = gfx.BLEND_ONE;
this._blendDstAlpha = gfx.BLEND_ZERO;
this._blendColor = 0xffffffff;
// depth
this._depthTest = false;
this._depthWrite = false;
this._depthFunc = gfx.DS_FUNC_LESS,
// stencil
this._stencilTest = false;
// front
this._stencilFuncFront = gfx.DS_FUNC_ALWAYS;
this._stencilRefFront = 0;
this._stencilMaskFront = 0xff;
this._stencilFailOpFront = gfx.STENCIL_OP_KEEP;
this._stencilZFailOpFront = gfx.STENCIL_OP_KEEP;
this._stencilZPassOpFront = gfx.STENCIL_OP_KEEP;
this._stencilWriteMaskFront = 0xff;
// back
this._stencilFuncBack = gfx.DS_FUNC_ALWAYS;
this._stencilRefBack = 0;
this._stencilMaskBack = 0xff;
this._stencilFailOpBack = gfx.STENCIL_OP_KEEP;
this._stencilZFailOpBack = gfx.STENCIL_OP_KEEP;
this._stencilZPassOpBack = gfx.STENCIL_OP_KEEP;
this._stencilWriteMaskBack = 0xff;
}
setStage(stage = PassStage.DEFAULT) {
this._stage = stage;
}
setCullMode(cullMode = gfx.CULL_BACK) {
this._cullMode = cullMode;
}
setBlend(
enabled = false,
blendEq = gfx.BLEND_FUNC_ADD,
blendSrc = gfx.BLEND_SRC_ALPHA,
blendDst = gfx.BLEND_ONE_MINUS_SRC_ALPHA,
blendAlphaEq = gfx.BLEND_FUNC_ADD,
blendSrcAlpha = gfx.BLEND_SRC_ALPHA,
blendDstAlpha = gfx.BLEND_ONE_MINUS_SRC_ALPHA,
blendColor = 0xffffffff
) {
this._blend = enabled;
this._blendEq = blendEq;
this._blendSrc = blendSrc;
this._blendDst = blendDst;
this._blendAlphaEq = blendAlphaEq;
this._blendSrcAlpha = blendSrcAlpha;
this._blendDstAlpha = blendDstAlpha;
this._blendColor = blendColor;
}
setDepth(
depthTest = false,
depthWrite = false,
depthFunc = gfx.DS_FUNC_LESS
) {
this._depthTest = depthTest;
this._depthWrite = depthWrite;
this._depthFunc = depthFunc;
}
setStencilFront(
enabled = false,
stencilFunc = gfx.DS_FUNC_ALWAYS,
stencilRef = 0,
stencilMask = 0xff,
stencilFailOp = gfx.STENCIL_OP_KEEP,
stencilZFailOp = gfx.STENCIL_OP_KEEP,
stencilZPassOp = gfx.STENCIL_OP_KEEP,
stencilWriteMask = 0xff
) {
this._stencilTest = enabled;
this._stencilFuncFront = stencilFunc;
this._stencilRefFront = stencilRef;
this._stencilMaskFront = stencilMask;
this._stencilFailOpFront = stencilFailOp;
this._stencilZFailOpFront = stencilZFailOp;
this._stencilZPassOpFront = stencilZPassOp;
this._stencilWriteMaskFront = stencilWriteMask;
}
setStencilBack(
enabled = false,
stencilFunc = gfx.DS_FUNC_ALWAYS,
stencilRef = 0,
stencilMask = 0xff,
stencilFailOp = gfx.STENCIL_OP_KEEP,
stencilZFailOp = gfx.STENCIL_OP_KEEP,
stencilZPassOp = gfx.STENCIL_OP_KEEP,
stencilWriteMask = 0xff
) {
this._stencilTest = enabled;
this._stencilFuncBack = stencilFunc;
this._stencilRefBack = stencilRef;
this._stencilMaskBack = stencilMask;
this._stencilFailOpBack = stencilFailOp;
this._stencilZFailOpBack = stencilZFailOp;
this._stencilZPassOpBack = stencilZPassOp;
this._stencilWriteMaskBack = stencilWriteMask;
}
}