Which is undesired. What I would like to happen, is for just the circle to fill, I don’t want to draw outside of the circle, just within it…I am using the following (short) code in the OnGUI() method:
public Material mat;
public Texture foregroundTexture, rightCircle;
void OnGUI()
{
if (Event.current.type == EventType.Repaint)
{
mat.SetFloat("_Cutoff", 80);
Graphics.DrawTexture(new Rect(971f, 0, 58, 30), foregroundTexture, mat);
// 30 is what is displayed, ideally I want to fill it from 0 to 45.
Graphics.DrawTexture(new Rect(971f, 0, 58, 45), rightCircle);
}
}
I am using three textures, a material shader which is set to transparent/cutout/diffuse, a foreground texture (in the shape of a rectangle, and a circle texture (which is a cropped circle with a transparent background), the circle and foreground textures should be attached and visiable below.
If someone could help me draw within the circle and not outside of it that would be sooo awesome as this is the last stage of my in-game GUI concept development!!
Which would be nice, because I could use my value (that increments based on certain conditions) and add it to the height that is being divided. But the result is yet again undesired:
As you can see the circle is red, but I need to fill the inside of it…help grr at this concept with me!
EDIT – I am just trying to find ‘the’ efficient way of doing this. Sure, n e one can make 100 horizontal texture ‘bars’ that do not exceed the circles image and then draw each respective ‘bar’ based on a certain value . . .
If you’re using a cutout shader, you should place the circle shape in the main texture’s alpha channel. This will only render the texture within the circle (or whatever other shape you draw there). Draw the circle in pure white and the background pure black and set the cutoff value about halfway.
Don’t draw it as a secondary image; add the red fill to the image you’re using with the cutout shader, and make sure you have a gradient inside the circle in the alpha channel of the image. The ‘Alpha cutoff’ will control how much of the circle’s interior (the red area) is visible.
I don’t understand how to ‘Add redfill’ (or any other color fill for that matter) to the cutout shader. By ‘redfill’ I presume it is the MainColor to the cutout shader. I don’t know how to proceed, could I have a little more information on adding a fill to a cutout shader?
However, I did manage to create the gradiant within the circle texture. The outline of the circle is visiable and the area within the cricle is not, indicating that my gradiant was successful.
I didn’t say add red fill to the shader, I said add it to the image. You should have an image that, with no alpha channel, would be a red disk with a black border; with the alpha channel, that would show as a black circle filled with a gradient of red to transparent.
Okay, I think i see now. I need to have a gradiant image (color is user perogative) that is within my shape (in this case a circle). When this image is applied to a shader, I can increase the Alpha Cutoff and the red will slowly start to fill the circle, and then by decreaseing the red will gradually shrink.
Which is not happening. I believe that I have done my fill correctly for the circles image.
There was no gradient visible in the last image you posted a screen-shot of; have you updated it since? And if so, what does it look like (and how is your material setup) now?
The gradiant should be visable now. I am using Corel paintshop pro X3. Below is an actual gradiant and NOT just a color:
I then make a more transparent gradiant and change (overwrite) the fill (as you see above) to below:
and save it as the alpha channel:
I then go to Unity and see that the image (above) is in as the material. I try to use arbitrary values for SetFloat to control the alpha cutoff in real time, but nothings happening.
public Material mat;
void OnGUI()
{
//...
rect = new Rect(973f, 0, 58, 45);
mat.SetFloat("_Cutoff", 80);
GUI.DrawTexture(rect, mat.mainTexture);
//...
}
However, when in the inspector, If I slide the slider from rightmost to left we see that the circle does fill:
Quite smoothly actually. But it doesn’t seem that I control it to see the results (via mat.SetFloat()) as I see them within the inspector…
There seems to be a disconnect here; using a cutout shader will only work if you’re using the shader… Calling GUI.DrawTexture() doesn’t use the shader, so it wont be affected by the shader’s cutout value.
Apply the material you created to a game object (e.g. a simple plane) instead. Again, only objects rendered using that material will be affected by changes you make to the material’s shader.
public Material mat;
void OnGUI()
{
rect = new Rect(973f, 0, 58, 45);
GUI.DrawTexture(rect, rightCircle); // Encompass our shader fill
mat.SetFloat("_Cutoff", 255 - Value_that_increments);
if (Event.current.type == EventType.Repaint) {
Graphics.DrawTexture(rect, mat.mainTexture, mat);
}
}
But, I am getting a lot of run-time errors. Is their a method that I should be including the Graphics.DrawTexture() functions within? Rathar than OnGUI?
I also found, that when in game:
1)The color is completely black.
2) The circle fills from top to bottom, I need it to fill bottom up.
I don’t have Pro, so I can’t help with Graphics.DrawTexture() issues; but problem 2 is trivial: just flip your image so the gradient is in the other direction.