Exemple #1
0
        bool IRenderable.Render(Camera camera, Light light)
        {
            this.device.RawDevice.SetRenderState(RenderState.ZEnable, false);
            this.device.RawDevice.SetRenderState(RenderState.ZWriteEnable, false);
            this.device.RawDevice.SetRenderState(RenderState.AlphaBlendEnable, false);

            this.device.RawDevice.VertexDeclaration = this.device.ScreenVertexDecl.RawDecl;

            if (this.device.RawDevice.SetStreamSource(0, this.device.ScreenVertexBuffer.RawBuffer, 0, this.device.ScreenVertexBuffer.ElementSize).IsFailure)
                return false;

            this.shader.Params["m_ViewInv"].SetValue(camera.ViewMatrix.Invert());
            this.shader.Params["diffuseTexture"].SetValue(SkyTexture);
            this.shader.Params["ambientColor"].SetValue(AmbientColor);
            this.shader.Params["scale"].SetValue(1.0f);
            this.shader.Params["aspectRatio"].SetValue(camera.AspectRatio);

            bool ret = this.shader.RenderTechnique((pass) =>
                {
                    return this.device.RawDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2).IsSuccess;
                }, "Skybox");

            this.device.RawDevice.SetRenderState(RenderState.ZEnable, true);
            this.device.RawDevice.SetRenderState(RenderState.ZWriteEnable, true);

            return ret;
        }
Exemple #2
0
 public Framework(IntPtr handle, int width, int height, string mediaRootPath)
 {
     Device = new Device(handle, width, height);
     AssetManager = new AssetManager(Device, mediaRootPath);
     Light = new Light();
     SpriteRenderer = new SpriteRenderer(Device);
     Renderer = new RenderSystem(Device, SpriteRenderer);
 }
Exemple #3
0
        public SceneManager(Device device, AssetManager assetManager)
        {
            this.device = device;
            this.assetManager = assetManager;

            // Create default camera and light.
            Camera = new Camera();
            Light = new Light();
        }
Exemple #4
0
        private bool RenderToRenderTarget(IRenderTarget target, IList<IRenderable> renderables, IList<ISprite> sprites, bool doPresent, Camera camera, Light light)
        {
            this.device.SetRenderTarget(target);

            if (target.ClearBackGround)
                this.device.RawDevice.Clear(target.ClearOptions, target.ClearColor.ToArgb(), 1.0f, 0);

            Result result = this.device.RawDevice.BeginScene();
            if (result.IsFailure)
            {
                Log.Msg(TraceLevel.Error, this, "BeginScene failed, " + result.ToString());
                return false;
            }

            try
            {
                if (renderables != null && renderables.Count > 0)
                {
                    foreach (var renderable in renderables)
                    {
                        renderable.Render(camera, light);
                    }
                }

                if (sprites != null && sprites.Count > 0)
                {
                    this.spriteRenderer.RawSprite.Begin(SpriteFlags.AlphaBlend);
                    foreach (var sprite in sprites)
                    {
                        sprite.Render(this.spriteRenderer);
                    }
                    this.spriteRenderer.RawSprite.End();
                }
            }
            finally
            {
                this.device.RawDevice.EndScene();
            }

            if (doPresent)
                this.device.RawDevice.Present();

            target.OnRender();

            return true;
        }
Exemple #5
0
        bool IRenderable.Render(Camera camera, Light light)
        {
            this.device.RawDevice.VertexDeclaration = this.device.MeshVertexDecl.RawDecl;

            if (this.device.RawDevice.SetStreamSource(0, this.mesh.VertexBuffer.RawBuffer, 0, this.mesh.VertexBuffer.ElementSize).IsFailure)
                return false;

            this.device.RawDevice.Indices = this.mesh.IndexBuffer.RawBuffer;

            return this.mesh.Material.Shader.Render(this.mesh.Material, light, camera, WorldMatrix,
                (pass) =>
                {
                    var drawResult = this.device.RawDevice.DrawIndexedPrimitives(D3D.PrimitiveType.TriangleList,
                                                                0, this.mesh.Attribute.VertexStart, this.mesh.Attribute.VertexCount,
                                                                this.mesh.Attribute.FaceStart * 3, this.mesh.Attribute.FaceCount);
                    return drawResult.IsSuccess;
                });
        }
Exemple #6
0
        public bool Render(Material material, Light light, Camera camera, Matrix4 worldMatrix, Func<int, bool> renderDelegate)
        {
            Params["m_World"].SetValue(worldMatrix);
            Params["m_WorldIT"].SetValue(worldMatrix.Invert().Transpose());
            Params["m_WVP"].SetValue(worldMatrix * camera.ViewMatrix * camera.ProjectionMatrix);
            Params["g_vLightPos"].SetValue(light.Position);
            Params["m_ViewInv"].SetValue(camera.ViewMatrix.Invert());
            Params["DiffuseTexture"].SetValue(material.DiffuseTexture);
            Params["useNormalMap"].SetValue(material.UseNormalMap);
            Params["NormalTexture"].SetValue(material.NormalTexture);
            Params["specularPower"].SetValue(material.SpecularPower);
            Params["specularColor"].SetValue(material.SpecularColor);
            Params["useOffsetMapping"].SetValue(material.UseOffsetMapping);
            Params["HeightMapTexture"].SetValue(material.HeightMapTexture);
            Params["g_fOffsetBias"].SetValue(material.OffsetHeight);

            return RenderTechnique(renderDelegate, material.Technique);
        }
Exemple #7
0
 bool IRenderable.Render(Camera camera, Light light)
 {
     for (int i = 0; i < this.materials.Count; ++i)
     {
         var material = this.materials[i];
         bool ret = material.Shader.Render(material, light, camera, Matrix4.Identity,
             (pass) =>
             {
                 foreach (var patch in this.patches)
                 {
                     if (patch.Render(i) == false)
                         return false;
                 }
                 return true;
             });
         if (ret == false)
             return false;
     }
     return true;
 }
Exemple #8
0
        bool IRenderable.Render(Camera camera, Light light)
        {
            if (IsEnabled == false)
                return true;

            if (this.textureRenderTarget == null ||
                this.textureRenderTarget.Size.Width != this.device.RenderTarget.Size.Width ||
                this.textureRenderTarget.Size.Height != this.device.RenderTarget.Size.Height)
            {
                this.textureRenderTarget = new TextureRenderTarget(this.device, this.device.RenderTarget.Size);
            }

            // Copy rendered buffer to our texture render target
            this.device.RawDevice.StretchRectangle(this.device.RenderTarget.TargetSurface, this.textureRenderTarget.TargetSurface, TextureFilter.None);

            this.device.RawDevice.SetRenderState(RenderState.ZEnable, false);
            this.device.RawDevice.SetRenderState(RenderState.ZWriteEnable, false);
            this.device.RawDevice.SetRenderState(RenderState.AlphaBlendEnable, false);

            this.device.RawDevice.VertexDeclaration = this.device.ScreenVertexDecl.RawDecl;

            if (this.device.RawDevice.SetStreamSource(0, this.device.ScreenVertexBuffer.RawBuffer, 0, this.device.ScreenVertexBuffer.ElementSize).IsFailure)
                return false;

            var windowSize = new Vector2(this.textureRenderTarget.Size.Width, this.textureRenderTarget.Size.Height);
            this.shader.Params["windowSize"].SetValue(windowSize);
            this.shader.Params["sceneMapTexture"].SetValue(this.textureRenderTarget.Texture);
            this.shader.Params["screenBorderFadeoutMapTexture"].SetValue(BorderTexture);

            bool ret = this.shader.RenderTechnique((pass) =>
            {
                return this.device.RawDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2).IsSuccess;
            }, "ScreenDarkenBorder");

            this.device.RawDevice.SetRenderState(RenderState.ZEnable, true);
            this.device.RawDevice.SetRenderState(RenderState.ZWriteEnable, true);

            return ret;
        }
Exemple #9
0
        bool IRenderable.Render(Camera camera, Light light)
        {
            if (IsEnabled == false)
                return true;

            var finalRenderTarget = this.device.RenderTarget;

            CreateTextureRenderTargets(finalRenderTarget.Size);
            CopyRenderTarget(finalRenderTarget, this.sceneMapRenderTarget);

            this.device.RawDevice.SetRenderState(RenderState.ZEnable, false);
            this.device.RawDevice.SetRenderState(RenderState.ZWriteEnable, false);
            this.device.RawDevice.SetRenderState(RenderState.AlphaBlendEnable, false);

            this.device.RawDevice.VertexDeclaration = this.device.ScreenVertexDecl.RawDecl;

            if (this.device.RawDevice.SetStreamSource(0, this.device.ScreenVertexBuffer.RawBuffer, 0, this.device.ScreenVertexBuffer.ElementSize).IsFailure)
                return false;

            var windowSize = new Vector2(finalRenderTarget.Size.Width, finalRenderTarget.Size.Height);
            this.shader.Params["windowSize"].SetValue(windowSize);
            this.shader.Params["radialBlurScaleFactor"].SetValue(RadialBlurScaleFactor);
            this.shader.Params["sceneMapTexture"].SetValue(this.sceneMapRenderTarget.Texture);
            this.shader.Params["radialSceneMapTexture"].SetValue(this.radialSceneMapRenderTarget.Texture);
            this.shader.Params["downsampleMapTexture"].SetValue(this.downsampleMapRenderTarget.Texture);
            this.shader.Params["blurMap1Texture"].SetValue(this.blurMap1RenderTarget.Texture);
            this.shader.Params["blurMap2Texture"].SetValue(this.blurMap2RenderTarget.Texture);
            this.shader.Params["blurWidth"].SetValue(BlurWidth);
            this.shader.Params["glowIntensity"].SetValue(GlowIntensity);
            this.shader.Params["highlightIntensity"].SetValue(HighlightIntensity);

            bool ret = this.shader.RenderTechnique(RenderPass, "ScreenGlow");

            this.device.RawDevice.SetRenderState(RenderState.ZEnable, true);
            this.device.RawDevice.SetRenderState(RenderState.ZWriteEnable, true);

            return ret;
        }
Exemple #10
0
        public bool Render(IRenderTarget renderTarget, IList<IRenderable> renderables, IList<ISprite> sprites, Camera camera, Light light, bool present)
        {
            if (camera == null || light == null)
                throw new ArgumentNullException("Argument camera or light is null");

            bool renderSuccess = false;
            try
            {
                // Save primary
                PrimaryRenderTarget.TargetSurface = this.device.RawDevice.GetRenderTarget(0);
                PrimaryRenderTarget.DepthStencilSurface = this.device.RawDevice.DepthStencilSurface;

                // Render this render target
                renderSuccess = RenderToRenderTarget(renderTarget, renderables, sprites, present, camera, light);
            }
            finally
            {
                // Restore primary
                this.device.SetRenderTarget(PrimaryRenderTarget);
            }

            return renderSuccess;
        }
Exemple #11
0
 bool IRenderable.Render(Camera camera, Light light)
 {
     RenderCalled(this, EventArgs.Empty);
     return true;
 }