Exemplo n.º 1
0
        public virtual void RenderUI(CanvasRenderer renderer, Component_RenderingPipeline.RenderSceneData.LightItem lightItem, Viewport viewport, double intensity)
        {
            var lightPosition = lightItem.Position;

            //!!!!override real position
            //{
            //	if( Sun.Instances.Count > 0 )
            //	{
            //		//get first sun entity on the map.
            //		Sun sun = Sun.Instances[ 0 ];

            //		Vec3 direction;
            //		if( sun.BillboardOverridePosition != Vec3.Zero )
            //			direction = sun.BillboardOverridePosition.GetNormalize();
            //		else
            //			direction = -sun.Rotation.GetForward();
            //		position = camera.Position + direction * 100000;

            //		return true;
            //	}

            //	position = Vec3.Zero;
            //	return false;
            //}

            if (viewport.CameraSettings.ProjectToScreenCoordinates(lightPosition, out var screenLightPosition))
            {
                //get enabled flares
                var flares = GetComponents <Component_LensFlare>(onlyEnabledInHierarchy: true);

                //sort by position
                CollectionUtility.SelectionSort(flares, delegate(Component_LensFlare f1, Component_LensFlare f2)
                {
                    if (f1.Position > f2.Position)
                    {
                        return(-1);
                    }
                    if (f1.Position < f2.Position)
                    {
                        return(1);
                    }
                    return(0);
                });

                //for( int n = 0; n < flares.Count; n++ )
                //	sortedFlares[ n ].tempSmoothIntensityFactor = cameraInfo.SmoothIntensityFactors[ n ];

                //render
                foreach (var flare in flares)
                {
                    var image = flare.Image.Value;

                    var flareVector   = screenLightPosition - new Vector2(0.5, 0.5);
                    var flarePosition = new Vector2(0.5, 0.5) + flareVector * flare.Position;
                    var size          = flare.Size.Value;
                    var flareSize     = new Vector2(size.X, size.Y * renderer.AspectRatio);
                    var rectangle     = new Rectangle(flarePosition - flareSize * 0.5, flarePosition + flareSize * 0.5);

                    var flareColor = Color.Value * flare.Color * new ColorValue(1, 1, 1, intensity);
                    // * new ColorValue( 1, 1, 1, item.tempSmoothIntensityFactor );

                    if (flareColor.Alpha > 0)
                    {
                        renderer.PushBlendingType(flare.Blending.Value);
                        renderer.AddQuad(rectangle, new RectangleF(0, 0, 1, 1), image, flareColor, true);
                        renderer.PopBlendingType();
                    }
                }
            }
        }