Soft Shadows

BlitzMax Forums/BlitzMax Programming/Soft Shadows

tonyg(Posted 2005) [#1]
Has anybody got the skill/time/inclination to port this...

softshadows

I'm giving it a go but lack the skill/time which is making very slow progress.


ImaginaryHuman(Posted 2005) [#2]
Cool page, just what I was looking for.


SillyPutty(Posted 2005) [#3]
man, I would also like to see a bmax solution.


ImaginaryHuman(Posted 2005) [#4]
It looks like it is a little limited in that the objects that the light interacts with have to be convex polygon objects made of vertices. Most 2D stuff is not likely to be polygon based.


tonyg(Posted 2005) [#5]
How about user defined points simulating the boundary of the 2D image? I know it might be a pain but built into a map/tile editor with the corners as default it might be workable.
I thinking something like the Sprite Candy Shape Editor...
Sprite Candy

P.S. If anybody has other ideas on the best way and best features for a 2D Light/shadow system I'd be interested.
This impressed me (the gameplay is suspect though)...
2D lights


GrahamK(Posted 2005) [#6]
Nice Link Tony.

;)


ImaginaryHuman(Posted 2005) [#7]
Yah that's an interesting link although it looks more like a `light and shadows` demo than a game at the moment.

If you read some of the comments that follow that first article about the soft shadows, someone suggests putting vertices around the edge of irregularly shaped 2d objects and then using those as the `corners`, but I think if you do that you're going to have a lot of very thin polygons all over the place.

I guess it kind of depends on how your game environment is structures as to how you would think about doing lights and shadows.

Like I said before somewhere else, there is no such thing as shadows. Things begin with darkness and any light that you add creates areas that are lit - any untouched areas remain dark - ie shadows. So you can either model the shadows, or you can model the light. Or both. It's kind of tied in.

Also, try casting shadows that are produced by a detailed particle system. Lots of work.

Shadow-casting is really about line-of-sight, whether the light is visible from a given pixel and if so how much of it. Soft shadows are just produced by the fact that the light source has some width, so certain amounts of it can be seen from different angles. It's not really any different than hard shadows being cast by pinprick light sources.

I think you probably will either way have to make your own OpenGL/DX engine in order to implement them well.

It looks like the Max3D module has an automated shadow-casting system using a similar technique to the above article - ie with shadow volumes. Seems like a lot of work though.

That second article that TonyG posted, looks like they use a raycasting technique where you shoot rays out from the light source in lots of directions and find what objects each of the rays hits, which forms surfaces to create shadow polygons. It's a lot like how game engines like Doom etc do raycasting ... tracing lines across a map until you hit surfaces, speeded up by using something like a Binary Space Partitioning tree or a quadtree/octree.

I'm planning to have lights/shadows in the game engine I'm working on and I was thinking to use the latter technique, but the softshadows technique suggests it could be done without needing to cast rays so blindly. I guess if you know which objects occupy what areas, though, you can just cast rays through those areas to find the perimeters.

*shrugs*


tonyg(Posted 2005) [#8]
I really like Tea-Monkey's light/shadow process...
here
I also like the idea of the Soft Shadow process but I wonder whether it can be simplified (or done with native Bmax). Maybe...
Divide your objects into 'irregular' shadow casters , blocking objects and 'regular' shadow casters.
Irregular shadow casters cast a shadow similar to their own shape. See the ZombieBlast demo for an example.
Blocking Objects simply divide 2 areas so cast no shadow.
I.e. a wall to the ceiling with a light on one side.
Regular Shadow casters need to be calculated using a set of pre-defined boundary points. A ray is then cast to each point extended to meet the light radius mark.
Taking the 2 points furthest away from each other on the radius plus their connected predefined points creates your shadow area. In a B3D test I used floodfill within these boundaries. Awful B3D code with lots of errors but showing this near the end of this thread...
Crapcode
With the drawpoly command or using OpenGL it's possible to shade or texture the resulting shape although I haven't accounted for the curve. Maybe use the same method to create the triangle_fan as the soft-shadows but only to get the edge points. Assuming you have the edge points the following methods could be used to create the shadow geometry.
Drawpoly
Texturepoly
leaving some way to 'add' the softshadow fins.
The draw order is going to be difficult without using OGL buffers but, possibly...
dark setclscolor (60,60,60)
'Floor' tiles with shadeblend
Lights with lightblend
shadows with shadeblend
Other objects with lightblend.
Personal aim is to have ambient light (time-of-day dependant), physical lights and shadow.
All speculation at the moment but any comments welcome.


ImaginaryHuman(Posted 2005) [#9]
I don't really understand what you're visualising, not quite following it.

Maybe get it working and show us a pic?


tonyg(Posted 2005) [#10]
Did you manage to run the B3D code?
This shows my, very poor, method of calculating the shadow geometry. In the B3D code I used a floodfill algo but, with Bmax, you could use Drawpoly or bind a texture with GL_TRIANGLE_FAN which should be much quicker.
As yet there are no soft edges.
Anyway, I'm visualising something like this...
Golem
Golem2
but with the pillars casting a shadow from the lightsource.


ImaginaryHuman(Posted 2005) [#11]
Not on a PC here, no B3D.

The Golem thing is interesting, would be interesting to see light/shadows in isometric. Adds another element to it.