예제 #1
0
        public void Draw(DrawState state)
        {
            //switch rendering mode based on the TutorialRenderMode flag
            switch (state.GetDrawFlag <TutorialRenderMode>())
            {
            case TutorialRenderMode.DepthOutput:
                //bind the depth output shader
                state.GetShader <Xen.Ex.Shaders.NonLinearDepthOutRg>().Bind(state);
                break;

            case TutorialRenderMode.DrawShadow:
                //bind the shadow rendering shader
                Shader.ShadowShader shader = state.GetShader <Shader.ShadowShader>();
                shader.TextureMap     = material.TextureMap;
                shader.TextureSampler = material.TextureMapSampler;
                shader.Bind(state);
                break;

            default:
                //no flag known specified
                material.Bind(state);
                break;
            }

            //draw the ground
            vertices.Draw(state, null, PrimitiveType.TriangleFan);
        }
예제 #2
0
        //draw the ground plane..
        public void Draw(DrawState state)
        {
            //first bind the material shader
            material.Bind(state);

            //then draw the vertices
            vertices.Draw(state, null, PrimitiveType.TriangleFan);
        }
예제 #3
0
        /// <summary>
        /// End the modifier (This method is called by the DrawTarget)
        /// </summary>
        /// <param name="state"></param>
        public void End(DrawState state)
        {
            if (enabledBuffer)
            {
                state.PopPostCuller();
            }

            if (cubes.Count > 0 ||
                spheres.Count > 0)
            {
                state.PushCamera(camera);

                state.PushRenderState();
                state.RenderState.DepthColourCull.DepthWriteEnabled = false;
                state.RenderState.AlphaBlend = AlphaBlendState.Alpha;

                Xen.Ex.Shaders.FillSolidColour shader = state.GetShader <Xen.Ex.Shaders.FillSolidColour>();
                shader.FillColour = new Vector4(1, 1, 1, 0.25f);
                shader.Bind(state);

                GenCubeVS(state);
                GenSphereVS(state);

                Matrix mat;
                for (int i = 0; i < cubes.Count; i++)
                {
                    mat = cubes[i];
                    state.PushWorldMatrix(ref mat);

                    cubeVS.Draw(state, null, PrimitiveType.LineList);

                    state.PopWorldMatrix();
                }

                mat = Matrix.Identity;
                Vector4 v;
                for (int i = 0; i < spheres.Count; i++)
                {
                    v = spheres[i];

                    mat.M11 = v.W;
                    mat.M22 = v.W;
                    mat.M33 = v.W;
                    mat.M41 = v.X;
                    mat.M42 = v.Y;
                    mat.M43 = v.Z;

                    state.PushWorldMatrix(ref mat);

                    sphereVS.Draw(state, null, PrimitiveType.LineList);

                    state.PopWorldMatrix();
                }

                state.PopRenderState();
                state.PopCamera();
            }
        }
예제 #4
0
        public void Draw(DrawState state)
        {
            Xen.Ex.Shaders.FillSolidColour shader = state.GetShader <Xen.Ex.Shaders.FillSolidColour>();

            shader.FillColour = colour;

            shader.Bind(state);
            vertices.Draw(state, null, PrimitiveType.TriangleStrip);
        }
예제 #5
0
        public void Draw(DrawState state)
        {
            //scale the mesh
            Matrix scaleMatrix;

            Matrix.CreateScale(this.scale, out scaleMatrix);

            state.PushWorldMatrixMultiply(ref worldMatrix);
            state.PushWorldMatrixMultiply(ref scaleMatrix);

            //setup blending
            state.PushRenderState();
            state.RenderState.DepthColourCull.CullMode = CullMode.None;
            state.RenderState.AlphaBlend = AlphaBlendState.AdditiveSaturate;
            state.RenderState.DepthColourCull.DepthWriteEnabled = false;

            //draw
            Xen.Ex.Shaders.FillVertexColour shader = state.GetShader <Xen.Ex.Shaders.FillVertexColour>();

            shader.Bind(state);
            vertices.Draw(state, null, PrimitiveType.TriangleFan);

            state.PopRenderState();

            state.PopWorldMatrix();
            state.PopWorldMatrix();

            //this is a hack :-)
            //flicker the scale

            //every so often, target a new scale
            if (random.Next(100) > 75)
            {
                scaleTarget = (float)random.NextDouble() * 0.4f + 0.6f;
            }

            //interpolate to the scale target
            this.scale = this.scale * 0.75f + this.scaleTarget * 0.25f;
        }
예제 #6
0
파일: Stats.cs 프로젝트: ARLM-Attic/xna-xen
        protected override void DrawElement(DrawState state)
        {
            if (graph == null)
            {
                graph = state.UserValues[graphID] as IVertices;

                if (graph == null)
                {
                    float[] graphValues = new float[MaxGraphSamples];
                    for (int i = 0; i < MaxGraphSamples; i++)
                    {
                        graphValues[i] = (float)i;
                    }

                    this.graph = Vertices <float> .CreateSingleElementVertices(graphValues, VertexElementUsage.Position, 0);

                    state.UserValues[graphID] = this.graph;
                }
            }

            graph.Draw(state, null, PrimitiveType.LineStrip, this.values.Length - 1, 0, 0);
        }
예제 #7
0
파일: Cube.cs 프로젝트: ARLM-Attic/xna-xen
 /// <summary>
 /// Draw the cube geometry
 /// </summary>
 /// <param name="state"></param>
 public void Draw(DrawState state)
 {
     verts.Draw(state, inds, PrimitiveType.TriangleList);
 }
예제 #8
0
        /// <summary>
        /// draws the particles on a GPU system
        /// </summary>
        protected override void DrawGpuParticles(DrawState state, Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Texture2D positionTex, Texture2D velocityRotation, Texture2D colourTex, Texture2D userValues, bool usesUserValuesPositionBuffer)
        {
            //this is very similar to the billboard drawer (see it for reference)
            Vector2 targetSize = state.DrawTarget.Size;

            state.PushRenderState();
            state.RenderState.AlphaBlend = blendMode;
            state.RenderState.DepthColourCull.DepthWriteEnabled = false;

            Texture2D displayTexture = particleType.Texture ?? Xen.Ex.Material.WhiteTexture.GetTexture(state);

            //get the shared vertice
            BillboardParticles2DElement.GenerateBillboardVertices(state, ref vertices, ref indices);

            int count = (int)particleCount;

            DrawVelocityParticles_GpuTex       shaderNoColour = null;
            DrawVelocityParticlesColour_GpuTex shaderColour   = null;
            //user variants
            DrawVelocityParticles_GpuTex_UserOffset       shaderNoColour_UO = null;
            DrawVelocityParticlesColour_GpuTex_UserOffset shaderColour_UO   = null;

            float resolutionXF = (float)positionTex.Width;
            float resolutionYF = (float)positionTex.Height;

            Vector2 invTextureSize;

            Vector2 velScale = new Vector2(velocityScale, 0);

            if (this.useRotationToScaleVelocityEffect)
            {
                velScale = new Vector2(0, velocityScale);
            }
            invTextureSize = new Vector2(1.0f / resolutionXF, 1.0f / resolutionYF);


            IShader shader;

            if (!usesUserValuesPositionBuffer)
            {
                if (colourTex != null)
                {
                    shader = shaderColour = state.GetShader <DrawVelocityParticlesColour_GpuTex>();

                    shaderColour.PositionTexture = positionTex;
                    shaderColour.ColourTexture   = colourTex;
                    shaderColour.VelocityTexture = velocityRotation;
                    shaderColour.DisplayTexture  = displayTexture;

                    shaderColour.SetVelocityScale(ref velScale);
                }
                else
                {
                    shader = shaderNoColour = state.GetShader <DrawVelocityParticles_GpuTex>();

                    shaderNoColour.PositionTexture = positionTex;
                    shaderNoColour.VelocityTexture = velocityRotation;
                    shaderNoColour.DisplayTexture  = displayTexture;

                    shaderNoColour.SetVelocityScale(ref velScale);
                }
            }
            else
            {
                if (colourTex != null)
                {
                    shader = shaderColour_UO = state.GetShader <DrawVelocityParticlesColour_GpuTex_UserOffset>();

                    shaderColour_UO.PositionTexture = positionTex;
                    shaderColour_UO.ColourTexture   = colourTex;
                    shaderColour_UO.VelocityTexture = velocityRotation;
                    shaderColour_UO.UserTexture     = userValues;
                    shaderColour_UO.DisplayTexture  = displayTexture;

                    shaderColour_UO.SetVelocityScale(ref velScale);
                }
                else
                {
                    shader = shaderNoColour_UO = state.GetShader <DrawVelocityParticles_GpuTex_UserOffset>();

                    shaderNoColour_UO.PositionTexture = positionTex;
                    shaderNoColour_UO.VelocityTexture = velocityRotation;
                    shaderNoColour_UO.UserTexture     = userValues;
                    shaderNoColour_UO.DisplayTexture  = displayTexture;

                    shaderNoColour_UO.SetVelocityScale(ref velScale);
                }
            }


            int drawn = 0;

            while (count > 0)
            {
                int drawCount = Math.Min(count, vertices.Count / 4);

                if (!usesUserValuesPositionBuffer)
                {
                    if (colourTex != null)
                    {
                        shaderColour.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
                    }
                    else
                    {
                        shaderNoColour.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
                    }
                }
                else
                {
                    if (colourTex != null)
                    {
                        shaderColour_UO.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
                    }
                    else
                    {
                        shaderNoColour_UO.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
                    }
                }

                //bind
                shader.Bind(state);

                vertices.Draw(state, indices, PrimitiveType.TriangleList, drawCount * 2, 0, 0);

                count -= drawCount;
                drawn += drawCount;
            }


            state.PopRenderState();
        }
예제 #9
0
        //draw the particle update data
        void IDraw.Draw(DrawState state)
        {
            int copyIndex = 0;

            //keep an application wide cache of the vertices used
            AllocateVertices(state);


            //special mode, renderig the life / age of particles

            if (renderLifeStoreMode)
            {
                DrawLifeAgeToStore(state);
                return;
            }
            //otherwise, render normal

            //move particles
            if (activeRenderPass.CopyCount > 0)
            {
                while (activeRenderPass.CopyCount > 0)
                {
                    int count = (this.processorData.FrameMoveShader as GpuParticleShader).SetMoveShaderEnabled(state, this, null, activeRenderPass.CopyData, null, activeRenderPass.CopyCount, copyIndex);

                    this.processorData.FrameMoveShader.Bind(state);

                    verticesRenderIndex.Draw(state, null, PrimitiveType.PointList, Math.Min(count, activeRenderPass.CopyCount), 0, 0);

                    activeRenderPass.CopyCount -= count;
                    copyIndex += count;
                }
            }

            //particle are being added?
            for (int i = 0; i < activeRenderPass.AddLists.Length; i++)
            {
                ProcessorAddList list = activeRenderPass.AddLists[i];

                if (list.AddCount > 0)
                {
                    copyIndex = 0;

                    GpuParticleShader shader = this.processorData.OnceShader as GpuParticleShader;

                    //added from a different processor?
                    if (list.processor != null)
                    {
                        shader = this.processorData.OnceCloneShader as GpuParticleShader;

                        Texture2D t0, t1, t2, t3, t4;
                        list.processor.GetLogicTextures(state, out t0, out t1, out t2, out t3, out t4);
                        shader.SetTextures(state, t0, t1, t2, t3, randomTexture.GetTexture(state), t4);
                    }
                    else
                    {
                        shader.SetTextures(state, null, null, null, null, randomTexture.GetTexture(state), null);
                    }

                    while (list.AddCount > 0)
                    {
                        //draw them
                        int count = shader.SetMoveShaderEnabled(state, this, list.processor, list.AddData, list.AddDetails, list.AddCount, copyIndex);

                        shader.Bind(state);

                        verticesRenderIndex.Draw(state, null, PrimitiveType.PointList, Math.Min(count, list.AddCount), 0, 0);

                        list.AddCount -= count;
                        copyIndex     += count;
                    }
                }
            }
        }
예제 #10
0
        /// <summary>
        /// implements the method to draw gpu particles
        /// </summary>
        protected override void DrawGpuParticles(DrawState state, Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Texture2D positionTex, Texture2D velocityRotation, Texture2D colourTex, Texture2D userValues, bool usesUserValuesPositionBuffer)
        {
            Vector2 targetSize = state.DrawTarget.Size;

            state.PushRenderState();
            state.RenderState.AlphaBlend = blendMode;
            state.RenderState.DepthColourCull.DepthWriteEnabled = false;

            //get the display texture, or a white texture if none exists
            Texture2D displayTexture = particleType.Texture ?? Xen.Ex.Material.WhiteTexture.GetTexture(state);

            //get / create the shared vertices and indices for drawing billboard particles
            BillboardParticles2DElement.GenerateBillboardVertices(state, ref vertices, ref indices);

            int count = (int)particleCount;

            //instances of the two possible shaders
            DrawVelocityBillboardParticles_GpuTex3D       shaderNoColour = null;
            DrawVelocityBillboardParticlesColour_GpuTex3D shaderColour   = null;
            //user variantes
            DrawVelocityBillboardParticles_GpuTex3D_UserOffset       shaderNoColour_UO = null;
            DrawVelocityBillboardParticlesColour_GpuTex3D_UserOffset shaderColour_UO   = null;

            float resolutionXF = (float)positionTex.Width;
            float resolutionYF = (float)positionTex.Height;

            Vector2 invTextureSize = new Vector2(1.0f / resolutionXF, 1.0f / resolutionYF);

            Matrix cameraMatrix;

            state.Camera.GetCameraMatrix(out cameraMatrix);

            Vector3 worldSpaceYAxis = new Vector3(cameraMatrix.M21, cameraMatrix.M22, cameraMatrix.M23);


            Vector2 velScale = new Vector2(velocityScale, 0);

            if (this.useRotationToScaleVelocityEffect)
            {
                velScale = new Vector2(0, velocityScale);
            }

            IShader shader;

            if (!usesUserValuesPositionBuffer)
            {
                if (colourTex != null)                 // does this particle system use colours?
                {
                    //get the shader
                    shaderColour = state.GetShader <DrawVelocityBillboardParticlesColour_GpuTex3D>();

                    //set the samplers
                    shaderColour.PositionTexture = positionTex;
                    shaderColour.ColourTexture   = colourTex;
                    shaderColour.VelocityTexture = velocityRotation;
                    shaderColour.DisplayTexture  = displayTexture;

                    shaderColour.SetWorldSpaceYAxis(ref worldSpaceYAxis);
                    shaderColour.SetVelocityScale(ref velScale);
                    shader = shaderColour;
                }
                else
                {
                    shaderNoColour = state.GetShader <DrawVelocityBillboardParticles_GpuTex3D>();

                    shaderNoColour.PositionTexture = positionTex;
                    shaderNoColour.VelocityTexture = velocityRotation;
                    shaderNoColour.DisplayTexture  = displayTexture;

                    shaderNoColour.SetWorldSpaceYAxis(ref worldSpaceYAxis);
                    shaderNoColour.SetVelocityScale(ref velScale);
                    shader = shaderNoColour;
                }
            }
            else
            {
                if (colourTex != null)                 // does this particle system use colours?
                {
                    //get the shader
                    shaderColour_UO = state.GetShader <DrawVelocityBillboardParticlesColour_GpuTex3D_UserOffset>();

                    //set the samplers
                    shaderColour_UO.PositionTexture = positionTex;
                    shaderColour_UO.ColourTexture   = colourTex;
                    shaderColour_UO.VelocityTexture = velocityRotation;
                    shaderColour_UO.UserTexture     = userValues;
                    shaderColour_UO.DisplayTexture  = displayTexture;

                    shaderColour_UO.SetWorldSpaceYAxis(ref worldSpaceYAxis);
                    shaderColour_UO.SetVelocityScale(ref velScale);
                    shader = shaderColour_UO;
                }
                else
                {
                    shaderNoColour_UO = state.GetShader <DrawVelocityBillboardParticles_GpuTex3D_UserOffset>();

                    shaderNoColour_UO.PositionTexture = positionTex;
                    shaderNoColour_UO.VelocityTexture = velocityRotation;
                    shaderNoColour_UO.UserTexture     = userValues;
                    shaderNoColour_UO.DisplayTexture  = displayTexture;

                    shaderNoColour_UO.SetWorldSpaceYAxis(ref worldSpaceYAxis);
                    shaderNoColour_UO.SetVelocityScale(ref velScale);
                    shader = shaderNoColour_UO;
                }
            }


            int drawn = 0;

            while (count > 0)
            {
                //draw upto vertices.Count / 4 (4 vertices per quad)
                int drawCount = Math.Min(count, vertices.Count / 4);

                //set the inverse texture size, and the start offset value, then bind the shader
                if (!usesUserValuesPositionBuffer)
                {
                    if (colourTex != null)
                    {
                        shaderColour.InvTextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
                    }
                    else
                    {
                        shaderNoColour.InvTextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
                    }
                }
                else
                {
                    if (colourTex != null)
                    {
                        shaderColour_UO.InvTextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
                    }
                    else
                    {
                        shaderNoColour_UO.InvTextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
                    }
                }

                //bind
                shader.Bind(state);

                //draw!
                vertices.Draw(state, indices, PrimitiveType.TriangleList, drawCount * 2, 0, 0);

                count -= drawCount;
                drawn += drawCount;
            }

            //and done.
            state.PopRenderState();
        }