-
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 9 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,93 @@ | ||
| using Arch.SystemGroups; | ||
| 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.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.Settings> | ||
| { | ||
| 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() | ||
| { | ||
| throw new NotImplementedException(); | ||
|
AlejandroAlvarezMelucciDCL marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| 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, | ||
| lightPoolRegistry, | ||
| sharedDependencies.SceneStateProvider | ||
| )); | ||
|
|
||
| ResetDirtyFlagSystem<PBLightSource>.InjectToWorld(ref builder); | ||
| } | ||
|
|
||
| public async UniTask InitializeAsync(Settings settings, CancellationToken ct) => | ||
| await CreateLightSourcePoolAsync(settings, ct); | ||
|
|
||
| private async UniTask CreateLightSourcePoolAsync(Settings settings, CancellationToken ct) | ||
| { | ||
| 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; | ||
| light.transform.SetParent(null); | ||
| light.transform.localPosition = Vector3.zero; | ||
| light.transform.localRotation = Quaternion.identity; | ||
|
AlejandroAlvarezMelucciDCL marked this conversation as resolved.
Outdated
|
||
|
|
||
| light.color = Color.white; | ||
| light.intensity = 1; | ||
| light.range = 10; | ||
| light.shadows = LightShadows.None; | ||
| light.type = LightType.Point; | ||
|
|
||
| light.innerSpotAngle = 12.8f; | ||
| light.spotAngle = 30f; | ||
|
AlejandroAlvarezMelucciDCL marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| private static void OnPoolGet(Light light) => | ||
| light.enabled = false; | ||
|
|
||
| [Serializable] | ||
| public class Settings : IDCLPluginSettings | ||
| { | ||
| [field: Header(nameof(LightSourcePlugin) + "." + nameof(Settings))] | ||
| [field: Space] | ||
| [field: SerializeField] | ||
| public AssetReferenceGameObject LightSourcePrefab; | ||
| } | ||
| } | ||
| } | ||
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,14 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace DCL.SDKComponents.LightSource | ||
| { | ||
| public struct LightSourceComponent | ||
| { | ||
| public readonly Light lightSourceInstance; | ||
|
|
||
| public LightSourceComponent(Light lightSourceInstance) | ||
| { | ||
| this.lightSourceInstance = lightSourceInstance; | ||
| } | ||
| } | ||
| } |
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,120 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!1 &6702869395793157098 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| serializedVersion: 6 | ||
| m_Component: | ||
| - component: {fileID: 5232691481928228032} | ||
| - component: {fileID: 3601112764250369252} | ||
| - component: {fileID: 9216909418390168617} | ||
| m_Layer: 0 | ||
| m_Name: LightSourcePrefab | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!4 &5232691481928228032 | ||
| Transform: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 6702869395793157098} | ||
| serializedVersion: 2 | ||
| m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} | ||
| m_LocalPosition: {x: 0, y: 0, z: 0} | ||
| m_LocalScale: {x: 1, y: 1, z: 1} | ||
| m_ConstrainProportionsScale: 0 | ||
| m_Children: [] | ||
| m_Father: {fileID: 0} | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!108 &3601112764250369252 | ||
| Light: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 6702869395793157098} | ||
| m_Enabled: 1 | ||
| serializedVersion: 10 | ||
| m_Type: 0 | ||
| m_Shape: 0 | ||
| m_Color: {r: 1, g: 1, b: 1, a: 1} | ||
| m_Intensity: 1 | ||
| m_Range: 10 | ||
| m_SpotAngle: 30 | ||
| m_InnerSpotAngle: 21.80208 | ||
| m_CookieSize: 10 | ||
| m_Shadows: | ||
| m_Type: 0 | ||
| m_Resolution: -1 | ||
| m_CustomResolution: -1 | ||
| m_Strength: 1 | ||
| m_Bias: 0.05 | ||
| m_NormalBias: 0.4 | ||
| m_NearPlane: 0.2 | ||
| m_CullingMatrixOverride: | ||
| e00: 1 | ||
| e01: 0 | ||
| e02: 0 | ||
| e03: 0 | ||
| e10: 0 | ||
| e11: 1 | ||
| e12: 0 | ||
| e13: 0 | ||
| e20: 0 | ||
| e21: 0 | ||
| e22: 1 | ||
| e23: 0 | ||
| e30: 0 | ||
| e31: 0 | ||
| e32: 0 | ||
| e33: 1 | ||
| m_UseCullingMatrixOverride: 0 | ||
| m_Cookie: {fileID: 0} | ||
| m_DrawHalo: 0 | ||
| m_Flare: {fileID: 0} | ||
| m_RenderMode: 0 | ||
| m_CullingMask: | ||
| serializedVersion: 2 | ||
| m_Bits: 4294967295 | ||
| m_RenderingLayerMask: 1 | ||
| m_Lightmapping: 4 | ||
| m_LightShadowCasterMode: 0 | ||
| m_AreaSize: {x: 1, y: 1} | ||
| m_BounceIntensity: 1 | ||
| m_ColorTemperature: 6570 | ||
| m_UseColorTemperature: 0 | ||
| m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} | ||
| m_UseBoundingSphereOverride: 0 | ||
| m_UseViewFrustumForShadowCasterCull: 1 | ||
| m_ShadowRadius: 0 | ||
| m_ShadowAngle: 0 | ||
| --- !u!114 &9216909418390168617 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 6702869395793157098} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: 474bcb49853aa07438625e644c072ee6, type: 3} | ||
| m_Name: | ||
| m_EditorClassIdentifier: | ||
| m_Version: 3 | ||
| m_UsePipelineSettings: 1 | ||
| m_AdditionalLightsShadowResolutionTier: 2 | ||
| m_LightLayerMask: 1 | ||
| m_RenderingLayers: 1 | ||
| m_CustomShadowLayers: 0 | ||
| m_ShadowLayerMask: 1 | ||
| m_ShadowRenderingLayers: 1 | ||
| m_LightCookieSize: {x: 1, y: 1} | ||
| m_LightCookieOffset: {x: 0, y: 0} | ||
| m_SoftShadowQuality: 0 |
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.
Uh oh!
There was an error while loading. Please reload this page.