Thursday, May 14, 2009

Pretty matrix trick

Floating point numbers are wonderful things.
Let's try to draw a distant mesh by standard approach.

Engine code:
shader_modelviewprojection = player_projection * player_modelview;

Vertex shader:
gl_Position = shader_modelviewprojection * vertex;

The result will be funny:


And it's time to trick now.

Engine code:
shader_offset = player_position;
shader_modelviewprojection = player_projection * player_modelview * translate(shader_offset);


Vertex shader:
gl_Position = shader_modelviewprojection * (vertex - shader_offset);

The result will be absolutely correct:

No comments:

Post a Comment