Пример #1
0
        /// <summary>
        /// Adds the draw call (single terrain patch drawing).
        /// </summary>
        /// <param name="terrain">The terrain to render. Cannot be null.</param>
        /// <param name="patchCoord">The terrain patch coordinates.</param>
        /// <param name="material">The material to apply during rendering. Cannot be null.</param>
        /// <param name="lodIndex">The geometry Level Of Detail index.</param>
        public void AddDrawCall(Terrain terrain, ref Int2 patchCoord, MaterialBase material, int lodIndex = -1)
        {
            if (terrain == null)
            {
                throw new ArgumentNullException(nameof(terrain));
            }
            if (material == null)
            {
                throw new ArgumentNullException(nameof(material));
            }

            for (int i = 0; i < 16; i++)
            {
                var drawCall = new RenderTask.DrawCall
                {
                    Type     = RenderTask.DrawCall.Types.TerrainChunk,
                    Flags    = StaticFlags.None,
                    LodIndex = lodIndex,
                    Index0   = patchCoord,
                    Index1   = new Int2(i % 4, i / 4),
                    Object   = terrain.unmanagedPtr,
                    Material = Object.GetUnmanagedPtr(material),
                };

                _drawCalls.Add(drawCall);
            }
        }
Пример #2
0
        /// <summary>
        /// Adds the draw call (single model drawing). Calculates target mesh level of detail and picks a proper meshes to draw (based on a material slot index).
        /// </summary>
        /// <param name="model">The model mesh to render. Cannot be null.</param>
        /// <param name="materialSlotIndex">The material slot index to draw.</param>
        /// <param name="material">The material to apply during rendering. Cannot be null.</param>
        /// <param name="bounds">The bounds of the model instance that is being drawn (model instance bounds).</param>
        /// <param name="world">The world matrix used to transform mesh geometry during rendering. Use <see cref="Matrix.Identity"/> to render mesh 'as is'.</param>
        /// <param name="flags">The static flags. Used to describe type of the geometry.</param>
        /// <param name="receiveDecals">True if rendered geometry can receive decals, otherwise false.</param>
        public void AddDrawCall(Model model, int materialSlotIndex, MaterialBase material, ref BoundingSphere bounds, ref Matrix world, StaticFlags flags = StaticFlags.None, bool receiveDecals = true)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            // Pick a proper LOD
            int lodIndex = RenderTask.Internal_ComputeModelLOD(model.unmanagedPtr, ref bounds, IntPtr.Zero);
            var lods     = model.LODs;

            if (lods == null || lods.Length < lodIndex || lodIndex < 0)
            {
                return;
            }
            var lod = lods[lodIndex];

            // Draw meshes
            for (int i = 0; i < lod.Meshes.Length; i++)
            {
                if (lod.Meshes[i].MaterialSlotIndex == materialSlotIndex)
                {
                    AddDrawCall(lod.Meshes[i], material, ref world, flags);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Adds the draw call (single model drawing). Calculates target mesh level of detail and picks a proper meshes to draw (based on a material slot index).
        /// </summary>
        /// <param name="model">The model mesh to render. Cannot be null.</param>
        /// <param name="materialSlotIndex">The material slot index to draw.</param>
        /// <param name="material">The material to apply during rendering. Cannot be null.</param>
        /// <param name="lodIndex">The model Level Of Detail to draw (zero-based index).</param>
        /// <param name="world">The world matrix used to transform mesh geometry during rendering. Use <see cref="Matrix.Identity"/> to render mesh 'as is'.</param>
        /// <param name="flags">The static flags. Used to describe type of the geometry.</param>
        /// <param name="receiveDecals">True if rendered geometry can receive decals, otherwise false.</param>
        public void AddDrawCall(Model model, int materialSlotIndex, MaterialBase material, int lodIndex, ref Matrix world, StaticFlags flags = StaticFlags.None, bool receiveDecals = true)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            // Pick a proper LOD
            var lods = model.LODs;

            if (lods == null || lods.Length < lodIndex || lodIndex < 0)
            {
                return;
            }
            var lod = lods[lodIndex];

            // Draw meshes
            for (int i = 0; i < lod.Meshes.Length; i++)
            {
                if (lod.Meshes[i].MaterialSlotIndex == materialSlotIndex)
                {
                    AddDrawCall(lod.Meshes[i], material, ref world, flags);
                }
            }
        }
Пример #4
0
        public void DrawPostFxMaterial(MaterialBase material, GPUTextureView view, ref Viewport viewport, GPUTexture input = null)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawPostFxMaterial3(unmanagedPtr, FlaxEngine.Object.GetUnmanagedPtr(material), view, ref viewport, FlaxEngine.Object.GetUnmanagedPtr(input));
#endif
        }
Пример #5
0
        public static void DrawMaterial(MaterialBase material, Rectangle rect)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawMaterial(Object.GetUnmanagedPtr(material), ref rect);
#endif
        }
Пример #6
0
        public static void DrawText(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawText2(Object.GetUnmanagedPtr(font), Object.GetUnmanagedPtr(customMaterial), text, ref layoutRect, ref color, horizontalAlignment, verticalAlignment, textWrapping, baseLinesGapScale, scale);
#endif
        }
Пример #7
0
        /// <summary>
        /// Draws postFx material to the render target.
        /// </summary>
        /// <param name="material">The material to render. It must be a post fx material.</param>
        /// <param name="output">The output texture. Must be valid and created.</param>
        /// <param name="input">The input texture. It's optional.</param>
        /// <param name="sceneRenderTask">Render task to use it's view description and the render buffers.</param>
        public void DrawPostFxMaterial(MaterialBase material, GPUTexture output, GPUTexture input, SceneRenderTask sceneRenderTask)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawPostFxMaterial1(unmanagedPtr, GetUnmanagedPtr(material), GetUnmanagedPtr(output), GetUnmanagedPtr(input), ref sceneRenderTask.View, Object.GetUnmanagedPtr(sceneRenderTask.Buffers));
#endif
        }
Пример #8
0
        public static void DrawText(Font font, MaterialBase customMaterial, string text, Color color, ref TextLayoutOptions layout)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_DrawText2(Object.GetUnmanagedPtr(font), Object.GetUnmanagedPtr(customMaterial), text, ref color, ref layout);
#endif
        }
Пример #9
0
        /// <summary>
        /// Draws a text using a custom material shader. Given material must have GUI domain and a public parameter named Font (texture parameter used for a font atlas sampling).
        /// </summary>
        /// <param name="font">The font to use.</param>
        /// <param name="customMaterial">Custom material for font characters rendering. It must contain texture parameter named Font used to sample font texture.</param>
        /// <param name="text">The text to render.</param>
        /// <param name="layoutRect">The size and position of the area in which the text is drawn.</param>
        /// <param name="color">The text color.</param>
        /// <param name="horizontalAlignment">The horizontal alignment of the text in a layout rectangle.</param>
        /// <param name="verticalAlignment">The vertical alignment of the text in a layout rectangle.</param>
        /// <param name="textWrapping">Describes how wrap text inside a layout rectangle.</param>
        /// <param name="baseLinesGapScale">The scale for distance one baseline from another. Default is 1.</param>
        /// <param name="scale">The text drawing scale. Default is 1.</param>
        public static void DrawText(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
        {
            var layout = new TextLayoutOptions
            {
                Bounds = layoutRect,
                HorizontalAlignment = horizontalAlignment,
                VerticalAlignment   = verticalAlignment,
                TextWrapping        = textWrapping,
                Scale             = scale,
                BaseLinesGapScale = baseLinesGapScale,
            };

            DrawText(font, text, color, ref layout, customMaterial);
        }
Пример #10
0
        /// <summary>
        /// Adds the draw call (single mesh drawing).
        /// </summary>
        /// <param name="mesh">The mesh to render. Cannot be null.</param>
        /// <param name="material">The material to apply during rendering. Cannot be null.</param>
        /// <param name="world">The world matrix used to transform mesh geometry during rendering. Use <see cref="Matrix.Identity"/> to render mesh 'as is'.</param>
        /// <param name="flags">The static flags. Used to describe type of the geometry.</param>
        /// <param name="receiveDecals">True if rendered geometry can receive decals, otherwise false.</param>
        public void AddDrawCall(Mesh mesh, MaterialBase material, ref Matrix world, StaticFlags flags = StaticFlags.None, bool receiveDecals = true)
        {
            if (mesh == null)
            {
                throw new ArgumentNullException(nameof(mesh));
            }
            if (material == null)
            {
                throw new ArgumentNullException(nameof(material));
            }

            var drawCall = new RenderTask.DrawCall
            {
                Type     = RenderTask.DrawCall.Types.Mesh,
                Flags    = flags,
                LodIndex = mesh._lodIndex,
                Index0   = new Int2(mesh._meshIndex, receiveDecals ? 1 : 0),
                Object   = Object.GetUnmanagedPtr(mesh.ParentModel),
                Material = Object.GetUnmanagedPtr(material),
                World    = world
            };

            _drawCalls.Add(drawCall);
        }
Пример #11
0
 /// <summary>
 /// Draws the GUI material.
 /// </summary>
 /// <param name="material">The material to render. Must be a GUI material type.</param>
 /// <param name="rect">The target rectangle to draw.</param>
 /// <param name="color">The color to use.</param>
 public static void DrawMaterial(MaterialBase material, Rectangle rect, Color color)
 {
     Internal_DrawMaterial(FlaxEngine.Object.GetUnmanagedPtr(material), ref rect, ref color);
 }
Пример #12
0
 /// <summary>
 /// Draws a text with formatting.
 /// </summary>
 /// <param name="font">The font to use.</param>
 /// <param name="text">The text to render.</param>
 /// <param name="textRange">The input text range (substring range of the input text parameter).</param>
 /// <param name="color">The text color.</param>
 /// <param name="layout">The text layout properties.</param>
 /// <param name="customMaterial">The custom material for font characters rendering. It must contain texture parameter named Font used to sample font texture.</param>
 public static void DrawText(Font font, string text, ref TextRange textRange, Color color, ref TextLayoutOptions layout, MaterialBase customMaterial = null)
 {
     Internal_DrawText3(FlaxEngine.Object.GetUnmanagedPtr(font), text, ref textRange, ref color, ref layout, FlaxEngine.Object.GetUnmanagedPtr(customMaterial));
 }
Пример #13
0
 /// <summary>
 /// Draws a text.
 /// </summary>
 /// <param name="font">The font to use.</param>
 /// <param name="text">The text to render.</param>
 /// <param name="textRange">The input text range (substring range of the input text parameter).</param>
 /// <param name="color">The text color.</param>
 /// <param name="location">The text location.</param>
 /// <param name="customMaterial">The custom material for font characters rendering. It must contain texture parameter named Font used to sample font texture.</param>
 public static void DrawText(Font font, string text, ref TextRange textRange, Color color, Vector2 location, MaterialBase customMaterial = null)
 {
     Internal_DrawText1(FlaxEngine.Object.GetUnmanagedPtr(font), text, ref textRange, ref color, ref location, FlaxEngine.Object.GetUnmanagedPtr(customMaterial));
 }
Пример #14
0
 /// <summary>
 /// Draws the model.
 /// </summary>
 /// <param name="renderContext">The rendering context.</param>
 /// <param name="material">The material to use for rendering.</param>
 /// <param name="world">The world transformation of the model.</param>
 /// <param name="flags">The object static flags.</param>
 /// <param name="receiveDecals">True if rendered geometry can receive decals, otherwise false.</param>
 public void Draw(ref RenderContext renderContext, MaterialBase material, ref Matrix world, StaticFlags flags = StaticFlags.None, bool receiveDecals = true)
 {
     Internal_Draw(unmanagedPtr, ref renderContext, FlaxEngine.Object.GetUnmanagedPtr(material), ref world, flags, receiveDecals);
 }
Пример #15
0
 /// <summary>
 /// Draws postFx material to the render target.
 /// </summary>
 /// <param name="material">The material to render. It must be a post fx material.</param>
 /// <param name="output">The output texture. Must be valid and created.</param>
 /// <param name="input">The input texture. It's optional.</param>
 public void DrawPostFxMaterial(MaterialBase material, GPUTexture output, GPUTexture input = null)
 {
     DrawPostFxMaterial(material, output.View(), input);
 }
 /// <summary>
 /// Removes the post fx material from the settings.
 /// </summary>
 /// <param name="material">The material.</param>
 public void RemovePostFxMaterial(MaterialBase material)
 {
     Internal_RemovePostFxMaterial(unmanagedPtr, FlaxEngine.Object.GetUnmanagedPtr(material));
 }
Пример #17
0
 /// <summary>
 /// Draws the terrain chunk.
 /// </summary>
 /// <param name="renderContext">The rendering context.</param>
 /// <param name="patchCoord">The patch location (x and z).</param>
 /// <param name="chunkCoord">The chunk location (x and z).</param>
 /// <param name="material">The material to use for rendering.</param>
 /// <param name="lodIndex">The LOD index.</param>
 public void DrawChunk(ref RenderContext renderContext, ref Int2 patchCoord, ref Int2 chunkCoord, MaterialBase material, int lodIndex = 0)
 {
     Internal_DrawChunk(unmanagedPtr, ref renderContext, ref patchCoord, ref chunkCoord, FlaxEngine.Object.GetUnmanagedPtr(material), lodIndex);
 }
Пример #18
0
 /// <summary>
 /// Sets the chunk material to override the terrain default one.
 /// </summary>
 /// <param name="patchCoord">The patch coordinates (x and z).</param>
 /// <param name="chunkCoord">The chunk coordinates (x and z).</param>
 /// <param name="value">The value to set.</param>
 public void SetChunkOverrideMaterial(ref Int2 patchCoord, ref Int2 chunkCoord, MaterialBase value)
 {
     Internal_SetChunkOverrideMaterial(unmanagedPtr, ref patchCoord, ref chunkCoord, FlaxEngine.Object.GetUnmanagedPtr(value));
 }
 /// <summary>
 /// Sets the material to the entry slot. Can be used to override the material of the meshes using this slot.
 /// </summary>
 /// <param name="entryIndex">The material slot entry index.</param>
 /// <param name="material">The material to set..</param>
 public void SetMaterial(int entryIndex, MaterialBase material)
 {
     Internal_SetMaterial(unmanagedPtr, entryIndex, FlaxEngine.Object.GetUnmanagedPtr(material));
 }
Пример #20
0
 /// <summary>
 /// Draws postFx material to the render target.
 /// </summary>
 /// <param name="context">The GPU commands context to use.</param>
 /// <param name="renderContext">The rendering context.</param>
 /// <param name="material">The material to render. It must be a post fx material.</param>
 /// <param name="output">The output texture. Must be valid and created.</param>
 /// <param name="input">The input texture. It's optional.</param>
 public static void DrawPostFxMaterial(GPUContext context, ref RenderContext renderContext, MaterialBase material, GPUTexture output, GPUTextureView input)
 {
     Internal_DrawPostFxMaterial(FlaxEngine.Object.GetUnmanagedPtr(context), ref renderContext, FlaxEngine.Object.GetUnmanagedPtr(material), FlaxEngine.Object.GetUnmanagedPtr(output), FlaxEngine.Object.GetUnmanagedPtr(input));
 }