Пример #1
0
        /// <summary>
        /// Initializes a new instance of Surface.
        /// </summary>
        public Surface( Renderer renderer, string materialName, Size size )
        {
            this.renderer = renderer;
            this.materialName = materialName;
            this.size = size;

            quad = Mesh.Rectangle( renderer, Color.White, size.Width, size.Height );
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of Surface.
        /// </summary>
        public Surface( Renderer renderer, string materialName, Size size,
            float textureMapTiling)
        {
            this.renderer = renderer;
            this.materialName = materialName;
            this.size = size;

            quad = Mesh.Rectangle( renderer, Color.Black, size.Width, size.Height, textureMapTiling );
        }
Пример #3
0
        /// <summary>
        /// Initializes the BloomPostProcessor.
        /// </summary>
        public BloomPostProcessor( Renderer renderer )
        {
            if ( renderer == null )
                throw new ArgumentNullException( "renderer", "Can't create the BloomPostProcessor with a "
                    + "null Renderer reference." );

            this.renderer = renderer;

            brightPassTex = new Texture( renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true );
            blurHorizontalTex = new Texture( renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true );
            blurVerticalTex = new Texture( renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true );
            finalBloomImage = new Texture( renderer, renderer.FullscreenSize.Width,
                renderer.FullscreenSize.Height, true );

            fullscreenQuad = Mesh.Rectangle( renderer, Color.Black, renderer.FullscreenSize.Width,
                renderer.FullscreenSize.Height );

            bloomEffect = GlobalResourceCache.CreateEffectFromFile( renderer,
                @".\\FXFiles\\Bloom.fx" );
        }
Пример #4
0
Файл: Mesh.cs Проект: zpconn/Gas
        /// <summary>
        /// Determines if two static (non-moving) meshes interpenetrate.
        /// </summary>
        /// <param name="other">The mesh to test for intersection against.</param>
        /// <param name="worldMat1">The world transform matrix for this mesh.</param>
        /// <param name="worldMat2">The world transform matrix for 'other'.</param>
        /// <returns>A boolean value indicating whether interpenetration occurs.</returns>
        public bool Intersects( Mesh other, Matrix worldMat1, Matrix worldMat2 )
        {
            for ( int vertexIndex = 0; vertexIndex < numVertices; ++vertexIndex )
            {
                Vector2 vertex = Vector2.TransformCoordinate( GetVertexPosition( vertexIndex ), worldMat1 );
                int numAwayFacingEdges = 0;

                for ( int edgeIndex = 0; edgeIndex < other.NumEdges; ++edgeIndex )
                {
                    Edge edge = other.GetEdge( edgeIndex );
                    Vector2 edgeCenter =
                        ( Vector2.TransformCoordinate( edge.Vertex1Pos, worldMat2 ) +
                        Vector2.TransformCoordinate( edge.Vertex2Pos, worldMat2 ) ) * 0.5f;
                    Vector2 vertexDir = edgeCenter - vertex;

                    // If the edge faces away from the vertex
                    if ( Vector2.Dot( vertexDir, edge.Normal ) >= 0.0f )
                        ++numAwayFacingEdges;
                }

                if ( numAwayFacingEdges == other.NumEdges )
                    return true;
            }

            for ( int vertexIndex = 0; vertexIndex < other.NumVertices; ++vertexIndex )
            {
                Vector2 vertex = Vector2.TransformCoordinate( other.GetVertexPosition( vertexIndex ), worldMat2 );
                int numAwayFacingEdges = 0;

                for ( int edgeIndex = 0; edgeIndex < NumEdges; ++edgeIndex )
                {
                    Edge edge = GetEdge( edgeIndex );
                    Vector2 edgeCenter =
                        ( Vector2.TransformCoordinate( edge.Vertex1Pos, worldMat1 ) +
                        Vector2.TransformCoordinate( edge.Vertex2Pos, worldMat1 ) ) * 0.5f;
                    Vector2 vertexDir = edgeCenter - vertex;

                    // If the edge faces away from the vertex
                    if ( Vector2.Dot( vertexDir, edge.Normal ) >= 0.0f )
                        ++numAwayFacingEdges;
                }

                if ( numAwayFacingEdges == NumEdges )
                    return true;
            }

            return false;
        }
Пример #5
0
Файл: Mesh.cs Проект: zpconn/Gas
        /// <summary>
        /// Builds a rectangular mesh, centered around the origin.
        /// </summary>
        public static Mesh Rectangle( Renderer renderer, Color color, float width, float height,
            float textureMapTiling)
        {
            Mesh rectMesh = new Mesh( renderer, 4, 2 );

            rectMesh.AddVertex( 0, new Vector3( -width / 2, height / 2, 1.0f ), color,
                new Vector2( 0.0f, 0.0f ) );
            rectMesh.AddVertex( 1, new Vector3( width / 2, height / 2, 1.0f ), color,
                new Vector2( textureMapTiling, 0.0f ) );
            rectMesh.AddVertex( 2, new Vector3( width / 2, -height / 2, 1.0f ), color,
                new Vector2( textureMapTiling, textureMapTiling ) );
            rectMesh.AddVertex( 3, new Vector3( -width / 2, -height / 2, 1.0f ), color,
                new Vector2( 0.0f, textureMapTiling ) );

            rectMesh.AddTriangle( 0, 0, 1, 2 );
            rectMesh.AddTriangle( 1, 0, 2, 3 );

            return rectMesh;
        }
Пример #6
0
Файл: Mesh.cs Проект: zpconn/Gas
        /// <summary>
        /// Builds a circular mesh centered around the origin.
        /// </summary>
        public static Mesh Circle( Renderer renderer, Color color, float radius,
            int numSubdivisions, float textureMapTiling)
        {
            Mesh circleMesh = new Mesh( renderer, numSubdivisions, numSubdivisions - 2 );

            float angleStep = ( 2 * ( float )Math.PI ) / numSubdivisions;
            for ( int i = 0; i < numSubdivisions; ++i )
            {
                Vector2 texCoords = textureMapTiling * ( new Vector2(
                    ( float )Math.Cos( angleStep * i ) / 2.0f + 0.5f,
                    1.0f - ( ( float )Math.Sin( angleStep * i ) / 2.0f + 0.5f ) ) );

                circleMesh.AddVertex( i, new Vector3( radius * ( float )Math.Cos( angleStep * i ),
                    radius * ( float )Math.Sin( angleStep * i ), 1.0f ), color, texCoords );
            }

            for ( int i = 2, count = 0; i < numSubdivisions - 1; ++i, ++count )
            {
                circleMesh.AddTriangle( count, 0, i, i - 1 );
            }

            circleMesh.AddTriangle( numSubdivisions - 3, 0, numSubdivisions - 2, numSubdivisions - 1 );

            return circleMesh;
        }
Пример #7
0
        public static void GenerateShadow( Mesh polygonGeometry, Matrix worldMatrix, Vector2 lightPosWS,
            float zValue, Vector2 shadowCasterCenter)
        {
            Vector3 UVOffset = new Vector3( 0.0f, -0.5f, 0.0f );

            // Transform the light position into model space
            Vector2 lightPos = Vector2.TransformCoordinate( lightPosWS, Matrix.Invert( worldMatrix ) );

            List<Edge> contourEdges = new List<Edge>();

            for ( int edgeIndex = 0; edgeIndex < polygonGeometry.NumEdges; ++edgeIndex )
            {
                Edge edge = polygonGeometry.GetEdge( edgeIndex );
                Vector2 edgeCenter = ( edge.Vertex1Pos + edge.Vertex2Pos ) * 0.5f;
                Vector2 incidentLightDir = edgeCenter - lightPos;

                // If the edge faces away from the light source
                if ( Vector2.Dot( incidentLightDir, edge.Normal ) >= 0.0f )
                {
                    contourEdges.Add( edge );
                }
            }

            if ( contourEdges.Count < 1 || contourEdges.Count == polygonGeometry.NumEdges )
            {
                return;
            }

            const float ExtrudeMagnitude = 1280;

            Shadow shadow = new Shadow();

            Vector3 lightPosVec3 = new Vector3( lightPos.X, lightPos.Y, zValue );
            lightPosVec3.TransformCoordinate( worldMatrix );

            int quadIndex = 0;
            foreach ( Edge edge in contourEdges )
            {
                Vector3 vertex1 = new Vector3(
                    edge.Vertex1Pos.X, edge.Vertex1Pos.Y, zValue );
                Vector3 vertex2 = new Vector3(
                    edge.Vertex2Pos.X, edge.Vertex2Pos.Y, zValue );

                // Transform the position data from model space to world space
                vertex1.TransformCoordinate( worldMatrix );
                vertex2.TransformCoordinate( worldMatrix );

                Quad quad = new Quad();
                Color shadowColor = Color.FromArgb( 1, 0, 0, 0 );

                quad.Vertices[ 2 * quadIndex + 0 ].Position = vertex1 + UVOffset -
                    18.0f * Vector3.Normalize( vertex1 - lightPosVec3 );
                quad.Vertices[ 2 * quadIndex + 0 ].Color = shadowColor.ToArgb();

                quad.Vertices[ 2 * quadIndex + 1 ].Position = vertex1 + ExtrudeMagnitude * ( vertex1 - lightPosVec3 )
                     + UVOffset;
                quad.Vertices[ 2 * quadIndex + 1 ].Color = shadowColor.ToArgb();

                quad.Vertices[ 2 * quadIndex + 2 ].Position = vertex2 + UVOffset -
                    18.0f * Vector3.Normalize( vertex2 - lightPosVec3 );
                quad.Vertices[ 2 * quadIndex + 2 ].Color = shadowColor.ToArgb();

                quad.Vertices[ 2 * quadIndex + 3 ].Position = vertex2 + ExtrudeMagnitude * ( vertex2 - lightPosVec3 )
                    + UVOffset;
                quad.Vertices[ 2 * quadIndex + 3 ].Color = shadowColor.ToArgb();

                shadow.Quads.Add( quad );
            }

            shadows.Add( shadow );
        }
Пример #8
0
        public static void Initialize( Renderer renderer )
        {
            ShadowManager.renderer = renderer;

            blur = config.GetSetting<float>( "ShadowBlur" );

            shadowTex = new Texture( renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true );
            blurHorizontalTex = new Texture( renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true );
            blurVerticalTex = new Texture( renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true );
            finalTex = new Texture( renderer, renderer.FullscreenSize.Width,
                renderer.FullscreenSize.Height, true );

            fullscreenQuad = Mesh.Rectangle( renderer, Color.Black, renderer.FullscreenSize.Width,
                renderer.FullscreenSize.Height );

            shadowEffect = GlobalResourceCache.CreateEffectFromFile( renderer,
                @".\\FXFiles\\Shadow.fx" );

            initialized = true;
        }