Elaztek Developer Hub
Blamite Game Engine - blam!  00406.12.10.23.1457.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: 6 //
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 
23 {
25  none,
26  point,
27  linear,
29 };
31 {
32  wrap,
33  mirror,
34  clamp,
35  border,
36 };
38 {
41  less_than,
43  equal,
44  not_equal,
47  disabled,
48 };
49 
50 
51 #pragma pack(push, 1)
52 struct material
53 {
54  //Material
55 
57  TAG_ENUM(material_type,
58  {
59  pbr,
60  unlit,
61  });
62 
63  TAG_BLOCK(pbr_material,
64  {
65  bitfield16 flags;
66  TAG_BLOCK(textures,
67  {
68  //TEXTURES
69 
70  TAG_ENUM(texture_type,
71  {
72  diffuse,
73  normal,
74  specular,
75  metallic,
76  roughness,
77  detail_weight,
78  detail_0,
79  detail_1,
80  detail_2,
81  detail_3,
82  detail_normal_0,
83  detail_normal_1,
84  detail_normal_2,
85  detail_normal_3,
86  emissive,
87  reflection,
88  });
89 
90  tag_reference texture;
91  //SAMPLER
92 
93  material_filter_modes filter_mode_min;
94  material_filter_modes filter_mode_mag;
95  material_filter_modes filter_mode_mip;
96  material_wrap_modes wrap_mode_x;
97  material_wrap_modes wrap_mode_y;
98  material_wrap_modes wrap_mode_z;
99  real lod_bias;
100  real max_anisotropy;
101  material_comparison_function sampler_comparison_function;
102  color border_color;
103  real min_lod;
104  real max_lod;
105  vector2 offset;
106  vector2 scale;
107  });
108  //BRDF
109  /*bidirectional reflectance distribution function*/
110  bitfield16 brdf_flags;
111  TAG_ENUM(brdf_function,
112  {
113  default_brdf,
114  cook_torrance,
115  blinn_phong,
116  });
117 
118  //ALPHA
119 
120  material_comparison_function alpha_comparison_function;
121  bitfield16 alpha_flags;
122  real alpha_test_threshold;
123  //COLORS
124 
125  color diffuse_color;
126  color background_diffuse_color;
127  color emissive_color;
128  //CLEAR COAT
129 
130  real clear_coat_amount;
131  real clear_coat_roughness;
132  //TRANSPARENCY
133 
134  real transparency_amount;
135  bitfield16 transparency_flags;
136  TAG_ENUM(transparency_mode,
137  {
138  none,
139  transparent,
140  fade,
141  refractive,
142  });
143 
144  real refraction_strength;
145  //WORKFLOWS
146 
147  TAG_ENUM(workflows,
148  {
149  specular,
150  specular_fresnel,
151  metallic,
152  });
153 
154  color specular_color;
155  real metalness;
156  real roughness;
157  });
158  TAG_BLOCK(unlit_material,
159  {
160  bitfield16 flags;
161  TAG_BLOCK(textures,
162  {
163  //TEXTURES
164 
165  int8_t texture_type;
166  tag_reference texture;
167  //SAMPLER
168 
169  material_filter_modes filter_mode_min;
170  material_filter_modes filter_mode_mag;
171  material_filter_modes filter_mode_mip;
172  material_wrap_modes wrap_mode_x;
173  material_wrap_modes wrap_mode_y;
174  material_wrap_modes wrap_mode_z;
175  vector2 lod;
176  real lod_bias;
177  real max_anisotropy;
178  vector2 offset;
179  vector2 scale;
180  });
181  color diffuse_color;
182  //ALPHA
183 
184  material_comparison_function alpha_comparison_function;
185  bitfield16 alpha_flags;
186  real alpha_test_threshold;
187  });
188  TAG_BLOCK(input_parameters,
189  {
190  ascii name;
191  field_reference output_field;
192  bitfield8 flags;
193  });
194 };
195 #pragma pack(pop)
196 
198 {
199 public:
201  {
202  class_name_long = "material";
203  class_name_short = "mat";
204  version = 6;
205 
206  revisions = {
207  {1, "haloman30", "Initial implementation."},
208  {2, "haloman30", "Add settings for texture sampler."},
209  {3, "haloman30", "Combine sampler and texture fields into tag block, with each entry specifying a texture."},
210  {4, "haloman30", "Add fields for texture offset and scale."},
211  {5, "haloman30", "Add input parameters block"},
212  {6, "haloman30", "Add support for unlit materials"},
213 
214  };
215 
216  tag_size = 228;
217 
218  fields =
219  {
220  new CommentField("Material",
221  ""),
222  new AsciiField("id", ""),
223  new Enum32Field("material type", "",
224  {
225  "pbr",
226  "unlit",
227  }),
228  new BlockField(100, "pbr material", "",
229  {
230  new Bitfield16Field("flags", "",
231  {
232  "uses two sided lighting",
233  "receives shadows",
234  "use emissive as lightmap",
235  }),
236  new BlockField(100, "textures", "",
237  {
238  new CommentField("TEXTURES",
239  ""),
240  new Enum32Field("texture type", "",
241  {
242  "diffuse",
243  "normal",
244  "specular",
245  "metallic",
246  "roughness",
247  "detail_weight",
248  "detail_0",
249  "detail_1",
250  "detail_2",
251  "detail_3",
252  "detail_normal_0",
253  "detail_normal_1",
254  "detail_normal_2",
255  "detail_normal_3",
256  "emissive",
257  "reflection",
258  }),
259  new TagReferenceField("texture", "", { "bitmap"}),
260  new CommentField("SAMPLER",
261  ""),
262  new Enum32Field("filter mode (min)", "",
263  {
264  "inherit from bitmap",
265  "none",
266  "point",
267  "linear",
268  "anisotropic",
269  }),
270  new Enum32Field("filter mode (mag)", "",
271  {
272  "inherit from bitmap",
273  "none",
274  "point",
275  "linear",
276  "anisotropic",
277  }),
278  new Enum32Field("filter mode (mip)", "",
279  {
280  "inherit from bitmap",
281  "none",
282  "point",
283  "linear",
284  "anisotropic",
285  }),
286  new Enum32Field("wrap mode x", "",
287  {
288  "wrap",
289  "mirror",
290  "clamp",
291  "border",
292  }),
293  new Enum32Field("wrap mode y", "",
294  {
295  "wrap",
296  "mirror",
297  "clamp",
298  "border",
299  }),
300  new Enum32Field("wrap mode z", "",
301  {
302  "wrap",
303  "mirror",
304  "clamp",
305  "border",
306  }),
307  new RealField("lod bias", ""),
308  new RealField("max anisotropy", ""),
309  new Enum32Field("sampler comparison function", "",
310  {
311  "always fail",
312  "always pass",
313  "less than",
314  "less than or equal",
315  "equal",
316  "not equal",
317  "greater than or equal",
318  "greater than",
319  "disabled",
320  }),
321  new ColorField("border color", ""),
322  new RealField("min lod", ""),
323  new RealField("max lod", ""),
324  new Vector2Field("offset", ""),
325  new Vector2Field("scale", ""),
326  }),
327  new CommentField("BRDF",
328  "bidirectional reflectance distribution function"),
329  new Bitfield16Field("brdf flags", "",
330  {
331  "uncorrelated",
332  "separate diffuse fresnel",
333  "legacy math",
334  "full legacy",
335  }),
336  new Enum32Field("brdf function", "",
337  {
338  "default",
339  "cook-torrance",
340  "blinn-phong",
341  }),
342  new CommentField("ALPHA",
343  ""),
344  new Enum32Field("alpha comparison function", "",
345  {
346  "always fail",
347  "always pass",
348  "less than",
349  "less than or equal",
350  "equal",
351  "not equal",
352  "greater than or equal",
353  "greater than",
354  "disabled",
355  }),
356  new Bitfield16Field("alpha flags", "",
357  {
358  "shadow caster only",
359  "use alpha from texture",
360  }),
361  new RealField("alpha test threshold", ""),
362  new CommentField("COLORS",
363  ""),
364  new ColorField("diffuse color", ""),
365  new ColorField("background diffuse color", ""),
366  new ColorField("emissive color", ""),
367  new CommentField("CLEAR COAT",
368  ""),
369  new RealField("clear coat amount", ""),
370  new RealField("clear coat roughness", ""),
371  new CommentField("TRANSPARENCY",
372  ""),
373  new RealField("transparency amount", ""),
374  new Bitfield16Field("transparency flags", "",
375  {
376  "use alpha from textures",
377  "change blend block",
378  }),
379  new Enum32Field("transparency mode", "",
380  {
381  "none",
382  "transparent",
383  "fade",
384  "refractive",
385  }),
386  new RealField("refraction strength", ""),
387  new CommentField("WORKFLOWS",
388  ""),
389  new Enum32Field("workflows", "",
390  {
391  "specular",
392  "specular (fresnel)",
393  "metallic",
394  }),
395  new ColorField("specular color", ""),
396  new RealField("metalness", ""),
397  new RealField("roughness", ""),
398  }),
399  new BlockField(48, "unlit material", "",
400  {
401  new Bitfield16Field("flags", "",
402  {
403  "enable planar reflections",
404  "enable diffuse color",
405  }),
406  new BlockField(89, "textures", "",
407  {
408  new CommentField("TEXTURES",
409  ""),
410  new Int8Field("texture type", ""),
411  new TagReferenceField("texture", "", { }),
412  new CommentField("SAMPLER",
413  ""),
414  new Enum32Field("filter mode (min)", "",
415  {
416  "inherit from bitmap",
417  "none",
418  "point",
419  "linear",
420  "anisotropic",
421  }),
422  new Enum32Field("filter mode (mag)", "",
423  {
424  "inherit from bitmap",
425  "none",
426  "point",
427  "linear",
428  "anisotropic",
429  }),
430  new Enum32Field("filter mode (mip)", "",
431  {
432  "inherit from bitmap",
433  "none",
434  "point",
435  "linear",
436  "anisotropic",
437  }),
438  new Enum32Field("wrap mode x", "",
439  {
440  "wrap",
441  "mirror",
442  "clamp",
443  "border",
444  }),
445  new Enum32Field("wrap mode y", "",
446  {
447  "wrap",
448  "mirror",
449  "clamp",
450  "border",
451  }),
452  new Enum32Field("wrap mode z", "",
453  {
454  "wrap",
455  "mirror",
456  "clamp",
457  "border",
458  }),
459  new Vector2Field("lod", ""),
460  new RealField("lod bias", ""),
461  new RealField("max anisotropy", ""),
462  new Vector2Field("offset", ""),
463  new Vector2Field("scale", ""),
464  }),
465  new ColorField("diffuse color", ""),
466  new CommentField("ALPHA",
467  ""),
468  new Enum32Field("alpha comparison function", "",
469  {
470  "always fail",
471  "always pass",
472  "less than",
473  "less than or equal",
474  "equal",
475  "not equal",
476  "greater than or equal",
477  "greater than",
478  "disabled",
479  }),
480  new Bitfield16Field("alpha flags", "",
481  {
482  "shadow caster only",
483  "use alpha from texture",
484  }),
485  new RealField("alpha test threshold", ""),
486  }),
487  new BlockField(149, "input parameters", "",
488  {
489  new AsciiField("name", ""),
490  new FieldReferenceField("output field", ""),
491  new Bitfield8Field("flags", "",
492  {
493  "enabled",
494  }),
495  }),
496 
497  };
498  }
499 };
500 
501 namespace Blam::Content::Tags
502 {
503  BLAM material* GetMaterialTag(std::string tag_path);
504 }
material_filter_modes::inherit_from_bitmap
@ inherit_from_bitmap
Blam::Content::Tags
Namespace containing functions related to tag data.
Definition: bitmap.h:195
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:416
material::TAG_BLOCK
TAG_BLOCK(pbr_material, { bitfield16 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;});bitfield16 brdf_flags;TAG_ENUM(brdf_function, { default_brdf, cook_torrance, blinn_phong, });material_comparison_function alpha_comparison_function;bitfield16 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;bitfield16 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_wrap_modes
material_wrap_modes
Definition: material.h:30
AsciiField
Class representing an ascii tag field.
Definition: ascii.h:18
ascii
char ascii[128]
Typedef for an ascii field, used in tag data definitions.
Definition: tags.h:410
Vector2Field
Class representing a vector2 tag field.
Definition: vector.h:34
material_comparison_function::less_than_or_equal
@ less_than_or_equal
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:46
Blam::API::v1::Tags::GetTagData
BLAM_EXT_API BlamTagData * GetTagData(std::string tag_path)
Retrieves information for a given tag.
Definition: api.cpp:34
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:195
bitfield8
Typedef for a bitfield8 field, used in tag data definitions.
Definition: tags.h:332
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:194
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:192
BlamTagClass::version
int version
The tag class version. Should be incremented any time a tag class is modified whatsoever.
Definition: tags.h:193
material_comparison_function::always_pass
@ always_pass
material_comparison_function::always_fail
@ always_fail
tag_reference
Structure representing a tag reference.
Definition: tags.h:272
field_reference
Structure representing a field reference.
Definition: tags.h:424
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:191
material
Definition: material.h:52
real
float real
Typedef for a 'real', aka a float.
Definition: tags.h:412
material_filter_modes
material_filter_modes
Definition: material.h:22
uint32_t
unsigned int uint32_t
Definition: stdint.h:17
MaterialTagClass
Definition: material.h:197
material::id
ascii id
Definition: material.h:56
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
bitfield16
Typedef for a bitfield16 field, used in tag data definitions.
Definition: tags.h:347
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:196
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:413
BlamTagData::address
void * address
The address pointing to the start of the tag's data.
Definition: tags.h:128
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:200
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:37
BlamTagClass
Class representing a tag class.
Definition: tags.h:188
name
ARPHIC PUBLIC LICENSE Ltd Yung Chi Taiwan All rights reserved except as specified below Everyone is permitted to copy and distribute verbatim copies of this license but changing it is forbidden Preamble The licenses for most software are designed to take away your freedom to share and change it By the ARPHIC PUBLIC LICENSE specifically permits and encourages you to use this provided that you give the recipients all the rights that we gave you and make sure they can get the modifications of this software Legal Terms Font means the TrueType fonts AR PL Mingti2L AR PL KaitiM AR PL KaitiM and the derivatives of those fonts created through any modification including modifying reordering converting changing font name
Definition: ARPHICPL.TXT:16
Bitfield8Field
Class representing a bitfield8 tag field.
Definition: bitfield.h:33
api.h
material_wrap_modes::clamp
@ clamp