0 votes

Basically, I want to see behavior similar to this:
Description
But ironically, the attachment was captured while an error in code, when everything works all wrong.
Can I get something like this with working shader code?

What I want exactly, is to read a data from a previous shader iteration for each separate pixel (last state of the current pixel).

My code isn't complicated at all. I thought it should move the picture down and to the left every frame, but in fact it just deforms the image like shown below.


shadertype canvasitem; void fragment() {
COLOR.xyz = textureLod(SCREENTEXTURE, SCREENUV + vec2(0.1, 0.1), 0.0).xyz;
}

enter image description here

Help me please!

Godot version 3.4
in Engine by (12 points)

I was trying to achieve this for quite some time, and I got to conclusion, that shaders don't work like this. It is possible, that GPU has no option to remember previous iteration. Notice, that it is impossible to even freeze ViewportTexture. If You want to stop it for one iteration You actually have to create image from it.
However most of the times it is possible to cheese it and I think your shader idea may not require previous iterations of fragment(). Main question is - what do You want to leave trace on screen ? Sprite against background ?

Thank you for your answer. I know that functionality like this may be achieved in Unity with thing named CustomRenderTexture, which uses double-buffering to get a result of the previous iteration. In Godot, we also have some sort of double-buffering, the node named BackBufferCopy.
It's possible that I just don't truly understand how's Unity CustomRenderTexture works.

Globally, I'm trying to adapt shaders for thing they are probably not supposed to do. It is pixel-perfect simulations like Game of Life or sand physics.

Then definetely it is impossible for shaders. Even if it was possible it would be highly unoptimal to force shaders to do it instead of CPU. Game of life is basically a tilemap, no shader.

But maybe You can use something simpler :
https://godotshaders.com/shader/2d-motion-blur/

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.