I also updated Ogre to use a CMake option OGRE_CONFIG_ENABLE_JSON. It was supposed to be mandatory but after much meditation I decided to make it optional.
What does it do?
Well, that's the juicy part: When enabled, Ogre will look for *.material.json files containing JSON definition of our favourite Hlms materials. The code is easier to maintain, the format is human readable and editable, and there's a lot of tools for handling JSON.
It supports all the features/options that PBS materials can handle, which is something the old implementation was lagging behind (it was becoming increasingly difficult to handle all the features).
The main goal of this system is to allow material editors to have something to work with that can be loaded and saved easily, while quick hand-edits with notepad are still possible.
This is an example of a valid json material:
Code: Select all
{
"samplers" :
{
"unique_name" :
{
"min" : "linear",
"mag" : "linear",
"mip" : "linear",
"u" : "wrap",
"v" : "wrap",
"w" : "wrap",
"miplodbias" : 0,
"max_anisotropic" : 1,
"compare_function" : "disabled",
"border" : [1, 1, 1, 1],
"min_lod" : -3.40282347E+38,
"max_lod" : 3.40282347E+38
}
},
"macroblocks" :
{
"unique_name" :
{
"scissor_test" : false,
"depth_check" : true,
"depth_write" : true,
"depth_function" : "less_equal",
"depth_bias_constant" : 0,
"depth_bias_slope_scale" : 0,
"cull_mode" : "clockwise",
"polygon_mode" : "solid"
}
},
"blendblocks" :
{
"unique_name" :
{
"alpha_to_coverage" : false,
"blendmask" : "rgba",
"separate_blend" : false,
"src_blend_factor" : "one",
"dst_blend_factor" : "zero",
"src_alpha_blend_factor" : "one",
"dst_alpha_blend_factor" : "zero",
"blend_operation" : "add",
"blend_operation_alpha" : "add"
}
},
"pbs" :
{
"material_name" :
{
"macroblock" : "unique_name",
"blendblock" : "unique_name",
"alpha_test" : ["disabled", 0.5],
"shadow_const_bias" : 0.01,
"workflow" : "specular_fresnel",
"transparency" :
{
"value" : 1.0,
"mode" : "None",
"use_alpha_from_textures" : true
},
"diffuse" :
{
"value" : [1, 1, 1],
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"specular" :
{
"value" : [1, 1, 1]
},
"roughness" :
{
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"fresnel" :
{
"mode" : "coeff",
"value" : [1, 1, 1],
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"normal" :
{
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"detail_weight" :
{
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"detail_diffuse0" :
{
"mode" : "NormalNonPremul",
"offset" : [0, 0],
"scale" : [1, 1],
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"detail_normal0" :
{
"offset" : [0, 0],
"scale" : [1, 1],
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"reflection" :
{
"texture" : "cubemap.png",
"sampler" : "unique_name"
}
}
}
}
Then these names can be referenced from the pbs materials.
For reference, these is an example of all available options. Note it is not valid JSON, nor a valid material (i.e. you shouldn't define a metallic texture when the workflow isn't metallic, it will assert in debug mode):
Code: Select all
{
"samplers" :
{
"unique_name" :
{
"min" : "point" "linear" "anisotropic",
"mag" : "point" "linear" "anisotropic",
"mip" : "none" "point" "linear" "anisotropic",
"u" : "wrap" "mirror" "clamp" "border",
"v" : "wrap" "mirror" "clamp" "border",
"w" : "wrap" "mirror" "clamp" "border",
"miplodbias" : 0,
"max_anisotropic" : 1,
"compare_function" : "less" "less_equal" "equal" "not_equal" "greater_equal" "greater" "never" "always" "disabled",
"border" : [1, 1, 1, 1],
"min_lod" : -3.40282347E+38,
"max_lod" : 3.40282347E+38
}
},
"macroblocks" :
{
"unique_name" :
{
"scissor_test" : false,
"depth_check" : true,
"depth_write" : true,
"depth_function" : "less" "less_equal" "equal" "not_equal" "greater_equal" "greater" "never" "always",
"depth_bias_constant" : 0,
"depth_bias_slope_scale" : 0,
"cull_mode" : "none" "clockwise" "anticlockwise",
"polygon_mode" : "points" "wireframe" "solid"
}
},
"blendblocks" :
{
"unique_name" :
{
"alpha_to_coverage" : false,
"blendmask" : "rgba",
"separate_blend" : true,
"src_blend_factor" : "one" "zero" "dst_colour" "src_colour" "one_minus_dst_colour" "one_minus_src_colour" "dst_alpha" "src_alpha" "one_minus_dst_alpha" "one_minus_src_alpha",
"dst_blend_factor" : "one" "zero" "dst_colour" "src_colour" "one_minus_dst_colour" "one_minus_src_colour" "dst_alpha" "src_alpha" "one_minus_dst_alpha" "one_minus_src_alpha",
"src_alpha_blend_factor" : "one" "zero" "dst_colour" "src_colour" "one_minus_dst_colour" "one_minus_src_colour" "dst_alpha" "src_alpha" "one_minus_dst_alpha" "one_minus_src_alpha",
"dst_alpha_blend_factor" : "one" "zero" "dst_colour" "src_colour" "one_minus_dst_colour" "one_minus_src_colour" "dst_alpha" "src_alpha" "one_minus_dst_alpha" "one_minus_src_alpha",
"blend_operation" : "add" "subtract" "reverse_subtract" "min" "max",
"blend_operation_alpha" : "add" "subtract" "reverse_subtract" "min" "max"
}
},
"pbs" :
{
"material_name" :
{
"macroblock" : "unique_name" ["unique_name", "unique_name_for_shadows"],
"blendblock" : "unique_name" ["unique_name", "unique_name_for_shadows"],
"alpha_test" : ["less" "less_equal" "equal" "not_equal" "greater_equal" "greater" "never" "always" "disabled", 0.5],
"shadow_const_bias" : 0.01,
"workflow" : "specular_ogre" "specular_fresnel" "metallic",
"transparency" :
{
"value" : 1.0,
"mode" : "None" "Transparent" "Fade",
"use_alpha_from_textures" : true
},
"diffuse" :
{
"value" : [1, 1, 1],
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"specular" :
{
"value" : [1, 1, 1],
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"roughness" :
{
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"fresnel" :
{
"mode" : "coeff" "ior" "coloured" "coloured_ior",
"value" : [1, 1, 1],
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"metallness" :
{
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"normal" :
{
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"detail_weight" :
{
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"detail_diffuse0" :
{
"mode" : "NormalNonPremul" "NormalPremul" "Add" "Subtract" "Multiply" "Multiply2x" "Screen" "Overlay" "Lighten" "Darken" "GrainExtract" "GrainMerge" "Difference",
"offset" : [0, 0],
"scale" : [1, 1],
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"detail_normal0" :
{
"offset" : [0, 0],
"scale" : [1, 1],
"value" : 1,
"texture" : "texture.png",
"sampler" : "unique_name",
"uv" : 0
},
"reflection" :
{
"texture" : "cubemap.png",
"sampler" : "unique_name"
}
}
}
}
Also note when an option isn't provided, a default is used.
There could be one or two bugs to iron out.
What about the old scripts? I don't plan on removing them, but I don't plan on improving it either. It was not scaling well.