Extensible 3D (X3D)
Part 1: Architecture and base components

Annex X


OpenGL Shading Language

--- X3D separator bar ---

cube 1 General

This annex defines how a browser implementing the Shader component maps the concepts of the OpenGL Shading Language to the Shading Component. It applies to the ComposedShader node that sets the language field to "GLSL".

cube 2 Topics

Table 1 provides links to the major topics in this annex.

Table 1 — Topics

cube 3 Interaction with Other Nodes and Components

3.1 Vertex Shader

The vertex shader replaces the fixed functionality of the vertex processor. The OpenGL specification states that the following functionality is disabled if a vertex shader is supplied:

3.2 Fragment Shader

The fragment shader replaces the fixed functionality of the fragment processor. The OpenGL specification states that the following functionality is disabled if a fragment shader is supplied:

3.3 LoadSensor

The LoadSensor node (See 9.4.3 LoadSensor) has two output fields isActive and isLoaded. The isLoaded field behaviour is unchanged.

The isActive field is defined to issue a TRUE event when the all the following conditions have been satisifed:

The LoadSensor node does not have any interaction with the process of linking multiple shader objects into a complete shader program.

3.4 Vertex Attributes

Each vertex attribute node directly maps the name field to the uniform variable of the same name. If the name is not available as a uniform variable in the provided shader source, the values of the node shall be ignored.

The browser implementation shall automatically assign appropriate internal index values for each attribute

cube 4 Data Type Mapping

4.1 Node fields

Fields that are of type SFNode/MFNode are ignored unless the value is of type X3DTextureNode. Field instances of type X3DTextureNode are mapped according to the appropriate sampler data type. The texture types are mapped as as defined in Table 2

Table 2 — Mapping of X3D texture node types to OpenGL Shading Language Sampler Types

X3D Texture type GLSL Variable Type
X3DTexture2DNode sampler2D
X3DTexture3DNode sampler3D
X3DEnvironmentTextureNode samplerCube

X3D does not define mappings to the OpenGL types sampler1D, sampler1DShadow and sampler2DShadow

4.2 X3D Field types to OpenGL Data Types

Table 3 indicates how the X3D field types shall be mapped to OpenGL data types used in the OpenGL Shading Language.

Table 3 — Mapping of X3D Field type to OpenGL Shading Language Type

X3D Field type GLSL Variable Type
SFBool bool
MFBool bool[]
MFInt32 int[]
SFInt32 int
SFFloat float
MFFloat float[]
SFDouble float
MFDouble float[]
SFTime float
MFTime float[]
SFNode See 4.1 Node Fields
MFNode See 4.1 Node Fields
SFVec2f vec2
MFVec2f vec2[]
SFVec3f vec3
MFVec3f vec3[]
SFVec4f vec4
MFVec4f vec4[]
SFVec3d float3
MFVec3d float3[]
SFVec4d float4
MFVec4d float4[]
SFRotation vec4
MFRotation vec4[]
MFColor vec4[]
SFColor vec4
SFImage int[]
MFImage int[]
SFString Not supported
MFString Not supported
SFMatrix3f mat3
MFMatrix3f mat3[]
SFMatrix4f mat4
MFMatrix4f mat4[]

OpenGL defines maximum supported lengths of each array data type, which may conflict with the minimum support requirements for X3D. OpenGL will automatically convert double precision data types to single precision types.

cube 5 Event Model

5.1 Changing URL fields

When the url receives an event changing the value, the browser shall immediately attempt to download the new source. Upon successful download, the browser shall attempt to compile the new source and issue the appropriate LoadSensor events. It shall not automatically relink the shader program, nor disable the currently running shader. This follows the semantics of the OpenGL API requirements for separate register-compile-link steps.

Values defined at load time of the file, do not require an explicit request to relink. It shall be assumed to automatically link once all the objects have successfully downloaded. If some of the shader source files are not downloaded or compiled (eg due to errors) then no linking will occur for the shader program

5.2 Changing the object field

If at any time after the initial load, the user changes the values of the object field, the user shall need to request an explicit relink of the containing shader program. The containing ComposedShader shall not automatically relink, nor should it automatically disable the current shader.

5.3 Changing the attrib field

Per-vertex attributes may be defined as one of the fields of X3DComposedGeometryNode. These may be changed at runtime by adding or removing node instances. Adding new node instances to the field shall require that the user request an explicit relink in order to make them visible to the shader.

5.4 Relinking Programs

The user may, at any time, request that OpenGL re-link the composing shader objects by sending a TRUE value to the activate inputOnly field of the ComposedShader node. Users may need to force a re-link of the ComposedShader under various circumstances, such as changing the url field of one or more ShaderPart nodes, or adding or removing ShaderPart nodes. Relinking the shader shall replace the existing shader with the new executable.

--- X3D separator bar ---
[ Xj3D Homepage | Xj3D @ Web3d | Screenshots | Dev docs | Dev Releases | Contributors | Getting Started ]
Last updated: $Date: 2004-09-16 19:52:10 $