I have the following code written in C#/WinUI 3:
<Grid Name="_MainGrid">
<Rectangle Name="_Test" Width="500" Height="500" Fill="Green"/>
</Grid>
Visual visualTest = ElementCompositionPreview.GetElementVisual(_Test);
Compositor compositorTest = visualTest.Compositor;
ContainerVisual containerVisualTest = (ContainerVisual)ElementCompositionPreview.GetElementVisual(_Test);
PointSpecularEffect light = new PointSpecularEffect()
{
Name = "Light",
Source = new CompositionEffectSourceParameter("source"),
LightColor = Colors.Red,
SpecularAmount = 2,
SpecularExponent = 2
};
CompositionEffectFactory lightFactory = compositorTest.CreateEffectFactory(light);
CompositionEffectBrush lightBrush = lightFactory.CreateBrush();
SpriteVisual lightVisual = compositorTest.CreateSpriteVisual();
lightVisual.Size = new Vector2(500, 500);
lightVisual.Brush = lightBrush;
containerVisualTest.Children.InsertAtTop(lightVisual);
But this code crashes on the following line with error System.ArgumentException: "Parameter specified incorrectly.":
CompositionEffectFactory lightFactory = compositorTest.CreateEffectFactory(light);
Moreover, other effects work correctly, such as GaussianBlurEffect or SaturationEffect. The problem arises with lighting effects. I had a similar problem when I tried to apply a GaussianBlurEffect to the FillBrush property of the CompositionSpriteShape class, which ended up being used in the ShapeVisual class. After researching the topic, I found out that this effect is only applicable to SpriteVisual. So, maybe there are some limitations with the PointSpecularEffect class too? Although, on the other hand, I'm just trying to create a factory with this effect, what restrictions can there be? Why is a factory with a light effect not created? Can you please tell me how to make this effect work?