Announcement

Collapse
No announcement yet.

custom material shader doesnt work in override....

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

  • custom material shader doesnt work in override....

    i wrote a custom material shader for maya, all has gone very well until I put it in a override field of a basic surface shader( ex. Reflection Material. ), and in the final image, i got the object shaded in a basic shading. I looked in the vray_MtlOverride.cpp and I noticed that override's shade() calls my overriding material's shade(). I tried printing something when my own material's shade() is called. But nothing was printed... So I supposed that override material has not called my material's shade() at all??? How that could happen?? Am I missing something?

    Best regards

    thekraken

    here is a simple pseudo code of my material shader:

    Code:
    using namespace VR;
    
    // Plugin parameters
    struct MyMaterialParams: VRayParameterListDesc {
    	MyMaterialParams(void) {
    	
    	//////////////////
    } ;
    
    // The plugin itself
    struct MyMaterialMyMaterial: VRayMaterial {
    	MyMaterial(VRayPluginDesc *desc):VRayMaterial(desc) {
    		/////////
    	}
        
    	// From VRayPlugin
    	void renderBegin(VRayRenderer *vray) { brdf_pool.init(vray->getSequenceData().maxRenderThreads); }
    	void renderEnd(VRayRenderer *vray) { brdf_pool.freeMem(); }
    	void frameBegin(VR::VRayRenderer *vray);
        
    	// From MaterialInterface
    	void shade(VR::VRayContext &rc);
        
    	// From BRDFInterface
    	BSDFSampler *newBSDF(const VR::VRayContext &rc, BSDFFlags flags) {
    		VR::DiffuseBRDF *bsdf=brdf_pool.newBRDF(rc);
    		initBSDF(rc, *bsdf);
    		return static_cast<BSDFSampler*>(bsdf);
    	}
    	void deleteBSDF(const VR::VRayContext &rc, BSDFSampler *bsdf) {
    		if (bsdf) brdf_pool.deleteBRDF(rc, (VR::DiffuseBRDF*) bsdf);
    	}
    	void initBSDF(const VRayContext &rc, VR::DiffuseBRDF &brdf);
        
    	PluginBase* getPlugin() { return static_cast<PluginBase*>(this); }
        
    	virtual PluginInterface* newInterface(InterfaceID id)
    	{
    		if( id == EXT_RTMTL )
    		{
    			return static_cast<PluginInterface*>((RTMtlInterface*)this);
    		}
            
    		return VRayMaterial::newInterface(id);
    	}
        
    private:
    	// Cached parameters
    	//////////////////////
        
    	BRDFPool<VR::DiffuseBRDF> brdf_pool;
    };
    
    // Define the plugin
    #define MyMaterial_PluginID PluginID(LARGE_CONST(2012022011))
    SIMPLE_PLUGIN_LIBRARY(MyMaterial_PluginID, EXT_MATERIAL, "MyMaterial", "MyMaterial for VRay", MyMaterial, MyMaterialParams);
    
    void MyMaterial::frameBegin(VR::VRayRenderer *vray) {
    	VRayMaterial::frameBegin(vray);
    
    }
    
    void MyMaterial::initBSDF(const VRayContext &rc, VR::DiffuseBRDF &bsdf) {
        std::cout<< "initBSDF is called"<<std::endl;
    	Color diffuse=combineTex(rc, diffuse_tex, Color(0.0,0.0,0.0),1.0);
        bsdf.init(diffuse, Color(.0,.0,.0), rc);
    }
    
    void MyMaterial::shade(VR::VRayContext &rc) {
        
        std::cout<< "shade is called" <<std::endl;
    	Color alpha=transparency.whiteComplement();
        
    	if ((rc.rayparams.rayType & RT_SHADOW) || rc.rayresult.realBack) {
    
            rc.mtlresult.color.makeZero();
    		rc.mtlresult.transp=transparency;
    		rc.mtlresult.alpha=alpha;
    		rc.mtlresult.alphaTransp=transparency;
            
            
    		return;
    	}
        
    
    	/*
    
    		computing		
    
    	*/
         
        
        
    	rc.mtlresult.color+=result;
    	rc.mtlresult.transp=transparency;
    	rc.mtlresult.alpha=alpha;
    	rc.mtlresult.alphaTransp=transparency;
    
        
    }
    Last edited by thekraken; 19-03-2012, 08:58 AM.

  • #2
    Is the newBSDF() method called for your material? It is possible that your material is wrapped in a MtlSingleBRDF material eventually, and that MtlSingleBRDF is attached to the node. In that case, it will call only the BSDF/BRDF functions of your material, and not its shade() method.

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

    Comment


    • #3
      1. Is the newBSDF() method called for your material?

      Yes, override shader called newBSDF() for sure, and it called only newBSDF()

      2. It is possible that your material is wrapped in a MtlSingleBRDF material eventually, and that MtlSingleBRDF is attached to the node.

      nope, my material is not wrapped in a MtlBRDF(If I have understood CORRECTLY what you talked about)... it was just in a lambert's override material field......

      could you PLEASE detail a little... i've been looking for the solution for 4 hours... it's driving me crazy...

      best regards

      Comment


      • #4
        Ok then; can you show me a .vrscene file with the material exported in this way? In any case, the solution would probably be to do what you need in the traceForward() method of your BRDF - i.e. derive your own BRDF class from VUtils:iffuseBRDF and reimplement its traceForward() method to do what you need (you'll still need to call DiffuseBRDF::traceForward() to do the regular shading stuff before that).

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

        Comment


        • #5
          that's very kind of you.

          here is the exported material
          Code:
           
          BRDFMirror VRayMtl1@mirror {
            transparency_tex=AColor(0, 0, 0, 1);
            cutoff=0.01;
            back_side=0;
            trace_reflections=1;
            trace_depth=5;
            reflect_exit_color=AColor(0, 0, 0, 1);
            reflect_dim_distance=100;
            reflect_dim_distance_on=0;
            reflect_dim_distance_falloff=0;
          }
          
          BRDFDiffuse VRayMtl1@diffuse {
            color=Color(0, 0, 0);
            color_tex=AColor(0, 0, 0, 1);
            transparency_tex=AColor(0, 0, 0, 1);
            roughness=0;
            use_irradiance_map=1;
          }
          
          BRDFLayered VRayMtl1@brdflayered {
            brdfs=List(
              VRayMtl1@mirror,
              VRayMtl1@diffuse
            );
            transparency=Color(0, 0, 0);
            channels=List(
            );
          }
          
          MtlSingleBRDF VRayMtl1@material {
            brdf=VRayMtl1@brdflayered;
            double_sided=1;
          }
          
          BRDFDiffuse lambert2@diffuse_brdf {
            color=Color(0, 0, 0);
            color_tex=lambert2@diffuse_brdf_color_tex@tex_with_amount;
            transparency=Color(0, 0, 0);
          }
          
          MtlOverride lambert2@diffuse_brdf_lambert2@override {
            base_mtl=lambert2@diffuse_brdf;
            reflect_mtl=VrayMyMaterial1;
          }
          
          VrayMyMaterialMayaPlugIn VrayMyMaterial1 {
            plgDiffuse_tex=AColor(0.1, 0.5, 0.2, 1);
            plgDiffuse_tex_mult=1;
            plgThresholdHigh=0.9;
            plgThresholdLow=0.3;
            plgHighColor=Color(1, 1, 1);
            plgMedColor=Color(0.8, 0.8, 0.8);
            plgLowColor=Color(0.2, 0.2, 0.2);
            plgTransparency=Color(0, 0, 0);
          }
          
          MtlSingleBRDF lambert2@material {
            brdf=lambert2@diffuse_brdf_lambert2@override;
          }
          I will derive my own BRDF from DiffuseBRDF... so there is no way that override would call my material shade() methode then?

          Thank you

          Best regards

          kraken

          Comment


          • #6
            Originally posted by thekraken View Post
            I will derive my own BRDF from DiffuseBRDF... so there is no way that override would call my material shade() methode then?
            Well, you could attach the MtlOverride material directly to the node, instead of passing it through a MtlSingleBRDF material. You can do this for example with the post-translate Python callback.

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

            Comment


            • #7
              Thanks vlado,

              I wrote a new class derived from BRDF to do the things finally and that works well. Thank you for all your replies. I will try the post-translate python callback later.

              best regards

              thekraken

              Comment

              Working...
              X