Issue with shader and changing variables programmatically

Godot Version

4.3

Question

Hey guys. I am new to godot and shaders and textures but I want to try out new things. As a first project I wanted to write a game that has a starfield in the background. For the starfield I found a great tutorial using shader and noise texture. The shader itself works fine and looks ok for the first version of the game. A starfield should have movement in it so I tried to set a speed variable in the shader from the scene that holds the starfield, what works more or less. The starship is controlled via cursor keys. Hitting the up key increases the speed, hitting the down key decreases the speed. This should reflect in the shader.

Now the issue: If I hit the respective keys, the shader starts to go crazy and seems to “race” imensely fast. If I release the key, the speed is set to the expected speed and the “animation” looks as I expect it to.

The project can be found here: Stefan Michalsky / Astro Racer · GitLab

Perhaps someone has time to check whats going wrong? That would be awesome. The shader is in the background scene. The code to connect the ship and the background is in game.

Regards
Stefan

Looks like one of my shaders. :sunglasses: But I didn’t solve this issue yet. Maybe it’s something Godot-specific? I’ll try to find out.

Indeed, I saw your video the last night and wanted to try out directly. Unfortunately my addition didn’t work as intended and my debugging-skills with godot are not very good yet.

I tested the project and seems to be an issue with the shader, i recommend you use the shader at speed zero and use a Parallax2D node to make the movement (this needs Godot 4.4 dev 3 or higher to work):

@matheusmdx Your suggestion would require to implement an endless scrolling on my own, right? Just to make it clear on my side… :slight_smile:

But that is exactly what Parallax2D do, just set the mirroing size, set the autoscroll based on the speed and done, 2m setup

Ah, ok. Then I’ll check out that node type. I thought it’s just taking over the positioning stuff. Seems there is a lot to learn regarding Godot…

Thanks for the hint.

The video show everything you need to do

Unfortunately I can’t play the video. My system says it doesn’t know the codec.

Maybe you can see it now

Hm, it seems I need to reinstall a few components on my system. I’ll try to get the video running. Thanks a lot for your support.

Strange, the first one i understand you can’t see because is in h265, but the second is in h264. Anyways, if you dont see now is totally your pc fault: https://youtu.be/yHUx_geCqKI

After fixing the packages I can see the videos now. Thanks a lot. I’ll try to reproduce and understand your solution :slight_smile:

@matheusmdx @FencerDevLog Thanks for helping out. I now refactored my approach and use Parallax2D successfully.

The issue with the shader “scrolling” isn’t fixed yet, but I am happy with the solution though.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.