Пример #1
0
        public override void Load(IResourceCache cache, ResourcePath path)
        {
            using (var stream = cache.ContentFileRead(path))
                using (var reader = new StreamReader(stream, EncodingHelpers.UTF8))
                {
                    ParsedShader = ShaderParser.Parse(reader);
                }

            switch (GameController.Mode)
            {
            case GameController.DisplayMode.Headless:
                return;

            case GameController.DisplayMode.Godot:
                GodotShader = new Godot.Shader
                {
                    Code = _getGodotCode(),
                };
                break;

            case GameController.DisplayMode.Clyde:
                ClydeHandle = IoCManager.Resolve <IClyde>().LoadShader(ParsedShader);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (GameController.OnGodot)
            {
                GodotShader = new Godot.Shader
                {
                    Code = _getGodotCode(),
                };
            }
            else
            {
                var clyde = IoCManager.Resolve <IClyde>();
                // TODO: vertex shaders.
                ClydeHandle = clyde.LoadShader(ParsedShader, path.ToString());
            }
        }
Пример #2
0
        public override ShaderContent Import(string filename, ContentImporterContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentException("Filename cannot be null or empty.", "filename");
            }
            FileInfo info = new FileInfo(filename);

            if (!info.Exists)
            {
                throw new FileNotFoundException("File not found", filename);
            }

            ContentIdentity identity = new ContentIdentity(info.FullName, ImporterName);

            string text = File.ReadAllText(filename);

            Lexer lexer = new Lexer(filename, text);

            lexer.Error += (sender, e) => ThrowParserException(e, info);
            Token[] tokens = lexer.GetTokens();

            ShaderParser parser = new ShaderParser(filename, tokens);

            parser.Error += (sender, e) => ThrowParserException(e, info);

            ShaderNode    shaderNode = parser.Parse();
            ShaderContent content    = new ShaderContent
            {
                ShaderNode = shaderNode
            };

            content.Identity = identity;
            return(content);
        }
Пример #3
0
        public void CanParseShader()
        {
            // Arrange.
            const string path   = "Resources/Shaders/Flat-Diffuse.shader";
            var          tokens = new Lexer(path, File.ReadAllText(path)).GetTokens();
            var          parser = new ShaderParser(path, tokens);

            parser.Error += (sender, args) =>
            {
                throw new Exception(args.Message + Environment.NewLine + args.Position);
            };

            // Act.
            var shaderNode = parser.Parse();

            // Assert.
            Assert.That(shaderNode, Is.Not.Null);
            Assert.That(shaderNode.Name, Is.EqualTo("Flat"));
            Assert.That(shaderNode.Properties, Has.Count.EqualTo(2));
            Assert.That(shaderNode.Technique, Is.Not.Null);
            Assert.That(shaderNode.Technique.State, Is.Not.Null);
            Assert.That(shaderNode.Technique.State.CullMode, Is.EqualTo(CullMode.CullClockwiseFace));
            Assert.That(shaderNode.Technique.State.FillMode, Is.Null);
            Assert.That(shaderNode.Technique.State.DepthBias, Is.EqualTo(0.001f));
            Assert.That(shaderNode.Technique.State.SlopeScaleDepthBias, Is.EqualTo(0.001f));
            Assert.That(shaderNode.Technique.State.DepthBufferFunction, Is.EqualTo(CompareFunction.LessEqual));
            Assert.That(shaderNode.Technique.State.DepthBufferWriteEnable, Is.True);
            Assert.That(shaderNode.Technique.State.DepthBufferEnable, Is.False);
            Assert.That(shaderNode.Technique.State.AlphaBlendFunction, Is.EqualTo(BlendFunction.Add));
            Assert.That(shaderNode.Technique.State.AlphaDestinationBlend, Is.EqualTo(Blend.One));
            Assert.That(shaderNode.Technique.State.AlphaSourceBlend, Is.EqualTo(Blend.Zero));
            Assert.That(shaderNode.Technique.State.ColorBlendFunction, Is.EqualTo(BlendFunction.Min));
            Assert.That(shaderNode.Technique.State.ColorDestinationBlend, Is.EqualTo(Blend.SourceAlpha));
            Assert.That(shaderNode.Technique.State.ColorSourceBlend, Is.EqualTo(Blend.SourceColor));
            Assert.That(shaderNode.Technique.Surface, Is.Not.Null);
            Assert.That(shaderNode.Technique.Surface.LightingModel, Is.EqualTo("FlatShading"));
        }
Пример #4
0
 /// <summary>
 /// Parses the specified source code.
 /// </summary>
 /// <param name="sourceCode">The source code.</param>
 /// <param name="sourceFileName">Name of the source file.</param>
 /// <returns></returns>
 public static Shader Parse(string sourceCode, string sourceFileName)
 {
     return(PrepareShader(ShaderParser.GetParser <XenkoGrammar>().ParseAndCheck(sourceCode, sourceFileName)));
 }
Пример #5
0
 /// <summary>
 /// Preprocesses and parses the specified source.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="sourceFileName">Name of the source file.</param>
 /// <param name="macros">The macros defined for the preprocessor.</param>
 /// <param name="includeDirectories">The include directories used by the preprocessor..</param>
 /// <returns>Result of parsing</returns>
 public static Shader PreProcessAndParse(string source, string sourceFileName, SiliconStudio.Shaders.Parser.ShaderMacro[] macros = null, params string[] includeDirectories)
 {
     return(PrepareShader(ShaderParser.GetParser <XenkoGrammar>().PreProcessAndParse(source, sourceFileName, macros, includeDirectories)));
 }
Пример #6
0
 /// <summary>
 /// Preinitialize the parser.
 /// </summary>
 public static void Initialize()
 {
     ShaderParser.GetParser <XenkoGrammar>();
 }
Пример #7
0
 /// <summary>
 /// Preinitialize the parser.
 /// </summary>
 public static void Initialize()
 {
     ShaderParser.GetParser <StrideGrammar>();
 }
Пример #8
0
 public HlslTranslator(ShaderParser parser)
     : base(parser)
 {
 }
Пример #9
0
        private void Init()
        {
            var mapParser = new MapParser(this.MapPath);
            var map       = mapParser.Parse();

            this.Sounds.AddRange(map.Sounds);
            this.Models.AddRange(map.Models);

            var allShaders = ShaderParser.ReadShaders(Path.Combine(this.ETMain, "scripts")).ToList();

            var(usedTextures, usedShaderFiles) = ShaderParser.GetRequiredFiles(map, allShaders);

            this.Shaders.AddRange(usedShaderFiles);
            this.Textures.AddRange(usedTextures);

            if (MapscriptParser.HasScript(map))
            {
                var msParser  = new MapscriptParser(map);
                var mapscript = msParser.Parse();
                this.Sounds.AddRange(mapscript.Sounds);
                this.Textures.AddRange(mapscript.Remaps);
                this.MiscFiles.Add(mapscript.FullPath);
            }
            else
            {
                Log.Info($"Mapscript not found '{MapscriptParser.GetScriptPath(map.FullPath)}'");
            }

            if (SpeakerscriptParser.HasSpeakerscript(map))
            {
                var spsParser     = new SpeakerscriptParser(map);
                var speakerscript = spsParser.Parse();
                this.Sounds.AddRange(speakerscript.Sounds);
                this.MiscFiles.Add(speakerscript.FullPath);
            }
            else
            {
                Log.Info($"Speaker script not found" +
                         $" '{SpeakerscriptParser.GetScriptPath(map.FullPath)}'");
            }

            if (SoundscriptParser.HasSoundscript(map))
            {
                var ssparser    = new SoundscriptParser(map);
                var soundscript = ssparser.Parse();
                this.Sounds.AddRange(soundscript.Sounds);
                this.MiscFiles.Add(soundscript.FullPath);
            }
            else
            {
                Log.Info($"Soundscript not found" +
                         $" '{SoundscriptParser.GetScriptPath(map.FullPath)}'");
            }

            // Add lightmaps
            if (Directory.Exists(this.LightmapFolder))
            {
                var lightmaps = Directory.GetFiles(this.LightmapFolder, "lm_????.tga");

                if (!lightmaps.Any())
                {
                    Log.Warn($"Lightmap folder found but " +
                             $"contains no lightmaps ('{this.LightmapFolder}')");
                }

                this.MiscFiles.AddRange(lightmaps);
            }
            else
            {
                Log.Info($"Lightmap folder not found '{this.LightmapFolder}'");
            }

            // Add levelshots, .arena, .objdata, and tracemap
            this.GetMiscFiles();
        }
Пример #10
0
 public Hlsl_4_0_level_9_1_Translator(ShaderParser parser)
     : base(parser)
 {
 }
Пример #11
0
 /// <summary>
 /// Parses the specified source.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="sourceFileName">Name of the source file.</param>
 /// <param name="macros">The macros defined for the preprocessor.</param>
 /// <param name="includeDirectories">The include directories used by the preprocessor..</param>
 /// <returns>Result of parsing</returns>
 public static Shader Parse(string source, string sourceFileName, ShaderMacro[] macros = null, params string[] includeDirectories)
 {
     return(ShaderParser.GetParser <HlslGrammar>().PreProcessAndParse(source, sourceFileName, macros, includeDirectories));
 }
Пример #12
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 public static void Initialize()
 {
     // Call get parser to force an initialization
     ShaderParser.GetParser <HlslGrammar>();
 }
Пример #13
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 static HlslParser()
 {
     // Call get parser to force an initialization
     ShaderParser.GetParser <HlslGrammar>();
 }
Пример #14
0
        public void Execute()
        {
            var shaders = ShaderParser.ReadShaders(this.Path);

            ShaderParser.FindDuplicates(shaders);
        }
Пример #15
0
 /// <summary>
 /// Preinitialize the parser.
 /// </summary>
 public static void Initialize()
 {
     ShaderParser.GetParser <ParadoxGrammar>();
 }