Displacer Deformer with Mograph Camera Shader not working
-
hello,
In the same c4d file, I need to deform a object with a Displacer Deformer which has a material Mograph Camera Shader in shading. It's working with a common shader but not with a Mograph Camera Shader which is not taken into account.However, the process works well in 2 distinct steps :
1/ render the source camera (a part of the scene) and save a external image
2/ import the external image into the shading of Mograph Camera Shader, to deform the object (a other part of the scene) according to the source camera view, then render the second final camera.But the source view is animated and many render are needed in production. This is not very optimized and it would be better if it were automatic, without saving an external image for each rendering.
Question 1 : So I would like to know if there is a way to make the Displacer Deformer working with a Mograph Camera Shader in shading, a tip to make it work wythout python ?
Question 2 : if not, would it be possible to do this in python, with the folowing steps :
1 - retrieve the rendering from the source camera as the Mograph Camera Shader does and create the corresponding bitmap
2 - assign this bitmap to the shading of the displacer deformer
3 - launch final rendering from the second cameraThanks in advance
-
Hello @bioquet,
Thank you for reaching out to us. While we understand that for users the distinction is not as clear as for us, I must remind you that developers.maxon.net is exclusively meant for API issues. For end user questions, as for example how to use MoGraph, please use our Support Center.
Regarding your question of if it would be possible to do this in Python: Generally I would say "yes", as there are only a few things which are not possible with our Python API when you are an experienced developers.
The general idea would to render the relevant scene with c4d.documents.RenderDocument or the c4d.documents.BatchRender (i.e., what is called the "Render Queue" in the UI). What to pick depends a bit on how you fashion the rest of the functionality. You would then either load that bitmap into a Bitmap shader, or create such shader, and then assign that shader to the displace deformer. Done would this be either from a Script Manager script (or
CommandData
plugin) or via a Python tag (or aTagData
plugin).The exact path to pick depends on how "dynamic" you want this to be. Your question mentions that 'the source view is animated and many render are needed in production', which is a little bit ambiguous. But the gist would be that when you have to update the deformer image each frame, you could go two routes:
- The command route (i.e., Script Manager script) and render out a movie for the entire length, and load that
mp4
,mov
etc. as the source in your displacement shader. Video compression could make this tricky, but otherwise this is the 'easy' solution. - The tag route. Here you would render each frame on demand. The problem is here that you have to deal with:
- Threading issues
TagData::Execute
and by extension themain
function of a Python tag do run off-main-thread, which entails certain Threading limitations. You might have to clone the document for rendering (it is a bit hazy to me which document is being rendered). - Priority issues. Expressions, i.e., tags, come after generators in the scene execution. So, when a pass (think of it as a 'frame' - not really correct but close enough) is executed, Cinema 4D would first execute all generators, including the displace defomer, and then execute the expressions (i.e., your tag). When this pass was for a frame change, and you then update the bitmap of the displace deformer, it is 'too late', as the deformer already did its deformation. This can be solved by setting the execution priority of the tag to generators and a negative value, so that it is executed before all generators. But this can still lead to issues.
- Threading issues
What I would probably do when I would have to write this for a production environment and would want this to be done quickly, while side stepping potential issues from using a movie as a displacement source, would be going for a mix of both options. First a relatively simple Script Manager script which pre-renders the displacement source into a series of images relative to the document, e.g.,
tex/displace/{object_hash}/...
and then a simple Python tag on each displacer, which grabs the correct texture file for each frame for the given displacer and sets it on the shader loaded into the displacer.Cheers,
Ferdinand - The command route (i.e., Script Manager script) and render out a movie for the entire length, and load that
-
Hello,
Thanks for your complete answer.
I think I will not start in thread management, but opted for your last solution which will still go through an external image but in an automated way by a python script.
Thanks again.