Pixel shaders: programming the GPU<br />By: Venkata Nanda Kishore<br />
What is a Shader?<br />Set of Software Instructions<br />Degree of Flexibility<br />Traits of an entity<br />
Entities,Traits And Degree<br /><ul><li>Entities:</li></ul>	Pixels<br />	Vertices<br />	Geometric shapes<br /><ul><li>Trai...
Types of Shaders<br />Initially, Shaders are just pixel shaders<br />Types of Shaders:<br /><ul><li>Pixel Shaders
Vertex Shaders
Geometric Shaders</li></ul>But the name remained as it was!<br />
Effect of Shaders<br />Replaced hard coded effects<br />Gives a programmable alternative<br />Fixed Function PipelineProg...
Programming Shaders<br />HLSL (Direct 3d)<br />GLSL (OpenGl)<br />Cg(Nvidia + Microsoft)<br />
Cg<br />What is Cg?<br />Is it similar to C?<br />Is it the right question?<br />Can we use it as a general programming la...
Background of Cg<br />Use of Assembly level language<br />What is assembly level?<br />What is high level,low level and mi...
Example of assembly level language<br />fib: movedx, [esp+8]<br />cmpedx, 0 ja @f <br />moveax, 0<br /> ret<br />@@: <br /...
Advantage of Cg<br />Portable<br />Easy<br />Optimize the code<br />
Syntax and Semantics(1)<br />Data Types:<br />int, float, half, fixed, bool, sampler*<br />Operators: Arithmetic and logic...
Syntax and Semantics(2)<br />Functions and Control Structures: Similar to C<br />Standard Cg Library: Specialised GPU prog...
Example Shader<br />// input vertexstructVertIn<br />{ float4 pos : POSITION; <br />float4 color : COLOR0; };<br />// outp...
Upcoming SlideShare
Loading in …5
×

Pixel shaders

625 views
588 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
625
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pixel shaders

  1. 1. Pixel shaders: programming the GPU<br />By: Venkata Nanda Kishore<br />
  2. 2. What is a Shader?<br />Set of Software Instructions<br />Degree of Flexibility<br />Traits of an entity<br />
  3. 3. Entities,Traits And Degree<br /><ul><li>Entities:</li></ul> Pixels<br /> Vertices<br /> Geometric shapes<br /><ul><li>Traits:</li></ul> Pixels: z-buffer, alpha values etc.<br />Vertices: Texture co-ordinates, Color<br />
  4. 4. Types of Shaders<br />Initially, Shaders are just pixel shaders<br />Types of Shaders:<br /><ul><li>Pixel Shaders
  5. 5. Vertex Shaders
  6. 6. Geometric Shaders</li></ul>But the name remained as it was!<br />
  7. 7. Effect of Shaders<br />Replaced hard coded effects<br />Gives a programmable alternative<br />Fixed Function PipelineProgrammable Function Pipeline<br />3.Parallel Programming<br />
  8. 8. Programming Shaders<br />HLSL (Direct 3d)<br />GLSL (OpenGl)<br />Cg(Nvidia + Microsoft)<br />
  9. 9. Cg<br />What is Cg?<br />Is it similar to C?<br />Is it the right question?<br />Can we use it as a general programming language?<br />
  10. 10. Background of Cg<br />Use of Assembly level language<br />What is assembly level?<br />What is high level,low level and middle level?<br />How easy is it?<br />
  11. 11. Example of assembly level language<br />fib: movedx, [esp+8]<br />cmpedx, 0 ja @f <br />moveax, 0<br /> ret<br />@@: <br />cmpedx, 2 ja @f<br />moveax, 1<br />ret <br />@@: <br />push ebx<br />movebx, 1<br />movecx, 1 <br />@@: lea eax, [ebx+ecx] <br />cmpedx, 3 jbe @f movebx, ecx<br />movecx, eax<br />decedx<br />jmp@b<br />@@: <br />pop ebx<br /> ret<br />
  12. 12. Advantage of Cg<br />Portable<br />Easy<br />Optimize the code<br />
  13. 13. Syntax and Semantics(1)<br />Data Types:<br />int, float, half, fixed, bool, sampler*<br />Operators: Arithmetic and logical operators as in C<br />Additional: arithmetic operations for vector and matrix operrations<br />
  14. 14. Syntax and Semantics(2)<br />Functions and Control Structures: Similar to C<br />Standard Cg Library: Specialised GPU programming tasks<br />Eg. Texture Mapping functions tex1D and tex2D<br />Cg Runtime Library:Can be used with OpenGl or DirectX<br />
  15. 15. Example Shader<br />// input vertexstructVertIn<br />{ float4 pos : POSITION; <br />float4 color : COLOR0; };<br />// output vertexstructVertOut<br />{ float4 pos : POSITION; float4 color : COLOR0; }; <br />// vertex shader main entry<br />VertOutmain(VertIn IN, uniform float4x4 modelViewProj) <br />{ VertOut OUT; <br />OUT.pos= mul(modelViewProj, IN.pos); // calculate output coords<br />OUT.color = IN.color; // copy input color to output<br />OUT.color.z= 1.0f; // blue component of color = 1.0f<br />return OUT; }<br />
  16. 16. Games that Use Cg<br />HIT MAN : Blood Money<br />BATTLE FIELD 2<br />FAR CRY<br />RACER<br />And many more<br />
  17. 17. How to use Pixel Shaders?<br />

×