public void ProcessLighting(Camera camera) { if (DaydreamLight.s_resortLights) { DaydreamLight.s_resortLights = false; DaydreamLight.ResortLights(); } bool changed = true; if (DaydreamLight.s_masterLightArray != null && DaydreamLight.s_masterLightArray.Length > 0) { // update lights DaydreamLight.StartFrame(camera); DaydreamLight lightData = null; for (int i = 0, k = DaydreamLight.s_masterLightArray.Length; i < k; ++i) { if (i >= DaydreamLight.s_masterLightArray.Length) { break; } lightData = DaydreamLight.s_masterLightArray[i]; #if UNITY_EDITOR lightData.InEditorUpdate(); #endif lightData.CheckForChange(); lightData.UpdateFrame(); lightData.UpdateViewSpace(); } changed = DaydreamLight.AnyLightChanged() || m_lightCount != DaydreamLight.GetLightCount(); m_lightCount = DaydreamLight.GetLightCount(); } if (DaydreamMeshRenderer.m_objectList != null) { DaydreamMeshRenderer.StartFrame(); // process objects for (int i = 0, k = DaydreamMeshRenderer.m_objectList.Count; i < k; ++i) { DaydreamMeshRenderer dmr = DaydreamMeshRenderer.m_objectList[i]; if (!dmr.m_didInit) { dmr.DMRInit(); } #if UNITY_EDITOR dmr.InEditorUpdate(); #endif dmr.UpdateStaticState(); dmr.ApplyLighting(changed); } } }
void OnPostprocessModel(GameObject model) { Renderer[] rs = model.GetComponentsInChildren <Renderer>(); foreach (Renderer r in rs) { foreach (Material m in r.sharedMaterials) { if (m.shader.name.ToLower().Contains("daydream")) { DaydreamMeshRenderer dmr = r.gameObject.GetComponent <DaydreamMeshRenderer>(); if (dmr != null) { GameObject.DestroyImmediate(dmr, true); } r.gameObject.AddComponent <DaydreamMeshRenderer>(); break; } } } }
public void ProcessLighting(Camera camera) { if (DaydreamLight.s_resortLights) { DaydreamLight.s_resortLights = false; DaydreamLight.ResortLights(); } #if UNITY_EDITOR for (int i = 0, k = s_inEditorUpdateList.Count; i < k; ++i) { s_inEditorUpdateList[i].InEditorUpdate(); } #endif bool changed = true; if (DaydreamLight.s_masterLightArray != null && DaydreamLight.s_masterLightArray.Length > 0) { // update lights DaydreamLight.StartFrame(camera); DaydreamLight lightData = null; for (int i = 0, k = DaydreamLight.s_masterLightArray.Length; i < k; ++i) { if (i >= DaydreamLight.s_masterLightArray.Length) { break; } lightData = DaydreamLight.s_masterLightArray[i]; // these should update once per frame regardless of camera count if (m_frameStarted) { #if UNITY_EDITOR lightData.InEditorUpdate(); #endif lightData.CheckForChange(); lightData.UpdateFrame(); } // this updates each frame for each camera lightData.UpdateViewSpace(); } // first time through this should get set back to false so other cameras // don't update light values that only need to be udpate once per frame m_frameStarted = false; changed = DaydreamLight.AnyLightChanged() || m_lightCount != DaydreamLight.GetLightCount(); m_lightCount = DaydreamLight.GetLightCount(); } if (s_objectList != null) { DaydreamMeshRenderer.StartFrame(); // process objects for (int i = 0, k = s_objectList.Count; i < k; ++i) { DaydreamMeshRenderer dmr = s_objectList[i]; if (!dmr.m_didInit) { dmr.DMRInit(); } #if UNITY_EDITOR if (!dmr.InEditorUpdate()) { continue; } #endif dmr.UpdateStaticState(); dmr.ApplyLighting(changed); } } }
public void OnPreCull(Camera camera) { DaydreamLightingManager.s_objectList.Clear(); DaydreamMeshRenderer.Clear(); }
public void OnPreCull(Camera camera) { DaydreamMeshRenderer.Clear(); }
static void ApplyLightingComponents() { // check renderers List <GameObject> roots = Utilities.GetAllRoots(); List <GameObject> missingRenderer = new List <GameObject>(); List <GameObject> missingDrLight = new List <GameObject>(); for (int i = 0, k = roots.Count; i < k; ++i) { Renderer[] renderers = roots[i].GetComponentsInChildren <Renderer>(); Light[] lights = roots[i].GetComponentsInChildren <Light>(); for (int j = 0, n = renderers.Length; j < n; ++j) { MeshRenderer mr = renderers[j] as MeshRenderer; SkinnedMeshRenderer smr = renderers[j] as SkinnedMeshRenderer; if (renderers[j] == null || (mr == null && smr == null)) { continue; } bool isDaydreamRendered = false; for (int m = 0; m < renderers[j].sharedMaterials.Length; ++m) { if (renderers[j].sharedMaterials[m] != null && renderers[j].sharedMaterials[m].shader.name.ToLower().Contains("daydream")) { isDaydreamRendered = true; break; } } if (renderers[j] != null && isDaydreamRendered) { DaydreamMeshRenderer dmr = renderers[j].GetComponent <DaydreamMeshRenderer>(); if (null == dmr) { missingRenderer.Add(renderers[j].gameObject); } else { // update disable/enabled dmr.enabled = renderers[j].enabled; } } } for (int j = 0, n = lights.Length; j < n; ++j) { if (lights[j] != null && null == lights[j].GetComponent <DaydreamLight>()) { missingDrLight.Add(lights[j].gameObject); } } } if (missingRenderer.Count != 0 || missingDrLight.Count != 0) { if (!Application.isPlaying) { for (int i = 0, k = missingRenderer.Count; i < k; ++i) { if (missingRenderer[i] != null) { missingRenderer[i].AddComponent <DaydreamMeshRenderer>(); } } for (int i = 0, k = missingDrLight.Count; i < k; ++i) { if (missingDrLight[i] != null) { missingDrLight[i].AddComponent <DaydreamLight>(); } } } else { Debug.LogWarning("DaydreamLight must be added to Light components and DaydreamMeshRenderer must be added to MeshRenderer objects in order for Daydream Lighting system to function"); } } }