Beispiel #1
0
        public static void SetupPaintColorMask(this SCNGeometry geometry, string name)
        {
            // if we've already set it up, don't do it again
            if (geometry.ValueForKey(new NSString(PaintMaskColorKey)) == null)
            {
                if (PaintColorMaskTextures.TryGetValue(name, out string paintMask))
                {
                    // all textures are absolute paths from the app folder
                    var texturePath = $"art.scnassets/textures/{paintMask}.ktx";

                    if (name.Contains("catapult"))
                    {
                        //os_log(.debug, "visited %s for texture", name)
                    }

                    var surfaceScript = @"
                    #pragma arguments

                    texture2d<float> paintMaskTexture;
                    //sampler paintMaskSampler;
                    float4 paintMaskColor;

                    #pragma body

                    // 0 is use diffuse texture.rgb, 1 is use paintMaskColor.rgb
                    float paintMaskSelector = paintMaskTexture.sample(
                        sampler(filter::linear), // paintMaskSampler,
                        _surface.diffuseTexcoord.xy).r;

                    _surface.diffuse.rgb = mix(_surface.diffuse.rgb, paintMaskColor.rgb, paintMaskSelector);
                    ";

                    geometry.ShaderModifiers = new SCNShaderModifiers()
                    {
                        EntryPointSurface = surfaceScript
                    };

                    // mask pro
                    var prop = SCNMaterialProperty.Create(new NSString(texturePath));
                    prop.MinificationFilter  = SCNFilterMode.Linear;
                    prop.MagnificationFilter = SCNFilterMode.Nearest;
                    prop.MipFilter           = SCNFilterMode.Nearest;
                    prop.MaxAnisotropy       = 1;

                    // set the uniforms, these will be overridden in the runtime
                    geometry.SetTexture("paintMaskTexture", prop);
                    geometry.SetFloat4(PaintMaskColorKey, SCNVector4.One);
                }
            }
        }
Beispiel #2
0
 public static bool HasUniform(this SCNGeometry geometry, string uniform)
 {
     return(geometry.ValueForKey(new NSString(uniform)) != null);
 }