public void UpdateLighting() { if (enableVoxelLight && mat != null) { Vector3 pos = lastPosition; // center of voxel pos.x += 0.5f; pos.y += 0.5f; pos.z += 0.5f; float light = env.GetVoxelLight(pos); if (useMaterialColor) { Color newColor = new Color(normalMatColor.r * light, normalMatColor.g * light, normalMatColor.b * light, normalMatColor.a); mat.color = newColor; } else { mat.SetFloat("_VoxelLight", env.GetVoxelLight(pos)); } } }
void ManageItem() { if (env == null) { return; } Vector3 currentPosition = transform.position; if (lastChunk != null && lastChunk.isRendered) { if (currentPosition == lastPosition) { return; } lastPosition = currentPosition; } // Update lighting if (mat != null) { mat.SetFloat("_VoxelLight", env.GetVoxelLight(currentPosition)); } // Update owner chunk VoxelChunk currentChunk; if (!env.GetChunk(currentPosition, out currentChunk, true)) { return; } if (currentChunk != lastChunk) { if (lastChunk != null) { lastChunk.RemoveItem(this); } currentChunk.AddItem(this); lastChunk = currentChunk; } if (currentChunk.isRendered && rb != null && !rb.useGravity) { rb.useGravity = true; } }
void UpdateLightingNow() { if (!enableVoxelLight) { return; } if (rd == null || rd.Length == 0) { FetchMaterials(); } Vector3 pos = lastPosition; // center of voxel pos.x += 0.5f; pos.y += 0.5f; pos.z += 0.5f; float light = env.GetVoxelLight(pos); for (int k = 0; k < rd.Length; k++) { if (rd[k].mat == null) { continue; } if (rd[k].useMaterialColor) { Color newColor = new Color(rd[k].normalMatColor.r * light, rd[k].normalMatColor.g * light, rd[k].normalMatColor.b * light, rd[k].normalMatColor.a); rd[k].mat.color = newColor; } else { rd[k].mat.SetFloat("_VoxelLight", light); } } }