Code Monkey home page Code Monkey logo

clipping-with-caps's Introduction

clipping-with-caps

Clipping a mesh and covering the openings with caps in WebGL

View the demo

screenshot

Licensed under MIT License

Dependencies:


Clipping meshes inside a shader program is fast and avoids triangulation problems that can arise when actually constructing a clipped mesh with constructive solid geometry. But since a mesh is just a hollow hull of triangles the clipped object will have an opening along the clipping edge. It is however possible to visually close this gaps without actually constructing the cap faces.

When there is just one clipping plane on an otherwise closed mesh and backface rendering is enabled, then there are backsides visible through the whole opening. Rendered into a stencil this area can be used to define where to render the caps. First a scene showing only the backfaces is used to increment the stencil and then another scene showing the front faces decrements the stencil. The resulting stencil is applied to a scene rendering a plane at the location of the clipping plane.

But this method fails when there is more than one clipping plane. Because clipping planes facing away from the camera result in hidden backfaces, these areas are missing in the stencil. The result would look like this:

screenshot

The solution is to use a different shader for rendering the stencil areas, that only clipps at clipping planes facing the camera. Since the camera position is known it can be calculated in the shader whether a clipping plane is facing towards the camera or away from it.

clipping-with-caps's People

Contributors

daign avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.