Morph targets.

Started by
18 comments, last by swiftcoder 12 years, 5 months ago

Btw. I wanted to actually write morph-target library a long time ago and I'm actually really thinking about that again ... thanks :D



Consider:

1. Base mesh.
2. Eye raise.
3. Jaw Open.


If you simply 'lerp' between 2 and 3, you'll have a half open Jaw, and a half raised eyebrow.
Let's say I want a "REALLY" open jaw, in most software I can extend the weight to 2.0 to achieve this. If you were simply using LERP, the head would scale up 1.5 times it's original size.

Both of these kinda indicate that using LERP is a no-no. A better idea is to subtract the target from the base mesh, and then sum the weighted offsets onto the base mesh.
Advertisement

You can only bind one VBO at once.

Say what? You can bind exactly as many VBOs as the number of vertex attribute streams your card supports.

(hint: glBindBuffer() is purely a client-side construct. glVertexAttribPonter() is what actually binds VBOs to the server side)

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I was reading a thread that was back and forth, Its better to just put it all in one buffer anyway, 1 glBindBuffer call

That's 5 draw calls to make sure you aren't just filling your gpu memory with 50+ copies of exactly the same data.
That's 5 more draw calls to alleviate a potential memory bottleneck on low end GPUs (eg laptops/netbooks) [in cases where they utilise system memory]
That's 5 draw calls that will give a significant improvement in the way you are utilising the GPU and it's ram.

Remember: Always optimise for memory before you optimise for computational performance. If there was always zero overhead for performing a memory read, you might have a point. Since that's not the case, it's best not to make that assumption.[/quote]
1.) Who cares about netbooks, if he does then your point might be valid.
2.) It might not be a significant improvement because 5 draw calls takes some time to get to the GPU, so if you split your model into 500 static verts and 500 morphable ones, then your going to be able to draw all 1,000 faster than drawing 500, GPU goes idle while waiting for your first command, still idle waits for second command, finally it gets the 5th command to actually draw something. So you are idling out your GPU for a small fraction of time.

Always optimise for memory before you optimise for computational performance.[/quote]
What? 50 copies of his model at 2,000 verts is probably less than 10 MB. And secondly, everything is about speed so I dont know what you mean. If your card has 512 MB, your card is not going to be slower the more ram you fill up. Everything is about optimizing computations in gpus. The only things that talk about memory are the ones that actually fill up the whole card because of megatexturing or something. Hes only saving memory if his model is actually big, again if it is small, then memory and speed are low enough to that trying to split the model with be slower. I wouldn't optimize memory unless I was actually going to go over budget and then realize I need to trade performance going down for an increase in more free memory.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


I was reading a thread that was back and forth, Its better to just put it all in one buffer anyway, 1 glBindBuffer call

Let me be very explicit about this: glBindBuffer() amounts to a pointer assignment in client memory - net performance impact: negligible.

If your model has (for example) 5 vertex attributes, then the server-side performance cost incurred by the necessary 5 calls to glVertexAttribPointer() will be the same regardless of whether those calls all source from the same VBO, or source from 5 different VBOs.

Where you can get a performance win by sourcing vertex attributes from a single VBO, is in cache coherency. If your vertex attributes are interleaved within a single VBO, and your vertex size is a multiple of a cache line, then you will see potentially significant performance gains. If you just cram vertex data into a VBO without carefully interleaving components and paying close attention to cache requirements, then you don't gain anything by using a single VBO.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

How can glBindBuffer not go to the GPU? glBufferData() wouldn't know what to manipulate on the GPU.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


How can glBindBuffer not go to the GPU? glBufferData() wouldn't know what to manipulate on the GPU.

The OpenGL API is a state machine (bind buffer, send buffer data, unbind buffer, etc.). But on the server-side (i.e. the driver/GPU end of things), it doesn't work like a state machine at all.

Roughly speaking, glBindBuffer() just sets a pointer in client memory telling the OpenGL API which buffer you want to work with. It isn't until you call glBufferData() that an actual driver transaction is started. At that time, the API will generate a transaction, which conceptually looks a little like this: {'setBufferData', <buffer-id>, <data>}, where the <buffer-id> is the value last set by glBindBuffer(). This transaction is all that is sent to the GPU - the state machine calls never leave the CPU side of things.

Only a handful of OpenGL calls actually result in data moving across the CPU <--> GPU connection. A (non-exhaustive) list of those would be something like this:
- VBO/PBO/Texture/Framebuffer upload/readback
- Shader/Program upload
- Draw calls
- glClear
All the other API calls are just providing extra data that is bundled up into the transactions generated by one of those calls.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Never read that anywhere, is there a specific spot you grabbed that info from? As for saying the GPU is not a state machine, its gotta be, glEnable(GL_TEXTURE_2D), I know that isn't sent down by the driver every time I draw something. Or glColor3f(), glEnable(anything) etc.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


Never read that anywhere, is there a specific spot you grabbed that info from?

Any of the in-depth discussions of the DirectX/OpenGL graphics pipelines, or the discussions of bare-metal renderers written for consoles - I couldn't point to a single source off the top of my head. Any keep in mind that the exact details vary by platform/vendor/driver/etc. None of this is set in stone.

As for saying the GPU is not a state machine, its gotta be, glEnable(GL_TEXTURE_2D), I know that isn't sent down by the driver every time I draw something.[/quote]
First off, you have to remember that texture bind state is separate for each texture unit (i.e. glActiveTexture). The GPU has no concept of textures being enabled or not - it's just a matter of whatever texture units the current fragment shader chooses to read from (and for the fixed function pipelline, its just a shader emulating the old pipeline).

Or glColor3f()[/quote]
glColor3f() just sets the current vertex colour - that value isn't even used until the user calls glVertex() to submit the vertex, and that doesn't (generally) take effect until the user calls glEnd() to submit the entire primitive to the pipeline.

glEnable(anything) etc.[/quote]
The glEnable() calls mostly set client state directly (pixel transfer state, that sort of thing), or they store state bits to be sent with future draw calls (GL_NORMALIZE, etc.). Some of them probably do set so-called 'server-side' driver state (i.e. GL_DEPTH_TEST), but I doubt that much of that state is actually stored on the GPU itself.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

The glEnable() calls mostly set client state directly (pixel transfer state, that sort of thing),[/quote]
Blending, Multisampling, cull face, glBlendFunc, depthfunc, stencil the gpu definitely has a fairly big or equal state machine to the one on the cpu.

The GPU has no concept of textures being enabled or not[/quote]
So your telling me every time I call glTexImage2D, glCopyTexImage2D, GenerateMipMaps, glTexParameter, that the client is also sending a handle to my texture? Why would they waste a 4 byte overhead to send the int to the GPU every time and not store that integer on the GPU? That just doesn't seem to make sense that they would even have a state machine. Why would I not just call the drivers functions: glBindTexture(handle, texture_unit) instead of glActiveTexture(texture_unit), glBindTexture(handle). Maybe it does, but it seems pretty stupid to send that integer for every single function I call, instead of just doing what it looks like is setting the int one time, and just manipulating the current texture.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


Blending, Multisampling, cull face, glBlendFunc, depthfunc, stencil the gpu definitely has a fairly big or equal state machine to the one on the cpu.

It's not a state machine though - state machines assume a serial process, one operation after the other, which is fine for a single-threaded API like OpenGL. The GPU is an inherently parallel machine: there can be many threads, in many programs, even multiple simultaneous OS performing operations at the same time.

Now, it's certainly true that the driver does maintain some per-context state in GPU memory, but it isn't nearly as simple as there being a single blending function. There is no guarantee that operations occur on the GPU in the same order you specify them - the driver is free to reorder operations however it likes, so long as the necessary dependencies between operations are met, so the blending function (among other state) must be attached to each operation.

Why would they waste a 4 byte overhead to send the int to the GPU every time and not store that integer on the GPU?[/quote]
You're uploading what, 100KB of texture data? 100MB? 4 bytes of overhead (and the command overhead is probably much more than that), is absolutely nothing - a standard PCI Express 2.0 bus can transfer 8 GB/s.

Why would I not just call the drivers functions: glBindTexture(handle, texture_unit) instead of glActiveTexture(texture_unit), glBindTexture(handle).[/quote]
it would indeed be much more convenient to eliminate binding altogether, and that is one of the reasons that there are regular cries for an object-oriented interface to OpenGL...

In the early 90's (when the OpenGL API was developed), graphics cards may indeed have operated somewhat along the same lines as the OpenGL API, but the hardware has long since diverged. At this point, OpenGL is a (somewhat poor) high level abstraction - it has little or nothing to do with the way GPUs actually work.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement