Files
grass-cutters/Assets/Scripts/World/LightingStyle.cs
Bonchellon 52619d8952 Hologram calls, HaulOS phone, Enhanced lighting, smoother camera; Blender remaster review files
Game:
- Assistant and Director portraits: GPT backgrounds and a holographic appear/disappear shader (Talk/TalkHolo) instead of on/off
- Phone redesigned (HaulOS home, address bar, dock, error/loading states) and the browser link made sturdier
- Settings > Graphics > Lighting: Classic / Enhanced (runtime volume, no project assets changed); Enhanced SSAO uses the
  smooth interleaved-gradient method at high samples so flat panels don't speckle
- Painted board textures (T_HullPanel, T_BarnRed) keep only edge wear: the big bare-wood patches read as dirty smudges
- The head leans into a sidestep smoothly instead of snapping with A / D
- New keys in all 11 languages

Review only (nothing swapped into the game yet): ArtSource/Blender/remaster (v1 paint pass of our own models, Synty-built
ones left out), remaster/crew (crew repaint with arm, colour-edge and face fixes), remaster_v2 (smooth-geometry pilot).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 15:28:47 +03:00

247 lines
12 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Reflection;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace GrassCutter
{
/// <summary>
/// The look of the light, from Settings › Graphics › Lighting: Classic is the scene's own post volume as it always was;
/// Enhanced lays a second volume over it with the grade of the prototype (TheWorstEscape's prison yard), softened for a
/// bright cartoon: split toning (cool shadows, warm highlights), a touch of cool in the shadows,
/// a little more colour and warmth, a warmer and wider bloom, a vignette, a fine grain and a hair of chromatic aberration,
/// stronger contact shadows (SSAO) and a glint on the sun. The prototype's ACES stays out: on this sunny meadow it crushed
/// the shade to black and burnt the colours (tried, 2026-11-23), and so did switching the pipeline to HDR grading at
/// runtime: the scene's own Neutral tonemapping and LDR grading stay. It also takes the world out of focus behind the phone held up and behind a window.
///
/// Nothing here touches the project's assets: the volumes and profiles are made at runtime, the pipeline is the
/// settings' own copy, and the SSAO strength changed in memory is put back on quit. Classic switches it all off again.
/// </summary>
public static class LightingStyle
{
public const int Classic = 0, Enhanced = 1;
static Volume s_look, s_focus;
static DepthOfField s_dof;
static float s_blur;
static ScriptableRendererFeature s_ssao;
static object s_ssaoSettings;
static float s_ssaoIntensity = -1f, s_ssaoDirect = -1f;
static int s_ssaoMethod = -1, s_ssaoSamples = -1;
public static bool On => GameSettings.Lighting == Enhanced;
/// <summary>
/// Test runs: -lookskip bloom,grade,wb,split,smh,vig,grain,ca,ssao,flare,dof leaves those parts of the look
/// out, to see which one does what; aooff switches the renderer's SSAO off altogether.
/// </summary>
public static bool Skip(string part) => (CommandLine.Get("-lookskip") ?? "").Contains(part);
/// <summary>The profile of the Enhanced look, so the day/night grade can tell the scene's volume from ours.</summary>
public static bool IsOurs(Volume v) => v && (v == s_look || v == s_focus);
public static void Apply()
{
Make();
s_look.enabled = On;
s_focus.enabled = On;
if (!Skip("flare")) Flare(RenderSettings.sun);
if (s_flare) s_flare.enabled = On;
if (!Skip("ssao")) Ssao(On);
if (Skip("dof")) s_focus.enabled = false;
}
static void Make()
{
if (s_look) return;
var go = new GameObject("Lighting (enhanced)");
Object.DontDestroyOnLoad(go);
go.hideFlags = HideFlags.DontSave;
var p = ScriptableObject.CreateInstance<VolumeProfile>();
p.name = "Enhanced look";
if (!Skip("bloom")) {
var bloom = p.Add<Bloom>(true);
bloom.intensity.Override(0.85f);
bloom.threshold.Override(0.95f);
bloom.scatter.Override(0.7f);
bloom.tint.Override(new Color(1f, 0.93f, 0.85f)); }
// contrast and saturation only: exposure and the colour filter stay the scene volume's, which the day and the
// night vision drive (DayNight)
if (!Skip("grade")) {
var grade = p.Add<ColorAdjustments>();
grade.contrast.Override(17f);
grade.saturation.Override(18f); }
if (!Skip("wb")) p.Add<WhiteBalance>().temperature.Override(4f);
if (!Skip("split")) {
var split = p.Add<SplitToning>();
split.shadows.Override(new Color(0.46f, 0.5f, 0.56f));
split.highlights.Override(new Color(0.56f, 0.53f, 0.48f));
split.balance.Override(-10f); }
if (!Skip("smh")) {
var smh = p.Add<ShadowsMidtonesHighlights>();
smh.shadows.Override(new Vector4(0.97f, 1f, 1.05f, 0f));
smh.midtones.Override(new Vector4(1f, 1f, 1f, 0.02f)); }
if (!Skip("vig")) {
var vig = p.Add<Vignette>();
vig.intensity.Override(0.24f);
vig.smoothness.Override(0.45f); }
if (!Skip("grain")) {
var grain = p.Add<FilmGrain>();
grain.type.Override(FilmGrainLookup.Thin1);
grain.intensity.Override(0.1f);
grain.response.Override(0.8f); }
if (!Skip("ca")) p.Add<ChromaticAberration>().intensity.Override(0.04f);
s_look = go.AddComponent<Volume>();
s_look.isGlobal = true;
s_look.priority = 10f;
s_look.sharedProfile = p;
var f = ScriptableObject.CreateInstance<VolumeProfile>();
f.name = "Focus";
s_dof = f.Add<DepthOfField>(true);
s_dof.mode.Override(DepthOfFieldMode.Gaussian);
s_dof.gaussianStart.Override(0.4f);
s_dof.gaussianEnd.Override(5f);
s_dof.gaussianMaxRadius.Override(1.5f);
s_dof.highQualitySampling.Override(true);
s_focus = go.AddComponent<Volume>();
s_focus.isGlobal = true;
s_focus.priority = 11f;
s_focus.weight = 0f;
s_focus.sharedProfile = f;
GameSettings.ApplyBloom();
}
static LensFlareComponentSRP s_flare;
/// <summary>
/// A glint on the sun: a warm glow, a faint halo and a few soft ghosts across the screen, all drawn shapes (no
/// textures), hidden behind anything in front of the sun.
/// </summary>
static void Flare(Light sun)
{
if (!sun) return;
if (!s_flare || s_flare.gameObject != sun.gameObject)
{
s_flare = sun.GetComponent<LensFlareComponentSRP>();
if (!s_flare)
{
var d = ScriptableObject.CreateInstance<LensFlareDataSRP>();
d.name = "Sun glint";
d.elements = new[]
{
Shape(SRPLensFlareType.Circle, 0f, 2.2f, 0.55f, new Color(1f, 0.86f, 0.62f), 0.12f),
Shape(SRPLensFlareType.Ring, 0f, 5.5f, 0.05f, new Color(0.8f, 0.9f, 1f), 0.5f),
Shape(SRPLensFlareType.Polygon, 0.45f, 0.7f, 0.06f, new Color(0.55f, 1f, 0.85f), 0.6f, 6),
Shape(SRPLensFlareType.Polygon, 0.85f, 0.35f, 0.08f, new Color(1f, 0.7f, 0.45f), 0.6f, 6),
Shape(SRPLensFlareType.Circle, 1.25f, 1.1f, 0.035f, new Color(0.6f, 0.75f, 1f), 0.9f),
Shape(SRPLensFlareType.Polygon, 1.6f, 0.5f, 0.05f, new Color(1f, 0.9f, 0.6f), 0.5f, 6),
};
s_flare = sun.gameObject.AddComponent<LensFlareComponentSRP>();
s_flare.lensFlareData = d;
s_flare.useOcclusion = true;
s_flare.occlusionRadius = 0.6f;
s_flare.sampleCount = 8;
s_flare.allowOffScreen = false;
}
}
s_flare.enabled = On;
}
static LensFlareDataElementSRP Shape(SRPLensFlareType kind, float at, float size, float strength, Color tint, float soft, int sides = 4)
{
return new LensFlareDataElementSRP
{
flareType = kind,
position = at,
uniformScale = size,
localIntensity = strength,
tint = tint,
fallOff = soft,
sideCount = sides,
blendMode = SRPLensFlareBlendMode.Additive,
modulateByLightColor = true,
visible = true,
};
}
/// <summary>Every frame (DayNight): the world goes soft behind the phone up at your face and behind a window.</summary>
public static void Tick()
{
if (!s_focus || !On) return;
var sun = RenderSettings.sun;
if (sun && !Skip("flare") && (!s_flare || s_flare.gameObject != sun.gameObject)) Flare(sun);
// the glint is the sun's: it goes with the daylight (the same light is the moon at night) and the clouds
if (s_flare) s_flare.intensity = (1f - DayNight.Dark) * Mathf.Clamp01(sun ? sun.intensity / 2f : 0f);
bool soft = Phone.Focused || (UIRoot.I && UIRoot.I.AnyModal) || Ctl.UIOpen;
s_blur = Mathf.MoveTowards(s_blur, soft ? 1f : 0f, Time.unscaledDeltaTime * 4f);
s_focus.weight = s_blur * s_blur * (3f - 2f * s_blur);
}
/// <summary>
/// The renderer's SSAO, stronger and reaching into the sunlight a little. Its settings are private to URP, so they
/// are found by name; if a URP update renames them this quietly does nothing.
/// </summary>
static void Ssao(bool strong)
{
if (s_ssaoSettings == null)
{
var rp = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
var data = rp ? rp.rendererDataList : default;
foreach (var d in data)
{
if (!d) continue;
foreach (var feature in d.rendererFeatures)
if (feature && feature.GetType().Name == "ScreenSpaceAmbientOcclusion") s_ssao = feature;
if (s_ssao) break;
}
if (!s_ssao) return;
var field = s_ssao.GetType().GetField("m_Settings", BindingFlags.Instance | BindingFlags.NonPublic);
s_ssaoSettings = field?.GetValue(s_ssao);
if (s_ssaoSettings == null) return;
s_ssaoIntensity = Get("Intensity");
s_ssaoDirect = Get("DirectLightingStrength");
s_ssaoMethod = GetEnum("AOMethod");
s_ssaoSamples = GetEnum("Samples");
Application.quitting += () => Ssao(false);
}
if (s_ssaoIntensity < 0f) return;
// the scene's blue-noise SSAO at medium samples speckles the flat panels once it is stronger (seen on the travel
// terminal, 2026-11-23): the stronger look takes the smooth interleaved-gradient method and the most samples
Set("Intensity", strong ? 0.6f : s_ssaoIntensity);
if (s_ssaoDirect >= 0f) Set("DirectLightingStrength", strong ? 0.15f : s_ssaoDirect);
if (s_ssaoMethod >= 0) SetEnum("AOMethod", strong ? 1 : s_ssaoMethod);
if (s_ssaoSamples >= 0) SetEnum("Samples", strong ? 0 : s_ssaoSamples);
s_ssao.SetActive(false);
s_ssao.SetActive(!Skip("aooff"));
Debug.Log($"[Look] SSAO {(Skip("aooff") ? "off" : "on")}: intensity {Get("Intensity")}, direct {Get("DirectLightingStrength")}, method {GetEnum("AOMethod")}, samples {GetEnum("Samples")}");
}
static float Get(string name)
{
var f = s_ssaoSettings.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return f != null && f.FieldType == typeof(float) ? (float)f.GetValue(s_ssaoSettings) : -1f;
}
static void Set(string name, float v)
{
var f = s_ssaoSettings.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (f != null && f.FieldType == typeof(float)) f.SetValue(s_ssaoSettings, v);
}
static int GetEnum(string name)
{
var f = s_ssaoSettings.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return f != null && f.FieldType.IsEnum ? System.Convert.ToInt32(f.GetValue(s_ssaoSettings)) : -1;
}
static void SetEnum(string name, int v)
{
var f = s_ssaoSettings.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (f != null && f.FieldType.IsEnum) f.SetValue(s_ssaoSettings, System.Enum.ToObject(f.FieldType, v));
}
}
}