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

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Recall: Indexing into Cube Map

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

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

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

CS 432 Interactive Computer Graphics

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

Introduction to Computer Graphics with WebGL

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

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

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

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

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CS 432 Interactive Computer Graphics

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

Shaders. Slide credit to Prof. Zwicker

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

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

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

CT5510: Computer Graphics. Texture Mapping

Introduction to Computer Graphics with WebGL

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

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

Computergraphics Exercise 15/ Shading & Texturing

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

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Discrete Techniques. 11 th Week, Define a buffer by its spatial resolution (n m) and its depth (or precision) k, the number of

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

CS179: GPU Programming

CS475/CS675 - Computer Graphics. OpenGL Drawing

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

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

Lecture 07: Buffers and Textures

CS212. OpenGL Texture Mapping and Related

INF3320 Computer Graphics and Discrete Geometry

Discussion 3. PPM loading Texture rendering in OpenGL

The Graphics Pipeline

Computer Graphics (CS 4731) Lecture 18: Lighting, Shading and Materials (Part 3)

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

Texture Mapping. Mike Bailey.

Computer Graphics (CS 563) Lecture 4: Advanced Computer Graphics Image Based Effects: Part 2. Prof Emmanuel Agu

Computer Graphics (CS 4731) & 2D Graphics Systems

Buffers, Textures, Compositing, and Blending. Overview. Buffers. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E.

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

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

CS 5600 Spring

The Graphics Pipeline

Texture and other Mappings

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

Lighting and Texturing

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2)

Surface Rendering. Surface Rendering

Shading. Flat shading Gouraud shading Phong shading

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

CPSC 436D Video Game Programming

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

We assume that you are familiar with the following:

Tutorial 12: Real-Time Lighting B

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

CSE528 Computer Graphics: Theory, Algorithms, and Applications

INF3320 Computer Graphics and Discrete Geometry

Tutorial 3: Texture Mapping

Computer Graphics (CS 543) Lecture 1 (Part 1): Introduction to Computer Graphics

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

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

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

Stored Texture Shaders

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

CS 130 Final. Fall 2015

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

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

Geometry Shaders. And how to use them

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

Lab 9 - Metal and Glass

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

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

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

Mobile Application Programing: Android. OpenGL Operation

The Rasterization Pipeline

2D graphics with WebGL

Texture Mapping and Sampling

COMP371 COMPUTER GRAPHICS

Overview. By end of the week:

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

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

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

INFOGR Computer Graphics

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

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

Transcription:

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

Fog Fog was part of OpenGL fixed function pipeline Programming fixed function fog Parameters: Choose fog color, fog model Enable: Turn it on Fixed function fog deprecated!! Shaders can implement even better fog Shaders implementation: fog applied in fragment shader just before display

Rendering Fog Mix some color of fog: + color of surface: c f cs c p fc f ( 1 f ) c f [0,1] s If f = 0.25, output color = 25% fog + 75% surface color How to compute f? 3 ways: linear, exponential, exponential-squared Linear: f z z end end z z p start z P z start z End

Fog Shader Fragment Shader Example float dist = abs(position.z); Float fogfactor = (Fog.maxDist dist)/ f Fog.maxDist Fog.minDist); fogfactor = clamp(fogfactor, 0.0, 1.0); z z end end z z p start vec3 shadecolor = ambient + diffuse + specular vec3 color = mix(fog.color, shadecolor,fogfactor); FragColor = vec4(color, 1.0); c p fc f ( 1 f ) cs

Fog Exponential Squared exponential f d f z p Exponential derived from Beer s law e e ( d f z p Beer s law: intensity of outgoing light diminishes exponentially with distance f 2 )

Fog f values for different depths ( z P )can be pre computed and stored in a table on GPU Distances used in f calculations are planar Can also use Euclidean distance from viewer or radial distance to create radial fog

Computer Graphics (4731) Lecture 20: Texturing Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

The Limits of Geometric Modeling Although graphics cards can render over 10 million polygons per second Many phenomena even more detailed Clouds Grass Terrain Skin Computationally inexpensive way to add details 8 Image complexity does not affect the complexity of geometry processing (transformation, clipping )

Textures in Games Everthing is a texture except foreground characters that require interaction Even details on foreground texture (e.g. clothes) is texture

Types of Texturing 1. geometric model 2. texture mapped Paste image (marble) onto polygon

Types of Texturing 3. Bump mapping Simulate surface roughness (dimples) 4. Environment mapping Picture of sky/environment over object

Texture Mapping 1. Define texture position on geometry 2. projection 4. patch texel 3D geometry 3. texture lookup t 2D projection of 3D geometry 2D image S

Texture Representation Bitmap (pixel map) textures: images (jpg, bmp, etc) loaded Procedural textures: E.g. fractal picture generated in.cpp file Textures applied in shaders t (1,1) Bitmap texture: 2D image - 2D array texture[height][width] Each element (or texel ) has coordinate (s, t) s and t normalized to [0,1] range Any (s,t) => [red, green, blue] color s (0,0)

Texture Mapping Map? Each (x,y,z) point on object, has corresponding (s, t) point in texture s = s(x,y,z) t = t(x,y,z) (x,y,z) t texture coordinates s world coordinates

6Main Steps to Apply Texture 1. Create texture object 2. Specify the texture Read or generate image assign to texture (hardware) unit enable texturing (turn on) 3. Assign texture (corners) to Object corners 4. Specify texture parameters wrapping, filtering 5. Pass textures to shaders 6. Apply textures in shaders

Step 1: Create Texture Object OpenGL has texture objects (multiple objects possible) 1 object stores 1 texture image + texture parameters First set up texture object GLuint mytex[1]; glgentextures(1, mytex); // Get texture identifier glbindtexture(gl_texture_2d, mytex[0]); // Form new texture object Subsequent texture functions use this object Another call to glbindtexture with new name starts new texture object

Step 2: Specifying a Texture Image Define input picture to paste onto geometry Define texture image as array of texels in CPU memory Glubyte my_texels[512][512][3]; Read in scanned images (jpeg, png, bmp, etc files) If uncompressed (e.g bitmap): read into array from disk If compressed (e.g. jpeg), use third party libraries (e.g. Qt, devil) to uncompress + load bmp, jpeg, png, etc

Step 2: Specifying a Texture Image Procedural texture: generate pattern in application code Enable texture mapping glenable(gl_texture_2d) OpenGL supports 1 4 dimensional texture maps

Specify Image as a Texture Tell OpenGL: this image is a texture!! glteximage2d( target, level, components, w, h, border, format, type, texels ); target: type of texture, e.g. GL_TEXTURE_2D level: used for mipmapping (0: highest resolution. More later) components: elements per texel w, h: width and height of texels in pixels border: used for smoothing (discussed later) format,type: describe texels texels: pointer to texel array Example: glteximage2d(gl_texture_2d, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels);

Fix texture size OpenGL textures must be power of 2 If texture dimensions not power of 2, either 1) Pad zeros 2) Scale the Image 60 100 128 Remember to adjust target polygon corners don t want black texels in your final picture 64

6Main Steps. Where are we? 1. Create texture object 2. Specify the texture Read or generate image assign to texture (hardware) unit enable texturing (turn on) 3. Assign texture (corners) to Object corners 4. Specify texture parameters wrapping, filtering 5. Pass textures to shaders 6. Apply textures in shaders

Step 3: Assign Object Corners to Texture Corners Each object corner (x,y,z) => image corner (s, t) E.g. object (200,348,100) => (1,1) in image Programmer esablishes this mapping Target polygon can be any size/shape (200,348,100) (1,0) (1,1) t (0,0,0) (0,0) s (1,0)

Step 3: Assigning Texture Coordinates After specifying corners, interior (s,t) ranges also mapped Example? Corners mapped below, abc subrange also mapped t 0, 1 Texture Space a 1, 1 Object Space (s, t) = (0.2, 0.8) A b 0, 0 1, 0 c s (0.4, 0.2) B C (0.8, 0.4)

Step 3: Code for Assigning Texture Coordinates Example: Trying to map a picture to a quad For each quad corner (vertex), specify Specify vertex (x,y,z), Specify corresponding corner of texture (s, t) May generate array of vertices + array of texture coordinates points[i] = point3(2,4,6); tex_coord[i] = point2(0.0, 1.0); points array tex_coord array x y z x y z x y z s t s t s t Position 1 A Position 2 B Position 3 Tex0 Tex1 C a b Tex3 c

Step 3: Code for Assigning Texture Coordinates void quad( int a, int b, int c, int d ) { quad_colors[index] = colors[a]; // specify vertex color points[index] = vertices[a]; // specify vertex position tex_coords[index] = vec2( 0.0, 0.0 ); //specify corresponding texture corner index++; quad_colors[index] = colors[b]; points[index] = vertices[b]; tex_coords[index] = vec2( 0.0, 1.0 ); Index++; colors array r g b r g b r g b // other vertices } points array Color 1 Colors 2 Colors 3 a b c tex_coord array x y z x y z x y z s t s t s t Position 1 a Position 2 b Position 3 Tex0 Tex1 c a b Tex2 c

Step 5: Passing Texture to Shader Pass vertex, texture coordinate data as vertex array Set texture unit Variable names in shader offset = 0; GLuint vposition = glgetattriblocation( program, "vposition" ); glenablevertexattribarray( vposition ); glvertexattribpointer( vposition, 4, GL_FLOAT, GL_FALSE, 0,BUFFER_OFFSET(offset) ); offset += sizeof(points); GLuint vtexcoord = glgetattriblocation( program, "vtexcoord" ); glenablevertexattribarray( vtexcoord ); glvertexattribpointer( vtexcoord, 2,GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(offset) ); // Set the value of the fragment shader texture sampler variable // ("texture") to the the appropriate texture unit. gluniform1i( glgetuniformlocation(program, "texture"), 0 );

Step 6: Apply Texture in Shader (Vertex Shader) Vertex shader receives data, output texture coordinates to fragment shader in vec4 vposition; //vertex position in object coordinates in vec4 vcolor; //vertex color from application in vec2 vtexcoord; //texture coordinate from application out vec4 color; //output color to be interpolated out vec2 texcoord; //output tex coordinate to be interpolated texcoord = vtexcoord color = vcolor gl_position = modelview * projection * vposition

Step 6: Apply Texture in Shader (Fragment Shader) Textures applied in fragment shader Samplers return a texture color from a texture object in vec4 color; //color from rasterizer in vec2 texcoord; //texure coordinate from rasterizer uniform sampler2d texture; //texture object from application void main() { gl_fragcolor = color * texture2d( texture, texcoord ); } Output color Of fragment Original color of object Lookup color of texcoord (s,t) in texture

Map textures to surfaces Texture mapping is performed in rasterization (0,1) (1,1) For each pixel, its texture coordinates (s, t) interpolated based corners texture coordinates (why not just interpolate the color?) (0,0) (1,0) The interpolated texture (s,t) coordinates are then used to perform texture lookup

Texture Mapping and the OpenGL Pipeline Images and geometry flow through separate pipelines that join during fragment processing Object geometry: geometry pipeline Image: pixel pipeline complex textures do not affect geometric complexity vertices geometry pipeline image pixel pipeline Fragment processor

6Main Steps to Apply Texture 1. Create texture object 2. Specify the texture Read or generate image assign to texture (hardware) unit enable texturing (turn on) 3. Assign texture (corners) to Object corners 4. Specify texture parameters wrapping, filtering 5. Pass textures to shaders 6. Apply textures in shaders still haven t talked about setting texture parameters

References Interactive Computer Graphics (6 th edition), Angel and Shreiner Computer Graphics using OpenGL (3 rd edition), Hill and Kelley