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

Similar documents
Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

Texture mapping. Computer Graphics CSE 167 Lecture 9

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

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

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

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

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

Texturing Theory. Overview. All it takes is for the rendered image to look right. -Jim Blinn 11/10/2018

INF3320 Computer Graphics and Discrete Geometry

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

Computer Graphics. Lecture 8 Antialiasing, Texture Mapping

INF3320 Computer Graphics and Discrete Geometry

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

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

Sampling, Aliasing, & Mipmaps

Sampling, Aliasing, & Mipmaps

CS 450: COMPUTER GRAPHICS TEXTURE MAPPING SPRING 2015 DR. MICHAEL J. REALE

3D Rasterization II COS 426

Computergrafik. Matthias Zwicker. Herbst 2010

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

CS 354R: Computer Game Technology

CT5510: Computer Graphics. Texture Mapping

Sampling, Aliasing, & Mipmaps

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

CS 130 Final. Fall 2015

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

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

Programming Graphics Hardware

Computer Graphics. Texture Filtering & Sampling Theory. Hendrik Lensch. Computer Graphics WS07/08 Texturing

CS 428: Fall Introduction to. Texture mapping and filtering. Andrew Nealen, Rutgers, /18/2010 1

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

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

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

Textures. Texture coordinates. Introduce one more component to geometry

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

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

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Texture Mapping 1/34

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

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

Texture Mapping and Sampling

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

TEXTURE MAPPING. DVA338 Computer Graphics Thomas Larsson, Afshin Ameri

Texture Mapping II. Light maps Environment Maps Projective Textures Bump Maps Displacement Maps Solid Textures Mipmaps Shadows 1. 7.

Perspective Projection and Texture Mapping

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

Lecture 07: Buffers and Textures

Texture Mapping 1/34

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

Evolution of GPUs Chris Seitz

CS179: GPU Programming

Texture Mapping. Mike Bailey.

CS 432 Interactive Computer Graphics

Mattan Erez. The University of Texas at Austin

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

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

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

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

Texture and other Mappings

+ = To Do. Texture Mapping. Adding Visual Detail. Parameterization. Option: Varieties of projections. Computer Graphics. geometry

CS 464 Review. Review of Computer Graphics for Final Exam

The Rasterization Pipeline

+ = To Do. Adding Visual Detail. Texture Mapping. Parameterization. Option: Varieties of projections. Foundations of Computer Graphics (Fall 2012)

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Computer Graphics Texture Mapping

CS 431/636 Advanced Rendering Techniques

Lighting and Texturing

Introduction to Computer Graphics with WebGL

Shaders. Slide credit to Prof. Zwicker

Computer Graphics. - Texturing Methods -

Texture Mapping. Michael Kazhdan ( /467) HB Ch. 14.8,14.9 FvDFH Ch. 16.3, , 16.6

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

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

CHAPTER 1 Graphics Systems and Models 3

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

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

CPSC / Texture Mapping

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

CS212. OpenGL Texture Mapping and Related

Lecture 6: Texture. Kayvon Fatahalian CMU : Graphics and Imaging Architectures (Fall 2011)

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Lab 9 - Metal and Glass

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

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

The Rasterizer Stage. Texturing, Lighting, Testing and Blending

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

Today. Anti-aliasing Surface Parametrization Soft Shadows Global Illumination. Exercise 2. Path Tracing Radiosity

Texture Mapping and Special Effects

Texture-Mapping Tricks. How Bad Does it Look? We've Seen this Sort of Thing Before. Sampling Texture Maps

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

Topics and things to know about them:


CS 4620 Program 3: Pipeline

x ~ Hemispheric Lighting

Fast Third-Order Texture Filtering

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

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

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

Transcription:

Computergrafik Today Basic shader for texture mapping Texture coordinate assignment Antialiasing Fancy textures Matthias Zwicker Universität Bern Herbst 2009 Texture mapping Glue textures (images) onto surfaces Same triangles, much more interesting and detailed appearance Think of colors as reflectance coefficients Texture mapping in OpenGL Slightly archaic API, load texture using glpixelstorei glgentextures glbindtexture glteximage2d etc Look up details when you need them Learn from example code Reference: http://www.glprogramming.com/red/ Basic shaders for texturing // Need to initialize texture using OpenGL API calls, which will be // implemented in Texture.java. // Vertex shader void main() // assign vertex attribute for texture coordinates to // predefined varying variable gl_texcoord[0] = gl_multitexcoord0; gl_position = ftransform(); f } Today Basic shader for texture mapping Texture coordinate assignment Texture filtering Fancy textures // Fragment shader uniform sampler2d tex; void main() { // the variable tex is automatically initialized // to access the texture gl_fragcolor = texture2d(tex, gl_texcoord[0].st); } 1

Texture coordinate assignment Surface parameterization Mapping between 3D positions on surface and 2D texture coordinates In practice, defined by texture coordinates of triangle vertices Various options to establish a parameterization Parametric mapping Surface given by parametric functions Very common in CAD Use(u,v) parameters as texture coordinates Later in class: Bézier surfaces Orthographic mapping Use linear transformation of object s xyz coordinates For example Projective mapping Use perspective projection of xyz coordinates OpenGL provides GL_TEXTURE matrix to apply perspective projection on texture coordinates Useful to achieve fake lighting g effects Spherical mapping Use, e.g., spherical coordinates for sphere Place object in sphere shrink-wrap sphere to object Shoot ray from center of sphere through each vertex Spherical coordinates of the ray are texture coordinates for vertex Cylindrical mapping Similar as spherical mapping, but with cylilnder Useful for faces 2

Skin mapping Techniques to unfold surface onto plane Minimize distortions Preserve area, angle Sophisticated math Functionality usually provided by 3D modeling tools (Maya, Blender, etc.) Today Basic shader for texture mapping Texture coordinate assignment Antialiasing Fancy textures What is going on here? Aliasing Sufficiently sampled, no aliasing Insufficiently sampled, aliasing High frequencies in the input appear as low frequencies in the sampled signal Antialiasing: intuition Pixel may cover large area on triangle in camera space Antialiasing: intuition Pixel may cover large area on triangle in camera space Corresponds to many texels in texture space Should compute average of texels over pixel area Texels Texels Pixel area Pixel area 3

Antialiasing: the math Pixels are samples, not little squares ftp://ftp.alvyray.com/acrobat/6_pixel.pdf Use frequency analysis to explain sampling artifacts Fourier transforms Antialiasing is achieved through low-pass filtering If you are interested http://www.cs.cmu.edu/~ph/texfund/texfund.pdf Glassner, Principles of digital image synthesis Antialiasing Can be achieved by averaging texels over pixel area Problems, disadvantages? Pixel area Texels Antialiasing using mipmaps Averaging over texels is expensive Many texels as objects get smaller Large memory access and computation cost Precompute averaged (filtered) textures Mipmaps MIP stands for multum in parvo (Williams 1983) Practical solution to aliasing problem Fast and simple Available in OpenGL, implemented in GPUs Reasonable quality Mipmaps Before rendering Precompute and store filtered versions of textures (mipmaps) Use high quality filtering (averaging) scheme Computing mipmaps Convolution Mipmaps Input function f, convolution kernel g Continuous formulation Discrete formulation Level 0 Level 1 Level 2 Two-dimensional convolution is a straightforward extension Level 3 Level 4 4

Mipmaps Filtered textures are blurry Reduce resolution by factor 2 successively without losing information Increases memory cost by 1/3 1/3 = ¼+1/16+1/64+ Width, height of texture needs to be power of two Mipmaps Resolutions 512x512, 256x256, 128x128, 64x64, 32x32 Level 1 Level 0 2 3 4 multum in parvo Mipmaps 1 texel in level 4 is an average of 4 4 =256 texels in level 0 Level 0 Level 1 2 3 4 multum in parvo Rendering with mipmaps Interpolate texture coordinate of each pixel as before Compute approximate size of pixel in texture space Look-up color in nearest mipmap E.g., if pixel corresponds to 10x10 texels use mip-map level 3 Use nearest neighbor or bilinear interpolation as before Mipmapping Size of a pixel in texture space Given by partial derivatives of mapping Texels Pixel area Mip-map level 0 Mip-map level 1 Mip-map level 2 Mip-map level 3 5

Nearest mipmap, nearest neighbor Visible transition between mipmap levels Nearest mipmap, bilinear Visible transition between mipmap levels Trilinear mipmapping Use two nearest mipmap levels Trilinear mipmapping Smooth transition between mipmap levels E.g., if pixel corresponds to 10x10 texels, use mipmap level 3 and 4 Perform bilinear interpolation in both mip- maps Linearly blend between the results Requires access to 8 texels for each pixel Standard method, supported by hardware with no performance penalty Note on OpenGL Distinguishes between minification and magnification Are we satisfied? Minification: a texel is smaller than a pixel Magnification: a texel is larger than a pixel Minification, magnification may vary across pixels of individual triangles OpenGL allows you to specify different interpolation techniques separately gltexparameteri Trilinear mipmapping 6

Mipmapping limitations Mipmap texels always represent square areas Pixel area is not always square in texture space Mipmapping makes trade-off between aliasing and blurriness Anisotropic texture filtering Average texture over elliptical area Higher quality than trilinear mip-mapping More expensive Anisotropic filtering in hardware Take several bilinear probes approximating the ellipse Reduces rendering performance on current GPUs Bilinear probe A circular pixel is back-projected to an ellipse Ellipse of backprojected pixel Comparison Animation Today Basic shader for texture mapping Texture coordinate assignment Texture filtering Fancy textures Fancy textures Textures most commonly used to modulate ambient and diffuse reflection E.g., diffuse shader with texture varying vec3 normal, lightdir; uniform sampler2d tex; void main() { gl_fragcolor = gl_lightsource[0].diffuse * max(dot(normal, normalize(lightdir)),0.0) * texture2d(tex, gl_texcoord[0].st); } void main() Bump mapping Texture map contains normal perturbations No modification of geometry Visible mostly at silhouettes Render using per-pixel shading, fragment shader Normal in each pixel is modified using texture map (later in course) Other applications? 7

Displacement mapping Texture map contains local height field Modifies geometry Correct silhouettes, shadows Requires complicated fragment shader Other effects Multi-texturing Several layers of textures for different effects Scratches, dents, rust, Illumination textures Animated textures Raindrops A TV screen, projector in a 3D scene Multi-texturing Next time Scene graphs and hierarchies 8