Пример #1
0
        /// <summary>
        /// Function to update the light data in the lighting shader.
        /// </summary>
        /// <param name="light">The light to retrieve data from.</param>
        private void UpdateLight(Gorgon2DLight light)
        {
            var lightData = new PointLightData
            {
                Position       = new DX.Vector4(new DX.Vector3(light.Position.X, light.Position.Y, -light.Position.Z), 1.0f),
                Color          = light.Color,
                LightDirection = new DX.Vector4(new DX.Vector3(light.LightDirection.X, light.LightDirection.Y, -light.LightDirection.Z), 0),
                LightAttribs   = new DX.Vector4(light.SpecularPower, light.Attenuation, light.Intensity, light.SpecularEnabled ? 1 : 0),
                LightType      = (int)light.LightType
            };

            _lightData.Buffer.SetData(ref lightData);
        }
Пример #2
0
        /// <summary>
        /// Function called to render a single effect pass.
        /// </summary>
        /// <param name="passIndex">The index of the pass being rendered.</param>
        /// <param name="renderMethod">The method used to render a scene for the effect.</param>
        /// <param name="output">The render target that will receive the final render data.</param>
        /// <remarks>
        /// <para>
        /// Applications must implement this in order to see any results from the effect.
        /// </para>
        /// </remarks>
        protected override void OnRenderPass(int passIndex, Action <int, int, DX.Size2> renderMethod, GorgonRenderTargetView output)
        {
            if (passIndex == 0)
            {
                renderMethod(passIndex, PassCount, new DX.Size2(output.Width, output.Height));
                return;
            }

            // We'll do our own drawing so we can ensure we have screen space.
            IGorgon2DCamera currentCamera = Renderer.CurrentCamera;

            Renderer.End();

            var   destRect = new DX.RectangleF(0, 0, output.Width, output.Height);
            float minZ     = 0;

            // Calculate our full screen blit area in camera projection if we're using another camera.
            if (currentCamera != null)
            {
                minZ     = currentCamera.MinimumDepth;
                destRect = currentCamera.ViewableRegion;
            }

            for (int i = 0; i < Lights.Count; ++i)
            {
                Gorgon2DLight light = Lights[i];

                if (light == null)
                {
                    continue;
                }

                UpdateLight(light);

                Renderer.Begin(_lightingState, currentCamera);
                Renderer.DrawFilledRectangle(destRect,
                                             GorgonColor.White,
                                             _gbufferTexture,
                                             new DX.RectangleF(0, 0, 1, 1),
                                             textureSampler: GorgonSamplerState.Default,
                                             depth: minZ);
                Renderer.End();
            }
        }