Example #1
0
        public virtual void Recalculate()
        {
            CalculatedStyle calculatedStyle  = Parent?.InnerDimensions ?? UserInterface.ActiveInstance.Dimensions;
            CalculatedStyle calculatedStyle2 = default;

            calculatedStyle2.X = Left.GetValue(calculatedStyle.Width) + calculatedStyle.X;
            calculatedStyle2.Y = Top.GetValue(calculatedStyle.Height) + calculatedStyle.Y;
            float value  = MinWidth.GetValue(calculatedStyle.Width);
            float value2 = MaxWidth.GetValue(calculatedStyle.Width);
            float value3 = MinHeight.GetValue(calculatedStyle.Height);
            float value4 = MaxHeight.GetValue(calculatedStyle.Height);

            calculatedStyle2.Width   = MathHelper.Clamp(Width.GetValue(calculatedStyle.Width), value, value2);
            calculatedStyle2.Height  = MathHelper.Clamp(Height.GetValue(calculatedStyle.Height), value3, value4);
            calculatedStyle2.Width  += MarginLeft + MarginRight;
            calculatedStyle2.Height += MarginTop + MarginBottom;
            calculatedStyle2.X      += calculatedStyle.Width * HAlign - calculatedStyle2.Width * HAlign;
            calculatedStyle2.Y      += calculatedStyle.Height * VAlign - calculatedStyle2.Height * VAlign;
            OuterDimensions          = calculatedStyle2;

            calculatedStyle2.X      += MarginLeft;
            calculatedStyle2.Y      += MarginTop;
            calculatedStyle2.Width  -= MarginLeft + MarginRight;
            calculatedStyle2.Height -= MarginTop + MarginBottom;
            Dimensions = calculatedStyle2;

            calculatedStyle2.X      += PaddingLeft;
            calculatedStyle2.Y      += PaddingTop;
            calculatedStyle2.Width  -= PaddingLeft + PaddingRight;
            calculatedStyle2.Height -= PaddingTop + PaddingBottom;
            InnerDimensions          = calculatedStyle2;

            RecalculateChildren();
        }
        public override UnityEngine.Color GetColour(double x, double y)
        {
            // Normal is..
            Color  normal = Normals.GetColour(x, y);
            double height = Height.GetValue(x, y);
            double ratio  = Ratio.GetValue(x, y);

            // Next, dot it with a vertical vector. (0,0,1)
            // Simplifies to just normal.z (blue):
            float dot = normal.b;

            double k = 1.0 - ratio * ratio * (1.0 - dot * dot);

            if (k < 0.0)
            {
                return(SourceModule.GetColour(x, y));
            }

            double rdSqrt = -(ratio * dot + System.Math.Sqrt(k));

            // Also apply height to it here:
            rdSqrt *= height;

            // Refraction vector is.. (just straight offset x/y):
            x += rdSqrt * normal.r;
            y += rdSqrt * normal.g;
            // float refractionVectorZ=ratio + rdSqrt * normal.b;

            return(SourceModule.GetColour(x, y));
        }
Example #3
0
 private void Update(EvaluationContext context)
 {
     Output.Value = new RawViewportF
     {
         X        = X.GetValue(context),
         Y        = Y.GetValue(context),
         Width    = Width.GetValue(context),
         Height   = Height.GetValue(context),
         MinDepth = MinDepth.GetValue(context),
         MaxDepth = MaxDepth.GetValue(context)
     };
 }
Example #4
0
 public new void Update(EvaluationContext context)
 {
     if (InputConnection.Count > 0)
     {
         Value = InputConnection[0].GetValue(context);
     }
     else
     {
         if (Width.InputConnection != null)
         {
             Value.Width = Width.GetValue(context);
         }
         if (Height.InputConnection != null)
         {
             Value.Height = Height.GetValue(context);
         }
     }
 }
Example #5
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            double intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100;

            int x, y;

            if (frame == 0)
            {
                int i;
                for (i = 0; i < _fireBuffer.Count(); i++)
                {
                    _fireBuffer[i] = 0;
                }
            }

            int maxHt = BufferHt;
            int maxWi = BufferWi;

            if (Location == FireDirection.Left || Location == FireDirection.Right)
            {
                maxHt = BufferWi;
                maxWi = BufferHt;
            }

            // build fire
            for (x = 0; x < maxWi; x++)
            {
                var r = x % 2 == 0 ? 190 + (Rand() % 10) : 100 + (Rand() % 50);
                SetFireBuffer(x, 0, r, maxWi, maxHt);
            }

            int h = (int)Height.GetValue(intervalPosFactor);

            if (h <= 0)
            {
                h = 1;
            }
            int step = 255 * 100 / maxHt / h;

            for (y = 1; y < maxHt; y++)
            {
                for (x = 0; x < maxWi; x++)
                {
                    var v1  = GetFireBuffer(x - 1, y - 1, maxWi, maxHt);
                    var v2  = GetFireBuffer(x + 1, y - 1, maxWi, maxHt);
                    var v3  = GetFireBuffer(x, y - 1, maxWi, maxHt);
                    var v4  = GetFireBuffer(x, y - 1, maxWi, maxHt);
                    var n   = 0;
                    var sum = 0;
                    if (v1 >= 0)
                    {
                        sum += v1;
                        n++;
                    }
                    if (v2 >= 0)
                    {
                        sum += v2;
                        n++;
                    }
                    if (v3 >= 0)
                    {
                        sum += v3;
                        n++;
                    }
                    if (v4 >= 0)
                    {
                        sum += v4;
                        n++;
                    }
                    var newIndex = n > 0 ? sum / n : 0;
                    if (newIndex > 0)
                    {
                        newIndex += (Rand() % 100 < 20) ? step : -step;
                        if (newIndex < 0)
                        {
                            newIndex = 0;
                        }
                        if (newIndex >= FirePalette.Count())
                        {
                            newIndex = FirePalette.Count() - 1;
                        }
                    }
                    SetFireBuffer(x, y, newIndex, maxWi, maxHt);
                }
            }
            for (y = 0; y < maxHt; y++)
            {
                for (x = 0; x < maxWi; x++)
                {
                    int xp = x;
                    int yp = y;
                    if (Location == FireDirection.Top || Location == FireDirection.Right)
                    {
                        yp = maxHt - y - 1;
                    }
                    if (Location == FireDirection.Left || Location == FireDirection.Right)
                    {
                        int t = xp;
                        xp = yp;
                        yp = t;
                    }

                    Color color = FirePalette.GetColor(GetFireBuffer(x, y, maxWi, maxHt));
                    var   hsv   = HSV.FromRGB(color);
                    if (CalculateHueShift(intervalPosFactor) > 0)
                    {
                        hsv.H = hsv.H + (CalculateHueShift(intervalPosFactor) / 100.0f);
                    }

                    hsv.V = hsv.V * LevelCurve.GetValue(intervalPosFactor) / 100;
                    //if (color.R == 0 && color.G == 0 && color.B == 0)
                    //{
                    //	color = Color.Transparent;
                    //}

                    frameBuffer.SetPixel(xp, yp, hsv);
                }
            }
        }
Example #6
0
        private void Update(EvaluationContext context)
        {
            try
            {
                var resourceManager = ResourceManager.Instance();

                var lowerRadius = Radius.GetValue(context);
                var upperRadius = lowerRadius + RadiusOffset.GetValue(context);
                var height      = Height.GetValue(context);

                var rows    = Rows.GetValue(context).Clamp(1, 10000);
                var columns = Columns.GetValue(context).Clamp(1, 10000);

                var c      = Center.GetValue(context);
                var center = new SharpDX.Vector3(c.X, c.Y, c.Z);

                var spinInRad  = Spin.GetValue(context) * MathUtils.ToRad;
                var twistInRad = Twist.GetValue(context) * MathUtils.ToRad;
                var basePivot  = BasePivot.GetValue(context);

                var fillRatio   = Fill.GetValue(context) / 360f;
                var capSegments = CapSegments.GetValue(context).Clamp(0, 1000);
                var addCaps     = capSegments > 0;
                //var isHullClosed = true; //Math.Abs(fillRatio - 1) < 0.01f;

                var isFlipped = lowerRadius < 0;

                var vertexHullColumns = columns + 1;

                var hullVerticesCount = (rows + 1) * vertexHullColumns;
                var hullTriangleCount = rows * columns * 2;

                var capsVertexCount   = +2 * (capSegments * vertexHullColumns + 1);
                var capsTriangleCount = 2 * ((capSegments - 1) * columns * 2 + columns);

                var totalVertexCount   = hullVerticesCount + (addCaps ? capsVertexCount : 0);
                var totalTriangleCount = hullTriangleCount + (addCaps ? capsTriangleCount : 0);

                // Create buffers
                if (_vertexBufferData.Length != totalVertexCount)
                {
                    _vertexBufferData = new PbrVertex[totalVertexCount];
                }

                if (_indexBufferData.Length != totalTriangleCount)
                {
                    _indexBufferData = new SharpDX.Int3[totalTriangleCount];
                }

                // Initialize
                var radiusAngleFraction = fillRatio / (vertexHullColumns - 1) * 2.0 * Math.PI;
                var rowStep             = height / rows;

                // Hull
                for (var rowIndex = 0; rowIndex < rows + 1; ++rowIndex)
                {
                    var heightFraction = rowIndex / (float)rows;
                    var rowRadius      = MathUtils.Lerp(lowerRadius, upperRadius, heightFraction);
                    var nextRowRadius  = MathUtils.Lerp(lowerRadius, upperRadius, (rowIndex + 1) / (float)rows);
                    var rowLevel       = height * (heightFraction - basePivot);
                    var rowCenter      = new SharpDX.Vector3(0, rowLevel, 0);

                    for (var columnIndex = 0; columnIndex < vertexHullColumns; ++columnIndex)
                    {
                        var columnAngle = columnIndex * radiusAngleFraction + spinInRad + twistInRad * heightFraction + Math.PI;

                        var u0 = columnIndex / (float)columns;
                        var u1 = (columnIndex + 1) / (float)rows;

                        var v0 = addCaps ? ((rowIndex + 1) / (float)rows) / 2f
                                         : (rowIndex + 1) / (float)rows;
                        var v1 = addCaps ? (rowIndex / (float)rows) / 2f
                                        : rowIndex / (float)rows;

                        var p = new SharpDX.Vector3((float)Math.Sin(columnAngle) * rowRadius,
                                                    rowLevel,
                                                    (float)Math.Cos(columnAngle) * rowRadius);

                        var p1 = new SharpDX.Vector3((float)Math.Sin(columnAngle) * rowRadius,
                                                     rowLevel + rowStep,
                                                     (float)Math.Cos(columnAngle) * rowRadius
                                                     );

                        var p2 = new SharpDX.Vector3((float)Math.Sin(columnAngle + radiusAngleFraction) * nextRowRadius,
                                                     rowLevel,
                                                     (float)Math.Cos(columnAngle + radiusAngleFraction) * nextRowRadius
                                                     );

                        var uv0 = new SharpDX.Vector2(u0, v1);
                        var uv1 = new SharpDX.Vector2(u1, v1);
                        var uv2 = new SharpDX.Vector2(u1, v0);

                        var normal0 = SharpDX.Vector3.Normalize(p - rowCenter);

                        MeshUtils.CalcTBNSpace(p, uv0, p1, uv1, p2, uv2, normal0, out var tangent0, out var binormal0);

                        var vertexIndex = rowIndex * vertexHullColumns + columnIndex;
                        _vertexBufferData[vertexIndex] = new PbrVertex
                        {
                            Position  = p + center,
                            Normal    = isFlipped ? normal0 * -1 : normal0,
                            Tangent   = tangent0,
                            Bitangent = isFlipped ? binormal0 * -1 : binormal0,
                            Texcoord  = uv0,
                            Selection = 1
                        };

                        var faceIndex = 2 * (rowIndex * (vertexHullColumns - 1) + columnIndex);
                        if (columnIndex < vertexHullColumns - 1 && rowIndex < rows)
                        {
                            if (isFlipped)
                            {
                                _indexBufferData[faceIndex + 0] = new SharpDX.Int3(vertexIndex + vertexHullColumns, vertexIndex + 1, vertexIndex + 0);
                                _indexBufferData[faceIndex + 1] =
                                    new SharpDX.Int3(vertexIndex + vertexHullColumns + 1, vertexIndex + 1, vertexIndex + vertexHullColumns);
                            }
                            else
                            {
                                _indexBufferData[faceIndex + 0] = new SharpDX.Int3(vertexIndex + 0, vertexIndex + 1, vertexIndex + vertexHullColumns);
                                _indexBufferData[faceIndex + 1] =
                                    new SharpDX.Int3(vertexIndex + vertexHullColumns, vertexIndex + 1, vertexIndex + vertexHullColumns + 1);
                            }
                        }
                    }
                }

                // Caps
                if (addCaps)
                {
                    for (var capIndex = 0; capIndex <= 1; capIndex++)
                    {
                        var isLowerCap = capIndex == 0;
                        var capLevel   = ((isLowerCap ? 0 : 1) - basePivot) * height;
                        var capRadius  = isLowerCap ? lowerRadius : upperRadius;
                        var isReverse  = isFlipped ^ isLowerCap;

                        var centerVertexIndex = hullVerticesCount + (capsVertexCount / 2) * (capIndex + 1) - 1;

                        for (var capSegmentIndex = 0; capSegmentIndex < capSegments; ++capSegmentIndex)
                        {
                            var isCenterSegment = capSegmentIndex == capSegments - 1;

                            var capFraction     = 1f - (capSegmentIndex) / (float)capSegments;
                            var nextCapFraction = 1f - (capSegmentIndex + 1) / (float)capSegments;
                            var radius          = upperRadius * capFraction;
                            var nextRadius      = upperRadius * nextCapFraction;


                            for (var columnIndex = 0; columnIndex < vertexHullColumns; ++columnIndex)
                            {
                                var columnAngle = columnIndex * radiusAngleFraction + spinInRad + twistInRad * (isLowerCap ? 0 : 1) + Math.PI;

                                var xx = (float)Math.Sin(columnAngle);
                                var yy = (float)Math.Cos(columnAngle);

                                var p = new SharpDX.Vector3(-xx * radius,
                                                            capLevel,
                                                            -yy * radius);

                                var normal0 = isLowerCap ? SharpDX.Vector3.Down : SharpDX.Vector3.Up;

                                var tangent0  = SharpDX.Vector3.Left;
                                var binormal0 = SharpDX.Vector3.ForwardRH;

                                var vertexIndex = capSegmentIndex * vertexHullColumns + columnIndex
                                                  + hullVerticesCount + (capsVertexCount / 2) * capIndex;

                                // Write vertex
                                var capUvOffset = isLowerCap
                                                      ? new SharpDX.Vector2(-0.25f, -0.25f)
                                                      : new SharpDX.Vector2(0.25f, -0.25f);
                                _vertexBufferData[vertexIndex] = new PbrVertex
                                {
                                    Position  = p + center,
                                    Normal    = isFlipped ? normal0 * -1 : normal0,
                                    Tangent   = tangent0,
                                    Bitangent = isFlipped ? binormal0 * -1 : binormal0,
                                    Texcoord  = new SharpDX.Vector2(-xx * (isLowerCap ? -1 : 1), yy) * capFraction / 4 + capUvOffset,
                                    Selection = 1
                                };

                                if (isCenterSegment)
                                {
                                    if (columnIndex == 0)
                                    {
                                        _vertexBufferData[centerVertexIndex] = new PbrVertex
                                        {
                                            Position  = new SharpDX.Vector3(0, capLevel, 0) + center,
                                            Normal    = (isFlipped) ? normal0 * -1 : normal0,
                                            Tangent   = tangent0,
                                            Bitangent = (isFlipped ^ isLowerCap) ? binormal0 * -1 : binormal0,
                                            Texcoord  = capUvOffset,
                                            Selection = 1
                                        };
                                    }
                                }

                                if (columnIndex < vertexHullColumns - 1 && capSegmentIndex < capSegments)
                                {
                                    if (isCenterSegment)
                                    {
                                        var faceIndex = (capSegmentIndex * (vertexHullColumns - 1) * 2 + columnIndex)
                                                        + hullTriangleCount + (capsTriangleCount / 2) * capIndex;

                                        var f1 = isReverse
                                                     ? new SharpDX.Int3(vertexIndex + 1, vertexIndex, centerVertexIndex)
                                                     : new SharpDX.Int3(centerVertexIndex, vertexIndex, vertexIndex + 1);
                                        _indexBufferData[faceIndex] = f1;
                                    }
                                    else
                                    {
                                        var faceIndex = (capSegmentIndex * (vertexHullColumns - 1) * 2) + columnIndex * 2
                                                        + hullTriangleCount +
                                                        (capsTriangleCount / 2) * capIndex;

                                        _indexBufferData[faceIndex]
                                            = isReverse
                                                  ? new SharpDX.Int3(vertexIndex + vertexHullColumns, vertexIndex + 1, vertexIndex)
                                                  : new SharpDX.Int3(vertexIndex, vertexIndex + 1, vertexIndex + vertexHullColumns);

                                        _indexBufferData[faceIndex + 1]
                                            = isReverse
                                                  ? new SharpDX.Int3(vertexIndex + vertexHullColumns, vertexIndex + vertexHullColumns + 1, vertexIndex + 1)
                                                  : new SharpDX.Int3(vertexIndex + 1, vertexIndex + vertexHullColumns + 1, vertexIndex + vertexHullColumns);
                                    }
                                }
                            }
                        }
                    }
                }

                // Write Data
                _vertexBufferWithViews.Buffer = _vertexBuffer;
                resourceManager.SetupStructuredBuffer(_vertexBufferData, PbrVertex.Stride * totalVertexCount, PbrVertex.Stride, ref _vertexBuffer);
                resourceManager.CreateStructuredBufferSrv(_vertexBuffer, ref _vertexBufferWithViews.Srv);
                resourceManager.CreateStructuredBufferUav(_vertexBuffer, UnorderedAccessViewBufferFlags.None, ref _vertexBufferWithViews.Uav);

                _indexBufferWithViews.Buffer = _indexBuffer;
                const int stride = 3 * 4;
                resourceManager.SetupStructuredBuffer(_indexBufferData, stride * totalTriangleCount, stride, ref _indexBuffer);
                resourceManager.CreateStructuredBufferSrv(_indexBuffer, ref _indexBufferWithViews.Srv);
                resourceManager.CreateStructuredBufferUav(_indexBuffer, UnorderedAccessViewBufferFlags.None, ref _indexBufferWithViews.Uav);

                _data.VertexBuffer  = _vertexBufferWithViews;
                _data.IndicesBuffer = _indexBufferWithViews;
                Data.Value          = _data;
                Data.DirtyFlag.Clear();
            }
            catch (Exception e)
            {
                Log.Error("Failed to create torus mesh:" + e.Message);
            }
        }
Example #7
0
 private void Update(EvaluationContext context)
 {
     Size.Value = new Size2(Width.GetValue(context), Height.GetValue(context));
 }
Example #8
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            double intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100;
            double level             = LevelCurve.GetValue(intervalPosFactor) / 100;
            double hueShift          = CalculateHueShift(intervalPosFactor);

            int x, y;

            int maxHt = BufferHt;
            int maxWi = BufferWi;

            if (Location == FireDirection.Left || Location == FireDirection.Right)
            {
                maxHt = BufferWi;
                maxWi = BufferHt;
            }

            // build fire
            for (x = 0; x < maxWi; x++)
            {
                var r = x % 2 == 0 ? 190 + (Rand() % 10) : 100 + (Rand() % 50);
                _fireBuffer[x] = r;
            }

            int h = (int)Height.GetValue(intervalPosFactor);

            if (h <= 0)
            {
                h = 1;
            }
            int step = 255 * 100 / maxHt / h;

            for (y = 1; y < maxHt; y++)
            {
                for (x = 0; x < maxWi; x++)
                {
                    var v1  = GetFireBuffer(x - 1, y - 1, maxWi, maxHt);
                    var v2  = GetFireBuffer(x + 1, y - 1, maxWi, maxHt);
                    var v3  = GetFireBuffer(x, y - 1, maxWi, maxHt);
                    var v4  = GetFireBuffer(x, y - 1, maxWi, maxHt);
                    var n   = 0;
                    var sum = 0;
                    if (v1 >= 0)
                    {
                        sum += v1;
                        n++;
                    }
                    if (v2 >= 0)
                    {
                        sum += v2;
                        n++;
                    }
                    if (v3 >= 0)
                    {
                        sum += v3;
                        n++;
                    }
                    if (v4 >= 0)
                    {
                        sum += v4;
                        n++;
                    }
                    var newIndex = n > 0 ? sum / n : 0;
                    if (newIndex > 0)
                    {
                        newIndex += (Rand() % 100 < 20) ? step : -step;
                        if (newIndex < 0)
                        {
                            newIndex = 0;
                        }
                        if (newIndex >= FirePalette.Count())
                        {
                            newIndex = FirePalette.Count() - 1;
                        }
                    }
                    _fireBuffer[y * maxWi + x] = newIndex;
                }
            }

            for (y = 0; y < maxHt; y++)
            {
                for (x = 0; x < maxWi; x++)
                {
                    var colorIndex = GetFireBuffer(x, y, maxWi, maxHt);
                    if (colorIndex == 0)
                    {
                        continue;                                      // No point going any further if color index is 0 (Black). Significantly reduces render time.
                    }
                    int xp = x;
                    int yp = y;
                    if (Location == FireDirection.Top || Location == FireDirection.Right)
                    {
                        yp = maxHt - y - 1;
                    }
                    if (Location == FireDirection.Left || Location == FireDirection.Right)
                    {
                        int t = xp;
                        xp = yp;
                        yp = t;
                    }
                    HSV hsv = FirePalette.GetColor(colorIndex);
                    if (hueShift > 0)
                    {
                        hsv.H = hsv.H + hueShift / 100.0f;
                    }

                    hsv.V *= level;

                    frameBuffer.SetPixel(xp, yp, hsv);
                }
            }
        }