Jump to content
  • Advertisement
Sign in to follow this  
JorenJoestar

Cave, temple and shadows

This topic is 3741 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, after many many posts here I'm finishing my first demo with HydraEngine (and I'll release all the source code, maybe you can find something useful there)...but I'm facing the last problem. I've exported some cave models done in 3D studio max (using tubes and some modifiers) that have the problem of normal flipped (I think is something about smoothgroups) that is something I can handle. The problem is the handling of lights and shadows: in the scene is possible that an object is influenced by more than one light that CASTS SHADOWS, so how can I choose which shadow map to use/use all of the shadow maps that influence the object? I'm using soft-shadowmap (like chapter 17 of GPU Gems2, if you remember my posts now works perfectly!)... And then: I don't have time to develop global illumination shaders/techniques, so but I want to use some form of static occlusion maps used like lightmaps...is it a good way to handle static light (like sun at a fixed direction)? The ambient light will come from outside the cave/temple located in the center of the sea...and the sun is fixed for this demo. Thank you guys, hope to finish soon and to help you with my code as you helped me through this journey! Best regards, Gabriel Sassone

Share this post


Link to post
Share on other sites
Advertisement
Ok...for the 3DS models it seems a common problem that happens to all the meshes that have a cylindrical base (like the tube I used to create the cave).

For the dynamic light/shadow system...I'm trying to design something very simple for this iteration (only to provide simple light in the first demo) but I cannot figure out how to handle the influence of the lights on objects.

I'm thinking of letting the object have a list of lights sorted per influence (distance and radius maybe) so when applying the shader I can feed the data from the first lights in the list.
But...how to update the list with newly entered/exited lights?
Do the lights need to have a list of object they influence and then force them to update?

Hope someone reply...thanks!

Share this post


Link to post
Share on other sites
Well no matter how you do your lighting, you're always going to be working with one light at a time and summing the contribution of all light sources. You just have to make sure that for each light you're working with, it has a shadow map associated and the shadow map matrix associated with it. Then when you do the calculations for that light, you use that shadow map. If you're doing multiple lights in a shader, it looks something like this:


// shader constants
float3 lightPos0;
float3 lightDir0;
float lightInnerCone0;
float lightOuterCone0;
float4x4 lightViewProjMatrix0;

float3 lightPos1;
float3 lightDir1;
float lightInnerCone1;
float lightOuterCone1;
float4x4 lightViewProjMatrix1;

...

// shadow maps
sampler2D shadowMap0;
sampler2D shadowMap1;

// pixel shader
float4 PS ( ... )
{
float3 lightingSum = 0;

// do calcs for first light
float4 posLightSpace = mul(posWorldSpace, lightViewProjMatrix0);
float shadowTerm = CalcShadowTerm(posLightSpace, shadowMap0);
lightingSum += CalcSpotlight(lightPos0, lightDir0, ...) * shadowTerm;

// do calcs for second light
posLightSpace = mul(posWorldSpace, lightViewProjMatrix1);
shadowTerm = CalcShadowTerm(posLightSpace, shadowMap1);
lightingSum += CalcSpotlight(lightPos1, lightDir1, ...) * shadowTerm;

// and so on...
}




You may also want to consider using a deferred shadow system. With this, you render the shadow occlusion term to a buffer before you actually render all your geometry and lighting. It requires doing a depth pre-pass, and then using those depth values to reconstruct the world-space position of a particular pixel. When you do this you can render using a full-screen quad for global lights, or you can use a bounding volume for local lights (spot lights, point lights). This effectively decouples your shadowing from your lighting, which can simply things quite a bit.

Share this post


Link to post
Share on other sites
Good solution...I'm always thinking about deferring rendering, but now I have no time :P

The code is kinda the shader code I'm thinking, thanks!

But for me the problem is to determine which lights affects objects...I've read many posts around, but in my mind it's not quite sure how to handle this problem...is the light needing a list of object that are influenced and every object has its own light list, that must be sorted per influence?
If yes, is it heavy to do for every object in the frustum for every frame?

Thank you!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!