protected void compileAndSaveShader(string name, string entryPoint) { Uri executablePath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); String shaderPath = System.IO.Path.GetDirectoryName(executablePath.LocalPath) + "\\Shaders\\"; try { ShaderBytecode shaderBytes = ShaderBytecode.CompileFromFile(shaderPath + name, entryPoint, "ps_2_0", ShaderFlags.None, EffectFlags.None, null, null); Logger.Log.Info("Compiled pixel shader: " + shaderPath + name); FileStream stream = new FileStream("D:\\Repos\\mediaviewer\\MediaViewer\\Resources\\CompiledShaders\\" + System.IO.Path.GetFileNameWithoutExtension(name) + ".ps", FileMode.Create); shaderBytes.Save(stream); stream.Close(); } catch (Exception e) { Logger.Log.Error("Error loading pixel shader " + name, e); throw; } }
protected void compileAndLoadShader(String name, String entryPoint) { PixelShader = new PixelShader(); Uri executablePath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); String shaderPath = System.IO.Path.GetDirectoryName(executablePath.LocalPath) + "\\Shaders\\"; try { ShaderBytecode shaderBytes = ShaderBytecode.CompileFromFile(shaderPath + name, entryPoint, "ps_2_0", ShaderFlags.None, EffectFlags.None, null, null); Logger.Log.Info("Compiled pixel shader: " + shaderPath + name); MemoryStream stream = new MemoryStream(); shaderBytes.Save(stream); stream.Position = 0; PixelShader.SetStreamSource(stream); } catch (Exception e) { Logger.Log.Error("Error loading pixel shader " + name, e); throw; } }
protected MyEffectBase(string asset) { string curdir = System.IO.Directory.GetCurrentDirectory(); bool needRecompile = false; System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(MyMinerGame.Static.RootDirectoryEffects + "\\" + asset)); SetEffectInDebug(asset); string sourceFX = Path.GetFileName(asset + ".fx"); string compiledFX = Path.GetFileName(asset + ".fxo"); if (File.Exists(compiledFX)) { if (File.Exists(sourceFX)) { DateTime compiledTime = File.GetLastWriteTime(compiledFX); DateTime sourceTime = File.GetLastWriteTime(sourceFX); if (sourceTime > compiledTime) { needRecompile = true; } } } else { if (File.Exists(sourceFX)) { needRecompile = true; } else { throw new FileNotFoundException("Effect not found: " + asset); } } //Nepouzivat ShaderFlags.PartialPrecision, kurvi to na GeForce6600 ShaderFlags flags = ShaderFlags.OptimizationLevel3 | ShaderFlags.SkipValidation; if (needRecompile) { //#if DEBUG // flags |= ShaderFlags.Debug; //#endif //m_D3DEffect = Effect.FromFile(MyMinerGameDX.Static.GraphicsDevice, sourceFX, flags); ShaderBytecode shaderByteCode = ShaderBytecode.CompileFromFile(sourceFX, "fx_2_0", flags); System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(MyMinerGame.Static.RootDirectoryEffects + "\\" + asset)); shaderByteCode.Save(compiledFX); shaderByteCode.Dispose(); } FileStream fs = File.Open(compiledFX, FileMode.Open, FileAccess.Read); byte[] m = new byte[fs.Length]; fs.Read(m, 0, (int)fs.Length); fs.Close(); fs.Dispose(); m_D3DEffect = Effect.FromMemory(MyMinerGame.Static.GraphicsDevice, m, flags); System.IO.Directory.SetCurrentDirectory(curdir); Init(); }
protected MyEffectBase(string asset) { string sourceFX = asset + ".fx"; string compiledFX = asset + ".fxo"; var srcPath = Path.Combine(MyFileSystem.ContentPath, sourceFX); var comPath = Path.Combine(MyFileSystem.ContentPath, compiledFX); var srcAbsolute = srcPath; bool needRecompile = false; if (File.Exists(comPath)) { if (File.Exists(srcPath) && !MyRenderProxy.IS_OFFICIAL) { var compiledTime = File.GetLastWriteTime(comPath); var sourceTime = File.GetLastWriteTime(srcAbsolute); m_includeProcessor.Reset(Path.GetDirectoryName(srcAbsolute)); ShaderBytecode.PreprocessFromFile(srcAbsolute, null, m_includeProcessor); sourceTime = m_includeProcessor.MostUpdateDateTime > sourceTime ? m_includeProcessor.MostUpdateDateTime : sourceTime; if (sourceTime > compiledTime) { needRecompile = true; } } } else { if (File.Exists(srcPath)) { needRecompile = true; } else { throw new FileNotFoundException("Effect not found: " + asset); } } ShaderFlags flags = ShaderFlags.OptimizationLevel3 | ShaderFlags.PartialPrecision | ShaderFlags.SkipValidation; if (needRecompile) { //#if DEBUG // flags |= ShaderFlags.Debug; //#endif //m_D3DEffect = Effect.FromFile(MySandboxGameDX.Static.GraphicsDevice, sourceFX, flags); try { var srcDir = Path.GetDirectoryName(srcAbsolute); m_includeProcessor.Reset(srcDir); var result = ShaderBytecode.CompileFromFile(srcAbsolute, "fx_2_0", flags, null, m_includeProcessor); ShaderBytecode shaderByteCode = result; shaderByteCode.Save(Path.Combine(srcDir, Path.GetFileNameWithoutExtension(srcAbsolute) + ".fxo")); result.Dispose(); } catch (Exception e) { Debug.Fail(e.Message); throw; } } using (var fs = MyFileSystem.OpenRead(comPath)) { byte[] m = new byte[fs.Length]; fs.Read(m, 0, (int)fs.Length); m_D3DEffect = Effect.FromMemory(MyRender.GraphicsDevice, m, flags); } Init(); }