Last active
August 2, 2018 17:58
-
-
Save Lokno/69cb6c4b81173a737f8bdc60b2e20e0f to your computer and use it in GitHub Desktop.
Renders a single screen-aligned triangle that fills the screen without a vertex buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Renders a single screen-aligned triangle that fills the screen without a vertex buffer | |
// Creates texture coordinates with (0,0) in the top left and (1,1) in the bottom right | |
// | |
// DX11 API calls: | |
// m_pD3D11Device->IASetInputLayout(NULL); | |
// m_pD3D11Device->IASetPrimitiveTopology( D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); | |
// m_pD3D11Device->Draw(3, 0); | |
struct VSOut | |
{ | |
float4 Pos : SV_POSITION; | |
float2 Tex : TEXCOORD0; | |
}; | |
// (-3,1) (1,1) | |
// 0---+---1 | |
// \ | | | |
// +---+ | |
// \ | | |
// 2 | |
// (1,-3) | |
VSOut VSScreenAligned(uint vertexId : SV_VertexID) | |
{ | |
VSOut output = (VSOut)0; | |
if (vertexId == 0) | |
{ | |
output.Pos = float4(-3.0, 1.0, 0.5, 1.0); | |
output.Tex = float2(-1.0, 0.0); | |
} | |
else if (vertexId == 1) | |
{ | |
output.Pos = float4(1.0, 1.0, 0.5, 1.0); | |
output.Tex = float2(1.0, 0.0); | |
} | |
else if (vertexId == 2) | |
{ | |
output.Pos = float4(1.0, -3.0, 0.5, 1.0); | |
output.Tex = float2(1.0, 2.0); | |
} | |
return output; | |
} | |
// simple pixel shader example that renders the | |
// texture coordinates as color | |
float4 PSVisCoords(VSOut input) : SV_Target | |
{ | |
return float4(input.Tex.x, input.Tex.y, 0.0, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment