User Tools

Site Tools


tutorial_203_20-_20shaders_20and_20effect_20system

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tutorial_203_20-_20shaders_20and_20effect_20system [2018/04/13 22:33]
richardrussell Added syntax highlighting
tutorial_203_20-_20shaders_20and_20effect_20system [2018/04/17 19:09] (current)
tbest3112 Added syntax highlighting for HLSL (useing glsl as close enough)
Line 12: Line 12:
 ===== Vertex Shaders ===== ===== Vertex Shaders =====
 \\  Vertex shaders are short programs that are executed by the GPU on vertices. Think of vertex shaders as C functions that take each vertex as input, process the input, and then output the modified vertex. In the Direct3D 11 tutorials, we will write our shaders in High-Level Shading Language (HLSL). Recall that our vertex data has a 3D position element, and the vertex shader will do no processing on the input at all. The resulting vertex shader looks like the following:​\\ \\  \\  Vertex shaders are short programs that are executed by the GPU on vertices. Think of vertex shaders as C functions that take each vertex as input, process the input, and then output the modified vertex. In the Direct3D 11 tutorials, we will write our shaders in High-Level Shading Language (HLSL). Recall that our vertex data has a 3D position element, and the vertex shader will do no processing on the input at all. The resulting vertex shader looks like the following:​\\ \\ 
 +<code glsl>
       float4 VS( float4 Pos : POSITION ) : SV_POSITION       float4 VS( float4 Pos : POSITION ) : SV_POSITION
       {       {
           return Pos;           return Pos;
       }       }
 +</​code>​
 \\  \\ 
 ===== Pixel Shaders ===== ===== Pixel Shaders =====
 \\  A pixel shader'​s primary purpose is to compute the colour that each pixel should have. The shader takes certain input about the pixel being coloured, computes the pixel'​s colour, then outputs that colour back to the pipeline. The vertex shader we created above outputs a float4 with the semantics SV_POSITION. This will be the input of our pixel shader. Since pixel shaders output color values, the output of our pixel shader will be a float4. We give the output the semantics SV_TARGET to signify outputting to the render target format. The pixel shader looks like the following:​\\ \\  \\  A pixel shader'​s primary purpose is to compute the colour that each pixel should have. The shader takes certain input about the pixel being coloured, computes the pixel'​s colour, then outputs that colour back to the pipeline. The vertex shader we created above outputs a float4 with the semantics SV_POSITION. This will be the input of our pixel shader. Since pixel shaders output color values, the output of our pixel shader will be a float4. We give the output the semantics SV_TARGET to signify outputting to the render target format. The pixel shader looks like the following:​\\ \\ 
 +<code glsl>
       float4 PS( float4 Pos : SV_POSITION ) : SV_Target       float4 PS( float4 Pos : SV_POSITION ) : SV_Target
       {       {
           return float4( 1.0f, 1.0f, 0.0f, 1.0f );    // Yellow, with Alpha = 1           return float4( 1.0f, 1.0f, 0.0f, 1.0f );    // Yellow, with Alpha = 1
       }       }
 +</​code>​
 \\  \\ 
 ===== Creating the Shaders ===== ===== Creating the Shaders =====
tutorial_203_20-_20shaders_20and_20effect_20system.txt ยท Last modified: 2018/04/17 19:09 by tbest3112