[英]How do I simulate “overflow: hidden” in three.js or WebGL?
I'm currently working on a WebGL GUI for my games and I really want to dig deep into GPU graphics, since it's a lot smoother than WebKit CSS rendering. 我目前正在为我的游戏开发WebGL GUI,我真的想深入研究GPU图形,因为它比WebKit CSS渲染要平滑得多。
Is it possible to make a scrollview where the inside meshes are following overflow rule to hide when going outside the boundaries of the parent mesh? 是否可以制作滚动视图,其中内部网格遵循溢出规则以在超出父网格边界时隐藏?
Perhaps a shader could work, any suggestions? 也许着色器可以工作,任何建议?
Thanks! 谢谢!
If you only want to clip by rectangles you can use the scissor test. 如果您只想按矩形剪辑,可以使用剪刀测试。
gl.enable(gl.SCISSOR_TEST);
gl.scissor(x, y, width, height);
Now WebGL will only render between x, y, width, and height. 现在,WebGL将仅在x,y,width和height之间呈现。
THREE.js also has scissor settings WebGLRenderer.setScissor
and WebGLRenderer.setScissorTest
THREE.js还有剪刀设置
WebGLRenderer.setScissor
和WebGLRenderer.setScissorTest
You could use a "stencil test" to achieve this. 您可以使用“模板测试”来实现此目的。 The stencil test allows you to mask subsequent rendering of geometry against pixels that you have denoted as the "stencil".
模板测试允许您屏蔽几何体的后续渲染与您表示为“模板”的像素。
In terms of what you are doing, you might use the stencil technique to: 就您正在做的事情而言,您可以使用模板技术:
To give you an idea of how to achieve this, you could define your rendering sequence as follows: 为了让您了解如何实现此目的,您可以按如下方式定义渲染序列:
// Clearing the stencil buffer
gl.clearStencil(0);
gl.clear(gl.STENCIL_BUFFER_BIT);
// Tell webgl how to render into the stencil buffer
gl.stencilFunc(gl.ALWAYS, 1, 1);
gl.stencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE);
gl.colorMask(false, false, false, false);
gl.enable(gl.STENCIL_TEST);
// Renders the inner rectangle of scroll area
drawInnerRectangleOfScrollArea();
// Tell webgl how to clip rendering of the scroll area content
gl.stencilFunc(gl.EQUAL, 1, 1);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
gl.colorMask(true, true, true, true);
// Renders the inner contents of scroll area (ie the list of items, etc)
drawInnerContentsOfScrollArea();
// Reset the stenicl test state so to not affect any other rendering
gl.disable(gl.STENCIL_TEST);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.