I downloaded deferred shading tutorial in XNA from riemers site (here is the link). Now i'm trying to implement it in c++. My problem is light changes shapes, disappears when i change my camera position. I looked normal map, color map and depth map. They are correct. Also I'm using exact same shaders from tutorial so i don't think there should be a problem. Here is the code i use and i added some pictures how it looks. I really appreciate any help i'm frustrated with this problem right now.
I'm creating depth, color and normal maps here.
void DrawShader1()
{
D3DXMATRIX mat;
D3DXMatrixIdentity(&mat);
And combine them here
void DrawShader3()
{
shader3->SetTechnique("CombineColorAndShading");
shader3->SetTexture("xColorMap", colorTexture);
shader3->SetTexture("xShadingMap", shadingTexture);
shader3->SetFloat("xAmbient", 0.4f);
There doesnt appear to be anything wrong with your code, so the issue likely lies somewhere else. Try to narrow the problem area down. Try other things like moving the light around to see where it stops drawing, then it will give you an idea of what is happening. Perhaps the light moves behind the wall, or the light moves outside the cameras view frustum... it is difficult to determine based on the information.
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
Thanks for reply. Actually i was having problem to narrow so i added all my code. First i tried to integrate it with my game and i had the same problem so i wrote the from the beginning but that doesn't change the problem. By the way as you said i tried changing light positions as you said and here is what i found. I was creating only one light as below.
light.Direction = D3DXVECTOR3(0, -1, 0);
light.Position = D3DXVECTOR3(150, 0.2f, 150);
light.ConeDecay = 1.0f;
light.ConeAngle = 0.7f;
light.Strength = 0.4f;
By the way my ground is between (0, 0) (200, 200). So i tried changing position in the code above. Until i make x and z 400 nothing changed. When i make them 400 i see a little bit of light. But if i move my camera a little bit higher (45 in the y axis) i start to see the light in its default position. And light's shape is strange it is not perfect circle. It changes shape when i increase camera y position. First it becomes like upside down 'V' then it becomes rectangle and it disappears :S. I really appreciate any help i'm trying to solve what is wrong for 2 days. So far i couldn't find anything. By the way i added all the code on c++ side and the shader code that im creating shading map below.
This is getting stranger and stranger. I looked the variables i send to shader and they are correct. Then i create a release version. And when i start the release version from the .exe (not from visual studio) the result was different. It wasn't correct but it isn't the same result when i start my app from visual studio. I'm really getting frustrated so even any little advise would be appreciated and if someone is willing to try my code i can send other shader codes and also you can find shader codes in the link i mentioned in my first post.
I notice your lights position has a y value of .2, the wall you are drawing has a y value of 0. So, your light is only .2 above the wall, which could cause some issues in actually seeing the light since it is so close. Other than that, your code looks like it should work.
I recommend changing this code here so you can see the entire area where your light is
float shading = 0;
if (coneCondition)
{
Output.Color.rgb = float3(1, 0. 0);// this should show the lights area as a solid red so you can see where it is at all times
} else {
Output.Color.rgb = shading;
}
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
Thanks for the reply. I try to change lights y position between -10 to 10 it changed nothing. Even with negative values it behaves same. I'm really frustrated right now since i'm trying to solve what is wrong with the code for two days. Shaders works with the code in the XNA example so i think there should be something wrong with my code but i cannot find it. My normal color and depth maps seem correct. So i think there is something wrong in the code where i create shading map. By the way thanks for the reply again i really appreciate even any little advise.
It looks like a run-of-the-mill wrong space issue to me. What you have here is actually already the view position, as long as you have your depth buffer as linear. (As is standard for us at least, I don't post much. )
So to get your world position you only need to multiply it with the to view inverse, not the view projection inverse.
Whenever your lights move when your camera moves, you're generally working in the wrong space.
I personally do everything in view space, but that's just a matter of personal taste, you should be able to do it in world space too.
Otherwise it looks allright, from what I see from a quick glance. Not sure about the spotlight attenuation calculations but I haven't done that in ages. x)
Thanks for reply i tried your solution but it wasn't working either. And i think multiplying with view projection inverse is true because im getting screen position by multiplying world position with view * projection. Besides as i mentioned i take shaders from the link in my first post. It was from an XNA example and it works with XNA. So i think there is something wrong with my code but i can't find it. Is there a tool to debug shader and look at variables in shader?
ok i solved my problem. I was creating depth texture like D3DXCreateTexture(device, 640, 480, 0, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &depthTexture);
i changed it to D3DXCreateTexture(device, 640, 480, 0, D3DUSAGE_RENDERTARGET, D3DFMT_R32F, D3DPOOL_DEFAULT, &depthTexture);
and now it works correct. It is a silly mistake but if anyone curious . And thanks again for all the replies and sharing pain with me