I’m trying to make a material that is normally black, but will light up to white when exposed to light. Attempts to just set texture to black have resulted in black materials that remain black when exposed to light.
Edit: By lit up, I don’t mean change completely to white, but have a gradient as an material normally would when exposed to light.
For what you want to achieve a shader is not necessary. Instead you can add a script that watches observes the light source.
Script Logic
Each light source has a type and a range. Spot light sources also has an Spot Angle. using a script you can measure the distance the light is from your object. Additionally, if the light source is a spot light, you can measure the spot Angle.
using these two variables you can calculate if your object is lit.
below is the script, note that this is not tested but th ebasic idea is there
Script
using UnityEngine;
using System;
public class isSeen : MonoBehaviour {
/* Public Variable */
public GameObject lightSource;
/* Private Variable */
float range;
float angle;
bool isSpot;
/* Functions */
void Start () {
Light l = lightSource.GetComponent<Light> ();
// Check the spot light type
isSpot = l.type == LightType.Spot;
// get the range
range = l.range;
// Get angle
range = l.SpotAngle;
}
void LateUpdate () {
if (isSpot) {
float _dist = Vector3.Distance (light.transform.position, transform.position);
float _angle = Vector3.Angle (light.transform.forward, transform.position);
if (_dist < range && Mathf.Abs(_angle) <= angle ) {
// make it white
GetComponent<Renderer> ().material.color = Color.White;
} else {
GetComponent<Renderer> ().material.color = Color.Black;
}
return;
}
// Not a Spot Light
float _dist = Vector3.Distance (light.transform.position, transform.position);
if (_dist < range ) {
// make it white
GetComponent<Renderer> ().material.color = Color.White;
} else {
GetComponent<Renderer> ().material.color = Color.Black;
}
}
}
My question was solved by a different person. My environmental lighting was tinged grey, which was why objects did not darken completely. I now have the behavior I wanted. Thanks.