Forums > Jitter

cast shadows in OpenGL

Jul 09 2009 | 3:19 pm

Hi all,
i have a general gl landscape with a plane and some 3d figures… everything is fine but i cannot get the shadows which would make the scenery realistic and more 3d.
How can i do that?
I fear it’s more difficult than just a toggle right?

Jul 09 2009 | 3:59 pm

Search on forum …
I don’t remember who send that but thanks to him

— Pasted Max Patch, click to expand. —
Jul 09 2009 | 8:11 pm

Hi, unfortunately i don’t have max 5 still working on 4.6.
Can you convert it somehow?

Jul 09 2009 | 9:09 pm

i downloaded max runtine 5 and the cde doesn’t work is it correct?

Jul 10 2009 | 8:16 am

I copy paste the code in an empty patch from my answer on the forum and it works.
Did you open an empty patch and make copy paste on it?
It’s not a .maxpatch that you’ll open like a file it’s a copy compressed file.
Are you still on demo?
Can you open an empty patch?
PS: upgrade to 5 you won’t regret!

okay here you have the .maxpat double clic on it…

Jul 11 2009 | 3:29 pm

Hi Hubert,
i finally used Supercollider to convert the patch to max 4! Thanks a lot for your patch.
It looks cool, but i’m not a jitter expert, i’m more an audio guy. What is unclear to me is how to make it general to every gl objet. Fom what i see it uses movie data to create a complex geometry, this provideas a stream of data out that is used to create the shadow in a second renderer. When i use i don’t have data out, so how then can i create a shadow using that patch?

Jul 11 2009 | 10:13 pm

the matrixoutput is not required for shadows.

here is another version of this same technique. it uses slightly more modern jitter objects, and uses two render passes on one gl.render, rather than two gl.renders.

as always, bang order is important.
hopefully this will clarify some things, however please don’t underestimate the complexity of rendering shadows.

in the future we hope to provide an easier mechanism for shadow rendering.

(pasted and attached)

— Pasted Max Patch, click to expand. —
Dec 24 2011 | 4:04 am

hi Robert –

Wondering if anything in Max 6 might enable some special new techniques for rendering cast shadows that would be a little less arcane…

Maybe someday can get a attribute for shadows?


Dec 24 2011 | 5:58 am

OpenGL does not have any built in support/primitives or ‘standard’ techniques for shadows. This means there are no generic ways of doing shadows. Shadows are complex, especially if you want soft shadows, multiple light support, point lights, spot lights, materials, etc support. Additionally, since OpenGL is dynamic enough, there are many different rendering techniques and strategies that support rendering shadows, each with pros and cons.


OpenGL does not support shadow rendering directly. However, any standard algorithm for rendering shadows can be used in OpenGL. Some algorithms are described at Follow the Coding Tutorials & Techniques link, then the Rendering Techniques link. Scroll down to the Lighting, Shadows, & Reflections section.

The GLUT 3.7 distribution comes with examples that demonstrate how to do this using projection shadows and the stencil buffer.

Projection shadows are ideal if your shadow is only to lie on a planar object. You can generate geometry of the shadow using glFrustum() to transform the object onto the projection plane.

Stencil buffer shadowing is more flexible, allowing shadows to lie on any object, planar or otherwise. The basic algorithm is to calculate a "shadow volume". Cull the back faces of the shadow volume and render the front faces into the stencil buffer, inverting the stencil values. Then render the shadow volume a second time, culling front faces and rendering the back faces into the stencil buffer, again inverting the stencil value. The result is that the stencil planes will now contain non-zero values where the shadow should be rendered. Render the scene a second time with only ambient light enabled and glDepthFunc() set to GL_EQUAL. The result is a rendered shadow.

Another mechanism for rendering shadows is outlined in the SIGGRAPH ’92 paper Fast Shadows and Lighting Effects Using Texture Mapping, Mark Segal et al. This paper describes a relatively simple extension to OpenGL for using the depth buffer as a shadow texture map. Both the GL_EXT_depth_texture and the GL_EXT_texture3D (or OpenGL 1.2) extensions are required to use this method.

Essentially, shadows need to be implemented in concert with how your scene needs to be rendered, the look you want. This means you are probably best off learning something about OpenGL and lighting/shading techniques and learning how to implement that in Jitter. Its not the best answer, but Shadows are non trivial to do generically, and require some extensive ‘engine’ work. It also means less flexibility to provide only one solution. Im not sure what to tell you, but, do some reading and see if you can’t figure something out to suit your needs.

Dec 24 2011 | 7:58 am


It was just a simple question. I appreciate your answer, but what you’re saying about shadows – that they’re non-trivial, complex, non-generic – could just as easily be said about physics, animation, materials etc., all of which are now available as Max 6 objects.

I certainly know something about OpenGL – among other things, I know enough to realize that implementing anything more than simple projection shadows on a flat plane is going to be beyond my skills and/or available time.

And since providing one solution (a basic cast shadow implementation, even if limited) wouldn’t prevent anyone from coding their own additional methods, I can’t see how it could possibly mean "less flexibility" overall.

Not every wheel needs to be re-invented on a per-project basis.

But far be it from me to complain about the newly available tools and techniques in Max 6 – if anything, it’s an embarrassment of riches. As a 3D engine, it now has everything one would expect, and much beyond – everything except shadows.

Dec 24 2011 | 10:42 pm

It may be a simple question, but that in no way implies a simple answer.

My statement about less flexibility was more about a specific shadow implementation being "less flexible" than a custom user one. IE, its not a one size fits all solution. I heavily suspect it would not be something reliable for all situations, and would require give and takes. I take issue with physics, animation and materials being lumped in, for various reasons. Physics is really not much different than animation (the logic is complex, but rendering is unchanged). Materials are built into OpenGL in various ways in both the fixed and programmable pipeline, but thats besides the point and becomes a semantic issue.

Personally, I think a better solution than some generic shadow implementation would be to allow for @capture to use multiple render targets, allowing for very strong deferred rendering support. Deferred rendering would allow you to use modern game engine rendering techniques, and write out in one render pass, albedo, depth, normals, material, specular to allow for very very nice shadows and per pixel lighting. You also can then chain slabs after to allow post processing. MRT is a hugely popular technique, and its really going to give you a lot more power. Cycling could then provide various lighting, shadow, and even depth of field implementations using MRT techniques. Its a perfect match for I think.

Anyway. Good luck.

Dec 26 2011 | 2:37 pm


This means you are probably best off learning something about OpenGL and lighting/shading techniques and learning how to implement that in Jitter.

Personally, I think a better solution than some generic shadow implementation would be to allow for @capture to use multiple render targets, allowing for very strong deferred rendering support.

What I would like to know is if it’s possible in the current incarnation of Max to implement it in Jitter. Has anyone done it? Are there any examples/videos? Or is the lack of multiple rendering targets withholding it?

I (and I’m sure many others) would like to be able to do this kind of images with Jitter (this was done with vvvv):

So, is it possible/feasible at all? It’s just a question of programming complexity or is Jitter really lacking some technical requirement/implementation that’s preventing it?

Thanks in advance!

Nov 26 2012 | 10:59 am

and does ogre can cast shadows ?

Viewing 13 posts - 1 through 13 (of 13 total)

Forums > Jitter