Esempio n. 1
0
        private void TranslateTextureUnit(Scripting.Compiler.ScriptCompiler compiler, AbstractNode node)
        {
            var             obj                    = (ObjectAbstractNode)node;
            var             texState               = (TextureUnitState)obj.Parent.Context;
            Pass            pass                   = texState.Parent;
            Technique       technique              = pass.Parent;
            Material        material               = technique.Parent;
            ShaderGenerator shaderGenerator        = ShaderGenerator.Instance;
            string          dstTechniqueSchemeName = obj.Name;
            bool            techniqueCreated;

            //Make sure teh scheme is valid - use default if none exists
            if (dstTechniqueSchemeName == string.Empty)
            {
                dstTechniqueSchemeName = ShaderGenerator.DefaultSchemeName;
            }

            //check if technique already created
            techniqueCreated = shaderGenerator.HasShaderBasedTechnique(material.Name, material.Group,
                                                                       technique.SchemeName, dstTechniqueSchemeName);

            if (techniqueCreated == false)
            {
                //Create the shader based techniqe
                techniqueCreated = shaderGenerator.CreateShaderBasedTechnique(material.Name, material.Group,
                                                                              technique.SchemeName,
                                                                              dstTechniqueSchemeName,
                                                                              shaderGenerator.
                                                                              CreateShaderOverProgrammablePass);
            }

            if (techniqueCreated)
            {
                //Attempt to get the render state which might have been created by the pass parsing
                this.generatedRenderState = shaderGenerator.GetRenderState(dstTechniqueSchemeName, material.Name,
                                                                           material.Group, (ushort)pass.Index);

                //Go over all the render state properties
                for (int i = 0; i < obj.Children.Count; i++)
                {
                    if (obj.Children[i] is PropertyAbstractNode)
                    {
                        var            prop           = obj.Children[i] as PropertyAbstractNode;
                        SubRenderState subRenderState = ShaderGenerator.Instance.createSubRenderState(compiler, prop,
                                                                                                      texState, this);

                        if (subRenderState != null)
                        {
                            AddSubRenderState(subRenderState, dstTechniqueSchemeName, material.Name, material.Group,
                                              pass.Index);
                        }
                    }
                    else
                    {
                        processNode(compiler, obj.Children[i]);
                    }
                }
            }
        }
Esempio n. 2
0
        public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler,
                                                      Scripting.Compiler.AST.PropertyAbstractNode prop, Graphics.Pass pass,
                                                      SGScriptTranslator stranslator)
        {
            SubRenderState subRenderState = CreateInstance();

            return(subRenderState);
        }
Esempio n. 3
0
        public override void Translate(Scripting.Compiler.ScriptCompiler compiler,
                                       Scripting.Compiler.AST.AbstractNode node)
        {
            var obj    = (ObjectAbstractNode)node;
            var parent = (ObjectAbstractNode)obj.Parent;

            //Translate section within a pass context
            if (parent.Cls == "pass")
            {
                TranslatePass(compiler, node);
            }
            if (parent.Cls == "texture_unit")
            {
                TranslateTextureUnit(compiler, node);
            }
        }
Esempio n. 4
0
        public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler,
                                                      Scripting.Compiler.AST.PropertyAbstractNode prop,
                                                      Graphics.Pass pass, SGScriptTranslator stranslator)
        {
            if (prop.Name == "fog_stage")
            {
                if (prop.Values.Count >= 1)
                {
                    string strValue;

                    if (!SGScriptTranslator.GetString(prop.Values[0], out strValue))
                    {
                        //compiler.AddError(...);
                        return(null);
                    }

                    if (strValue == "ffp")
                    {
                        SubRenderState subRenderState    = CreateOrRetrieveInstance(stranslator);
                        var            fogSubRenderState = (FFPFog)subRenderState;
                        int            it = 0;

                        if (prop.Values.Count >= 2)
                        {
                            it++;
                            if (!SGScriptTranslator.GetString(prop.Values[it], out strValue))
                            {
                                //compiler.AddError(...);
                                return(null);
                            }
                            if (strValue == "per_vertex")
                            {
                                fogSubRenderState.CalculationMode = FFPFog.CalcMode.PerVertex;
                            }
                            else if (strValue == "per_pixel")
                            {
                                fogSubRenderState.CalculationMode = FFPFog.CalcMode.PerPixel;
                            }
                        }
                        return(subRenderState);
                    }
                }
            }
            return(null);
        }
Esempio n. 5
0
        public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler,
                                                      Scripting.Compiler.AST.PropertyAbstractNode prop,
                                                      Graphics.Pass pass, SGScriptTranslator stranslator)
        {
            if (prop.Name == "integrated_pssm4")
            {
                if (prop.Values.Count != 4)
                {
                    //TODO
                    // compiler.AddError(...);
                }
                else
                {
                    var splitPointList = new List <Real>();

                    foreach (var it in prop.Values)
                    {
                        Real curSplitValue;

                        if (!SGScriptTranslator.GetReal(it, out curSplitValue))
                        {
                            //TODO
                            //compiler.AddError(...);
                            break;
                        }

                        splitPointList.Add(curSplitValue);
                    }

                    if (splitPointList.Count == 4)
                    {
                        SubRenderState subRenderState     = CreateOrRetrieveInstance(stranslator);
                        var            pssmSubRenderState = (IntegratedPSSM3)subRenderState;
                        pssmSubRenderState.SetSplitPoints(splitPointList);

                        return(pssmSubRenderState);
                    }
                }
            }

            return(null);
        }
Esempio n. 6
0
        public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler,
                                                      Scripting.Compiler.AST.PropertyAbstractNode prop,
                                                      Graphics.Pass pass, SGScriptTranslator stranslator)
        {
            if (prop.Name == "lighting_stage")
            {
                if (prop.Values.Count == 1)
                {
                    string modelType;
                    if (SGScriptTranslator.GetString(prop.Values[0], out modelType) == false)
                    {
                        //compiler.AddError(...)
                        return(null);
                    }
                    if (modelType == "per_pixel")
                    {
                        return(CreateOrRetrieveInstance(stranslator));
                    }
                }
            }

            return(null);
        }
Esempio n. 7
0
        private void TranslatePass(Scripting.Compiler.ScriptCompiler compiler, AbstractNode node)
        {
            var             obj                    = (ObjectAbstractNode)node;
            var             pass                   = (Pass)obj.Parent.Context;
            Technique       technique              = pass.Parent;
            Material        material               = technique.Parent;
            ShaderGenerator shaderGenerator        = ShaderGenerator.Instance;
            string          dstTechniqueSchemeName = obj.Name;
            bool            techniqueCreated;

            //Make sure scheme name is valid - use default if none exists
            if (dstTechniqueSchemeName == string.Empty)
            {
                dstTechniqueSchemeName = ShaderGenerator.DefaultSchemeName;
            }

            //Create the shader based tedchnique
            techniqueCreated = shaderGenerator.CreateShaderBasedTechnique(material.Name, material.Group,
                                                                          technique.SchemeName, dstTechniqueSchemeName,
                                                                          shaderGenerator.
                                                                          CreateShaderOverProgrammablePass);

            if (techniqueCreated)
            {
                //Go over all render state properties
                for (int i = 0; i < obj.Children.Count; i++)
                {
                    if (obj.Children[i] is PropertyAbstractNode)
                    {
                        var            prop = obj.Children[i] as PropertyAbstractNode;
                        SubRenderState subRenderState;

                        //Handle light count property.
                        if (prop != null && prop.Name == "light_count")
                        {
                            if (prop.Values.Count != 3)
                            {
                                //compiler.AddError(...);
                            }
                            else
                            {
                                var lightCount = new int[3];
                                if (!getInts(prop.Values, 0, out lightCount, 3))
                                {
                                    //compiler.addError(...);
                                }
                                else
                                {
                                    shaderGenerator.CreateScheme(dstTechniqueSchemeName);
                                    RenderState renderState = shaderGenerator.GetRenderState(dstTechniqueSchemeName,
                                                                                             material.Name,
                                                                                             material.Group,
                                                                                             (ushort)pass.Index);
                                    renderState.SetLightCount(lightCount);
                                    renderState.LightCountAutoUpdate = false;
                                }
                            }
                        }
                        else
                        {
                            subRenderState = ShaderGenerator.Instance.createSubRenderState(compiler, prop, pass, this);
                            if (subRenderState != null)
                            {
                                AddSubRenderState(subRenderState, dstTechniqueSchemeName, material.Name, material.Group,
                                                  pass.Index);
                            }
                        }
                    }
                    else
                    {
                        processNode(compiler, obj.Children[i]);
                    }
                }
            }
        }
Esempio n. 8
0
        public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler,
                                                      Scripting.Compiler.AST.PropertyAbstractNode prop, Pass pass,
                                                      SGScriptTranslator stranslator)
        {
            if (prop.Name == "rtss_ext_reflection_map")
            {
                if (prop.Values.Count >= 2)
                {
                    string strValue;
                    int    it = 0;

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

                    SubRenderState subRenderState = CreateInstance();
                    var            reflectionMapSubRenderState = subRenderState as ReflectionMap;

                    //Reflection map is cubic texture.
                    if (strValue == "cube_map")
                    {
                        reflectionMapSubRenderState.ReflectionMapType = TextureType.CubeMap;
                    }
                    else if (strValue == "2d_map")
                    {
                        reflectionMapSubRenderState.ReflectionMapType = TextureType.TwoD;
                    }

                    if (!SGScriptTranslator.GetString(prop.Values[it], out strValue))
                    {
                        //compiler.AddError(...)
                        return(null);
                    }
                    reflectionMapSubRenderState.MaskMapTextureName = strValue;
                    it++;

                    //read reflection texture
                    if (!SGScriptTranslator.GetString(prop.Values[it], out strValue))
                    {
                        //compiler.AddError(...);
                        return(null);
                    }
                    reflectionMapSubRenderState.ReflectionMapTextureName = strValue;
                    it++;

                    //Read reflection power value
                    Real reflectionPower = 0.5;
                    if (!SGScriptTranslator.GetReal(prop.Values[it], out reflectionPower))
                    {
                        //compiler.AddError(...)
                        return(null);
                    }
                    reflectionMapSubRenderState.ReflectionPower = reflectionPower;

                    return(subRenderState);
                }
            }

            return(null);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler,
                                                      Scripting.Compiler.AST.PropertyAbstractNode prop,
                                                      Graphics.TextureUnitState texState, ScriptTranslator translator)
        {
            if (prop.Name == "layered_blend")
            {
                string blendType;
                if (!SGScriptTranslator.GetString(prop.Values[0], out blendType))
                {
                    // compiler.AddError(...);
                    return(null);
                }

                LayeredBlending.BlendMode blendMode = StringToBlendMode(blendType);
                if (blendMode == LayeredBlending.BlendMode.Invalid)
                {
                    //  compiler.AddError(...);
                    return(null);
                }

                //get the layer blend sub-render state to work on
                var layeredBlendState = (LayeredBlending)CreateOrRetrieveInstance(translator);

                int texIndex = -1;
                //TODO: check impl. Ogre use: texIndex = texState.Parent.GetTextureUnitStateIndex(texState);
                for (int i = 0; i < texState.Parent.TextureUnitStatesCount; i++)
                {
                    if (texState.Parent.GetTextureUnitState(i) == texState)
                    {
                        texIndex = i;
                        break;
                    }
                }
                layeredBlendState.SetBlendMode(texIndex, blendMode);

                return(layeredBlendState);
            }
            if (prop.Name == "source_modifier")
            {
                if (prop.Values.Count < 3)
                {
                    //compiler.AddError(..);
                    return(null);
                }

                //Read light model type
                bool   isParseSuccess;
                string modifierString;
                string paramType;
                int    customNum;

                int itValue = 0;
                isParseSuccess = SGScriptTranslator.GetString(prop.Values[itValue], out modifierString);
                LayeredBlending.SourceModifier modType = StringToSourceModifier(modifierString);
                isParseSuccess &= modType != LayeredBlending.SourceModifier.Invalid;
                if (isParseSuccess == false)
                {
                    //compiler.AddError(...);
                    return(null);
                }
                itValue++;
                isParseSuccess  = SGScriptTranslator.GetString(prop.Values[itValue], out paramType);
                isParseSuccess &= (paramType == "custom");
                if (isParseSuccess == false)
                {
                    // compiler.AddError(...);

                    return(null);
                }

                itValue++;
                isParseSuccess = SGScriptTranslator.GetString(prop.Values[itValue], out paramType);
                if (isParseSuccess == false)
                {
                    //compiler.AddError(...);
                    return(null);
                }
                itValue++;
                isParseSuccess = SGScriptTranslator.GetInt(prop.Values[itValue], out customNum);
                if (isParseSuccess == false)
                {
                    //compiler.AddError(...);
                    return(null);
                }

                //get the layer blend sub render state to work on
                var layeredBlendState = (LayeredBlending)CreateOrRetrieveInstance(translator);

                int texIndex = 0;
                //update the layer sub render state
                for (int i = 0; i < texState.Parent.TextureUnitStatesCount; i++)
                {
                    if (texState.Parent.GetTextureUnitState(i) == texState)
                    {
                        texIndex = i;
                        break;
                    }
                }
                layeredBlendState.SetSourceModifier(texIndex, modType, customNum);

                return(layeredBlendState);
            }
            return(null);
        }
Esempio n. 11
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);
        }