Post

ShaderProgram

ShaderProgram

Overview

ShaderProgram is contained by ProgramShader and provides the source and interface to a self-contained program that occupies one part of the rendering process: either a vertex or fragment shader.

The ShaderProgram node belongs to the Shaders component and requires at least level 1, its default container field is programs. It is available from X3D version 3.0 or higher.

Hierarchy

1
2
+ X3DNode
  + ShaderProgram (X3DUrlObject, X3DProgrammableShaderObject)*

* Derived from multiple interfaces.

Fields

SFNode [in, out] metadata NULL [X3DMetadataObject]

Information about this node can be contained in a MetadataBoolean, MetadataDouble, MetadataFloat, MetadataInteger, MetadataString or MetadataSet node.

Hint

SFString [in, out] description “”

Author-provided prose that describes intended purpose of the url asset.

Hint

  • Many XML tools substitute XML character references for special characters automatically if needed within an attribute value (such as & for & ampersand character, or " for “ quotation-mark character).

SFString [ ] type “VERTEX” [“VERTEX”|”FRAGMENT”]

type indicates whether this ShaderProgram is a vertex or fragment (pixel) shader.

Warning

  • Do not wrap extra quotation marks around these SFString enumeration values, since “quotation” “marks” are only used for MFString values.

SFBool [in, out] load TRUE

load=true means load immediately, load=false means defer loading or else unload a previously loaded scene.

Hints

  • Allows author to design when Inline loading occurs via user interaction, event chains or scripting.
  • Use a separate LoadSensor node to detect when loading is complete.

MFString [in, out] url [ ] [URI]

Location and filename of shader. Multiple locations are more reliable, and including a Web address lets e-mail attachments work.

Hints

  • Embedded ecmascript: source can also be contained in the sourceCode pseudo-field without escape characters, equivalent to last entry in the url list, when using other API codebases and file encodings.
  • MFString arrays can have multiple values, so separate each individual string by quote marks “https://www.web3d.org” “https://www.web3d.org/about” “etc.”
  • Alternative XML encoding for quotation mark “ is " (which is an example of a character entity).
  • Can replace embedded blank(s) in url queries with %20 for each blank character.
  • X3D Scene Authoring Hints, urls

Warning

  • Strictly match directory and filename capitalization for http links! This is important for portability. Some operating systems are forgiving of capitalization mismatches, but http/https url addresses and paths in Unix-based operating systems are all case sensitive and intolerant of uppercase/lowercase mismatches.

SFTime [in, out] autoRefresh 0 [0,∞)

autoRefresh defines interval in seconds before automatic reload of current url asset is performed.

Hints

  • If preceding file loading fails or load field is false, no refresh is performed.
  • Repeated refresh attempts to reload currently loaded entry of url list. If that fails, the browser retries other entries in the url list.

Warning

  • Automatically reloading content has security considerations and needs to be considered carefully.

SFTime [in, out] autoRefreshTimeLimit 3600 [0,∞)

autoRefreshTimeLimit defines maximum duration that automatic refresh activity can occur.

Hint

  • Automatic refresh is different than query and response timeouts performed by a networking library while sequentially attempting to retrieve addressed content from a url list.

Warning

  • Automatically reloading content has security considerations and needs to be considered carefully.

Advice

Hints

  • ShaderProgram contains field declarations and then corresponding IS/connect statements (if any).
  • Insert an XML Character Data (CDATA) block within the Script node to contain source code embedded within an X3D scene, avoiding the need for escape characters.
  • A contained XML Character Data (CDATA) block for source code protects whitespace, line breaks, and literal characters (such as & for ampersand character, < for less-than-sign character, and > for greater-than-sign character) from unintended escape-character modifications by XML parsers.
  • When parent node is LoadSensor, apply containerField='children' (X3Dv4) or containerField='watchList' (X3Dv3).
  • Embedded ecmascript: source can also be contained in the sourceCode pseudo-field without escape characters, equivalent to last entry in the url list, when using other API codebases and file encodings.

Warning

  • Strict order is required for contained constructs: first field declarations (if any), then IS/connect statements (if any), and finally CDATA source-code block.

See Also

This post is licensed under CC BY 4.0 by the author.