What is the vec4 position returned by a vertex shader?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Zarty55
Citizen
Posts: 79
Joined: Thu Jul 25, 2013 2:36 am

What is the vec4 position returned by a vertex shader?

Post by Zarty55 »

Just a quick question. I thought it would be vec2 or vec3. What does the components of that vector means? And also, what kind of transformation is the transform_projection doing? Thanks!
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: What is the vec4 position returned by a vertex shader?

Post by raidho36 »

The GPU uses 3d coordinates anyway, and you need a 4 dimensional vector to go along with 3+1d projection matrix. It's components are simply x, y and z coordinates, and a w additional projection value which you shouldn't touch.

The projection sets up a matrix such that multiplying world coordinates vector by this matrix yields screen coordinates. It has to do with object positions.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: What is the vec4 position returned by a vertex shader?

Post by bartbes »

As some extra explanation, using 4 coordinates to describe 3-dimensional points means you can easily do translation. To do the same in 2 dimensions, you only need 3 coordinates, but OpenGL works with 3-dimensional coordinates. For the maths to work, the 4th coordinate needs to be 1, though OpenGL divides all other coordinates by it in case it isn't.

The transform_projection passed to the vertex shader represents all transformations you have done using love.graphics.translate, love.graphics.scale, etc, and finally the "base" projection that turns the input vector into a vector representing its position in clip space (which ends up being its position on the screen I know this isn't strictly true, leave me be, opengl wizards).
Zarty55
Citizen
Posts: 79
Joined: Thu Jul 25, 2013 2:36 am

Re: What is the vec4 position returned by a vertex shader?

Post by Zarty55 »

Thanks for the answers guys :)

Ok, I've read somewhere else about the 4th component (And it's related to either a true Z value or a trick where 0 is scaling and 1 means translating? I'm confused about this). But the 3rd component is the one I'm not understanding. I tried to modify it and it simply makes whatever I'm drawing disappear if it's bigger than 1 or smaller than -1. My thought was that the vertex shader was actually the last thing that would happen to the vertex and after that it would draw the polygon on the screen. But the fact that it is a vec4 makes it seems to me that something else is happening after that. Is there a diagram that represents the general proccess so I can locate myself in all this?

If it's too complicated to explain maybe you guys could give me a website to read about it?

Edit: Ok I've found some openGL pipeline diagram. What I want to know is if Love changes any of that?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: What is the vec4 position returned by a vertex shader?

Post by raidho36 »

It's hard-wired in the GPU and cannot be changed.

The reason why graphics disappear if you modify z value too much is because camera clipping still applies, and apparently it's set such that only graphics within [-1, 1] regions show up. Not that it matters, because 2d graphics is rendered in specific order and blended, so the z value is practically discarded.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests