С++ Directx 11 Окружающее освещение

В настоящее время у меня проблема с освещением в 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);

И тогда я получаю следующее: деловой кот

Почему?


person Miguel P    schedule 03.08.2012    source источник


Ответы (1)


Я попробовал ваш шейдер и, кажется, работает, поэтому, возможно, какая-то переменная передается неправильно.

вы можете попытаться напрямую установить одно имя переменной для цветного вывода:

output.color = lightvec;

и

output.color = lightcol;

Для начала, чтобы вы могли дважды проверить, что значения передаются правильно.

person mrvux    schedule 25.09.2012