[UPDATE: script v1.1] image based lighting in blender

Making a python script to put HDR Shop’s plugin lightgen’s text output to use in Blender…

tests at http://members.lycos.co.uk/kurppa/blender/hdr.html

C&C welcome as usual.

UPDATE: get the script at http://members.lycos.co.uk/kurppa/blender/hdr.html

Seems nice.

Eeshlo also has a script for IBL, but instead of using the text output of HDR shop (which wasn’t available at that time, if I remember correctly), it uses a downsampled version of the hdr file to place the lamps and spots.

http://www.stormpages.com/eeshlo/Blender_IBL.html

Martin

look at the end of this page:
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_b223new.htm

theeth: yea as I investigated all things related to hdr & stuff I found also eeshlos script… but after thinking it was qute old and wouldn’t work anymore after the python api changes & all thought it would be cool to write my own version.

also started this to learn to make a gui to a script… not yet at that point but getting there bit by bit…

jms: my french isn’t too good but from what I could make of the site with systransoft I dunno quite what you were after…

It was already available but somebody else was creating a script for that back then. It never was released though. I had actually included this in my own version of the script, but also never released it, the script didn’t seem to be used all that much, probably made it too complicated, and the python api wasn’t as developped as it is now. There is an example of it on the method comparison page (the R2D2 pictures).

Anyway, nice work kurppa!

I used to use Eeshlo’s scripts and recently did a new test. Don’t rember but think I used Blender 223. Worked fine. Look here for the test.
https://blenderartists.org/forum/viewtopic.php?t=14095
But I like the idea of what you are doing too. Can’t have too many ways to use HDRI.
Paradox

I don’t really wish to criticize it, but I’m not sure if that really is a good example of HDRI, it seems more like an environmentmapped sphere reflecting the background. Any panorama (spherical mapped) picture could be used for that. I don’t really see how the script helped accomplish this, you don’t need any lights for this type of render.
But anyway, thanks for giving the script a try though. :wink:

Thank you Eeshlo, I realize that an enviroment map would work, but I used a sphere because I had done a sphere in yafray using that probe and I wanted to compare results. One result is the yafray one took 30 mintues and this one took less than 2. And they looked similar. Most of my older examples using your script went bye bye with my last hard drive. I guess I’ll have to make some new ones because your script does produce great results iand a lot faster than ray tracing.
And in that same thread the sphere thing was mentioned so I refered him to your site to show a better example of your HDR lighting. (refering to the box glass sphere skull picture).

Paradox

When you parse an image with the hdri lightgen, the soft creates
a text file with the color and the position of each point of light. So
you just have to read this file and add the lamps in Blender. The
positions are given on a sphere with a radiaus = 1.0 .


# ----------------------------------------
# Hdrshop Light Importer v0.1 
# Jm Soler 03/2003
# this script is under GPL licence.
# ----------------------------------------
import Blender
from Blender import *
rayon=15.0 #radius
version=Blender.Get('version')
filename="G:/stock_logiciel_et_plugin/hdrshop/test.txt"
if version>=225: 
   scene=Scene.getCurrent()
   f=open(filename,"r")
   tableau=f.readlines()
   f.close()
   for n in range(len(tableau)):
   if tableau[n].find('Color:')!=-1:
     c=tableau[n].split(' ')
     print c
     if version>=225:
       objet=Object.New(Object.Types['LAMP'])
       if tableau[n+1].find('Direction:')!=-1:
          d=tableau[n+1].split(' ')
          objet.loc=(float(d[1])*rayon,
                     float(d[2])*rayon,
                     float(d[3])*rayon)
       lampe=Lamp.New('Lamp')
       lampe.R=float(c[2])/256.0
       lampe.G=float(c[3])/256.0
       lampe.B=float(c[4])/256.0
       objet.link(lampe)
       scene.link(objet) 

get the script at http://members.lycos.co.uk/kurppa/blender/hdr.html

it’s my first ever released python script & my firs ever script with gui so don’t be to hard on it.

When you parse an image with the hdri lightgen, the soft creates
a text file with the color and the position of each point of light. So
you just have to read this file and add the lamps in Blender. The
positions are given on a sphere with a radiaus = 1.0 .
[/quote]

I know, I was refering to Paradox’s example picture, not your or kurppa’s script.

Anyway, congratulations with your first script kurppa!

could someone please explain this to me:

From the lightgen plugin:

The image must be in longitude/latitude format.
The positions of the lights are in the coordinate system where +Y is up,
+Z corresponds to the center of the lightprobe image, and +X corresponds to one quarter from the right border of the lightprobe image.
Note that the number of lightsources generated may in some cases be
less than the number specified.

Is this actually a sphere they are talking about because they go on to mention:

Suggested parameter values: Use a 128 x 64 lightprobe image.

Do they mean take the lightprobe and resize it to these x and y dimensions? and must it be “flattened” out (relevant image data to all 4 corners as opposed to a sphere)

The idea of doing lightprobes in blender is fantastic. If I could only figure it out.


kurppa

Nice script !

How do you set the DIST value for the lights? With Radius set to 20 its fine but if I want it at 60 I should actually be able to increase the light distance.

Cant figure it out.

thanks

soletread: didn’t think the DIST value would be so important because the main thing is to use spot lamps but will add that as a button in next version! or if you can’t wait you can create the lamps with radius 20 and then select them all and put the cursor in the middle of them. then press DOT-KEY for scale from cursor. and scale the lamps with S-KEY & voila!

kurppa

I am using spot lamps. But maybe I am not quite understanding what the spot lamps are actually doing.

If I scale like you say, the DIST value remains the same. The clip end is only or shadows right?

:expressionless:

hmm… thought it would work because the lamp’s cone in the 3d window grows bigger with scaling… but it really doesn’t do a thing to the DIST value…

oh well… then you have to wait for tomorrow for v1.2… any other suggestions of what to add to the script while I’m at it?

Nothing to add that I can think of right now. Thanks for asking :smiley: (Maybe a way af making all the spots point to the centre by default? Thats all, a very useful script as is.

I tried experimenting a little with it and thought just as a quick fix I could rig the Dist value to be the same as the radius. The results appear good with the 20 / 20 as the default values so I figure these ratios are good.

so I tried:

l.setDist(radius.val)

I get: Attribute error setDist

setDist is listed in the documentation, but still get this error.

So there went that idea.


kurppa

stiv informs me that setDist() is buggy.

He suggested using l.dist, which I did and it works nicely.

So I added: l.dist = radius.val to both light creation and light edit routines and now no matter what radius you choose, the spots will always have the correct dist value and create the same results.

Now just to get those lamps to point inwards.

Can one assign a track to constraint in python? It would probably be easier to create an empty then a track to and then delete the empty afterwards. Rather than working all that trig stuff to make them point the right way.

cheers

way cool! couldn’t figure it out myself… now must try that too!

but for the rotation it would really be best to do the stuff with the script without any track-constraints… and the math isn’t really that hard… might add it myself but you can find the equations to do it anywhere or do it any way you like… then just parent all the lamps to the empty after rotating them and you’re all set and done all with the script…