Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing the time to GLSL shaders

2,263 views
Skip to first unread message

Jon Harrop

unread,
Dec 22, 2007, 12:03:23 AM12/22/07
to

I'm doing the obvious thing in passing the current time to my GLSL shaders
as a float, following the tutorials. But on my machine the resulting
animation is extremely jerky, as if the variable doesn't get updated for
many frames of animation and then suddenly catches up.

What might be causing that?

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u

Philipp Klaus Krause

unread,
Dec 22, 2007, 12:50:51 PM12/22/07
to
Jon Harrop schrieb:

> I'm doing the obvious thing in passing the current time to my GLSL shaders
> as a float, following the tutorials. But on my machine the resulting
> animation is extremely jerky, as if the variable doesn't get updated for
> many frames of animation and then suddenly catches up.
>
> What might be causing that?
>

I suppose you're passing it as a uniform. Unfortunately at least Nvidia
has taken the approach of treating uniforms as constants and recompiling
the whole shader whenever a uniform changes. You probably see delays
caused by framerate drops due to recompiling.

Philipp

Jon Harrop

unread,
Dec 22, 2007, 5:06:54 PM12/22/07
to

Ugh, is there another way for me to pass them in?

Philipp Klaus Krause

unread,
Dec 22, 2007, 5:43:31 PM12/22/07
to
Jon Harrop schrieb:

> Philipp Klaus Krause wrote:
>> I suppose you're passing it as a uniform. Unfortunately at least Nvidia
>> has taken the approach of treating uniforms as constants and recompiling
>> the whole shader whenever a uniform changes. You probably see delays
>> caused by framerate drops due to recompiling.
>
> Ugh, is there another way for me to pass them in?
>

Use a varying.

Philipp

Malte Clasen

unread,
Dec 22, 2007, 10:14:22 PM12/22/07
to
Philipp Klaus Krause wrote:
>> Ugh, is there another way for me to pass them in?
>
> Use a varying.

Aren't varyings supposed to transport data from the vertex shader to the
fragment shader? Do you suggest passing the time as uniform to the
vertex shader and from there as varying to the pixel shader? If so, that
would improve performance only if the vertex shader is significantly
simpler than the fragment shader, wouldn't it?

Malte

Philipp Klaus Krause

unread,
Dec 23, 2007, 4:51:13 AM12/23/07
to
Malte Clasen schrieb:

Don't use a uniform. Use vertex attributes to pass it to the vertex
shader and a varying to pass it from the vertex to the fragment shader.

Philipp

ts

unread,
Jan 2, 2008, 6:46:08 PM1/2/08
to
On Dec 23 2007, 3:51 am, Philipp Klaus Krause <p...@spth.de> wrote:

> Don't use a uniform. Use vertex attributes to pass it to the vertex
> shader and a varying to pass it from the vertex to the fragment shader.

How can you pass a single "global" value as a vertex attribute? Do you
mean that the data needs to be set on each vertex? If the change in
the uniform causes a recompile, then NVIDIA needs to fix the problem.
I personally haven't looked for any similar performance glitch but I
just recently started using uniforms that change multiple times for
each update.

Can you clarify?

ts

folays

unread,
Jan 3, 2008, 3:41:47 AM1/3/08
to
ts <talk...@gmail.com> writes:

In hardware skinning area, using Uniform values to change matrices used by
the shader is the way to go (at least with all ressources i've read and my
homework i got working). Those matrices are recalculated each frame, using
the time and interpolation coupled to the animation sequences.

On the other hand, I have multiple static VBOs (vertex position, color, and
bones indices + bones weights) which never change between frames.

So, the only thing that it takes me to display a model each frame is to
recalculate the bones position, and update them to the shader via Uniforms.

On a graphic card having room for ~ 12-24 bones matrices, which is common,
but could be up to 80, and a model having at least 100 bones, it means that
you have to split your model into at least 5 batch, each having a couple of
Uniform updates to change the bones matrices.

Moving those global values to vertex attributes would need 4 more vertex
attributes (each vertex have up to 4 bones weights/indices), which would need
much more graphic card memory and VBOs data pre-fetching performance hits,
and even more if you want to display the same model multiple times in a scene.

I doubt that people which first moved this previously CPU-done work onto the
GPU (multiplying the vertex by the bones matrices indexed by bones indices)
lost performance by doing this.

So i guess that if you have a "global value", you should put in a Uniform,
and if it does a huge performance hit, it's an issue with the driver.

It tooks me a lot of time to find and read good documentation on hw skinning,
so, if some people are more interested in this area, feel free to throw an
eye through a set of copy-and-paste stuff i mostly took from gamedev.net
forums: http://hyrule.folays.net/skinning/ , and also this paper:
http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html

--
folays

0 new messages