Git Product home page Git Product logo

geometryshadercookbook's Introduction

Geometry Shader Cookbook

The repository is the practice project of Geometry shader in Unity engine.

Define the Method of Geometry Shader

#pragma geometry geom

Define Data Structure

//The data structure from the application to the vertex shader.
struct a2v  
{  
    float4 vertex : POSITION;  
    float2 uv : TEXCOORD0;  
};  

//The data structure from the vertex shader to the geometry shader.
struct v2g  
{  
    float4 vertex : POSITION;  
    float2 uv : TEXCOORD0;  
};

//The data structure from the geometry shader to the fragment shader.
struct g2f
{  
    float4 vertex : SV_POSITION;  
    float2 uv : TEXCOORD0;
};  

Write Geometry Shader

  [maxvertexcount(3)]  
  void geom(triangle v2g input[3], inout TriangleStream<g2f> outStream)  
  {  
        g2f o;  

        for(int i = 0; i < 3; i++)  
        {  
              o.vertex = UnityObjectToClipPos(input[i].vertex);  
              o.uv = input[i].uv;  
              outStream.Append(o);  
        }  
  
        outStream.RestartStrip();  
  }
Attribute
maxvertexcount(number) The output vertex number for the geometry shader.
Inputs
point The point pritimive data.
line The line pritimive data.
lineadj The line pritimive data, including the adjacent line pritimive data.
triangle The triangle pritimive data.
triangleadj The triangle pritimive data, including the adjacent triangle pritimive data.
Outputs
PointStream The point stream data.
LineStream The line stream data.
TriangleStream The triangle stream data.
Stream Methods
Append(struct) The method to add the data.
RestartStrip() If the output is TriangleStream, you need to call the method to form the triangle. (Three vertices form a triangle)

Implement Examples

PointStream/Vertex

LineStream/Line

TriangleStream/DoNothing

TriangleStream/ExtrudeVertex

TriangleStream/TriangleAnimation

TriangleStream/ExtrudePyramid

TriangleStream/ExtrudePyramidAnimation

TriangleStream/ExtrudeTriangle

TriangleStream/ExtrudeTriangleAnimation

geometryshadercookbook's People

Contributors

ted10401 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.