Achieving 1 pixel outline around sprites which changes colour depending on the background? - unity3d

Here's an example of what I mean: http://38.media.tumblr.com/aa36eac06bebe495f34046d4b2557410/tumblr_n8a8p4dkOb1s6ek46o1_500.gif
In this gif, when the character is on the dark background, his outline is almost black, whilst it retains more colour if the background he's on is the sky one. How can I achieve this in Unity? I don't think it's individual sprites

Related

Sprite-Kit: change the contact points color

The scene background color is white.
In the scene there are two sprite nodes (SKSpriteNode) sprite 1 and sprite 2 with black borders and transparent backgrounds.
sprite 2 moves.
sprite 2 reaches sprite 1 and contacts it.
What I'm trying to do is merging the two sprite contact borders when they contact each other. With other words: I want to change the color of the contact points of both sprites into the scene background color. I tried to do this with the blendMode property. But it seems that the blendMode property works only with a node and his parent.
Does the blendMode property work only with a node and his parent? If yes, is there any way to change the colors of the contact points of two "normal sprite nodes"?
Thanks for any ideas.
EDIT:
the background color is white.
each sprite is transparent and has a border with black color.
when a sprite contacts OR is moving along the border of another sprite, the black color of all contact points of both sprite borders changes to white (that is the background color). The color of all other border points of both sprites stays black.
I put another picture with more details.
Thanks in advance.
Blend mode will only blend textures together, it will not remove that black border unless you are applying something like Xor Blending. The actual sprite would blend to the destinations frame buffer, not the parent, so whatever is below the sprite at the time of rendering it.
Blending the Sprite into the Framebuffer
The final stage of rendering is to blend the sprite’s texture into its destination framebuffer. The default behavior uses the alpha values of the texture to blend the texture with the destination pixels. However, you can use other blend modes when you want to add other special effects to a scene.
You control the sprite’s blending behavior using the blendMode property. For example, an additive blend mode is useful to combine multiple sprites together, such as for fire or lighting. Listing 2-6 shows how to change the blend mode to use an additive blend.
Source: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Sprites/Sprites.html
To achieve what you are looking for, I wouldn't even mess with blending, instead have your sprite broken up into 2 sub sprites, the border, and the inside color.
What I mean by this is lets say you have a circle with radius 10 and a 1 pixel thick. We create a node, that has a child that is just the border with a transparent area at radius 10, and another child that has a radius of 9, which will be filled with white.
Set the borders zposition to 0
Set the inside sprites zposition to 10.
When 2 sprites merge together, here is how drawing will be rendered
Sprite 1 border
Sprite 2 border
Sprite 1 inside
Sprite 2 inside
This will give you the effect you are looking for with the sprites merged together.
Of course, if your inside has transparent and not a solid color then we have a
problem. (Right now you are saying your BG is white, so we do not need transarency, your circle cam be white, but if you want to put a texture on the BG, then we have an issue.)
If you indeed want to keep your circle "transparent", then what you need to do is capture the background underneath before the border gets drawn, and make that the texture of your inner circles

How to add a debossed effect to text in a highly textured image using CG-methods in Swift

I have to write some text on a custom CGRect with a highly textured in a CGContext.
This has work for dark and for light images. The texture has to be visible at the debossed letters.
Current approach
calculate avg. color of background image
darken (related to the luminance) the color
CGRect.drawText... with the ID with color of 2.
add a darker ouster shadow to text
add a light inner shadow to text
done.
Problem
My current approach works for dark, slightly textured backgrounds but it does not work for dark strong textured backgrounds.
Example usecase
Render license plates with an embossed ID for a car app.
or
Dog tags (see wikimedia)
It was a rough play with background color of the material, background color of the embossed thing and 4 different shadows.
All in all I have (sorry for that) no 'how to do it' solution. Thanks for your help.

Blending with background in cocos2d-x

I am new to blending in cocos2d-x and couldn't find much on google.
I have white background in my game and i have added red colour sprite "circle.png" on it(empty from centre region) .
Now i want to blend certain parts of circle with background so that it seems to user that the circle is broken from certain parts.

How to create an art asset that can be dynamically colored in software?

I asked this question on the Graphic Design site, but it includes a programming component that might be better answered here.
Specifically, I have a bunch of photographic crayon images. I would like to remove the color from one to produce a neutral image that I can load into an iPhone app that I'm writing and dynamically color. The crayon images have dark regions (shadows) and light regions (shine) which I would like to preserve. I will be dynamically coloring it with many different colors, ranging from white to rainbow colors to black.
My first inclination is to turn the image into a grayscale image and then somehow turn the color channel into an alpha channel, and change the color of all pixels to black. Then I could use it as a mask. However, this would only preserve the shadows, and I would lose all the highlights.
Any ideas?
Two options come to mind:
Make a grayscale version that could be tinted as you said, with the shadows and highlights simply white and gray.
Make an outline, i.e. an image with alpha that had 0% opacity in the colored parts, say 10% white over the highlights, 10% black on the shadows, and 100% black/dark gray for the lines/edges. The idea being that you could put any color under the outline and it would look right.

OpenGLES mix and match blending options complicated question

So I have a background line drawing, black and white. I want to be able to draw over this, keeping the black lines in there, and drawing only where it is white. I can do this by using
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
And the black stays black and white gets whatever color I want. However in the white areas, I want to be able to draw some color, pick to another color and then blend. However this doesn't work because the blend function is messed up.
So what I was thinking is having a linedrawing framebuffer, and a user-drawing framebuffer. The user draws into the userdrawing framebuffer, with a different blending, and then I switch blending options and draw into the linedrawing framebuffer. But i don't know enough OpenGL to say whether or not this will work or is a stupid idea.
Thanks a lot
If your drawing is transparent in the white regions, you can do this: Draw your colored areas first and then the line drawing over them, using the standard GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA blend.