H3DU.ShaderInfo
H3DU.ShaderInfo([vertexShader], [fragmentShader])
Holds source code for a WebGL shader program. A shader program in WebGL consists of a vertex shader (which processes vertices), and a fragment shader (which processes pixels). Shader programs are specially designed for running on a graphics processing unit, or GPU.
This class also stores semantics and uniform values associated with the shader source code.
Note that this class is not associated with any WebGL context, so the uniform values this object stores is not set for any WebGL context.
Currently, the following attribute names are associated with this object by default:
position
- "POSITION" semanticnormal
- "NORMAL" semanticuv
- "TEXCOORD_0" semantictangent
- Attribute for tangents.bitangent
- Attribute for bitangentscolorAttr
- "COLOR"
Currently, the following uniform names are associated with this object by default:
projection
- Projection matrixmodelViewMatrix
- Model-view matrixnormalMatrix
- Inverse transpose of the model-view matrixworld
- World matrix.inverseView
- Inverse view matrix.
Parameters
vertexShader
(Type: string) (optional)
Source text of a vertex shader, in OpenGL ES Shading Language (GLSL). If null, a default vertex shader is used instead.fragmentShader
(Type: string) (optional)
Source text of a fragment shader in GLSL. If null, a default fragment shader is used instead.
Methods
- copy
Returns a new shader info object with the information in this object copied to that object. - dispose
Deprecated: Yes - getBasicVertex
Gets the text of a basic vertex shader. - getDefaultFragment
Gets the text of the default fragment shader. - getDefaultVertex
Gets the text of the default vertex shader. - getFragmentShader
Gets the text of the fragment shader stored in this object. - getVertexShader
Gets the text of the vertex shader stored in this object. - makeCopyEffect
Generates source code for a shader program that copies the colors of a texture. - makeEdgeDetectEffect
Generates source code for a shader program that generates a two-color texture showing the source texture's edges. - makeEffect
Generates source code for a shader program for applying a raster effect (postprocessing effect) to a texture. - makeEffectFragment
Generates source code for a fragment shader for applying a raster effect to a texture. - makeInvertEffect
Generates source code for a shader program that inverts the colors of a texture. - setSemantic
Sets the semantic for a vertex attribute. - setUniformSemantic
Sets a semantic for the given named uniform. - setUniforms
Sets the values of one or more uniforms used by this shader program.
H3DU.ShaderInfo#copy()
Returns a new shader info object with the information in this object copied to that object.
Return Value
Return value. (Type: H3DU.ShaderInfo)
H3DU.ShaderInfo#dispose()
Deprecated: Yes
This method was introduced for compatibility reasons.
(static) H3DU.ShaderInfo.getBasicVertex()
Gets the text of a basic vertex shader.
Return Value
The resulting shader text. (Type: string)
(static) H3DU.ShaderInfo.getDefaultFragment()
Gets the text of the default fragment shader.
Return Value
The resulting shader text. (Type: string)
(static) H3DU.ShaderInfo.getDefaultVertex()
Gets the text of the default vertex shader. Putting "#define SHADING\n" at the start of the return value enables the lighting model.
Return Value
The resulting shader text. (Type: string)
H3DU.ShaderInfo#getFragmentShader()
Gets the text of the fragment shader stored in this object.
Return Value
return value. (Type: string)
H3DU.ShaderInfo#getVertexShader()
Gets the text of the vertex shader stored in this object.
Return Value
return value. (Type: string)
(static) H3DU.ShaderInfo.makeCopyEffect()
Generates source code for a shader program that copies the colors of a texture.
Return Value
The resulting shader program. (Type: H3DU.ShaderInfo)
(static) H3DU.ShaderInfo.makeEdgeDetectEffect()
Generates source code for a shader program that generates a two-color texture showing the source texture's edges.
Return Value
The resulting shader program. (Type: H3DU.ShaderInfo)
(static) H3DU.ShaderInfo.makeEffect(functionCode)
Generates source code for a shader program for applying a raster effect (postprocessing effect) to a texture.
Parameters
functionCode
(Type: string)
A string giving shader code in OpenGL ES Shading Language (GLSL) that must contain a function with the following signature:vec4 textureEffect(sampler2D sampler, vec2 uvCoord, vec2 textureSize)
where
sampler
is the texture sampler,uvCoord
is the texture coordinates ranging from 0 to 1 in each component,textureSize
is the dimensions of the texture in pixels, and the return value is the new color at the given texture coordinates. Besides this requirement, the shader code is also free to define additional uniforms, constants, functions, and so on (but not another "main" function).
Return Value
The resulting shader program. (Type: H3DU.ShaderInfo)
(static) H3DU.ShaderInfo.makeEffectFragment(functionCode)
Generates source code for a fragment shader for applying a raster effect to a texture.
Parameters
functionCode
(Type: string)
See H3DU.ShaderInfo.makeEffect.
Return Value
The source text of the resulting fragment shader. (Type: string)
(static) H3DU.ShaderInfo.makeInvertEffect()
Generates source code for a shader program that inverts the colors of a texture.
Return Value
The resulting shader program. (Type: H3DU.ShaderInfo)
H3DU.ShaderInfo#setSemantic(name, semantic, semanticIndex)
Sets the semantic for a vertex attribute.
Parameters
name
(Type: string)
Name of the attribute.semantic
(Type: Number | String)
An attribute semantic, such as H3DU.Semantic.POSITION, "POSITION", or "TEXCOORD_0".semanticIndex
(Type: number)
The set index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "semantic" is a string.
Return Value
This object. Throws an error if the given semantic is unsupported. (Type: H3DU.ShaderInfo)
H3DU.ShaderInfo#setUniformSemantic(u, sem)
Sets a semantic for the given named uniform.
Parameters
u
(Type: string)
The name of the uniform.sem
(Type: number)
A uniform semantic given in H3DU.Semantic.
Return Value
This object. (Type: H3DU.ShaderInfo)
H3DU.ShaderInfo#setUniforms(uniforms)
Sets the values of one or more uniforms used by this shader program. Since this object doesn't store a WebGL context, or receive one as input, the uniforms won't be associated with a WebGL context.
Parameters
uniforms
(Type: Object)
An object whose keys are the names of uniforms defined in either the vertex or fragment shader of this shader program. If the uniform is an array, each element in the array is named as in these examples: "unif[0]", "unif[1]". If it's a struct, each member in the struct is named as in these examples: "unif.member1", "unif.member2". If it's an array of struct, each member is named as in these examples: "unif[0].member1", "unif[0].member2". The value of each key depends on the data type expected for the uniform named by that key. The value can be a 3-, 4-, 9-, or 16-element array if the uniform is a "vec3", "vec4", "mat3", or "mat4", respectively, or a Number if the uniform is a "float" or "int".
Return Value
This object. (Type: H3DU.ShaderInfo)