I'll post my current project somewhere at a later time. My question is quite general so no need for any .love-file I think.
So to my question...
In love.graphics.draw() you can assign a position offset for the object being drawn. Can you access this position in a shader? Is it included in any of the accessible built-in matrices in Löve perhaps? From what I've tried it doesn't seem like it.
What I'm trying to accomplish is a vertex shader in which all camera translation and scaling are performed. All my values in the Lua-code are meant to be in meters and I want to push the actual pixel-position calculation to the very last in the pipe-line in order to have a more flexible and manageable system.
The scaling is easy. I just have a variable that tells how many pixels a meter is on the screen and multiply that value with the vertex position.
The issue is that the vertex position is local in relation to the object containing the mesh. The object has its own position which is used in love.graphics.draw(). I want to access this position in the vertex shader and scale it up as well.
Here's how the vertex shader looks right now. Objects are drawn in correct size but not with the correct position in relation to the screen. As the positions are in meters they are basically drawn at the top left area of the screen.
Code: Select all
// Camera position in screen space, updated every frame
extern vec3 positionCamera;
// How many pixels a meter is on the screen, could be used for zooming
extern float unit;
// Vertex shader
vec4 position(mat4 transform , vec4 positionVertex)
{
// Offset the vertex with camera position in screen space
positionVertex.xy -= positionCamera.xy;
// Scale the vertex position in order to draw the object at correct size in relation to the screen
positionVertex.xy *= unit;
return transform * positionVertex;
}