首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++ DirectX11环境照明

C++ DirectX11环境照明
EN

Stack Overflow用户
提问于 2012-08-03 21:51:26
回答 1查看 2K关注 0票数 1

我目前在Directx 11的照明方面遇到了问题,实际上是它的环境照明。代码如下:

代码语言:javascript
复制
 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;
}

然后我将这些值发送到着色器:

代码语言:javascript
复制
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);

然后,我得到了以下内容:

为什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-25 22:58:28

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

您可以尝试直接将一个变量名设置为颜色输出:

代码语言:javascript
复制
output.color = lightvec;

代码语言:javascript
复制
output.color = lightcol;

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11797106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档