private static DX11Effect LoadByteCode(byte[] bytecode) { DX11Effect shader = new DX11Effect(); try { DataStream ds = new DataStream(bytecode.Length, true, true); ds.Write(bytecode, 0, bytecode.Length); shader.ByteCode = new ShaderBytecode(ds); //fs.Close(); ds.Dispose(); shader.IsCompiled = true; shader.ErrorMessage = ""; shader.Preprocess(); } catch (Exception ex) { shader.IsCompiled = false; shader.ErrorMessage = ex.Message; shader.DefaultEffect = null; } return shader; }
private static DX11Effect Compile(string content, bool isfile, Include include, ShaderMacro[] defines) { DX11Effect shader = new DX11Effect(); string errors; try { ShaderFlags flags = ShaderFlags.OptimizationLevel1; if (isfile) { shader.ByteCode = ShaderBytecode.CompileFromFile(content, "fx_5_0", flags, EffectFlags.None, defines, include, out errors); } else { shader.ByteCode = ShaderBytecode.Compile(content, "fx_5_0", flags, EffectFlags.None, defines, include, out errors); } //Compilation worked, but we can still have warning shader.IsCompiled = true; shader.ErrorMessage = errors; shader.Preprocess(); } catch (Exception ex) { shader.IsCompiled = false; shader.ErrorMessage = ex.Message; shader.DefaultEffect = null; } return(shader); }
private static DX11Effect LoadByteCode(byte[] bytecode) { DX11Effect shader = new DX11Effect(); try { DataStream ds = new DataStream(bytecode.Length, true, true); ds.Write(bytecode, 0, bytecode.Length); shader.ByteCode = new ShaderBytecode(ds); //fs.Close(); ds.Dispose(); shader.IsCompiled = true; shader.ErrorMessage = ""; shader.Preprocess(); } catch (Exception ex) { shader.IsCompiled = false; shader.ErrorMessage = ex.Message; shader.DefaultEffect = null; } return(shader); }
private static DX11Effect Compile(string content, bool isfile, Include include, ShaderMacro[] defines) { DX11Effect shader = new DX11Effect(); ShaderFlags flags = ShaderFlags.OptimizationLevel1;// | ShaderFlags.PackMatrixRowMajor; try { if (isfile) { shader.CompilationResult = ShaderBytecode.CompileFromFile(content, "fx_5_0", flags, EffectFlags.None, defines, include); } else { shader.CompilationResult = ShaderBytecode.Compile(content, "fx_5_0", flags, EffectFlags.None, defines, include); } if (shader.IsCompiled) { shader.DefaultEffect = new Effect(NullDevice.Device, shader.CompilationResult.Bytecode); } } catch (Exception ex) { shader.CompilationResult = new CompilationResult(null, Result.Fail, ex.Message); } return(shader); }
public static DX11Effect LoadFromByteCode(byte[] data) { DX11Effect shader = new DX11Effect(); shader.CompilationResult = new CompilationResult(new ShaderBytecode(data), Result.Ok, ""); shader.DefaultEffect = new Effect(NullDevice.Device, shader.CompilationResult.Bytecode); return(shader); }
private static DX11Effect CompileSharpDX(string content, bool isfile, Include include, ShaderMacro[] defines, bool library = false) { DX11Effect shader = new DX11Effect(); var profile = library ? "lib_5_0" : "fx_5_0"; SharpDX.D3DCompiler.Include sdxInclude = include != null ? new SharpDXIncludeWrapper(include) : null; var sdxDefines = defines != null?defines.AsSharpDXMacro() : null; string errors; try { SharpDX.D3DCompiler.ShaderFlags flags = SharpDX.D3DCompiler.ShaderFlags.OptimizationLevel1; if (isfile) { SharpDX.D3DCompiler.CompilationResult result = SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile(content, profile, flags, SharpDX.D3DCompiler.EffectFlags.None, sdxDefines, sdxInclude); if (result.Bytecode != null) { SlimDX.DataStream ds = new SlimDX.DataStream(result.Bytecode, true, true); shader.ByteCode = new ShaderBytecode(ds); shader.Preprocess(); } errors = result.Message; } else { //shader.ByteCode = ShaderBytecode.Compile(content, "fx_5_0", flags, EffectFlags.None, defines, include, out errors); SharpDX.D3DCompiler.CompilationResult result = SharpDX.D3DCompiler.ShaderBytecode.Compile(content, profile, flags, SharpDX.D3DCompiler.EffectFlags.None, sdxDefines, sdxInclude); if (result.Bytecode != null) { SlimDX.DataStream ds = new SlimDX.DataStream(result.Bytecode, true, true); shader.ByteCode = new ShaderBytecode(ds); shader.Preprocess(); } errors = result.Message; } //Compilation worked, but we can still have warning shader.IsCompiled = shader.ByteCode != null; shader.ErrorMessage = errors; } catch (Exception ex) { shader.IsCompiled = false; shader.ErrorMessage = ex.Message; shader.DefaultEffect = null; } return(shader); }
public override void SetShader(DX11Effect shader, bool isnew) { if (isnew) { this.FShader = shader; } if (shader.IsCompiled) { this.FShader = shader; this.varmanager.SetShader(shader); } //Only set technique if new, otherwise do it on update/evaluate if (isnew) { string defaultenum; if (shader.IsCompiled) { defaultenum = shader.TechniqueNames[0]; this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames); this.varmanager.CreateShaderPins(); } else { defaultenum = ""; this.FHost.UpdateEnum(this.TechniqueEnumId, "", new string[0]); } } else { if (shader.IsCompiled) { this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames); this.varmanager.UpdateShaderPins(); } } this.shaderupdated = true; this.FInvalidate = true; }
public void SetEffect(DX11Effect shader) { //Create if (this.shader == null) { this.shader = shader; if (shader.IsCompiled) { this.shaderinstance = new DX11ShaderInstance(this.context, shader.ByteCode); this.UpdateTechnique(); } } else { if (shader.IsCompiled) { //Update shader if (shader != this.shader) { //Dispose old effect if applicable this.shader = shader; if (this.shaderinstance != null) { this.shaderinstance.Dispose(); } this.shaderinstance = new DX11ShaderInstance(this.context, shader.ByteCode); this.UpdateTechnique(); this.DisposeLayouts(); } } } }
public override void SetShader(DX11Effect shader, bool isnew, string fileName) { this.FShader = shader; this.varmanager.SetShader(shader); FOutPath.SliceCount = 1; FOutPath[0] = fileName; //Only set technique if new, otherwise do it on update/evaluate if (isnew) { string defaultenum; if (shader.IsCompiled) { defaultenum = shader.TechniqueNames[0]; this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames); this.varmanager.CreateShaderPins(); } else { defaultenum = ""; this.FHost.UpdateEnum(this.TechniqueEnumId, "", new string[0]); } //Create Technique enum pin InputAttribute inAttr = new InputAttribute("Technique"); inAttr.EnumName = this.TechniqueEnumId; inAttr.DefaultEnumEntry = defaultenum; inAttr.Order = 1000; this.FInTechnique = this.FFactory.CreateDiffSpread<EnumEntry>(inAttr); this.FoutCS.AssignFrom(this.varmanager.GetCustomData()); } else { if (shader.IsCompiled) { this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames); this.varmanager.UpdateShaderPins(); this.FoutCS.AssignFrom(this.varmanager.GetCustomData()); } } this.shaderupdated = true; this.FInvalidate = true; }
private static DX11Effect Compile(string content, bool isfile, Include include) { DX11Effect shader = new DX11Effect(); try { string errors; ShaderFlags flags = ShaderFlags.OptimizationLevel1; if (isfile) { shader.ByteCode = ShaderBytecode.CompileFromFile(content, "fx_5_0", flags, EffectFlags.None, null, include, out errors); } else { shader.ByteCode = ShaderBytecode.Compile(content, "fx_5_0", flags, EffectFlags.None, null, include, out errors); } //Compilation worked, but we can still have warning shader.IsCompiled = true; shader.ErrorMessage = errors; shader.Preprocess(); } catch (Exception ex) { shader.IsCompiled = false; shader.ErrorMessage = ex.Message; shader.DefaultEffect = null; } return shader; }
public void SetShader(DX11Effect shader) { this.shader = shader; }
public override void SetShader(DX11Effect shader, bool isnew, string fileName) { FOutPath.SliceCount = 1; FOutPath[0] = fileName; if (shader.IsCompiled) { this.FShader = shader; this.varmanager.SetShader(shader); this.varmanager.RebuildTextureCache(); this.varmanager.RebuildPassCache(tid); } //Only set technique if new, otherwise do it on update/evaluate if (isnew) { string defaultenum; if (shader.IsCompiled) { defaultenum = shader.TechniqueNames[0]; this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames); this.varmanager.CreateShaderPins(); } else { defaultenum = ""; this.FHost.UpdateEnum(this.TechniqueEnumId, "", new string[0]); } } else { if (shader.IsCompiled) { this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames); this.varmanager.UpdateShaderPins(); } } this.shaderupdated = true; this.FInvalidate = true; }
public abstract void SetShader(DX11Effect shader, bool isnew);
public EffectInstance(DxDevice device, DX11Effect effect) { this.device = device; this.effect = new Effect(device.Device, effect.ByteCode); this.currenttechnique = this.effect.GetTechniqueByIndex(0); }
public abstract void SetShader(DX11Effect shader, bool isnew, string fileName);
public int GetPreferredTechnique(DX11Effect shader) { string[] techniqueNames = shader.TechniqueNames; foreach (string pref in this.PreferredTechniques) { for (int i = 0; i < techniqueNames.Length; ++i) { if (techniqueNames[i].ToLower() == pref) { return i; } } } return -1; }
public DX11ShaderInstance(DX11RenderContext context, DX11Effect effect) { this.context = context; this.effect = new Effect(context.Device, effect.ByteCode); this.currenttechnique = this.effect.GetTechniqueByIndex(0); }