Announcement

Collapse
No announcement yet.

shader writting

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

  • shader writting

    Hi,

    I'm having trouble finding enough help to get started in shader programming through the VRay SDK. Maybe I missed the correct manual or help page? I have trouble understanding how everything works, the inheritance and so on. Like for example if you want to write a shader you have to create a class that inherits from VRayMaterial? How about if you want to create a custom render element rather than a shader?

    And how would you tell Maya that a new shader exists or where to look for it? I suppose you should drop it in this folder "C:\Program Files\Autodesk\Maya2009\vray\vrayplugins" right? But that is not enough?

    As you can see I'm quite lost, any help would be greatly appreciated.

    Thanks in advance

    Cheers,

    Alberto

  • #2
    Hi,

    if you need to write a new render channel you can see an example of this in "samples\vray_plugins\rchannels\multimatte", this directory is located in
    "C:\Program Files\Chaos Group\V-Ray\Maya 2009 for x64" for a Maya 2009-x64 installation.
    Additionally you'll need to specify the render channel attributes for the interface inside Maya in
    "C:\Program Files\Autodesk\Maya2009\vray\scripts\renderElement s.txt", the mutlimatte element is on the top of this file.
    Once you add the description of your render element there, it will show up in the "Render elements" tab in the "Render settings" window.
    You'll of course need to copy your plugin to ""C:\Program Files\Autodesk\Maya2009\vray\vrayplugins" like you mentioned.

    When writing a shader or a texture you need to add the export description in "C:\Program Files\Autodesk\Maya2009\vray\shaders\desc.txt" or create a new txt file in that directory with your description ( this way your changes won't be overwritten when V-Ray for Maya is reinstalled, unlike the renderElements.txt file which still doesn't support additional files). Also you'll need to create a corresponding Maya node for your texture/shader. This node has to be little special. You have to add an additional output attribute to your Maya node so V-Ray will recognize it. The output attribute contains the name of the node ( the name used in the desc.txt file). This is not actually needed as the name can be obtained otherwise but it was done that way and is left as a legacy.

    You can create it like this

    MFnTypedAttribute tAttr;
    MFnStringData strData;
    strData.create("name_used_in_desc_txt");
    m_outApiType = tAttr.create("outApiType", "oat", MFnData::kString, strData.object());
    tAttr.setStorable(true);
    tAttr.setKeyable(false);
    tAttr.setHidden(true);
    addAttribute(m_outApiType);

    This is done in the "initialize" method of the Maya node. Of course you have to declare and define m_outApiType the usual way (as a static MObject which is part of the Maya node class).

    The desc.txt file does not support exporting array attributes, currently. You can work around this by just using a fixed number of attributes in case the array is not going to be very long. We'll probably consider adding support for this once a few people ask for it.

    For textures you can skip the desc.txt part and directly create a node for your texture inside Maya by going to Create->VRay->Create texture from V-Ray plugin. In that case V-Ray will handle the export for you. This texture will also have a swatch created and rendered with V-Ray, something custom Maya nodes won't have. The only reason you might want to create a custom Maya node would be to be able to specify a better looking interface than the one V-Ray creates for you.

    If you have a specific question how to write a particular type of plug-in, please ask here.

    Greetings,
    Vladimir Nedev
    Last edited by vladimir.nedev; 11-03-2010, 11:04 AM.
    Vantage developer, e-mail: vladimir.nedev@chaos.com , for licensing problems please contact : chaos.com/help

    Comment


    • #3
      Thank you! I'll post here if I have more questions

      Comment


      • #4
        Hi,

        Thanks for your help, we've got our custom render element working

        Is it necessary that all the plug-ins in C:\Program Files\Autodesk\Maya2009\vray\vrayplugins start by "vray_"? Because at first it didn't work when it was named something different...

        Cheers
        Alberto

        Comment


        • #5
          Yes, the dll names have to start with vray_, I guess this was done so unrelated dlls won't be inadvertently loaded.

          Greetings,
          Vladimir Nedev
          Vantage developer, e-mail: vladimir.nedev@chaos.com , for licensing problems please contact : chaos.com/help

          Comment


          • #6
            perfect

            Comment


            • #7
              is there any way of writing custom meta-data in exr files?

              Comment


              • #8
                Not right now, but we have noted this as a feature request.

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

                Comment


                • #9
                  Great! Thank you.

                  One more question. We're now trying to use the getUserProperty() function of the DefaultVRayShadeData class to read values of custom attributes but it seams to always return NULL. We're not sure what we're doing wrong. The attributes are stored in the object's shape and Shading Engine in Maya and we feed getUserProperty() their names.

                  Comment


                  • #10
                    The user attributes are not actually Maya's dynamic attributes, they're added as an extra V-Ray attribute. They can be added only to meshes/NURBS surfaces and subdivision surfaces for now. You need to add them through the Attributes -> VRay -> User attributes of the Attribute editor menu. You get one string attribute, all of the actual attributes are described using it. For example if the value of this attribute is set to
                    "attr1=value1;attr2=value2;attr3=value3;"
                    you'll get three attributes with names "attr1", "attr2" and "attr3", which will have values "value1", "value2" and "value3".

                    Greetings,
                    Vladimir Nedev
                    Vantage developer, e-mail: vladimir.nedev@chaos.com , for licensing problems please contact : chaos.com/help

                    Comment


                    • #11
                      Hi Vlado,

                      I followed the vrayplane plugin in (C:\Program Files\Chaos Group\V-Ray\Maya 2011 for x64\samples\maya_plugins\vrayplane) and I'd like to pass custom parameter to the plugin "MayaPlane" to create different geometry at render time, but with no luck.
                      I tried to write a desc.txt file to describe the relationship between "MayaPlane" and the "VRayPlane" maya node (apiType = "VRayGeometry"), but again, no parameter is exported when I render the scene. In the vrscene file, the only section about MayaPlane is like this:
                      MayaPlane pSolidShape1@mesh1 {
                      }
                      Can you tell me how to pass parameter to MayaPlane? Or any other workaround?
                      Thanks!

                      Best regards,
                      Gene

                      Comment


                      • #12
                        Just create some members of your class derived from VRayPluginParameter and use VRayPlugin::setParameter() to assign them to the plugin. For simple types (numbers, arrays etc) you can use the pre-defined parameters in defparams.h. So it would be something like this:
                        Code:
                        #include "defparams.h"
                        class MyVRayPlane: public MPxNode {
                          // Parameters that store the specific values that will be passed to our plugin.
                          DefIntParam a_number;
                          DefFloatParam b_number;
                        public:
                          MyVRayPlane(void);
                           ...
                        };
                        
                        MyVRayPlane::MyVRayPlane(void): a_number("a", 0), b_number("b", 0.0f) {
                        }
                        
                        void MyVRayPlane::createVRayPlugin(VR::VRayGeomInfo *geomInfo) {
                            if (!geomInfo) return;
                            PluginManager *plugman=geomInfo->getPluginManager();
                            if (!plugman) return;
                        
                            // Check to see if our class is already registered in the plugin manager
                            // and register it if necessary
                            PluginDesc *mayaPlanePluginDesc=plugman->getPluginDesc("MyMayaPlane");
                            if (!mayaPlanePluginDesc) plugman->registerPlugin(&mayaPlaneDesc);
                            else {
                              plugman->unregisterPlugin(&mayaPlaneDesc);
                              plugman->registerPlugin(&mayaPlaneDesc);
                            }
                        
                            // Create the MayaPlane plugin
                            bool existing=false;
                            MyMayaPlane *myMayaPlane=static_cast<MyMayaPlane*>(geomInfo->newPlugin("MyMayaPlane", existing));
                            if (!existing) {
                              // Compute the values for the parameters
                              a_number->setInt(5);
                              b_number->setFloat(3.14f);
                        
                              // Set the parameters of the plugin
                              myMayaPlane->setParameter(&a_number);
                              myMayaPlane->setParameter(&b_number);
                            }
                        }
                        You will also need to define the "a" and "b" parameters to the V-Ray plugin itself:
                        Code:
                        struct MyMayaPlane: VR::VRayStaticGeomSource {
                          // The parameter values will be stored here by the default implementation of frameBegin().
                          int a;
                          float b;
                        
                          MyMayaPlane(void) {
                            // Link the parameters of our plugin to specific memory locations,
                            // so that they can be updated in the default implementation of frameBegin().
                            paramList->setParamCache("a", &a);
                            paramList->setParamCache("b", &b);
                          }
                        
                          ....
                        };
                        
                        struct MyMayaPlane_Params: VR::VRayParameterDesc {
                          // Declare the parameters of our plugin
                          MyMayaPlane_Params(void) {
                            addParamInt("a", 1, -1, "The a parameter");
                            addParamFloat("b", 0.5f, -1, "The b parameter");
                          }
                        };
                        Also keep in mind that V-Ray already has an object named "VRayPlane", so you'll need to modify this in the example code - I will make a note to fix this in the example. I will also make a note to expand the example to include some parameters.

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

                        Comment


                        • #13
                          Hi Vlado,

                          Thank you for the quick reply.
                          The parameter setting worked perfectly!
                          I have one more question about hair primitive in VRay.
                          I noticed that each hair strand in VRayFur is rendered with several line segments (depends on the number of knots).
                          That means I'll have to assign a lot of segments if I want to render close up scenes.
                          Does VRay support spline curve for rendering hair primitive? Like riCurve in RenderMan and hair primitive in mental ray?
                          Thanks!

                          Best regards,
                          Gene

                          Comment


                          • #14
                            Hi Vlado,

                            I use the pre-defined parameters in defparams.h. to set my parameters for custom geometry.
                            Now I want to set different values for each frame in a animation sequence.
                            Since the function createVRayPlugin(VR::VRayGeomInfo *geomInfo) is inside Maya's compute, createVRayPlugin will be called only once in the beginning of the animation sequence.
                            Is there a way to set different frame with different parameters?
                            Thanks!

                            Best regards,
                            Gene

                            Comment


                            • #15
                              Originally posted by genelin1211 View Post
                              Hi Vlado,

                              I use the pre-defined parameters in defparams.h. to set my parameters for custom geometry.
                              Now I want to set different values for each frame in a animation sequence.
                              Since the function createVRayPlugin(VR::VRayGeomInfo *geomInfo) is inside Maya's compute, createVRayPlugin will be called only once in the beginning of the animation sequence.
                              Is there a way to set different frame with different parameters?
                              Thanks!

                              Best regards,
                              Gene
                              This is a bit more tricky and unfortunately we don't provide ready classes for it, so you'll have to do some extra coding (you could use the code from defparams.h as a starting point, of course). You need to re-implement the getXXXX() method of your plugin parameters to take into account the "time" parameter and return different values for different times.

                              This will work fine for rendering inside Maya; to export the animated parameter information to .vrscene files, you have to add some extra steps - if you need to do that let me know and I'll post how to do it.

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

                              Comment

                              Working...
                              X