1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    Dismiss Notice

Subtractive Boolean Rendering

Discussion in 'Shaders' started by Cactus_on_Fire, Dec 4, 2015.

  1. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    346
    Hello.

    I'm looking for a way to render the meshes where a mesh-defined or geometrically-defined area will "cut out" the mesh when it's rendered so the insides are visible. It doesn't necessarily have to fill the gaps pf the polygons but doing so will be fine as well. Here is an example of what I mean :

    [​IMG]
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    2,439
  3. StevenGerrard

    StevenGerrard

    Joined:
    Jun 1, 2015
    Posts:
    91
    Here is a step by step progress
    => The sphere material should be "Cull Front" and "Write Depth",
    => "Cull Front" make you only see inside of sphere surface.
    => "Write Depth" make sphere block the cube.
    => The box material should be "Enable Depth Test".
    => "Enable Depth Test" make your cube blocked by sphere.
    => Gaps problem can be solved by something called "soft particle by depth buffer". Try google it.
    => Use stencil also ok however stencil buffer is terrible supported on mobile platform. Take care of it.
     
  4. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    346
    I tried stencils, but they only mask the object and not actually cut off their Zdepths :(


    I'm not sure how I can enable depth test.
     
  5. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    346
    Hey steven. Did you have a solution for closing gaps of meshes when they are cut off ?
     
  6. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    733
    I'd say, pass 1 (after other geometry to have correct contents of the stencil buffer):
    - Render the cube
    - Write 1 to stencil

    Pass 2 (after pass 1):
    - Render the sphere
    - Reverse culling, Cull Front
    - Only if stencil is 1 to only intersect into cube
    - ZTest GEqual

    Stencil is not needed if the sphere should be rendered into everything.
     
  7. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    346
    How can I implement something like that with shader code ? I'm a noob when it comes to writing scripts for shaders.