vtx. copy?

Hi,
I´m just starting with GLSL so most probably a simple question - I´m working on a terrain algorithm from NVIDIA (described in GEMS), where is mentioned:

we can render the (x, y) geometries of all terrain blocks using a single read-only vertex buffer and index buffer, by letting the vertex shader scale and translate the block (x, y) geometry using a few parameters.
so if I understand, for most of the blocks I make only one VBO block (for example 64x64) and then ´translate´ it in shaders.

My question is: how to do that? - I have made one VBO block 64x64 (in webGL), so now I should ´copy-paste´ it via shaders.

Any help more that appreciated.

Add a uniform vec2 parameter to your vertex shader and store the offset where you want e.g. the lower left corner to appear in that.
Before transforming the vertices to eye space add that offset to it.


uniform vec2 blockOffset;

void main()
{
    gl_Position = gl_ModelViewMatrix * (gl_Vertex + vec4(blockOffset, 0, 0));
    // ...
}


Before rendering each copy of the block, change the uniform parameter to the new offset.

thank you for the reply. I don’t understand following:

Before rendering each copy of the block, change the uniform parameter to the new offset.

do you mean to change the blockOffset parameter in the draw/redraw() function within the OpenGL?
so after I have drawElements() call I will change the offset and make one more drawElements() call?

Yes.

Another way is to just put that translate into your modelview matrix. Code would become
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;

or
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

or better yet, define your own ModelViewProjectionMatrix and don`t use the GL stuff.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.