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

Next revision
Previous revision
tutorial_203_20-_20shaders_20and_20effect_20system [2018/03/31 13:19]
127.0.0.1 external edit
tutorial_203_20-_20shaders_20and_20effect_20system [2018/04/17 19:09]
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 =====
-\\  In the application code, we will need to create a vertex shader object and a pixel shader object. The code is demonstrated below:\\ \\ +\\  In the application code, we will need to create a vertex shader object and a pixel shader object. The code is demonstrated below: 
 + 
 +<code bb4w>
         REM Compile the vertex shader:         REM Compile the vertex shader:
         hr% = FN_CompileShaderFromFile(@dir$+"​Tutorial02.fx",​ "​VS",​ "​vs_4_0",​ ^pVSBlob%)         hr% = FN_CompileShaderFromFile(@dir$+"​Tutorial02.fx",​ "​VS",​ "​vs_4_0",​ ^pVSBlob%)
Line 40: Line 46:
           ERROR 100, "​ID3D11Device::​CreateVertexShader failed: "​+STR$~hr%           ERROR 100, "​ID3D11Device::​CreateVertexShader failed: "​+STR$~hr%
         ENDIF         ENDIF
-\\ + 
         REM Compile the pixel shader:         REM Compile the pixel shader:
         hr% = FN_CompileShaderFromFile(@dir$+"​Tutorial02.fx",​ "​PS",​ "​ps_4_0",​ ^pPSBlob%)         hr% = FN_CompileShaderFromFile(@dir$+"​Tutorial02.fx",​ "​PS",​ "​ps_4_0",​ ^pPSBlob%)
Line 55: Line 61:
           ERROR 100, "​ID3D11Device::​CreatePixelShader failed: "​+STR$~hr%           ERROR 100, "​ID3D11Device::​CreatePixelShader failed: "​+STR$~hr%
         ENDIF         ENDIF
-\\ +</​code>​ 
 ===== Putting It Together ===== ===== Putting It Together =====
 \\  After walking through the graphics pipeline, we can start to understand the process of rendering the triangle we created at the beginning of Tutorial 2. Creating Direct3D applications requires two distinct steps. The first would be creating the source data in vertex data, as we've done in Tutorial 2. The second stage would be to create the shaders which would transform that data for rendering, which we showed in this tutorial. \\  After walking through the graphics pipeline, we can start to understand the process of rendering the triangle we created at the beginning of Tutorial 2. Creating Direct3D applications requires two distinct steps. The first would be creating the source data in vertex data, as we've done in Tutorial 2. The second stage would be to create the shaders which would transform that data for rendering, which we showed in this tutorial.
tutorial_203_20-_20shaders_20and_20effect_20system.txt · Last modified: 2018/04/17 19:09 by tbest3112