예제 #1
0
 public void Render(RenderStage stage)
 {
     if (stage == RenderStage.PREGUI)
     {
         window.Draw(sprBackground);
     }
 }
예제 #2
0
        private void DrawChunks(GraphicsDevice device, ChunkData[] chunks, Effect effect, RenderStage stage)
        {
            for (var index = 0; index < chunks.Length; index++)
            {
                var chunk = chunks[index];
                if (chunk == null)
                {
                    continue;
                }

                chunk.Draw(device, stage, effect);
            }
        }
예제 #3
0
 public RenderViewFeatureStage(RenderStage renderStage, int renderNodeStart, int renderNodeEnd)
 {
     RenderStage     = renderStage;
     RenderNodeStart = renderNodeStart;
     RenderNodeEnd   = renderNodeEnd;
 }
예제 #4
0
 public SpineSprite()
 {
     RenderStage = RenderStage.Bloom;
     Enabled     = true;
     Visible     = true;
 }
        protected override Task <bool> Initialize(EditorServiceGame editorGame)
        {
            if (editorGame == null)
            {
                throw new ArgumentNullException(nameof(editorGame));
            }
            game = (EntityHierarchyEditorGame)editorGame;

            var pickingRenderStage = game.EditorSceneSystem.GraphicsCompositor.RenderStages.First(x => x.Name == "Picking");
            // TODO: Move selection/wireframe render stage in EditorGameComponentGizmoService (as last render step?)
            var selectionRenderStage = new RenderStage("SelectionGizmo", "Wireframe");

            selectionRenderStage.Filter = new WireframeFilter();

            var lightProbeGizmoRenderStage     = new RenderStage("LightProbeGizmo", "Main");
            var lightProbeWireframeRenderStage = new RenderStage("LightProbeWireframe", "Main");

            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(selectionRenderStage);
            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(lightProbeGizmoRenderStage);
            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(lightProbeWireframeRenderStage);

            // Meshes
            var meshRenderFeature = game.EditorSceneSystem.GraphicsCompositor.RenderFeatures.OfType <MeshRenderFeature>().First();

            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect,
                RenderGroup = LightProbeGizmo.LightProbeGroupMask,
                RenderStage = lightProbeGizmoRenderStage
            });
            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect + ".Picking",
                RenderGroup = LightProbeGizmo.LightProbeGroupMask,
                RenderStage = pickingRenderStage,
            });
            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect + ".Wireframe",
                RenderGroup = LightProbeGizmo.LightProbeGroupMask,
                RenderStage = selectionRenderStage,
            });
            meshRenderFeature.RenderFeatures.Add(new WireframeRenderFeature());

            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect,
                RenderGroup = LightProbeWireGroupMask,
                RenderStage = lightProbeWireframeRenderStage,
            });
            meshRenderFeature.PipelineProcessors.Add(new AntiAliasLinePipelineProcessor {
                RenderStage = lightProbeWireframeRenderStage
            });
            var editorCompositor = (EditorTopLevelCompositor)game.EditorSceneSystem.GraphicsCompositor.Game;

            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = lightProbeWireframeRenderStage, Name = "LightProbe Wireframe Gizmos"
            });
            editorCompositor.PostGizmoCompositors.Add(new ClearRenderer {
                ClearFlags = ClearRendererFlags.DepthOnly
            });
            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = lightProbeGizmoRenderStage, Name = "LightProbe Gizmos"
            });
            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = selectionRenderStage, Name = "LightProbe Selection Gizmo"
            });

            // Add debug entity
            debugEntity = new Entity("Navigation debug entity");
            game.EditorScene.Entities.Add(debugEntity);

            var color = Color.Yellow;

            color.A           = 0x9F;
            wireframeMaterial = CreateDebugMaterial(color);

            game.Script.AddTask(Update);

            return(Task.FromResult(true));
        }
예제 #6
0
        protected override Entity Create()
        {
            base.Create();

            var entity = new Entity("Space Marker");

            cameraComponent = new CameraComponent
            {
                UseCustomAspectRatio = true,
                AspectRatio          = 1.0f,
                NearClipPlane        = 0.1f,
                FarClipPlane         = 1000.0f,
                UseCustomViewMatrix  = true,
                VerticalFieldOfView  = VerticalFieldOfView
            };
            entity.Add(cameraComponent);

            // Add a renderer on the left bottom size
            var cameraOrientationGizmoRenderStage = new RenderStage("CameraOrientationGizmo", "Main");

            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(cameraOrientationGizmoRenderStage);

            var meshRenderFeature = game.EditorSceneSystem.GraphicsCompositor.RenderFeatures.OfType <MeshRenderFeature>().First();

            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect,
                RenderGroup = SpaceMarkerGroupMask,
                RenderStage = cameraOrientationGizmoRenderStage
            });

            var editorCompositor = (EditorTopLevelCompositor)game.EditorSceneSystem.GraphicsCompositor.Game;

            editorCompositor.PostGizmoCompositors.Add(new ClearRenderer {
                ClearFlags = ClearRendererFlags.DepthOnly
            });
            editorCompositor.PostGizmoCompositors.Add(new GizmoViewportRenderer
            {
                Name             = "Render Spacemarker",
                ViewportSize     = ViewportSize,
                ViewportPosition = new Vector2(0.0f, 1.0f),
                Camera           = cameraComponent,
                Content          = new SceneRendererCollection
                {
                    new SingleStageRenderer {
                        RenderStage = cameraOrientationGizmoRenderStage
                    },
                    new DelegateSceneRenderer(RenderSpaceMarkerAxisNames),
                },
            });

            // create the default fonts
            var fontItem = OfflineRasterizedSpriteFontFactory.Create();

            fontItem.FontType.Size = 8;
            defaultFont            = OfflineRasterizedFontCompiler.Compile(Services.GetService <IFontFactory>(), fontItem, GraphicsDevice.ColorSpace == ColorSpace.Linear);

            // create the sprite batch use to draw text
            spriteBatch = new SpriteBatch(GraphicsDevice)
            {
                DefaultDepth = 1
            };

            var rotations = new[] { Vector3.Zero, new Vector3(0, 0, MathUtil.Pi / 2), new Vector3(0, -MathUtil.Pi / 2f, 0) };
            var coneMesh  = GeometricPrimitive.Cone.New(GraphicsDevice, ConeRadius, ConeHeigth, GizmoTessellation).ToMeshDraw();
            var bodyMesh  = GeometricPrimitive.Cylinder.New(GraphicsDevice, BodyLength, BodyRadius, GizmoTessellation).ToMeshDraw();

            // create the axis arrows
            for (int axis = 0; axis < 3; ++axis)
            {
                var material   = GetAxisDefaultMaterial(axis);
                var coneEntity = new Entity("ArrowCone" + axis)
                {
                    new ModelComponent {
                        Model = new Model {
                            material, new Mesh {
                                Draw = coneMesh
                            }
                        }, RenderGroup = RenderGroup
                    }
                };
                var bodyEntity = new Entity("ArrowBody" + axis)
                {
                    new ModelComponent {
                        Model = new Model {
                            material, new Mesh {
                                Draw = bodyMesh
                            }
                        }, RenderGroup = RenderGroup
                    }
                };

                coneEntity.Transform.Position.X       = BodyLength + ConeHeigth * 0.5f;
                bodyEntity.Transform.Position.X       = BodyLength / 2;
                coneEntity.Transform.Rotation         = Quaternion.RotationZ(-MathUtil.Pi / 2);
                bodyEntity.Transform.RotationEulerXYZ = -MathUtil.Pi / 2 * Vector3.UnitZ;

                // create the arrow entity composed of the cone and bode
                var arrowEntity = new Entity("ArrowEntity" + axis);
                arrowEntity.Transform.Children.Add(coneEntity.Transform);
                arrowEntity.Transform.Children.Add(bodyEntity.Transform);
                arrowEntity.Transform.RotationEulerXYZ = rotations[axis];

                // Add the arrow entity to the gizmo entity
                entity.AddChild(arrowEntity);
            }

            return(entity);
        }
예제 #7
0
 private ChunkRenderStage CreateRenderStage(RenderStage arg)
 {
     return(new ChunkRenderStage(this));
 }
예제 #8
0
        public override async Task Execute()
        {
            //setup rendering in the debug entry point if we have it
            var compositor    = SceneSystem.GraphicsCompositor;
            var debugRenderer =
                ((compositor.Game as SceneCameraRenderer)?.Child as SceneRendererCollection)?.Children.Where(
                    x => x is DebugRenderer).Cast <DebugRenderer>().FirstOrDefault();

            if (debugRenderer == null)
            {
                return;
            }

            // HACK: renamed effectSlotName 'Main' to fix Z fighting
            var shapesRenderState = new RenderStage("PhysicsDebugShapes", "Mainn");

            compositor.RenderStages.Add(shapesRenderState);
            var meshRenderFeature = compositor.RenderFeatures.OfType <MeshRenderFeature>().First();

            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = "XenkoForwardShadingEffect",
                RenderGroup = (RenderGroupMask)(1 << (int)RenderGroup),
                RenderStage = shapesRenderState,
            });
            meshRenderFeature.PipelineProcessors.Add(new WireframePipelineProcessor {
                RenderStage = shapesRenderState
            });
            debugRenderer.DebugRenderStages.Add(shapesRenderState);

            var simulation = this.GetSimulation();

            if (simulation != null)
            {
                simulation.ColliderShapesRenderGroup = RenderGroup;
            }

            var enabled = false;

            while (Game.IsRunning)
            {
                if (Input.IsKeyDown(Keys.LeftShift) && Input.IsKeyDown(Keys.LeftCtrl) && Input.IsKeyReleased(Keys.O))
                {
                    if (simulation != null)
                    {
                        if (enabled)
                        {
                            simulation.ColliderShapesRendering = false;
                            enabled = false;
                        }
                        else
                        {
                            simulation.ColliderShapesRendering = true;
                            enabled = true;
                        }
                    }
                }

                await Script.NextFrame();
            }
        }
예제 #9
0
        private int DrawChunks(GraphicsDevice device, ChunkData[] chunks, Effect effect, RenderStage stage)
        {
            int verticeCount = 0;

            for (var index = 0; index < chunks.Length; index++)
            {
                var chunk = chunks[index];
                if (chunk == null)
                {
                    continue;
                }

                if (chunk.Draw(device, stage, effect, out var vertexCount))
                {
                    verticeCount += vertexCount;
                }
            }

            return(verticeCount);
        }
예제 #10
0
 public Text SetRenderStage(RenderStage value)
 {
     RenderStage = value; return(this);
 }
예제 #11
0
        private void DrawWindowArea(IWindowArea area, int _x, int _y, Rectangle frame, RenderStage stage)
        {
            var state  = Mouse.GetState();
            var mouse  = new Point(state.X, state.Y);
            var scale  = new Point((int)(16 * Game.ScaleFactor * 2), (int)(16 * Game.ScaleFactor * 2));
            var origin = new Point((int)(
                                       Game.GraphicsDevice.Viewport.Width / 2 - Scale(frame.Width / 2) + Scale(_x)),
                                   (int)(Game.GraphicsDevice.Viewport.Height / 2 - Scale(frame.Height / 2) + Scale(_y)));

            for (var i = 0; i < area.Length; i++)
            {
                var item = area[i];
                var x    = (int)(i % area.Width * Scale(18));
                var y    = (int)(i / area.Width * Scale(18));
                if (area is CraftingWindowArea)
                {
                    // hack
                    if (i == 0)
                    {
                        if (area.Width == 2)
                        {
                            x = (int)Scale(144 - _x);
                            y = (int)Scale(36 - _y);
                        }
                        else
                        {
                            x = (int)Scale(124 - _x);
                            y = (int)Scale(35 - _y);
                        }
                    }
                    else
                    {
                        i--;
                        x = (int)(i % area.Width * Scale(18));
                        y = (int)(i / area.Width * Scale(18));
                        i++;
                    }
                }

                var position = origin + new Point(x, y);
                var rect     = new Rectangle(position.X, position.Y, scale.X, scale.Y);
                if (stage == RenderStage.Sprites && rect.Contains(mouse))
                {
                    SelectedSlot = (short)(area.StartIndex + i);
                    SpriteBatch.Draw(Game.WhitePixel, rect, new Color(Color.White, 150));
                }

                if (item.Empty)
                {
                    continue;
                }
                var provider = Game.ItemRepository.GetItemProvider(item.Id);
                var texture  = provider.GetIconTexture((byte)item.Metadata);
                if (texture != null && stage == RenderStage.Sprites)
                {
                    IconRenderer.RenderItemIcon(SpriteBatch, Items, provider,
                                                (byte)item.Metadata, rect, Color.White);
                }
                if (texture == null && stage == RenderStage.Models && provider is IBlockProvider)
                {
                    IconRenderer.RenderBlockIcon(Game, provider as IBlockProvider, (byte)item.Metadata, rect);
                }
                if (stage == RenderStage.Text && item.Count > 1)
                {
                    var offset = 10;
                    if (item.Count >= 10)
                    {
                        offset -= 6;
                    }
                    position += new Point((int)Scale(offset), (int)Scale(5));
                    Font.DrawText(SpriteBatch, position.X, position.Y, item.Count.ToString(), Game.ScaleFactor);
                }
            }
        }
예제 #12
0
 public void Render(RenderStage stage)
 {
 }
예제 #13
0
        protected override Task <bool> Initialize(EditorServiceGame editorGame)
        {
            game        = (EntityHierarchyEditorGame)editorGame;
            editorScene = game.EditorScene;

            var transformMainGizmoRenderStage        = new RenderStage("TransformGizmoOpaque", "Main");
            var transformTransparentGizmoRenderStage = new RenderStage("TransformGizmoTransparent", "Main")
            {
                SortMode = new BackToFrontSortMode()
            };

            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(transformMainGizmoRenderStage);
            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(transformTransparentGizmoRenderStage);

            var meshRenderFeature = game.EditorSceneSystem.GraphicsCompositor.RenderFeatures.OfType <MeshRenderFeature>().First();

            // Reset all stages for TransformationGrizmoGroup
            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                RenderGroup = TransformationGizmo.TransformationGizmoGroupMask,
            });
            meshRenderFeature.RenderStageSelectors.Add(new MeshTransparentRenderStageSelector
            {
                EffectName             = EditorGraphicsCompositorHelper.EditorForwardShadingEffect,
                RenderGroup            = TransformationGizmo.TransformationGizmoGroupMask,
                OpaqueRenderStage      = transformMainGizmoRenderStage,
                TransparentRenderStage = transformTransparentGizmoRenderStage,
            });
            meshRenderFeature.PipelineProcessors.Add(new MeshPipelineProcessor {
                TransparentRenderStage = transformTransparentGizmoRenderStage
            });

            var editorCompositor = (EditorTopLevelCompositor)game.EditorSceneSystem.GraphicsCompositor.Game;

            editorCompositor.PostGizmoCompositors.Add(new ClearRenderer {
                ClearFlags = ClearRendererFlags.DepthOnly
            });
            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = transformMainGizmoRenderStage, Name = "Transform Opaque Gizmos"
            });
            editorCompositor.PostGizmoCompositors.Add(new SingleStageRenderer {
                RenderStage = transformTransparentGizmoRenderStage, Name = "Transform Transparent Gizmos"
            });

            TranslationGizmo = new TranslationGizmo();
            RotationGizmo    = new RotationGizmo();
            ScaleGizmo       = new ScaleGizmo();
            TranslationGizmo.TransformationEnded += OnGizmoTransformationFinished;
            ScaleGizmo.TransformationEnded       += OnGizmoTransformationFinished;
            RotationGizmo.TransformationEnded    += OnGizmoTransformationFinished;

            transformationGizmos.Add(TranslationGizmo);
            transformationGizmos.Add(RotationGizmo);
            transformationGizmos.Add(ScaleGizmo);

            Services.Get <IEditorGameEntitySelectionService>().SelectionUpdated += UpdateModifiedEntitiesList;

            // Initialize and add the Gizmo entities to the gizmo scene
            MicrothreadLocalDatabases.MountCommonDatabase();

            // initialize the gizmo
            foreach (var gizmo in transformationGizmos)
            {
                gizmo.Initialize(game.Services, editorScene);
            }

            // Deactivate all transformation gizmo by default
            foreach (var gizmo in transformationGizmos)
            {
                gizmo.IsEnabled = false;
            }

            // set the default active transformation gizmo
            ActiveTransformationGizmo = TranslationGizmo;

            // Start update script (with priority 1 so that it happens after UpdateModifiedEntitiesList is called -- which usually happens from a EditorGameComtroller.PostAction() which has a default priority 0)
            game.Script.AddTask(Update, 1);
            return(Task.FromResult(true));
        }
예제 #14
0
        private void CalculateModel(IBlockAccess world,
                                    BlockCoordinates blockCoordinates,
                                    ChunkData chunkBuilder,
                                    Vector3 position,
                                    Block baseBlock,
                                    BlockStateModel blockStateModel,
                                    ResourcePackModelBase model,
                                    Biome biome)
        {
            //bsModel.Y = Math.Abs(180 - bsModel.Y);

            //if (Resources.BlockModelRegistry.TryGet(blockStateModel.ModelName, out var registryEntry))
            {
                //var model = registryEntry.Value;

                var baseColor = baseBlock.BlockMaterial.TintColor;

                for (var index = 0; index < model.Elements.Length; index++)
                {
                    var element = model.Elements[index];
                    element.To *= Scale;

                    element.From *= Scale;

                    foreach (var face in element.Faces)
                    {
                        var facing   = face.Key;
                        var cullFace = face.Value.CullFace ?? face.Key;

                        if (blockStateModel.X > 0f)
                        {
                            var offset = blockStateModel.X / 90;
                            cullFace = RotateDirection(cullFace, offset, FACE_ROTATION_X, INVALID_FACE_ROTATION_X);
                            facing   = RotateDirection(facing, offset, FACE_ROTATION_X, INVALID_FACE_ROTATION_X);
                        }

                        if (blockStateModel.Y > 0f)
                        {
                            var offset = blockStateModel.Y / 90;
                            cullFace = RotateDirection(cullFace, offset, FACE_ROTATION, INVALID_FACE_ROTATION);
                            facing   = RotateDirection(facing, offset, FACE_ROTATION, INVALID_FACE_ROTATION);
                        }

                        if (!ShouldRenderFace(world, facing, position, baseBlock))
                        {
                            continue;
                        }

                        var positionOffset = baseBlock.GetOffset(NoiseGenerator, position);

                        var   uv = face.Value.UV;
                        float x1 = 0, x2 = 0, y1 = 0, y2 = 0;

                        if (uv == null)
                        {
                            switch (face.Key)
                            {
                            case BlockFace.North:
                            case BlockFace.South:
                                x1 = element.From.X;
                                x2 = element.To.X;
                                y1 = 16f - element.To.Y;
                                y2 = 16f - element.From.Y;

                                break;

                            case BlockFace.West:
                            case BlockFace.East:
                                x1 = element.From.Z;
                                x2 = element.To.Z;
                                y1 = 16f - element.To.Y;
                                y2 = 16f - element.From.Y;

                                break;

                            case BlockFace.Down:
                            case BlockFace.Up:
                                x1 = element.From.X;
                                x2 = element.To.X;
                                y1 = 16f - element.To.Z;
                                y2 = 16f - element.From.Z;

                                break;
                            }
                        }
                        else
                        {
                            x1 = uv.X1;
                            x2 = uv.X2;
                            y1 = uv.Y1;
                            y2 = uv.Y2;
                        }

                        var faceColor = baseColor;

                        bool hasTint = (face.Value.TintIndex.HasValue && face.Value.TintIndex == 0);

                        if (hasTint)
                        {
                            switch (baseBlock.BlockMaterial.TintType)
                            {
                            case TintType.Default:
                                faceColor = Color.White;

                                break;

                            case TintType.Color:
                                faceColor = baseBlock.BlockMaterial.TintColor;

                                break;

                            case TintType.Grass:
                                if (SmoothLighting)
                                {
                                    var bx = (int)position.X;
                                    var y  = (int)position.Y;
                                    var bz = (int)position.Z;

                                    faceColor = CombineColors(
                                        GetGrassBiomeColor(world, bx, y, bz),
                                        GetGrassBiomeColor(world, bx - 1, y, bz),
                                        GetGrassBiomeColor(world, bx, y, bz - 1),
                                        GetGrassBiomeColor(world, bx + 1, y, bz),
                                        GetGrassBiomeColor(world, bx, y, bz + 1),
                                        GetGrassBiomeColor(world, bx + 1, y, bz - 1));
                                }
                                else
                                {
                                    faceColor = Resources.ResourcePack.GetGrassColor(
                                        biome.Temperature, biome.Downfall, (int)position.Y);
                                }

                                break;

                            case TintType.Foliage:
                                if (face.Value.TintIndex.HasValue && face.Value.TintIndex == 0)
                                {
                                    faceColor = Resources.ResourcePack.GetFoliageColor(
                                        biome.Temperature, biome.Downfall, (int)position.Y);
                                }

                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }
                        }

                        faceColor = AdjustColor(faceColor, facing, element.Shade);

                        var uvMap = GetTextureUVMap(
                            Resources, ResolveTexture(model, face.Value.Texture), x1, x2, y1, y2, face.Value.Rotation, faceColor);

                        var vertices = GetFaceVertices(face.Key, element.From, element.To, uvMap);

                        vertices = ProcessVertices(vertices, blockStateModel, element, uvMap, facing, face.Value);

                        RenderStage targetState = RenderStage.OpaqueFullCube;

                        if (baseBlock.BlockMaterial.IsLiquid)
                        {
                            targetState = RenderStage.Liquid;
                        }
                        else if (uvMap.IsAnimated)
                        {
                            targetState = RenderStage.Animated;
                        }
                        else if (baseBlock.Transparent)
                        {
                            if (baseBlock.BlockMaterial.IsOpaque)
                            {
                                if (!Block.FancyGraphics && baseBlock.IsFullCube)
                                {
                                    targetState = RenderStage.OpaqueFullCube;
                                }
                                else
                                {
                                    targetState = RenderStage.Transparent;
                                }
                            }
                            else
                            {
                                targetState = RenderStage.Translucent;
                            }
                        }
                        else if (!baseBlock.IsFullCube)
                        {
                            targetState = RenderStage.Opaque;
                        }

                        for (int i = 0; i < vertices.Length; i++)
                        {
                            var vertex = vertices[i];

                            BlockModel.GetLight(
                                world, vertex.Position + position + vertex.Face.GetVector3(), out var blockLight,
                                out var skyLight, true);

                            chunkBuilder.AddVertex(
                                blockCoordinates, vertex.Position + position + positionOffset, vertex.TexCoords,
                                vertex.Color, blockLight, skyLight, targetState);
                        }
                    }
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Creates a graphics compositor programatically that renders into a Rendertarget. It can render everything the default Compositor can
        /// </summary>
        public static GraphicsCompositor CreateOffscreenCompositor(
            bool enablePostEffects,
            Texture renderTarget,
            CameraComponent camera    = null,
            RenderGroupMask groupMask = RenderGroupMask.All)
        {
            #region Render stages
            var opaqueRenderStage = new RenderStage("Opaque", "Main")
            {
                SortMode = new StateChangeSortMode()
            };
            var transparentRenderStage = new RenderStage("Transparent", "Main")
            {
                SortMode = new BackToFrontSortMode()
            };
            var shadowMapCaster = new RenderStage("ShadowMapCaster", "ShadowMapCaster")
            {
                SortMode = new FrontToBackSortMode()
            };
            var shadowMapCasterrParaboloidRenderStage = new RenderStage("ShadowMapCasterParaboloid", "ShadowMapCasterParaboloid")
            {
                SortMode = new FrontToBackSortMode()
            };
            var shadowMapCasterCubeMapRenderStage = new RenderStage("ShadowMapCasterCubeMap", "ShadowMapCasterCubeMap")
            {
                SortMode = new FrontToBackSortMode()
            };
            var gBuffer = new RenderStage("GBuffer", "GBuffer")
            {
                SortMode = new FrontToBackSortMode()
            };
            #endregion

            #region RenderFeatures
            var meshRenderFeature = new MeshRenderFeature
            {
                PipelineProcessors =
                {
                    new MeshPipelineProcessor()
                    {
                        TransparentRenderStage = transparentRenderStage
                    },
                    new ShadowMeshPipelineProcessor()
                    {
                        DepthClipping = false, ShadowMapRenderStage = shadowMapCaster
                    },
                    new ShadowMeshPipelineProcessor()
                    {
                        DepthClipping = true, ShadowMapRenderStage = shadowMapCasterrParaboloidRenderStage
                    },
                    new ShadowMeshPipelineProcessor()
                    {
                        DepthClipping = true, ShadowMapRenderStage = shadowMapCasterCubeMapRenderStage
                    }
                },
                RenderFeatures =
                {
                    new TransformRenderFeature(),
                    new SkinningRenderFeature(),
                    new MaterialRenderFeature(),
                    new ShadowCasterRenderFeature(),
                    new ForwardLightingRenderFeature()
                    {
                        LightRenderers =
                        {
                            new LightAmbientRenderer(),
                            new LightDirectionalGroupRenderer(),
                            new LightSkyboxRenderer(),
                            new LightClusteredPointSpotGroupRenderer(),
                            new LightPointGroupRenderer()
                        }
                    }
                },
                RenderStageSelectors =
                {
                    new MeshTransparentRenderStageSelector()
                    {
                        EffectName             = "XenkoForwardShadingEffect",
                        OpaqueRenderStage      = opaqueRenderStage,
                        TransparentRenderStage = transparentRenderStage,
                        RenderGroup            = groupMask
                    },
                    new ShadowMapRenderStageSelector()
                    {
                        EffectName           = "XenkoForwardShadingEffect.ShadowMapCaster",
                        ShadowMapRenderStage = shadowMapCaster,
                        RenderGroup          = groupMask
                    },
                    new ShadowMapRenderStageSelector()
                    {
                        EffectName           = "XenkoForwardShadingEffect.ShadowMapCasterParaboloid",
                        ShadowMapRenderStage = shadowMapCasterrParaboloidRenderStage,
                        RenderGroup          = groupMask
                    },
                    new ShadowMapRenderStageSelector()
                    {
                        EffectName           = "XenkoForwardShadingEffect.ShadowMapCasterCubeMap",
                        ShadowMapRenderStage = shadowMapCasterCubeMapRenderStage,
                        RenderGroup          = groupMask
                    },
                    new MeshTransparentRenderStageSelector()
                    {
                        EffectName        = "XenkoForwardShadingEffect.ShadowMapCaster",
                        OpaqueRenderStage = gBuffer,
                        RenderGroup       = groupMask
                    }
                }
            };

            var spriteRenderFeature = new SpriteRenderFeature()
            {
                RenderStageSelectors =
                {
                    new SpriteTransparentRenderStageSelector()
                    {
                        EffectName             = "Test", // TODO: Check this
                        OpaqueRenderStage      = opaqueRenderStage,
                        TransparentRenderStage = transparentRenderStage,
                        RenderGroup            = groupMask
                    }
                }
            };

            var backgroundRenderFeature = new BackgroundRenderFeature()
            {
                RenderStageSelectors =
                {
                    new SimpleGroupToRenderStageSelector()
                    {
                        EffectName  = "Test",
                        RenderStage = opaqueRenderStage,
                        RenderGroup = groupMask
                    }
                }
            };

            var uiRenderFeature = new UIRenderFeature()
            {
                RenderStageSelectors =
                {
                    new SimpleGroupToRenderStageSelector()
                    {
                        EffectName  = "Test",
                        RenderStage = transparentRenderStage,
                        RenderGroup = groupMask
                    }
                }
            };

            var particleEmitterRenderFeature = new ParticleEmitterRenderFeature()
            {
                RenderStageSelectors =
                {
                    new ParticleEmitterTransparentRenderStageSelector()
                    {
                        OpaqueRenderStage      = opaqueRenderStage,
                        TransparentRenderStage = transparentRenderStage,
                        RenderGroup            = groupMask
                    }
                }
            };

            //TODO: add that when in VL Context (needs VL.Xenko nuget)
            //var vlLayerRenderfeature = new LayerRenderFeature()
            //{
            //    RenderStageSelectors =
            //    {
            //        new SimpleGroupToRenderStageSelector()
            //        {
            //            RenderStage = opaqueRenderStage,
            //            RenderGroup = groupMask
            //        }
            //    }

            //};
            #endregion

            #region Camera slots
            var offscreenCameraSlot = new SceneCameraSlot();
            if (camera != null)
            {
                camera.Slot = offscreenCameraSlot.ToSlotId();
            }
            #endregion

            #region post fx
            var postProcessingEffects = enablePostEffects
                ? new PostProcessingEffects
            {
                ColorTransforms =
                {
                    Transforms =
                    {
                        new ToneMap(),
                    },
                },
            }
                : null;

            if (postProcessingEffects != null)
            {
                postProcessingEffects.DisableAll();
                postProcessingEffects.ColorTransforms.Enabled = true;
            }
            #endregion

            #region Renderers
            var forwardRenderer = new ForwardRenderer
            {
                Clear = { ClearFlags = ClearRendererFlags.ColorAndDepth, Color = new Color4(0, 0, 0, 0) },
                GBufferRenderStage = gBuffer,
                LightProbes        = true,
                MSAALevel          = MultisampleCount.None,
                //MSAAResolver = new MSAAResolver() { FilterType = MSAAResolver.FilterTypes.BSpline, FilterRadius = 1.0f },
                OpaqueRenderStage     = opaqueRenderStage,
                ShadowMapRenderStages = { shadowMapCaster },
                //SubsurfaceScatteringBlurEffect,
                TransparentRenderStage = transparentRenderStage,
                // TODO: add postFX once their alpha is sorted out
                PostEffects = postProcessingEffects
            };

            var singleViewforwardRenderer = new ForwardRenderer
            {
                Clear = { ClearFlags = ClearRendererFlags.ColorAndDepth, Color = new Color4(0, 0, 0, 0) },
                GBufferRenderStage = gBuffer,
                LightProbes        = true,
                MSAALevel          = MultisampleCount.None,
                //MSAAResolver = new MSAAResolver() { FilterType = MSAAResolver.FilterTypes.BSpline, FilterRadius = 1.0f },
                OpaqueRenderStage     = opaqueRenderStage,
                ShadowMapRenderStages = { shadowMapCaster },
                //SubsurfaceScatteringBlurEffect,
                TransparentRenderStage = transparentRenderStage
            };
            #endregion

            #region Game
            var game = new SceneCameraRenderer()
            {
                Camera = offscreenCameraSlot,
                Child  = new RenderTextureSceneRenderer()
                {
                    RenderTexture = renderTarget,
                    Child         = forwardRenderer,
                }
            };
            #endregion

            return(new GraphicsCompositor
            {
                Cameras = { offscreenCameraSlot },

                RenderStages =
                {
                    opaqueRenderStage,
                    transparentRenderStage,
                    shadowMapCaster,
                    shadowMapCasterrParaboloidRenderStage,
                    shadowMapCasterCubeMapRenderStage,
                    gBuffer
                },
                RenderFeatures =
                {
                    meshRenderFeature,
                    spriteRenderFeature,
                    backgroundRenderFeature,
                    uiRenderFeature,
                    particleEmitterRenderFeature,
                    //vlLayerRenderfeature
                },

                Game = game
            });
        }
예제 #16
0
        /// <summary>
        /// Creates a typical graphics compositor programatically. It can render meshes, sprites and backgrounds.
        /// </summary>
        public static GraphicsCompositor CreateDefault(bool enablePostEffects, string modelEffectName = "StrideForwardShadingEffect", CameraComponent camera = null, Color4?clearColor = null, GraphicsProfile graphicsProfile = GraphicsProfile.Level_10_0, RenderGroupMask groupMask = RenderGroupMask.All)
        {
            var opaqueRenderStage = new RenderStage("Opaque", "Main")
            {
                SortMode = new StateChangeSortMode()
            };
            var transparentRenderStage = new RenderStage("Transparent", "Main")
            {
                SortMode = new BackToFrontSortMode()
            };
            var shadowCasterRenderStage = new RenderStage("ShadowMapCaster", "ShadowMapCaster")
            {
                SortMode = new FrontToBackSortMode()
            };
            var shadowCasterCubeMapRenderStage = new RenderStage("ShadowMapCasterCubeMap", "ShadowMapCasterCubeMap")
            {
                SortMode = new FrontToBackSortMode()
            };
            var shadowCasterParaboloidRenderStage = new RenderStage("ShadowMapCasterParaboloid", "ShadowMapCasterParaboloid")
            {
                SortMode = new FrontToBackSortMode()
            };

            var postProcessingEffects = enablePostEffects
                ? new PostProcessingEffects
            {
                ColorTransforms =
                {
                    Transforms =
                    {
                        new ToneMap(),
                    },
                },
            }
                : null;

            if (postProcessingEffects != null)
            {
                postProcessingEffects.DisableAll();
                postProcessingEffects.ColorTransforms.Enabled = true;
            }

            var singleView = new ForwardRenderer
            {
                Clear                  = { Color = clearColor ?? Color.CornflowerBlue },
                OpaqueRenderStage      = opaqueRenderStage,
                TransparentRenderStage = transparentRenderStage,
                ShadowMapRenderStages  = { shadowCasterRenderStage, shadowCasterParaboloidRenderStage, shadowCasterCubeMapRenderStage },
                PostEffects            = postProcessingEffects,
            };

            var forwardLighting = graphicsProfile >= GraphicsProfile.Level_10_0
                ? new ForwardLightingRenderFeature
            {
                LightRenderers =
                {
                    new LightAmbientRenderer(),
                    new LightSkyboxRenderer(),
                    new LightDirectionalGroupRenderer(),
                    new LightPointGroupRenderer(),
                    new LightSpotGroupRenderer(),
                    new LightClusteredPointSpotGroupRenderer(),
                },
                ShadowMapRenderer = new ShadowMapRenderer
                {
                    Renderers =
                    {
                        new LightDirectionalShadowMapRenderer
                        {
                            ShadowCasterRenderStage = shadowCasterRenderStage,
                        },
                        new LightSpotShadowMapRenderer
                        {
                            ShadowCasterRenderStage = shadowCasterRenderStage,
                        },
                        new LightPointShadowMapRendererParaboloid
                        {
                            ShadowCasterRenderStage = shadowCasterParaboloidRenderStage,
                        },
                        new LightPointShadowMapRendererCubeMap
                        {
                            ShadowCasterRenderStage = shadowCasterCubeMapRenderStage,
                        },
                    },
                },
            }
                : new ForwardLightingRenderFeature
            {
                LightRenderers =
                {
                    new LightAmbientRenderer(),
                    new LightDirectionalGroupRenderer(),
                    new LightSkyboxRenderer(),
                    new LightPointGroupRenderer(),
                    new LightSpotGroupRenderer(),
                },
            };

            var cameraSlot = new SceneCameraSlot();

            if (camera != null)
            {
                camera.Slot = cameraSlot.ToSlotId();
            }

            return(new GraphicsCompositor
            {
                Cameras =
                {
                    cameraSlot,
                },
                RenderStages =
                {
                    opaqueRenderStage,
                    transparentRenderStage,
                    shadowCasterRenderStage,
                    shadowCasterParaboloidRenderStage,
                    shadowCasterCubeMapRenderStage,
                },
                RenderFeatures =
                {
                    new MeshRenderFeature
                    {
                        RenderFeatures =
                        {
                            new TransformRenderFeature(),
                            new SkinningRenderFeature(),
                            new MaterialRenderFeature(),
                            new ShadowCasterRenderFeature(),
                            forwardLighting,
                        },
                        RenderStageSelectors =
                        {
                            new MeshTransparentRenderStageSelector
                            {
                                EffectName = modelEffectName,
                                OpaqueRenderStage = opaqueRenderStage,
                                TransparentRenderStage = transparentRenderStage,
                                RenderGroup = groupMask,
                            },
                            new ShadowMapRenderStageSelector
                            {
                                EffectName = modelEffectName + ".ShadowMapCaster",
                                ShadowMapRenderStage = shadowCasterRenderStage,
                                RenderGroup = groupMask,
                            },
                            new ShadowMapRenderStageSelector
                            {
                                EffectName = modelEffectName + ".ShadowMapCasterParaboloid",
                                ShadowMapRenderStage = shadowCasterParaboloidRenderStage,
                                RenderGroup = groupMask,
                            },
                            new ShadowMapRenderStageSelector
                            {
                                EffectName = modelEffectName + ".ShadowMapCasterCubeMap",
                                ShadowMapRenderStage = shadowCasterCubeMapRenderStage,
                                RenderGroup = groupMask,
                            },
                        },
                        PipelineProcessors =
                        {
                            new MeshPipelineProcessor       {
                                TransparentRenderStage = transparentRenderStage
                            },
                            new ShadowMeshPipelineProcessor {
                                ShadowMapRenderStage = shadowCasterRenderStage
                            },
                            new ShadowMeshPipelineProcessor {
                                ShadowMapRenderStage = shadowCasterParaboloidRenderStage, DepthClipping = true
                            },
                            new ShadowMeshPipelineProcessor {
                                ShadowMapRenderStage = shadowCasterCubeMapRenderStage, DepthClipping = true
                            },
                        },
                    },
                    new SpriteRenderFeature
                    {
                        RenderStageSelectors =
                        {
                            new SpriteTransparentRenderStageSelector
                            {
                                EffectName = "Test",
                                OpaqueRenderStage = opaqueRenderStage,
                                TransparentRenderStage = transparentRenderStage,
                                RenderGroup = groupMask,
                            },
                        },
                    },
                    new BackgroundRenderFeature
                    {
                        RenderStageSelectors =
                        {
                            new SimpleGroupToRenderStageSelector
                            {
                                RenderStage = opaqueRenderStage,
                                EffectName = "Test",
                                RenderGroup = groupMask,
                            },
                        },
                    },
                },
                Game = new SceneCameraRenderer()
                {
                    Child = singleView,
                    Camera = cameraSlot,
                },
                Editor = singleView,
                SingleView = singleView,
            });
        }
예제 #17
0
        protected override Entity Create()
        {
            base.Create();

            DefaultMaterial         = CreateUniformColorMaterial(Color.White);
            ElementSelectedMaterial = CreateUniformColorMaterial(Color.Gold);

            var entity = new Entity("View Gizmo");

            cameraComponent = new CameraComponent
            {
                UseCustomAspectRatio = true,
                AspectRatio          = 1.0f,
                NearClipPlane        = 0.1f,
                FarClipPlane         = 1000.0f,
                UseCustomViewMatrix  = true,
                VerticalFieldOfView  = VerticalFieldOfView
            };
            entity.Add(cameraComponent);

            // create the default fonts
            var fontItem = OfflineRasterizedSpriteFontFactory.Create();

            fontItem.FontType.Size = FontSize;
            defaultFont            = OfflineRasterizedFontCompiler.Compile(Services.GetService <IFontFactory>(), fontItem, GraphicsDevice.ColorSpace == ColorSpace.Linear);

            // create the sprite batch use to draw text
            spriteBatch = new SpriteBatch(GraphicsDevice)
            {
                DefaultDepth = 1
            };

            // Add a renderer on the top right size
            var cameraOrientationGizmoRenderStage = new RenderStage("CameraOrientationGizmo", "Main");

            game.EditorSceneSystem.GraphicsCompositor.RenderStages.Add(cameraOrientationGizmoRenderStage);

            var meshRenderFeature = game.EditorSceneSystem.GraphicsCompositor.RenderFeatures.OfType <MeshRenderFeature>().First();

            meshRenderFeature.RenderStageSelectors.Add(new SimpleGroupToRenderStageSelector
            {
                EffectName  = EditorGraphicsCompositorHelper.EditorForwardShadingEffect,
                RenderGroup = ViewGizmoGroupMask,
                RenderStage = cameraOrientationGizmoRenderStage
            });

            var editorCompositor = (EditorTopLevelCompositor)game.EditorSceneSystem.GraphicsCompositor.Game;

            editorCompositor.PostGizmoCompositors.Add(new ClearRenderer {
                ClearFlags = ClearRendererFlags.DepthOnly
            });
            editorCompositor.PostGizmoCompositors.Add(gizmoViewportRenderer = new GizmoViewportRenderer
            {
                Name             = "Render Camera Orientation",
                ViewportSize     = ViewportSize,
                ViewportPosition = new Vector2(1.0f, 0.0f),
                Camera           = cameraComponent,
                Content          = new SceneRendererCollection
                {
                    new SingleStageRenderer {
                        RenderStage = cameraOrientationGizmoRenderStage
                    },
                    new DelegateSceneRenderer(RenderFaceNames),
                },
            });

            var cubeMesh = GeometricPrimitive.Cube.New(GraphicsDevice).ToMeshDraw();

            int i = 0;

            for (var z = -1; z <= 1; z++)
            {
                for (var y = -1; y <= 1; y++)
                {
                    for (var x = -1; x <= 1; x++)
                    {
                        if (x == 0 && y == 0 && z == 0)
                        {
                            continue;
                        }

                        var cubeEntity = new Entity("CubeEntity" + i++)
                        {
                            new ModelComponent {
                                Model = new Model {
                                    x == 0 ? ElementSelectedMaterial : DefaultMaterial, new Mesh {
                                        Draw = cubeMesh
                                    }
                                }, RenderGroup = RenderGroup
                            }
                        };

                        cubeEntity.Transform.Scale    = new Vector3(x == 0 ? InnerExtent * 2 : Border, y == 0 ? InnerExtent * 2 : Border, z == 0 ? InnerExtent * 2 : Border);
                        cubeEntity.Transform.Position = new Vector3(x, y, z) * (InnerExtent + Border / 2);

                        entity.AddChild(cubeEntity);
                        entities.Add(cubeEntity);
                    }
                }
            }

            return(entity);
        }
예제 #18
0
        private void DrawChunks(NoiseData[] chunks, RenderTarget2D target, RenderStage renderStage)
        {
            GraphicsDevice.SetRenderTarget(target);

            //using (SpriteBatch sb = new SpriteBatch(GraphicsDevice))
            {
                _spriteBatch.Begin();

                foreach (var data in chunks)
                {
                    var column = data.Chunk;
                    var worldX = data.X << 4;
                    var worldZ = data.Z << 4;

                    for (int cx = 0; cx < 16; cx++)
                    {
                        var rx = (data.X << 4) + (cx * _resolution);

                        for (int cz = 0; cz < 16; cz++)
                        {
                            var rz = (data.Z << 4) + (cz * _resolution);

                            var pixelPosition = new Rectangle(rx, rz, _resolution, _resolution);
                            var biome         = _worldGen.BiomeProvider.GetBiome(column.GetBiome(cx, cz));

                            var temp  = (int)Math.Max(0, Math.Min(255, (255 * (biome.Temperature / 2f))));
                            var humid = (int)Math.Max(0, Math.Min(255, (255 * biome.Downfall)));

                            /*var t    = data.Temperature[NoiseMap.GetIndex(cx, cz)];
                             * var temp = (int) Math.Max(0,
                             *      Math.Min(255, (255 * (t / 2f))));
                             *
                             * var r = data.Humidity[NoiseMap.GetIndex(cx, cz)];// MathF.Abs(_worldGen.RainfallNoise.GetValue(rx, rz));
                             * var humid = (int) Math.Max(0,
                             *      Math.Min(255, (255 * r)));*/

                            switch (renderStage)
                            {
                            case RenderStage.Humidity:
                                _spriteBatch.Draw(_pixel, pixelPosition, new Color(humid, humid, humid));
                                break;

                            case RenderStage.Temperature:
                                _spriteBatch.Draw(_pixel, pixelPosition, new Color(temp, 0, humid));
                                break;

                            case RenderStage.Height:
                                int height = column.GetHeight(cx, cz);
                                _spriteBatch.Draw(_pixel, pixelPosition, new Color(height, height, height));
                                //	_spriteBatch.Draw(_pixel, pixelPosition, new Color(temp, temp, temp));
                                break;

                            case RenderStage.HumidityAndTemperature:
                                //	var biome = _worldGen.BiomeProvider.GetBiome(t, r);
                                //	var c = biome.Color.GetValueOrDefault(System.Drawing.Color.White);
                                if (_biomeColors.TryGetValue(biome.Id, out var c))
                                {
                                    _spriteBatch.Draw(_pixel, pixelPosition, new Color(c.R, c.G, c.B));
                                }

                                break;
                            }

                            /*var t = WorldGen.TemperatureNoise.GetValue(rx, rz) + 1f;
                             * var r = MathF.Abs(WorldGen.RainfallNoise.GetValue(rx, rz));
                             *
                             * var humid = (int) Math.Max(0,
                             *  Math.Min(255, (255 * r)));
                             *
                             * humidityMap.SetPixel(rx, rz, Color.FromArgb(humid, humid, humid));
                             *
                             * var temp = (int) Math.Max(0,
                             *  Math.Min(255, (255 * (t / 2f))));
                             *
                             * heatmap.SetPixel(rx, rz, Color.FromArgb(temp, temp, temp));*/


                            // humidityMap.SetPixel(rx, rz, Color.FromArgb(humid, humid, humid));
                            // heatmap.SetPixel(rx, rz, Color.FromArgb(temp, temp, temp));

                            // chunkHeight.SetPixel(rx, rz, Color.FromArgb(height, height, height));

                            /*height = (int) Math.Max(0,
                             *  Math.Min(255,
                             *      (255 * MathUtils.ConvertRange(-2f, 2f, 0f, 1f,
                             *           ((biome.MinHeight + biome.MaxHeight) / 2f)))));*/

                            // heightmap.SetPixel(rx, rz, Color.FromArgb(height, height, height));
                        }
                    }

                    //DrawBorder(new Rectangle(worldX,worldZ, 16, 16), 1, Color.Magenta);
                }

                DrawBorder(new Rectangle(0, 0, target.Width, target.Height), 1, Color.Red);
                ;                               _spriteBatch.End();
            }

            GraphicsDevice.SetRenderTarget(null);
        }
예제 #19
0
        //public RenderOutputDescription Output { get; private set; }

        internal RenderOutputValidator(RenderStage renderStage)
        {
            this.renderStage = renderStage;
        }
        private void Init()
        {
            InitTexture();

            RenderStage      _stage = Rendering_pipeline._stage;
            ApplicationStage Astage = (ApplicationStage)_stage;

            //Init GameObject
            Mesh cubeMesh = new Mesh(
                CubeData.pointList,
                CubeData.indexs,
                CubeData.normals,
                CubeData.vertColors,
                CubeData.mat,
                CubeData.uvs)
            {
                Texture         = texture,
                IsRenderTexture = true
            };
            GameObject cubeGameObject = new GameObject(cubeMesh,
                                                       new Vector3(1, 0, 10))
            {
                UpdateFunction = Rotate
            };

            Astage.AddGameObject(cubeGameObject);


            Mesh sphereMesh = new Mesh(
                SphereData.pointList,
                SphereData.indexs,
                SphereData.normals,
                SphereData.vertColors,
                SphereData.mat,
                SphereData.uvs)
            {
                flagBlendAlpha = true,
                ZWrite         = false
            };

            sphereMesh.SetAlpha(0.35f);

            GameObject sphereGameObject = new GameObject(sphereMesh, new Vector3(-1, -1, 5))
            {
                UpdateFunction = Rotate,
                scale          = new Vector3(1.4f, 1.4f, 1.4f),
            };

            Astage.AddGameObject(sphereGameObject);



            //Init Camera
            Camera MainCamera = new Camera
            {
                pos          = new Vector3(0, 0, 0, 1),
                lookAt       = new Vector3(0, 0, 1, 1),
                up           = new Vector3(0, 1, 0, 0),
                fov          = (float)System.Math.PI / 4f,
                aspect       = MaximumSize.Width / (float)MaximumSize.Height,
                zn           = 1f,
                zf           = 500f,
                ScreenHeight = MaximumSize.Height
            };

            Astage.SetMainCamera(MainCamera);

            //Init Light
            Light light = new Light(new Vector3(0, 3, 0), new Vector3(0.6f, 1, 0), new Color(1, 1, 0))
            {
                intensity = 5f
            };

            light.SetPointLight(0.3f, 0.5f);
            Astage.AddLight(light);
        }
예제 #21
0
        public RenderStageViewModel([NotNull] GraphicsCompositorEditorViewModel editor, RenderStage renderStage) : base(editor)
        {
            RenderStage     = renderStage;
            renderStageNode = editor.Session.AssetNodeContainer.GetOrCreateNode(renderStage);

            nameNodeBinding       = new MemberGraphNodeBinding <string>(renderStageNode[nameof(RenderStage.Name)], nameof(Name), OnPropertyChanging, OnPropertyChanged, editor.UndoRedoService);
            effectSlotNodeBinding = new MemberGraphNodeBinding <string>(renderStageNode[nameof(RenderStage.EffectSlotName)], nameof(EffectSlotName), OnPropertyChanging, OnPropertyChanged, editor.UndoRedoService);
        }
예제 #22
0
        private void TryRenderTreeSlice(ITreeChartBox treeBox, int index, GDMIndividualRecord currentPatriarch)
        {
            IndiObj indi = fIndiQueue[index];

            fProcessed.Add(indi.IRec.XRef);

            int         depthLimit  = 3;
            float       scaleFactor = 1.0f;
            int         tries       = 0;
            RenderStage stage       = RenderStage.Normal;

            while (true)
            {
                treeBox.Model.DepthLimit = depthLimit;
                treeBox.Model.Scale      = scaleFactor;
                treeBox.GenChart(indi.IRec, indi.TreeKind, false);
                tries += 1;

                ExtSize imageSize = treeBox.GetImageSize();
                var     sf        = GfxHelper.ZoomToFit(imageSize.Width, imageSize.Height, fPageSize.GetWidth(), fPageSize.GetHeight());

                if (sf < 1.0f)
                {
                    // need to reduce image's size
                    switch (stage)
                    {
                    case RenderStage.Normal:
                        depthLimit -= 1;
                        stage       = RenderStage.Shrink;
                        break;

                    case RenderStage.Grow:
                        depthLimit -= 1;
                        stage       = RenderStage.Break;
                        break;

                    case RenderStage.Shrink:
                        scaleFactor = sf;
                        stage       = RenderStage.Break;
                        break;
                    }
                }
                else if (sf > 1.0f)
                {
                    // need to increase image's size
                    switch (stage)
                    {
                    case RenderStage.Normal:
                    case RenderStage.Grow:
                        depthLimit += 1;
                        stage       = RenderStage.Grow;
                        break;

                    case RenderStage.Shrink:
                        scaleFactor = sf;
                        stage       = RenderStage.Break;
                        break;
                    }
                }

                if (stage == RenderStage.Break || tries > 10)
                {
                    break;
                }
            }

            scaleFactor = Math.Min(1.0f, scaleFactor);
            treeBox.Model.DepthLimit = depthLimit;
            treeBox.Model.Scale      = scaleFactor;
            treeBox.GenChart(indi.IRec, indi.TreeKind, false);
            treeBox.RenderImage(RenderTarget.Printer, true);

            for (int i = 0; i < treeBox.Model.Persons.Count; i++)
            {
                TreeChartPerson     person  = treeBox.Model.Persons[i];
                GDMIndividualRecord indiRec = person.Rec;
                if (indiRec == null)
                {
                    continue;
                }

                int iNum = (int)indiRec.ExtData;

                var    offset = treeBox.Model.GetOffsets();
                int    ix     = offset.X + person.Rect.Left;
                int    iy     = offset.Y + person.Rect.Top - (int)fTextFont.Size;
                string iRef   = indiRec.XRef + "#" + iNum;
                fRenderer.DrawAnchor(iRef, iRef, fTextFont, null, ix, iy);

                iNum           += 1;
                indiRec.ExtData = iNum;

                if (!person.CanExpand)
                {
                    continue;
                }

                ix   = offset.X + person.Rect.Left;
                iy   = offset.Y + person.Rect.Bottom;
                iRef = indiRec.XRef + "#" + iNum;
                fRenderer.DrawHyperlink(iRef, iRef, fLinkFont, null, ix, iy);

                if (person.HasFlag(PersonFlag.pfAncWalk))
                {
                    if (person.HasFlag(PersonFlag.pfHasInvAnc) && !IsPatriarchsDescendant(indiRec, currentPatriarch))
                    {
                        CheckQueue(indiRec, TreeChartKind.ckAncestors);
                    }
                }
                else if (person.HasFlag(PersonFlag.pfDescWalk))
                {
                    if (person.HasFlag(PersonFlag.pfSpouse))
                    {
                        if (person.HasFlag(PersonFlag.pfHasInvAnc) && !IsPatriarchsDescendant(indiRec, currentPatriarch))
                        {
                            CheckQueue(indiRec, TreeChartKind.ckAncestors);
                        }
                    }
                    else
                    {
                        if (person.HasFlag(PersonFlag.pfHasInvDesc) && TreeTools.PL_SearchAnc(indiRec, currentPatriarch, true))
                        {
                            CheckQueue(indiRec, TreeChartKind.ckDescendants);
                        }
                    }
                }
            }
        }
예제 #23
0
 public void Render(RenderStage stage)
 {
 }
예제 #24
0
 private void DrawCraftingWindow(RenderStage stage)
 {
     var window = (CraftingBenchWindow)Game.Client.CurrentWindow;
     DrawWindowArea(window.CraftingGrid, 29, 16, CraftingWindowRect, stage);
     DrawWindowArea(window.MainInventory, 8, 84, CraftingWindowRect, stage);
     DrawWindowArea(window.Hotbar, 8, 142, CraftingWindowRect, stage);
 }
예제 #25
0
 public SpineSprite SetRenderStage(RenderStage value)
 {
     RenderStage = value; return(this);
 }
예제 #26
0
 private void DrawInventoryWindow(RenderStage stage)
 {
     DrawWindowArea(Game.Client.Inventory.MainInventory, 8, 84, InventoryWindowRect, stage);
     DrawWindowArea(Game.Client.Inventory.Hotbar, 8, 142, InventoryWindowRect, stage);
     DrawWindowArea(Game.Client.Inventory.CraftingGrid, 88, 26, InventoryWindowRect, stage);
     DrawWindowArea(Game.Client.Inventory.Armor, 8, 8, InventoryWindowRect, stage);
 }
예제 #27
0
 private void DrawWindowArea(IWindowArea area, int _x, int _y, Rectangle frame, RenderStage stage)
 {
     var mouse = Mouse.GetState().Position.ToVector2();
     var scale = new Point((int)(16 * Game.ScaleFactor * 2));
     var origin = new Point((int)(
         Game.GraphicsDevice.Viewport.Width / 2 - Scale(frame.Width / 2) + Scale(_x)),
         (int)(Game.GraphicsDevice.Viewport.Height / 2 - Scale(frame.Height / 2) + Scale(_y)));
     for (int i = 0; i < area.Length; i++)
     {
         var item = area[i];
         int x = (int)((i % area.Width) * Scale(18));
         int y = (int)((i / area.Width) * Scale(18));
         if (area is CraftingWindowArea)
         {
             // yes I know this is a crappy hack, bite me
             if (i == 0)
             {
                 if (area.Width == 2)
                 {
                     x = (int)Scale(144 - _x);
                     y = (int)Scale(36 - _y);
                 }
                 else
                 {
                     x = (int)Scale(124 - _x);
                     y = (int)Scale(35 - _y);
                 }
             }
             else
             {
                 i--;
                 x = (int)((i % area.Width) * Scale(18));
                 y = (int)((i / area.Width) * Scale(18));
                 i++;
             }
         }
         var position = origin + new Point(x, y);
         var rect = new Rectangle(position, scale);
         if (stage == RenderStage.Sprites && rect.Contains(mouse))
         {
             SelectedSlot = (short)(area.StartIndex + i);
             SpriteBatch.Draw(Game.White1x1, rect, new Color(Color.White, 150));
         }
         if (item.Empty)
             continue;
         var provider = Game.ItemRepository.GetItemProvider(item.ID);
         var texture = provider.GetIconTexture((byte)item.Metadata);
         if (texture != null && stage == RenderStage.Sprites)
             IconRenderer.RenderItemIcon(SpriteBatch, Items, provider,
                 (byte)item.Metadata, rect, Color.White);
         if (texture == null && stage == RenderStage.Models && provider is IBlockProvider)
             IconRenderer.RenderBlockIcon(Game, provider as IBlockProvider, (byte)item.Metadata, rect);
         if (stage == RenderStage.Text && item.Count > 1)
         {
             int offset = 10;
             if (item.Count >= 10)
                 offset -= 6;
             position += new Point((int)Scale(offset), (int)Scale(5));
             Font.DrawText(SpriteBatch, position.X, position.Y, item.Count.ToString(), Game.ScaleFactor);
         }
     }
 }
예제 #28
0
 public virtual void Render(RenderStage stage)
 {
 }