Skip to content

Physically-based punctual lighting system (point + spot lights)#81

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/design-physical-lighting-scheme
Draft

Physically-based punctual lighting system (point + spot lights)#81
Copilot wants to merge 3 commits intomainfrom
copilot/design-physical-lighting-scheme

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 27, 2026

The engine only supported a single main directional light. This adds a complete multi-light pipeline for point and spot lights with physically-based attenuation.

Shader

  • lighting/punctual_light.hlslh (new) — Inverse-square distance attenuation with smooth range windowing (saturate(1-(d/r)⁴)² / max(d²,ε)), spot angular falloff, Cook-Torrance BRDF evaluation per punctual light
  • layout/default_pass.hlslhPointLightData/SpotLightData structs + cbuffer bindings at slots 12–13 (MAX_POINT_LIGHTS=8, MAX_SPOT_LIGHTS=4)
  • layout/default_global_view.hlslhPointLightCount/SpotLightCount added to global cbuffer
  • standard_pbr.hlslENABLE_PUNCTUAL_LIGHTS pass option; light accumulation loop in FSMain

C++ core

  • RenderBuiltinLayout.h — GPU-matching structs (ShaderPointLightData, ShaderSpotLightData, buffer wrappers); ShaderPassInfo extended with light counts
  • LightBase.h/cppPointLight gets position/range; SpotLight gets position/direction/range/inner+outer cone angles
  • LightFeatureProcessorGatherPunctualLightData() collects lights into GPU-ready buffers each Tick()
  • DefaultForwardPipeline — UBO init + per-frame upload for light buffers at descriptor slots 12–13

ECS integration

  • PointLightComponent / SpotLightComponentComponentAdaptor + ITransformEvent pattern, serialization, registered in RenderModule

Usage

// Create a point light via ECS
auto *pl = lf->CreateLight<PointLight>();
pl->SetPosition({5.f, 3.f, 0.f});
pl->SetRange(20.f);
pl->SetColor({1.f, 0.8f, 0.6f});
pl->SetIntensity(100.f); // candela
// Shader — automatically iterated when ENABLE_PUNCTUAL_LIGHTS=1
for (uint pi = 0; pi < PointLightCount && pi < MAX_POINT_LIGHTS; ++pi)
    e0 += EvaluatePointLight(PointLights[pi], V, N, worldPos, pbrParam);
Original prompt

帮我设计一套物理光照方案


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 27, 2026 08:23
Add multi-light support with physically-based distance attenuation
(UE4/Frostbite inverse-square + range windowing) and spot light
angular falloff for point and spot lights.

Shader changes:
- Add PointLightData/SpotLightData structs in default_pass.hlslh
- Add light counts to global cbuffer
- New punctual_light.hlslh with EvaluatePointLight/EvaluateSpotLight
- Integrate punctual light loop in standard_pbr.hlsl (ENABLE_PUNCTUAL_LIGHTS)

C++ changes:
- Add ShaderPointLightData/ShaderSpotLightData/ShaderLightInfo to RenderBuiltinLayout.h
- Enhance PointLight/SpotLight with physical params (range, inner/outer cone)
- LightFeatureProcessor gathers punctual light data for GPU upload
- Pipeline binds light UBOs at slots 12-13
- New PointLightComponent/SpotLightComponent ECS components

Agent-Logs-Url: https://github.com/bluesky013/SkyEngine/sessions/443e8444-26ec-4c5b-b076-7543a63da3aa

Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
…dant copies

Agent-Logs-Url: https://github.com/bluesky013/SkyEngine/sessions/443e8444-26ec-4c5b-b076-7543a63da3aa

Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot AI changed the title [WIP] Design a physical lighting scheme Physically-based punctual lighting system (point + spot lights) Mar 27, 2026
Copilot AI requested a review from bluesky013 March 27, 2026 08:28
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.

2 participants