0
votes

In simple, I would like my custom shader to have access to its own output during the last frame in order to have a pseudo-motion blur through color accumulation. Although motion blur isn't the correct term at all.

Consider the following: I have a mesh with a mostly transparent texture. The texture offset constantly changes. I would now like to build a shader with which the texture, instead of jumping, slowly fades from the locations it has been at. A full-screen blur effect will not do; the blur has to remain only on the object and needs to be camera-movement independent.

My idea so far has been to define a RenderTexture that would contain the generated texture during the last frame, but since RenderTextures are rendered by a camera which, since all I would like is the mesh-specific texture, I wouldn't know how to implement.

I have also tried to use GrabPass { } in the shader, however that again seems to grab the entire rendered screen rather than the texture.

I may be misunderstanding how shaders work; If rendering the entire screen is the only option, then I could assign my material to a plane and render the texture that way, however I am unsure how, or rather: where in my code, I would do that. Creating a primitive plane as well as a camera just to get a shader to work also seems like it'd be a lot of things required for an effect that, initially, I thought simple to implement. shrug

Any help or pointers would be much appreciated,

- s_m_w

Edit: Here is a very quick mock drawing of what I would like to achieve:

Mock shader

I achieve the current effect by manipulating the texture offset. The "blur" in the second effect needs to be independent from camera movement.

1
Can you draw a mocking of the effect you would like to achieve? I fail to imagine the desired effect... Or explain it in more detail?Thomas Hilbert
@ThomasHilbert I have added a quick sketch that hopefully explains it betters_m_w
Can the object itself move over the screen or will it remain at a constant position relative to the camera? Can the object be covered by other objects that move between the object and the camera? What would happen then?Thomas Hilbert
The object can move and will not remain constant relative to the camera much and yes, it can be covered, in which case it should simply be overlappeds_m_w

1 Answers

1
votes

I think you'll have to render the effect onto a RenderTexture. You can create a Camera in code. You can set its render target to your RenderTexture, and you can conveniently render fullscreen quads using OpenGL commands (GL class). Basically, you can set up the complete effect rendering infrastructure in code.

Frame 1: Set EffectShader source texture to RenderTexture1. Render onto RenderTexture2. Use RenderTexture2 to shade your object using ObjectShader.

Frame 2: Set EffectShader source texture to RenderTexture2. Render onto RenderTexture1. Use RenderTexture1 to shade your object using ObjectShader.

Repeat.