RealtimeRenderPasses in the ViewCapture

Hey all, what does the RealtimeRenderPasses mean in the ViewCapture? I noticed that the CaptureToBitmap is finished immediately. How do I get the high quality output as if I’m using the render button in the UI? Thanks!

        rhinoscriptsyntax.EnableRedraw(True)
        rhinoscriptsyntax.ViewDisplayMode(viewport_name, "Rendered")
        rhinoscriptsyntax.ShowGrid(viewport_name, show=False)
        rhinoscriptsyntax.ShowGridAxes(viewport_name, show=False)
        rhinoscriptsyntax.ShowWorldAxes(viewport_name, show=False)

        view_capture = Rhino.Display.ViewCapture()
        view_capture.Width = selected_view.ActiveViewport.Size.Width
        view_capture.Height = selected_view.ActiveViewport.Size.Height
        view_capture.ScaleScreenItems = False
        view_capture.DrawAxes = False
        view_capture.DrawGrid = False
        view_capture.DrawGridAxes = False
        view_capture.TransparentBackground = True
        view_capture.RealtimeRenderPasses = rendering_pass
        bitmap = view_capture.CaptureToBitmap(selected_view)
        if bitmap:
            temp_dir = tempfile.gettempdir()
            random_filename = str(uuid.uuid4()) + '.png'
            file_path = os.path.join(temp_dir, random_filename)

            bitmap.Save(file_path, System.Drawing.Imaging.ImageFormat.Png)
            print(file_path)

That is for the case you’re using a viewport mode that is based on the realtime render engine integration. In default Rhino that is Raytraced. So set the viewport display mode to Raytraced and set the RealtimeRenderPasses to the amount of samples you want done. Start with say 50 to get a feel, then bump up to a value you think gives you useable output.

That said, it is IMO best to just not switch any viewport to Raytraced and just use the _Render command instead.

_Render, followed by _SaveRenderWindowAs and CloseRenderWindow.

The reason is that when you use Raytraced then you’ll end most likely up running two Raytraced sessions. With larger scenes that can be detrimental because you’ll get potential resource starvation. Just doing the Render will run just the one session.

Thank you Nathan, is there any example for the python code to invoke these three commands? I’m new to the Rhino scriping world.

Also, is it possible for the render command to render a transparent image?

Yes, just make sure you set in Rendering panel background to transparent.

#! python3
import Rhino

path_to_file = "Generate path file name here"
# Note, create a path to a filename ending in .png when
# you want to save with alpha channel.

Rhino.RhinoApp.RunScript("_Render", True)
Rhino.RhinoApp.RunScript(f'_SaveRenderWindowAs "{path_to_file}" ')
Rhino.RhinoApp.RunScript('_CloseRenderWindow')

Thank you so much! Is there anyway to do this via the script? Also, how can we specify which viewport and what size to render? Is there a documentation for all possible parameters for each command like Renedr?

In the document RenderSettings you can set RenderSettings.TransparentBackground Property , RenderSettings.ImageSize Property and RenderSettings.RenderSource Property.

RenderSettings can be accessed on an instance of a document via RhinoDoc.RenderSettings Property

Set these in Python before you run the macro commands with RunScript.

The links provided here should also show you where to find more about the RhinoCommon API, which can be used from Python fully.

That works:

        settings = self.document.RenderSettings
        active_viewport = selected_view.ActiveViewport
        settings.ImageSize = System.Drawing.Size(active_viewport.Size.Width,
                                                 active_viewport.Size.Height)
        settings.TransparentBackground = True
        settings.SpecificViewport = viewport_name

Thank you so much!

Hmmm I might have missed this, where can you specify the rendering pass in render settings? Thanks!

Currently the only way to set samples is via predefined RenderSettings.AntialiasLevel Property

This is in the GUI the quality dropdown

image