2

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.

zdd
  • 8,258
  • 8
  • 46
  • 75
Liton
  • 1,398
  • 2
  • 14
  • 27

1 Answers1

2

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;
}
zdd
  • 8,258
  • 8
  • 46
  • 75
  • I have variable number of COLOR elements. Besides, I have a number of shader files which were used from C# programs using Direct3D 9. I am writing C++ programs using Direct3D 11 and don't want to modify those shader files. – Liton Mar 20 '14 at 15:02
  • @Liton I don't think you can do this HLSL in DirectX, since HLSL does not support native array, so I recommend you use struct. – zdd Mar 24 '14 at 04:32