Jump to content

  • Log In with Google      Sign In   
  • Create Account


Chananya Freiman

Member Since 12 Dec 2012
Offline Last Active Sep 14 2013 09:37 AM
-----

Posts I've Made

In Topic: How to do animation and IK with OpenGL?

18 July 2013 - 05:15 PM

There is a tendency where flexible enough parts of OpenGL (i.e. shader scripts) are "misused" to do some stuff not directly related to graphics rendering. An example is skinning on the GPU. However, general animation and kinematics is IMO still done on the CPU.

 

That isn't misusing OpenGL, that's using properly your GPU. The whole idea of shaders is to give you the programmable ability to do anything you want with it.

Your GPU is by far better at these things than your CPU, and by "these things" I mean applying redundant calculations on big vector-like data sets. Bones (matrices) happen to fit that description.

GPGPU just makes this more obvious (either through OpenCL/CUDA, or compute shaders, if they exist already?).

 

Updating the animation skeletons, and using IK (which isn't really related to rendering in any way, but rather to physics), though, is usually done on the CPU. There will probably be a time when that, too, wont be true anymore, but we are still not there.


In Topic: app crashes when binding buffers and call draw function

12 July 2013 - 05:56 PM

Sorry if this offends you, but it's crashing because there is hardly one line of code there that isn't an error.

I'll add a full reply once I get back to my computer if nobody answers by then.


In Topic: Index Buffer help

12 July 2013 - 03:24 PM

You will use all the vertices.

 

The idea is that you don't use the vertices to describe your mesh.

You use indices to describe your mesh.

 

At the end, to actually render a rectangle, you have to give OpenGL two triangles, which are six vertices. So you can either give OpenGL the six vertices up front, or you can give it the four vertices that actually define the rectangle, and tell GL "I gave you four vertices, I want you to make two triangles out of them like this index buffer tells you".

 

When using indices, GL simply grabs the vertices from your vertex buffer. Your first value in the index buffer is 0? ok, let's grab the first value in the vertex buffer. The second value is 1? grab the second value in the vertex buffer. 2? grab the third. Now we grabbed three vertices, which form the first triangle.

Then it continues with indices 0, 2 and 3. Note that we reused two vertices - 0, and 2. Even though we sent them only once, we actually used them twice.


In Topic: What if I have more models per level than available VBO memory?

12 July 2013 - 06:55 AM

Regarding the above comment.

 

Drivers are free to swap your buffers from RAM to video RAM (VRAM has two meanings in this context) and the other way around at any point of time.

While giving them hints as to the usage of buffers might (and again, might not) make them initialize the buffer where you want, drivers are free to do real-time analysis as to the actual usage of your buffers, and swap them if they want to, and in fact I read years ago that they indeed do this.


In Topic: Index Buffer help

12 July 2013 - 06:41 AM

Suppose you have a 2D rectangle of size [2, 2].

These are the vertices it uses:

[-1, -1]

[-1, 1]

[1, 1]

[1, -1]

 

While we only need four vertices to represent this rectangle, the graphics cards wants triangles, each one having three vertices.

So if we were to split the above rectangle into triangles, we would need to send six coordinates instead of four.

 

Another way to do this, is send only those four vertices, but together with them also tell the graphics card how to form triangles from them.

This is where the index (element in OpenGL) buffer comes in.

The element buffer has numbers that index your vertices.

E.g. 0 would be the first vertex, 1 the second, and so on.

So with an element buffer, to form the triangles needed for the rectangle, we need to send these indices: [0, 1, 2, 0, 2, 3]. If you replace the numbers with the actual vertices they index, you will see you get the original six vertices to form the triangles.

 

Indexing reduces memory and bandwidth (except for very uncommon worst case scenarios), which in turn help rendering speed.

 

Most file formats (to which you export from Blender, 3ds Max, etc.) support indexing, but there are two variants of indexing for file formats.

In modeling tools (and in fact, in your OpenGL code too!), a "vertex" isn't a position, it's a combination of a position, a normal vector, a color, a texture coordinate, and so on.

Every one of these things is called a vertex attribute, and is only one part of the whole vertex.

OpenGL (and Direct3D) only allow 1D indexing, or in other words - you have one index that points to all the vertex attributes.

 

For example, if you have an array of vertex positions and another array of vertex normals, then index 0 would be the first position and the first normal.

 

This might seem obvious, but some file formats don't actually store their data this way.

In most cases, a model doesn't actually need the same amount of positions, normals, and so on.

If there are many vertices that have the same normal, the file might store only one normal, and let them all share it.

You then have different indices for each vertex attribute, which you can't directly use for rendering.

In this case, you will have to "flatten" the arrays and fill them up with all the shared data.

 

This can be seen in the completely obsolete, bad format *.OBJ (it's the most terrible format in existence, but for some reason it's used everywhere).


PARTNERS