← Users | Developers → | |||||||||||||||||||
Intro | News | view3dscene | The Castle | All Programs | Forum | Donate | Engine | VRML/X3D | Blender |
Screen EffectsContents: 1. IntroScreen effects allow you to create nice effects by processing the rendered image. Demos:
2. DefinitionYou can define your own screen effects by using the ScreenEffect node in your VRML/X3D files. Inside the ScreenEffect node you provide your own shader code to process the screen, given the current color and depth buffer contents. With the power of GLSL shading language, your possibilities are endless :). You can warp the view, apply textures in screen-space, do edge detection, color operations and so on. ScreenEffect : X3DChildNode { SFNode [in,out] metadata NULL # [X3DMetadataObject] SFBool [in,out] enabled TRUE SFBool [in,out] needsDepth FALSE MFNode [in,out] shaders [] # [X3DShaderNode] } A ScreenEffect is active if it's a part of normal VRML/X3D transformation hierarchy (in normal words: it's not inside a disabled child of the Switch node or such) and when the "enabled" field is TRUE. In the simple cases, you usually just add ScreenEffect node anywhere at the top level of your VRML/X3D file. If you use many ScreenEffect nodes, then their order matters: they process the rendered screen in the given order. You have to specify a shader to process the rendered screen by the "shaders" field. This works exactly like the standard X3D "Appearance.shaders", by selecting a first supported shader. Right now our engine supports only GLSL (OpenGL shading language) shaders inside ComposedShader nodes, see the general overview of shaders support in our engine and X3D "Programmable shaders component" specification and of course the GLSL documentation. The shader inside ScreenEffect is always linked with a library of useful GLSL functions:.
3. ExamplesA simplest example: ScreenEffect { shaders ComposedShader { language "GLSL" parts ShaderPart { type "FRAGMENT" url "data:text/plain, ivec2 screen_position(); vec4 screen_get_color(ivec2 position); void main (void) { gl_FragColor = screen_get_color(screen_position()); } " } } } The above example processes the screen without making any changes. You now have the full power of GLSL to modify it to make any changes to colors, sampled positions and such. For example make colors two times smaller (darker) by just dividing by 2.0: ivec2 screen_position(); vec4 screen_get_color(ivec2 position); void main (void) { gl_FragColor = screen_get_color(screen_position()) / 2.0; } Or turn the screen upside-down by changing the 2nd texture coordinate: ivec2 screen_position(); vec4 screen_get_color(ivec2 position); int screen_x(); int screen_y(); void main (void) { gl_FragColor = screen_get_color( ivec2(screen_x(), screen_height - screen_y())); } 4. DetailsDetails about special functions available in the ScreenEffect shader:
5. TodosScreenEffect under a dynamic Switch doesn't react properly — changing "Switch.whichChoice" doesn't deactivate the old effect, and doesn't activate the new effect. For now, do not place ScreenEffect under Switch that can change during the world life. If you want to (de)activate the shader dynamically (based on some events in your world), you can send events to the exposed "enabled" field. |