Unity - How can I control fog color based on skybox color? - unity3d

I have a gradient on a skybox, and I want the terminal fog color to be the same as the sky color behind the object that is being occluded. But it still needs to be fog and respect distance.
I see one way of doing it without actually using fog, with a gradient of my choosing on a skybox. The skybox gets masked out by the depth map, and then overlaid onto the non-sky geometry. You would be able to look down into the depths, and the blackness below gets darker gradually like a "fog" because it is masked by the depth operation. Look up and see the same phenomenon with the lighter color. Basically control "fog" terminal color by camera angle.
What would be the best way to implement this, and could it be performant on mobile devices?

Related

Skybox affecting sprites

The default skybox affects the sprites colour. I'm not sure how to stop this from happening. You can see below that the outline of the sprite is brown instead of grey.
If I set the main camera clear flags and background to Solid colour & black respectively, the brown from the skybox still shows through.
I'm not sure what information would be useful for others to assist me with this, so if there is any info I can add, just let me know and I'll update accordingly.
What you're seeing here is alpha blending, your 'outline' pixels have low alpha, so when rendered Unity will blend their color with the background. It generally represents transparency, but in this case it's behaving as a kind of anti-aliasing (it makes your sprites look smoother and less pixely) In that sense, it's working as intended. Look at your sprites at normal resolution and you'll notice they should look good.
If you prefer the pixelated look and really don't want this behaviour, you need to edit your sprites to have full alpha on those pixels.
I'm not sure about Empty's answer:
Are you using the standard shader? That shader uses the environment map as an ambient color on top of the diffuse color (albedo). This is perfectly normal behaviour and makes colors of everything blend nicely with each other. (with an orange sky white objects will look onage-ish. ) This is part of "physically correct lighting" (PBL). It is not at all physically correct, but it comes close enough for now.
If you don't want the environment to affect the colro that mucha you could either alter the environment map to a less dramatic color (normal blue/white sky) or use an unlit shader/material.
Window->Rendering->Lighting Settings
Under Debug Settings, select Generate Lighting.
De-select Auto Generate.
From the Baked Lightmaps set Lighting Data Asset to None.
Remove generated Lighting from the project.

Unity 2D: Irregular shape window to a different background world?

I want to make an irregular shape display its colors from a different set of images. Currently, I have a flashlight represented by an irregular shape (kite shaped) that when casted over an area, certain objects appear. When the shape is removed, the items disappear. Now, I want to have the background that is within this irregular shape to display an altered version of the background.
I am planning to use a RenderTexture to get its info from a camera that views the flashlight's corrosponding location in the other world, and then use this image as the basis of the flashlight's altered background. However, when I try this, the flashlight shows black instead of the other world. When I texture a plane, the RenderTexture works properly. Anyone have any ideas how to accomplish this?

Cocos2d mask layer (tilemap lighting)

I'm trying to add lighting to a certain extent within my tilemap based iPhone game. For lack of a better example, I'm trying to add minecraft style lighting - the further a tile is from the light source the greater "dark" tint it has.
The most efficient way I can think of doing this would be to add some type of mask over the tilemap layer in order to create this effect and simply move the masks with the tilemap as the player moves around.
I haven't been able to find any documentation on how to add masks to an entire layer, is this possible? Or is it bad practice? Or can you think of a better possible method for achieving this effect?
The simplest and most efficient solution would be to modify the color property of a tile. By default all nodes have the color "white" and by applying gray colors between black & white you'll be able to control the brightness of the tile.
Note however that when you do treat a tile like a CCSprite, cocos2d will change the tile from its basic implementation and change it into a CCSprite. This may become a performance and/or memory issue. Each CCSprite instance was 420 Bytes last time I checked in cocos2d 0.99.

OpenGL ES flash of bright light

I'm having some trouble achieving my desired effect in an OpenGL ES app I'm working on. I can use OpenGL ES 1.1 or 2.0. What I'm trying to achieve is the following...
In a 2D ortho scene (black clear color), render a red square to the screen with some transparency so it is a darker red (or just set to darker red color). This is no problem for me. Then, when a user clicks in the region of the square, I want it to quickly flash in a bright flash of light (just in the region of the square). This flash doesn't have to persist long at all, just enough that if the user was in a completely dark room, this flash of light would create a brief noticeable flash in the users face. I've been having some trouble getting a "light bloom" or glow effect to work efficiently, and was wondering if anyone had ideas for a quick, efficient way to make the color flash brightly for a split second. Possibly through the use of some kind of texturing trick that I don't know of. Also, the flash doesn't have to blur outside of the region, it can be fully contained within the region with sharp edges. Really all I'm after is the aesthetic of the flash lighting the immediate area around the screen.
Disable texturing, glColor3ub(255,255,255), render square, wait a bit, redraw square normally.

How to draw a light effect over a texture on iPhone using UIKit/Quartz

I have a scene with a background image (a lit room), and a black image (shadow) over that. I need to be able to move my finger over the background and reveal some parts of the scene, simulating a dim light source in a dark room.
My current approach was to generate a mask depending on the position of the touch, and then applying that mask to the shadow image. The problem is I'm generating a new mask and applying it every time I receive a touch event. It's a large image (800x600) and this causes the performance to go down and it increases a lot the memory usage, eventually crashing the game (I think I don't have any memory leaks, but that's not warrantied... anyway the performance itself isn't acceptable).
Can anyone think of a better approach (which doesn't involve using OpenGL ES -- that's not an option in this project) to do this?
To go with my comments above.
Maybe to get around the different shadow levels you could also have a grid of views (squares) between the image and the shadow view. each grid square has a different alpha opacity and when the spot is over a grid square, the grid square's alpha opacity changes to 0. when the spot moves off the grid square it's alpha opacity changes back to it's default.
Without more information it is a little difficult to know whether this approach will work in your case but what you could do is generate a single mask image, say, a radial alpha gradient and then apply an affine transform to it to shape it according to the touches. This can be used to simulate a torch/flashlight beam.
I would try this: use one view with a custom drawRect implemetation: first draw the shadow image (in grayscale) then a bright spot image in white an alpha. And finally the background image in a 'multiply' blend mode.
Just a thought, does the shadow has to be an image? Perhaps you could simply fill the shadow layer with a color and mask it then? This way the memory usage should be less and the effect should be nearly identical (if not exactly the same).
There is no reason to generate a new mask on every touch move. Instead, let the mask be initialized once and manipulate it (reset it's frame) as needed upon touch events.