Pixel shaders

1,395 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
1,395
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
26
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. GRAPHICS PIPELINE<br />Geometric Shaders<br />Rasteriser<br />VertexShaders<br />Pixel Shaders<br />
  8. 8. 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 />
  9. 9. Programming Shaders<br />HLSL (Direct 3d)<br />GLSL (OpenGl)<br />Cg(Nvidia + Microsoft)<br />
  10. 10. 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 />
  11. 11. 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 />
  12. 12. 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 />
  13. 13. Advantage of Cg<br />Portable<br />Easy<br />Optimize the code<br />
  14. 14. Games that Use Cg<br />HIT MAN : Blood Money<br />BATTLE FIELD 2<br />FAR CRY<br />RACER<br />And many more<br />
  15. 15. 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 />
  16. 16. 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 />
  17. 17. Example Shader<br />structVertIn //Input vertex<br />{ float4 pos : POSITION; <br />float4 color : COLOR0; }; // output vertex<br />structVertOut<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); //position<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 />
  18. 18. Loading Pixel Shaders in OpenGL<br />1.Loading extensions:<br />glEnable(GL_FRAGMENT_PROGRAM_ARB);<br />2.Create Shader Number:<br />glGenProgramsARB(1, &shader_num); <br />glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader_num);<br />
  19. 19. Actually Loading the Shader<br />glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(program_string), program_string);<br />glDisable(GL_FRAGMENT_PROGRAM_ARB);<br />http://joshbeam.com/articles/cg_pixel_shaders_in_opengl/<br />
  20. 20. Examples <br />https://support.steampowered.com/kb_article.php?ref=4360-TPJL-2065<br />Gives what games need what version of pixel shaders<br />http://www.nvidia.com/object/feature_pixelshader.html<br />http://www.toymaker.info/Games/html/pixel_shaders.html<br />
  21. 21. Free Book!<br />http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html<br />

×