Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#Actualcozzie

Posted 29 December 2012 - 12:30 PM

Hi, thanks. I got it, with the difference that I have a different diffuse and ambient material.
Part of the lighting calculation (diffuse light) is done in te Vertex shader, the rest in the pixel shader.

The working result now is:
 

float4 PS_function(VS_OUTPUT input): COLOR0
{
    float4 textureColor = tex2D(textureSampler, input.TexCoord);
    textureColor.a = 1;

    return saturate((input.Color * MatDiff + AmbientColor * AmbientIntensity * MatAmb) * textureColor);
}

The only thing I don't understand is that splitting the formula up, doesn't give the correct result.
I tried it like this:

float amb = AmbientColor * AmbientIntensity * MatAmb
float diff = input.Color * MatDiff
return saturate(diff + amb) * textureColor

This doesn't work though, resulting pixels are black/ not as expected.
I tried to fund this by doing a pseudo formula:

return saturate((input.Color * MatDiff + AmbientColor * AmbientIntensity * MatAmb) * textureColor);
equals
result = ((A * B + C * D * E) * F)

amb = C * D * E
diff = A * B

result = (A + B) * F

When I fill in fictive numbers for A though F, I get the same result calculating it in one formula as when I do it in with the amb/diff step in between.
Strange? or am I missing something


#1cozzie

Posted 29 December 2012 - 12:27 PM

Hi, thanks. I got it, with the difference that I have a different diffuse and ambient material.

Part of the lighting calculation (diffuse light) is done in te Vertex shader, the rest in the pixel shader.

 

The working result now is:

float4 PS_function(VS_OUTPUT input): COLOR0
{
    float4 textureColor = tex2D(textureSampler, input.TexCoord);
    textureColor.a = 1;

    return saturate((input.Color * MatDiff + AmbientColor * AmbientIntensity * MatAmb) * textureColor);
}

The only thing I don't understand is that splitting the formula up, doesn't give the correct result.

I tried it like this:

 

float amb = AmbientColor * AmbientIntensity * MatAmb

float diff = input.Color * MatDiff

return saturate(diff + amb) * textureColor

 

This doesn't work though, resulting pixels are black/ not as expected.

I tried to fund this by doing a pseudo formula:

 

return saturate((input.Color * MatDiff + AmbientColor * AmbientIntensity * MatAmb) * textureColor);

equals

result = ((A * B + C * D * E) * F)

 

amb = C * D * E

diff = A * B

 

result = (A * B) * F

 

When I fill in fictive numbers for A though F, I get the same result calculating it in one formula as when I do it in with the amb/diff step in between.

Strange? or am I missing something


PARTNERS