Shader

Shader

Defines vertex and fragment shader and uniforms to shader callbacks


{
vshader: [required] vertex shader source
fshader: [required] fragment shader source
defines : shader definitions (becomes #define)
attributes : attribute bindings
attribute bindings need to map to an attribute in the meshdata being rendered
uniforms : uniform bindings
uniform bindings can be a value (like 2.5 or [1, 2]) or a function
}

Constructor

new Shader(name, shaderDefinition)

Parameters:
Name Type Description
name string

Shader name (mostly for debug/tool use)

shaderDefinition ShaderDefinition

Shader data

Classes

LoadShaderFromFileXHR

Members

attributeIndexMapping :Object.<string, number>

Maps attribute variable's name to attribute location (from getAttribLocation).

attributeMapping :Object.<string, object>

Attributes detected in the shader source code.
Maps attribute variable's name to {format: string}

name :string

The shader name

renderer :WebGLRenderingContext

The renderer where the program and shaders were allocated.

renderQueue :number

Determines the order in which an object is drawn. There are four pre-defined render queues:


  • RenderQueue.BACKGROUND = Rendered before any other objects. Commonly used for skyboxes and the likes
    (0-999)
  • RenderQueue.OPAQUE = Used for most objects, typically opaque geometry. Rendered front to back
    (1000-1999)
  • RenderQueue.TRANSPARENT = For all alpha-blended objects. Rendered back to front (2000-2999)
  • RenderQueue.OVERLAY = For overlay effects like lens-flares etc (3000+)

By default materials use the render queue of the shader. See RenderQueue for more info

textureSlots :Array

Texture slots detected in the shader source code.
Will be an array of {format: string, name: string}

uniformBufferDataBlocks

List of uniform blocks.

uniformCallMapping :Object.<string, ShaderCall>

Maps uniform variable name to ShaderCall object.

uniformMapping :Object.<string, object>

Uniforms detected in the shader source code.
Maps variable name to {format: string}.

Methods

(static) investigateShader(source, target)

Extract shader variable definitions from shader source code.

Parameters:
Name Type Description
source string

The source code.

target Object
Properties
Name Type Description
attributeMapping Object
uniformMapping Object
textureSlots Array

InitializeFromObject(name, shaderDefinition)

Initializes the shader using shader definition and shader name
Moved to its own init function in case of loading from file and deferring the initialization

Parameters:
Name Type Description
name string

Shader name (mostly for debug/tool use) or contains the name of shader file if a file is given
if file is given then make sure .glsl is given in name

shaderDefinition ShaderDefinition

Shader data


{
vshader: [required] vertex shader source
fshader: [required] fragment shader source
defines : shader definitions (becomes #define)
attributes : attribute bindings
attribute bindings need to map to an attribute in the meshdata being rendered
uniforms : uniform bindings
uniform bindings can be a value (like 2.5 or [1, 2]) or a function
glslversion : shader version
only accepted value for is 300 or nothing at all. if 300 is passed then #version 300 es
will be added to top of shader
gl1Extensions : WebGL 1.0 extensions
Added after the shader definition to support features not supported by glsl 100
gl2Extensions : WebGL 2.0 extensions
Added after the shader definition to support features not supported by glsl 300
}