Getting the object it is being rendered, from inside a shader plugin
-
I already searched for this in the forum and found some similar questions and answers and thay are all quite old.
One of then was even asked by me a long time ago, when I was still using COFFEE.
And some other were asked about PYTHON and the answer was that it was only possible in C++.
But a lot of time has passed and I would like to know if such a basic thing was already possible in PYTHON.
So, is there any way to know what object is being rendered inside the Output method of a PYTHON shader plugin? -
Hey @rui_mac,
thank you for reaching out to us. In general only shaders which are volume shaders have access to the object for which they are being called for. In Python (or in COFFEE) you cannot implement volume shaders and therefore cannot access the object which is being rendered.
When you are implementing a volume shader in C++, you can do this (untested pseudo code):
cinema::Vector MyShader::Output(cinema::BaseShader* shader, cinema::ChannelData* cd){ // Get the volume data from the channel data. cinema::VolumeData* const vd = cd ? cd->vd : nullptr; if (!vd) return COLOR_RENDER_ERROR; // Get the ray objects. for (cinema::Int32 i; i < vd->GetObjCount(); i++) { const cinema::RayObject* const ro = vd->GetObj(i); if (!obj) continue; // Attempt to find the object this ray object has been constructed for. const cinema::BaseObject* const op = ro._texture_link ? ro._texture_link : ro._link; if (!op) return COLOR_RENDER_ERROR; // Do stuff with the object ... } return COLOR_RENDER_ERROR; }
Cheers,
Ferdinand