Kaira Digital ArtsKaira Digital Arts
Sayfalar (23)Lens flare occlusion

Lens flare occlusion

Son güncelleme: 6 Ekim 2026

Bu sayfa henüz Türkçeye çevrilmedi, İngilizcesi gösteriliyor.

Two scripts that make the sun's Lens Flare (SRP) fade correctly when something moves in front of the sun. They read the depth buffer instead of casting rays, so they need no colliders and they see alpha clipped geometry: a flare fades behind tree leaves out of the box.

ScriptRole
LensFlareDepthOcclusionFeatureURP renderer feature. Samples scene depth in a ring around the sun's screen position and reads the result back without stalling the GPU
LensFlareSmoothOcclusionComponent on the sun light. Turns that visibility into the flare's intensity through two independent fade channels

Setup

  1. Add Lens Flare Depth Occlusion Feature to your URP Renderer asset (Add Renderer Feature). The Quick Start window flags it as missing as soon as a scene uses the component, and adds it with one click.
  2. Its Shader field finds Hidden/LensFlareDepthOcclusion by itself. Assign it by hand only if you renamed the shader.
  3. Enable Depth Texture on the URP asset.
  4. Add a Lens Flare (SRP) component to the sun light. A ready made flare is included at Content/Flare/LensFlare.asset.
  5. Add Lens Flare Smooth Occlusion to the same object.

The Celestial Module finds the component and fades it with the sun height and the cloud cover (Auto Lens Flare).

The two fade channels

The reason a flare disappears matters, so the component keeps the two causes apart:

ChannelBehaviour
ObstacleA leaf, rock or building moves in front of the sun: the intensity is cut at once, because a real obstacle blocks light at once. When it clears, the flare fills back in over fadeInDuration
Screen edgeThe sun leaves the view with nothing in the way: the flare fades out smoothly across screenEdgeFadeMargin, reaching zero before the sun crosses the border
text
intensity = maxIntensity * easing(obstacle visibility) * screen edge fade * VisibilityMultiplier

Settings

SettingDefaultDescription
lensFlare, viewCameraFall back to the component on the same object and to the main camera
sampleRadius0.012Depth sampling radius around the sun in screen UV. Larger softens the occlusion edge
sampleCount8Ring samples. More give smoother partial occlusion
fadeInDuration0.35Seconds to return to full brightness
instantOccludeonAn obstacle cuts the flare at once. Off, it fades out as well
easingease in and outCurve applied to the smoothed obstacle visibility
screenEdgeFadeMargin0.15Fade band along the screen border, as a fraction of the screen height. 0 cuts the flare hard at the border
fadeOutDuration0.5Rate limit for the screen edge fade, so a fast camera turn does not pop
maxIntensity0Intensity at full visibility. 0 takes the flare's own value on Awake

API

MemberDescription
float MaxIntensityTarget brightness at full visibility. The component writes lensFlare.intensity every frame, so change this instead
float VisibilityMultiplierRuntime dimmer on top of everything else, not saved. The Celestial Module drives it
float SunVisibilityLast visibility read back from the depth pass: 0 blocked, 1 clear

The occlusion pass runs for Game cameras only, so the Scene view always shows the flare unoccluded. Like the fog, it is recorded through Render Graph only. The component also switches off the flare's own occlusion option, because it manages occlusion itself.

Bu sayfaya bağlantı veren sayfalar

Hâlâ takıldınız mı?

Unity sürümünüzü, render pipeline bilginizi ve sorunun ekran görüntüsünü gönderin.

Destek alın