Jump to content
  • Advertisement
Sign in to follow this  
lyhlroffel

OpenGL Strange result from flattening vertex shader

This topic is 4170 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm trying to learn how to do shaders, and am currently following this tutorial: http://www.lighthouse3d.com/opengl/glsl/index.php?flatten My problem is that the following vertex shader: void main(void) { vec4 v = vec4(gl_Vertex); v.z = 0.0; gl_Position = gl_ModelViewProjectionMatrix * v; } Doesn't produce what I was expecting, or what the article is saying, both using my own program, and the one supplied by the tutorial. I'm expecting the following to happen: The model will become paper thin (like paper mario :-)), as long as I don't do any rotation. So, if I translate (0.0, 0.0, 5.0), I should see the same result with and without the shader, but once I start rotation I will see that it is flat. What I'm experiencing: The model seems to be flatten in the y direction instead :( Is there some change of coordinate basis or something going on that I don't know of with shaders, or am I doing something wrong? It seems like z and y get changed! For a demonstration, download the example code for the tutorial, and open flatten.vert and comment out the v.z line and enter v.z = 0.0 instead. If we enter v.y = 0.0 instead we get the desired result. Example code at: http://www.lighthouse3d.com/opengl/glsl/examples/flatten_2.0.zip

Share this post


Link to post
Share on other sites
Advertisement
I'm guessing that the GLUT teapot uses a model-space where Z is the up-direction and the XY-plane is the "ground" the teapot sits on. Since you set v.z/v.y to zero before any transformation, the flattening occurs in model-space, and I presume that the the teapot function automatically adds an Y/Z axis swap to thew modelview transformation before rendering. So everything is working correctly, just in a model-space where Z is up.

Share this post


Link to post
Share on other sites
If he is using the GLUT teapot, I heard it calls glpushmatrix, and it changes the modelview and then glpopmatrix.
Use some other model dude.

Share this post


Link to post
Share on other sites
void main(void)
{
vec4 v = vec4(gl_Vertex);
v.z = 0.0;

gl_Position = gl_ModelViewProjectionMatrix * v;
}

Try changing
v.z = 0.0
to
v.y = 00

It may just be that the model is using z as the up axis rather than the conventional y.

Share this post


Link to post
Share on other sites
Aha, this seems like a reasonable explanation (but WHY does glut do it like that?) I will test it with another model later. Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!