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.
Difficulty with shader on coordinate system
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Difficulty with shader on coordinate system
Nobody has a solution?
Re: Difficulty with shader on coordinate system
I don't fully understand the issue; maybe I'm not the only one.
Re: Difficulty with shader on coordinate system
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
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:
And in the Lua side, when you have the transformation ready:
I can't offer better help without a more specific question, sorry.
Edit: Added example.
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;
...
}
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)
Edit: Added example.
- Attachments
-
- transform_example.love
- (177.54 KiB) Downloaded 107 times
Re: Difficulty with shader on coordinate system
Thank you! This may help..
Who is online
Users browsing this forum: slime and 5 guests