How to implement conical / conical / circular gradient in WPF

I would like to recreate a conical / circular gradient in WPF. I looked at the inheritance of System.Windows.Media.GradientBrush - which can be inherited from - but uses a lot of internal plumbing to complete the task (inherited from System.Windows.Media.Brush)

Any ideas on how to achieve this will be appreciated (preferably without resorting to bitmaps)

Greetings.

Dan

This question was asked some time ago in July ( Circular Gradient and WPF ), but I did not want to resurrect the old question.

+3
source share
1 answer

. Shazzam, DirectX SDK. , , .

/// <class>AngleGradient</class>
/// <description>Renders an angle gradient.</description>
//-----------------------------------------------------------------------------------------
// Shader constant register mappings (scalars - float, double, Point, Color, Point3D, etc.)
//-----------------------------------------------------------------------------------------
/// <summary>The centre of the gradient.</summary>
/// <minValue>0</minValue>
/// <maxValue>1</maxValue>
/// <defaultValue>0.5,0.5</defaultValue>
float2 Centre : register(C0);

/// <summary>The start angle.</summary>
/// <minValue>0</minValue>
/// <maxValue>1</maxValue>
/// <defaultValue>0</defaultValue>
float Angle : register(C1);

//--------------------------------------------------------------------------------------
// Sampler Inputs (Brushes, including ImplicitInput)
//--------------------------------------------------------------------------------------

sampler1D implicitInputSampler : register(S0);
static const float PI = 3.14159265f;
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 main(float2 uv : TEXCOORD) : COLOR
{
    float angle = atan2(uv.y-Centre.y, uv.x-Centre.x)+PI;
    angle = (angle/(2*PI)) + Angle; 
    return tex1D(implicitInputSampler,min(angle > 1 ? angle-1 : angle,0.99));
+5

Source: https://habr.com/ru/post/1731008/


All Articles