Blender (software): Difference between revisions

 
(10 intermediate revisions by the same user not shown)
Line 20: Line 20:


===Geometry Nodes===
===Geometry Nodes===
[https://docs.blender.org/manual/en/latest/modeling/geometry_nodes/index.html Blender Manual Geometry Nodes]
Geometry nodes allow you to procedurally modify the geometry of the object.   
Geometry nodes allow you to procedurally modify the geometry of the object.   
Some things it can do include instancing of objects, moving vertices, and arithmetic.
Some things it can do include instancing of objects, moving vertices, and arithmetic
Note that Geometry nodes are available in Blender 2.92+ with some nodes introduced in 2.93 LTS.


See some references:
See some references:
Line 27: Line 30:
* [https://www.youtube.com/watch?v=TjGL4RjR13Q Making a raspberry by Bad Normals]
* [https://www.youtube.com/watch?v=TjGL4RjR13Q Making a raspberry by Bad Normals]
* [https://www.youtube.com/watch?v=52UYqe3zdxQ Making a gumdrop by Blender Guru]
* [https://www.youtube.com/watch?v=52UYqe3zdxQ Making a gumdrop by Blender Guru]
==Materials and Shaders==
Blender uses a node system for shader which let you composite different textures and BSDFS.
===Bypass BSDF===
If you wish to use a raw colors from a texture, bypassing materials altogether, you can directly attach a image texture node output to the material output.<br>
For transparent textures, you will need a transparent BSDF node and a mix node with alpha connected to <code>mix.outputs["Fac"]</code> to achieve transparency.


==Animations==
==Animations==


==Rendering and Compositing==
==Rendering and Compositing==
Press <key>F12</key> to render.
Press {{key press|F12}} to render.


===Denoising===
===Denoising===
Line 78: Line 88:
# Add material to an object
# Add material to an object
my_object.data.materials.append(my_material)
my_object.data.materials.append(my_material)
</syntaxhighlight>
====Images====
<syntaxhighlight lang="python">
# Add an image
image_bpy = bpy.data.images.new("my_image", width=width, height=height, alpha=(channels==4), float_buffer=False)
image_bpy.pixels = np.flipud(image_np).ravel()
image_tex_node = my_material.node_tree.nodes.new("ShaderNodeTexImage")
image_tex_node.image = image_bpy
my_material.node_tree.links.new(image_tex_node.outputs['Color'], my_bsdf.inputs['Base Color'])
</syntaxhighlight>
</syntaxhighlight>


Line 90: Line 109:
exec(compile(open(filepath).read(), filename, 'exec'))
exec(compile(open(filepath).read(), filename, 'exec'))
</syntaxhighlight>
</syntaxhighlight>
===Rendering===
<syntaxhighlight lang="python">
def render_to_file(filepath, width, height):
    # Set device to GPU
    bpy.context.scene.cycles.device = "GPU"
    # Set resolution
    bpy.context.scene.render.resolution_x = width
    bpy.context.scene.render.resolution_y = height
    bpy.context.scene.render.resolution_percentage = 100
    # Set output file path
    bpy.context.scene.render.filepath = filepath
    # Do render
    bpy.ops.render.render(write_still=True)
</syntaxhighlight>
===MVP matrices===
[https://github.com/blender/blender/blob/v2.93.0/doc/python_api/examples/gpu.9.py Example python code]
<syntaxhighlight lang="python">
# Model matrix
my_object.matrix_world
# View matrix
bpy.context.scene.camera.matrix_world.inverted()
# Projection matrix
projection_matrix = bpy.context.scene.camera.calc_matrix_camera(
    bpy.context.evaluated_depsgraph_get(), x=WIDTH, y=HEIGHT)
</syntaxhighlight>
===Python Modules===
To add modules, install them using pip to the <code>scripts/modules</code> directory of your Blender install:
<pre>
python3.9 -m pip install -t=scripts/modules $MODULE
</pre>
* If you installed blender using snap, you will need to create another scripts directory somewhere else.


==Compiling Blender==
==Compiling Blender==