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

Similar documents
Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

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

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

Programmable Graphics Hardware

12.2 Programmable Graphics Hardware

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

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

Introduction to Shaders.

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

Supplement to Lecture 22

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

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

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

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

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

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book IMGD 4000 (D 10) 1

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

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

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

Introduction to the OpenGL Shading Language

Sign up for crits! Announcments

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

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

The Basic Computer Graphics Pipeline, OpenGL-style. Introduction to the OpenGL Shading Language (GLSL)

Introduction to the OpenGL Shading Language (GLSL)

Programming shaders & GPUs Christian Miller CS Fall 2011

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

The Graphics Pipeline

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

The Graphics Pipeline

CMPS160 Shader-based OpenGL Programming. All slides originally from Prabath Gunawardane, et al. unless noted otherwise

Programmable Graphics Hardware

Lecture 09: Shaders (Part 1)

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

COMP371 COMPUTER GRAPHICS

OPENGL RENDERING PIPELINE

Ciril Bohak. - INTRODUCTION TO WEBGL

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

CMPS160 Shader-based OpenGL Programming

Shaders. Slide credit to Prof. Zwicker

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

Dave Shreiner, ARM March 2009

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

GLSL v1.20. Scott MacHaffie Schrödinger, Inc.

Stripes, Rings, and Dots!

Rendering Objects. Need to transform all geometry then

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

GPU Programming EE Final Examination

OpenGL Performances and Flexibility. Visual Computing Laboratory ISTI CNR, Italy

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

Tuesday, 23 March OpenGL Shading Language

2D graphics with WebGL

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

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

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

CS 432 Interactive Computer Graphics

GLSL. OpenGL Shading Language. OpenGL 1.5 Logical Diagram. OpenGL 2.0 Logical Diagram

Objectives. Open GL Shading Language (GLSL)

Rasterization Overview

E.Order of Operations

GPU Programming EE Final Examination

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

OpenGL Performances and Flexibility

Lecture 2. Shaders, GLSL and GPGPU

Computer Graphics Coursework 1

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

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

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

Graphics Processing Unit Architecture (GPU Arch)

Mobile Application Programing: Android. OpenGL Operation

2.11 Particle Systems

Waves, Displacement, Reflections. Arun Rao CS 594

Intro to GPU Programming (OpenGL Shading Language) Cliff Lindsay Ph.D. Student CS WPI

CPSC 436D Video Game Programming

An Overview GLUT GLSL GLEW

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

LSU EE Homework 5 Solution Due: 27 November 2017

CS452/552; EE465/505. Image Processing Frame Buffer Objects

CS770/870 Fall 2015 Advanced GLSL

OpenGL Programmable Shaders

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

Understanding M3G 2.0 and its Effect on Producing Exceptional 3D Java-Based Graphics. Sean Ellis Consultant Graphics Engineer ARM, Maidenhead

OpenGL shaders and programming models that provide object persistence

Lecture 13: OpenGL Shading Language (GLSL)

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

Programmable shader. Hanyang University

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

CMSC427 OpenGL and JOGL

Models and Architectures

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

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

Game Graphics Programmers

Advanced Graphics. The Shader knows. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

Lab 9 - Metal and Glass

Transcription:

Shader Programming Daniel Wesslén, dwn@hig.se Stefan Seipel, ssl@hig.se Examples 1

Per-pixel lighting Texture convolution filtering 2

Post-processing, animated procedural textures Vertex displacement mapping 3

Fragment shader Mandelbrot set Animation 4

Direct volume rendering The OpenGL pipeline 5

OpenGL 1.4 connectivity vertex transform & lighting primitive assembly rasterization texture fog, texturing framebuffer blending, depth, stencil OpenGL 2.1 connectivity vertex shader primitive assembly rasterization VBO texture framebuffer fragment shader blending, depth, stencil 6

Shader processing Parallel processing vertices: properties vertex scheduler vertex processors vertices: positions, properties rasterizer fragments: positions, properties fragment processors framebuffer fragments: colors 7

Vertex shader vertices: properties vertex processors vertices: positions, properties Transform Animation Per-vertex lighting Displacement Mostly: Parameter setup for fragments Can not modify topology No access to other vertices Fragment shader fragments: positions, properties fragment processors fragments: colors Per-pixel lighting Texturing Compositing Filtering Fog Can not read or write pixels No access to other fragments 8

Simple example Per-pixel lighting 9

Vertex shader color = gl_color.rgb; normal = normalize(gl_normalmatrix * gl_normal); pos = vec3(gl_modelviewmatrix * gl_vertex); gl_position = gl_modelviewprojectionmatrix * gl_vertex; Vertex shader color = gl_color.rgb; normal = normalize(gl_normalmatrix * gl_normal); pos = vec3(gl_modelviewmatrix * gl_vertex); uniform (prog. to vertex, per primitive) attribute (prog. to vertex, per vertex) varying (vertex to fragment) gl_position = gl_modelviewprojectionmatrix * gl_vertex; 10

Vertex shader color = gl_color.rgb; normal = normalize(gl_normalmatrix * gl_normal); pos = vec3(gl_modelviewmatrix * gl_vertex); int, float, bool (basic types) vec2, vec3, vec4 (2,3,4d vector) mat2, mat3, mat4 (2,3,4d float matrix) ivec3, bvec4, etc. (vectors only) gl_position = gl_modelviewprojectionmatrix * gl_vertex; Vertex shader color = gl_color.rgb; normal = normalize(gl_normalmatrix * gl_normal); pos = vec3(gl_modelviewmatrix * gl_vertex); gl_position = gl_modelviewprojectionmatrix * gl_vertex; 11

Vertex shader vertex shader built-in attributes writing to gl_position is mandatory color = gl_color.rgb; normal = normalize(gl_normalmatrix * gl_normal); pos = vec3(gl_modelviewmatrix * gl_vertex); gl_position = gl_modelviewprojectionmatrix * gl_vertex; Vertex shader built-in uniforms color = gl_color.rgb; normal = normalize(gl_normalmatrix * gl_normal); pos = vec3(gl_modelviewmatrix * gl_vertex); gl_position = gl_modelviewprojectionmatrix * gl_vertex; 12

Fragment shader uniform float shininess; vec3 nlight = normalize(gl_lightsource[0].position.xyz - pos); vec3 neye = normalize(-pos); vec3 nnormal = normalize(normal); vec3 nhalf = normalize(neye + nlight); float diff = max(0.0, dot(nlight, nnormal)); float spec = diff > 0.0? pow(dot(nhalf, nnormal), shininess) : 0.0; gl_fragcolor = vec4(color * diff + spec, 1); Fragment shader uniform float shininess; built-in functions vec3 nlight = normalize(gl_lightsource[0].position.xyz - pos); vec3 neye = normalize(-pos); vec3 nnormal = normalize(normal); vec3 nhalf = normalize(neye + nlight); float diff = max(0.0, dot(nlight, nnormal)); float spec = diff > 0.0? pow(dot(nhalf, nnormal), shininess) : 0.0; gl_fragcolor = vec4(color * diff + spec, 1); 13

Fragment shader uniform float shininess; writing to gl_fragcolor or gl_fragdata[] is mandatory vec3 nlight = normalize(gl_lightsource[0].position.xyz - pos); vec3 neye = normalize(-pos); vec3 nnormal = normalize(normal); vec3 nhalf = normalize(neye + nlight); float diff = max(0.0, dot(nlight, nnormal)); float spec = diff > 0.0? pow(dot(nhalf, nnormal), shininess) : 0.0; gl_fragcolor = vec4(color * diff + spec, 1); 14