public static ShaderCompilerOptions DefaultCompileOptions( IEnumerable<string> defines, string entry, DirectoryInfo sourceDir, BuildTarget buildTarget, string shaderModel = null ) { var includes = new HashSet<string> { sourceDir.FullName }; var compileOptions = new ShaderCompilerOptions { includeFolders = includes, defines = new HashSet<string>(), entry = entry }; compileOptions.defines.UnionWith(defines); if (!string.IsNullOrEmpty(shaderModel)) compileOptions.defines.Add($"SHADER_TARGET={shaderModel}"); // Add default unity includes var path = Path.Combine(EditorApplication.applicationContentsPath, "CGIncludes"); if (Directory.Exists(path)) compileOptions.includeFolders.Add(path); // Add package symlinks folder // So shader compiler will find include files with "Package/<package_id>/..." compileOptions.includeFolders.Add(Path.Combine(Application.dataPath, $"../{PackagesUtilities.PackageSymbolicLinkFolder}")); return compileOptions; }
/// <summary>Start a compile operation.</summary> /// <param name="sourceFile">Path of the file to compile.</param> /// <param name="genDir">Path to the generated directory.</param> /// <param name="targetFile">Path to the generated binary.</param> /// <param name="options">Options to use during compilation.</param> /// <param name="profile">Profile to compile.</param> /// <param name="shaderTarget">Target to compile.</param> /// <returns>The compile operation.</returns> public virtual CompileOperation Compile( FileInfo sourceFile, DirectoryInfo genDir, FileInfo targetFile, ShaderCompilerOptions options, ShaderProfile profile, ShaderTarget shaderTarget ) => new CompileOperation( new ProcessStartInfo(), sourceFile, sourceFile, targetFile, options );
/// <summary>Create a new compile operation.</summary> /// <param name="startInfo"> /// Specific info to provide to the process generated. /// /// Some properties will be override to enable redirection of input and output streams. /// </param> /// <param name="sourceFile">Path of the source file to compile.</param> /// <param name="intermediateSourceFile">Path of the intermediate file to use.</param> /// <param name="targetFile">Path to the generated file.</param> /// <param name="options">Options to use for compilation.</param> public CompileOperation( ProcessStartInfo startInfo, FileInfo sourceFile, FileInfo intermediateSourceFile, FileInfo targetFile, ShaderCompilerOptions options ) { startInfo.RedirectStandardInput = false; startInfo.RedirectStandardError = true; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; commandLine = $"{startInfo.FileName} {startInfo.Arguments}"; m_Process = ProcessManager.Enqueue(startInfo, PreStart, PostStart); this.sourceFile = sourceFile; this.targetFile = targetFile; this.options = options; this.intermediateSourceFile = intermediateSourceFile; }