0

我是学习 HLSL(Direct 3D Shader)的初学者。下面是一些代码来构建一个简单的 LSLS Light 应用程序。我的问题是函数 mainVS() 中的“WorldXf”是什么意思。

代码在【Fx Composer2.5】</p>

代码正在流动:

float4x4 WorldViewProj : WorldViewProjection;

uniform float4x4 WorldXf : World <
    string UIWidget = " None";
>;


uniform float4 Color
<
    string UIName = "color";
    string UIWidget = "Color";
> = float4 (1.0f,0.0f,0.0f,1.0f);

float3 Light0Pos :Position<
    string Object = "PointLight0";
    string UIName = "PointLight0 Position";
    string UIWidget = "Position";
    string Space = "World";
> = float3 (0.0f,0.0f,0.0f);

float3 Light0Color : Diffuse <
    string Object = "PointLight0";
    string UIName = "PointLight0";
    string UIWidget = "Color";
> = {1.0f,1.0f,1.0f};

struct VS_INPUT
{
    float4 Position : POSITION;
    float3 Normal   : Normal;
};

struct VS_OUTPUT
{
    float4 Position : POSITION;
    float4 Color    : COLOR;
};
VS_OUTPUT mainVS(VS_INPUT In){

    VS_OUTPUT Out;
    Out.Position = mul(float4(In.Position.xyz,1.0f),WorldViewProj);
    float3 vWorldNormal = mul(In.Normal,(float3x3)WorldXf);
    float3 vWorldPosition = mul(In.Position,WorldXf).xyz;
    float3 vDir = normalize(Light0Pos - vWorldPosition);

    Out.Color.rgb = Light0Color * saturate ( dot(vDir,vWorldNormal));
    Out.Color.a = 1.0f;
    return Out;
}

float4 mainPS(VS_OUTPUT In) : COLOR {
    return In.Color;
}

technique technique0 {
    pass p0 {
        CullMode = None;
        VertexShader = compile vs_3_0 mainVS();
        PixelShader = compile ps_3_0 mainPS();
    }
}
4

1 回答 1

0

它的意思是“世界变换”,我不确定使用 xform 作为变换的缩写的约定来自哪里,但它有点普遍。仅使用 Xf 更加不透明。

于 2013-09-27T16:38:40.963 回答