void ShowRealtimeLightmapPreview(Hash128 inputSystemHash) { if (inputSystemHash == new Hash128()) { return; } Hash128 contentHash = LightmapVisualizationUtility.GetRealtimeGITextureHash(inputSystemHash, GITextureType.Irradiance); // if we need to fetch a new texture if (m_CachedRealtimeTexture.texture == null || m_CachedRealtimeTexture.contentHash != contentHash) { m_CachedRealtimeTexture = LightmapVisualizationUtility.GetRealtimeGITexture(inputSystemHash, GITextureType.Irradiance); } if (m_CachedRealtimeTexture.texture == null) { return; } GUILayout.BeginHorizontal(); GUILayout.Space(30); Rect rect = GUILayoutUtility.GetRect(100, 100, EditorStyles.objectField); EditorGUI.Toggle(rect, false, EditorStyles.objectFieldThumb); if (rect.Contains(Event.current.mousePosition)) { Object actualTargetObject = m_CachedRealtimeTexture.texture; Component com = actualTargetObject as Component; if (com) { actualTargetObject = com.gameObject; } if (Event.current.clickCount == 2) { LightmapPreviewWindow.CreateLightmapPreviewWindow(m_Renderers[0].GetInstanceID(), true, false); } } if (Event.current.type == EventType.Repaint) { rect = EditorStyles.objectFieldThumb.padding.Remove(rect); EditorGUI.DrawPreviewTexture(rect, m_CachedRealtimeTexture.texture); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
bool UpdateRealtimeTexture(Hash128 inputSystemHash, int instanceId) { if (inputSystemHash == new Hash128()) { return(false); } Hash128 contentHash = LightmapVisualizationUtility.GetRealtimeGITextureHash(inputSystemHash, GITextureType.Irradiance); // if we need to fetch a new texture if (m_CachedRealtimeTexture.texture == null || m_CachedRealtimeTexture.contentHash != contentHash) { m_CachedRealtimeTexture = LightmapVisualizationUtility.GetRealtimeGITexture(inputSystemHash, GITextureType.Irradiance); } if (m_CachedRealtimeTexture.texture == null) { return(false); } return(true); }
private void UpdateCachedTexture(GITextureType textureType) { if (isIndexBased) { if (isRealtimeLightmap) { Hash128[] mainHashes = Lightmapping.GetMainSystemHashes(); if (!m_RealtimeTextureHash.isValid || !mainHashes.Contains(m_RealtimeTextureHash)) { m_RealtimeTextureHash = mainHashes.ElementAtOrDefault(m_LightmapIndex); } } } else // instance based { if (isRealtimeLightmap) { Hash128 systemHash; if (!Lightmapping.GetInputSystemHash(m_InstanceID, out systemHash)) { m_CachedTexture.textureAvailability = GITextureAvailability.GITextureNotAvailable; return; } m_RealtimeTextureHash = systemHash; } else { int lightmapIndex; if (!Lightmapping.GetLightmapIndex(m_InstanceID, out lightmapIndex)) { m_CachedTexture.textureAvailability = GITextureAvailability.GITextureNotAvailable; return; } m_LightmapIndex = lightmapIndex; } } Hash128 contentHash = isRealtimeLightmap ? LightmapVisualizationUtility.GetRealtimeGITextureHash(m_RealtimeTextureHash, textureType) : LightmapVisualizationUtility.GetBakedGITextureHash(m_LightmapIndex, m_InstanceID, textureType); // if we need to fetch a new texture if (m_CachedTexture.texture == null || m_CachedTexture.type != textureType || m_CachedTexture.contentHash != contentHash || m_CachedTexture.contentHash == new Hash128()) { m_CachedTexture = isRealtimeLightmap ? LightmapVisualizationUtility.GetRealtimeGITexture(m_RealtimeTextureHash, textureType) : LightmapVisualizationUtility.GetBakedGITexture(m_LightmapIndex, m_InstanceID, textureType); } if (!m_ShowUVOverlay) { return; // if we don't wanna show any overlay } if (m_CachedTexture.texture == null || m_CachedTexture.textureAvailability == GITextureAvailability.GITextureNotAvailable || m_CachedTexture.textureAvailability == GITextureAvailability.GITextureUnknown) { return; // if we dont have a texture } // fetch Renderers if (isRealtimeLightmap) { m_CachedTextureObjects = LightmapVisualizationUtility.GetRealtimeGITextureRenderers(m_RealtimeTextureHash); } else if (LightmapVisualizationUtility.IsAtlasTextureType(textureType)) { m_CachedTextureObjects = LightmapVisualizationUtility.GetBakedGITextureRenderers(m_LightmapIndex); } else // if it's an instance based baked lightmap, we only have 1 object in it { m_CachedTextureObjects = new GameObject[] {} }; }