Viewport "foggy" backround

Hello, We have been toying with setBgGradientColors() to set different background colours and gradients. And this works ok, but it would be cool if we could add a more "fancy" background such as a fog-like background as in Blender.

Is there any way to implement a foggy background with an OpenGL shader or similar? We have both vertex- and fragment shaders, but we were not able to find how to set this for the entire scene, only single AIS objects.

It's worth noticing that we are using a minimal setup from this blog post: https://unlimited3d.wordpress.com/2021/10/13/occt-viewer-and-qopenglwidget/

Kirill Gavrilov's picture

it would be cool if we could add a more "fancy" background such as a fog-like background as in Blender

As not all users of this forum familiar with Blender, it would be handy attaching screenshot with such background for clarity.

We have both vertex- and fragment shaders, but we were not able to find how to set this for the entire scene, only single AIS objects.

There no API (yet) to set shaders for rendering background itself. If you have something simple - you may consider drawing background as static 2D image. You may also draw a 2D rectangle (Graphic3d_TMF_2d transform-persistence mode) as AIS object within Graphic3d_ZLayerId_BotOSD layer and deactivated selection to define your background using custom GLSL programs.

Dan Bentzen's picture

Thank you for your answer Kirill. Sorry about that. A screenshot is now added. I also added a screenshot from Cascade studio, where they have used a "fog-shader" unfortunately it does look like the webGL API is quite different.

I would like to add some more motivation to this: when trying to make a grid appear "infinite" the foggy background makes the grid fade out. Unfortunately, I do not think that using a static image will since the shader needs to be a function of the distance to the camera. The last solution could work. Would you mind telling me what the purpose of Graphic3d_ZLayer is?

Kirill Gavrilov's picture

Graphic3d_ZLayer alters the order and some rendering properties (depth buffer) of object. By default, 3D objects are rendered in Graphic3d_ZLayerId_Default layer. Graphic3d_ZLayerId_BotOSD would put object behind normal 3D objects. See also a property AIS_InteractiveObject::ZLayer() / ::SetZLayer().