• 日本語
  • Unityで使用する際の一部Spine素材のモザイク処理について

いつもお世話になっています。
Spineでデータを作成し、Unityで動かしています。

質問なのですが、Spineの一部にだけモザイクをかける方法を教えていただきたいです。

サンプルAの画像をサンプルBの画像のように、特定のボーンにのみモザイクをかけたいと思っています。

参考になるサイトやフォーラムがありましたら、教えてもらえるととても助かります。

Related Discussions
...

新しいスパインユニティドキュメントページで説明されているように、カスタムスロットマテリアルを使用できます。
You could use custom slot materials, as described on the new spine-unity docs page:

spine-unity Runtime Documentation: Changing Materials Per Instance

skeletonAnimation.CustomSlotMaterial[slot] = newMaterial; // to enable the replacement.
skeletonAnimation.CustomSlotMaterial.Remove(slot); // to disable that replacement.

この方法で、ピクセル化された検閲方法でレンダリングする特別なシェーダーでマテリアルを割り当てることができます。 または、このマテリアルの同じアトラステクスチャのピクセル化バージョンを作成します。
This way you could assign a material with a special shader that renders in a pixelated censored way. Or simply create a pixellated version of the same atlas texture for this material.

Unity AssetStoreでもこのパッケージを見つけました。
https://assetstore.unity.com/packages/vfx/shaders/censor-effect-111983
たぶんそれも役立ちます。
I also found this package on the Unity AssetStore:
https://assetstore.unity.com/packages/vfx/shaders/censor-effect-111983
Maybe it helps as well.

13 jours plus tard

ありがとうございます!
返信遅くなりすみません。

頂きました情報をもとに作成進めさせていただこうと思います!
ご確認ありがとうございます、とても助かります!


回答ありがとうございました。
早速もらった情報で作ってみたのですが問題が2つ発生しました。

1.
gunにモザイクをかけたのですが、モザイクが四角くかかってしまいました。
モザイクをgunの形に合わせてかけることは出来ますか?

2.
モザイクをかけたgunが顔の後ろに隠れたときに、顔にもモザイクが入ってしまいました。
「gunにだけモザイクを使う」ということは出来ますか?

アドバイスを貰っていつもとても参考になります。
今回も助けてもらえると、とても助かります。

5 jours plus tard

どういたしまして!

質問1について:
これはもう少し注意が必要ですが、カスタムシェーダーでも実行できます。このシェーダーは、フル解像度でアルファテストを実行する必要があります(透明でない場合は、ピクセル化されたダウンサンプリングされた画像をレンダリングします)。
画像に示されているソリューションをどのように実現しましたか? Unity Asset Storeのシェーダーですか、それとも何か違うものですか?ソリューションは、使用されるアプローチに大きく依存します。

シェーダーを使用する場合は、ここでフォーラムにシェーダーファイルを投稿できます(または、フリーでないアセットの場合はメールで送信します)。それから私はそれを見ることができます。

質問2について:
繰り返しますが、画像に示されているソリューションをどのように実現するかに大きく依存します。
まだこれを行っていない場合:上記のように、 SkeletonRenderSeparatorを使用して、スケルトンを2つ以上のパーツに分割し、それをガンパーツにのみ適用できます。おそらく、使用されている検閲ソリューションでは、一部のレイヤーにのみ適用するレイヤーマスクが提供されているため、銃を「検閲済み」レイヤーに割り当てることができます。
SkeletonAnimationにZインスペクションを追加することもできます(インスペクターの「詳細」セクション)。


Original English text below


You're welcome!

Regarding question 1:
This is a bit more tricky, but can be done with a custom shader as well. This shader would need to perform the alpha-test at full-resolution (and if it is not transparent, render the pixelated downsampled image).
How did you achieve the solution shown in your images? Is it a shader from the Unity Asset Store, or something different? The solution depends heavily on the used approach.

If it uses a shader, you can post the shader file here on the forum (or send it via email in case it is a non-free asset). Then I can have a look at it.

Regarding question 2:
Again, it depends heavily on how you achieve the solution shown in your images.
In case you haven't done this already: you could use a SkeletonRenderSeparator, as described above, to separate the skeleton into two or more parts, and then only apply it to the gun part. Perhaps the used censoring solution provides layer masks to apply it only to some layers, then you could assign the gun to a 'censored' layer.
You could also add some Z-spacing at the SkeletonAnimation (in the Advanced section in the inspector).

マテリアルは教えてもらった
https://assetstore.unity.com/packages/vfx/shaders/censor-effect-111983
これを使っています。

コードはこのようにしてつかっています。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity;
using Spine;

public class TestScene : MonoBehaviour
{
public GameObject spineboy;
public SkeletonAnimation spineboySA;
public Slot slot;
public Material material;
public Shader shader;
private void Start()
{
spineboySA = spineboy.GetComponent<SkeletonAnimation>();
slot = spineboySA.skeleton.FindSlot("gun");
spineboySA.CustomSlotMaterials[slot] = material;
//spineboySA.CustomSlotMaterials[slot].shader = shader;
}
}

また、前回の画像に関してわかりにくくてごめんなさい。
前の投稿で添付した画像は説明用に加工した画像です。
上のコードでは今はこのような画像になります。

使用しているアセットパッケージは別の方法で機能しています。
別のオブジェクトまたはメッシュに配置することを目的としており(アセットに含まれるサンプルシーンに見られるように)、シーンからピクセルを取得し、再レンダリングします。
The asset package you are using is working in a different way:
It is intended to be put on a separate object or mesh (as seen in the included example scene in the asset), it then grabs the pixels from the scene and re-renders them.

gunスロットに直接アタッチしたため、銃はレンダリングされず、画面から既存のピクセルを取得して再度レンダリングします。 これにより、銃が削除されます。
As you have attached it directly to the gun slot, it will not render the gun but instead grab existing pixels from the screen and render them again. This will remove the gun.

だからあなたはどちらか
a)スプライトにアタッチすることにより機能する別のピクセル化シェーダーアセットを検索し、(テクスチャアクセスを変更することにより)ピクセル化された方法でこのスプライトをレンダリングします。
b)SkeletonRenderSeparatorを使用してメッシュを複数の部分に分割し、SkeletonAnimationコンポーネントでZ-Spacingを増やしてから配置します 銃の前にあるが、他の資産の後ろにある検閲オブジェクト。 その後、通常どおり BoneFollowerを使用して銃の位置を追跡できます。

So you could either
a) search for a different pixelation-shader asset which works by being attached to a sprite and then renders this sprite in a pixelated way (by changing texture access).
b) split your mesh into multiple parts using a SkeletonRenderSeparator, increase Z-Spacing at the SkeletonAnimation component and then place the censorship-object in front of the gun, but behind other assets. You can then use a BoneFollower as usual to follow the gun position.

un mois plus tard

情報ありがとうございます。
返信遅くなりましたが、修正できましたので報告させていただきます。

スロットに関してはスクリプトの方で使いこなせなかったので、Spineの元の素材に「pixel」というスロットを新しく追加し、それにモザイクの処理を入れるようにしました。

かなり時間がかかってしまいましたが、無事実装できました、ハロルドさん、いつも情報ありがとうございます、凄く助かりました!

お返事ありがとうございます。 お役に立てたことをうれしく思います。ソリューションが機能したことを非常に嬉しく思います。
Thank you for getting back to us. We are glad to have been of help, very happy that your solution worked.