light baking to vertices

Does anybody know how to script baking lighting to vertex colors? I need specifically vertex coloring (I know there are a couple of other scripts doing UV-map baking) - I need to read the values back after they’ve been baked.

Also, I’m trying to bake shadows - is this possible? I suppose I should ask in the texturing area…


Something like that :

You could look at this :
the faster method to record correct shadows.

Can you just bake into vert colors and not worry about textures?
theres 2 ways in blendeer.

  1. Bake radiosity- just turn maxEl down to zero and you wont get any subdiv.
  2. In vertex paint menu, run “Self Shadow” - for good results try a highlight angle between 5-20.


Is it possible to access either of those options via Python?


Both are accessable via python.
Blenders Radio bake is much more complex and makes all the meshes 1 blob, my self shadow script is ok for quick and dirty fake AO.

What are you interested in doing?


I’m not sure the self-shadow option would do it - basically, I need to calculate the amount of shadow from object A falling on object B because of lamp C. Will radiosity do shadowing, or does that require raytracing?

I’m also looking at the BRad script - I’ve used Radiance before, but it might be more information than I need.


hrm. can you explain more?

radio will do shadowing but it dosnt use lamps and its not precice.

if you just want to get a point and see if its in shadow or not you can use python to do ray casting (see Mathutils.RayIntersect()) -

If you wanted you could build some spacial subdivision structure so its not that slow.

Best explain the big picture though if you want better advice, :wink:

Simply with a lone line :

jms - I’ll give that a try - that seems easier than doing it manually!

Cambo -
I’m designing an architectural shading device, except that I want it to diffuse light rather than just block it. What I’d like to do is bake the light onto a plane on the ground, and then read the light levels from the verts of the plane. By counting the number that fall in a middle range (not dark, not direct sunlight), I could come up with a number to evaluate the success of the shade. Whew! Any ideas?


jms -
I just went looking in the API for Mesh.update, and found Mesh.vertexShade(). Is this the same? It seems more appropriate…


If its just a plane you could have the blender lamp an area light (or a lamp cluster) and render off an image in python - setting the camera location etc,
I have a function in decal bake that get a matrix from a quad - this could be used to set the camera location.
Load it up and read the pixel values.

If you prefer use a buggy and not reliable module …

Rather then cryticising the work of others, you could submit bug reports and help them in the development process.

Just as people submit bug reports for your scripts and help you maintain their quality.

The problem with Mesh getting fluids and softbodies has been resolved. Mesh has access to some data then NMesh dosnt- like TexMesh, uvSelection, activeGroup. in general NMesh is mature but gathering dust because its not activly maintained.

rocketship, are you looking for any shadowing? or shadowless lighting based on the surrounding lamps?

  • if no shadows are needed, you may use vertexShade(), if you find any bugs - of course report them and one of the py dev team will look at fixing.


I need both shadowing and indirect lighting (bounced light). Is this unrealistic?


if you wanted diffuse only it would be simple, for shadows too you can…
render an image off in blender, load it back and read the pixels…
(Wurth doing if you need many samples)

if you need under 40 or so samples you can try getting the points of light yourself, getting the lights, surrounding objects etc and then calculating weather there in shadow,

for complex scenes your much better off rendering.


What would be the easiest way of setting up the rendering in a script?

I’m imagining:

  1. Turn all objects except Plane to “Only Cast Shadows”
  2. Set a camera to the same transformation matrix as the plane
  3. Set the camera to orthographic and transpose it in Z the required amount (there’s probably a good relationship between camera scaling, distance and plane size)
  4. Render with Blender Internal

What do you think?

Is there a way to iterate through vertex colors in the Image module (ok, maybe I’ll just look!)


Rocketship, you got it-
Getting the quad into a camera matrix is tricky and you also have to get the aspect of the camera right, though not THAT big a deal.

Probably dont worry about other material settings (Only Cast Shadow’s)
if you render the camera close to the plane with its clipping set to just before the plane starts, other objects should not interfere. - Unless you have objects that are setting on or intersecting the plane.

Only material you need to worry about is the planes.

Once the image is rendered, you can load it back in, see BPyRender for some example code that does that. You can get the color values for the pixels and that can of course be used as vertex colors. - [image.getPixelI](file:///cvs_blender/blender/source/blender/python/api2_2x/doc/BPY_API/Image.Image-class.html#getPixelI)(x, y)


So, setting up the camera was no problem, but I don’t seem to be getting any reflected light :confused:, just ray-traced shadows- I even set up an entirely specular cube sitting right on the ground, and no luck. Does the Blender internal renderer do diffused reflections, or would I need Yafray(which wouldn’t work, because of the clipping planes)?

[edit]Hmm…by placing an ortho camera close to the surface and adjusting the scaling, I actually CAN get a [sort of] clipping plane with Yafray…


can you save a blend and the script? - havnt had thar problem before.

Hi Cambo,I would like to know if you script which bakes vertex normals to uv texture image works for animation too(mainly for meshes deformed by armature).
I need to recalc normals frame by frame(on deformed meshes) and use it in render(I have a custom node that do normal mapping)
Generating a sequence of images(with baked normals) could be a very useful feature,we can use as a movie texture.