Beispiel #1
0
        internal void ReadEffect(BinaryReader reader)
        {
            var effectPass = new EffectPass(this, "Pass", null, null, BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullNone, new EffectAnnotationCollection());

            effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length));
            var shaderProgram = effectPass._shaderProgram;

            Parameters = new EffectParameterCollection();
            for (int i = 0; i < shaderProgram.UniformCount; i++)
            {
                Parameters.Add(EffectParameterForUniform(shaderProgram, i));
            }
#warning Hacks for BasicEffect as we don't have these parameters yet
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor",
                               3, 1, "float3",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3]));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower",
                               1, 1, "float",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), 0.0f));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "FogVector",
                               4, 1, "float4",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor",
                               4, 1, "float4",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));

            Techniques = new EffectTechniqueCollection();
            var effectPassCollection = new EffectPassCollection();
            effectPassCollection.Add(effectPass);
            Techniques.Add(new EffectTechnique(this, "Name", effectPassCollection, new EffectAnnotationCollection()));

            ConstantBuffers = new ConstantBuffer[0];

            CurrentTechnique = Techniques[0];
        }
Beispiel #2
0
		internal void ReadEffect(BinaryReader reader)
		{
			var effectPass = new EffectPass(this, "Pass", null, null, BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullNone, new EffectAnnotationCollection());
			effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length));
			var shaderProgram = effectPass._shaderProgram;
			Parameters = new EffectParameterCollection();
			for (int i = 0; i < shaderProgram.UniformCount; i++)
			{	
			    Parameters.Add(EffectParameterForUniform(shaderProgram, i));
			}
			
			#warning Hacks for BasicEffect as we don't have these parameters yet
            Parameters.Add (new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor",
                3, 1, "float3",
                new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3]));
            Parameters.Add (new EffectParameter(
                EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower",
                1, 1, "float",
                new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), 0.0f));
            Parameters.Add (new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "FogVector",
                4, 1, "float4",
                new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));
            Parameters.Add (new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor",
                4, 1, "float4",
                new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));
            
            Techniques = new EffectTechniqueCollection();
            var effectPassCollection = new EffectPassCollection();
            effectPassCollection.Add(effectPass);
            Techniques.Add(new EffectTechnique(this, "Name", effectPassCollection, new EffectAnnotationCollection()));
       
            ConstantBuffers = new ConstantBuffer[0];
            
            CurrentTechnique = Techniques[0];
        }
Beispiel #3
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List<Shader> shaders)
        {
            Shader vertexShader = null;
            Shader pixelShader = null;

            var collection = new EffectPassCollection();

            var count = (int)reader.ReadByte();

            for (var i = 0; i < count; i++)
            {
                var name = reader.ReadString();
                var annotations = ReadAnnotations(reader);

                
                // Assign these to the default shaders at this point? or do that in the effect pass.
                // Get the vertex shader.
                var shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                {
                    vertexShader = shaders[shaderIndex];
                }

                // Get the pixel shader.
                shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                {
                    pixelShader = shaders[shaderIndex];
                }

				BlendState blend = null;
				DepthStencilState depth = null;
				RasterizerState raster = null;
				if (reader.ReadBoolean())
				{
					blend = new BlendState
					{
						AlphaBlendFunction = (BlendFunction)reader.ReadByte(),
						AlphaDestinationBlend = (Blend)reader.ReadByte(),
						AlphaSourceBlend = (Blend)reader.ReadByte(),
						BlendFactor = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()),
						ColorBlendFunction = (BlendFunction)reader.ReadByte(),
						ColorDestinationBlend = (Blend)reader.ReadByte(),
						ColorSourceBlend = (Blend)reader.ReadByte(),
						ColorWriteChannels = (ColorWriteChannels)reader.ReadByte(),
						ColorWriteChannels1 = (ColorWriteChannels)reader.ReadByte(),
						ColorWriteChannels2 = (ColorWriteChannels)reader.ReadByte(),
						ColorWriteChannels3 = (ColorWriteChannels)reader.ReadByte(),
						MultiSampleMask = reader.ReadInt32(),
					};
				}
				if (reader.ReadBoolean())
				{
					depth = new DepthStencilState
					{
						CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
						CounterClockwiseStencilFail = (StencilOperation)reader.ReadByte(),
						CounterClockwiseStencilFunction = (CompareFunction)reader.ReadByte(),
						CounterClockwiseStencilPass = (StencilOperation)reader.ReadByte(),
						DepthBufferEnable = reader.ReadBoolean(),
						DepthBufferFunction = (CompareFunction)reader.ReadByte(),
						DepthBufferWriteEnable = reader.ReadBoolean(),
						ReferenceStencil = reader.ReadInt32(),
						StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
						StencilEnable = reader.ReadBoolean(),
						StencilFail = (StencilOperation)reader.ReadByte(),
						StencilFunction = (CompareFunction)reader.ReadByte(),
						StencilMask = reader.ReadInt32(),
						StencilPass = (StencilOperation)reader.ReadByte(),
						StencilWriteMask = reader.ReadInt32(),
						TwoSidedStencilMode = reader.ReadBoolean(),
					};
				}
				if (reader.ReadBoolean())
				{
					raster = new RasterizerState
					{
						CullMode = (CullMode)reader.ReadByte(),
						DepthBias = reader.ReadSingle(),
						FillMode = (FillMode)reader.ReadByte(),
						MultiSampleAntiAlias = reader.ReadBoolean(),
						ScissorTestEnable = reader.ReadBoolean(),
						SlopeScaleDepthBias = reader.ReadSingle(),
					};
				}
				var pass = new EffectPass(effect, name, vertexShader, pixelShader, blend, depth, raster, annotations);
				collection.Add(pass);         
			}

			return collection;
		}
Beispiel #4
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = null;
            Shader pixelShader  = null;

            var collection = new EffectPassCollection();

            var count = (int)reader.ReadByte();

            for (var i = 0; i < count; i++)
            {
                var name        = reader.ReadString();
                var annotations = ReadAnnotations(reader);


                // Assign these to the default shaders at this point? or do that in the effect pass.
                // Get the vertex shader.
                var shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                {
                    vertexShader = shaders[shaderIndex];
                }

                // Get the pixel shader.
                shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                {
                    pixelShader = shaders[shaderIndex];
                }

                BlendState        blend  = null;
                DepthStencilState depth  = null;
                RasterizerState   raster = null;
                if (reader.ReadBoolean())
                {
                    blend = new BlendState
                    {
                        AlphaBlendFunction    = (BlendFunction)reader.ReadByte(),
                        AlphaDestinationBlend = (Blend)reader.ReadByte(),
                        AlphaSourceBlend      = (Blend)reader.ReadByte(),
                        BlendFactor           = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()),
                        ColorBlendFunction    = (BlendFunction)reader.ReadByte(),
                        ColorDestinationBlend = (Blend)reader.ReadByte(),
                        ColorSourceBlend      = (Blend)reader.ReadByte(),
                        ColorWriteChannels    = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels1   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels2   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels3   = (ColorWriteChannels)reader.ReadByte(),
                        MultiSampleMask       = reader.ReadInt32(),
                    };
                }
                if (reader.ReadBoolean())
                {
                    depth = new DepthStencilState
                    {
                        CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFail            = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFunction        = (CompareFunction)reader.ReadByte(),
                        CounterClockwiseStencilPass            = (StencilOperation)reader.ReadByte(),
                        DepthBufferEnable      = reader.ReadBoolean(),
                        DepthBufferFunction    = (CompareFunction)reader.ReadByte(),
                        DepthBufferWriteEnable = reader.ReadBoolean(),
                        ReferenceStencil       = reader.ReadInt32(),
                        StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        StencilEnable          = reader.ReadBoolean(),
                        StencilFail            = (StencilOperation)reader.ReadByte(),
                        StencilFunction        = (CompareFunction)reader.ReadByte(),
                        StencilMask            = reader.ReadInt32(),
                        StencilPass            = (StencilOperation)reader.ReadByte(),
                        StencilWriteMask       = reader.ReadInt32(),
                        TwoSidedStencilMode    = reader.ReadBoolean(),
                    };
                }
                if (reader.ReadBoolean())
                {
                    raster = new RasterizerState
                    {
                        CullMode             = (CullMode)reader.ReadByte(),
                        DepthBias            = reader.ReadSingle(),
                        FillMode             = (FillMode)reader.ReadByte(),
                        MultiSampleAntiAlias = reader.ReadBoolean(),
                        ScissorTestEnable    = reader.ReadBoolean(),
                        SlopeScaleDepthBias  = reader.ReadSingle(),
                    };
                }
                var pass = new EffectPass(effect, name, vertexShader, pixelShader, blend, depth, raster, annotations);
                collection.Add(pass);
            }

            return(collection);
        }
Beispiel #5
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = (Shader)null;
            Shader pixelShader  = (Shader)null;
            EffectPassCollection effectPassCollection = new EffectPassCollection();
            int num = (int)reader.ReadByte();

            for (int index1 = 0; index1 < num; ++index1)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int index2 = (int)reader.ReadByte();
                if (index2 != (int)byte.MaxValue)
                {
                    vertexShader = shaders[index2];
                }
                int index3 = (int)reader.ReadByte();
                if (index3 != (int)byte.MaxValue)
                {
                    pixelShader = shaders[index3];
                }
                BlendState        blendState        = (BlendState)null;
                DepthStencilState depthStencilState = (DepthStencilState)null;
                RasterizerState   rasterizerState   = (RasterizerState)null;
                if (reader.ReadBoolean())
                {
                    blendState = new BlendState()
                    {
                        AlphaBlendFunction    = (BlendFunction)reader.ReadByte(),
                        AlphaDestinationBlend = (Blend)reader.ReadByte(),
                        AlphaSourceBlend      = (Blend)reader.ReadByte(),
                        BlendFactor           = new Color((int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte()),
                        ColorBlendFunction    = (BlendFunction)reader.ReadByte(),
                        ColorDestinationBlend = (Blend)reader.ReadByte(),
                        ColorSourceBlend      = (Blend)reader.ReadByte(),
                        ColorWriteChannels    = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels1   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels2   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels3   = (ColorWriteChannels)reader.ReadByte(),
                        MultiSampleMask       = reader.ReadInt32()
                    }
                }
                ;
                if (reader.ReadBoolean())
                {
                    depthStencilState = new DepthStencilState()
                    {
                        CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFail            = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFunction        = (CompareFunction)reader.ReadByte(),
                        CounterClockwiseStencilPass            = (StencilOperation)reader.ReadByte(),
                        DepthBufferEnable      = reader.ReadBoolean(),
                        DepthBufferFunction    = (CompareFunction)reader.ReadByte(),
                        DepthBufferWriteEnable = reader.ReadBoolean(),
                        ReferenceStencil       = reader.ReadInt32(),
                        StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        StencilEnable          = reader.ReadBoolean(),
                        StencilFail            = (StencilOperation)reader.ReadByte(),
                        StencilFunction        = (CompareFunction)reader.ReadByte(),
                        StencilMask            = reader.ReadInt32(),
                        StencilPass            = (StencilOperation)reader.ReadByte(),
                        StencilWriteMask       = reader.ReadInt32(),
                        TwoSidedStencilMode    = reader.ReadBoolean()
                    }
                }
                ;
                if (reader.ReadBoolean())
                {
                    rasterizerState = new RasterizerState()
                    {
                        CullMode             = (CullMode)reader.ReadByte(),
                        DepthBias            = reader.ReadSingle(),
                        FillMode             = (FillMode)reader.ReadByte(),
                        MultiSampleAntiAlias = reader.ReadBoolean(),
                        ScissorTestEnable    = reader.ReadBoolean(),
                        SlopeScaleDepthBias  = reader.ReadSingle()
                    }
                }
                ;
                EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, blendState, depthStencilState, rasterizerState, annotations);
                effectPassCollection.Add(pass);
            }
            return(effectPassCollection);
        }
Beispiel #6
0
 private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List<Shader> shaders)
 {
   Shader vertexShader = (Shader) null;
   Shader pixelShader = (Shader) null;
   EffectPassCollection effectPassCollection = new EffectPassCollection();
   int num = (int) reader.ReadByte();
   for (int index1 = 0; index1 < num; ++index1)
   {
     string name = reader.ReadString();
     EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
     int index2 = (int) reader.ReadByte();
     if (index2 != (int) byte.MaxValue)
       vertexShader = shaders[index2];
     int index3 = (int) reader.ReadByte();
     if (index3 != (int) byte.MaxValue)
       pixelShader = shaders[index3];
     BlendState blendState = (BlendState) null;
     DepthStencilState depthStencilState = (DepthStencilState) null;
     RasterizerState rasterizerState = (RasterizerState) null;
     if (reader.ReadBoolean())
       blendState = new BlendState()
       {
         AlphaBlendFunction = (BlendFunction) reader.ReadByte(),
         AlphaDestinationBlend = (Blend) reader.ReadByte(),
         AlphaSourceBlend = (Blend) reader.ReadByte(),
         BlendFactor = new Color((int) reader.ReadByte(), (int) reader.ReadByte(), (int) reader.ReadByte(), (int) reader.ReadByte()),
         ColorBlendFunction = (BlendFunction) reader.ReadByte(),
         ColorDestinationBlend = (Blend) reader.ReadByte(),
         ColorSourceBlend = (Blend) reader.ReadByte(),
         ColorWriteChannels = (ColorWriteChannels) reader.ReadByte(),
         ColorWriteChannels1 = (ColorWriteChannels) reader.ReadByte(),
         ColorWriteChannels2 = (ColorWriteChannels) reader.ReadByte(),
         ColorWriteChannels3 = (ColorWriteChannels) reader.ReadByte(),
         MultiSampleMask = reader.ReadInt32()
       };
     if (reader.ReadBoolean())
       depthStencilState = new DepthStencilState()
       {
         CounterClockwiseStencilDepthBufferFail = (StencilOperation) reader.ReadByte(),
         CounterClockwiseStencilFail = (StencilOperation) reader.ReadByte(),
         CounterClockwiseStencilFunction = (CompareFunction) reader.ReadByte(),
         CounterClockwiseStencilPass = (StencilOperation) reader.ReadByte(),
         DepthBufferEnable = reader.ReadBoolean(),
         DepthBufferFunction = (CompareFunction) reader.ReadByte(),
         DepthBufferWriteEnable = reader.ReadBoolean(),
         ReferenceStencil = reader.ReadInt32(),
         StencilDepthBufferFail = (StencilOperation) reader.ReadByte(),
         StencilEnable = reader.ReadBoolean(),
         StencilFail = (StencilOperation) reader.ReadByte(),
         StencilFunction = (CompareFunction) reader.ReadByte(),
         StencilMask = reader.ReadInt32(),
         StencilPass = (StencilOperation) reader.ReadByte(),
         StencilWriteMask = reader.ReadInt32(),
         TwoSidedStencilMode = reader.ReadBoolean()
       };
     if (reader.ReadBoolean())
       rasterizerState = new RasterizerState()
       {
         CullMode = (CullMode) reader.ReadByte(),
         DepthBias = reader.ReadSingle(),
         FillMode = (FillMode) reader.ReadByte(),
         MultiSampleAntiAlias = reader.ReadBoolean(),
         ScissorTestEnable = reader.ReadBoolean(),
         SlopeScaleDepthBias = reader.ReadSingle()
       };
     EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, blendState, depthStencilState, rasterizerState, annotations);
     effectPassCollection.Add(pass);
   }
   return effectPassCollection;
 }