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

fix/outlinetransparents #3184

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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 @@ -27,7 +27,9 @@
"GUID:e25ef972de004615a22937e739de2def",
"GUID:543b8f091a5947a3880b7f2bca2358bd",
"GUID:d832748739a186646b8656bdbd447ad0",
"GUID:8e25e34dc0eb4a7b93392a4dc25366bd"
"GUID:8e25e34dc0eb4a7b93392a4dc25366bd",
"GUID:09c5cab4669b047398fa5d42a2f64f5b",
"GUID:15fc0a57446b3144c949da3e2b9737a9"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public struct AvatarShapeComponent
public string Name;

public readonly List<CachedAttachment> InstantiatedWearables;
public readonly List<Renderer> OutlineCompatibleRenderers;

public AvatarShapeComponent(string name, string id, BodyShape bodyShape, WearablePromise wearablePromise,
Color skinColor, Color hairColor, Color eyesColor)
Expand All @@ -33,18 +34,35 @@ public AvatarShapeComponent(string name, string id, BodyShape bodyShape, Wearabl
IsDirty = true;
WearablePromise = wearablePromise;
InstantiatedWearables = new List<CachedAttachment>();
OutlineCompatibleRenderers = new List<Renderer>();
SkinColor = skinColor;
HairColor = hairColor;
EyesColor = eyesColor;
IsVisible = true;
HiddenByModifierArea = false;
}

public void CreateOutlineCompatibilityList()
{
foreach (var wearable in InstantiatedWearables)
{
if (wearable.OutlineCompatible)
{
foreach (var rend in wearable.Renderers)
{
if (rend.sharedMaterial.renderQueue >= 2000 && rend.sharedMaterial.renderQueue < 3000)
OutlineCompatibleRenderers.Add(rend);
}
}
}
}

public AvatarShapeComponent(string name, string id) : this()
{
ID = id;
Name = name;
InstantiatedWearables = new List<CachedAttachment>();
OutlineCompatibleRenderers = new List<Renderer>();
IsVisible = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public static void Execute(FixedComputeBufferHandler vertOutBuffer, IAttachments
jobWrapper.ReleaseAvatar(ref avatarTransformMatrixComponent);

if (avatarShapeComponent.WearablePromise.IsConsumed)
{
avatarShapeComponent.OutlineCompatibleRenderers.Clear();
wearableAssetsCache.ReleaseAssets(avatarShapeComponent.InstantiatedWearables);
}
else
avatarShapeComponent.Dereference();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ private AvatarCustomSkinningComponent InstantiateAvatar(ref AvatarShapeComponent
skinningStrategy.SetVertOutRegion(vertOutBuffer.Rent(skinningComponent.vertCount), ref skinningComponent);
avatarBase.gameObject.SetActive(true);

avatarShapeComponent.CreateOutlineCompatibilityList();
wearableIntention.Dispose();

if (wearablesResult.Succeeded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using DCL.Character.Components;
using DCL.CharacterCamera;
using DCL.ECSComponents;
using DCL.Quality;
using DCL.Rendering.Avatar;
using ECS.Abstract;
using System.Runtime.CompilerServices;
Expand All @@ -16,9 +17,13 @@ namespace DCL.AvatarRendering.AvatarShape.Systems
[UpdateInGroup(typeof(CameraGroup))]
public partial class AvatarShapeVisibilitySystem : BaseUnityLoopSystem
{
private readonly OutlineRendererFeature? outlineFeature;
private SingleInstanceEntity camera;

public AvatarShapeVisibilitySystem(World world) : base(world) { }
public AvatarShapeVisibilitySystem(World world, IRendererFeaturesCache outlineFeature) : base(world)
{
this.outlineFeature = outlineFeature.GetRendererFeature<OutlineRendererFeature>();
}

public override void Initialize()
{
Expand All @@ -42,27 +47,19 @@ public bool IsVisibleInCamera(Camera camera, Bounds bounds)
return GeometryUtility.TestPlanesAABB(planes, bounds);
}

public bool IsWithinCameraDistance(Camera camera, Transform objectTransform, float maxDistance)
public bool IsWithinCameraDistance(Camera camera, Transform objectTransform, float maxDistancesquared)
{
float distance = Vector3.Distance(camera.transform.position, objectTransform.position);
return distance <= maxDistance;
var diff = camera.transform.position - objectTransform.position;
float distance = diff.sqrMagnitude;
return distance <= maxDistancesquared;
}

[Query]
private void GetAvatarsVisibleWithOutline(in AvatarBase avatarBase, ref AvatarShapeComponent avatarShape, ref AvatarCachedVisibilityComponent avatarCachedVisibility)
private void GetAvatarsVisibleWithOutline(in AvatarBase avatarBase, ref AvatarShapeComponent avatarShape)
{
if (IsWithinCameraDistance(camera.GetCameraComponent(World).Camera, avatarBase.HeadAnchorPoint, 8.0f) && IsVisibleInCamera(camera.GetCameraComponent(World).Camera, avatarBase.AvatarSkinnedMeshRenderer.bounds))
if (outlineFeature?.isActive && IsWithinCameraDistance(camera.GetCameraComponent(World).Camera, avatarBase.HeadAnchorPoint, 64.0f) && IsVisibleInCamera(camera.GetCameraComponent(World).Camera, avatarBase.AvatarSkinnedMeshRenderer.bounds))
{
foreach (var avs in avatarShape.InstantiatedWearables)
{
if (avs.OutlineCompatible)
{
foreach (var rend in avs.Renderers)
{
OutlineRendererFeature.m_OutlineRenderers.Add(rend);
}
}
}
OutlineRendererFeature.m_OutlineRenderers.AddRange(avatarShape.OutlineCompatibleRenderers);
}
}

Expand Down Expand Up @@ -115,6 +112,7 @@ private void UpdateVisibilityState(ref AvatarShapeComponent avatarShape, ref Ava
Hide(ref avatarShape);
else
Show(ref avatarShape);

avatarCachedVisibility.IsVisible = shouldBeHidden;
}

Expand Down
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/Editor/DCL.Editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"GUID:286980af24684da6acc1caa413039811",
"GUID:1d2c76eb8b48e0b40940e8b31a679ce1",
"GUID:fc37ca6521833154cab08ec51af097d9",
"GUID:fdc035e0abb695e408d8ccf2c3bd63a5"
"GUID:fdc035e0abb695e408d8ccf2c3bd63a5",
"Quality.RenderFeatures"
],
"includePlatforms": [
"Editor"
Expand Down
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 @@ -153,7 +153,8 @@
"GUID:fdc035e0abb695e408d8ccf2c3bd63a5",
"GUID:ead265f036164eb7899edc341131f4d5",
"GUID:e9db755bba99425db4ca5d30e48b7429",
"GUID:5462d37de7d4344df8aade58a45b403e"
"GUID:5462d37de7d4344df8aade58a45b403e",
"GUID:09c5cab4669b047398fa5d42a2f64f5b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
7 changes: 5 additions & 2 deletions Explorer/Assets/DCL/PluginSystem/Global/AvatarPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using DCL.AvatarRendering.AvatarShape.Helpers;
using DCL.Multiplayer.Profiles.Entities;
using DCL.AvatarRendering.Loading.Assets;
using DCL.Multiplayer.Profiles.Tables;
using DCL.Quality;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Pool;
Expand All @@ -51,6 +51,7 @@ public class AvatarPlugin : IDCLGlobalPlugin<AvatarPlugin.AvatarShapeSettings>
private readonly IPerformanceBudget frameTimeCapBudget;
private readonly ObjectProxy<AvatarBase> mainPlayerAvatarBaseProxy;
private readonly IPerformanceBudget memoryBudget;
private readonly IRendererFeaturesCache rendererFeaturesCache;
private readonly IRealmData realmData;

private readonly AttachmentsAssetsCache attachmentsAssetsCache;
Expand Down Expand Up @@ -84,6 +85,7 @@ public AvatarPlugin(
IAssetsProvisioner assetsProvisioner,
IPerformanceBudget frameTimeCapBudget,
IPerformanceBudget memoryBudget,
IRendererFeaturesCache rendererFeaturesCache,
IRealmData realmData,
ObjectProxy<AvatarBase> mainPlayerAvatarBaseProxy,
IDebugContainerBuilder debugContainerBuilder,
Expand All @@ -106,6 +108,7 @@ ExposedTransform playerTransform
this.chatEntryConfiguration = chatEntryConfiguration;
this.defaultFaceFeaturesHandler = defaultFaceFeaturesHandler;
this.memoryBudget = memoryBudget;
this.rendererFeaturesCache = rendererFeaturesCache;
this.nametagsData = nametagsData;
this.textureArrayContainerFactory = textureArrayContainerFactory;
this.remoteEntities = remoteEntities;
Expand Down Expand Up @@ -166,7 +169,7 @@ public void InjectToWorld(ref ArchSystemsWorldBuilder<Arch.Core.World> builder,
FinishAvatarMatricesCalculationSystem.InjectToWorld(ref builder, skinningStrategy,
avatarTransformMatrixJobWrapper);

AvatarShapeVisibilitySystem.InjectToWorld(ref builder);
AvatarShapeVisibilitySystem.InjectToWorld(ref builder, rendererFeaturesCache);
AvatarCleanUpSystem.InjectToWorld(ref builder, frameTimeCapBudget, vertOutBuffer, avatarMaterialPoolHandler,
avatarPoolRegistry, computeShaderPool, attachmentsAssetsCache, mainPlayerAvatarBaseProxy,
avatarTransformMatrixJobWrapper);
Expand Down
1 change: 1 addition & 0 deletions Explorer/Assets/DCL/Quality/Container/csc.rsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-nullable:enable
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Quality/Container/csc.rsp.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/Quality/DCL.Quality.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"GUID:4794e238ed0f65142a4aea5848b513e5",
"GUID:a29f69b42fb1815409464ac7b05381d0",
"GUID:21c2e77c042a2d34d8cfbf58f8217053",
"GUID:fc37ca6521833154cab08ec51af097d9"
"GUID:fc37ca6521833154cab08ec51af097d9",
"GUID:09c5cab4669b047398fa5d42a2f64f5b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using DCL.Quality.Runtime;
using System;
using System.Linq;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.Compilation;

namespace DCL.Quality
Expand Down
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Quality/RenderFeatures.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,16 @@
{
"name": "Quality.RenderFeatures",
"rootNamespace": "",
"references": [
"GUID:15fc0a57446b3144c949da3e2b9737a9"
],
"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.

Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ static IMultiPool MultiPoolFactory() =>
assetsProvisioner,
staticContainer.SingletonSharedDependencies.FrameTimeBudget,
staticContainer.SingletonSharedDependencies.MemoryBudget,
staticContainer.QualityContainer.RendererFeaturesCache,
staticContainer.RealmData,
staticContainer.MainPlayerAvatarBaseProxy,
debugBuilder,
Expand Down
Loading