See picture through surface material

I’m creating some surfaces in a grasshopper preview that are somewhat transparent.

Rhino.Display.DisplayMaterial dm = new Rhino.Display.DisplayMaterial(color, transparency);
args.Display.DrawBrepShaded(brep, dm);

For looking through the surface and seeing CAD objects this is fine. However, one of my users wants to see a background picture that he has inserted, and no matter the transparency value of view mode this is always blocked by my preview brep.

However, if in Rhino I create a surface then apply a glass material to it and set Rhino to render mode I can see the picture through the surface. How do I create my own ‘glass’ materials for previewing purposes?

HI @hugh_groves,

Sorry I missed this. What conduit channel are you drawing your shaded Brep in? Do you have some sample code, that you can share, that demonstrates the problem you are trying to solve?

– Dale

Hi @dale thanks for the response. I’m using grasshopper previews to draw my breps. The sample code is very simple:

args.Display.DrawBrepShaded(b, colour);

where b is a brep, and colour is a Rhino.Display.DisplayMaterial with a transparency of 0.3

Hi @hugh_groves,

Since I don’t know anything about the display conduit used by Grasshopper, I’ve moved this issue to the Grasshopper Developer category.

@jeff, any ideas on this?

– Dale

This is an order problem… Transparency is nothing more than an “effect” that tricks humans into thinking they’re seeing something that is “see through”…nothing more.

The effect is achieved by blending pixel colors with other pixel colors by some percentage amount. However, if MUST make sure that certain pixels exist in a very specific order, otherwise the effect will be lost.

That being said… The way Rhino achieves the transparent effect is that it first draws ALL objects that don’t have any kind of transparent effect… It then sorts all remaining objects by distance from the camera/eye from furthest to closest (known as “The Painter’s Algorithm”). It then draws those objects and performs a blend between their pixels and the pixels that exist prior to drawing them. The end result is that some objects “appear” to be behind other objects…but all it really is, is a bunch of pixels with certain color values…there is no such thing as “transparency” to a computer.

Given that, since Rhino’s pipeline draws all “transparent based” objects last, any object that gets drawn after that will “wreck” the effect… And any transparent objects drawn before they’re supposed to, will most likely lose their transparent effect.

Sorry for being long winded here…but it’s important that you understand the “why” behind what I’m about to say next…

The only way plugins and 3rd party code can come close to getting their objects to appear transparent is to make sure that they draw their transparent objects after Rhino has completed drawing all objects…and currently the only way to do that is to make sure the drawing is done in the PostDrawObjects() channel. If you’re drawing things in any other channel, I’m afraid “transparency” is just not going to work.

So Dale’s question is very relevant and important… What channel are you using to draw your objects? I don’t really know what is meant by “I’m drawing them in GH’s preview”… somewhere you must specify a channel(s) for your conduit…which channel(s) are you including, and which ones are drawing geometry?


Maybe this is a question for David Rutten, I’m just using the API that he has provided (as outlined in the code snippet above).