SHADERS:
Releasing the power of the GPU
     (and your creativity)
PART I:
THE SHADER CONCEPT
3D Programming
Rasterization
THE BIRTH OF GPU SHADERS

        1. No special hardware
      2. Hardware acceleration
     3. Programmable Hardware
4. P...
Rasterization (GPU)
PART II:
THE OPENGL SHADER API
How do we make a program?
    1. Enter some text in a file
        2. Compile the file
  3. Check for compilation errors
 ...
How do we make a program?
    1. Enter somewin.cin a file
           1. vim text
      2.2.gcc –Wall thewin.c
           C...
How do we make a program?
      1. Enter somewin.cin a file
          1. 1. vim text
             ShaderSource()
        2...
• SHADER OBJECT        • PROGRAM OBJECT

• glCreateShader       • glCreateProgram
• glDeleteShader       • glDeleteProgram...
#define BUFSZ 1024
#define SHADER_SOURCE = quot;void main (void) { gl_Position = ftransform (); }quot;


GLuint vert;
GLin...
#define BUFSZ 1024
GLuint vert, frag, prog;
GLint stat;
char buf[BUFSZ];


vert = my_load_shader (quot;vertex.glslquot;);
...
PART III:
GLSL PROGRAMMING
Vertex Attributes      Uniforms

glVertexAttrib*        glGetUniformLocation
glBindAttribLocation   glUniform*
GLuint prog; GLint texLoc, timeLoc; GLfloat time;
#define WEIGHT_INDEX 1
prog = my_load_prog ();


texLoc = glGetUniformLo...
LET'S WRITE SHADERS!
THANK YOU!
and enjoy your CG practical

   tom@mimicmedia.nl
GLSL: Releasing the power of the GPU
GLSL: Releasing the power of the GPU
GLSL: Releasing the power of the GPU
GLSL: Releasing the power of the GPU
GLSL: Releasing the power of the GPU
GLSL: Releasing the power of the GPU
Upcoming SlideShare
Loading in …5
×

GLSL: Releasing the power of the GPU

1,920 views

Published on

This is an Introduction to the OpenGL shaders. When you need high performance or customized features in your 3D program, these are the way to go.

Published in: Technology, Art & Photos
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
1,920
On SlideShare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
0
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

GLSL: Releasing the power of the GPU

  1. 1. SHADERS: Releasing the power of the GPU (and your creativity)
  2. 2. PART I: THE SHADER CONCEPT
  3. 3. 3D Programming
  4. 4. Rasterization
  5. 5. THE BIRTH OF GPU SHADERS 1. No special hardware 2. Hardware acceleration 3. Programmable Hardware 4. Programmable Hardware Interface
  6. 6. Rasterization (GPU)
  7. 7. PART II: THE OPENGL SHADER API
  8. 8. How do we make a program? 1. Enter some text in a file 2. Compile the file 3. Check for compilation errors 4. Link some compiled code 5. Check for linking errors 6. Run your program!
  9. 9. How do we make a program? 1. Enter somewin.cin a file 1. vim text 2.2.gcc –Wall thewin.c Compile –c file 3. Check 3. echo $? for compilation errors 4. gcc –Wall win.o iexplore.o 4. Link some compiled code 5. Check for linking errors 5. echo $? 6. Run your program! 6. ./a.out
  10. 10. How do we make a program? 1. Enter somewin.cin a file 1. 1. vim text ShaderSource() 2.2.gcc –Wall thewin.c 2. CompileShader() Compile –c file 3. Check 3. echo $? 3. COMPILE_STATUS for compilation errors 4. 4. gcc –Wall win.o iexplore.o 4. Link some compiled code AttachShader(); LinkProgram() 5. Check for linking errors 5. 5. echo $? LINK_STATUS 6. 6. UseProgram() Run your program! 6. ./a.out
  11. 11. • SHADER OBJECT • PROGRAM OBJECT • glCreateShader • glCreateProgram • glDeleteShader • glDeleteProgram • glShaderSource • glAttachShader • glCompileShader • glDetachShader • glLinkProgram • glIsShader • glUseProgram • glGetShaderiv • glValidateProgram • glGetShaderInfoLog • glIsProgram • glGetProgramiv • glGetProgramInfoLog
  12. 12. #define BUFSZ 1024 #define SHADER_SOURCE = quot;void main (void) { gl_Position = ftransform (); }quot; GLuint vert; GLint stat; char buf[BUFSZ]; vert = glCreateShader (GL_VERTEX_SHADER); glShaderSource (vert, 1, SHADER_SOURCE, NULL); glCompileShader (vert); glGetShaderInfoLog (vert, BUFSZ, NULL, buf); printf (quot;log: %snquot;, buf); glGetShaderiv (vert, GL_COMPILE_STATUS, &stat); printf (quot;compile %snquot;, (stat == GL_TRUE)? quot;okquot;: quot;failedquot;); glDeleteShader (vert);
  13. 13. #define BUFSZ 1024 GLuint vert, frag, prog; GLint stat; char buf[BUFSZ]; vert = my_load_shader (quot;vertex.glslquot;); frag = my_load_shader (quot;fragment.glslquot;); prog = glCreateProgram (); glAttachShader (prog, vert); glAttachShader (prog, frag); glLinkProgram (prog); glGetProgramInfoLog (prog, BUFSZ, NULL, buf); printf (quot;log: %snquot;, buf); glGetProgramiv (program, GL_LINK_STATUS, &stat); printf (quot;link %snquot;, (stat == GL_TRUE)? quot;okquot;: quot;failedquot;);
  14. 14. PART III: GLSL PROGRAMMING
  15. 15. Vertex Attributes Uniforms glVertexAttrib* glGetUniformLocation glBindAttribLocation glUniform*
  16. 16. GLuint prog; GLint texLoc, timeLoc; GLfloat time; #define WEIGHT_INDEX 1 prog = my_load_prog (); texLoc = glGetUniformLocation (prog, quot;texquot;); if (texLoc == -1) my_panic (); timeLoc = glGetUniformLocation (prog, quot;timequot;); if (timeLoc == -1) my_panic (); glBindAttribLocation (prog, WEIGHT_INDEX, quot;weightquot;); glUseProgram (prog); glUniform1i (texLoc, 0); // USE TEXTURE UNIT 0 while (not_stop) { time = my_time_update (); glUniform1f (timeLoc, time); my_render_func (); } glUseProgram (0);
  17. 17. LET'S WRITE SHADERS!
  18. 18. THANK YOU! and enjoy your CG practical tom@mimicmedia.nl

×