Page 1 of 1
Difficulty with shader on coordinate system
Posted: Tue Apr 24, 2018 11:54 pm
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.
Re: Difficulty with shader on coordinate system
Posted: Fri Apr 27, 2018 1:22 am
by Cipheroid
Nobody has a solution?
Re: Difficulty with shader on coordinate system
Posted: Fri Apr 27, 2018 2:22 am
by pgimeno
I don't fully understand the issue; maybe I'm not the only one.
Re: Difficulty with shader on coordinate system
Posted: Fri Apr 27, 2018 11:58 pm
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)
Re: Difficulty with shader on coordinate system
Posted: Sat Apr 28, 2018 9:44 am
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.
Re: Difficulty with shader on coordinate system
Posted: Sun Apr 29, 2018 3:29 am
by Cipheroid
Thank you! This may help..