cast shadows in OpenGL

Jul 9, 2009 at 3:19pm

cast shadows in OpenGL

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?
Thanks
Alberto

#44679
Jul 9, 2009 at 3:59pm

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

– Pasted Max Patch, click to expand. –
#160786
Jul 9, 2009 at 8:11pm

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

#160787
Jul 9, 2009 at 9:09pm

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

#160788
Jul 10, 2009 at 8:16am

hello,
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?
Cheers,
Hubert
PS: upgrade to 5 you won’t regret!

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

#160789
Jul 11, 2009 at 3:29pm

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 jit.gl.gridshape i don’t have data out, so how then can i create a shadow using that patch?
A

#160790
Jul 11, 2009 at 10:13pm

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. –
#160791
Dec 24, 2011 at 4:04am

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 jit.gl.light can get a attribute for shadows?

pH

#160792
Dec 24, 2011 at 5:58am

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.

ie: http://www.opengl.org/resources/faq/technical/lights.htm

OpenGL does not support shadow rendering directly. However, any standard algorithm for rendering shadows can be used in OpenGL. Some algorithms are described at http://www.opengl.org. 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.

#160793
Dec 24, 2011 at 7:58am

vade-

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.

#160794
Dec 24, 2011 at 10:42pm

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 jit.gl.node I think.

Anyway. Good luck.

#160795
Dec 26, 2011 at 2:37pm

vade:

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!

#160796
Nov 26, 2012 at 10:59am

and does ogre can cast shadows ?

#160797

You must be logged in to reply to this topic.