Unable to retrieve the ambient light color in my shader

rated by 0 users
This post has 2 Replies | 2 Followers

Top 500 Contributor
Posts 9
SunBurn_Community_Licensee
Aaron Benzel Posted: 03-17-2012 2:00 PM

Hello Sunburn Community,
I’m not sure if this is a bug or if I’m doing something wrong.  I’ve been trying to create an “Ambient Light Shader.”  This was supposed to be an easy first step towards more difficult shaders.  Unfortunately I haven’t been able to get this first one to work.  I’m unable to retrieve the ambient light color using:

float3 AmbientLightColor
<
string SasBindAddress = "Sas.AmbientLight[0].Color";
>;

I know the rest of the code works because I hard coded an AmbientLightColor and that appears to work.
Here is the entire .fx file.  Any help would be greatly appreciated.  Thanks in advance.

//-----------------------------------------------
// Ambient Light Shader
//-----------------------------------------------

// main scene transforms - bound as common semantics to
// automatically receive data from SunBurn.

float4x4 _World : WORLD;
float4x4 _View : VIEW;
float4x4 _Projection : PROJECTION;

// variables that control lighting - bound to SAS lighting
// addresses (note: this shader only supports ambient lighting).


float3 AmbientLightColor
<
string SasBindAddress = "Sas.AmbientLight[0].Color";
>;

float AmbientIntensity = 0.1;


struct InputData
{
 float4 position : POSITION;
};

struct ShaderLink
{
 float4 position : POSITION;
};

ShaderLink AmbientVS(InputData input)
{
 ShaderLink output;

 output.position = mul(input.position, _World);
 output.position = mul(output.position, _View);
 output.position = mul(output.position, _Projection);

 return output;
}

float4 AmbientSceneDataPS(ShaderLink input) : COLOR
{
 float4 AmbientLightColorFloat4 = float4(0, 0, 0, 0);
 AmbientLightColorFloat4.xyz = (AmbientLightColor * AmbientIntensity).xyz;
 return AmbientLightColorFloat4;
}

technique Ambient_Technique
{
 pass P0
 {
  VertexShader = compile vs_3_0 AmbientVS();
  PixelShader  = compile ps_3_0 AmbientSceneDataPS();
 }
}

 

Top 10 Contributor
Posts 5,368
Employee
SunBurn_Studio_Licensee

Hi Aaron,

I had to look into this one a bit.  Your shader looks great, but we're seeing the same result here - it turns out if there are no point or directional light bindings specified in the shader it's viewed as a non-lighting shader and the ambient bindings are not used.

To clarify, simply adding a binding for the directional light color (even if it's unused in the shader code) will enable lighting on the effect:


float3 DirectionalLightColor
<
string SasBindAddress = "Sas.DirectionalLight[0].Color";
>;


I've logged this as an anomaly, which we need to make more intuitive in the future.

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Top 500 Contributor
Posts 9
SunBurn_Community_Licensee

That did it.  Thanks so much for your help.  You all have made a great engine.

Page 1 of 1 (3 items) | RSS