DrawBrepShaded rendering artifacts in DisplayConduit
Description
I’m experiencing a rendering issue with DisplayPipeline.DrawBrepShaded() in a custom DisplayConduit. When I render a Brep in the conduit’s preview, the rendered result appears incorrect - some parts are missing while other parts seem duplicated or misplaced. However, the same Brep renders perfectly fine when added to the Rhino document using doc.Objects.AddBrep().
Expected Behavior
The Brep should render correctly in the DisplayConduit preview, matching how it appears when added to the document.
Actual Behavior
The Brep renders with visual artifacts:
- Some surfaces are missing
- Some areas appear duplicated or rendered in wrong positions
- The overall geometry looks corrupted in the preview
Steps to Reproduce
- Create a Brep (in my case, a flanging/offset geometry from Brep edges)
- Enable a custom DisplayConduit that renders the Brep using
DrawBrepShaded() - Observe the incorrect rendering in the conduit preview
- Add the same Brep to document - it displays correctly
Code Sample
DisplayConduit Implementation
public class FlangingDisplayer : DisplayConduit
{
public List<FlangingItem> Items { get; set; } = [];
protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e)
{
if (Items.Count == 0)
{
return;
}
foreach (var item in Items)
{
if (item.Parent != null)
{
e.IncludeBoundingBox(item.Parent.GetBoundingBox(false));
}
}
}
protected override void DrawForeground(DrawEventArgs e)
{
if (Items.Count == 0)
{
return;
}
foreach (var item in Items)
{
item.Preview(e.Display);
}
}
}
Preview Method
public void Preview(DisplayPipeline pipeline)
{
if (Flangings.Count > 0)
{
foreach (var brep in Flangings)
{
if (brep == null)
{
continue;
}
pipeline.DrawBrepShaded(brep, SurfaceRenderConfig.PreviewMaterial);
pipeline.DrawBrepWires(brep, Color.DarkGreen, 2);
}
}
}
Material Configuration
public static SurfaceRenderConfig Preview { get; } = new SurfaceRenderConfig
{
Diffuse = Color.FromArgb(100, 200, 100),
BackDiffuse = Color.FromArgb(100, 200, 100),
Specular = Color.White,
BackSpecular = Color.White,
Shine = 0.4,
BackShine = 0.4,
Transparency = 0.5,
BackTransparency = 0.5,
IsTwoSided = true
};
public DisplayMaterial DefaultDisplayMaterial
{
get
{
var material = new DisplayMaterial
{
Diffuse = Diffuse,
BackDiffuse = BackDiffuse,
Specular = Specular,
BackSpecular = BackSpecular,
Emission = Emission,
BackEmission = BackEmission,
Shine = Shine,
BackShine = BackShine,
Transparency = Transparency,
BackTransparency = BackTransparency,
IsTwoSided = IsTwoSided
};
return material;
}
}
Observations
- The wireframe rendering (
DrawBrepWires) appears correct - Only the shaded rendering (
DrawBrepShaded) has issues - The Brep validates as correct (can be added to document without issues)
- The problem occurs in
DrawForegroundoverride of DisplayConduit - The bounding box calculation seems correct
- The problem seems related to rendering, not the geometry itself
Questions
- Does
DrawBrepShadedrequire the Brep to be in a specific state when called from DisplayConduit? - Is there a render mesh preparation step I’m missing before calling
DrawBrepShaded? - Could the transparency setting (0.5) be causing Z-fighting or depth sorting issues in the conduit?
- Should I call any Brep preparation methods before rendering (e.g.,
Brep.Compact(),CreateMeshes())? - Is
DrawForegroundthe correct override to use for drawing shaded Breps, or should I use a different event?
Environment
- Rhino Version: [Your Version]
- RhinoCommon SDK Version: [Your Version]
- Operating System: [Your OS]
Screenshots
The normal display should look like this.
Additional Information
I’m implementing a custom preview for an edge flanging operation. The Brep is generated from offset edge curves and appears geometrically valid. The DisplayConduit is enabled during command execution to show real-time preview of the operation result. Any insights into what might cause this rendering discrepancy would be greatly appreciated.





