/// <summary> /// Initializes a new instance of the <see cref="GorgonShaderMacro"/> struct. /// </summary> /// <param name="name">The name of the macro.</param> /// <param name="value">[Optional] The value for the macro.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="name"/> parameter is <b>null</b>.</exception> /// <exception cref="ArgumentEmptyException">Thrown when the <paramref name="name"/> parameter is empty.</exception> public GorgonShaderMacro(string name, string value = null) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (name.Length == 0) { throw new ArgumentEmptyException(nameof(name)); } D3DShaderMacro = new D3D.ShaderMacro(name, value); }
public EffectContainer(Device device, string EffectFile, InputElement[] _InputElement) { //Name = EffectFile; string extension = System.IO.Path.GetExtension(EffectFile); if (extension.ToLower() == ".fx") { IncludeFX includeFX = new IncludeFX(); //Компилируем шейдер в байткод #if !DEBUG //на время отладки шейдеров try #endif { SharpDX.Direct3D.ShaderMacro[] Macross = new SharpDX.Direct3D.ShaderMacro[6]; Macross[0] = new SharpDX.Direct3D.ShaderMacro("DX10_1", (Program.featureLevel > FeatureLevel.Level_10_0)? 1:0 ); Macross[1] = new SharpDX.Direct3D.ShaderMacro("SPLITCOUNT", PSSMsHelper.SplitsNumber); Macross[2] = new SharpDX.Direct3D.ShaderMacro("OCCLPPIXELINTEX", DrawHelper.OcclPixelInTex); Macross[3] = new SharpDX.Direct3D.ShaderMacro("SCREENX", Global.Settings.Width); Macross[4] = new SharpDX.Direct3D.ShaderMacro("SCREENY", Global.Settings.Height); using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile(EffectFile, "fx_5_0", #if DEBUG ShaderFlags.Debug | ShaderFlags.SkipOptimization | ShaderFlags.PreferFlowControl, #else ShaderFlags.OptimizationLevel3, #endif EffectFlags.None, Macross, includeFX)) { // Загрузим скомпилированный эффект в видеокарту renderEffect = new Effect(device, bytecode); } } #if !DEBUG catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show("Error! Ошибкак чтения эффекта: " + EffectFile); new CompilationException(EffectFile); } #endif } else if (extension.ToLower() == ".ees") { try { System.IO.FileStream fs = new System.IO.FileStream(EffectFile, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, (int)fs.Length); fs.Close(); using (DataStream DS = new DataStream(bytes.Length, true, true)) { DS.Write(bytes, 0, bytes.Length); using (ShaderBytecode bytecode = new ShaderBytecode(DS)) { renderEffect = new Effect(device, bytecode); } } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show("Error! Ошибкак чтения эффекта: " + EffectFile); new CompilationException(EffectFile); } } else { System.Windows.Forms.MessageBox.Show("Error! Не найден файл эффекта: " + EffectFile); new FileNotFoundException("Не найден файл", EffectFile); } //TODO изучить влияние renderEffect.Optimize(); TechniqueCount = renderEffect.Description.TechniqueCount; renderTechniques = new EffectTechnique[TechniqueCount]; // Загружаем техники из шейдера for (int i = 0; i < TechniqueCount; i++) { renderTechniques[i] = renderEffect.GetTechniqueByIndex(i); } // Выберем входную сигнатуру данных первого прохода var renderPassSignature = renderTechniques[0].GetPassByIndex(0).Description.Signature; if (_InputElement == null) { _InputElement= new InputElement[]{ new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 24, 0), new InputElement("TEXCOORD", 1, Format.R32G32_Float, 32, 0), new InputElement("TANGENT", 0, Format.R32G32B32_Float, 40, 0), new InputElement("BINORMAL", 0, Format.R32G32B32_Float, 52, 0)}; } //создаем входную конфигурвцию для стандартного меша layout = new InputLayout(device, renderPassSignature, _InputElement); }