예제 #1
0
파일: Program.cs 프로젝트: bostich83/axiom
        /// <summary>
        /// </summary>
        /// <param name="type"> </param>
        /// <param name="index"> </param>
        /// <param name="variability"> default is .All </param>
        /// <param name="suggestedName"> </param>
        /// <param name="size"> Default is 0 </param>
        /// <returns> </returns>
        public UniformParameter ResolveParameter(Axiom.Graphics.GpuProgramParameters.GpuConstantType type, int index,
                                                 GpuProgramParameters.GpuParamVariability variability,
                                                 string suggestedName, int size)
        {
            UniformParameter param = null;

            if (index == -1)
            {
                index = 0;

                //find the next availalbe index of the target type
                for (int i = 0; i < this.parameters.Count; i++)
                {
                    if (this.parameters[i].Type == type && this.parameters[i].IsAutoConstantParameter == false)
                    {
                        index++;
                    }
                }
            }
            else
            {
                //Check if parameter already exits
                param = GetParameterByType(type, index);
                if (param != null)
                {
                    return(param);
                }
            }
            //Create new parameter.
            param = ParameterFactory.CreateUniform(type, index, (int)variability, suggestedName, size);
            AddParameter(param);

            return(param);
        }
예제 #2
0
파일: Program.cs 프로젝트: bostich83/axiom
        private void AddParameter(UniformParameter parameter)
        {
            if (GetParameterByName(parameter.Name) != null)
            {
                throw new Axiom.Core.AxiomException("Parameter <" + parameter.Name + "> already declared in program.");
            }

            this.parameters.Add(parameter);
        }
예제 #3
0
        /// <summary>
        ///   Bind the auto parameters for a given CPU and GPU program set.
        /// </summary>
        /// <param name="pCpuProgram"> </param>
        /// <param name="pGpuProgram"> </param>
        internal void BindAutoParameters(Program pCpuProgram, GpuProgram pGpuProgram)
        {
            var gpuParams  = pGpuProgram.DefaultParameters;
            var progParams = pCpuProgram.Parameters;

            for (int itParams = 0; itParams < progParams.Count; ++itParams)
            {
                UniformParameter curParam = progParams[itParams];

                var gpuConstDef = gpuParams.FindNamedConstantDefinition(curParam.Name);

                if (gpuConstDef != null)
                {
                    if (curParam.IsAutoConstantParameter)
                    {
                        if (curParam.IsAutoConstantRealParameter)
                        {
                            gpuParams.SetNamedAutoConstantReal(curParam.Name,
                                                               curParam.AutoConstantType,
                                                               curParam.AutoConstantRealData);
                        }
                        else if (curParam.IsAutoConstantIntParameter)
                        {
                            gpuParams.SetNamedAutoConstant(curParam.Name,
                                                           curParam.AutoConstantType,
                                                           curParam.AutoConstantIntData);
                        }
                    }
                }
                //Case this is not auto constant - we have to update its variablity ourself.
                else
                {
                    gpuConstDef.Variability |= (GpuProgramParameters.GpuParamVariability)curParam.Variablity;

                    //update variability in the float map.
                    if (gpuConstDef.IsSampler == false)
                    {
                        var floatLogical = gpuParams.FloatLogicalBufferStruct;
                        if (floatLogical != null)
                        {
                            for (int i = 0; i < floatLogical.Map.Count; i++)
                            {
                                if (floatLogical.Map[i].PhysicalIndex == gpuConstDef.PhysicalIndex)
                                {
                                    floatLogical.Map[i].Variability |= gpuConstDef.Variability;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: bostich83/axiom
 private void RemoveParameter(UniformParameter parameter)
 {
     for (int i = 0; i < this.parameters.Count; i++)
     {
         if (this.parameters[i] == parameter)
         {
             this.parameters[i] = null;
             this.parameters.RemoveAt(i);
             break;
         }
     }
 }
예제 #5
0
 private void WriteUniformParameter(StreamWriter stream, UniformParameter parameter)
 {
     stream.WriteLine(this.gpuConstTypeMap[parameter.Type]);
     stream.Write("\t");
     stream.Write(parameter.Name);
     if (parameter.IsArray)
     {
         stream.Write("[" + parameter.Size.ToString() + "]");
     }
     if (parameter.IsSampler)
     {
         stream.Write(" : register(s" + parameter.Index + ")");
     }
 }
예제 #6
0
파일: Program.cs 프로젝트: bostich83/axiom
        /// <summary>
        ///   Resolve uniform auto constant parameter with associated int data of this program
        /// </summary>
        /// <param name="autoType"> The auto type of the desried parameter </param>
        /// <param name="data"> The data to associate with the auto parameter </param>
        /// <param name="size"> number of elements in the parameter </param>
        /// <returns> </returns>
        public UniformParameter ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType autoType, int data,
                                                        int size)
        {
            UniformParameter param = null;

            //check if parameter already exits.
            param = GetParameterByAutoType(autoType);
            if (param != null)
            {
                if (param.IsAutoConstantIntParameter && param.AutoConstantIntData == data)
                {
                    param.Size = Axiom.Math.Utility.Max(size, param.Size);
                    return(param);
                }
            }
            //Create new parameter
            param = new UniformParameter(autoType, data, size);
            AddParameter(param);

            return(param);
        }
예제 #7
0
		/// <summary>
		///   Resolve uniform auto constant parameter with associated real data of this program
		/// </summary>
		/// <param name="autoType"> The auto type of the desired parameter </param>
		/// <param name="data"> The data to associate with the auto parameter </param>
		/// <param name="size"> number of elements in the parameter </param>
		/// <returns> parameter instance in case of that resolve operation succeeded, otherwise null </returns>
		public UniformParameter ResolveAutoParameterReal( GpuProgramParameters.AutoConstantType autoType, Real data,
		                                                  int size )
		{
			UniformParameter param = null;

			//check if parameter already exists.
			param = GetParameterByAutoType( autoType );
			if ( param != null )
			{
				if ( param.IsAutoConstantRealParameter && param.AutoConstantRealData == data )
				{
					param.Size = Axiom.Math.Utility.Max( size, param.Size );
					return param;
				}
			}

			//Create new parameter
			param = new UniformParameter( autoType, data, size );
			AddParameter( param );

			return param;
		}
예제 #8
0
파일: Program.cs 프로젝트: bostich83/axiom
        /// <summary>
        ///   Resolve uniform auto constant parameter with associated real data of this program
        /// </summary>
        /// <param name="autoType"> The auto type of the desired parameter </param>
        /// <param name="type"> The desried data type of the auto parameter </param>
        /// <param name="data"> The data to associate with the auto parameter </param>
        /// <param name="size"> number of elements in the parameter </param>
        /// <returns> parameter instance in case of that resolve operation succeeded, otherwise null </returns>
        public UniformParameter ResolveAutoParameterReal(GpuProgramParameters.AutoConstantType autoType,
                                                         Axiom.Graphics.GpuProgramParameters.GpuConstantType type,
                                                         Real data, int size)
        {
            UniformParameter param = null;

            //check if parameter already exists
            param = GetParameterByAutoType(autoType);
            if (param != null)
            {
                if (param.IsAutoConstantRealParameter && param.AutoConstantRealData == data)
                {
                    param.Size = Axiom.Math.Utility.Max(size, param.Size);
                    return(param);
                }
            }

            //Create new parameter
            param = new UniformParameter(autoType, data, size, type);
            AddParameter(param);

            return(param);
        }
예제 #9
0
		protected bool ResolveGlobalParameters( ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;
			Function vsMain = vsProgram.EntryPointFunction;
			Function psMain = psProgram.EntryPointFunction;

			//Resolve world view IT matrix
			this.worldViewITMatrix =
				vsProgram.ResolveAutoParameterInt(
					GpuProgramParameters.AutoConstantType.InverseTransposeWorldViewMatrix, 0 );
			if ( this.worldViewITMatrix == null )
			{
				return false;
			}

			//Get surface ambient color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Ambient ) == 0 )
			{
				this.derivedAmbientLightColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedAmbientLightColor, 0 );
				if ( this.derivedAmbientLightColor == null )
				{
					return false;
				}
			}
			else
			{
				this.lightAmbientColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.AmbientLightColor, 0 );
				if ( this.lightAmbientColor == null )
				{
					return false;
				}

				this.surfaceAmbientColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceAmbientColor, 0 );
				if ( this.surfaceAmbientColor == null )
				{
					return false;
				}
			}

			//Get surface diffuse color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
			{
				this.surfaceDiffuseColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceDiffuseColor, 0 );
				if ( this.surfaceDiffuseColor == null )
				{
					return false;
				}
			}

			//Get surface emissive color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Emissive ) == 0 )
			{
				this.surfaceEmissiveColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceEmissiveColor, 0 );
				if ( this.surfaceEmissiveColor == null )
				{
					return false;
				}
			}

			//Get derived scene color
			this.derivedSceneColor =
				psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0 );
			if ( this.derivedSceneColor == null )
			{
				return false;
			}

			//Get surface shininess
			this.surfaceShininess = psProgram.ResolveAutoParameterInt(
				GpuProgramParameters.AutoConstantType.SurfaceShininess, 0 );
			if ( this.surfaceShininess == null )
			{
				return false;
			}

			//Resolve input vertex shader normal
			this.vsInNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0,
			                                                Parameter.ContentType.NormalObjectSpace,
			                                                GpuProgramParameters.GpuConstantType.Float3 );
			if ( this.vsInNormal == null )
			{
				return false;
			}

			this.vsOutNormal = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
			                                                  Parameter.ContentType.NormalViewSpace,
			                                                  GpuProgramParameters.GpuConstantType.Float3 );
			if ( this.vsOutNormal == null )
			{
				return false;
			}

			//Resolve input pixel shader normal.
			this.psInNormal = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutNormal.Index,
			                                                this.vsOutNormal.Content, GpuProgramParameters.GpuConstantType.Float3 );
			if ( this.psInNormal == null )
			{
				return false;
			}

			var inputParams = psMain.InputParameters;
			var localParams = psMain.LocalParameters;

			this.psDiffuse = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorDiffuse,
			                                                 GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psDiffuse == null )
			{
				this.psDiffuse = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorDiffuse,
				                                                 GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.psDiffuse == null )
				{
					return false;
				}
			}

			this.psOutDiffuse = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0,
			                                                   Parameter.ContentType.ColorDiffuse,
			                                                   GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psOutDiffuse == null )
			{
				return false;
			}

			this.psTempDiffuseColor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lPerPixelDiffuse",
			                                                        GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psTempDiffuseColor == null )
			{
				return false;
			}

			if ( this.specularEnable )
			{
				this.psSpecular = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorSpecular,
				                                                  GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.psSpecular == null )
				{
					this.psSpecular = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorSpecular,
					                                                  GpuProgramParameters.GpuConstantType.Float4 );
					if ( this.psSpecular == null )
					{
						return false;
					}
				}

				this.psTempSpecularColor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0,
				                                                         "lPerPixelSpecular",
				                                                         GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.psTempSpecularColor == null )
				{
					return false;
				}

				this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
				                                                  Parameter.ContentType.PositionObjectSpace,
				                                                  GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.vsInPosition == null )
				{
					return false;
				}

				this.vsOutViewPos = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
				                                                   Parameter.ContentType.PositionViewSpace,
				                                                   GpuProgramParameters.GpuConstantType.Float3 );
				if ( this.vsOutViewPos == null )
				{
					return false;
				}

				this.psInViewPos = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
				                                                 this.vsOutViewPos.Index, this.vsOutViewPos.Content,
				                                                 GpuProgramParameters.GpuConstantType.Float3 );
				if ( this.psInViewPos == null )
				{
					return false;
				}

				this.worldViewMatrix =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 );
				if ( this.worldViewMatrix == null )
				{
					return false;
				}
			}

			return true;
		}
예제 #10
0
        protected override bool ResolveParameters(ProgramSet programSet)
        {
            Program  vsProgram = programSet.CpuVertexProgram;
            Function vsMain    = vsProgram.EntryPointFunction;

            //REsolve world view IT matrix
            this.worldViewITMatrix =
                vsProgram.ResolveAutoParameterInt(
                    GpuProgramParameters.AutoConstantType.InverseTransposeWorldViewMatrix, 0);
            if (this.worldViewITMatrix == null)
            {
                return(false);
            }

            //Get surface ambient color if need to
            if ((this.trackVertexColorType & TrackVertexColor.Ambient) == 0)
            {
                this.derivedAmbientLightColor =
                    vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.DerivedAmbientLightColor, 0);
                if (this.derivedAmbientLightColor == null)
                {
                    return(false);
                }
            }
            else
            {
                this.lightAmbientColor =
                    vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.AmbientLightColor, 0);
                if (this.lightAmbientColor == null)
                {
                    return(false);
                }

                this.surfaceAmbientColor =
                    vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.SurfaceAmbientColor, 0);
                if (this.surfaceAmbientColor == null)
                {
                    return(false);
                }
            }

            //Get surface diffuse color if need to.
            if ((this.trackVertexColorType & TrackVertexColor.Diffuse) == 0)
            {
                this.surfaceDiffuseColor =
                    vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.SurfaceDiffuseColor, 0);
                if (this.surfaceDiffuseColor == null)
                {
                    return(false);
                }
            }

            //Get surface specular color if need to
            if ((this.trackVertexColorType & TrackVertexColor.Specular) == 0)
            {
                this.surfaceSpecularColor =
                    vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.SurfaceSpecularColor, 0);
                if (this.surfaceSpecularColor == null)
                {
                    return(false);
                }
            }

            //Get surface emissive color if need to.
            if ((this.trackVertexColorType & TrackVertexColor.Emissive) == 0)
            {
                this.surfaceEmissiveCoilor =
                    vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.SurfaceEmissiveColor, 0);
                if (this.surfaceEmissiveCoilor == null)
                {
                    return(false);
                }
            }

            //Get derived scene color
            this.derivedSceneColor =
                vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0);
            if (this.derivedSceneColor == null)
            {
                return(false);
            }

            //get surface shininess
            this.surfaceShininess = vsProgram.ResolveAutoParameterInt(
                GpuProgramParameters.AutoConstantType.SurfaceShininess, 0);
            if (this.surfaceShininess == null)
            {
                return(false);
            }

            //Resolve input vertex shader normal
            this.vsInNormal = vsMain.ResolveInputParameter(Parameter.SemanticType.Normal, 0,
                                                           Parameter.ContentType.NormalObjectSpace,
                                                           GpuProgramParameters.GpuConstantType.Float3);
            if (this.vsInNormal == null)
            {
                return(false);
            }

            if (this.trackVertexColorType != 0)
            {
                this.vsDiffuse = vsMain.ResolveInputParameter(Parameter.SemanticType.Color, 0,
                                                              Parameter.ContentType.ColorDiffuse,
                                                              GpuProgramParameters.GpuConstantType.Float4);
                if (this.vsDiffuse == null)
                {
                    return(false);
                }
            }

            //Resolve output vertex shader diffuse color.
            this.vsOutDiffuse = vsMain.ResolveOutputParameter(Parameter.SemanticType.Color, 0,
                                                              Parameter.ContentType.ColorDiffuse,
                                                              GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsOutDiffuse == null)
            {
                return(false);
            }

            //Resolve per light parameters
            for (int i = 0; i < this.lightParamsList.Count; i++)
            {
                switch (this.lightParamsList[i].Type)
                {
                case LightType.Directional:
                    this.lightParamsList[i].Direction =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                   GpuProgramParameters.GpuParamVariability.Lights,
                                                   "light_position_view_space");
                    if (this.lightParamsList[i].Direction == null)
                    {
                        return(false);
                    }
                    break;

                case LightType.Point:
                    this.worldViewMatrix =
                        vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0);
                    if (this.worldViewMatrix == null)
                    {
                        return(false);
                    }

                    this.vsInPosition = vsMain.ResolveInputParameter(Parameter.SemanticType.Position, 0,
                                                                     Parameter.ContentType.PositionObjectSpace,
                                                                     GpuProgramParameters.GpuConstantType.Float4);
                    if (this.vsInPosition == null)
                    {
                        return(false);
                    }

                    this.lightParamsList[i].Position =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                   GpuProgramParameters.GpuParamVariability.Lights,
                                                   "light_position_view_space");
                    if (this.lightParamsList[i].Position == null)
                    {
                        return(false);
                    }

                    this.lightParamsList[i].AttenuatParams =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                   GpuProgramParameters.GpuParamVariability.Lights,
                                                   "light_attenuation");
                    if (this.lightParamsList[i].AttenuatParams == null)
                    {
                        return(false);
                    }
                    break;

                case LightType.Spotlight:
                    this.worldViewMatrix =
                        vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0);
                    if (this.worldViewMatrix == null)
                    {
                        return(false);
                    }

                    this.vsInPosition = vsMain.ResolveInputParameter(Parameter.SemanticType.Position, 0,
                                                                     Parameter.ContentType.PositionObjectSpace,
                                                                     GpuProgramParameters.GpuConstantType.Float4);
                    if (this.vsInPosition == null)
                    {
                        return(false);
                    }

                    this.lightParamsList[i].Position =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                   GpuProgramParameters.GpuParamVariability.Lights,
                                                   "light_position_view_space");
                    if (this.lightParamsList[i].Position == null)
                    {
                        return(false);
                    }


                    this.lightParamsList[i].Direction =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                   GpuProgramParameters.GpuParamVariability.Lights,
                                                   "light_direction_view_space");
                    if (this.lightParamsList[i].Direction == null)
                    {
                        return(false);
                    }

                    this.lightParamsList[i].AttenuatParams =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                   GpuProgramParameters.GpuParamVariability.Lights,
                                                   "light_attenuation");
                    if (this.lightParamsList[i].AttenuatParams == null)
                    {
                        return(false);
                    }

                    this.lightParamsList[i].SpotParams =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float3, -1,
                                                   GpuProgramParameters.GpuParamVariability.Lights,
                                                   "spotlight_params");
                    if (this.lightParamsList[i].SpotParams == null)
                    {
                        return(false);
                    }

                    break;
                }

                //Resolve diffuse color
                if ((this.trackVertexColorType & TrackVertexColor.Diffuse) == 0)
                {
                    this.lightParamsList[i].DiffuseColor =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                   GpuProgramParameters.GpuParamVariability.Global |
                                                   GpuProgramParameters.GpuParamVariability.Lights,
                                                   "derived_light_diffuse");
                    if (this.lightParamsList[i].DiffuseColor == null)
                    {
                        return(false);
                    }
                }
                else
                {
                    this.lightParamsList[i].DiffuseColor =
                        vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                   GpuProgramParameters.GpuParamVariability.Lights, "light_diffuse");
                    if (this.lightParamsList[i].DiffuseColor == null)
                    {
                        return(false);
                    }
                }

                if (this.specularEnable)
                {
                    //Resolve specular color
                    if ((this.trackVertexColorType & TrackVertexColor.Specular) == 0)
                    {
                        this.lightParamsList[i].SpecularColor =
                            vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                       GpuProgramParameters.GpuParamVariability.Global |
                                                       GpuProgramParameters.GpuParamVariability.Lights,
                                                       "derived_light_specular");
                        if (this.lightParamsList[i].SpecularColor == null)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        this.lightParamsList[i].SpecularColor =
                            vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                       GpuProgramParameters.GpuParamVariability.Lights,
                                                       "light_specular");
                        if (this.lightParamsList[i].SpecularColor == null)
                        {
                            return(false);
                        }
                    }

                    if (this.vsOutSpecular == null)
                    {
                        this.vsOutSpecular = vsMain.ResolveOutputParameter(Parameter.SemanticType.Color, 1,
                                                                           Parameter.ContentType.ColorSpecular,
                                                                           GpuProgramParameters.GpuConstantType.Float4);
                        if (this.vsOutSpecular == null)
                        {
                            return(false);
                        }
                    }

                    if (this.vsInPosition == null)
                    {
                        this.vsInPosition = vsMain.ResolveInputParameter(Parameter.SemanticType.Position, 0,
                                                                         Parameter.ContentType.PositionObjectSpace,
                                                                         GpuProgramParameters.GpuConstantType.Float4);
                        if (this.vsInPosition == null)
                        {
                            return(false);
                        }
                    }

                    if (this.worldViewMatrix == null)
                    {
                        this.worldViewMatrix =
                            vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0);
                        if (this.worldViewMatrix == null)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
예제 #11
0
		protected override bool ResolveParameters( ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Function vsMain = vsProgram.EntryPointFunction;

			//REsolve world view IT matrix
			this.worldViewITMatrix =
				vsProgram.ResolveAutoParameterInt(
					GpuProgramParameters.AutoConstantType.InverseTransposeWorldViewMatrix, 0 );
			if ( this.worldViewITMatrix == null )
			{
				return false;
			}

			//Get surface ambient color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Ambient ) == 0 )
			{
				this.derivedAmbientLightColor =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedAmbientLightColor, 0 );
				if ( this.derivedAmbientLightColor == null )
				{
					return false;
				}
			}
			else
			{
				this.lightAmbientColor =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.AmbientLightColor, 0 );
				if ( this.lightAmbientColor == null )
				{
					return false;
				}

				this.surfaceAmbientColor =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceAmbientColor, 0 );
				if ( this.surfaceAmbientColor == null )
				{
					return false;
				}
			}

			//Get surface diffuse color if need to.
			if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
			{
				this.surfaceDiffuseColor =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceDiffuseColor, 0 );
				if ( this.surfaceDiffuseColor == null )
				{
					return false;
				}
			}

			//Get surface specular color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 )
			{
				this.surfaceSpecularColor =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceSpecularColor, 0 );
				if ( this.surfaceSpecularColor == null )
				{
					return false;
				}
			}

			//Get surface emissive color if need to.
			if ( ( this.trackVertexColorType & TrackVertexColor.Emissive ) == 0 )
			{
				this.surfaceEmissiveCoilor =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceEmissiveColor, 0 );
				if ( this.surfaceEmissiveCoilor == null )
				{
					return false;
				}
			}

			//Get derived scene color
			this.derivedSceneColor =
				vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0 );
			if ( this.derivedSceneColor == null )
			{
				return false;
			}

			//get surface shininess
			this.surfaceShininess = vsProgram.ResolveAutoParameterInt(
				GpuProgramParameters.AutoConstantType.SurfaceShininess, 0 );
			if ( this.surfaceShininess == null )
			{
				return false;
			}

			//Resolve input vertex shader normal
			this.vsInNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0,
			                                                Parameter.ContentType.NormalObjectSpace,
			                                                GpuProgramParameters.GpuConstantType.Float3 );
			if ( this.vsInNormal == null )
			{
				return false;
			}

			if ( this.trackVertexColorType != 0 )
			{
				this.vsDiffuse = vsMain.ResolveInputParameter( Parameter.SemanticType.Color, 0,
				                                               Parameter.ContentType.ColorDiffuse,
				                                               GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.vsDiffuse == null )
				{
					return false;
				}
			}

			//Resolve output vertex shader diffuse color.
			this.vsOutDiffuse = vsMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0,
			                                                   Parameter.ContentType.ColorDiffuse,
			                                                   GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsOutDiffuse == null )
			{
				return false;
			}

			//Resolve per light parameters
			for ( int i = 0; i < this.lightParamsList.Count; i++ )
			{
				switch ( this.lightParamsList[ i ].Type )
				{
					case LightType.Directional:
						this.lightParamsList[ i ].Direction =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_position_view_space" );
						if ( this.lightParamsList[ i ].Direction == null )
						{
							return false;
						}
						break;
					case LightType.Point:
						this.worldViewMatrix =
							vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 );
						if ( this.worldViewMatrix == null )
						{
							return false;
						}

						this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
						                                                  Parameter.ContentType.PositionObjectSpace,
						                                                  GpuProgramParameters.GpuConstantType.Float4 );
						if ( this.vsInPosition == null )
						{
							return false;
						}

						this.lightParamsList[ i ].Position =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_position_view_space" );
						if ( this.lightParamsList[ i ].Position == null )
						{
							return false;
						}

						this.lightParamsList[ i ].AttenuatParams =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_attenuation" );
						if ( this.lightParamsList[ i ].AttenuatParams == null )
						{
							return false;
						}
						break;
					case LightType.Spotlight:
						this.worldViewMatrix =
							vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 );
						if ( this.worldViewMatrix == null )
						{
							return false;
						}

						this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
						                                                  Parameter.ContentType.PositionObjectSpace,
						                                                  GpuProgramParameters.GpuConstantType.Float4 );
						if ( this.vsInPosition == null )
						{
							return false;
						}

						this.lightParamsList[ i ].Position =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_position_view_space" );
						if ( this.lightParamsList[ i ].Position == null )
						{
							return false;
						}


						this.lightParamsList[ i ].Direction =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_direction_view_space" );
						if ( this.lightParamsList[ i ].Direction == null )
						{
							return false;
						}

						this.lightParamsList[ i ].AttenuatParams =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_attenuation" );
						if ( this.lightParamsList[ i ].AttenuatParams == null )
						{
							return false;
						}

						this.lightParamsList[ i ].SpotParams =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float3, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "spotlight_params" );
						if ( this.lightParamsList[ i ].SpotParams == null )
						{
							return false;
						}

						break;
				}

				//Resolve diffuse color
				if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
				{
					this.lightParamsList[ i ].DiffuseColor =
						vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
						                            GpuProgramParameters.GpuParamVariability.Global |
						                            GpuProgramParameters.GpuParamVariability.Lights,
						                            "derived_light_diffuse" );
					if ( this.lightParamsList[ i ].DiffuseColor == null )
					{
						return false;
					}
				}
				else
				{
					this.lightParamsList[ i ].DiffuseColor =
						vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
						                            GpuProgramParameters.GpuParamVariability.Lights, "light_diffuse" );
					if ( this.lightParamsList[ i ].DiffuseColor == null )
					{
						return false;
					}
				}

				if ( this.specularEnable )
				{
					//Resolve specular color
					if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 )
					{
						this.lightParamsList[ i ].SpecularColor =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Global |
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "derived_light_specular" );
						if ( this.lightParamsList[ i ].SpecularColor == null )
						{
							return false;
						}
					}
					else
					{
						this.lightParamsList[ i ].SpecularColor =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_specular" );
						if ( this.lightParamsList[ i ].SpecularColor == null )
						{
							return false;
						}
					}

					if ( this.vsOutSpecular == null )
					{
						this.vsOutSpecular = vsMain.ResolveOutputParameter( Parameter.SemanticType.Color, 1,
						                                                    Parameter.ContentType.ColorSpecular,
						                                                    GpuProgramParameters.GpuConstantType.Float4 );
						if ( this.vsOutSpecular == null )
						{
							return false;
						}
					}

					if ( this.vsInPosition == null )
					{
						this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
						                                                  Parameter.ContentType.PositionObjectSpace,
						                                                  GpuProgramParameters.GpuConstantType.Float4 );
						if ( this.vsInPosition == null )
						{
							return false;
						}
					}

					if ( this.worldViewMatrix == null )
					{
						this.worldViewMatrix =
							vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 );
						if ( this.worldViewMatrix == null )
						{
							return false;
						}
					}
				}
			}
			return true;
		}
예제 #12
0
		private bool ResolveGlobalParameters( ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;
			Function vsMain = vsProgram.EntryPointFunction;
			Function psMain = psProgram.EntryPointFunction;

			//Resolve normal map texture sampler parameter
			this.normalMapSampler = psProgram.ResolveParameter(
				Axiom.Graphics.GpuProgramParameters.GpuConstantType.Sampler2D, this.normalMapSamplerIndex,
				GpuProgramParameters.GpuParamVariability.PerObject, "gNormalMapSampler" );
			if ( this.normalMapSampler == null )
			{
				return false;
			}

			//Get surface ambient color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Ambient ) == 0 )
			{
				this.derivedAmbientLightColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedAmbientLightColor, 0 );
				if ( this.derivedAmbientLightColor == null )
				{
					return false;
				}
			}
			else
			{
				this.lightAmbientColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.AmbientLightColor, 0 );
				if ( this.lightAmbientColor == null )
				{
					return false;
				}

				this.surfaceAmbientColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceAmbientColor, 0, 0 );
				if ( this.surfaceAmbientColor == null )
				{
					return false;
				}
			}

			//Get surface diffuse color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
			{
				this.surfaceDiffuseColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceDiffuseColor, 0 );
				if ( this.surfaceDiffuseColor == null )
				{
					return false;
				}
			}

			//Get surface specular color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 )
			{
				this.surfaceSpecularColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceSpecularColor, 0 );
				if ( this.surfaceSpecularColor == null )
				{
					return false;
				}
			}

			//Get surface emissive color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Emissive ) == 0 )
			{
				this.surfaceEmissiveColor =
					psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.SurfaceEmissiveColor, 0 );
				if ( this.surfaceEmissiveColor == null )
				{
					return false;
				}
			}

			//Get derived scene color
			this.derivedSceneColor =
				psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0 );
			if ( this.derivedSceneColor == null )
			{
				return false;
			}

			//Get surface shininess.
			this.surfaceShininess = psProgram.ResolveAutoParameterInt(
				GpuProgramParameters.AutoConstantType.SurfaceShininess, 0 );
			if ( this.surfaceShininess == null )
			{
				return false;
			}

			//Resolve input vertex shader normal
			this.vsInNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0,
			                                                Parameter.ContentType.NormalObjectSpace,
			                                                Axiom.Graphics.GpuProgramParameters.GpuConstantType.Float3 );
			if ( this.vsInNormal == null )
			{
				return false;
			}

			//Resolve input vertex shader tangent
			if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
			{
				this.vsInTangent = vsMain.ResolveInputParameter( Parameter.SemanticType.Tangent, 0,
				                                                 Parameter.ContentType.TangentObjectSpace,
				                                                 GpuProgramParameters.GpuConstantType.Float3 );
				if ( this.vsInTangent == null )
				{
					return false;
				}

				//Resolve local vertex shader TNB matrix
				this.vsTBNMatrix = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lMatTBN",
				                                                 GpuProgramParameters.GpuConstantType.Matrix_3X3 );
				if ( this.vsTBNMatrix == null )
				{
					return false;
				}
			}

			//resolve input vertex shader texture coordinates
			Parameter.ContentType texCoordToUse = Parameter.ContentType.TextureCoordinate0;
			switch ( this.vsTexCoordSetIndex )
			{
				case 0:
					texCoordToUse = Parameter.ContentType.TextureCoordinate0;
					break;
				case 1:
					texCoordToUse = Parameter.ContentType.TextureCoordinate1;
					break;
				case 2:
					texCoordToUse = Parameter.ContentType.TextureCoordinate2;
					break;
				case 3:
					texCoordToUse = Parameter.ContentType.TextureCoordinate3;
					break;
				case 4:
					texCoordToUse = Parameter.ContentType.TextureCoordinate4;
					break;
				case 5:
					texCoordToUse = Parameter.ContentType.TextureCoordinate5;
					break;
				case 6:
					texCoordToUse = Parameter.ContentType.TextureCoordinate6;
					break;
				case 7:
					texCoordToUse = Parameter.ContentType.TextureCoordinate7;
					break;
				default:
					throw new AxiomException( "vsTexCoordIndexOut of range", new ArgumentOutOfRangeException() );
			}
			this.vsInTexcoord = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsTexCoordSetIndex,
			                                                  texCoordToUse, GpuProgramParameters.GpuConstantType.Float2 );
			if ( this.vsInTexcoord == null )
			{
				return false;
			}

			//Resolve output vertex shader texture coordinates
			this.vsOutTexcoord = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, texCoordToUse,
			                                                    GpuProgramParameters.GpuConstantType.Float2 );
			if ( this.vsOutTexcoord == null )
			{
				return false;
			}

			//resolve pixel input texture coordinates normal
			this.psInTexcoord = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutTexcoord.Index,
			                                                  this.vsOutTexcoord.Content, this.vsOutTexcoord.Type );
			if ( this.psInTexcoord == null )
			{
				return false;
			}

			//Resolve pixel shader normal.
			if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object )
			{
				this.psNormal = psMain.ResolveLocalParameter( Parameter.SemanticType.Normal, 0,
				                                              Parameter.ContentType.NormalObjectSpace,
				                                              GpuProgramParameters.GpuConstantType.Float3 );
				if ( this.psNormal == null )
				{
					return false;
				}
			}
			else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
			{
				this.psNormal = psMain.ResolveLocalParameter( Parameter.SemanticType.Normal, 0,
				                                              Parameter.ContentType.NormalTangentSpace,
				                                              GpuProgramParameters.GpuConstantType.Float3 );
				if ( this.psNormal == null )
				{
					return false;
				}
			}

			var inputParams = psMain.InputParameters;
			var localParams = psMain.LocalParameters;

			this.psDiffuse = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorDiffuse,
			                                                 GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psDiffuse == null )
			{
				this.psDiffuse = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorDiffuse,
				                                                 GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.psDiffuse == null )
				{
					return false;
				}
			}

			this.psOutDiffuse = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0,
			                                                   Parameter.ContentType.ColorDiffuse,
			                                                   GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psOutDiffuse == null )
			{
				return false;
			}

			this.psTempDiffuseColor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lNormalMapDiffuse",
			                                                        GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psTempDiffuseColor == null )
			{
				return false;
			}

			if ( this.specularEnabled )
			{
				this.psSpecular = Function.GetParameterByContent( inputParams, Parameter.ContentType.ColorSpecular,
				                                                  GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.psSpecular == null )
				{
					this.psSpecular = Function.GetParameterByContent( localParams, Parameter.ContentType.ColorSpecular,
					                                                  GpuProgramParameters.GpuConstantType.Float4 );
					if ( this.psSpecular == null )
					{
						return false;
					}
				}

				this.psTempSpecularColor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0,
				                                                         "lNormalMapSpecular",
				                                                         GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.psTempSpecularColor == null )
				{
					return false;
				}

				this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
				                                                  Parameter.ContentType.PositionObjectSpace,
				                                                  GpuProgramParameters.GpuConstantType.Float4 );
				if ( this.vsInPosition == null )
				{
					return false;
				}
				if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
				{
					this.vsOutView = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
					                                                Parameter.ContentType.PostOCameraTangentSpace,
					                                                GpuProgramParameters.GpuConstantType.Float3 );
					if ( this.vsOutView == null )
					{
						return false;
					}
				}
				else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object )
				{
					this.vsOutView = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
					                                                Parameter.ContentType.PostOCameraTangentSpace,
					                                                GpuProgramParameters.GpuConstantType.Float3 );
					if ( this.vsOutView == null )
					{
						return false;
					}
				}

				this.psInView = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutView.Index,
				                                              this.vsOutView.Content, this.vsOutView.Type );
				if ( this.psInView == null )
				{
					return false;
				}

				//Resolve camera position world space
				this.camPosWorldSpace =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.CameraPosition, 0 );
				if ( this.camPosWorldSpace == null )
				{
					return false;
				}

				this.vsLocalDir = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lNormalMapTempDir",
				                                                GpuProgramParameters.GpuConstantType.Float3 );
				if ( this.vsLocalDir == null )
				{
					return false;
				}

				this.vsWorldPosition = vsMain.ResolveLocalParameter( Parameter.SemanticType.Position, 0,
				                                                     Parameter.ContentType.PositionWorldSpace,
				                                                     GpuProgramParameters.GpuConstantType.Float3 );
				if ( this.vsWorldPosition == null )
				{
					return false;
				}

				//Resolve world matrix
				this.worldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 );
				if ( this.worldMatrix == null )
				{
					return false;
				}

				//Resolve inverse world rotation matrix
				this.worldInvRotMatrix = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1,
				                                                     GpuProgramParameters.GpuParamVariability.PerObject,
				                                                     "inv_world_rotation_matrix" );
				if ( this.worldInvRotMatrix == null )
				{
					return false;
				}
			}


			return true;
		}
예제 #13
0
		private bool ResolvePerLightParameters( ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;
			Function vsMain = vsProgram.EntryPointFunction;
			Function psMain = psProgram.EntryPointFunction;

			for ( int i = 0; i < this.lightParamsList.Count; i++ )
			{
				switch ( this.lightParamsList[ i ].Type )
				{
					case LightType.Directional:
						this.lightParamsList[ i ].Direction =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.PerObject,
							                            "light_direction_obj_space" );
						if ( this.lightParamsList[ i ].Direction == null )
						{
							return false;
						}


						Parameter.ContentType pctToUse;

						if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
						{
							switch ( i )
							{
								case 0:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace0;
									break;
								case 1:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace1;
									break;
								case 2:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace2;
									break;
								case 3:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace3;
									break;
								case 4:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace4;
									break;
								case 5:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace5;
									break;
								case 6:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace6;
									break;
								default:
									throw new AxiomException( "Index out of range" );
							}
							this.lightParamsList[ i ].VSOutDirection =
								vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, pctToUse,
								                               GpuProgramParameters.GpuConstantType.Float3 );
						}
						else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object )
						{
							switch ( i )
							{
								case 0:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace0;
									break;
								case 1:
									pctToUse = Parameter.ContentType.LightDirectionTangentSpace1;
									break;
								case 2:
									pctToUse = Parameter.ContentType.LightDirectionObjectSpace2;
									break;
								case 3:
									pctToUse = Parameter.ContentType.LightDirectionObjectSpace3;
									break;
								case 4:
									pctToUse = Parameter.ContentType.LightDirectionObjectSpace4;
									break;
								case 5:
									pctToUse = Parameter.ContentType.LightDirectionObjectSpace5;
									break;
								case 6:
									pctToUse = Parameter.ContentType.LightDirectionObjectSpace6;
									break;
								default:
									throw new AxiomException( "Index out of range" );
							}
							this.lightParamsList[ i ].VSOutToLightDir =
								vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, pctToUse,
								                               GpuProgramParameters.GpuConstantType.Float3 );
						}
						if ( this.lightParamsList[ i ].VSOutToLightDir == null )
						{
							return false;
						}

						this.lightParamsList[ i ].PSInDirection =
							psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
							                              this.lightParamsList[ i ].VSOutToLightDir.Index,
							                              this.lightParamsList[ i ].VSOutToLightDir.Content,
							                              this.lightParamsList[ i ].VSOutToLightDir.Type );
						if ( this.lightParamsList[ i ].PSInDirection == null )
						{
							return false;
						}

						break;
					case LightType.Point:
						this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
						                                                  Parameter.ContentType.PositionObjectSpace,
						                                                  GpuProgramParameters.GpuConstantType.Float4 );
						if ( this.vsInPosition == null )
						{
							return false;
						}

						this.lightParamsList[ i ].Position =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights |
							                            GpuProgramParameters.GpuParamVariability.PerObject,
							                            "light_position_world_space" );
						if ( this.lightParamsList[ i ].Position == null )
						{
							return false;
						}

						if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
						{
							this.lightParamsList[ i ].VSOutToLightDir =
								vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
								                               IntToEnum( RTShaderSystem.NormalMapSpace.Tangent, i ),
								                               GpuProgramParameters.GpuConstantType.Float3 );
						}
						else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object )
						{
							this.lightParamsList[ i ].VSOutToLightDir =
								vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
								                               IntToEnum( RTShaderSystem.NormalMapSpace.Object, i ),
								                               GpuProgramParameters.GpuConstantType.Float3 );
						}
						if ( this.lightParamsList[ i ].VSOutToLightDir == null )
						{
							return false;
						}

						this.lightParamsList[ i ].PSInToLightDir =
							psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
							                              this.lightParamsList[ i ].VSOutToLightDir.Index,
							                              this.lightParamsList[ i ].VSOutToLightDir.Content,
							                              this.lightParamsList[ i ].VSOutToLightDir.Type );
						if ( this.lightParamsList[ i ].PSInToLightDir == null )
						{
							return false;
						}

						this.lightParamsList[ i ].AttenuatParams =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_attenuation" );
						if ( this.lightParamsList[ i ].AttenuatParams == null )
						{
							return false;
						}

						//Resolve local dir
						if ( this.vsLocalDir == null )
						{
							this.vsLocalDir = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0,
							                                                "lNormalMapTempDir",
							                                                GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.vsLocalDir == null )
							{
								return false;
							}
						}

						//Resolve world position
						if ( this.vsWorldPosition == null )
						{
							this.vsWorldPosition = vsMain.ResolveLocalParameter( Parameter.SemanticType.Position, 0,
							                                                     Parameter.ContentType.PositionWorldSpace,
							                                                     GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.vsWorldPosition == null )
							{
								return false;
							}
						}

						//resolve world matrix
						if ( this.worldMatrix == null )
						{
							this.worldMatrix =
								vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 );
							if ( this.worldMatrix == null )
							{
								return false;
							}
						}
						//resolve inverse world rotation matrix
						if ( this.worldInvRotMatrix == null )
						{
							this.worldInvRotMatrix =
								vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1,
								                            GpuProgramParameters.GpuParamVariability.PerObject,
								                            "inv_world_rotation_matrix" );
							if ( this.worldInvRotMatrix == null )
							{
								return false;
							}
						}
						break;
					case LightType.Spotlight:
						this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
						                                                  Parameter.ContentType.PositionObjectSpace,
						                                                  GpuProgramParameters.GpuConstantType.Float4 );
						if ( this.vsInPosition == null )
						{
							return false;
						}

						this.lightParamsList[ i ].Position =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights |
							                            GpuProgramParameters.GpuParamVariability.PerObject,
							                            "light_position_world_space" );
						if ( this.lightParamsList[ i ].Position == null )
						{
							return false;
						}

						if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
						{
							this.lightParamsList[ i ].VSOutToLightDir =
								vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
								                               IntToEnum( RTShaderSystem.NormalMapSpace.Tangent, i ),
								                               GpuProgramParameters.GpuConstantType.Float3 );
						}
						if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object )
						{
							this.lightParamsList[ i ].VSOutToLightDir =
								vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
								                               IntToEnum( RTShaderSystem.NormalMapSpace.Object, i ),
								                               GpuProgramParameters.GpuConstantType.Float3 );
						}
						if ( this.lightParamsList[ i ].VSOutToLightDir == null )
						{
							return false;
						}

						this.lightParamsList[ i ].PSInToLightDir =
							psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
							                              this.lightParamsList[ i ].VSOutToLightDir.Index,
							                              this.lightParamsList[ i ].VSOutToLightDir.Content,
							                              this.lightParamsList[ i ].VSOutToLightDir.Type );
						if ( this.lightParamsList[ i ].PSInToLightDir == null )
						{
							return false;
						}

						this.lightParamsList[ i ].Direction =
							vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights |
							                            GpuProgramParameters.GpuParamVariability.PerObject,
							                            "light_direction_obj_space" );
						if ( this.lightParamsList[ i ].Direction == null )
						{
							return false;
						}
						if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
						{
							this.lightParamsList[ i ].VSOutDirection =
								vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
								                               IntToEnum( RTShaderSystem.NormalMapSpace.Tangent, i ),
								                               GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.lightParamsList[ i ].VSOutDirection == null )
							{
								return false;
							}
						}
						else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object )
						{
							this.lightParamsList[ i ].VSOutDirection =
								vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
								                               IntToEnum( RTShaderSystem.NormalMapSpace.Object, i ),
								                               GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.lightParamsList[ i ].VSOutDirection == null )
							{
								return false;
							}
						}
						if ( this.lightParamsList[ i ].VSOutDirection == null )
						{
							return false;
						}

						this.lightParamsList[ i ].PSInDirection =
							psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
							                              this.lightParamsList[ i ].VSOutDirection.Index,
							                              this.lightParamsList[ i ].VSOutDirection.Content,
							                              this.lightParamsList[ i ].VSOutDirection.Type );
						if ( this.lightParamsList[ i ].PSInDirection == null )
						{
							return false;
						}

						this.lightParamsList[ i ].AttenuatParams =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_attenuation" );
						if ( this.lightParamsList[ i ].AttenuatParams == null )
						{
							return false;
						}

						this.lightParamsList[ i ].SpotParams =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float3, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "spotlight_params" );
						if ( this.lightParamsList[ i ].SpotParams == null )
						{
							return false;
						}

						//Resolve local dir
						if ( this.vsLocalDir == null )
						{
							this.vsLocalDir = vsMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0,
							                                                "lNormalMapTempDir",
							                                                GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.vsLocalDir == null )
							{
								return false;
							}
						}

						//resolve world postion
						if ( this.vsWorldPosition == null )
						{
							this.vsWorldPosition = vsMain.ResolveLocalParameter( Parameter.SemanticType.Position, 0,
							                                                     Parameter.ContentType.PositionWorldSpace,
							                                                     GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.vsWorldPosition == null )
							{
								return false;
							}
						}
						//resolve world matrix
						if ( this.worldMatrix == null )
						{
							this.worldMatrix =
								vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 );
							if ( this.worldMatrix == null )
							{
								return false;
							}
						}
						//resovle inverse world rotation matrix
						if ( this.worldInvRotMatrix == null )
						{
							this.worldInvRotMatrix =
								vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1,
								                            GpuProgramParameters.GpuParamVariability.PerObject,
								                            "inv_world_rotation_matrix" );
							if ( this.worldInvRotMatrix == null )
							{
								return false;
							}
						}
						break;
				}

				//resolve diffuse color
				if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
				{
					this.lightParamsList[ i ].DiffuseColor =
						psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
						                            GpuProgramParameters.GpuParamVariability.Lights,
						                            "derived_light_diffuse" );
					if ( this.lightParamsList[ i ].DiffuseColor == null )
					{
						return false;
					}
				}
				else
				{
					this.lightParamsList[ i ].DiffuseColor =
						psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
						                            GpuProgramParameters.GpuParamVariability.Lights, "light_diffuse" );
					if ( this.lightParamsList[ i ].DiffuseColor == null )
					{
						return false;
					}
				}

				if ( this.specularEnabled )
				{
					//resolve specular color
					if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 )
					{
						this.lightParamsList[ i ].SpecularColor =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "derived_light_specular" );
						if ( this.lightParamsList[ i ].SpecularColor == null )
						{
							return false;
						}
					}
					else
					{
						this.lightParamsList[ i ].SpecularColor =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_specular" );
						if ( this.lightParamsList[ i ].SpecularColor == null )
						{
							return false;
						}
					}
				}
			}

			return true;
		}
예제 #14
0
		private void RemoveParameter( UniformParameter parameter )
		{
			for ( int i = 0; i < this.parameters.Count; i++ )
			{
				if ( this.parameters[ i ] == parameter )
				{
					this.parameters[ i ] = null;
					this.parameters.RemoveAt( i );
					break;
				}
			}
		}
예제 #15
0
		private void AddParameter( UniformParameter parameter )
		{
			if ( GetParameterByName( parameter.Name ) != null )
			{
				throw new Axiom.Core.AxiomException( "Parameter <" + parameter.Name + "> already declared in program." );
			}

			this.parameters.Add( parameter );
		}
예제 #16
0
		protected override bool ResolveParameters( ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;
			Function vsMain = vsProgram.EntryPointFunction;
			Function psMain = psProgram.EntryPointFunction;

			//Get input position parameter
			this.vsInPos = Function.GetParameterBySemantic( vsMain.InputParameters, Parameter.SemanticType.Position, 0 );
			if ( this.vsInPos == null )
			{
				return false;
			}

			//Get output position parameter
			this.vsOutPos = Function.GetParameterBySemantic( vsMain.OutputParameters, Parameter.SemanticType.Position, 0 );
			if ( this.vsOutPos == null )
			{
				return false;
			}

			//Resolve vertex shader output depth.
			this.vsOutDepth = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
			                                                 Parameter.ContentType.DepthViewSpace,
			                                                 GpuProgramParameters.GpuConstantType.Float1 );
			if ( this.vsOutDepth == null )
			{
				return false;
			}

			//Resolve input depth parameter.
			this.psInDepth = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutDepth.Index,
			                                               this.vsOutDepth.Content, GpuProgramParameters.GpuConstantType.Float1 );
			if ( this.psInDepth == null )
			{
				return false;
			}

			//Get in/local specular paramter
			this.psSpecular = Function.GetParameterBySemantic( psMain.InputParameters, Parameter.SemanticType.Color, 1 );
			if ( this.psSpecular == null )
			{
				this.psSpecular = Function.GetParameterBySemantic( psMain.LocalParameters, Parameter.SemanticType.Color, 1 );
				if ( this.psSpecular == null )
				{
					return false;
				}
			}
			//Resolve computed local shadow color parameter.
			this.psLocalShadowFactor = psMain.ResolveLocalParameter( Parameter.SemanticType.Unknown, 0, "lShadowFactor",
			                                                         GpuProgramParameters.GpuConstantType.Float1 );
			if ( this.psLocalShadowFactor == null )
			{
				return false;
			}

			//Resolve computed local shadow color parameter
			this.psSplitPoints = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
			                                                 GpuProgramParameters.GpuParamVariability.Global,
			                                                 "pssm_split_points" );
			if ( this.psSplitPoints == null )
			{
				return false;
			}

			//Get derived scene color
			this.psDerivedSceneColor =
				psProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0 );
			if ( this.psDerivedSceneColor == null )
			{
				return false;
			}

			int lightIndex = 0;

			foreach ( var it in this.shadowTextureParamsList )
			{
				it.WorldViewProjMatrix = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1,
				                                                     GpuProgramParameters.GpuParamVariability.PerObject,
				                                                     "world_texture_view_proj" );
				if ( it.WorldViewProjMatrix == null )
				{
					return false;
				}

				Parameter.ContentType lightSpace = Parameter.ContentType.PositionLightSpace0;

				switch ( lightIndex )
				{
					case 1:
						lightSpace = Parameter.ContentType.PositionLightSpace1;
						break;
					case 2:
						lightSpace = Parameter.ContentType.PositionLightSpace2;
						break;
					case 3:
						lightSpace = Parameter.ContentType.PositionLightSpace3;
						break;
					case 4:
						lightSpace = Parameter.ContentType.PositionLightSpace4;
						break;
					case 5:
						lightSpace = Parameter.ContentType.PositionLightSpace5;
						break;
					case 6:
						lightSpace = Parameter.ContentType.PositionLightSpace6;
						break;
					case 7:
						lightSpace = Parameter.ContentType.PositionLightSpace7;
						break;
				}

				it.VSOutLightPosition = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
				                                                       lightSpace,
				                                                       GpuProgramParameters.GpuConstantType.Float4 );
				if ( it.VSOutLightPosition == null )
				{
					return false;
				}

				it.PSInLightPosition = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
				                                                     it.VSOutLightPosition.Index,
				                                                     it.VSOutLightPosition.Content,
				                                                     GpuProgramParameters.GpuConstantType.Float4 );
				if ( it.PSInLightPosition == null )
				{
					return false;
				}

				it.TextureSampler = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Sampler2D,
				                                                it.TextureSamplerIndex,
				                                                GpuProgramParameters.GpuParamVariability.Global,
				                                                "shadow_map" );
				if ( it.TextureSampler == null )
				{
					return false;
				}

				it.InvTextureSize = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
				                                                GpuProgramParameters.GpuParamVariability.Global,
				                                                "inv_shadow_texture_size" );
				if ( it.InvTextureSize == null )
				{
					return false;
				}

				lightIndex++;
			}

			return true;
		}
예제 #17
0
		private static bool CompareUniformByName( UniformParameter param, string str )
		{
			return param.Name == str;
		}
예제 #18
0
		protected override bool ResolveParameters( ProgramSet programSet )
		{
			if ( this.fogMode == FogMode.None )
			{
				return true;
			}

			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;
			Function vsMain = vsProgram.EntryPointFunction;
			Function psMain = psProgram.EntryPointFunction;

			//Resolve world view matrix.
			this.worldViewProjMatrix =
				vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0 );
			if ( this.worldViewProjMatrix == null )
			{
				return false;
			}

			//Resolve vertex shader input position
			this.vsInPos = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
			                                             Parameter.ContentType.PositionObjectSpace,
			                                             GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsInPos == null )
			{
				return false;
			}

			//Resolve fog color
			this.fogColor = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
			                                            GpuProgramParameters.GpuParamVariability.Global, "gFogColor" );
			if ( this.fogColor == null )
			{
				return false;
			}

			//Resolve pixel shader output diffuse color
			this.psOutDiffuse = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0,
			                                                   Parameter.ContentType.ColorDiffuse,
			                                                   GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psOutDiffuse == null )
			{
				return false;
			}

			//Per pixel fog
			if ( this.calcMode == CalcMode.PerPixel )
			{
				//Resolve fog params
				this.fogParams = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
				                                             GpuProgramParameters.GpuParamVariability.Global, "gFogParams" );
				if ( this.fogParams == null )
				{
					return false;
				}

				//Resolve vertex shader output depth
				this.vsOutDepth = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
				                                                 Parameter.ContentType.DepthViewSpace,
				                                                 GpuProgramParameters.GpuConstantType.Float1 );
				if ( this.vsOutDepth == null )
				{
					return false;
				}

				//Resolve pixel shader input depth.
				this.psInDepth = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, this.vsOutDepth.Index,
				                                               this.vsOutDepth.Content,
				                                               GpuProgramParameters.GpuConstantType.Float1 );
				if ( this.psInDepth == null )
				{
					return false;
				}
			}
				//per vertex fog
			else
			{
				this.fogParams = vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
				                                             GpuProgramParameters.GpuParamVariability.Global, "gFogParams" );
				if ( this.fogParams == null )
				{
					return false;
				}

				//Resolve vertex shader output fog factor
				this.vsOutFogFactor = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
				                                                     Parameter.ContentType.Unknown,
				                                                     GpuProgramParameters.GpuConstantType.Float1 );
				if ( this.vsOutFogFactor == null )
				{
					return false;
				}

				//Resolve pixel shader input fog factor
				this.psInFogFactor = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
				                                                   this.vsOutFogFactor.Index, this.vsOutFogFactor.Content,
				                                                   GpuProgramParameters.GpuConstantType.Float1 );
				if ( this.psInFogFactor == null )
				{
					return false;
				}
			}


			return true;
		}
예제 #19
0
        protected override bool AddFunctionInvocations(ProgramSet programSet)
        {
            Program            vsProgram         = programSet.CpuVertexProgram;
            Program            psProgram         = programSet.CpuFragmentProgram;
            Function           psMain            = psProgram.EntryPointFunction;
            Function           vsMain            = vsProgram.EntryPointFunction;
            FunctionInvocation curFuncInvocation = null;
            //Calculate the position and size of the texture in the atlas in the vertex shader
            int groupOrder = ((int)FFPRenderState.FFPVertexShaderStage.VSTexturing -
                              (int)FFPRenderState.FFPVertexShaderStage.VSLighting) / 2;
            int internalCounter = 0;

            for (int i = 0; i < TextureAtlasSampler.MaxTextures; i++)
            {
                if (this.isAtlasTextureUnits[i] == true)
                {
                    Operand.OpMask textureIndexMask = Operand.OpMask.X;
                    switch (i)
                    {
                    case 1:
                        textureIndexMask = Operand.OpMask.Y;
                        break;

                    case 2:
                        textureIndexMask = Operand.OpMask.Z;
                        break;

                    case 3:
                        textureIndexMask = Operand.OpMask.W;
                        break;
                    }
                    curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign, groupOrder,
                                                               internalCounter++);
                    curFuncInvocation.PushOperand(this.vsTextureTable[i], Operand.OpSemantic.In);
                    curFuncInvocation.PushOperand(this.vsInpTextureTableIndex, Operand.OpSemantic.In, (int)textureIndexMask,
                                                  1);
                    curFuncInvocation.PushOperand(this.vsOutTextureDatas[i], Operand.OpSemantic.Out);
                    vsMain.AddAtomInstance(curFuncInvocation);
                }
            }

            //sample the texture in the fragment shader given the extracted data in the pixel shader
            // groupOrder = (FFP_PS_SAMPLING + FFP_PS_TEXTURING) / 2;
            internalCounter = 0;

            var inpParams   = psMain.InputParameters;
            var localParams = psMain.LocalParameters;

            Parameter psAtlasTextureCoord = psMain.ResolveLocalParameter(Parameter.SemanticType.Unknown, -1,
                                                                         "atlasCoord",
                                                                         GpuProgramParameters.GpuConstantType.Float2);

            for (int j = 0; j < TextureAtlasSampler.MaxTextures; j++)
            {
                if (this.isAtlasTextureUnits[j] == true)
                {
                    //Find the texture coordinates texel and sampler from the original FFPTexturing
                    Parameter texcoord = Function.GetParameterByContent(inpParams,
                                                                        (Parameter.ContentType)
                                                                            ((int)Parameter.ContentType.TextureCoordinate0 +
                                                                            j),
                                                                        GpuProgramParameters.GpuConstantType.Float2);
                    Parameter        texel   = Function.GetParameterByName(localParams, this.paramTexel + j.ToString());
                    UniformParameter sampler =
                        psProgram.GetParameterByType(GpuProgramParameters.GpuConstantType.Sampler2D, j);

                    //TODO
                    string addressUFuncName = GetAddressingFunctionName(this.textureAddressings[j].U);
                    string addressVFuncName = GetAddressingFunctionName(this.textureAddressings[j].V);

                    //Create a function which will replace the texel with the texture texel
                    if ((texcoord != null) && (texel != null) && (sampler != null) &&
                        (addressUFuncName != null) && (addressVFuncName != null))
                    {
                        //calculate the U value due to addressing mode
                        curFuncInvocation = new FunctionInvocation(addressUFuncName, groupOrder, internalCounter++);
                        curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, Operand.OpMask.X);
                        curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.Out, Operand.OpMask.X);
                        psMain.AddAtomInstance(curFuncInvocation);

                        //calculate the V value due to addressing mode
                        curFuncInvocation = new FunctionInvocation(addressVFuncName, groupOrder, internalCounter++);
                        curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, Operand.OpMask.Y);
                        curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.Out, Operand.OpMask.Y);
                        psMain.AddAtomInstance(curFuncInvocation);

                        //sample the texel color
                        curFuncInvocation =
                            new FunctionInvocation(this.autoAdjustPollPosition ? SGXFuncAtlasSampleAutoAdjust : SGXFuncAtlasSampleNormal,
                                                   groupOrder, internalCounter++);
                        curFuncInvocation.PushOperand(sampler, Operand.OpSemantic.In);
                        curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, (int)(Operand.OpMask.X | Operand.OpMask.Y));
                        curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.In);
                        curFuncInvocation.PushOperand(this.psInpTextureData[j], Operand.OpSemantic.In);
                        curFuncInvocation.PushOperand(this.psTextureSizes[j], Operand.OpSemantic.In);
                        curFuncInvocation.PushOperand(texel, Operand.OpSemantic.Out);
                        psMain.AddAtomInstance(curFuncInvocation);
                    }
                }
            }

            return(true);
        }
예제 #20
0
 private static bool CompareUniformByName(UniformParameter param, string str)
 {
     return(param.Name == str);
 }
예제 #21
0
        protected override bool ResolveParameters(ProgramSet programSet)
        {
            Program  vsProgram = programSet.CpuVertexProgram;
            Program  psProgram = programSet.CpuFragmentProgram;
            Function vsMain    = vsProgram.EntryPointFunction;
            Function psMain    = psProgram.EntryPointFunction;

            //Get input position parameter
            this.vsInPos = Function.GetParameterBySemantic(vsMain.InputParameters, Parameter.SemanticType.Position, 0);
            if (this.vsInPos == null)
            {
                return(false);
            }

            //Get output position parameter
            this.vsOutPos = Function.GetParameterBySemantic(vsMain.OutputParameters, Parameter.SemanticType.Position, 0);
            if (this.vsOutPos == null)
            {
                return(false);
            }

            //Resolve vertex shader output depth.
            this.vsOutDepth = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1,
                                                            Parameter.ContentType.DepthViewSpace,
                                                            GpuProgramParameters.GpuConstantType.Float1);
            if (this.vsOutDepth == null)
            {
                return(false);
            }

            //Resolve input depth parameter.
            this.psInDepth = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, this.vsOutDepth.Index,
                                                          this.vsOutDepth.Content, GpuProgramParameters.GpuConstantType.Float1);
            if (this.psInDepth == null)
            {
                return(false);
            }

            //Get in/local specular paramter
            this.psSpecular = Function.GetParameterBySemantic(psMain.InputParameters, Parameter.SemanticType.Color, 1);
            if (this.psSpecular == null)
            {
                this.psSpecular = Function.GetParameterBySemantic(psMain.LocalParameters, Parameter.SemanticType.Color, 1);
                if (this.psSpecular == null)
                {
                    return(false);
                }
            }
            //Resolve computed local shadow color parameter.
            this.psLocalShadowFactor = psMain.ResolveLocalParameter(Parameter.SemanticType.Unknown, 0, "lShadowFactor",
                                                                    GpuProgramParameters.GpuConstantType.Float1);
            if (this.psLocalShadowFactor == null)
            {
                return(false);
            }

            //Resolve computed local shadow color parameter
            this.psSplitPoints = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                            GpuProgramParameters.GpuParamVariability.Global,
                                                            "pssm_split_points");
            if (this.psSplitPoints == null)
            {
                return(false);
            }

            //Get derived scene color
            this.psDerivedSceneColor =
                psProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.DerivedSceneColor, 0);
            if (this.psDerivedSceneColor == null)
            {
                return(false);
            }

            int lightIndex = 0;

            foreach (var it in this.shadowTextureParamsList)
            {
                it.WorldViewProjMatrix = vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Matrix_4X4, -1,
                                                                    GpuProgramParameters.GpuParamVariability.PerObject,
                                                                    "world_texture_view_proj");
                if (it.WorldViewProjMatrix == null)
                {
                    return(false);
                }

                Parameter.ContentType lightSpace = Parameter.ContentType.PositionLightSpace0;

                switch (lightIndex)
                {
                case 1:
                    lightSpace = Parameter.ContentType.PositionLightSpace1;
                    break;

                case 2:
                    lightSpace = Parameter.ContentType.PositionLightSpace2;
                    break;

                case 3:
                    lightSpace = Parameter.ContentType.PositionLightSpace3;
                    break;

                case 4:
                    lightSpace = Parameter.ContentType.PositionLightSpace4;
                    break;

                case 5:
                    lightSpace = Parameter.ContentType.PositionLightSpace5;
                    break;

                case 6:
                    lightSpace = Parameter.ContentType.PositionLightSpace6;
                    break;

                case 7:
                    lightSpace = Parameter.ContentType.PositionLightSpace7;
                    break;
                }

                it.VSOutLightPosition = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1,
                                                                      lightSpace,
                                                                      GpuProgramParameters.GpuConstantType.Float4);
                if (it.VSOutLightPosition == null)
                {
                    return(false);
                }

                it.PSInLightPosition = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates,
                                                                    it.VSOutLightPosition.Index,
                                                                    it.VSOutLightPosition.Content,
                                                                    GpuProgramParameters.GpuConstantType.Float4);
                if (it.PSInLightPosition == null)
                {
                    return(false);
                }

                it.TextureSampler = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Sampler2D,
                                                               it.TextureSamplerIndex,
                                                               GpuProgramParameters.GpuParamVariability.Global,
                                                               "shadow_map");
                if (it.TextureSampler == null)
                {
                    return(false);
                }

                it.InvTextureSize = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                               GpuProgramParameters.GpuParamVariability.Global,
                                                               "inv_shadow_texture_size");
                if (it.InvTextureSize == null)
                {
                    return(false);
                }

                lightIndex++;
            }

            return(true);
        }
예제 #22
0
		private void WriteUniformParameter( StreamWriter stream, UniformParameter parameter )
		{
			stream.Write( this.gpuConstTypeMap[ parameter.Type ] );
			stream.Write( "\t" );
			stream.Write( parameter.Name );
			if ( parameter.IsArray )
			{
				stream.Write( "[" + parameter.Size + "]" );
			}

			if ( parameter.IsSampler )
			{
				stream.Write( " : register(s" + parameter.Index + ")" );
			}
		}
예제 #23
0
		protected override bool ResolveParameters( Axiom.Components.RTShaderSystem.ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;

			Function vsMain = vsProgram.EntryPointFunction;
			Function psMain = psProgram.EntryPointFunction;

			//Resolve vertex shader output position in projective space.

			this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
			                                                  Parameter.ContentType.PositionObjectSpace,
			                                                  Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsInPosition == null )
			{
				return false;
			}

			this.vsOriginalOutPositionProjectiveSpace = vsMain.ResolveOutputParameter( Parameter.SemanticType.Position, 0,
			                                                                           Parameter.ContentType.
			                                                                           	PositionProjectiveSpace,
			                                                                           Graphics.GpuProgramParameters.
			                                                                           	GpuConstantType.
			                                                                           	Float4 );
			if ( this.vsOriginalOutPositionProjectiveSpace == null )
			{
				return false;
			}

			var positionProjectiveSpaceAsTexcoord = (Parameter.ContentType)( Parameter.ContentType.CustomContentBegin + 1 );
			this.vsOutPositionProjectiveSpace = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
			                                                                   positionProjectiveSpaceAsTexcoord,
			                                                                   Graphics.GpuProgramParameters.GpuConstantType.
			                                                                   	Float4 );
			if ( this.vsOutPositionProjectiveSpace == null )
			{
				return false;
			}

			//Resolve ps input position in projective space
			this.psInPositionProjectiveSpace = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
			                                                                 this.vsOutPositionProjectiveSpace.Index,
			                                                                 this.vsOutPositionProjectiveSpace.Content,
			                                                                 Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psInPositionProjectiveSpace == null )
			{
				return false;
			}

			//Resolve vertex shader uniform monitors count
			this.vsInMonitorsCount = vsProgram.ResolveParameter( Graphics.GpuProgramParameters.GpuConstantType.Float2, -1,
			                                                     Graphics.GpuProgramParameters.GpuParamVariability.Global,
			                                                     "monitorsCount" );
			if ( this.vsInMonitorsCount == null )
			{
				return false;
			}

			//Resolve pixel shader uniform monitors count
			this.psInMonitorsCount = psProgram.ResolveParameter( Graphics.GpuProgramParameters.GpuConstantType.Float2, -1,
			                                                     Graphics.GpuProgramParameters.GpuParamVariability.Global,
			                                                     "monitorsCount" );
			if ( this.psInMonitorsCount == null )
			{
				return false;
			}

			//Resolve the current world & view matrices concatenated
			this.worldViewMatrix =
				vsProgram.ResolveAutoParameterInt( Graphics.GpuProgramParameters.AutoConstantType.WorldViewMatrix,
				                                   0 );
			if ( this.worldViewMatrix == null )
			{
				return false;
			}

			//Resolve the current projection matrix
			this.projectionMatrix = vsProgram.ResolveAutoParameterInt(
				Graphics.GpuProgramParameters.AutoConstantType.ProjectionMatrix, 0 );
			if ( this.projectionMatrix == null )
			{
				return false;
			}

			var monitorIndex = Parameter.ContentType.TextureCoordinate3;
			//Resolve vertex shader monitor index
			this.vsInMonitorIndex = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, 3, monitorIndex,
			                                                      Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsInMonitorIndex == null )
			{
				return false;
			}

			Parameter.ContentType matrixR0 = Parameter.ContentType.TextureCoordinate4;
			Parameter.ContentType matrixR1 = Parameter.ContentType.TextureCoordinate5;
			Parameter.ContentType matrixR2 = Parameter.ContentType.TextureCoordinate6;
			Parameter.ContentType matrixR3 = Parameter.ContentType.TextureCoordinate7;

			//Resolve vertex shader viewport offset matrix
			this.vsInViewportOffsetMatrixR0 = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, 4,
			                                                                matrixR0,
			                                                                Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsInViewportOffsetMatrixR0 == null )
			{
				return false;
			}
			this.vsInViewportOffsetMatrixR1 = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, 4,
			                                                                matrixR1,
			                                                                Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsInViewportOffsetMatrixR1 == null )
			{
				return false;
			}
			this.vsInViewportOffsetMatrixR2 = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, 4,
			                                                                matrixR2,
			                                                                Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsInViewportOffsetMatrixR2 == null )
			{
				return false;
			}
			this.vsInViewportOffsetMatrixR3 = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, 4,
			                                                                matrixR3,
			                                                                Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsInViewportOffsetMatrixR3 == null )
			{
				return false;
			}

			this.vsOutMonitorIndex = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1, monitorIndex,
			                                                        Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsOutMonitorIndex == null )
			{
				return false;
			}

			//Resolve ps input monitor index
			this.psInMonitorIndex = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
			                                                      this.vsOutMonitorIndex.Index,
			                                                      this.vsOutMonitorIndex.Content,
			                                                      Graphics.GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psInMonitorIndex == null )
			{
				return false;
			}

			return true;
		}
예제 #24
0
		protected bool ResolvePerLightParameters( ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;
			Function vsMain = vsProgram.EntryPointFunction;
			Function psMain = psProgram.EntryPointFunction;

			//Resolve per light parameters
			for ( int i = 0; i < this.lightParamsList.Count; i++ )
			{
				switch ( this.lightParamsList[ i ].Type )
				{
					case LightType.Directional:
						this.lightParamsList[ i ].Direction =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_direction_view_space" );
						if ( this.lightParamsList[ i ].Direction == null )
						{
							return false;
						}
						break;
					case LightType.Point:
						this.worldViewMatrix =
							vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 );
						if ( this.worldViewMatrix == null )
						{
							return false;
						}

						this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
						                                                  Parameter.ContentType.PositionObjectSpace,
						                                                  GpuProgramParameters.GpuConstantType.Float4 );
						if ( this.vsInPosition == null )
						{
							return false;
						}

						this.lightParamsList[ i ].Position =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_position_view_space" );
						if ( this.lightParamsList[ i ].Position == null )
						{
							return false;
						}

						this.lightParamsList[ i ].AttenuatParams =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_attenuation" );
						if ( this.lightParamsList[ i ].AttenuatParams == null )
						{
							return false;
						}

						if ( this.vsOutViewPos == null )
						{
							this.vsOutViewPos = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
							                                                   Parameter.ContentType.PositionViewSpace,
							                                                   GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.vsOutViewPos == null )
							{
								return false;
							}

							this.psInViewPos = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
							                                                 this.vsOutViewPos.Index, this.vsOutViewPos.Content,
							                                                 GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.psInViewPos == null )
							{
								return false;
							}
						}
						break;
					case LightType.Spotlight:
						this.worldViewMatrix =
							vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldViewMatrix, 0 );
						if ( this.worldViewMatrix == null )
						{
							return false;
						}

						this.vsInPosition = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
						                                                  Parameter.ContentType.PositionObjectSpace,
						                                                  GpuProgramParameters.GpuConstantType.Float4 );
						if ( this.vsInPosition == null )
						{
							return false;
						}

						this.lightParamsList[ i ].Position =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_position_view_space" );
						if ( this.lightParamsList[ i ].Position == null )
						{
							return false;
						}

						this.lightParamsList[ i ].Direction =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_direction_view_space" );
						if ( this.lightParamsList[ i ].Direction == null )
						{
							return false;
						}

						this.lightParamsList[ i ].AttenuatParams =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_attenuation" );
						if ( this.lightParamsList[ i ].AttenuatParams == null )
						{
							return false;
						}

						this.lightParamsList[ i ].SpotParams =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float3, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "spotlight_params" );
						if ( this.lightParamsList[ i ].SpotParams == null )
						{
							return false;
						}

						if ( this.vsOutViewPos == null )
						{
							this.vsOutViewPos = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
							                                                   Parameter.ContentType.PositionViewSpace,
							                                                   GpuProgramParameters.GpuConstantType.Float3 );
							if ( this.vsOutViewPos == null )
							{
								return false;
							}

							this.psInViewPos = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
							                                                 this.vsOutViewPos.Index,
							                                                 this.vsOutViewPos.Content,
							                                                 GpuProgramParameters.GpuConstantType.Float3 );

							if ( this.psInViewPos == null )
							{
								return false;
							}
						}
						break;
				}

				//Resolve diffuse color
				if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
				{
					this.lightParamsList[ i ].DiffuseColor =
						psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
						                            GpuProgramParameters.GpuParamVariability.Lights |
						                            GpuProgramParameters.GpuParamVariability.Global,
						                            "derived_light_diffuse" );
					if ( this.lightParamsList[ i ].DiffuseColor == null )
					{
						return false;
					}
				}
				else
				{
					this.lightParamsList[ i ].DiffuseColor =
						psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
						                            GpuProgramParameters.GpuParamVariability.Lights, "light_diffuse" );
					if ( this.lightParamsList[ i ].DiffuseColor == null )
					{
						return false;
					}
				}

				if ( this.specularEnable )
				{
					//Resolve specular color
					if ( ( this.trackVertexColorType & TrackVertexColor.Specular ) == 0 )
					{
						this.lightParamsList[ i ].SpecularColor =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights |
							                            GpuProgramParameters.GpuParamVariability.Global,
							                            "derived_light_specular" );
						if ( this.lightParamsList[ i ].SpecularColor == null )
						{
							return false;
						}
					}
					else
					{
						this.lightParamsList[ i ].SpecularColor =
							psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float4, -1,
							                            GpuProgramParameters.GpuParamVariability.Lights,
							                            "light_specular" );
						if ( this.lightParamsList[ i ].SpecularColor == null )
						{
							return false;
						}
					}
				}
			}
			return true;
		}
예제 #25
0
		private bool ResolveUniformParams( TextureUnitParams textureUnitParams, ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;

			//Resolve texture sampler parameter.
			textureUnitParams.TextureSampler = psProgram.ResolveParameter( textureUnitParams.TextureSamplerType,
			                                                               textureUnitParams.TextureSamplerIndex,
			                                                               GpuProgramParameters.GpuParamVariability.
			                                                               	Global, "gTextureSampler" );
			if ( textureUnitParams.TextureSampler == null )
			{
				return false;
			}

			//Resolve texture matrix parameter
			if ( NeedsTextureMatrix( textureUnitParams.TextureUnitState ) )
			{
				textureUnitParams.TextureMatrix =
					vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.TextureMatrix,
					                                   textureUnitParams.TextureSamplerIndex );
				if ( textureUnitParams.TextureMatrix == null )
				{
					return false;
				}
			}

			switch ( textureUnitParams.TexCoordCalcMethod )
			{
				case TexCoordCalcMethod.None:
					break;
				case TexCoordCalcMethod.EnvironmentMap:
				case TexCoordCalcMethod.EnvironmentMapNormal:
				case TexCoordCalcMethod.EnvironmentMapPlanar:
					this.worldITMatrix =
						vsProgram.ResolveAutoParameterInt(
							GpuProgramParameters.AutoConstantType.InverseTransposeWorldMatrix, 0 );
					if ( this.worldITMatrix == null )
					{
						return false;
					}

					this.viewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.ViewMatrix, 0 );
					if ( this.viewMatrix == null )
					{
						return false;
					}
					break;
				case TexCoordCalcMethod.EnvironmentMapReflection:
					this.worldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix,
					                                                      0 );
					if ( this.worldMatrix == null )
					{
						return false;
					}

					this.worldITMatrix =
						vsProgram.ResolveAutoParameterInt(
							GpuProgramParameters.AutoConstantType.InverseTransposeWorldMatrix, 0 );
					if ( this.worldITMatrix == null )
					{
						return false;
					}

					this.viewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.ViewMatrix, 0 );
					if ( this.viewMatrix == null )
					{
						return false;
					}
					break;
				case TexCoordCalcMethod.ProjectiveTexture:
					this.worldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix,
					                                                      0 );
					if ( this.worldMatrix == null )
					{
						return false;
					}

					textureUnitParams.TextureViewProjImageMatrix =
						vsProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Matrix_4X4, -1,
						                            GpuProgramParameters.GpuParamVariability.Lights,
						                            "gTexViewProjImageMatrix" );
					if ( textureUnitParams.TextureViewProjImageMatrix == null )
					{
						return false;
					}

					var effects = new List<TextureEffect>();
					for ( int i = 0; i < textureUnitParams.TextureUnitState.NumEffects; i++ )
					{
						var curEffect = textureUnitParams.TextureUnitState.GetEffect( i );
						effects.Add( curEffect );
					}

					foreach ( var effi in effects )
					{
						if ( effi.type == TextureEffectType.ProjectiveTexture )
						{
							textureUnitParams.TextureProjector = effi.frustum;
							break;
						}
					}

					if ( textureUnitParams.TextureProjector == null )
					{
						return false;
					}
					break;
			}
			return true;
		}
예제 #26
0
파일: FFPFog.cs 프로젝트: bostich83/axiom
        protected override bool ResolveParameters(ProgramSet programSet)
        {
            if (this.fogMode == FogMode.None)
            {
                return(true);
            }

            Program  vsProgram = programSet.CpuVertexProgram;
            Program  psProgram = programSet.CpuFragmentProgram;
            Function vsMain    = vsProgram.EntryPointFunction;
            Function psMain    = psProgram.EntryPointFunction;

            //Resolve world view matrix.
            this.worldViewProjMatrix =
                vsProgram.ResolveAutoParameterInt(GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0);
            if (this.worldViewProjMatrix == null)
            {
                return(false);
            }

            //Resolve vertex shader input position
            this.vsInPos = vsMain.ResolveInputParameter(Parameter.SemanticType.Position, 0,
                                                        Parameter.ContentType.PositionObjectSpace,
                                                        GpuProgramParameters.GpuConstantType.Float4);
            if (this.vsInPos == null)
            {
                return(false);
            }

            //Resolve fog color
            this.fogColor = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                       GpuProgramParameters.GpuParamVariability.Global, "gFogColor");
            if (this.fogColor == null)
            {
                return(false);
            }

            //Resolve pixel shader output diffuse color
            this.psOutDiffuse = psMain.ResolveOutputParameter(Parameter.SemanticType.Color, 0,
                                                              Parameter.ContentType.ColorDiffuse,
                                                              GpuProgramParameters.GpuConstantType.Float4);
            if (this.psOutDiffuse == null)
            {
                return(false);
            }

            //Per pixel fog
            if (this.calcMode == CalcMode.PerPixel)
            {
                //Resolve fog params
                this.fogParams = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                            GpuProgramParameters.GpuParamVariability.Global, "gFogParams");
                if (this.fogParams == null)
                {
                    return(false);
                }

                //Resolve vertex shader output depth
                this.vsOutDepth = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1,
                                                                Parameter.ContentType.DepthViewSpace,
                                                                GpuProgramParameters.GpuConstantType.Float1);
                if (this.vsOutDepth == null)
                {
                    return(false);
                }

                //Resolve pixel shader input depth.
                this.psInDepth = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, this.vsOutDepth.Index,
                                                              this.vsOutDepth.Content,
                                                              GpuProgramParameters.GpuConstantType.Float1);
                if (this.psInDepth == null)
                {
                    return(false);
                }
            }
            //per vertex fog
            else
            {
                this.fogParams = vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1,
                                                            GpuProgramParameters.GpuParamVariability.Global, "gFogParams");
                if (this.fogParams == null)
                {
                    return(false);
                }

                //Resolve vertex shader output fog factor
                this.vsOutFogFactor = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1,
                                                                    Parameter.ContentType.Unknown,
                                                                    GpuProgramParameters.GpuConstantType.Float1);
                if (this.vsOutFogFactor == null)
                {
                    return(false);
                }

                //Resolve pixel shader input fog factor
                this.psInFogFactor = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates,
                                                                  this.vsOutFogFactor.Index, this.vsOutFogFactor.Content,
                                                                  GpuProgramParameters.GpuConstantType.Float1);
                if (this.psInFogFactor == null)
                {
                    return(false);
                }
            }


            return(true);
        }
예제 #27
0
		protected override bool ResolveParameters( ProgramSet programSet )
		{
			Program vsProgram = programSet.CpuVertexProgram;
			Program psProgram = programSet.CpuFragmentProgram;
			Function vsMain = vsProgram.EntryPointFunction;
			Function psMain = psProgram.EntryPointFunction;

			// Resolve vs input mask texture coordinates.
			// NOTE: We use the first texture coordinate hard coded here
			// You may want to parametrize this as well - just remember to add it to hash and copy methods. 
			this.vsInMaskTexcoord = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, 0,
			                                                      Parameter.ContentType.TextureCoordinate0,
			                                                      GpuProgramParameters.GpuConstantType.Float2 );
			if ( this.vsInMaskTexcoord == null )
			{
				return false;
			}

			//Resolve vs output mask texture coordinates
			this.vsInMaskTexcoord = vsMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates, 0,
			                                                      Parameter.ContentType.TextureCoordinate0,
			                                                      GpuProgramParameters.GpuConstantType.Float2 );
			if ( this.vsInMaskTexcoord == null )
			{
				return false;
			}

			//Resolve vs output mask texture coordinates.
			this.vsOutMaskTexcoord = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
			                                                        this.vsInMaskTexcoord.Content,
			                                                        GpuProgramParameters.GpuConstantType.Float2 );
			if ( this.vsInMaskTexcoord == null )
			{
				return false;
			}

			//Resolve ps input mask texture coordinates.
			this.psInMaskTexcoord = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
			                                                      this.vsOutMaskTexcoord.Index,
			                                                      this.vsOutMaskTexcoord.Content,
			                                                      GpuProgramParameters.GpuConstantType.Float2 );

			//Resolve vs output reflection texture coordinates
			this.vsOutReflectionTexcoord = vsMain.ResolveOutputParameter( Parameter.SemanticType.TextureCoordinates, -1,
			                                                              Parameter.ContentType.Unknown,
			                                                              ( this.reflectionMapType == TextureType.TwoD )
			                                                              	? GpuProgramParameters.GpuConstantType.Float2
			                                                              	: GpuProgramParameters.GpuConstantType.Float3 );
			if ( this.vsOutReflectionTexcoord == null )
			{
				return false;
			}

			//Resolve ps input reflection texture coordinates.
			this.psInReflectionTexcoord = psMain.ResolveInputParameter( Parameter.SemanticType.TextureCoordinates,
			                                                            this.vsOutReflectionTexcoord.Index,
			                                                            this.vsOutReflectionTexcoord.Content,
			                                                            this.vsOutReflectionTexcoord.Type );

			//Resolve world matrix.
			this.worldMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.WorldMatrix, 0 );
			if ( this.worldMatrix == null )
			{
				return false;
			}

			this.worldITMatrix = vsProgram.ResolveAutoParameterInt(
				GpuProgramParameters.AutoConstantType.InverseTransposeWorldMatrix, 0 );
			if ( this.worldITMatrix == null )
			{
				return false;
			}

			this.viewMatrix = vsProgram.ResolveAutoParameterInt( GpuProgramParameters.AutoConstantType.ViewMatrix, 0 );
			if ( this.viewMatrix == null )
			{
				return false;
			}

			this.vsInputPos = vsMain.ResolveInputParameter( Parameter.SemanticType.Position, 0,
			                                                Parameter.ContentType.PositionObjectSpace,
			                                                GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.vsInputPos == null )
			{
				return false;
			}

			this.vsInputNormal = vsMain.ResolveInputParameter( Parameter.SemanticType.Normal, 0,
			                                                   Parameter.ContentType.NormalObjectSpace,
			                                                   GpuProgramParameters.GpuConstantType.Float3 );
			if ( this.vsInputNormal == null )
			{
				return false;
			}

			this.maskMapSampler = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Sampler2D,
			                                                  this.maskMapSamplerIndex,
			                                                  GpuProgramParameters.GpuParamVariability.Global, "mask_sampler" );
			if ( this.maskMapSampler == null )
			{
				return false;
			}

			this.reflectionMapSampler =
				psProgram.ResolveParameter(
					( this.reflectionMapType == TextureType.TwoD )
						? GpuProgramParameters.GpuConstantType.Sampler2D
						: GpuProgramParameters.GpuConstantType.SamplerCube,
					this.reflectionMapSamplerIndex, GpuProgramParameters.GpuParamVariability.Global, "reflection_texture" );
			if ( this.reflectionMapSampler == null )
			{
				return false;
			}

			this.reflectionPower = psProgram.ResolveParameter( GpuProgramParameters.GpuConstantType.Float1, -1,
			                                                   GpuProgramParameters.GpuParamVariability.Global,
			                                                   "reflection_power" );
			if ( this.reflectionPower == null )
			{
				return false;
			}

			this.psOutDiffuse = psMain.ResolveOutputParameter( Parameter.SemanticType.Color, 0,
			                                                   Parameter.ContentType.ColorDiffuse,
			                                                   GpuProgramParameters.GpuConstantType.Float4 );
			if ( this.psOutDiffuse == null )
			{
				return false;
			}

			return true;
		}