【问题标题】:Geometry Shader must have a max vertex count DirectX 11几何着色器必须具有最大顶点数 DirectX 11
【发布时间】:2021-12-27 22:08:21
【问题描述】:

我正在尝试在 C++ 中将几何着色器添加到我的 DirectX 11 项目

我看到的任何地方没有这样的例子。有数百万关于 OpenGL 的教程,但没有关于 DirectX 中的几何着色器的教程

我刚刚在下面写了一个基本的着色器,但是在尝试构建它时出现以下错误

error X3514: 'LightGeometryShader' must have a max vertex count

谁能告诉我这个着色器缺少什么才能编译?

////////////////////////////////////////////////////////////////////////////////
// Filename: light.gs
////////////////////////////////////////////////////////////////////////////////


//////////////
// TYPEDEFS //
//////////////
struct GeometryInputType
{
    float4 position : POSITION;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
};

struct PixelInputType
{
    float4 position : SV_POSITION;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
};


////////////////////////////////////////////////////////////////////////////////
// Geometry Shader
////////////////////////////////////////////////////////////////////////////////
PixelInputType LightGeometryShader(GeometryInputType input)
{
    PixelInputType output;
    
    output = input;

    return output;
}

【问题讨论】:

    标签: c++ windows directx directx-11


    【解决方案1】:

    GeometryShader 不一定是 1:1 函数,这就是为什么您必须提供最大顶点数的原因。见Microsoft Docs

    [maxvertexcount(3)]
    void LightGeometryShader( triangle GeometryInputType input[3],
        inout TriangleStream<PixelInputType> outStream )
    {
        PixelInputType output;
        for( int v = 0; v < 3; v++ )
        {
            output.position = input[v].position;
            output.tex = input[v].tex;
            output.normal = input[v].normal;
            outStream.Append( output );
        }
    }
    

    几何着色器是在 Direct3D 10 中引入的,因此当时大部分开发的示例都在旧版 DirectX SDK 中。您可以在GitHub 上找到无需旧版 DirectX SDK 即可构建的这些示例的最新副本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多