Skip to content

Add sky controller prefab for sun positioning#187

Draft
argallegos wants to merge 19 commits into
mainfrom
sky-controller
Draft

Add sky controller prefab for sun positioning#187
argallegos wants to merge 19 commits into
mainfrom
sky-controller

Conversation

@argallegos

Copy link
Copy Markdown
Contributor

This implements a sun, sky, and atmosphere solution for Cesium for Unity per #173.
Includes the following components:

  • A sky controller script that exposes time of day and other settings to the user to control direction of the sun
  • A prefab that users can add to their levels to quickly set the required parameters
  • A skybox shader for URP that creates an atmosphere blending effect when the camera moves from earth to space.

It's currently a work in progress. Remaining items:

  • Ensure HDRP compatibility - this is primarily on the shader side, but further work needs to be done to tie the prefab to the HDRP atmosphere options.
  • Implement sun positioning math in cesium-native
  • Sky shader
    • Improved atmospheric blending
    • A ground color that reduces the visual impact of missing tiles

@flankechen

Copy link
Copy Markdown

looking forward for the implementation. is this branch merge into main or any tags now?
I try 1.7.1 sample sky-controller branch, not working. any idea of which sample branch I should use if going to try this?

@kring

kring commented Jan 8, 2024

Copy link
Copy Markdown
Member

It's not available in any pre-built binaries. If you want to use this, the only option is to build from this PR's branch yourself. It's based on a very old version of Cesium for Unity, though, so you'll probably want to merge in main. In short, it's likely to be a lot of work. Sorry we don't have a simple solution right now.

@flankechen

Copy link
Copy Markdown

It's not available in any pre-built binaries. If you want to use this, the only option is to build from this PR's branch yourself. It's based on a very old version of Cesium for Unity, though, so you'll probably want to merge in main. In short, it's likely to be a lot of work. Sorry we don't have a simple solution right now.

I did try to build cesium from this PR branch and try to run in some cesium example branches, sadly not working. yeap, this looks some old codes. I might not have time for a more deep dive into this. Anyway, looking forward for this to develped and merge into main branch and get release. UE sky looks cool, looking forward for Unity.

@asafMasa

Copy link
Copy Markdown

Hi,
@argallegos are you still working on this PR?
It sounds real nice to have this in Unity

@kring

kring commented Jun 19, 2025

Copy link
Copy Markdown
Member

@asafMasa Alex isn't working on this anymore unfortunately, but we'd be very happy to see someone from the community pick it up and run with it!

@j9liu j9liu linked an issue Dec 1, 2025 that may be closed by this pull request
@baruchInsert-tech

Copy link
Copy Markdown
Contributor

Hi @kring, I'd like to pick this up and get sun/sky/atmosphere (#173) across the line.

I saw this PR has been sitting since early 2023 and is based on a pretty old version of Cesium for Unity, and that you mentioned you'd be happy for someone from the community to run with it. I've spent some time digging into the problem and I'd like to take it on.

Rather than try to revive this branch as-is, I'm planning to rebase the good ideas here onto current main and rework it into a few smaller, reviewable pieces. I went through the existing code here, the CesiumSunSky actor in cesium-unreal, and the CesiumJS Clock example to make sure I understand what "correct" looks like before writing anything.

Here's the plan I'm proposing:

Phase 1 - Sun + URP sky

  • A CesiumSkyController component with date, time of day, and time zone. Latitude/longitude come from the CesiumGeoreference, same as Unreal.
  • Sun position from the NOAA solar algorithm (the same one Unreal's Sun Position Calculator uses).
  • Orient a directional light from it, drive ambient, and a custom URP skybox shader that fades to black as you leave the surface - basically what this PR already started.

Phase 2 - Clock + UI

  • A small CesiumClock (start/current/stop time, multiplier, play/pause, loop) mirroring CesiumJS's Clock, plus a simple on-screen play/pause/speed/scrub UI so the day/night cycle can actually animate.

Phase 3 - HDRP

  • Wire the same sun up to HDRP's Physically Based Sky and port Unreal's trick of adjusting the atmosphere ground radius by camera height, which is what fixes the "artifacts from space" problem Sun, sky, and atmosphere implementation #173 mentions.

Phase 4 - Integration + polish

  • Prefab + Quick Add entry so it's drag-and-drop, tests for the solar math, and visual polish.

A couple of things I ran into that I'd like your input on before I start:

  1. This PR's checklist has "Implement sun positioning math in cesium-native". In my prototyping I found it's clean to do entirely in C# (the sun is far enough away that its ECEF direction is effectively the same everywhere on Earth, so no observer position is needed, and it matches how CesiumJS produces sunDirectionWC). Is there a reason you'd prefer it live in cesium-native, or is a C# implementation acceptable?

  2. One correctness note: I'd compute the sun direction in ECEF and convert with the georeference's transforms rather than building it in a local East/Up/North frame. The ENU shortcut is only correct in CartographicOrigin placement mode - it silently breaks in TrueOrigin mode - so going through ECEF keeps it correct in both.

If this direction sounds good I'll start on Phase 1 and open it as its own PR so it's easy to review in isolation. Thanks!

@kring

kring commented Jul 22, 2026

Copy link
Copy Markdown
Member

Hi @baruchInsert-tech, thanks for picking this up! Your plan sounds reasonable to me, though @j9liu and @azrogers may want to weigh in as well.

Regarding cesium-native versus C#, the main advantage to putting it in cesium-native is that it allows it to be used across engines. For example, if the sun position were implemented in C# and we wanted to add it to 3D Tiles for Godot, we would need to reimplement it. Adding it to cesium-native makes it more widely reusable.

So I would say that's not a strict requirement, but as long as the burden isn't too unreasonably high for you, I would definitely recommend that you do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sun, sky, and atmosphere implementation

6 participants