Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    how to use RenderShaderPreview() [SOLVED]

    SDK Help
    0
    9
    884
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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/cpp/2023_2/customgui__matpreview_8h.html#a610e9d34410135db7bcf74974b8eac66

      in old thread I asked about procedural textures caching, found that the best solution is getting the preview.
      https://developers.maxon.net/forum/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[URL-REMOVED]* pOriginalDoc
      2- image->pDest   to    BaseBitmap[URL-REMOVED]* pDest
      3- image->pThread    to    BaseThread[URL-REMOVED]* pThread
      4- image->rTime    to    Real rCurrentTime
      5- lFlags in the function should be RENDER_PREVIEW_USE_BMP_SIZE

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


      [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

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

            Hello,

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

            • Sample shader with modified ChannelData

            best wishes,
            Sebastian

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              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"

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  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"

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    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.

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      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

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post