Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Cinema4D's break point in BakeTexture

 Post Reply Post Reply
Author
Message
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 263
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Topic: Cinema4D's break point in BakeTexture
    Posted: 2017 Jul 04 at 2:51pm

User Information:

Cinema 4D Version:   R18 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

Hello.

I've got some problems when I try to use BakeTexture for a sub-shader in a ShaderData plugin. 

Here is the scenario. I have a ShaderData plugin with a shaderlink parameter.  The shader set in that shaderlink parameter has to be baked.

So, in InitRender of the ShaderData, I use BakeTexture in the inner shader and I get a breakpoint here:

  CINEMA 4D.exe!00007ff6c91528ce() Unknown
  CINEMA 4D.exe!00007ff6c915283d() Unknown
  c4dplugin.xdl64!00007ff89d020528() Unknown
  c4dplugin.xdl64!00007ff89e92fe49() Unknown
  c4dplugin.xdl64!00007ff89d050c43() Unknown
  sla.cdl64!00007ff89019b52f() Unknown
  sla.cdl64!00007ff890199e29() Unknown
<..... My method call that uses BakeTexture.......>
This problem with BakeTexture appears ONLY in the ShaderData's InitRender.
I use the same texture baking code in other places and everything works fine. 
I use the thread and document that are passed in InitRender.
Once I continue after the break point, the returned value of BakeTexture is BAKE_TEX_ERR_NONE.
The BakeTexture's result is correct.

How can I find the problem here ?

Thank you very much for your time.


Edited by peterakos - 2017 Jul 23 at 2:51am
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1381
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 05 at 9:15am
Hi,

you gave me some headache here. Actually I was wondering, how do you use BakeTexture() to bake a shader? And even worse, where do you get the needed infos, when in InitRender()?
So I came up with my own solution, which does not show any problems. The sub-shader gets baken without any breakpoint or crash.
Maybe you can tell us, what exactly you are doing in InitRender()?

Here's roughly what I did:

- chn argument -> the BaseDocument.
- VolumeData (in irs argument) -> RayObject and TexData.
- TexData -> TextureTag and from this BaseObject
- Cloned the object (including tags, these tex and uvw tags will be used later on) and the sub-shader
- Created a new document, inserted cloned object
- Created new material
- Inserted the cloned shader and assigned it to the color channel (actually same channel the sub-shader is assigned to)
- Inserted new material into new document
- Set material of tex tag on cloned object to refer to new material

With all of this I was able to use InitBakeTexture() and BakeTexture() in InitRender to get a proper image of a noise shader without any breakpoints.

Cheers,
Andreas
SDK Support Engineer
Back to Top
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 263
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 17 at 3:22am
Hello and thank you very much for your support !

I don't use the VolumeData passed in InitRender's InitRenderStruct.
I create a dummy plane from which I retrieve the uvw tag that will be used later on InitBakeTexture:

	
BaseContainer plane_data;
plane_data.InsData(PRIM_PLANE_SUBW,GeData(1));
plane_data.InsData(PRIM_PLANE_SUBH,GeData(1));

BaseObject* plane = GeneratePrimitive(dummy_document, Oplane, plane_data, 1.0, false, baking_thread);
ModelingCommandData command_data;
command_data.doc = dummy_document;
command_data.op = plane;

if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT,command_data)) {
BaseObject::Free(plane);
return false;
}
BaseObject::Free(plane);

BaseObject* polygon_plane = static_cast<BaseObject *>(command_data.result->GetIndex(0));
bake_uvw_tag = (UVWTag *)polygon_plane->GetTag(Tuvw,0);

bake_texture_tag = TextureTag::Alloc();
bake_texture_tag->SetParameter(DescID(TEXTURETAG_PROJECTION),TEXTURETAG_PROJECTION_UVW,DESCFLAGS_SET_0);
polygon_plane->InsertTag(bake_texture_tag);   
dummy_document->InsertObject(polygon_plane,NULL,NULL);

The dummy_document in the above code is the cloned one. bake_uvw_tag and bake_texture_tag are used in InitBakeTexture.
So basically I skip the steps 2,3,4 in your post and I replace them with the code above. 
Does this cause any problem ?

Thank you.
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1381
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 18 at 7:53am
Ok, by my approach I somewhat shot myself in the knee... sorry!

As I took the information from the VolumeData, I baked only if the VolumeData was existent. Obviously missing the case, where no VolumeData is available, which is the case when the shader preview gets rendered/prepared.

In this case there's a threading issue, as BakeTexture() internally wants to do something, it is not allowed from a worker thread. So there's unfortunately no solution in this case.

But lets look at it from a different perspective. Why do you need to bake? Couldn't you just sample the sub-shaders? If this could be an option, the BaseShader manual has a code snippet demonstrating how to do it properly.

Cheers,
Andreas
SDK Support Engineer
Back to Top
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 263
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 19 at 2:09am
Hello.

The thread that is used for baking is NULL (taken from InitRenderStruct).
I use texture baking because I want to produce an image based on that shader.
I could use sampling, but isn't it slower ? 

Thank you for your time Andreas !
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1381
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 19 at 9:18am
I haven't done any measurements and in the end it may probably depend on the scenario. But when baking the shader needs to be sampled as well.

Cheers,
Andreas
SDK Support Engineer
Back to Top
peterakos View Drop Down
Member
Member


Joined: 2015 Jul 13
Online Status: Offline
Posts: 263
Post Options Post Options   Quote peterakos Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 20 at 12:27am
Hello Andreas.

Allow me to ask one last thing before replacing texture baking with sampling.
Do they produce the same result if set correctly ? 
If I'm about to replace texture baking with sampling, I need them to produce the exact same image.

Thank you again !
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1381
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jul 20 at 1:24am
Well, that depoends highly on the scenario, especially on the bake settings. With sampling you won't get any lighting information or effects.

Cheers,
Andreas
SDK Support Engineer
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.