MPxHardwareShader Class Reference

#include <MPxHardwareShader.h>

Class Description

Base class for user defined hardware shaders.

MPxHardwareShader allows the creation of user-defined hardware shaders. A hardware shader allows the plug-in writer to control the on-screen display of an object in Maya.

You must derive a hardware shader node from MPxHardwareShader for it to have any affect on the on-screen display at all. In addition to their affect on the on-screen display of objects, hardware shaders function as surface shader nodes. This allows you to connect any shading network up to the hardware shader's outColor attribute to handle the shading during a software render.

To create a working hardware shader, derive from this class and override the render() and optionally the populateRequirements() methods. The other methods of the parent class MPxNode may also be overridden to perform dependency node capabilities.

NOTE: Plug-in hardware shaders are fully supported for polygonal mesh shapes. NURBS surfaces are only supported in the High Quality Interactive viewport and Hardware Renderer.

+ Examples:
+ Inheritance diagram for MPxHardwareShader:

Classes

struct  RenderParameters
 Provides information on how to render the image. More...
 
struct  ShaderContext
 Provides contextual information about the current invocation of the shader. More...
 

Public Types

enum  TransparencyOptions { kIsTransparent = 0x0001, kNoTransparencyFrontBackCull = 0x0002, kNoTransparencyPolygonSort = 0x0004 }
 Transparency option bitmasks. More...
 
- Public Types inherited from MPxNode
enum  Type {
  kDependNode, kLocatorNode, kDeformerNode, kManipContainer,
  kSurfaceShape, kFieldNode, kEmitterNode, kSpringNode,
  kIkSolverNode, kHardwareShader, kHwShaderNode, kTransformNode,
  kObjectSet, kFluidEmitterNode, kImagePlaneNode, kParticleAttributeMapperNode,
  kCameraSetNode, kConstraintNode, kManipulatorNode, kMotionPathNode,
  kClientDeviceNode, kThreadedDeviceNode, kAssembly, kSkinCluster,
  kGeometryFilter, kBlendShape, kLast
}
 Defines the type of node. More...
 
enum  SchedulingType {
  kParallel, kSerial, kGloballySerial, kUntrusted ,
  kDefaultScheduling = kSerial, kSerialize = kSerial, kGloballySerialize = kGloballySerial
}
 Defines the degree of parallelism of a node. More...
 

Public Member Functions

 MPxHardwareShader ()
 Class constructor.
 
virtual ~MPxHardwareShader ()
 Class destructor.
 
virtual MPxNode::Type type () const
 This method returns the type of the node. More...
 
MStatus setVaryingParameters (const MVaryingParameterList &parameters, bool remapCurrentValues=true, MDagModifier *dagModifier=NULL)
 Call this method to set the list of varying parameters this shader uses. More...
 
MStatus setUniformParameters (const MUniformParameterList &parameters, bool remapCurrentValues=true, MDagModifier *dagModifier=NULL)
 Call this method to set the list of uniform parameters this shader uses. More...
 
virtual MStatus render (MGeometryList &iterator)
 Override this method to render geometry using your hardware shader. More...
 
virtual unsigned int transparencyOptions ()
 This method returns transparency options for usage as hints for Maya's internal draw during a given rendering pass. More...
 
virtual const MRenderProfileprofile ()
 Override this method to specify the renderers your shader supports. More...
 
virtual MStatus populateRequirements (const MPxHardwareShader::ShaderContext &context, MGeometryRequirementsLegacy &requirements)
 This method is not available in Python. More...
 
virtual MStatus getAvailableImages (const MPxHardwareShader::ShaderContext &context, const MString &uvSetName, MStringArray &imageNames)
 This method is not available in Python. More...
 
virtual MStatus renderImage (const MPxHardwareShader::ShaderContext &context, const MString &imageName, floatRegion region, int &imageWidth, int &imageHeight)
 This method is not available in Python. More...
 
virtual MStatus renderImage (const MPxHardwareShader::ShaderContext &context, const MString &imageName, floatRegion region, const MPxHardwareShader::RenderParameters &parameters, int &imageWidth, int &imageHeight)
 This method is not available in Python. More...
 
virtual MStatus renderImage (const MPxHardwareShader::ShaderContext &context, MHWRender::MUIDrawManager &uiDrawManager, const MString &imageName, floatRegion region, const MPxHardwareShader::RenderParameters &parameters, int &imageWidth, int &imageHeight)
 This method is not available in Python. More...
 
virtual MStatus renderSwatchImage (MImage &image)
 If the shader specifies to override swatch rendering, then this method must be overridden in order to draw anything into a swatch. More...
 
- Public Member Functions inherited from MPxNode
 MPxNode ()
 Constructor. More...
 
virtual ~MPxNode ()
 Destructor.
 
virtual void postConstructor ()
 Post constructor. More...
 
virtual MStatus compute (const MPlug &, MDataBlock &)
 This method should be overridden in user defined nodes. More...
 
virtual bool getInternalValue (const MPlug &, MDataHandle &)
 This method is overridden by nodes that store attribute data in some internal format. More...
 
virtual bool setInternalValue (const MPlug &, const MDataHandle &)
 This method is overridden by nodes that store attribute data in some internal format. More...
 
virtual int internalArrayCount (const MPlug &) const
 This method is overridden by nodes that have internal array attributes which are not stored in Maya's datablock. More...
 
virtual void copyInternalData (MPxNode *)
 This method is overridden by nodes that store attribute data in some internal format. More...
 
virtual MStatus legalConnection (const MPlug &, const MPlug &, bool asSrc, bool &isLegal) const
 This method allows you to check for legal connections being made to attributes of this node. More...
 
virtual MStatus legalDisconnection (const MPlug &, const MPlug &, bool asSrc, bool &isLegal) const
 This method allows you to check for legal disconnections being made to attributes of this node. More...
 
virtual MStatus setDependentsDirty (const MPlug &plug, MPlugArray &plugArray)
 This method can be overridden in user defined nodes to specify which plugs should be set dirty based upon an input plug {plugBeingDirtied} which Maya is marking dirty. More...
 
virtual MStatus preEvaluation (const MDGContext &context, const MEvaluationNode &evaluationNode)
 Prepare a node's internal state for threaded evaluation. More...
 
virtual MStatus postEvaluation (const MDGContext &context, const MEvaluationNode &evaluationNode, PostEvaluationType evalType)
 Clean up node's internal state after threaded evaluation. More...
 
virtual SchedulingType schedulingType () const
 When overridden this method controls the degree of parallelism supported by the node during threaded evaluation. More...
 
virtual MStatus connectionMade (const MPlug &, const MPlug &, bool asSrc)
 This method gets called when connections are made to attributes of this node. More...
 
virtual MStatus connectionBroken (const MPlug &, const MPlug &, bool asSrc)
 This method gets called when connections are broken with attributes of this node. More...
 
virtual MStatus dependsOn (const MPlug &, const MPlug &, bool &depends) const
 This method may be overridden by the user defined node. More...
 
virtual bool isPassiveOutput (const MPlug &) const
 This method may be overridden by the user defined node if it wants to provide output attributes which do not prevent value modifications to the destination attribute. More...
 
virtual MStatus shouldSave (const MPlug &, bool &isSaving)
 This method may be overridden by the user defined node. More...
 
virtual MPlug passThroughToOne (const MPlug &) const
 This method may be overridden by nodes that have a one-to-one relationship between an input attribute and a corresponding output attribute. More...
 
virtual bool passThroughToMany (const MPlug &, MPlugArray &) const
 This method is overridden by nodes that want to control the traversal behavior of some Maya search algorithms which traverse the history/future of shape nodes looking for directly related nodes. More...
 
virtual bool isAbstractClass () const
 Override this class to return true if this node is an abstract node. More...
 
virtual MStringArray getFilesToArchive (bool shortName=false, bool unresolvedName=false, bool markCouldBeImageSequence=false) const
 Use this method to return all external files used by this node. More...
 
virtual void getExternalContent (MExternalContentInfoTable &table) const
 Returns the external content (files) that this node depends on. More...
 
bool addExternalContentForFileAttr (MExternalContentInfoTable &, const MObject &attr) const
 Adds content info to the specified table from a file path attribute. More...
 
bool setExternalContentForFileAttr (const MObject &attr, const MExternalContentLocationTable &)
 Sets content info in the specified attribute from the table. More...
 
virtual void setExternalContent (const MExternalContentLocationTable &)
 Changes the location of external content in batch. More...
 
virtual MTypeId typeId () const
 Returns the TYPEID of this node. More...
 
virtual MString typeName () const
 Returns the type name of this node. More...
 
virtual MString name () const
 Returns the name of this particular instance of this class. More...
 
virtual MObject thisMObject () const
 Returns the MObject associated with this user defined node. More...
 
virtual MStatus setExistWithoutInConnections (bool flag)
 This method specifies whether or not the node can exist without input connections. More...
 
virtual bool existWithoutInConnections (MStatus *ReturnStatus=NULL) const
 Determines whether or not this node can exist without input connections. More...
 
virtual MStatus setExistWithoutOutConnections (bool flag)
 This method specifies whether or not the node can exist without output connections. More...
 
virtual bool existWithoutOutConnections (MStatus *ReturnStatus=NULL) const
 Determines whether or not this node can exist without output connections. More...
 
MDataBlock _forceCache (const MDGContext &)
 This method is obsolete. More...
 
virtual bool getInternalValueInContext (const MPlug &, MDataHandle &, MDGContext &)
 This method is obsolete. More...
 
virtual bool setInternalValueInContext (const MPlug &, const MDataHandle &, MDGContext &)
 This method is obsolete. More...
 
virtual int internalArrayCount (const MPlug &, const MDGContext &) const
 This method is obsolete. More...
 

Static Public Member Functions

static MPxHardwareShadergetHardwareShaderPtr (MObject &object)
 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). More...
 
static MString findResource (const MString &name, const MString &shaderPath, MStatus *status=NULL)
 This is a static utility to find the full path to a shader resource (typically a texture). More...
 
static const char * className ()
 Returns the name of this class. More...
 
- Static Public Member Functions inherited from MPxNode
static MStatus addAttribute (const MObject &attr)
 This method adds a new attribute to a user defined node type during the type's initialization. More...
 
static MStatus inheritAttributesFrom (const MString &parentClassName)
 This method allows a class of plugin node to inherit all of the attributes of a second class of plugin node. More...
 
static MStatus attributeAffects (const MObject &whenChanges, const MObject &isAffected)
 This method specifies that a particular input attribute affects a specific output attribute. More...
 
static const char * className ()
 Returns the name of this class. More...
 

Static Public Attributes

static MObject outColor
 output color value
 
static MObject outColorR
 output color red
 
static MObject outColorG
 output color green
 
static MObject outColorB
 output color blue
 
- Static Public Attributes inherited from MPxNode
static MObject message
 message attribute
 
static MObject isHistoricallyInteresting
 is historically interesting attribute
 
static MObject caching
 caching attribute
 
static MObject state
 state attribute
 
static MObject frozen
 frozen attribute
 

Additional Inherited Members

- Protected Member Functions inherited from MPxNode
virtual MDataBlock forceCache ()
 USE _forceCache() IN SCRIPT. More...
 
virtual void setMPSafe (bool flag)
 USE _setMPSafe() IN SCRIPT. More...
 
virtual MStatus setDoNotWrite (bool flag)
 USE _setDoNotWrite() IN SCRIPT. More...
 
virtual bool doNotWrite (MStatus *ReturnStatus=NULL) const
 USE _doNotWrite() IN SCRIPT. More...
 
virtual MDataBlock forceCache (const MDGContext &)
 This method is obsolete. More...
 

Member Enumeration Documentation

Transparency option bitmasks.

Enumerator
kIsTransparent 

When set means draw transparent.

kNoTransparencyFrontBackCull 

When set means ignore front back cull.

kNoTransparencyPolygonSort 

When set means ignore polygon sorting.

Member Function Documentation

MPxNode::Type type ( ) const
virtual

This method returns the type of the node.

This method should not be overridden by the user. It will return MPxNode::kHardwareShader.

Returns
The type of node

Reimplemented from MPxNode.

MStatus setVaryingParameters ( const MVaryingParameterList parameters,
bool  remapCurrentValues = true,
MDagModifier dagModifier = NULL 
)

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
[in]parametersthe list of varying parameters for this shader
[in]remapCurrentValuesif 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.
[in]dagModifieran optional DG modifier to use when managing the attributes used to represent the geometry parameters on this shader.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.
MStatus setUniformParameters ( const MUniformParameterList parameters,
bool  remapCurrentValues = true,
MDagModifier dagModifier = NULL 
)

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
[in]parametersthe list of uniform parameters for this shader
[in]remapCurrentValuesif 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.
[in]dagModifieran optional DG modifier to use when managing the attributes used to represent the geometry parameters on this shader.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.
MStatus render ( MGeometryList iterator)
virtual

Override this method to render geometry using your hardware shader.

It is important to note that you can only access surface data (e.g. uv sets) that you specified in populateRequirements. Any data you did not ask for is unlikely to be available in the geometry cache passed to you.

For example:

for( ; !iter.isDone(); iter.next())
{
MGeometry& geometry = iter.geometry( MGeometryList::kMatrices | MGeometryList::kCulling);
glVertexPointer( 3, GL_FLOAT, 0, geometry.position().data());
glNormalPointer( GL_FLOAT, 0, geometry.normal().data());
MGeometryPrimitive primitives = geometry.primitiveArray( 0);
glDrawElements( GL_TRIANGLES, primitives.elementCount(), GL_UNSIGNED_INT, primitives.data());
}
Parameters
[in]iteratoran iterator containing the geometry items you need to render.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.
+ Examples:
unsigned int transparencyOptions ( )
virtual

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 TransparencyOptions enumeration :

  • 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.

Note : Setting the "hasTransparency()" method to true will override this method. This is for backward compatibility with behaviour on existing hardware shader nodes. It is recommended that shaders use the "transparencyOptions()" override, and not longer use the older "hasTransparency()" override from their shader classes.

Returns
Integer containing the appropriate options set via masks.
+ Examples:
const MRenderProfile & profile ( )
virtual

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.

Returns
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.
+ Examples:
MStatus populateRequirements ( const MPxHardwareShader::ShaderContext context,
MGeometryRequirementsLegacy requirements 
)
virtual

This method is not available in Python.

Override this method to let Maya know what surface data (e.g.

positions, normals, uv sets, tangents, binormals, etc) your shader needs in order to render the specified geometry. This is the only data your shader will be able to access when rendering the geometry. For example, if your shader needs uv set "foo" to render a texture, you must include that here before trying to use it in your render method.

The default implementation (in MPxHardwareShader) sets up the requirements for any public MVaryingParameters you have configured on this shader. If you override this method and use MVaryingParameters, you should make a call into the base class method as part of your implementation of the method.

Parameters
[in]contextContext of the draw request (e.g. the surface being shaded, shading engine making the request).
[out]requirementsThe requirements structure you need to fill in.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.
MStatus getAvailableImages ( const MPxHardwareShader::ShaderContext context,
const MString uvSetName,
MStringArray imageNames 
)
virtual

This method is not available in Python.

Maya will call this method to get your shader's list of images which are available for use in the UV 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.

Parameters
[in]contextContext of the draw request (e.g. the surface being shaded, shading engine making the request).
[in]uvSetNameName of a UV set the channel list should be filtered against.
[out]imageNamesArray in which to return the names of the images this shader defines which are valid for the uvSetName specified.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.
  • MS::kNotImplemented Use the default behaviour.
+ Examples:
MStatus renderImage ( const MPxHardwareShader::ShaderContext context,
const MString imageName,
floatRegion  region,
int &  imageWidth,
int &  imageHeight 
)
virtual

This method is not available in Python.

This method is obsolete.

Deprecated:
Use renderImage() that provides RenderParameters instead.

This method allows you to to render the background image used for this shader in the UV 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.

For example:

glPushAttrib( <GL bits your shader modifies> );
glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT);
... setup material here ...
glBegin( GL_QUADS);
glTexCoord2f(region[0][0], region[0][1]);
glVertex2f(region[0][0], region[0][1]);
glTexCoord2f(region[0][0], region[1][1]);
glVertex2f(region[0][0], region[1][1]);
glTexCoord2f(region[1][0], region[1][1]);
glVertex2f(region[1][0], region[1][1]);
glTexCoord2f(region[1][0], region[0][1]);
glVertex2f(region[1][0], region[0][1]);
glEnd();
glPopAttrib();
glPopClientAttrib();
Parameters
[in]contextContext of the draw request (e.g. the surface being shaded, shading engine making the request).
[in]imageNameName of the image to render. This corresponds to one of the image names returned by your shader's getAvailableImages() method.
[in]regionRectangular region to be rendered. The values of this parameter should be used to populate the vertex and texture coordinates of the rectangle being rendered.
[out]imageWidthNative width (e.g. texture pixel width) of the image. This should be for the entire image, not just the portion within 'region'.
[out]imageHeightNative height (e.g. texture pixel height) of the image. This should be for the entire image, not just the portion within 'region'.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.
+ Examples:
MStatus renderImage ( const MPxHardwareShader::ShaderContext context,
const MString imageName,
floatRegion  region,
const MPxHardwareShader::RenderParameters parameters,
int &  imageWidth,
int &  imageHeight 
)
virtual

This method is not available in Python.

This method allows you to to render the background image used for this shader in the UV 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.

For example:

glPushAttrib( <GL bits your shader modifies> );
glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT);
... setup material here ...
glBegin( GL_QUADS);
glTexCoord2f(region[0][0], region[0][1]);
glVertex2f(region[0][0], region[0][1]);
glTexCoord2f(region[0][0], region[1][1]);
glVertex2f(region[0][0], region[1][1]);
glTexCoord2f(region[1][0], region[1][1]);
glVertex2f(region[1][0], region[1][1]);
glTexCoord2f(region[1][0], region[0][1]);
glVertex2f(region[1][0], region[0][1]);
glEnd();
glPopAttrib();
glPopClientAttrib();
Parameters
[in]contextContext of the draw request (e.g. the surface being shaded, shading engine making the request).
[in]imageNameName of the image to render. This corresponds to one of the image names returned by your shader's getAvailableImages() method.
[in]regionRectangular region to be rendered. The values of this parameter should be used to populate the vertex and texture coordinates of the rectangle being rendered.
[in]parametersAdditional parameters on how to render the image. The values reflect the image settings of the UV editor.
[out]imageWidthNative width (e.g. texture pixel width) of the image. This should be for the entire image, not just the portion within 'region'.
[out]imageHeightNative height (e.g. texture pixel height) of the image. This should be for the entire image, not just the portion within 'region'.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.
MStatus renderImage ( const MPxHardwareShader::ShaderContext context,
MHWRender::MUIDrawManager uiDrawManager,
const MString imageName,
floatRegion  region,
const MPxHardwareShader::RenderParameters parameters,
int &  imageWidth,
int &  imageHeight 
)
virtual

This method is not available in Python.

This method allows you to to render the background image used for this shader in the UV editor in viewport 2.0.

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.

Parameters
[in]contextContext of the draw request (e.g. the surface being shaded, shading engine making the request).
[in]uiDrawManagerThe UI draw manager, it can be used to draw some simple geometry
[in]imageNameName of the image to render. This corresponds to one of the image names returned by your shader's getAvailableImages() method.
[in]regionRectangular region to be rendered. The values of this parameter should be used to populate the vertex and texture coordinates of the rectangle being rendered.
[in]parametersAdditional parameters on how to render the image. The values reflect the image settings of the UV editor.
[out]imageWidthNative width (e.g. texture pixel width) of the image. This should be for the entire image, not just the portion within 'region'.
[out]imageHeightNative height (e.g. texture pixel height) of the image. This should be for the entire image, not just the portion within 'region'.
Returns
Status code
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.
MStatus renderSwatchImage ( MImage image)
virtual

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 MHardwareRenderer::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 MHardwareRenderer::referenceDefaultGeometry(). The possible "default" geometries are either a sphere, cube or plane.
  • Either use the provided default light and camera or set up your own. MHardwareRenderer provides methods to retrieve the 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().
Parameters
[in,out]imageImage 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
Status code
Status Codes:
  • MS::kNotImplemented : No rendering will occur.
+ Examples:
MPxHardwareShader * getHardwareShaderPtr ( MObject object)
static

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).

Parameters
[in]objectThe object to examine.
Returns
A pointer to an MPxHardwareShader. If the method failed for any reason then a 0 (null) will be returned.
+ Examples:
MString findResource ( const MString name,
const MString shaderPath,
MStatus status = NULL 
)
static

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.

Parameters
[in]nameThe name of the resource to look for (e.g. "normals.dds")
[in]shaderPathThe full path to the current shader (e.g. "C:/shaders/myshader.fx")
[in]statusIf a pointer to a status is provided, the status will be set to MS::kSuccess if the resource was found, and MS::kFailure otherwise.
Returns
The full path of the resource (e.g. "C:/shaders/textures/normals.dds")
const char * className ( )
static

Returns the name of this class.

Returns
The name of this class.

The documentation for this class was generated from the following files:
  • MPxHardwareShader.h
  • MPxHardwareShader.cpp