c++directx-11hlslgeometry-shader

How to implement Geometry Shader in DirectX for a 3D object like Cylinder?


I need help on how to implement Geometry Shader on Cylinder and what is the value of [maxvertexcount()], and do we need to provide the values of vertices and indices in ModelClass?


Solution

  • The Geometry Shader stage of Direct3D is not intended for generating complete geometry like a cylinder, nor it is really designed for Tessellation.

    https://learn.microsoft.com/en-us/windows/uwp/graphics-concepts/geometry-shader-stage--gs-

    You can do some small amount of amplification, but generally the hardware implementations work best when you either skip the GS stage or you output the same number of vertices as your inputs. Even initial 'use cases' for GS like generating a point-sprite (a quad) from a single input point have proven to be fairly inefficient compared to other methods.

    The primary value of the GS is working with adjacency information, or doing face-based computations like implementing classic 'flat-shading' without duplicating vertices. Geometry Shader can be very useful in doing Non-Photorealistic Rendering. The GS stage can also do some interesting tricks with Stream Out and controlling multi-render target selection in the pipeline.

    https://npr-art.blogspot.com/2009/07/geometry-shader-silhouettes.html

    If you want to generate a Cylinder, your best option is to build it on the CPU. See GeometricPrimitive in DirectX Tool Kit.