Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here are the key points I understand from your request:
- Write a Blender Python script
- The script should render the current frame as a normal map
- The normal map should be normalized to look like a typical normal map
- You provided an example image of what a normal map should look like
- To render the current frame in Blender as a normalized normal map, you can use a script like this:
- import bpy
- Set the render engine to Cycles
- bpy.context.scene.render.engine = 'CYCLES'
- Create a new image to bake to
- image_name = "Normal_Map"
- image = bpy.data.images.new(image_name, width=1024, height=1024)
- Create a new material and assign it to the active object
- mat = bpy.data.materials.new(name="Bake_Mat")
- bpy.context.active_object.data.materials.append(mat)
- Enable use of baked normal map
- mat.use_nodes = True
- nodes = mat.node_tree.nodes
- texture_node = nodes.new("ShaderNodeTexImage")
- texture_node.image = image
- texture_node.select = True
- nodes.active = texture_node
- Set bake settings
- bpy.context.scene.render.bake.use_selected_to_active = False
- bpy.context.scene.render.bake.use_cage = False
- bpy.context.scene.render.bake.cage_extrusion = 0.1
- bpy.context.scene.render.bake.type = 'NORMAL'
- bpy.context.scene.render.bake.normal_space = 'TANGENT'
- bpy.context.scene.render.bake.normal_r = 'POS_X'
- bpy.context.scene.render.bake.normal_g = 'POS_Y'
- bpy.context.scene.render.bake.normal_b = 'POS_Z'
- Bake normal map
- bpy.ops.object.bake(type='NORMAL')
- Save the normal map image
- image.filepath_raw = "//normal_map.png"
- image.file_format = 'PNG'
- image.save()
- This will bake a tangent space normal map of the current frame, normalized with the typical blue as the Z direction. It will save the normal map as "normal_map.png" in the same directory as your Blender file.
- Let me know if you have any other questions! I'd be happy to explain or modify the script further.
Advertisement
Add Comment
Please, Sign In to add comment