CS179: GPU Programming

Similar documents
Lighting and Texturing

CS 432 Interactive Computer Graphics

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

CISC 3620 Lecture 7 Lighting and shading. Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping

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

OpenGL Texture Mapping. Objectives Introduce the OpenGL texture functions and options

-=Catmull's Texturing=1974. Part I of Texturing

Texture Mapping. Mike Bailey.

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

CS212. OpenGL Texture Mapping and Related

CS452/552; EE465/505. Texture Mapping in WebGL

Lecture 2. Shaders, GLSL and GPGPU

CS 179: GPU Programming

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

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

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

CS 179 GPU Programming

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Discussion 3. PPM loading Texture rendering in OpenGL

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

Texture Mapping. Computer Graphics, 2015 Lecture 9. Johan Nysjö Centre for Image analysis Uppsala University

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

INF3320 Computer Graphics and Discrete Geometry

INF3320 Computer Graphics and Discrete Geometry

Lecture 07: Buffers and Textures

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실.

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

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

CPSC 436D Video Game Programming

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

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

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

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

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

CS195V Week 6. Image Samplers and Atomic Operations

Texture mapping. Computer Graphics CSE 167 Lecture 9

Texture Mapping. Texture Mapping. Map textures to surfaces. Trompe L Oeil ( Deceive the Eye ) The texture. Texture map

Objectives. Texture Mapping and NURBS Week 7. The Limits of Geometric Modeling. Modeling an Orange. Three Types of Mapping. Modeling an Orange (2)

General Purpose computation on GPUs. Liangjun Zhang 2/23/2005

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

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

Sign up for crits! Announcments

Tutorial 3: Texture Mapping

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

OPENGL RENDERING PIPELINE

OpenGL & Visualization

GLSL Applications: 2 of 2

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Dave Shreiner, ARM March 2009

Lecture 5 3D graphics part 3

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

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

11494 Interactive and GPU Computing Lab. 6-06/05/2015. Textures

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

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

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

To Do. Review of Last Demo. Methodology for Lecture. Geometry Basic Setup. Outline. Foundations of Computer Graphics (Fall 2012)

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

Programming shaders & GPUs Christian Miller CS Fall 2011

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

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

Overview. By end of the week:

Methodology for Lecture

2D graphics with WebGL

Cap. 3 Textures. Mestrado em Engenharia Informática (6931) 1º ano, 1º semestre

CS770/870 Fall 2015 Advanced GLSL

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

Computer Graphics. Three-Dimensional Graphics VI. Guoying Zhao 1 / 73

Texturas. Objectives. ! Introduce Mapping Methods. ! Consider two basic strategies. Computação Gráfica

1 of 5 9/10/ :11 PM

Lecture 13: OpenGL Shading Language (GLSL)

Computer Graphics. Bing-Yu Chen National Taiwan University

VGP352 Week March-2008

Preparing for Texture Access. Stored Texture Shaders. Accessing Texture Maps. Vertex Shader Texture Access

Jitter Shaders. Fig 1. The opengl pipeline (simplified).

Motivation Hardware Overview Programming model. GPU computing. Part 1: General introduction. Ch. Hoelbling. Wuppertal University

Stored Texture Shaders

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

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

Texturing. Slides done bytomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

三維繪圖程式設計 3D Graphics Programming Design 第七章基礎材質張貼技術嘉大資工系盧天麒

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

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

Practical Texturing (WebGL) CS559 Fall 2016 Lecture 20 November 7th 2016

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

Game Technology. Lecture Hardware Rendering. Prof. Dr.-Ing. Ralf Steinmetz KOM - Multimedia Communications Lab. Dr.-Ing.

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

MXwendler Fragment Shader Development Reference Version 1.0

Texture Mapping and Special Effects

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

+ = Texturing: Glue n-dimensional images onto geometrical objects. Texturing. Texture magnification. Texture coordinates. Bilinear interpolation

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

More frames per second. Alex Kan and Jean-François Roy GPU Software

Shaders. Slide credit to Prof. Zwicker

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

Steiner- Wallner- Podaras

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Transcription:

CS179: GPU Programming Lecture 4: Textures Original Slides by Luke Durant, Russel McClellan, Tamas Szalay

Today Recap Textures What are textures? Traditional uses Alternative uses

Recap Our data so far: Vertices with associated data Position, color, etc. Triangles Fragments in triangle interpolate vertex data All our data is constant! ex. we can only have triangle be single color How could we attach pictures to triangles?

Textures Images stored in GPU memory Variety of storage types, usually floats Ex: RGBA for each pixel Can vary in size, resolution Generally powers of 2 OpenGL supports 1D, 2D, and 3D textures 2D are probably the most intuitive

Textures Access data via Texture Coordinates Referred to as (u, v), or (s, t, p, q) Range from 0 to 1 (0, 0) (1, 0) (0, 1) (1, 1)

Texturing in the Pipeline Specify texcoords per vertex Interpolated between verts (like other varyings) Fragment color is original image sampled at interpolated coordinate

Texturing Complex Models

Texturing in OpenGL Create texture: glgentextures Bind (select) texture: glbindtexture Set parameters: gltexparameter[f/i] Set image data: glteximage2d Enable textures: glenable(gl_texture_2d) Set texture coords: gltexcoord2f Between glbegin and glend As always, this will be provided!

Mipmaps

Mipmaps

Texture Parameters gltexparameterf(gl_texture_2d, param, value) GL_TEXTURE_WRAP_S/T {GL_REPEAT, GL_CLAMP} Sets behavior for coords outside of (0, 1) GL_TEXTURE_MIN/MAG_FILTER {GL_LINEAR, GL_NEAREST} Sets inter-pixel sampling mode (linear is bilinear, samples nearest 4 pixels) when zooming in or out

Multitexturing Unfortunately, glbindtexture only works for one texture at a time To use multiple textures, use glactivetexture glactivetexture(gl_texturen), replace n with 0,1,... Now gl calls affect texture n Set coords using glmultitexcoord(gl_texturen, s, t, p, q)

Texturing in GLSL Attribute texture coordinate inputs to vertex shader gl_multitexcoordn (N = 0,...,7) gl_texcoord[ ] is a set of writeable varyings To read textures, use 2D sampler uniforms: uniform sampler2d tex; Access using texture2d function: ex: vec4 color = texture2d(tex, gl_texcoord[0].st)

GLSL Swizzling In above example, we access gl_texcoord[0].st.st outputs a vec2 Can access vec data like this, using a variety of abbreviations: vec.xyzw, vec.stpq, vec.rgba All mean the same thing We can also mix them: If vec is a vec3 = (1, 2, 3): vec.xy = (1, 2) and vec.yx = (2, 1) are both valid! Output vec2's

Summary On OpenGL we: Create texture Set data Set params Set uniforms Set texcoords On GLSL side we: Use built-in texture coordinates and varyings Define samplers for uniforms for each texture Use texture2d functions to read data Don't worry, plenty of practice in lab2

Side Note Rendering complex models: We don't want to hardcode it Going through a for-loop to assign texcoords to verts This is really bad/slow Instead, use pointers and buffers: glvertexpointer, gltexcoordpointer, etc. Buffers work like textures, create and bind them You don't need to know the details for this class, but it is good to know

Uses of Texturing Texturing pre-generated models Used in almost all video games since Quake.. Pretty simple, so we wont cover here Modify surface properties Ex. suppose we want to model a bottle with a label Have a texture that is 0 where the glass is and 1 where the label is Or, cheat and store this 0 or 1 in the alpha channel of the color map Most of using shaders/textures is cheating

Uses of Texturing Visual effects Ex: blur texture Sample all points around a coordinate, and average Pretty fast Height maps Can be used to model terrain with only a 2D texture You'll use this idea in lab 2 NVIDIA Cascades 3D textures to generate rock formations

Using Textures in Vertex Shaders Similar to frag shaders, can have sampler2d uniforms in vertex shader Can store all sorts of info in textures for verts We'll use this more in lab 3

Data from Textures Uniform arrays are limited in size Can't be bigger than a few kb To pass large amounts of data, we need textures As mentioned, can sample in either vertex shader or frag shader