Last active
January 3, 2016 01:59
-
-
Save JohanLarsson/8392670 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sampler2D inputSampler : register(S0); | |
| /// <summary>The center of the gradient. </summary> | |
| /// <minValue>0,0</minValue> | |
| /// <maxValue>1,1</maxValue> | |
| /// <defaultValue>.5,.5</defaultValue> | |
| float2 CenterPoint : register(C0); | |
| /// <summary>The primary color of the gradient. </summary> | |
| /// <defaultValue>Blue</defaultValue> | |
| float4 StartColor : register(C1); | |
| /// <summary>The secondary color of the gradient. </summary> | |
| /// <defaultValue>Red</defaultValue> | |
| float4 EndColor : register(C2); | |
| /// <summary>The starting angle of the gradient, counterclockwise from X-axis</summary> | |
| /// <minValue>0</minValue> | |
| /// <maxValue>360</maxValue> | |
| /// <defaultValue>0</defaultValue> | |
| float StartAngle : register(C3); | |
| /// <summary>The arc length angle of the gradient, counterclockwise from X-axis</summary> | |
| /// <minValue>-360</minValue> | |
| /// <maxValue>360</maxValue> | |
| /// <defaultValue>360</defaultValue> | |
| float ArcLength : register(C4); | |
| static float4 transparent = float4(0, 0, 0, 0); // WPF uses pre-multiplied alpha everywhere internally for a number of performance reasons. | |
| static float Pi = 3.141592f; | |
| float AngleTo(float2 v1, float2 v2, bool clockWise) | |
| { | |
| int sign = clockWise ? -1 : 1; | |
| float a1 = atan2(v1.y, v1.x) * sign; | |
| float a2 = atan2(v2.y, v2.x) * sign; | |
| float a = a2 - a1; | |
| if (a < 0) | |
| { | |
| return 2 * Pi + a; ; | |
| } | |
| return a; | |
| } | |
| float2x2 RotationMatrix(float rotation) | |
| { | |
| float c = cos(rotation); | |
| float s = sin(rotation); | |
| return float2x2(c, -s, s, c); | |
| } | |
| float4 main(float2 uv : TEXCOORD) : COLOR | |
| { | |
| float4 src = tex2D(inputSampler, uv); | |
| if (src.a < 0.01 || abs(ArcLength) < 0.01) | |
| { | |
| return transparent; | |
| } | |
| float2 v = uv - CenterPoint; | |
| float2 vs = mul(float2(1, 0), RotationMatrix(radians(StartAngle))); | |
| float a = degrees(AngleTo( vs,v, ArcLength < 0)); | |
| float f = abs(a) < 0.1 ? 0 : a / abs(ArcLength); | |
| if (f < 0 || f > 1) | |
| { | |
| return transparent; | |
| } | |
| float3 rgb = lerp(StartColor.rgb, EndColor.rgb, f); | |
| return float4(rgb, src.a); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Ellipse Stroke="Red" StrokeThickness="30"> | |
| <Ellipse.Effect> | |
| <effects:AngularGradientEffect PrimaryColor="Red" SecondaryColor="Transparent"/> | |
| </Ellipse.Effect> | |
| </Ellipse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sampler2D inputSampler : register(s0); | |
| /// <summary>The second image.</summary> | |
| /// <defaultValue>c:\examplefolder\examplefile.jpg</defaultValue> | |
| sampler2D Image2 : register(s1); | |
| float4 main(float2 uv : TEXCOORD) : COLOR | |
| { | |
| float4 p1 = tex2D(inputSampler, uv); | |
| float4 p2 = tex2D(Image2, uv); | |
| float d = distance(p1.rgb, p2.rgb); | |
| return float4(1,1,1,1) - abs(p2 - p1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <class>FadeToBlackEffect</class> | |
| /// <description>Fade to black by animating the strength</description> | |
| sampler2D inputSampler : register(S0); | |
| //----------------------------------------------------------------------------------------- | |
| // Shader constant register mappings (scalars - float, double, Point, Color, Point3D, etc.) | |
| //----------------------------------------------------------------------------------------- | |
| /// <summary>The color used to tint the input.</summary> | |
| /// <defaultValue>Yellow</defaultValue> | |
| float Strength : register(C0); | |
| float4 main(float2 uv : TEXCOORD) : COLOR | |
| { | |
| float4 srcColor = tex2D(inputSampler, uv); | |
| float3 color =(1-Strength)*srcColor.rgb; | |
| return float4(color, srcColor.a); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <class>FadeToMonochrome</class> | |
| /// <description>An effect that turns the input into shades of a single color.</description> | |
| sampler2D inputSampler : register(S0); | |
| //----------------------------------------------------------------------------------------- | |
| // Shader constant register mappings (scalars - float, double, Point, Color, Point3D, etc.) | |
| //----------------------------------------------------------------------------------------- | |
| /// <summary>The strength of the effect.</summary> | |
| /// <minValue>0</minValue> | |
| /// <maxValue>1</maxValue> | |
| /// <defaultValue>0</defaultValue> | |
| float Strength : register(C0); | |
| float4 main(float2 uv : TEXCOORD) : COLOR | |
| { | |
| float4 srcColor = tex2D(inputSampler, uv); | |
| float3 rgb = srcColor.rgb; | |
| float3 luminance =(1-Strength)*rgb+Strength* dot(rgb, float3(0.30, 0.59, 0.11)); | |
| return float4(luminance, srcColor.a); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment