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

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

CS 432 Interactive Computer Graphics

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

Discussion 3. PPM loading Texture rendering in OpenGL

INSTANCE VARIABLES (1/2) P. 1

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

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

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

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

Geometry Shaders. And how to use them

2D graphics with WebGL

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

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

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

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

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

COMP371 COMPUTER GRAPHICS

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

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

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

Overview. By end of the week:

CS 432 Interactive Computer Graphics

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

Computergraphics Exercise 15/ Shading & Texturing

Steiner- Wallner- Podaras

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

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

CS179: GPU Programming

Tutorial 3: Texture Mapping

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

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

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

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

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

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

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

OUTLINE. Tessellation in OpenGL Tessellation of Bezier Surfaces Tessellation for Terrain/Height Maps Level of Detail

Computer Graphics with OpenGL ES (J. Han) Chapter 6 Fragment shader

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

CMSC427 OpenGL and JOGL

Tutorial 12: Real-Time Lighting B

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

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

CSE 167. Discussion 03 ft. Glynn 10/16/2017

Sign up for crits! Announcments

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

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

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

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

INF3320 Computer Graphics and Discrete Geometry

CPSC 436D Video Game Programming

OPENGL AND GLSL. Computer Graphics

OPENGL RENDERING PIPELINE

CS212. OpenGL Texture Mapping and Related

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

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

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

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

Programmable Graphics Hardware

CT5510: Computer Graphics. Texture Mapping

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

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

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

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

Mobile Application Programing: Android. OpenGL Operation

12.2 Programmable Graphics Hardware

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

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

INTRODUCTION TO OPENGL PIPELINE

Lecture 9(B): GPUs & GPGPU

INF3320 Computer Graphics and Discrete Geometry

Introduction to Computer Graphics with WebGL

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

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

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

The Graphics Pipeline

CS475/CS675 - Computer Graphics. OpenGL Drawing

CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J.

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

Introduction to the OpenGL Shading Language (GLSL)

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

The Graphics Pipeline

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

OpenGL Performances and Flexibility

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL

MXwendler Fragment Shader Development Reference Version 1.0

11 - Bump Mapping. Bump-Mapped Objects. Bump-Mapped Objects. Bump-Mapped Objects. Limitations Of Texture Mapping. Bumps: Perturbed Normals

Introduction to Computer Graphics with WebGL

Dave Shreiner, ARM March 2009

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

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

Lighting and Texturing

Supplement to Lecture 22

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

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

Transcription:

TEXTURE MAPPING 1

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

BASIC STRAGEGY Three steps to applying a texture 1. specify the texture read or generate image assign to texture enable texturing 2. assign texture coordinates to vertices Proper mapping function is left to application 3. specify texture parameters wrapping, filtering 3

SPECIFY THE TEXTURE Data and mechanisms needed: A Texture object to hold the texture image Uniform sampler variable in the vertex shader so shader can access texture Buffer to hold texture coordinates Vertex attribute to pass texture coordinates through pipeline Texture unit on the graphics card

TEXTURE OBJECT The loadtexture method from the Java/JOGL example code public Texture loadtexture(string texturefilename) { Texture tex = null; try { tex = TextureIO.newTexture(new File(textureFileName), false); } catch (Exception e) { e.printstacktrace(); } return tex; }

SETTING UP THE TEXTURE AS AN OPENGL TEXTURE Instance variables: private int bricktexture; private Texture joglbricktexture; In init(): joglbricktexture = loadtexture("brick1.jpg"); bricktexture = joglbricktexture.gettextureobject();

TEXTURE COORDINATES Need to specify texture coordinates for each vertex in our object(s) Two buffers for each set of vertex coordinates Vertex coordinates in 3D space (x, y, z) Texture coordinates in 2D space (s, t) Assumption is that texture image is rectangular with 0, 0 in the lower left and 1,1 in the upper right. Coordinates should all be between 0 and 1 Texture coordinates are stored in a vertex attribute so they are also interpolated by the rasterizer Difficult to specify by hand for complex objects If built in an object modeling tool, often they provide UV-mapping for this purpose

TEXTURE MAPPING GONE WRONG We saw this mapping last time specifying coordinates incorrectly can have bad results

TEXTURE MAPPING Specifying them correctly can look realistic

TEXTURE MAPPING THE PYRAMID Vertices Texture Coordinates -1.0-1.0 1.0 0 0 front face 1.0-1.0 1.0 1 0 0.0 1.0 0.0.5 1 1.0-1.0 1.0 0 0 right face 1.0-1.0-1.0 1 0 0.0 1.0 0.0.5 1 1.0-1.0-1.0 0 0 back face -1.0-1.0-1.0 1 0 0.0 1.0 0.0.5 1

TEXTURE MAPPING THE PYRAMID CODE, SETUPVERTICES() METHOD float[] pyramid_positions = {-1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, //front 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, //right 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, //back -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, //left -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, //LF 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f //RR }; float[] texture_coordinates = {0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f };

LOADING TEXTURE COORDINATES INTO BUFFERS Instance variables: private int vao[] = new int[1]; private int vbo[] = new int[2]; In display(): gl.glbindbuffer(gl_array_buffer, vbo[0]); gl.glvertexattribpointer(0, 3, GL_FLOAT, false, 0, 0); gl.glenablevertexattribarray(0); gl.glbindbuffer(gl_array_buffer, vbo[1]); gl.glvertexattribpointer(1, 2, GL_FLOAT, false, 0, 0); gl.glenablevertexattribarray(1);

GLSL CODE Vertex shader needs coordinates Fragment shader needs access to the texture object

VERTEX SHADER #version 430 layout (location=0) in vec3 pos; layout (location=1) in vec2 texcoord; out vec2 tc; uniform mat4 mv_matrix; uniform mat4 proj_matrix; layout (binding=0) uniform sampler2d samp; void main(void) { gl_position = proj_matrix * mv_matrix * vec4(pos,1.0); tc = texcoord; }

FRAGMENT SHADER #version 430 in vec2 tc; out vec4 color; uniform mat4 mv_matrix; uniform mat4 proj_matrix; layout (binding=0) uniform sampler2d samp; void main(void) { color = texture(samp, tc); }

BACK TO JAVA/JOGL CODE After binding buffers with vertices and texture coordinates in display(): gl.glactivetexture(gl_texture0); gl.glbindtexture(gl_texture_2d, bricktexture); Recall that bricktexture is an integer that holds the pointer to the OpenGL texture object we created in init()

WHAT CAN GO WRONG Differences between texture image size and object image size Texture image resolution less than that of object Can stretch texture across image region May become blurry and possibly distorted Texture image resolution higher than that of object Aliasing caused by sampling errors Can cause false patterns or shimmering in moving objects

WHAT CAN GO WRONG False patterns Shimmering

MIPMAPPING Can often correct aliasing errors Different versions (sizes) of the image stored in the texture buffer The one closest to the size of the region is used for texturing Separate RGB versions of the image are stored at each resolution Several ways to sample a mipmap GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR

MIPMAPPING Linear filtering (GL_LINEAR_MIPMAP_NEAREST) Trilinear filtering (GL_LINEAR_MIPMAP_LINEAR)

MIPMAPPING In the Java/JOGL code, after loading the texture object: gl.glbindtexture(gl_texture_2d, bricktexture); gl.gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl.glgeneratemipmap(gl.gl_texture_2d);

FILTERING Mipmapped images can appear more blurry Anisotropic filtering uses rectangular resolutions of the image as well as the square versions in mipmapping More computationally expensive (of course) Java/JOGL code in init(): if (gl.isextensionavailable("gl_ext_texture_filter_anisotropic")) { float anisoset[] = new float[1]; gl.glgetfloatv(gl_max_texture_max_anisotropy_ext, anisoset, 0); gl.gltexparameterf(gl_texture_2d, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoset[0]); }

PERSPECTIVE CORRECTION OpenGL applies perspective correction by default Corrects for distortion caused by perspective projection If you don t want this, can turn it off by including the following in both the vertex and fragment shaders: noperspective out vec2 texcoord;

SUMMARY Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction 24