Ending: rail camera, stable far planet, green bursts from a US landing

Flights run on rails at even speed along the spline with eased ends and
smooth zoom pushes, no hand-held shake. Grass fur, sector lines and
shadows fade out as the camera climbs, and above 250 m the ground swaps
to an even cube-sphere skin so the relief no longer pops while orbiting.
Per-shot FOV, motion blur, slamming titles and a warp to Earth; the
rocket now lands in Kansas and the green bursts straight out of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bonchellon
2026-12-01 16:30:08 +03:00
parent a3e4f00282
commit d4dff6ea99
6 changed files with 289 additions and 41 deletions

View File

@ -43,11 +43,12 @@ namespace GrassCutter
float s = Time.time; float s = Time.time;
yield return Until(s, 9f, "Call"); yield return Shot("end_01_call"); yield return Until(s, 9f, "Call"); yield return Shot("end_01_call");
// the flights: skim, arc round the base, (a machine), the rise; times from the start of each stage // the flights: skim, arc round the base, (a machine), the rise; times from the start of each stage
yield return AtStage("Climb", 2.5f, "end_02_skim"); yield return AtStage("Climb", 2.0f, "end_02_skim");
yield return AtStage("Climb", 5.6f, "end_02b_skim_late"); yield return AtStage("Climb", 4.4f, "end_02b_skim_late");
yield return AtStage("Climb", 8.5f, "end_03_arc"); yield return AtStage("Climb", 6.5f, "end_03_arc");
yield return AtStage("Climb", 12.5f, "end_03b_arc_late"); yield return AtStage("Climb", 10.2f, "end_03b_arc_late");
yield return AtStage("Space", 1.5f, "end_04a_rise_low"); yield return AtStage("Space", 1.5f, "end_04a_rise_low");
yield return AtStage("Space", 3.5f, "end_04a2_rise_fade");
yield return AtStage("Space", 5.5f, "end_04b_rise_mid"); yield return AtStage("Space", 5.5f, "end_04b_rise_mid");
yield return AtStage("Space", 8.5f, "end_04c_rise_high"); yield return AtStage("Space", 8.5f, "end_04c_rise_high");
yield return AtStage("Space", 10.8f, "end_04d_rise_top"); yield return AtStage("Space", 10.8f, "end_04d_rise_top");

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UIElements; using UnityEngine.UIElements;
namespace GrassCutter namespace GrassCutter
@ -62,6 +64,18 @@ namespace GrassCutter
double _mown; double _mown;
VisualElement _layer, _black, _top, _bottom, _titleBox, _stats, _creditsBox, _flash; VisualElement _layer, _black, _top, _bottom, _titleBox, _stats, _creditsBox, _flash;
// the punch on top of every shot: the lens's own field of view (eased), a kick that springs back, a shake, a bank into
// turns, a lens bend and colour fringes, and blur from the lens's own motion
float _fovShot = 70f, _fov = 70f, _fovShown = 70f, _fovKick, _fovKickV, _shake, _roll, _distort, _fringe;
float _fovHold = -1f;
Vector3 _lastEye;
Volume _fx;
MotionBlur _blur;
LensDistortion _lens;
ChromaticAberration _ca;
float _shadow0 = -1f;
static readonly int FarOnlyId = Shader.PropertyToID("_GcFarOnly");
// Earth, and the lens round it: how far round from the sun (degrees) and how far out // Earth, and the lens round it: how far round from the sun (degrees) and how far out
EndingEarth _earth; EndingEarth _earth;
float _eTheta, _eDist, _eDistTo, _warp; float _eTheta, _eDist, _eDistTo, _warp;
@ -208,11 +222,13 @@ namespace GrassCutter
var looks = new Vector3[at.Length]; var looks = new Vector3[at.Length];
for (int i = 0; i < at.Length; i++) for (int i = 0; i < at.Length; i++)
{ {
eyes[i] = Ground(home + d * at[i] + side * Mathf.Sin(i * 0.9f) * 3f, h[i]); eyes[i] = Ground(home + d * at[i] + side * (2f - i) * 1.2f, h[i]);
looks[i] = i >= at.Length - 2 ? home + up * (i == at.Length - 1 ? 1f : 4f) : Ground(home + d * (at[i] - 45f), 1.6f); looks[i] = i >= at.Length - 2 ? home + up * (i == at.Length - 1 ? 1f : 4f) : Ground(home + d * (at[i] - 45f), 1.6f);
} }
Sfx.Play("cut_whoosh_1", 0.32f, 0.85f, 0f); Sfx.Play("cut_whoosh_1", 0.4f, 0.85f, 0f);
yield return Fly(eyes, looks, 6.2f); _fovShot = _fov = _fovShown = 84f;
Kick(10f, 0.2f, -0.25f, 0.6f);
yield return Fly(eyes, looks, 5f);
} }
// past a machine or a robot near the base, if the crew has one // past a machine or a robot near the base, if the crew has one
@ -222,8 +238,10 @@ namespace GrassCutter
var wSide = Vector3.Cross(wUp, wFwd); var wSide = Vector3.Cross(wUp, wFwd);
var eyes = new[] { Ground(wPos - wFwd * 14f + wSide * 7f, 2.2f), Ground(wPos - wFwd * 2f + wSide * 6f, 1.8f), Ground(wPos + wFwd * 11f + wSide * 5f, 2.4f) }; var eyes = new[] { Ground(wPos - wFwd * 14f + wSide * 7f, 2.2f), Ground(wPos - wFwd * 2f + wSide * 6f, 1.8f), Ground(wPos + wFwd * 11f + wSide * 5f, 2.4f) };
var looks = new[] { wPos + wUp * 1f, wPos + wUp * 1f, wPos + wUp * 1.2f }; var looks = new[] { wPos + wUp * 1f, wPos + wUp * 1f, wPos + wUp * 1.2f };
Sfx.Play("cut_whoosh_2", 0.3f, 0.95f, 0f); Sfx.Play("cut_whoosh_2", 0.35f, 0.95f, 0f);
yield return Fly(eyes, looks, 5f); _fovShot = _fov = _fovShown = 72f;
Kick(-6f, 0f, 0.15f, 0.4f);
yield return Fly(eyes, looks, 4.2f);
} }
// round the base, close, over the roofs, half way round it // round the base, close, over the roofs, half way round it
@ -240,27 +258,34 @@ namespace GrassCutter
looks[i] = c; looks[i] = c;
} }
arcEnd = eyes[n - 1]; arcEnd = eyes[n - 1];
yield return Fly(eyes, looks, 8f); Sfx.Play("cut_whoosh_1", 0.35f, 1.1f, 0f);
_fovShot = _fov = _fovShown = 64f;
Kick(-6f, 0f, 0.15f, 0.4f);
yield return Fly(eyes, looks, 6.5f);
} }
// the rise: on from where the arc left off, straight up over the base, then out, without a cut, into the orbit // the rise: on from where the arc left off, straight up over the base, then out, without a cut, into the orbit
_phase = Phase.Space; _phase = Phase.Space;
OrbitSetup(Planet.Up(arcEnd), side); OrbitSetup(Planet.Up(arcEnd), side);
Sfx.Play("space_rumble", 0.8f, 1f, 0f); Sfx.Play("space_rumble", 0.8f, 1f, 0f);
Sfx.Play("cut_whoosh_2", 0.35f, 0.7f, 0f); Sfx.Play("cut_whoosh_2", 0.45f, 0.7f, 0f);
_fovShot = 60f;
Kick(-12f, 0.45f, 0.3f, 0.7f);
yield return Rise(arcEnd, home + up * 2.5f, 12f); yield return Rise(arcEnd, home + up * 2.5f, 12f);
_shot = Shot.Orbit; _shot = Shot.Orbit;
yield return new WaitForSeconds(1.2f); yield return new WaitForSeconds(0.9f);
_title.text = Loc.T("HERBARIA-7"); _title.text = Loc.T("HERBARIA-7");
_sub.text = Loc.T("100% MOWN"); _sub.text = Loc.T("100% MOWN");
_sub.style.display = DisplayStyle.Flex; _sub.style.display = DisplayStyle.Flex;
Show(_titleBox, 1.4f); Show(_titleBox, 0.25f);
UIK.PopIn(_title, 0f, 0.6f); Slam(_title);
SlideIn(_sub, 0.35f);
yield return new WaitForSeconds(4.6f); yield return new WaitForSeconds(4.6f);
Hide(_titleBox, 1.2f); Hide(_titleBox, 1.2f);
yield return new WaitForSeconds(1.4f); yield return new WaitForSeconds(1.4f);
_line.text = Loc.T("Every blade. Cut, packed and shipped."); _line.text = Loc.T("Every blade. Cut, packed and shipped.");
Show(_line, 0.9f); Show(_line, 0.6f);
SlideIn(_line, 0f);
yield return new WaitForSeconds(3.4f); yield return new WaitForSeconds(3.4f);
Hide(_line, 0.9f); Hide(_line, 0.9f);
yield return new WaitForSeconds(1.1f); yield return new WaitForSeconds(1.1f);
@ -268,6 +293,8 @@ namespace GrassCutter
// 4. what the crew did, the ball easing off to the right // 4. what the crew did, the ball easing off to the right
_phase = Phase.Results; _phase = Phase.Results;
_shiftTo = 1f; _shiftTo = 1f;
Kick(-4f, 0.1f, 0f, 0.25f);
Sfx.Play("paper_whoosh", 0.35f, 0.9f, 0f);
yield return new WaitForSeconds(0.8f); yield return new WaitForSeconds(0.8f);
FillStats(true); FillStats(true);
yield return new WaitForSeconds(9.5f); yield return new WaitForSeconds(9.5f);
@ -281,13 +308,15 @@ namespace GrassCutter
yield return new WaitForSeconds(1.4f); yield return new WaitForSeconds(1.4f);
_title.text = Loc.T("EARTH"); _title.text = Loc.T("EARTH");
_sub.style.display = DisplayStyle.None; _sub.style.display = DisplayStyle.None;
Show(_titleBox, 1.4f); Show(_titleBox, 0.25f);
UIK.PopIn(_title, 0f, 0.6f); Slam(_title);
yield return new WaitForSeconds(3.6f); yield return new WaitForSeconds(3.6f);
Hide(_titleBox, 1.2f); Hide(_titleBox, 1.2f);
yield return new WaitForSeconds(1.0f); yield return new WaitForSeconds(1.0f);
// 6. the rocket from Herbaria-7 past the lens and down onto it, and the green spreading from where it lands // 6. the rocket from Herbaria-7 past the lens and down onto it, and the green spreading from where it lands
_earth.OnPass = () => Kick(10f, 0f, -0.2f, 0.6f);
_earth.OnLand = () => { Kick(-8f, 0f, 0.25f, 0.9f); Sfx.Play("bomb_boom", 0.45f, 0.7f, 0f); };
yield return _earth.Rocket(EarthPose, LandingPlace, 7f); yield return _earth.Rocket(EarthPose, LandingPlace, 7f);
float greenT = 0f; float greenT = 0f;
bool said = false; bool said = false;
@ -298,7 +327,8 @@ namespace GrassCutter
{ {
said = true; said = true;
_line.text = Loc.T("Earth has grass again."); _line.text = Loc.T("Earth has grass again.");
Show(_line, 0.9f); Show(_line, 0.6f);
SlideIn(_line, 0f);
} }
yield return null; yield return null;
} }
@ -309,6 +339,7 @@ namespace GrassCutter
// 7. the credits roll up past it, the ball easing off to the right // 7. the credits roll up past it, the ball easing off to the right
_phase = Phase.Credits; _phase = Phase.Credits;
_shiftTo = 1f; _shiftTo = 1f;
Kick(-3f, 0.08f, 0f, 0.2f);
yield return new WaitForSeconds(0.8f); yield return new WaitForSeconds(0.8f);
yield return RollCredits(32f); yield return RollCredits(32f);
@ -316,36 +347,77 @@ namespace GrassCutter
yield return End(); yield return End();
} }
/// <summary>The screen goes white while the lens falls away from the ball; it comes back on Earth.</summary> /// <summary>
/// A jump: the lens falls away from the ball and stretches wide, bent and fringed, the screen goes white; it comes back
/// wide on Earth and settles.
/// </summary>
IEnumerator Warp() IEnumerator Warp()
{ {
Sfx.Play("meteor_whoosh", 0.7f, 0.7f, 0f); Sfx.Play("meteor_whoosh", 0.8f, 0.7f, 0f);
Sfx.Play("cut_whoosh_2", 0.5f, 0.6f, 0f); Sfx.Play("cut_whoosh_2", 0.6f, 0.6f, 0f);
_flash.style.display = DisplayStyle.Flex; _flash.style.display = DisplayStyle.Flex;
float fov0 = _fov;
float t = 0f; float t = 0f;
while (t < 0.7f) while (t < 0.9f)
{ {
t += Time.deltaTime; t += Time.deltaTime;
float k = Mathf.Clamp01(t / 0.7f); float k = Mathf.Clamp01(t / 0.9f);
_warp = k * k; _warp = k * k;
_flash.style.opacity = k * k; _fovHold = Mathf.Lerp(fov0, 125f, k * k * k);
_distort = Mathf.Lerp(0f, -0.65f, k * k);
_fringe = k;
_shake = Mathf.Max(_shake, k * 0.5f);
_flash.style.opacity = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.55f, 1f, k));
yield return null; yield return null;
} }
_flash.style.opacity = 1f; _flash.style.opacity = 1f;
EarthSetup(); EarthSetup();
_warp = 0f; _warp = 0f;
_fovHold = -1f;
_fov = _fovShown = 118f;
_distort = -0.5f;
yield return null; yield return null;
Sfx.Play("space_rumble", 0.6f, 0.8f, 0f); Sfx.Play("space_rumble", 0.7f, 0.8f, 0f);
Sfx.Play("popk_boom_2", 0.5f, 0.55f, 0f);
t = 0f; t = 0f;
while (t < 1.3f) while (t < 1.0f)
{ {
t += Time.deltaTime; t += Time.deltaTime;
_flash.style.opacity = 1f - Mathf.SmoothStep(0f, 1f, t / 1.3f); _flash.style.opacity = 1f - Mathf.SmoothStep(0f, 1f, t / 1.0f);
yield return null; yield return null;
} }
_flash.style.display = DisplayStyle.None; _flash.style.display = DisplayStyle.None;
} }
/// <summary>A title lands: big, then down to size with a bounce, the lens jolted with it.</summary>
void Slam(VisualElement e)
{
e.style.scale = new Scale(new Vector2(1.8f, 1.8f));
Tween.Run(e, 0.55f, k =>
{
float sc = Mathf.LerpUnclamped(1.8f, 1f, k);
e.style.scale = new Scale(new Vector2(sc, sc));
}, Ease.OutBack);
Kick(-7f, 0.35f, 0.25f, 0.6f);
Sfx.Play("popk_boom_2", 0.55f, 0.6f, 0f);
}
/// <summary>Words come up into place from a little below.</summary>
static void SlideIn(VisualElement e, float delay)
{
e.style.translate = new Translate(0f, 40f);
Tween.Run(e, 0.6f, k => e.style.translate = new Translate(0f, Mathf.Lerp(40f, 0f, k)), Ease.OutCubic, delay);
}
/// <summary>A hit on the lens: field of view (degrees, springs back), shake, lens bend, colour fringes.</summary>
void Kick(float fov, float shake, float distort, float fringe)
{
_fovKick += fov;
_shake = Mathf.Max(_shake, shake);
_distort += distort;
_fringe = Mathf.Max(_fringe, fringe);
}
/// <summary>Earth made (once) and the lens out in front of it, stars round the new spot.</summary> /// <summary>Earth made (once) and the lens out in front of it, stars round the new spot.</summary>
void EarthSetup() void EarthSetup()
{ {
@ -356,18 +428,20 @@ namespace GrassCutter
_eTheta = 58f; _eTheta = 58f;
_eDist = EndingEarth.R * 3.0f; _eDist = EndingEarth.R * 3.0f;
_eDistTo = EndingEarth.R * 2.3f; _eDistTo = EndingEarth.R * 2.3f;
// Africa under the rocket when it comes down (about 15 s on), Europe and the Middle East up round it // America under the rocket when it comes down (about 15 s on)
_earth.Face(LandingPlace, EarthLanding(), 15f); _earth.Face(LandingPlace, EarthLanding(), 15f);
} }
_shift = _shiftTo = 0f; _shift = _shiftTo = 0f;
_shot = Shot.Earth; _shot = Shot.Earth;
_fovShot = 64f;
_near = 1f; _near = 1f;
_far = 60000f; _far = 60000f;
SpaceSky.Set(false, Vector3.zero); SpaceSky.Set(false, Vector3.zero);
SpaceSky.Set(true, EarthEye()); SpaceSky.Set(true, EarthEye());
} }
static readonly Vector3 LandingPlace = EndingEarth.Geo(12f, 18f); // the middle of the United States (Kansas): green fields all round once it takes
static readonly Vector3 LandingPlace = EndingEarth.Geo(39f, -98f);
Vector3 EarthView() Vector3 EarthView()
{ {
@ -431,6 +505,19 @@ namespace GrassCutter
// a flight along a smooth curve through the eyes, looking along a smooth curve through the looks // a flight along a smooth curve through the eyes, looking along a smooth curve through the looks
Vector3[] _pathEyes, _pathLooks; Vector3[] _pathEyes, _pathLooks;
float[] _pathLen;
/// <summary>Where along the curve (in points) the lens is when it has gone this share of the way by length.</summary>
float PathAt(float share)
{
var L = _pathLen;
if (L == null || L.Length < 2) return share * (_pathEyes.Length - 1);
float want = share * L[L.Length - 1];
int lo = 0, hi = L.Length - 1;
while (hi - lo > 1) { int mid = (lo + hi) / 2; if (L[mid] < want) lo = mid; else hi = mid; }
float f = L[hi] > L[lo] ? (want - L[lo]) / (L[hi] - L[lo]) : 0f;
return (lo + f) / (L.Length - 1) * (_pathEyes.Length - 1);
}
float _pathT, _pathFor; float _pathT, _pathFor;
// the rise: from an eye over the ground out to the orbit's first spot // the rise: from an eye over the ground out to the orbit's first spot
Vector3 _riseFrom, _riseLook, _riseTop; Vector3 _riseFrom, _riseLook, _riseTop;
@ -439,6 +526,16 @@ namespace GrassCutter
IEnumerator Fly(Vector3[] eyes, Vector3[] looks, float seconds) IEnumerator Fly(Vector3[] eyes, Vector3[] looks, float seconds)
{ {
_pathEyes = eyes; _pathLooks = looks; _pathEyes = eyes; _pathLooks = looks;
// the curve's length table: the lens runs along it at an even speed, like a dolly on its track
const int Steps = 240;
_pathLen = new float[Steps + 1];
var prev = Spline(eyes, 0f);
for (int i = 1; i <= Steps; i++)
{
var e = Spline(eyes, i / (float)Steps * (eyes.Length - 1));
_pathLen[i] = _pathLen[i - 1] + Vector3.Distance(prev, e);
prev = e;
}
_pathT = 0f; _pathFor = seconds; _pathT = 0f; _pathFor = seconds;
_shot = Shot.Path; _shot = Shot.Path;
_near = 0.05f; _far = 14000f; _near = 0.05f; _far = 14000f;
@ -530,6 +627,7 @@ namespace GrassCutter
GrassField.FurReach = 3.5f; GrassField.FurReach = 3.5f;
// the last picture is Earth, green all over // the last picture is Earth, green all over
_warp = 0f; _warp = 0f;
_fovHold = -1f;
EarthSetup(); EarthSetup();
_earth.HealNow(); _earth.HealNow();
_run = StartCoroutine(End()); _run = StartCoroutine(End());
@ -545,13 +643,20 @@ namespace GrassCutter
_shot = Shot.None; _shot = Shot.None;
_shift = _shiftTo = 0f; _shift = _shiftTo = 0f;
_warp = 0f; _warp = 0f;
_fovHold = -1f;
_fovKick = _fovKickV = _shake = _roll = _distort = _fringe = 0f;
if (_fx) _fx.enabled = false;
Shader.SetGlobalFloat(FarOnlyId, 0f);
GrassCutter.Ground.FarSkin = false;
if (_shadow0 >= 0f && RenderSettings.sun) RenderSettings.sun.shadowStrength = _shadow0;
_shadow0 = -1f;
_earth?.Destroy(); _earth?.Destroy();
_earth = null; _earth = null;
if (_flash != null) _flash.style.display = DisplayStyle.None; if (_flash != null) _flash.style.display = DisplayStyle.None;
SpaceSky.Set(false, Vector3.zero); SpaceSky.Set(false, Vector3.zero);
GrassField.FurReach = 1f; GrassField.FurReach = 1f;
var cam = CameraFx.Cam; var cam = CameraFx.Cam;
if (cam) { cam.nearClipPlane = 0.05f; cam.farClipPlane = 14000f; } if (cam) { cam.nearClipPlane = 0.05f; cam.farClipPlane = 14000f; cam.fieldOfView = CameraFx.BaseFov; }
if (cam && cam.transform.parent) cam.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity); if (cam && cam.transform.parent) cam.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
Ctl.Cinematic = false; Ctl.Cinematic = false;
if (UIRoot.I) UIRoot.I.HideHud(false); if (UIRoot.I) UIRoot.I.HideHud(false);
@ -615,6 +720,12 @@ namespace GrassCutter
_skip = UIK.Text("", "cinema-skip t-outline", _layer, false); _skip = UIK.Text("", "cinema-skip t-outline", _layer, false);
} }
_layer.style.display = DisplayStyle.Flex; _layer.style.display = DisplayStyle.Flex;
MakeFx();
_fx.enabled = true;
if (RenderSettings.sun && _shadow0 < 0f) _shadow0 = RenderSettings.sun.shadowStrength;
var cam0 = CameraFx.Cam;
_fov = _fovShot = _fovShown = cam0 ? cam0.fieldOfView : CameraFx.BaseFov;
_fovKick = _fovKickV = _shake = _roll = _distort = _fringe = 0f;
_ring.text = Loc.T("G.R.A.S.S.A. IS CALLING"); _ring.text = Loc.T("G.R.A.S.S.A. IS CALLING");
_theEnd.text = Loc.T("THE END"); _theEnd.text = Loc.T("THE END");
_unless.text = Loc.T("…unless?"); _unless.text = Loc.T("…unless?");
@ -683,6 +794,30 @@ namespace GrassCutter
UIK.Text(Loc.T("We take grass very seriously."), "ending-credits-motto t-outline", _creditsBox, false); UIK.Text(Loc.T("We take grass very seriously."), "ending-credits-motto t-outline", _creditsBox, false);
} }
/// <summary>The film's own lens effects, over the game's look: motion blur, a lens bend and colour fringes.</summary>
void MakeFx()
{
if (_fx) return;
var go = new GameObject("Ending lens");
go.transform.SetParent(transform, false);
var p = ScriptableObject.CreateInstance<VolumeProfile>();
_blur = p.Add<MotionBlur>(true);
_blur.mode.Override(MotionBlurMode.CameraOnly);
_blur.quality.Override(MotionBlurQuality.Medium);
_blur.intensity.Override(0.5f);
_blur.clamp.Override(0.06f);
_lens = p.Add<LensDistortion>(true);
_lens.intensity.Override(0f);
_lens.scale.Override(1f);
_ca = p.Add<ChromaticAberration>(true);
_ca.intensity.Override(0.05f);
_fx = go.AddComponent<Volume>();
_fx.isGlobal = true;
_fx.priority = 40f;
_fx.sharedProfile = p;
_fx.enabled = false;
}
static VisualElement Bar(VisualElement root, bool top) static VisualElement Bar(VisualElement root, bool top)
{ {
var b = new VisualElement { pickingMode = PickingMode.Ignore }; var b = new VisualElement { pickingMode = PickingMode.Ignore };
@ -749,17 +884,20 @@ namespace GrassCutter
if (up.sqrMagnitude < 0.01f) up = Vector3.ProjectOnPlane(Vector3.up, dir).normalized; if (up.sqrMagnitude < 0.01f) up = Vector3.ProjectOnPlane(Vector3.up, dir).normalized;
} }
float _rollTo;
void LateUpdate() void LateUpdate()
{ {
var cam = CameraFx.Cam; var cam = CameraFx.Cam;
if (!cam || !Running || _shot == Shot.None) return; if (!cam || !Running || _shot == Shot.None) return;
_rollTo = 0f;
if (_shot == Shot.Path) if (_shot == Shot.Path)
{ {
_pathT += Time.deltaTime; _pathT += Time.deltaTime;
float k = Mathf.Clamp01(_pathT / _pathFor); float k = Mathf.Clamp01(_pathT / _pathFor);
// eased in and out, but never standing still at either end of a flight // a dolly: eases off and in at the ends, an even glide between
k = Mathf.Lerp(k, k * k * (3f - 2f * k), 0.6f); k = Mathf.Lerp(k, k * k * (3f - 2f * k), 0.5f);
float u = k * (_pathEyes.Length - 1); float u = PathAt(k);
var e = Spline(_pathEyes, u); var e = Spline(_pathEyes, u);
// never under the ground between the points // never under the ground between the points
float alt = Planet.Altitude(e); float alt = Planet.Altitude(e);
@ -810,6 +948,7 @@ namespace GrassCutter
{ {
_orbitAngle += _orbitSpeed * Time.deltaTime; _orbitAngle += _orbitSpeed * Time.deltaTime;
_shift = Mathf.Lerp(_shift, _shiftTo, 1f - Mathf.Exp(-Time.deltaTime * 0.9f)); _shift = Mathf.Lerp(_shift, _shiftTo, 1f - Mathf.Exp(-Time.deltaTime * 0.9f));
_fovShot = 72f;
OrbitPose(_orbitAngle, out var e, out var up0); OrbitPose(_orbitAngle, out var e, out var up0);
var dir = (e - Planet.Center).normalized; var dir = (e - Planet.Center).normalized;
if (_warp > 0f) e += dir * _orbitDist * 2.5f * _warp; if (_warp > 0f) e += dir * _orbitDist * 2.5f * _warp;
@ -820,6 +959,47 @@ namespace GrassCutter
} }
cam.nearClipPlane = _near; cam.nearClipPlane = _near;
cam.farClipPlane = _far; cam.farClipPlane = _far;
Punch(cam);
}
/// <summary>
/// Over whatever the shot set: the field of view (the shot's, eased, plus a push that eases back off: a zoom, never a
/// jolt), the lens effects, and the planet's near detail going as the lens leaves the ground. No shake, no hand-held
/// drift: a film camera on rails.
/// </summary>
void Punch(Camera cam)
{
float dt = Time.deltaTime;
// a push in or out that eases back without overshoot
_fovKick = Mathf.Lerp(_fovKick, 0f, 1f - Mathf.Exp(-dt * 1.4f));
_fov = Mathf.Lerp(_fov, _fovShot, 1f - Mathf.Exp(-dt * 1.6f));
_fovShown = Mathf.Lerp(_fovShown, Mathf.Clamp((_fovHold > 0f ? _fovHold : _fov) + _fovKick, 25f, 140f), 1f - Mathf.Exp(-dt * (_fovHold > 0f ? 30f : 5f)));
cam.fieldOfView = _fovShown;
_distort = Mathf.Lerp(_distort, 0f, 1f - Mathf.Exp(-dt * 2.6f));
_fringe = Mathf.Lerp(_fringe, 0f, 1f - Mathf.Exp(-dt * 2.2f));
var eye = cam.transform.position;
if (_fx)
{
_lens.intensity.value = Mathf.Clamp(_distort, -0.75f, 0.75f);
_ca.intensity.value = Mathf.Clamp01(0.05f + _fringe * 0.8f);
// a cut is a jump of the lens: no streak across it
float allow = (40f + Mathf.Max(0f, Planet.Altitude(eye)) * 0.6f) * Mathf.Max(dt, 0.016f) * 4f;
bool cut = (eye - _lastEye).sqrMagnitude > allow * allow;
_blur.intensity.value = cut ? 0f : 0.5f;
}
_lastEye = eye;
// off the ground the near detail (the cut floor, the pile, the sector lines, the shadows' reach) gives way
// evenly to the far planet, so no ring of it is left round the base
float alt = _shot == Shot.Earth ? 1e6f : Planet.Altitude(eye);
// (the detail goes from 5 m up, under the skim's end; the shadows, which hold the base down, only from 30 m)
float far = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(5f, 10f, alt));
Shader.SetGlobalFloat(FarOnlyId, far);
// high up: the even skin fixed to the ball, so the hills stay put as the lens moves round
GrassCutter.Ground.FarSkin = alt > 250f;
float shade = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(30f, 160f, alt));
if (_shadow0 >= 0f && RenderSettings.sun) RenderSettings.sun.shadowStrength = _shadow0 * (1f - shade);
} }
} }
} }

View File

@ -25,6 +25,8 @@ namespace GrassCutter
public bool Landed => _seeds.Count > 0; public bool Landed => _seeds.Count > 0;
/// <summary>0 dead … 1 green all over: the air, the clouds.</summary> /// <summary>0 dead … 1 green all over: the air, the clouds.</summary>
public float Life { get; private set; } public float Life { get; private set; }
/// <summary>The rocket goes by the lens / comes down: the film hits the lens for them.</summary>
public System.Action OnPass, OnLand;
readonly GameObject _root; readonly GameObject _root;
readonly Transform _ball; readonly Transform _ball;
@ -197,8 +199,8 @@ namespace GrassCutter
static float Spread(Seed s) static float Spread(Seed s)
{ {
float k = Mathf.Clamp01(s.age / s.grow); float k = Mathf.Clamp01(s.age / s.grow);
// under way at once, quickest half way, easing into its last stretch // out from the point at once, quickest at the start, slowing as it wraps round the ball
return s.full * Mathf.Max(0.5f - 0.5f * Mathf.Cos(Mathf.PI * k), Mathf.Min(k * 0.6f, 0.05f)); return s.full * (1f - Mathf.Pow(1f - k, 1.7f));
} }
void Apply() void Apply()
@ -355,11 +357,11 @@ namespace GrassCutter
var at = Vector3.Lerp(prev, pos, (i + 1f) / n); var at = Vector3.Lerp(prev, pos, (i + 1f) / n);
// close by the lens a small flame and no smoke: left in the air there, it would fill the frame // close by the lens a small flame and no smoke: left in the air there, it would fill the frame
float flame = Mathf.Min(s * Random.Range(2.2f, 3.2f), 0.4f + far * 0.035f); float flame = Mathf.Min(s * Random.Range(2.2f, 3.2f), 0.4f + far * 0.035f);
Emit(_glow, at - dir * s * 0.4f, -dir * s * 6f, flame, new Color(1f, 0.62f, 0.25f, 0.95f), 0.22f); Emit(_glow, at - dir * s * 0.4f, -dir * s * 6f, flame, new Color(1f, 0.62f, 0.25f, 0.95f), far < 45f ? 0.05f : 0.22f);
if (i % 2 == 0 && far > 45f) if (i % 2 == 0 && far > 45f)
Emit(_glow, at - dir * s * 1.2f, Random.insideUnitSphere * s * 0.6f, s * Random.Range(2.6f, 3.8f), new Color(0.92f, 0.9f, 0.86f, 0.55f), 2.4f); Emit(_glow, at - dir * s * 1.2f, Random.insideUnitSphere * s * 0.6f, s * Random.Range(2.6f, 3.8f), new Color(0.92f, 0.9f, 0.86f, 0.55f), 2.4f);
} }
if (!whoosh && Vector3.Dot(pos - ln.position, ln.forward) > 0f) { whoosh = true; Sfx.Play("meteor_whoosh", 0.6f, 0.95f, 0f); } if (!whoosh && Vector3.Dot(pos - ln.position, ln.forward) > 0f) { whoosh = true; Sfx.Play("meteor_whoosh", 0.6f, 0.95f, 0f); OnPass?.Invoke(); }
prev = pos; prev = pos;
yield return null; yield return null;
} }
@ -370,6 +372,7 @@ namespace GrassCutter
Sfx.Play("rocket_land", 0.7f, 0.8f, 0f); Sfx.Play("rocket_land", 0.7f, 0.8f, 0f);
Sfx.Play("buff_shimmer", 0.5f, 0.9f, 0f); Sfx.Play("buff_shimmer", 0.5f, 0.9f, 0f);
Land(landOS, lens().position - Center); Land(landOS, lens().position - Center);
OnLand?.Invoke();
} }
} }

View File

@ -29,6 +29,13 @@ namespace GrassCutter
/// <summary>A plant this close to the camera falls over when its sector is finished; further off it just isn't there any more.</summary> /// <summary>A plant this close to the camera falls over when its sector is finished; further off it just isn't there any more.</summary>
const float FellSeen = 260f; const float FellSeen = 260f;
Transform _root, _skin; Transform _root, _skin;
/// <summary>
/// A film looking at the ball from far off (the ending's rise and orbit): the skin is an even mesh fixed to the ball
/// instead of the rings gathered under the lens, whose coarse far rings swim over the hills as the lens moves round.
/// </summary>
public static bool FarSkin;
MeshFilter _skinMf;
Mesh _nearSkin, _farSkin;
int _rockAt; int _rockAt;
static readonly int SkyRotId = Shader.PropertyToID("_GcSkyRot"), SkyOnId = Shader.PropertyToID("_GcSkyOn"); static readonly int SkyRotId = Shader.PropertyToID("_GcSkyRot"), SkyOnId = Shader.PropertyToID("_GcSkyOn");
@ -172,7 +179,13 @@ namespace GrassCutter
if (!cam) return; if (!cam) return;
var p = cam.transform.position; var p = cam.transform.position;
Planet.SetFrame(p); Planet.SetFrame(p);
_skin.rotation = Quaternion.FromToRotation(Vector3.up, Planet.LocalUp); if (_skinMf)
{
if (FarSkin && !_farSkin) _farSkin = BuildEvenSkin();
var want = FarSkin ? _farSkin : _nearSkin;
if (_skinMf.sharedMesh != want) _skinMf.sharedMesh = want;
}
_skin.rotation = FarSkin ? Quaternion.identity : Quaternion.FromToRotation(Vector3.up, Planet.LocalUp);
Shader.SetGlobalMatrix(SkyRotId, Matrix4x4.Rotate(Quaternion.Inverse(Planet.Frame))); Shader.SetGlobalMatrix(SkyRotId, Matrix4x4.Rotate(Quaternion.Inverse(Planet.Frame)));
Shader.SetGlobalFloat(SkyOnId, 1f); Shader.SetGlobalFloat(SkyOnId, 1f);
// climb and the haze lets go of the planet // climb and the haze lets go of the planet
@ -235,13 +248,57 @@ namespace GrassCutter
var go = new GameObject("Terrain"); var go = new GameObject("Terrain");
go.transform.SetParent(_root, false); go.transform.SetParent(_root, false);
go.transform.position = Planet.Center; go.transform.position = Planet.Center;
go.AddComponent<MeshFilter>().sharedMesh = m; _skinMf = go.AddComponent<MeshFilter>();
_skinMf.sharedMesh = m;
_nearSkin = m;
var mr = go.AddComponent<MeshRenderer>(); var mr = go.AddComponent<MeshRenderer>();
mr.sharedMaterial = soil; mr.sharedMaterial = soil;
mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
_skin = go.transform; _skin = go.transform;
} }
/// <summary>The ball's skin with every vertex about the same distance apart (a cube blown up into a sphere), facing out.</summary>
static Mesh BuildEvenSkin()
{
const int N = 160;
var verts = new List<Vector3>(6 * (N + 1) * (N + 1));
var tris = new List<int>(6 * N * N * 6);
Vector3[] fwd = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };
foreach (var f in fwd)
{
var a = Mathf.Abs(f.y) > 0.5f ? Vector3.right : Vector3.up;
var b = Vector3.Cross(f, a);
int o = verts.Count;
for (int y = 0; y <= N; y++)
for (int x = 0; x <= N; x++)
{
// tangent spacing evens the cells out towards the cube's edges
float u = Mathf.Tan((x / (float)N * 2f - 1f) * Mathf.PI * 0.25f);
float v = Mathf.Tan((y / (float)N * 2f - 1f) * Mathf.PI * 0.25f);
verts.Add((f + a * u + b * v).normalized);
}
for (int y = 0; y < N; y++)
for (int x = 0; x < N; x++)
{
int i0 = o + y * (N + 1) + x, i1 = i0 + 1, i2 = i0 + N + 1, i3 = i2 + 1;
AddOut(verts, tris, i0, i2, i1);
AddOut(verts, tris, i1, i2, i3);
}
}
var m = new Mesh { name = "PlanetSkinEven", indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 };
m.SetVertices(verts);
m.SetTriangles(tris, 0);
m.bounds = new Bounds(Vector3.zero, Vector3.one * Planet.Radius * 3f);
return m;
}
static void AddOut(List<Vector3> v, List<int> t, int a, int b, int c)
{
// Unity's front face: the side the clockwise normal points to; it must point out of the ball
if (Vector3.Dot(Vector3.Cross(v[b] - v[a], v[c] - v[a]), v[a]) < 0f) { int s = b; b = c; c = s; }
t.Add(a); t.Add(b); t.Add(c);
}
void Populate() void Populate()
{ {
var rng = new System.Random(7177); var rng = new System.Random(7177);

View File

@ -80,6 +80,9 @@ Shader "GrassCutter/GrassFur"
float4 _GcPushers[8]; // x, y, z, radius float4 _GcPushers[8]; // x, y, z, radius
float _GcPusherCount; float _GcPusherCount;
float _GcTime, _GcHeight, _GcFurScale, _GcFurMax; float _GcTime, _GcHeight, _GcFurScale, _GcFurMax;
// 0 normally; climbing to 1 as a film's lens leaves the ground: the whole field dissolves evenly into the
// planet's own far ground, so no ring of the near detail stays in shot
float _GcFarOnly;
struct Attributes struct Attributes
{ {
@ -183,6 +186,7 @@ Shader "GrassCutter/GrassFur"
float ign = frac(52.9829189 * frac(dot(i.positionCS.xy, float2(0.06711056, 0.00583715)))); float ign = frac(52.9829189 * frac(dot(i.positionCS.xy, float2(0.06711056, 0.00583715))));
float e = (ign - 0.5) * _GcShells.w; float e = (ign - 0.5) * _GcShells.w;
if ((_GcShells.y > 0 && dist < _GcShells.y + e) || dist >= _GcShells.z + e) discard; if ((_GcShells.y > 0 && dist < _GcShells.y + e) || dist >= _GcShells.z + e) discard;
if (_GcFarOnly > 0 && frac(ign * 7.31 + 0.37) < _GcFarOnly) discard;
// a sector's square reaches past its borders: each pixel belongs to one sector // a sector's square reaches past its borders: each pixel belongs to one sector
#if defined(GC_SECTOR_BUFFER) #if defined(GC_SECTOR_BUFFER)

View File

@ -45,6 +45,8 @@ Shader "GrassCutter/Ground"
float _GcSkyOn, _GcTime; float _GcSkyOn, _GcTime;
// 1 once the whole planet is mown (EndingCinematic): the far meadow is stubble and soil, as the cut sectors are drawn // 1 once the whole planet is mown (EndingCinematic): the far meadow is stubble and soil, as the cut sectors are drawn
float _GcBald; float _GcBald;
// a film's lens leaving the ground (0 .. 1): the sector lines go and the cloud shade softens
float _GcFarOnly;
float4 _GcCam; float4 _GcCam;
float4x4 _GcSkyRot; float4x4 _GcSkyRot;
float4 _GcIcoN[20], _GcIcoR0[20], _GcIcoR1[20], _GcIcoR2[20]; float4 _GcIcoN[20], _GcIcoR0[20], _GcIcoR1[20], _GcIcoR2[20];
@ -110,12 +112,13 @@ Shader "GrassCutter/Ground"
float edge = HexEdge(up); float edge = HexEdge(up);
float pixel = max(fwidth(edge), 1e-3); float pixel = max(fwidth(edge), 1e-3);
float line_ = (1 - smoothstep(0.1, 0.1 + pixel, edge)) * saturate(0.16 / pixel); float line_ = (1 - smoothstep(0.1, 0.1 + pixel, edge)) * saturate(0.16 / pixel);
col = lerp(col, _Border.rgb, line_ * (1 - smoothstep(120, 320, dist))); col = lerp(col, _Border.rgb, line_ * (1 - smoothstep(120, 320, dist)) * (1 - _GcFarOnly));
Light main = GetMainLight(TransformWorldToShadowCoord(p)); Light main = GetMainLight(TransformWorldToShadowCoord(p));
float ndl = saturate(dot(nrm, main.direction)); float ndl = saturate(dot(nrm, main.direction));
float3 ambient = SampleSH(_GcSkyOn > 0.5 ? mul((float3x3)_GcSkyRot, nrm) : nrm); float3 ambient = SampleSH(_GcSkyOn > 0.5 ? mul((float3x3)_GcSkyRot, nrm) : nrm);
float3 lit = col * (main.color * ndl * lerp(0.3, 1, main.shadowAttenuation) * GcCloudSun(p, _GcTime) + ambient + GcLamp(p)); float clouds = lerp(GcCloudSun(p, _GcTime), 1, _GcFarOnly * 0.6);
float3 lit = col * (main.color * ndl * lerp(0.3, 1, main.shadowAttenuation) * clouds + ambient + GcLamp(p));
lit *= GcContact(p); lit *= GcContact(p);
lit = MixFog(lit, i.fog); lit = MixFog(lit, i.fog);
return half4(lit, 1); return half4(lit, 1);