Difficulty with shader on coordinate system

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
Cipheroid
Prole
Posts: 9
Joined: Fri Feb 24, 2017 7:52 am

Difficulty with shader on coordinate system

Post by Cipheroid »

I am having difficulty creating a shader that draws a texture affected by the coordinate system (translation,scale, and rotation, no shearing). The texture's size must stay the same regardless of other images and intersecting opaque pixels should be affected by the pixels on the texture. (essentially using the transformed pixels of the texture and affecting all other images by the texture's pixels)
Doing this is very difficult, since I do not know much about shaders that involve transforming coordinates and the use of matricies.

Alternate methods on doing similar use stencils, which need discard functionality to work properly, but my graphics card cannot handle those smoothly and efficiently, even with a canvas and optimized Lua code, because I use Intel HD Graphics 400.

Image
Cipheroid
Prole
Posts: 9
Joined: Fri Feb 24, 2017 7:52 am

Re: Difficulty with shader on coordinate system

Post by Cipheroid »

Nobody has a solution? :huh:
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Difficulty with shader on coordinate system

Post by pgimeno »

I don't fully understand the issue; maybe I'm not the only one.
Cipheroid
Prole
Posts: 9
Joined: Fri Feb 24, 2017 7:52 am

Re: Difficulty with shader on coordinate system

Post by Cipheroid »

pgimeno wrote: Fri Apr 27, 2018 2:22 am I don't fully understand the issue; maybe I'm not the only one.
Using an image displayed by the shader transformed by the coordinate system to affect pixels of other images intersecting with the pixels displayed by the shader. Simply overlaying that image to other images using the main image's coordinates like I found in other shaders in this forum causes misaligned pixels, wrong sizes, and does not work with the coordinate system. (That is as far as I ever got with this. I am terrible with shaders)
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Difficulty with shader on coordinate system

Post by pgimeno »

I'm mostly guessing here, but it appears to me that you want to apply the inverse transform to the one that LÖVE uses, to the screen coordinates passed in the shader's effect().

If so, you can do something like this:

In the shader:

Code: Select all

extern mat3 tf;
...
vec4 effect(vec4 col, Image texture, vec2 texpos, vec2 origscrpos)
{
  vec2 scrpos = (tf * vec3(origscrpos, 1)).xy;
  ...
}
And in the Lua side, when you have the transformation ready:

Code: Select all

-- at the top of the file:
local tf = {0,0,0,0,0,0,0,0,1}

...
-- probably in love.draw:
  local ox, oy = love.graphics.inverseTransformPoint(0, 0)
  local ix, iy = love.graphics.inverseTransformPoint(1, 0)
  local jx, jy = love.graphics.inverseTransformPoint(0, 1)
  ix, iy = ix - ox, iy - oy
  jx, jy = jx - ox, jy - oy
  tf[1] = ix; tf[2] = jx; tf[3] = ox; tf[4] = iy; tf[5] = jy; tf[6] = oy
  shader:send('tf', tf)
I can't offer better help without a more specific question, sorry.

Edit: Added example.
Attachments
transform_example.love
(177.54 KiB) Downloaded 107 times
Cipheroid
Prole
Posts: 9
Joined: Fri Feb 24, 2017 7:52 am

Re: Difficulty with shader on coordinate system

Post by Cipheroid »

Thank you! This may help..
Post Reply

Who is online

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