-
Notifications
You must be signed in to change notification settings - Fork 17
feat: dynamic lights #3113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: dynamic lights #3113
Changes from all commits
570d7e4
12e4864
39453f9
86e2200
d5db45f
7a8aa36
14598d9
75f58ea
1fc1ec2
e3a8e0c
0a8fbdf
4e6d6aa
08a6a1c
9434230
5cbe598
148cfef
8ed45b1
a544ebc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| using Arch.SystemGroups; | ||
| using CrdtEcsBridge.Components.Conversion; | ||
| using Cysharp.Threading.Tasks; | ||
| using DCL.AssetsProvision; | ||
| using DCL.ECSComponents; | ||
| using DCL.Optimization.Pools; | ||
| using DCL.PluginSystem.World.Dependencies; | ||
| using DCL.ResourcesUnloading; | ||
| using DCL.SDKComponents.LightSource; | ||
| using DCL.SDKComponents.LightSource.Systems; | ||
| using ECS.LifeCycle; | ||
| using ECS.LifeCycle.Systems; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using Unity.Mathematics; | ||
| using UnityEngine; | ||
| using UnityEngine.AddressableAssets; | ||
| using Object = UnityEngine.Object; | ||
|
|
||
| namespace DCL.PluginSystem.World | ||
| { | ||
| public class LightSourcePlugin : IDCLWorldPlugin<LightSourcePlugin.LightSourceSettings> | ||
| { | ||
| private static LightSourceDefaults lightSourceDefaults; | ||
| private readonly IComponentPoolsRegistry poolsRegistry; | ||
| private readonly IAssetsProvisioner assetsProvisioner; | ||
| private readonly CacheCleaner cacheCleaner; | ||
| private IComponentPool<Light>? lightPoolRegistry; | ||
|
|
||
| public LightSourcePlugin( | ||
| IComponentPoolsRegistry poolsRegistry, | ||
| IAssetsProvisioner assetsProvisioner, | ||
| CacheCleaner cacheCleaner) | ||
| { | ||
| this.assetsProvisioner = assetsProvisioner; | ||
| this.poolsRegistry = poolsRegistry; | ||
| this.cacheCleaner = cacheCleaner; | ||
| } | ||
|
|
||
| public void Dispose() { } | ||
|
|
||
| public void InjectToWorld(ref ArchSystemsWorldBuilder<Arch.Core.World> builder, in ECSWorldInstanceSharedDependencies sharedDependencies, in PersistentEntities persistentEntities, List<IFinalizeWorldSystem> finalizeWorldSystems, List<ISceneIsCurrentListener> sceneIsCurrentListeners) | ||
| { | ||
| finalizeWorldSystems.Add(LightSourceSystem.InjectToWorld( | ||
| ref builder, | ||
| sharedDependencies.SceneData, | ||
| sharedDependencies.SceneStateProvider, | ||
| sharedDependencies.ScenePartition, | ||
| lightPoolRegistry | ||
| )); | ||
|
|
||
| ResetDirtyFlagSystem<PBLightSource>.InjectToWorld(ref builder); | ||
| } | ||
|
|
||
| public async UniTask InitializeAsync(LightSourceSettings settings, CancellationToken ct) => | ||
| await CreateLightSourcePoolAsync(settings, ct); | ||
|
|
||
| private async UniTask CreateLightSourcePoolAsync(LightSourceSettings settings, CancellationToken ct) | ||
| { | ||
| lightSourceDefaults = (await assetsProvisioner.ProvideMainAssetAsync(settings.LightSourceDefaultValues, ct: ct)).Value; | ||
| Light light = (await assetsProvisioner.ProvideMainAssetAsync(settings.LightSourcePrefab, ct: ct)).Value.GetComponent<Light>(); | ||
| lightPoolRegistry = poolsRegistry.AddGameObjectPool(() => Object.Instantiate(light, Vector3.zero, quaternion.identity), onRelease: OnPoolRelease, onGet: OnPoolGet); | ||
| cacheCleaner.Register(lightPoolRegistry); | ||
| } | ||
|
|
||
| private static void OnPoolRelease(Light light) => | ||
| light.enabled = false; | ||
|
|
||
| private static void OnPoolGet(Light light) | ||
| { | ||
| light.enabled = lightSourceDefaults.active; | ||
| light.transform.SetParent(null); | ||
| light.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity); | ||
| light.color = lightSourceDefaults.color; | ||
| light.intensity = PrimitivesConversionExtensions.PBBrightnessInLumensToUnityCandels(lightSourceDefaults.brightness); | ||
| light.range = lightSourceDefaults.range; | ||
| light.type = LightType.Spot; | ||
| light.shadows = LightShadows.None; | ||
| light.innerSpotAngle = lightSourceDefaults.innerAngle; | ||
| light.spotAngle = lightSourceDefaults.outerAngle; | ||
| light.cookie = null; | ||
| } | ||
|
|
||
| public struct LightSourceSettings : IDCLPluginSettings | ||
| { | ||
| [field: SerializeField] | ||
| public AssetReferenceGameObject LightSourcePrefab; | ||
|
|
||
| [field: SerializeField] | ||
| public LightDefaultsRef LightSourceDefaultValues; | ||
|
|
||
| [Serializable] | ||
| public class LightDefaultsRef : AssetReferenceT<LightSourceDefaults> | ||
| { | ||
| public LightDefaultsRef(string guid) : base(guid) { } | ||
| } | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using UnityEngine; | ||
| using Promise = ECS.StreamableLoading.Common.AssetPromise<ECS.StreamableLoading.Textures.Texture2DData, ECS.StreamableLoading.Textures.GetTextureIntention>; | ||
|
|
||
| namespace DCL.SDKComponents.LightSource | ||
| { | ||
| public struct LightSourceComponent | ||
| { | ||
| public readonly Light lightSourceInstance; | ||
| public Promise? TextureMaskPromise; | ||
|
|
||
| public LightSourceComponent(Light lightSourceInstance) | ||
| { | ||
| this.lightSourceInstance = lightSourceInstance; | ||
| TextureMaskPromise = null; | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using DCL.ECSComponents; | ||
| using System; | ||
| using UnityEngine; | ||
|
|
||
| namespace DCL.SDKComponents.LightSource | ||
| { | ||
| [CreateAssetMenu(fileName = "LightSourceDefaults", menuName = "DCL/LightSource/LightSource Default Settings", order = 1)] | ||
| [Serializable] | ||
| public class LightSourceDefaults : ScriptableObject | ||
| { | ||
| // I'll update the url when the protocol PR is merged | ||
| [Header("These values come from the protocol definition \nfound here: https://github.com/decentraland/protocol/pull/234")] | ||
| public bool active; | ||
| public Color color; | ||
| public float brightness; | ||
| public float range; | ||
|
|
||
| [Header("Point Settings")] | ||
| public PBLightSource.Types.ShadowType pointShadowType; | ||
|
|
||
| [Header("Spot Settings")] | ||
| public PBLightSource.Types.ShadowType spotShadowType; | ||
| public float innerAngle; | ||
| public float outerAngle; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "LightSource", | ||
| "rootNamespace": "", | ||
| "references": [ | ||
| "GUID:1b8e1e1bd01505f478f0369c04a4fb2f", | ||
| "GUID:4794e238ed0f65142a4aea5848b513e5", | ||
| "GUID:3640f3c0b42946b0b8794a1ed8e06ca5", | ||
| "GUID:286980af24684da6acc1caa413039811", | ||
| "GUID:3c7b57a14671040bd8c549056adc04f5", | ||
| "GUID:d414ef88f3b15f746a4b97636b50dfb4", | ||
| "GUID:0d87731a01a547bd97421cb01c596850", | ||
| "GUID:275e22790c04e9b47a5085d7b0c4432a" | ||
| ], | ||
| "includePlatforms": [], | ||
| "excludePlatforms": [], | ||
| "allowUnsafeCode": false, | ||
| "overrideReferences": false, | ||
| "precompiledReferences": [], | ||
| "autoReferenced": true, | ||
| "defineConstraints": [], | ||
| "versionDefines": [], | ||
| "noEngineReferences": false | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!114 &11400000 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 0} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: 3f88d85d4a404487b6d1d67e6a3b6a09, type: 3} | ||
| m_Name: LightSourceDefaults | ||
| m_EditorClassIdentifier: | ||
| active: 1 | ||
| color: {r: 1, g: 1, b: 1, a: 1} | ||
| brightness: 250 | ||
| range: 10 | ||
| pointShadowType: 0 | ||
| spotShadowType: 0 | ||
| innerAngle: 21.8 | ||
| outerAngle: 30 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.