View Full Version : gl_vertex.w

wizzo

06-07-2005, 10:54 PM

what does the .w component of gl_Vertex stands for ?

its value are :

1 if you don't change it

0 if you want to throw the vertex to infinity

are there any other specific values that could be usefull ?

thanks in advance

wizzo

yooyo

06-07-2005, 11:45 PM

.w is homogenius coordinate. Simple... if .w is 1.0 and vertex is transformed by 4x4 matrix it will be affected by translation part of matrix. If .w is 0.0 it will not be affected by translation part.

You can use it for some kind of geometry blending... imagine sphere with vertices that have .w in 0 to 1 (different values) and two matrices 4x4. In vertex shader do something like this:

vec4 v1 = matrix1 * gl_Vertex;

vec4 v2 = matrix2 * vec4(gl_Vertex.xyz, 1.0 - gl_Vertex.w);

vec4 finalvert = v1 + v2; And finalvertex will have "blended" position.

yooyo

Relic

06-08-2005, 12:30 AM

Uhm, no, I wouldn't do this.

The gl_Vertex.w and its result after the transformation is important for clipping space calculations (check OpenGL spec chapter 2.11 Coordinate Transformations) and you can't just put a weight into the w and expect things to work like this.

V-man

06-08-2005, 05:59 AM

Originally posted by Relic:

Uhm, no, I wouldn't do this.

It doesn't work if you do blending like that.

Blending is done by transforming a vertex by 2 matrices (or more)

result1 = matrix1 * vertex;

result2 = matrix2 * vertex;

//and use some blend factor

blendvertex = mix(result1, result2, blend_factor);

the value of w in vertex doesn't matter. The blending will always work.

its value are :

1 if you don't change it

0 if you want to throw the vertex to infinity

It can have any value.

yooyo

06-08-2005, 03:20 PM

Well, I know it is not correct and I put blended in quotes. Correct solution might be:

vec4 v = vec4(gl_Vertex.xyz, 1.0);

vec4 v1 = matrix1 * v;

vec4 v2 = matrix2 * v;

vec4 finalvert = mix(v1, v2. gl_Vertex.w); yooyo

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.