Skip to content

Instantly share code, notes, and snippets.

@forestrf
Last active June 24, 2026 20:44
Show Gist options
  • Select an option

  • Save forestrf/14cd7348469213db7aa82f5c2d1ec860 to your computer and use it in GitHub Desktop.

Select an option

Save forestrf/14cd7348469213db7aa82f5c2d1ec860 to your computer and use it in GitHub Desktop.
Lightmap Preview Mode in final render instead of using debug mode.
// https://discussions.unity.com/t/decent-lightmapper-preview/1571658/2
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
public class LightmapPreviewModeWindow : EditorWindow {
[MenuItem("Tools/Lightmap preview mode")]
public static void Get() {
GetWindow<LightmapPreviewModeWindow>().Show();
}
[InitializeOnLoadMethod]
static void Init() {
var s_ShowInteractiveLightBakingToggleCameraModes = typeof(SceneView).GetField("s_ShowInteractiveLightBakingToggleCameraModes", BindingFlags.NonPublic | BindingFlags.Static);
(s_ShowInteractiveLightBakingToggleCameraModes.GetValue(null) as HashSet<DrawCameraMode>).Add(DrawCameraMode.Textured);
}
SceneView dummySceneInDebugMode;
SceneView lastScene;
void OnEnable2() {
bool thisHasFocus = this.hasFocus;
dummySceneInDebugMode = CreateWindow<SceneView>("Ignore", typeof(LightmapPreviewModeWindow));
dummySceneInDebugMode.cameraMode = SceneView.GetBuiltinCameraMode(DrawCameraMode.BakedLightmap);
dummySceneInDebugMode.debugDrawModesUseInteractiveLightBakingData = true;
dummySceneInDebugMode.wantsLessLayoutEvents = true;
if (thisHasFocus) {
ShowTab();
}
lastScene = SceneView.lastActiveSceneView;
}
void OnDisable() {
dummySceneInDebugMode?.Close();
if (lastScene != null) lastScene.debugDrawModesUseInteractiveLightBakingData = false;
}
void OnGUI() {
if (dummySceneInDebugMode == null) {
OnEnable2();
return;
}
GUILayout.Label("Lightmap preview mode", EditorStyles.boldLabel);
EditorGUILayout.HelpBox("Real time lightmap preview to configure lights quickly", MessageType.Info);
EditorGUILayout.HelpBox("Doesn't update Lightprobes", MessageType.Warning);
EditorGUILayout.HelpBox("Close this window when done", MessageType.Info);
var scene = SceneView.lastActiveSceneView;
if (scene != lastScene) {
if (lastScene != null) lastScene.debugDrawModesUseInteractiveLightBakingData = false;
}
}
void Update() {
lastScene = SceneView.lastActiveSceneView;
if (lastScene != null) {
lastScene.debugDrawModesUseInteractiveLightBakingData = true;
var sceneCam = lastScene.camera;
dummySceneInDebugMode.camera.transform.SetPositionAndRotation(sceneCam.transform.position, sceneCam.transform.rotation);
dummySceneInDebugMode.camera.fieldOfView = sceneCam.fieldOfView;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment