[Sandy] lighting and a quick demo

Petit petit at petitpub.com
Wed Apr 11 16:48:09 EDT 2007


Martin, welcome to the dev team!

Your demo is quite beautiful, and the idea of precalculated lit textures 
sounds appealing.
I guess the advantage would be less if the skin is a MovieSkin with 
animation or a VideoSkin,
where the texture is changed for each frame ( of the world rendering or 
of the movie/video ).

1. I like the idea of ambient light.
2. Lighting calculation is something for the chief developer to decide - 
Thomas :)

Martin Wood-Mitrovski wrote:
> Here's a little something im working on which i'll add to SVN when its finished,
> its a prelit texture skin. you can see a quick demo here :
>
> http://relivethefuture.com/code/sandy/sandytest.html
>
> I was quite shocked by the drop in performance when i first enabled the lighting 
> on a texture skin so I did some investigation and noticed that the
>
> _tmp.applyFilter( _tmp , _tmp.rectangle, _p,  _cmf );
>
> call is incredibly slow, so slow that it makes any kind of animation practically 
>   unusable.
>
> So, I thought that one way to get around the problem is to precalculate a set of 
> lit textures and then I can completely avoid the applyFilter call, I just needed 
> a way to map the lighting strength to an index into my texture list.
>
> (Of course this comes at the expense of some memory, but at least it runs fast)
>
> Before I commit there are a couple of things I want to discuss to see what 
> peoples ideas and opinions are.
>
> 1. Ambient lighting
>
> I found it really useful to add an ambientLight setting to World3D so I could 
> control what the darkest possible lighting strength is in the scene.
>
> My initial implementation is just a number, i.e. white light, which gets added 
> on to the computed light strength.
>
> 2. Lighting calculation
>
> At the moment the light direction vector isnt normalised so the strength 
> calculation is affected by how the light is specified when its created. I think 
> for the current implementation it would be better to normalise the light 
> direction vector.
>
> This is the current code :
>
> <code>
> var dot:Number 	= lp - ( VectorMath.dot( l.getDirectionVector(), 
> f.createNormale() ) );
> </code>
>
> As you can see the light strength is calculated by doing a dot product of the 
> direction vector with the current face normal, so if they are both normalized 
> the dot product (DP) range will be restricted between -1 -> 1.
>
> Now, the code above works by subtracting the DP from the light power (lp) 
> because you want the maximum light when the DP is lowest (-1). What I think 
> would be a better solution is to instead invert the DP, multiply it with the 
> light power and then add the ambient lighting.
>
> <code>
> var DP:Number = VectorMath.dot( l.getDirectionVector(), f.createNormale()) * -1;
> // if DP is less than 0 then the face is facing away from the light
> // so set it to zero
> if(DP < 0) DP = 0;
> var lightStrength:Number = (lp * DP) + ambientLight;
> </code>
>
> this then gives you a light strength ranging from the ambientLight level to 
> (light power + ambient light)
>
> One other small detail is in the skin the light power is scaled down like this :
>
> var lp:Number	= 0.01 * l.getPower();
>
> but I think it would be better to implement l.getNormalizedPower() to scale the 
> light power between 0 and 1 (by using MAX_POWER in Light3D).
>
> I think that about covers it all, apologies for the long post but I thought it 
> would be better to go into detail. :)
>
> id be interested to hear your ideas and opinions.
>
> thanks,
>
> Martin
>
>
> _______________________________________________
> Sandy mailing list
> Sandy at osflash.org
> http://osflash.org/mailman/listinfo/sandy_osflash.org
>
>
>   




More information about the Sandy mailing list