'WPF 3d LinearGardientBrush / TextureCoordinates

I have the following LinearGradientBrush

var brush = new LinearGradientBrush();
brush.GradientStops.Add(new GradientStop { Color = Colors.Transparent, Offset = 0 });
brush.GradientStops.Add(new GradientStop { Color = Colors.Blue, Offset = 0.1 });
brush.GradientStops.Add(new GradientStop { Color = Colors.Cyan, Offset = 0.2 });
brush.GradientStops.Add(new GradientStop { Color = Colors.GreenYellow, Offset = 0.4 });
brush.GradientStops.Add(new GradientStop { Color = Colors.Yellow, Offset = 0.6 });
brush.GradientStops.Add(new GradientStop { Color = Colors.Red, Offset = 0.8 });
brush.GradientStops.Add(new GradientStop { Color = Colors.Magenta, Offset = 1 });

and I use the following code to set the texture coordinates

textureCoordinates.Add(new Point(z_value / 100d, 0));

The result is not bad. But as you can see in the following image the highest value is always magenta even if the z value I used for the texture coordinate is quite low:

enter image description here

The right example should be colored blue.

How can I set the color correctly? My z values are all between 0 and 100.



Solution 1:[1]

This took me hours too before I found the solution here.

The LinearGradientBrush is using the bounding box as reference by default. To fix this, the Property MappingMode of your brush object must be set to BrushMappingMode.Absolute. So in your case try this :)

brush.MappingMode=BrushMappingMode.Absolute

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LevArris