Example #1
0
        protected override void OnRender(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, ref Component_Image actualTexture)
        {
            var demandFormat = PixelFormat.Float16RGBA;

            if (actualTexture.Result.ResultFormat != demandFormat)
            {
                var newTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, demandFormat);

                context.SetViewport(newTexture.Result.GetRenderTarget().Viewports[0]);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName = @"Base\Shaders\EffectsCommon_vs.sc";
                //shader.VertexProgramFunctionName = "main_vp";
                shader.FragmentProgramFileName = @"Base\Shaders\Effects\ToHDR_fs.sc";
                //shader.FragmentProgramFunctionName = "main_fp";

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/, actualTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                //var size = context.owner.DimensionsInPixels.Size;
                //shader.Parameters.Set( "viewportSize", new Vec4( size.X, size.Y, 1.0 / (double)size.X, 1.0 / (double)size.Y ).ToVec4F() );

                //Mat4F identity = Mat4F.Identity;
                //shader.Parameters.Set( "worldViewProjMatrix", ParameterType.Matrix4x4, 1, &identity, sizeof( Mat4F ) );

                context.RenderQuadToCurrentViewport(shader);

                //free old texture
                context.DynamicTexture_Free(actualTexture);

                actualTexture = newTexture;
            }
        }
Example #2
0
        bool CheckVisibilityPhysics(ViewportRenderingContext context, Vector3 position)
        {
            var scene = context.Owner.AttachedScene;

            if (scene != null)
            {
                var cameraVisibleStartOffset = 1.0;

                var cameraPosition = context.Owner.CameraSettings.Position;
                //if( camera.IsReflected() )
                //	cameraPosition = camera.GetReflectionMatrix() * cameraPosition;

                var direction = (position - cameraPosition).GetNormalize();
                var start     = cameraPosition + direction * cameraVisibleStartOffset;

                //!!!!contact group
                var item = new PhysicsRayTestItem(new Ray(start, position - start), 1, -1, PhysicsRayTestItem.ModeEnum.One);
                scene.PhysicsRayTest(item);

                if (item.Result.Length != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #3
0
        protected override void OnSetShaderParameters(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, Component_Image actualTexture, CanvasRenderer.ShaderItem shader)
        {
            base.OnSetShaderParameters(context, frameData, actualTexture, shader);

            var noiseTexture = ResourceManager.LoadResource <Component_Image>(noiseTextureDefault);

            if (noiseTexture == null)
            {
                noiseTexture = ResourceUtility.WhiteTexture2D;
            }

            var gpuNoiseTexture = noiseTexture.Result;

            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1 /*"noiseTexture"*/, noiseTexture, TextureAddressingMode.Wrap, FilterOption.Point, FilterOption.Point, FilterOption.Point));

            {
                var size = actualTexture.Result.ResultSize;
                shader.Parameters.Set("viewportSize", new Vector4(size.X, size.Y, 1.0 / (double)size.X, 1.0 / (double)size.Y).ToVector4F());
            }

            {
                var size = gpuNoiseTexture.ResultSize;
                shader.Parameters.Set("noiseTextureSize", new Vector4(size.X, size.Y, 1.0 / (double)size.X, 1.0 / (double)size.Y).ToVector4F());
            }
        }
Example #4
0
        public override void Render(ViewportRenderingContext context, out int verticesRendered)
        {
            base.Render(context, out verticesRendered);

            var context2 = context.objectInSpaceRenderingContext;
            var renderer = context.Owner.Simple3DRenderer;

            if (/*ConstraintRigid != null && */ renderer != null)
            {
                var tr  = TransformV;
                var pos = tr.Position;

                {
                    var color = new ColorValue(0, 0, 0);
                    renderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);

                    renderer.AddLine(pos, tr * new Vector3(1, 0, 0));
                    verticesRendered += 2;

                    var point1 = tr.Position;
                    var point2 = tr * new Vector3(1, 0, 0);

                    var dimensions = new Vector2(tr.Scale.X / 10, tr.Scale.X / 10);

                    renderer.AddEllipse(dimensions, 16, Matrix4.FromTranslate(point1), true);
                    renderer.AddEllipse(dimensions, 16, Matrix4.FromTranslate(point2), true);

                    verticesRendered += 17 * 2;
                }
            }
        }
Example #5
0
        void RenderBack2(ViewportRenderingContext context, Rectangle rectangle)
        {
            var renderer = context.Owner.CanvasRenderer;
            var context2 = context.objectInSpaceRenderingContext;
            var fontSize = GetFontSizeScreen(context);

            //calculate rectangle
            var rect2 = rectangle;

            rect2.Expand(new Vector2(renderer.AspectRatioInv, 1) * fontSize * BackSizeAdd.Value);

            //render
            if (Back && BackColor.Value.Alpha > 0 || context2.selectedObjects.Contains(this) || context2.canSelectObjects.Contains(this))
            {
                var handled = false;
                RenderBackBefore?.Invoke(this, context, rect2, ref handled);
                if (!handled)
                {
                    RenderBack(context, rect2);
                    RenderBackAfter?.Invoke(this, context, rect2);
                }
            }

            //modify selection label
            if (EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Editor)
            {
                var item = context2.viewport.GetLastFrameScreenLabelByObjectInSpace(this);
                if (item != null)
                {
                    item.ScreenRectangle = rect2;
                    item.Color           = ColorValue.Zero;
                    item.Shape           = Viewport.LastFrameScreenLabelItem.ShapeEnum.Rectangle;
                }
            }
        }
Example #6
0
        public bool CheckNeedShowDevelopmentDataOfAreaAndPoints(ViewportRenderingContext context, GetRenderSceneDataMode mode)
        {
            if (EnabledInHierarchy && VisibleInHierarchy && mode == GetRenderSceneDataMode.InsideFrustum)
            {
                if (ParentScene.GetDisplayDevelopmentDataInThisApplication() && ParentScene.DisplayAreas)
                {
                    return(true);
                }

                var context2 = context.objectInSpaceRenderingContext;

                if (context2.selectedObjects.Contains(this) || context2.canSelectObjects.Contains(this) || context2.objectToCreate == this)
                {
                    return(true);
                }

                foreach (var point in GetPoints())
                {
                    if (context2.selectedObjects.Contains(point) || context2.canSelectObjects.Contains(point) || context2.objectToCreate == point)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public virtual void ConvertToLDR(ViewportRenderingContext context, ref Component_Image actualTexture)
        {
            //!!!!может другие тоже форматы? провер¤ть на FloatXX?
            var demandFormat = PixelFormat.A8R8G8B8;

            if (actualTexture.Result.ResultFormat != demandFormat)
            {
                var newTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, demandFormat);

                context.SetViewport(newTexture.Result.GetRenderTarget().Viewports[0]);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                shader.FragmentProgramFileName = @"Base\Shaders\Effects\ToLDR_fs.sc";

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/, actualTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                //var size = context.owner.DimensionsInPixels.Size;
                //shader.Parameters.Set( "viewportSize", new Vec4( size.X, size.Y, 1.0 / (double)size.X, 1.0 / (double)size.Y ).ToVec4F() );

                //Mat4F identity = Mat4F.Identity;
                //shader.Parameters.Set( "worldViewProjMatrix", ParameterType.Matrix4x4, 1, &identity, sizeof( Mat4F ) );

                context.RenderQuadToCurrentViewport(shader);

                //free old texture
                context.DynamicTexture_Free(actualTexture);

                actualTexture = newTexture;
            }
        }
Example #8
0
        protected override void OnRender(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, ref Component_Image actualTexture)
        {
            var newTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, PixelFormat.A8R8G8B8);

            context.SetViewport(newTexture.Result.GetRenderTarget().Viewports[0]);

            CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
            shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
            shader.FragmentProgramFileName = @"Base\Shaders\Effects\ToneMapping_fs.sc";

            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/, actualTexture,
                                                                               TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

            shader.Parameters.Set("u_tonemapping_parameters", new Vector4F((float)Intensity, (float)GammaInput, (float)Exposure, (float)GammaOutput));

            shader.Defines.Add(new CanvasRenderer.ShaderItem.DefineItem($"TONEMAPPING_METHOD_{Method.Value.ToString().ToUpper()}"));
            if (Method.Value == MethodEnum.Custom)
            {
                shader.Defines.Add(new CanvasRenderer.ShaderItem.DefineItem("CUSTOM_CODE", CustomCode.Value));
            }

            context.RenderQuadToCurrentViewport(shader);

            //free old texture
            context.DynamicTexture_Free(actualTexture);

            actualTexture = newTexture;
        }
Example #9
0
        Vector2 ConvertOffsetToScreen(ViewportRenderingContext context, UIMeasureValueVector2 value)
        {
            if (value.Value == Vector2.Zero)
            {
                return(Vector2.Zero);
            }

            Vector2 screen = Vector2.Zero;

            //from
            switch (value.Measure)
            {
            case UIMeasure.Parent:
                screen = value.Value;                // * GetScreenSize();
                break;

            case UIMeasure.Screen:
                screen = value.Value;
                break;

            case UIMeasure.Units:
                screen = DivideWithZeroCheck(value.Value, GetParentContainerSizeInUnits(context));
                break;

            case UIMeasure.Pixels:
                screen = DivideWithZeroCheck(value.Value, GetParentContainerSizeInPixels(context));
                break;
            }

            return(screen);
        }
Example #10
0
        double GetFontSizeScreen(ViewportRenderingContext context)
        {
            var value    = FontSize.Value;
            var fontSize = ConvertOffsetToScreen(context, new UIMeasureValueVector2(value.Measure, 0, value.Value)).Y;

            return(fontSize);
        }
Example #11
0
        public override void OnGetRenderSceneData(ViewportRenderingContext context, GetRenderSceneDataMode mode)
        {
            base.OnGetRenderSceneData(context, mode);

            if (mode == GetRenderSceneDataMode.InsideFrustum)
            {
                var context2 = context.objectInSpaceRenderingContext;

                if (EngineApp.ApplicationType != EngineApp.ApplicationTypeEnum.Simulation ||
                    EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Simulation && DisplayInSimulation)
                {
                    var cameraPosition = context.Owner.CameraSettings.Position;
                    var sphere         = new Sphere(cameraPosition, VisibilityDistance);

                    if (SpaceBounds.CalculatedBoundingSphere.Intersects(ref sphere))
                    {
                        var canvasRenderer = context.Owner.CanvasRenderer;
                        var renderer       = context.Owner.Simple3DRenderer;

                        if (canvasRenderer != null && renderer != null)
                        {
                            if (context.Owner.CameraSettings.ProjectToScreenCoordinates(TransformV.Position, out var screenPosition))
                            {
                                Render(context, screenPosition);
                            }
                        }
                    }
                }
            }
        }
Example #12
0
        public void RenderDownscale(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, Vector2I destinationSize, ref Component_Image actualTexture)
        {
            if (Technique.Value >= TechniqueEnum.SSAAx2 && Technique.Value <= TechniqueEnum.SSAAx4 && context.Owner.SizeInPixels != actualTexture.Result.ResultSize)
            {
                var rescaledTexture = context.RenderTarget2D_Alloc(context.Owner.SizeInPixels, actualTexture.Result.ResultFormat);

                //copy to scene texture with downscale
                {
                    context.SetViewport(rescaledTexture.Result.GetRenderTarget().Viewports[0]);

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\DownscaleAntialiasing_fs.sc";

                    shader.Defines.Add(new CanvasRenderer.ShaderItem.DefineItem(Technique.Value.ToString().ToUpper()));

                    var multiplier = new Vector2F(1, 1) / destinationSize.ToVector2F() * (float)DownscaleSamplerMultiplier.Value;
                    shader.Parameters.Set("antialiasing_multiplier", multiplier);

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/,
                                                                                       actualTexture, TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.None));

                    context.RenderQuadToCurrentViewport(shader);
                }

                context.DynamicTexture_Free(actualTexture);

                actualTexture = rescaledTexture;
            }
        }
Example #13
0
        /////////////////////////////////////////

        unsafe void RenderObjects(ViewportRenderingContext context, Component_RenderingPipeline_Basic.FrameData frameData, ref Component_Image actualTexture, double scale, ColorValue color, Vector4 anyData, List <Vector2I> renderableItems)
        {
            var pipeline = context.RenderingPipeline as Component_RenderingPipeline_Basic;
            var owner    = context.Owner;


            float scaleFactor = 1.0f / 200.0f;

            float scaleV        = scaleFactor * (float)scale * (float)Scale.Value;
            var   aspectRatio   = (float)context.CurrentViewport.SizeInPixels.X / (float)context.CurrentViewport.SizeInPixels.Y;
            var   effectScale   = new Vector2F(scaleV / aspectRatio, scaleV);
            var   effectAnyData = anyData.ToVector4F();

            var scaleSizeInPixels = (int)(scaleV * (float)context.CurrentViewport.SizeInPixels.Y);


            var scissor = RectangleI.Cleared;

            {
                var points = new Vector3[8];

                for (int nRenderableItem = 0; nRenderableItem < renderableItems.Count; nRenderableItem++)
                {
                    var renderableItem = renderableItems[nRenderableItem];

                    if (renderableItem.X == 0)
                    {
                        //meshes
                        ref var meshItem = ref frameData.RenderSceneData.Meshes.Data[renderableItem.Y];

                        meshItem.BoundingSphere.ToBounds(out var bounds);
                        bounds.ToPoints(ref points);
                    }
Example #14
0
 private void Scene_GetRenderSceneData(Component_Scene scene, ViewportRenderingContext context)
 {
     if (DisplayPath)
     {
         pathController?.DrawPath(context);
     }
 }
Example #15
0
        ////Add
        //ReferenceField<ColorValuePowered> _add = new ColorValuePowered( 1, 1, 1, 1, 0 );
        //[DefaultValue( "1 1 1; 0" )]
        //[ColorValueNoAlpha]
        //[ApplicableRangeColorValuePower( 0, 10, ApplicableRangeAttribute.ConvenientDistributionEnum.Exponential )]
        //public Reference<ColorValuePowered> Add
        //{
        //	get
        //	{
        //		if( _add.BeginGet() )
        //			Add = _add.Get( this );
        //		return _add.value;
        //	}
        //	set
        //	{
        //		if( _add.BeginSet( ref value ) )
        //		{
        //			try { AddChanged?.Invoke( this ); }
        //			finally { _add.EndSet(); }
        //		}
        //	}
        //}
        //public event Action<Component_RenderingEffect_ColorGrading> AddChanged;

        /////////////////////////////////////////

        protected override void OnSetShaderParameters(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, Component_Image actualTexture, CanvasRenderer.ShaderItem shader)
        {
            base.OnSetShaderParameters(context, frameData, actualTexture, shader);

            var texture = LookupTable.Value;

            shader.Parameters.Set("useLookupTable", texture != null ? 1.0f : -1.0f);
        }
Example #16
0
        /////////////////////////////////////////

        protected override void OnRender(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, ref Component_Image actualTexture)
        {
            base.OnRender(context, frameData, ref actualTexture);

            //PixelFormat.A8R8G8B8 );

            //bright pass
            //!!!!или A8R8G8B8?
            //R8G8B8
            var brightTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, PixelFormat.A8R8G8B8);              //!!!! PixelFormat.R8G8B8 );
            {
                context.SetViewport(brightTexture.Result.GetRenderTarget().Viewports[0]);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                shader.FragmentProgramFileName = @"Base\Shaders\Effects\Bloom\Bright_fs.sc";

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/, actualTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.Point));
                shader.Parameters.Set("brightThreshold", (float)BrightThreshold);

                context.RenderQuadToCurrentViewport(shader);
            }

            //blur
            var pipeline    = (Component_RenderingPipeline_Basic)context.RenderingPipeline;
            var blurTexture = pipeline.GaussianBlur(context, this, brightTexture, BlurFactor, BlurDownscalingMode, BlurDownscalingValue);

            context.DynamicTexture_Free(brightTexture);

            //create final
            var finalTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, actualTexture.Result.ResultFormat);

            {
                context.SetViewport(finalTexture.Result.GetRenderTarget().Viewports[0]);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                shader.FragmentProgramFileName = @"Base\Shaders\Effects\Bloom\Final_fs.sc";

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/, actualTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1 /*"bloomTexture"*/, blurTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                shader.Parameters.Set("intensity", (float)Intensity);
                shader.Parameters.Set("scale", (float)Scale);

                context.RenderQuadToCurrentViewport(shader);
            }

            //free old textures
            context.DynamicTexture_Free(actualTexture);
            context.DynamicTexture_Free(blurTexture);

            //update actual texture
            actualTexture = finalTexture;
        }
Example #17
0
        unsafe public override void Render(Component_RenderingPipeline pipeline, ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData)
        {
            UpdateProcessedCubemaps();

            if (mesh != null)
            {
                var pass = GetMaterialPass();
                if (pass != null)
                {
                    ////!!!!
                    //CreatedCubemapUpdate();

                    //!!!!double
                    Matrix4F worldMatrix = Matrix4.FromTranslate(context.Owner.CameraSettings.Position).ToMatrix4F();

                    foreach (var item in mesh.Result.MeshData.RenderOperations)
                    {
                        ParameterContainer generalContainer = new ParameterContainer();
                        generalContainer.Set("multiplier", Multiplier.Value.ToColorValue());
                        GetRotationMatrix(out var rotation);
                        generalContainer.Set("rotation", rotation);                          // Matrix3.FromRotateByZ( Rotation.Value.InRadians() ).ToMatrix3F() );

                        Component_Image tex = null;

                        //!!!!сделать GetResultEnvironmentCubemap()?
                        //!!!!!!где еще его использовать
                        if (processedEnvironmentCubemap != null)
                        {
                            tex = processedEnvironmentCubemap;
                        }
                        //else if( AnyCubemapSideIsSpecified() )
                        //	tex = createdCubemap;
                        else
                        {
                            tex = Cubemap;
                        }
                        if (tex == null)
                        {
                            tex = ResourceUtility.BlackTextureCube;
                        }

                        if (tex.Result != null && tex.Result.TextureType == Component_Image.TypeEnum.Cube)
                        {
                            var addressingMode = TextureAddressingMode.Clamp;

                            context.BindTexture(new ViewportRenderingContext.BindTextureData(0 /*"skyboxTexture"*/, tex, addressingMode, FilterOption.Linear, FilterOption.Linear, FilterOption.Linear));

                            var containers = new List <ParameterContainer>();
                            containers.Add(generalContainer);

                            Bgfx.SetTransform((float *)&worldMatrix);
                            ((Component_RenderingPipeline_Basic)pipeline).RenderOperation(context, item, pass, containers);
                        }
                    }
                }
            }
        }
Example #18
0
        public override void OnGetRenderSceneData(ViewportRenderingContext context, GetRenderSceneDataMode mode)
        {
            base.OnGetRenderSceneData(context, mode);

            if (mode == GetRenderSceneDataMode.InsideFrustum && AutoUpdate)
            {
                lastVisibleTime = Time.Current;
            }
        }
Example #19
0
        public override void OnGetRenderSceneData(ViewportRenderingContext context, GetRenderSceneDataMode mode, Component_Scene.GetObjectsInSpaceItem modeGetObjectsItem)
        {
            base.OnGetRenderSceneData(context, mode, modeGetObjectsItem);

            if (mode == GetRenderSceneDataMode.InsideFrustum && AutoUpdate)
            {
                lastVisibleTime = Time.Current;
            }
        }
Example #20
0
        /////////////////////////////////////////

        //detect what LOD is need. can be -1 when skip by visibility distance
        static int DetectDemandedLOD(ViewportRenderingContext context, Component_Mesh mesh, double objectVisibilityDistance, ref Vector3 objectPosition)
        {
            int demandLOD;

            var cameraSettings = context.Owner.CameraSettings;

            double maxDistance;

            if (mesh != null)
            {
                maxDistance = Math.Min(objectVisibilityDistance, mesh.VisibilityDistance);
            }
            else
            {
                maxDistance = objectVisibilityDistance;
            }

            if (maxDistance < cameraSettings.FarClipDistance && (cameraSettings.Position - objectPosition).LengthSquared() > maxDistance * maxDistance)
            {
                demandLOD = -1;
            }
            else
            {
                demandLOD = 0;

                if (mesh != null)
                {
                    var lods = mesh.Result.MeshData.LODs;
                    if (lods != null)
                    {
                        //!!!!что про дребежжание когда быстро туда сюда переключаться нужно?

                        var distanceSquared = (float)(objectPosition - cameraSettings.Position).LengthSquared() * context.renderingPipeline.LODScale.Value;
                        var range           = context.renderingPipeline.LODRange.Value.ToVector2I() - new Vector2I(1, 1);

                        for (int n = Math.Min(lods.Length - 1, range.Y); n >= 0; n--)
                        {
                            ref var lod = ref lods[n];

                            var lodDistanceSquared = lod.DistanceSquared;
                            if (distanceSquared > lodDistanceSquared || n <= range.X)
                            {
                                var lodMeshData = lod.Mesh?.Result?.MeshData;
                                if (lodMeshData != null)
                                {
                                    demandLOD = n + 1;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
Example #21
0
        public override void OnGetRenderSceneData(ViewportRenderingContext context, GetRenderSceneDataMode mode, Component_Scene.GetObjectsInSpaceItem modeGetObjectsItem)
        {
            var area = Parent as Component_Area;

            if (area != null)
            {
                if (!area.CheckNeedShowDevelopmentDataOfAreaAndPoints(context, mode))
                {
                    var context2 = context.objectInSpaceRenderingContext;
                    context2.disableShowingLabelForThisObject = true;
                }
            }
        }
Example #22
0
        protected override void OnRender(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, ref Component_Image actualTexture)
        {
            base.OnRender(context, frameData, ref actualTexture);

            //create final
            var finalTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, PixelFormat.A8R8G8B8);

            {
                context.SetViewport(finalTexture.Result.GetRenderTarget().Viewports[0]);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                shader.FragmentProgramFileName = @"Base\Shaders\Effects\ShowRenderTarget_fs.sc";

                string textureName = "";
                switch (Texture.Value)
                {
                case TextureType.Normal: textureName = "normalTexture"; break;

                case TextureType.Depth: textureName = "depthTexture"; break;

                case TextureType.MotionVector: textureName = "motionTexture"; break;
                }
                context.objectsDuringUpdate.namedTextures.TryGetValue(textureName, out var showTexture);
                if (showTexture == null)
                {
                    context.DynamicTexture_Free(finalTexture);
                    return;
                }

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/, actualTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1 /*"showTexture"*/, showTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                shader.Parameters.Set("intensity", (float)Intensity);
                shader.Parameters.Set("nearClipDistance", (float)context.Owner.CameraSettings.NearClipDistance);
                shader.Parameters.Set("farClipDistance", (float)context.Owner.CameraSettings.FarClipDistance);
                shader.Parameters.Set("mode", (float)Texture.Value);
                shader.Parameters.Set("depthMultiplier", (float)DepthMultiplier);
                shader.Parameters.Set("motionMultiplier", (float)MotionMultiplier);

                context.RenderQuadToCurrentViewport(shader);
            }

            //free old textures
            context.DynamicTexture_Free(actualTexture);

            //update actual texture
            actualTexture = finalTexture;
        }
Example #23
0
        /////////////////////////////////////////

        void CheckVisibilityScreenPosition(ViewportRenderingContext context, Vector3 position, out bool gotScreenPosition, out bool insideScreen)
        {
            gotScreenPosition = false;
            insideScreen      = false;

            if (context.Owner.CameraSettings.ProjectToScreenCoordinates(position, out var screenLightPosition))
            {
                gotScreenPosition = true;
                if (new Rectangle(0, 0, 1, 1).Contains(screenLightPosition))
                {
                    insideScreen = true;
                }
            }
        }
Example #24
0
        public override void OnGetRenderSceneData(ViewportRenderingContext context, GetRenderSceneDataMode mode)
        {
            base.OnGetRenderSceneData(context, mode);

            if (mode == GetRenderSceneDataMode.InsideFrustum)
            {
                var context2 = context.objectInSpaceRenderingContext;

                //context.

                bool show = (ParentScene.GetDisplayDevelopmentDataInThisApplication() && ParentScene.DisplayCameras) ||
                            context2.selectedObjects.Contains(this) || context2.canSelectObjects.Contains(this) || context2.objectToCreate == this;
                if (show)
                {
                    var skip = false;

                    var cameraSettings = context.Owner.CameraSettings;
                    //!!!!
                    if ((cameraSettings.Position - TransformV.Position).Length() < 0.5)
                    {
                        skip = true;
                    }

                    if (!skip && context2.displayCamerasCounter < context2.displayCamerasMax)
                    {
                        context2.displayCamerasCounter++;

                        ColorValue color;
                        if (context2.selectedObjects.Contains(this))
                        {
                            color = ProjectSettings.Get.SelectedColor;
                        }
                        else if (context2.canSelectObjects.Contains(this))
                        {
                            color = ProjectSettings.Get.CanSelectColor;
                        }
                        else
                        {
                            color = ProjectSettings.Get.SceneShowLightColor;
                        }

                        var viewport = context.Owner;
                        viewport.Simple3DRenderer.SetColor(color, color * ProjectSettings.Get.HiddenByOtherObjectsColorMultiplier);
                        DebugDraw(viewport);
                    }
                }
                //if( !show )
                //	context.disableShowingLabelForThisObject = true;
            }
        }
Example #25
0
        public virtual void Render(ViewportRenderingContext context, out int verticesRendered)
        {
            verticesRendered = 0;

            //var context2 = context.objectInSpaceRenderingContext;
            //var renderer = context.Owner.Simple3DRenderer;

            //if( !Broken )
            //{
            //	Vec3 anchor = Anchor;
            //	Vec3 halfDir = Axis.Direction * .5f;
            //	debugGeometry.AddLine( anchor - halfDir, anchor + halfDir );
            //}
        }
Example #26
0
 protected virtual void Render(ViewportRenderingContext context, Vector2 screenPosition)
 {
     if (!string.IsNullOrEmpty(Text))
     {
         if (Multiline)
         {
             RenderMultilineEnabled(context, screenPosition);
         }
         else
         {
             RenderMultilineDisabled(context, screenPosition);
         }
     }
 }
Example #27
0
 protected override void OnRender(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, ref Component_Image actualTexture)
 {
     if (Technique.Value != TechniqueEnum.None)
     {
         if (Technique.Value == TechniqueEnum.FXAA)
         {
             RenderFXAA(context, frameData, ref actualTexture, Intensity);
         }
         else
         {
             RenderDownscale(context, frameData, actualTexture.Result.ResultSize, ref actualTexture);
         }
     }
 }
        public override void OnGetRenderSceneData(ViewportRenderingContext context, GetRenderSceneDataMode mode, Component_Scene.GetObjectsInSpaceItem modeGetObjectsItem)
        {
            base.OnGetRenderSceneData(context, mode, modeGetObjectsItem);

            if (mode == GetRenderSceneDataMode.InsideFrustum)
            {
                var context2 = context.objectInSpaceRenderingContext;

                if (!ParentScene.GetDisplayDevelopmentDataInThisApplication())
                {
                    context2.disableShowingLabelForThisObject = true;
                }
            }
        }
Example #29
0
        /////////////////////////////////////////

        protected override void OnRender(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, ref Component_Image actualTexture)
        {
            context.objectsDuringUpdate.namedTextures.TryGetValue("motionTexture", out var motionTexture);

            if (motionTexture != null)
            {
                //create final
                var finalTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, actualTexture.Result.ResultFormat);
                {
                    context.SetViewport(finalTexture.Result.GetRenderTarget().Viewports[0]);

                    var shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\MotionBlur_fs.sc";

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/, actualTexture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1 /*"motionTexture"*/, motionTexture,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                    shader.Parameters.Set("intensity", (float)Intensity);

                    var multiplier = 0.0;
                    if (context.Owner.LastUpdateTimeStep != 0)
                    {
                        multiplier = (1.0 / context.Owner.LastUpdateTimeStep) / 45.0;
                    }
                    multiplier *= Multiplier.Value;

                    //fix initial rattling
                    if (context.Owner.LastUpdateTimeStep > 0.1)
                    {
                        multiplier = 0;
                    }

                    shader.Parameters.Set("motionBlurMultiplier", (float)multiplier);

                    var size = actualTexture.Result.ResultSize;
                    shader.Parameters.Set("viewportSize", new Vector4(size.X, size.Y, 1.0 / (double)size.X, 1.0 / (double)size.Y).ToVector4F());

                    context.RenderQuadToCurrentViewport(shader);
                }

                //free old textures
                context.DynamicTexture_Free(actualTexture);

                //update actual texture
                actualTexture = finalTexture;
            }
        }
        ////!!!!
        ///// <summary>Computes the convex hull of a polygon, in clockwise order in a Y-up
        ///// coordinate system (counterclockwise in a Y-down coordinate system).</summary>
        ///// <remarks>Uses the Monotone Chain algorithm, a.k.a. Andrew's Algorithm.</remarks>
        //public static List<Vector2> ComputeConvexHull( IEnumerable<Vector2> points )
        //{
        //	var list = new List<Vector2>( points );
        //	return ComputeConvexHull( list, true );
        //}
        //public static List<Vector2> ComputeConvexHull( List<Vector2> points, bool sortInPlace )//= false )
        //{
        //	if( !sortInPlace )
        //		points = new List<Vector2>( points );

        //	points.Sort( ( a, b ) => a.X == b.X ? a.Y.CompareTo( b.Y ) : ( a.X > b.X ? 1 : -1 ) );

        //	// Importantly, DList provides O(1) insertion at beginning and end
        //	List<Vector2> hull = new List<Vector2>();
        //	int L = 0, U = 0; // size of lower and upper hulls

        //	// Builds a hull such that the output polygon starts at the leftmost point.
        //	for( int i = points.Count - 1; i >= 0; i-- )
        //	{
        //		Vector2 p = points[ i ], p1;

        //		// build lower hull (at end of output list)
        //		while( L >= 2 && ( p1 = hull.Last ).Sub( hull[ hull.Count - 2 ] ).Cross( p.Sub( p1 ) ) >= 0 )
        //		{
        //			hull.RemoveAt( hull.Count - 1 );
        //			L--;
        //		}
        //		hull.PushLast( p );
        //		L++;

        //		// build upper hull (at beginning of output list)
        //		while( U >= 2 && ( p1 = hull.First ).Sub( hull[ 1 ] ).Cross( p.Sub( p1 ) ) <= 0 )
        //		{
        //			hull.RemoveAt( 0 );
        //			U--;
        //		}
        //		if( U != 0 ) // share the point added above, except in the first iteration
        //			hull.PushFirst( p );
        //		U++;
        //	}
        //	hull.RemoveAt( hull.Count - 1 );
        //	return hull;
        //}

        void GetDirectionalLightShadowsCascadeHullPlanes(ViewportRenderingContext context, LightItem lightItem, int cascadeIndex, out Plane[] planes, out Bounds bounds)
        {
            var cornerPoints = GetDirectionalLightShadowsCameraCornerPoints(context, cascadeIndex);

            var inputVertices = new List <Vector3>(cornerPoints.Length * 2);

            inputVertices.AddRange(cornerPoints);
            foreach (var point in cornerPoints)
            {
                inputVertices.Add(point - lightItem.data.Rotation.ToQuaternion().GetForward() * ShadowDirectionalLightExtrusionDistance);
            }

            var projectMatrix   = lightItem.data.Rotation.ToQuaternion().GetInverse();
            var unprojectMatrix = lightItem.data.Rotation.ToQuaternion();

            var projected2D = new Vector2[cornerPoints.Length];

            for (int n = 0; n < projected2D.Length; n++)
            {
                var p = projectMatrix * cornerPoints[n];
                projected2D[n] = new Vector2(p.Y, p.Z);
            }

            var convex = MathAlgorithms.GetConvexByPoints(projected2D);

            var planesList = new List <Plane>(convex.Count);

            for (int n = 0; n < convex.Count; n++)
            {
                var p1 = convex[n];
                var p2 = convex[(n + 1) % convex.Count];

                var u1 = unprojectMatrix * new Vector3(0, p1.X, p1.Y);
                var u2 = unprojectMatrix * new Vector3(0, p2.X, p2.Y);
                var u3 = unprojectMatrix * new Vector3(1, p2.X, p2.Y);

                planesList.Add(Plane.FromPoints(u1, u3, u2));
            }
            planes = planesList.ToArray();

            ////!!!!глючит
            //ConvexHullAlgorithm.Create( inputVertices.ToArray(), out planes );

            bounds = Bounds.Cleared;
            foreach (var p in inputVertices)
            {
                bounds.Add(p);
            }
        }