Tada! Non-linear projection through the vertex shader

K.I.L.E.R

Retarded moron
Veteran
It displays lots of dots. :LOL: In any case, the projection matrix is the directrix. Obviously I have a bit more work to do on it and clean up the useless bits but it certainly possible to do non-linear projection.
Code:
 varying vec4 colour;  void main(){    vec3 vertex;    vec3 focus;    vec3 pointDirectrix;    vec3 pointOnPorabola;    float dstVertexToDirectrix;        vertex = vec3(0.0, 0.0, 0.0);    pointDirectrix = vec3(gl_ModelViewProjectionMatrix * gl_Vertex);    dstVertexToDirectrix = length(vertex - pointDirectrix);    focus = vec3(0.0, 0.0, 2.0 * dstVertexToDirectrix);        pointOnPorabola = vec3(0.0);    pointOnPorabola.x = (pointDirectrix.y * pointDirectrix.y) / (4.0 * dstVertexToDirectrix * pointDirectrix.x);    pointOnPorabola.y = sqrt(4.0 * dstVertexToDirectrix * pointDirectrix.x);     gl_Position = vec4(pointOnPorabola, gl_Vertex.w);    colour = gl_Color; }

My triangle is stretched like a SOB.
Need to modify it.
It obviously works.
 
Code:
varying vec4 colour;

  
void main()
{
    vec3 vertex;
    vec3 focus;
    vec3 pointDirectrix;
    vec3 pointOnPorabola;
    float dstVertexToDirectrix;

    vertex = vec3(0.0, 0.0, 0.0);

    pointDirectrix = vec3(gl_ModelViewProjectionMatrix * gl_Vertex);

    dstVertexToDirectrix = length(vertex - pointDirectrix);

    focus = vec3(0.0, 0.0, 2.0 * dstVertexToDirectrix);

    pointOnPorabola = vec3(0.0);
    pointOnPorabola.x = (pointDirectrix.y * pointDirectrix.y) / (4.0 * dstVertexToDirectrix * pointDirectrix.x);
    pointOnPorabola.y = sqrt(4.0 * dstVertexToDirectrix * pointDirectrix.x);

    gl_Position = vec4(pointOnPorabola, gl_Vertex.w);

    colour = gl_Color;
}

:LOL:


And get to bed. It's late damnit. [edit] (I'm not entirly sure why I said that. Kitty must be controlling me with his mind. I can see him now, watching. Something about the carrots.)
 
Fixed it. Amazing what a night of sleep and a game of Dungeon Siege 2 can do. :)
The first image is without projection.
The second is with projection.

Code:
varying vec4 colour;

void main(){
   vec3 vertex;
   vec3 focus;
   vec3 pointDirectrix;
   vec3 pointOnPorabola;
   float dstVertexToDirectrix;
   
   vertex = vec3(0.0, 0.0, 0.0);
   pointDirectrix = vec3(gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex);
   dstVertexToDirectrix = length(vertex - pointDirectrix);
   focus = vec3(0.0, 0.0, 2.0 * dstVertexToDirectrix);
   
   pointOnPorabola = vec3(0.0);
   pointOnPorabola.x = (pointDirectrix.y * pointDirectrix.y) / (4.0 * dstVertexToDirectrix * pointDirectrix.x);
   pointOnPorabola.y = sqrt(4.0 * dstVertexToDirectrix * pointDirectrix.x);
   pointOnPorabola.z = -1.0;

   gl_Position = vec4(pointOnPorabola, gl_Vertex.w);
   colour = gl_Color;
}
 

Attachments

  • noProjection.JPG
    noProjection.JPG
    3.8 KB · Views: 26
  • projection.JPG
    projection.JPG
    11.8 KB · Views: 32
Erm, am I doing something screwy? When I try to view the pictures I get:
Rufus210, you do not have permission to access this page. This could be due to one of several reasons:

1. Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
2. If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
 
It's a Beyond3D thing unfortunately. Might have to pester Dave about it.
And just what would Dave be able to do about it? Secondly, this is the Beginner's Questions forum, so next time you feel like posting needlessly in here, make sure there's at least a question attached of some kind. The beginner bit we'll waive, seeing as though it's you.
 
Why is this very silly?
Could it possibly be because simply projecting the vertices of the triangles in a "non-linear" way is a trifle pointless given that everything else is done "linearly" in the visibility calculations? As a hint, how "non-linear" are the edges of your projected triangle?
 
What do you suggest I do? Project my non-linear final calculation onto a flat plane?
Could it possibly be because simply projecting the vertices of the triangles in a "non-linear" way is a trifle pointless given that everything else is done "linearly" in the visibility calculations? As a hint, how "non-linear" are the edges of your projected triangle?
 
What do you suggest I do? Project my non-linear final calculation onto a flat plane?
You have to tessellate your model sufficiently so that a piecewise linear representation is an accurate enough approximation.
 
Ahhh!!!! The rasteriser is only going to rasterise lines, not curves. Shit! I forgot about that. Thanks.
 
Back
Top