A Shader object is a container of shading techniques.
A Shader object can be constructed with the GraphicsDevice.createShader function.
Summary
Returns the requested shader technique.
Syntax
var techniqueByName = shader.getTechnique('blinn');
var techniqueByIndex = shader.getTechnique(1);
Returns a Technique object. Techniques can be requested by name or by index from zero to shader.numTechniques minus one. Returns a Technique object if the requested name or index exists, null otherwise. It is recommended to request techniques once at loading time and to store them somewhere else rather than to request them continuously.
Summary
Returns the requested shader parameter information.
Syntax
var parameterInfoByName = shader.getParameter('lightColor');
var parameterInfoByIndex = shader.getParameter(1);
var parameterName = parameterInfoByIndex.name;
var parameterType = parameterInfoByIndex.type;
var parameterNumRows = parameterInfoByIndex.rows;
var parameterNumColumns = parameterInfoByIndex.columns;
Parameters can be requested by name or by index from zero to shader.numParameters minus one.
Returns a shader parameter information object if the requested name or index exists, null otherwise.
Summary
Releases the Shader resources, the object will be invalid after the method is called.
Syntax
shader.destroy();
Summary
The name of the shader object, usually the path to the CgFX file that originated the shader definition used to create the shader.
Syntax
var shaderName = shader.name;
Note
Read Only
Summary
The unique identification number of the Shader object.
Syntax
var shaderId = shader.id;
Note
Read Only
Summary
The number of shading techniques contained on the Shader object.
Syntax
var numTechniquesShader = shader.numTechniques;
Note
Read Only
Summary
The number of shading parameters used by the techniques on the Shader object.
Syntax
var numParametersShader = shader.numParameters;
Note
Read Only
A shading technique. This object is required to perform any geometry rendering.
Summary
The name of the shading technique.
Syntax
var techniqueName = technique.name;
Note
Read Only
Summary
The unique identification number of the Technique object.
Syntax
var techniqueId = technique.id;
Note
Read Only
Shading techniques require shading parameters to be set before any effective rendering can be done, for example the vertex program could require the world transformation matrix and the view-projection one, whilst the fragment program may require a material color or a light position.
This shading properties can be modified by grouping them on a TechniqueParameters object to be set all at once by graphicsDevice.setTechniqueParameters, or one by one directly on the Technique object. The later method is recommended only when a handful of properties need to be changed between draw calls, for example:
graphicsDevice.setTechnique(sharedTechnique);
graphicsDevice.setTechniqueParameters(sharedTechniqueParameters);
var renderable, n;
for (n = 0; n < numRenderables; n += 1)
{
renderable = renderables[n];
sharedTechnique.world = renderable.worldMatrix;
graphicsDevice.setStream(renderable.vertexBuffer, renderable.semantics);
graphicsDevice.setIndexBuffer(renderable.indexBuffer);
graphicsDevice.drawIndexed(renderable.primitive, renderable.numIndices);
}
The name of the shading property will be the name of the uniform variable used on the shading programs.
Valid types for shading properties are:
Numbers
- Arrays of numbers
- It is highly recommended to use those created by the MathDevice object.
TechniqueParameterBuffer objects
Texture objects
Booleans
Setting a property directly onto a Technique object will cause the plugin to crash if the parameter is unsupported by the Technique. Be careful of this when debugging shaders as the compiler will remove any unused parameters from Techniques.