Sign in to follow this  

Is it a good idea to scale models using vertex's w component in vertex shader

This topic is 820 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

Maybe it's very simple,but i googled without success.Will there be any problem to scale models by setting vertex's w component(the last one) in vertex shader? is it free,that is to say,whether i set w or not,divided by w is performed all the time?

Besides this way only scale uniformly, are there other drawbacks?because those i googled all scaling by setting x,y,z.

Edited by PolarWolf

Share this post


Link to post
Share on other sites

The vertex shader performs the w divide on gl_Position (or whatever HLSL uses) after it has run, and then the results are spit out into the next shader. If you want to be able to translate your vertices using the world matrix, you need to have the w value set to 1, or else the translation will not work, and only the scale and rotation will work.

 

Setting the w value to 0 will nullify the translation. Setting it to 1 fixes it, and setting it to 0.5 halves the translation... etc. It's a multiplication against the translation amount and the w value, and then it is added to the final x,y, or z value.

Edited by Solid_Spy

Share this post


Link to post
Share on other sites

Maybe it's very simple,but i googled without success.Will there be any problem to scale models by setting vertex's w component(the last one) in vertex shader? is it free,that is to say,whether i set w or not,divided by w is performed all the time?
Besides this way only scale uniformly, are there other drawbacks?because those i googled all scaling by setting x,y,z.

It's a bad idea. Think what you will have to do if you want multiple sizes of your model in your scene, you'll have to either:

a. Update every vertex of your model and draw from CPU memory or upload it to the GPU every time you want to use it - both of which are slow.
b. Keep several copies of your model stored in GPU memory - which isn't inherently slow but you might prefer to use the GPU memory for something else. You could just prescale the x,y,z components in this case as well.

It's far better to pass a scale factor into your shader using a separate variable.

Share this post


Link to post
Share on other sites

This topic is 820 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this