InitRender() with large textures
-
Hi Roger, thanks for following up and providing the texture.
A few notes:
- the texture attached actually points to a resized texture (760 x 760): is it wanted?
- the texture gets loaded and sampled flawlessly on my test plugins (both ObjectData and TagData)
- test were done on macOS/C4DR19.024
Could you please provide the full high-res picture to grant correct testing?
Cheers, Riccardo
-
@r_gigante I uploaded the texture here on the forums, I think it was reduced. Here's it is.
But any JPG, 4096x4096, using MIP sampling fails with me. -
Hi Roger, thanks for providing the test picture.
Unfortunately I've not being able to reproduce the issue with the test code below.
Could you kindly check the same code on your side and see how it behaves?Bool PC_11085_ObjectData::ModifyObject(BaseObject* mod, BaseDocument* doc, BaseObject* op, const Matrix& op_mg, const Matrix& mod_mg, Float lod, Int32 flags, BaseThread* thread) { if (!mod || !op || !doc || !thread) return false; // Retrieve the BaseContainer instance of the modifier. BaseContainer *bcPtr = mod->GetDataInstance(); // // Retrieve the Object Manager parameters values. const Bool useXbitmap = bcPtr->GetBool(PC11085_XBITMAP); BaseList2D* const xBitmapBL = bcPtr->GetLink(PC11085_SHADERLINK, doc); const String textureFilename = bcPtr->GetString(PC11085_TEXTURE); // allocate and init the InitRenderStruct InitRenderStruct irs(doc); // check the color space COLORSPACETRANSFORMATION transform = COLORSPACETRANSFORMATION_NONE; // check if linear workflow is enabled if (irs.linear_workflow) transform = COLORSPACETRANSFORMATION_LINEAR_TO_SRGB; if (xBitmapBL) { // cast to BaseShader BaseShader* activeMatColorBS = (BaseShader*)xBitmapBL; // define the ChannelData and set the u/v coords for sampling ChannelData chData; // call the InitRender before executing sampling const INITRENDERRESULT res = activeMatColorBS->InitRender(irs); if (res != INITRENDERRESULT_OK) return EXECUTIONRESULT_OK; const Int32 steps = 100; for (Int32 x = 0; x < steps; x++) { for (Int32 y = 0; y < steps; y++) { chData.p.x = double(x)/double(steps); chData.p.y = double(y)/double(steps); // sample const Vector sampledValue = activeMatColorBS->Sample(&chData); // correct based on the color space transformation const Vector transformedColor = TransformColor(sampledValue, transform).Clamp01(); // just print GePrint("Shader sample at ["+String::FloatToString(chData.p.x)+","+String::FloatToString(chData.p.y)+"]: "+String::VectorToString(sampledValue)+" / "+String::VectorToString(transformedColor)); } } // call the FreeRender to release allocated memory used for sampling activeMatColorBS->FreeRender(); } // Notify Cinema about the internal data update. op->Message(MSG_UPDATE); return true; }
EXECUTIONRESULT PC_11085_TagData::Execute (BaseTag *tag, BaseDocument *doc, BaseObject *op, BaseThread *bt, Int32 priority, EXECUTIONFLAGS flags) { if (!tag || !doc || !op || !bt) return EXECUTIONRESULT_OUTOFMEMORY; // allocate and init the InitRenderStruct InitRenderStruct irs(doc); // check the color space COLORSPACETRANSFORMATION transform = COLORSPACETRANSFORMATION_NONE; // check if linear workflow is enabled if (irs.linear_workflow) transform = COLORSPACETRANSFORMATION_LINEAR_TO_SRGB; // find for the attached TextureTag and the related material TextureTag* opTTag = (TextureTag*)op->GetTag(Ttexture); if (!opTTag) return EXECUTIONRESULT_OK; BaseMaterial* opMat = opTTag->GetMaterial(); if (!opMat) return EXECUTIONRESULT_OK; // look for the material BaseContainer and the BaseList2D associated to the color param BaseContainer* activeMatBC = opMat->GetDataInstance(); if (!activeMatBC) return EXECUTIONRESULT_OK; BaseList2D* activeMatColorBL = activeMatBC->GetLink(MATERIAL_COLOR_SHADER, doc); if (!activeMatColorBL) return EXECUTIONRESULT_OK; // cast to BaseShader BaseShader* activeMatColorBS = (BaseShader*)activeMatColorBL; // define the ChannelData and set the u/v coords for sampling ChannelData chData; // call the InitRender before executing sampling const INITRENDERRESULT res = activeMatColorBS->InitRender(irs); if (res != INITRENDERRESULT_OK) return EXECUTIONRESULT_OK; const Int32 steps = 100; for (Int32 x = 0; x < steps; x++) { for (Int32 y = 0; y < steps; y++) { chData.p.x = double(x)/double(steps); chData.p.y = double(y)/double(steps); // sample const Vector sampledValue = activeMatColorBS->Sample(&chData); // correct based on the color space transformation const Vector transformedColor = TransformColor(sampledValue, transform).Clamp01(); // just print GePrint("Shader "+activeMatColorBL->GetName()+" sample at ["+String::FloatToString(chData.p.x)+","+String::FloatToString(chData.p.y)+"]: "+String::VectorToString(sampledValue)+" / "+String::VectorToString(transformedColor)); } } // call the FreeRender to release allocated memory used for sampling activeMatColorBS->FreeRender(); return EXECUTIONRESULT_OK; }
Looking forward hearing from you, give best
Riccardo -
Hi @rsodre, any feedback so far?
Cheers, Riccardo
-
Hi @r_gigante, I still didn't got a chance to test your sample code and see if it fails here, but it looks like the same workflow I'm using.
When I first opened the issue, I was using a tag, that now evolved to be a modifier, so there's no need to test the tag.
But is your object a modifier? -
@rsodre as said in InitRender() with large textures:
Bool PC_11085_ObjectData::ModifyObject
which indeed is only available in
BaseObject
for modifier.Look forward your feedbacks
-
Hi @rsodre, I'm going to mark this thread as solved being passed two weeks from the last post.
Feel free to open a new thread if issue persists.
Best, Riccardo
-
@r_gigante That's sad, because it's a recurrent issue we have.
I'll try to isolate it as soon as I have some time. -
Hi @r_gigante,
I finally took some time to isolate my shader init and sample code on a simple project, and was unable to reproduce the error I was having. If it works on a separate project, should work on my full plugin too.
So I started stripping code from my modifier and generator, always testing if the shader was loading properly, until the objects were barely empty, when the error finally stopped. I traced the culprit down to a single EventAdd() call in some function inside my generator's ModifyObject(). Removing it fixed the problem. Looks like calling it before the first modifier pass somehow causes the shader init error.
Just wanted to leave this feedback in case anyone has a similar problem someday.
Thanks for the help! -
hello,
Thanks a lot for your feedback and happy to see your issue resolved.
Cheers
Manuel