为什么我的法向量总是空白? HLSL

问题描述

我正在尝试使用 HLSL 和 this rbwhitaker tutorial 创建一个基本的漫反射着色器。着色器运行没有错误并且可以显示三角形,但似乎顶点着色器的法线输入从未被赋予值,这会导致漫反射照明中断。我通过将输出颜色设置为白色,然后减去法线来测试这个,但是颜色从来没有任何变化,它保持白色。我的着色器代码如下。

float4x4 World;
float4x4 View;
float4x4 Projection;

float4x4 WorldInverseTranspose;

float3 DiffuseLightDirection = float3(1,0);
float4 DiffuseColor = float4(1,1,1);
float DiffuseIntensity = 1.0;
float4 AmbientColor = float4(1,1);
float AmbientIntensity = 0.1;

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float4 normal : norMAL0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position,World);
    float4 viewPosition = mul(worldPosition,View);
    output.Position = mul(viewPosition,Projection); 
    
    
    float4 normal = mul(input.normal,WorldInverseTranspose);
    float lightIntensity = dot(normal,DiffuseLightDirection);
    output.Color = saturate(DiffuseColor * DiffuseIntensity * lightIntensity);;
    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
   return saturate(input.Color + AmbientColor * AmbientIntensity);
}

technique Diffuse
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}

编辑: 我想这可能是因为我没有直接将法线传递给着色器,但如果没有内置方式,我不知道如何计算它。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)