88 lines
5.0 KiB
C#
88 lines
5.0 KiB
C#
// WL-816j — ⑦ 데모와 나란히 (에디트 모드 렌더 · §9 데모 Play 안 함)
|
|
// ⓐ 아레나 데모(톤 기준 814t) 수평선 ⓑ 워터 셰이더 벤더 샘플 씬의 「흰 거품 띠」(물보라 기준)
|
|
using System.Text;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.Universal;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
|
|
public static class WL816j_Demo
|
|
{
|
|
const string D = "Screenshots_WL/WL816j/";
|
|
|
|
public static void Run()
|
|
{
|
|
var sb = new StringBuilder();
|
|
|
|
// ⓐ 아레나 데모 — 우리 섬 수평선과 같은 카메라
|
|
EditorSceneManager.OpenScene("Assets/LowPolyFantasyArena/Scenes/LowPolyArena_Demo.unity", OpenSceneMode.Single);
|
|
sb.AppendLine("아레나 데모 수평선 = " + Shot(Cam(new Vector3(-14f, 8f, -14f), new Vector3(6f, 0f, 6f), 55f), D + "o_demo_arena_horizon.png", 1080, 1920));
|
|
|
|
// ⓑ 워터 셰이더 벤더 샘플 — 물이 벽에 닿는 곳의 흰 거품 띠
|
|
EditorSceneManager.OpenScene("Assets/ResWork/UToonAndRealisticWater/Scene/UToonAndRealisticShaderSampleScene.unity", OpenSceneMode.Single);
|
|
var w = GameObject.Find("Water");
|
|
Vector3 c = w != null ? w.transform.position : Vector3.zero;
|
|
sb.AppendLine("벤더 샘플 Water = " + (w != null ? w.transform.position + " scale " + w.transform.localScale : "없음"));
|
|
sb.AppendLine("벤더 거품 띠 = " + Shot(Cam(c + new Vector3(3.5f, 1.6f, 3.5f), c + new Vector3(-1f, 0f, -1f), 32f), D + "o_demo_vendor_foam.png", 720, 1280));
|
|
sb.AppendLine("벤더 전경 = " + Shot(Cam(c + new Vector3(0f, 6f, -8f), c, 55f), D + "o_demo_vendor_wide.png", 1080, 1920));
|
|
|
|
Strip(new[] { D + "o_demo_arena_horizon.png", D + "n_after_horizon.png" }, D + "o_demo_vs_island.png");
|
|
Strip(new[] { D + "o_demo_vendor_foam.png", D + "n_after_shore.png" }, D + "o_vendor_vs_island_shore.png");
|
|
sb.AppendLine("나란히 = o_demo_vs_island.png(좌 아레나 데모 / 우 우리 섬 · 같은 카메라)");
|
|
sb.AppendLine("나란히 = o_vendor_vs_island_shore.png(좌 벤더 샘플 거품 띠 / 우 우리 섬 가장자리)");
|
|
|
|
// 다음 작업을 위해 InGame 으로 (데모 씬 저장 0)
|
|
EditorSceneManager.OpenScene("Assets/Scenes/InGame.unity", OpenSceneMode.Single);
|
|
System.IO.File.WriteAllText("AgentScripts/WL816j_DEMO.txt", sb.ToString());
|
|
Debug.Log("[816j demo]\n" + sb);
|
|
}
|
|
|
|
static Camera Cam(Vector3 pos, Vector3 at, float fov)
|
|
{
|
|
var go = new GameObject("~WL816jDemoCam"); go.hideFlags = HideFlags.DontSave;
|
|
var c = go.AddComponent<Camera>();
|
|
c.orthographic = false; c.fieldOfView = fov; c.nearClipPlane = 0.1f; c.farClipPlane = 2000f;
|
|
c.clearFlags = CameraClearFlags.Skybox; c.cullingMask = ~0; c.depth = -100f;
|
|
go.transform.position = pos; go.transform.LookAt(at);
|
|
go.AddComponent<UniversalAdditionalCameraData>();
|
|
return c;
|
|
}
|
|
static string Shot(Camera cam, string path, int w, int h)
|
|
{
|
|
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
|
|
var rt = new RenderTexture(w, h, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
|
|
rt.antiAliasing = 1; rt.Create();
|
|
var pA = RenderTexture.active;
|
|
cam.targetTexture = rt; cam.Render(); RenderTexture.active = rt;
|
|
var t = new Texture2D(w, h, TextureFormat.RGB24, false);
|
|
t.ReadPixels(new Rect(0, 0, w, h), 0, 0); t.Apply();
|
|
RenderTexture.active = pA; cam.targetTexture = null; rt.Release(); Object.DestroyImmediate(rt);
|
|
System.IO.File.WriteAllBytes(path, t.EncodeToPNG());
|
|
var px = t.GetPixels32(); long r = 0, g = 0, b = 0; int n = 0;
|
|
for (int i = 0; i < px.Length; i += 7) { r += px[i].r; g += px[i].g; b += px[i].b; n++; }
|
|
Object.DestroyImmediate(t); Object.DestroyImmediate(cam.gameObject);
|
|
return "평균 #" + ((int)(r / n)).ToString("X2") + ((int)(g / n)).ToString("X2") + ((int)(b / n)).ToString("X2") + " → " + path;
|
|
}
|
|
static void Strip(string[] paths, string outPath)
|
|
{
|
|
var ts = new Texture2D[paths.Length]; int w = 0, h = 0;
|
|
for (int i = 0; i < paths.Length; i++)
|
|
{
|
|
if (!System.IO.File.Exists(paths[i])) return;
|
|
ts[i] = new Texture2D(2, 2, TextureFormat.RGB24, false);
|
|
ts[i].LoadImage(System.IO.File.ReadAllBytes(paths[i]));
|
|
w += ts[i].width; h = Mathf.Max(h, ts[i].height);
|
|
}
|
|
var o = new Texture2D(w, h, TextureFormat.RGB24, false);
|
|
var f = new Color32[w * h];
|
|
for (int i = 0; i < f.Length; i++) f[i] = new Color32(24, 24, 28, 255);
|
|
o.SetPixels32(f);
|
|
int x = 0;
|
|
for (int i = 0; i < ts.Length; i++) { o.SetPixels32(x, 0, ts[i].width, ts[i].height, ts[i].GetPixels32()); x += ts[i].width; }
|
|
o.Apply();
|
|
System.IO.File.WriteAllBytes(outPath, o.EncodeToPNG());
|
|
Object.DestroyImmediate(o);
|
|
for (int i = 0; i < ts.Length; i++) Object.DestroyImmediate(ts[i]);
|
|
}
|
|
}
|