Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/stencil testing #244

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

DougLilliequist
Copy link
Contributor

@DougLilliequist DougLilliequist commented Dec 22, 2024

@gordonnl Made a new fork which has a cleaner commit history now.

Will eventually make an example in OGL. Worth pointing out that it works with both depth testing and depth texture creation when using render targets (as shown in the gif)

stencilgif

As for implementation, here is how one would write to the stencil buffer:

const program = new Program(this.gl, {
  vertex,
  fragment,
  depthWrite: false,
  depthTest: false,
 })

program.setStencilFunc(this.gl.ALWAYS, 1, 0xff);
program.setStencilOp(this.gl.KEEP, this.gl.KEEP, this.gl.REPLACE);

And here is how an exisiting mesh can test against the stencil buffer. What is neat is that you don't need to make any drastic changes to your exisiting shaders:

this.sphere = new SphereMesh(this.gl);
this.sphere.program.setStencilFunc(this.gl.EQUAL, 2, 0xff);
this.sphere.program.setStencilOp(this.gl.KEEP, this.gl.KEEP, this.gl.KEEP);

@monolithMktg
Copy link

@DougLilliequist thanks for your amazing contributions :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants