Getting screen-space world origin in pixel 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
Jugbot
Prole
Posts: 14
Joined: Mon Jun 24, 2019 9:54 pm

Getting screen-space world origin in pixel shader?

Post by Jugbot »

I am trying to get the origin in a pixel shader in screen space but the origin is always the same value (I think it is always 0,0 but opengl makes it hard to tell)

Code: Select all

vec4 origin = TransformProjectionMatrix * vec4(0.0f, 0.0f, 0.0f, 1.0f);
I am using hump.camera and the camera tracks the player yet the origin does not seem to change.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Getting screen-space world origin in pixel shader?

Post by pgimeno »

No, the origin rarely changes in Löve 11.x because most transforms are done by the CPU, not the GPU. See the note in TransformMatrix here: Shader_Variables (it applies to TransformProjectionMatrix as well).

I believe it's a consequence of overzealous autobatching. Apparently it's done so the same batch can be used between matrix changes, yet I don't think it's common to keep drawing the same texture between matrix changes.
Jugbot
Prole
Posts: 14
Joined: Mon Jun 24, 2019 9:54 pm

Re: Getting screen-space world origin in pixel shader?

Post by Jugbot »

That is pretty weird since I am using the transform projection on the vertices and that has an effect, so I was expecting I was missing something basic :x

I am drawing with a quad.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Getting screen-space world origin in pixel shader?

Post by pgimeno »

If you leave only the projection and remove the transform (i.e. use only ProjectionMatrix), you'll probably obtain the same result. That means that the transform is a unit matrix and therefore has no effect.

The projection matrix is necessary to transform screen coordinates to normalized device coordinates (ranging from -1 to 1 in all axes). I don't think there's anything that changes it, so it's likely not considered for autobatching. I haven't looked into the related source, though, so I may be wrong.
Jugbot
Prole
Posts: 14
Joined: Mon Jun 24, 2019 9:54 pm

Re: Getting screen-space world origin in pixel shader?

Post by Jugbot »

What is the easiest way to draw a full screen pixel effect while still getting the transform matrix?
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Getting screen-space world origin in pixel shader?

Post by pgimeno »

In 11.x I'm not sure if it's possible directly. Maybe if you render a spritebatch, not sure. Anyway, if you use the Löve transformation object (e.g. via cam11) you can pass the transform matrix to the shader; see Transform:getMatrix and Shader:send.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests