Use function insteead of projection matrix

Is it possible to use a custom function instead of the projection matrix to for example not project a vertex on a plane but a sphere ?
It should return an X-/Y-/Z-value between 0 and 1 of course and whats about the W-value is it W = 1/Z ?

Thanks in advance

[QUOTE=NoName;1288414]Is it possible to use a custom function instead of the projection matrix to for example not project a vertex on a plane but a sphere ?
It should return an X-/Y-/Z-value between 0 and 1 of course and whats about the W-value is it W = 1/Z ?
[/QUOTE]
When using a vertex shader, you can use any function. However, the resulting triangle will still lie in the plane defined by the three projected vertices, not on the surface of a sphere. Ultimately, the primitive is determined entirely by the outputs of the vertex shader (including gl_Position); how those values are computed doesn’t matter.

Regarding W: scaling all four components by the same factor leaves the position unchanged, but it will affect how attribute values are interpolated across the primitive (unless the variables have the [var]noperspective[/var] qualifier).

I know its not really the topic anymore but I wrote this function to simulate a perspective projection in the shader and for me It seems mouch simpler then a matrix multiplication so my question is how fast it would be relative to a projection matrix.

And whats about my change in the Z value calculation ?

My function : (the model and view matrix need to be applied before)

vec4 projection(vec4 coord)
{
vec4 result;
float dist = length(coord.xyz);

result.x = (coord.x/1)/(aspecttan(fovdegree/2));
result.y = (coord.y/1)/(tan(fov*degree/2));
result.z = 1-(1/(max(coord.z, 0)+1));
result.w = -coord.z;

return vec4(result);
}

Probably quite a bit slower, as you’re performing two calls to tan() for each vertex. It’s also less general than a matrix transformation (e.g. the vanishing point is forced to be in the centre of the viewport). And the max() call in the Z calculation shouldn’t be there.

Even so, you probably aren’t going to notice the overhead compared to that of a fragment shader.

Thanks for your reply, I moved the tan() thing to my CPU program and removed the max() thing (used if() instead ).
Now my program is running 0.7 to 1.5 fps faster then the same program with a projection matrix.
(Im using glutWireSierpinskiSponge() to have a many vertices )

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.