How to implement a conical/cone/circular gradient in WPF

馋奶兔 提交于 2019-12-04 11:32:25

You could create a custom Effect. I would recommend downloading Shazzam you will also need the DirectX SDK. Give the element a horizontal gradient then apply the effect to transform it into a cone gradient.

/// <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));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!