シェーダーのほうだけでは解決できません。
シェーダー上では、
_Size("Size", Float) = 4
となっている値を、画面サイズに対しての実際の描画サイズとして変更する必要があります。
テクスチャ書き込みをする場合は、特に問題なくなると思いますが
そうではない場合は、カメラの描画領域と実際のスクリーンサイズの比率でSizeを変更する必要があります。
こんなコンポーネントを作って、モザイクシェーダーを使うパーツのオブジェクトにAddComponentするとよいかと思います。
using System;
using Live2D.Cubism.Rendering;
using UnityEngine;
using UtageExtensions;
namespace Utage
{
public class Live2DMosaicMaterial : MonoBehaviour
{
[Min(1)]
public float size = 4;
CubismRenderer cubismRenderer;
AdvGraphicObjectCustom advGraphicObject;
private LetterBoxCamera letterBoxCamera;
private bool IsInit { get; set; }
void Init()
{
cubismRenderer = this.GetComponent<CubismRenderer>();
advGraphicObject = this.GetComponentInParent<AdvGraphicObjectCustom>();
this.letterBoxCamera = advGraphicObject.Engine.CameraManager.FindCameraByLayer(this.gameObject.layer).GetComponent<LetterBoxCamera>();
}
void LateUpdate()
{
if (!IsInit)
{
Init();
IsInit = true;
}
float scale = GetScaleSize();
cubismRenderer.Material.SetFloat("_Size", Mathf.CeilToInt( size * scale));
}
float GetScaleSize()
{
AdvGraphicObject obj = advGraphicObject.ParentObject;
if (obj.EnableRenderTexture)
{
return 1.0f;
}
else
{
return Mathf.Min(Screen.width / letterBoxCamera.CurrentSize.x, Screen.height / letterBoxCamera.CurrentSize.y);
}
}
}
}
2021年8月2日月曜日 23:03:56 UTC+9 scottie: