コード例 #1
0
        public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler,
                                                      PropertyAbstractNode prop, Graphics.Pass pass,
                                                      SGScriptTranslator stranslator)
        {
            if (prop.Name == "lighting_stage")
            {
                if (prop.Values.Count >= 2)
                {
                    string strValue;
                    int    it = 0;

                    //Read light model type.
                    if (!SGScriptTranslator.GetString(prop.Values[it], out strValue))
                    {
                        //compiler.AddError(...)
                        return(null);
                    }

                    //Case light model type is normal map
                    if (strValue == "normal_map")
                    {
                        it++;
                        if (!SGScriptTranslator.GetString(prop.Values[it], out strValue))
                        {
                            //compiler.AddError(...)
                            return(null);
                        }

                        SubRenderState subRenderState          = CreateOrRetrieveInstance(stranslator);
                        var            normalMapSubRenderState = subRenderState as NormalMapLighting;

                        normalMapSubRenderState.NormalMapTextureName = strValue;

                        //Read normal map space type.
                        if (prop.Values.Count >= 3)
                        {
                            it++;
                            if (!SGScriptTranslator.GetString(prop.Values[it], out strValue))
                            {
                                //compiler.AddError(...)
                                return(null);
                            }

                            //Normal map defines normals in tangent space.
                            if (strValue == "tangent_space")
                            {
                                normalMapSubRenderState.NormalMapSpace = NormalMapSpace.Tangent;
                            }

                            //Normal map defines normals in object space
                            if (strValue == "object_space")
                            {
                                normalMapSubRenderState.NormalMapSpace = NormalMapSpace.Object;
                            }
                        }

                        //Read texture coordinate index.
                        if (prop.Values.Count >= 4)
                        {
                            int textureCoordinatesIndex = 0;
                            it++;
                            if (!SGScriptTranslator.GetInt(prop.Values[it], out textureCoordinatesIndex))
                            {
                                normalMapSubRenderState.TexCoordIndex = textureCoordinatesIndex;
                            }
                        }

                        //Read texture filtering format
                        if (prop.Values.Count >= 5)
                        {
                            it++;
                            if (!SGScriptTranslator.GetString(prop.Values[it], out strValue))
                            {
                                //compiler.AddError(...)
                                return(null);
                            }

                            if (strValue == "none")
                            {
                                normalMapSubRenderState.SetNormalMapFiltering(Graphics.FilterOptions.Point, Graphics.FilterOptions.Point,
                                                                              Graphics.FilterOptions.None);
                            }
                            else if (strValue == "bilinear")
                            {
                                normalMapSubRenderState.SetNormalMapFiltering(Graphics.FilterOptions.Linear, Graphics.FilterOptions.Linear,
                                                                              Graphics.FilterOptions.Point);
                            }
                            else if (strValue == "trilinear")
                            {
                                normalMapSubRenderState.SetNormalMapFiltering(Graphics.FilterOptions.Linear, Graphics.FilterOptions.Linear,
                                                                              Graphics.FilterOptions.Linear);
                            }
                            else if (strValue == "anisotropic")
                            {
                                normalMapSubRenderState.SetNormalMapFiltering(Graphics.FilterOptions.Anisotropic,
                                                                              Graphics.FilterOptions.Anisotropic, Graphics.FilterOptions.Linear);
                            }
                        }

                        //Read max anisotropy value
                        if (prop.Values.Count >= 6)
                        {
                            int maxAnisotropy = 0;
                            it++;
                            if (SGScriptTranslator.GetInt(prop.Values[it], out maxAnisotropy))
                            {
                                normalMapSubRenderState.NormalMapAnisotropy = maxAnisotropy;
                            }
                        }
                        //Read mip bias value.
                        if (prop.Values.Count >= 7)
                        {
                            Real mipBias = 0;
                            it++;
                            if (SGScriptTranslator.GetReal(prop.Values[it], out mipBias))
                            {
                                normalMapSubRenderState.NormalMapMipBias = mipBias;
                            }
                        }
                        return(subRenderState);
                    }
                }
            }
            return(null);
        }
コード例 #2
0
        public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler,
                                                      Scripting.Compiler.AST.PropertyAbstractNode prop, Pass pass,
                                                      SGScriptTranslator stranslator)
        {
            if (prop.Name == "hardware_skinning")
            {
                bool         hasError     = false;
                int          boneCount    = 0;
                int          weightCount  = 0;
                string       skinningType = string.Empty;
                SkinningType skinType     = SkinningType.Linear;
                bool         correctAntipodalityHandling = false;
                bool         scalingShearingSupport      = false;

                if (prop.Values.Count >= 2)
                {
                    int it = 0;

                    if (SGScriptTranslator.GetInt(prop.Values[it], out boneCount) == false)
                    {
                        hasError = true;
                    }

                    it++;
                    if (SGScriptTranslator.GetInt(prop.Values[it], out weightCount) == false)
                    {
                        hasError = true;
                    }

                    if (prop.Values.Count >= 5)
                    {
                        it++;
                        SGScriptTranslator.GetString(prop.Values[it], out skinningType);

                        it++;
                        SGScriptTranslator.GetBoolean(prop.Values[it], out correctAntipodalityHandling);

                        it++;
                        SGScriptTranslator.GetBoolean(prop.Values[it], out scalingShearingSupport);
                    }

                    //If the skinningType is not specified or is specified incorretly, default to linear
                    if (skinningType == "dual_quaternion")
                    {
                        skinType = SkinningType.DualQuaternion;
                    }
                    else
                    {
                        skinType = SkinningType.Linear;
                    }
                }
                if (hasError)
                {
                    //TODO
                    //compiler.AddError(...);
                    return(null);
                }
                else
                {
                    //create and update the hardware skinning sub render state
                    SubRenderState subRenderState = CreateOrRetrieveInstance(stranslator);
                    var            hardSkinSrs    = (HardwareSkinning)subRenderState;
                    hardSkinSrs.SetHardwareSkinningParam(boneCount, weightCount, skinType, correctAntipodalityHandling,
                                                         scalingShearingSupport);

                    return(subRenderState);
                }
            }


            return(null);
        }