Inverting Colors Inside a Material (UE4)? - colors

I'm attempting to write a material that will invert any color inside it, but I'm not sure where to start. For instance, half of that red cube should be inverted to blue once it enters the space of the material. I would assume it has something to do with modulating (blend type)? If anyone could give any assistance, I would be appreciative.
What I Have So Far

Yes, you'll need some blending but it's the same as using a PostProcess material as a filter inside a PostProcess volume. That way you create a way to manipulate buffers as a postprocess effect.
Material-wise, inverting the colors (which I'm assuming it means using the opposite color in the spectrum) simply feed the color to a 1-X material node and pass on the result.

Related

How to detect that a sprite has encountered a color in pygame

I want to detect that the sprite has encountered a color in pygame, which function should I use to achieve this function.
Though it is possible to get the color at any point in the surface that you want to check against using get_at() (docs here). You would need to find the new area that your sprite covered that it did not cover last time and check every pixel in that, and if other things were moving around you would have to check if your sprite now overlapped with any of those area and check that. Or you could decide that was too complicated and just run through every pixel under your sprites location (without you sprite drawn yet) and check for that color.
It is possible, but would likely not be very fast.
An alternative is if you know where those colors are you can mark those areas using rects, circles, sprites or masks (see here and here) that you can check against. That is usually much faster. These do not have to be drawn and so would be invisible. They would just be used to mark areas for the collision check.
If you do not know exactly where the colors are in the background or the other images, you can create masks based on the colors in them using pygame.mask.from_surface() or pygame.mask.from_threshold() (docs here and here).

How can I even out colors so text is readable against them at any given hue and lightness?

Anyone who frequently does UI likely knows that for a given color hsl(H, 100%, 50%) (syntax is CSS) not all values of H will produce a color suitable to be placed under arbitrarily black or white text. The specific fact I'm noting is that certain colors (green) appear especially bright and other (blue) appear especially dark.
Well suppose I would like a user to be able to enter a color hue and have the color always appear with a consistent brightness so that one of either white or black text is guaranteed to always be readable on top of it. I would like all colors to also maintain the most vivid level of saturation they can given the constraint on brightness.
Here is a quick example of what I've tried so far. I start with a grid of squared like this rendered using a bunch of html div elements. Essentially these are hue values roughly from 0 to 360 along the horizontal axis and lightness values from roughly 0% to 100% along the vertical axis. All saturation value are set to 100%.
Using a JS library library called chroma.js, I now process all colors using the color.luminance function, whose definition seems to be to do what I'm looking for. I just passed the lightness of the hsl value in as the parameter to the function. I don't know for sure that this is the best way to accomplish my goal though since I'm not familiar with all the terminology at play here. Please note that my choice to use this library is by no means a constraint on how I want to go about this. It just represents my attempt at solving the problem.
The colors certainly now have a more consistent lightness, but the spectrum now seems particularly vivid around the orange to cyan area and particularly dull everywhere else. Also the colors seems to drop very quickly away from black at the top.
Hopefully this example helps a bit to express what I'm trying to accomplish here. Does any know what they best way to go about this is?
I found the solution! Check out HSLuv. It balances out all the hues in the spectrum so that at any given saturation and lightness, all hues will have the exact same perceived brightness to the human eye.
This solved my problem because now I can just set my text color to white (for example) and then as long as the text is readable against a certain HSLuv lightness it is guaranteed that it will be readable against any hue and saturation used in combination with that lightness. Magic.

Color scheme trasformations

Given a set of colors, say colors on this webpage, and another palette of an equal number of colors, what would be a good way to map the former to the latter while:
preserving contrast between individual colors
preserving the relative intensity of the colors (not sure how important this would be)
Essentially, this webpage should be rendered in the new color palette while still legible.
What color space would be appropriate for this task?
Can you also point me to any related work?
Update: The mapping can surely be done manually but I intend to automate the mapping for any given set of colors and palette and so I'm looking for an algorithmic approach or rather an understanding of what properties need to be preserved in favor of legibility and beauty.
In general, I think it is better to transform colours into HSV, and then transform hue (and than back to original encoding). We use brightness (dark elements) and saturation (unselected buttons, etc) as semantic element, so it is better to preserve it.
In such way you maintain also the contrast.
But: normal HSV is not really a true physiological HSV: the most used formula are just set for gamut of RGB, and to give maximum range and being the parameter independent. On reality maximum V depend on H (if one want to compare V between different colours), and other effect.
And These and other visual effects (not in any HSV) will effect the visual result, so you may do it programmatically (e.g. JavaScript which read and override all colours, but this is a topic for other questions), but if you do a website professionally, you must still manually tweak some elements.
Note: last version of CSS, and many CSS preprocessors allow you to use HSV values, and apply programmatically saturation, light and hue changes.

SVG filter that highlights a path upwards (image sample provided)

I'm trying to highlight the countries of a svg map in a specific manner.
This is the result I want to achieve:
Before
After
Using the drop shadow technique provided here: https://stackoverflow.com/a/6094674, I was able to obtain a small relief effect, but I think this might not be the correct direction.
How should I approach this?
This gives you a shadow effect, which is fine. But if you want a true relief effect that works for all shapes (even fiddly ones with thin horizontal lines), then you'll need to composite multiple copies of the SourceGraphic, incrementally offset in y once for each pixel. Alternatively, you can use lighting primitives and some fancy compositing.

SVG plot from point-value pairs

I need to write some code (for a web.py webapp with a straight-HTML/JS client) that will generate a visual representation of a set of point-values. Each point has an X and Y coordinate, and the value is an integer. If I can use SVG to do this, then I can scale the image client-side with no extra code. Can I actually do this? I am concerned about a couple of things:
The points don't necessarily have any relation to each other. They aren't necessarily in a grid, nor can we say how many points are nearby, etc.
Gradients are primarily one-direction, and multiple gradients on the same shape seems to be a foreign concept.
Fills require an existing image, at which point, I'd be better off generating the entire image server-side anyway.
Objects always have a layering, even if it isn't specified, which can change how the image is rendered.
If it helps, consider a situation where we have a point surrounded by 5 others, where one of them is a bit closer than the others (exact distances and sizes can be adjusted). All six of the points have different colors (Red, Green, Blue, Cyan, Magenta, Yellow, with red in the center and Yellow being slightly closer), and the outer five points are arranged roughly in a pentagon. Note that this situation is not the only option, just a theoretically possible situation.
Can I do this with SVG, or should I render an image server-side?
EDIT: The main difficulty isn't in drawing the points, it is in filling the space between the points so that there is no whitespace, and color transitions aren't harsh/unpredictable if you know the data.
I don't entirely understand the different issues you are having with wanting to use svg. I am currently using the set up you are describing to render X-Y scatter plots and gaussian curves and found that it works great.
Regarding the last point about object layering, you have to be particularly careful when layering objects with less than 100% opacity which are different colors. The way the colors "add" depends on the order in which you add the objects to your svg drawing.
Thankfully you can use different filters to overlay the colors without blending them. Specifically I am using the FeComposite filter element. There is a good example of its usage here:
http://www.w3.org/TR/SVG/filters.html#feCompositeElement

Resources