-
Notifications
You must be signed in to change notification settings - Fork 571
Materials
This document is designed to help those who wanted to quickly get up to speed in Ray-MMD
, the PBR (physically-based-rendering) is a rendering pipeline around the physics that has rapidly gained popularity, so the first thing you need to know what is the PBR term.
There are three forms of PBR's material (physically-based material), we'll be present the albedo/smoothness/metalness pipeline, and not the albedo/roughness/metalness, because of the roughness does not be easy to understand and to use, and not the diffuse/specular/gloss pipeline, because it's not PBR's term, and then i'll go over all of the entries commonly used in Ray-MMD
and also attach links to the wiki for more details.
Currently, you can create a new material by duplicate a material_2.0.fx
and if you want to create a variety of textures, current software such as dDO, nDO, Substance Designer, Substance Painter, Photoshop, etc, that will do much to create these conditions make the process a bit easier and help you create your own materials.
Albedo
is also called base color
, defines the overall color of the material, thus uses all 3 color channels, the albedo maps are normalized value in the sRGB color-space and clamped between 0.0
and 1.0
-
You can use a
linear-color
andsRGB-texture
to change the colors in your model by set the followingcode
to theALBEDO_MAP_FROM
.0
. Parameter fetch fromlinear-color
from theconst float3 albedo = 1.0
.
1
. You can use asrgb-image
(bmp, png, jpg, tga, dds) by enter a relative and absolutely path to theALBEDO_MAP_FILE
.
2
. You can use aanimation srgb-image
(gif, apng) by enter a relative and absolutely path to theALBEDO_MAP_FILE
.
3
. Parameter fetch fromTexture
from thepmx
.
4
. Parameter fetch fromSphere map
from thepmx
.
5
. Parameter fetch fromToon map
from thepmx
.
6
. Parameter fetch fromavi
orscreen
from theDummyScreen.x
insideextension
folder.
7
. Parameter fetch fromAmbient Color
from thepmx
.
8
. Parameter fetch fromSpecular Color
from thepmx
.
9
. Parameter fetch fromSpecular Power
from thepmx
. //Only for smoothness
-
You can flip your texture for the
X
andY
axis mirror by setcode
to theALBEDO_MAP_UV_FLIP
0
. None
1
. Flip axisX
2
. Flip axisY
3
. Flip axisX
andY
-
You can apply the color from
albedo
to change the colors in your texture by setcode
to theALBEDO_MAP_APPLY_SCALE
0
. None
1
. map values * albedo
2
. map values ^ albedo (The^
is exponential operations ofX
andY
) -
Texture colors to multiply with
diffuse
from thePMX
. -
Texture colors to multiply with color from the (
R+
/G+
/B+
) morph controller. seePointLight.pmx
for more information -
If
ALBEDO_MAP_FROM
is1
or2
, you will need to enter the path to the texture resource.You can set the xxx.png to the ALBEDO_MAP_FILE like : #define ALBEDO_MAP_FILE "xxx.png"
You can set the xxx.png to the ALBEDO_MAP_FILE like : #define ALBEDO_MAP_FILE "../xxx.png"
You can set the xxx.png to the ALBEDO_MAP_FILE like : #define ALBEDO_MAP_FILE "../other path/xxx.png"
You can set the xxx.png to the ALBEDO_MAP_FILE like : #define ALBEDO_MAP_FILE "C:/Users/User Name/Desktop/xxx.png"
- Using
../
instead of parent folder - Change all
\
to/
.
-
If
ALBEDO_MAP_FROM
is0
orALBEDO_MAP_APPLY_SCALE
is1
, you need to set color to theconst float3 albedo = 1.0;
.1. If the red is normalized value, it can be set to albedo like:
const float3 albedo = float3(1.0, 0.0, 0.0);
2. If the red is unnormalized value, it can be set to albedo like:
const float3 albedo = float3(255, 0.0, 0.0) / 255.0;
3. If the color is fetched from your monitor, you need to convert the color from sRGB to linear color-space by
color ^ gamma
- Convert the
srgb color-space
from normalized value tolinear color-space
like:const float3 albedo = pow(float3(r, g, b), 2.2);
- Convert the
srgb color-space
from unnormalized value tolinear color-space
like:const float3 albedo = pow(float3(r, g, b) / 255.0, 2.2);
-
You can tile your texture for the
X
andY
axis separately by changealbedoMapLoopNum = float2(x, y)
-
const flaot albedoMapLoopNum = 2;
OR const flaot2 albedoMapLoopNum = 2;
const flaot2 albedoMapLoopNum = float2(2, 3);
-
-
You can apply second value for
base color
change by set thecode
toALBEDO_SUB_ENABLE
0
. None
1
. albedo * albedoSub
2
. albedo ^ albedoSub
3
. albedo + albedoSub
4
. melanin
5
. Alpha Blend -
ALBEDO_SUB_MAP_FROM (see ALBEDO_MAP_FROM)
-
ALBEDO_SUB_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
ALBEDO_SUB_MAP_APPLY_SCALE (see ALBEDO_MAP_APPLY_SCALE)
-
ALBEDO_SUB_MAP_FILE (see ALBEDO_MAP_FILE)
-
const float2 albedoSubMapLoopNum = 0.0 ~ inf; (see albedoMapLoopNum)
It has no effect on opaque objects, each tab is independent of other tab, it won't affects all of the other tabs, and other tab will fetched alpha value from .PMX model rather than this entry, so if you modified this entry you should also edit the main.fx
at the same time.
-
ALPHA_MAP_FROM (see ALBEDO_MAP_FROM)
-
ALPHA_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
The ordering of the data fetched from a
texture
from thecode
.0
. Fetch data fromR
channel
1
. Fetch data fromG
channel
2
. Fetch data fromB
channel
3
. Fetch data fromA
channel#define SMOOTHNESS_MAP_SWIZZLE 0
#define SMOOTHNESS_MAP_SWIZZLE 1
-
ALPHA_MAP_FILE (see ALBEDO_MAP_FILE)
-
const float2 alphaMapLoopNum = 0.0 ~ inf; (see albedoMapLoopNum)
The normal maps alters the topography of the mesh and alters the angle of the light to add shadows to it in the details,
this map is almost always uses tangent-space map with three channels in the most time, but the influences of some other factors such as old pipeline and bandwidth,
this allows you to use different type to access the different texture of the normal map, see the NORMAL_MAP_TYPE
for more information,
in order to calculate the light in the real-time, All input models must have the normals else will result a problem with the white edge,
that looks like some white edges on your model, so you can put the scene in the PMXEditor
and
check the scene that all normals
are not zero-length
(XYZ are the same equal to zero) to be used for model.
-
NORMAL_MAP_FROM (see ALBEDO_MAP_FROM)
-
Other parameter types for
normal
, see UE4 docs forPerturbNormalLQ
andPerturbNormalHQ
.0
. Calculate world-space normal from RGB tangent-space map.
1
. Calculate world-space normal from RG compressed tangent-space map.
2
. Calculate world-space normal from Grayscale bump map byPerturbNormalLQ
(Low Quality). It has no effect on small objects.
3
. Calculate world-space normal from Grayscale bump map byPerturbNormalHQ
(High Quality).
4
. Calculate world-space normal from RGB world-space map. -
NORMAL_MAP_UV_FLIP (see ALBEDO_MAP_APPLY_SCALE)
-
NORMAL_MAP_FILE (see ALBEDO_MAP_FILE)
-
const float2 normalMapLoopNum = 0 ~ inf; (see albedoMapLoopNum)
this entry is designed to add detail to a base normal map in a consistent way, that pack two normal map into a normal map by using Reoriented Normal Mapping, and also, you can see the docs for more information.
-
NORMAL_SUB_MAP_FROM (see ALBEDO_MAP_FROM)
-
NORMAL_SUB_MAP_TYPE (see NORMAL_MAP_TYPE)
-
NORMAL_SUB_MAP_UV_FLIP (see ALBEDO_MAP_APPLY_SCALE)
-
NORMAL_SUB_MAP_FILE (see ALBEDO_MAP_FILE)
-
const float normalSubMapLoopNum = 0.0 ~ inf; (see albedoMapLoopNum)
Smoothness maps determines the unevenness of surface, this is always a grayscale map with mono channel,
but there is almost never grayscale map used, and as such only uses the R
channel in the RGBA
map as default channel,
also, you can specify what channel will happen for the default channel by sets code
to the SMOOTHNESS_MAP_SWIZZLE
, and
it's almost a time when a material_2.0.fx is used, it'll fetched data from a SpecularPower
from the PMX
file
and convert the SpecularPower
to Smoothness
as default value.
-
SMOOTHNESS_MAP_FROM (see ALBEDO_MAP_FROM)
-
Other parameter types for
Smoothness
0
.Smoothness
(from Frostbite / CE5 textures)
1
. CalculateSmoothness
from Roughness by1.0 - Roughness ^ 0.5
(from UE4/GGX/SubstancePainter2)
2
. CalculateSmoothness
from Roughness by1.0 - Roughness
(from UE4/GGX/SubstancePainter2 with linear roughness) -
SMOOTHNESS_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
SMOOTHNESS_MAP_SWIZZLE (see ALPHA_MAP_SWIZZLE)
-
SMOOTHNESS_MAP_APPLY_SCALE (see ALBEDO_MAP_APPLY_SCALE)
-
SMOOTHNESS_MAP_FILE (see ALBEDO_MAP_FILE)
-
const float2 smoothnessMapLoopNum = 1.0; (see albedoMapLoopNum)
Metalness is one method of determining reflectivity and what part of the texture is a metal,
used to instead of old pipeline such as specular highlight map, the metalness maps are always a grayscale map with mono channel,
but there is almost never grayscale map used, and as such only uses the R
channel in the RGBA
map as default channel,
also, you can specify what channel will happen for the default channel by sets code
to the METALNESS_MAP_SWIZZLE
-
METALNESS_MAP_FROM (see ALBEDO_MAP_FROM)
-
METALNESS_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
METALNESS_MAP_SWIZZLE (see ALPHA_MAP_SWIZZLE)
-
METALNESS_MAP_APPLY_SCALE (see ALBEDO_MAP_APPLY_SCALE)
-
METALNESS_MAP_FILE (see ALBEDO_MAP_FILE)
-
const float2 metalnessMapLoopNum = 1.0; (see albedoMapLoopNum)
Specular maps aren't environment and sphere maps, only modifies the base reflectivity
for the model,
that is used for control over the colors of the reflection, and there have two type of specular map that are RGB
and grayscale
,
but they have no effect when the metalness
is greater than zero, and that RGB type of specular map will not work with when CUSTOM_ENABLE
is not equal to zero,
so you can use the grayscale map instead of RGB
by sets code
to the SPECULAR_MAP_TYPE
,
and if you don't feel like the model to reflect the specular color, you can set zero to const float3 specular = 0.0;
-
SPECULAR_MAP_FROM (see ALBEDO_MAP_FROM)
-
Other parameter types for Specular
0
. Calculate reflection coefficient from specular color byF(x) = 0.08*(x )
(from UE4 textures)
1
. Calculate reflection coefficient from specular color byF(x) = 0.16*(x^2)
(from Frostbite textures)
2
. Calculate reflection coefficient from specular grays byF(x) = 0.08*(x )
(from UE4 textures)
3
. Calculate reflection coefficient from specular grays byF(x) = 0.16*(x^2)
(from Frostbite textures)
4
. Using reflection coefficient (0.04
) instead of specular value (0.5
), Available whenSPECULAR_MAP_FROM
at0
-
SPECULAR_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
SPECULAR_MAP_SWIZZLE (see ALPHA_MAP_SWIZZLE)
-
SPECULAR_MAP_APPLY_SCALE (see ALBEDO_MAP_APPLY_SCALE)
-
SPECULAR_MAP_FILE (see ALBEDO_MAP_FILE)
-
Anything less than
2%
is physically impossible and is instead considered to be shadowing
For example: The reflectance coefficient is equal toF(x) = (x - 1)^2 / (x + 1)^2
Consider light that is incident upon a transparent medium with a refractive index of1.5
That result will be equal to(1.5 - 1)^2 / (1.5 + 1)^2
=0.04
(or4%
).
Specular to reflection coefficient is equal toF(x) = 0.08*x
, if thex
is equal to0.5
the result will be0.04
.
So default value is0.5
for0.04
coefficient and clamped value between0.0
~1.0
-
const float2 specularMapLoopNum = 1.0; (see albedoMapLoopNum)
The ambient occlusion (AO) is an effect that approximates the attenuation of environment light due to occlusion.
Bacause sky lighting from many directions, cannot simply to calculating shadows in the real-time.
A simply way able to replaced by using occlusion map
and SSAO
,
and if you don't want diffuse
and specular
, you can set zero to the const float occlusion = 1.0
.
-
OCCLUSION_MAP_FROM (see ALBEDO_MAP_FROM)
-
Other parameter types for
Occlusion
0
. Fetchambient occlusion
from linear color-space
1
. Fetchambient occlusion
from sRGB color-space
2
. Fetchambient occlusion
from linear color-space from second UV set
3
. Fetchambient occlusion
from sRGB color-space from second UV set -
OCCLUSION_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
OCCLUSION_MAP_SWIZZLE (see ALPHA_MAP_SWIZZLE)
-
OCCLUSION_MAP_APPLY_SCALE (see ALBEDO_MAP_APPLY_SCALE)
-
const float2 occlusionMapLoopNum = 0.0 ~ inf; (see albedoMapLoopNum)
You can use a height map
but the parallax
does not work with vertex displacement in the DX9
-
PARALLAX_MAP_FROM (see ALBEDO_MAP_FROM)
-
Other parameter types for
parallax
0
. calculate without transparency
1
. calculate parallax occlusion with transparency and bestSSDO
-
PARALLAX_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
PARALLAX_MAP_SWIZZLE (see ALPHA_MAP_SWIZZLE)
-
PARALLAX_MAP_FILE (see ALBEDO_MAP_FILE)
-
const float2 parallaxMapLoopNum = 0.0 ~ inf; (see albedoMapLoopNum)
You can add a light source in MMD (PointLight or others), And key it as part of emissive of the model, and the same color set it to your light source and emissive color
-
EMISSIVE_MAP_FROM (see ALBEDO_MAP_FROM)
-
EMISSIVE_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
EMISSIVE_MAP_APPLY_SCALE (see ALBEDO_MAP_APPLY_SCALE)
-
EMISSIVE_MAP_APPLY_MORPH_COLOR (see ALBEDO_MAP_APPLY_MORPH_COLOR)
-
Texture colors to multiply with intensity from morph controller (Intensity+/-).
-
You can set the blink using following
code
.0
. None
1
. colors to multiply with frequency fromemissiveBlink
. like : const float3 emissiveBlink = float3(1.0, 2.0, 3.0);
2
. colors to multiply with frequency fromBlink
morph controller, seePointLight.pmx
for more information -
EMISSIVE_MAP_FILE (ALBEDO_MAP_FILE)
-
const float2 emissiveMapLoopNum = 0.0 ~ inf; (see albedoMapLoopNum)
-
ID Material CustomA CustomB 0 Default Invalid Invalid 1 PreIntegrated Skin Curvature Transmittance color 2 Unlit placeholder Invalid Invalid 3 Anisotropy Anisotropic Shift tangent 4 Glass Curvature Transmittance color 5 Cloth Sheen Fuzz Color 6 Clear Coat Smoothness Invalid 7 Subsurface Curvature Transmittance color 8 Cel Shading Threshold Shadow color 9 ToonBased Shading Haredness Shadow color -
CUSTOM_A_MAP_FROM (see ALBEDO_MAP_FROM)
-
CUSTOM_A_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
CUSTOM_A_MAP_SWIZZLE (see ALPHA_MAP_SWIZZLE)
-
CUSTOM_A_MAP_APPLY_SCALE (see ALBEDO_MAP_APPLY_SCALE)
-
CUSTOM_A_MAP_FILE "custom.png" (see ALBEDO_MAP_FILE)
-
const float2 customAMapLoopNum = 1.0; (see albedoMapLoopNum)
-
CUSTOM_B_MAP_FROM (see ALBEDO_MAP_FROM)
-
CUSTOM_B_MAP_UV_FLIP (see ALBEDO_MAP_UV_FLIP)
-
CUSTOM_B_MAP_APPLY_SCALE (see ALBEDO_MAP_APPLY_SCALE)
-
CUSTOM_B_MAP_FILE "custom.png" (see ALBEDO_MAP_FILE)
-
const float2 customBMapLoopNum = 1.0; (see albedoMapLoopNum)
The curvature
is also called opacity
, defines the overall scattering intensity affects all the surface, see the UE4 docs for more information
In order to make refraction work, you must set alpha value to less then 0.999
in the pmx model
Sheen
is interpolation between GGX
and InvGGX
, and Fuzz Color
is f0 of fresnel params in sRGB color-space, defines the overall color of the specular see paper for cloth information,
see paper for more information, but chinese
-
What is sRGB-color and Gamma
- The Gamma is near 2.2 used most of time, About sRGB and Gamma, You can see docs for more information
https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch24.html
https://en.wikipedia.org/wiki/SRGB
-
What is gloss map
- Gloss map is a
smoothness map
- Gloss map is a
-
How to use roughness map
- Enter the path to the
SMOOTHNESS_MAP_FILE
and setSMOOTHNESS_MAP_TYPE
to 1
- Enter the path to the
-
Where melanin
- It has moved into
ALBEDO_SUB_ENABLE
, seeALBEDO_SUB_ENABLE
for more information
- It has moved into
-
Why increase number of parallaxMapLoopNum will increase the loop number of albedo, normals, etc
- Bacause parallax coordinates can be calculated from
height map
,that are then used to access textures withalbedo
,normals
,smoothness
,metalness
, etc, In other words like fetched data (albedo
,normals
, etc) from parallax coordinates *parallaxMapLoopNum
*albedo
/normal
/MapLoopNum
- Bacause parallax coordinates can be calculated from