Skip to content
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

Merged
merged 18 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
570d7e4
Pointed protocol to feature branch. Generated classes.
AlejandroAlvarezMelucciDCL Jan 13, 2025
12e4864
First iteration of new component LightSource
AlejandroAlvarezMelucciDCL Jan 16, 2025
39453f9
Added LightSourceSystem World Plugins Container and LightSource prefa…
AlejandroAlvarezMelucciDCL Jan 21, 2025
86e2200
Fixed wrong component being released to the pool
AlejandroAlvarezMelucciDCL Jan 21, 2025
d5db45f
Fixed Transform tweens on entities that also have MaterialComponent t…
AlejandroAlvarezMelucciDCL Jan 23, 2025
7a8aa36
Added LightSource to ResetDirtyFlagSystem
AlejandroAlvarezMelucciDCL Jan 23, 2025
14598d9
Merge branch 'dev' into feat/dynamic-lights
AlejandroAlvarezMelucciDCL Jan 24, 2025
75f58ea
Updated protocol and reverted SocialService.V3 to V2
AlejandroAlvarezMelucciDCL Jan 24, 2025
1fc1ec2
Added full support to tweak LightSource from the SDK. Minor cleanups.
AlejandroAlvarezMelucciDCL Jan 24, 2025
e3a8e0c
Updated protocol
AlejandroAlvarezMelucciDCL Jan 31, 2025
0a8fbdf
Updated protobuf generated class. Small code cleanup and improvements
AlejandroAlvarezMelucciDCL Jan 31, 2025
4e6d6aa
Addressed PR comments. Improved pool object cycle. Added proper suppo…
AlejandroAlvarezMelucciDCL Jan 31, 2025
08a6a1c
Merge branch 'dev' into feat/dynamic-lights
AlejandroAlvarezMelucciDCL Jan 31, 2025
9434230
Fixed referenced scriptable object issue
AlejandroAlvarezMelucciDCL Jan 31, 2025
5cbe598
Fixed starting scene values not being properly set.
AlejandroAlvarezMelucciDCL Feb 1, 2025
148cfef
Small fixes
AlejandroAlvarezMelucciDCL Feb 1, 2025
8ed45b1
Merge branch 'dev' into feat/dynamic-lights
AlejandroAlvarezMelucciDCL Feb 4, 2025
a544ebc
Point protocol to experimental branch
AlejandroAlvarezMelucciDCL Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MonoBehaviour:
m_DefaultGroup: 47f803e1e9c5079449bd106df98a0b7d
m_currentHash:
serializedVersion: 2
Hash: 929bc0a851082190651830d8f45eaaca
Hash: c5b9b16724d7315a9b37da69c2735fae
m_OptimizeCatalogSize: 0
m_BuildRemoteCatalog: 0
m_BundleLocalCatalog: 0
Expand Down Expand Up @@ -50,6 +50,7 @@ MonoBehaviour:
- {fileID: 11400000, guid: dfcf8d697a676564cba6e67051b21967, type: 2}
- {fileID: 11400000, guid: 16f521477e6564a958075901ccb95f7e, type: 2}
- {fileID: 11400000, guid: 87f4a5efef76fa14488910f4e8acdd53, type: 2}
- {fileID: 11400000, guid: c78cdb3c90e791745af8cc89892b1a81, type: 2}
- {fileID: 11400000, guid: cbb0d807e72e1ce45af9fa353aed05ba, type: 2}
- {fileID: 11400000, guid: e0f0f2d4ff3471c44953d71c1c51b7b7, type: 2}
- {fileID: 11400000, guid: 908e3bc21ce6079428d027b3d8b69cd0, type: 2}
Expand All @@ -63,6 +64,7 @@ MonoBehaviour:
- {fileID: 11400000, guid: 65ec81046e8d04372a28e44540e14a9d, type: 2}
- {fileID: 11400000, guid: f230ff8ddb68e6342a84ce4b5bf941a5, type: 2}
- {fileID: 11400000, guid: a979db80e679cae4da503a3cfd0a3a11, type: 2}
- {fileID: 11400000, guid: 74b57aba17f2b264bb568f41300fc460, type: 2}
m_BuildSettings:
m_CompileScriptsInVirtualMode: 0
m_CleanupStreamingAssetsAfterBuilds: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ MonoBehaviour:
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 52c856180dc5d6447b902f06d38f4161
m_Address: LightSourceDefaults
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 53b70d09c4a814878a30c68582ad4523
m_Address: Assets/DCL/MapRenderer/Addressables/HotUserMarkerObject.prefab
m_ReadOnly: 0
Expand Down Expand Up @@ -277,6 +282,11 @@ MonoBehaviour:
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 7f09a2d0d9adc4e43b67879ab9cdf360
m_Address: LightSourcePrefab
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 86bf0204cf3bb75429342452a2a460af
m_Address: Assets/DCL/Landscape/Data/ParcelData.asset
m_ReadOnly: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,7 @@ public static class ReportCategory
public const string FRIENDS = nameof(FRIENDS);

public const string DISK_CACHE = nameof(DISK_CACHE);

public const string LIGHT_SOURCE = nameof(LIGHT_SOURCE);
AlejandroAlvarezMelucciDCL marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/PluginSystem/DCL.Plugins.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@
"GUID:e9db755bba99425db4ca5d30e48b7429",
"GUID:5462d37de7d4344df8aade58a45b403e",
"GUID:f3634757d00dab2429c6c11e69404e97",
"GUID:09c5cab4669b047398fa5d42a2f64f5b"
"GUID:09c5cab4669b047398fa5d42a2f64f5b",
"GUID:07fae1aaf8481a840a6165058ced43aa"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
100 changes: 100 additions & 0 deletions Explorer/Assets/DCL/PluginSystem/World/LightSourcePlugin.cs
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.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ MonoBehaviour:
- rid: 7615904969758605314
- rid: 634089542387236867
- rid: 1970080267461197826
- rid: 5734404086669770757
- rid: 3414978285727645698
- rid: 3414978285727645699
references:
version: 2
RefIds:
Expand Down Expand Up @@ -154,14 +155,30 @@ MonoBehaviour:
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
- rid: 4753057106328551424
type: {class: SceneUIPlugin/Settings, ns: DCL.PluginSystem.World, asm: DCL.Plugins}
- rid: 3414978285727645698
type: {class: PointerInputAudioPlugin/Settings, ns: DCL.PluginSystem.Global, asm: DCL.Plugins}
data:
<Canvas>k__BackingField:
m_AssetGUID: e0f5a4ab5d8f74640ae94adb6824bd45
<InteractionsAudioConfigsReference>k__BackingField:
m_AssetGUID: cbb820cf51b7a714e88a7c873eb5de9c
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
- rid: 3414978285727645699
type: {class: LightSourcePlugin/LightSourceSettings, ns: DCL.PluginSystem.World, asm: DCL.Plugins}
data:
LightSourcePrefab:
m_AssetGUID: 7f09a2d0d9adc4e43b67879ab9cdf360
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
LightSourceDefaultValues:
m_AssetGUID: 52c856180dc5d6447b902f06d38f4161
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
- rid: 4753057106328551424
type: {class: SceneUIPlugin/Settings, ns: DCL.PluginSystem.World, asm: DCL.Plugins}
data:
<StyleSheet>k__BackingField:
m_AssetGUID: 295cf8ad8d171d849863eccaf581c9e7
m_SubObjectName:
Expand All @@ -180,14 +197,6 @@ MonoBehaviour:
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
- rid: 5734404086669770757
type: {class: PointerInputAudioPlugin/Settings, ns: DCL.PluginSystem.Global, asm: DCL.Plugins}
data:
<InteractionsAudioConfigsReference>k__BackingField:
m_AssetGUID: cbb820cf51b7a714e88a7c873eb5de9c
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
- rid: 6784895267130048515
type: {class: MaterialsPlugin/Settings, ns: DCL.PluginSystem.World, asm: DCL.Plugins}
data:
Expand Down

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
Expand Up @@ -27,7 +27,8 @@
"GUID:1300820cd310d4584b09afde765bdd16",
"GUID:5ab29fa8ae5769b49ab29e390caca7a4",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b",
"GUID:5eabe9a3d4dd19d42a16208ea5411062"
"GUID:5eabe9a3d4dd19d42a16208ea5411062",
"GUID:0d87731a01a547bd97421cb01c596850"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/SDKComponents/LightSource.meta

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.

8 changes: 8 additions & 0 deletions Explorer/Assets/DCL/SDKComponents/LightSource/Prefab.meta

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.

Loading
Loading