This reference page is linked to from the following overview topics: Autodesk Maya 2014, Extension for Autodesk Maya 2013, Data Classes, Rendering Overrides, Framework Classes, 2.3 Shader Instances, 3.2 The Renderer, 4.5 Handling custom renderables for object overrides, Shader semantics supported by Viewport 2.0.
Provides access to MShaderInstance objects for use in Viewport 2.0.
This class generates MShaderInstance objects for use with user-created MRenderItem objects. Any MShaderInstance objects created by this class are owned by the caller.
The methods for adding shader and shader include paths will allow for additional search paths to be used with the "getEffectsFileShader()" method which searches for shader files on disk. The default search path is in the "Cg" and "HLSL" folders found in the runtime directory. It is recommended that user defined shaders not reside at this location to avoid any potential shader conflicts.
When acquiring a shader instance the caller may also specify pre-draw and post-draw callback functions. These functions will be invoked any time a render item that uses the shader instance is about to be drawn. These callbacks are passed an MDrawContext object as well as the render item being drawn and may alter the draw state in order to get different rendering effects. Accessing Maya nodes from within these callbacks is an error and may result in instability.
#include <MShaderManager.h>
Public Types | |
| enum | MStockShader { k3dSolidShader, k3dBlinnShader, k3dDefaultMaterialShader, k3dSolidTextureShader, k3dCPVFatPointShader, k3dShadowerShader, k3dFatPointShader, k3dThickLineShader, k3dCPVThickLineShader, k3dDashLineShader, k3dCPVDashLineShader, k3dStippleShader, k3dThickDashLineShader, k3dCPVThickDashLineShader, k3dDepthShader, k3dCPVSolidShader } |
Name of an available "stock" shader. More... | |
Public Member Functions | |
| MStatus | addShaderPath (const MString &path) const |
| Add a path to the list of shader search paths. | |
| MStatus | shaderPaths (MStringArray &paths) const |
| Query the list of shader search paths. | |
| MStatus | addShaderIncludePath (const MString &path) const |
| Add a path to the list of paths used for searching for shader include files. | |
| MStatus | shaderIncludePaths (MStringArray &paths) const |
| Query the list of search paths user for searching for shader include files. | |
| MShaderInstance * | getEffectsFileShader (const MString &effectsFileName, const MString &techniqueName, MShaderCompileMacro *macros=0, unsigned int numberOfMacros=0, bool useEffectCache=true, MShaderInstance::DrawCallback preCb=0, MShaderInstance::DrawCallback postCb=0) const |
| Get a new instance of a shader generated from an effects file stored on disk. | |
| MShaderInstance * | getEffectsBufferShader (const void *buffer, unsigned int size, const MString &techniqueName, MShaderCompileMacro *macros=0, unsigned int numberOfMacros=0, bool useEffectCache=true, MShaderInstance::DrawCallback preCb=0, MShaderInstance::DrawCallback postCb=0) const |
| Get a new instance of a shader generated from a block of memory containing device-specific source code (as char*). | |
| MShaderInstance * | getFragmentShader (const MString &fragmentName, const MString &structOutputName, bool decorateFragment, MShaderInstance::DrawCallback preCb=0, MShaderInstance::DrawCallback postCb=0) const |
| Get a new instance of a shader generated from a named shader fragment or fragment graph. | |
| MShaderInstance * | getStockShader (MStockShader name, MShaderInstance::DrawCallback preCb=0, MShaderInstance::DrawCallback postCb=0) const |
| Get a new instance of a stock shader. | |
| void | releaseShader (MShaderInstance *shader) const |
| Deletes the MShaderInstance and releases its reference to the underlying shader which is held by the MShaderInstance object. | |
Static Public Member Functions | |
| static bool | isSupportedShaderSemantic (const MString &value) |
| Return if a given string is a supported shader semantic. | |
| static const char * | className () |
| Returns the name of this class. | |
| enum MStockShader |
Name of an available "stock" shader.
Add a path to the list of shader search paths.
| [in] | path | Shader search path. |
| MStatus shaderPaths | ( | MStringArray & | paths | ) | const |
Query the list of shader search paths.
| [out] | paths | A string array which is filled in with search path strings. Each array element will contain one shader path string. |
Add a path to the list of paths used for searching for shader include files.
| [in] | path | Shader include path. |
| MStatus shaderIncludePaths | ( | MStringArray & | paths | ) | const |
Query the list of search paths user for searching for shader include files.
| [out] | paths | A string array which is filled in with search path strings. Each array element will contain one shader include path string. |
| MShaderInstance * getEffectsFileShader | ( | const MString & | effectsFileName, |
| const MString & | techniqueName, | ||
| MShaderCompileMacro * | macros = 0, |
||
| unsigned int | numberOfMacros = 0, |
||
| bool | useEffectCache = true, |
||
| MShaderInstance::DrawCallback | preCb = 0, |
||
| MShaderInstance::DrawCallback | postCb = 0 |
||
| ) | const |
Get a new instance of a shader generated from an effects file stored on disk.
If a file extension is not supplied as part of the file name argument then the following strings are appended to the file name based on the drawing API which is currently being used by the renderer:
When the object is no longer needed, MShaderManager::releaseShader() should be called to notify the shader manager that the caller is done with the shader.
Optionally, a pre-draw and post-draw callback function may be associated with the shader. The callbacks will be invoked any time a render item using the shader is drawn.
| [in] | effectsFileName | The effects file |
| [in] | techniqueName | The name of a technique in the effects file. If an empty string is specified then the first technique in the effects file will be used. |
| [in] | macros | Pointer to an array of shader macros structures. The default value is 0, meaning that no macros are specified. |
| [in] | numberOfMacros | Number of macros. The default value is 0. |
| [in] | useEffectCache | Use the internal effect cache to prevent reloading the effect file every time it is requested. Unless you are changing the effect, this should always be set to true for maximum performance. |
| [in] | preCb | A pointer to the function to be called before render items are drawn with this shader. |
| [in] | postCb | A pointer to the function to be called after render items are drawn with this shader. |
| MShaderInstance * getEffectsBufferShader | ( | const void * | buffer, |
| unsigned int | size, | ||
| const MString & | techniqueName, | ||
| MShaderCompileMacro * | macros = 0, |
||
| unsigned int | numberOfMacros = 0, |
||
| bool | useEffectCache = true, |
||
| MShaderInstance::DrawCallback | preCb = 0, |
||
| MShaderInstance::DrawCallback | postCb = 0 |
||
| ) | const |
Get a new instance of a shader generated from a block of memory containing device-specific source code (as char*).
When the object is no longer needed, MShaderManager::releaseShader() should be called to notify the shader manager that the caller is done with the shader.
Optionally, a pre-draw and post-draw callback function may be associated with the shader. The callbacks will be invoked any time a render item using the shader is drawn.
| [in] | buffer | A pointer to the block of memory from which to load the effect. |
| [in] | size | The size of the effect to load in bytes. |
| [in] | techniqueName | The name of a technique in the effect. If an empty string is specified then the first technique in the effects file will be used. |
| [in] | macros | Pointer to an array of shader macros structures. The default value is 0, meaning that no macros are specified. |
| [in] | numberOfMacros | Number of macros. The default value is 0. |
| [in] | useEffectCache | Use the internal effect cache to prevent reloading the effect every time it is requested. Unless you are changing the effect, this should always be set to true for maximum performance. |
| [in] | preCb | A pointer to the function to be called before render items are drawn with this shader. |
| [in] | postCb | A pointer to the function to be called after render items are drawn with this shader. |
| MShaderInstance * getFragmentShader | ( | const MString & | fragmentName, |
| const MString & | structOutputName, | ||
| bool | decorateFragment, | ||
| MShaderInstance::DrawCallback | preCb = 0, |
||
| MShaderInstance::DrawCallback | postCb = 0 |
||
| ) | const |
Get a new instance of a shader generated from a named shader fragment or fragment graph.
MFragmentManager can be used to query the names of registered fragments and fragment graphs and to add new fragments and graphs to Maya.
The named fragment must have a single 3-float or 4-float output. If the fragment has a struct output, callers may specify the name of a 3-float or 4-float member of the struct to use as the output for the final shader instance. If the fragment does not have a struct output, the struct member name parameter is ignored.
Callers may request that Maya decorate the fragment with additonal lighting information before creating the shader instance. This will allow the shader to work with Maya lights. Internal surface shader fragments require this decoration in order to function correctly. Please see the documentation for MPxSurfaceShadingNodeOverride for more details.
| [in] | fragmentName | The name of the fragment to generate a shader from |
| [in] | structOutputName | If the output of the fragment is a struct, use this parameter to specify which member of the struct to use. This parameter is ignored if the output of the fragment is not a struct. |
| [in] | decorateFragment | If true, Maya state fragments will be added |
| [in] | preCb | A pointer to the function to be called before render items are drawn with this shader. |
| [in] | postCb | A pointer to the function to be called after render items are drawn with this shader. |
| MShaderInstance * getStockShader | ( | MStockShader | name, |
| MShaderInstance::DrawCallback | preCb = 0, |
||
| MShaderInstance::DrawCallback | postCb = 0 |
||
| ) | const |
Get a new instance of a stock shader.
When the object is no longer needed, MShaderManager::releaseShader() should be called to notify the shader manager that the caller is done with the shader.
Optionally, a pre-draw and post-draw callback function may be associated with the shader. The callbacks will be invoked any time a render item using the shader is drawn.
| [in] | name | Name of stock shader |
| [in] | preCb | A pointer to the function to be called before render items are drawn with this shader. |
| [in] | postCb | A pointer to the function to be called after render items are drawn with this shader. |
| void releaseShader | ( | MShaderInstance * | shader | ) | const |
Deletes the MShaderInstance and releases its reference to the underlying shader which is held by the MShaderInstance object.
After calling this method it is an error to try to use the MShaderInstance and attempting to do so will result in instability. The underlying shader might not be deleted immediately if it is in use by the renderer (for example if it is assigned to a render item).
| [in] | shader | The shader to release |
| bool isSupportedShaderSemantic | ( | const MString & | value | ) | [static] |
Return if a given string is a supported shader semantic.
To be supported means that, for a shader parameter which has this semantic, the renderer will automatically set the parameter's value before the shader is used for rendering.
The plugin writer should not be explicitly setting the values for parameters with supported shader semantics.
For example a matrix parameter with the "projection" semantic will have its value updated with the current camera projection matrix before the shader is used.
| value | String to check |
| const char * className | ( | ) | [static] |