explanation of shadows

Hello all,
I’ve been working hard on a personal game project and so far i’ve learned a ton.

So far, I haven’t had to resort to posting anything, but I decided I might on this one, as many of you seem to know very well what you’re doing, and I’ve been searching for hours to no avail for a good explanation.

One thing that I don’t quite understand is shadows. I was wondering if someone could take a moment to explain to those who don’t know many of the aspects of shadows. What are light cameras? How do I keep the light camera still and move my main camera? Why are all my objects textured with the texture of a certain object in the scene? These are guidelines for some things to explain. Any help would be greatly appreciated!

Basically, you’re rendering a depth buffer from the light viewpoint (hence you need a camera) and projecting the depth image onto the scene. Where the depth image differs from the real image, there is shadow.

en.wikipedia.org/wiki/Shadow_mapping

This page is about OpenGL but a useful read about shadow mapping: (although some info may be inaccurate or wrong)
bytechunk.net/shadowmapping/index.php

thanks for that.
i have been looking at tutorials and sample programs trying to get basic shadowing to work.

i would appreciate an explanation of the essentials. i understand you need a light camera, but for some reason my objects keep flickering between grayscale/color. they have no texture (except for the sky), but for some reason take on the texture of the sky, even my main character. also, i cannot get the light source to stay still, as it seems to move with my main camera.

what is the usefulness of ‘caster.sha’ in the sample? i didn’t see it in other program.

also, an explanation of the setShaderInput keywords would be much appreciated.

Thanks! and I hope that more than just myself can learn from your help!

Caster.sha is pretty useless, it’s only for cards that don’t support depth render, but about every card that supports shaders also supports depth textures. :slight_smile:

If you get random flickering textures, it means you are using a texture from within a shader that you didn’t assign (using setShaderInput for example).

If you get moire artifacts, that means you didn’t enable backface culling using shadowcam.node().setInitialState(RenderState.make(CullFaceAttrib.makeReverse())).

Have you seen the “Shadows” sample program?

thanks for that, i’ll try it out. yeah, i’ve looked at the shadow demo, which is helping. are new cameras automatically parented to base.camera? it seems that i have gotten the light camera to stick in one spot by parenting it to render and setting a position. it looks like a point light. is there a way to change it’s light type?

thanks for all of your help. i truly appreciate it!

also, i believe that the flickering may be due to the fact that i have vertex colors versus a texture applied to most of my objects.

If you use base.makeCamera I think they are reparented under base.camera, but that is not what you want (since then they would share the same position with the main camera).

Instead, your light camera must have its own position in the scene. Since cameras have a PerspectiveLens by default, it’s a spotlight. If you want to have a directional light instead, apply an OrthographicLens.

The CVS trunk of Panda3D already fully supports built-in shadow mapping - this will make it into the 1.7.0 release. There, it is as easy as light.setShadowCaster(True). If you want to benefit from that now, you’d need to make a CVS checkout of Panda and build it from CVS.

i think i’m making progress. the orthographic lens seems a little funky, but i’ll keep researching its properties. i’m still learning what film size is and things like that.

also, is there a list of setShaderInput strings that can be put in for the first parameter (avatar.setShaderInput(param1, param2))?

i appreciate your help!

There’s not really a list of things. There are the following ways:

setShaderInput("name", float, float, float, float)
setShaderInput("name", Vec4(float, float, float, float))

Those are passed to the shader as “uniform float4 k_name”.

This:

setShaderInput("name", nodePath)

has a number of different meanings, read the manual page called “List of shader inputs” for more details.

This:

setShaderInput("name", texture)

is passed to the shader as “uniform sampler*** k_name” parameter.

Hi,

I am trying to get the shadows from 1.7 CVS trunk. I was successful in downloading and compiling panda. I tried running the Disco Lights sample code but do not see any shadows. Is there anything that i need to be doing?

Thanks!
Goutham

Yes, you need to enable shadows for the lights explicitly. something like light.node().setShadowCaster(True)