Python Shadow baking

Hello, heres a script I just wrote to experement with shadows.
At the moment it does AO but it could be modified to do radiosity fairly easily (multiple bounces and transfor color) - lights also

It uses a spacialy subdivided tree to get verts proximity. this is how it avoids being realy realy slow.
Once this datas collected it doesent change, so it could be re-used to do multiple passes. emit etc.

Feel free to play with it and make new versions or whatever. - Lines 260 to 280 have the fun stuff to play with,

  • image removed

It gives me error in line 293, “ZeroDivisionError: float division”.

Try some different values, if you get that error it means the range of the color go’s from 0 to 0 so you wouldent have usefull results anyway.

or maybe theres a case I didnt account for that should work but dosent…

I think i’m not doing things right. Can you put an example blend with already changed values?:o

Try this with default distance

I got it!
Interesting script. Have to make more tests.

Glad you got it working, incase you didnt see the message its a fair bit faster when psycos installed.

Update script (script inside blend too)
Added some checks so you shouldent get an error now.

  • was thinking it would be cool to build 2 way connection data between verts so rather then each vert looking for all the verts in front of it (what its doing now)
    it could be calculated, saved for both verts and then reused.

It would be interesting to assume darkness and
and do some trick with - even make selected verts act as lights would be a quick way, but light support could be added in. or use initial vertex colors as lights, a bit like how blenders radiosity uses the materials emit value.

i’ve been waiting for this one :slight_smile:

what would it look like if you multiplied the results of this with the results of MaSelf or the AO self shadow?

Hi Lucid monkey.
You can now. Shdow baker in the CVS multiplies with current colors.

I have been experementing and this script needs a UI with gammut values that can be tweaked. - once the tones generated it would be fast enough to update.

Hi Cambo,

Very nice script. I’m using it to rapidly create self-shadow maps for a vehicle in a game. One question though: I sometimes get this error “no verts in range, use a larger range”. What does this mean? How do I fix this?


The way self shadow works-
Each verts ‘pointyness’ is measured, so you can be up to 180d convex (pin sharp) or 180d hole. - so between 180 sharp and 180 concave your verts are shaded, however sometimes you dont have anything that concave or sharp.
or theres no desire for a pin tip to be brighter then a flat area.

so you can say 10d for the brightest area. 10d or more will be light, and say 90d for the darkest area…

The issue with verts being out of range is that there may be no verts concave for instance. so theres no range in which to do tonal ‘pointyness’ based shading.

Thanks Cambo. Can’t say that I completely understand your explanation, but appreciate your trying anyways :slight_smile:

Attached is a screen shot of one of the models I get the error message with.

Would you mind walking me through the steps you take to create the lightmaps at the top of the thread? The work flow I’m using is:

  1. UV unwrap my model
  2. Use your script to lightmap the vertices
  3. Use the “Texture Baker” script built into 2.42a.

Any advice or improvements you might recommend? Thanks!

Does this use vertex painting then and not affect the texture. Would it be something that could be used in a game scene with tiled textures? Could you do the whole scene at once?

Would you be able to uplaod the blend? - much faster for me to debug (blends are better then Images, saved me remodeling it)

About baking textures, I have made some scripts that are in blenders CVS and rely on newer features of Blenders python API.

  1. UV -> Archimap - just uv unwrap so any non overlapping uv map would do.
  2. Radiosity bake- self shadow woudl work too but for non connected objects its not good enough
  3. add new mesh in a new layer, from the radio tool once baked
  4. from the UV window “Image -> Bake Vertex Color Image from UVs”
  5. re-apply the resulting image to your un-subdivided mesh.

Thanks Cambo, I’ll give the Radiosity tool a try with Texture bake and see how that goes. I’m on a Mac and have no way of compiling from CVS at present, so I’ll just have to wait for 2.43 to see your latest goodies.

The problem I’ve had with BRrayBaker and Texture Baker are the seams that inevitably occur. I’m still learning this stuff, so hopefully my models will start to look better soon.

As for Fireside’s questions:
Yes to your first question. This script bakes the lighting info to the vertices of the mesh and so are independent of the meshes other material properties. I’m also trying to create a “lightmap” for a game model, so I hope the answer to your second question is yes also. I’m afraid the answer to your 3rd question is no, I haven’t found any way of baking the lighting for several objects at the same time. Here’s a link to the thread I’m following:

read this :

I tried running this script on an object and it said no verts in range select a larger range, which doesn’t do anything. I just put an object in the scene and ran the script, is there something else I’m supposed to do?

firesize, I think thats fixed in the CVS. could you upload a blend that causes the error?

Cambo: Can you PM me an email address? I’ll send you my file so you can play with it.

JMS: I went through your tutorial quickly yesterday. Your English is much better than my Francais, but I found your tutorial a bit confusing. I’ll go through it again today and see how it goes.

my emails on my dead homepage :wink: