16. Effect development
16.1 Compatibility with MikuMikuEffect
MMM possesses functionality compatible with MikuMikuEffect.
However, the following annotations cannot be used at present.
Mouse-related(MOUSEPOSITION / LEFTMOUSEDOWN / MIDDLEMOUSEDOWN / RIGHTMOUSEDOWN)
AnimationTexture
There are other functions which are implemented but do not yet possess exactly the same functionality as they do in MME.
16.2 Parameter control
In MMM, by attaching an annotation to an effect's parameter, real-time GUI operation and keyframe registration can be enabled.
Note that there are 6 types of parameter forms controllable on the GUI: bool, int, float, float2, float3, and float4.
If the parameter is bool, the control is automatically set to a checkbox.
Usable annotations:
Usable UIWidget controls:
16.3 Transforms caused by bones
MMM uses the GPU to process transforms caused by bones.
Because of this, vertices are passed to the shader at default coordinates, and skinning must be performed inside the shader.
The following structures and functions for skinning are provided for use in MMM.
To use these, save the effect file as a file type of either .fxm or .fxsub.
■Structures for vertex shader input
------------------------------------------------------------------------------
struct MMM_SKINNING_INPUT{
float4 Pos : POSITION; // Coordinates
float4 BlendWeight : BLENDWEIGHT; // Weight
float4 BlendIndices : BLENDINDICES; // Bone index
float3 Normal : NORMAL; // Normal
float2 Tex : TEXCOORD0; // Texture UV
float4 AddUV1 : TEXCOORD1; // Added UV1
float4 AddUV2 : TEXCOORD2; // Added UV2
float4 AddUV3 : TEXCOORD3; // Added UV3
float4 AddUV4 : TEXCOORD4; // Added UV4
float4 SdefC : TEXCOORD5; // SDEF C value
float3 SdefR0 : TEXCOORD6; // SDEF R0 value
float3 SdefR1 : TEXCOORD7; // SDEF R1 value
float EdgeWeight : TEXCOORD8; // Edge width
};
■Structures for skinning function return values
------------------------------------------------------------------------------
struct MMM_SKINNING_OUTPUT {
float4 Position; // Coordinates
float3 Normal; // Normals
};
■Skinning functions(Retrieves coordinates and normals)
------------------------------------------------------------------------------
MMM_SkinninedPositionNormal
Argument0 float4 Coordinates
Argument1 float3 Normals
Argument3 float4 Weight
Argument4 float4 Bone index
Argument5 float4 SDEF C value
Argument6 float4 SDEF R0 value
Argument7 float4 SDEF R1 value
Return value MMM_SKINNING_OUTPUT
■Skinning functions(Retrieves only coordinates)
------------------------------------------------------------------------------
MMM_SkinninedPosition
Argument0 float4 Coordinates
Argument1 float3 Normal
Argument3 float4 Weight
Argument4 float4 Index
Argument5 float4 SDEF C value
Argument6 float4 SDEF R0 value
Argument7 float4 SDEF R1 value
Return value float4 Coordinates after conversion
There is a sample in the "Shader" folder which makes use of the above information. Please use it as a reference.
16.4 Light
MMM can use up to 3 lights.
Annotations have been added to allow for retrieval of light information.
---------------------------------------------------------------------------
■POSITION0, POSITION1, POSITION2
■DIRECTION0, DIRECTION1, DIRECTION2
A light's position and direction. The form can be either float3 or float4.
Only object="Light" is active. object="Camera" causes all items to be given the same value.
No number and zero carry the same meaning。Example: POSITION and POSITION0 are equivalent.
---------------------------------------------------------------------------
■DIFFUSE0, DIFFUSE1, DIFFUSE2
■AMBIENT0, AMBIENT1, AMBIENT2
■SPECULAR0, SPECULAR1, SPECULAR2
A light's diffuse, ambient, and specular colors. The form can be float3 or float4.
Only object="Light" is active. object="Camera" causes all items to have the same value.
No number carries the same meaning as 0.
---------------------------------------------------------------------------
■VIEW0, VIEW1, VIEW2
■PROJECTION0, PROJECTION1, PROJECTION2
■WORLDVIEW0, WORLDVIEW1, WORLDVIEW2
■VIEWPROJECTION0, VIEWPROJECTION1, VIEWPROJECTION2
■WORLDVIEWPROJECTION0, WORLDVIEWPROJECTION1, WORLDVIEWPROJECTION2
These are the various matrices for a light's view.
Only object="Light" is active. object="Camera" causes all items to be given the same value.
No number and zero carry the same meaning.
Inverse and transpose are also usable.
---------------------------------------------------------------------------
■LIGHTWVPMATRICES
The matrix of a light's WorldViewProjection is passed as an array.
---------------------------------------------------------------------------
■LIGHTDIRECTIONS
The directional vector of a light is passed as an array.
---------------------------------------------------------------------------
■LIGHTPOSITIONS
The light position is passed as an array.
---------------------------------------------------------------------------
■LIGHTDIFFUSECOLORS
The light's diffuse color is passed as an array.
---------------------------------------------------------------------------
■LIGHTAMBIENTCOLORS
The light's ambient color is passed as an array.
---------------------------------------------------------------------------
■LIGHTSPECULARCOLORS
The light's specular color is passed as an array.
---------------------------------------------------------------------------
■SHADOWDEEP, SHADOWDEEP_POSITIVE, SHADOWDEEP_NEGATIVE
Values that express shadow thickness:
SHADOWDEEP
SHADOWDEEP_POSITIVE
SHADOWDEEP_NEGATIVE
The shadow's thickness. Retrieves a value from 0.0~1.0.
When shadow thickness is higher 0.5, 2.0 - SHADOWDEEP * 2 is taken. When below 0.5, it is set at 1.0.
When shadow thickness is less than 0.5, the value of SHADOWDEEP * 2 is taken. When above 0.5, it is set at 1.0.
---------------------------------------------------------------------------
■MMM_LightCount
A static variable that expresses the light count. It is always 3.
16.5 Other
■MMM_ToonTexSampler
---------------------------------------------------------------------------
The Toon texture sampler. Please use tex2D.
■MMM_SelfShadowSampler[MMM_LightCount]
---------------------------------------------------------------------------
The sampler for the self-shadow depth map.
■MMM_UnpackDepth *(Function)
---------------------------------------------------------------------------
Retrieves a depth value from the self-shadow depth map.
In order to raise the fidelity of depth, since 16 bit is used to save textures, this is a function that returns the depth to its original state.
Argument0 Float4 A variable retrieved from MMM_SelfShadowSampler
Return value float Depth value (0.0~1.0)
16.6 SSAO sample
Below is an SSAO effect usable with MMM.