Communicating with another shader in C++?
-
On 17/12/2015 at 23:53, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R17
Platform: Mac ;
Language(s) : C++ ;---------
Is there any way to have shaders in C++ communicate with each other (presumably within the same material)?I'm working on a fairly complicated shader that needs some way of generating additional textures that can be plugged into a variety of different texture slots. ~95% of the calculations that occur internally during render are identical between each of these textures, so I'd rather not evaluate the entire shader three whole times if I can somehow avoid that (calculating the required data only once) by having each shader talk to the others and figure out who has already calculated the required data and use that instead.
How would I best implement this? Is this something that I should be using the Message APIs for, or is there a better way?
-CMPX
-
On 18/12/2015 at 04:14, xxxxxxxx wrote:
Hi,
Yes the Message API is way to go to implement communication between nodes in Cinema.
-
On 09/01/2016 at 17:25, xxxxxxxx wrote:
Hey, thanks for the reply.
Quick question- what do I use for the message type ID?
It seems like some plugins just pick arbitrary numbers for this (I've even seen some that overlap with C4D's built-in messages), others appear to use a registered plugin ID instead (the number looks high enough that that's the case).
What should I use in my own plugins? Should I just use any number I know won't collide with the C4D messages, or should I register a new plugin ID specifically for that message?
-CMPX
-
On 09/01/2016 at 20:07, xxxxxxxx wrote:
If you are going to use SpecialEventAdd() to send CoreMessages, a unique plugin ID is the way to go.
-
On 09/01/2016 at 21:36, xxxxxxxx wrote:
Do I need to do that?
All I need to do is get some data from another shader instance on occasion. I figured I could do that just by calling ((BaseShader * )myShader)->Message(MSG_DO_SOMETHING, (void * ) &messageData) and having the other shader set messageData as required and return true or false depending on whether or not the message call succeeded.
Is there some reason why I'd need to use a CoreMessage instead?
-CMPX
-
On 10/01/2016 at 06:24, xxxxxxxx wrote:
When you pass a message like that, it should be something unique to the receiver. I have used it to simulate a button press on another plugin's button using MSG_DESCRIPTION_COMMAND. As long as your message 'type' will not collide with some other message value, you can use whatever you want. But I think that for full coverage, a plugin ID (and you can use your shader plugin ID, by the way) will maintain that uniqueness.
-
On 10/01/2016 at 08:01, xxxxxxxx wrote:
If its in the same plugin library file, you could also just cast the result of shader->GetNodeData() to your ShaderData subclass and access the data from there.
Cheers,
Niklas