public DrawInfo(Matrix3?matrix = null, Matrix3?matrixInverse = null, ColourInfo?colour = null, BlendingInfo?blending = null) { Matrix = matrix ?? Matrix3.Identity; MatrixInverse = matrixInverse ?? Matrix3.Identity; Colour = colour ?? ColourInfo.SingleColour(Color4.White); Blending = blending ?? new BlendingInfo(); }
public void TestColourInfoSingle() { //Given var data = "rgba(2, 181, 254, 255)"; var value = ColourInfo.SingleColour(new Color4(2, 181, 254, 255)); //Then testAssert(data, value); }
public void TestColourInfoSingle() { //Given var code = @"osu.Framework.Graphics.Colour.ColourInfo.SingleColour(new osuTK.Graphics.Color4(0.1F, 0.2F, 0.3F, 0.4F))"; var value = ColourInfo.SingleColour(new Color4(0.1F, 0.2F, 0.3F, 0.4F)); //Then testAssert(code, value); }
private void drawEdgeEffect() { if (maskingInfo == null || edgeEffect.Type == EdgeEffectType.None || edgeEffect.Radius <= 0.0f || edgeEffect.Colour.Linear.A <= 0) { return; } RectangleF effectRect = maskingInfo.Value.MaskingRect.Inflate(edgeEffect.Radius).Offset(edgeEffect.Offset); if (!screenSpaceMaskingQuad.HasValue) { screenSpaceMaskingQuad = Quad.FromRectangle(effectRect) * DrawInfo.Matrix; } MaskingInfo edgeEffectMaskingInfo = maskingInfo.Value; edgeEffectMaskingInfo.MaskingRect = effectRect; edgeEffectMaskingInfo.ScreenSpaceAABB = screenSpaceMaskingQuad.Value.AABB; edgeEffectMaskingInfo.CornerRadius = maskingInfo.Value.CornerRadius + edgeEffect.Radius + edgeEffect.Roundness; edgeEffectMaskingInfo.BorderThickness = 0; // HACK HACK HACK. We abuse blend range to give us the linear alpha gradient of // the edge effect along its radius using the same rounded-corners shader. edgeEffectMaskingInfo.BlendRange = edgeEffect.Radius; edgeEffectMaskingInfo.AlphaExponent = 2; edgeEffectMaskingInfo.EdgeOffset = edgeEffect.Offset; edgeEffectMaskingInfo.Hollow = edgeEffect.Hollow; edgeEffectMaskingInfo.HollowCornerRadius = maskingInfo.Value.CornerRadius + edgeEffect.Radius; GLWrapper.PushMaskingInfo(edgeEffectMaskingInfo); GLWrapper.SetBlend(new BlendingInfo(edgeEffect.Type == EdgeEffectType.Glow ? BlendingMode.Additive : BlendingMode.Mixture)); Shader.Bind(); ColourInfo colour = ColourInfo.SingleColour(edgeEffect.Colour); colour.TopLeft.MultiplyAlpha(DrawColourInfo.Colour.TopLeft.Linear.A); colour.BottomLeft.MultiplyAlpha(DrawColourInfo.Colour.BottomLeft.Linear.A); colour.TopRight.MultiplyAlpha(DrawColourInfo.Colour.TopRight.Linear.A); colour.BottomRight.MultiplyAlpha(DrawColourInfo.Colour.BottomRight.Linear.A); DrawQuad( Texture.WhitePixel, screenSpaceMaskingQuad.Value, colour, null, null, null, // HACK HACK HACK. We re-use the unused vertex blend range to store the original // masking blend range when rendering edge effects. This is needed for smooth inner edges // with a hollow edge effect. new Vector2(maskingInfo.Value.BlendRange)); Shader.Unbind(); GLWrapper.PopMaskingInfo(); }
/// <summary> /// Retrieves the applicable colour for a beat index. /// </summary> /// <param name="placementIndex">The 0-based beat index from the point of placement.</param> /// <returns>The applicable colour.</returns> protected ColourInfo GetColourForIndexFromPlacement(int placementIndex) { var timingPoint = beatmap.ControlPointInfo.TimingPointAt(StartTime); var beatLength = timingPoint.BeatLength / beatDivisor.Value; var beatIndex = (int)Math.Round((StartTime - timingPoint.Time) / beatLength); var colour = BindableBeatDivisor.GetColourFor(BindableBeatDivisor.GetDivisorForBeatIndex(beatIndex + placementIndex + 1, beatDivisor.Value), Colours); int repeatIndex = placementIndex / beatDivisor.Value; return(ColourInfo.SingleColour(colour).MultiplyAlpha(0.5f / (repeatIndex + 1))); }
public static ColourInfo Deserialize(string data) { data = data.Trim(); string[] parts; if (data.StartsWith("gradient(", StringComparison.OrdinalIgnoreCase) && data.EndsWith(')')) { parts = data.Substring(9, data.Length - 10).SplitByComma(); var direction = parts[0]; if (direction.Equals("vertical", StringComparison.OrdinalIgnoreCase)) { return(ColourInfo.GradientVertical( c1: Color4Converter.Deserialize(parts[1]), c2: Color4Converter.Deserialize(parts[2]))); } if (direction.Equals("horizontal", StringComparison.OrdinalIgnoreCase)) { return(ColourInfo.GradientHorizontal( c1: Color4Converter.Deserialize(parts[1]), c2: Color4Converter.Deserialize(parts[2]))); } } parts = data.SplitByComma(); if (parts.Length == 1) { return(ColourInfo.SingleColour(Color4Converter.Deserialize(parts[0]))); } if (parts.Length == 4) { return new ColourInfo { TopLeft = Color4Converter.Deserialize(parts[0]), TopRight = Color4Converter.Deserialize(parts[1]), BottomRight = Color4Converter.Deserialize(parts[2]), BottomLeft = Color4Converter.Deserialize(parts[3]) } } ; throw new FormatException($"Unrecognized {nameof(ColourInfo)} '{data}'."); } }
private void drawEdgeEffect() { if (MaskingInfo == null || EdgeEffect.Type == EdgeEffectType.None || EdgeEffect.Radius <= 0.0f || EdgeEffect.Colour.Linear.A <= 0.0f) { return; } RectangleF effectRect = MaskingInfo.Value.MaskingRect.Inflate(EdgeEffect.Radius).Offset(EdgeEffect.Offset); if (!ScreenSpaceMaskingQuad.HasValue) { ScreenSpaceMaskingQuad = Quad.FromRectangle(effectRect) * DrawInfo.Matrix; } MaskingInfo edgeEffectMaskingInfo = MaskingInfo.Value; edgeEffectMaskingInfo.MaskingRect = effectRect; edgeEffectMaskingInfo.ScreenSpaceAABB = ScreenSpaceMaskingQuad.Value.AABB; edgeEffectMaskingInfo.CornerRadius += EdgeEffect.Radius + EdgeEffect.Roundness; edgeEffectMaskingInfo.BorderThickness = 0; edgeEffectMaskingInfo.BlendRange = EdgeEffect.Radius; edgeEffectMaskingInfo.AlphaExponent = 2; edgeEffectMaskingInfo.Hollow = EdgeEffect.Hollow; GLWrapper.PushMaskingInfo(edgeEffectMaskingInfo); GLWrapper.SetBlend(new BlendingInfo(EdgeEffect.Type == EdgeEffectType.Glow ? BlendingMode.Additive : BlendingMode.Mixture)); Shader.Bind(); ColourInfo colour = ColourInfo.SingleColour(EdgeEffect.Colour); colour.TopLeft.MultiplyAlpha(DrawInfo.Colour.TopLeft.Linear.A); colour.BottomLeft.MultiplyAlpha(DrawInfo.Colour.BottomLeft.Linear.A); colour.TopRight.MultiplyAlpha(DrawInfo.Colour.TopRight.Linear.A); colour.BottomRight.MultiplyAlpha(DrawInfo.Colour.BottomRight.Linear.A); Texture.WhitePixel.DrawQuad(ScreenSpaceMaskingQuad.Value, colour); Shader.Unbind(); GLWrapper.PopMaskingInfo(); }
private void drawBlurredFrameBuffer(int kernelRadius, float sigma, float blurRotation) { FrameBuffer source = currentFrameBuffer; FrameBuffer target = advanceFrameBuffer(); GLWrapper.SetBlend(new BlendingInfo { Source = BlendingFactorSrc.One, Destination = BlendingFactorDest.Zero, SourceAlpha = BlendingFactorSrc.One, DestinationAlpha = BlendingFactorDest.Zero, }); using (bindFrameBuffer(target, source.Size)) { BlurShader.GetUniform <int>(@"g_Radius").Value = kernelRadius; BlurShader.GetUniform <float>(@"g_Sigma").Value = sigma; BlurShader.GetUniform <Vector2>(@"g_TexSize").Value = source.Size; float radians = -MathHelper.DegreesToRadians(blurRotation); BlurShader.GetUniform <Vector2>(@"g_BlurDirection").Value = new Vector2((float)Math.Cos(radians), (float)Math.Sin(radians)); BlurShader.Bind(); drawFrameBufferToBackBuffer(source, new RectangleF(0, 0, source.Texture.Width, source.Texture.Height), ColourInfo.SingleColour(Color4.White)); BlurShader.Unbind(); } }
private void drawBlurredFrameBuffer(int kernelRadius, float sigma, float blurRotation) { FrameBuffer current = SharedData.CurrentEffectBuffer; FrameBuffer target = SharedData.GetNextEffectBuffer(); GLWrapper.SetBlend(BlendingParameters.None); using (BindFrameBuffer(target)) { blurShader.GetUniform <int>(@"g_Radius").UpdateValue(ref kernelRadius); blurShader.GetUniform <float>(@"g_Sigma").UpdateValue(ref sigma); Vector2 size = current.Size; blurShader.GetUniform <Vector2>(@"g_TexSize").UpdateValue(ref size); float radians = -MathUtils.DegreesToRadians(blurRotation); Vector2 blur = new Vector2(MathF.Cos(radians), MathF.Sin(radians)); blurShader.GetUniform <Vector2>(@"g_BlurDirection").UpdateValue(ref blur); blurShader.Bind(); DrawFrameBuffer(current, new RectangleF(0, 0, current.Texture.Width, current.Texture.Height), ColourInfo.SingleColour(Color4.White)); blurShader.Unbind(); } }
public DrawColourInfo(ColourInfo?colour = null, BlendingParameters?blending = null) { Colour = colour ?? ColourInfo.SingleColour(Color4.White); Blending = blending ?? BlendingParameters.Inherit; }
public DrawColourInfo(ColourInfo?colour = null, BlendingInfo?blending = null) { Colour = colour ?? ColourInfo.SingleColour(Color4.White); Blending = blending ?? new BlendingInfo(); }
private void drawBlurredFrameBuffer(int kernelRadius, float sigma, float blurRotation) { FrameBuffer source = currentFrameBuffer; FrameBuffer target = advanceFrameBuffer(); GLWrapper.SetBlend(new BlendingInfo(BlendingMode.None)); using (bindFrameBuffer(target, source.Size)) { blurShader.GetUniform <int>(@"g_Radius").UpdateValue(ref kernelRadius); blurShader.GetUniform <float>(@"g_Sigma").UpdateValue(ref sigma); Vector2 size = source.Size; blurShader.GetUniform <Vector2>(@"g_TexSize").UpdateValue(ref size); float radians = -MathHelper.DegreesToRadians(blurRotation); Vector2 blur = new Vector2((float)Math.Cos(radians), (float)Math.Sin(radians)); blurShader.GetUniform <Vector2>(@"g_BlurDirection").UpdateValue(ref blur); blurShader.Bind(); drawFrameBufferToBackBuffer(source, new RectangleF(0, 0, source.Texture.Width, source.Texture.Height), ColourInfo.SingleColour(Color4.White)); blurShader.Unbind(); } }