...it always bugged me that weapons always appear the same regardless of local lighting levels.
FPSWeapon OnGUI() code now uses DaggerfallUI.DrawTextureWithTexCoords() which allows color blending.
I wrote some short testing code...
Code: Select all
//in FPSWeapon.OnGUI...
DaggerfallUI.DrawTextureWithTexCoords(
weaponPosition,
curCustomTexture ? curCustomTexture : weaponAtlas,
curAnimRect,
true,
GetLightLevel());
Code: Select all
public static Color GetLightLevel()
{
Color totalLight = RenderSettings.ambientLight;
GameObject obj = GameManager.Instance.PlayerObject;
Vector3 position = obj.transform.position + obj.transform.forward * 0.5f;
//Performance issue.
//Should be using cached values from a call to PlayerGPS.GetNearbyObjects() or similar.
Light[] lights = GameObject.FindObjectsOfType<Light>();
foreach (Light light in lights)
{
float distance = Vector3.Distance(light.transform.position, position);
if (distance <= 1)
totalLight += light.color * light.intensity;
else if (distance < light.range)
totalLight += light.color * light.intensity / (distance * distance);
}
//How to detect if standing in building shadows when outside?
totalLight.r = Mathf.Clamp(totalLight.r, 0f, 1f);
totalLight.g = Mathf.Clamp(totalLight.g, 0f, 1f);
totalLight.b = Mathf.Clamp(totalLight.b, 0f, 1f);
totalLight.a = 1.0f; //not messing with alpha, unless ghost player (hmm...)
return totalLight;
}
Other than the FindObjectsOfType() performance issue (easily fixed), it should be easy to shade weapons and other hand related stuff.