Skip to content

Commit

Permalink
Merge pull request #1027 from malaybaku/develop
Browse files Browse the repository at this point in the history
v3.6.0
  • Loading branch information
malaybaku committed Feb 25, 2024
2 parents 16be409 + 0d560ba commit 15a2e6f
Show file tree
Hide file tree
Showing 31 changed files with 704 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Batches/version.txt
@@ -1 +1 @@
v3.5.1
v3.6.0
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -4,10 +4,10 @@

Logo: by [@otama_jacksy](https://twitter.com/otama_jacksy)

v3.5.1
v3.6.0

* 作成: 獏星(ばくすたー)
* 2024/01/30
* 2024/02/25

WindowsでVRMを表示し、追加のデバイスなしで動かせるアプリケーションです。

Expand Down
4 changes: 2 additions & 2 deletions README_en.md
Expand Up @@ -5,10 +5,10 @@

Logo: by [@otama_jacksy](https://twitter.com/otama_jacksy)

v3.5.1
v3.6.0

* Author: Baxter
* 2024/Jan/30
* 2024/Feb/25

The VRM avatar application without any special device.

Expand Down
Expand Up @@ -25,6 +25,37 @@ MonoBehaviour:
scanline:
overrideState: 1
value: 0.117
--- !u!114 &-4968429724501136736
MonoBehaviour:
m_ObjectHideFlags: 3
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: 1c7e0b21f9fde1c429ce58be087a0258, type: 3}
m_Name: VmmAlphaEdge
m_EditorClassIdentifier:
active: 0
enabled:
overrideState: 1
value: 1
thickness:
overrideState: 1
value: 15
threshold:
overrideState: 1
value: 0.5
edgeColor:
overrideState: 1
value: {r: 1, g: 1, b: 1, a: 1}
outlineOverwriteAlpha:
overrideState: 1
value: 0.8
highQualityMode:
overrideState: 1
value: 0
--- !u!114 &-4431195256121071682
MonoBehaviour:
m_ObjectHideFlags: 3
Expand Down Expand Up @@ -112,6 +143,7 @@ MonoBehaviour:
- {fileID: 114612591270388130}
- {fileID: -679367385162691271}
- {fileID: 1713800730463470002}
- {fileID: -4968429724501136736}
--- !u!114 &114612591270388130
MonoBehaviour:
m_ObjectHideFlags: 3
Expand All @@ -124,7 +156,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 48a79b01ea5641d4aa6daa2e23605641, type: 3}
m_Name: Bloom
m_EditorClassIdentifier:
active: 1
active: 0
enabled:
overrideState: 1
value: 1
Expand Down
@@ -1,6 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
using UniVRM10;
using VRM;
using Zenject;

namespace Baku.VMagicMirror.FK
Expand All @@ -20,11 +22,9 @@ public class BoneFrameReducer : MonoBehaviour
[SerializeField] private float updateInterval = 0.05f;

//NOTE: 揺れものはフルFPSでええねん、という事です
private readonly Dictionary<HumanBodyBones, Transform> _bones = new Dictionary<HumanBodyBones, Transform>();
private readonly Dictionary<HumanBodyBones, Quaternion> _reducedRotations =
new Dictionary<HumanBodyBones, Quaternion>();
private readonly Dictionary<HumanBodyBones, Quaternion> _tempRotations =
new Dictionary<HumanBodyBones, Quaternion>();
private readonly Dictionary<HumanBodyBones, Transform> _bones = new();
private readonly Dictionary<HumanBodyBones, Quaternion> _reducedRotations = new();
private readonly Dictionary<HumanBodyBones, Quaternion> _tempRotations = new();

private Vector3 _reducedHipsPosition;
private Vector3 _tempHipsPosition;
Expand All @@ -34,22 +34,30 @@ public class BoneFrameReducer : MonoBehaviour

private bool _frameReduceEnabled = false;

private VRM10InstanceUpdater _instanceUpdater;
private Vrm10Instance _vrm10Instance;

[Inject]
public void Initialize(IMessageReceiver receiver, IVRMLoadable vrmLoadable)
public void Initialize(
IMessageReceiver receiver,
IVRMLoadable vrmLoadable,
VRM10InstanceUpdater instanceUpdater
)
{
vrmLoadable.VrmLoaded += OnModelLoaded;
vrmLoadable.VrmDisposing += OnModelUnloaded;
receiver.AssignCommandHandler(
VmmCommands.UseFrameReductionEffect,
c => _frameReduceEnabled = c.ToBoolean()
);
c => _frameReduceEnabled = c.ToBoolean());
_instanceUpdater = instanceUpdater;
}

private void OnModelLoaded(VrmLoadedInfo info)
{
_bones.Clear();
_reducedRotations.Clear();
_tempRotations.Clear();
_vrm10Instance = info.instance;

for (var i = (int) HumanBodyBones.Hips; i < (int) HumanBodyBones.LastBone; i++)
{
Expand All @@ -69,25 +77,35 @@ private void OnModelLoaded(VrmLoadedInfo info)
private void OnModelUnloaded()
{
_bones.Clear();
_vrm10Instance = null;
_hasModel = false;
}

private void Start()
{
StartCoroutine(RestoreFullFpsPose());
_instanceUpdater.PreRuntimeProcess
.Subscribe(_ => PreRuntimeProcess())
.AddTo(this);
_instanceUpdater.PostRuntimeProcess
.Subscribe(_ => PostRuntimeProcess())
.AddTo(this);
// StartCoroutine(RestoreFullFpsPose());
}

private void LateUpdate()
//やってること
// 1. 仮想骨が読み取られる前に「reduceした状態で適用するボーン値」を取って
// - キャッシュ値で上書きする
// - たまにキャッシュ値を更新する
// 2. 仮想骨が転写されたら、上書きしてしまった値は戻してく
// - ※揺れものの計算に対して無害にするためだが、VRM1.0とこの処理は相性がすごく悪いかも…
private void PreRuntimeProcess()
{
if (!_hasModel || !_frameReduceEnabled)
{
_updateCount = updateInterval;
return;
}

//2つのことをやる
// 1. 一定間隔で「reduceした状態で適用するボーン値」を取る
// 2. ボーン情報をreduce値に全部書き換えて描画させてから描画後に元に戻す -> 揺れものの計算をいい感じにするため
_updateCount += Time.deltaTime;
if (_updateCount >= updateInterval)
{
Expand All @@ -114,23 +132,21 @@ private void LateUpdate()
}
}

private IEnumerator RestoreFullFpsPose()
private void PostRuntimeProcess()
{
var eof = new WaitForEndOfFrame();
while (true)
if (!_hasModel || !_frameReduceEnabled)
{
yield return eof;
if (!_hasModel || !_frameReduceEnabled)
{
continue;
}
return;
}

_bones[HumanBodyBones.Hips].position = _tempHipsPosition;
foreach (var rotPair in _tempRotations)
{
_bones[rotPair.Key].localRotation = rotPair.Value;
}
_bones[HumanBodyBones.Hips].position = _tempHipsPosition;
foreach (var rotPair in _tempRotations)
{
_bones[rotPair.Key].localRotation = rotPair.Value;
}

//TODO: 揺れものの暴れ対策で必要なのはそうだが、メチャクチャ重たいはずなのでもっと軽い方法で代替したい…
_vrm10Instance.Runtime.ReconstructSpringBone();
}
}
}
Expand Up @@ -27,8 +27,8 @@ public static void ResetScriptSymbols()
[MenuItem("VMagicMirror/Symbols: Dev Standard", false, 11)]
public static void PrepareDevStandardSymbols()
=> PrepareScriptDefineSymbol(false, false);
[MenuItem("VMagicMirror/Symbols: Prod Full", false, 12)]
public static void PrepareDeFullSymbols()
[MenuItem("VMagicMirror/Symbols: Dev Full", false, 12)]
public static void PrepareDevFullSymbols()
=> PrepareScriptDefineSymbol(true, false);

[MenuItem("VMagicMirror/Symbols: Prod Standard", false, 21)]
Expand Down
Expand Up @@ -22,13 +22,17 @@ public class LightingController : MonoBehaviour

private Color _color = Color.white;
private Bloom _bloom;
private VmmAlphaEdge _vmmAlphaEdge;
private VmmVhs _vmmVhs;
private VmmMonochrome _vmmMonochrome;
private bool _handTrackingEnabled = false;
//NOTE: この値自体はビルドバージョンによらずfalseがデフォルトで良いことに注意。
//制限版でGUI側にtrue相当の値が表示されるが、これはGUI側が別途決め打ちしてくれてる
private bool _showEffectDuringTracking = false;

private bool _windowFrameVisible = true;
private bool _enableOutlineEffect = false;

[Inject]
public void Initialize(IMessageReceiver receiver)
{
Expand Down Expand Up @@ -89,7 +93,38 @@ public void Initialize(IMessageReceiver receiver)
float[] bloomRgb = message.ToColorFloats();
SetBloomColor(bloomRgb[0], bloomRgb[1], bloomRgb[2]);
});


receiver.AssignCommandHandler(
VmmCommands.WindowFrameVisibility,
message =>
{
_windowFrameVisible = message.ToBoolean();
SetOutlineEffectActive(_windowFrameVisible, _enableOutlineEffect);
});
receiver.AssignCommandHandler(
VmmCommands.OutlineEffectEnable,
message =>
{
_enableOutlineEffect = message.ToBoolean();
SetOutlineEffectActive(_windowFrameVisible, _enableOutlineEffect);
});
receiver.AssignCommandHandler(
VmmCommands.OutlineEffectThickness,
message => SetOutlineEffectThickness(message.ToInt())
);
receiver.AssignCommandHandler(
VmmCommands.OutlineEffectColor,
message =>
{
var rgb = message.ToColorFloats();
var color = new Color(rgb[0], rgb[1], rgb[2]);
SetOutlineEffectEdgeColor(color);
});
receiver.AssignCommandHandler(
VmmCommands.OutlineEffectHighQualityMode,
message => SetOutlineEffectHighQualityMode(message.ToBoolean())
);

receiver.AssignCommandHandler(
VmmCommands.EnableImageBasedHandTracking,
message =>
Expand All @@ -110,6 +145,7 @@ public void Initialize(IMessageReceiver receiver)
private void Start()
{
_bloom = postProcess.profile.GetSetting<Bloom>();
_vmmAlphaEdge = postProcess.profile.GetSetting<VmmAlphaEdge>();
_vmmMonochrome = postProcess.profile.GetSetting<VmmMonochrome>();
_vmmVhs = postProcess.profile.GetSetting<VmmVhs>();
}
Expand Down Expand Up @@ -209,6 +245,19 @@ private void SetBloomIntensity(float intensity)
private void SetBloomThreshold(float threshold)
=> _bloom.threshold.value = threshold;

private void SetOutlineEffectActive(bool windowFrameVisible, bool enableOutlineEffect)
=> _vmmAlphaEdge.active = !windowFrameVisible && enableOutlineEffect;

//NOTE: GUIからは整数指定するが設定上はfloat
private void SetOutlineEffectThickness(int thickness)
=> _vmmAlphaEdge.thickness.Override(thickness);

private void SetOutlineEffectEdgeColor(Color color)
=> _vmmAlphaEdge.edgeColor.Override(color);

private void SetOutlineEffectHighQualityMode(bool useHighQualityMode)
=> _vmmAlphaEdge.highQualityMode.Override(useHighQualityMode);

private void UpdateRetroEffectStatus()
{
bool enableEffect =_handTrackingEnabled &&
Expand Down
@@ -0,0 +1,39 @@
using System;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;

namespace Baku.VMagicMirror
{

[Serializable]
[PostProcess(typeof(VmmAlphaEdgeRenderer), PostProcessEvent.AfterStack, "Vmm/AlphaEdge", allowInSceneView: false)]
public sealed class VmmAlphaEdge : PostProcessEffectSettings
{
public FloatParameter thickness = new() { value = 20f };
public FloatParameter threshold = new() { value = 1f };
public ColorParameter edgeColor = new() { value = Color.white };
public FloatParameter outlineOverwriteAlpha = new() { value = 0.02f };
public BoolParameter highQualityMode = new() { value = false };
}

public sealed class VmmAlphaEdgeRenderer : PostProcessEffectRenderer<VmmAlphaEdge>
{
private static readonly int Thickness = Shader.PropertyToID("_Thickness");
private static readonly int Threshold = Shader.PropertyToID("_Threshold");
private static readonly int EdgeColor = Shader.PropertyToID("_EdgeColor");
private static readonly int OutlineOverwriteAlpha = Shader.PropertyToID("_OutlineOverwriteAlpha");
private static readonly int HighQualityMode = Shader.PropertyToID("_HighQualityMode");

public override void Render(PostProcessRenderContext context)
{
var sheet = context.propertySheets.Get(Shader.Find("Hidden/Vmm/AlphaEdge"));
sheet.properties.SetFloat(Thickness, settings.thickness);
sheet.properties.SetFloat(Threshold, settings.threshold);
sheet.properties.SetColor(EdgeColor, settings.edgeColor);
sheet.properties.SetFloat(OutlineOverwriteAlpha, settings.outlineOverwriteAlpha);
sheet.properties.SetFloat(HighQualityMode, settings.highQualityMode ? 1f : 0f);

context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
}
}
}

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

Expand Up @@ -173,6 +173,11 @@ public static class VmmCommands
public const string BloomThreshold = nameof(BloomThreshold);
public const string BloomColor = nameof(BloomColor);

public const string OutlineEffectEnable = nameof(OutlineEffectEnable);
public const string OutlineEffectThickness = nameof(OutlineEffectThickness);
public const string OutlineEffectColor = nameof(OutlineEffectColor);
public const string OutlineEffectHighQualityMode = nameof(OutlineEffectHighQualityMode);

public const string ShowEffectDuringHandTracking = nameof(ShowEffectDuringHandTracking);

public const string WindEnable = nameof(WindEnable);
Expand Down

0 comments on commit 15a2e6f

Please sign in to comment.