Shading a charactor based on a lightmap?

Blitz3D Forums/Blitz3D Programming/Shading a charactor based on a lightmap?

Craig H. Nisbet(Posted 2004) [#1]
Hi, I have a charactor on a terrain object. The terrain has a lightmap on it. Is it possible to some how get the light map info for the pixel where my charactor is standing on the terrain, and then use that pixels luma value to shade my charactor darker or lighter depending on the map? This way his shading would change if he went under trees. any ideas?


Perturbatio(Posted 2004) [#2]
if you know what vertex the character is near, you could use VertexU and VertexV to get the U/V coords, then get the pixel luminance value at that location (or perhaps faster would be to preload the luminance values of the texture into a bank or array).


jhocking(Posted 2004) [#3]
To figure out which polygon is beneath the character do a LinePick straight down and then call PickedTriangle


Bot Builder(Posted 2004) [#4]
If you know the direction of the light, you could also do linepicks in the opposite direction - probably more accurate.


poopla(Posted 2004) [#5]
Bot builder is correct. You are going to want to do more then just linepick once, might want to do a cemicircle of short casts to sample the lighting values from. Since it might be quite bright just next to the player, will *Sort* of simulate radiosity. Not accurately or anything, but better then nothing :).


JoshK(Posted 2004) [#6]
You are best off just checking for visibility between the character and the light posiiton. That will be pretty accurate, and match the shading of your lightmap.


Craig H. Nisbet(Posted 2004) [#7]
Haha, I cheated I guess. All I did to solve the problem was store the luma values of each pixal in the lightmap texure to an array, then check where the charactor was on the terrain and scale it to that array. Since the terrain mesh isn't rotated, it was pretty easy to scale the values. Seems to work fine for what I need. Thanks for the help though.


Michael Reitzenstein(Posted 2004) [#8]
I think the original Unreal (Tournament) checks the brightness of the lightmap texel right below the player, and lights the player accordingly.


aCiD2(Posted 2004) [#9]
theres something that does this on blitzcoder.com cant find it though, if anyone knows where it is, please tell me!


Warren(Posted 2004) [#10]
I think the original Unreal (Tournament) checks the brightness of the lightmap texel right below the player, and lights the player accordingly.

Actually, it picks the closest X lights (4-8 depending on your system specs) and hits the character model with them.


Craig H. Nisbet(Posted 2004) [#11]
How do you tell the system to only light a charactor with certain X lights? Doesn't it just light from all of them(the 8 it can display) at the same time?


Warren(Posted 2004) [#12]
"It" in my post being "Unreal Tournament". We didn't use hardware lights.

But if you want to do this in Blitz, I suppose you could determine which lights were closest to the character, hide the ones that are too far away, and then draw the character.


Michael Reitzenstein(Posted 2004) [#13]
Actually, it picks the closest X lights (4-8 depending on your system specs) and hits the character model with them

Oh. I wonder what game it was that did check the texel beneath, then.


Warren(Posted 2004) [#14]
I think the original Quake engine did that ...


Craig H. Nisbet(Posted 2004) [#15]
Is it possible to hide lights? Would this make them not affect the scene?