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

## Recommended Posts

Hi... I'm newbie in this forum. Now I want to create a graphic project. It's about shadow mapping. I was success using shadow mapping with one light source. And now I want to try create more than one light source. Maybe for the start I want to create with two light. But I was confuse about the step for do that. Maybe you can give me some explanation about how to use the shadow mapping with two light source. Thanx

##### Share on other sites
Which part is it exactly that you're stuck on? Is it the creation of the actual shadow maps, or their application when rendering your scene? Also, is your renderer currently built to handle multiple light sources? If so, are you using multi-pass or single-pass lighting?

##### Share on other sites
I was confuse what I must to with the depth map.

When I have two light sources, so I will need two depth map to store the texture. And after that I don't know what I must to do with both depth map. What I must do with the depth maps???
After that for the rendering process from camera's point of view.. Is I need to use both effect from two lights (ambient, specular, etc).
And the last, I want to know how does I can go in compare process...

So, maybe I not really know about the theory for shadow mapping in multi light... So I hope you can help me. And for single or multi pass... i think I use single pass light.

##### Share on other sites
Okay then. Extending your system for multiple shadow maps should be a relatively painless process then. If you're doing a single-pass system where you're going to be rendering the contributions from both light sources in one shader. This means that you'll need to apply the depth maps from both maps as textures, and then your shader will look up the depth and make the comparison individually for both light sources and attenuate the contributions seperately. In pseudo-code it would look something like this:

//main app codeapply paramaters for first light sourceapply shadow map and light projection matrix for first light sourceapply paramaters for second light sourceapply shadow map and light projection matrix for second light source//in the pixel shaderPixelShader (){    calculate diffuse and specular lighting contribution for first light source    determine shadowMap texture lookup coordinates    lookup depth in shadowmap    compare with fragment depth    attenuate first light contribution based on depth comparison    calculate diffuse and specular lighting contribution for second light source    determine shadowMap texture lookup coordinates    lookup depth in shadowmap    compare with fragment depth    attenuate second light contribution based on depth comparison    sum contributions of both light sources}

##### Share on other sites
So, firstly I must get the shadow map for both light. After I get it, I render again from camera view point using each light effect and step in to comparing process for each light.. It's my opinion right?

And what is the mean of sum contribution for each light?? Using what I can do it? OpenGL?? Or What?? Now I try to create this project in OpenGL and MFC VC++ 8

##### Share on other sites
Quote:
 Original post by T-motAnd what is the mean of sum contribution for each light?? Using what I can do it? OpenGL?? Or What?? Now I try to create this project in OpenGL and MFC VC++ 8

By "contribution for each light", I mean the value you add to your final color for each light source affecting the pixel. I assume you have something like this in your shader, for doing one light source:

float4 diffuse = diffuseMaterial * lightColor * max(0,dot(normal, pixelToLight)) * attenuation;float3 R = normalize(reflect(lightToPixel, normal));float4 specular = specularMaterial * lightColor * pow(max(0, dot(R, -eyeToPixel)), specularPower/4) * attenuation;//shadowAttenuation is the result of your shadow-map depth comparisonfloat4 lightContribution = (diffuse + specular) * shadowAttenuation;float4 color = ambient + lightContribution;

So for two lights, you would simply repeat that top portion twice and determine ambient and diffuse values for each light (as well as shadow attenuation values from each shadow-map) and then add it all together to get your final color value.

//calculate diffuse, specular, and shadow attenuation for each lightfloat4 lightContribution1 = (diffuse1 + specular1) * shadowAttenuation1;float4 lightContribution2 = (diffuse2 + specular2) * shadowAttenuation2;float4 color = ambient + lightContribution1 + lightContribution2;

Alternatively, you could do this in one pass per light. This would mean you would use the same shader you use for 1 light source, and render each visible object twice (one pass per light source) using additive blending to sum the results into your frame-buffer. You would just need to ensure you don't add the ambient component twice, and change your shader constants to reflect the parameters of your second light before rendering your second pass.

##### Share on other sites
So for the sum of contribution I must do like that.. But in my project, I not using that calculation for create a light effect. I using openGL with glLight and glMaterialf. So I don't use like that calculation.. Can you give me some advise..

And how about the shadow map it self?? Is I create into two texture and after I have two texture, how I can use its for shadow mapping process???

And my last question is about the comparing process... In shadow mapping there is some step to compare the depth value that stored in depth map with distance. How I can do it with two light or two texture?

##### Share on other sites
After I read some paper and suggest from all of you, I have been create the step for shadow mapping for two light using opengl...

This is my pseudocode, but I still have something wrong in my step...

each light
{
//render from light's point of view
set light matrix projection and view;
draw object;
save into depth map;
}

each light
{
//render from camera's point of view
set camera matrix projection and view;
set ambient, specular, and diffuse light's material;
enable lighting;
draw object;

//comparing process
create texture matrix from bias matrix*light matrix projection*light matrix view;
get s,t,r,q for texture coordinate;
get the depth map for light
compare the depth value and coordinate using glee component
using glalphafunc();
draw object;
disable all variable;
}

That is my pseudocode step in shadow mapping program for two light, after I read some tutorial... But, there is some mistake that the result is not make a two shadow but only one shadow result. I guess that I need some glBlend() code into my program, but I don't know where I must put this code.. Or maybe there is some wrong else in my program...

So, I hope all of you can help me... thanks

##### Share on other sites
I actually didn't know shadow mapping was possible with fixed function. You really should try to switch to GLSL, it makes things a whole lot more strait forward. You only have math do deal with, no tricky vocabulary.

##### Share on other sites
Why must move to GLSL??
What is the meaning that shadow mapping can't use in fixed fucntion??

I think that in my project.. I almost did it.. But, I need some little information about my mistake in coding. Sorry, if I wrong..

But, I really need help for this shadow mapping with two light sources project.

1. 1
Rutin
35
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633340
• Total Posts
3011421
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!