Example #1
0
        public void RenderFinalPass(Camera activeCamera, List <IRenderable> renderItems)
        {
            ShaderManager.GetInstance().Ambient.Parameters["World"].SetValue(Matrix.CreateTranslation(0, 0, 0));
            ShaderManager.GetInstance().Ambient.Parameters["View"].SetValue(activeCamera.CameraViewMatrix);
            ShaderManager.GetInstance().Ambient.Parameters["Projection"].SetValue(activeCamera.CameraProjectionMatrix);
            ShaderManager.GetInstance().Ambient.Parameters["AmbientIntensity"].SetValue(TEMP_Ambient);
            //  ShaderManager.GetInstance().Ambient.CurrentTechnique = ShaderManager.GetInstance().Ambient.Techniques["Technique1"];

            //Set the texture that the effect will be rendered to
            graphicsDevice.SetRenderTargets(_outputTarget);
            graphicsDevice.Clear(Color.LightBlue);

            foreach (EffectPass pass in ShaderManager.GetInstance().Ambient.CurrentTechnique.Passes)
            {
                pass.Apply();
            }

            activeCamera.Render(ScreenManager.GetInstance().GraphicsDevice);

            foreach (IRenderable renderItem in renderItems)
            {
                renderItem.Render(ScreenManager.GetInstance().GraphicsDevice);
            }

            // Un-set the render targets
            graphicsDevice.SetRenderTargets(null);
        }
Example #2
0
        //RENDER PASS METHOD

        private void RenderDepthMaps(ref SystemTransform systemTransform)
        {
            int[] currentViewPort = new int[4];
            GL.GetInteger(GetPName.Viewport, currentViewPort);

            GL.UseProgram(ShaderManager.GetInstance().GetProgram("shadowTextured"));

            int lightNum = 0;

            var gameObjects = _world.GameObjects;

            GL.Enable(EnableCap.CullFace);

            GL.CullFace(CullFaceMode.Front);
            for (int jdx = 0; jdx < _world.ObjectMemory; jdx++)
            {
                if (gameObjects[jdx].Components.HasFlag(Component.LIGHT))
                {
                    if (_world.LightComps[jdx].LightObject.HasShadowMap)
                    {
                        var lightComp = _world.LightComps[jdx];
                        var light     = lightComp.LightObject;

                        light.ShadowMap.BindFBO();
                        GL.Clear(ClearBufferMask.DepthBufferBit);

                        int lightType = 0;
                        if (lightComp.LightType == LightType.SUN)
                        {
                            lightType = 1;
                        }

                        GL.Uniform1(3, lightType);
                        GL.Uniform1(4, lightNum);

                        for (int idx = 0; idx < _world.ObjectMemory; idx++)
                        {
                            if (_world.ExistingGameObjects[idx])
                            {
                                if (gameObjects[idx].Components.HasFlag(RenderQualfier))
                                {
                                    Bind(idx, false);
                                    systemTransform.PushModelMatrix(idx);
                                    int elementCount = ModelManager.GetInstance().GetModel(ref _staticModelComps[idx]).ElementCount;
                                    GL.DrawElements(PrimitiveType.Triangles, elementCount, DrawElementsType.UnsignedInt, IntPtr.Zero);
                                }
                            }
                        }
                        lightNum++;
                        lightNum %= 3;
                    }
                }
            }
            GL.CullFace(CullFaceMode.Back);
            GL.Disable(EnableCap.CullFace);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Viewport(currentViewPort[0], currentViewPort[1], currentViewPort[2], currentViewPort[3]);
            GL.Clear(ClearBufferMask.DepthBufferBit);
        }
Example #3
0
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch Batch, Camera camera)
        {
            this.camera = camera;

            if (isDrawable)
            {
                BoundingFrustum Frustum = new BoundingFrustum(camera.CameraViewMatrix * camera.CameraProjectionMatrix);

                DrawWireframe(ShaderManager.GetInstance().DefaultEffect, ScreenManager.GetInstance().GraphicsDevice);

                if (TEMP_selectedObject != null)
                {
                    TEMP_selectedObject.DrawRotatedBoundingBox(ShaderManager.GetInstance().DefaultEffect, ScreenManager.GetInstance().GraphicsDevice);
                }

                // if (type == Frustum.Contains(worldObject.Position))

                /*   if (model != null)
                 * {
                 *     foreach (ModelMesh mesh in model.Meshes)
                 *     {
                 *         BoundingSphere sourceSphere = new BoundingSphere(Position, mesh.BoundingSphere.Radius);
                 *
                 *         //Get the radius and position of the Object's bounding sphere
                 *         // BoundingSphere sourceSphere = new BoundingSphere(new Vector3(0, 0, 0), mesh.BoundingSphere.Radius);
                 *
                 *         if (Frustum.Intersects(sourceSphere))
                 *         {
                 *             foreach (BasicEffect effect in mesh.Effects)
                 *             {
                 *                 // Make sure lighting and texturing is enabled so we can see the result
                 *                 //  effect.EnableDefaultLighting();
                 *                 //   effect.PreferPerPixelLighting=true;
                 *                 effect.TextureEnabled = true;
                 *
                 *                 // Begin to render with the specified texture
                 *                 if (texture != null)
                 *                 {
                 *                     effect.Texture = texture;
                 *                 }
                 *
                 *                 effect.World = Matrix.CreateFromYawPitchRoll(-rotation.Y, rotation.X, rotation.Z)
                 * Matrix.CreateScale(scale) * Matrix.CreateTranslation(position);
                 *
                 *                 effect.Projection = camera.CameraProjectionMatrix;
                 *                 effect.View = camera.CameraViewMatrix;
                 *             }
                 *
                 *
                 *             mesh.Draw();
                 *         }
                 *
                 *     }
                 * }*/
            }
        }
Example #4
0
        public void DrawWireframe(BasicEffect effect, GraphicsDevice graphicsDevice)
        {
            GetCubeWireframe();

            ShaderManager.GetInstance().DefaultEffect.TextureEnabled = false;
            ShaderManager.GetInstance().DefaultEffect.VertexColorEnabled = true;
            ShaderManager.GetInstance().DefaultEffect.CurrentTechnique.Passes[0].Apply();

            graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, faces_wireframe.ToArray(), 0, faces_wireframe.Count - 1);
        }
Example #5
0
        public override void DrawRotatedBoundingBox(BasicEffect effect, GraphicsDevice graphicsDevice)
        {
            List <VertexPositionColor> wall_wireframe = GetWallRotatedBoundingBox();

            ShaderManager.GetInstance().DefaultEffect.TextureEnabled = false;
            ShaderManager.GetInstance().DefaultEffect.VertexColorEnabled = true;
            ShaderManager.GetInstance().DefaultEffect.CurrentTechnique.Passes[0].Apply();

            if (wall_wireframe.Count > 0)
            {
                graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, wall_wireframe.ToArray(), 0, wall_wireframe.Count - 1);
            }
        }
        public void Build()
        {
            GameObject go = new GameObject();

            label        = go.AddComponent <UILabel>();
            label.pivot  = UIWidget.Pivot.Bottom;
            label.font   = font;
            go.hideFlags = HideFlags.HideAndDontSave;
            GameObject.DontDestroyOnLoad(go);
            material             = new Material(ShaderManager.GetInstance().KingSoftNumTip);
            material.mainTexture = font.material.mainTexture;
            material.renderQueue = 5000;
        }
    public void RenderToTarget(Transform fellow, int index, float height, GameObject [] subMeshs)
    {
        height = height * _scale;
        int   row_count = size / delta;
        int   _x        = index / row_count;
        int   _y        = index % row_count;
        float uvdelta   = ((float)delta) / size;
        int   old_layer = fellow.gameObject.layer;

        camera.CopyFrom(Camera.main);
        camera.backgroundColor    = backgroundColor;
        camera.isOrthoGraphic     = true;
        camera.orthographicSize   = height / 2;
        camera.transform.position = fellow.position + Vector3.up * height / 2;
        camera.transform.forward  = new Vector3(0, 0, 1);
        float angle = Camera.main.transform.rotation.eulerAngles.y;

        camera.transform.Rotate(0, angle, 0, Space.Self);
        camera.transform.Translate(new Vector3(0, 0, -10), Space.Self);
        camera.targetTexture    = aimTarget;
        camera.cullingMask      = 1 << 30;
        camera.clearFlags       = CameraClearFlags.SolidColor;
        fellow.gameObject.layer = 30;
        if (null != subMeshs)
        {
            if (null != subMeshs[0])
            {
                subMeshs[0].layer = 30;
            }
            if (null != subMeshs[1])
            {
                subMeshs[1].layer = 30;
            }
        }
        //camera.RenderWithShader(Shader.Find("Hidden/Show Render Types"),"RenderType");
        camera.RenderWithShader(ShaderManager.GetInstance().KingSoftGhost.shader, "RenderType");
        fellow.gameObject.layer = old_layer;
        if (null != subMeshs)
        {
            if (null != subMeshs[0])
            {
                subMeshs[0].layer = old_layer;
            }
            if (null != subMeshs[1])
            {
                subMeshs[1].layer = old_layer;
            }
        }
        ImageEffects.Blit(aimTarget, new Rect(0, 0, 1, 1), renderTarget, new Rect(_x * uvdelta, _y * uvdelta, uvdelta, uvdelta), BlendMode.Copy);
        RenderMesh(list);
    }
Example #8
0
        public void LoadEngine()
        {
            //    ModelMap map = new ModelMap();

            //Initialise Game Engine
            LoadingScreen.SetLoadingDetailText("Loading Engine");
            //  engine = new Engine();
            //   engine.OnExit += OnExit;
            //Load Model into the engine

            //if (!isMapEditor)
            //{
            //    engine.Initialise();
            //}
            //else
            //{
            // //   engine.InitialiseMapEditor(map);
            //}

            Thread.Sleep(loadDisplayTime);


            LoadingScreen.SetLoadingDetailText("Loading Renderer");
            //Initialise Graphics Renderer
            gameplayScreen = new GameplayScreen();
            //  renderer = map.LoadRenderer();
            gameplayScreen.Pause += OnPause;
            gameplayScreen.Play  += OnPlay;
            gameplayScreen.Initialise();


            Thread.Sleep(loadDisplayTime);

            LoadingScreen.SetLoadingDetailText("Loading Shaders");
            ShaderManager.GetInstance().LoadShaders();


            //Load graphics into the renderer


            //Put the thread to sleep so that anything still being initialised is ready when it exits and fires OnLoad event
            Thread.Sleep(loadDisplayTime);
            LoadingComplete(this, new EventArgs());
            // OnLoad(this, new EventArgs());
        }
Example #9
0
        public void DrawWireframe(BasicEffect effect, GraphicsDevice graphicsDevice)
        {
            List <VertexPositionColor> wireframe = GetAABBWireframe();

            ShaderManager.GetInstance().DefaultEffect.TextureEnabled = false;
            ShaderManager.GetInstance().DefaultEffect.VertexColorEnabled = true;
            ShaderManager.GetInstance().DefaultEffect.CurrentTechnique.Passes[0].Apply();

            graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, wireframe.ToArray(), 0, wireframe.Count - 1);


            List <VertexPositionColor> collisionWireframe = _collisionBox.GetCollisionBoxWireframe(Color.White);

            graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, facingLine.ToArray(), 0, facingLine.Count - 1);

            #region Axes


            graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, xAxisLine.ToArray(), 0, xAxisLine.Count - 1);

            graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, zAxisLine.ToArray(), 0, zAxisLine.Count - 1);
            #endregion
            if (mouseRayLine != null && mouseRayLine.Count > 1)
            {
                graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, mouseRayLine.ToArray(), 0, mouseRayLine.Count - 1);
            }

            if (TEMP_selectedObjects != null && TEMP_selectedObjects.Count > 0)
            {
                foreach (AbstractWorldObject obj in TEMP_selectedObjects)
                {
                    obj.DrawRotatedBoundingBox(effect, graphicsDevice);
                }
            }

            foreach (List <VertexPositionColor> movementLine in movementLines)
            {
                graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, movementLine.ToArray(), 0, movementLine.Count - 1);
            }
            graphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, collisionWireframe.ToArray(), 0, collisionWireframe.Count - 1);
        }
Example #10
0
        //设置发光
        public object OnSetGlow(params object[] objs)
        {
            bool isGlow = Convert.ToBoolean(objs[0]);

            if (glowMaterial == null)
            {
                glowMaterial = ShaderManager.GetInstance().KingSoftSelected;

                /*if (!isLoadingGlowMaterial)
                 * {
                 *  AssetLoader.GetInstance().Load(URLUtil.GetEffectPath("effect_hero_light"), GlowMaterial_LoadComplete, AssetType.BUNDLER);
                 *  isLoadingGlowMaterial = true;
                 * }*/
            }
            else
            {
                SetGlowImpl(isGlow);
            }
            //SetGlowImpl(isGlow);
            return(null);
        }
Example #11
0
        public void RenderDepthNormal(Camera activeCamera, List <IRenderable> renderItems)
        {
            ShaderManager.GetInstance().DepthNormal.Parameters["World"].SetValue(Matrix.CreateTranslation(0, 0, 0));
            ShaderManager.GetInstance().DepthNormal.Parameters["View"].SetValue(activeCamera.CameraViewMatrix);
            ShaderManager.GetInstance().DepthNormal.Parameters["Projection"].SetValue(activeCamera.CameraProjectionMatrix);
            //  ShaderManager.GetInstance().DepthNormal.CurrentTechnique = ShaderManager.GetInstance().DepthNormal.Techniques["Technique1"];

            //Set the texture that the effect will be rendered to
            graphicsDevice.SetRenderTargets(_normalTarget, _depthTarget);
            graphicsDevice.Clear(Color.White);

            foreach (EffectPass pass in ShaderManager.GetInstance().DepthNormal.CurrentTechnique.Passes)
            {
                pass.Apply();
            }

            foreach (IRenderable renderItem in renderItems)
            {
                renderItem.Render(ScreenManager.GetInstance().GraphicsDevice);
            }

            // Un-set the render targets
            graphicsDevice.SetRenderTargets(null);
        }
Example #12
0
        public void RenderPointLightmap(Camera activeCamera, List <PointLight> pointLights)
        {
            // Set the depth and normal map info to the effect
            ShaderManager.GetInstance().Lightmap.Parameters["DepthTexture"].SetValue(_depthTarget);
            ShaderManager.GetInstance().Lightmap.Parameters["NormalTexture"].SetValue(_normalTarget);
            // Set effect parameters to light mapping effect
            ShaderManager.GetInstance().Lightmap.Parameters["viewportWidth"].SetValue((float)viewWidth);
            ShaderManager.GetInstance().Lightmap.Parameters["viewportHeight"].SetValue((float)viewHeight);

            // Calculate the view * projection matrix
            Matrix viewProjection = activeCamera.CameraViewMatrix * activeCamera.CameraProjectionMatrix;

            // Set the inverse of the view * projection matrix to the effect
            Matrix invViewProjection = Matrix.Invert(viewProjection);

            ShaderManager.GetInstance().Lightmap.Parameters["InvViewProjection"].SetValue(invViewProjection);

            // Set the render target to the graphics device
            graphicsDevice.SetRenderTarget(_lightTarget);

            // Clear the render target to black (no light)
            graphicsDevice.Clear(Color.Black);

            // Set render states to additive (lights will add their influences)
            graphicsDevice.BlendState        = BlendState.Additive;
            graphicsDevice.DepthStencilState = DepthStencilState.None;

            //Loop through all lights in the scene and render them
            foreach (PointLight pointLight in pointLights)
            {
                pointLight.SetEffectParameters(ShaderManager.GetInstance().Lightmap);

                // Calculate the world * view * projection matrix and set it to
                // the effect
                Matrix wvp = (Matrix.CreateScale(pointLight.Attenuation)
                              * Matrix.CreateTranslation(pointLight.Position)) * viewProjection;

                ShaderManager.GetInstance().Lightmap.Parameters["WorldViewProjection"].SetValue(wvp);

                // Determine the distance between the light and camera
                float dist = Vector3.Distance(activeCamera.CameraPosition,
                                              pointLight.Position);
                // If the camera is inside the light-sphere, invert the cull mode
                // to draw the inside of the sphere instead of the outside
                if (dist < pointLight.Attenuation)
                {
                    graphicsDevice.RasterizerState = RasterizerState.CullClockwise;
                }

                // Draw the point-light-sphere
                //    sphereModel2.Meshes[0].Draw();//NOTE: Model does not render properly - problem with world matrix
                foreach (ModelMesh mesh in sphereModel.Meshes)
                {
                    foreach (ModelMeshPart part in mesh.MeshParts)
                    {
                        part.Effect = ShaderManager.GetInstance().Lightmap;
                    }
                    mesh.Draw();
                }

                // Revert the cull mode
                graphicsDevice.RasterizerState = RasterizerState.
                                                 CullCounterClockwise;
            }

            // Revert the blending and depth render states
            graphicsDevice.BlendState        = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.Default;

            // Un-set the render target
            graphicsDevice.SetRenderTarget(null);
        }