Baking normal in Object space: Bake Material Tag V.S. BakeTexture()
-
Hey guys,
I'm trying to understand why the normal map baked (in object space) by the Bake Material tag is different from the one that is baked by the the SDK (using the
InitBakeTexture()
andBakeTexture()
functions) when they are seemingly both given the same parameters.In both cases (the Bake Material tag and the SDK functions), these are my settings:
- Width: 1024
- Height: 1024
- Channel: Normal (active)
- Source (inside of the Normals sub-section): Object whose normals are being baked
- Method: Object (default)
The Base Material tag gives me this:
While the
InitBakeTexture()
andBakeTexture()
functions give me this:
Unless I am wrong, the result yielded by the Bake Material tag seems to be the most accurate and favorable one (in terms of color spectrum). Am I wrong?
Here is an excerpt of my C++ code:
BaseContainer settings; settings.SetInt32(BAKE_TEX_WIDTH, 1024); settings.SetInt32(BAKE_TEX_HEIGHT, 1024); settings.SetInt32(BAKE_TEX_PIXELBORDER, 0); settings.SetBool(BAKE_TEX_CONTINUE_UV, true); settings.SetBool(BAKE_TEX_USE_PHONG_TAG, true); settings.SetVector(BAKE_TEX_FILL_COLOR, Vector(0.0)); settings.SetBool(BAKE_TEX_NORMAL, true); settings.SetBool(BAKE_TEX_NORMAL_METHOD_OBJECT, true); BAKE_TEX_ERR err; BaseDocument* bakeDoc = InitBakeTexture(doc, (TextureTag*)textureTag, (UVWTag*)uvwTag, nullptr, settings, &err, nullptr); // Check if initialization was successful if (err != BAKE_TEX_ERR::NONE) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Failed to initialize baking of the normal map."_s); // Prepare bitmap for baking MultipassBitmap* normalMap = MultipassBitmap::Alloc(1024, 1024, COLORMODE::RGBw); if (!normalMap) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Could not allocate normal map."_s); // Perform the bake for the normal map BakeTexture(bakeDoc, settings, normalMap, nullptr, nullptr, nullptr); // File path of the normal map maxon::Url urlNormalMapResult{ "file:///C:/filepath/normal_map.png"_s }; normalMap->Save(MaxonConvert(urlNormalMapResult), FILTER_PNG, nullptr, SAVEBIT::NONE);
Note: I am currently assigning the color mode
RGBw
tonormalMap
. I have experimented a lot in that area and I have not been able to find any otherCOLORMODE
or any other setting/enum for that matter that would get me closer to the normal map baked by the Base Material tag.Any insight/guidance would be massively appreciated as always.
Thank you so much!
-
Thinking that the problem stemmed from the lack of color profile, I attempted to add the
BAKE_TEX_COLORPROFILE
enum to mysettings
, but I was unable to do so without it throwing an error upon the building of my solution.My updated settings:
AutoAlloc<ColorProfile> colorProfile; if (!colorProfile || !colorProfile->GetDefaultSRGB()) { return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Failed to allocate or initialize the color profile."_s); } // Setup bake settings BaseContainer settings; // ...other settings removed for brevity... settings.SetData(BAKE_TEX_COLORPROFILE, GeData(colorProfile));
Unfortunately, the additional line above (i.e.
BAKE_TEX_COLORPROFILE
) throws the following errors upon building my solution:- Error C2661:
BaseContainer::SetData
: no overloaded function takes 1 arguments - Error C2440:
<function-style-cast>
: cannot convert fromAutoAlloc<ColorProfile>
toGeData
I've been "fighting" with the SDK for the past hour while extensively reading the documentation, but I have yet to find a solution.
If my problem has nothing to do with the color profile, I guess that would also be good to know!
Thank you very much as always.
- Error C2661:
-
Whoopsies. I had forgotten this one setting:
settings.SetBool(BAKE_TEX_NORMAL_USE_RAYCAST, true);
It works as expected now.
Apologies!
This matter is now resolved.
-
Hi @justinleduc ,
Great to hear your issue was resolved! Special thanks on sharing your solution with the community!
Regarding compiling issues you had:
Error C2440: <function-style-cast>: cannot convert from AutoAlloc<ColorProfile> to GeData
The AutoAlloc wrapper is just a convenient wrapper for a raw pointer. Hence, to fix your issue you just had to dereference the pointer:
CheckState(colorProfile); settings.SetData(BAKE_TEX_COLORPROFILE, GeData(*colorProfile));
Cheers,
Ilia