This topic is 3723 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.

##### Share on other sites
Sticking with fixed-function, couldn't you write it in very much the same way as a single light using a multiple pass approach?

##### Share on other sites
Ok.. now I know about that fixed function.

So, what I must to do with this algorithm?? How create the shadows from two light...

I confuse in camera render process and comparing process...

##### Share on other sites

And one member of this forum said that with fixed function we can do the process for two lights source. For each depth map, we must give it comparing process...

But, I didn't done with that... I can't combine the result from first comparing with the second comparing... Or maybe there some solution for comparing two depth map with the texture matrix...

Maybe someone else has any opinion???

##### Share on other sites
OK.. already can make the shadow with two light source. But, the result is too glowing... So, all my object almost have a white color because glowing.

I use a opengl shininess material, specular material, and also ambient_and_diffuse for color material. After that I also give my project with ambient,specular, and diffuse color for each light. And I use a default standard value for each parameter. And like I say, the result is a glowing scene for all my object. Can I make a shadow mapping project with standard parameter for material and light color??
Or I must combine using math or something?? Because I confuse for calculation...

Any suggest for my project??? Maybe some mistake I have???

##### Share on other sites
If you want to do this in fixed function, the basic process should be like this:

1) Render shadow maps for light #1
2) Render shadow maps for light #2

I think you've got that part working.

3) Clear the screen to black.
4) Set up just the ambient lighting, and nothing else. Render your scene with ambient light. Blending should be disabled, so objects are opaque.
5) For each light: Set up just the lighting from that light (no ambient!). Turn on blending, and make your blending additive. Render the scene.

Basically, this will render your entire scene once per light (plus once for the ambient pass, which also fills in your Z-buffer). By using additive blending, you're basically adding the effect of each light in the frame buffer.

This isn't the most efficient way of doing this, but it does make the idea much simpler to understand.

##### Share on other sites
OK... I already made it. But the result is too glowing.. I guest i cause of the GL_SHININESS that I use.
In the step no. 5, I must render for each light using other light like diffuse,etc except ambient light. But, what material light that I must use...
Now, i create my project using GL_AMBIENT_AND_DIFFUSE for color material, using specular and shininess for light material, and using diffuse and specular light. And the value that I fill in each parameter is default value.

After that I using GL_BLEND too for blending. But, I confuse for what function that I must use for glBlendFunc... Now, I try to use glBlendFunc(GL_ONE,GL_ONE)..
Maybe you can give me suggest what blending function that I must use for this shadow mapping project.

##### Share on other sites
OK... I already made it. But the result is too glowing.. I guest i cause of the GL_SHININESS that I use.
In the step no. 5, I must render for each light using other light like diffuse,etc except ambient light. But, what material light that I must use...
Now, i create my project using GL_AMBIENT_AND_DIFFUSE for color material, using specular and shininess for light material, and using diffuse and specular light. And the value that I fill in each parameter is default value.

After that I using GL_BLEND too for blending. But, I confuse for what function that I must use for glBlendFunc... Now, I try to use glBlendFunc(GL_ONE,GL_ONE)..
Maybe you can give me suggest what blending function that I must use for this shadow mapping project.

##### Share on other sites
Hi,

If you turned off your shadow mapping, whether the light effect is still glowing?

Also, could you put some pictures as well for better understanding?

##### Share on other sites
Em.. use the light effect (ambient, diffuse, specular) only in shadow map result. And for the result, you can look at:

john.petra.ac.id/~m26403037/TA/hasil.JPG

I don't know where is the wrong things.... Maybe after you look out my result, you can give me some suggestion...

##### Share on other sites

Lets say you have a pixel with RGB = { 255, 127, 63 }, it's orange.
Now if you light it using 1 light and N dot L / distance^2 plus some other params give you, e.g. 80% you'll get RGB = { 204, 102, 50 }.
Now if you add a second light and it's close the first so that it gives you e.g 90%, then you have to add those 2 ratios, 80% + 90% = 170%. So you'll get 170% of original RGB values = { 433, 216, 107 }, which will get clamped to { 255, 215, 107 }. If you want to deal with that, you'll have to:

1) Move light away from each other
2) Lower the ambient, diffuse etc parameters
3) use HDR and tone mapping

##### Share on other sites
I already try to move the both light away and change the ambient, diffuse, etc parameter.. But, the result still same. And if I try to reduce the parameter value from shininess in OpenGL, the glow will reduce too, but my shadow will not seen clearly. I so confuse how too make it right.

Or maybe I have a wrong blending method... Now I using OpenGL blending method with GL_BLENDFUNC... And I use GL_ONE for the source and GL_ONE too for the destination.. Is I have wrong blending function???