Difference between revisions of "3D Fundamentals Tutorial 9"

From Chilipedia
Jump to: navigation, search
(Video)
(Video)
Line 12: Line 12:
 
:* These functors determine the color of the pixel based on their input
 
:* These functors determine the color of the pixel based on their input
 
</div>
 
</div>
* Refactoring of the <code>gfx.PutPixel(...)</code> function in <code>Pipeline.h<code> [https://youtu.be/pef2405M-os?t=2m04s 2:04]
+
* Refactoring of the <code>gfx.PutPixel(...)</code> function in <code>Pipeline.h</code> [https://youtu.be/pef2405M-os?t=2m04s 2:04]
 
:* This is where we are ultimately determining the color of the pixel
 
:* This is where we are ultimately determining the color of the pixel
 
:* Inside the PutPixel function, we want to call a shader object that defines the coloring behavior
 
:* Inside the PutPixel function, we want to call a shader object that defines the coloring behavior
Line 18: Line 18:
 
:* We template the pipeline class on an <code><class Effect></code>
 
:* We template the pipeline class on an <code><class Effect></code>
 
:* We will adjust the definition of the <code>Vertex</code> class depending on what effect we are using
 
:* We will adjust the definition of the <code>Vertex</code> class depending on what effect we are using
:* We  adjust the PutPixel call as:
+
:* We  adjust the PutPixel to take the pixel shader object, and call the function operator with the interpolated Vertex data:
::  
+
::<syntaxhighlight lang="cpp" line>
 +
gfx.PutPixel( x,y,effect.ps( iLine ) );
 +
</syntaxhighlight>
 
* ... [https://youtu.be/pef2405M-os?t=0m20s 0:20]
 
* ... [https://youtu.be/pef2405M-os?t=0m20s 0:20]
 
* ... [https://youtu.be/pef2405M-os?t=0m20s 0:20]
 
* ... [https://youtu.be/pef2405M-os?t=0m20s 0:20]

Revision as of 19:51, 1 June 2020

In this tutorial we incorporate our first shader stage into the 3D pipeline: the pixel shader stage. We also explore some basic example pixel shaders (more heavy-duty stuff to come later).

Video

The tutorial video is on YouTube here.


  • What is a Pixel Shader and why is it used? 0:20
  • We want to make color mapping of the triangles in the rendering pipeline configurable
  • One way is to use templated function objects (functors) as "plug-in" code
  • These functors determine the color of the pixel based on their input
  • Refactoring of the gfx.PutPixel(...) function in Pipeline.h 2:04
  • This is where we are ultimately determining the color of the pixel
  • Inside the PutPixel function, we want to call a shader object that defines the coloring behavior
  • Implementation of the programmable pixel shader stage in the pipeline 3:11
  • We template the pipeline class on an <class Effect>
  • We will adjust the definition of the Vertex class depending on what effect we are using
  • We adjust the PutPixel to take the pixel shader object, and call the function operator with the interpolated Vertex data:
gfx.PutPixel( x,y,effect.ps( iLine ) );

Downloads

The GitHub repository for the tutorial code is here.

See also