here’s a little subsurface scattering script i wrote. its in its very early stages, so don’t expect too much.
you can see its effect by doing the following:
- creating a mesh and a light.
- create a material for the mesh which uses vertex colours for extra light
- on the mesh editing panel, toggle on the vertex colours
- change line 6 on the python script to the name of the mesh’s data block (not to be confused with the object that owns the mesh)
- alt-p and wait…
- render
enjoy!
from Blender import *
import math
time1 = sys.time()
# this value may need to be adjusted according to the object's size
scale = 0.005
# change the name to whatever mesh data block you want to use
mesh = NMesh.GetRaw("Suzanne")
# happy sss-ing
faces = mesh.faces
alteredFace = range(len(faces))
for faceNum in range(len(faces)):
face = faces[faceNum]
verts = face.v
cols = face.col
alteredVert = range(len(verts))
for vertNum in range(len(verts)):
vert = verts[vertNum]
coords = vert.co
col = cols[vertNum]
scatter = NMesh.Col(col.r, col.g, col.b, col.a)
for fn in range(len(faces)):
f = faces[fn]
vs = f.v
cls = f.col
for vn in range(len(vs)):
v = vs[vn]
c = v.co
cl = cls[vn]
dist = math.sqrt(pow(c[0]-coords[0], 2) + pow(c[1]-coords[1], 2)+
pow(c[2]-coords[2], 2))
if dist > 0:
scatter.r = scatter.r + int(cl.r * scale / dist)
scatter.g = scatter.g + int(cl.r * scale / dist)
scatter.b = scatter.b + int(cl.r * scale / dist)
alteredVert[vertNum] = scatter
alteredFace[faceNum] = alteredVert
print faceNum
for faceNum in range(len(faces)):
face = faces[faceNum]
verts = face.v
for vertNum in range(len(verts)):
mesh.faces[faceNum].col[vertNum].r = alteredFace[faceNum][vertNum].r
mesh.faces[faceNum].col[vertNum].g = alteredFace[faceNum][vertNum].g
mesh.faces[faceNum].col[vertNum].b = alteredFace[faceNum][vertNum].b
print faceNum
mesh.update()
Redraw()
time2 = sys.time()
print "calculation time: ", time2 - time1


i’m in the process of moving back to school, but once i get i get settled i’ll post the updated code. for enquiring minds, my method does not use any official equations, just an algorithm that gives a rough calculation. one of its biggest problems is that since it looks to nearby vertices for scattered light, denser areas of the mesh tend to get over-lit.