DrawGroup & DrawOp

 



Introduction

DrawGroup and DrawOp allows to influence some low level rendering modes. Especially using custom blendmodes several blended layered effects are possible.

 

Nodes

DrawGroup

EXTERNPROTO definitions

EXTERNPROTO DrawGroup[
	exposedField SFVec3f bboxSize
	exposedField SFVec3f bboxCenter
	exposedField SFBool sortedAlpha       # if false geometry with transparent Materials/Textures are drawn in-place
	exposedField MFNode drawOp
	exposedField MFNode children          # contains normal children intermixed with DrawOp nodes
	eventIn MFNode addChildren
	eventIn MFNode removeChildren
	]
["urn:inet:bitmanagement.de:node:DrawGroup","http://www.bitmanagement.de/vrml/protos/nodes.wrl#DrawGroup","nodes.wrl#DrawGroup"]
EXTERNPROTO DrawOp[ exposedField MFInt32 op # [ opcode1 argument1 opcode2 argument2 ] exposedField MFFloat args # used for some ops if float arguments are required ] ["urn:inet:bitmanagement.de:node:DrawOp","http://www.bitmanagement.de/vrml/protos/nodes.wrl#DrawOp","nodes.wrl#DrawOp"]
The field op contains pairs <opcode> <value>
Op code value Name value type remark  
0 ZEnable boolean zbuffer check on/off  
1 ZWriteEnable Boolean z buffer write on/off  
2 ZFunc CMPFUNC z-buffer comparison function GL-Info
3 AlphaTest Boolean alpha testing on/off  
4 AlphaFunc CMPFUNC alpha test function GL-Info
5 AlphaRef 0..255 the comparison value for alpha testing  
6 BlendEnable Boolean turn (alpha) blending on/off  
7 SrcBlend BLENDFUNC set the src blend function, default BLEND_SRCALPHA GL-Info
8 DestBlend BLENDFUNC set the dest blend function, default BLEND_INVSRCALPHA  
9 AlphaBlend   not needed  
10 ZBias float shift z-buffer pixels  
11 MipMapLodBias float shift texture mip-levels  
12 UseAppearance Boolean use VRML appearance node in children  
13 UseTextures Boolean " textures  
14 UseLights Boolean " lights  
15 BackfaceCulling Boolean note: set by Geometry nodes implicit (ccw, solid fields)  
16 FrontFaceCW Boolean    
17 RenderMode int switch wireframe solid ..rendering  
18 MipMapEnable Boolean turn mip-mapping on (note: mip-maps are computed at texture load time only)  
19 TextureAnsiotropy int 1..16, texture anisotropic texture filtering  
20 AutoMipMap Boolean turn on auto mip-map generation for textures  
21 AutoMipMapDynamic Boolean automip-map for movie textures (dynamic textures)  
22 TextureCompression Boolean use texture compression for newly created textures  
23 LocalViewer Boolean switch local viewer lighting (0 is faster)  
24 TwosidedLighting Boolean switch twosided lighting note: set by Geometry nodes implicit (ccw, solid fields)  
25 Normalize Boolean normalize normals (0 is faster)  
26 Dither Boolean dithering flag for 16-Bit color rendering  
27 FillMode FILLMODE filling mode for triangles  
28 ShadeMode SHADEMODE shading mode  
29 FogEnable bool    
30 AlphaFactor 0..255 alpha scale value for all colors  
31 LightEnable boolean    
32 LastPixel boolean   DX7 only
33 SetSpecular boolean enable/disable specular lighting  
34 ViewCulling boolean do view frustum culling checks  
35 OcclusionCulling boolean use OcclusionCulling  
36 OcclusionCullingGeometry boolean use OcclusionCulling at geometry level  
37 OcclusionVisiblePixels int number of visible pixel allowed for culling objects  
38 OcclusionVertexLimit int min vertex count for doing OcclusionCullingGeometry  
39 LODScale float (from args) scale factor apply to LOD node distances  
40 TraversalOrder int    
41 SetClipPlane int index, 4 float plane (from args)

defines the parameters for clipplane with index (index usually 0 up to 5)

4 Plane parameters A*X + B*Y+C*Y + D = 0 are consumed from the float parameters

GL-Info
42 SetClipPlaneMask int

mask of planes: bit set plane enabled.

Ie the value is 1 for enabling clipplane 0 only, the value is 3 for enabling plane 0 and 1

use value 0 to disable all clipplanes.

 
ATI OpenGL NPatch codes     Only for OpenGL with ATI N-Patch extension  
43 NPatchEnable boolean use ATI NPatches  
44 NPatchPosCubic boolean use cubic position interpolation, false linear  
45 NPatchNormQuadric boolean use quadric normal interpolation, false linear  
46 NPatchLevel int 0.. max subdivision level  
47 NPatchAutoLOD boolean use auto LOD  
48 NPatchLODMaxLevel int 0.. max subdivision level  
         
49 Clear uint integer mask of rendering buffers to clear  
50 ColorWrite uint mask, enabled RGBA planes of color buffer (not in DX7)
  Stencil functions      
51 StencilEnable boolean enable/disable stencil test function  
52 StencilFunc CMPFUNC stencil test function GL-Info
53 StencilRef int stencil test/write reference value  
54 StencilMask uint additional test and mask  
55 StencilOpFail STENCILOP stencil action when the stencil test fails GL-Info
56 StencilOpZFail STENCILOP stencil action when the stencil test passes, but the depth test fails.  
57 StencilOpPass STENCILOP stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled  
58 StencilWriteMask uint bitmask controling the writing of individual bits in the stencil planes GL-Info
59 StencilClear uint specify the clear value for the stencil buffer GL-Info
  Separate Alpha Blend      
60 AlphaSrcBlend BLENDFUNC separate alpha blending op GL-Info(GL Extension )
61 AlphaDestBlend BLENDFUNC    
62 BlendOp BLENDOP   GL-Info
63 BlendColor int 0, 4 float values RGBA value Blend Op extra operand GL-Info
         
64 PolygonOffset 2 float factor & offset GL-Info
65 PolygonOffsetFill boolean    
66 PolygonOffsetLine boolean    
67 PolygonOffsetPoint boolean    
69 VertexColor int 0, 4 float values RGBA value

set the color for point rendering

 
70 NormalColor int 0, 4 float values RGBA value

set the color for normal rendering

 
71 EdgeColor int 0, 4 float values RGBA value

set the color for edge rendering

 
72 SilhouetteEdgeColor int 0, 4 float values RGBA value

set the color for silhouette edge rendering

 
73 FaceColor int 0, 4 float values RGBA value

set the color for face rendering

 
74 BBoxColor int 0, 4 float values RGBA value

set the line color for bounding box rendering

 
76 DepthBiasSloped 2 float
bias, slopedBias
Shifts the z-values of pixels back, (DirectX9 only)  
 	DrawOp {
		op [
			# DX9 sloped depth bias, shift back 
			76 0
		]
		args [0.001 1.0]
	}
	## render shift back geometry 
 	DrawOp {
		op [
			76 0
		]
		args [0 0]
	}
	# render overlay geometry 
	
 
77 StereoEyeVertDistance float    
78 SilhouetteEdgesEnable bool    
79 SilhouetteEdgesBorderEnable bool    
80 UseCulling bool true:use solid and ccw flags from geometry nodes for backface culling, if false use current value or value from drawOp 15+16  
81 TextureFiltering bool  
82 TextureMagFilter int  
83 TextureMinFilter int  
84 TextureMipFilter int  
85 TextureMaxMipLevel int  
86 TextureMaxAnisotropy int  
87 TextureSRGB int  
88 TextureBorderColor int 0, 4 float values RGBA value  
89 VisibilityLimit float Overwrite the visibility limit ( zfar clipping) to adapt culling distance for geometry  
90 VisibilityLimit Scale float Overwrite the visibility limit as a factor of current visibility limit (e.g. 0.5 for cullilng at half the distance)  
91 FogStart float  
92 FogEnd float  
93 FogDensity float  
94 FogColor int 0, 4 float values RGBA value

set the color for fog

 
95 FogMode int set type of fog mode  
96 BackgroundColor int 0, 4 float values RGBA value the color for clearing the background (clear)  
97 AmbientColor int 0, 4 float values RGBA value the gloabl light ambient color (D3D)  
100 NO OP int no operation  

Argument values for CMPFUNC

CMP_NEVER             = 1
CMP_LESS              = 2
CMP_EQUAL             = 3
CMP_LESSEQUAL         = 4
CMP_GREATER           = 5
CMP_NOTEQUAL          = 6
CMP_GREATEREQUAL      = 7
CMP_ALWAYS            = 8
 

Argument values for FOGMODE

FOG_EXP                 = 1
FOG_EXP2                = 2
FOG_LINEAR              = 3

Argument values for BLENDFUNC
 
BLEND_ZERO            = 1
BLEND_ONE             = 2
BLEND_SRCCOLOR        = 3
BLEND_INVSRCCOLOR     = 4
BLEND_SRCALPHA        = 5
BLEND_INVSRCALPHA     = 6
BLEND_DESTALPHA       = 7
BLEND_INVDESTALPHA    = 8
BLEND_DESTCOLOR       = 9
BLEND_INVDESTCOLOR    = 10
BLEND_SRCALPHASAT     = 11

DX9:
BLEND_BLENDFACTOR     = 14
BLEND_INVBLENDFACTOR  = 15

GL 1.4
BLEND_CONSTCOLOR      = 16
BLEND_INVCONSTCOLOR   = 17
BLEND_CONSTALPHA      = 18   
BLEND_INVCONSTALPHA   = 19

 

Argument values for blend operation function BLENDOP
 BLENDOP_ADD          = 1
 BLENDOP_SUBTRACT     = 2
 BLENDOP_REVSUBTRACT  = 3
 BLENDOP_MIN          = 4
 BLENDOP_MAX          = 5

Argument values for stencil operations STENCILOP
STENCILOP_KEEP        = 1
STENCILOP_ZERO        = 2
STENCILOP_REPLACE     = 3
STENCILOP_INCRSAT     = 4
STENCILOP_DECRSAT     = 5
STENCILOP_INVERT      = 6
STENCILOP_INCR        = 7   (GL: GL_INCR_WRAP_EXT)
STENCILOP_DECR        = 8   (GL: GL_DECR_WRAP_EXT)

Buffer clear mask values (ored together) for clear
CLEAR_TARGET          = 1   Clear target surface (color buffer)
CLEAR_ZBUFFER         = 2   Clear target z buffer
CLEAR_STENCIL         = 4   Clear stencil planes
CLEAR_ACCUML          = 8   Clear ACCUM buffer (GL only)

Color write mask values (ored together)
COLORWRITE_RED        = 1
COLORWRITE_GREEN      = 2
COLORWRITE_BLUE       = 4
COLORWRITE_ALPHA      = 8
 

Shade mode
SHADE_FLAT            = 1,
SHADE_GOURAUD         = 2,

Fill mode
FILL_POINT            = 1,
FILL_WIREFRAME        = 2,
FILL_SOLID            = 3,

Render mode
Vertices              = 0,
BoundingBoxes         = 1,
Wireframe             = 2,
Solid                 = 3,
NonLighted            = 4,
Flat                  = 5,
Gouraud               = 6,
HiddenLine            = 9,

Example :

DrawGroup {
    sortedAlpha FALSE

    children [

        # path 1
        DEF THE-OBJECT Shape {  ... }

        # path 2
        DrawOp {
            op [
                2  4   # Z test le-equal
                6  1   # blend enable
                7  2   # src blend mode
                8  2   # dst blend mode
            ]
        }

        USE THE-OBJECT

        # undo draw-op
        DrawOp {
            op [
                ##1  0
                2  2   # Z test less
                6  0   # blend enable
                7  5   # src blend mode (default)
                8  6   # dst blend mode
            ]
        }
    ]
}



 

Instead of using MultiTexturing, geometry can be drawn in multiple pathes using different rendering attributes.

The drawback is that geometry is drawn several times. The benefit is that an arbitrary number of effects can be combined and the feature will work on all graphics boards. Multipath rendering can also be used to use the output of radiosity programs to combine it with the basic unlighted textured scene.

Examples:

3 Texture are blended together : ifs_multipath.wrl

Effect of tunnel_detailtex achieved with multipath rendering: tunnel_detailtex_multipath.wrl

 

Example using the Stencil buffer in OpenGL: stencil_test.wrl

An circle is drawn to the stencil buffer, but not the color buffer. The rendering of a cube later is limited to pixels with a stencil bits equalsl 1. (Need OpenGL with stencil format enabled. Set Preferences->OpenGL stencil bits to 8., in DirectX9 choose a backbuffer format with Stencil support.)

Example using clipping planes: clipplane-test.wrl clipplane-test2.wrl

An one sided sphere drawn, but the geometry is clipped to a plane specified in normal form A*X + B*Y+C*Y + D = 0. Graphics drivers usually support up to 6 custom clipping planes.

Example using DepthBiasSloped: depthBiasSloped.wrl

Example using 16 directional lights by using blending mode add and multipath rendering: MultiLightBlend.wrl

Limit the visibility and fog range of a local group:

#limit visibility 
DrawGroup  {
	restoreOp TRUE
	sortedAlpha	FALSE

	children [
		DrawOp { op[
					89 0 ## VisibilityLimit 

					# adapted local fog
					91 0 # FogStart
					92 0 # FogEnd
					94 0 # FogColor

				]
				args [ 300 # new limit 
					   150 # new fog start 
					   280 # new fog end 
					   0.7 0.5 0.5 1 # new fog color 
				] 
			} 

		DEF RootObj1 Group { 
		    children [ ... ]
		} 
	]		
}