Skinned Metaball Builder Manual -Reference- (English)

Skinned Metaball Builder Manual -Reference-

 

0. Menu Commands

 

f:id:nkdtr:20150604194340p:plain

 

Save Prefab :

 Enabled only when a GameObject under MetaballSeed is selected.

 Saves selected metaball structure as a prefab.

 (If you drag & drop it to the project view (normal process of creating prefab), mesh data will not be set on the prefab because the mesh data is not asset but belongs to scene).

Save Mesh :

 Enabled only when a GameObject under MetaballSeed is selected.

 Saves mesh data only as an asset.

 The mesh data can be used for mesh filter, mesh collider and so on.

RebuildMesh :

 Enabled only when a GameObject under MetaballSeed is selected.

 Builds mesh by the metaball nodes.

CreateChild :

 Enabled only when a GameObject under MetaballNode is selected.

 Adds a GameObject with MetaballNode component under the selected GameObject.

 

1. SkinnedMetaballSeed / StaticMetaballSeed component

 Component to build a metaball mesh.

There are Skinned and Static MetaballSeed component.

Skinned doubles as Static except that building mesh costs a little bit higher (in memory usage and calculation time).

 

Properties

 If you use prefab (two prefabs are contained in folder "Metaball/Prefabs"), all the properties required for just making your mesh are set.

But this document will help you adjust properties for your application.

f:id:nkdtr:20150604160409p:plain

Bone Root :

 Node under which "skeleton" objects are automatically constructed by this tool.

 Also used for SkinnedMeshRenderer's "RootBone".

Source Root :

 Node under which metaball data is defined by user (or application script).

Every GameObject under this is supposed to have "MetaballNode" component.

 Shortcut command "Ctrl(Command) + Shift + C" (create child metaball node) is enabled when a GameObject under this is selected.

Cell Obj Prefab :

 Prefab for nodes under constructed "skeleton".

 Component "MetaballCellObject" is required to be attached.

 This can be null if you don't need special behavior of your metaball at all.

Grid Size :

 Size of cells in grid (refer http://en.wikipedia.org/wiki/Marching_cubes for details).

 Small size means, high-def mesh and high-processing cost,

and large size vice versa.

Auto Grid Size (Ver1.02~)

 Ignoring "Grid Size", use automatically decided grid size by "Auto Grid Quality".

Auto Grid Quality (Ver1.02~)

 Parameter to define grid size (if Auto Grid Size is checked).

Higher value means higher resolution of mesh (small grid size).

UV Project Node :

 Guide node for texture coordinates.

 Wired cube is displayed as a gizmo to show how the texture is applied.

 Using non-repeat ("wrap mode"=clamp) texture is easy way to confirm how this works.

Power Threshold :

 Value to determine "inside" points from scalar field calculated via metaball.

 Smaller threshold means larger area becomes inside ( larger mesh created ).

Base Radius :

 This is just for editor.

 Radius of created metaball node is set to this value by default.

B Reverse :

 If true, create mesh become reverse-surfaced.

 Useful to create dungeons (see "Dungeon" sample).

B Use Fixed Bounds :

 If true, following property "Fixed Bounds" is enabled,

so that marching cubes grid area is fixed.

 If false, bounds are automatically calcurated by metaballs info.

 This is useful if you want your mesh to be stable (otherwise, change of bounding box have a slight effect on each vertex position).

 But be careful, mesh will be cut off at the bounds.

Fixed Bounds :

 See "B Use Fixed Bounds".

B Use Color :
 If true, created mesh contains vertex colors.

Each color is interpolated between MetaballNodes.

 

SkinnedMesh (SkinnedMetaballSeed) :

 Renderer to receive the created mesh.

MeshFilter (StaticMetaballSeed) :

 Mesh filter to receive the created mesh.

 

 

APIs

void CreateMesh();

 Recreate mesh by metaballs information.

Same effect as menu command "Rebuild Mesh".

 

Mesh Mesh { get; set; } 

 Get or set current mesh data.

 

2. Metaball Node component

 

 

f:id:nkdtr:20150604203818p:plain

Properties

Base Radius 

 Radius of metaball.

Be careful that metaball radius is not affected by scale of transform.

B Subtract

 If true, metaball become subtractive.

Base Color

 Color of node, applied to vertex colors if the MetaballSeed is checked with "B Use Color"

【UE4】 マテリアルエディタのシェーダーコード生成についてちょっとね

# 結論
* Customノードは関数、頑張れば別のCustomノードで呼び出して使える
* MaterialFunctionは展開される。Customノードからの呼び出しはできない

 

# 実験
1. Customノードを関数として呼び出してみる

以下の条件を満たすときこれが可能。
* 呼び出されるCustom関数が実際に使われている(使われていないとコードから除外される)
* 呼び出されるCustom関数が呼び出し部分より手前で定義されている

f:id:nkdtr:20141216003142p:plain

こんなのを作った。

sin_custom の中身

sin(x)

test_customの中身

CustomExpression0(Parameters, x)


sin_customには0を入力しているので出力も0.

それをAddに使っているので実際には何の効力もないが、

無理やりにでも使っておかないとコードが生成されないのでこんな感じにした。

test_customの中身が今回のミソで、

Customノードがシェーダーコードに変換されるとき、

* CustomExpressionX(Xには0から順に整数が割り当てられる)という名前の関数になる

* Parametersという名前の引数が最初に付加される

ということを反映している。

実際のコードはWindow->HLSL Code で見ることができ、

今回のsin_customについては以下のようなコードに変換されていた。

 

MaterialFloat3 CustomExpression0(FMaterialPixelParameters Parameters,MaterialFloat x)
{
return sin(x);
}

 

関数名につく数字はシェーダーコードが生成されるたびに割り当てなおされるので、

マテリアルをいじると変わる場合がある。

したがってこの呼び出し方はよほどの事情がない限り行わない方がよい。

 

なお、WorldPositionOffsetなど頂点シェーダーとして解釈される部分についてはParametersの型が異なってくるため、ピクセルシェーダー側との互換性が無い。

 

2. MaterialFunctionノードによるシェーダーコードの検証

f:id:nkdtr:20141216004612p:plain

こんなのを作った。

コードを見つけやすいように0.12345という変な値を入れておいた。

出てきたシェーダーコードがこれ。

half3 GetMaterialEmissiveRaw(FMaterialPixelParameters Parameters)
{
MaterialFloat Local0 = (MaterialFloat2(0.00000000,0.00000000).r * MaterialFloat2(0.12345000,0.00000000).r);
MaterialFloat Local1 = (MaterialFloat2(0.00000000,0.00000000).g * MaterialFloat2(0.12345000,0.00000000).g);
MaterialFloat Local2 = (Local0 - Local1);
MaterialFloat Local3 = (MaterialFloat2(0.00000000,0.00000000).r * MaterialFloat2(0.12345000,0.00000000).g);
MaterialFloat Local4 = (MaterialFloat2(0.00000000,0.00000000).g * MaterialFloat2(0.12345000,0.00000000).r);
MaterialFloat Local5 = (Local3 + Local4);
MaterialFloat3 Local6 = (MaterialFloat3(MaterialFloat2(Local2,Local5),0) + Material.VectorExpressions[0].rgb);
return Local6;;
}

どう見ても展開されている。

MF_MultComplex はVector2を複素数と見なして乗算した結果を返すもので、

一応載せておくと下のようなもの。

f:id:nkdtr:20141216004836p:plain

実装内容によって展開されないこともあるのかもしれないが、

試した限りではこういう結果になった。