I'm working on an Android project using the Filament rendering engine to display 3D models in GLB format. I have successfully loaded and displayed models with existing materials using Filament. However, I would like to apply a custom shader to an existing material to achieve specific visual effects like an airflow animation.
My understanding is that Filament provides a powerful rendering framework, but I'm not sure about the steps required to apply a custom shader to an existing material. Specifically, I want to modify certain properties of the material, such as base color, emissive factor, or normal mapping, to create dynamic effects like an airflow animation.
Could someone guide me through the process of how to achieve this? What are the key steps to create and apply a custom shader to an existing material in Filament? Are there any specific examples or code snippets that could help me understand the workflow better?
I appreciate any insights or advice from anyone who has experience with Filament and custom shader integration on existing materials. Thank you in advance!
val matPackage = MaterialBuilder()
// By default, materials are generated only for DESKTOP. Since we're an Android
// app, we set the platform to MOBILE.
.platform(MaterialBuilder.Platform.MOBILE)
// Set the name of the Material for debugging purposes.
.name("Clear coat")
// Defaults to LIT. We could change the shading model here if we desired.
.shading(MaterialBuilder.Shading.LIT)
// Add a parameter to the material that can be set via the setParameter method once
// we have a material instance.
.uniformParameter(MaterialBuilder.UniformType.FLOAT3, "baseColor")
// Fragment block- see the material readme (docs/Materials.md.html) for the full
// specification.
.material("void material(inout MaterialInputs material) {\n" +
" prepareMaterial(material);\n" +
" material.baseColor.rgb = materialParams.baseColor;\n" +
" material.roughness = 0.65;\n" +
" material.metallic = 1.0;\n" +
" material.clearCoat = 1.0;\n" +
"}\n")
// Turn off shader code optimization so this sample is compatible with the "lite"
// variant of the filamat library.
.optimization(MaterialBuilder.Optimization.NONE)
// When compiling more than one material variant, it is more efficient to pass an Engine
// instance to reuse the Engine's job system
.build(engine)