Announcement

Collapse
No announcement yet.

VRay shader not appear in maya hypershade ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VRay shader not appear in maya hypershade ?

    hi,

    I follow the instruction of "V-Ray for Maya translator SDK" to try to make a simple VRay shader visiable in maya's hypershade but it not works.

    This is my VRay plugin code:

    TexInputTypeTest_VC11.cpp
    Code:
    #include "vrayplugins.h"
    #include "vrayinterface.h"
    #include "vrayrenderer.h"
    #include "vraytexutils.h"
    
    #include "meshinfobase.h"
    #include "meshinfointerface.h"
    
    #include "globalnewdelete.cpp"
    
    // Prevent from "to tchar*" conversion warning ...
    #if (defined __GNUC__) && !(defined __clang__)
    	#pragma GCC diagnostic ignored "-Wwrite-strings"
    #endif //(defined __GNUC__) && !(defined __clang__)
    
    using namespace VR;
    
    // Parameters
    struct TexInputTypeTest_Params: VRayParameterListDesc {
        TexInputTypeTest_Params(void) {
            addParamInt("int", 0, -1);
        }
    };
    
    struct TexInputTypeTest: VRayTexture {
        TexInputTypeTest(VRayPluginDesc *pluginDesc):VRayTexture(pluginDesc) {
            // Set parameter caches
    	paramList->setParamCache("int", &int_val);
        }
    
        AColor getTexColor(const VRayContext &rc);
        void getTexColorBounds(AColor &cmin, AColor &cmax);
        Vector getColorBumpGradient(const VRayContext &rc);
        
        virtual PluginInterface* newInterface(InterfaceID id) { return VRayTexture::newInterface(id); }
        
        // VRayTexture Member function
        PluginBase* getPlugin(void) { return static_cast<PluginBase*>(this); }
        
        // These pure virtual functions have to be implemented if support RTTexInterface
        //int getDataSize(void) { return 0; }
        //void getData(float *fdata) { }
        //int getSource(const char *part,const char *outParam,const char *lang,VUtils::ShaderSource &, OCLData &mtlData);
            
        private:
            int int_val;
    };
    
    #define TexInputTypeTest_PluginID PluginID(LARGE_CONST(2004711829))
    SIMPLE_PLUGIN_LIBRARY(TexInputTypeTest_PluginID, EXT_TEXTURE, "TexInputTypeTest", "Test curious input type of VRay plugin", TexInputTypeTest, TexInputTypeTest_Params);
    
    AColor TexInputTypeTest::getTexColor(const VRayContext &rc) {
        return AColor(0.0f, 0.0f, 0.0f, 1.0f);
    }
    
    void TexInputTypeTest::getTexColorBounds(AColor &cmin, AColor &cmax) {
        cmin = AColor(0.0f, 0.0f, 0.0f, 1.0f);
        cmax = AColor(1.0f, 1.0f, 1.0f, 1.0f);
    }
    
    Vector TexInputTypeTest::getColorBumpGradient(const VRayContext &rc) {
        return Vector(0.0f, 0.0f, 0.0f);
    }

    and the corresponding maya plugin as follows:


    VRayInputTypeTestNode.h
    Code:
    #ifndef _VRayInputTypeTestNode
    #define _VRayInputTypeTestNode
    
    #include <maya/MPxNode.h>
    #include <maya/MFnNumericAttribute.h>
    #include <maya/MTypeId.h> 
     
    class VRayInputTypeTest : public MPxNode
    {
        public:
            VRayInputTypeTest();
            virtual    ~VRayInputTypeTest(); 
    
    	virtual MStatus	compute(const MPlug& plug, MDataBlock& data);
    	static void* creator();
    	static MStatus initialize();
    
    	static MTypeId id;
    	static MString apiType;
    	static MString classification;
    
        private:
    	// Input Attributes
            static MObject m_Int;
    
            // Output Attributes
            static MObject m_OutColor;
    	static MObject m_OutAPIType;
    	static MObject m_OutAPIClassification;
    };
    
    #endif

    VRayInputTypeTestNode.cpp
    Code:
    #include <maya/MPlug.h>
    #include <maya/MDataBlock.h>
    #include <maya/MDataHandle.h>
    #include <maya/MGlobal.h>
    #include <maya/MFnTypedAttribute.h>
    #include <maya/MFnStringData.h>
    
    // V-Ray headers
    #include "vraybase.h"
    #include "vrayplugins.h"
    #include "VRayInputTypeTestNode.h"
    
    MTypeId     VRayInputTypeTest::id(0x002104F1);
    
    MString VRayInputTypeTest::classification("shader/surface/utility/:swatch/VRayMtlSwatchGen");
    
    MObject VRayInputTypeTest::m_Int;
    
    MObject VRayInputTypeTest::m_OutColor;
    MObject VRayInputTypeTest::m_OutAPIType;
    MObject VRayInputTypeTest::m_OutAPIClassification;
    
    VRayInputTypeTest::VRayInputTypeTest() {}
    VRayInputTypeTest::~VRayInputTypeTest() {}
    
    MStatus VRayInputTypeTest::compute( const MPlug& plug, MDataBlock& data )
    {
    	return MS::kSuccess;
    }
    
    void* VRayInputTypeTest::creator()
    {
    	return new VRayInputTypeTest();
    }
    
    MStatus VRayInputTypeTest::initialize()
    {
    	MFnNumericAttribute nAttr;
    	MFnTypedAttribute tAttr;
    	MFnStringData strData;
    	MStatus	stat;
    
    	// Create input attributes
    	m_Int = nAttr.createColor("Int", "mit");
    	CHECK_MSTATUS(nAttr.setKeyable(false));
    	CHECK_MSTATUS(nAttr.setStorable(true));
    	CHECK_MSTATUS(nAttr.setReadable(true));
    	CHECK_MSTATUS(nAttr.setWritable(true));
    
    	// Create output attributes
    	m_OutColor = nAttr.createColor("OutColor", "oc");
    	CHECK_MSTATUS(nAttr.setKeyable(false));
    	CHECK_MSTATUS(nAttr.setStorable(false));
    	CHECK_MSTATUS(nAttr.setReadable(true));
    	CHECK_MSTATUS(nAttr.setWritable(false));
    
    	//strData.create(VRayInputTypeTest::m_OutAPIType);   // Error ???
    	m_OutAPIType = tAttr.create("OutAPIType", "oat", MFnData::kString, strData.object());
    	CHECK_MSTATUS(tAttr.setStorable(true));
    	CHECK_MSTATUS(tAttr.setKeyable(false));
    	CHECK_MSTATUS(tAttr.setHidden(true));
    
    	//strData.create(VRayInputTypeTest::m_OutAPIClassification);
    	m_OutAPIClassification = tAttr.create("OutAPIClassification", "oac", MFnData::kString, strData.object());
    	CHECK_MSTATUS(tAttr.setStorable(true));
    	CHECK_MSTATUS(tAttr.setKeyable(false));
    	CHECK_MSTATUS(tAttr.setHidden(true));
    
    	// Add the attributes
    	CHECK_MSTATUS(addAttribute(m_Int));
    	CHECK_MSTATUS(addAttribute(m_OutColor));
    	CHECK_MSTATUS(addAttribute(m_OutAPIType));
    	CHECK_MSTATUS(addAttribute(m_OutAPIClassification));
    
    	return MS::kSuccess;
    }

    pluginMain.cpp
    Code:
    #include "defines.h"
    #ifdef X64
    #define Bits64_
    #endif
    
    #include "VRayInputTypeTestNode.h"
    
    #include <maya/MFnPlugin.h>
    #include <maya/MGlobal.h>
    
    MStatus initializePlugin(MObject obj)
    { 
    	MStatus status;
    	MString errStr;
    	MFnPlugin plugin(obj, "Seila", "1.0", "Any");
    
    	if (!status) {
    		MGlobal::displayInfo("Could not initialize MFnPlugin\n");
    		errStr = "Failed to initialize plugin";
    		status.perror(errStr);
    	}
    
    	// Register the VRayInputTypeTest node
    	const MString classification(VRayInputTypeTest::classification);
    	status = plugin.registerNode("VRayInputTypeTest", VRayInputTypeTest::id, VRayInputTypeTest::creator, VRayInputTypeTest::initialize, MPxNode::kDependNode, &classification);
    
    	if (!status) {
    		errStr = "RegisterNode failed";
    		status.perror(errStr);
    	}
    
    	return status;
    }
    
    MStatus uninitializePlugin(MObject obj)
    {
    	MStatus status;
    	MString errStr;
    	MFnPlugin plugin(obj);
    
    	// Deregister the VRayInputTypeTest node
    	status = plugin.deregisterNode(VRayInputTypeTest::id);
    	if (!status) {
    		status.perror("Deregister Node Failed");
    	}
    
    	return status;
    }
    Both plugins are successfully compiled (with just some warning about DLL exporting) and the produced files are named "vray_TexInputTypeTest.dll" and "VRayInputTypeTest.mll". I put both of them in the same folder and set a desc.txt with content like this:

    Code:
    TexInputTypeTest VRayInputTypeTest {
    "int"                  number       "Int"                 number       INPUT
    ""                     texture      "OutColor"            texture      OUTPUT
    }
    Then set "MAYA_PLUG_IN_PATH" environment variable to the path that plugin files reside. I think that's all i have to do to make my shader appear in maya's hypershade but it not. Do i miss anything ? (I also try to compile the blinn material in the maya plugin example folder but it also not work at all)
    Last edited by Seila; 11-10-2015, 07:33 AM.

  • #2
    I think the classification string when registering the Maya node is the only one that matters for the hypershade; none of the other files has any relation to that (they are only needed to tell V-Ray what to do). Further on, I think attribute names in Maya are case-sensitive, you can't just type what you want there. The attribute name for the output classification should be "outApiClassification", for the output type "outApiType", for the output color "outColor" etc - exactly like that.

    Next, you need to load the Maya .mll plugin explicitly from Window > Settings/Preferences > Plugin manager (you can set it to auto-load).

    Finally, for the recent versions of V-Ray, there's no need to create a Maya .mll plugin for your shader at all; V-Ray can create hypershade nodes on its own. Check the [vraysdk]\docs\maya_sdk.html file, the section on "Automatic generation of shading nodes".

    Best regards,
    Vlado
    I only act like I know everything, Rogers.

    Comment


    • #3
      Thanks vlado, i can make my shader node visible in hypershade now.

      The next thing I want to do is to make my shader node can accept other types of information rather than just texture color, so i add other type of attributes in my maya node:

      Code:
      MObject VRayInputTypeTest::m_TextureFloat;
      MObject VRayInputTypeTest::m_TextureMatrix;
      MObject VRayInputTypeTest::m_TextureTransform;
      MObject VRayInputTypeTest::m_Material;
      MObject VRayInputTypeTest::m_Geometry;
      
      ...
      
      MStatus VRayInputTypeTest::initialize()
      {
      	MFnNumericAttribute nAttr;
      	MFnTypedAttribute tAttr;
      	MFnStringData strData;
      	MStatus	stat;
      
              ...
      
      	m_TextureFloat = nAttr.createColor("TextureFloat", "mtf");
      	CHECK_MSTATUS(nAttr.setKeyable(false));
      	CHECK_MSTATUS(nAttr.setStorable(true));
      	CHECK_MSTATUS(nAttr.setReadable(true));
      	CHECK_MSTATUS(nAttr.setWritable(true));
      	
      	m_TextureMatrix = nAttr.createColor("TextureMatrix", "mtm");
      	CHECK_MSTATUS(nAttr.setKeyable(false));
      	CHECK_MSTATUS(nAttr.setStorable(true));
      	CHECK_MSTATUS(nAttr.setReadable(true));
      	CHECK_MSTATUS(nAttr.setWritable(true));
      
      	m_TextureTransform = nAttr.createColor("TextureTransform", "mtt");
      	CHECK_MSTATUS(nAttr.setKeyable(false));
      	CHECK_MSTATUS(nAttr.setStorable(true));
      	CHECK_MSTATUS(nAttr.setReadable(true));
      	CHECK_MSTATUS(nAttr.setWritable(true));
      	
      	m_Material = nAttr.createColor("Material", "mm");
      	CHECK_MSTATUS(nAttr.setKeyable(false));
      	CHECK_MSTATUS(nAttr.setStorable(true));
      	CHECK_MSTATUS(nAttr.setReadable(true));
      	CHECK_MSTATUS(nAttr.setWritable(true));
      	
      	m_Geometry = nAttr.createColor("Geometry", "mg");
      	CHECK_MSTATUS(nAttr.setKeyable(false));
      	CHECK_MSTATUS(nAttr.setStorable(true));
      	CHECK_MSTATUS(nAttr.setReadable(true));
      	CHECK_MSTATUS(nAttr.setWritable(true));				
      
              ...
      
              CHECK_MSTATUS(addAttribute(m_TextureFloat));
      	CHECK_MSTATUS(addAttribute(m_TextureMatrix));
      	CHECK_MSTATUS(addAttribute(m_TextureTransform));
      	CHECK_MSTATUS(addAttribute(m_Material));
      	CHECK_MSTATUS(addAttribute(m_Geometry));
      
              ...
      The VRay plugin node also added with the corresponding attributes:

      Code:
      struct TexInputTypeTest_Params: VRayParameterListDesc {
          TexInputTypeTest_Params(void) {
              ...
              addParamTextureFloat("texture_float", 0, -1);
              addParamTextureMatrix("texture_matrix");
      	addParamTextureTransform("texture_transform");    // How to make default value of matrix ???
      	addParamPlugin("material", EXT_MATERIAL, -1);
      	addParamPlugin("geometry", EXT_STATIC_GEOM_SOURCE);
         }
      };
      
      struct TexInputTypeTest: VRayTexture {
          TexInputTypeTest(VRayPluginDesc *pluginDesc):VRayTexture(pluginDesc) {
              // Set parameter caches
      	paramList->setParamCache("int", &int_val);
      	paramList->setParamCache("texture_float", &texture_float);
      	paramList->setParamCache("texture_matrix", &texture_matrix);
      	paramList->setParamCache("texture_transform", &texture_transform);
      	paramList->setParamCache("material", &materiral_Plugin);
      	paramList->setParamCache("geometry", &geometry_Plugin);		
             ...
         }
      };
      And desc.txt as follows:
      Code:
      TexInputTypeTest VRayInputTypeTest {
      "int"                         number       "Int"                         number       INPUT
      "texture_float"           number       "TextureFloat"            number       INPUT
      "texture_matrix"        transform    "TextureMatrix"          transform    INPUT
      "texture_transform"    transform    "TextureTransform"    transform    INPUT
      "material"                 material      "Material"                  material     INPUT
      "geometry"               uvwgen       "Geometry"                plugin       INPUT
      ""                            texture        "OutColor"                 texture      OUTPUT
      }
      Although the result node have these attributes in it, it seems they all exposed as texture\color plug such that i can't plug a matrix, material or geometry to corresponding attributes. Does VRay plugin node's inputs are limited to texture\color ? Is it possible to make my shader node to connect with matrix, material ,geometry, volume or light object ? (This is the reason that i want to make corresponding maya node for VRay plugin node, since i suppose auto-generated node just can't recognize output from other type nodes(i.e. mesh or material) without maya node's help)

      Comment

      Working...
      X