Access last value of pixel shader / Creating afterglow or decay effect


#1

I’m working on a pixel shader that is revealing an object based on its world position. That part is working fine.

I would now like to add sort of an afterglow or decay effect to it. So the object should lose its colour (fade to black/transparent) slowly instead of instantly. Very much like what you can see here: https://youtu.be/XO4cMHnUs1g?t=222 only instead of a 2-dimensional surface using a 3-dimensional object and basing the colour on its fragments world coordinates.

The problem is that I don’t know how to access the previous value of the pixel shader. I might have to feed it back into the shader somehow. But in what format - a texture or some sort of buffer? How do I do this?

Is there an example that does something similar and I could take a look at?

Thanks a lot in advance!


Output multiple textures from shader
#2

Well you can try echo effect
Also a ringbuffer in contribs or in the Advanced Shaders there is Compute Texture Queue in examples (witch is a bit complicated but exactly what you want)

What you do is a texture array and then you blend it thru the function…


#3

Thanks, @antokhio.

Don’t think I can do this based on the rendered texture, as the object is moving as well.

Where can I find this?

Thanks, I think I know what you mean and am going to get started on that. Although, I’m pretty sure I don’t know all of the steps yet. :)


#4

Solved it!

I’m first rendering a UV texture based on world position blended with the previous output texture via FrameDelay. Then rendering the geometry again using Constant and this UV texture.

image

reveal geometry with afterglow.zip (9.5 KB)

It creates a texture of a certain size which is independent from the renderer’s resolution. Not sure if this is the most elegant solution. Happy to hear your thoughts.

Thanks for your help, @antokhio.


#5

Okay, this only works for a quad or grid unfortunately.

I’m doing this in the first shader which seems to work in that case:

output.posScreen = input.posObject * float4(2,2,1,1);

What needs to be changed it make it work with any geometry?

Thanks a lot.


#6

I’m not sure i understand exactly what you are after.
Normally mesh has it’s UV coords, witch is 2d plane try looking this:

i guess i need to see an example…

from what i’m guessing you want to reveal mesh by some sort of 3d function with feedback…
in that case you need to raymarch your function against mesh (try look here https://vvvv.org/contribution/vvekend-vvorkshops-raymarching-basics)
but it will be density function in your case… whitch is more complicated

also this might give you some hint https://vvvv.org/contribution/texture-noise-3d


#7

Thanks, @antokhio.

I’m sorry if I’m not using the right terminology here and this might be confusing.

But you got me. This is what I was looking for. And it basically does it for me but I think there are some more problems with the UV coordinates as I get different issues or glitches based on the geometry. I’ve made some examples.

Teapot looks like - with glitches:
image

should instead look like :
image

Cylinder looks like - caps are weird:
image

should instead look like:
image

Box looks like - seems to apply same texture to all sides:
image

should instead look like:
image

This is the example patch I’ve used for testing:
sine Reveal object UV.zip (18.8 KB)