Hey,
I am working on a project involving a sphere lighted by 6 different directional lights as seen below.
The main goal of this project is to have the sphere shrink and grow on the user’s command while the lights move closer or further so that the smaller the sphere gets the whiter it becomes.
The initial stage of the sphere in one of the four different color modes is shown below.
My main concern is that when I try to shrink it there are specific keyframes that the sphere’s colors/lights create a weird shadow-like cross as seen below.
My main question is whether it is possible to adjust the color or light blending so that the cross is not visible and the colors appear as equally distributed as in the first picture when the sphere is full size.
More details about the project’s environment are shown in the pictures below.
Project’s architecture
Sphere’s material
1 light component
Light Controller component
Light Controller Code
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
public class LightController : MonoBehaviour
{
public List<Light> lights;
private List<Color> lightsInit;
public GameObject sphere;
public float scaleSpeed = 0.1f;
public float maxScale = 5.0f;
public float minScale = 0.1f;
private float scale = 1.0f; // current scale of the sphere
private float direction = 0.0f; // direction of the scale change (1 for growing, -1 for shrinking)
public float lightSaturation = 1.0f; // set the default value of lightSaturation to 1.0
Color blueColor;
Color greenColor;
Color redColor;
Color whiteColor;
Color enabledColor;
Color blackColor;
public RawImage whiteBG;
public RawImage blueBG;
public RawImage redBG;
public RawImage greenBG;
void Start(){
lightsInit = new List<Color>();
for (int i = 0; i < lights.Count; i++)
{
// store the initial color of the light in the list
lightsInit.Add(lights[i].color);
}
ColorUtility.TryParseHtmlString("#5AE4FF", out enabledColor);
ColorUtility.TryParseHtmlString("#FFFFFF", out whiteColor);
ColorUtility.TryParseHtmlString("#000000", out blackColor);
ColorUtility.TryParseHtmlString("#FF0000", out redColor);
ColorUtility.TryParseHtmlString("#00FF00", out greenColor);
ColorUtility.TryParseHtmlString("#0000FF", out blueColor);
}
void Update()
{
// if the 'C' key is pressed, change the direction to grow
if (Input.GetKeyDown(KeyCode.C))
{
direction = 1.0f;
}
// if the 'N' key is pressed, change the direction to shrink
if (Input.GetKeyDown(KeyCode.N))
{
direction = -1.0f;
}
// update the scale of the sphere
scale += scaleSpeed * direction * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.B))
{
ChangeColor("blue1", "blue2", "spotblue1", "spotblue2");
sphere.GetComponent<Renderer>().material.color = blueColor;
whiteBG.color = blackColor;
blueBG.color = enabledColor;
redBG.color = blackColor;
greenBG.color = blackColor;
}
if (Input.GetKeyDown(KeyCode.G))
{
ChangeColor("green1", "green2", "spotgreen1", "spotgreen2");
sphere.GetComponent<Renderer>().material.color = greenColor;
whiteBG.color = blackColor;
blueBG.color = blackColor;
redBG.color = blackColor;
greenBG.color = enabledColor;
}
if (Input.GetKeyDown(KeyCode.R))
{
ChangeColor("red1", "red2","spotred1","spotred2");
sphere.GetComponent<Renderer>().material.color = redColor;
whiteBG.color = blackColor;
blueBG.color = blackColor;
redBG.color = enabledColor;
greenBG.color = blackColor;
}
if (Input.GetKeyDown(KeyCode.V))
{
ResetColors();
sphere.GetComponent<Renderer>().material.color = whiteColor;
whiteBG.color = enabledColor;
blueBG.color = blackColor;
redBG.color = blackColor;
greenBG.color = blackColor;
}
// if the scale has reached the minimum or maximum allowed, reverse the direction
if (scale <= minScale || scale >= maxScale)
{
direction = 0;
}
// apply the scale to the sphere
sphere.transform.localScale = Vector3.one * scale;
// adjust the saturation of the lights based on the scale of the sphere
for (int i = 0; i < lights.Count; i++)
{
Color lightColor = lights[i].color;
float saturation = scale / maxScale;
float h, s, v;
Color.RGBToHSV(lightColor, out h, out s, out v);
if(s != 0){
s = saturation;
lightColor = Color.HSVToRGB(h, s, v);
lights[i].color = lightColor;
}
}
}
void ChangeColor(string lightName1, string lightName2, string spotName1, string spotName2)
{
ResetColors();
for (int i = 0; i < lights.Count; i++)
{
Light light = lights[i];
if (light.name == lightName1 || light.name == lightName2 || light.name == spotName1 || light.name == spotName1)
{
lights[i].color = whiteColor;
lights[i].intensity = 1;
}
else
{
lights[i].intensity = 4;
}
}
}
void ResetColors()
{
for (int i = 0; i < lights.Count; i++)
{
lights[i].intensity = 1;
// set the color of the light to the initial color stored in the list
lights[i].color = lightsInit[i];
}
}
}
Thanks in advance for your time reading it and any answers!