Introduction to Shaders.

Similar documents
Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Lecture 2. Shaders, GLSL and GPGPU

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Programmable Graphics Hardware

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Supplement to Lecture 22

Programmable Graphics Hardware

Shaders. Slide credit to Prof. Zwicker

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Graphics Hardware. Instructor Stephen J. Guy

12.2 Programmable Graphics Hardware

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

printf Debugging Examples

Introduction to the OpenGL Shading Language

Graphics Hardware. Graphics Processing Unit (GPU) is a Subsidiary hardware. With massively multi-threaded many-core. Dedicated to 2D and 3D graphics

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

COMP371 COMPUTER GRAPHICS

OPENGL RENDERING PIPELINE

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

1.2.3 The Graphics Hardware Pipeline

Graphics Pipeline & APIs

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

Programming shaders & GPUs Christian Miller CS Fall 2011

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

NVIDIA FX Composer. Developer Presentation June 2004

Cg 2.0. Mark Kilgard

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

Graphics Pipeline & APIs

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

OpenGL Programmable Shaders

MXwendler Fragment Shader Development Reference Version 1.0

An Overview GLUT GLSL GLEW

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Graphics Hardware. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 2/26/07 1

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Content. Building Geometry Appearance Lights Model Loaders

2.11 Particle Systems

Models and Architectures

Mobile Application Programing: Android. OpenGL Operation

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

Sign up for crits! Announcments

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Shaders : the sky is the limit Sébastien Dominé NVIDIA Richard Stenson SCEA

Practical Performance Analysis Koji Ashida NVIDIA Developer Technology Group

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

The Transition from RenderMan to the OpenGL Shading Language (GLSL)

CS 354R: Computer Game Technology

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

The Ultimate Developers Toolkit. Jonathan Zarge Dan Ginsburg

Programming Graphics Hardware

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Shaders (some slides taken from David M. course)

Sung-Eui Yoon ( 윤성의 )

The Application Stage. The Game Loop, Resource Management and Renderer Design

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

CSE4030 Introduction to Computer Graphics

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

RenderMonkey 1.6. Natalya Tatarchuk ATI Research

Programmable shader. Hanyang University

Introduction to Computer Graphics with WebGL

Spring 2009 Prof. Hyesoon Kim

Could you make the XNA functions yourself?

Prospects for a more robust, simpler and more efficient shader cross-compilation pipeline in Unity with SPIR-V

Dave Shreiner, ARM March 2009

The Graphics Pipeline

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST

Introduction to OpenGL

CS427 Multicore Architecture and Parallel Computing

Graphics Processing Unit Architecture (GPU Arch)

Line Drawing. Foundations of Computer Graphics Torsten Möller

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Ciril Bohak. - INTRODUCTION TO WEBGL

GPU Programming EE Final Examination

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

CS770/870 Fall 2015 Advanced GLSL

Levy: Constraint Texture Mapping, SIGGRAPH, CS 148, Summer 2012 Introduction to Computer Graphics and Imaging Justin Solomon

Mobile Application Programing: Android. OpenGL Operation

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

The Graphics Pipeline

The Rasterization Pipeline

Grafica Computazionale: Lezione 30. Grafica Computazionale. Hiding complexity... ;) Introduction to OpenGL. lezione30 Introduction to OpenGL

Rasterization Overview

3D Graphics and OpenGl. First Steps

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

Transcription:

Introduction to Shaders Marco Benvegnù hiforce@gmx.it www.benve.org Summer 2005

Overview Rendering pipeline Shaders concepts Shading Languages Shading Tools Effects showcase Setup of a Shader in OpenGL Introduction to GLSL

Rendering Pipeline Vertex Connectivity Fragment Position Application Vertex Processor Rasterizer Fragment Processor Buffer Vertices Transformed Vertices Fragments Colored Fragments Wood Texture

Application Output: Vertices attributes (position, texture coordinates, color, normal...) Connectivity information This snippet sends the position and color of 2 vertices: glbegin(gl_lines); glcolor3f(1.0, 0.9, 0.0); glvertex3f(1.0, 4.0, 2.0); glcolor3f(1.0, 0.1, 0.0); glvertex3f(2.0, 1.0, 2.0); glend();

Vertex Processor Input: Vertex attributes Predefined operations: Vertex position transformation Lighting computations per vertex Generation or transformation of texture coordinates Output: Transformed vertex attributes

Rasterizer Input: Transformed vertices Connectivity information Operations: Primitives assembly (and clipping) Rasterization(determines the pixels covered by the primitive) Interpolation of vertices attributes along each primitive Output: Position of the fragments in the frame buffer Interpolated attributes for each fragment

Fragment Processor Input: Interpolated fragment attributes Predefined operations: Texturing Fog Output: Final color and depth of the fragment

Buffer Inputs: Fragment color and depth Fragment position Operations: Scissor test Alpha test and blending Stencil test Depth test

What are Shaders? Shaders are programs executed by vertex and fragment processors in the graphics hardware Vertex Shaders fully replace the T&L Unit Pixel Shaders fully replace the Texturing Unit

Why the need? Before 2001 the graphics hardware wasn t programmable and offered limited control on the rendering pipeline But the graphics industry is mostly driven to create new and newer effects Programmers started to perform multi-pass rendering and spend more and more time to tweak the render state for tasks beyond the original scope of design GPU vendors started to implement custom extensions Shaders opened the door to new exciting rendering effects and tecniques

Vertex Shader Input: Vertex attributes Common tasks: Vertex position transformation Per vertex lighting Normal transformation Texture coordinates transformation or generation Vertex color computation Geometry skinning Cannot access any vertex other than the current one Minimal output: Vertex position (in the clip space)

Fragment Shader Input: Interpolation of the vertex shader outputs Common tasks: Texturing (even procedural) Per pixel lighting Fragment color computation Cannot access neighboring fragments Typical output: Fragment color

Simple sample void main() // Vertex shader { gl_position = gl_modelviewprojectionmatrix * gl_vertex; } void main() // Fragment shader { gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); }

Shaders concepts Shaders have access to Textures and to the Render state (parameters, matrices, lights, materials ) A Pass is the rendering of a 3D Model with a Vertex and Pixel Shader pair An effect can require multiple Passes Each pass can use a different Model and/or Shader pair A Pass can render to a texture (to be used by another Pass) Think to the fixed functionality as to the default Shader

Shading Languages HLSL (Microsoft, 2002) Cg (nvidia, 2002) GLSL (ARB, 2003) ASM Shading Languages (2001) Direct3D (Microsoft, 1995) OpenGL (ARB, 1992)

Other Languages Sh is a meta-language embedded in C++, allowing the integration of Shaders in the application source code BrookGPU is a scientific computing language for GPUs, allowing general-purpose computations on powerful graphics hardware

High level languages C-like sintax Data types: Vectors (1 to 4 floats, integers, booleans) Matrices (2x2, 3x3, 4x4) Arrays and Textures Conditions, loops, functions Vector-Matrix algebra Special instructions (Trigonometry, Exponentials, Geometry, Interpolation...)

Runtime compilation Shaders will be compiled whenthe 3D application starts They will be validated and optimized for the current hardware Direct3D natively compiles HLSL Shaders OpenGL natively compiles GLSL Shaders The Cg Runtime Library allows to compile Cg Shaders in both D3D and OGL applications Still, high level Shaders can be compiled down to ASM to be fully optimized at hand (for several hardware profiles)

Shading tools RenderMonkey (ATI / 3Dlabs) Intuitive IDE Supports GLSL Cg Toolkit (nvidia) All you need to start with Cg FX Composer (Microsoft / nvidia) FX files editor (best interchange format) Best profiling and debugging tools Maya/Max plugins to test and tune shaders in your scene

Workflow DCC tool (Max, Maya) FX plugin Scene exporter plugin FX FX Composer Composer.FX files Same output! Scene Manager FX runtime library Application

How to learn Shaders 1. Start by using existing Shaders in your applications (no need to learn a shading language for this) 2. Try to tweak some parameters and equations, to see their meaning (RenderMonkey is perfect for this) 3. Don t reinvent the weel: many effects are already implemented! Instead learn how to adapt them to your needs 4. Learn linear algebra and lighting models

References www.ati.com/developer developer.nvidia.com www.shadertech.com Cg Toolkit: User's Manual The OpenGL Shading Language The OpenGL Graphics System: A Specification