diff --git a/materials/image.filamat b/materials/image.filamat new file mode 100644 index 00000000..b2287483 Binary files /dev/null and b/materials/image.filamat differ diff --git a/materials/image.filamat.metal b/materials/image.filamat.metal new file mode 100644 index 00000000..36f41af2 Binary files /dev/null and b/materials/image.filamat.metal differ diff --git a/materials/image.mat b/materials/image.mat new file mode 100644 index 00000000..5acabd9f --- /dev/null +++ b/materials/image.mat @@ -0,0 +1,54 @@ +material { + name : Image, + parameters : [ + { + type : sampler2d, + name : image + }, + { + type : mat4, + name : transform, + precision : high + }, + { + type : float3, + name : backgroundColor + }, + { + type : int, + name : showImage + } + ], + variables : [ + imageUV + ], + vertexDomain : device, + depthWrite : false, + shadingModel : unlit, + variantFilter : [ skinning, shadowReceiver, vsm ], + culling: none +} + +vertex { + void materialVertex(inout MaterialVertexInputs material) { + material.imageUV.st = getPosition().st * 0.5 + 0.5; + } +} + +fragment { + void material(inout MaterialInputs material) { + prepareMaterial(material); + + vec4 bg = vec4(materialParams.backgroundColor, 1.0); + highp vec2 uv = (materialParams.transform * vec4(saturate(variable_imageUV.st), 1.0, 1.0)).st; + if (materialParams.showImage == 0 || uv.s > 1.0 || uv.s < 0.0 || uv.t < 0.0 || uv.t > 1.0) { + material.baseColor = bg; + } else { + uv.t = 1.0 - uv.t; + vec4 color = max(texture(materialParams_image, uv.st), 0.0); + color.rgb *= color.a; + // Manual, pre-multiplied srcOver with opaque destination optimization + material.baseColor.rgb = color.rgb + bg.rgb * (1.0 - color.a); + } + } +} diff --git a/pubspec.yaml b/pubspec.yaml index f8ecb1f1..861dbe9f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,6 +26,6 @@ flutter: pluginClass: PolyvoxFilamentPlugin package: app.polyvox.filament ios: - pluginClass: PolyvoxFilamentPlugin + pluginClass: SwiftPolyvoxFilamentPlugin windows: - pluginClass: PolyvoxFilamentPlugin \ No newline at end of file + pluginClass: PolyvoxFilamentPlugin