Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
material.h
Go to the documentation of this file.
1 // material [mat] - Tag Definition //
3 // -------- //
4 // Author: haloman30 //
5 // Revision: 7 //
6 // -------- //
7 // Part of the Blamite Game Engine //
8 // Copyright (c) Elaztek Studios 2013 - 2023 //
10 
11 
12 #pragma once
13 
14 #include <string>
15 #include <blam/api/v1/types/tags.h>
17 
18 #ifndef BLAM
19 #define BLAM
20 #endif
21 
22 #define tag_mat "mat"
23 
25 {
27  none,
28  point,
29  linear,
31 };
33 {
34  wrap,
35  mirror,
36  clamp,
37  border,
38 };
40 {
43  less_than,
45  equal,
46  not_equal,
49  disabled,
50 };
51 
52 
53 #pragma pack(push, 1)
54 struct material
55 {
57  TAG_ENUM(material_type,
58  {
59  pbr,
60  unlit,
61  });
62 
63  TAG_BLOCK(pbr_material,
64  {
65  struct bitfield16_flags
66  {
67  bool uses_two_sided_lighting : 1;
68  bool receives_shadows : 1;
69  bool use_emissive_as_lightmap : 1;
70  bool allow_zero_texture_offset_scale : 1;
71  bool unused4 : 1;
72  bool unused5 : 1;
73  bool unused6 : 1;
74  bool unused7 : 1;
75  bool unused8 : 1;
76  bool unused9 : 1;
77  bool unused10 : 1;
78  bool unused11 : 1;
79  bool unused12 : 1;
80  bool unused13 : 1;
81  bool unused14 : 1;
82  bool unused15 : 1;
83  };
84 
85  bitfield16_flags flags;
86  TAG_BLOCK(textures,
87  {
88  TAG_ENUM(texture_type,
89  {
90  diffuse,
91  normal,
92  specular,
93  metallic,
94  roughness,
95  detail_weight,
96  detail_0,
97  detail_1,
98  detail_2,
99  detail_3,
100  detail_normal_0,
101  detail_normal_1,
102  detail_normal_2,
103  detail_normal_3,
104  emissive,
105  reflection,
106  });
107 
108  tag_reference texture;
109  material_filter_modes filter_mode_min;
110  material_filter_modes filter_mode_mag;
111  material_filter_modes filter_mode_mip;
112  material_wrap_modes wrap_mode_x;
113  material_wrap_modes wrap_mode_y;
114  material_wrap_modes wrap_mode_z;
115  real lod_bias;
116  real max_anisotropy;
117  material_comparison_function sampler_comparison_function;
118  color border_color;
119  real min_lod;
120  real max_lod;
121  vector2 offset;
122  vector2 scale;
123  });
124  struct bitfield16_brdf_flags
125  {
126  bool uncorrelated : 1;
127  bool separate_diffuse_fresnel : 1;
128  bool legacy_math : 1;
129  bool full_legacy : 1;
130  bool unused4 : 1;
131  bool unused5 : 1;
132  bool unused6 : 1;
133  bool unused7 : 1;
134  bool unused8 : 1;
135  bool unused9 : 1;
136  bool unused10 : 1;
137  bool unused11 : 1;
138  bool unused12 : 1;
139  bool unused13 : 1;
140  bool unused14 : 1;
141  bool unused15 : 1;
142  };
143 
144  bitfield16_brdf_flags brdf_flags;
145  TAG_ENUM(brdf_function,
146  {
147  default_brdf,
148  cook_torrance,
149  blinn_phong,
150  });
151 
152  material_comparison_function alpha_comparison_function;
153  struct bitfield16_alpha_flags
154  {
155  bool shadow_caster_only : 1;
156  bool use_alpha_from_texture : 1;
157  bool unused2 : 1;
158  bool unused3 : 1;
159  bool unused4 : 1;
160  bool unused5 : 1;
161  bool unused6 : 1;
162  bool unused7 : 1;
163  bool unused8 : 1;
164  bool unused9 : 1;
165  bool unused10 : 1;
166  bool unused11 : 1;
167  bool unused12 : 1;
168  bool unused13 : 1;
169  bool unused14 : 1;
170  bool unused15 : 1;
171  };
172 
173  bitfield16_alpha_flags alpha_flags;
174  real alpha_test_threshold;
175  color diffuse_color;
176  color background_diffuse_color;
177  color emissive_color;
178  real clear_coat_amount;
179  real clear_coat_roughness;
180  real transparency_amount;
181  struct bitfield16_transparency_flags
182  {
183  bool use_alpha_from_textures : 1;
184  bool change_blend_block : 1;
185  bool unused2 : 1;
186  bool unused3 : 1;
187  bool unused4 : 1;
188  bool unused5 : 1;
189  bool unused6 : 1;
190  bool unused7 : 1;
191  bool unused8 : 1;
192  bool unused9 : 1;
193  bool unused10 : 1;
194  bool unused11 : 1;
195  bool unused12 : 1;
196  bool unused13 : 1;
197  bool unused14 : 1;
198  bool unused15 : 1;
199  };
200 
201  bitfield16_transparency_flags transparency_flags;
202  TAG_ENUM(transparency_mode,
203  {
204  none,
205  transparent,
206  fade,
207  refractive,
208  });
209 
210  real refraction_strength;
211  TAG_ENUM(workflows,
212  {
213  specular,
214  specular_fresnel,
215  metallic,
216  });
217 
218  color specular_color;
219  real metalness;
220  real roughness;
221  });
222  TAG_BLOCK(unlit_material,
223  {
224  struct bitfield16_flags
225  {
226  bool enable_planar_reflections : 1;
227  bool enable_diffuse_color : 1;
228  bool allow_zero_texture_offset_scale : 1;
229  bool unused3 : 1;
230  bool unused4 : 1;
231  bool unused5 : 1;
232  bool unused6 : 1;
233  bool unused7 : 1;
234  bool unused8 : 1;
235  bool unused9 : 1;
236  bool unused10 : 1;
237  bool unused11 : 1;
238  bool unused12 : 1;
239  bool unused13 : 1;
240  bool unused14 : 1;
241  bool unused15 : 1;
242  };
243 
244  bitfield16_flags flags;
245  TAG_BLOCK(textures,
246  {
247  int8_t texture_type;
248  tag_reference texture;
249  material_filter_modes filter_mode_min;
250  material_filter_modes filter_mode_mag;
251  material_filter_modes filter_mode_mip;
252  material_wrap_modes wrap_mode_x;
253  material_wrap_modes wrap_mode_y;
254  material_wrap_modes wrap_mode_z;
255  vector2 lod;
256  real lod_bias;
257  real max_anisotropy;
258  vector2 offset;
259  vector2 scale;
260  });
261  color diffuse_color;
262  material_comparison_function alpha_comparison_function;
263  struct bitfield16_alpha_flags
264  {
265  bool shadow_caster_only : 1;
266  bool use_alpha_from_texture : 1;
267  bool unused2 : 1;
268  bool unused3 : 1;
269  bool unused4 : 1;
270  bool unused5 : 1;
271  bool unused6 : 1;
272  bool unused7 : 1;
273  bool unused8 : 1;
274  bool unused9 : 1;
275  bool unused10 : 1;
276  bool unused11 : 1;
277  bool unused12 : 1;
278  bool unused13 : 1;
279  bool unused14 : 1;
280  bool unused15 : 1;
281  };
282 
283  bitfield16_alpha_flags alpha_flags;
284  real alpha_test_threshold;
285  });
286  TAG_BLOCK(input_parameters,
287  {
288  data_reference name;
289  field_reference output_field;
290  struct bitfield8_flags
291  {
292  bool enabled : 1;
293  bool unused1 : 1;
294  bool unused2 : 1;
295  bool unused3 : 1;
296  bool unused4 : 1;
297  bool unused5 : 1;
298  bool unused6 : 1;
299  bool unused7 : 1;
300  };
301 
302  bitfield8_flags flags;
303  });
304 };
305 #pragma pack(pop)
306 
308 {
309 public:
311  {
312  class_name_long = "material";
313  class_name_short = "mat";
314  version = 7;
315 
316  revisions = {
317  {1, "haloman30", "Initial implementation."},
318  {2, "haloman30", "Add settings for texture sampler."},
319  {3, "haloman30", "Combine sampler and texture fields into tag block, with each entry specifying a texture."},
320  {4, "haloman30", "Add fields for texture offset and scale."},
321  {5, "haloman30", "Add input parameters block"},
322  {6, "haloman30", "Add support for unlit materials"},
323  {7, "haloman30", "* Added flag to pbr/unlit materials to allow zero values for texture offset/scale (disabled by default to mimic ogre behavior)"},
324 
325  };
326 
327  tag_size = 132;
328 
329  fields =
330  {
331  new CommentField("Material",
332  ""),
333  new DataReferenceField("id", ""),
334  new Enum32Field("material type", "",
335  {
336  "pbr",
337  "unlit",
338  }),
339  new BlockField(100, "pbr material", "",
340  {
341  new Bitfield16Field("flags", "",
342  {
343  "uses two sided lighting",
344  "receives shadows",
345  "use emissive as lightmap",
346  "allow zero values for texture offset/scale",
347  }),
348  new BlockField(100, "textures", "",
349  {
350  new CommentField("TEXTURES",
351  ""),
352  new Enum32Field("texture type", "",
353  {
354  "diffuse",
355  "normal",
356  "specular",
357  "metallic",
358  "roughness",
359  "detail_weight",
360  "detail_0",
361  "detail_1",
362  "detail_2",
363  "detail_3",
364  "detail_normal_0",
365  "detail_normal_1",
366  "detail_normal_2",
367  "detail_normal_3",
368  "emissive",
369  "reflection",
370  }),
371  new TagReferenceField("texture", "", { "bitmap"}),
372  new CommentField("SAMPLER",
373  ""),
374  new Enum32Field("filter mode (min)", "",
375  {
376  "inherit from bitmap",
377  "none",
378  "point",
379  "linear",
380  "anisotropic",
381  }),
382  new Enum32Field("filter mode (mag)", "",
383  {
384  "inherit from bitmap",
385  "none",
386  "point",
387  "linear",
388  "anisotropic",
389  }),
390  new Enum32Field("filter mode (mip)", "",
391  {
392  "inherit from bitmap",
393  "none",
394  "point",
395  "linear",
396  "anisotropic",
397  }),
398  new Enum32Field("wrap mode x", "",
399  {
400  "wrap",
401  "mirror",
402  "clamp",
403  "border",
404  }),
405  new Enum32Field("wrap mode y", "",
406  {
407  "wrap",
408  "mirror",
409  "clamp",
410  "border",
411  }),
412  new Enum32Field("wrap mode z", "",
413  {
414  "wrap",
415  "mirror",
416  "clamp",
417  "border",
418  }),
419  new RealField("lod bias", ""),
420  new RealField("max anisotropy", ""),
421  new Enum32Field("sampler comparison function", "",
422  {
423  "always fail",
424  "always pass",
425  "less than",
426  "less than or equal",
427  "equal",
428  "not equal",
429  "greater than or equal",
430  "greater than",
431  "disabled",
432  }),
433  new ColorField("border color", ""),
434  new RealField("min lod", ""),
435  new RealField("max lod", ""),
436  new Vector2Field("offset", ""),
437  new Vector2Field("scale", ""),
438  }),
439  new CommentField("BRDF",
440  "bidirectional reflectance distribution function"),
441  new Bitfield16Field("brdf flags", "",
442  {
443  "uncorrelated",
444  "separate diffuse fresnel",
445  "legacy math",
446  "full legacy",
447  }),
448  new Enum32Field("brdf function", "",
449  {
450  "default",
451  "cook-torrance",
452  "blinn-phong",
453  }),
454  new CommentField("ALPHA",
455  ""),
456  new Enum32Field("alpha comparison function", "",
457  {
458  "always fail",
459  "always pass",
460  "less than",
461  "less than or equal",
462  "equal",
463  "not equal",
464  "greater than or equal",
465  "greater than",
466  "disabled",
467  }),
468  new Bitfield16Field("alpha flags", "",
469  {
470  "shadow caster only",
471  "use alpha from texture",
472  }),
473  new RealField("alpha test threshold", ""),
474  new CommentField("COLORS",
475  ""),
476  new ColorField("diffuse color", ""),
477  new ColorField("background diffuse color", ""),
478  new ColorField("emissive color", ""),
479  new CommentField("CLEAR COAT",
480  ""),
481  new RealField("clear coat amount", ""),
482  new RealField("clear coat roughness", ""),
483  new CommentField("TRANSPARENCY",
484  ""),
485  new RealField("transparency amount", ""),
486  new Bitfield16Field("transparency flags", "",
487  {
488  "use alpha from textures",
489  "change blend block",
490  }),
491  new Enum32Field("transparency mode", "",
492  {
493  "none",
494  "transparent",
495  "fade",
496  "refractive",
497  }),
498  new RealField("refraction strength", ""),
499  new CommentField("WORKFLOWS",
500  ""),
501  new Enum32Field("workflows", "",
502  {
503  "specular",
504  "specular (fresnel)",
505  "metallic",
506  }),
507  new ColorField("specular color", ""),
508  new RealField("metalness", ""),
509  new RealField("roughness", ""),
510  }),
511  new BlockField(48, "unlit material", "",
512  {
513  new Bitfield16Field("flags", "",
514  {
515  "enable planar reflections",
516  "enable diffuse color",
517  "allow zero values for texture offset/scale",
518  }),
519  new BlockField(89, "textures", "",
520  {
521  new CommentField("TEXTURES",
522  ""),
523  new Int8Field("texture type", ""),
524  new TagReferenceField("texture", "", { }),
525  new CommentField("SAMPLER",
526  ""),
527  new Enum32Field("filter mode (min)", "",
528  {
529  "inherit from bitmap",
530  "none",
531  "point",
532  "linear",
533  "anisotropic",
534  }),
535  new Enum32Field("filter mode (mag)", "",
536  {
537  "inherit from bitmap",
538  "none",
539  "point",
540  "linear",
541  "anisotropic",
542  }),
543  new Enum32Field("filter mode (mip)", "",
544  {
545  "inherit from bitmap",
546  "none",
547  "point",
548  "linear",
549  "anisotropic",
550  }),
551  new Enum32Field("wrap mode x", "",
552  {
553  "wrap",
554  "mirror",
555  "clamp",
556  "border",
557  }),
558  new Enum32Field("wrap mode y", "",
559  {
560  "wrap",
561  "mirror",
562  "clamp",
563  "border",
564  }),
565  new Enum32Field("wrap mode z", "",
566  {
567  "wrap",
568  "mirror",
569  "clamp",
570  "border",
571  }),
572  new Vector2Field("lod", ""),
573  new RealField("lod bias", ""),
574  new RealField("max anisotropy", ""),
575  new Vector2Field("offset", ""),
576  new Vector2Field("scale", ""),
577  }),
578  new ColorField("diffuse color", ""),
579  new CommentField("ALPHA",
580  ""),
581  new Enum32Field("alpha comparison function", "",
582  {
583  "always fail",
584  "always pass",
585  "less than",
586  "less than or equal",
587  "equal",
588  "not equal",
589  "greater than or equal",
590  "greater than",
591  "disabled",
592  }),
593  new Bitfield16Field("alpha flags", "",
594  {
595  "shadow caster only",
596  "use alpha from texture",
597  }),
598  new RealField("alpha test threshold", ""),
599  }),
600  new BlockField(53, "input parameters", "",
601  {
602  new DataReferenceField("name", ""),
603  new FieldReferenceField("output field", ""),
604  new Bitfield8Field("flags", "",
605  {
606  "enabled",
607  }),
608  }),
609 
610  };
611  }
612 };
613 
614 namespace Blam::Content::Tags
615 {
616  BLAM material* GetMaterialTag(std::string tag_path);
617 }
material::TAG_BLOCK
TAG_BLOCK(pbr_material, { struct bitfield16_flags { bool uses_two_sided_lighting :1;bool receives_shadows :1;bool use_emissive_as_lightmap :1;bool allow_zero_texture_offset_scale :1;bool unused4 :1;bool unused5 :1;bool unused6 :1;bool unused7 :1;bool unused8 :1;bool unused9 :1;bool unused10 :1;bool unused11 :1;bool unused12 :1;bool unused13 :1;bool unused14 :1;bool unused15 :1;};bitfield16_flags flags;TAG_BLOCK(textures, { TAG_ENUM(texture_type, { diffuse, normal, specular, metallic, roughness, detail_weight, detail_0, detail_1, detail_2, detail_3, detail_normal_0, detail_normal_1, detail_normal_2, detail_normal_3, emissive, reflection, });tag_reference texture;material_filter_modes filter_mode_min;material_filter_modes filter_mode_mag;material_filter_modes filter_mode_mip;material_wrap_modes wrap_mode_x;material_wrap_modes wrap_mode_y;material_wrap_modes wrap_mode_z;real lod_bias;real max_anisotropy;material_comparison_function sampler_comparison_function;color border_color;real min_lod;real max_lod;vector2 offset;vector2 scale;});struct bitfield16_brdf_flags { bool uncorrelated :1;bool separate_diffuse_fresnel :1;bool legacy_math :1;bool full_legacy :1;bool unused4 :1;bool unused5 :1;bool unused6 :1;bool unused7 :1;bool unused8 :1;bool unused9 :1;bool unused10 :1;bool unused11 :1;bool unused12 :1;bool unused13 :1;bool unused14 :1;bool unused15 :1;};bitfield16_brdf_flags brdf_flags;TAG_ENUM(brdf_function, { default_brdf, cook_torrance, blinn_phong, });material_comparison_function alpha_comparison_function;struct bitfield16_alpha_flags { bool shadow_caster_only :1;bool use_alpha_from_texture :1;bool unused2 :1;bool unused3 :1;bool unused4 :1;bool unused5 :1;bool unused6 :1;bool unused7 :1;bool unused8 :1;bool unused9 :1;bool unused10 :1;bool unused11 :1;bool unused12 :1;bool unused13 :1;bool unused14 :1;bool unused15 :1;};bitfield16_alpha_flags alpha_flags;real alpha_test_threshold;color diffuse_color;color background_diffuse_color;color emissive_color;real clear_coat_amount;real clear_coat_roughness;real transparency_amount;struct bitfield16_transparency_flags { bool use_alpha_from_textures :1;bool change_blend_block :1;bool unused2 :1;bool unused3 :1;bool unused4 :1;bool unused5 :1;bool unused6 :1;bool unused7 :1;bool unused8 :1;bool unused9 :1;bool unused10 :1;bool unused11 :1;bool unused12 :1;bool unused13 :1;bool unused14 :1;bool unused15 :1;};bitfield16_transparency_flags transparency_flags;TAG_ENUM(transparency_mode, { none, transparent, fade, refractive, });real refraction_strength;TAG_ENUM(workflows, { specular, specular_fresnel, metallic, });color specular_color;real metalness;real roughness;})
material_filter_modes::inherit_from_bitmap
@ inherit_from_bitmap
Blam::Content::Tags
Namespace containing functions related to tag data.
Definition: bitmap.h:181
RealField
Class representing a real tag field.
Definition: real.h:16
color
BlamColor color
Typedef for a color field, used in tag definitions.
Definition: tags.h:447
material_wrap_modes
material_wrap_modes
Definition: material.h:32
Vector2Field
Class representing a vector2 tag field.
Definition: vector.h:34
material_comparison_function::less_than_or_equal
@ less_than_or_equal
DataReferenceField
Class representing a data reference, or dataref for short.
Definition: dataref.h:19
material_wrap_modes::wrap
@ wrap
Bitfield16Field
Class representing a bitfield16 tag field.
Definition: bitfield.h:44
bitmap_filtering_mode::point
@ point
TagReferenceField
Class representing a tag reference, or tagref for short.
Definition: tagref.h:20
Enum32Field
Definition: enum.h:45
Blam::API::v1::Tags::GetTagData
BLAM_EXT_API BlamTagData * GetTagData(std::string tag_path)
Retrieves information for a given tag.
Definition: api.cpp:208
int8_t
signed char int8_t
Definition: stdint.h:11
BlamTagClass::fields
std::vector< BlamTagClassField * > fields
A series of tag fields that store the layout of the tag.
Definition: tags.h:209
bitmap_filtering_mode::anisotropic
@ anisotropic
BlamTagClass::revisions
std::vector< BlamTagClassRevision > revisions
List of all tag class revisions. Does not get written to tags, but is included in plugin files.
Definition: tags.h:208
material_comparison_function::less_than
@ less_than
plugins.h
Int8Field
Class representing an int8 tag field.
Definition: int.h:72
material.h
BlamTagClass::class_name_short
std::string class_name_short
The short, 4-character name of the tag class.
Definition: tags.h:206
BlamTagClass::version
int version
The tag class version. Should be incremented any time a tag class is modified whatsoever.
Definition: tags.h:207
material_comparison_function::always_pass
@ always_pass
material_comparison_function::always_fail
@ always_fail
tag_reference
Structure representing a tag reference.
Definition: tags.h:289
field_reference
Structure representing a field reference.
Definition: tags.h:455
material_wrap_modes::border
@ border
BlamTagClass::class_name_long
std::string class_name_long
The longer class name. Typically shown alongside short name for user-friendliness.
Definition: tags.h:205
material
Definition: material.h:54
real
float real
Typedef for a 'real', aka a float.
Definition: tags.h:443
material_filter_modes
material_filter_modes
Definition: material.h:24
uint32_t
unsigned int uint32_t
Definition: stdint.h:17
MaterialTagClass
Definition: material.h:307
bitmap_filtering_mode::none
@ none
bitmap_filtering_mode::linear
@ linear
material_wrap_modes::mirror
@ mirror
material_comparison_function::greater_than_or_equal
@ greater_than_or_equal
material::id
data_reference id
Definition: material.h:56
data_reference
Structure representing a data reference.
Definition: tags.h:342
tag_mat
#define tag_mat
Definition: material.h:22
material_comparison_function::disabled
@ disabled
BlamTagClass::tag_size
int tag_size
The size of the tag's data. Used on loading/writing tag files.
Definition: tags.h:210
material_comparison_function::not_equal
@ not_equal
material::TAG_ENUM
TAG_ENUM(material_type, { pbr, unlit, })
BLAM
#define BLAM
Definition: material.h:19
ColorField
Class representing a color tag field.
Definition: color.h:19
vector2
BlamVector2 vector2
Typedef for a vector2 field, used in tag definitions.
Definition: tags.h:444
BlamTagData::address
void * address
The address pointing to the start of the tag's data.
Definition: tags.h:132
tags.h
BlamTagData
Class used to contain and access tag data.
Definition: tags.h:125
Blam::Content::Tags::GetMaterialTag
BLAM material * GetMaterialTag(std::string tag_path)
Definition: material.cpp:16
material_comparison_function::equal
@ equal
FieldReferenceField
Class representing a fieldref tag field.
Definition: fieldref.h:17
MaterialTagClass::MaterialTagClass
MaterialTagClass()
Definition: material.h:310
CommentField
Class representing a comment field.
Definition: comment.h:29
material_comparison_function::greater_than
@ greater_than
BlockField
Class representing a tag block field, also sometimes referred to as a struct or reflexive in the modd...
Definition: block.h:19
material_comparison_function
material_comparison_function
Definition: material.h:39
BlamTagClass
Class representing a tag class.
Definition: tags.h:202
Bitfield8Field
Class representing a bitfield8 tag field.
Definition: bitfield.h:33
api.h
BlamTagData::tag_class
std::string tag_class
The tag's short class name.
Definition: tags.h:146
material_wrap_modes::clamp
@ clamp