I have a simple material with a texture that has transparency baked in (PNG file), this is the code that I did to load it :
var triMat = SimpleMaterial(color: .orange, isMetallic: false)
triMat.color = SimpleMaterial.BaseColor( tint: .white.withAlphaComponent(0.9), texture: MaterialParameters.Texture(try! .load(named: "whity_4x4")))
self.components[ModelComponent.self] = try! ModelComponent(mesh: .generate(from: [meshDesc]), materials: [triMat])
It's pretty straight foward and it works fine, the geometry is a plane and it shows the texture correctly with transparency.
But when I try to create a surface shader (I want to animate the uv so it looks like it scrolls) the transparency become a black color. This is the part where I sample the texture for color and opacity
auto color = params.textures().base_color().sample(textureSampler, float2(u1,v1));
auto opacity = params.textures().opacity().sample(textureSampler, float2(u1,v1)).r;
and I set the surface color and opacity
params.surface().set_base_color(color.rgb);
params.surface().set_opacity(opacity);
upon debugging, it seems the opacity value is wrong (always 1) that's why it doesn't show as transparent. Did I do something wrong with sampling the texture opacity? I looked at the Metal API documentation that's how you supposed to do it?
Thanks for any help