CS 480/680 Part 1: Model Loading.

Slides:



Advertisements
Similar presentations
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Advertisements

Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
Introduction to Shader Programming
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
The programmable pipeline Lecture 10 Slide Courtesy to Dr. Suresh Venkatasubramanian.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
GEOMETRY SHADER. Breakdown  Basics  Review – graphics pipeline and shaders  What can the geometry shader do?  Working with the geometry shader  GLSL.
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
An Introduction to the OpenGL Shading Language Benj Lipchak Rob Simpson Bill Licea-Kane.
CIS 565 Fall 2011 Qing Sun
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
CS 480/680 Computer Graphics Shader Applications Dr. Frederick C Harris, Jr. Fall 2011.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Shader Basics Chap. 2 of Orange Book. 2 Contents Why write shaders OpenGL programmable processors Language overview System overview.
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shader Applications Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Shaders in OpenGL Marshall Hahn. Introduction to Shaders in OpenGL In this talk, the basics of OpenGL Shading Language will be covered. This includes.
CS418 Computer Graphics John C. Hart
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
GLSL OpenGL Programming and Reference Guides, other sources
OpenGL Shading Language (GLSL)
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
OpenGL Shading Language (GLSL)
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Mesh Skinning Sébastien Dominé. Agenda Introduction to Mesh Skinning 2 matrix skinning 4 matrix skinning with lighting Complex skinning for character.
OpenGL Shading Language
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Computer Science – Game DesignUC Santa Cruz Tile Engine.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Shaders, part 2 alexandri zavodny.
Shader.
CSE Real Time Rendering
Carl Johan Gribel, PhD student
Texture Mapping Part II
Objectives Simple Shaders Programming shaders with GLSL
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
UMBC Graphics for Games
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Shader Basics Chap. 2 of Orange Book.
ICG 2018 Fall Homework1 Guidance
Programming with OpenGL Part 3: Shaders
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
03 | Creating, Texturing and Moving Objects
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
CS 480/680 (Fall 2018) Part 2: Texture Loading
Assimp.
Introduction to Computer Graphics with WebGL
OpenGL-Rendering Pipeline
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

CS 480/680 Part 1: Model Loading

Today’s Topics What is Assimp? Installation Usage Recap Pseudocode Resources Questions

What is Assimp? Assimp (written in C++) is an Open Source library that is used by developers to import 3D models in a variety of file formats. Your model loader is only capable of loading .obj files. Assimp can handle .blend, .3ds, .obj, .lwo, .lws, .x, .cob, and more.

What is Assimp? Assimp will load all of these file formats into the same data structure which is used for further processing. Operations such as computing normal and tangent vectors are not only available, but also optimized.

Installation Install assimp3, which is compatible with Ubuntu 13.04 or higher. sudo apt-get install libassimp-dev Modifications to your makefile: In the LIBS section, you’ll want to add -lassimp.

Includes Furthermore, you’ll want to include the following in either your main.cpp file or your model loader class (recommended, develops abstraction in your code). #include <assimp/Importer.hpp> Includes the Assimp importer, which is used to read your .obj files. #include <assimp/scene.h> Includes the data structure that is used for further processing.

Includes More libraries to include: #include <assimp/postprocess.h> Includes flags for post processing (calculating tangents, normals, etc.). #include <assimp/color4.h> Includes the aiColor4 object, which is used to handle colors associated with your objects.

Usage First off, you’ll want to declare an Assimp::Importer object and use it to read in the data from your .obj file, like so: Assimp::Importer importer; const aiScene *myScene = importer.ReadFile(yourObjFile, aiProcess_Triangulate); Triangles are a GPU’s favorite shape. Your myScene variable is a pointer to an impressively large data structure that has everything you’d ever want to know about your model.

Usage An aiScene object will consist of the following attributes (there’s much more within the object; we’re only covering the portion you need for your assignment): unsigned int mNumMeshes; Number of meshes in the scene (typically just one). aiMesh **mMeshes; This is an array of type aiMesh* and of size mNumMeshes, where each element of the array is pointing to a single aiMesh object, not an array of them. It’s more like a 1D array, the elements of which are pointers to single object.

Usage What information can we get out of an aiMesh object? unsigned int mNumFaces; Number of primitives (can be triangles, polygons, or lines, but since we used the aiProcess_Triangulate flag, they’re triangles). aiFace *mFaces; A pointer to an array of aiFace objects (of size mNumFaces), which are the faces that make up the mesh (same faces that you encountered in PA04). aiVector3D *mVertices; An array of vertex positions. This is the information we need for our model, but we have to do some further processing.

Usage We also just said that mFaces is a pointer to an array of aiFace objects, but what information can we get out of an aiFace object? unsigned int *mIndices; A pointer to the indices array. These are the same indices that were in the faces you encountered in PA04. Again, since we used the aiProcess_Triangulate flag, this array will have a size of three (because triangles). unsigned int mNumIndices; This value will be three (because triangles).

Putting It Together There’s still one more issue to address: In PA04, you had to use the indices in the faces to actually obtain the coordinate info regarding each vertex. We have to do something similar in Assimp. To obtain the coordinate info of each vertex, we use the indices from the mIndices array to offset into our aiMesh’s aiVector3D *mVertices attribute. In other words, we use the mIndices values to obtain the vertex coordinates from mVertices within the aiMesh object.

Summary Confused? We were too. To recap: An aiScene contains (usually one) aiMesh. An aiMesh has many aiFaces. Each aiFace contains three indices (located in mIndices). An aiMesh also contains a aiVector3D *mVertices attribute. This is the vertex coordinate info that the GPU needs to render our models, but we need the mIndices values to correctly obtain this data.

Pseudocode Initialize an Assimp::Importer object and use it to read in your .obj file. Find out how many aiMesh objects are in your aiScene. For the .obj files we use, there’s usually only one aiMesh, so the following pseudocode will require modification if more than one aiMesh is present. What modifications would you make? Obtain the single aiMesh object from the aiScene. Iterate through each aiFace in the given aiMesh. Use the values found in the current aiFace’s mIndices array to offset into the aiMesh’s mVertices array and save these values to an array (of Vertex structs) that can be sent to the GPU. What about color?

Resources Assimp’s documentation: A very detailed link: http://assimp.sourceforge.net/lib_html/index.html A very detailed link: http://ogldev.atspace.co.uk/www/tutorial22/tutorial22.html

Vertex Shader Applications Moving Vertices Morphing Wave Motion Fractals Lighting More realistic models Cartoon Shaders

Fragment Shader Applications: Per Vertex Lighting Per Fragment Lighting

Fragment Shader Applications: Texture mapping Smooth shading Environment Mapping Bump Mapping

GLSL OpenGL Shading Language Vertex and Fragment shaders written in GLSL Part of OpeGL 2.0 and up As of OpenGL 3.1, application must use shaders. Example code of a vertex shader: const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); out vec3 color_out; void main(void){ gl_Position = vPosition; color_out = red; }

Vertex & Fragment shader pipelin

Data Types C types: int, float, bool, double, uint Arrays/Vectors: float vec2, vec3, vec4 Also int (ivec) and boolean (bvec) Matrices of floats or doubles: Square matrices: 2x2, 3x3, or 4x4 : mat2, mat3, mat4 Stored by columns Standard referencing m[row][col] non-square matrices: size {2,3,4}x{2,3,4}: mat3x4, dmat4x2 texture samplers sampler1D, sampler2D, sampler3D for 1, 2, 3D power-of-two textures sampler2DRect for rectangle textures samplerCube for cubemap textures

Data Types Variable declaration and initialization very similar to C-style float a = 1.0; vec3 point = vec3(1.0,1.0,4.0); mat2 mat = mat2(1.0,0.0,0.0,1.0); (matrices are assigned in column major order) C++ style constructors vec3 a = vec3(1.0, 2.0, 3.0) vec2 b = vec2(a)

Pointers There are no pointers in GLSL We can use C structs which can be copied back from functions. Because matrices and vectors are basic types they can be passed into and be output from GLSL functions mat3 func(mat3 a)

Qualifiers GLSL has many of the same qualifiers (const) as C/C++ Need others due to the nature of the execution model Variables can change Once per primitive Once per vertex Once per fragment Any time in the program

Passing Values call by value‐return. Two possibilities in: variables copied in out: returned values are copied back inout (deprecated) Example: vertex shader using out const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); out vec3 color_out; void main(void){ gl_Position = vPosition; color_out = red; }

Vertex Attribute Variables Vertex Attribute variables can change at most once per vertex Flows down the pipeline with each vertex Position, color, normal, texture cooddinates There are a few built in variables such as gl_Position but most have been deprecated User defined (in application program) Use in qualifier to get to shader (read only) in float temperature in vec3 velocity layout (location = 0) in vec3 vp;

Uniform parameters Variables that are set by the application but are constant for the entire primitive Transformation matrices, parameters of light sources, textures Can be changed in the application and sent to the shader Cannot be changed in the shader. uniform mat4 projectionMatrix;

Uniform parameters To set parameters, use glGetUniformLocation, glUniform* in application After shader is active, before rendering Example In shader declare uniform float a; In application, set a using GLuint p; //… initialize program p int i=glGetUniformLocation(p,”a”); glUniform1f(i, 1.f);

Some Built-In Variables vertex shader in: int gl_VertexID (for indexed rendering) vertex shader out: vec4 gl_Position (clip space position), - Required float gl_PointSize (pixel width/height for point rendering) Note other out variables will be interpolated during rasterization (texture coordiantes, …) fragment shader in: vec4 gl_FragCoord (location in window space) Note: for user defined variables you Need to have same variable name as output (declared as out) of vertex shader fragment shader out: float gl_FragDepth (fragment depth)

Operators and Functions Standard C functions Trigonometric: cos, sin, tan, etc Arithmetic: log, min, max, abs, etc Normalize, reflect, length Overloading of vector and matrix types mat4 a; vec4 b, c, d; c = b*a; // a column vector stored as a 1d array d = a*b; // a row vector stored as a 1d array

Swizzling and Selection Can refer to array elements by element using [] or selection (.) operator with x, y, z, w r, g, b, a s, t, p, q vec4 a; a[2], a.b, a.z, a.p are the same Swizzling operator lets us manipulate components a.yz = vec2(1.0, 2.0);

Open GL Quick Reference Card https://www.khronos.org/files/opengl45- quick-reference-card.pdf GLSL starts on page 9

Sample Screenshots The next few slides will have screenshots from the code section of the presentation.

Questions?