Page 1 of 1

Shader outruns the player

Posted: Tue Apr 21, 2020 7:36 am
by yoyohoho
Hey guys!

I'm playing around with shaders for the first time and though it's challenging it's a lot of fun.

I'm creating a 2D platformer, where the setting is a cave so I thought it would be neat to have the lightning only just around the player.
However, I'm having a problem where this eclipse of light simply outruns the player as the map starts scrolling (look at the GIF):
The attachment shader_problem.gif is no longer available
I have no clue why this is. I'm using a variable called playPosition that simply tracks the position of the player on the x-axis.
It's almost all in my main.lua which I have enclosed as well if you want to take a look. The shader-code is in the top while the shader is being drawn in love.draw.

I really hope one of you is able to help me. :awesome:

Re: Shader outruns the player

Posted: Tue Apr 21, 2020 7:47 am
by sphyrth
Before people start requesting for your love file, I think the problem has a connection with the camera.

Looking at your gif, the shader begins to have a problem the moment the camera begins scrolling with the player.

Re: Shader outruns the player

Posted: Tue Apr 21, 2020 8:04 am
by pgimeno
Yeah, it looks like a double transformation.

main.lua is not there, by the way. The forum software is bugged when it comes to multiple attachments. It's not possible to be more specific without the code, sorry.

Re: Shader outruns the player

Posted: Tue Apr 21, 2020 8:18 am
by yoyohoho
sphyrth wrote: Tue Apr 21, 2020 7:47 am Before people start requesting for your love file, I think the problem has a connection with the camera.

Looking at your gif, the shader begins to have a problem the moment the camera begins scrolling with the player.
Just a little question, when you say that people are going to request my .love file, deos that mean that I should include the entire folder with all my game files or just a distributed version of the game?

Yes, you were right. It somehow added the position of the player (player.x) to the position of the camera (map.camX) so all I had to was to subtract the latter from the prior. Thank you so much!

Re: Shader outruns the player

Posted: Tue Apr 21, 2020 8:20 am
by yoyohoho
pgimeno wrote: Tue Apr 21, 2020 8:04 am Yeah, it looks like a double transformation.

main.lua is not there, by the way. The forum software is bugged when it comes to multiple attachments. It's not possible to be more specific without the code, sorry.
That's good to know, thanks. I figured it out (look at my reply to the first post), I'm not sure what a double transformation is, but it sounds like that might have been the issue.

Re: Shader outruns the player

Posted: Tue Apr 21, 2020 8:28 am
by pgimeno
yoyohoho wrote: Tue Apr 21, 2020 8:18 am Just a little question, when you say that people are going to request my .love file, deos that mean that I should include the entire folder with all my game files or just a distributed version of the game?
It means something we can run and test, in order to be able to debug ourselves. The idea is that if you have the code and can't figure it out, you can't expect others to figure it out without the code. There aren't many cases such as this in which the problem is evident from the screenshot. Also, not many people post a screenshot.

Dummy replacement images would be OK, if it is runnable. A minimal .love file with just the code necessary to be able to see the problem, even without images, would also be OK.

Re: Shader outruns the player

Posted: Tue Apr 21, 2020 8:37 am
by yoyohoho
pgimeno wrote: Tue Apr 21, 2020 8:28 am
yoyohoho wrote: Tue Apr 21, 2020 8:18 am Just a little question, when you say that people are going to request my .love file, deos that mean that I should include the entire folder with all my game files or just a distributed version of the game?
It means something we can run and test, in order to be able to debug ourselves. The idea is that if you have the code and can't figure it out, you can't expect others to figure it out without the code. There aren't many cases such as this in which the problem is evident from the screenshot. Also, not many people post a screenshot.

Dummy replacement images would be OK, if it is runnable. A minimal .love file with just the code necessary to be able to see the problem, even without images, would also be OK.
Gotya, that makes perfect sense. I did include the main.lua file but I guess you couldn't see it due to the bug that you mentioned. I'll make sure to include it in future posts :)