DisplayPipeline.DrawMeshShaded does not considers lights

Hi,
I do have an issue with a display conduit, I am not sure if I am doing something wrong. When I use DrawMeshShaded the rendered mesh is flat and does not seem to consider the lights that are in the model. Do I need to manually add something? For reference this is what I get:

and I would like it to be somewhat shaded better. Are there any options for me to support some simple light shading?

Thanks a lot,
Alberto

Hi @Alberto,

What channel are you drawing your shaded mesh in? Any code you can share might be helpful.

– Dale

Hi @dale

this is the code of my conduit, it is pretty simple actually. I tried both pre and post draw but I got the same result.

    protected override void PreDrawObjects(DrawEventArgs e)
    {
    
      var display = e.Display;
      foreach (var item in PreviewMeshes) {
          var mesh = item.Value;

          display.DrawMeshShaded(mesh.TheMesh,
                                 mesh.TheMaterial == null ?
                                 new DisplayMaterial(color) :
                                 mesh.TheDisplayMaterial);
        }
      }
    }

Let me know if there is anything that can help

Alberto

Hi @Alberto,

Sorry, I should have also asked what display mode you are drawing into.

The only mode that uses model lights is the Rendered mode. All other lights and their types come from the display mode (if it’s a “shaded” mode). So this can play into what you are seeing.

– Dale

Cool, understood. If I switch to rendered mode then I see the model lit properly.

Another question, is there a way that I can force a simple light calculation within the shaded mode? As the users would like to see something that does not look that flat, but rather something that looks similar to what meshes look like in shaded.

Thanks a lot,
Alberto

Hi Alberto,

If you’re already in a “Shaded” mode, then light calculations should be getting done. If they’re not, then either there is a bug, or you’re not drawing your meshes at the correct time within the pipeline.

Rhino’s display pipeline is driven by Display Mode Attributes, which get defined and set within the Display Mode Settings (Options->View->Display modes->[MODE]). There really isn’t any special processing made from one mode to the next… The only difference between each display mode, is that each one has specific settings that are set or unset compared to other modes.

For example: The only “main” difference between “Rendered” mode and “Shaded” mode, is that:

Render Mode has:

  • “Color & material usage” set to “Rendering material”…which means use the materials assigned from the Material Editor/Library when shading…
  • “Lighting method” set to “Scene lighting”…which means “Use the lights found in the scene/model to shade objects”

Shaded Mode has:

  • “Color & material usage” set to “Custom material for all objects”, which you can drill down (“Customize…” button) and see how that’s configured.
  • “Lighting method” is set to “Custom lighting”, which you can also drill down and see the lighting definitions (3 Directional lights).

So there’s really nothing different being done (internally) between the two modes…it’s just that each mode tells the pipeline where to get its information, and what that information contains will determine the final results.

Given that, if you’re drawing your meshes in the proper place within the pipeline, then your objects should “shade” exactly the same way all other Rhino objects are being shaded…if you’re in Rendered mode, then your objects should shade according to the lights within the scene. If you’re in Shaded mode, then your objects should shade according to the customized lights defined in the Shaded mode settings… The bottom line is that your objects should appear and shade the same as all/any other objects in the scene, according to whatever the current display mode is.

However, if you’re trying to draw shaded meshes in a Wireframe mode, then you need to make some minor changes… Wireframe modes have their “Lighting method” set to “Default lighting”…which for “wireframe” means “No lights at all”… If you want your meshes to shade in Wireframe, using the lights in your scene, then you need to set the “Wireframe” mode’s “Lighting method” to “Scene lighting” (just like Rendered mode does)… If you want your own custom lighting, then you should set the lighting method to “Custom lighting” and define the light(s) accordingly.

Most of the time when a plugin requires specific display modes settings to be made, the plugin defines and installs its own set of display attributes and display mode name(s) (i.e. “Albertos Mode1”, “Albertos Mode2”, etc…etc…), then the plugin can set the display mode to one of its desired modes, rather than require or expect the users to make the appropriate settings to the appropriate modes.

So having said all of that… Are you still having a problem getting your meshes to shade in a “Shaded” mode? And by “shaded”, I don’t necessarily mean Rhino’s “Shaded” mode, I mean any mode that requires shading of mesh objects… If you are, then I’d like to see your plugin code (or small example program that demonstrates the problem)…and I can then make the appropriate tweaks to get things working… If I wrote an example program here, I’m pretty sure it would work as I’d expect :wink: … So I really need to see what it is you’re doing…the small snippets of code aren’t enough… I want something I can compile, install and run.

Thanks,
-Jeff

Hi Jeff,
thanks for the clarification. Most of the things that we do are inside of display conduits, I am not sure then when you talk about the proper place in the pipeline which one of this is. At the moment I tried both Predrawobject and postdrawobjects and I do not get the proper shading of the mesh (in “shaded” mode, in "rendered mode I do).

Can you clarify what you mean with proper place what do you mean?

Thanks a lot
Alberto

Hi Alberto,

It sounds like you’ve got things happening in the correct place if Rendered mode is working, so this may be a bug in Rhino…but again, I’d a simple test case that demonstrates the problem…and I can debug and step through Rhino’s core to see what’s happening (or not happening)…

Thanks,
-Jeff