Developer Luxophia on Github developed a powerful library, MyMaterial, that works with Direct 3D and lets you create your own material and apply them to 3D objects in Delphi 10 Berlin with FireMonkey. Normally in FireMonkey in order to give a texture, such as colors and patterns to 3D components, TColorMaterialSource, TTextureMaterialSource and TLightMaterialSource are used but if you require more complex material you have to create your own. At the core of MyMaterial library stand: TShaderSource, TShaderVar which are used in TMaterial. The TShaderVar contains information about the color, vertex, light, shader of the material. One thing to remember is that Direct3D uses HLSL (High-Level Shader Language or High-Level Shading Language), a proprietary shading language used to describe the shader. MyMaterial library translated the HLSL into TShaderSource and TShaderVar, thus you are no longer required to describe each shader variable, it will do this automatically. You can even load the shader from an external file (text file).

Delphi/Pascal

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

TMyMaterial=class(TMaterial)

private

protected

_FMatrixMVP:TShaderVarMatrix;

_FMatrixMV:TShaderVarMatrix;

_TIMatrixMV:TShaderVarMatrix;

_EyePos:TShaderVarVector;

_Opacity:TShaderVarFloat;

_EmisColor:TShaderVarColor;

_AmbiColor:TShaderVarColor;

_DiffColor:TShaderVarColor;

_SpecColor:TShaderVarColor;

_SpecShiny:TShaderVarFloat;

_Lights:TShaderVarLights;

_Texture:TShaderVarTexture;

_ShaderV:TShaderSourceV;

_ShaderP:TShaderSourceP;

///// Method procedure DoInitialize; override;

procedureDoApply(constContext_:TContext3D);override;

public

constructorCreate;override;

destructorDestroy;override;

///// Property property EmisColor: TShaderVarColor read _EmisColor;

propertyAmbiColor:TShaderVarColor read_AmbiColor;

propertyDiffColor:TShaderVarColor read_DiffColor;

propertySpecColor:TShaderVarColor read_SpecColor;

propertySpecShiny:TShaderVarFloat read_SpecShiny;

propertyTexture:TShaderVarTexture read_Texture;

end;

TMyMaterialSource is the component that puts the textures on top of the 3D components. MyMaterial library is available for Delphi 10 Berlin with FireMonkey and it looks to be open source. Demos are available for you to test its features. For those developers who want to study the source code, it is available on Github. With MyMaterial libray you can easily create your own custom textures and effects and apply them to the components you create.