我可以在Three.js中使用stencilFunc和stencilOp函数吗? 我试图为模板测试实现代码,但没有用。
var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer({
antialias: true,
stencil: true
});
function render() {
var context = renderer.context;
context.enable(context.STENCIL_TEST);
context.stencilFunc(context.ALWAYS, 0, 0xffffffff);
context.stencilOp(context.REPLACE, context.REPLACE, context.REPLACE);
context.clearStencil(0);
context.clear(context.COLOR_BUFFER_BIT, context.DEPTH_BUFFER_BIT, context.STENCIL_BUFFER_BIT);
renderer.render(scene, camera);
context.stencilFunc(context.EQUAL, 1, 0xffffffff);
context.stencilOp(context.KEEP, context.KEEP, context.KEEP);
context.disable(context.STENCIL_TEST);
context.flush();
}
答案 0 :(得分:0)
创建WebGL渲染器时,默认情况下,根据threeJS文档
http://threejs.org/docs/#Reference/Renderers/WebGLRenderer
您可以直接从渲染对象中调用clearStencil(),因为它是渲染器的行为,不确定为什么要从上下文中调用它,同时
您在代码中调用的某些函数在ThreeJs webGL渲染器类中不存在。
以下是类源代码的链接。请检查
https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLRenderer.js