Hi Unity Community!
I hear great things about you, so I figured you might be willing to help me with my Sprite effect.
I’ve only been using Unity and C# for a couple of weeks, and for my first project, I decided to create this sprite effect - the effect is pretty simple; it basically creates visual “echos” of a sprite, which are then tinted and/or scaled and faded out over time, with various tweak-able parameters (echo lifetime, time between echos, color etc.) - it basically looks like this:
Currently, it works great, the effect does pretty much exactly what I want it to do - it is, however, very CPU heavy. At the moment, every single echo is a separate GameObject! Not only that, but all the calculations handling tinting/scaling/alpha-fading are done by the CPU - there must be a better way to do this!
So I started looking more into it, and found some ‘candidates’ for optimization
- Writing a custom Shader
It would be nice having a shader offload the calculations for scaling/tinting/alpha-fading to the GPU. The issue with this is, that I don’t know how to handle the positioning - I need to somehow perserve the Texture of the Sprite I want to draw, but I need to discard/replace the position information - I’ve never written a shader before, and looking at default shaders, I’m having trouble wrapping my head around how to do this (the position of a Texture seems to be embedded in the Texture?)
- Blit / CommandBuffer
I would like to draw the echo Texture/Sprite directly to the screen, instead of having to use GameObject’s - it seems like unnecessary overhead (I wont ever need to add stuff like colliders or scripts to the echo’s - they’re supposed to be just visual, not actual objects) - I have, however, not managed to successfully make Blit actually draw anything (I DID however manage to crash my GPU driver but putting a Blit call inside FixedUpdate! WOHO!) - but as far as I can read, Graphics.Blit is indeed what you need if you want to draw directly to the screen (there’s also Graphics.DrawTexture, but it seems to be for GUI stuff?)
I’ve attached the script below (including editor-script) - If you would take a look at it, and post some feedback, I’d be very grateful - If you have any ideas or thoughts on how to optimize it, or can point me in the right direction, I’d be even more so!
2520322–174682–TrailFx.zip (2.66 KB)
2520322–174692–TrailFx.unitypackage (2.42 KB)