Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplacing Vertices in the Vertex shader
    primarykey
    data
    text
    <p>My code creates a grid of lots of vertices and then displaces them by a random noise value in height in the vertex shader. Moving around using</p> <pre><code>glTranslated(-camera.x, -camera.y, -camera.z); </code></pre> <p>works fine, but that would mean you could go until the edge of the grid.</p> <p>I thought about sending the camera position to the shader, and letting the whole displacement get offset by it. Hence the final vertex shader code:</p> <pre><code>uniform vec3 camera_position; varying vec4 position; void main() { vec3 tmp; tmp = gl_Vertex.xyz; tmp -= camera_position; gl_Vertex.y = snoise(tmp.xz / NOISE_FREQUENCY) * NOISE_SCALING; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; position = gl_Position; } </code></pre> <p>EDIT: I fixed a flaw, the vertices themselves should not get horizontally displaced.</p> <p>For some reason though, when I run this and change camera position, the screen flickers but nothing moves. Vertices are displaced by the noise value correctly, and coloring and everything works, but the displacement doesn't move.</p> <p>For reference, here is the git repository: <a href="https://github.com/Orpheon/Synthworld" rel="nofollow">https://github.com/Orpheon/Synthworld</a></p> <p>What am I doing wrong?</p> <p>PS: "Flickering" is wrong. It's as if with some positions it doesn't draw anything, and others it draws the normal scene from position 0, so if I move without stopping it flickers. I can stop at a spot where it stays black though, or at one where it stays normal.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload