- Home /
Glow/Bloom replacement shader alpha problem
I wish to add some object specific glow/bloom effects to my game for things like energy beams, special items and health pickups. I have created a heart (health pickup) that utilizes vertex displacement to give it a neat dynamic rippling effect as well as an overall heartbeat.
I then have a replacement shader that looks for tag "glowable" for items to render. This leads to ALL other render types not rendering, and my glow appearing "through walls".
This really leaves me with two problems.
1. Glows appear on top of everything, of course.
2. My override shader is going to try to make every "glowable" object beat like a heart, rather than obeying each item's unique vertex animations.
Does anyone know if there is a way to directly inherit deformed vertices inside a replacement shader? I am able to access property values and textures, but for the life of me I can't find a way to say "please inherit my source shader's vertices." Also, I'm considering trying a #if defined(IS_HEART) in my replacement shader to attempt to distinguish between object types, but I'm afraid this will be inefficient.
Is there perhaps just a better way to approach this? Thanks very much for any insight you may have.
In case it helps, I was starting from the method from this video: https://www.youtube.com/watch?v=SMLbbi8oaO8
Update: I've made some progress. I found that rather than adding a new keyword of "glowable" I should instead give it a custom rendertype like "RenderType" = "GlowableHeart" or "GlowablePowerup" or just "Glowable". Then, in my replacement shader I make a new subshader for each of these new rendertypes I have made up. The subshaders allow distinct shader code for each type (like the heart should beat, but a powerup would have no vertex animation, for example). Then I made a subshader of "opaque" that just renders black. This lets other geometry cover up the glow effect. Almost there!
This lead me to another problem. My main shader is a surface shader. When I created my replacment shader, I made it a simple frag shader. When animating the vertex displacement inside the v2f vert function resulted in inverted displacement, as well as it being SLIGHTLY incorrect. I inverted the movement, and ignored the slight displacement discrepancy because it is going to be blurred.
However, something is wrong with the depth pass now. When the vertex animation contracts, it causes an error and puts pieces of the heart in FRONT of other geometry it shouldn't be. As though it is poking through, when in reality it is several feet behind the geometry. My assumption is that this is a depth pass error. I have tried adding "addshadow" to the vert pragma. I have also tried making my own entry into Internal-DepthNormalsTexture, but no luck. Does anyone know what I am doing wrong? Clearly when I move vertices inside of a frag shader I am missing a step leading to errors.
I did find a workaround. I redid my replacement shader as a surface shader, recreated the same vertex animation from my main shader, and now there are no depth problems AND the profile seems to match perfectly. I imagine this isn't as streamlined as doing a simple frag shader, but it definitely works. I would still love to know how to properly do vertex animated fragmentation shaders.
Your answer
Follow this Question
Related Questions
Unity 5 2D Bloom Effect? 2 Answers
Glow Effect 3 Answers
Glow/bloom in Mobile Unity? 0 Answers
Glow and Bloom Effects on iPhone 3 Answers
2D Glow/Bloom effect 0 Answers