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).
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(); }}
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 tweetsAwesome XNA Videos – Lighting, Rendering, and game videos
That did it. Thanks so much for your help. You all have made a great engine.