I am trying to minimize SetPass calls in Unity canvas.
Consider the following example:
The rendering in canvas happens layer by layer. The rendering sequence can be like the following:
Red squares (+1 set pass call)
Text "1" and yellow squares (+2 set pass call)
Text "2" and pink square (+2 set pass call)
Text "3" (+1 set pass call)
Or, it might be a little better:
Red squares (+1 set pass call)
Yellow squares and then text "1" (+1 set pass call)
Pink square and then texts "2" and "3" (+2 set pass calls)
Because of this, drawing is switching from default image material to text material and back. The result of this drawing will produce at least 4 draw calls, instead of 2. Even though only 2 materials are in use. This example also assumes that Red, Yellow, and Pink squares weren't batched.
Question: is there a way to ensure that text will be always drawn on top?
Notes:
TextMeshPro UI material (mobile-overlay) doesn't help here.
Unity 2019.3.12.f1
All texts are actually placed as last layers (e.g. there is nothing drawing on top of them).
Batching helps sometimes. However, complex UI might use several materials. Since my intention is to always draw text over everything, isn't there a general solution for this?
Z-order makes drawing order even worse and switching between materials happens more frequently.
Related
My guns have a certain range. When hovering over one I want to demonstrate what that means. So I've added a 3d-object (a flattened cylinder) which I want to show/hide onMouse-enter/leave.
But first I need it to be transparent - I've searched and found how - It's materials rendering mode must be transparent, and the color must have an alpha value (here 128).
But it looks VERY SOLID BLACK to me...?
I need to make syntax colors lighter (for dark themes). Globaly or not.
Yes, in fact there is a dimmer switch that affects all faces. There are in fact several such dimmer switches: (1) to dim/brighten, (2) to heighten colors or make them more washed-out, (3) to move toward or away from a particular hue, or (4, 5, 6) to make them all more - or less - red, blue, or green.
All of these dimmer switches that act on all faces together are rolled into a single command -- well two commands: one for the face backgrounds (doremi-all-faces-bg+) and one for the face foregrounds (doremi-all-faces-fg+).
These are two of several Do Re Mi color incrementer commands. The others work on individual faces or on frame backgrounds and foregrounds. All of these commands work the same way. After invoking the command (e.g. M-x doremi-all-faces-bg+):
You are prompted for the color COMPONENT to increment/decrement (a character):
`r` - red
`g` - green
`b` - blue
`h` - hue (basic color)
`s` - saturation (purity)
`v` - value (brightness)
`R` - red, green, and blue, at the same time
`H` - hue, saturation, and value, at the same time
`R` and `H` increment all components of the respective color spaces,
according to the value of INCREMENT.
You can at any time change, to increment/decrement a different color
component (r, g, b, h, s, v, R, or H). For example, you can type `r`
and use the arrow keys or mouse wheel to change the red component,
then type `b` and use the arrows or wheel to change the blue
component, and so on, all in the same call.
For desaturating, that is, to render all colors more pale or washed-out, you just use s.
See Angry Fruit Salad for more information about this synchronized saturation dimming of all faces.
You can use the dimmer switch whenever you want, if you want more or less washed out colors. Or you can use it to find a good combination and then save the current face values in your custom-file (or your init file, if you do not have a custom-file, which you should have).
More likely, you will want to experiment by "dimming" and then follow that up with some customization of a few individual faces. For that, you can use the similar dimmer switches for individual faces (doremi-face-bg+ etc.). Incrementing qualities of all faces at once is a bit rough-and-ready. But for something like desaturating, it is very quick and does the job well.
Note that the face changes made using Do Re Mi commands are not saved automatically. User option doremi-customization-status controls how Customize views such changes.
By default, Customize sees them as if you had made them using the Customize UI. In this case, you can use command customize-unsaved to open Customize for them all, where you can save individual changes or all of the together.
If you set option doremi-customization-status to value outside then Customize sees the changes instead as having been made outside Customize. In this case, you can use command customize-rogue to open Customize for them all.
If you set the option to anything else then Customize ignores the changes altogether - you cannot use Customize to save them until you reapply them using Customize itself or a command such as set-face-foreground. This option setting can be useful if you just want to experiment and do not want Customize to see what you do.
I have some textures containing some transparency parts (a donut, for example, which would show a transparent center). What I want to do is fill the middle of the donut (or anything else) with a plain white, in code (I don't want to have a double of all my assets that need this tweak in one part of my game).
Is there a way to do this? Or do I really have to have 2 of each of my assets?
First it is possible to change a transparent texture to not-transparent, if it wasn't then graphic editors would be in trouble.
Solution 1 - Easy but takes repetitive editing by hand
The question you should be asking yourself is can you afford the transition at run time or would have two sets of textures be more efficient; from experience I find that the later tends to be more efficient.
Solution 2 - Extremely hard
You will need a shader that supports transparency and that it marks the sections that have to be shaded white. That is, it keeps track of which area will be later filled with white. It is implied that since your "donut" is already transparent on some parts then it already uses that texture that has an alpha, but you will have to write your own shader mask and be able to distinguish which is okay to fill white and which is not (fun problem here). What you need to do is find the condition in which that alpha no longer needs to be alpha and has to be white. Once the condition is met you can change the alpha of via the Color's alpha property. The only way I see you able to do this is if there is a pattern to the objects, so that you can apply some mathematical model to them and use that to find which area gets filled. If the objects are very different then the make two sets of textures starts to look more appealing.
Solution 3 - Medium with high re-use value
You could edit the textures to have two different colors, say pink and green. Green is the area that gets turned white and pink is always transparent. When green should not be white then it is transparent. You would have to edit your textures by hand as well.
I was staring at my code thinking how boring the text looks.
All I see is text, with no visualizable structure.
Visualizable structures would be awesome:
Background graphics such as 3D half-pipes on edge connecting the opening and closing brackets of loop scopes, nested in 3D to show how deep the loops are nested.
Wires with arrows along them showing where a goto statement points, with a code section highlight (or preview if out of viewport) of the target label.
Conditional blocks could be rendered to show the "true" code in a positive color and the "false" code in a negative color, and mousing over the background at the left edge could reveal a preview of the condition statement for that block (appended with "== true" or "== false" depending on the code context).
Icons for Types, that show up in front of variable names so you know what type they are.
Change the background of the method, displaying tiled locks or keys, depending on whether you type public or private in front of the method (a nice indicator of the default if you fail to specify either).
Is there anything out there that illustrates code like this?
I don't mean analytically generated graphics representing the code or algorthmic structure in some way. Rather, I mean something that actually illustrates the editable code in place.
I need to place labels with a transparent background over a variable-content UIImage. Readability will vary significantly depending on the relationship between the color of the label's text and the color/luminosity of the area of the image displayed under the label. Since the image will be constantly changing, the color of the label's text needs to change in sync.
I have found several techniques for determining the color, perceived luminosity etc of a single pixel. However, I need to rather quickly (while a view loads) determine the rough perceived color/luminosity of an area of the UIImage under the frame of the UILabel. I presume I will also need to measure the alpha because the same color/luminosity looks different at different alpha values.
Is there a way to calculate such a value for an area? Will I be reduced to simply summing pixels? If it comes to that, is there an algorithm to accomplish this?
I've thought of two possible approaches:
Perform some "folding" operations i.e. combining pixels from one half of the area to the other half. Then repeat until I get a single value. Would this be practical? How would you logically combine pixels to average their perceived color/luminosity?
Sample a statistically significant number of pixels in the area and then combine them (somehow) to get a rough measure.
I think this problem comes up a lot these days with people being so found of customizing backgrounds. Seems like something that would be worth my time to bang out a category or class to handle this and then share it around.
What about simply outlining your text in a way that it will show on both dark and light backgrounds?
This is how it is handled in other situations where text must be displayed over a background with unknown content (for example, films with subtitles).