Hello everyone,
I'm having problem compiling the following HLSL pixel shader with shader model 5.1:
struct VShaderOutput
{
float4 clipPos : SV_POSITION;
float3 position : POSITION;
float3 normal : NORMAL;
float2 textCoord : TEXTCOORD;
};
struct DirectionalLight
{
float3 color;
float pad;
float3 direction;
float pad1;
};
#define DIR_LIGHTS_COUNT 10
ConstantBuffer<DirectionalLight> directionalLights[DIR_LIGHTS_COUNT] : register(b0);
struct SceneState
{
float3 eyePosition;
};
ConstantBuffer<SceneState> sceneState : register(b0, space1);
float4 main(VShaderOutput input) : SV_TARGET
{
float3 normal = normalize(input.normal);
float3 position = input.position;
float3 toEye = normalize(sceneState.eyePosition - position);
float3 color = float3(0.05f, 0.05f, 0.05f);
float3 diffuseColor = float3(0.5f, 0.5f, 0.5f);
for (int i = 0; i < DIR_LIGHTS_COUNT; i++)
{
float3 toLight = -directionalLights[i].direction;
float3 lightColor = directionalLights[i].color;
float cosThetaL = dot(normal, toLight);
float3 incidentRadiance = max(cosThetaL, 0.0f)* lightColor;
color += diffuseColor*incidentRadiance;
}
return float4(color, 1.0f);
}
FXC crashes and the function D3DCompileFromFile triggers an access violation reading exception. This only happens when optimizations are enabled (in the first case with the "Disable Optimizations" option set to "No" in the Visual Studio property page, and using any D3DCOMPILE_OPTIMIZATION_LEVELi flag in the second one).
The error message generated in the first case is the following: