C# Meshes become transparent when drawn with DrawMeshShaded()

Hey,

I’m texturing a list of meshes via DrawMeshShaded() like this:

    public override void DrawViewportMeshes(IGH_PreviewArgs args)
    {
        for (int i = 0; i < mesh.Count; i++)
        {
            mesh[i].SetTextureCoordinates(textureMapping[i], Transform.Identity, true);
            args.Display.DrawMeshShaded(mesh[i], new Rhino.Display.DisplayMaterial(material[i]));               
        }
    }

In Shaded mode everything works well:

Switching to Rendered makes my custom meshes transparent if they visually intersect with an existing Rhino object (white box). This only happens if shadows are on, though. While this is true for Rhino geometry, custom meshes remain opaque while visually intersecting with other custom objects (violet box). Also, custom objects don’t cast shadows, while existing Rhino geometry does.

Running the same geometry through a Custom Preview component fixes both issues.

Any idea how to fix this? I’ve found this issue. Could these be related @jeff?

Having researched a bit more about this, it seems, that using the display pipeline is a dead end, and the rendering pipeline should be used instead:

That’s great news, but I’m struggling with finding any examples of how to access the CustomRenderMeshProvider method from GH.

@DavidRutten, @andy could you please shed some light on it?

While trying various approaches, I bumped into the AppendRenderGeometry method. According to the docs it is obsolete now. What replaces it, though?

How to add a GH mesh to the rendering pipeline?

I think it’s not so much a problem of transparency, as the fact that the shadows get drawn on top of your geometry, but without taking into account your geometry.

@andy designed the various render and display pipelines that are involved here and he’ll be able to tell you which ones are ideal for drawing your shapes in. The custom render mesh pipeline is tricky to use from within Grasshopper because I believe it involves registration from the plugin Load event, which you don’t have as a Grasshopper plugin. But again Andy will be able to tell you what, if any, workarounds are available here.

1 Like

Thanks @DavidRutten!

There are a few posts on the forums asking similar questions but none provides a clear solution. It has to be doable from within Grasshopper, because the Custom Preview component doesn’t suffer from this issue. You mentioned it adds meshes to the rendering rather than the display pipeline. Could you elaborate on how this is done, maybe?

Or maybe @andy could?

Or is it just a result of a bug already filed here?

Like I said, that component relies on the Grasshopper plugin registering a custom render mesh provider. You don’t have an RHP associated with your code so you’ll need to solve your issue in some other way.