An instance of a shader that may be used with Viewport 2.0.
Constructor & Destructor Documentation
OpenMayaRender.MShaderInstance.__init__
(
)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Member Function Documentation
OpenMayaRender.MShaderInstance.activatePass
(
)
activatePass(MDrawContext, int) -> self
Activates the given pass of the shader.
Must be called between calls to bind() and unbind().
OpenMayaRender.MShaderInstance.addInputFragment
(
)
addInputFragment(fragmentName, outputName, inputName, promotedInputName=None) -> self
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.
* fragmentName (string) - The name of a fragment that has been registered with the MFragmentManager.
* outputName (string) - The name of the output on the registered fragment to connect to.
* inputName (string) - The name of the input parameter on the MShaderInstance to connect to.* promotedInputName (string) - The name of the input parameter on the new fragment that will be promoted to replace the input parameter being connected to.
addInputFragmentForMultiParams(fragmentName, uniqueName, outputNames, inputNames, invalidParameterIndices=None, fragmentUsage=MShaderInstance.kPixelShader) -> self
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.
* fragmentName (string) - Name of the input fragment.
* uniqueName (string) - A unique name to prefix names of input parameters on the input fragment.
* outputNames (list of strings) - Names of the output parameters on the input fragment to connect from.
* inputNames (list of strings) - Names of the input parameters on the MShaderInstance to connect to.
* invalidParameterIndices (list of ints) - Optional list to query indices of invalid parameters.
* fragmentUsage (int) - Not implemented.
OpenMayaRender.MShaderInstance.addOutputFragment
(
)
addOutputFragment(fragmentName, inputName) -> self
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.
* fragmentName (string) - The name of a fragment that has been registered with the MFragmentManager.
* inputName (string) - The name of the input parameter on the fragment to connect the shaders output to.
OpenMayaRender.MShaderInstance.annotation
(
)
annotation(parameterName, annotationName) -> int / float / string
Returns the value of a named parameter annotation.
* parameterName (string) - The name of the parameter.
* annotationName (string) - The name of the annotation.
OpenMayaRender.MShaderInstance.bind
(
)
bind(MDrawContext) -> self
Binds the shader instance to the draw context, so that it is the active shader.
OpenMayaRender.MShaderInstance.clone
(
)
clone() -> MShaderInstance
Clone the shader. This will return a new MShaderInstance object which is identical to the existing shader.
createShaderInstanceWithColorManagementFragment(inputColorSpace) -> MShaderInstance
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.
* inputColorSpace (string) - The color space the current image is in
OpenMayaRender.MShaderInstance.getArraySize
(
)
getArraySize(string) -> int
Return the size of an array if it is an array. Returns 0 if it is not an array
OpenMayaRender.MShaderInstance.getPassCount
(
)
getPassCount(MDrawContext) -> int
Returns the number of draw passes defined by the shader.
None if the shader instance or draw context was invalid.
OpenMayaRender.MShaderInstance.isArrayParameter
(
)
isArrayParameter(string) -> bool
Determine whether the named parameter is an array.
OpenMayaRender.MShaderInstance.isTransparent
(
)
isTransparent() -> bool
Return whether the shader will render with transparency.
OpenMayaRender.MShaderInstance.isVaryingParameter
(
)
isVaryingParameter(string) -> bool
Return the true if a named parameter's values vary per vertex.
parameterDefaultValue(parameterName) -> bool / int / float / tuple of float
Returns the default value of named parameter, None if no default value.
OpenMayaRender.MShaderInstance.parameterList
(
)
parameterList() -> list of string
Get the names of all parameters that are settable on this shader instance.
OpenMayaRender.MShaderInstance.parameterSemantic
(
)
parameterSemantic(parameterName) -> string
Returns the semantic associated to a named parameter.
OpenMayaRender.MShaderInstance.parameterType
(
)
parameterType(string) -> int
Get the type of the named parameter, returns kInvalid if parameter is not found.
OpenMayaRender.MShaderInstance.passAnnotation
(
)
passAnnotation(pass, annotationName) -> int / float / string
Returns the value of the current technique's pass annotation.
* pass (int) - The index of the pass.
* annotationName (string) - The name of the pass annotation.
OpenMayaRender.MShaderInstance.postDrawCallback
(
)
postDrawCallback() -> function/None
Returns the post-draw callback function set for the this shader instance.
Returns None if the callback function is not set or is not a python function.
OpenMayaRender.MShaderInstance.preDrawCallback
(
)
preDrawCallback() -> function/None
Returns the pre-draw callback function set for the this shader instance.
Returns None if the callback function is not set or is not a python function.
OpenMayaRender.MShaderInstance.renameParameter
(
)
renameParameter(parameterName, string) -> self
Rename a named parameter.
requiredVertexBuffers(MVertexBufferDescriptorList) -> self
Get the vertex buffer descriptors that describe the buffers required
by a given shader instance.
OpenMayaRender.MShaderInstance.resourceName
(
)
resourceName(parameterName) -> string
Returns the resource name of a named 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.
OpenMayaRender.MShaderInstance.semantic
(
)
semantic(string) -> string
Return the semantic for a named parameter.
OpenMayaRender.MShaderInstance.setArrayParameter
(
)
setArrayParameter(parameterName, sequence of bool, int) -> self
setArrayParameter(parameterName, sequence of int, int) -> self
setArrayParameter(parameterName, sequence of float, int) -> self
setArrayParameter(parameterName, sequence of MMatrix, int) -> self
Set the value of a named array parameter.
OpenMayaRender.MShaderInstance.setAsVarying
(
)
setAsVarying(parameterName, bool) -> self
Set whether the named parameter's values will vary per vertex.
OpenMayaRender.MShaderInstance.setIsTransparent
(
)
setIsTransparent(bool) -> self
Set whether the shader will render with transparency.
OpenMayaRender.MShaderInstance.setParameter
(
)
setParameter(parameterName, bool) -> self
setParameter(parameterName, int) -> self
setParameter(parameterName, float) -> self
setParameter(parameterName, list of float) -> self
setParameter(parameterName, MFloatVector) -> self
setParameter(parameterName, MMatrix) -> self
setParameter(parameterName, MFloatMatrix) -> self
setParameter(parameterName, MTexture) -> self
setParameter(parameterName, MRenderTarget) -> self
setParameter(parameterName, MSamplerState) -> self
Set the value of the named parameter.
OpenMayaRender.MShaderInstance.setSemantic
(
)
setSemantic(parameterName, string) -> self
Set the semantic of a named parameter.
techniqueAnnotation(annotationName) -> int / float / string
Returns the value of the current technique annotation.
* annotationName (string) - The name of the technique annotation.
OpenMayaRender.MShaderInstance.techniqueNames
(
)
techniqueNames() -> list of strings
Returns a list of the technique names for the effect.
OpenMayaRender.MShaderInstance.uiName
(
)
uiName(parameterName) -> string
Returns the UI name associated with a named parameter.
The UI name can be specified in shader using the 'UIName' annotation.
The UI name can be used to specify the name that will be displayed in the Attribute Editor.
OpenMayaRender.MShaderInstance.uiWidget
(
)
uiWidget(parameterName) -> string
Returns the UI widget type associated with a named parameter.
The UI widget type can be specified in shader using the 'UIWidget' annotation.The UI widget can be used to specify which widget should be used to control the parameter in the Attribute Editor.
OpenMayaRender.MShaderInstance.unbind
(
)
unbind(MDrawContext) -> self
Unbinds the shader instance from the draw context.
OpenMayaRender.MShaderInstance.updateParameters
(
)
updateParameters(MDrawContext) -> self
Updates the bound shader instance with the current parameter data.
writeEffectSourceToFile(filePath) -> self
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.