Announcement

Collapse
No announcement yet.

V-Ray SDK BitmapInterface getting color crashes V-ray & Maya

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

  • V-Ray SDK BitmapInterface getting color crashes V-ray & Maya

    Hey Guys,

    Somehow I'm unable to use the SDK forum so I'm quickly putting it here in public. Probably picked up the wrong account or something.
    Anyway...

    I'm trying to create my own shader that samples an image at a specified UV point and figured I needed to use the bitmap interface.
    But it keeps on crashing on me and I don't really understand why. I took most of the source code from the bitmap example and the checker.

    Here's my code:

    Code:
    //**************************************************
    // File: tex_AColor.cpp
    // Description: this file is an implementation of a simple AColor texture for VRay
    // Notes: used when exporting data - to do a conversion from AColor to Texture.
    //        it can also work with textures as input and will leave them unchanged.
    //        (file created from tex_invert.cpp)
    //**************************************************
    
    #include "vrayplugins.h"
    #include "vrayinterface.h"
    #include "vrayrenderer.h"
    #include "vraytexutils.h"
    #include <math.h>
    
    #include "globalnewdelete.cpp"
    
    using namespace VR;
    
    // Parameters
    struct SphereMapTex_Params: VRayParameterListDesc {
    	SphereMapTex_Params(void) {
    		// Add the parameters
    		addParamPlugin("uvwgen", EXT_UVWGEN);
    		//addParamTexture("texture");
    		addParamTexture("bitmap", EXT_BITMAP);
    	}
    };
    
    
    struct SphereMapTex: VRayTexture, RTTexInterface {
    	SphereMapTex(VRayPluginDesc *pluginDesc):VRayTexture(pluginDesc) {
    		// Set parameter caches
    		paramList->setParamCache("uvwgen", &uvwgen_plugin);
    		paramList->setParamCache("bitmap", &bitmap_plugin);
    		//paramList->setParamCache("texture", &texture);
    	}
    
    	void renderBegin(VR::VRayRenderer *vray);
    	void renderEnd(VR::VRayRenderer *vray);
    	void frameBegin(VR::VRayRenderer *vray);
    	void frameEnd(VR::VRayRenderer *vray);
    
    	AColor getTexColor(const VRayContext &rc);
    	void getTexColorBounds(AColor &cmin, AColor &cmax);
    	Vector getColorBumpGradient(const VRayContext &rc);
    private:
    	// Cached parameters
    	PluginBase* uvwgen_plugin;
    	UVWGenInterface* uvwgen;
    	//TextureInterface *texture;
    	PluginBase* bitmap_plugin;
    	BitmapInterface *bitmap;
    	BitmapInterface2 *bitmap2;
    
    	// The color cache
    	ShadeCache<AColor, true, false> shadeCache;
    public:
    	// From RTTexInterface
    	PluginBase* getPlugin(void) { return this; }
    	int getDataSize(void) { return 0; }
    	void getData(float *fdata) { }
    
    	PluginInterface *newInterface( InterfaceID id ) {
    		if (EXT_RTTEX==id) return static_cast<PluginInterface*>( (RTTexInterface*)this );
    		return VRayTexture::newInterface(id);
    	}
    	
    	virtual int getSource(const char *part,const char *outParam,const char *lang,VUtils::ShaderSource &shaderSrc, OCLData &mtlData)
    	{
    		return 0;
    	}
    };
    
    #define SphereMapTex_PluginID PluginID(LARGE_CONST(20141228000))
    SIMPLE_PLUGIN_LIBRARY(SphereMapTex_PluginID, EXT_TEXTURE, "SphereMapTex", "SphereMap texture for VRay", SphereMapTex, SphereMapTex_Params);
    
    void SphereMapTex::renderBegin(VR::VRayRenderer *vray) {
    	VRayTexture::renderBegin(vray);
    	shadeCache.renderBegin(vray);
    }
    
    void SphereMapTex::renderEnd(VR::VRayRenderer *vray) {
    	VRayTexture::renderEnd(vray);
    	shadeCache.renderEnd(vray);
    }
    
    void SphereMapTex::frameBegin(VR::VRayRenderer *vray) {
    	// Call the base class to update the parameter caches
    	VRayTexture::frameBegin(vray);
    
    	// Call frameBegin on the shade cache
    	shadeCache.frameBegin(vray);
    
    	// Get the uvw gen
    	uvwgen=(UVWGenInterface*) GET_INTERFACE(uvwgen_plugin, EXT_UVWGEN);
    
    	// Get bitmap data
    	bitmap=(BitmapInterface*) GET_INTERFACE(bitmap_plugin, EXT_BITMAP);
    	bitmap2=static_cast<BitmapInterface2*>(GET_INTERFACE(bitmap_plugin, EXT_BITMAP2));
    	const VRaySequenceData &sdata=vray->getSequenceData();
    	if (!bitmap && sdata.progress) sdata.progress->warning("[TexBitmap] No bitmap buffer specified.\n");
    }
    
    void SphereMapTex::frameEnd(VR::VRayRenderer *vray) {
    	VRayTexture::frameEnd(vray);
    	shadeCache.frameEnd(vray);
    }
    
    AColor SphereMapTex::getTexColor(const VRayContext &rc) {
    	if (!bitmap) return AColor(0.5, 0.5, 0.5, 1.0);
    
    	double u = 0.5;
    	double v = 0.5;
    
    
    	//return AColor(1.0, 0.0, 0.0, 1.0); // test with red (keeping this avoids the crash and render it red as expected)
    	// !!!!!!!!!!!!!!!!!!!!!CRASH!!!!!!!!!!!!!!!!!!
    	bitmap->getInterpolatedColor(Vector2(u, v), 1); // THIS LINE CRASHES MAYA & RENDERER
    
    }
    
    void SphereMapTex::getTexColorBounds(AColor &cmin, AColor &cmax) {
    	//if (texture==NULL) cmin=cmax=AColor(0.5f, 0.5f, 0.5f, 1.0f); 
    	//else texture->getTexColorBounds(cmin, cmax);
    	if (!bitmap) return;
    	bitmap->getColorBounds(cmin, cmax);
    }
    
    Vector SphereMapTex::getColorBumpGradient(const VRayContext &rc) {
    	return Vector(0.0f, 0.0f, 0.0f);
    	//if (texture==NULL) return Vector(0.0f, 0.0f, 0.0f);
    	//return texture->getColorBumpGradient(rc);
    }
    Any help is greatly appreciated!

    Cheers,
    Roy

  • #2
    Code:
    bitmap->getInterpolatedColor(Vector2(u, v), 1); // THIS LINE CRASHES MAYA & RENDERER
    You're missing a return statement at the beginning of this line.
    Increase the warning level of you compiler and you'll see a warning about this same line.
    V-Ray developer

    Comment


    • #3
      Originally posted by t.petrov View Post
      You're missing a return statement at the beginning of this line.
      This probably has nothing to do with the crash though...

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

      Comment


      • #4
        Can you post the call stack at the time of the crash?

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

        Comment


        • #5
          The missing return statement was indeed a copy/paste and clean-up thing that I removed. I definitely had it in there the whole time for the crashes (otherwise the compiler wouldn't even compile) just pasted it over to the forum without it. Woops!

          I've written many plug-ins for different software applications (learned by myself) but never got any grip on how to handle the beast of an IDE like Visual Studio.
          To get to the call stack at the time of the crash I need to compile in debug mode right? And then connect the debugger to the running app and make the crash happen?
          Any tips for this?
          I'll have a go at this tomorrow and see if I can get some nice debugging output either way.

          Thanks for the amazingly quick replies Vlado and t.petrov.

          Cheers,
          Roy

          Comment


          • #6
            Originally posted by colorbleed View Post
            To get to the call stack at the time of the crash I need to compile in debug mode right? And then connect the debugger to the running app and make the crash happen?
            Though technically it's not needed to compile in debug mode, it helps to make more sense of the code. When it crashes, in Visual Studio, go to Debug > Windows > Call stack, make sure you scroll to the top, and send me a screengrab to vlado@chaosgroup.com

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

            Comment


            • #7
              Hey Vlado,

              Maya crashes with the line giving the error on Create Texture from Plugin when I create the node.
              All I can see in the call stack for Maya is a single line saying:
              > 0000000000000000()

              So I'm probably doing something wrong with debugging this.

              By the way could it be that the crash is related to not inheriting from a MappedTexture like the bitmap example?
              Basically I don't need the object's UV but want to sample an image with my own algorithm at a calculated point U and V so I assumed I didn't need the MappedTexture.
              I so hope to nail this bug today, hehe. Any pointers are welcome.

              Thanks.

              -Roy

              Comment


              • #8
                Originally posted by colorbleed View Post
                By the way could it be that the crash is related to not inheriting from a MappedTexture like the bitmap example?
                No, this should not matter. It would be best if we can reproduce this here. Is that the entire source code above? Can you also get me a simple Maya scene with this set up?

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

                Comment


                • #9
                  Hey Vlado,

                  I e-mailed you the files.
                  The code above should work (incl. crash) if you add the missing return statement as mentioned above.
                  I can't really make a Maya scene with the set-up because it crashes even on creating the node with the getInterpolatedColor() line enabled.

                  -Roy

                  Comment


                  • #10
                    Originally posted by colorbleed View Post
                    I e-mailed you the files.
                    Which email did you use?

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

                    Comment


                    • #11
                      I used vlado@chaosgroup.com, but it was blocking my mail with the .dll (compiled plug-in) both separately attached or in a .zip file.
                      So now I've just sent a new one with only the .cpp file. Hope this comes through.

                      - Roy

                      Comment


                      • #12
                        It crashes because you declared the parameter with addParamTexture(), but you are using it as a bitmap. You will either have to use addParamPlugin() instead, or else use a regular texture parameter.

                        I don't know how you intend to use the plugin, but within the Maya UI, there is no way to handle pure bitmap buffer parameters, only textures. Might be something to keep in mind...

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

                        Comment


                        • #13
                          Vlado, it's crazy that I missed that the whole time when looking over the differences with the bitmap example!
                          Thank you so very much.

                          Basically to work around that texture issue not popping up in the Maya interface is by writing a Maya node equivalent with a corresponding shader description file, correct?

                          -Roy

                          Comment


                          • #14
                            It is actually showing the bitmap attribute, but during my first test it seemed it didn't work to actually sample the file that I connected to it.
                            Probably that's what you meant with it not working? Can I workaround this at all with the bitmap parameter? I think it should be because it's also used for the bitmap example. (Or I misunderstood the concept of that example).

                            The reason I chose for a bitmap parameter is because I could sample that at an arbitrary UV point, which I was unable to do with a texture parameter.

                            Comment


                            • #15
                              Originally posted by colorbleed View Post
                              The reason I chose for a bitmap parameter is because I could sample that at an arbitrary UV point, which I was unable to do with a texture parameter.
                              This can actually be done, although it is not obvious how. I will rework your example a bit to show you.

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

                              Comment

                              Working...
                              X