Render effect based on intersection of two objects

Hey there Monkey People,

I am using jMonkey to draw 3D graphs in real time.  I have defined two objects, which I have called blobs. 

  1. A data blob
  2. a filter blob

    I am interested in the interaction of these two blobs.  I only want render the pixels of the data blob where it intersects with the filter blob.

    To make things a little simpler I am starting off by limiting the filter blob to a plane that is defined by a value on the z axis.  In my simple model the data blob is sphere, so that the intersection of the two blobs would result in the outline of a circle. 

    The filter blob will always be defined by a mathematical function.

    My current think is this:

    At the start of the rendering pipeline pass each pixel through a transformation matrix, such that if the x,y,z values of the pixel is not equal to the x,y,z of the filter function, set the z value of the pixel to -1.  Then  go through with the normal rendering process. 

    Is there a way to implement this sort of transformation matrix within the JME API, or do I have to do it with a direct call to openGL?




You can try using ZBuffer to achieve the desired effect:

  1. Render filter object that writes into ZBuffer but not the color buffer.
  2. Render the data object that only renders pixels with ZBuffer values equal to that of the filter object.

      ZBufferState zs = renderer.createZBufferState();
      zs = renderer.createZBufferState();

One problem I see with this approach is: rasterization might produce pixels that will have slightly different ZBuffer values and the equality test will always fail.

If the EQUALITY tests fails, you can use two filters: one upper and one lower. And squeeze the data between two filters in ZBuffer.

  1. render upper filter while writing to zbuffer and not writing to the color buffer
  2. render data with ZBuffer function LESS_EQUAL
  3. render lower filter with ZBuffer function LESS_EQUAL and color of the object equal to the background color

Thanks for your response lex,

I'll give that a go tonight and let you know how I go.


using the stencil buffer seems like a good choice for this…