当前位置: 首页>>代码示例>>C#>>正文


C# ShaderMacro类代码示例

本文整理汇总了C#中ShaderMacro的典型用法代码示例。如果您正苦于以下问题:C# ShaderMacro类的具体用法?C# ShaderMacro怎么用?C# ShaderMacro使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ShaderMacro类属于命名空间,在下文中一共展示了ShaderMacro类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileFromFileAsync

        public static async Task<ShaderBytecode> CompileFromFileAsync(string hlslFile, string entryPoint, string profile, ShaderMacro[] defines = null)
        {
            if (!Path.IsPathRooted(hlslFile))
                hlslFile = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, hlslFile);

            CompilationResult result = null;
            
            await Task.Run(() =>
            {
                var shaderSource = SharpDX.IO.NativeFile.ReadAllText(hlslFile);

                // Compile the shader file
                ShaderFlags flags = ShaderFlags.None;
#if DEBUG
                flags |= ShaderFlags.Debug | ShaderFlags.SkipOptimization;
#endif
                var includeHandler = new HLSLFileIncludeHandler(Path.GetDirectoryName(hlslFile));
                result = ShaderBytecode.Compile(shaderSource, entryPoint, profile, flags, EffectFlags.None, defines, includeHandler, Path.GetFileName(hlslFile));

                if (!String.IsNullOrEmpty(result.Message))
                    throw new CompilationException(result.ResultCode, result.Message);
            });

            return result;
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:25,代码来源:HLSLCompiler.cs

示例2: VertexShader

 public static SharpDX.Direct3D11.VertexShader VertexShader(SharpDX.Direct3D11.Device device, string hlslFile, string entryPoint, ShaderMacro[] defines = null, string profile = "vs_5_0")
 {
     using (var bytecode = CompileFromFile(hlslFile, entryPoint, profile, defines))
     {
         return new SharpDX.Direct3D11.VertexShader(device, bytecode);
     }
 }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:7,代码来源:HLSLCompiler.cs

示例3: Init

        internal static void Init()
        {
            m_vs = MyShaders.CreateVs("decal.hlsl");
            var normalMapMacro = new ShaderMacro("USE_NORMALMAP_DECAL", null);
            var colorMapMacro = new ShaderMacro("USE_COLORMAP_DECAL", null);
            m_psColorMap = MyShaders.CreatePs("decal.hlsl", new ShaderMacro[] { colorMapMacro, new ShaderMacro("USE_DUAL_SOURCE_BLENDING", null) });
            m_psNormalMap = MyShaders.CreatePs("decal.hlsl", new ShaderMacro[] { normalMapMacro });
            m_psNormalColorMap = MyShaders.CreatePs("decal.hlsl", new ShaderMacro[] { normalMapMacro, colorMapMacro });

            InitIB();
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:11,代码来源:MyScreenDecals.cs

示例4: InitShaders

        private static int InitShaders(MyBlurDensityFunctionType densityFunctionType, int maxOffset, float depthDiscardThreshold)
        {
            bool useDepthDiscard = depthDiscardThreshold > 0;
            int shaderKey = GetShaderKey(densityFunctionType, maxOffset, useDepthDiscard);

            if(!m_blurShaders.ContainsKey(shaderKey))
            {
                ShaderMacro depthMacro = new ShaderMacro(useDepthDiscard ? "DEPTH_DISCARD_THRESHOLD" : "", useDepthDiscard ? depthDiscardThreshold : 1);

                var macrosHorizontal = new[] { new ShaderMacro("HORIZONTAL_PASS", null), new ShaderMacro("MAX_OFFSET", maxOffset), new ShaderMacro("DENSITY_FUNCTION", (int)densityFunctionType), depthMacro };
                var macrosVertical = new[] { new ShaderMacro("VERTICAL_PASS", null), new ShaderMacro("MAX_OFFSET", maxOffset), new ShaderMacro("DENSITY_FUNCTION", (int)densityFunctionType), depthMacro };
                var shaderPair = MyTuple.Create(MyShaders.CreatePs("Postprocess/Blur.hlsl", macrosHorizontal), MyShaders.CreatePs("Postprocess/Blur.hlsl", macrosVertical));
                m_blurShaders.Add(shaderKey, shaderPair);
            }
            return shaderKey;
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:16,代码来源:MyBlur.cs

示例5: CompileFromFile

        /// <summary>
        /// Compile the HLSL file using the provided <paramref name="entryPoint"/>, shader <paramref name="profile"/> and optionally conditional <paramref name="defines"/>
        /// </summary>
        /// <param name="hlslFile">Absolute path to HLSL file, or path relative to application installation location</param>
        /// <param name="entryPoint">Shader function name e.g. VSMain</param>
        /// <param name="profile">Shader profile, e.g. vs_5_0</param>
        /// <param name="defines">An optional list of conditional defines.</param>
        /// <returns>The compiled ShaderBytecode</returns>
        /// <exception cref="CompilationException">Thrown if the compilation failed</exception>
        public static ShaderBytecode CompileFromFile(string hlslFile, string entryPoint, string profile, ShaderMacro[] defines = null)
        {
            if (!Path.IsPathRooted(hlslFile))
                hlslFile = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), hlslFile);
            var shaderSource = SharpDX.IO.NativeFile.ReadAllText(hlslFile);
            CompilationResult result = null;

            // Compile the shader file
            ShaderFlags flags = ShaderFlags.None;
            #if DEBUG
            flags |= ShaderFlags.Debug | ShaderFlags.SkipOptimization;
            #endif
            var includeHandler = new HLSLFileIncludeHandler(Path.GetDirectoryName(hlslFile));
            result = ShaderBytecode.Compile(shaderSource, entryPoint, profile, flags, EffectFlags.None, defines, includeHandler, Path.GetFileName(hlslFile));

            if (result.ResultCode.Failure)
                throw new CompilationException(result.ResultCode, result.Message);

            return result;
        }
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:29,代码来源:HLSLCompiler.cs

示例6: Compile

 /// <summary>
 /// Compiles the provided shader or effect source.
 /// </summary>
 /// <param name="shaderSource">A string containing the source of the shader or effect to compile.</param>
 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
 /// <param name="profile">The shader target or set of shader features to compile against.</param>
 /// <param name="shaderFlags">Shader compilation options.</param>
 /// <param name="effectFlags">Effect compilation options.</param>
 /// <param name="defines">A set of macros to define during compilation.</param>
 /// <param name="include">An interface for handling include files.</param>
 /// <param name="sourceFileName">Name of the source file.</param>
 /// <param name="secondaryDataFlags">The secondary data flags.</param>
 /// <param name="secondaryData">The secondary data.</param>
 /// <returns>
 /// The compiled shader bytecode, or <c>null</c> if the method fails.
 /// </returns>
 public static CompilationResult Compile(string shaderSource, string entryPoint, string profile,
                                      ShaderFlags shaderFlags, EffectFlags effectFlags, ShaderMacro[] defines,
                                      Include include, string sourceFileName = "unknown", SecondaryDataFlags secondaryDataFlags = SecondaryDataFlags.None, DataStream secondaryData = null)
 {
     if (string.IsNullOrEmpty(shaderSource))
     {
         throw new ArgumentNullException("shaderSource");
     }
     var shaderSourcePtr = Marshal.StringToHGlobalAnsi(shaderSource);
     try
     {
         return Compile(shaderSourcePtr, shaderSource.Length, entryPoint, profile, shaderFlags, effectFlags, defines,
                        include, sourceFileName, secondaryDataFlags, secondaryData);
     }
     finally
     {
         if (shaderSourcePtr != IntPtr.Zero) Marshal.FreeHGlobal(shaderSourcePtr);
     }
 }
开发者ID:pH200,项目名称:SharpDX,代码行数:35,代码来源:ShaderBytecode.cs

示例7: CreatePs

        public static PixelShaderId CreatePs(string file, ShaderMacro[] macros = null)
        {
            var bytecode = CreateBytecode();

            var id = new PixelShaderId { Index = PixelShaders.Allocate() };
            PixelShaders.Data[id.Index] = new MyShaderInfo
            {
                Bytecode = bytecode
            };
            MyArrayHelpers.Reserve(ref PsObjects, id.Index + 1);

            // compile at once

            Shaders[bytecode] = new MyShaderCompilationInfo
            {
                File = X.TEXT_(file),
                Profile = MyShadersDefines.Profiles.ps_5_0,
                Macros = macros
            };

            PsObjects[id.Index] = null;

            InitPs(id, file);
            PsIndex.Add(id);

            return id;
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:27,代码来源:MyShaders.cs

示例8: Preprocess

 /// <summary>
 ///   Preprocesses the provided shader or effect source.
 /// </summary>
 /// <param name = "shaderSource">An array of bytes containing the raw source of the shader or effect to preprocess.</param>
 /// <param name = "defines">A set of macros to define during preprocessing.</param>
 /// <param name = "include">An interface for handling include files.</param>
 /// <returns>The preprocessed shader source.</returns>
 public static string Preprocess(byte[] shaderSource, ShaderMacro[] defines = null, Include include = null, string sourceFileName = "")
 {
     string errors = null;
     return Preprocess(shaderSource, defines, include, out errors, sourceFileName);
 }
开发者ID:pH200,项目名称:SharpDX,代码行数:12,代码来源:ShaderBytecode.cs

示例9: CompileFromFile

 /// <summary>
 ///   Compiles a shader or effect from a file on disk.
 /// </summary>
 /// <param name = "fileName">The name of the source file to compile.</param>
 /// <param name = "profile">The shader target or set of shader features to compile against.</param>
 /// <param name = "shaderFlags">Shader compilation options.</param>
 /// <param name = "effectFlags">Effect compilation options.</param>
 /// <param name = "defines">A set of macros to define during compilation.</param>
 /// <param name = "include">An interface for handling include files.</param>
 /// <param name = "compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if compilation succeeded.</param>
 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
 public static CompilationResult CompileFromFile(string fileName, string profile, ShaderFlags shaderFlags = ShaderFlags.None , EffectFlags effectFlags = EffectFlags.None, ShaderMacro[] defines = null, Include include = null)
 {
     return CompileFromFile(fileName, null, profile, shaderFlags, effectFlags, defines, include);
 }
开发者ID:pH200,项目名称:SharpDX,代码行数:15,代码来源:ShaderBytecode.cs

示例10: PreprocessShader

 private static string PreprocessShader(string source, ShaderMacro[] macros)
 {
     try
     {
         var includes = new MyIncludeProcessor(Path.Combine(MyFileSystem.ContentPath, MyShadersDefines.ShadersContentPath));
         return ShaderBytecode.Preprocess(source, macros, includes);
     }
     catch (CompilationException e)
     {
         return null;
     }
 }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:12,代码来源:MyShaders.cs

示例11: Compile

        internal static byte[] Compile(string source, ShaderMacro[] macros, MyShadersDefines.Profiles profile, string sourceDescriptor, bool optimize, bool invalidateCache, out bool wasCached, out string compileLog)
        {
            ProfilerShort.Begin("MyShaders.Compile");
            string function = MyShadersDefines.ProfileEntryPoint(profile);
            string profileName = MyShadersDefines.ProfileToString(profile);

            wasCached = false;
            compileLog = null;

            ProfilerShort.Begin("MyShaders.Preprocess");
            string preprocessedSource = PreprocessShader(source, macros);

            var key = MyShaderCache.CalculateKey(preprocessedSource, function, profileName);
            if (!invalidateCache)
            {
                var cached = MyShaderCache.TryFetch(key);
                if (cached != null)
                {
                    wasCached = true;
                    ProfilerShort.End();
                    ProfilerShort.End();
                    return cached;
                }
            }
            ProfilerShort.End();

            try
            {
                string descriptor = sourceDescriptor + " " + profile + " " + macros.GetString();
                CompilationResult compilationResult = ShaderBytecode.Compile(preprocessedSource, function, profileName, optimize ? ShaderFlags.OptimizationLevel3 : 0, 0, null, null, descriptor);

                if (DUMP_CODE)
                {
                    var disassembly = compilationResult.Bytecode.Disassemble(DisassemblyFlags.EnableColorCode |
                                                                             DisassemblyFlags.EnableInstructionNumbering);
                    string asmPath;
                    if (MyRender11.DebugMode)
                    {
                        asmPath = Path.GetFileName(descriptor + "__DEBUG.html");
                    }
                    else
                    {
                        asmPath = Path.GetFileName(descriptor + "__O3.html");
                    }

                    using (var writer = new StreamWriter(Path.Combine(MyFileSystem.ContentPath, "ShaderOutput", asmPath)))
                    {
                        writer.Write(disassembly);
                    }
                }

                if (compilationResult.Message != null)
                {
                    compileLog = ExtendedErrorMessage(source, compilationResult.Message) + DumpShaderSource(key, preprocessedSource);
                }

                if (compilationResult.Bytecode != null && compilationResult.Bytecode.Data.Length > 0)
                    MyShaderCache.Store(key.ToString(), compilationResult.Bytecode.Data);

                return compilationResult.Bytecode != null ? compilationResult.Bytecode.Data : null;
            }
            catch (CompilationException e)
            {
                Debug.WriteLine(preprocessedSource);
                compileLog = ExtendedErrorMessage(source, e.Message) + DumpShaderSource(key, preprocessedSource);
            }
            finally
            {
                ProfilerShort.End();
            }
            return null;
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:72,代码来源:MyShaders.cs

示例12: CreateGs

        internal static GeometryShaderId CreateGs(string file, ShaderMacro[] macros = null, MyShaderStreamOutputInfo? streamOut = null)
        {
            var bytecode = CreateBytecode();

            var id = new GeometryShaderId { Index = GeometryShaders.Allocate() };
            GeometryShaders.Data[id.Index] = new MyShaderInfo
            {
                Bytecode = bytecode
            };
            MyArrayHelpers.Reserve(ref GsObjects, id.Index + 1);

            // compile at once

            Shaders[bytecode] = new MyShaderCompilationInfo
            {
                File = X.TEXT_(file),
                Profile = MyShadersDefines.Profiles.gs_5_0,
                Macros = macros
            };

            GsObjects[id.Index] = null;

            if (streamOut.HasValue)
            {
                StreamOutputs[id] = streamOut.Value;
            }

            InitGs(id, file);
            GsIndex.Add(id);
            GsObjects[id.Index].DebugName = file;

            return id;
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:33,代码来源:MyShaders.cs

示例13: CreateCs

        internal static ComputeShaderId CreateCs(string file, ShaderMacro[] macros = null)
        {
            var bytecode = CreateBytecode();

            var id = new ComputeShaderId { Index = ComputeShaders.Allocate() };
            ComputeShaders.Data[id.Index] = new MyShaderInfo
            {
                Bytecode = bytecode
            };
            MyArrayHelpers.Reserve(ref CsObjects, id.Index + 1);

            // compile at once

            Shaders[bytecode] = new MyShaderCompilationInfo
            {
                File = X.TEXT_(file),
                Profile = MyShadersDefines.Profiles.cs_5_0,
                Macros = macros,
            };

            CsObjects[id.Index] = null;

            InitCs(id, file);
            CsIndex.Add(id);

            return id;
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:27,代码来源:MyShaders.cs

示例14: PreprocessFromFile

 /// <summary>
 ///   Preprocesses a shader or effect from a file on disk.
 /// </summary>
 /// <param name = "fileName">The name of the source file to compile.</param>
 /// <param name = "defines">A set of macros to define during preprocessing.</param>
 /// <param name = "include">An interface for handling include files.</param>
 /// <returns>The preprocessed shader source.</returns>
 public static string PreprocessFromFile(string fileName, ShaderMacro[] defines, Include include)
 {
     string errors = null;
     return PreprocessFromFile(fileName, defines, include, out errors);
 }
开发者ID:pH200,项目名称:SharpDX,代码行数:12,代码来源:ShaderBytecode.cs

示例15: CompileShaderFile

        private ITaskItem CompileShaderFile(string sourceFile, string outputFile, ShaderMacro[] defines)
        {
            try
            {
                var shaderFlags = GetShaderFlags();

                using (var shaderInclude = new ShaderInclude(IncludePath ?? string.Empty))
                using (var compilerResult = ShaderBytecode.CompileFromFile(sourceFile, EntryPoint ?? "main", Profile, include: shaderInclude, shaderFlags: shaderFlags, defines: defines))
                {
                    if (compilerResult.HasErrors)
                    {
                        int line;
                        int column;
                        string errorMessage;

                        GetCompileResult(compilerResult.Message, out line, out column, out errorMessage);

                        Log.LogError("Shader", compilerResult.ResultCode.ToString(), string.Empty, sourceFile, line, column, 0, 0, errorMessage);
                    }

                    var fileInfo = new FileInfo(outputFile);
                    if (fileInfo.Directory != null)
                    {
                        fileInfo.Directory.Create();
                    }

                    File.WriteAllBytes(outputFile, compilerResult.Bytecode.Data);
                    return new TaskItem(outputFile);
                }
            }
            catch (CompilationException ex)
            {
                int line;
                int column;
                string errorMessage;

                GetCompileResult(ex.Message, out line, out column, out errorMessage);

                Log.LogError("Shader", ex.ResultCode.ToString(), string.Empty, sourceFile, line, column, 0, 0, errorMessage);
                return null;
            }
            catch (Exception ex)
            {
                Log.LogError("Shader",
                             ex.HResult.ToString(CultureInfo.InvariantCulture),
                             string.Empty,
                             sourceFile,
                             0,
                             0,
                             0,
                             0,
                             string.Format("Critical failure ({0}:) {1}", ex.GetType(), ex.Message));
                return null;
            }
        }
开发者ID:Bloyteg,项目名称:ShaderCompiler,代码行数:55,代码来源:Shader.cs


注:本文中的ShaderMacro类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。