Liton
Liton

Reputation: 1428

Pass an array to HLSL vertex shader as an argument?

I need to pass an array to my vertex shader as an argument in Direct3D. The signature of the shader function looks like the following:

ReturnDataType main(float3 QuadPos : POSITION0, float4 OffsetArray[4] : COLOR0)

Is the signature OK? How do I define input layout description?

Thanks in Advance.

Upvotes: 2

Views: 5630

Answers (1)

zdd
zdd

Reputation: 8727

From HLSL references page, The function arguments only support intrinsic type, and user-defined type, the user-defined type also rely on intrinsic type, which does not support native array type, vector type or struct type might be your choice.

here is an example to use struct, you can simply build up a struct and pass in it as below like VS_INPUT.

//--------------------------------------------------------------------------------------
// Input / Output structures
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
    float4 vPosition    : POSITION;
    float3 vNormal      : NORMAL;
    float2 vTexcoord    : TEXCOORD0;
};

struct VS_OUTPUT
{
    float3 vNormal      : NORMAL;
    float2 vTexcoord    : TEXCOORD0;
    float4 vPosition    : SV_POSITION;
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT VSMain( VS_INPUT Input )
{
    VS_OUTPUT Output;

    Output.vPosition = mul( Input.vPosition, g_mWorldViewProjection );
    Output.vNormal = mul( Input.vNormal, (float3x3)g_mWorld );
    Output.vTexcoord = Input.vTexcoord;

    return Output;
}

Upvotes: 2

Related Questions