Difference between revisions of "3D Fundamentals Tutorial 9"

From Chilipedia
Jump to: navigation, search
(Video)
(Video)
Line 22: Line 22:
 
gfx.PutPixel( x,y,effect.ps( iLine ) );
 
gfx.PutPixel( x,y,effect.ps( iLine ) );
 
</syntaxhighlight>
 
</syntaxhighlight>
* ... [https://youtu.be/pef2405M-os?t=0m20s 0:20]
+
* Changes to the <code>Pipeline</code> class [https://youtu.be/pef2405M-os?t=5m37s 5:37]
* ... [https://youtu.be/pef2405M-os?t=0m20s 0:20]
+
:* The <code>Pipeline</code> object now holds an <code>Effect</code> object (which holds all shader data and methods)
 +
:* Coding the <code>Effect</code> class [https://youtu.be/pef2405M-os?t=6m03s 6:03]
 +
:* Coding the <code>PixelShader</code> class [https://youtu.be/pef2405M-os?t=6m22s 6:22]
 +
* Putting it all together in a new <code>CubeSkinScene.h</code> class [https://youtu.be/pef2405M-os?t=7m26s 7:26]
 +
:* The code now renders the same scene, but has become completely configurable
 +
* Making a new <code>Effect</code>: Color Blending [https://youtu.be/pef2405M-os?t=8m31s 8:31]
 +
 
 +
* Making a new <code>Effect</code>: Solid Colors [https://youtu.be/pef2405M-os?t=14m47s 14:47]
 +
 
 
* ... [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 20:00, 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 gfx.PutPixel(...) to take a pixel shader object, and call the function operator with the interpolated Vertex data:
gfx.PutPixel( x,y,effect.ps( iLine ) );
  • Changes to the Pipeline class 5:37
  • The Pipeline object now holds an Effect object (which holds all shader data and methods)
  • Coding the Effect class 6:03
  • Coding the PixelShader class 6:22
  • Putting it all together in a new CubeSkinScene.h class 7:26
  • The code now renders the same scene, but has become completely configurable
  • Making a new Effect: Color Blending 8:31
  • Making a new Effect: Solid Colors 14:47

Downloads

The GitHub repository for the tutorial code is here.

See also