Extensions:2.4/Py/Nodes/Cookbook/Textures
< Extensions:2.4 | Py | Nodes | Cookbook(Resources/PyNode Cookbook/Texturesから転送)
Ideas
- Noise node: see http://www.blender.org/documentation/246PythonDoc/Noise-module.html for inspiration. Basically this should allow one to reimplement various textures found in Blender already.
- Add your idea here.
Recipes
Blend
This script produces a simple gradient from given color to black. Making second color customizable is left as an exercise to the reader.
from Blender import Node
class BlendNode(Node.Scripted):
def __init__(self, sockets):
vector = Node.Socket('Vector', val = 3*[1.0])
col = Node.Socket('Color', val = 4*[1.0])
axis = Node.Socket('Axis', val=0.0, min=0.0, max=2.0)
sockets.input = [vector, col, axis]
sockets.output = [col]
def __call__(self):
fac = (self.input.Vector[int(self.input.Axis + 0.5)] + 1) / 2
self.output.Color = map(lambda x: x * fac, self.input.Color)
__node__ = BlendNode
Brick
This script generates a simple texture. Use axis to define axis on which direction it is headed to.
from Blender import Node
class BrickNode(Node.Scripted):
def __init__(self, sockets):
vector = Node.Socket('Vector', val = 3*[1.0])
col1 = Node.Socket('Main_Color', val = 4*[1.0])
col2 = Node.Socket('Seam_Color', val = 4*[1.0])
w_frequency = Node.Socket('W_Frequency', val=5.0, min=-100.0, max=100.0)
h_frequency = Node.Socket('H_Frequency', val=5.0, min=-100.0, max=100.0)
seam = Node.Socket('Seam', val=.1, min=0.0, max=1.0)
axis = Node.Socket('Axis', val=0.0, min=0.0, max=2.0)
col = Node.Socket('Color', val = 4*[1.0])
sockets.input = [vector, col1, col2, w_frequency, h_frequency, seam, axis]
sockets.output = [col]
def __call__(self):
tex_coords = self.input.Vector
axis_int = int(self.input.Axis + 0.5)
if axis_int == 0:
x, y = tex_coords[2], tex_coords[1]
elif axis_int == 1:
x, y = tex_coords[0], tex_coords[2]
else:
x, y = tex_coords[1], tex_coords[0]
col = self.input.Seam_Color
if self.input.W_Frequency * x % 1.0 > 0.5 + self.input.Seam:
if self.input.W_Frequency * x % 1.0 < 1.0 - self.input.Seam:
if self.input.H_Frequency * y % 1.0 > self.input.Seam:
col = self.input.Main_Color
elif self.input.W_Frequency * x % 1.0 < 0.5 - self.input.Seam:
if self.input.W_Frequency * x % 1.0 > self.input.Seam:
if self.input.H_Frequency * (y + y / 2) % 1.0 < 1.0 - self.input.Seam: # TODO: offset could be better
col = self.input.Main_Color
self.output.Color = col
__node__ = BrickNode
Chess
This script produces a simple chess pattern. Use axis to define axis on which direction it is headed to.
from Blender import Node
class ChessNode(Node.Scripted):
def __init__(self, sockets):
vector = Node.Socket('Vector', val = 3*[1.0])
col1 = Node.Socket('Main_Color', val = 4*[1.0])
col2 = Node.Socket('Seam_Color', val = 4*[1.0])
w_frequency = Node.Socket('W_Frequency', val=5.0, min=-100.0, max=100.0)
h_frequency = Node.Socket('H_Frequency', val=5.0, min=-100.0, max=100.0)
seam = Node.Socket('Seam', val=.1, min=0.0, max=0.5)
axis = Node.Socket('Axis', val=0.0, min=0.0, max=2.0)
col = Node.Socket('Color', val = 4*[1.0])
sockets.input = [vector, col1, col2, w_frequency, h_frequency, seam, axis]
sockets.output = [col]
def __call__(self):
tex_coords = self.input.Vector
axis_int = int(self.input.Axis + 0.5)
if axis_int == 0:
x, y = tex_coords[2], tex_coords[1]
elif axis_int == 1:
x, y = tex_coords[0], tex_coords[2]
else:
x, y = tex_coords[1], tex_coords[0]
col = self.input.Seam_Color
if self.input.W_Frequency * x % 1.0 > 0.5 + self.input.Seam:
if self.input.H_Frequency * y % 1.0 > 0.5 + self.input.Seam:
col = self.input.Main_Color
elif self.input.W_Frequency * x % 1.0 < 0.5 - self.input.Seam:
if self.input.H_Frequency * y % 1.0 < 0.5 - self.input.Seam:
col = self.input.Main_Color
self.output.Color = col
__node__ = ChessNode
Mod 1
This script produces a stripy texture.
from Blender import Node
class ModNode(Node.Scripted):
def __init__(self, sockets):
vector = Node.Socket('Vector', val = 3*[1.0])
col = Node.Socket('Color', val = 4*[1.0])
frequency = Node.Socket('Frequency', val=5.0, min=-100.0, max=100.0)
axis = Node.Socket('Axis', val=0.0, min=0.0, max=2.0)
sockets.input = [vector, frequency, axis]
sockets.output = [col]
def __call__(self):
tex_coords = self.input.Vector
col = 0.0
if self.input.Frequency * tex_coords[int(self.input.Axis + 0.5)] % 1.0 > 0.5:
col = 1.0
self.output.Color = 3*[col] + [1.0]
__node__ = ModNode
Mod 2
This script produces a beach balloony texture.
from math import atan2
from Blender import Node
class Mod2Node(Node.Scripted):
def __init__(self, sockets):
vector = Node.Socket('Vector', val = 3*[1.0])
color1 = Node.Socket('Color1', val = 4*[1.0])
color2 = Node.Socket('Color2', val = 4*[1.0])
threshold = Node.Socket('Threshold', val=0.5, min=0.0, max=1.0)
frequency = Node.Socket('Frequency', val=5.0, min=-100.0, max=100.0)
axis = Node.Socket('Axis', val=0.0, min=0.0, max=2.0)
col = Node.Socket('Color', val = 4*[1.0])
sockets.input = [vector, color1, color2, threshold, frequency, axis]
sockets.output = [col]
def __call__(self):
tex_coords = self.input.Vector
axis_int = int(self.input.Axis + 0.5)
if axis_int == 0:
x, y = tex_coords[2], tex_coords[1]
elif axis_int == 1:
x, y = tex_coords[2], tex_coords[0]
else:
x, y = tex_coords[1], tex_coords[0]
self.output.Color = self.input.Color1
if self.input.Frequency * atan2(y, x) % 1.0 > self.input.Threshold:
self.output.Color = self.input.Color2
__node__ = Mod2Node