Shader and canvas position issue.

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
User avatar
Cucurbitacée
Prole
Posts: 47
Joined: Fri Dec 14, 2012 10:22 am
Location: Frankfurt am Main

Shader and canvas position issue.

Post by Cucurbitacée »

Hello there,

At the moment I'm trying to clone Nebulus, a game that I loved on my C64. Like most I do, it won't go very far, but it's still interesting on a learning point of view.

Anyway, the game features towers in the middle of the water, and I'm trying to make a mirror/wave effect. For this I'm toying with a shader found in the topic "share a shader".

Here the code at the moment:

Code: Select all

extern number time		= 0.0;
extern vec2 resolution	= vec2(1024, 600);
uniform sampler2D tex0;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)

{
    vec2 halfres	= resolution/2.0;
    vec2 cPos		= pixel_coords.xy;
    cPos.x 			-= halfres.x;
    cPos.y 			-= halfres.y * 2.0;
    float cLength	= length(cPos)*1.5;
	vec2 uv			= pixel_coords/resolution-(cPos/cLength)*sin(cLength/30.0-time*5.0)/50.0;
    vec3 col		= texture2D(tex0,uv).xyz;
 return vec4( col, 1.0 );
}
I have a canvas that I draw twice, one above the other, applying the shader on the botttom one, with this code it renders good:

Code: Select all

love.graphics.setShader(fx.pulse)
love.graphics.draw(game.canvas, 0, 0)
love.graphics.setShader()
love.graphics.draw(game.canvas, 0, -500)
Image

But if try to change the position (0, 0) from the canvas that has the shader effect, for example like this:

Code: Select all

love.graphics.setShader(fx.pulse)
love.graphics.draw(game.canvas, 0, 200)
love.graphics.setShader()
love.graphics.draw(game.canvas, 0, -300)
Image
The canvas moved, but the content stayed in the same position. :huh: So what am I doing wrong there?

Thanks. :nyu:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 43 guests