GLSL: Releasing the power of the GPU

  • 1,181 views
Uploaded 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.

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.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • very good
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
1,181
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
1
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. SHADERS: Releasing the power of the GPU (and your creativity)
  • 2. PART I: THE SHADER CONCEPT
  • 3. 3D Programming
  • 4. Rasterization
  • 5. THE BIRTH OF GPU SHADERS 1. No special hardware 2. Hardware acceleration 3. Programmable Hardware 4. Programmable Hardware Interface
  • 6. Rasterization (GPU)
  • 7. PART II: THE OPENGL SHADER API
  • 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. 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. 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. • SHADER OBJECT • PROGRAM OBJECT • glCreateShader • glCreateProgram • glDeleteShader • glDeleteProgram • glShaderSource • glAttachShader • glCompileShader • glDetachShader • glLinkProgram • glIsShader • glUseProgram • glGetShaderiv • glValidateProgram • glGetShaderInfoLog • glIsProgram • glGetProgramiv • glGetProgramInfoLog
  • 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. #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. PART III: GLSL PROGRAMMING
  • 15. Vertex Attributes Uniforms glVertexAttrib* glGetUniformLocation glBindAttribLocation glUniform*
  • 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. LET'S WRITE SHADERS!
  • 18. THANK YOU! and enjoy your CG practical tom@mimicmedia.nl