Пример #1
0
        public override void ApplyObliqueDepthProjection(ref Matrix4 matrix, Plane plane, bool forGpuProgram)
        {
            // Thanks to Eric Lenyel for posting this calculation at www.terathon.com

            // Calculate the clip-space corner point opposite the clipping plane
            // as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
            // transform it into camera space by multiplying it
            // by the inverse of the projection matrix

            /* generalised version
             * Vector4 q = matrix.inverse() *
             *  Vector4(Math::Sign(plane.normal.x), Math::Sign(plane.normal.y), 1.0f, 1.0f);
             */
            var q = new Vector4();

            q.x = System.Math.Sign(plane.Normal.x) / matrix.m00;
            q.y = System.Math.Sign(plane.Normal.y) / matrix.m11;
            q.z = 1.0f;

            // flip the next bit from Lengyel since we're right-handed
            if (forGpuProgram)
            {
                q.w = (1.0f - matrix.m22) / matrix.m23;
            }
            else
            {
                q.w = (1.0f + matrix.m22) / matrix.m23;
            }

            // Calculate the scaled plane vector
            var clipPlane4D = new Vector4(plane.Normal.x, plane.Normal.y, plane.Normal.z, plane.D);

            var c = clipPlane4D * (1.0f / (clipPlane4D.Dot(q)));

            // Replace the third row of the projection matrix
            matrix.m20 = c.x;
            matrix.m21 = c.y;

            // flip the next bit from Lengyel since we're right-handed
            if (forGpuProgram)
            {
                matrix.m22 = c.z;
            }
            else
            {
                matrix.m22 = -c.z;
            }

            matrix.m23 = c.w;
        }
Пример #2
0
		public override void UpdateGpuProgramsParams( Graphics.IRenderable rend, Graphics.Pass pass,
		                                              Graphics.AutoParamDataSource source,
		                                              Core.Collections.LightList lightList )
		{
			int shadowIndex = 0;

			foreach ( var it in this.shadowTextureParamsList )
			{
				it.WorldViewProjMatrix.SetGpuParameter( source.GetTextureWorldViewProjMatrix( shadowIndex ) );
				it.InvTextureSize.SetGpuParameter( source.GetInverseTextureSize( it.TextureSamplerIndex ) );

				shadowIndex++;
			}

			var splitPoints = new Vector4();

			splitPoints.x = this.shadowTextureParamsList[ 0 ].MaxRange;
			splitPoints.y = this.shadowTextureParamsList[ 1 ].MaxRange;
			splitPoints.z = 0.0;
			splitPoints.w = 0.0;

			this.psSplitPoints.SetGpuParameter( splitPoints );
		}
Пример #3
0
		/// <summary>
		///		Multiplies a Vector4 by a scalar value.
		/// </summary>
		/// <param name="vector"></param>
		/// <param name="scalar"></param>
		/// <returns></returns>
		public static Vector4 operator *( Vector4 vector, Real scalar )
		{
			var result = new Vector4();

			result.x = vector.x*scalar;
			result.y = vector.y*scalar;
			result.z = vector.z*scalar;
			result.w = vector.w*scalar;

			return result;
		}
Пример #4
0
		// TODO: Find the signifance of having 2 overloads with opposite param lists that do transposed operations
		public static Vector4 operator *( Vector4 vector, Matrix4 matrix )
		{
			var result = new Vector4();

			result.x = vector.x*matrix.m00 + vector.y*matrix.m10 + vector.z*matrix.m20 + vector.w*matrix.m30;
			result.y = vector.x*matrix.m01 + vector.y*matrix.m11 + vector.z*matrix.m21 + vector.w*matrix.m31;
			result.z = vector.x*matrix.m02 + vector.y*matrix.m12 + vector.z*matrix.m22 + vector.w*matrix.m32;
			result.w = vector.x*matrix.m03 + vector.y*matrix.m13 + vector.z*matrix.m23 + vector.w*matrix.m33;

			return result;
		}
Пример #5
0
		/// <summary>
		///		
		/// </summary>
		/// <param name="vector"></param>
		/// <param name="matrix"></param>
		/// <returns></returns>
		public static Vector4 Multiply( Vector4 vector, Matrix4 matrix )
		{
			return vector*matrix;
		}
Пример #6
0
		/// <summary>
		///     Calculates the dot (scalar) product of this vector with another.
		/// </summary>
		/// <param name="vec">
		///     Vector with which to calculate the dot product (together with this one).
		/// </param>
		/// <returns>A Real representing the dot product value.</returns>
		public Real Dot( Vector4 vec )
		{
			return this.x*vec.x + this.y*vec.y + this.z*vec.z + this.w*vec.w;
		}
		public override void ApplyObliqueDepthProjection( ref Matrix4 matrix, Plane plane, bool forGpuProgram )
		{
			// Thanks to Eric Lenyel for posting this calculation at www.terathon.com

			// Calculate the clip-space corner point opposite the clipping plane
			// as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
			// transform it into camera space by multiplying it
			// by the inverse of the projection matrix

			/* generalised version
            Vector4 q = matrix.inverse() *
                Vector4(Math::Sign(plane.normal.x), Math::Sign(plane.normal.y), 1.0f, 1.0f);
            */
			var q = new Vector4();
			q.x = System.Math.Sign( plane.Normal.x )/matrix.m00;
			q.y = System.Math.Sign( plane.Normal.y )/matrix.m11;
			q.z = 1.0f;

			// flip the next bit from Lengyel since we're right-handed
			if ( forGpuProgram )
			{
				q.w = ( 1.0f - matrix.m22 )/matrix.m23;
			}
			else
			{
				q.w = ( 1.0f + matrix.m22 )/matrix.m23;
			}

			// Calculate the scaled plane vector
			var clipPlane4D = new Vector4( plane.Normal.x, plane.Normal.y, plane.Normal.z, plane.D );

			var c = clipPlane4D*( 1.0f/( clipPlane4D.Dot( q ) ) );

			// Replace the third row of the projection matrix
			matrix.m20 = c.x;
			matrix.m21 = c.y;

			// flip the next bit from Lengyel since we're right-handed
			if ( forGpuProgram )
			{
				matrix.m22 = c.z;
			}
			else
			{
				matrix.m22 = -c.z;
			}

			matrix.m23 = c.w;
		}
Пример #8
0
		public void SetFogProperties( FogMode fogMode, ColorEx fogColor, float fogStart, float fogEnd, float fogDensity )
		{
			this.fogMode = fogMode;
			this.fogColorValue = fogColor;
			this.fogParamsValue = new Vector4( fogDensity, fogStart, fogEnd, fogEnd != fogStart ? 1/( fogEnd - fogStart ) : 0 );
		}