3D Tutorial: Changing Render Modes

This step reviews how to use and switch between common 3D render modes.

 

 

The HOOPS/MVO HBaseView class provides a utility function called SetRenderMode() which modifies the visual aspects of how the scene is drawn. Valid modes are listed in the enum type HRenderMode.

 

Setting Common Render Modes

 

Wireframe

This mode is set by calling HBaseView::SetRenderMode(HRenderWireframe). Only 'wires' (which include HOOPS/3dGS 'edges' and 'lines') will get drawn. The AppWizard-generated app already has a toggle for this mode.

Gouraud

This mode is set by calling HBaseView::SetRenderMode(HRenderGouraud). The faces of any appropriate HOOPS/3dGS geometry will get drawn using a smooth (gouraud) shading technique. The AppWizard-generated app already has a toggle for this mode.

Hidden Line Removal

This mode is set by calling HBaseView::SetRenderMode(HRenderHiddenLine) and enables an analytic HLR algorithm. Only visible parts of edges/lines will be displayed; any visible faces will be used to 'hide' the lines. (See Section 6.1.3 of the HOOPS/3dGS Programming Guide for more info). The AppWizard-generated app already has a toggle for this mode

Phong Shading

This mode is set by calling HBaseView::SetRenderMode(HRenderPhong). The faces of any appropriate HOOPS/3dGS geometry will get drawn using a phong-lighting technique. We could extend the application to add support for this render mode, but there is a better alternative discussed in the next section.

 

Advanced Render Modes

HRenderShaded

We saw how to set both phong and gouraud shading above. Gouraud shading is commonly accerlerated by 3D hardware, but phong is not. However, HOOPS/3dGS can actually take advantage of 3d hardware texturing capabilities to effectively produce hardware-accelerated phong-lit scenes. This involves making direct HOOPS/3dGS calls to check the driver's capabilites, but MVO has a setting that does this cheching for you. If you just set the rendermode to HRenderShaded, MVO will tell HOOPS/3dGS to perform phong lighting if it can be HW-accelerated, otherwise it will tell HOOPS to use gouraud lighting.

Let's modify the Spheres application to replace the 'gouraud' render mode toggle with the 'shaded' render mode. You can generally do a search for instances of the word 'phong' and remove that word (leaving just 'shaded'). We'll also set the initial render mode to 'Shaded'.We do this be replacing the call to RenderGouraud() with a call to RenderShaded() inside of CSpheresView::OnInitialUpdate() :


After you're done, run the app and try to discern whether HOOPS is performing phong lighting. If the sphere contains a noticeable, bright specular highlight, it means that HOOPS is performing phong lighting by using graphics hardware acceleration. It is a personal preference whether you want to always use 'gouraud' shading in your app, or whether you want your to use the 'shaded' mode and have HOOPS try and perform hardware phong lighting. Phong lighting will make surfaces looked more

 

HRenderHiddenLineFast

This setting tells HOOPS to perform a more optimized HLR calculation than the 'regular' HLR setting discussed above. The 'fast' algorithm is only available if a 3d driver is being used. As mentioned in hidden surfaces section of the HOOPS/3dGS Programming Guide, a way to combine the use of the two algorithms would be to use the fast algorithm for visual display, but use the more accurate analytic algorithm for hardcopy output.

Let's modify the application to use HRenderHiddenLineFast instead of HRenderHiddenLine:

{
m_pHView->SetRenderMode(HRenderHiddenLineFast, true);
}
 

While we're at it, let's take a look at the HLR options available to us in the documentation for hlro suboption in Set_Rendering_Options, and modify them. We'll make the hidden-lines visible and change their color and pattern. We should do this in HSpheresView::Init():

{
.
.
HC_Set_Rendering_Options("hlro = (visibility = on, pattern = 4)");
.
.
}

 

Customizing Render Modes

Recalling that the HBaseView class serves as wrapper for the top level 'driver instance' segment, the HBaseView::SetRenderMode method described above essentially acts as a 'macro' that sets several attributes on that segment. The attributes that are set when calling SetRenderMode include:

 

For example, if we look at the source code that gets executed when the render mode is set to 'HRenderFlat' (looking at the source to HBaseView::SetRenderMode() in the MVO source) we can see that:

This gives us a flat-shaded scene that is properly hidden surfaced removed using the best HSR algorithm available, and shell/mesh/polygon edges won't be visible. But what if you want to see the 'edges'? Or perhaps you don't want to modify the edge visibility at all (and leave the Visibility attribute alone, simply letting it inherit from above). You could do this by overloading HBaseView::SetRenderMode so that it calls the base class and then sets or unsets attributes as you desire.