Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
0.8.4:materials [2022/06/15 19:39] – [Texture-Atlas] admin | 0.8.4:materials [2022/06/15 20:17] – [Materials] admin | ||
---|---|---|---|
Line 23: | Line 23: | ||
* [[shared-material|TGorillaSharedMaterialSource]] | * [[shared-material|TGorillaSharedMaterialSource]] | ||
* [[runtime-material|TGorillaRuntimeMaterialSource]] | * [[runtime-material|TGorillaRuntimeMaterialSource]] | ||
+ | |||
+ | |||
===== Default-Material ===== | ===== Default-Material ===== | ||
+ | |||
The **TGorillaDefaultMaterialSource** (TGorillaDefaultMaterial) is the approach to centralize basic shader operations like vertex transformation, | The **TGorillaDefaultMaterialSource** (TGorillaDefaultMaterial) is the approach to centralize basic shader operations like vertex transformation, | ||
Line 32: | Line 35: | ||
Read more about the default material: [[default-material|DefaultMaterial]] | Read more about the default material: [[default-material|DefaultMaterial]] | ||
- | |||
- | |||
- | |||
- | |||
- | ===== Layered-Material ===== | ||
- | |||
- | The **TGorillaLayeredMaterialSource** is a container of multiple sub materials. | ||
- | It works like a stack, where one material is rendered above another. | ||
- | The following schema visualizes this idea: | ||
- | |||
- | {{ :: | ||
- | |||
- | **It is important that those sub materials do not clear the context, otherwise it will produce unexpected behaviour!** | ||
- | |||
- | If the materials collection is empty, Gorilla3D will render the complete buffer with black color. | ||
- | |||
- | To setup sub-materials, | ||
- | |||
- | <file pascal> | ||
- | var LLayMat : TGorillaLayeredMaterialSource; | ||
- | LSubMat1 : TGorillaNormalMapMaterialSource; | ||
- | LSubMat2 : TGorillaPhongMaterialSource; | ||
- | LSubMatEntry : TGorillaLayeredMaterialItem; | ||
- | [...] | ||
- | |||
- | // create the layered material source | ||
- | LLayMat := TGorillaLayeredMaterialSource.Create(FGorilla); | ||
- | LLayMat.Parent := FGorilla; | ||
- | |||
- | // create sub-material #1 | ||
- | LSubMat1 := TGorillaNormalMapMaterialSource.Create(FGorilla); | ||
- | LSubMat1.Parent := FGorilla; | ||
- | |||
- | // add sub-material #1 | ||
- | LSubMatEntry := LLayMat.Materials.Add(); | ||
- | LSubMatEntry.Material := LSubMat1; | ||
- | |||
- | // create sub-material #2 | ||
- | LSubMat2 := TGorillaPhongMaterialSource.Create(FGorilla); | ||
- | LSubMat2.Parent := FGorilla; | ||
- | |||
- | // add sub-material #2 | ||
- | LSubMatEntry := LLayMat.Materials.Add(); | ||
- | LSubMatEntry.Material := LSubMat2; | ||
- | </ | ||
- | ===== Shared-Material / Atlas-Material ===== | ||
- | |||
- | Having games like Minecraft in mind, texturing seems very simple when using a single atlas texture. Working with FMX materials makes this a struggle. | ||
- | Because each time you create a material source and use the atlas texture, FMX will load the texture into the GPU. So if you're having an atlas with 8x8 parts, this will create 64 texture with the size of the original one. This is just horrible memory management. | ||
- | |||
- | That's not what we want. Gorilla3D offers a solution to you: SharedMaterialSource' | ||
- | |||
- | {{: | ||
- | |||
- | In the following example we have added 3 TGorillaAtlasMaterialSource instances from component palette before. We've set the " | ||
- | We have 3 cubes, to which we will apply the atlas materials. | ||
- | The shared source material will be created at runtime. (There is no design-time component yet!) | ||
- | |||
- | <file pascal> | ||
- | procedure TForm1.FormCreate(Sender: | ||
- | var LTexFile : String; | ||
- | begin | ||
- | {$IFDEF MSWINDOWS} | ||
- | LTexFile := ' | ||
- | {$ENDIF} | ||
- | {$IFDEF ANDROID} | ||
- | LTexFile := IncludeTrailingPathDelimiter(TPath.GetHomePath()) + ' | ||
- | {$ENDIF} | ||
- | |||
- | /// lets create a source material | ||
- | /// It's used as texture container, which GorillaAtlasMaterialSourceX uses. | ||
- | /// This will only register the atlas texture once, instead of multiple times | ||
- | /// CAUTION: currently this is only available at runtime | ||
- | SharedAtlasSource := TGorillaSharedAtlasMaterialSource.Create(GorillaViewport1); | ||
- | SharedAtlasSource.Parent := GorillaViewport1; | ||
- | SharedAtlasSource.AtlasRowCount := 8; | ||
- | SharedAtlasSource.AtlasColCount := 8; | ||
- | SharedAtlasSource.FrameWidth := 32; | ||
- | SharedAtlasSource.FrameHeight := 32; | ||
- | SharedAtlasSource.Texture.LoadFromFile(LTexFile); | ||
- | |||
- | // now link atlas materials to the source | ||
- | GorillaAtlasMaterialSource1.SharedSource := SharedAtlasSource; | ||
- | GorillaAtlasMaterialSource2.SharedSource := SharedAtlasSource; | ||
- | GorillaAtlasMaterialSource3.SharedSource := SharedAtlasSource; | ||
- | |||
- | // now link to cubes | ||
- | GorillaCube1.MaterialSource := GorillaAtlasMaterialSource1; | ||
- | GorillaCube2.MaterialSource := GorillaAtlasMaterialSource2; | ||
- | GorillaCube3.MaterialSource := GorillaAtlasMaterialSource3; | ||
- | end; | ||
- | </ | ||
- | |||
- | |||
- | ===== Grass-Material ===== | ||
- | |||
- | ===== Water-Material ===== | ||
- | |||
- | Read more about water material on documentation about [[water|Water]] | ||
- | ===== Runtime Material ===== | ||
- | |||
- | Read more about usage of Runtime Materials at [[runtime-material|RuntimeMaterial]] | ||
Next step:: [[primitives|Primitives]] | Next step:: [[primitives|Primitives]] | ||