Vol. 1 · No. 338Blender 3.6 / 4.2 / 4.5 / 5.0 / 5.2 / 5.3Cycles · EEVEE
JANCTION
Render · Blender on RTX PRO 6000 · 東京
0.1 円/ GPU 秒最初の 100 円無料・カード不要

第 9 号  質感

被写界深度の浅いビー玉(f/1.8)

f/1.8 のビー玉。cam.data.dof の浅い被写界深度。

● 質感 · CyclesRTX PRO 6000 · 東京
被写界深度の浅いビー玉(f/1.8)
Cycles1920 × 1080サンプル 128PNG
図 — 被写界深度の浅いビー玉(f/1.8)。 本番の GPU で描いた本物の結果。
短い答え

本番の GPU で描いた本物の結果と、そのまま動く bpy スクリプト、設定、GPU 秒。スクリプトの URL を scene_url に渡せば同じものが出ます。本番の GPU で 7.3 GPU 秒、0.1 円/GPU 秒で 0.7 円。

写っているもの

テーブルにパステルのつやのあるビー玉と、いくつかのクロム。1 つにピントが合い、ほかは柔らかくぼけていきます。被写界深度は、小さな物をレンズに近く感じさせるものです。

シーンの組み方

スクリプトでカメラの被写界深度を有効にしています。focus_object で 1 つのビー玉にピントを固定し、f/1.8 の絞りで合焦の幅を狭くします。Cycles はぼけを物理的に描くので、きれいに保つにはサンプル数が要ります。ノイズ除去は既定で有効です。

自分用に変える

絞りの値を上げるとピントの合う範囲が広がります。focus_object を別のビー玉に向けることもできます。1080p の仕上げの前に 720p の試し描きでぼけを確かめます。

0.7 円 でこの 1 枚。新しい鍵の無料のようこそクレジットなら、カード無しで約 137 回分。

この作例を自分の AI で描く

ChatGPT · Claude · Grok · Perplexity

JANCTION Render(MCP サーバー https://render.janction.jp/mcp)で、この作例を描いて: render_preview(scene_url="https://render.janction.jp/samples/ex09_macro_marbles.py")。そのあと、私の題材に合わせて色・形・カメラを変える案を出して。仕上げの前に確認して。

リンクを押すと、下の文が入った状態でそのアプリが開きます(入らないときは写して貼ってください)。そのアプリに JANCTION Render をまだつないでいなければ、先にコネクタとして https://render.janction.jp/mcp を足してください。

Blender の警告

  • environment preset 'studio' replaced the scene's world (HDRI lighting)

スクリプト(bpy、そのまま動く)

ex09_macro_marbles.py。シーン・カメラ・コマ範囲だけを組み、解像度・サンプル・ノイズ除去・GPU はサービスが決めます。

"""JANCTION Render example 09: marbles on a wooden table, shallow depth of field at f/1.8 (one still).

Reproduce: render_final(scene_url="https://render.janction.jp/samples/ex09_macro_marbles.py",
                        width=1920, height=1080, samples=128, environment="studio")
Depth of field is cam.data.dof: focus_object picks the sharp marble, aperture_fstop sets the blur.
"""
import random

import bpy
from mathutils import Vector

for ob in list(bpy.data.objects):
    bpy.data.objects.remove(ob, do_unlink=True)
scene = bpy.context.scene
scene.frame_start = 1
scene.frame_end = 1


def material(name, color, roughness=0.5, metallic=0.0, **inputs):
    mat = bpy.data.materials.new(name)
    mat.use_nodes = True
    bsdf = mat.node_tree.nodes["Principled BSDF"]
    bsdf.inputs["Base Color"].default_value = (*color, 1.0)
    bsdf.inputs["Roughness"].default_value = roughness
    bsdf.inputs["Metallic"].default_value = metallic
    for key, value in inputs.items():
        bsdf.inputs[key].default_value = value
    return mat


def smooth(ob):
    for p in ob.data.polygons:
        p.use_smooth = True
    return ob


def add(op, name, mat=None, **kw):
    getattr(bpy.ops.mesh, op)(**kw)
    ob = bpy.context.object
    ob.name = name
    if mat is not None:
        ob.data.materials.append(mat)
    return ob


def look_at(ob, target):
    ob.rotation_euler = (Vector(target) - ob.location).to_track_quat("-Z", "Y").to_euler()


def light(name, kind, location, energy, target=None, size=1.0, color=(1.0, 1.0, 1.0)):
    data = bpy.data.lights.new(name, kind)
    data.energy = energy
    data.color = color
    if kind == "AREA":
        data.size = size
    ob = bpy.data.objects.new(name, data)
    scene.collection.objects.link(ob)
    ob.location = location
    if target is not None:
        look_at(ob, target)
    return ob


table = material("Table", (0.45, 0.28, 0.16), roughness=0.35)
add("primitive_plane_add", "Table", table, size=12)

colors = [(0.9, 0.2, 0.15), (0.2, 0.5, 0.9), (0.95, 0.75, 0.2), (0.3, 0.75, 0.35), (0.85, 0.85, 0.9),
          (0.6, 0.25, 0.7), (0.95, 0.5, 0.2), (0.2, 0.7, 0.7), (0.95, 0.95, 0.95)]
rng = random.Random(3)
focus = None
for i, color in enumerate(colors):
    gx, gy = i % 3, i // 3
    x = (gx - 1) * 0.72 + rng.uniform(-0.12, 0.12)
    y = (gy - 1) * 0.72 + rng.uniform(-0.12, 0.12)
    if i in (4, 8):
        mat = material("Marble%d" % i, color, roughness=0.15, metallic=1.0)
    else:
        mat = material("Marble%d" % i, color, roughness=0.05, **{"Coat Weight": 1.0, "Coat Roughness": 0.02})
    ball = add("primitive_uv_sphere_add", "Marble%d" % i, mat, radius=0.3, segments=96, ring_count=48, location=(x, y, 0.3))
    smooth(ball)
    if i == 4:
        focus = ball

light("Key", "AREA", (1.5, -1.5, 2.0), 150, target=(0, 0, 0.3), size=1.5)

data = bpy.data.cameras.new("Camera")
data.lens = 60
data.dof.use_dof = True
data.dof.focus_object = focus
data.dof.aperture_fstop = 1.8
cam = bpy.data.objects.new("Camera", data)
scene.collection.objects.link(cam)
cam.location = (0.5, -3.1, 1.35)
look_at(cam, (0.0, 0.0, 0.3))
scene.camera = cam

この号の質問

Python で Blender のカメラに被写界深度を付けるには

cam.data.dof.use_dof = True にし、focus_object か focus_distance を決め、aperture_fstop を設定します。値が小さいほどピントが浅くなります。

ノイズ除去は既定で有効ですか

有効です。denoise=false で切れます。

ほかの号