1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Blender 4.2で虹を作る

Last updated at Posted at 2022-04-24

概要

Blenderで虹を作る方法を紹介します。
ポイントは、カラーランプのカラーモードをHSLにすると2色で十分というところです。

作成方法

細かい手順を説明するよりPythonで実行した方が簡単で間違いもないので、Pythonで作成します。
下記をコピペして実行してください。

"""
Make Rainbow
"""
import bpy

bpy.ops.mesh.primitive_circle_add(
    fill_type='NGON', rotation=(1.5708, -1.5708, 0))
obj = bpy.context.object
mat = bpy.data.materials.new(name="rainbow")
obj.active_material = mat
mat.use_nodes = True
mat.blend_method = "BLEND"
ndtc = mat.node_tree.nodes.new("ShaderNodeTexCoord")
ndtc.location = -800, 250
ndmp = mat.node_tree.nodes.new("ShaderNodeMapping")
ndmp.location = -630, 250
ndmp.inputs[1].default_value = -0.5, -0.5, 0
ndtw = mat.node_tree.nodes.new("ShaderNodeTexWave")
ndtw.location = -450, 250
ndtw.wave_type = "RINGS"
ndtw.rings_direction = "Z"
ndtw.inputs[1].default_value = 0.31
ndgr = mat.node_tree.nodes.new("ShaderNodeTexGradient")
ndgr.location = -450, -80
ndvr = mat.node_tree.nodes.new("ShaderNodeValToRGB")
ndvr.location = -260, 250
ndvr.color_ramp.elements[0].position = 0.949
ndvr.color_ramp.elements[0].color = 0, 0, 0, 0
p1 = ndvr.color_ramp.elements.new(position=0.95)
p1.color = 0.333, 0, 1, 1
ndvr.color_ramp.elements[2].color = 1, 0, 0, 1
ndvr.color_ramp.color_mode = "HSL"
ndvr.color_ramp.hue_interpolation = "FAR"
ndmv = mat.node_tree.nodes.new("ShaderNodeMath")
ndmv.location = -250, -110
ndmv.operation = "MULTIPLY"
ndpb = mat.node_tree.nodes["Principled BSDF"]
ndpb.inputs[0].default_value = 0, 0, 0, 1
ndpb.inputs[2].default_value = 1
ndpb.inputs[27].default_value = 1
mat.node_tree.links.new(ndtc.outputs[0], ndmp.inputs[0])
mat.node_tree.links.new(ndmp.outputs[0], ndtw.inputs[0])
mat.node_tree.links.new(ndmp.outputs[0], ndgr.inputs[0])
mat.node_tree.links.new(ndtw.outputs[1], ndvr.inputs[0])
mat.node_tree.links.new(ndgr.outputs[1], ndmv.inputs[1])
mat.node_tree.links.new(ndvr.outputs[0], ndpb.inputs[26])
mat.node_tree.links.new(ndvr.outputs[1], ndmv.inputs[0])
mat.node_tree.links.new(ndmv.outputs[0], ndpb.inputs[4])

参考:BlenderでPythonを実行する方法

円のオブジェクトの上半分だけ表示しています。

作成した虹のマテリアルは、下記のようになります。

以上

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?