C++ API Reference
|
An instance of a shader that may be used with Viewport 2.0. More...
#include <MShaderManager.h>
Public Types | |
enum | ParameterType { kInvalid, kBoolean, kInteger, kFloat, kFloat2, kFloat3, kFloat4, kFloat4x4Row, kFloat4x4Col, kTexture1, kTexture2, kTexture3, kTextureCube, kSampler } |
Specifies parameter types. More... | |
enum | FragmentUsage { kPixelShader, kNormalShader, kNormalShader2, kVertexShader, kGeometryShader, kGlossShader, kGlossShader2, kRotationAngleShader, kRotationAngleShader2, kReflectanceShader, kReflectanceShader2, kRoughnessShader, kRoughnessShader2, kAnisotropyShader, kAnisotropyShader2, kDisplacementPosShader } |
Specifies where a fragment will be connected and used. More... | |
typedef void(* | DrawCallback) (MDrawContext &context, const MRenderItemList &renderItemList, MShaderInstance *shaderInstance) |
Definition for pre/post draw callback functions. | |
Public Member Functions | |
DrawCallback | preDrawCallback () const |
Access the pre-draw callback function pointer set for the this shader instance. More... | |
DrawCallback | postDrawCallback () const |
Access the post-draw callback function pointer set for the this shader instance. More... | |
void | parameterList (MStringArray &list) const |
Get the names of all parameters that are settable on this shader instance. More... | |
ParameterType | parameterType (const MString ¶meterName) const |
Get the type of the named parameter, returns kInvalid if parameter is not found. More... | |
bool | isArrayParameter (const MString ¶meterName) const |
Determine whether the named parameter is an array. More... | |
int | getArraySize (const MString ¶meterName) const |
Get the size of the array. More... | |
MString | semantic (const MString ¶meterName) const |
Return the semantic for a named parameter. More... | |
bool | isVaryingParameter (const MString ¶meterName) const |
Determine whether the named parameter is varying or is uniform. More... | |
MStatus | setParameter (const MString ¶meterName, bool value) |
Set a named, boolean parameter on the shader instance. More... | |
MStatus | setParameter (const MString ¶meterName, int value) |
Set a named, integer parameter on the shader instance. More... | |
MStatus | setParameter (const MString ¶meterName, float value) |
Set a named, float parameter on the shader instance. More... | |
MStatus | setParameter (const MString ¶meterName, const float *value) |
Set a named, float, float2, float3 or float4 parameter on the shader instance. More... | |
MStatus | setParameter (const MString ¶meterName, const MFloatVector &value) |
Set a named, float, float2, float3 parameter on the shader instance. More... | |
MStatus | setParameter (const MString ¶meterName, const MMatrix &value) |
Set a named, matrix parameter on the shader instance. More... | |
MStatus | setParameter (const MString ¶meterName, const MFloatMatrix &value) |
Set a named, matrix parameter on the shader instance. More... | |
MStatus | setParameter (const MString ¶meterName, MTextureAssignment &textureAssignment) |
Set a texture parameter on the shader instance. More... | |
MStatus | setParameter (const MString ¶meterName, MRenderTargetAssignment &targetAssignment) |
Set a named, texture parameter on the shader instance to a render target. More... | |
MStatus | setParameter (const MString ¶meterName, const MSamplerState &sampler) |
Set a sampler parameter on the shader instance. More... | |
MStatus | setArrayParameter (const MString ¶meterName, const bool *values, unsigned int count) |
Set a named, bool array parameter on the shader instance. More... | |
MStatus | setArrayParameter (const MString ¶meterName, const int *values, unsigned int count) |
Set a named, integer array parameter on the shader instance. More... | |
MStatus | setArrayParameter (const MString ¶meterName, const float *values, unsigned int count) |
Set a named, float array parameter on the shader instance. More... | |
MStatus | setArrayParameter (const MString ¶meterName, const MMatrix *values, unsigned int count) |
Set a named, matrix array parameter on the shader instance. More... | |
MStatus | addInputFragment (const MString &fragmentName, const MString &outputName, const MString &inputName, const MString promotedInputName=MString()) |
Connect a fragment that has been registered with the fragment manager to an input on the existing MShaderInstance. More... | |
MStatus | addInputFragmentForMultiParams (const MString &fragmentName, const MString &uniqueName, const MStringArray &outputNames, const MStringArray &inputNames, MUintArray *invalidParameterIndices=nullptr, FragmentUsage fragmentUsage=kPixelShader) |
Connect a named fragment that has been registered with the MFragmentManager to this MShaderInstance. More... | |
MStatus | addOutputFragment (const MString &fragmentName, const MString &inputName) |
Connect a fragment that has been registered with the fragment manager to an output on the existing MShaderInstance. More... | |
MStatus | renameParameter (const MString &oldName, const MString &newName) |
Rename the parameter. More... | |
MStatus | setSemantic (const MString ¶mName, const MString &semantic) |
Set the semantic for a fragment based parameter. More... | |
MStatus | setAsVarying (const MString ¶mName, bool) |
Set the parameter to be a varying parameter or not for a fragment based parameter. More... | |
MStatus | bind (const MDrawContext &context) const |
Binds the shader instance to the draw context, so that it is the active shader. More... | |
unsigned int | getPassCount (const MDrawContext &context, MStatus *status=NULL) const |
Returns the number of draw passes defined by the shader. More... | |
MStatus | activatePass (const MDrawContext &context, unsigned int pass) const |
Activates the given pass of the shader. More... | |
MStatus | unbind (const MDrawContext &context) const |
Unbinds the shader instance from the draw context. More... | |
MStatus | updateParameters (const MDrawContext &context) const |
Updates the bound shader instance with the current parameter data. More... | |
bool | isTransparent () const |
Return whether the shader will render with transparency. More... | |
MStatus | setIsTransparent (bool value) |
Set whether the shader will render with transparency. More... | |
MShaderInstance * | clone () const |
Clone the shader. More... | |
MShaderInstance * | createShaderInstanceWithColorManagementFragment (const MString &inputColorSpace) |
Return a new shader instance with Color Management fragment added, which is based on the callee. More... | |
MStatus | requiredVertexBuffers (MVertexBufferDescriptorList &list) const |
Get the vertex buffer descriptors that describe the buffers required by a given shader instance. More... | |
int | annotationAsInt (const MString ¶meterName, const MString &annotationName, MStatus &status) |
Returns annotation value for a given parameter as integer. More... | |
float | annotationAsFloat (const MString ¶meterName, const MString &annotationName, MStatus &status) |
Returns annotation value for a given parameter as float. More... | |
MString | annotationAsString (const MString ¶meterName, const MString &annotationName, MStatus &status) |
Returns annotation value for a given parameter as MString. More... | |
MString | parameterSemantic (const MString ¶meterName, MStatus &status) |
Returns the semantic associated to a given parameter. More... | |
void * | parameterDefaultValue (const MString ¶meterName, MStatus &status) |
Returns the default value of a given parameter. More... | |
MString | resourceName (const MString ¶meterName, MStatus &status) |
Returns the resource name of a given texture parameter. More... | |
MString | uiWidget (const MString ¶meterName, MStatus &status) |
Returns the UI widget type associated with a given parameter. More... | |
MString | uiName (const MString ¶meterName, MStatus &uiName) |
Returns the UI name associated with a given parameter. More... | |
MStatus | techniqueNames (MStringArray &techniqueNames) const |
Returns a list of the technique names for the effect. More... | |
int | techniqueAnnotationAsInt (const MString &annotationName, MStatus &status) |
Returns the value of the current technique annotation as integer. More... | |
float | techniqueAnnotationAsFloat (const MString &annotationName, MStatus &status) |
Returns the value of the current technique annotation as float. More... | |
MString | techniqueAnnotationAsString (const MString &annotationName, MStatus &status) |
Returns the value of the current technique annotation as MString. More... | |
int | passAnnotationAsInt (unsigned int pass, const MString &annotationName, MStatus &status) |
Returns the value of the current technique's pass annotation as int. More... | |
float | passAnnotationAsFloat (unsigned int pass, const MString &annotationName, MStatus &status) |
Returns the value of the current technique's pass annotation as float. More... | |
MString | passAnnotationAsString (unsigned int pass, const MString &annotationName, MStatus &status) |
Returns the value of the current technique's pass annotation as MString. More... | |
MStatus | writeEffectSourceToFile (const MString &filePath) const |
Write the source of the final OGSFX/HLSL/CgFX effect to a specified file. More... | |
Static Public Member Functions | |
static const char * | className () |
Returns the name of this class. More... | |
An instance of a shader that may be used with Viewport 2.0.
This class represents a shader that may be used with the MRenderItem class for rendering in Viewport 2.0.
enum ParameterType |
Specifies parameter types.
enum FragmentUsage |
Specifies where a fragment will be connected and used.
MShaderInstance::DrawCallback preDrawCallback | ( | ) | const |
Access the pre-draw callback function pointer set for the this shader instance.
MShaderInstance::DrawCallback postDrawCallback | ( | ) | const |
Access the post-draw callback function pointer set for the this shader instance.
void parameterList | ( | MStringArray & | list | ) | const |
Get the names of all parameters that are settable on this shader instance.
[out] | list | The list to populate parameter names |
MShaderInstance::ParameterType parameterType | ( | const MString & | parameterName | ) | const |
Get the type of the named parameter, returns kInvalid if parameter is not found.
[in] | parameterName | Name of the parameter to query |
bool isArrayParameter | ( | const MString & | parameterName | ) | const |
Determine whether the named parameter is an array.
[in] | parameterName | Name of the parameter to query |
int getArraySize | ( | const MString & | parameterName | ) | const |
Get the size of the array.
[in] | parameterName | Name of the parameter to query, if the named parameter is an array |
Return the semantic for a named parameter.
[in] | parameterName | Name of the parameter to query |
bool isVaryingParameter | ( | const MString & | parameterName | ) | const |
Determine whether the named parameter is varying or is uniform.
[in] | parameterName | Name of the parameter to query |
Set a named, boolean parameter on the shader instance.
[in] | parameterName | Name of the parameter to set |
[in] | value | Value of the parameter |
Set a named, integer parameter on the shader instance.
[in] | parameterName | Name of the parameter to set |
[in] | value | Value of the parameter |
Set a named, float parameter on the shader instance.
[in] | parameterName | Name of the parameter to set |
[in] | value | Value of the parameter |
Set a named, float, float2, float3 or float4 parameter on the shader instance.
The floating point data stored in "value" will be interpreted based on the type of the named parameter. For example, for a parameter of type kFloat3, the data will be assumed to be an array containing three floats.
[in] | parameterName | Name of the parameter to set |
[in] | value | Value of the parameter |
MStatus setParameter | ( | const MString & | parameterName, |
const MFloatVector & | value | ||
) |
Set a named, float, float2, float3 parameter on the shader instance.
The floating point data stored in "value" will be interpreted based on the type of the named parameter. For example, for a parameter of type kFloat3, the first 3 elements of the data will be set.
[in] | parameterName | Name of the parameter to set |
[in] | value | Value of the parameter |
Set a named, matrix parameter on the shader instance.
Note that this method does not alter the matrix and it is up to the caller to set the values correctly depending on whether the parameter is row-major or column-major.
[in] | parameterName | Name of the parameter to set |
[in] | value | Value of the parameter |
MStatus setParameter | ( | const MString & | parameterName, |
const MFloatMatrix & | value | ||
) |
Set a named, matrix parameter on the shader instance.
Note that this method does not alter the matrix and it is up to the caller to set the values correctly depending on whether the parameter is row-major or column-major.
[in] | parameterName | Name of the parameter to set |
[in] | value | Value of the parameter |
MStatus setParameter | ( | const MString & | parameterName, |
MTextureAssignment & | textureAssignment | ||
) |
Set a texture parameter on the shader instance.
If the texture assignment contains a NULL value for texture then the shader parameter will be set to NULL.
[in] | parameterName | Name of the parameter to set |
[in] | textureAssignment | Texture to assign |
MStatus setParameter | ( | const MString & | parameterName, |
MRenderTargetAssignment & | targetAssignment | ||
) |
Set a named, texture parameter on the shader instance to a render target.
If the render target assignment contains a NULL value then the shader parameter will be set to NULL.
Note, there is a significant performance penalty when binding MSAA targets (i.e. targets where multiSampleCount > 1).
[in] | parameterName | Name of the parameter to set |
[in] | targetAssignment | Render target to assign |
MStatus setParameter | ( | const MString & | parameterName, |
const MSamplerState & | sampler | ||
) |
Set a sampler parameter on the shader instance.
[in] | parameterName | Name of the parameter to set |
[in] | sampler | Sampler state to assign |
MStatus setArrayParameter | ( | const MString & | parameterName, |
const bool * | values, | ||
unsigned int | count | ||
) |
Set a named, bool array parameter on the shader instance.
[in] | parameterName | Name of the parameter to set |
[in] | values | The array of values to set |
[in] | count | The number of values in the array |
Set a named, integer array parameter on the shader instance.
[in] | parameterName | Name of the parameter to set |
[in] | values | The array of values to set |
[in] | count | The number of values in the array |
MStatus setArrayParameter | ( | const MString & | parameterName, |
const float * | values, | ||
unsigned int | count | ||
) |
Set a named, float array parameter on the shader instance.
This method is used for setting not just float arrays but float2, float3 and float4 array parameters as well. The floating point data stored in "values" will be interpreted based on the type of the named parameter. For example, for a parameter of type kFloat3, the data will be assumed to be a list of float-triples containing a total of "count" float-triples. So if "count" in this example is 5, that means the total number of raw floats is 3*5=15.
[in] | parameterName | Name of the parameter to set |
[in] | values | The array of values to set |
[in] | count | The number of floats stored in the array divided by the dimension of the data |
MStatus setArrayParameter | ( | const MString & | parameterName, |
const MMatrix * | values, | ||
unsigned int | count | ||
) |
Set a named, matrix array parameter on the shader instance.
Note that this method does not alter the matrices and it is up to the caller to set the values correctly depending on whether the parameter is row-major or column-major.
[in] | parameterName | Name of the parameter to set |
[in] | values | The array of values to set |
[in] | count | The number of values in the array |
MStatus addInputFragment | ( | const MString & | fragmentName, |
const MString & | outputName, | ||
const MString & | inputName, | ||
const MString | promotedInputName = MString() |
||
) |
Connect a fragment that has been registered with the fragment manager to an input on the existing MShaderInstance.
Use this method to add shader instructions to an existing MShaderInstance. The code defined in the fragment will be compiled and executed on the GPU to compute the value for the input parameter.
[in] | fragmentName | The name of a fragment that has been registered with the MFragmentManager. |
[in] | outputName | The name of the output on the registered fragment to connect to. |
[in] | inputName | The name of the input parameter on the MShaderInstance to connect to. |
[in] | promotedInputName | The name of the input parameter on the new fragment that will be promoted to replace the input parameter being connected to. If this argument is not specified, and an input with the same name as inputName exist on the input fragment it will automatically be promoted. |
MStatus addInputFragmentForMultiParams | ( | const MString & | fragmentName, |
const MString & | uniqueName, | ||
const MStringArray & | outputNames, | ||
const MStringArray & | inputNames, | ||
MUintArray * | invalidParameterIndices = nullptr , |
||
FragmentUsage | fragmentUsage = kPixelShader |
||
) |
Connect a named fragment that has been registered with the MFragmentManager to this MShaderInstance.
The code defined in the fragment will be included in the new shader and executed on GPU to compute values for input parameters specified by inputNames
.
To connect with fragments, this MShaderInstance needs to be created from a shader fragment or fragment graph as well. Thus, a shader instance created from a file-based effect cannot connect with any fragments.
After the fragment is connected, all input parameters with the same name in the new fragment graph are mapped to a single parameter in the shader by default. If uniqueness is required for input parameters on the fragment, uniqueName
can be used to prefix names of the input parameters.
This method is particularly useful when plugin needs to make multiple connections from the input fragment to this MShaderInstance. It can be used to make a single connection, but addInputFragment() is more convenient in this case. The numbers of the output and input parameters must match. An output and an input parameter with the same index in the two string arrays will be connected. To specify fan-out connections, the same output name can be repeated in outputNames
as need. Fan-in connections are not allowed.
If the numbers of the output and input parameters don't match, or a parameter (either output or input) doesn't exist, or their types don't match, the relevant parameters will not be connected and the method will return MStatus::kInvalidParameter. In this case, the fragment may still be connected partially to this MShaderInstance through other connectable parameter pairs, and plugin can use invalidParameterIndices
to query indices of those invalid parameters in outputNames
and inputNames
.
[in] | fragmentName | Name of the input fragment. |
[in] | uniqueName | A unique name to prefix names of input parameters on the input fragment. |
[in] | outputNames | Names of the output parameters on the input fragment to connect from. |
[in] | inputNames | Names of the input parameters on the MShaderInstance to connect to. |
[out] | invalidParameterIndices | Optional array to query indices of invalid parameters. |
[in] | fragmentUsage | Not implemented. |
Connect a fragment that has been registered with the fragment manager to an output on the existing MShaderInstance.
The code defined in the fragment will be compiled and executed on the GPU to modify the value returned by the original shader. For example, use this method to add additional alpha or conditionals to the output color.
[in] | fragmentName | The name of a fragment that has been registered with the MFragmentManager. |
[in] | inputName | The name of the input parameter on the fragment to connect the shaders output to. |
Rename the parameter.
Note this only works for fragment based shader instances.
[in] | oldName | The name of a parameter. |
[in] | newName | The new name to give the parameter. |
Set the semantic for a fragment based parameter.
Note this only works for fragment based shaders.
[in] | paramName | The name of a parameter. |
[in] | semantic | The semantic to assign to the parameter. Semantics can be used to identify parameters by their use, independent of their names. |
Set the parameter to be a varying parameter or not for a fragment based parameter.
Note this only works for fragment based shaders.
[in] | paramName | The name of a parameter. |
[in] | isVarying | True if the parameter should vary per vertex, false if the parameter should be treated as a uniform value. |
MStatus bind | ( | const MDrawContext & | context | ) | const |
Binds the shader instance to the draw context, so that it is the active shader.
The typical call sequence is
bind() getPassCount() activatePass( 0 ) do drawing activatePass( 1 ) do drawing ... unbind()
Note that it is the plug-in author's responsibility to call unbind() at the appropriate time. Failing to do so may corrupt subsequent drawing.
[in] | context | The current draw context |
unsigned int getPassCount | ( | const MDrawContext & | context, |
MStatus * | status = NULL |
||
) | const |
Returns the number of draw passes defined by the shader.
[in] | context | The current draw context |
[out] | status | Status code |
MStatus activatePass | ( | const MDrawContext & | context, |
unsigned int | pass | ||
) | const |
Activates the given pass of the shader.
Must be called between calls to bind() and unbind().
[in] | context | The current draw context |
[in] | pass | The index of the pass to activate |
MStatus unbind | ( | const MDrawContext & | context | ) | const |
Unbinds the shader instance from the draw context.
[in] | context | The current draw context |
MStatus updateParameters | ( | const MDrawContext & | context | ) | const |
Updates the bound shader instance with the current parameter data.
This is useful in cases where the same shader instance is reusable but with different input parameters.
Must be called between calls to bind() and unbind().
Calling this method will invalidate any currently active pass. Must invoke activatePass() after calling this method.
[in] | context | The current draw context |
bool isTransparent | ( | ) | const |
Return whether the shader will render with transparency.
MStatus setIsTransparent | ( | bool | value | ) |
Set whether the shader will render with transparency.
[in] | value | Value to set |
MShaderInstance * clone | ( | ) | const |
Clone the shader.
This will return a new MShaderInstance object which is identical to the existing shader. The new shader is completely independent of the original. Setting parameter values on either shader after calling clone will have no effect on the other.
Using clone can improve performance when many copies of the same shader are needed. When requesting MShaderInstance objects from MShaderManager the shader is recompiled for each request. The clone() method does not cause a recompilation.
MShaderInstance * createShaderInstanceWithColorManagementFragment | ( | const MString & | inputColorSpace | ) |
Return a new shader instance with Color Management fragment added, which is based on the callee.
The callee shader instance is the one used for rendering a render item with image(a MPxNode with image, etc.) The new shader is completely independent of the original shader. Setting parameter values on either shader after calling this function will have no effect on the other. The function won't keep a copy of input parameter.
When the returned new shader instance is no longer needed, MShaderManager::releaseShader() should be called to notify the shader manager that the caller is done with the shader.
[in] | inputColorSpace | The color space the current image is in |
MStatus requiredVertexBuffers | ( | MVertexBufferDescriptorList & | list | ) | const |
Get the vertex buffer descriptors that describe the buffers required by a given shader instance.
The descriptor elements will be appended to the passed list. It is the responsibility of the caller to clear the list if desired before calling this method using the MVertexBufferDescriptorList::clear() method.
[out] | list | List of vertex buffer descriptors |
|
static |
Returns the name of this class.
int annotationAsInt | ( | const MString & | parameterName, |
const MString & | annotationName, | ||
MStatus & | status | ||
) |
Returns annotation value for a given parameter as integer.
[in] | parameterName | The name of the parameter. |
[in] | annotationName | The name of the annotation. |
[in] | status | Reference to a status object to output operation status. |
float annotationAsFloat | ( | const MString & | parameterName, |
const MString & | annotationName, | ||
MStatus & | status | ||
) |
Returns annotation value for a given parameter as float.
[in] | parameterName | The name of the parameter. |
[in] | annotationName | The name of the annotation. |
[in] | status | Reference to a status object to output operation status. |
MString annotationAsString | ( | const MString & | parameterName, |
const MString & | annotationName, | ||
MStatus & | status | ||
) |
Returns annotation value for a given parameter as MString.
[in] | parameterName | The name of the parameter. |
[in] | annotationName | The name of the annotation. |
[in] | status | Reference to a status object to output operation status. |
Returns the semantic associated to a given parameter.
[in] | parameterName | The name of the parameter. |
[in] | status | Reference to a status object to output operation status. |
Returns the default value of a given parameter.
[in] | parameterName | The name of the parameter. |
[in] | status | Reference to a status object to output operation status. |
Returns the resource name of a given texture parameter.
The resource name of a texture parameter can be specified in the effect file using the "ResourceName" annotation. It allows users to define a default texture using an external file. If no resource was defined for a texture, this function returns an empty string.
[in] | parameterName | The name of the texture parameter. |
[in] | status | Reference to a status object to output operation status. |
Returns the UI widget type associated with a given parameter.
The UI widget type can be specified in shader using the "UIWidget" annotation.
[in] | parameterName | The name of the parameter. |
[in] | status | Reference to a status object to output operation status. |
Returns the UI name associated with a given parameter.
The UI name can be specified in shader using the "UIName" annotation.
[in] | parameterName | The name of the parameter. |
[in] | status | Reference to a status object to output operation status. |
MStatus techniqueNames | ( | MStringArray & | techniqueNames | ) | const |
Returns a list of the technique names for the effect.
[out] | techniqueNames | Returns the list of technique names for the effect. |
Returns the value of the current technique annotation as integer.
[in] | annotationName | The name of the technique annotation. |
[in] | status | Reference to a status object to output operation status. |
Returns the value of the current technique annotation as float.
[in] | annotationName | The name of the technique annotation. |
[in] | status | Reference to a status object to output operation status. |
Returns the value of the current technique annotation as MString.
[in] | annotationName | The name of the technique annotation. |
[in] | status | Reference to a status object to output operation status. |
Returns the value of the current technique's pass annotation as int.
[in] | pass | The index of the pass. |
[in] | annotationName | The name of the pass annotation. |
[in] | status | Reference to a status object to output operation status. |
Returns the value of the current technique's pass annotation as float.
[in] | pass | The index of the pass. |
[in] | annotationName | The name of the pass annotation. |
[in] | status | Reference to a status object to output operation status. |
MString passAnnotationAsString | ( | unsigned int | pass, |
const MString & | annotationName, | ||
MStatus & | status | ||
) |
Returns the value of the current technique's pass annotation as MString.
[in] | pass | The index of the pass. |
[in] | annotationName | The name of the pass annotation. |
[in] | status | Reference to a status object to output operation status. |
Write the source of the final OGSFX/HLSL/CgFX effect to a specified file.
Use this for debugging to see how fragments are turned into the final effect for the current drawing API.
Note that the effect will not be written if the effect is not generated from shader fragments or any of the shader fragments is marked as hidden.
[in] | filePath | Path of the file to write the effect source |