我想在xamarin.iOS中使用自定义着色器文件创建GPUImageTwoInputFilter。我正在使用GPUImage组件。
var stillCamera = new GPUImageStillCamera ();
var filter1 = new GPUImageTwoInputFilter();
stillCamera.AddTarget(filter1);
var internalSourcePicture1 = new GPUImagePicture(UIImage.FromFile("image.png").CGImage,true);
internalSourcePicture1.AddTarget(filter1);
internalSourcePicture1.ProcessImage();
但我们不知道如何在GPUImageTwoInputFilter中传递着色器文件
答案 0 :(得分:0)
将自定义片段着色器(id="sec[0-9]+"
)添加到.fsh
应用包中,作为Xamarin.iOS
的构建类型。
然后通过BundleResource
注意:请勿包含文件扩展名,否则您将在app output / log中收到“无法加载顶点着色器”
GPUImageFilter.FromFragmentShaderFile
或将片段着色器嵌入为字符串:
var filter = GPUImageFilter.FromFragmentShaderFile ("StackOverflowShader");
并通过 fragShaderString = @"
varying highp vec2 textureCoordinate;
varying highp vec2 textureCoordinate2;
uniform sampler2D inputImageTexture;
uniform sampler2D inputImageTexture2;
void main()
{
lowp vec4 base = texture2D(inputImageTexture, textureCoordinate);
lowp vec4 overlayer = texture2D(inputImageTexture2, textureCoordinate2);
gl_FragColor = vec4(min(overlayer.rgb * base.a, base.rgb * overlayer.a) + overlayer.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlayer.a), 1.0);
}
";
FromFragmentShaderString