• Shaders
  • sampler2D does not match captured viewport texture

https://1drv.ms/u/s!Aup_NDH7UAIvg6cB6EMyyUdUHqpkOQ?e=DtL5cM://

The little project in the link above has a shader on a sprite that copies a sampler2D texture over the sprite, but offset by 1 pixel to the left, it also draws a blue area on the right of the screen. The main GDScript code grabs the texture from the viewport that the sprite is on each frame and sends this back to the shader as the sampler2D.

The effect should be that the blue area on the right gets dragged across the viewport. What actually happens is that the blue gets copied a bit darker each time (this seems to accelerate exponentially as it gets darker) until it is black. If the blue colour is full blue (.b = 1.0) then all works fine, but smaller numbers (eg 0.99) cause it to get darker when copied.

I have tried changing the type hints on the sampler2D and the flags on the images in the GDScript, none has any effect.

I did think it might be a rounding issue from the difference between floats and 8 bit colour values, but the exponential nature would seem to deny this.

Any idea why this happens? Can it be fixed?

What version of Godot are you using? I tried the project using Godot 3.2.3 RC5 on Windows 10 and it seems to be working as expected with colors below full blue. I do not know how fast it turns to black, but I've left it running for a minute or so and its still looks like the same blue color.

Sorry, should have put some info on that. Yes, 3.2.3 for me too (stable official), also Windows 10 home and GeForce 2060RTX super.

Interesting that it works for you, it only takes about 10 pixels to go to black on mine. I am pretty sure it is the sampler that is the issue as if I copy the texture to a sprite (offsetting the sprite I can get the same scrolling effect) it works fine.

I wonder if it is a graphics card setting, like anti-aliasing or somesuch?

I have used the sprite method in my project now, which works nicely and I suspect is going to be more consistent across different systems.

Thanks for trying this out :)

Write a Reply...