Example #1
0
        private static void LoadShaderFiles(Shader shader, string[] shaderRelativePaths)
        {
            var shaders = new List <Tuple <string, ShaderType, string> >();

            foreach (string file in shaderRelativePaths)
            {
                // The input paths are relative to the main shader directory.
                string shaderPath = shaderSourceDirectory + "\\" + file;
                if (!File.Exists(shaderPath))
                {
                    continue;
                }

                // Read the shader file.
                string shaderName   = Path.GetFileNameWithoutExtension(shaderPath);
                string shaderSource = File.ReadAllText(shaderPath);

                // Determine the shader type based on the file extension.
                ShaderType shaderType = ShaderType.FragmentShader;
                if (file.EndsWith(".vert"))
                {
                    shaderType = ShaderType.VertexShader;
                }
                else if (file.EndsWith(".frag"))
                {
                    shaderType = ShaderType.FragmentShader;
                }
                else if (file.EndsWith(".geom"))
                {
                    shaderType = ShaderType.GeometryShader;
                }

                shaders.Add(new Tuple <string, ShaderType, string>(shaderSource, shaderType, shaderName));
            }
            shader.LoadShaders(shaders);
        }