How can I scale model size in GLSL vertex program?

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

Recommended Posts

uniform float lerp;
uniform float scale;
void main(void)
{
vec4 Vertex;
Vertex = mix( gl_Vertex, gl_Color, lerp ); // mix 2 keyframe using in model's motion
gl_Position = gl_ModelViewProjectionMatrix * scale * Vertex;

gl_TexCoord[0] = gl_MultiTexCoord0;
}


It does'n work. THe model is draw as usual, in normal size. How can I scale it in GLSL? Thanks...

Share on other sites
Multiply not the scale with position, instead scale with vertex components

Share on other sites
scale with vertex components? how?

Share on other sites
try this:

Vertex.x *= scale;
Vertex.y *= scale;
Vertex.z *= scale;

insert this between gl_Position and Vertex = mix(......); line

Share on other sites
It' working. Thanks!

Share on other sites
Vertex *= scale;

should also work as well.

Share on other sites
Isn't that illegeal according to the standard? I know nvidia supports it. but the standard says it has to be Vertex *= vec4(scale);

Share on other sites
hmmm as far as i can remember vec*scale multipliers are fine... infact, I know it is as in my lighting equations I do it (speccolour * specpower where specpower is a float and speccolour is a vec3 or vec4)

Share on other sites
gl_Vertex is 4 components thus Vertex *= scale; will also multiply the w as well but u only want to scale x,y,z

Share on other sites
you raise a good point.. in which case adjusting it to Vertex.xyz *= scale; or at worse Vertex.xyz = Vertex.xyz * scale; should work.

The compiler should make a better job of optermising either of those when compared to doing it one component at a time as you are explicately vectorising it.

However, that said, looking at his inital 'lerp' code that needs adjusting as well, as he is lerping two vec4s, so he'll lerp the W coord there as well.

Share on other sites
Quote:
 Original post by phantomHowever, that said, looking at his inital 'lerp' code that needs adjusting as well, as he is lerping two vec4s, so he'll lerp the W coord there as well.

But wouldn't it be 1 in both cases, so interpolating between 1 and 1 isn't really doing any harm? So many ways, setting w to 1 after the scaling, using a vector for scaling with w=1, applying the scaling the old fashioned way through the matrix (unless too much extra effort).

Share on other sites
Not to hijack this thread but the whole vec4 vs vec3 topic is somewhat related here. Phantom your code in the book uses vec4 for lighting in the VS, and vec3 is needed for lighting... Nvidia pointed this out to me due to the W memeber is being calculated.

Share on other sites
the Vertex.xyz *= scale; and the Vertex *= vec4(vec3(scale),1.0); worked fine...
Vertex.x *= scale;
Vertex.y *= scale;
Vertex.z *= scale;
is also a working code, but too long for me :)

Vertex *= scale; caused compiler error to me. :(

Share on other sites
Quote:
Original post by Trienco
Quote:
 Original post by phantomHowever, that said, looking at his inital 'lerp' code that needs adjusting as well, as he is lerping two vec4s, so he'll lerp the W coord there as well.

But wouldn't it be 1 in both cases, so interpolating between 1 and 1 isn't really doing any harm?

Yes, you are right... thats what I get for posting 10mins after waking up, heh

Share on other sites
Quote:
 Original post by fazekaimVertex *= scale; caused compiler error to me. :(

Hmmm, odd, I've just run this code by the 3DLabs shader validator and it validates just fine.
uniform float lerp;uniform float scale;void main(void){    vec4 Vertex;    Vertex = mix( gl_Vertex, gl_Color, lerp ); // mix 2 keyframe using in model's motion    Vertex *= scale;     gl_Position = gl_ModelViewProjectionMatrix * Vertex;    gl_TexCoord[0] = gl_MultiTexCoord0;}

Can you post the error you are getting?
edit: and what hardware are you running on?
I'm on an ATI card...

Share on other sites
Quote:
 Original post by MARS_999Not to hijack this thread but the whole vec4 vs vec3 topic is somewhat related here. Phantom your code in the book uses vec4 for lighting in the VS, and vec3 is needed for lighting... Nvidia pointed this out to me due to the W memeber is being calculated.

I assume you are talking about the vertex lighting example?
What bit are you refering to as the only vec4s in use are for the eye coordinates and the vector to the light, which uses 2 vec4s to work out the position (light coord and eye coords) and is then converted to a vec3 anyways.
moving the vec3 inside and outside the normalise function didnt appear to cause a significant change in the colours.

However, I do point out in the book this is just an example of GLSL, by no means should it be taken as a decent light model [smile]

Share on other sites
Quote:
Original post by phantom
Quote:
 Original post by MARS_999Not to hijack this thread but the whole vec4 vs vec3 topic is somewhat related here. Phantom your code in the book uses vec4 for lighting in the VS, and vec3 is needed for lighting... Nvidia pointed this out to me due to the W memeber is being calculated.

I assume you are talking about the vertex lighting example?
What bit are you refering to as the only vec4s in use are for the eye coordinates and the vector to the light, which uses 2 vec4s to work out the position (light coord and eye coords) and is then converted to a vec3 anyways.
moving the vec3 inside and outside the normalise function didnt appear to cause a significant change in the colours.

However, I do point out in the book this is just an example of GLSL, by no means should it be taken as a decent light model [smile]

I think so, don't have the book near by. The reason he pointed it out was for directional vs. spot or point lights. I am using directional lighting and not spot or point lighting. I could send you an email to show you what he is talking about if you are interested. Decent model well beggers can't be choosers when compared to FFP lighting or per vertex. :)

Share on other sites
Quote:
 Original post by MARS_999I think so, don't have the book near by. The reason he pointed it out was for directional vs. spot or point lights. I am using directional lighting and not spot or point lighting. I could send you an email to show you what he is talking about if you are interested. Decent model well beggers can't be choosers when compared to FFP lighting or per vertex. :)

Yeah, that would make sense, it was really only being used as a directional light example, so the calculation correctness for other lighting models wasnt really on my list of things to think about [wink]

The warning about it being a decent model basically was to say 'heres a way of doing it, it might not be fast nor correct but it gives you an idea of how to use things'... heck, I'm not a lighting expert myself so I wasnt really happy with trying to produce a decent lighting model shader [grin]

Share on other sites
Vertex *= scale; is working now... i don't know what could be the problem in the last case...
by the way, i'm using nvidia now.