4
\$\begingroup\$

I am beginning an Spherical Harmonics shader project for an iOS app I am writing. I have begun by reading this excellent in-depth paper on the subject.

The paper describes a scene pre-processing step that involves ray-casting (one bounce, shadow feeler). Can someone describe how ray-casting can be performed using GLSL on iOS?

\$\endgroup\$
4
  • \$\begingroup\$ What is it that you want to use the spherical harmonics for? Is it just for lighting? \$\endgroup\$ Apr 25, 2012 at 18:56
  • \$\begingroup\$ That's an indepth paper on the subject? It simply pops out equations with 0 effort to justify them. It's simple to understand for someone who has previous experience with probability, integration, function reconstruction/approximation (Fourier series at least), but for someone who would indeed like the gritty details, it's really a failure to illustrate such concepts. Especially for someone whose notions of the lighting equation is the allmighty dot product, which he mentions briefly as the common lighting model at the time (and still is, but that paper is from ~2003.) \$\endgroup\$ Apr 27, 2012 at 1:46
  • 1
    \$\begingroup\$ That is the best introductory paper on the subject. There is also an implementation here and a section in a book called "Advanced Lighting and Materials with Shaders" \$\endgroup\$
    – bobobobo
    Jul 4, 2012 at 14:51
  • \$\begingroup\$ Also note this paper \$\endgroup\$
    – bobobobo
    Aug 10, 2012 at 20:07

2 Answers 2

1
\$\begingroup\$

The raycasting is a preprocess. It has nothing to do with GLSL.

You raycast to find ambient occlusion, really. Where a ray does not strike any geometry, it is "open to ambient lighting" from that direction.

What Green is trying to do on page 26 is estimate the ambient occlusion function in spherical harmonics. To do so he first generates a "sphere of rays" in every which direction (page 7). He evaluates the SH function on each (l,m) band and saves that in a data structure coupled with the ray direction.

Want: To estimate the ambient occlusion function at VERTEX in spherical harmonics

To estimate the ambient occlusion function at VERTEX in SH, you cast all the rays in the "sphere of rays collection". Call an example ray RAY. Where RAY DOESN'T strike anything, it should be used to estimate the ambient occlusion function at VERTEX. So, you add a scaled copy of the SH coefficients of RAY to the SH approx to of the ambient occlusion function at VERTEX. The scaled of the SH coefficients of RAY is the dot product of RAY with the VERTEX's normal.

\$\endgroup\$
-1
\$\begingroup\$

Ray casting which therefore is ray tracing is very very expensive. If you want it in real-time, that would be impossible or only possible within very restricted scene.

I do not recommend calculating spherical harmonics for general scene in iOS. Alternatively, you can pre-calculate spherical harmonics values via PC and use them in iOS such as sh light map(or sh value for each vertex).

The method for ray casting is same as ray tracing. You can find much references and sources codes about it.

\$\endgroup\$
5
  • \$\begingroup\$ If you really want ray casting(ray tracing) within glsl shader, it is POSSIBLE to implement it with glsl shader by the way. But this way differs from the way you use glsl shader in a standard way. \$\endgroup\$
    – Hybrid
    Jul 4, 2012 at 15:18
  • \$\begingroup\$ Not even close to impossible. I have it working on the 360 via XNA, real time in a single pass. Nontrivial, but very possible. \$\endgroup\$
    – 3Dave
    Jul 4, 2012 at 18:10
  • \$\begingroup\$ You're right. But I meant it is almost impossible in practically. You can do it with sphere, or very restricted scene. But, in practically, I don't think ray tracing can be used for games in iOS. \$\endgroup\$
    – Hybrid
    Jul 5, 2012 at 18:29
  • \$\begingroup\$ I don't know about iOS, but my implementation doesn't have any restrictions on scene complexity. Render time for a fixed size frame buffer is basically constant, and a function of the depth of your geometry tree, ray step algorithm and number of pixels to draw. \$\endgroup\$
    – 3Dave
    Jul 6, 2012 at 14:57
  • \$\begingroup\$ I'm not sure this actually answers or addresses the question at all, it should perhaps be a comment. \$\endgroup\$
    – user1430
    Oct 16, 2012 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .