Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

C++ Directx Ambient Light issue.

This topic is 2150 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

I'm currently having a problem with lighting in Directx 11, actually its ambient lighting. Here is the code:


cbuffer ConstantBuffer
{
float4x4 final;
float4x4 rotation; // the rotation matrix
float4 lightvec; // the light's vector
float4 lightcol; // the light's color
float4 ambientcol; // the ambient light's color
}
struct VOut
{
float4 color : COLOR;
float4 position : SV_POSITION;
};
VOut VShader(float4 position : POSITION, float4 normal : NORMAL)
{
VOut output;
output.position = mul(final, position);
// set the ambient light
output.color = ambientcol;
// calculate the diffuse light and add it to the ambient light
float4 norm = normalize(mul(rotation, normal));
float diffusebrightness = saturate(dot(norm, lightvec));
output.color += lightcol * diffusebrightness;
return output;
}
float4 PShader(float4 color : COLOR) : SV_TARGET
{
return color;
}


Then i send the values to the shader:


ambLight.LightVector = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 0.0f);
ambLight.LightColor = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
ambLight.AmbientColor = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);

ShaderManager.UpdateSubresourceDiffuseShader(devcon);


And then i get the following:

Attached image

Why?

Share this post


Link to post
Share on other sites
Advertisement
You didn't say what's the problem.

Your ambient light is D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f); and box is almost black, seems right to me.

Share this post


Link to post
Share on other sites

are you sure you are not reffering to that your directional light dosent work?


I'm following a tutorial from DIrectxtutorial.com you cant see it because you need to be premium, well if you are, its the dx11 lighting tutorial.
Its supposed to look like this:
dx11BC4-15.PNG

Share this post


Link to post
Share on other sites
Ohh snap, I've fixed it.

I forgot to send the rotation matrix. I feel very dumb xD

Well well, thank you for trying to help me!

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!