{"id":18011,"date":"2017-08-05T06:00:05","date_gmt":"2017-08-04T21:00:05","guid":{"rendered":"https:\/\/jirak.net\/wp\/creating-materials-and-lights-in-the-visual-layer\/"},"modified":"2017-08-05T06:35:55","modified_gmt":"2017-08-04T21:35:55","slug":"creating-materials-and-lights-in-the-visual-layer","status":"publish","type":"post","link":"https:\/\/jirak.net\/wp\/creating-materials-and-lights-in-the-visual-layer\/","title":{"rendered":"Creating Materials and Lights in the Visual Layer"},"content":{"rendered":"<p>Creating Materials and Lights in the Visual Layer<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jirak.net\/wp\/wp-content\/uploads\/2017\/08\/e528c6ace39235d9633de5a7104945ba.gif\" width=\"900\" height=\"544\"><\/p>\n<p>In today\u2019s post, we\u2019re going wrap up this series by combining everything we\u2019ve learned so far and take you through the steps in creating a custom material. We also have an amazing new tool to show you that empowers anyone to design a custom material. To see how you can use these custom materials in your XAML app, be sure to check out the last two posts in this series; <strong>XAML and Visual Layer Interop<\/strong>, <a href=\"https:\/\/blogs.windows.com\/buildingapps\/2017\/07\/18\/working-brushes-content-xaml-visual-layer-interop-part-one\/#v62aboAcokXz4kpI.97\"><strong>part one<\/strong><\/a> and <a href=\"https:\/\/blogs.windows.com\/buildingapps\/2017\/07\/19\/new-lights-propertyset-interop-xaml-visual-layer-interop-part-two\/#zfvt45qeSLv3YDqM.97\"><strong>part two<\/strong><\/a>.<\/p>\n<p><a href=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/e528c6ace39235d9633de5a7104945ba.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-49084\" src=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/e528c6ace39235d9633de5a7104945ba.gif\" alt=\"\" width=\"900\" height=\"544\" \/><\/a><\/p>\n<p>The <a href=\"http:\/\/fluent.microsoft.com\/\">Fluent Design Language<\/a> is an evolving concept, rather than a one-time design language release like MDL and MDL2. It was designed to expand and grow as Microsoft\u00a0and the community of creators (developers and designers), adds to what it could be. We\u2019ll show you that anything is possible, as designers, developers and the Windows community have common ground to share their creations and create amazing materials.<\/p>\n<p>Let\u2019s get started by first showing you how a material is created by chaining effects, then we&#8217;ll explore using the new <a href=\"https:\/\/github.com\/Microsoft\/WindowsUIDevLabs\/tree\/master\/Demos\/MaterialCreator\"><strong>Material Creator<\/strong><\/a> to easily and quickly create materials.<\/p>\n<h2>Creating Material with the Visual Layer<\/h2>\n<h3>CompositionEffectBrush<\/h3>\n<p>Whether we&#8217;ll be using the effect in a XamlCompositionBrushBase or painting a SpriteVisual, the construction of the effect graph is the core of the approach. In order to create the material we want, we&#8217;ll need the following components:<\/p>\n<ul>\n<li><strong>Effect sources<\/strong>: A SurfaceBrush for the NormalMap and a BackdropBrush for access to the pixels underneath the material<\/li>\n<li><strong>The effect graph<\/strong>: A composite of different effects to control the Material&#8217;s reflectance properties and filter effects (such as blur and tint) to customize for UI usage<\/li>\n<li><strong>Lighting<\/strong>: The Visual is in a scene that has a CompositionLight applied<\/li>\n<\/ul>\n<p>Let&#8217;s start with the first source, a SurfaceBrush. This will be provided by using LoadedImageSurface to load a NormalMap.<\/p>\n<h3>NormalMap and LoadedImageSurface<\/h3>\n<p><a href=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/39d3fac116981508b4c2ea87a26eab74.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-49087\" src=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/39d3fac116981508b4c2ea87a26eab74.png\" alt=\"\" width=\"750\" height=\"563\" \/><\/a><\/p>\n<p>If you\u2019ve had any experience with 3D computer graphics, maybe as a game developer, you may already know what a normal map is and the image above looks familiar. If you\u2019ve never worked with one before, Normal mapping is a technique that determines the reflectance of light at every pixel (read more about Normal mapping <a href=\"https:\/\/en.wikipedia.org\/wiki\/Normal_mapping\">here<\/a>). The Visual Layer in Windows 10 gives you a choice of industry standard reflectance models; Blinn-Phong and Physically Based Blinn-Phong.\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/graphics-concepts\/mathematics-of-lighting\">Go here<\/a> to read more about the math behind how this is done.<\/p>\n<p>For today\u2019s demo, we used a 2D picture of a textured surface and transformed it into a Normal map image using an image editor. There are many image editing tools that let you do this. You can use any one you prefer to create your image.<\/p>\n<p>To get started, we can load the image using the new <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.xaml.media.loadedimagesurface\">LoadedImageSurface<\/a> API. Let\u2019s add a private field for the LoadedImageSurface, load the image and create a CompositionSurfaceBrush with it.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\">\r\n\r\n\/\/ Load NormalMap onto an ICompositionSurface using LoadedImageSurface\r\nLoadedImageSurface _surface = LoadedImageSurface.StartLoadFromUri(new Uri(&amp;quot;ms-appx:\/\/\/Images\/NormalMap.jpg&amp;quot;), new Size(512,384));\r\n\r\n\/\/ Load Surface onto SurfaceBrush\r\nCompositionSurfaceBrush normalMap = compositor.CreateSurfaceBrush(_surface);\r\nnormalMap.Stretch = CompositionStretch.Uniform;\r\n\r\n<\/pre>\n<p>Now we\u2019re ready to move on to creating and chaining effects.<\/p>\n<h2>Chaining Effects to create the effect graph<\/h2>\n<p>For our material, we are going to create a chain of effects that leverages the Win2D\u2019s <a href=\"http:\/\/microsoft.github.io\/Win2D\/html\/T_Microsoft_Graphics_Canvas_Effects_ArithmeticCompositeEffect.htm\">ArithmeticCompositeEffect<\/a> (note: be sure to add the <a href=\"https:\/\/www.nuget.org\/packages\/Win2D.uwp\">Win2D NuGet package<\/a> to your project). All effects can be used as input sources for other effects, thus enabling you to allow a chain of effects to one or more inputs.<\/p>\n<p>ArithmeticCompositeEffect lets you assign two sources for the composite, giving each one a weight toward the final effect. For example, Source1 at 0.75 (75%) and Source2 at 0.25 (25%). You can also use an additional ArithmeticCompositeEffect as one of the sources to add more effects in the composite chain.<\/p>\n<p>Let\u2019s step back for a minute and think about how we want create the composite:<\/p>\n<ul>\n<li>Parent <strong>ArithmeticCompositeEffect<\/strong> to be used for Brush\n<ul>\n<li>Source 1: Child <strong>ArithmeticCompositeEffect<\/strong>\n<ul>\n<li>Source 1: <strong>ColorSourceEffect<\/strong> for tint coloring<\/li>\n<li>Source 2: <strong>GaussianBlurEffect<\/strong> using the BackDropBrush for its source<\/li>\n<\/ul>\n<\/li>\n<li>Source2: <strong>SceneLightingEffect<\/strong> using the Normal map for its source<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>For source 1, we\u2019ll combine a <a href=\"http:\/\/microsoft.github.io\/Win2D\/html\/T_Microsoft_Graphics_Canvas_Effects_ColorSourceEffect.htm\">ColorSourceEffect<\/a> and <a href=\"http:\/\/microsoft.github.io\/Win2D\/html\/T_Microsoft_Graphics_Canvas_Effects_GaussianBlurEffect.htm\">GaussianBlurEffect<\/a> (from Win2D) with a nested ArithmeticSourceEffect. For Source 2, we&#8217;ll use a <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/Windows.UI.Composition.Effects.SceneLightingEffect\">SceneLightingEffect<\/a> (from Windows.UI.Composition.Effects). This will manipulate the reflective properties of the effect&#8217;s source when a CompositionLight, from a XamlLight for example, is applied.<\/p>\n<p>Note that the SceneLightingEffect is used to modify the default lighting applied to the contents of a <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/Windows.UI.Composition.SpriteVisual\">SpriteVisual<\/a> targeted by a <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.composition.compositionlight\">CompositionLight<\/a>. In today\u2019s example, we are going to create SurfaceBrush using a NormalMap (loaded by <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.xaml.media.loadedimagesurface\">LoadedImageSurface<\/a>) to define dents and bumps that the light reflects off of.<\/p>\n<p>Furthermore, in order to use the SceneLightingEffect, the content being modified must be defined as one of the sources into a multi-input effect graph, with the other input being the SceneLightingEffect. For example, above, the content whose lighting properties are being modified is defined by Source1 of the parent ArithmeticCompositeEffect.<\/p>\n<p>Here&#8217;s what the code looks like for the effect graph:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\">\r\n\r\n\/\/ Define Effect graph\r\nconst float glassLightAmount = 0.5f;\r\nconst float glassBlurAmount = 0.95f;\r\nColor tintColor = Color.FromArgb(255, 128, 128, 128);\r\n \r\nvar graphicsEffect = new ArithmeticCompositeEffect\r\n{\r\n    Name = &amp;quot;LightComposite&amp;quot;,\r\n    Source1Amount = 1,\r\n    Source2Amount = glassLightAmount,\r\n    MultiplyAmount = 0,\r\n    \/\/ Nested Composite to combine the Blur and Color tint effects\r\n    Source1 = new ArithmeticCompositeEffect\r\n    {\r\n        Name = &amp;quot;BlurComposite&amp;quot;,\r\n        Source1Amount = 1 - glassBlurAmount,\r\n        Source2Amount = glassBlurAmount,\r\n        MultiplyAmount = 0,\r\n        Source1 = new ColorSourceEffect\r\n        {\r\n            Name = &amp;quot;Tint&amp;quot;,\r\n            Color = tintColor,\r\n        },\r\n        Source2 = new GaussianBlurEffect\r\n         {\r\n            BlurAmount = 20,\r\n             Source = new CompositionEffectSourceParameter(&amp;quot;Backdrop&amp;quot;),\r\n            Optimization = EffectOptimization.Balanced,\r\n            BorderMode = EffectBorderMode.Hard,\r\n        },\r\n    },\r\n    \/\/ The SceneLighting effect, which will use a NormalMap\r\n    Source2 = new SceneLightingEffect\r\n    {\r\n        AmbientAmount = 0.15f,\r\n        DiffuseAmount = 1,\r\n        SpecularAmount = 0.1f,\r\n        NormalMapSource = new CompositionEffectSourceParameter(&amp;quot;NormalMap&amp;quot;)\r\n    }\r\n};\r\n\r\n<\/pre>\n<p>Notice the SceneLightingEffect&#8217;s <strong>NormalMapSource <\/strong>property and the GaussianBlurEffect&#8217;s <strong>Source;\u00a0<\/strong>these are parameter provided sources. We will set what these parameters are as we pull everything together to create the <strong>CompositionEffectBrush<\/strong>:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\">\r\n\r\n\/\/ Create EffectFactory and the CompositionEffectBrush\r\nCompositionEffectFactory effectFactory = Window.Current.Compositor.CreateEffectFactory(graphicsEffect);\r\nCompositionEffectBrush effectBrush = effectFactory.CreateBrush();\r\n \r\n\/\/ Create BackdropBrush, this is used by the GaussianBlurEffect\r\nCompositionBackdropBrush backdrop = Window.Current.Compositor.CreateBackdropBrush();\r\n \r\n\/\/ Set Sources to Effect\r\neffectBrush.SetSourceParameter(&amp;quot;NormalMap&amp;quot;, _normalMap);\r\neffectBrush.SetSourceParameter(&amp;quot;Backdrop&amp;quot;, backdrop);\r\n\r\n<\/pre>\n<p>With the CompositionEffect completed, we can now use it to paint a <strong>SpriteVisual<\/strong>, like this:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\">\r\n\r\nSpriteVisual spriteVisual = Window.Current.Compositor.CreateSpriteVisual();\r\nspriteVisual.Brush = effectBrush;\r\n\r\n<\/pre>\n<p>If you&#8217;re primarily a XAML dev, you can use this effect in a XamlCompositionBrushBase. Let&#8217;s take a look.<\/p>\n<h2>Using the CompositionEffectBrush in a XamlCompositionBrushBase<\/h2>\n<p>As I mentioned earlier, we can also create this effect graph in <strong>XamlCompositionBrushBase <\/strong>and set the XamlCompositionBrushBase&#8217;s <strong>CompsositionBrush <\/strong>property. If you haven&#8217;t read the post in this series on how to create a XamlCompositionBrushBase, <a href=\"https:\/\/blogs.windows.com\/buildingapps\/2017\/07\/18\/working-brushes-content-xaml-visual-layer-interop-part-one\/\">go here to catch up<\/a>.<\/p>\n<p>As with the other XamlCompositionBrushBase implementations, we build the effect graph in the <strong>OnConnected <\/strong>method and make sure that the user\u2019s device supports effects. This can be done using the <strong>AreEffectsSupported<\/strong> method of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.composition.compositioncapabilities\">CompositionCapabilities API<\/a>.<\/p>\n<p>Here&#8217;s the full class:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\">\r\n\r\npublic sealed class MaterialBrush : XamlCompositionBrushBase\r\n{\r\n    private LoadedImageSurface _surface;\r\n\r\n    protected override void OnConnected()\r\n    {\r\n        if (DesignMode.DesignModeEnabled) return;\r\n\r\n        Compositor compositor = Window.Current.Compositor;\r\n\r\n        \/\/ CompositionCapabilities: Are Effects supported?\r\n        bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported();\r\n        FallbackColor = Color.FromArgb(100, 60, 60, 60);\r\n\r\n        if (usingFallback)\r\n        {\r\n            \/\/ If Effects are not supported, use Fallback Solid Color\r\n            CompositionBrush = compositor.CreateColorBrush(FallbackColor);\r\n            return;\r\n        }\r\n            \r\n        \/\/ Load NormalMap onto an ICompositionSurface using LoadedImageSurface\r\n        _surface = LoadedImageSurface.StartLoadFromUri(new Uri(&amp;quot;ms-appx:\/\/\/Images\/NormalMap.jpg&amp;quot;), new Size(512, 384));\r\n\r\n        \/\/ Load Surface onto SurfaceBrush\r\n        CompositionSurfaceBrush normalMap = compositor.CreateSurfaceBrush(_surface);\r\n        normalMap.Stretch = CompositionStretch.Uniform;\r\n\r\n        \/\/ Define Effect graph\r\n        const float glassLightAmount = 0.5f;\r\n        const float glassBlurAmount = 0.95f;\r\n        Color tintColor = Color.FromArgb(255, 128, 128, 128);\r\n\r\n        var graphicsEffect = new ArithmeticCompositeEffect()\r\n        {\r\n            Name = &amp;quot;LightComposite&amp;quot;,\r\n            Source1Amount = 1,\r\n            Source2Amount = glassLightAmount,\r\n            MultiplyAmount = 0,\r\n            Source1 = new ArithmeticCompositeEffect()\r\n            {\r\n                Name = &amp;quot;BlurComposite&amp;quot;,\r\n                Source1Amount = 1 - glassBlurAmount,\r\n                Source2Amount = glassBlurAmount,\r\n                MultiplyAmount = 0,\r\n                Source1 = new ColorSourceEffect()\r\n                {\r\n                    Name = &amp;quot;Tint&amp;quot;,\r\n                    Color = tintColor,\r\n                },\r\n                Source2 = new GaussianBlurEffect()\r\n                {\r\n                    BlurAmount = 20,\r\n                    Source = new CompositionEffectSourceParameter(&amp;quot;Backdrop&amp;quot;),\r\n                    Optimization = EffectOptimization.Balanced,\r\n                    BorderMode = EffectBorderMode.Hard,\r\n                },\r\n            },\r\n            Source2 = new SceneLightingEffect()\r\n            {\r\n                AmbientAmount = 0.15f,\r\n                DiffuseAmount = 1,\r\n                SpecularAmount = 0.1f,\r\n                NormalMapSource = new CompositionEffectSourceParameter(&amp;quot;NormalMap&amp;quot;)\r\n            },\r\n        };\r\n\r\n        \/\/ Create EffectFactory and EffectBrush\r\n        CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect);\r\n        CompositionEffectBrush effectBrush = effectFactory.CreateBrush();\r\n\r\n        \/\/ Create BackdropBrush\r\n        CompositionBackdropBrush backdrop = compositor.CreateBackdropBrush();\r\n\r\n        \/\/ Set Sources to Effect\r\n        effectBrush.SetSourceParameter(&amp;quot;NormalMap&amp;quot;, normalMap);\r\n        effectBrush.SetSourceParameter(&amp;quot;Backdrop&amp;quot;, backdrop);\r\n\r\n        \/\/ Set EffectBrush as the brush that XamlCompBrushBase paints onto Xaml UIElement\r\n        CompositionBrush = effectBrush;\r\n    }\r\n\r\n    protected override void OnDisconnected()\r\n    {\r\n        \/\/ Clean up resources\r\n        _surface?.Dispose();\r\n        _surface = null;\r\n\r\n        CompositionBrush?.Dispose();\r\n        CompositionBrush = null;\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>To see this in action, let\u2019s create a Grid to put in the middle of our page\u2019s root Grid and set an instance of our MaterialBrush to that Grid\u2019s Background brush:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\">\r\n\r\n&amp;lt;Grid Background=&amp;quot;Gray&amp;quot;&amp;gt;\r\n    &amp;lt;Grid Width=&amp;quot;580&amp;quot;\r\n          Height=&amp;quot;387&amp;quot;\r\n          HorizontalAlignment=&amp;quot;Center&amp;quot;\r\n          VerticalAlignment=&amp;quot;Center&amp;quot;&amp;gt;\r\n\r\n        &amp;lt;!-- Our new MaterialBrush --&amp;gt;\r\n        &amp;lt;Grid.Background&amp;gt;\r\n            &amp;lt;brushes:MaterialBrush \/&amp;gt;\r\n        &amp;lt;\/Grid.Background&amp;gt;\r\n    &amp;lt;\/Grid&amp;gt;\r\n&amp;lt;\/Grid&amp;gt;\r\n\r\n<\/pre>\n<p>Here\u2019s what it would look like if you ran the app now:<\/p>\n<p><a href=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/28563c99b36c15109115209eb802f63d.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-49090\" src=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/28563c99b36c15109115209eb802f63d.png\" alt=\"\" width=\"812\" height=\"542\" \/><\/a><\/p>\n<p>This is because you\u2019re missing the second part of the approach, the lighting!<\/p>\n<h2>Illuminating the Material with Lights<\/h2>\n<p>In the <a href=\"https:\/\/blogs.windows.com\/buildingapps\/2017\/07\/19\/new-lights-propertyset-interop-xaml-visual-layer-interop-part-two\/\">last post<\/a>, we created two lights (an <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.composition.ambientlight\">AmbientLight<\/a> \u201cAmbLight\u201d and the <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.composition.spotlight\">SpotLight<\/a> \u201cHoverLight\u201d). We\u2019ll use them today to apply lighting to the UIElement that is using our custom material.<\/p>\n<p>Since our MaterialBrush uses the new SceneLightingEffect with a Normal map, any lights applied will enhance the material per the SceneLightingEffect\u2019s configuration. Note that this isn&#8217;t necessary, but can greatly enhance your material. For example, if you&#8217;re using an Acrylic material in your app, adding Reveal will enhance the Acrylic.<\/p>\n<p>Let\u2019s now add the two XamlLights to the Grid:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\">\r\n\r\n&amp;lt;Grid Background=&amp;quot;Gray&amp;quot;&amp;gt;\r\n    &amp;lt;Grid Width=&amp;quot;580&amp;quot;\r\n          Height=&amp;quot;387&amp;quot;\r\n          HorizontalAlignment=&amp;quot;Center&amp;quot;\r\n          VerticalAlignment=&amp;quot;Center&amp;quot;&amp;gt;\r\n        &amp;lt;Grid.Background&amp;gt;\r\n            &amp;lt;brushes:MaterialBrush \/&amp;gt;\r\n        &amp;lt;\/Grid.Background&amp;gt;\r\n\r\n        &amp;lt;!-- Added lights --&amp;gt;\r\n        &amp;lt;Grid.Lights&amp;gt;\r\n            &amp;lt;lights:HoverLight \/&amp;gt;\r\n            &amp;lt;lights:AmbLight \/&amp;gt;\r\n        &amp;lt;\/Grid.Lights&amp;gt;\r\n    &amp;lt;\/Grid&amp;gt;\r\n&amp;lt;\/Grid&amp;gt;\r\n\r\n<\/pre>\n<p>Now, this is what you\u2019ll see at runtime:<\/p>\n<p><a href=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/8fee210963b95d08be7aebce0e085850.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-49093\" src=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/8fee210963b95d08be7aebce0e085850.gif\" alt=\"\" width=\"900\" height=\"519\" \/><\/a><\/p>\n<p>What if it were easier to create and experiment with new materials? What if there were a tool that anyone can use? Let\u2019s take a look at what\u2019s coming to the <a href=\"https:\/\/github.com\/Microsoft\/WindowsUIDevLabs\">WindowsUIDevLabs GitHub repo<\/a>, the Material Creator tool.<\/p>\n<h2>Using the new Material Creator<\/h2>\n<p>Introducing availability of the new <strong>Material Creator <\/strong>tool!<\/p>\n<p><a href=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/5191ee38b110eced0032c50989ef8c61.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-49096\" src=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/5191ee38b110eced0032c50989ef8c61.gif\" alt=\"\" width=\"600\" height=\"380\" \/><\/a><\/p>\n<p>Creating custom materials may sometimes requires a bit of experimentation and tweaking to get the effect\u2019s property configuration just right. This would take time if you had to constantly tweak and redeploy your app. What if there were a way that you could change effect properties and material layers in real time?<\/p>\n<p>The Material Creator can be found on the WindowsUIDevLabs GitHub repo <a href=\"https:\/\/github.com\/Microsoft\/WindowsUIDevLabs\/tree\/master\/Demos\/MaterialCreator\">in the demos folder here<\/a>. (<strong>Note<\/strong>: you need to be running Windows 10, build 16225 or higher to use the Material Creator).<\/p>\n<h3>Generating the SceneLightingEffect code<\/h3>\n<p><a href=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/e007fc366f39bdd1b14225a69acb17b5.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-49099\" src=\"https:\/\/winblogs.azureedge.net\/win\/2017\/08\/e007fc366f39bdd1b14225a69acb17b5.gif\" alt=\"\" width=\"600\" height=\"380\" \/><\/a><\/p>\n<p>One of the great features of the tool is being able to see the effect graph after you\u2019re done creating the material. Click the ellipsis next to the save button and select \u201cview effect graph\u201d to see the C# code for the <strong>SceneLightingEffect.<\/strong> You can then copy and use this code directly in your custom material class.<\/p>\n<p>If you go back up to the part of this article where we created the ArithemticCompositeEffect that contains a SceneLightingEffect, that\u2019s where you can use this code!<\/p>\n<h3>Saving and Loading Materials<\/h3>\n<p>The Material Editor can also save and load materials! If you want to save your current progress on a material, or share a completed material with another developer, just click the Save button and it will create a json file containing all the layers and effect configurations. To load an existing material or edit a material shared with you, just click <strong>Load<\/strong> and select the json file.<\/p>\n<p><strong>The key takeaway is that you don\u2019t need to be a developer to create materials<\/strong>. A designer can create a material and then share the saved json file with a developer for implementation in a XamlCompositionBrushBase. Even Windows enthusiasts, like the Windows Insiders, can start building out a universe of materials to drive the evolution of Fluent Design.<\/p>\n<h2>Blog Series Wrap up: The future of Fluent Design materials<\/h2>\n<p>Acrylic and Reveal are stunning examples of how using Material with Lights can alter the Windows experience, but they\u2019re just the beginning of what is possible. The vision for the Fluent Design Language going forward is that developers and designers can easily build custom materials, innovate and share as well.<\/p>\n<p>The message we want you to walk away with is that you can build new Materials, for a couple primary reasons:<\/p>\n<ul>\n<li>Because you&#8217;re a Creator<\/li>\n<li>Because it embodies your brand<\/li>\n<\/ul>\n<p>We look forward to seeing what kinds of materials you create for your Windows apps! If you\u2019ve already built your own material, feel free to share in the comments below.<\/p>\n<h2>Resources<\/h2>\n<ul>\n<li>Demo Code:\n<ul>\n<li><a href=\"https:\/\/github.com\/Microsoft\/WindowsUIDevLabs\/tree\/master\/Demos\/MaterialCreator\">Material Creator<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Microsoft\/WindowsUIDevLabs\/tree\/master\/SampleGallery\/Samples\/SDK%2015063\/BrushInterop\">Brush Interop<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Microsoft\/WindowsUIDevLabs\/tree\/master\/SampleGallery\/Samples\/SDK%2015063\/LightInterop\">Light Interop<\/a><\/li>\n<\/ul>\n<\/li>\n<li>Blog posts: XAML and Visual Layer Interop series\n<ul>\n<li><a href=\"https:\/\/blogs.windows.com\/buildingapps\/2017\/07\/18\/working-brushes-content-xaml-visual-layer-interop-part-one\/#v62aboAcokXz4kpI.97\">Part One<\/a><\/li>\n<li><a href=\"https:\/\/blogs.windows.com\/buildingapps\/2017\/07\/19\/new-lights-propertyset-interop-xaml-visual-layer-interop-part-two\/#dCVXOaqFsyZh6r2Z.97\">Part Two<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/graphics-concepts\/lighting-overview\">Lighting Overview<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.composition.compositioncapabilities\">CompositionCapabilities API<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/graphics-concepts\/light-types\">Light Types<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/graphics-concepts\/mathematics-of-lighting\">Mathematics of lighting<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.composition.effects.scenelightingeffect\">SceneLightingEffect<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Microsoft\/WindowsUIDevLabs\">WindowsUIDevLabs GitHub repo<\/a> (contains Samples Gallery app)<\/li>\n<li><a href=\"http:\/\/microsoft.github.io\/Win2D\/html\/N_Microsoft_Graphics_Canvas_Effects.htm\">Win2D Effects API Documentation<\/a><\/li>\n<\/ul>\n<p>Source: <a href=\"http:\/\/blogs.windows.com\/buildingapps\/2017\/08\/04\/creating-materials-lights-visual-layer\/\" target=\"_blank\">Creating Materials and Lights in the Visual Layer<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Creating Materials and Lights in the Visual Layer In today\u2019s post, we\u2019re going wrap up this series by combining everything we\u2019ve learned so far and take you through the steps in creating a custom material. We also have an amazing new tool to show you that empowers anyone to design a custom material. To see how you can use these custom materials in your XAML app, be sure to check out the last two posts in this series; XAML and Visual Layer Interop, part one and part two. The Fluent Design Language is an evolving concept, rather than a one-time design language release like MDL and MDL2. It was designed to expand and grow as Microsoft\u00a0and the community of creators (developers and designers), adds to what it could be. We\u2019ll show you that anything is possible, as designers, developers and <a class=\"mh-excerpt-more\" href=\"https:\/\/jirak.net\/wp\/creating-materials-and-lights-in-the-visual-layer\/\" title=\"Creating Materials and Lights in the Visual Layer\">[ more&#8230; ]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":18012,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[201],"class_list":["post-18011","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","tag-windows"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/18011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/comments?post=18011"}],"version-history":[{"count":1,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/18011\/revisions"}],"predecessor-version":[{"id":18013,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/18011\/revisions\/18013"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/media\/18012"}],"wp:attachment":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/media?parent=18011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/categories?post=18011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/tags?post=18011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}