protected override bool BeginRenderOpacityBrushOverride(Texture tex, RenderContext renderContext) { if (_gradientBrushTexture == null || _refresh) { _gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops); if (_gradientBrushTexture == null) { return(false); } } Matrix finalTransform = renderContext.Transform.Clone(); if (_refresh) { _refresh = false; _effect = ContentManager.Instance.GetEffect(EFFECT_LINEAROPACITYGRADIENT); g_startpoint = new float[] { StartPoint.X, StartPoint.Y }; g_endpoint = new float[] { EndPoint.X, EndPoint.Y }; if (MappingMode == BrushMappingMode.Absolute) { g_startpoint[0] /= _vertsBounds.Width; g_startpoint[1] /= _vertsBounds.Height; g_endpoint[0] /= _vertsBounds.Width; g_endpoint[1] /= _vertsBounds.Height; } g_framesize = new float[] { _vertsBounds.Width, _vertsBounds.Height }; if (RelativeTransform != null) { Matrix m = RelativeTransform.GetTransform(); m.Transform(ref g_startpoint[0], ref g_startpoint[1]); m.Transform(ref g_endpoint[0], ref g_endpoint[1]); } } SurfaceDescription desc = tex.GetLevelDescription(0); float[] g_LowerVertsBounds = new float[] { _vertsBounds.Left / desc.Width, _vertsBounds.Top / desc.Height }; float[] g_UpperVertsBounds = new float[] { _vertsBounds.Right / desc.Width, _vertsBounds.Bottom / desc.Height }; _effect.Parameters[PARAM_TRANSFORM] = GetCachedFinalBrushTransform(); _effect.Parameters[PARAM_OPACITY] = (float)(Opacity * renderContext.Opacity); _effect.Parameters[PARAM_STARTPOINT] = g_startpoint; _effect.Parameters[PARAM_ENDPOINT] = g_endpoint; _effect.Parameters[PARAM_FRAMESIZE] = g_framesize; _effect.Parameters[PARAM_ALPHATEX] = _gradientBrushTexture.Texture; _effect.Parameters[PARAM_UPPERVERTSBOUNDS] = g_UpperVertsBounds; _effect.Parameters[PARAM_LOWERVERTSBOUNDS] = g_LowerVertsBounds; GraphicsDevice.Device.SetSamplerState(0, SamplerState.AddressU, SpreadAddressMode); _effect.StartRender(tex, finalTransform); return(true); }
protected override bool BeginRenderBrushOverride(PrimitiveBuffer primitiveContext, RenderContext renderContext) { if (_gradientBrushTexture == null || _refresh) { _gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops); if (_gradientBrushTexture == null) { return(false); } } Matrix finalTransform = renderContext.Transform.Clone(); if (_refresh) { _refresh = false; _effect = ContentManager.Instance.GetEffect(EFFECT_LINEARGRADIENT); g_startpoint = new float[] { StartPoint.X, StartPoint.Y }; g_endpoint = new float[] { EndPoint.X, EndPoint.Y }; if (MappingMode == BrushMappingMode.Absolute) { g_startpoint[0] /= _vertsBounds.Width; g_startpoint[1] /= _vertsBounds.Height; g_endpoint[0] /= _vertsBounds.Width; g_endpoint[1] /= _vertsBounds.Height; } g_framesize = new float[] { _vertsBounds.Width, _vertsBounds.Height }; if (RelativeTransform != null) { Matrix m = RelativeTransform.GetTransform(); m.Transform(ref g_startpoint[0], ref g_startpoint[1]); m.Transform(ref g_endpoint[0], ref g_endpoint[1]); } } _effect.Parameters[PARAM_FRAMESIZE] = g_framesize; _effect.Parameters[PARAM_TRANSFORM] = GetCachedFinalBrushTransform(); _effect.Parameters[PARAM_OPACITY] = (float)(Opacity * renderContext.Opacity); _effect.Parameters[PARAM_STARTPOINT] = g_startpoint; _effect.Parameters[PARAM_ENDPOINT] = g_endpoint; GraphicsDevice.Device.SetSamplerState(0, SamplerState.AddressU, SpreadAddressMode); _effect.StartRender(_gradientBrushTexture.Texture, finalTransform); return(true); }
protected void RefreshEffectParameters() { float w = _vertsBounds.Width; float h = _vertsBounds.Height; Vector2 maxuv = TextureMaxUV; Vector4 brushRect = ViewPort; // Determine image rect in viewport space if (Stretch != Stretch.Fill) { // Convert brush dimensions to viewport space Vector2 brushSize = BrushDimensions; brushSize.X /= w; brushSize.Y /= h; switch (Stretch) { case Stretch.None: // Center (or alignment), original size break; case Stretch.Uniform: // Center (or alignment), keep aspect ratio and show borders { float ratio = Math.Min(ViewPort.Z / brushSize.X, ViewPort.W / brushSize.Y); brushSize.X *= ratio; brushSize.Y *= ratio; } break; case Stretch.UniformToFill: // Center (or alignment), keep aspect ratio, zoom in to avoid borders { float ratio = Math.Max(ViewPort.Z / brushSize.X, ViewPort.W / brushSize.Y); brushSize.X *= ratio; brushSize.Y *= ratio; } break; } // Align brush in viewport brushRect = AlignBrushInViewport(brushSize); } // Compensate for any texture borders brushRect.Z /= maxuv.X; brushRect.W /= maxuv.Y; float repeatx = 1.0f / brushRect.Z; float repeaty = 1.0f / brushRect.W; // Transform ViewPort into Texture-space and store for later use in tiling _textureViewport = new Vector4 { X = ViewPort.X * repeatx - brushRect.X * repeatx, Y = ViewPort.Y * repeaty - brushRect.Y * repeaty, Z = ViewPort.Z * repeatx, W = ViewPort.W * repeaty }; // This structure is used for modifying vertex texture coords to position the brush texture _brushTransform = new Vector4(brushRect.X * repeatx, brushRect.Y * repeaty, repeatx, repeaty); _relativeTransformCache = RelativeTransform == null ? Matrix.Identity : Matrix.Invert(RelativeTransform.GetTransform()); // Determine if we can use the simpler, more optimised effects if (Tile == TileMode.None && Stretch != Stretch.UniformToFill) { _simplemode = true; } else if (ViewPort.X <= 0.0f && ViewPort.Z >= 1.0f && ViewPort.Y <= 0.0f && ViewPort.W >= 1.0f) { _simplemode = true; } else { _simplemode = false; } }
protected override bool BeginRenderBrushOverride(PrimitiveBuffer primitiveContext, RenderContext renderContext) { if (_gradientBrushTexture == null || _refresh) { _gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops); if (_gradientBrushTexture == null) { return(false); } } Matrix finalTransform = renderContext.Transform.Clone(); if (_refresh) { _refresh = false; _gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops); _effect = ContentManager.Instance.GetEffect("radialgradient"); g_focus = new float[] { GradientOrigin.X, GradientOrigin.Y }; g_center = new float[] { Center.X, Center.Y }; g_radius = new float[] { (float)RadiusX, (float)RadiusY }; if (MappingMode == BrushMappingMode.Absolute) { g_focus[0] /= _vertsBounds.Width; g_focus[1] /= _vertsBounds.Height; g_center[0] /= _vertsBounds.Width; g_center[1] /= _vertsBounds.Height; g_radius[0] /= _vertsBounds.Width; g_radius[1] /= _vertsBounds.Height; } g_relativetransform = RelativeTransform == null ? Matrix.Identity : Matrix.Invert(RelativeTransform.GetTransform()); } _effect.Parameters[PARAM_RELATIVE_TRANSFORM] = g_relativetransform; _effect.Parameters[PARAM_TRANSFORM] = GetCachedFinalBrushTransform(); _effect.Parameters[PARAM_FOCUS] = g_focus; _effect.Parameters[PARAM_CENTER] = g_center; _effect.Parameters[PARAM_RADIUS] = g_radius; _effect.Parameters[PARAM_OPACITY] = (float)(Opacity * renderContext.Opacity); GraphicsDevice.Device.SetSamplerState(0, SamplerState.AddressU, SpreadAddressMode); _effect.StartRender(_gradientBrushTexture.Texture, finalTransform); return(true); }
protected override bool BeginRenderOpacityBrushOverride(Texture tex, RenderContext renderContext) { if (_gradientBrushTexture == null || _refresh) { _gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops); if (_gradientBrushTexture == null) { return(false); } } Matrix finalTransform = renderContext.Transform.Clone(); if (_refresh) { _refresh = false; _gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops); _effect = ContentManager.Instance.GetEffect(EFFECT_RADIALOPACITYGRADIENT); g_focus = new float[] { GradientOrigin.X, GradientOrigin.Y }; g_center = new float[] { Center.X, Center.Y }; g_radius = new float[] { (float)RadiusX, (float)RadiusY }; if (MappingMode == BrushMappingMode.Absolute) { g_focus[0] /= _vertsBounds.Width; g_focus[1] /= _vertsBounds.Height; g_center[0] /= _vertsBounds.Width; g_center[1] /= _vertsBounds.Height; g_radius[0] /= _vertsBounds.Width; g_radius[1] /= _vertsBounds.Height; } g_relativetransform = RelativeTransform == null ? Matrix.Identity : Matrix.Invert(RelativeTransform.GetTransform()); } SurfaceDescription desc = tex.GetLevelDescription(0); float[] g_LowerVertsBounds = new float[] { _vertsBounds.Left / desc.Width, _vertsBounds.Top / desc.Height }; float[] g_UpperVertsBounds = new float[] { _vertsBounds.Right / desc.Width, _vertsBounds.Bottom / desc.Height }; _effect.Parameters[PARAM_RELATIVE_TRANSFORM] = g_relativetransform; _effect.Parameters[PARAM_TRANSFORM] = GetCachedFinalBrushTransform(); _effect.Parameters[PARAM_FOCUS] = g_focus; _effect.Parameters[PARAM_CENTER] = g_center; _effect.Parameters[PARAM_RADIUS] = g_radius; _effect.Parameters[PARAM_OPACITY] = (float)(Opacity * renderContext.Opacity); _effect.Parameters[PARAM_ALPHATEX] = _gradientBrushTexture.Texture; _effect.Parameters[PARAM_UPPERVERTSBOUNDS] = g_UpperVertsBounds; _effect.Parameters[PARAM_LOWERVERTSBOUNDS] = g_LowerVertsBounds; GraphicsDevice.Device.SetSamplerState(0, SamplerState.AddressU, SpreadAddressMode); _effect.StartRender(tex, finalTransform); return(true); }