TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Similar documents
Lecture 5 3D graphics part 3

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

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

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Discussion 3. PPM loading Texture rendering in OpenGL

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

CS 432 Interactive Computer Graphics

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

CT5510: Computer Graphics. Texture Mapping

Steiner- Wallner- Podaras

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

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

Computergraphics Exercise 15/ Shading & Texturing

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

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

INF3320 Computer Graphics and Discrete Geometry

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

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

Overview. By end of the week:

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

INF3320 Computer Graphics and Discrete Geometry

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

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

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

Stored Texture Shaders

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

CMSC 425: Lecture 12 Texture Mapping Thursday, Mar 14, 2013

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Overview. Goals. MipMapping. P5 MipMap Texturing. What are MipMaps. MipMapping in OpenGL. Generating MipMaps Filtering.

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

COMP371 COMPUTER GRAPHICS

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

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

Sign up for crits! Announcments

Shading/Texturing. Dr. Scott Schaefer

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

Lecture 07: Buffers and Textures

CS GPU and GPGPU Programming Lecture 12: GPU Texturing 1. Markus Hadwiger, KAUST

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

Texture Mapping. Mike Bailey.

CS179: GPU Programming

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

CS212. OpenGL Texture Mapping and Related

Computer Graphics (CS 543) Lecture 8c: Environment Mapping (Reflections and Refractions)

CS GPU and GPGPU Programming Lecture 16+17: GPU Texturing 1+2. Markus Hadwiger, KAUST

Billboards!! A texture mapped polygon, which always faces the viewer

Texture mapping. Computer Graphics CSE 167 Lecture 9

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

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

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

Computer Graphics Texture Mapping

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

Shadow Rendering. CS7GV3 Real-time Rendering

Mipmaps. Lecture 23 Subsection Fri, Oct 30, Hampden-Sydney College. Mipmaps. Robb T. Koether. Discrete Sampling.

INFOGR Computer Graphics

INFOGR Computer Graphics

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

CSE 167: Lecture 11: Textures 2. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

Quick Shader 0.1 Beta

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

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

CPSC / Texture Mapping

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

CS GPU and GPGPU Programming Lecture 11: GPU Texturing 1. Markus Hadwiger, KAUST

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

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

CS 354R: Computer Game Technology

Grafica Computazionale

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

Lab 9 - Metal and Glass

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

CS451Real-time Rendering Pipeline

Lighting and Texturing

Animation Essentially a question of flipping between many still images, fast enough

QUESTION 1 [10] 2 COS340-A October/November 2009

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Real-time Graphics 6. Reflections, Refractions

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

Content. Building Geometry Appearance Lights Model Loaders

Computer Graphics Texture Mapping

GLSL Applications: 2 of 2

Texture. Texture Mapping. Texture Mapping. CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

Department of Computer Sciences Graphics Spring 2013 (Lecture 19) Bump Maps

Magnification and Minification

Introduction to Computer Graphics with WebGL

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

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

Programmable Graphics Hardware

CHAPTER 1 Graphics Systems and Models 3

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

CS559 Computer Graphics Fall 2015

OPENGL RENDERING PIPELINE

Transcription:

1(61) Information Coding / Computer Graphics, ISY, LiTH TSBK 07 Computer Graphics Ingemar Ragnemalm, ISY 1(61)

Lecture 6 Texture mapping Skyboxes Environment mapping Bump mapping 2(61)2(61)

Texture mapping Texture coordinates from 0 to 1 3(61)3(61)

Texture units Textures are bound to texture units, hardware resources for looking up textures The shader uses the texture unit ID, not the texture object Texture image Texture object Texture unit Shader sampler 4(61)4(61)

Texture parameters gltexparameter(...); GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_REPEAT GL_CLAMP_TO_EDGE 2 2 1 1 1 0 0 1 0-1 -1 0 1 2 0-1 -1 0 1 2 5(61)5(61)

Magnification and minification parameters: gltexparameteri(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_NEAREST); Specifies what should happen when the texture doesn t match the pixel grid MIN MAG 6(61)6(61)

Aliasing A digital image is a sampled signal If the signal is not band limited, aliasing will occur 7(61)7(61)

Aliasing in texture mapping At large distance, textures get smaller => higher spatial frequencies on the screen => increasing risk for aliasing 8(61)8(61)

Aliasing can be reduced by two methods: Filtering gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR); Mip-mapping glgeneratemipmap(); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 9(61)9(61)

MIP mapping Texture mapping with anti-aliasing. A resolution pyramid is built from every texture. Memory cost: 33% more. Cheap 128x128 64x64 32x32 16x16 10(61) 10(61)

MIP mapping filtering Both within a level and between 11(61)11(61)

MIP mapping filtering GL_NEAREST GL_LINEAR GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR Preferred: GL_LINEAR for magnification GL_LINEAR_MIPMAP_LINEAR for minification 12(61)12(61)

MIP mapping Gives anti-aliasing at a very low cost. Good results in most situations. Aliasing problems remain at steep angles. 13(61)13(61)

Texture mapping is not just stretching: Affine Perspective correct 14(61)14(61)

Generating texture coordinates Now we know how to draw, but... where do the texture coordinates come from? May be delivered with the model... but can we make them ourselves? Yes 15(61)15(61)

Pre-calculating (s,t) for every vertex in a model Texture map (s,t) Map to intermediate surface (u,v) Map to 3D object (x, y, z) 16(61)16(61)

Pre-calculating (s,t) for every vertex in a model Use to index the texture map Map to inter- mediate surface coordinates Polygon vertex coordinates 17(61)17(61)

Examples Planar (Linear) Cylinder Sphere 18(61)18(61)

Common mappings Planar Cylinder Sphere 19(61)19(61)

Planar texture mapping Along z: u = x v = y 20(61)20(61)

Cylindrical texture mapping x = Rcos(θ) y = Rsin(θ) u = θ = arctan(y,x) v = z arctan(y,x) = x > 0: tan-1(y/x) x<0: π + tan-1(y/x) x = 0, y > 0: π/2 x = 0, y < 0: -π/2 21(61)21(61)

Spherical texture mapping x = Rcos(φ)cos(θ) y = Rcos(φ)sin(θ) z = Rsin(φ) u = arctan(y,x) v = sin-1(z/r) (Swap cos(φ) and sin(φ) if you define φ from the z axis rather than from the equator) arctan(y,x) = x > 0: tan-1(y/x) x<0: π + tan-1(y/x) x = 0, y > 0: π/2 x = 0, y < 0: -π/2 22(61)22(61)

(u,v) => (s,t) Normalize, typically 0 to 1 Example: Cylinder x = Rcos(u) y = Rsin(u) u = arctan(y,x) v = z s = (u + π/2) / 2π t = (v - z min ) / (z max - z min ) 23(61)23(61)

Watch the edges Example: six-sided barrel s = 1/2 s = 1/3 s = 2/3 s = 1/6 s = 0 s = 5/6 x = Rcos(u) y = Rsin(u) u = arctan(y,x) v = z s = (u + π/2) / 2π t = (v - z min ) / (z max - z min ) 24(61)24(61)

Problem is detected by checking proximity to the edge Unlikely (impossible) Good Duplicate vertices to solve 25(61)25(61)

Multitexturing The GPU has several texture units. Each texture unit can have one texture attached to it, available to the shader. glactivetexture() selects a texture unit to work on. Then glbindtexture can bind a texture to that unit. You can use several texture units in the same fragment shader Just use multiple "sampler" variables. 26(61)26(61)

Multitexturing Applications: Bump mapping Gloss mapping Light mapping Blending between textures (e.g. mountains) Putting non-texture data in textures Any case where you need more data than a single texture 27(61)27(61)

Multitexturing in GLSL Bind one texture per texturing unit Pass GLSL unit number and name Declare as samplers in GLSL 28(61)28(61)

Bind textures Pass unit numbers Declare as samplers Multitexturing in GLSL glactivetexture(gl_texture0); glbindtexture(flowertex); glactivetexture(gl_texture1); glbindtexture(bumptex); gluseprogramobject(shader); GLint loc = glgetuniformlocation(shader, "flowertex"); gluniform1i(loc, 0); // texture unit 0 loc = glgetuniformlocation(shader, "bumptex"); gluniform1i(loc, 1); // texture unit 1 loc = glgetuniformlocation(shader, "noisetex"); uniform sampler2d flowertex; uniform sampler2d bumptex; 29(61)29(61)

Example: Multitexturing Simple example: blend depending on model coordinate uniform sampler2d worldtex; uniform sampler2d flowertex; in vec4 pixelpos; in vec2 texcoord; out vec4 outcolor; void main() { outcolor = sin(pixelpos.z*10.0) * texture(flowertex, texcoord.st) + (1.0 - sin(pixelpos.z*10.0)) * texture(worldtex, texcoord.st); } 30(61)30(61)

Example: Multitexturing 31(61)31(61)

Example: Multitexturing (Lighting omitted, calculates light from two light sources, spec/spec2) uniform sampler2d world; uniform sampler2d flower; out vec4 outcolor;... float tot = diffusestrength*0.2 + specularstrength*0.9; tot = max(0.0, tot); outcolor = vec4(1.0 - tot) * world*0.7 + vec4(tot)* flower; 32(61)32(61)

Example: Multitexturing Switches texture depending on light 33(61)33(61)

Texture mapping conclusions Texture coordinates (s, t) Texture objects and texture units Filtering and mip-mapping Texture coordinate generation Multi-texturing 34(61)34(61)

Skyboxes A backdrop that makes your virtual world look bigger than it is. Skybox Skydome 35(61)35(61)

Skybox, example 36(61)36(61)

Skyboxes Infinite distance = the camera should always be in the center => Always draw the skybox centered on the camera 37(61)37(61)

Skybox implementation Must be at infinite distance Must follow camera Must rotate with world How big should it be? 38(61)38(61)

The skybox does not have to be big "Maximum size" will waste frustum space Draw any size between "near" and "far" planes Draw with Z buffer turned off gldisable(gl_depth_test); Draw glenable(gl_depth_test); Then anything else will be drawn on top 39(61)39(61)

Follow and rotate Use the world-to-view matrix for the rest of the scene, but keep only rotations 40(61)40(61)

More on skyboxes No light If you put light on a skybox, it will look like a box Clamp to edge Repeating textures will cause visible errors at edges (Why?) 41(61)41(61)

Environment mapping Reflects an environment texture in the surface Mimicks mirroring reflections In OpenGL: Spherical environment mapping (old) Cube map environment mapping 42(61)42(61)

t s point in (s, t) Bounding shape, environment (cube, sphere etc) Shape with environment mapping prp Reflected ray direction is converted to texture coordinates Simplification: Only direction, not reflection point, is used 43(61)43(61)

Sphere environment mapping First hardware supported method. Simple and straightforward. Requires view dependent distorsion of the texture. 44(61)44(61)

Better method: Cube environment mapping 45(61)45(61)

Cube environment mapping Hardware support on modern hardware Six separate textures is one cube map glteximage2d(gl_texture_cube_map_positive_x, 0, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, minitex1); glteximage2d(gl_texture_cube_map_negative_x, 0, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, minitex2); glteximage2d(gl_texture_cube_map_positive_y, 0, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, minitex3); glteximage2d(gl_texture_cube_map_negative_y, 0, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, minitex4); glteximage2d(gl_texture_cube_map_positive_z, 0, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, minitex5); glteximage2d(gl_texture_cube_map_negative_z, 0, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, minitex6); 46(61)46(61)

Cube map lookup Done with direction vector A direction......is converted to a position in the cube 47(61)47(61)

Environment mapping with cube maps Mirror view direction in surface to get direction vector Vector for cube map lookup View direction Normal vector Can be done in vertex shader -> fast 48(61)48(61)

Environment mapping shaders Vertex shader: Transform tricks in vec3 inposition; in vec3 innormal; out vec3 reflectedview; uniform mat4 projmatrix; uniform mat4 worldtoview; uniform mat4 modeltoworld; void main(void) { mat3 normalmatrix1 = mat3(worldtoview * modeltoworld); gl_position = projmatrix * worldtoview * modeltoworld * vec4(inposition, 1.0); vec3 posinviewcoord = vec3(worldtoview * modeltoworld * vec4(inposition, 1.0)); vec3 viewdirectioninviewcoord = normalize(posinviewcoord); vec3 viewdirectioninworldcoord = inverse(mat3(worldtoview)) * viewdirectioninviewcoord; vec3 wcnormal = mat3(modeltoworld) * innormal; reflectedview = reflect(viewdirectioninworldcoord, normalize(wcnormal)); } Trivial fragment shader #version 150 out vec4 outcolor; uniform samplercube cubemap; in vec3 reflectedview; void main(void) { // Cubemap texture only: outcolor = texture(cubemap, normalize(reflectedview)); } Lookup in skybox coordinates = world coordinates 49(61)49(61)

Combine skybox with environment map Immersive and cheap 50(61)50(61)

Advanced environment mapping Recursive environment mapping Fake ray-tracing Advanced multi-pass method Render the scene from the object Use the result as texture Result: Possible to see reflections of moving objects. Much higher performance cost 51(61)51(61)

Gloss mapping Map material parameters over a surface for varied reflectivity 52(61)52(61)