2012-08-03 79 views
1

我目前在Directx 11中的照明问题,实际上是其环境照明。下面是代码:C++ Directx 11环境照明

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; 
} 

然后我的值发送到着色器:

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); 

然后我得到以下几点: a busy cat http://i49.tinypic.com/2j105fs.png

为什么?

回答

0

我试过你的着色器,似乎工作,所以也许一些变量没有正确传递。

你可以尝试直接设置一个变量名彩色输出:

output.color = lightvec; 

output.color = lightcol; 

作为一个开始,所以你可以仔细检查值正确地传递。