CSCI E-74. Simulation and Gaming

Similar documents
CSCI E-74. Simulation and Gaming

CSCI E-74. Simulation and Gaming

CSCI E-74. Simulation and Gaming

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Assignment #6 2D Vector Field Visualization Arrow Plot and LIC

Precept 2 Aleksey Boyko February 18, 2011

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

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

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

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Introduction to OpenGL

CSC 240 Computer Graphics. Fall 2015 Smith College

Shading. Flat shading Gouraud shading Phong shading

Announcements. Written Assignment 2 is out see the web page. Computer Graphics

Visualizing Molecular Dynamics

VGP352 Week March-2008

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Texture and other Mappings

Scene Graphs. CS4620/5620: Lecture 7. Announcements. HW 1 out. PA 1 will be out on Wed

Graphics Pipeline & APIs

OpenGL. White Square Code 11/4/09. OpenGL. OpenGL. OpenGL

Graphics Pipeline & APIs

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

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

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

Chapter 3: Modeling Transformation

Models and Architectures

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

Module 13C: Using The 3D Graphics APIs OpenGL ES

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

Graphics Programming

Computer Graphics. Chapter 10 Three-Dimensional Viewing

3D Graphics and OpenGl. First Steps

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Computer graphics MN1

Scientific Visualization Basics

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

3D computer graphics: geometric modeling of objects in the computer and rendering them

Sign up for crits! Announcments

ES E 3 3 L a L b 3 OpenGLES

GPU Programming EE Practice Midterm Examination

OpenGL. Toolkits.

CS 130 Final. Fall 2015

CT5510: Computer Graphics. Texture Mapping

OpenGL: Setup 3D World

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Computer graphics Labs: OpenGL (1/3) Geometric transformations and projections

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

2.11 Particle Systems

Graphical Objects and Scene Graphs

Lecture 4. Viewing, Projection and Viewport Transformations

Graphics Hardware. Instructor Stephen J. Guy

Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

CSC 470 Computer Graphics

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

IntMu.Lab5. Download all the files available from

Lecture 4 Advanced Computer Graphics (CS & SE )

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

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

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

CS 354R: Computer Game Technology

Textures. Texture coordinates. Introduce one more component to geometry

Lectures OpenGL Introduction

1.2 Basic Graphics Programming

CS 4620 Program 3: Pipeline

Graphics Hardware and OpenGL

5.2 Shading in OpenGL

CS451Real-time Rendering Pipeline

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Introduction to Computer Graphics with WebGL

Cheating: In case of cheating, all parts involved (source(s) and receiver(s)) get zero.

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

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

SE313: Computer Graphics and Visual Programming. Computer Graphics Notes Gazihan Alankus, Fall 2011

Shading/Texturing. Dr. Scott Schaefer

Graphics for VEs. Ruth Aylett

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

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

OpenGL Transformations

Transformation Pipeline

Virtual Environments

Computer Graphics I Lecture 11

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Texture Mapping. Mike Bailey.

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Hierarchical Modeling and scene graphs

Shading in OpenGL. Outline. Defining and Maintaining Normals. Normalization. Enabling Lighting and Lights. Outline

E.Order of Operations

Advanced Computer Graphics (CS & SE )

Introduction to Shaders.

Computational Strategies

Graphics and Visualization

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

Performance OpenGL Programming (for whatever reason)

CS 432 Interactive Computer Graphics

Rasterization Overview

Transcription:

CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming Fall term 2017 Gianluca De Novi, PhD Lesson 7 Multi Texturing

Data Structures in a 3D Engine Vertices/Vectors Segments Matrices Polygons Surfaces Materials Objects (Generic) Super categories of Objects Lights Camera Motion Data Lattices Skeletons Textures Particles CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 2

Data Structure TEngineVR TScene TObject TSurface TPolygon TVertex TObject TSurface TPolygon TVertex TObject TSurface TPolygon TVertex TMaterial TTexture TMaterial TTexture TMaterial TTexture Cameras Motion Data Lights CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 3

Data Hierarchy TObject TextureList TextureListLen TSurface VertexList NormalList TexCoords TMaterial Specular Diffuse Ambient Emissive Shininess Smoothing Doublesided Wireframe Visible TextureLevelList TextureOps TextureIDListLen TTexture Image Data [r,g,b,a] ID Name Width Height Interpolation CromaKey KeyColor CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 4

Texture Drawing Workflow V1(x,y,z) T1(u,v) 0,0 1,0 u V0(x,y,z) T0(u,v) v 0,1 1,1 V2(x,y,z) T2(u,v) Usually square with side lengths power of 2 ( 2x2, 4x4, 8x8, 16x16, 32x32, 64x64, 128x128, 256x256, 512x512, 1024x1024, etc.) CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 5

Textured Operations Avg + CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 6

Textured Levels Combination glenable(gl_texture_2d); for(j=0;j<materiallist[material].texturelevellistlen;j++) { glbindtexture(gl_texture_2d, Material.Texture); gltexenvf(gl_texture_env,gl_texture_env_mode, EnvMode); glenable(gl_blend); glblendfunc(blendsrc, BlendDst); glbegin(gl_triangles); glnormal3f(n.x, n.y, n.z); gltexcoord2f(t0.u, t0.v); glvertex3f(v0.x, v0.y, v0.z); gltexcoord2f(t1.u, t1.v); glvertex3f(v1.x, v1.y, v1.z); gltexcoord2f(t2.u, t0.v); glvertex3f(v2.x, v2.y, v2.z); glend(); gldisable(gl_blend); } gldisable(gl_texture_2d); V0(x,y,z) T0(u,v) V1(x,y,z) T1(u,v) The combination of these parameters determine the final operation and color of the texel This is not an optimized approach, there are hardware supported methods for multi texturing V2(x,y,z) T2(u,v) CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 7

Blending Operation glblendfunc(blendsrc, BlendDst); Final Color = Source Color * Source Factor + Destination Color * Destination Factor CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 8

TMaterials Class typedef struct { unsigned int TextureIndex; unsigned int EnvMode; unsigned int MappingType; unsigned int Blend; unsigned int BlendSrc; unsigned int BlendDst; unsigned int Visible; }TextureLevel; // Texture index in the object // Environment Combination mode // Mapping mode, UV or spherical mapping // Blending enable/disable // Blending Source Factor // Blending Destination Factor // Visible flag class TMaterial { float Ambient [4]; float Specular[4]; float Diffuse [4]; float Emissive[4]; float Color [4]; float Shinines; short Smoothing; short Visible; short Doublesided; short Wireframe; short Visible; TextureLevel TextureLevelList[ ]; unsigned int TextureLevelListLen; void LoadDefaultMaterial(); void LoadMaterial(); int AddTextureLevel(unsigned int TexID, unsigned int Operation); void RemoveTextureLevel(unsigned int Level); }; CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 9

Texture Coordinates UV Can different texture level use different UV coordinate sets? Yes it is possible to use different UV sets The majority of the 3D engines use only one set UV and the other are dynamically generated like spherical or cube mapping. CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 10

Method 5: Cube Mapping It represents an improved version of the reflection spherical mapping The cube map can be updated in real-time CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 11

Examples of Materials with Multi-texturing It represents an improved version of the reflection spherical mapping Mapping Type : UV Blend : OFF Blend Src:-- Blend Dst:-- Mapping Type : Spherical Blend : ON Blend Src: SRC COLOR Blend Dst: 1-SRC COLOR Gloss Gray Plastic CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 12

Examples of Materials with Multi-texturing It represents an improved version of the reflection spherical mapping Mapping Type : UV Blend : OFF Blend Src:-- Blend Dst:-- Mapping Type : Spherical Blend : ON Blend Src: SRC COLOR Blend Dst: DST COLOR Chrome CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 13

Examples of Materials with Multi-texturing It represents an improved version of the reflection spherical mapping Mapping Type : UV Blend : OFF Blend Src:-- Blend Dst:-- Mapping Type : Spherical Blend : ON Blend Src: SRC COLOR Blend Dst: DST COLOR Mapping Type : UV Blend : ON Blend Src: SRC COLOR Blend Dst: 1-SRC ALPHA Rusted Chrome CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 14

Examples of Materials with Multi-texturing It represents an improved version of the reflection spherical mapping Mapping Type : UV EnvMode : Blend Blend : OFF Blend Src:-- Blend Dst:-- Mapping Type : Spherical EnvMode : Blend Blend : ON Blend Src: SRC COLOR Blend Dst: DST COLOR Mapping Type : UV Blend : ON Blend Src: SRC ALPHA Blend Dst: 1-SRC ALPHA Oxidized Copper CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 15

Examples of Materials with Multi-texturing It represents an improved version of the reflection spherical mapping Mapping Type : UV Blend : OFF Blend Src:-- Blend Dst:-- Mapping Type : Spherical Blend : ON Blend Src: SRC COLOR Blend Dst: 1-SRC COLOR Mapping Type : UV Blend : ON Blend Src: SRC COLOR Blend Dst: 1-SRC COLOR Wood CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 16

Background Texture In some scenes it might be nice to have a background image, how is it done? Draw a polygon of the size of the viewport Use a texture Disable the Depth Test CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 17

Background Texture glmatrixmode(gl_projection); glpushmatrix(); glloadidentity(); glortho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glmatrixmode(gl_modelview); glpushmatrix(); glloadidentity(); gldisable(gl_lighting); gldisable(gl_depth_test); gldisable(gl_color_material); glenable(gl_texture_2d); glbindtexture(gl_texture_2d,backgroundtexture); gltexenvi(gl_texture_env,gl_texture_env_mode,gl_replace); glbegin(gl_quads); gltexcoord2f(0,0); glvertex2f(0,0); gltexcoord2f(1,0); glvertex2f(1,0); gltexcoord2f(1,1); glvertex2f(1,1); gltexcoord2f(0,1); glvertex2f(0,1); glend(); gldisable(gl_texture_2d); glmatrixmode(gl_projection); glpopmatrix(); glmatrixmode(gl_modelview); glpopmatrix(); Save and re-initialize the Projection Matrix Set and orthographic matrix for the clipping planes Save and re-initialize the Model View Matrix Disables Lighting, Depth Test and Colors Selects a texture Use replacement settings Draws a 2D quad with the view coordinate Pops the matrices Re-enable the depth test glenable(gl_depth_test); CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 18

Scene Class class TScene { public: Tcamera Camera; TObject OList[ ]; //List of objects unsigned int OListLen; //Number of objects int Visible; //Visibility Flag }; void InitScene(); //Initialize Scene Geometry void BuildSceneMatrices();//builds the scene matrices; void Draw(); //draw scene unsigned int EnableBkgTexture; TTexture Background; void DrawBackground(); void TScene::DrawBackground() { glmatrixmode(gl_projection); glpushmatrix(); glloadidentity(); glortho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glmatrixmode(gl_modelview); glpushmatrix(); glloadidentity(); } gldisable(gl_lighting); gldisable(gl_depth_test); gldisable(gl_color_material); glenable(gl_texture_2d); glbindtexture(gl_texture_2d,background.texture); gltexenvi(gl_texture_env,gl_texture_env_mode,gl_replace); //gltexenvf(gl_texture_env,gl_texture_env_color,gl_replace) glcolor4f(1.0f,1.0f,1.0f,1.0f); glbegin(gl_quads); gltexcoord2f(0,0); glvertex2f(0,0); gltexcoord2f(1,0); glvertex2f(1,0); gltexcoord2f(1,1); glvertex2f(1,1); gltexcoord2f(0,1); glvertex2f(0,1); glend(); gldisable(gl_texture_2d); glmatrixmode(gl_projection); glpopmatrix(); glmatrixmode(gl_modelview); glpopmatrix(); glenable(gl_depth_test); For example NB: This model doesn t consider the vertex optimization CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 19

Rendering inside a Texture Is it possible to transfer the final rendering inside a texture? Move the Camera where desired Set the ViewPort with the same size of the texture Render the frame without flipping the frame buffer Copy the image inside the texture Reset the ViewPort Size to the original one It is mostly used to simulate reflective surfaces CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 20

EngineVR Class class TEngineVR { public: unsigned int ViewPortWidth; unsigned int ViewPortHeight; Tscene SCList[ ]; //Available Scenes unsigned int SCListLen; //Number of Scenes unsigned int CurrentScene; //Selected Scene void InitScene(); //Initializes selected Scene void RenderScene();//draw scene void EngineVR::RenderToTexture(TTexture * t) { if(t && t->texture) { glviewport(0,0,t->width,t->height); ClearBuffers(); RenderScene(); glbindtexture(gl_texture_2d,t->texture); glcopytexsubimage2d(gl_texture_2d,0,0,0,0,0,t->width,t->height); glviewport(0,0,viewportwidth,viewportheight); } } }; void RenderToTexture(TTexture * t); For example NB: This model doesn t consider the vertex optimization CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 21