Problems baking textures



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/09/2007 at 03:19, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   10.102 
    Platform:   Windows  ;   
    Language(s) :

    ---------
    Hi there!

    Currently I'm trying to add automatic texture baking to my scene exporter (from C4D to Ogre) in order to get the materials in Ogre as close as possible to their C4D counterparts.
    However I've run into some problems with the baking. First of all it seems the only channel I can be sure not to be affected by lighting would be the luminance channel of the material. I've tried baking textures manually and no matter what options I set in the BakeTexture tag in C4D, the color channel for example always depends on the lighting in the scene.
    So, in order to export an approximation of the actual channel texture / shader used, I thought I'd do the following:

    1. Take the channel I want to bake from Material M and copy it to the luminance channel of a temporary Material N.
    2. Clone the TextureTag into a temporary one, change the material used there to Material N from (1.), add that tag to the object's tags.
    3. Bake that stuff with BAKE_TEX_LUMINANCE set to true.
    4. Save resulting BaseBitmap to file.

    There are two problems with this:
    a) When I copy the original channel to the luminance channel of N, only the top-most level of info is copied. My simple test case is a material with a Noise shader in the color channel. After copying the color channel to N's luminance channel, the Noise shader is there, but its parameters are back to standard, i.e. not copied. I assume the same thing would happen with Fusion or any other shader. (I checked this by adding the material N to the document.)
    How can I copy a complete channel of a material, including its shaders and their hierarchy? (like the Copy / Paste Channel functions in C4D do)

    b) It seems my code still bakes the old, unchanged material and still bakes only the color channel while taking illumination into account. Can somebody tell me where I'm going wrong?

    This is the source for the main of my texture baking thread:
    <CODE>
    BaseDocument* bakeDoc = NULL;;
    BaseContainer bakeSettings;
    char info[512];
    sprintf_s(info, 512, "TextureBaker started with %d jobs to do...", this->m_vWorkList.size());
    GeConsoleOut(String(info));
    BaseContainer lumData;
    for(std::vector<BakerInstruction>::iterator i = this->m_vWorkList.begin(); i != this->m_vWorkList.end(); i++)
    {
         TextureTag* tTagToBake = TextureTag::Alloc();
         Material* matToBake = Material::Alloc();
         matToBake->SetChannelState(CHANNEL_LUMINANCE, TRUE);
         matToBake->SetChannelState(CHANNEL_COLOR, FALSE);
         matToBake->SetChannelState(CHANNEL_SPECULAR, FALSE);
         i->TexTag->CopyTo(tTagToBake, COPY_NO_INTERNALS, 0);
         tTagToBake->SetMaterial(matToBake);
         tTagToBake->InsertBefore(i->TexTag->GetObject()->GetFirstTag());
         BaseChannel* source = i->TexTag->GetMaterial()->GetChannel(i->ChannelToBake);
         lumData = source->GetData();
         matToBake->GetChannel(CHANNEL_LUMINANCE)->SetData(lumData);

    g_pDocument->InsertMaterial(matToBake);

    bakeSettings.FlushAll();
         bakeSettings.InsData(BAKE_TEX_LUMINANCE, GeData(TRUE));
         bakeSettings.InsData(BAKE_TEX_WIDTH, GeData(i->TargetResX));
         bakeSettings.InsData(BAKE_TEX_HEIGHT, GeData(i->TargetResY));
         bakeSettings.InsData(BAKE_TEX_UV_LEFT, GeData(i->MinU));
         bakeSettings.InsData(BAKE_TEX_UV_RIGHT, GeData(i->MaxU));
         bakeSettings.InsData(BAKE_TEX_UV_TOP, GeData(i->MinV));
         bakeSettings.InsData(BAKE_TEX_UV_BOTTOM, GeData(i->MaxV));
         
         bakeDoc = InitBakeTexture(g_pDocument, tTagToBake, i->SourceUVs, i->ResultUVs, bakeSettings, &i-;>ResultError, this->Get());
         if(i->ResultError || !bakeDoc)
         {
              GeConsoleOut(i->ToString());
              continue;
         }
         BaseBitmap* resultBitmap = BaseBitmap::Alloc();
         i->ResultError = BakeTexture(bakeDoc, bakeSettings, resultBitmap, this->Get(), NULL, NULL);
         if(i->ResultError)
         {
              GeConsoleOut(i->ToString());
              continue;
         }
         i->ResultFile = Filename(i->ExpMat->GetName()+String("_")+i->TexTag->GetObject()->GetName()+String("_")+TexChannelToString(i->ChannelToBake));
         i->ResultFile.SetSuffix("tif");
         switch(i->ChannelToBake)
         {
         case CHANNEL_COLOR: i->ExpMat->SetDiffuseTex(i->ResultFile); break;
         case CHANNEL_TRANSPARENCY: i->ExpMat->SetTransparencyTex(i->ResultFile); break;
         case CHANNEL_SPECULARCOLOR: i->ExpMat->SetSpecTex(i->ResultFile); break;
         default: GeConsoleOut("Can't set new filename for exportmaterial"); break;
         }
         
         GeConsoleOut(i->ToString());
         if(!resultBitmap->Save(Filename(i->TargetFolder.GetString()+String("\")+i->ResultFile.GetFileString()), FILTER_TIF, 0, 0))
         {
              GeConsoleOut("ERROR: Failed writing texture to disc!");
         }
         //tTagToBake->Remove();
         BaseBitmap::Free(resultBitmap);
         
    }
    //TextureTag::Free(tTagToBake);
    bakeSettings.FlushAll();
    GeConsoleOut("TextureBaker done!");
    </CODE>



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/09/2007 at 05:45, xxxxxxxx wrote:

    Okay, I've changed my code quite a bit in the last few hours. Currently the texture baking always results in the color channel being baked without lighting.
    That's better than before, but I'd still want to be able to bake the channel I want.
    As the specular color channel is unavailable as a baking option I would at least still have to copy that one, so the question about copying material channels still remains open.
    Ideally I would like to implement a function that allows me to copy any material channel to the materials luminance channel.

    Another problem is that using the BakeTexture functionality to export normal-maps doesn't work using the API for me. So some help with that would be great, too.

    Currently I'm filling the BaseContainer "bakeSettings" with every info the BakeTexture tag contains (i.e. I call InsData(...) with every BAKE_TEX_... key and set a value that should be equivalent to the BakeTextures standard settings). After that I change the data in "bakeSettings" to reflect the settings I would use in the BakeTexture tag in C4D: For example for export of normal-maps I call
    bakeSettings.setData(BAKE_TEX_NORMAL, TRUE) and bakeSettings.setData(BAKE_TEX_NORMAL_METHOD, BAKE_TEX_NORMAL_METHOD_TANGENT).
    For every other channel I assume I've copied it to the luminance channel of the material, so I use bakeSettings.setData(BAKE_TEX_LUMINANCE, TRUE) to enable that channel.
    After that I start the baking process. If you need the current version of the code please let me know.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/09/2007 at 02:39, xxxxxxxx wrote:

    Quote: _Another problem is that using the BakeTexture functionality to export normal-maps doesn't work using the API for me. So some help with that would be great, too.
    >
    > * * *
    _


    You have to use a MultipassBitmap instead a Bitmap to bake normals, AO, UVs etc. In general I would recommend to always use MultipassBitmap for baking purposes.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/09/2007 at 04:37, xxxxxxxx wrote:

    thx for the tip. Never would have thought of that. Will try it out now.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/09/2007 at 04:43, xxxxxxxx wrote:

    brilliant, thx. Works like a charm, I just replaced BaseBitmap with MultipassBitmap and it works :) I had my own bump map to normal map conversion written, but this one's much better, as it hopefully results in exactly the normals that C4D uses for rendering. Most definitely it will give more accurate results than my guessing :)


Log in to reply