I've been messing around with various methods to create an energymeter-like GUI-element.
This is what I would like to generate:
As I see it, I have two options:
Solution #2 would be the best in my opinion, but how should i do this? I've tried to do this with this culling-shader, but that only generates this result:
In other words; the masking isn't happening dynamically - as when I scale it, the culling texture is scaled as well.
Can anyone help me out? Am I trying to solve this in all the wrong ways?
Thank you for your time.
asked Dec 03, 2009 at 01:36 PM
You could use the masking shader you linked to with success, but the mask texture would have to contain a ramp from white to black and you would be controlling the status (the energy percentage or whatnot) by setting the _Cutoff property of the material from a script.
Or you can forget the ramp texture and use the shader pasted below instead. :)
To use it, create a material using that shader, drop it on a quad (with good UVs of course) and assign the texture of the blue bar to it (the texture's alpha channel will be nicely taken into account as well). You can now take a look at the material in the inspector and slide the "Progress" slider to see what happens.
From a script you would control the meter by calling:
And here's the shader:
answered Dec 03, 2009 at 04:25 PM
You could create a custom mesh of a plane, and adjust the UVs to only show the relevant parts of the texture. Then you can draw that, either manually, using Graphics.DrawMeshNow, or using a normal MeshRenderer component.
answered Dec 03, 2009 at 01:57 PM
jonas echterhoff ♦♦
Hi Talemon! Maybe my answer it's a little late, but you have to replace the word "Overlay+1" in the shader with "Transparent", so your plane respect its position in the render. I hope this helps! :)
An thanks, Robert, for the shader, it's working perfectly :3