1

I got a project to draw a hole(transparent cube) on a wall, but the hole could be any shape and any size, and maybe out of the wall. And I'm tried to use blend to override the existing wall, absolutely, this could not work correctly.

In the project, the walls are drawn with instancing method DrawArraysInstanced, and the transparent cube is drawn with instancing method (this isn't essential, there should be DrawArrays in the future), too. And I tried to use StencilFunc and DepthMask, but could not figure out how to do it.

Briefly, Is there an approach to draw rectangles by instancing and then cut small rectangles on some rectangles (I mean some instanced rectangle have a window)? Noticed that the shape that cut rectangles could be any size and type.

Any advice and suggestions would be greatly appreciated, and If the question is not clear, please let me know.

Edit: I know the practical way is to calculate the shape intersection to get the triangles and using DrawArraysInstanced to draw the triangles with those object that cutted holes, but I just want to know If there is a tricky way to make it work.

Tokenyet
  • 4,063
  • 2
  • 27
  • 43
  • 1
    Possible duplicate of [I have an OpenGL Tessellated Sphere and I want to cut a cylindrical hole in it](https://stackoverflow.com/questions/3963957/i-have-an-opengl-tessellated-sphere-and-i-want-to-cut-a-cylindrical-hole-in-it) – Spektre Sep 18 '17 at 13:59
  • Looks duplicated, but I'm seeking is there a solution for instancing. Maybe there is no solution for instancing with Stencil. And I'm not gonna using CSG, becasue the language I used is not supported. – Tokenyet Sep 18 '17 at 14:09
  • If your hole/cut is well defined you could try to do it procedurily inside shaders. Another option is to use volumetric rendering. But without any specific info we can only guess ... – Spektre Sep 18 '17 at 14:15
  • @Spektre, do you mean use the texture that predefined and do it in shader? I'm going to this way if there is no other solution for instancing, and I need to change my restriction to predifined shape. Volumetric rendering seems to be too complex for me... – Tokenyet Sep 18 '17 at 14:26
  • Volumetric rendering is simple but very demanding on memory and computation power. – Spektre Sep 18 '17 at 14:30
  • I just recently answered a similar question: https://computergraphics.stackexchange.com/questions/5301/honouring-depth-test-with-stencil-test/5608#5608 – Andreas Sep 18 '17 at 17:03

0 Answers0