Sign in to follow this  
fazekaim

How can I scale model size in GLSL vertex program?

Recommended Posts

Here are my shader:
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by phantom
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.


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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Trienco
Quote:
Original post by phantom
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by fazekaim
Vertex *= 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 this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by phantom
Quote:
Original post by MARS_999
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
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. :)


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 this post


Link to post
Share on other sites

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