Skip to content

Vertex Indexing in FShade Geometry shader

Attila Szabo edited this page Dec 22, 2023 · 1 revision

FShade attributes pass-through geometry-stage

To be able to pass attributes through the geometry stage without explicitly copying them, the input vertex has to hold the semantic "SourceVertexIndex" as an attribute. "SourceVertexIndex" allows to identify the connection of input and output attributes.

For example the following shaders can be composed due to the VertexIndex field:

type Vertex = {
    [<Position>]                p       : V4d
    [<SourceVertexIndex>]       vi      : int
    [<Color>]                   c       : V4d
}
 
 
let gs (Line<Vertex>) =
    triangle{
        // vi = 0 -> all non-existing attributes are copied from the first input-vertex
        yield { line.P0 with pos = V4d.IOO; vi = 0}     
        yield { line.P0 with pos = -V4d.IOO; vi = 0}
        // vi = 1 -> all non-existing attributes are copied from the second input-vertex
        yield { line.P1 with pos = V4d.OIO; vi = 1}     
        yield { line.P1 with pos = -V4d.OIO; vi = 1}   
        // note that setting the indices in record-copies is actually unnecessary
        // since the input-vertices already have their corresponding indices
        // whenever a field is marked with the SourceVertexIndex attribute
    }
 
type OtherVertex = { [<Normal>] n : V3d }
let fs (input : OtherVertex) =
    fragment{
        return V4d(input.n, 1.0)
    }
Clone this wiki locally