Exemple #1
0
        private static void LoadShaderFiles(Shader shader, string[] shaderRelativePaths)
        {
            foreach (string file in shaderRelativePaths)
            {
                // The input paths are relative to the main shader directory.
                string shaderPath = shaderMainDir + "\\" + 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.
                if (file.EndsWith(".vert"))
                {
                    shader.LoadShader(shaderSource, ShaderType.VertexShader, shaderName);
                }
                else if (file.EndsWith(".frag"))
                {
                    shader.LoadShader(shaderSource, ShaderType.FragmentShader, shaderName);
                }
                else if (file.EndsWith(".geom"))
                {
                    shader.LoadShader(shaderSource, ShaderType.GeometryShader, shaderName);
                }
            }
        }
Exemple #2
0
        private static void CreateShader(string shaderName, string shaderFolder, List <String> additionalShaderFiles = null)
        {
            // All shaders should be named shaderName.frag, shaderName.vert, etc.
            if (!Runtime.shaders.ContainsKey(shaderName))
            {
                Shader shader = new Shader();

                // Additional shaders for utility functions. These should be loaded first.
                // The order in which shaders are loaded is important.
                if (additionalShaderFiles != null)
                {
                    foreach (string file in additionalShaderFiles)
                    {
                        shader.LoadShader(MainForm.executableDir + "\\lib\\Shader\\" + file);
                    }
                }

                string shaderFileName = MainForm.executableDir + shaderFolder + "\\" + shaderName;

                // Required shaders. These files can be omitted and specified in the additionalShaderFiles list.
                if (File.Exists(shaderFileName + ".vert"))
                {
                    shader.LoadShader(shaderFileName + ".vert");
                }
                if (File.Exists(shaderFileName + ".frag"))
                {
                    shader.LoadShader(shaderFileName + ".frag");
                }

                // Geometry shaders are optional.
                if (File.Exists(shaderFileName + ".geom"))
                {
                    shader.LoadShader(shaderFileName + ".geom");
                }



                Runtime.shaders.Add(shaderName, shader);
            }
        }