» cn.Tutorial Effects - Vertexshader Preparations
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

cn.Tutorial Effects - Vertexshader Preparations

English | Spanish | Italian | Japanese

TOC: Of Effects and Shaders
Next: Mr. Wiggle


顶点着色器操纵网格上的每个顶点。对于很多种的数据场来说一个顶点是一个容器。这些数据场作为输入的参数在顶点着色器中使用。最重要的是位置,材质坐标和法线。作为一个着色器的制作者,你需要知道每个顶点中能储存什么样的数据。你可以使用VertexDeclaration (EX9.Geometry Mesh) 获得网格中的数据描述。


Mesh Data




  • 引脚中着色器的值
  • 空间变换信息
  • 网格信息

顶到着色器把顶点的位置信息转换到一个直接坐标系空间中,然后投射到屏幕上(3D空间 -> 2D屏幕空间,参见ex9.spaces。取决于着色器它同时也准备一些其它的数据,这些数据之后被用到像素着色中。顶点着色器计算的所有的数据被封装到一个数据结构中,这个结构我们称之为“vs2ps”。它可以包含很多种的数据场,这完全取决与你在像素着色器中的需求。但它必须要输出位置数据场,这样显卡才能计算屏幕中的那些网格包含在网格内。所有的其它的数据场都是可操控的,最常用的是材质坐标和法线。

Mesh data flow

详细信息参见 ex9.dataflow


Clone the Template (EX9.Effect) on a patch and connect a mesh to it and render it into a Renderer (EX9):在程序片中克隆Template (EX9.Effect)在上面连接一个网格,用Renderer (EX9)渲染:

Basic patch


float4x4 tW: WORLD;        //the models world matrix as via the shader
float4x4 tV: VIEW;         //view matrix as set via Renderer (EX9)
float4x4 tP: PROJECTION;   //projection matrix as set via Renderer (EX9)
float4x4 tWVP: WORLDVIEWPROJECTION; //all 3 premultiplied 
//texture transformation marked with semantic TEXTUREMATRIX
//to achieve symmetric transformations
float4x4 tTex: TEXTUREMATRIX <string uiname="Texture Transform";>;
//the data structure: "vertexshader to pixelshader"
//used as output data of the VS function
//and as input data of the PS function
struct vs2ps
    float4 Pos  : POSITION;
    float2 TexCd : TEXCOORD0;
//vertex shader
vs2ps VS(
    float4 PosO  : POSITION,
    float4 TexCd : TEXCOORD0)
    //declare output struct
    vs2ps Out;
    //transform position
    Out.Pos = mul(PosO, tWVP);
    //transform texturecoordinates
    Out.TexCd = mul(TexCd, tTex);
    return Out;
technique TSimpleShader
    pass P0
        VertexShader = compile vs_1_1 VS();
        PixelShader  = null;

Next: Mr. Wiggle
TOC: Of Effects and Shaders

anonymous user login


~3d ago

auralscapes: By the way, if anyone would like to use any of my tracks or even parts thereof you are welcome. No fee. jerome@auralscapes.com

~3d ago

auralscapes: Thx for the advice. Much appreciated.

~3d ago

tonfilm: @auralscapes you can contact the author @dottore and ask him for the conditions.

~3d ago

auralscapes: A question for the group. I came across an application called Partitura. Is this app commercially available?

~4d ago

auralscapes: Don't have a clue how this all works but it is going to be an interesting journey indeed.

~7d ago

tonfilm: @all #vl now also has pin groups! vl-input-and-output-pin-groups #vvvv #creativecoding #visualprogramming #dotnet

~8d ago

evvvvil: Hey, broski, check my shader "The gamma ray feast" it goes bang and is commented with bad to mediocre jokes. https://www.shadertoy.com/view/wssXWl

~10d ago

hrovac: someone at b-seite on saturday?