how to use RenderShaderPreview() [SOLVED]



  • On 09/05/2015 at 19:44, xxxxxxxx wrote:

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

    ---------
    from documentation "it is  private",
    https://developers.maxon.net/docs/Cinema4DCPPSDK/html/customgui__matpreview_8h.html#a610e9d34410135db7bcf74974b8eac66

    in old thread I asked about procedural textures caching, found that the best solution is getting the preview.
    https://plugincafe.maxon.net/topic/8072/10498_creating-instance-of-procedural-texture-write-it

    RenderShaderPreview seems like what I want "or you suggest a better alternative if any"
    so far I'm confused about how to use it!!

    what I have:
    1- BaseShader*
    2- BaseBitmap* "with my specified size"

    #### [RENDERRESULT]() RenderShaderPreview(const [Filename]()& docpath, [BaseShader]()* pShaderClone, [BaseShader]()* pOrigShader, [BaseThread]()* pThread, [BaseBitmap]()* pDest, [BaseDocument]()* pOriginalDoc, Real rCurrentTime, LONG lFlags = 0)_<_h4_>_
    

    and from SimpleMaterial example in the SDK I have:

    		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);
    				image->pDest->Clear(0, 0, 0);
    				image->lResult = RenderDocument(image->pDoc, bcRender, nullptr, nullptr, image->pDest,
    													 RENDERFLAGS_EXTERNAL | RENDERFLAGS_PREVIEWRENDER, image->pThread);
    			}
    			return true;
    			break;
    		}
    

    so I can see things in common, which are:
    1- image->pDoc    to    BaseDocument* pOriginalDoc
    2- image->pDest   to    BaseBitmap* pDest
    3- image->pThread    to    BaseThread* pThread
    4- image->rTime    to    Real rCurrentTime
    5- lFlags in the function should be RENDER_PREVIEW_USE_BMP_SIZE

    now  "const Filename& docpath, BaseShader* pShaderClone,BaseShader* pOrigShader" confuses me.
    I expect Filename& docpath to be the preview file "how to set it to Flat(2d)"
    I expect BaseShader* pOrigShader to be the shader that I'm querying.
    I don't expect anything about  BaseShader* pShaderClone.



  • On 11/05/2015 at 10:47, xxxxxxxx wrote:

    Hello,

    RenderShaderPreview() is marked as private and you should not use it as it might only be useful in a certain context. If you use it you do this on your own risk since the functionality may change.

    For docpath you can use the path delivered by GetDocumentPath(), pShaderClone is a clone of the original shader created with GetClone(). So something like this could work but as said before the function is marked as private:

      
    AutoAlloc<BaseBitmap> bitmap;  
    bitmap->Init(800,600);  
      
    BaseShader* clone = (BaseShader* )shader->GetClone(COPYFLAGS_0,nullptr);  
      
    RenderShaderPreview(doc->GetDocumentPath(),clone,shader,nullptr,bitmap,nullptr,0,RENDER_PREVIEW_USE_BMP_SIZE);  
      
    ShowBitmap(bitmap);  
      
    BaseShader::Free(clone);  
    

    best wishes,
    Sebastian



  • On 11/05/2015 at 14:28, xxxxxxxx wrote:

    thanks a lot Sebastian!!
    any alternative to RenderShaderPreview() ? I just want the preview of the texture , any possible consistent alternative should be ok.



  • On 12/05/2015 at 01:04, xxxxxxxx wrote:

    Hello,

    the alternative is to sample the shader yourself using Sample(). This was discussed recently:

    best wishes,
    Sebastian



  • On 12/05/2015 at 08:29, xxxxxxxx wrote:

    the above code works like a charm!! thanks a lot Sebastian
    for the "doc" variable, I'm using this: "Shader->GetDocument()->GetDocumentPath()" , is this ok? "this will be used in a preprocess inside a RenderDocument() call"



  • On 12/05/2015 at 09:40, xxxxxxxx wrote:

    nvm, I think I was too hasty, found "vps->doc" which should be what I need for the task.



  • On 16/05/2015 at 21:29, xxxxxxxx wrote:

    you can mark this as solved, "and hopefully tell me how to mark it as solved 😊, kinda noob in using forums"



  • On 18/07/2015 at 19:20, xxxxxxxx wrote:

    Hi Sebastian,

    sorry for opening this again, but there is a follow up question:
    there is a data that I need, which is Float rCurrentTime.
    there are 2 cases:
    1- Xbitmap, there is a calculate button for animations, how to do a similar behavior. (I just need the remapped time)
    2- any other Xbase, for example Xnoise, and it is animated, how to get the animated time.



  • On 20/07/2015 at 05:40, xxxxxxxx wrote:

    Hello,

    the rCurrentTime parameter seems to be the document time in seconds. But as said before, RenderShaderPreview() is no function that should be used by third party developers and no more support can be given.

    Best wishes,
    Sebastian


Log in to reply