2012-09-10 46 views
0

我知道,在頂點着色器,你做這樣的:?如何在DirectX11中的幾何着色器中實例化?

PixelInputType TextureVertexShader(VertexInputType input) 
{ 
     PixelInputType output; 

// Change the position vector to be 4 units for proper matrix calculations. 
     input.position.w = 1.0f; 
// Update the position of the vertices based on the data for this particular instance. 
     input.position.x += input.instancePosition.x; 
     input.position.y += input.instancePosition.y; 
     input.position.z += input.instancePosition.z; 
// Calculate the position of the vertex against the world, view, and projection matrices. 
     output.position = mul(input.position, worldMatrix); 
     output.position = mul(output.position, viewMatrix); 
     output.position = mul(output.position, projectionMatrix); 

// Store the texture coordinates for the pixel shader. 
output.tex = input.tex; 

     return output; 
} 

什麼是在幾何着色器使用instancedPosition相當於就像當我想實例模型所做的1個頂點併爲每個實例在幾何着色器中創建一個四元組,並將四元組的位置設置爲實例緩衝區中相應實例的instancePosition的位置。

回答

0

爲了通過在幾何着色器中的數據,你可以簡單地通過從VS到GS過去的,讓你的VS輸出結構將是這樣的:

struct GS_INPUT 
{ 
    float4 vertexposition :POSITION; 
    float4 instanceposition : TEXCOORD0; //Choose any semantic you like here 
    float2 tex : TEXCOORD1; 
    //Add in any other relevant data your geometry shader is gonna need 
}; 

然後在你的頂點着色器,直接在幾何着色器中傳遞數據(未轉換)

根據您的輸入基本拓撲結構,幾何着色器將接收點,線或全三角形的數據,因爲您提到要將點轉換爲四邊形,原型看起來像這樣

[maxvertexcount(4)] 
void GS(point GS_INPUT input[1], inout TriangleStream<PixelInputType> SpriteStream) 
{ 
    PixelInputType output; 

    //Prepare your 4 vertices to make a quad, transform them and once they ready, use 
    //SpriteStream.Append(output); to emit them, they are triangle strips, 
    //So if you need a brand new triangle, 
    // you can also use SpriteStream.RestartStrip();  
}