Character shading
Blitz3D Forums/Blitz3D Programming/Character shading
| ||
..let say I have lightmapped level, with some trees on it..so when I move my character under some of the trees (inside shadow area), how to achieve that my character have effect like my character receiving that specific shadow over surface while its moving under tree?? |
| ||
It's called dynamic lightning and blitz doesn't support that afaik, maybe you can calculate the uv coordinates where your lightmap shadows are and check if your player is inside the shadow area then tint the player's color... Or you can use a dynamic shadow userlib like devil's child's to cast shadows from trees but that would be a huge performance hit. |
| ||
The simplest way may be to change the entitycolor of the entity you want to affect as it comes underneath things such as trees etc. IPete2. |
| ||
Yes but there will be no detailed shadows projected on player. And it may be a pain in the back to code it for every simple shadow casting model, for tweaking the distance properly. Anyway; If EntityDistance( Player, Tree ) < 300 EntityColor Player, 100, 100, 100 EndIf |
| ||
Well if you wanted to be a little more creative and perhaps clever, you'd put a pivot 1000 units directly above the player and cast down to it, if you see the player do nothing, if you don't use the above code. That way you only need to have one small raycast per loop and not have to worry about putting loads of code for objects. Also you could find out what was intefering and adapt the sahdow based on that response. Just needs a little creative thinking that is all. IPete2. |
| ||
An other, probably too sophisticated method is to pre-scan the 3D world and store the global illumination of every space cluster in a 3D grid. Depending on the resolution/waste of RAM you'll be able to do realtime GI. But this isn't very practical (and not even dynamic). So I'd do it like IPete said. |
| ||
Just have a lightmap texture for each object the player can walk on. Then pick below the character. get the UV coords of the pick, then check the lightmap at those UV coords to get the proper color / shade to apply to the character.; edit: i put somthing together from some code archive submissions that should work. Just call shadeentity on the character and pass the lightmap texture into it. |
| ||
@IPete2:"Well if you wanted to be a little more creative and perhaps clever, you'd put a pivot 1000 units directly above the player and cast down to it, if you see the player do nothing, if you don't use the above code. That way you only need to have one small raycast per loop and not have to worry about putting loads of code for objects." What if the shadow casting object isn't a tree but a wall? What if the shadow is not under the tree? :P RifRaf's solution is the best IMO I would stick with it. |
| ||
well, naughty actually was talking explicitely about trees. RifRafs solution may be pretty slow since it is using ReadPixel in the texturebuffer. The texture probably even ain't using flag 256, so this is going to take a while I'm afraid. Instead you better use an array or bank to hold that lightmap data, tho the redundant data my be a waste of RAM. |
| ||
ive used the picking UV method before Slow depends on how you use it. if you have 200 characters to pick every frame.. yeah. But you can even get clever on that and pick one character per frame, and you shouldnt be able to notice any latency in shading. Or you may just update characters in view, or within a given range to camera ect. cycling them one char per frame. If you wanted to take the time to make a hybrid of an array and UV picking minus the readpixel you would have the best of speed and accuracy. Just make your array the same size as your lightmap (this is IF you have one world lightmap) |
| ||
thank you RifRaf..your idea seems to be very nice...I need it only for main character, and eventually for 3-4 additional characters, per scene..thats all.. |
| ||
Youre welcome.. I went ahead and made an array version if you run into speed problems you can give it a go. The only differnce is you have to load the lightmap first with Lightmap_Array(lightmap) |
| ||
Yeah what jfk said really - the question was about trees, and I said a very simple solution, not even crafted really, off the top of my head. The entity color idea was fresh in my mind because I had just used it recently for a neat effect with hot water and my main character. RifRaf's idea is far more creative and what a neat idea to use lightmaps! I'm gonna look into that myself now. Fab work RifRaf! The other person to ask, but he's away in Europe next week, is Josh at Leadwerks, as he released a b3d demo a while back, with trees casting shadows onto the floor and moving in synch with the trees branches. There's a video on his website with it in. You can see it here: http://www.leadwerks.com/ it is called Living Forest Movie on the right side bar menu IPete2. |
| ||
that living forest demo is very cool. im going to try rifraf's idea myself good job. |