Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
0.8.4:materials [2022/06/15 19:37] admin0.8.4:materials [2022/07/22 12:55] (current) – [Materials] admin
Line 3: Line 3:
  
 Since version 0.8+, the most materials are inherited from the node based **TGorillaDefaultMaterialSource** for comfortable shader code reusage. Since version 0.8+, the most materials are inherited from the node based **TGorillaDefaultMaterialSource** for comfortable shader code reusage.
 +===== Default-Material =====
 +
 +The **TGorillaDefaultMaterialSource** (TGorillaDefaultMaterial) is the approach to centralize basic shader operations like vertex transformation, multiple light computation, shadow casting, normal mapping and much more.
 +
 +The simple reason for that is, not to reinvent the basic functionality each time for new materials. Many materials need multiple lights, shadows and so one. Those operations also getting very complex in combination and its hard to keep them still efficient.
 +
 +Because of that, the default material uses a node based memory structure to build shader source code. On rendering the source code will automatically be compiled and registered in GPU.
 +
 +Read more about the default material: [[default-material|TGorillaDefaultMaterialSource]]
 +
 +===== Materials =====
  
   * [[lambert-material|TGorillaLambertMaterialSource]]   * [[lambert-material|TGorillaLambertMaterialSource]]
Line 19: Line 30:
   * [[grass-material|TGorillaGrassMaterialSource]]   * [[grass-material|TGorillaGrassMaterialSource]]
   * [[grid-material|TGorillaGridMaterialSource]]   * [[grid-material|TGorillaGridMaterialSource]]
 +  * [[particle-material|TGorillaParticleMaterialSource]]
   * [[layered-material|TGorillaLayeredMaterialSource]]   * [[layered-material|TGorillaLayeredMaterialSource]]
   * [[shared-material|TGorillaSharedMaterialSource]]   * [[shared-material|TGorillaSharedMaterialSource]]
   * [[runtime-material|TGorillaRuntimeMaterialSource]]   * [[runtime-material|TGorillaRuntimeMaterialSource]]
-===== Default-Material ===== 
-The **TGorillaDefaultMaterialSource** (TGorillaDefaultMaterial) is the approach to centralize basic shader operations like vertex transformation, multiple light computation, shadow casting, normal mapping and much more. 
- 
-The simple reason for that is, not to reinvent the basic functionality each time for new materials. Many materials need multiple lights, shadows and so one. Those operations also getting very complex in combination and its hard to keep them still efficient. 
- 
-Because of that, the default material uses a node based memory structure to build shader source code. On rendering the source code will automatically be compiled and registered in GPU. 
- 
-Read more about the default material: [[default-material|DefaultMaterial]] 
- 
- 
- 
-===== Particle-Material ===== 
- 
-The TGorillaParticleMaterialSource (TGorillaParticleMaterial) is inherited from TGorillaDefaultMaterialSource, supports multiple light sources and enables texture atlas and point-sprite handling if activated: **GORILLA_GLSL_DEFINE_USE_TEXTURE_ATLAS**, **GORILLA_GLSL_DEFINE_USE_POINTSPRITE** 
- 
-Depending on the material configuration it enables different rendering techniques: 
- 
-^ Mode ^ UseTexture ^ IsTextureAtlas ^ Technique ^ 
-| OnlyColor | false | false | Renders each particle with the provided color information and without texturing | 
-| Texturing | true | false | Renders each particle with the provided texture but without atlas mapping | 
-| Atlas-Texturing | true | true | Renders each particle with the provided texture-atlas | 
- 
-==== Texture-Atlas ==== 
- 
-A texture atlas (also called a sprite sheet or an image sprite) is an image containing a collection of smaller images, usually packed together to reduce the atlas size.[1] Atlases can consist of uniformly-sized sub-images, or they can consist of images of varying dimensions.[1] A sub-image is drawn using custom texture coordinates to pick it out of the atlas. In an application where many small textures are used frequently, it is often more efficient to store the textures in a texture atlas which is treated as a single unit by the graphics hardware. Storing textures in an atlas reduces the overhead of a context switch by increasing memory locality. Careful alignment may be needed to avoid bleeding between sub textures when used with mipmapping and texture compression. 
- 
-[https://en.wikipedia.org/wiki/Texture_atlas] 
- 
-To configure a supplied texture atlas in the material use the provided properties: 
- 
-^ Property ^ Notice ^ 
-| AtlasRowCount | Defines the number of rows the texture atlas has. | 
-| AtlasColCount | Defines the number of columns the texture atlas has. | 
-| FrameWidth | Defines the width of each frame in pixels. The width has to be a potency of 2. For example: 16, 32, 64, 128, ... | 
-| FrameHeight | Defines the height of each frame in pixels. The height has to be a potency of 2. For example: 16, 32, 64, 128, ... | 
-===== 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: 
- 
-{{ ::doc-g3d-layeredmat.png?nolink&600 |}} 
- 
-**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, simply add those to the material collection: 
- 
-<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; 
-</file> 
-===== 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's! You set up a shared atlas material source once, where you load up your atlas texture. Than you only create referenced materials linked to that source. The reference material shader will use the global texture for rendering, instead of registering its own. 
- 
-{{:atlas.png?nolink&400|Sample atlas texture}} 
- 
-In the following example we have added 3 TGorillaAtlasMaterialSource instances from component palette before. We've set the "TextureIndex" property to an index of the sub-texture in our atlas (from left to right, up to down, beginning with 0). 
-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: TObject); 
-var LTexFile : String; 
-begin 
-{$IFDEF MSWINDOWS} 
-  LTexFile := 'atlas.png'; 
-{$ENDIF} 
-{$IFDEF ANDROID} 
-  LTexFile := IncludeTrailingPathDelimiter(TPath.GetHomePath()) + 'atlas.png'; 
-{$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; 
-</file> 
- 
- 
-===== 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]]