コード例 #1
0
        public void WindowMovedOrResized(Vector2I size)          // bool fullScreen )//, Vec2I windowSize )
        {
            if (Disposed)
            {
                return;
            }

            EngineThreading.CheckMainThread();

            this.size = size;

            //!!!!по идее не во всех графических API надо пересоздавать
            if (thisIsApplicationWindow)
            {
                Bgfx.Reset(size.X, size.Y, RenderingSystem.GetApplicationWindowResetFlags());
            }
            else
            {
                frameBuffer.Dispose();
                frameBuffer = new FrameBuffer(windowHandle, size.X, size.Y);
            }

            //update aspect ratio
            foreach (Viewport viewport in viewports)
            {
                viewport.UpdateAspectRatio();
            }
        }
コード例 #2
0
        /////////////////////////////////////////

        public MultiRenderTarget MultiRenderTarget_Create(MultiRenderTarget.Item[] items)
        {
            var mrt = RenderingSystem.CreateMultiRenderTarget(items);

            mrt.AddViewport(false, false);
            //var item = new MultiRenderTargetItem( targets, mrt );
            multiRenderTargets.Add(mrt);
            return(mrt);
        }
コード例 #3
0
        public void WindowMovedOrResized(Vector2I size)          // bool fullScreen )//, Vec2I windowSize )
        {
            if (Disposed)
            {
                return;
            }

            EngineThreading.CheckMainThread();

            //unsafe
            //{
            //!!!!было
            //MyOgreSceneManager.destroyShadowTextures( SceneManager.realObject );

            //!!!!как теперь? текстуры композитинга удалять? где еще?
            //MyOgreSceneManager.destroyAdditionalMRTs( SceneManager.realObject );
            //}

            //foreach( Viewport viewport in viewports )
            //{
            //   foreach( CompositorInstance instance in viewport.CompositorInstances )
            //      instance.DoRealEnabledUpdate( false );
            //}

            this.size = size;

            //!!!!по идее не во всех графических API надо пересоздавать
            if (thisIsApplicationWindow)
            {
                Bgfx.Reset(size.X, size.Y, RenderingSystem.GetApplicationWindowResetFlags());
            }
            else
            {
                frameBuffer.Dispose();
                frameBuffer = new FrameBuffer(windowHandle, size.X, size.Y);
            }

            //unsafe
            //{
            //	OgreRenderWindow.windowMovedOrResized( realObjectRenderWindow, fullScreen );//, windowSize.X, windowSize.Y );
            //}
            //GetSizeFromNative();

            //update aspect ratio
            foreach (Viewport viewport in viewports)
            {
                viewport.UpdateAspectRatio();
            }
        }
コード例 #4
0
            public void Generate(Component_Mesh mesh, string writeRealFileName)
            {
                this.mesh = mesh;
                Init();

                //create scene
                var scene = CreateScene(false);

                if (mesh != null)
                {
                    var objInSpace = scene.CreateComponent <Component_MeshInSpace>();
                    objInSpace.Mesh = mesh;
                }
                scene.Enabled = true;

                //generate an image
                {
                    viewport.Update(true);

                    //clear temp data
                    viewport.RenderingContext.MultiRenderTarget_DestroyAll();
                    viewport.RenderingContext.DynamicTexture_DestroyAll();

                    texture.Result.GetRealObject(true).BlitTo(viewport.RenderingContext.CurrentViewNumber, textureRead.Result.GetRealObject(true), 0, 0);

                    var demandedFrame = textureRead.Result.GetRealObject(true).Read(imageData, 0);

                    while (RenderingSystem.CallBgfxFrame() < demandedFrame)
                    {
                    }
                }

                //write png
                if (!ImageUtility.Save(writeRealFileName, imageData, imageSizeRender, 1, imageFormat, 1, 0, out var error))
                {
                    throw new Exception(error);
                }

                DetachAndOrDestroyScene();
                Shutdown();
            }
コード例 #5
0
ファイル: LensEffects.cs プロジェクト: zwiglm/NeoAxisEngine
        protected override void OnRender(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, ref Component_Image actualTexture)
        {
            base.OnRender(context, frameData, ref actualTexture);

            var pipeline = context.RenderingPipeline as Component_RenderingPipeline_Basic;

            if (pipeline == null)
            {
                return;
            }
            var frameData2 = frameData as Component_RenderingPipeline_Basic.FrameData;

            if (frameData2 == null)
            {
                return;
            }
            if (Intensity.Value == 0)
            {
                return;
            }

            bool skip = true;

            foreach (var lightIndex in frameData2.LightsInFrustumSorted)
            {
                var lightItem = frameData2.Lights[lightIndex];

                if (lightItem.data.children != null)
                {
                    foreach (var child in lightItem.data.children)
                    {
                        var lensFlares = child as Component_LensFlares;
                        if (lensFlares != null)
                        {
                            skip = false;
                            break;
                        }
                    }
                }
            }
            if (skip)
            {
                return;
            }

            //init context data
            ViewportRenderingContextData contextData;

            if (context.anyData.TryGetValue("LensEffects", out var contextData2))
            {
                contextData = (ViewportRenderingContextData)contextData2;
            }
            else
            {
                contextData = new ViewportRenderingContextData();
                context.anyData["LensEffects"] = contextData;
            }

            //update context data light items
            contextData.Update(context.Owner.LastUpdateTimeStep, Intensity, FadeSpeed);

            //create copy
            var newTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, actualTexture.Result.ResultFormat, createSimple3DRenderer: true, createCanvasRenderer: true);

            var viewport = newTexture.Result.GetRenderTarget().Viewports[0];
            //!!!!double precision
            Matrix4F viewMatrix       = context.Owner.CameraSettings.ViewMatrix.ToMatrix4F();
            Matrix4F projectionMatrix = context.Owner.CameraSettings.ProjectionMatrix.ToMatrix4F();

            context.SetViewport(viewport, viewMatrix, projectionMatrix);

            pipeline.CopyToCurrentViewport(context, actualTexture);

            var simple3DRenderer = viewport.Simple3DRenderer;
            var canvasRenderer   = viewport.CanvasRenderer;

            //render
            foreach (var lightIndex in frameData2.LightsInFrustumSorted)
            {
                var lightItem = frameData2.Lights[lightIndex];

                if (lightItem.data.children != null)
                {
                    foreach (var child in lightItem.data.children)
                    {
                        var lensFlares = child as Component_LensFlares;
                        if (lensFlares != null)
                        {
                            var light = lightItem.data.Creator as Component_Light;
                            if (light != null)
                            {
                                CheckVisibilityScreenPosition(context, lightItem.data.Position, out var gotScreenPosition, out var insideScreen);

                                if (gotScreenPosition)
                                {
                                    //update
                                    {
                                        switch (CheckVisibilityMethod.Value)
                                        {
                                        case CheckVisibilityMethodEnum.OcclusionQuery:
                                        {
                                            var parameter = (contextData, light);
                                            if (RenderingSystem.TryCreateOcclusionQuery(OcclusionQueryCallback, parameter, out var query))
                                            {
                                                var thickness = context.Owner.Simple3DRenderer.GetThicknessByPixelSize(lightItem.data.Position, 5);
                                                var bounds    = new Bounds(lightItem.data.Position);
                                                bounds.Expand(thickness * 0.5);

                                                simple3DRenderer.SetColor(new ColorValue(1, 0, 0));
                                                simple3DRenderer.SetOcclusionQuery(query);
                                                simple3DRenderer.AddBounds(bounds, true);
                                                //simple3DRenderer.AddSphere( new Sphere( lightItem.data.Position, 0.5 ), 4, true );
                                                simple3DRenderer.SetOcclusionQuery(null);
                                            }
                                        }
                                        break;

                                        case CheckVisibilityMethodEnum.PhysicsRayCast:
                                            if (CheckVisibilityPhysics(context, lightItem.data.Position))
                                            {
                                                contextData.UpdateLastTimeVisible(light);
                                            }
                                            break;
                                        }
                                    }

                                    //render
                                    var intensity = contextData.GetIntensity(light);
                                    if (intensity > 0)
                                    {
                                        //simple3DRenderer.SetColor( new ColorValue( 1, 0, 0 ) );
                                        //simple3DRenderer.AddSphere( new Sphere( lightItem.data.Position, 0.5 ), 10, true );

                                        lensFlares.RenderUI(canvasRenderer, lightItem.data, context.Owner, intensity);
                                    }
                                }
                                else
                                {
                                    contextData.Remove(light);
                                }
                            }
                        }
                    }
                }
            }

            //render
            if (simple3DRenderer._ViewportRendering_PrepareRenderables())
            {
                simple3DRenderer._ViewportRendering_RenderToCurrentViewport(context);
                simple3DRenderer._Clear();
            }
            canvasRenderer._ViewportRendering_RenderToCurrentViewport(context, true, context.Owner.LastUpdateTime);


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

            //update actual texture
            actualTexture = newTexture;
        }
コード例 #6
0
        public void UpdateCaptureCubemap()
        {
            if (Mode.Value != ModeEnum.Capture)
            {
                return;
            }

            Component_Image texture     = null;
            Component_Image textureRead = null;

            try
            {
                //create

                var resolution = Resolution.Value;
                var hdr        = HDR.Value;

                var size = int.Parse(resolution.ToString().Replace("_", ""));
                //!!!!16 бит достаточно, тогда нужно поддержку для Image2D
                PixelFormat format = hdr ? PixelFormat.Float32RGBA : PixelFormat.A8R8G8B8;
                //PixelFormat format = hdr ? PixelFormat.Float16RGBA : PixelFormat.A8R8G8B8;

                texture               = ComponentUtility.CreateComponent <Component_Image>(null, true, false);
                texture.CreateType    = Component_Image.TypeEnum._2D;
                texture.CreateSize    = new Vector2I(size, size);
                texture.CreateMipmaps = false;
                texture.CreateFormat  = format;
                texture.CreateUsage   = Component_Image.Usages.RenderTarget;
                texture.CreateFSAA    = 0;
                texture.Enabled       = true;

                var renderTexture = texture.Result.GetRenderTarget(0, 0);
                //!!!!
                var viewport = renderTexture.AddViewport(true, false);
                //var viewport = renderTexture.AddViewport( false, false );
                viewport.Mode          = Viewport.ModeEnum.ReflectionProbeCubemap;
                viewport.AttachedScene = ParentScene;

                textureRead               = ComponentUtility.CreateComponent <Component_Image>(null, true, false);
                textureRead.CreateType    = Component_Image.TypeEnum._2D;
                textureRead.CreateSize    = new Vector2I(size, size);
                textureRead.CreateMipmaps = false;
                textureRead.CreateFormat  = format;
                textureRead.CreateUsage   = Component_Image.Usages.ReadBack | Component_Image.Usages.BlitDestination;
                textureRead.CreateFSAA    = 0;
                textureRead.Enabled       = true;
                //!!!!
                textureRead.Result.PrepareNativeObject();

                //render
                var image2D = new ImageUtility.Image2D(PixelFormat.Float32RGB, new Vector2I(size * 4, size * 3));

                var position = Transform.Value.Position;

                for (int face = 0; face < 6; face++)
                {
                    Vector3 dir = Vector3.Zero;
                    Vector3 up  = Vector3.Zero;

                    //flipped
                    switch (face)
                    {
                    case 0: dir = -Vector3.YAxis; up = Vector3.ZAxis; break;

                    case 1: dir = Vector3.YAxis; up = Vector3.ZAxis; break;

                    case 2: dir = Vector3.ZAxis; up = -Vector3.XAxis; break;

                    case 3: dir = -Vector3.ZAxis; up = Vector3.XAxis; break;

                    case 4: dir = Vector3.XAxis; up = Vector3.ZAxis; break;

                    case 5: dir = -Vector3.XAxis; up = Vector3.ZAxis; break;
                    }

                    //!!!!renderingPipelineOverride

                    var scene        = ParentScene;
                    var cameraEditor = scene.Mode.Value == Component_Scene.ModeEnum._2D ? scene.CameraEditor2D.Value : scene.CameraEditor.Value;
                    if (cameraEditor == null)
                    {
                        cameraEditor = new Component_Camera();
                    }

                    var cameraSettings = new Viewport.CameraSettingsClass(viewport, 1, 90, NearClipPlane.Value, FarClipPlane.Value, position, dir, up, ProjectionType.Perspective, 1, cameraEditor.Exposure, cameraEditor.EmissiveFactor, renderSky: RenderSky);

                    viewport.Update(true, cameraSettings);

                    //clear temp data
                    viewport.RenderingContext.MultiRenderTarget_DestroyAll();
                    viewport.RenderingContext.DynamicTexture_DestroyAll();

                    texture.Result.GetRealObject(true).BlitTo(viewport.RenderingContext.CurrentViewNumber, textureRead.Result.GetRealObject(true), 0, 0);

                    //get data
                    var totalBytes = PixelFormatUtility.GetNumElemBytes(format) * size * size;
                    var data       = new byte[totalBytes];
                    unsafe
                    {
                        fixed(byte *pBytes = data)
                        {
                            var demandedFrame = textureRead.Result.GetRealObject(true).Read((IntPtr)pBytes, 0);

                            while (RenderingSystem.CallBgfxFrame() < demandedFrame)
                            {
                            }
                        }
                    }

                    Vector2I index = Vector2I.Zero;
                    switch (face)
                    {
                    case 1: index = new Vector2I(2, 1); break;

                    case 0: index = new Vector2I(0, 1); break;

                    case 2: index = new Vector2I(1, 0); break;

                    case 3: index = new Vector2I(1, 2); break;

                    case 4: index = new Vector2I(1, 1); break;

                    case 5: index = new Vector2I(3, 1); break;
                    }
                    //switch( face )
                    //{
                    //case 0: index = new Vector2I( 2, 1 ); break;
                    //case 1: index = new Vector2I( 0, 1 ); break;
                    //case 2: index = new Vector2I( 1, 0 ); break;
                    //case 3: index = new Vector2I( 1, 2 ); break;
                    //case 4: index = new Vector2I( 1, 1 ); break;
                    //case 5: index = new Vector2I( 3, 1 ); break;
                    //}

                    var faceImage = new ImageUtility.Image2D(format, new Vector2I(size, size), data);

                    //flip by X
                    var faceImageFlip = new ImageUtility.Image2D(format, new Vector2I(size, size));
                    for (int y = 0; y < size; y++)
                    {
                        for (int x = 0; x < size; x++)
                        {
                            var pixel = faceImage.GetPixel(new Vector2I(x, y));
                            faceImageFlip.SetPixel(new Vector2I(size - 1 - x, y), pixel);
                        }
                    }

                    image2D.Blit(index * size, faceImageFlip);
                }

                //reset alpha channel
                for (int y = 0; y < image2D.Size.Y; y++)
                {
                    for (int x = 0; x < image2D.Size.X; x++)
                    {
                        var pixel = image2D.GetPixel(new Vector2I(x, y));
                        pixel.W = 1.0f;
                        image2D.SetPixel(new Vector2I(x, y), pixel);
                    }
                }

                var destRealFileName = VirtualPathUtility.GetRealPathByVirtual(GetDestVirtualFileName());

                if (!Directory.Exists(Path.GetDirectoryName(destRealFileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(destRealFileName));
                }

                if (!ImageUtility.Save(destRealFileName, image2D.Data, image2D.Size, 1, image2D.Format, 1, 0, out var error))
                {
                    throw new Exception(error);
                }

                //delete Gen files
                var names = new string[] { "_Gen.info", "_GenEnv.dds", "_GenIrr.dds" };
                foreach (var name in names)
                {
                    var fileName2 = VirtualPathUtility.GetRealPathByVirtual(destRealFileName + name);
                    if (File.Exists(fileName2))
                    {
                        File.Delete(fileName2);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
            }
            finally
            {
                texture?.Dispose();
                textureRead?.Dispose();
            }

            processedCubemapNeedUpdate = true;
        }