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

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

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

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

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

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

Programming shaders & GPUs Christian Miller CS Fall 2011

CPSC 436D Video Game Programming

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

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

Lighting and Texturing

Programmable Graphics Hardware

OpenGL & Visualization

Introduction to Shaders.

CS179: GPU Programming

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

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

Supplement to Lecture 22

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

VGP352 Week March-2008

Programmable shader. Hanyang University

Introduction to the OpenGL Shading Language (GLSL)

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

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

OPENGL RENDERING PIPELINE

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

Sign up for crits! Announcments

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

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

OpenGL Performances and Flexibility

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

Lecture 2. Shaders, GLSL and GPGPU

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

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

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

Dave Shreiner, ARM March 2009

1)Write a shader program that renders a regular pentagon with textured image like the one shown below.

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

Introduction to Computer Graphics with WebGL

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

Computergraphics Exercise 15/ Shading & Texturing

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

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Shaders. Slide credit to Prof. Zwicker

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

Discussion 3. PPM loading Texture rendering in OpenGL

BCA611 Video Oyunları için 3B Grafik

OpenGL. Toolkits.

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

GPU Programming EE Final Examination

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

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

1) Here is the various stages of the tetrahedron:

COMP371 COMPUTER GRAPHICS

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Philip Calderon CSE 520 Lab 3 Color Shader

HD (in) Processing. Andrés Colubri Design Media Arts dept., UCLA Broad Art Center, Suite 2275 Los Angeles, CA

Lecture 9(B): GPUs & GPGPU

CSCI E-74. Simulation and Gaming

Overview. By end of the week:

Programmable Graphics Hardware

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

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Introduction to GLSL. Announcements. Agenda. Course Contents. Patrick Cozzi University of Pennsylvania CIS Fall 2012

1 of 5 9/10/ :11 PM

Stored Texture Shaders

CS 432 Interactive Computer Graphics

Programming Graphics Hardware

This Lecture. Why OpenGL? Introduction to OpenGL. Programmer s View

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

To Do. Demo: Surreal (HW 3) This Lecture. Introduction to OpenGL. Outline. Foundations of Computer Graphics (Spring 2012)

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

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Graphics Pipeline & APIs

2.11 Particle Systems

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

12.2 Programmable Graphics Hardware

Erik Anchondo cse 520 lab 4

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

Lab 9 - Metal and Glass

2a. The triangles scale increases (expands) when the 'e' key is pressed and decreases (contracts) when the 'c' key is pressed.

Review of Thursday. xa + yb xc + yd

MXwendler Fragment Shader Development Reference Version 1.0

compatibility mode core mode

Precept 2 Aleksey Boyko February 18, 2011

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

Methodology for Lecture

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

Objectives. Open GL Shading Language (GLSL)

INTRODUCTION TO OPENGL 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

Page 6 PROCESSOR PROCESSOR FRAGMENT FRAGMENT. texy[1] texx. texy[1] texx. texy[0] texy[0]

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

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

CT5510: Computer Graphics. Texture Mapping

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

Mobile Application Programing: Android. OpenGL Operation

Transcription:

GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Straight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things with C/C++. Some advantages come from the limited environment! Algol descendant, easy to learn if you know any of its followers.

GLSL Example Vertex shader: void main() gl_position = gl_projectionmatrix * gl_modelviewmatrix * gl_vertex; Pass-through shader, implements the minimal functionality of the fixed pipeline

GLSL Example Fragment shader: void main() gl_fragcolor = vec4(1.0, 1.0, 1.0, 1.0); Set-to-white shader

Example Pass-through vertex shader + set-to-white fragment shader // Vertex shader void main() gl_position = gl_projectionmatrix * gl_modelviewmatrix * gl_vertex; // Fragment shader void main() gl_fragcolor = vec4(1.0, 1.0, 1.0, 1.0);

So what do we care about for GPGPU? Vertex shader almost irrelevant. Light sources, vertex colors, geometry shader... forget about most of them here. Fragment shader is the computing kernel. Texture access vital. Uniforms = constant memory.

Texture access Example: uniform sampler2d texture; void main() gl_fragcolor = texture2d(texture, gl_texcoord[0].st); texture2d() performs texture access

Texture coordinates Built-in variables: gl_multitexcoord0 is texture coordinate for vertex for texture unit 0. gl_texcoord[0] is a built-in varying for interpolating texture coordinates. gl_texcoord[0].s and gl_texcoord[0].t give the S and T components separately.

Texture data In order to use predefined texture data, they should be communicated from OpenGL! This is done by a uniform, a variable that can not be changed within a primitive. samplers : pre-defined type for referencing texture data

Writing to textures Use Framebuffer Objects Lets you bind a texture as rendering target.

Ping-ponging in working code void runfilter(gluint shader, GLuint texin, GLuint texin2, GLuint fboout) glbindframebufferext(gl_framebuffer, fboout); glactivetexture(gl_texture1); glbindtexture(gl_texture_2d, texin2); glactivetexture(gl_texture0); glbindtexture(gl_texture_2d, texin); glviewport(0, 0, width, height); if (fboout == 0) glviewport(0, 0, lastw, lasth); // Clean matrices! glmatrixmode(gl_projection); glpushmatrix(); glloadidentity(); glmatrixmode(gl_modelview); glpushmatrix(); glloadidentity(); gluseprogram(shader); // Polygon over framebuffer glbegin(gl_polygon); gltexcoord2f(0, 0); glvertex2f(-1, -1); gltexcoord2f(1, 0); glvertex2f(1, -1); gltexcoord2f(1, 1); glvertex2f(1, 1); gltexcoord2f(0, 1); glvertex2f(-1, 1); glend(); // Restore glmatrixmode(gl_projection); glpopmatrix(); glmatrixmode(gl_modelview); glpopmatrix();

...gets pretty nice in the end // Run treshold shader from tex 1 to tex/fbo 2 runfilter(tresholdshader, tex1, 0, fb2); // Filter several times for (i = 0; i < loops; i++) runfilter(lpvshader, tex2, 0, fb3); runfilter(lphshader, tex3, 0, fb2); // Output result runfilter(0, tex2, 0, 0);

Conclusions: Shader-based GPGPU is not dead, it is just not hyped Superior compatibility and ease of installation makes it highly interesting for the forseeable future. Especially suitable for all imagerelated problems. GLSL The OpenGL shading language was introduced. How to do GPGPU with shaders FBOs, Ping-ponging, algorithms, special considerations.

Thatʼs all folks! Next time: OpenCL