Shader affects image in other node but not parent node?
Asked Answered
M

6

0

Hello,
I've got this really weird behavior with shaders. There is the following setup

  • ParallaxBackground
  • - ParallaxLayer_1
  • - - TextureRect_1 (solid image)
  • - ParallaxLayer_2
  • - - TextureRect_2 (image with transparency)

Now at some point the two parallax layers are going to become visible and start scrolling. This is to create the illusion of fast motion.
To add to the illusion, I wanted to blur TextureRext_2. So I applied a shader to it inside a material, as is stated in the documentation.
The code of the shader can be found here:
https://pastebin.com/YjQ5Qxv8

Now here's what happens.
1) TextureRect_2 completely disappears. It is no longer visible as soon as the shader is applied to it.
2) TextureRect_1 becomes blurry.
3) If I apply the shader to TextureRect_1 it also disappears.
So how does this work? Do I need to create a separate texture rect for just the shader and it will affect everything before it?
I created a TextureRect_3, added the shader to it and placed it below TextureRect_2, in the same ParallaxLayer and a separate one, but that didn't do anything.
I thought a shader applies to its parent object. Did I misunderstand? If so, why did placing the TextureRect_3 not work?
Is something wrong with the shader code?
What is going on?

Mumbletypeg answered 19/8, 2022 at 11:7 Comment(0)
A
0

Hi,

I tested a quick scene with the same setup, using the shader from
https://github.com/godotengine/godot-demo-projects/blob/master/2d/sprite_shaders/shaders/blur.shader
and it works fine

Can you try to change SCREEN_TEXTURE to TEXTURE and SCREEN_UV to UV ?

Aestivation answered 19/8, 2022 at 12:52 Comment(0)
M
0

Aestivation Okay, so changing SCREEN_UV to UV doesn't do anything. Changing SCREEN_TEXTURE to TEXTURE makes the layer visible and the shader is now applied to the correct object. However, anything that is supposed to be transparent is now white.

Mumbletypeg answered 19/8, 2022 at 16:8 Comment(0)
E
0

Mumbletypeg Hmmmm.... when I tried that shader in a pong demo with a colorrect, i noticed the thing goes completely black when the "samples" in the shader param is at 1. Did you check the params?

Honestly, this shader isn't terribly great for motion blur. I am betting you could find a better one.

Edwinaedwine answered 19/8, 2022 at 17:53 Comment(0)
M
0

Vortical Okay, thank you. Thanks to the shader you posted it became obvious that there's an issue in the code. Yours works fine. I have no idea what is going on as I don't really know anything about shader coding. However, I was at least able to combine the two into one that works. Code is here:

Santanasantayana Truth is I couldn't tell a good shader from a bad one. Don't know enough about themn. If you know a better one that does directional blur/motion blur, please tell me.

Mumbletypeg answered 19/8, 2022 at 19:20 Comment(0)
E
0

Mumbletypeg sadly you kind of have to just play around with them. GodotShaders.com has many good one though.

Edwinaedwine answered 19/8, 2022 at 19:55 Comment(0)
M
0

Edwinaedwine Thanks for the tip. I'll check if I can find one that fits. If not... it looks okay so far and I'm not gonna mess about with shaders at this time. I don't think I'll need any more shaders for the game. 🙂

Mumbletypeg answered 20/8, 2022 at 1:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.