public static Blob CompileFromFile(
        string fileName,
        ShaderMacro[] macros,
        Include include,
        string entryPoint,
        string profile,
        ShaderFlags shaderFlags = ShaderFlags.None,
        EffectFlags effectFlags = EffectFlags.None)
    {
        Result result = CompileFromFile(
            fileName,
            macros,
            include,
            entryPoint,
            profile,
            shaderFlags,
            effectFlags,
            out Blob blob,
            out Blob? errorBlob);

        if (result.Failure)
        {
            if (errorBlob != null)
            {
                throw new SharpGenException(result, errorBlob.AsString());
            }
            else
            {
                throw new SharpGenException(result);
            }
        }

        errorBlob?.Dispose();
        return(blob);
    }
Exemple #2
0
    public void Init()
    {
        if (DXEffect != null)
        {
            DXEffect.Dispose();
        }

        CompilationResult cr = null;

        EffectFlags EFFECT_FLAGS = EffectFlags.None;

#if DEBUG
        ShaderFlags SHADER_FLAGS = ShaderFlags.Debug;
#else
        ShaderFlags SHADER_FLAGS = ShaderFlags.OptimizationLevel3;
#endif
        try
        {
            _isValid = true;
            cr       = ShaderBytecode.CompileFromFile(ShaderFullFilename, "fx_5_0", SHADER_FLAGS, EFFECT_FLAGS, null, new IncludeFX(Program.DXConfig.ShadersIncludePath));
            DXEffect = new Effect(Program.Renderer.DXDevice, cr.Bytecode);
            cr.Bytecode.Dispose();
            Dirty = false;
        }
        catch (Exception e)
        {
            _isValid = false;
            string text = "Compilation failed for shader: " + ShaderFullFilename + "\n" + e.Message;
            if (MessageBox.Show(text, "Shader compiler", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
            {
                Init();
            }
        }
    }
        Tolerance GetTolerance(CFGData cfg, EffectFlags flags)
        {
            Tolerance result;

            if (HasResistance(cfg, flags))
            {
                result = Tolerance.Resistant;
            }
            else if (HasImmunity(cfg, flags))
            {
                result = Tolerance.Immune;
            }
            else if (HasLowTolerance(cfg, flags))
            {
                result = Tolerance.LowTolerance;
            }
            else if (HasCriticalWeakness(cfg, flags))
            {
                result = Tolerance.CriticalWeakness;
            }
            else
            {
                result = Tolerance.Normal;
            }

            return(result);
        }
Exemple #4
0
 public Effect(string name, Image image, string subMenuName, EffectFlags effectFlags)
 {
     this.name        = name;
     this.image       = image;
     this.subMenuName = subMenuName;
     this.effectFlags = effectFlags;
     this.envParams   = EffectEnvironmentParameters.DefaultParameters;
 }
Exemple #5
0
        /// <summary>
        /// Base constructor for the Effect class.
        /// </summary>
        /// <param name="name">A unique name for the effect.</param>
        /// <param name="image">A 16x16 icon for the effect that will show up in the menu.</param>
        /// <param name="subMenuName">The name of a sub-menu to place the effect into. Pass null for no sub-menu.</param>
        /// <param name="effectFlags">A set of flags indicating important information about the effect.</param>
        /// <remarks>
        /// Do not include the word 'effect' in the name parameter.
        /// The shortcut key is only honored for effects with the [EffectCategory(EffectCategory.Adjustment)] attribute.
        /// The sub-menu parameter can be used to group effects. The name parameter must still be unique.
        /// </remarks>

        public Effect(string name, Image image, string subMenuName, EffectFlags effectFlags)
        {
            Name                  = name;
            Image                 = image;
            SubMenuName           = subMenuName;
            EffectFlags           = effectFlags;
            EnvironmentParameters = EffectEnvironmentParameters.DefaultParameters;
        }
    public static Blob Compile(
        string shaderSource,
        string entryPoint,
        string sourceName,
        ShaderMacro[] macros,
        Include include,
        string profile,
        ShaderFlags shaderFlags = ShaderFlags.None,
        EffectFlags effectFlags = EffectFlags.None)
    {
        if (string.IsNullOrEmpty(shaderSource))
        {
            throw new ArgumentNullException(nameof(shaderSource));
        }

        IntPtr shaderSourcePtr = Marshal.StringToHGlobalAnsi(shaderSource);

        try
        {
            Result result = Compile(
                shaderSourcePtr,
                shaderSource.Length,
                sourceName,
                macros,
                include,
                entryPoint,
                profile,
                shaderFlags,
                effectFlags,
                out Blob blob,
                out Blob? errorBlob);

            if (result.Failure)
            {
                if (errorBlob != null)
                {
                    throw new SharpGenException(result, errorBlob.AsString());
                }
                else
                {
                    throw new SharpGenException(result);
                }
            }

            errorBlob?.Dispose();
            return(blob);
        }
        finally
        {
            if (shaderSourcePtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(shaderSourcePtr);
            }
        }
    }
        public ShaderBytecode LoadByteCodeFromFile(ShaderType shaderType, string fileName, string entryPoint = null, ShaderFlags shaderFlags = ShaderFlags.None, EffectFlags effectFlags = EffectFlags.None)
        {
            #if DEBUG
            shaderFlags |= ShaderFlags.Debug;
            #endif

            var profile = GetProfileFromDevice(shaderType);
            var compilationResult = ShaderBytecode.CompileFromFile(fileName, entryPoint, profile, shaderFlags, effectFlags, include: new IncludeFromDisk());

            return compilationResult.Bytecode;
        }
 public PixelShader10(Device device,
              string shaderSource,
              string entryPoint,
              ShaderVersion shaderVersion,
              ShaderFlags shaderFlags = ShaderFlags.None,
              EffectFlags effectFlags = EffectFlags.None) :
     base(shaderSource, entryPoint, shaderVersion, shaderFlags, effectFlags)
 {
     m_device = device;
     CreatePixelShader();
 }
 internal ControlPoint(double offset, double beatLength, TimeSignatures timeSignature, SampleSet sampleSet,
                       CustomSampleSet customSamples, int volume, bool timingChange, EffectFlags effectFlags)
 {
     this.Offset        = offset;
     this.BeatLength    = beatLength;
     this.TimeSignature = timeSignature;
     this.SampleSet     = sampleSet == SampleSet.None ? SampleSet.Soft : sampleSet;
     this.CustomSamples = customSamples;
     this.Volume        = volume;
     this.TimingChange  = timingChange;
     this.EffectFlags   = effectFlags;
 }
Exemple #10
0
 protected ShaderBase(string shaderSource,
                      string entryPoint,
                      ShaderVersion shaderVersion,
                      ShaderFlags shaderFlags = ShaderFlags.None,
                      EffectFlags effectFlags = EffectFlags.None)
 {
     m_shaderByteCode = ShaderBytecode.Compile(shaderSource,
                                               entryPoint,
                                               shaderVersion.ToShaderVersionString(),
                                               shaderFlags,
                                               effectFlags);
 }
Exemple #11
0
            public CompileParams(string filename, string fx, ShaderFlags shaderFlags, EffectFlags effectFlags, ShaderMacro[] shaderMacros, IncludeHandler includeHandler)
            {
                this.filename       = filename;
                this.fx             = fx;
                this.shaderFlags    = shaderFlags;
                this.effectFlags    = effectFlags;
                this.shaderMacros   = shaderMacros;
                this.includeHandler = includeHandler;
                this.cacheFilename  = "";

                cacheFilename = getBytecodeFilename();
            }
 public VertexShader10(Device device,
                      string embeddedSourceResourceName,
                      string entryPoint,
                      ShaderVersion shaderVersion,
                      ShaderFlags shaderFlags = ShaderFlags.None,
                      EffectFlags effectFlags = EffectFlags.None) :
     base(embeddedSourceResourceName,
          entryPoint,
          shaderVersion,
          shaderFlags,
          effectFlags)
 {
     m_device = device;
     CreatePixelShader();
 }
Exemple #13
0
        protected ShaderBase(string embeddedSourceResourceName,
                             Assembly resourceAssembly,
                             string entryPoint,
                             ShaderVersion shaderVersion,
                             ShaderFlags shaderFlags = ShaderFlags.None,
                             EffectFlags effectFlags = EffectFlags.None)
        {
            string shaderSource = GetResourceString(embeddedSourceResourceName, resourceAssembly);

            m_shaderByteCode = ShaderBytecode.Compile(shaderSource,
                                                      entryPoint,
                                                      shaderVersion.ToShaderVersionString(),
                                                      shaderFlags,
                                                      effectFlags);
        }
Exemple #14
0
        public static Result Compile(
            string shaderSource,
            ShaderMacro[] defines,
            Include include,
            string entryPoint,
            string sourceName,
            string profile,
            ShaderFlags shaderFlags,
            EffectFlags effectFlags,
            out Blob blob,
            out Blob errorBlob)
        {
            if (string.IsNullOrEmpty(shaderSource))
            {
                throw new ArgumentNullException(nameof(shaderSource));
            }

            var shaderSourcePtr = Marshal.StringToHGlobalAnsi(shaderSource);

            try
            {
                return(Compile(
                           shaderSourcePtr,
                           shaderSource.Length,
                           sourceName,
                           defines,
                           include,
                           entryPoint,
                           profile,
                           shaderFlags,
                           effectFlags,
                           out blob,
                           out errorBlob));
            }
            finally
            {
                if (shaderSourcePtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(shaderSourcePtr);
                }
            }
        }
        public static ShaderBytecode PrecompileOrLoad(string fileName, string entryPoint, string profile, ShaderFlags shaderFlags, EffectFlags effectFlags)
        {
            FileInfo sourceFile = new FileInfo(fileName);

            if (!sourceFile.Exists)
                throw new FileNotFoundException();

            FileInfo compiledFile = new FileInfo(@"Precompiled\" + Path.GetFileNameWithoutExtension(sourceFile.Name) + "_" + entryPoint + "_" + profile + ".bin");

            if (compiledFile.Exists && sourceFile.LastWriteTime > compiledFile.LastWriteTime)
            {
                compiledFile.Delete();
                compiledFile.Refresh();
            }

            ShaderBytecode shaderBytecode = null;

            if (compiledFile.Exists)
            {
                byte[] compiledBytes = File.ReadAllBytes(compiledFile.FullName);
                DataStream compiledDataStream = new DataStream(compiledBytes, true, false);

                shaderBytecode = new ShaderBytecode(compiledDataStream);
            }
            else
            {
                shaderBytecode = ShaderBytecode.CompileFromFile(fileName, entryPoint, profile, shaderFlags, effectFlags);

                byte[] compiledBytes = shaderBytecode.Data.ReadRange<byte>((int)shaderBytecode.Data.Length);

                Directory.CreateDirectory(Path.GetDirectoryName(compiledFile.FullName));
                File.WriteAllBytes(compiledFile.FullName, compiledBytes);
            }

            if (shaderBytecode == null)
                throw new D3DCompilerException();

            return shaderBytecode;
        }
Exemple #16
0
        public static Result Compile(
            byte[] shaderSource,
            ShaderMacro[] defines,
            Include include,
            string entryPoint,
            string sourceName,
            string profile,
            ShaderFlags shaderFlags,
            EffectFlags effectFlags,
            out Blob blob,
            out Blob errorBlob)
        {
            if (shaderSource == null || shaderSource.Length == 0)
            {
                throw new ArgumentNullException(nameof(shaderSource));
            }

            unsafe
            {
                fixed(void *pData = &shaderSource[0])
                {
                    return(Compile(
                               (IntPtr)pData,
                               shaderSource.Length,
                               sourceName,
                               defines,
                               include,
                               entryPoint,
                               profile,
                               shaderFlags,
                               effectFlags,
                               out blob,
                               out errorBlob));
                }
            }
        }
Exemple #17
0
 internal WarpEffectBase(string name, Image image, string submenuName, EffectFlags options)
     : base(name, image, submenuName, options)
 {
 }
Exemple #18
0
 /// <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);
 }
Exemple #19
0
        /// <summary>
        /// Compiles the provided shader or effect source.
        /// </summary>
        /// <param name="shaderSource">An array of bytes containing the raw 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 used for reporting errors. Default is "unknown"</param>
        /// <returns>
        /// The compiled shader bytecode, or <c>null</c> if the method fails.
        /// </returns>
        public static CompilationResult Compile(byte[] shaderSource, string entryPoint, string profile,
                                             ShaderFlags shaderFlags, EffectFlags effectFlags, ShaderMacro[] defines,
                                             Include include, string sourceFileName = "unknown")
        {
            unsafe
            {
                var resultCode = Result.Ok;

                Blob blobForCode = null;
                Blob blobForErrors = null;

#if !DIRECTX11_1
                if ((shaderFlags & Effect10) != 0)
                {
                    shaderFlags ^= Effect10;

                    fixed (void* pData = &shaderSource[0])
                        resultCode = D3D.CompileEffect10FromMemory(
                            (IntPtr)pData,
                            shaderSource.Length,
                            sourceFileName,
                            PrepareMacros(defines),
                            IncludeShadow.ToIntPtr(include),
                            shaderFlags,
                            effectFlags,
                            out blobForCode,
                            out blobForErrors);
                }
                else
#endif
                {
                    fixed (void* pData = &shaderSource[0])
                        resultCode = D3D.Compile(
                            (IntPtr)pData,
                            shaderSource.Length,
                            sourceFileName,
                            PrepareMacros(defines),
                            IncludeShadow.ToIntPtr(include),
                            entryPoint,
                            profile,
                            shaderFlags,
                            effectFlags,
                            out blobForCode,
                            out blobForErrors);
                }

                if (resultCode.Failure)
                {
                    if (blobForErrors != null)
                    {
                        if (Configuration.ThrowOnShaderCompileError) throw new CompilationException(resultCode, Utilities.BlobToString(blobForErrors));
                    }
                    else
                    {
                        throw new SharpDXException(resultCode);
                    }
                }

                return new CompilationResult(blobForCode != null ? new ShaderBytecode(blobForCode) : null, resultCode, Utilities.BlobToString(blobForErrors));
            }
        }
Exemple #20
0
 /// <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="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="sourceFileName">Name of the source file.</param>
 /// <returns>
 /// The compiled shader bytecode, or <c>null</c> if the method fails.
 /// </returns>
 public static CompilationResult Compile(string shaderSource, string profile, ShaderFlags shaderFlags,
                                      EffectFlags effectFlags, string sourceFileName = "unknown")
 {
     if (string.IsNullOrEmpty(shaderSource))
     {
         throw new ArgumentNullException("shaderSource");
     }
     return Compile(Encoding.ASCII.GetBytes(shaderSource), null, profile, shaderFlags, effectFlags, null, null,
                    sourceFileName);
 }
Exemple #21
0
 /// <summary>
 /// Compiles the provided shader or effect source.
 /// </summary>
 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect 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="sourceFileName">Name of the source file.</param>
 /// <returns>
 /// The compiled shader bytecode, or <c>null</c> if the method fails.
 /// </returns>
 public static CompilationResult Compile(byte[] shaderSource, string profile, ShaderFlags shaderFlags,
                                      EffectFlags effectFlags, ShaderMacro[] defines, Include include,
                                      string sourceFileName = "unknown")
 {
     return Compile(shaderSource, null, profile, shaderFlags, effectFlags, defines, include, sourceFileName);
 }
        Tolerance GetTolerance(CFGData cfg, EffectFlags flags)
        {
            Tolerance result;

            if (HasResistance(cfg, flags))
                result = Tolerance.Resistant;
            else if (HasImmunity(cfg, flags))
                result = Tolerance.Immune;
            else if (HasLowTolerance(cfg, flags))
                result = Tolerance.LowTolerance;
            else if (HasCriticalWeakness(cfg, flags))
                result = Tolerance.CriticalWeakness;
            else
                result = Tolerance.Normal;

            return result;
        }
Exemple #23
0
 /// <summary>
 /// Compiles the provided shader or effect source.
 /// </summary>
 /// <param name="shaderSource">An array of bytes containing the raw 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 used for reporting errors. Default is "unknown"</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(byte[] shaderSource, string entryPoint, string profile,
                                      ShaderFlags shaderFlags, EffectFlags effectFlags, ShaderMacro[] defines,
                                      Include include, string sourceFileName = "unknown", SecondaryDataFlags secondaryDataFlags = SecondaryDataFlags.None, DataStream secondaryData = null)
 {
     unsafe
     {
         fixed (void* pData = &shaderSource[0])
             return Compile(
                 (IntPtr)pData,
                 shaderSource.Length,
                 entryPoint,
                 profile,
                 shaderFlags,
                 effectFlags,
                 defines,
                 include,
                 sourceFileName,
                 secondaryDataFlags,
                 secondaryData);
     }
 }
Exemple #24
0
 internal WarpEffectBase(string name, Image image, string submenuName, EffectFlags options)
     : base(name, image, submenuName, options)
 {
 }
 /// <summary>
 /// Determines if class has critical weakness to effects.
 /// </summary>
 /// <param name="flags">EffectFlags to test.</param>
 /// <returns>True if critical weakness.</returns>
 bool HasCriticalWeakness(CFGData cfg, EffectFlags flags)
 {
     return(((cfg.CriticalWeaknessFlags & (byte)flags) == (byte)flags) ? true : false);
 }
 /// <summary>
 /// Determines if class is resistant to effects.
 /// </summary>
 /// <param name="flags">EffectFlags to test.</param>
 /// <returns>True if resistant.</returns>
 bool HasResistance(CFGData cfg, EffectFlags flags)
 {
     return ((cfg.ResistanceFlags & (byte)flags) == (byte)flags) ? true : false;
 }
Exemple #27
0
        internal static bool BuildDll(string scriptText, string scriptPath, string subMenuname, string menuName, string iconPath, string author, int majorVersion, int minorVersion, string supportURL, string windowTitle, bool isAdjustment, string description, string keyWords, EffectFlags effectFlags, EffectRenderingSchedule renderingSchedule, HelpType helpType, string helpText)
        {
            string FileName = Path.GetFileNameWithoutExtension(scriptPath);

            // Calculate output path
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string dllPath     = Path.Combine(desktopPath, FileName);

            dllPath = Path.ChangeExtension(dllPath, ".dll");
            string zipPath = Path.ChangeExtension(dllPath, ".zip");
            string batPath = Path.Combine(desktopPath, "Install_" + Regex.Replace(FileName, @"[^\w]", ""));

            batPath = Path.ChangeExtension(batPath, ".bat");

            // Remove non-alpha characters from namespace
            string NameSpace = Regex.Replace(FileName, @"[^\w]", "") + "Effect";

            // Generate code
            string SourceCode = ScriptWriter.FullSourceCode(scriptText, FileName, isAdjustment, subMenuname, menuName, iconPath, supportURL, effectFlags, renderingSchedule, author, majorVersion, minorVersion, description, keyWords, windowTitle, helpType, helpText);

            exceptionMsg = null;
            // Compile code
            try
            {
                string newCompilerOptions = defaultOptions;
                if (File.Exists(iconPath))
                {
                    // If an icon is specified and exists, add it to the build as an imbedded resource to the same namespace as the effect.
                    newCompilerOptions += " /res:\"" + iconPath + "\",\"" + NameSpace + "." + Path.GetFileName(iconPath) + "\" ";

                    // If an icon exists, see if a sample image exists
                    string samplepath = Path.ChangeExtension(iconPath, ".sample.png");
                    if (File.Exists(samplepath))
                    {
                        // If an image exists in the icon directory with a ".sample.png" extension, add it to the build as an imbedded resource.
                        newCompilerOptions += " /res:\"" + samplepath + "\",\"" + NameSpace + "." + Path.GetFileName(samplepath) + "\" ";
                    }
                }
                string HelpPath = Path.ChangeExtension(scriptPath, ".rtz");
                if (helpType == HelpType.RichText && File.Exists(HelpPath))
                {
                    // If an help file exists in the source directory with a ".rtz" extension, add it to the build as an imbedded resource.
                    newCompilerOptions += " /res:\"" + HelpPath + "\",\"" + NameSpace + "." + Path.GetFileName(HelpPath) + "\" ";
                }

                newCompilerOptions += " /debug- /target:library /out:\"" + dllPath + "\"";

                param.CompilerOptions = newCompilerOptions;
                result = cscp.CompileAssemblyFromSource(param, SourceCode);
                param.CompilerOptions = defaultOptions;

                lineOffset = (SourceCode.Substring(0, SourceCode.IndexOf("#region User Entered Code", StringComparison.Ordinal)) + "\r\n").CountLines();

                if (result.Errors.HasErrors)
                {
                    return(false);
                }

                // Create install bat file
                if (File.Exists(batPath))
                {
                    File.Delete(batPath);
                }
                if (File.Exists(zipPath))
                {
                    File.Delete(zipPath);
                }

                // Try this in Russian for outputting Russian characters to the install batch file:

                //System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("windows-1251");
                //var stream = new FileStream(installPath, FileMode.Create);
                //StreamWriter sw = new StreamWriter(stream, encoding);

                StreamWriter sw = new StreamWriter(batPath);

                sw.WriteLine("@echo off");
                sw.WriteLine(":: Get ADMIN Privs");
                sw.WriteLine("mkdir \"%windir%\\BatchGotAdmin\"");
                sw.WriteLine("if '%errorlevel%' == '0' (");
                sw.WriteLine("  rmdir \"%windir%\\BatchGotAdmin\" & goto gotAdmin");
                sw.WriteLine(") else ( goto UACPrompt )");
                sw.WriteLine("");
                sw.WriteLine(":UACPrompt");
                sw.WriteLine("    echo Set UAC = CreateObject^(\"Shell.Application\"^) > \"%temp%\\getadmin.vbs\"");
                sw.WriteLine("    echo UAC.ShellExecute %0, \"\", \"\", \"runas\", 1 >> \"%temp%\\getadmin.vbs\"");
                sw.WriteLine("    \"%temp%\\getadmin.vbs\"");
                sw.WriteLine("    exit /B");
                sw.WriteLine("");
                sw.WriteLine(":gotAdmin");
                sw.WriteLine("    if exist \"%temp%\\getadmin.vbs\" ( del \"%temp%\\getadmin.vbs\" )");
                sw.WriteLine("    pushd \"%CD%\"");
                sw.WriteLine("    CD /D \"%~dp0\"");
                sw.WriteLine("");
                sw.WriteLine(":: End Get ADMIN Privs");
                sw.WriteLine(":: Read registry to find Paint.NET install directory");
                sw.WriteLine("reg query HKLM\\SOFTWARE\\Paint.NET /v TARGETDIR 2>nul || (echo Sorry, I can't find Paint.NET! & goto store)");
                sw.WriteLine("set PDN_DIR=");
                sw.WriteLine("for /f \"tokens=2,*\" %%a in ('reg query HKLM\\SOFTWARE\\Paint.NET /v TARGETDIR ^| findstr TARGETDIR') do (");
                sw.WriteLine("  set PDN_DIR=%%b");
                sw.WriteLine(")");
                sw.WriteLine("if not defined PDN_DIR (echo Sorry, I can't find Paint.NET! & goto store)");
                sw.WriteLine(":: End read registry");
                sw.WriteLine(":: Now do install");
                sw.WriteLine("@echo off");
                sw.WriteLine("cls");
                sw.WriteLine("echo.");
                sw.WriteLine("echo Installing " + Path.GetFileName(dllPath) + " to %PDN_DIR%\\Effects\\");
                sw.WriteLine("echo.");
                sw.WriteLine("copy /y \"" + Path.GetFileName(dllPath) + "\" \"%PDN_DIR%\\Effects\\\"");
                sw.WriteLine("if '%errorlevel%' == '0' (");
                sw.WriteLine("goto success");
                sw.WriteLine(") else (");
                sw.WriteLine("goto fail");
                sw.WriteLine(")");
                sw.WriteLine(":store");
                sw.WriteLine("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" /v Personal 2>nul || (echo Sorry, I can't find Paint.NET! & goto fail)");
                sw.WriteLine("set PDN_DIR=");
                sw.WriteLine("for /f \"tokens=2,*\" %%a in ('reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" /v Personal ^| findstr Personal') do (");
                sw.WriteLine("  set PDN_DIR=%%b");
                sw.WriteLine(")");
                sw.WriteLine("if not defined PDN_DIR (echo Sorry, I can't find Paint.NET! & goto fail)");
                sw.WriteLine("@echo off");
                sw.WriteLine("cls");
                sw.WriteLine("setlocal enabledelayedexpansion");
                sw.WriteLine("set PDN_DIR=!PDN_DIR:%%USERPROFILE%%=%USERPROFILE%!");
                sw.WriteLine("setlocal disabledelayedexpansion");
                sw.WriteLine("echo.");
                sw.WriteLine("echo I could not find the standard installation of Paint.NET.");
                sw.WriteLine("echo I will install this effect in your Documents folder instead");
                sw.WriteLine("echo in case you are using the store version.");
                sw.WriteLine("echo.");
                sw.WriteLine("echo Installing " + Path.GetFileName(dllPath) + " to %PDN_DIR%\\paint.net App Files\\Effects\\");
                sw.WriteLine("echo.");
                sw.WriteLine("mkdir \"%PDN_DIR%\\paint.net App Files\\Effects\\\" 2>nul");
                sw.WriteLine("copy /y \"" + Path.GetFileName(dllPath) + "\" \"%PDN_DIR%\\paint.net App Files\\Effects\\\"");
                sw.WriteLine("if '%errorlevel%' == '0' (");
                sw.WriteLine("goto success");
                sw.WriteLine(") else (");
                sw.WriteLine("goto fail");
                sw.WriteLine(")");
                sw.WriteLine(":success");
                sw.WriteLine("echo.");

                sw.WriteLine(@"echo    _____ _    _  _____ _____ ______  _____ _____  _ ");
                sw.WriteLine(@"echo   / ____) !  ! !/  ___)  ___)  ____)/ ____) ____)! !");
                sw.WriteLine(@"echo  ( (___ ! !  ! !  /  /  /   ! (__  ( (___( (___  ! !");
                sw.WriteLine(@"echo   \___ \! !  ! ! (  (  (    !  __)  \___ \\___ \ ! !");
                sw.WriteLine(@"echo   ____) ) !__! !  \__\  \___! (____ ____) )___) )!_!");
                sw.WriteLine(@"echo  (_____/ \____/ \_____)_____)______)_____/_____/ (_)");
                //sw.WriteLine(@"echo  _  _  ___  _____  ____  _  _  _ ");
                //sw.WriteLine(@"echo ( \/ )/ __)(  _  )(  __)( \/ )/ \");
                //sw.WriteLine(@"echo  )  /( (__  )( )(  ) _)  )  ( \_/");
                //sw.WriteLine(@"echo (__/  \___)(_) (_)(____)(_/\_)(_)");

                sw.WriteLine("goto done");
                sw.WriteLine(":fail");
                sw.WriteLine("echo.");

                sw.WriteLine(@"echo  _____       _____ _      _ ");
                sw.WriteLine(@"echo !  ___)/\   (_   _) !    ! !");
                sw.WriteLine(@"echo ! (__ /  \    ! ! ! !    ! !");
                sw.WriteLine(@"echo !  __) /\ \   ! ! ! !    ! !");
                sw.WriteLine(@"echo ! ! / ____ \ _! !_! !___ !_!");
                sw.WriteLine(@"echo !_!/_/    \_\_____)_____)(_)");
                //sw.WriteLine(@"echo   __  ____  __ _  ___  ____   _");
                //sw.WriteLine(@"echo  /  \(_  _)!  / /(_  \( __ ) / \");
                //sw.WriteLine(@"echo (  O ) )(  !   ( / _  )(__ \ \_/");
                //sw.WriteLine(@"echo  \__/ (__) !__\_\\___/(____/ (_)");

                sw.WriteLine("echo.");
                sw.WriteLine("echo Close Paint.NET and try installing again.");
                sw.WriteLine(":done");
                sw.WriteLine("echo.");
                sw.WriteLine("pause");

                sw.Flush();
                sw.Close();

                // Create .zip file on user's desktop
                using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Create))
                {
                    archive.CreateEntryFromFile(dllPath, Path.GetFileName(dllPath)); // add .dll file
                    archive.CreateEntryFromFile(batPath, Path.GetFileName(batPath)); // add install.bat
                }

                if (File.Exists(zipPath))
                {
                    // if the zip file was successfully built, delete temp files
                    File.Delete(dllPath);
                    File.Delete(batPath);
                }

                return(true);
            }
            catch (Exception ex)
            {
                exceptionMsg = ex.Message;
            }
            return(false);
        }
 /// <summary>
 /// Determines if class has low tolerance to effects.
 /// </summary>
 /// <param name="flags">EffectFlags to test.</param>
 /// <returns>True if low tolerance.</returns>
 bool HasLowTolerance(CFGData cfg, EffectFlags flags)
 {
     return ((cfg.LowToleranceFlags & (byte)flags) == (byte)flags) ? true : false;
 }
 /// <summary>
 /// Determines if class is immune to effects.
 /// </summary>
 /// <param name="flags">EffectFlags to test.</param>
 /// <returns>True if immune.</returns>
 bool HasImmunity(CFGData cfg, EffectFlags flags)
 {
     return ((cfg.ImmunityFlags & (byte)flags) == (byte)flags) ? true : false;
 }
 /// <summary>
 /// Determines if class has critical weakness to effects.
 /// </summary>
 /// <param name="flags">EffectFlags to test.</param>
 /// <returns>True if critical weakness.</returns>
 bool HasCriticalWeakness(CFGData cfg, EffectFlags flags)
 {
     return ((cfg.CriticalWeaknessFlags & (byte)flags) == (byte)flags) ? true : false;
 }
Exemple #31
0
 public static CompilationResult CompileFromResource(string resourceName, string entryPoint, string profile, EffectFlags effectFlags = EffectFlags.None, string sourceFileName = "unknown")
 {
     using (Stream stream = Application.GetResourceStream(new Uri(resourceName)).Stream)
     {
         using (StreamReader reader = new StreamReader(stream))
         {
             return(ShaderBytecode.Compile(reader.ReadToEnd(), entryPoint, profile, shaderFlags, effectFlags, sourceFileName));
         }
     }
 }
Exemple #32
0
 /// <summary>
 /// Compiles the provided shader or effect source.
 /// </summary>
 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect 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="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(byte[] shaderSource, string profile, ShaderFlags shaderFlags,
                                      EffectFlags effectFlags, ShaderMacro[] defines, Include include,
                                      string sourceFileName = "unknown", SecondaryDataFlags secondaryDataFlags = SecondaryDataFlags.None, DataStream secondaryData = null)
 {
     return Compile(shaderSource, null, profile, shaderFlags, effectFlags, defines, include,
                    sourceFileName, secondaryDataFlags, secondaryData);
 }
 /// <summary>
 /// Determines if class is immune to effects.
 /// </summary>
 /// <param name="flags">EffectFlags to test.</param>
 /// <returns>True if immune.</returns>
 bool HasImmunity(CFGData cfg, EffectFlags flags)
 {
     return(((cfg.ImmunityFlags & (byte)flags) == (byte)flags) ? true : false);
 }
Exemple #34
0
 public BgEffect(Device device, byte[] byteCode, EffectFlags flags)
     : base(device, byteCode, flags)
 {
     Init();
 }
Exemple #35
0
 protected CodeLab(string extendedName, EffectFlags flags, EffectRenderingSchedule renderingSchedule)
     : base("CodeLab" + extendedName, StaticImage, "Advanced", new EffectOptions() { Flags = EffectFlags.Configurable | flags, RenderingSchedule = renderingSchedule })
 {
 }
 public static ShaderBytecode PrecompileOrLoad(string fileName, string profile, ShaderFlags shaderFlags, EffectFlags effectFlags)
 {
     return PrecompileOrLoad(fileName, null, profile, shaderFlags, effectFlags);
 }
Exemple #37
0
 /// <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);
     }
 }
Exemple #38
0
        private void handleTimingPoint(string line)
        {
            try
            {
                string[] split = line.Split(',');

                double time            = getOffsetTime(double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo));
                double beatLength      = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo);
                double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1;

                TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;
                if (split.Length >= 3)
                {
                    timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)int.Parse(split[2]);
                }

                LegacySampleBank sampleSet = defaultSampleBank;
                if (split.Length >= 4)
                {
                    sampleSet = (LegacySampleBank)int.Parse(split[3]);
                }

                int customSampleBank = 0;
                if (split.Length >= 5)
                {
                    customSampleBank = int.Parse(split[4]);
                }

                int sampleVolume = defaultSampleVolume;
                if (split.Length >= 6)
                {
                    sampleVolume = int.Parse(split[5]);
                }

                bool timingChange = true;
                if (split.Length >= 7)
                {
                    timingChange = split[6][0] == '1';
                }

                bool kiaiMode = false;
                bool omitFirstBarSignature = false;
                if (split.Length >= 8)
                {
                    EffectFlags effectFlags = (EffectFlags)int.Parse(split[7]);
                    kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai);
                    omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine);
                }

                string stringSampleSet = sampleSet.ToString().ToLowerInvariant();
                if (stringSampleSet == @"none")
                {
                    stringSampleSet = @"normal";
                }

                if (timingChange)
                {
                    var controlPoint = CreateTimingControlPoint();
                    controlPoint.Time          = time;
                    controlPoint.BeatLength    = beatLength;
                    controlPoint.TimeSignature = timeSignature;

                    handleTimingControlPoint(controlPoint);
                }

                handleDifficultyControlPoint(new DifficultyControlPoint
                {
                    Time            = time,
                    SpeedMultiplier = speedMultiplier
                });

                handleEffectControlPoint(new EffectControlPoint
                {
                    Time             = time,
                    KiaiMode         = kiaiMode,
                    OmitFirstBarLine = omitFirstBarSignature
                });

                handleSampleControlPoint(new LegacySampleControlPoint
                {
                    Time             = time,
                    SampleBank       = stringSampleSet,
                    SampleVolume     = sampleVolume,
                    CustomSampleBank = customSampleBank
                });
            }
            catch (FormatException e)
            {
            }
        }
Exemple #39
0
        /// <summary>
        /// Compiles the provided shader or effect source.
        /// </summary>
        /// <param name="textSource">The shader data.</param>
        /// <param name="textSize">Size of the shader.</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 used for reporting errors. Default is "unknown"</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(IntPtr textSource, int textSize, string entryPoint, string profile,
                                             ShaderFlags shaderFlags, EffectFlags effectFlags, ShaderMacro[] defines,
                                             Include include, string sourceFileName = "unknown", SecondaryDataFlags secondaryDataFlags = SecondaryDataFlags.None, DataStream secondaryData = null)
        {
            unsafe
            {
                var resultCode = Result.Ok;

                Blob blobForCode = null;
                Blob blobForErrors = null;

                try
                {
                    D3D.Compile2(
                        (IntPtr)textSource,
                        textSize,
                        sourceFileName,
                        PrepareMacros(defines),
                        IncludeShadow.ToIntPtr(include),
                        entryPoint,
                        profile,
                        shaderFlags,
                        effectFlags,
                        secondaryDataFlags,
                        secondaryData != null ? secondaryData.DataPointer : IntPtr.Zero,
                        secondaryData != null ? (int)secondaryData.Length : 0,
                        out blobForCode,
                        out blobForErrors);
                }
                catch (SharpDXException ex)
                {
                    if (blobForErrors != null)
                    {
                        resultCode = ex.ResultCode;
                        if (Configuration.ThrowOnShaderCompileError)
                            throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
                    }
                    else
                    {
                        throw;
                    }
                }

                return new CompilationResult(blobForCode != null ? new ShaderBytecode(blobForCode) : null, resultCode, Utilities.BlobToString(blobForErrors));
            }
        }
Exemple #40
0
 /// <summary>
 /// Returns true if the specified flag is set.
 /// </summary>
 /// <param name="flags"></param>
 /// <returns></returns>
 public bool Has(EffectFlags flags)
 {
     return ((this.EffectFlags & flags) != 0);
 }
Exemple #41
0
 /// <summary>
 ///   Compiles the provided shader or effect source.
 /// </summary>
 /// <param name = "shaderSource">An array of bytes containing the raw 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>
 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
 public static CompilationResult Compile(byte[] shaderSource, string entryPoint, string profile,
                                      ShaderFlags shaderFlags = ShaderFlags.None,
                                      EffectFlags effectFlags = EffectFlags.None, string sourceFileName = "unknown")
 {
     return Compile(shaderSource, entryPoint, profile, shaderFlags, effectFlags, null, null,
                    sourceFileName);
 }
Exemple #42
0
        internal void RegisterEffect(string shaderEffectString, string[] techniqueNames, ShaderFlags sFlags = ShaderFlags.None, EffectFlags eFlags = EffectFlags.None)
        {
#if DEBUG
            sFlags |= ShaderFlags.Debug;
            eFlags |= EffectFlags.None;
#endif

            var preprocess = ShaderBytecode.Preprocess(shaderEffectString, null, new IncludeHandler());
            var hashCode   = preprocess.GetHashCode();
            if (!File.Exists(hashCode.ToString()))
            {
                try
                {
                    var shaderBytes = ShaderBytecode.Compile(preprocess, "fx_5_0", sFlags, eFlags);
                    shaderBytes.Bytecode.Save(hashCode.ToString());
                    this.RegisterEffect(shaderBytes.Bytecode, techniqueNames);
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(string.Format("Error compiling effect: {0}", ex.Message), "Error");
                }
            }
            else
            {
                var shaderBytes = ShaderBytecode.FromFile(hashCode.ToString());
                this.RegisterEffect(shaderBytes, techniqueNames);
            }
        }
Exemple #43
0
 /// <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="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if compilation succeeded.</param>
 /// <param name="sourceFileName">Name of the source file.</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")
 {
     if (string.IsNullOrEmpty(shaderSource))
     {
         throw new ArgumentNullException("shaderSource");
     }
     return Compile(Encoding.ASCII.GetBytes(shaderSource), entryPoint, profile, shaderFlags, effectFlags, defines,
                    include, sourceFileName);
 }
Exemple #44
0
 /// <summary>
 /// Register an effect for a set of RenderTechniques.
 /// </summary>
 /// <param name="shaderEffectBytecode">A byte array representing the compiled shader.</param>
 /// <param name="techniques">A set of RenderTechnique objects for which to associate the Effect.</param>
 /// <param name="eFlags"></param>
 protected void RegisterEffect(byte[] shaderEffectBytecode, RenderTechnique[] techniques, EffectFlags eFlags = EffectFlags.None)
 {
     var effect = new Effect(device, shaderEffectBytecode, eFlags);
     foreach (var tech in techniques)
         data[tech.Name] = effect;
 }
Exemple #45
0
        /// <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="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>
        /// <returns>
        /// The compiled shader bytecode, or <c>null</c> if the method fails.
        /// </returns>
        public static CompilationResult CompileFromFile(string fileName, string entryPoint, string profile, ShaderFlags shaderFlags = ShaderFlags.None, EffectFlags effectFlags = EffectFlags.None, ShaderMacro[] defines = null, Include include = null)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("Could not open the shader or effect file.", fileName);
            }

            unsafe
            {
                var resultCode = Result.Ok;

                Blob blobForCode = null;
                Blob blobForErrors = null;

#if DIRECTX11_1
                resultCode = D3D.CompileFromFile(
                    fileName,
                    PrepareMacros(defines),
                    IncludeShadow.ToIntPtr(include),
                    entryPoint,
                    profile,
                    shaderFlags,
                    effectFlags,
                    out blobForCode,
                    out blobForErrors);

                if (resultCode.Failure)
                {
                    if (blobForErrors != null)
                    {
                        if (Configuration.ThrowOnShaderCompileError) throw new CompilationException(resultCode, Utilities.BlobToString(blobForErrors));
                    }
                    else
                    {
                        throw new SharpDXException(resultCode);
                    }
                }

                return new CompilationResult(blobForCode != null ? new ShaderBytecode(blobForCode) : null, resultCode, Utilities.BlobToString(blobForErrors));
#else
                return Compile(File.ReadAllText(fileName), entryPoint, profile, shaderFlags, effectFlags,
                                PrepareMacros(defines), include, fileName);
#endif
            }


        }
Exemple #46
0
        internal static bool BuildEffectDll(string scriptText, string scriptPath, string subMenuname, string menuName, string iconPath, string author, int majorVersion, int minorVersion, string supportURL, string windowTitle, bool isAdjustment, string description, string keyWords, EffectFlags effectFlags, EffectRenderingSchedule renderingSchedule, HelpType helpType, string helpText)
        {
            string projectName = Path.GetFileNameWithoutExtension(scriptPath);

            // Generate code
            string sourceCode = ScriptWriter.FullSourceCode(scriptText, projectName, isAdjustment, subMenuname, menuName, iconPath, supportURL, effectFlags, renderingSchedule, author, majorVersion, minorVersion, description, keyWords, windowTitle, helpType, helpText);

            List <string> resourceFiles = new List <string>();

            if (File.Exists(iconPath))
            {
                // If an icon is specified and exists, add it to the build as an embedded resource to the same namespace as the effect.
                resourceFiles.Add(iconPath);
            }

            string samplepath = Path.ChangeExtension(scriptPath, ".sample.png");

            if (File.Exists(samplepath))
            {
                // If an image exists in the icon directory with a ".sample.png" extension, add it to the build as an embedded resource.
                resourceFiles.Add(samplepath);
            }

            string helpPath = Path.ChangeExtension(scriptPath, ".rtz");

            if (helpType == HelpType.RichText && File.Exists(helpPath))
            {
                // If an help file exists in the source directory with a ".rtz" extension, add it to the build as an embedded resource.
                resourceFiles.Add(helpPath);
            }

            return(BuildDll(projectName, resourceFiles, sourceCode, ProjectType.Effect));
        }
 private static string GetEffectFlagsString(EffectFlags effectFlags)
 {
     var text = effectFlags.ToString();
     return text;
 }
Exemple #48
0
 internal void RegisterEffect(string shaderEffectString, string techniqueName, ShaderFlags sFlags = ShaderFlags.None, EffectFlags eFlags = EffectFlags.None)
 {
     RegisterEffect(shaderEffectString, new[] { techniqueName }, sFlags, eFlags);
 }
Exemple #49
0
 /// <summary>
 /// Returns true if the specified flag is set.
 /// </summary>
 /// <param name="flags"></param>
 /// <returns></returns>
 public bool Has(EffectFlags flags)
 {
     return((this.EffectFlags & flags) != 0);
 }
Exemple #50
0
        internal void RegisterEffect(byte[] shaderEffectBytecode, string[] techniqueNames, EffectFlags eFlags = EffectFlags.None)
        {
            var effect = new Effect(device, shaderEffectBytecode, eFlags);

            foreach (var name in techniqueNames)
            {
                data[name] = effect;
            }
        }
Exemple #51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Effect"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="effectByteCode">The effect byte code.</param>
 /// <param name="fxFlags">Effect compile options</param>
 /// <param name="effectPool">Optional. A reference to an memory space for effect variables that are shared across effects (see <see cref="SharpDX.Direct3D10.EffectPool"/>).</param>
 public unsafe Effect(Device device, byte[] effectByteCode, EffectFlags fxFlags = EffectFlags.None, EffectPool effectPool = null) 
 {
     fixed (void* ptr = effectByteCode)
         D3D10.CreateEffectFromMemory((IntPtr)ptr, effectByteCode.Length, (int)fxFlags, device, effectPool, this);
 }
Exemple #52
0
 /// <summary>
 /// Register an effect for a RenderTechnique.
 /// 
 /// Override in a derived class to control how effects are registered.
 /// </summary>
 /// <param name="shaderEffectString">A string representing the shader code.</param>
 /// <param name="techniqueName"></param>
 /// <param name="sFlags"></param>
 /// <param name="eFlags"></param>
 protected void RegisterEffect(string shaderEffectString, RenderTechnique technique, ShaderFlags sFlags = ShaderFlags.None, EffectFlags eFlags = EffectFlags.None)
 {
     RegisterEffect(shaderEffectString, new[] { technique }, sFlags, eFlags);
 }
 internal ColorDifferenceEffect(string name, Image image, string subMenuName, EffectFlags flags)
     : base(name, image, subMenuName, flags)
 {
 }
Exemple #54
0
 /// <summary>
 /// Register an effect for a RenderTechnique.
 /// </summary>
 /// <param name="shaderEffectString">A string representing the shader code.</param>
 /// <param name="techniqueName"></param>
 /// <param name="sFlags"></param>
 /// <param name="eFlags"></param>
 public void RegisterEffect(string shaderEffectString, RenderTechnique technique, ShaderFlags sFlags = ShaderFlags.None, EffectFlags eFlags = EffectFlags.None)
 {
     RegisterEffect(shaderEffectString, new[] { technique }, sFlags, eFlags);
 }
 /// <summary>
 /// Determines if class is resistant to effects.
 /// </summary>
 /// <param name="flags">EffectFlags to test.</param>
 /// <returns>True if resistant.</returns>
 bool HasResistance(CFGData cfg, EffectFlags flags)
 {
     return(((cfg.ResistanceFlags & (byte)flags) == (byte)flags) ? true : false);
 }
Exemple #56
0
        /// <summary>
        /// Register an effect for a set of RenderTechniques.
        /// </summary>
        /// <param name="shaderEffectString">A string representing the shader code.</param>
        /// <param name="techniques">A set of RenderTechnique objects for which to associate the Effect.</param>
        /// <param name="sFlags"></param>
        /// <param name="eFlags"></param>
        public void RegisterEffect(string shaderEffectString, RenderTechnique[] techniques, ShaderFlags sFlags = ShaderFlags.None, EffectFlags eFlags = EffectFlags.None)
        {
#if PRECOMPILED_SHADERS
            try
            {
                var shaderBytes = Techniques.TechniquesSourceDict[techniques[0]];
                this.RegisterEffect(shaderBytes, techniques);
            }
            catch (Exception ex)
            {
                //System.Windows.MessageBox.Show(string.Format("Error registering effect: {0}", ex.Message), "Error");
                Debug.WriteLine(string.Format("Error registering effect: {0}", ex.Message), "Error");
                throw;
            }
#else
#if DEBUG
            sFlags |= ShaderFlags.Debug;
            eFlags |= EffectFlags.None;
#else
            sFlags |= ShaderFlags.OptimizationLevel3;
            eFlags |= EffectFlags.None;
#endif

            var preposessMacros = new List <ShaderMacro>();

#if DEFERRED
#if DEFERRED_MSAA
            preposessMacros.Add(new ShaderMacro("DEFERRED_MSAA", true));
#endif

#if SSAO
            preposessMacros.Add(new ShaderMacro("SSAO", true));
#endif
#endif
            var preprocess = ShaderBytecode.Preprocess(shaderEffectString, preposessMacros.ToArray(), new IncludeHandler());
            var hashCode   = preprocess.GetHashCode();
            if (!File.Exists(hashCode.ToString()))
            {
                try
                {
                    var shaderBytes = ShaderBytecode.Compile(preprocess, "fx_5_0", sFlags, eFlags);
                    shaderBytes.Bytecode.Save(hashCode.ToString());
                    this.RegisterEffect(shaderBytes.Bytecode, techniques);
                }
                catch (Exception ex)
                {
                    //System.Windows.MessageBox.Show(string.Format("Error compiling effect: {0}", ex.Message), "Error");
                    Debug.WriteLine(string.Format("Error compiling effect: {0}", ex.Message), "Error");
                    throw;
                }
            }
            else
            {
                var shaderBytes = ShaderBytecode.FromFile(hashCode.ToString());
                this.RegisterEffect(shaderBytes, techniques);
            }
#endif
        }
 /// <summary>
 /// Determines if class has low tolerance to effects.
 /// </summary>
 /// <param name="flags">EffectFlags to test.</param>
 /// <returns>True if low tolerance.</returns>
 bool HasLowTolerance(CFGData cfg, EffectFlags flags)
 {
     return(((cfg.LowToleranceFlags & (byte)flags) == (byte)flags) ? true : false);
 }
Exemple #58
0
        /// <summary>
        /// Register an effect for a set of RenderTechniques.
        /// </summary>
        /// <param name="shaderEffectBytecode">A byte array representing the compiled shader.</param>
        /// <param name="techniques">A set of RenderTechnique objects for which to associate the Effect.</param>
        /// <param name="eFlags"></param>
        public void RegisterEffect(byte[] shaderEffectBytecode, RenderTechnique[] techniques, EffectFlags eFlags = EffectFlags.None)
        {
            var effect = new Effect(device, shaderEffectBytecode, eFlags);

            foreach (var tech in techniques)
            {
                data[tech.Name] = effect;
            }
        }
Exemple #59
0
        /// <summary>
        /// Register an effect for a set of RenderTechniques.
        /// </summary>
        /// <param name="shaderEffectString">A string representing the shader code.</param>
        /// <param name="techniques">A set of RenderTechnique objects for which to associate the Effect.</param>
        /// <param name="sFlags"></param>
        /// <param name="eFlags"></param>
        protected void RegisterEffect(string shaderEffectString, RenderTechnique[] techniques, ShaderFlags sFlags = ShaderFlags.None, EffectFlags eFlags = EffectFlags.None)
        {
#if PRECOMPILED_SHADERS

            try
            {
                var shaderBytes = ((DefaultRenderTechniquesManager)renderTechniquesManager).TechniquesSourceDict[techniques[0]];
                RegisterEffect(shaderBytes, techniques);
            }
            catch (Exception ex)
            {
                //System.Windows.MessageBox.Show(string.Format("Error registering effect: {0}", ex.Message), "Error");
                Debug.WriteLine(string.Format("Error registering effect: {0}", ex.Message), "Error");
                throw;
            }
#else

#if DEBUG
            sFlags |= ShaderFlags.Debug;
            eFlags |= EffectFlags.None;
#else
            sFlags |= ShaderFlags.OptimizationLevel3;
            eFlags |= EffectFlags.None;       
#endif

            var preposessMacros = new List<ShaderMacro>();

#if DEFERRED
#if DEFERRED_MSAA
            preposessMacros.Add(new ShaderMacro("DEFERRED_MSAA", true));
#endif

#if SSAO
            preposessMacros.Add(new ShaderMacro("SSAO", true));
#endif
#endif
            var preprocess = ShaderBytecode.Preprocess(shaderEffectString, preposessMacros.ToArray(), new IncludeHandler());
            var hashCode = preprocess.GetHashCode();
            if (!File.Exists(hashCode.ToString()))
            {
                try
                {
                    var shaderBytes = ShaderBytecode.Compile(preprocess, "fx_5_0", sFlags, eFlags);
                    shaderBytes.Bytecode.Save(hashCode.ToString());
                    this.RegisterEffect(shaderBytes.Bytecode, techniques);
                }
                catch (Exception ex)
                {
                    //System.Windows.MessageBox.Show(string.Format("Error compiling effect: {0}", ex.Message), "Error");
                    Debug.WriteLine(string.Format("Error compiling effect: {0}", ex.Message), "Error");
                    throw;
                }
            }
            else
            {
                var shaderBytes = ShaderBytecode.FromFile(hashCode.ToString());
                this.RegisterEffect(shaderBytes, techniques);
            }
#endif
        }
Exemple #60
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Effect"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="effectByteCode">The effect byte code.</param>
 /// <param name="fxFlags">Effect compile options</param>
 public unsafe Effect(Device device, byte[] effectByteCode, EffectFlags fxFlags = EffectFlags.None)
 {
     fixed(void *ptr = effectByteCode)
     D3DX11Effects.CreateEffectFromMemory((IntPtr)ptr, effectByteCode.Length, (int)fxFlags, device, this);
 }