Lighting and Texturing

Similar documents
CS179: GPU Programming

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

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

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

Computergraphics Exercise 15/ Shading & Texturing

CS 432 Interactive Computer Graphics

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

Texture Mapping. Mike Bailey.

GLSL Overview: Creating a Program

Lecture 07: Buffers and Textures

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

Steiner- Wallner- Podaras

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

INF3320 Computer Graphics and Discrete Geometry

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

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

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

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

ก ก ก.

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

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

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

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

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

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

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

CS212. OpenGL Texture Mapping and Related

INF3320 Computer Graphics and Discrete Geometry

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

Discussion 3. PPM loading Texture rendering in OpenGL

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

Tutorial 3: Texture Mapping

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

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

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

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

CPSC 436D Video Game Programming

Overview. By end of the week:

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

Introduction to Computer Graphics with WebGL

Pipeline Operations. CS 4620 Lecture 14

OPENGL RENDERING PIPELINE

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

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

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

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

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

Assignment #5: Scalar Field Visualization 3D: Direct Volume Rendering

CT5510: Computer Graphics. Texture Mapping

Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or

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

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

Shaders. Slide credit to Prof. Zwicker

Introduction to the OpenGL Shading Language (GLSL)

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

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

Stored Texture Shaders

Programmable shader. Hanyang University

9.Texture Mapping. Chapter 9. Chapter Objectives

Tutorial 12: Real-Time Lighting B

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

OpenGL & Visualization

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

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

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

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

Sign up for crits! Announcments

Texture Mapping 1/34

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

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

The Rasterization Pipeline

Methodology for Lecture

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

Computer Graphics Texture Mapping

CS475/CS675 - Computer Graphics. OpenGL Drawing

Computer Graphics. Bing-Yu Chen National Taiwan University

CS 418: Interactive Computer Graphics. Basic Shading in WebGL. Eric Shaffer

Lecture 5. Scan Conversion Textures hw2

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

CS195V Week 6. Image Samplers and Atomic Operations

Geometry Shaders. And how to use them

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

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

Grafica Computazionale

Shading. Flat shading Gouraud shading Phong shading

1 of 5 9/10/ :11 PM

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

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 432 Interactive Computer Graphics

OpenCL / OpenGL Texture Interoperability: An Image Blurring Case Study

CS 432 Interactive Computer Graphics

CS 354R: Computer Game Technology

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

Texture Mapping 1/34

- Rasterization. Geometry. Scan Conversion. Rasterization

Transcription:

Lighting and Texturing Michael Tao Michael Tao Lighting and Texturing 1 / 1

Fixed Function OpenGL Lighting Need to enable lighting Need to configure lights Need to configure triangle material properties Michael Tao Lighting and Texturing 2 / 1

Enable Lighting Enable Lighting: glenable(gl_lighting) Initialize the lights to be activated Lights labeled by GL_LIGHTN for N [0...GL_MAX_LIGHTS-1] Enable light 0: glenable(gl_light0) Set Lighting parameters Individual light parameters: gllighti,gllightf (will explain later) Select flat or smooth shading: glshademodel GL_FLAT,GL_SMOOTH Smooth is Gouraud shading (interpolated values from vertex evaluations) Flat is the value chosen from one vertex Michael Tao Lighting and Texturing 3 / 1

Setting Materials Instead of setting individual colors we change the material parameter states Set normals when specifying vertices (glnormal3f(float,float,float)) Set material parameters like we set colors before (Next slide covers the parameters) Independent materials can be set on the front and back faces Michael Tao Lighting and Texturing 4 / 1

Lighting and Material Parameters Materials and Lights both need Phong-Blinn shading parameters Lighting: gllightf(glenum light, GLenum pname, float param) light: GL_LIGHT0...GL_LIGHTN Materials: glmaterialfv(glenum face, GLenum pname, float* params) face: GL_FRONT,GL_BACK,GL_FRONT_AND_BACK pname: GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_SHININESS Light doesn t have GL_SHININESS Most params are 4 values for RGBA streams Michael Tao Lighting and Texturing 5 / 1

Results? Gourad Michael Tao Lighting and Texturing 6 / 1

Quick Note on GLSL Implementing gourad vs phong shading is trivial Pass materials, light positions, etc as uniforms (or use built-in variables from fixed function pipeline) Gourad: Evaluate lighting in vertex shader and pass a color to fragment shader Fragment shader interpolates colors passed from vertex shader by default Phong: Pass normal and world-space position from vertex shader to fragment shader Fragment shader uses interpolated Flat: Do the same as Gourad except use flat out vec4 color Michael Tao Lighting and Texturing 7 / 1

Texturing... Need to create texture objects Need to configure texture behvaior Need to push texture data Need to activate textures Need to set texture coordinates to objects Michael Tao Lighting and Texturing 8 / 1

The initialization mess Create texture objects Bind a texture Configure it glenable ( GL_TEXTURE_2D ); GLuint tex [4]; glgentextures (4, tex ); glbindtexture ( GL_TEXTURE_2D, tex [0]) ; gltexparameteri ( GL_ TEXTURE_ 2D, GL_ TEXTURE_ MIN_ FILTER, GL_LINEAR ); gltexparameteri ( GL_ TEXTURE_ 2D, GL_ TEXTURE_ MAX_ FILTER, GL_NEAREST ); gltexparameteri ( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ T, GL_CLAMP_TO_EDGE ); Michael Tao Lighting and Texturing 9 / 1

void glteximage2d ( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data ); Michael Tao Lighting and Texturing 10 / 1 Set The Data target: GL_TEXTURE_2D is almost all you ll need level: just set to 0 for now, until you understand what mipmaps are internalformat: the way the data for the texture should be stored. For now GL_RGBA8 is fine or GL_ALPHA for single values. width/height is obvious border = 0. I m not sure about this myself type is the sort of data you are producing. In general GL_RGBA but if you only want to assert a single value (like depth) use GL_RED format is the pixel data format that you re submitting Generally can use GL_UNSIGNED_INT_8_8_8_8 GL_FLOAT,GL_INT,GL_UNSIGNED_INT can be used when your internal format is a scalar.

Use a Texture Activate a specific texture units Make sure texturing is enabled Set a texture active GL_TEXTUREN for N up to GL_MAX_TEXTURE_UNITS-1 Apparently you can do things with gltexenvi Makes a lot more sense in GLSL :P Bind a texture to the currently active texture Start rendering vertices glenable ( GL_TEXTURE_2D ); glactivetexture ( GL_ TEXTURE0 ); glbindtexture ( GL_TEXTURE_2D, tex ); glbegin ( GL_TRIANGLES ); gltexcoord2f (0,0) ; glvertex2f (0,0) ; gltexcoord2f (1,0) ; glvertex2f (1,0) ;... Michael Tao Lighting and Texturing 11 / 1

Quick Note on GLSL Pass texture coords through gl_multitexcoord0 and write to gl_texcoord[0] Textures are treated as uniform sampler2d objects and are sampled through texture uniform sampler2d mysampler ; int main () {... texture2d ( mysampler,st);// glsl1.2 texture ( mysampler,st);// modern glsl The active texture tells GLSL which uniform to bind to glbindprogram ( programid ); GLuint loc = glgetuniformlocation ( programid," mysampler "); gluniform1i ( loc,0) ;// switch 0 for whichever GL_ TEXTUREN value N we want Michael Tao Lighting and Texturing 12 / 1