4 ms·
He uses a nice trick to approximate the real thing, however this algorithm wouldn't be able to deal with curved objects.
by Mithaldu 13y ago
He uses a nice trick to approximate the real thing, however this algorithm wouldn't be able to deal with curved objects.
- dllu 13y agoYou can simply shoot some rays tangent to each curve in addition to the endpoints/vertices.
- Mithaldu 13y agoI'm not too strong with trig. Would this also work with curves that have more than one bump? (sine, etc.)
- dllu 13y agoYes, with calculus you can find all the tangent lines from a point to any kind of curve. The exact equations vary based on what kind of curve it is (sine, parabola, cubic splines, Bezier curves, non-uniform rational B-splines, etc) and are kinda complicated.
- Mithaldu 13y agoHm, then it becomes a question of whether that can be ran fast enough and remain realtime. :)
- awj 13y agoAt that point you're no longer dealing with rays and the math gets way more expensive for a goal of 1/60th of a second per render loop.
- kevingadd 13y agoAny of this is absurdly trivial on modern graphics hardware, you can literally do all of the geometric math to compute your shadow volumes on the GPU and it will be a miniscule portion of your frame time.
- vlasev 13y agoLet P be the point (a,b) and let Q be the point (x(t),y(t)) of a curve for some parameter t. The tangent vector to that curve is (x'(t),y'(t)) and the ray PQ is just (a-x(t),b-y(t)). You need to make sure these vectors are the same (up to a constant multiple) in order to have a tangent ray. That is you are led to two equations cx'(t) = a-x(t) cy'(x) = b-y(t) You need to solve these two equations for values of c and t. The difficulty of this task depends mostly on the difficulty of the curve itself. If the curve has equation y = f(x) (or in other words a simple representation x(t) = t and y(t) = f(x(t)) = f(t)), then you have c = a-x cf'(x) = b-f(x) Therefore (a-x)f'(x) = b-f(x). If f(x) is a polynomial of degree n, the problem is reduced to root-finding of a polynomial of degree n so you'll have at most n roots to deal with. So in general it won't be easy. This reduces to the code in the post if you use line segments.
- forrestthewoods 13y agoI'm downvoting your comment because on technical posts the top rated comment is damn near always of zero value and only serves to make the commenter try to sound smarter than the post author. The more in-depth and complicated the post the more those type of comments appear. This is a nice little post that reasonably describes a technique that has been used by a fair number of professional, commercial products. That anyone would try to downplay it to make themselves feel superior is silly. To provide some actual value, most of the the images in the post are actually interactive. It's pretty cool. I somehow read the whole thing and didn't notice.
- sartakdotorg 13y agoYou didn't read very carefully if you missed that everything was interactive. "Today, I will show you how to make something like this: (move your mouse around in the box below)" "The demo below just draws a bunch of line segments and tracks your mouse position." "Here's what all that math looks like: (move your mouse over the box)"
- forrestthewoods 13y agoYou are correct. I did not read very carefully. Thank you for pointing that out. I focused on the pretty pictures before reading all of the text. I can say with extreme confidence that I am not the only person who made the mistake of not reading carefully so I thought it worthwhile to mention.
- richforrester 13y agoSome of us only skim articles. It's not a sin.
- sartakdotorg 13y agoAgreed. But given the rest of forrestthewoods's post I thought it was worth pointing out.
- Mithaldu 13y ago
- User8712 13y agoCouldn't you do something like this for a hack? http://i.imgur.com/G5U43ZU.png http://i.imgur.com/G5U43ZU.png Calculate the edge points of the circle, draw a line between them, and then your shadow is simply a rectangle. Overlay the circle over the shadow to hide the line. This will work with circles and ovals, but not more complex curves.
- TophWells 13y agoThat's not a hack, that's actually the best way to do it. And it can work with more complex shapes (even non-convex ones) as long as you can find the tangent points - which isn't always easy.