Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two color background

Tags:

unity3d

I saw an interesting background on a game and I would like to know how it is made and how can I implement it to my own application. enter image description here

Here we can see the background. Yellow on the top, blue on the bottom. This is not a simple image, cuz during the gameplay the colors change like a transition.

Also, how can I make a cube look faded like the 1st one from the bottom?

Thanks in advance.

like image 530
Alexandru Vasiliu Avatar asked Jun 29 '17 09:06

Alexandru Vasiliu


People also ask

How do I set two background colors in CSS?

CSS allows you to add multiple background images for an element, through the background-image property. The different background images are separated by commas, and the images are stacked on top of each other, where the first image is closest to the viewer.

How do you add two background colors in HTML?

To add background color in HTML, use the CSS background-color property. Set it to the color name or code you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a table, heading, div, or span tag.

How do I use two colors in CSS?

To use more than 2 colors (because why not), put the powerful rgba() to use and use 2 gradient parameters. Here's an example with the background property holding an image and masking some portion of the image with a gradient of orange and transparent.


2 Answers

Using a simple 2x1 sized texture, you could achieve a similar effect.

Put a canvas (in Camera world, quite far from your camera) with a raw image taking the whole screen.

Then, create a script with the following code :

public UnityEngine.UI.RawImage img;

private Texture2D backgroundTexture ;

void Awake()
{
    backgroundTexture  = new Texture2D(1, 2);
    backgroundTexture.wrapMode = TextureWrapMode.Clamp;
    backgroundTexture.filterMode = FilterMode.Bilinear;
    SetColor( Color.black, Color.white ) ;
}

public void SetColor( Color color1, Color color2 )
{
    backgroundTexture.SetPixels( new Color[] { color1, color2 } );
    backgroundTexture.Apply();
    img.texture = backgroundTexture;
}

If you want to have a gradient with more colors, change the height of the created texture, and change a little bit the SetColor` function.

Else, I found this Git repository with a cusztom Skybox gradient shader :

https://github.com/keijiro/UnitySkyboxShaders

Paid solution, this asset seems to be what you want : https://www.assetstore.unity3d.com/en/#!/content/37726

like image 63
Hellium Avatar answered Oct 05 '22 11:10

Hellium


One way to achieve the gradient background is through the use of a skybox. I can also vouch for Marvelous Techniques (MT), for which Hellium also provided a link in their answer. It does cost money, and you won't learn much in the process, of course. But if your main goal is to only have what you see in the picture, MT should get you there.

And to answer your second question, shaders. There was a recent blog post about creating a gradient shader very much like the one seen in the picture you have provided. The blog post walks you through the creation of the shader, and the full code for the shader is provided at the end of the post.

like image 27
Kasperi Avatar answered Oct 05 '22 09:10

Kasperi