Oh wow, I can’t believe my password to this place was still in the Firefox browser on this workstation :o
I’ve been flirting with the darkside (Direct3D) the last few years, but now thanks to WebGL (and the perennial hair yanker) here I am. Disclaimer: I’ve been working on restoring some old turn of the century software mainly which happened to be DirectX based.
Moving along. I’ve been doing a lot of stuff with graphics without ever running into any trouble for a long time… so I am humbled to be here looking for some schooling today. I haven’t invested a ton of time into this problem, but I went totally Moby Dick on it last night, so now I am trying to find some distance.
The problem is simple enough: http://www.swordofmoonlight.net/canvas.php?shadow=1 (link will need a WebGL browser)
Before bed I decided to see if a shadow would add anything to this model viewer project (about two weeks old 3D code wise) … I am pleased with the effect, which was simple enough to setup, and seems very natural versus the usual abstract ground plane visualization.
I expected to project things against the light in the shader, but I did two seconds of research and got the picture that you can use a matrix to do all the work for you.
I grabbed some code from here (http://www.opengl.org/resources/features/StencilTalk/tsld021.htm) and got started.
The projection was going in a snap and seems fine…
But that was not the end of my story :whistle:
PROBLEM STATED:
Shadows have a problem of being infinite… or nearly so. So that won’t work, because the shadow either gets lost beyond the far plane, or goes outside the viewport (which may need to be seamlessly blended over a background)
So the idea, is to be able to create a radial fog around the model (so the shadow will be blended into the background before it gets too far away)
It seems like a very simple problem. Alas I tried 3~5 distinct techniques and could not get a cleanly blended shadow. I am befuddled as to why not.
I don’t grasp the matrix construction frankly, but I don’t see how in model space the product of the matrix would exhibit the kind of dislocality I’ve observed. Like I say it looks good, but I may have set it up wrong and or am not appreciation its role.
The fog needs to be relative to the center of the model on display. So I calculate the distance from the shadow points for the basis of blending the shadow. I’ve tried that in local, model, view space, and screen space, and the distances are always discontinuous and generally dirty. For this model, around the base, the result is a nice radial bloom, as expected, but the projection of the spout is always disastrous…
I wish I could visualize the shadow matrix without running it through the projection matrix, but then it would not be visible would it. I can attest that along the Y plane the distances are uniform meaning the shadow plane in its own space is not askew, but otherwise I am stumped.
I can setup different scenarios on request. The source code can be seen in the link (have the browser pull it up) … if you want to tinker with the page you can save it (WebPage complete) and drop the files here (http://www.swordofmoonlight.net/jsom/test/o175.zip) into the folder with the root document. Mind you Google Chrome won’t let you access the files through the file:// protocol (so you would need to use Firefox)
Many features in the controls do not work yet, you just want to use the 1/2/3 radios and scrollbars (click to make them appear) in the WebGL app.
If you like the any of the unlicensed code feel free to take it / do whatever you want with it.
Apologies for the wordy post. Viva OpenGL :eek: