Python API 2.0 Reference
OpenMayaUI.MPxHardwareShader Class Reference
+ Inheritance diagram for OpenMayaUI.MPxHardwareShader:

Public Member Functions

def __init__ ()
 
def getAvailableImages ()
 
def profile ()
 
def renderImage ()
 
def renderSwatchImage ()
 
def setUniformParameters ()
 
def setVaryingParameters ()
 
def transparencyOptions ()
 
- Public Member Functions inherited from OpenMaya.MPxNode
def __init__ ()
 
def addExternalContentForFileAttr ()
 
def compute ()
 
def configCache ()
 
def connectionBroken ()
 
def connectionMade ()
 
def copyInternalData ()
 
def dependsOn ()
 
def doNotWrite ()
 
def existWithoutInConnections ()
 
def existWithoutOutConnections ()
 
def forceCache ()
 
def getCacheSetup ()
 
def getExternalContent ()
 
def getFilesToArchive ()
 
def getInternalValue ()
 
def getInternalValueInContext ()
 
def hasInvalidationRangeTransformation ()
 
def internalArrayCount ()
 
def isAbstractClass ()
 
def isPassiveOutput ()
 
def legalConnection ()
 
def legalDisconnection ()
 
def name ()
 
def passThroughToMany ()
 
def passThroughToOne ()
 
def postConstructor ()
 
def postEvaluation ()
 
def preEvaluation ()
 
def setDependentsDirty ()
 
def setDoNotWrite ()
 
def setExistWithoutInConnections ()
 
def setExistWithoutOutConnections ()
 
def setExternalContent ()
 
def setExternalContentForFileAttr ()
 
def setInternalValue ()
 
def setInternalValueInContext ()
 
def setMPSafe ()
 
def shouldSave ()
 
def thisMObject ()
 
def transformInvalidationRange ()
 
def type ()
 
def typeId ()
 
def typeName ()
 

Static Public Member Functions

def __new__ ()
 
def findResource ()
 
def getHardwareShader ()
 
- Static Public Member Functions inherited from OpenMaya.MPxNode
def __new__ ()
 
def addAttribute ()
 
def attributeAffects ()
 
def inheritAttributesFrom ()
 

Static Public Attributes

int kIsTransparent = 1
 
int kNoTransparencyFrontBackCull = 2
 
int kNoTransparencyPolygonSort = 4
 
 outColor = <OpenMaya.MObjectobject>
 
 outColorB = <OpenMaya.MObjectobject>
 
 outColorG = <OpenMaya.MObjectobject>
 
 outColorR = <OpenMaya.MObjectobject>
 
- Static Public Attributes inherited from OpenMaya.MPxNode
int kAssembly = 22
 
int kBlendShape = 25
 
int kCameraSetNode = 16
 
int kClientDeviceNode = 20
 
int kConstraintNode = 17
 
int kDeformerNode = 2
 
int kDependNode = 0
 
int kEmitterNode = 6
 
int kEvaluatedDirectly = 1
 
int kEvaluatedIndirectly = 0
 
int kFieldNode = 5
 
int kFluidEmitterNode = 13
 
int kGeometryFilter = 24
 
int kHardwareShader = 9
 
int kHwShaderNode = 10
 
int kIkSolverNode = 8
 
int kImagePlaneNode = 14
 
int kLast = 26
 
int kLeaveDirty = 2
 
int kLocatorNode = 1
 
int kManipContainer = 3
 
int kManipulatorNode = 18
 
int kMotionPathNode = 19
 
int kObjectSet = 12
 
int kParticleAttributeMapperNode = 15
 
int kPostEvaluationTypeLast = 3
 
int kSkinCluster = 23
 
int kSpringNode = 7
 
int kSurfaceShape = 4
 
int kThreadedDeviceNode = 21
 
int kTransformNode = 11
 

Detailed Description

Base class for user defined hardware shaders.

Method resolution order:
-   MPxHardwareShader
-   OpenMaya.MPxNode
-   builtins.object

Constructor & Destructor Documentation

def OpenMayaUI.MPxHardwareShader.__init__ ( )
Initialize self.  See help(type(self)) for accurate signature.

Member Function Documentation

def OpenMayaUI.MPxHardwareShader.__new__ ( )
static
Create and return a new object.  See help(type) for accurate signature.
def OpenMayaUI.MPxHardwareShader.findResource ( )
static
findResource(name, shaderPath) -> string

This is a static utility to find the full path to a shader resource (typically a texture). This method will search the list of paths in the MAYA_HW_SHADER_RESOURCE_PATH environment variable, resolving relative paths based on the directory containing the shader.

* name (string) - The name of the resource to look for (e.g. 'normals.dds')
* shaderPath (string) - The full path to the current shader (e.g. 'C:/shaders/myshader.fx')


Return the full path of the resource (e.g. 'C:/shaders/textures/normals.dds').
def OpenMayaUI.MPxHardwareShader.getAvailableImages ( )
getAvailableImages(context, uvSetName) -> list of string/None

Maya will call this method to get your shader's list of images which are available for use in the UV texture editor for the UV set specified. Typically, this list will include one entry for each texture using the specified UV set, however, your shader is free to return as many images as you wish (for example, blending between two textures, texture alpha masks, artificially shaded views of bump/normal maps, etc). Your shader's renderImage() method will be used to render the images themselves.

* context (ShaderContext) - Context of the draw request (e.g. the surface being shaded, shading engine making the request)
* uvSetName (string) - Name of a UV set the channel list should be filtered against.

Returns the names of the images this shader defines which are valid for the uvSetName specified.
Returns None if method is not implemented : Use the default behaviour.
def OpenMayaUI.MPxHardwareShader.getHardwareShader ( )
static
getHardwareShader(object) -> TODO

This is a static convenience method to be able to get an MPxHardwareShader from an MObject provided by a swatch generator class (Class derived from MSwatchRenderRegister).

* object (MObject) - The object to examine.

Return a MPxHardwareShader. If the method failed for any reason then None will be returned.
def OpenMayaUI.MPxHardwareShader.profile ( )
profile() -> MRenderProfile

Override this method to specify the renderers your shader supports. If this method is not overridden, Maya will assume your shader supports only Maya's iternal OpenGL based renderer.

Note that this method is called inside the rendering loop and as such, you should make this method as fast as possible - typically just returning a static/precalculated value.

Return a reference to the render profile for this Shader. Your shader class should create this once (usually for the whole class) and return the same object each time this method is called.
def OpenMayaUI.MPxHardwareShader.renderImage ( )
renderImage(context, imageName, region, parameters) -> [int, int]/None
renderImage(context, uiDrawManager, imageName, region, parameters) -> [int, int]/None

This method allows you to to render the background image used for this shader in the UV texture editor. The image requested will be one of the image names returned by your shader's getAvailableImages() method.

The implementation must return the dimensions of the image in the 'imageWidth' and 'imageHeight' parameters so that Maya can perform pixel snapping and other resolution-dependent operations.

The implementation can assume OpenGL context, model view projection matrix, and texture transformations have already been set. A default color of white will be set, however you are free to change this. The magnification filter will be set to either point or bilinear based on user configuration and should not be modified. The values of GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T are undefined on entry, and your implementation is responsible for setting them to appropriate values (e.g. GL_REPEAT).

The arguments contain the name of the image to render, and the vertex and texture coordinate values to use at each corner of the rectangular image being rendered. Your implementation is responsible for restoring the original the value of any OpenGL state that is modified.

* context (ShaderContext) - Context of the draw request (e.g. the surface being shaded, shading engine making the request)
* imageName (string) - Name of the image to render. This corresponds to one of the image names returned by your shader's getAvailableImages() method.
* region (float[2][2]) - Rectangular region to be rendered. The values of this parameter should be used to populate the vertex and texture coordinates of the rectangle being rendered.
* parameters (RenderParamters) - Additional parameters on how to render the image. The values reflect the image settings of the UV editor.

A second version with the uiDrawManager parameter allows you to to render the background image used for this shader in the UV texture editor in viewport 2.0.

* uiDrawManager (MUIDrawManager) - The UI draw manager, it can be used to draw some simple geometry

Returns None if method is not implemented : No rendering will occur.
def OpenMayaUI.MPxHardwareShader.renderSwatchImage ( )
renderSwatchImage(image) -> self

If the shader specifies to override swatch rendering, then this method must be overridden in order to draw anything into a swatch.

The shader will only draw a swatch if it has been registered to do so, by providing a valid classification during MFnPlugin::registerNode(). The shader should provide a classification that defines a swatch rendering node such as : "shader/surface/utility/:drawdb/shader/surface/myCustomShader:swatch/myCustomShaderSwatchGenerator" and have "myCustomShaderSwatchGenerator" registered has a swatch renderer : MSwatchRenderRegister.registerSwatchRender("myCustomShaderSwatchGenerator", MHWShaderSwatchGenerator.createObj );

The default implementation is to draw nothing. The basic logic to draw a swatch is as follows:

  Determine the size of the swatch required. This is the dimensions of the MImage passed in as an argument. The pixels for the MImage will have been pre-allocated. The format of the pixels is 32-bit R,G,B,A, with 8-bits per channel.
  Either use an offscreen "swatch context" provided to you or use your own offscreen context. The provided context is available via the MHardwareRenderer class method makeSwatchContextCurrent(). Note that the swatch context may be smaller than the desired image size. In this case the rendering dimensions will be clamped.
  Either use swatch geometry provided to you, or use your own swatch geometry. The provided geometry is available via the method MHardwareRenderer::referenceDefaultGeometry(). The possible "default" geometries are either a sphere, cube or plane.
  Either use the provided "default" light and "default" camera or set up your own. Use the methods (getSwatchOrthoCameraSetting(), getSwatchLightDirection()) on MHardwareRenderer to get these defaults.
  Read back the swatch context into the provided MImage. The convenience method MHardwareRenderer::readSwatchContextPixels() can be used. By default the format of the MImage and the swatch context are the same, so the user does not need to worry about this. The context will read into the pre-allocated MImage pixels.
  Unreference any swatch geometry used for rendering using MHardwareRenderer::dereferenceGeometry().

* image [IN/OUT] (MImage) - Image object to which this method must write the rendered swatch. On input the image's dimensions are already set and pixel storage already allocated.

Returns None if method is not implemented : No rendering will occur.
def OpenMayaUI.MPxHardwareShader.setUniformParameters ( )
setUniformParameters(parameters, remapCurrentValues=True, dagModifier=None) -> self

Call this method to set the list of uniform parameters this shader uses. Once set, you can use these parameters to access the cached values of shader parameters, including testing when the value has been updated (to minimise the shader state changes). When using this method to manage uniform parameters, Maya will handle the underlyintg attributes, serialization and user interface for you.It is important to call this method whenever the shader parameters are modified (including at load time).This is an optional method - shader implementations are still free to manage uniform (i.e. shader-level) parameters independently if they wish.* parameters (MUniformParameterList) - the list of uniform parameters for this shader
* remapCurrentValues (bool) - if True (the default), Maya will attempt to initialise the value of new parameters based on any equivalently named parameters that currently exist on the node. Otherwise, the parameters will be setup using default values. Unless you wish to forcibly reset parameter values, the default value of True should be used.
* dagModifier (MDagModifier) - an optional DG modifier to use when managing the attributes used to represent the geometry parameters on this shader.
def OpenMayaUI.MPxHardwareShader.setVaryingParameters ( )
setVaryingParameters(parameters, remapCurrentValues=True, dagModifier=None) -> self

Call this method to set the list of varying parameters this shader uses. Once set, you can use these parameters directly to access geometry data for surfaces being shaded. When using this method to manage shader varying parameters, there is no need to override populateRequirements or handle the node interface as Maya will handle parameter setup, presentation and configuration for you.

It is important to call this method whenever the shader parameters are modified (including at load time).

This is an optional method - shader implementations are still free to manage geometry parameters independently if they wish.

* parameters (MUniformParameterList) - the list of varying parameters for this shader
* remapCurrentValues (bool) - if True (the default), Maya will attempt to initialise the value of new parameters based on any equivalently named parameters that currently exist on the node. Otherwise, the parameters will be setup using default values. Unless you wish to forcibly reset parameter values, the default value of True should be used.
* dagModifier (MDagModifier) - an optional DG modifier to use when managing the attributes used to represent the geometry parameters on this shader.
def OpenMayaUI.MPxHardwareShader.transparencyOptions ( )
transparencyOptions() -> int

This method returns transparency options for usage as hints for Maya's internal draw during a given rendering pass. Parameters are returned via an integer containing masked out bits. By default the mask is set to 0, meaning that the drawing should be treated as regular opaque object drawing. This will generally mean one call per draw pass.

Options to control transparency are specified by returning one or more masks specified by the following values :
  - kIsTransparent : Draw as a transparent object. If no transparency overrides are specified, then control of how to draw during a given pass is determined internally by Maya's refresh algorithm, and options the user can set per modelling viewport.
  - kNoTransparencyFrontBackCull : When kisTransparent is set and this flag is set, do not perform transparency drawing using the internal 2-pass front-face + back-face culling algorithm.
  - kNoTransparencyPolygonSort : When kisTransparent is set and this flag is set, do not perform transparency drawing using the internal 2-pass drawing of back-to-front sorted triangles.