I’ve been exploring and testing the capabilities of a 3D Texture engine, focusing particularly on the ability to add sub-images—a feature not yet supported by the engine. The primary advantage of using 3D Textures is the simplification it brings to dynamically assigning different textures to meshes. Without this support, the process tends to be more cumbersome and less efficient.
In scenarios lacking 3D Texture support, assigning different textures to various meshes typically requires creating multiple meshes, each with its own material. This approach is resource-intensive and complex, especially when managing a large number of meshes, due to the need for creating and managing many individual elements.
However, with a 3D Texture engine, this process becomes much more streamlined. Instead of multiple meshes and materials, a single mesh with the 3D Texture can be used. The 3D Texture acts as a container for multiple texture layers, allowing different textures to be assigned to different parts of the mesh, or to different instances of the same mesh, without the need for multiple mesh-material combinations.
This method is currently being explored and tested. The use of 3D Texture has the potential to provide a more efficient and flexible way to handle multiple textures in 3D environments.
The first step in this process was to declare new ThinEngine methods, utilizing the TypeScript extension mechanism and syntax already in use in Babylon.
You can see the progression of this exploration in the following BabylonJS Playgrounds:
- The classic, straightforward version.
- Then, by introducing instances, i achieve the use ONE draw call but with the cost of allowing ONE Material only.
- To further this, we create a new material, allowing each instance to hold an index corresponding to the layer (sub-image) index. This involves:
- Adding instance buffers to store the indices.
- Building a simplified shader, both vertex and fragment.
The next step is to introduce a new TextureType to extend the framework. For this, I created a new type of BaseTexture:
- Starting with the interfaces.
- Followed by the implementation.
Finally, I modified the shader to account for the texture depth.
This marks a solid beginning to augmenting the engine with this feature. The next phase may involve exploring support for WebGPU to complete the work. Any assistance or input would be greatly appreciated!
G.