64 lines
2.9 KiB
C#
64 lines
2.9 KiB
C#
#if UNITY_EDITOR
|
|
using System.IO;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
/// <summary>Force-reimport XTerrain, punch ground lightmap contrast, recapture HomeCamp review.</summary>
|
|
public static class FixHomeCampShadowPunch
|
|
{
|
|
const string Root = "Assets/Bundles/Scenes/Town/HomeCamp";
|
|
const string ScenePath = Root + "/HomeCamp.unity";
|
|
const string Review = "D:/UD/AI/AIGame/Tools/output/homecamp_review";
|
|
|
|
public static string Run()
|
|
{
|
|
AssetDatabase.ImportAsset("Assets/Bundles/Shaders/XShader/XTerrain.shader", ImportAssetOptions.ForceSynchronousImport);
|
|
AssetDatabase.ImportAsset("Assets/Bundles/Shaders/XShader/XTerrain_Base.hlsl", ImportAssetOptions.ForceSynchronousImport);
|
|
|
|
var mat = AssetDatabase.LoadAssetAtPath<Material>(Root + "/ground_terrain.mat");
|
|
if (!mat) return "FAIL: no ground mat";
|
|
// Stronger than 1.45 — busy albedo still hid plaza shade after the CBUFFER fix.
|
|
mat.SetFloat("_LightmapContrast", 1.85f);
|
|
EditorUtility.SetDirty(mat);
|
|
AssetDatabase.SaveAssetIfDirty(mat);
|
|
|
|
var scene = EditorSceneManager.OpenScene(ScenePath, OpenSceneMode.Single);
|
|
var root = scene.GetRootGameObjects().Single(g => g.name == "HomeCamp");
|
|
var ground = root.transform.Find("Ground")?.GetComponentInChildren<MeshRenderer>();
|
|
var live = ground ? ground.sharedMaterial.GetFloat("_LightmapContrast") : -1f;
|
|
|
|
// Warm shader variants so Capture does not draw the first frame without LIGHTMAP_ON.
|
|
ShaderUtil.allowAsyncCompilation = false;
|
|
var cam = root.GetComponentInChildren<Camera>();
|
|
Capture(cam, Review + "/homecamp_portrait.png", 1080, 1920);
|
|
Capture(cam, Review + "/homecamp_tall.png", 1080, 2400);
|
|
|
|
return "contrast=" + live.ToString("F2") + " groundLM=" + (ground ? ground.lightmapIndex.ToString() : "?")
|
|
+ " maps=" + LightmapSettings.lightmaps.Length;
|
|
}
|
|
|
|
static void Capture(Camera camera, string file, int w, int h)
|
|
{
|
|
Directory.CreateDirectory(Path.GetDirectoryName(file));
|
|
var rt = RenderTexture.GetTemporary(w, h, 24, RenderTextureFormat.ARGB32);
|
|
var old = RenderTexture.active; var oldT = camera.targetTexture; var oldA = camera.aspect;
|
|
var tex = new Texture2D(w, h, TextureFormat.RGB24, false);
|
|
try
|
|
{
|
|
camera.aspect = (float)w / h; camera.targetTexture = rt; RenderTexture.active = rt;
|
|
camera.Render(); camera.Render();
|
|
tex.ReadPixels(new Rect(0, 0, w, h), 0, 0); tex.Apply();
|
|
File.WriteAllBytes(file, tex.EncodeToPNG());
|
|
}
|
|
finally
|
|
{
|
|
camera.targetTexture = oldT; camera.aspect = oldA; RenderTexture.active = old;
|
|
RenderTexture.ReleaseTemporary(rt); Object.DestroyImmediate(tex);
|
|
}
|
|
}
|
|
}
|
|
#endif
|