重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
godot-3d-lighting by thedivergentai/gd-agentic-skills
npx skills add https://github.com/thedivergentai/gd-agentic-skills --skill godot-3d-lighting提供带有阴影和全局光照的真实感 3D 光照专家指导。
size 设置为紧密贴合你的场景。:在实现相应模式之前,请阅读适当的脚本。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
基于一天中的时间动态调整太阳位置和颜色。处理 DirectionalLight3D 旋转、色温和强度曲线。用于户外昼夜系统。
用于全局光照设置的 VoxelGI 和 SDFGI 管理。
动态光源池和 LOD。根据相机距离管理光源剔除和阴影开关。用于优化多光源场景的性能。
体积雾和上帝光配置。运行时雾密度/颜色调整和光束设置。用于大气效果。
根据太阳角度和相机倾斜度动态调整 DirectionalLight3D 阴影分割距离的专家逻辑。
使用 Shadowmasking 模式进行混合静态/动态阴影的高级 LightmapGI 配置模式。
实时全局光照 (SDFGI) 的动态质量缩放器。调整单元大小和遮挡以权衡性能/质量。
使用 Tweens 和 Area3D 触发器为洞穴入口或森林空地实现平滑过渡的局部雾密度。
高效的“移动端全局光照”模式。使用无阴影的方向性填充光模拟地面反射的光线。
在游戏过程中过渡 WorldEnvironment 参数(天空、环境光、色调映射)的架构模式。
用于校正高保真方向光上“彼得潘现象”和“阴影痤疮”的优化脚本。
在密集环境中对 OmniLight3D 节点进行基于距离的阴影和可见性剔除。
性能感知的 ReflectionProbe 处理,针对大型环境变化使用手动 'Update Once' 触发器。
使用投影仪纹理模拟复杂阴影图案(格栅、玻璃波纹)的高细节光照。
# 适用于相机从近到远移动的户外场景
extends DirectionalLight3D
func _ready() -> void:
shadow_enabled = true
directional_shadow_mode = SHADOW_PARALLEL_4_SPLITS
# 分割距离(距离相机的米数)
directional_shadow_split_1 = 10.0 # 第一级联:0-10米
directional_shadow_split_2 = 50.0 # 第二级联:10-50米
directional_shadow_split_3 = 200.0 # 第三级联:50-200米
# 第四级联:200米 - 最大阴影距离
directional_shadow_max_distance = 500.0
# 质量与性能权衡
directional_shadow_blend_splits = true # 平滑过渡
# sun_controller.gd
extends DirectionalLight3D
@export var time_of_day := 12.0 # 0-24 小时
@export var rotation_speed := 0.1 # 每秒小时数
func _process(delta: float) -> void:
time_of_day += rotation_speed * delta
if time_of_day >= 24.0:
time_of_day -= 24.0
# 旋转太阳(0° = 正午,180° = 午夜)
var angle := (time_of_day - 12.0) * 15.0 # 每小时 15°
rotation_degrees.x = -angle
# 调整强度
if time_of_day < 6.0 or time_of_day > 18.0:
light_energy = 0.0 # 夜晚
elif time_of_day < 7.0:
light_energy = remap(time_of_day, 6.0, 7.0, 0.0, 1.0) # 日出
elif time_of_day > 17.0:
light_energy = remap(time_of_day, 17.0, 18.0, 1.0, 0.0) # 日落
else:
light_energy = 1.0 # 白天
# 颜色偏移
if time_of_day < 8.0 or time_of_day > 16.0:
light_color = Color(1.0, 0.7, 0.4) # 橙色(黎明/黄昏)
else:
light_color = Color(1.0, 1.0, 0.9) # 中性白色
# torch.gd
extends OmniLight3D
func _ready() -> void:
omni_range = 10.0 # 最大范围
omni_attenuation = 2.0 # 衰减曲线(1.0 = 线性,2.0 = 二次方/真实)
# 对于“魔法”光源,减少衰减
omni_attenuation = 0.5 # 更平缓的衰减,范围更远
# campfire.gd
extends OmniLight3D
@export var base_energy := 1.0
@export var flicker_strength := 0.3
@export var flicker_speed := 5.0
func _process(delta: float) -> void:
var flicker := sin(Time.get_ticks_msec() * 0.001 * flicker_speed) * flicker_strength
light_energy = base_energy + flicker
# flashlight.gd
extends SpotLight3D
func _ready() -> void:
spot_range = 20.0
spot_angle = 45.0 # 锥形角度(度)
spot_angle_attenuation = 2.0 # 边缘柔和度
shadow_enabled = true
# 投影仪纹理(可选 - 遮光片/图案片)
light_projector = load("res://textures/flashlight_mask.png")
# player_flashlight.gd
extends SpotLight3D
@onready var camera: Camera3D = get_viewport().get_camera_3d()
func _process(delta: float) -> void:
if camera:
global_transform = camera.global_transform
| 特性 | VoxelGI | SDFGI |
|---|---|---|
| 设置 | 每个房间手动设置边界 | 自动,场景范围 |
| 动态物体 | 完全支持 | 部分支持 |
| 性能 | 中等 | 成本较高 |
| 使用场景 | 室内,中小型场景 | 大型户外场景 |
| Godot 版本 | 4.0+ | 4.0+ |
# room_gi.gd - 每个房间/区域放置一个 VoxelGI
extends VoxelGI
func _ready() -> void:
# 紧密贴合房间
size = Vector3(20, 10, 20)
# 质量设置
subdiv = VoxelGI.SUBDIV_128 # 越高 = 质量越好,越慢
# 烘焙全局光照数据
bake()
# world_environment.gd
extends WorldEnvironment
func _ready() -> void:
var env := environment
# 启用 SDFGI
env.sdfgi_enabled = true
env.sdfgi_use_occlusion = true
env.sdfgi_read_sky_light = true
# 级联(基于相机自动缩放)
env.sdfgi_min_cell_size = 0.2 # 细节级别
env.sdfgi_max_distance = 200.0
# 场景结构:
# - LightmapGI 节点
# - 带有 GeometryInstance3D.gi_mode = STATIC 的 StaticBody3D 网格
# lightmap_baker.gd
extends LightmapGI
func _ready() -> void:
# 质量设置
quality = LightmapGI.BAKE_QUALITY_HIGH
bounces = 3 # 间接光反弹次数
# 烘焙(仅在编辑器中,非运行时)
# 点击编辑器中的 "Bake Lightmaps" 按钮
# world_env.gd
extends WorldEnvironment
func _ready() -> void:
var env := environment
env.background_mode = Environment.BG_SKY
var sky := Sky.new()
var sky_material := PanoramaSkyMaterial.new()
sky_material.panorama = load("res://hdri/sky.hdr")
sky.sky_material = sky_material
env.sky = sky
# 天空对全局光照的贡献
env.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
env.ambient_light_sky_contribution = 1.0
extends WorldEnvironment
func _ready() -> void:
var env := environment
env.volumetric_fog_enabled = true
env.volumetric_fog_density = 0.01
env.volumetric_fog_albedo = Color(0.9, 0.9, 1.0) # 偏蓝色
env.volumetric_fog_emission = Color.BLACK
用于局部反射(镜子、闪亮的地板):
# reflection_probe.gd
extends ReflectionProbe
func _ready() -> void:
# 捕获区域
size = Vector3(10, 5, 10)
# 质量
resolution = ReflectionProbe.RESOLUTION_512
# 更新模式
update_mode = ReflectionProbe.UPDATE_ONCE # 烘焙一次
# 或 UPDATE_ALWAYS 用于动态反射(开销大)
# 推荐限制:
# - 带阴影的 DirectionalLight3D:1-2 个
# - 带阴影的 OmniLight3D:3-5 个
# - 带阴影的 SpotLight3D:2-4 个
# - 不带阴影的 OmniLight3D:20-30 个
# - 不带阴影的 SpotLight3D:15-20 个
# 在次要光源上禁用阴影
@onready var candle_lights: Array = [$Candle1, $Candle2, $Candle3]
func _ready() -> void:
for light in candle_lights:
light.shadow_enabled = false # 节省性能
# 对远处的光源禁用阴影
extends OmniLight3D
@export var shadow_max_distance := 50.0
func _process(delta: float) -> void:
var camera := get_viewport().get_camera_3d()
if camera:
var dist := global_position.distance_to(camera.global_position)
shadow_enabled = (dist < shadow_max_distance)
# 问题:薄地板让阴影穿透
# 解决方案:增加阴影偏移
extends DirectionalLight3D
func _ready() -> void:
shadow_enabled = true
shadow_bias = 0.1 # 如果阴影渗漏,请增加此值
shadow_normal_bias = 2.0
# 问题:VoxelGI 光线透过墙壁泄漏
# 解决方案:每个房间放置 VoxelGI 节点,不要重叠
# 同时:确保墙壁有适当的厚度(不是纸一样薄)
为远处的物体渲染实时阴影开销太大。通过将 DirectionalLight3D 设置为 Dynamic 烘焙模式并烘焙 LightmapGI 来使用阴影遮罩。这将远处的阴影烘焙到纹理中,同时允许动态物体在近处投射实时阴影,防止“双重阴影”伪影。
如果你完全无法承受全局光照的开销(例如,严格的移动端限制),那就模拟它!复制你的主 DirectionalLight3D,将其旋转 180 度(从地面向上照射),关闭阴影,将高光设置为 0.0,并将能量减少到 10-40%。这样可以廉价地模拟地面反射的光线。
Godot 的 OmniLight3D 缩放可以模拟百分比接近软阴影(距离投射体越远阴影越模糊)。
extends OmniLight3D
func _ready() -> void:
# 模拟面光源和百分比接近软阴影 (PCSS)。
# 注意:高性能开销。保持 light_size > 0.0 的光源数量较少。
light_size = 0.5
shadow_enabled = true
# 距离淡出在超出范围时完全剔除光源和阴影,
# 防止集群渲染器因太多重叠的 PCSS 光源而卡顿。
distance_fade_enabled = true
distance_fade_begin = 20.0
distance_fade_length = 5.0
每周安装数
72
代码仓库
GitHub 星标数
59
首次出现
2026年2月10日
安全审计
安装于
gemini-cli70
opencode70
codex69
kimi-cli67
github-copilot67
amp67
Expert guidance for realistic 3D lighting with shadows and global illumination.
size to tightly fit your scene.MANDATORY : Read the appropriate script before implementing the corresponding pattern.
Dynamic sun position and color based on time-of-day. Handles DirectionalLight3D rotation, color temperature, and intensity curves. Use for outdoor day/night systems.
VoxelGI and SDFGI management for global illumination setup.
Dynamic light pooling and LOD. Manages light culling and shadow toggling based on camera distance. Use for performance optimization with many lights.
Volumetric fog and god ray configuration. Runtime fog density/color adjustments and light shaft setup. Use for atmospheric effects.
Expert logic for adjusting DirectionalLight3D shadow split distances dynamically based on sun angle and camera tilt.
Advanced LightmapGI configuration pattern using Shadowmasking mode for hybrid static/dynamic shadowing.
Dynamic quality scaler for real-time Global Illumination (SDFGI). Adjusts cell size and occlusion for performance/quality trade-offs.
Smoothly transitioning localized fog density for cave entrances or forest clearings using Tweens and Area3D triggers.
Efficient 'Mobile-GI' pattern. Simulates light bouncing off the floor using non-shadowed directional fill lights.
Architectural pattern for transitioning WorldEnvironment parameters (Sky, Ambient, Tonemap) during gameplay.
Optimization script for correcting 'Peter Panning' and 'Shadow Acne' on high-fidelity directional lights.
Distance-based shadow and visibility culling for OmniLight3D nodes in dense environments.
Performance-aware ReflectionProbe handling using manual 'Update Once' triggers for large environmental changes.
High-detail lighting using Projector textures to fake complex shadow patterns (grates, glass ripples).
# For outdoor scenes with camera moving from near to far
extends DirectionalLight3D
func _ready() -> void:
shadow_enabled = true
directional_shadow_mode = SHADOW_PARALLEL_4_SPLITS
# Split distances (in meters from camera)
directional_shadow_split_1 = 10.0 # First cascade: 0-10m
directional_shadow_split_2 = 50.0 # Second: 10-50m
directional_shadow_split_3 = 200.0 # Third: 50-200m
# Fourth cascade: 200m - max shadow distance
directional_shadow_max_distance = 500.0
# Quality vs performance
directional_shadow_blend_splits = true # Smooth transitions
# sun_controller.gd
extends DirectionalLight3D
@export var time_of_day := 12.0 # 0-24 hours
@export var rotation_speed := 0.1 # Hours per second
func _process(delta: float) -> void:
time_of_day += rotation_speed * delta
if time_of_day >= 24.0:
time_of_day -= 24.0
# Rotate sun (0° = noon, 180° = midnight)
var angle := (time_of_day - 12.0) * 15.0 # 15° per hour
rotation_degrees.x = -angle
# Adjust intensity
if time_of_day < 6.0 or time_of_day > 18.0:
light_energy = 0.0 # Night
elif time_of_day < 7.0:
light_energy = remap(time_of_day, 6.0, 7.0, 0.0, 1.0) # Sunrise
elif time_of_day > 17.0:
light_energy = remap(time_of_day, 17.0, 18.0, 1.0, 0.0) # Sunset
else:
light_energy = 1.0 # Day
# Color shift
if time_of_day < 8.0 or time_of_day > 16.0:
light_color = Color(1.0, 0.7, 0.4) # Orange (dawn/dusk)
else:
light_color = Color(1.0, 1.0, 0.9) # Neutral white
# torch.gd
extends OmniLight3D
func _ready() -> void:
omni_range = 10.0 # Maximum reach
omni_attenuation = 2.0 # Falloff curve (1.0 = linear, 2.0 = quadratic/realistic)
# For "magical" lights, reduce attenuation
omni_attenuation = 0.5 # Flatter falloff, reaches farther
# campfire.gd
extends OmniLight3D
@export var base_energy := 1.0
@export var flicker_strength := 0.3
@export var flicker_speed := 5.0
func _process(delta: float) -> void:
var flicker := sin(Time.get_ticks_msec() * 0.001 * flicker_speed) * flicker_strength
light_energy = base_energy + flicker
# flashlight.gd
extends SpotLight3D
func _ready() -> void:
spot_range = 20.0
spot_angle = 45.0 # Cone angle (degrees)
spot_angle_attenuation = 2.0 # Edge softness
shadow_enabled = true
# Projector texture (optional - cookie/gobo)
light_projector = load("res://textures/flashlight_mask.png")
# player_flashlight.gd
extends SpotLight3D
@onready var camera: Camera3D = get_viewport().get_camera_3d()
func _process(delta: float) -> void:
if camera:
global_transform = camera.global_transform
| Feature | VoxelGI | SDFGI |
|---|---|---|
| Setup | Manual bounds per room | Automatic, scene-wide |
| Dynamic objects | Fully supported | Partially supported |
| Performance | Moderate | Higher cost |
| Use case | Indoor, small-medium scenes | Large outdoor scenes |
| Godot version | 4.0+ | 4.0+ |
# room_gi.gd - Place one VoxelGI per room/area
extends VoxelGI
func _ready() -> void:
# Tightly fit the room
size = Vector3(20, 10, 20)
# Quality settings
subdiv = VoxelGI.SUBDIV_128 # Higher = better quality, slower
# Bake GI data
bake()
# world_environment.gd
extends WorldEnvironment
func _ready() -> void:
var env := environment
# Enable SDFGI
env.sdfgi_enabled = true
env.sdfgi_use_occlusion = true
env.sdfgi_read_sky_light = true
# Cascades (auto-scale based on camera)
env.sdfgi_min_cell_size = 0.2 # Detail level
env.sdfgi_max_distance = 200.0
# Scene structure:
# - LightmapGI node
# - StaticBody3D meshes with GeometryInstance3D.gi_mode = STATIC
# lightmap_baker.gd
extends LightmapGI
func _ready() -> void:
# Quality settings
quality = LightmapGI.BAKE_QUALITY_HIGH
bounces = 3 # Indirect light bounces
# Bake (editor only, not runtime)
# Click "Bake Lightmaps" button in editor
# world_env.gd
extends WorldEnvironment
func _ready() -> void:
var env := environment
env.background_mode = Environment.BG_SKY
var sky := Sky.new()
var sky_material := PanoramaSkyMaterial.new()
sky_material.panorama = load("res://hdri/sky.hdr")
sky.sky_material = sky_material
env.sky = sky
# Sky contribution to GI
env.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
env.ambient_light_sky_contribution = 1.0
extends WorldEnvironment
func _ready() -> void:
var env := environment
env.volumetric_fog_enabled = true
env.volumetric_fog_density = 0.01
env.volumetric_fog_albedo = Color(0.9, 0.9, 1.0) # Blueish
env.volumetric_fog_emission = Color.BLACK
For localized reflections (mirrors, shiny floors):
# reflection_probe.gd
extends ReflectionProbe
func _ready() -> void:
# Capture area
size = Vector3(10, 5, 10)
# Quality
resolution = ReflectionProbe.RESOLUTION_512
# Update mode
update_mode = ReflectionProbe.UPDATE_ONCE # Bake once
# or UPDATE_ALWAYS for dynamic reflections (expensive)
# Recommended limits:
# - DirectionalLight3D with shadows: 1-2
# - OmniLight3D with shadows: 3-5
# - SpotLight3D with shadows: 2-4
# - OmniLight3D without shadows: 20-30
# - SpotLight3D without shadows: 15-20
# Disable shadows on minor lights
@onready var candle_lights: Array = [$Candle1, $Candle2, $Candle3]
func _ready() -> void:
for light in candle_lights:
light.shadow_enabled = false # Save performance
# Disable shadows for distant lights
extends OmniLight3D
@export var shadow_max_distance := 50.0
func _process(delta: float) -> void:
var camera := get_viewport().get_camera_3d()
if camera:
var dist := global_position.distance_to(camera.global_position)
shadow_enabled = (dist < shadow_max_distance)
# Problem: Thin floors let shadows through
# Solution: Increase shadow bias
extends DirectionalLight3D
func _ready() -> void:
shadow_enabled = true
shadow_bias = 0.1 # Increase if shadows bleed through
shadow_normal_bias = 2.0
# Problem: VoxelGI light bleeds through walls
# Solution: Place VoxelGI nodes per-room, don't overlap
# Also: Ensure walls have proper thickness (not paper-thin)
Rendering real-time shadows for distant objects is too expensive. Use Shadowmasking by setting a DirectionalLight3D to the Dynamic bake mode while baking a LightmapGI. This bakes distant shadows into a texture while allowing dynamic objects to cast real-time shadows up close, preventing "double shadowing" artifacts.
If you cannot afford GI at all (e.g., strict mobile constraints), fake it! Duplicate your main DirectionalLight3D, rotate it 180 degrees (pointing up from the ground), turn Shadows OFF, set Specular to 0.0, and reduce Energy to 10-40%. This cheaply simulates bounced floor lighting.
Godot's OmniLight3D scaling can simulate Percentage-Closer Soft Shadows (blurrier shadows further from the caster).
extends OmniLight3D
func _ready() -> void:
# Simulates area lights and Percentage-Closer Soft Shadows (PCSS).
# Note: High performance cost. Keep the number of lights with light_size > 0.0 low.
light_size = 0.5
shadow_enabled = true
# Distance fade culls the light and shadow completely when out of range,
# preventing the clustered renderer from choking on too many overlapping PCSS lights.
distance_fade_enabled = true
distance_fade_begin = 20.0
distance_fade_length = 5.0
Weekly Installs
72
Repository
GitHub Stars
59
First Seen
Feb 10, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli70
opencode70
codex69
kimi-cli67
github-copilot67
amp67
TanStack Query v5 完全指南:React 数据管理、乐观更新、离线支持
2,500 周安装
员工手册AI助手:快速解答公司政策、福利、流程问题,提升HR效率
96 周安装
arch-tsdown-cli:TypeScript CLI项目启动模板,支持ESM、d.ts自动生成与npm可信发布
98 周安装
Spec设计调研技能:AI驱动需求分析,系统化提取未知项并生成研究任务
97 周安装
Next.js OG 图像生成 - 动态社交预览图片生成方案,支持服务器端渲染和构建时缓存
97 周安装
Zustand 5 状态管理教程:基础存储、持久化、选择器、异步操作与切片模式
63 周安装
Axios HTTP 客户端教程:Promise 驱动的浏览器与 Node.js 请求库
99 周安装