Texture Baking in Redshift using Python
-
Hi,
I have a simple scene with a few takes, each using a different material, and two baking sets. I’m trying to write a script that travels through the takes, accesses the corresponding baking set, bakes the textures for each take, and then moves to the next one. While I’ve written some initial code, I couldn’t find any documentation or examples specific to Redshift to help me make it work.Could you please review my attached code and sample scene? If possible, could you provide a code snippet demonstrating how to implement this functionality?
I also have a couple of related questions:
- Is there a way to increase baked texture brightness without altering light intensity or modifying the materials? I’d like to match the renders , where I manipulate brightness using f-Stop on Redshift camera. I understand that exposure manipulation may not work during baking, but any suggestions would be helpful.
- All my AOVs are set up in Redshift render settings. Can they be used during the baking process?
- When baking textures, Redshift materials using standard bluish normal maps result in green normals. Is there a way to resolve this issue?
Thank you for your assistance. I’ve attached my initial code and a sample scene for your reference.
Best regards,
Tomaszimport c4d import re list_of_takes = [] cat_2_baker = {"RS BakeSet_WallTiles":"003","RS BakeSet_FeatureWalls":"002"} def get_all_takes_recursively(take, takeData): while take: if "_BakeMat_" in take.GetName(): list_of_takes.append(take) #print(f"Added {take.GetName()}") get_all_takes_recursively(take.GetDown(), takeData) take = take.GetNext() def node_2_bakerset(take_name): match = re.search(r"_BakeMat_(\d{3})", take_name) if match: code = match.group(1) result = next((key for key, value in cat_2_baker.items() if value == code), None) return result else: return None def bake_textures(take, bakingset_2_use): print (f"Baking mat {take.GetName()} using {bakingset_2_use} set") def main(): doc = c4d.documents.GetActiveDocument() if not doc: return # Get take data take_data = doc.GetTakeData() if not take_data: print("No take data in document") get_all_takes_recursively(take_data.GetMainTake(), take_data) for take in list_of_takes: #print(take.GetName()) node_2_use = node_2_bakerset(take.GetName()) bake_textures(take, node_2_use) # Create parent take for material previews c4d.EventAdd() if __name__ == '__main__': c4d.CallCommand(13957) # Clear Console main()
-
Hi Tomasz,
Thanks for reaching out to us. First I'd like to note that according to our Support Procedures we cannot provide you with complete solutions:
We provide code examples but we do not provide full solutions or design applications.
We cannot debug your code for you and instead provide answers to specific problems.
Regarding your question. In short, what you're trying to do here is not easily achievable (if possible at all).
Although, you can manipulate Redshift AOVs as discussed in get the names of redshift multi passes AOV names from the render settings, I'm afraid there's no such functionality exposed for interacting the baking tool itself. This effectively means that you can simulate pressing the "Bake" button in the bakeset attributes using C4D API, but you cannot skip manual interaction in the bake tool. I'd suggest you double checking this on redshift forum as it would be the place with the most concentrated knowledge on this topic.
Regarding your related questions. First, please make sure you're dedicating your threads to a singular question or topic as explained in How to ask questions:
Singular Question: The initial posting of a support topic must contain a singular question. Do not ask ten things at once, that makes it extremely hard to answer topics. Break up your questions into multiple topics. Asking follow-up questions is allowed but they must be bound to the initial subject.
- Manipulating data of the baked AOV textures. Trying to adapt them to look like on final render image is an ill-posed problem, as each AOV is some sort of "layer" of the information the renderer uses to create final rendering. I'd suggest you first check the documentation on the AOVs: Intro to AOVs and Redshift: Baking. If you still have end-user questions, you're very welcome to ask them on our Support Center.
- To the best of my knowledge using AOVs from the render settings is supposed to work with the Bake tool as long as you use AOV Manager to set them up.
- The effect of "green normals" that you observe is likely the unexpected coordinate system for your normal data. Namely, Redshift is always working with objects in worldspace, hence the normal data is also represented the same way. The blueish normal maps are typically those that are expressed in tangent space. Unfortunately there's no built-in AOV that does this for you. To achieve this, you could potentially leverage the "Store Color To AOV" node for that, although this would require adjusting your node material setup, e.g. like below:
Cheers,
Ilia