HOME | DD

Taemojitsu — MMD 'Toon' explanation and shader download by

#guide #toon #shader #hatsunemiku #mikumikudance #mikumikudancedownload
Published: 2019-11-25 02:34:39 +0000 UTC; Views: 6431; Favourites: 33; Downloads: 137
Redirect to original
Description

Hi everyone! It's winter again, so I can use my laptop for MMD without it overheating.


'Toons' in MMD are small images that are supposed to be used to determine the change in color from the part of a model that's directly exposed to light to the part that's in shadow. In practice, shaders often only use one corner of the image and use math to determine how much of that color to apply.


A lot of models in MMD have textures that are 'overexposed'. They have been pushed close to pure white, with only a little color left. If the part of the model in shadow was displayed with the same colors, it would appear pale and desaturated. The 'toon' color adds back in some of the missing color to shadows, and is closer to the object's true color than the main texture is.


But toon color is not always set correctly. Some examples:


- no toon because 'supposed to be emissive'. Doesn't make sense if diffuse or ambient is greater than 0, but diffuse/ambient of 0 wouldn't work if toon wasn't 0 as well. miku's glowy hip gear.

- no toon for unknown reason. miku's face. makes sense for shader to set toon color here. Possible explanation: toon file is set along with texture file, so white eyes use same toon as face?

- no toon because model was imported. shader should set toon here, but textures are darker and toon should be gray. misaki school model from doa.


If a material on a model doesn't have toon set when MMD thinks it uses toon, it will look the same in light and shadow (unless its specular properties, specular power and color, are set, but many models don't use this). Even without editing a model, you can tell a shader to use a toon color when none is present. The downloadable archive contains a shader that displays toon color. It is modified from AdultShader. See MME guide and reference translated from Japanese to English:


www.deviantart.com/taemojitsu/…


This effect has been modified to use the same technique with 'if' statements, instead of compiling separate versions, so it compiles faster (2 seconds instead of 12 seconds for me) but is slightly slower (12 fps instead of 14 fps for a large window for me). It also has an experiment with ambient lighting for the self-shadow version (making it darker).


The shader used by the self-shadow technique has been modified to have the following line at the end:


if(use_toon)Color.rgb = MaterialToon;


MaterialToon is automatically set using the lower-left corner of the Toon file by MMD, because of the 'TOONCOLOR' semantic in this line earlier in the shader:


float3   MaterialToon      : TOONCOLOR;


Since this change was only made for the self-shadow shader, you can see the normal result by turning off self-shadows, such as by pressing C to select a bone while viewing a model. You can also comment out the line with "//" at its start.


The first image in this post was created by setting a default toon color. Search for the line that says this:


static float3 MaterialToon_x_TP_ETP = pow( abs(MaterialToon),ToonPower + ExtraToonPower);


Change the part that says "abs(MaterialToon)" to this instead:


abs(min(MaterialToon, float3(0.95,0.9,0.85)))


Since colors are red-green-blue (or red-green-blue-alpha), this keeps the most red, keeps a little less green, and keeps the least blue. abs() is absolute value, min() is minimum. So if there is already a dark Toon Color, it will not be changed. Since different materials should have different toon colors to have accurate shadow colors, you could use this shader for a subset material, like only for the face since it's missing a toon color for Miku Append.


Models:

mikumikudance.fandom.com/wiki/… (has download link)

mikumikudance.fandom.com/wiki/…

www.deviantart.com/murabito124…

www.deviantart.com/murabito124…


Change log:

18 Dec 2019: changed '#if defined X' to '#if defined(X)'. My 32-bit compiler on Windows gave an error for the first form. If there's an error about too many instructions, change vs_2_0 and ps_2_0 to vs_3_0 and ps_3_0, respectively. I think my 32-bit Windows compiler also gave this error, even though my 64-bit compilers on Windows and Linux don't.


If you want mipmaps, which blur textures when zoomed out, change to this (0 means all):

texture ObjectTexture: MATERIALTEXTURE < int miplevels = 0 ; >;


and add this to 'sampler ObjTexSampler':

mipfilter = linear;


Don't use Notepad for editing effects. It has poor undo and find, older versions have some bugs, it has no line numbers, it can't display Japanese-encoded text, and it has no syntax highlighting for programming languages like C. (It also inserts a byte-order mark in Unicode files, which gives an error in MMD.) If you can select the character encoding when opening the file, Japanese files (and MME) use Shift-JIS or cp932, as mentioned in the effect guide.

Related content
Comments: 1

sangan76 [2023-11-22 09:02:28 +0000 UTC]

👍: 0 ⏩: 0