MATPREVIEW_GENERATE_IMAGE with custom renderer



  • On 16/06/2015 at 10:16, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   15+ 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    I got my own renderer, it works fine in viewport and picture viewer, but it doesn't get called in material preview.

      
    		case MATPREVIEW_GENERATE_IMAGE:
    		{
    			MatPreviewGenerateImage* image = (MatPreviewGenerateImage* )data;
    			if (image->pDoc)
    			{
    				Int32					w = image->pDest->GetBw();
    				Int32					h = image->pDest->GetBh();
    				BaseContainer bcRender = image->pDoc->GetActiveRenderData()->GetData();
    				bcRender.SetFloat(RDATA_XRES, w);
    				bcRender.SetFloat(RDATA_YRES, h);
    				bcRender.SetInt32(RDATA_ANTIALIASING, ANTI_GEOMETRY);
    				if (image->bLowQuality)
    					bcRender.SetBool(RDATA_RENDERENGINE, RDATA_RENDERENGINE_PREVIEWSOFTWARE);
    				else
    					bcRender.SetInt32(RDATA_RENDERENGINE, ID_MYRENDERER);//my video post renderer ID
    				image->pDest->Clear(0, 0, 0);
    				image->lResult = RenderDocument(image->pDoc, bcRender, nullptr, nullptr, image->pDest,
    													 RENDERFLAGS_EXTERNAL | RENDERFLAGS_PREVIEWRENDER, image->pThread);
    			}
    			return MaterialData::Message(node, type, data);
    			//break;
    		}  
    

    am I missing something?



  • On 16/06/2015 at 10:24, xxxxxxxx wrote:

    to be precise, RenderDocument() is called, but it doesn't call my renderer Execute().



  • On 17/06/2015 at 06:38, xxxxxxxx wrote:

    Hello,

    changing the RDATA_RENDERENGINE value is just that – you change the value of the parameter and nothing else. The preview can only render using your render engine if you actually add your render engine to the scene. This means that you have to add the BaseVideoPost of your render engine to the document's render data using InsertVideoPost(). Something like this:

      
    RenderData* rdata = image->pDoc->GetActiveRenderData();  
      
    BaseVideoPost* myRenderer = BaseVideoPost::Alloc(MY_RENDERER_ID);  
    rdata->InsertVideoPost(myRenderer);  
    

    best wishes,
    Sebastian



  • On 17/06/2015 at 06:52, xxxxxxxx wrote:

    thanks a lot Sebastian, should I do this everytime I call RenderDocument()? or do it once in the material init() function?



  • On 17/06/2015 at 11:59, xxxxxxxx wrote:

    Hello,

    well, how often do you call RenderDocuent()? This has nothing to do with MaterialData::Init(). The document that is used by the material preview is no copy of your current document so its render settings are not your render settings. This is why you have to add the video post.

    Best wishes,
    Sebastian



  • On 17/06/2015 at 12:03, xxxxxxxx wrote:

    well, I call it on material update, so it will be a lot, I just pasted the 3 lines that you posted before RenderDocument() call and it worked, but I was aware if this is the correct thing to do.


Log in to reply