Faking X-Ray rendering
RenderSettings_t RS = viewer.GetSettings (); if (enable) { RS.stateOverrides |= (CSG_OVERRIDE_MATERIAL | CSG_OVERRIDE_SHADER); glBlendFunc(GL_CONSTANT_ALPHA_EXT, GL_ONE); glBlendColorEXT(0.1, 0.1, 0.1, 0.1); glEnable (GL_BLEND); glDisable (GL_DEPTH_TEST); } else { RS.stateOverrides &= ~(CSG_OVERRIDE_MATERIAL | CSG_OVERRIDE_SHADER); glDisable (GL_BLEND); glEnable (GL_DEPTH_TEST); } viewer.AssignSettings (RS); There are two keys to create an x-ray effect: Enable additive blending and disable the depth test. glBlendColor() eliminates the necessity to provide blending weights via alpha values by specifying fixed blending weights. The glBlendFunc() directs OpenGL to use the blend colors alpha value for scaling all incoming color values (GL_CONSTANT_ALPHA_EXT) before adding them to what already is in the frame buffer (taken as is since the destination factor is set to GL_ONE).
Using GL_CONSTANT_ALPHA_EXT will take the blend colors alpha value for all color components, the blend colors rgb values are left unused. The value of 0.1 is chosen arbitrarily and determines how many polygons can be blended together before reaching the maximum intensity of 1.0. Since incoming colors are only scaled and added to the framebuffer, lighting calculations remain active. You will still see some geometry curves caused by lighting effects. The state overrides is a tinySG traverser render state setting, instructing the traverser to start traversal with flags to skip all material and shader nodes it encounters. This will keep material settings constant for all geometry in the scene and use a grey default material for all geometry.
Keep rendering,
Copyright by Christian Marten, 2012 Last change: 09.03.2012 |