C++ Directx 11 环境光

标签 c++ shader hlsl lighting 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);

然后我得到以下信息: a busy cat

为什么?

最佳答案

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

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

output.color = lightvec;

output.color = lightcol;

作为开始,您可以仔细检查值是否正确传递。

关于C++ Directx 11 环境光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11797106/

相关文章:

c++ - 是否有任何 DirectX 11 (HLSL 5.0) 等同于 DirectX 9 纹理 "string function"语法?

c++ - directx11 点光源问题。从原点平移的对象没有正确点亮

random - 我可以在像素着色器中生成随机数吗?

c++ - 在 C++/CX 中解析 JSON ISO8601 日期

c++ - 有什么方法可以在考虑崩溃的情况下同步进程吗?

opengl - 什么是 OpenGL 中的着色器,我们需要它们做什么?

javascript - 自定义 phong 着色器

c++ - OpenCV destroyWindow() 不执行任何操作。

c++ - 接口(interface)和多重继承

shader - .hlsl 和 .hlsli 有什么区别?