A really easy way to do real-time shadows that is applicable for actual game use

Blitz3D Forums/Blitz3D Programming/A really easy way to do real-time shadows that is applicable for actual game use

"You realize your shadow resolution is like way higher than the highest setting in Unreal II?"

No, I had no idea, I have not played Unreal II. The shadow res can be lowered to 128x128 in the demo, it defaults to 256x256. Are you saying the shadows in Unreal II are lower than 128x128?


"I assume you are using a combination of the distance between the sphere center and a plane defined by the triangle, and the distance between the triangle verts and the center of the sphere?"

Right now, I am using a shadow frustrum made from planes and determining if all of the triangle's vertices are on the outside of any one of the planes.

That is taking 5-6 muls on average per triangle. Sometimes as many as 7.



"I assume you are using a combination of the distance between the sphere center and a plane defined by the triangle, and the distance between the triangle verts and the center of the sphere?"

And I have no clue what you are saying. Are you talking about some way of storing the triangle sphere?

Because what I inteded to do was find a sphere that encompassed the points of the triangle, not neccessarily a very close fit sphere, but close enough, and then determine that sphere's squared distance from a shadow ray, and if that distance was greater than a squared radius of the shadow ray then the triangle would definitely be outside the shaodw view frustrum.

However, I am finding that calculating the sphere that contains the points alone would take like nine muls, three divides, and some IFs.

To find the sphere that encompasses the points, first I must average the points to find the center of the triangle. That requires a divide for each axis.

Then I have to find the squared distance of each of the points to the centerpoint I just calculated.

To do that I have to use three muls for each vertex.

And then I have to choose the distance which is the greatest, which will require between 1 or 2 if statements.

Once that is done I'd have the coordinates and radius of my sphere.

Now, I COULD precalculate all that. I'd rather not get into precalculating stuff though, more than I already have.

Anyhow, then I would find the closest point on my ray to that sphere.

Unfortunately, this is the straw that breaks the camel's back.

To find the distance of a point to a line requires six muls and a divide. Which is more expensive than the current system.

Hm. And I thought I was onto something there for a minute.

Still, I refuse to accept that I need to do 6 muls per triangle just to trivially discard them.

I could perhaps pre-sort the triangles into some kind of bsp tree or put them into a cube array but that would be cheating. And besides I don't know enough about BSP trees to figure that one out easily right now. And I don't want to have to store all the vertex info for a mesh in the shadow system.

I'll find a way.