public override void Init( FXEffect m_effect, FXConstantBuffer m_cb ) { // bind the local variables with the shader Color_Variable = m_cb.GetMemberByName<Vector3>( VariableName + "_Color" ); // set the default values Color_Variable.Set(_color); }
public override void Init( FXEffect m_effect, FXConstantBuffer m_cb ) { // bind the local variables with the shader Texture_Variable = m_effect.GetResourceByName(VariableName + "_Texture"); // set the default values if (Tex != null) Texture_Variable.SetResource(Tex.shaderResource); }
public override void Init( FXEffect m_effect, FXConstantBuffer m_cb ) { // bind the local variables with the shader NumBoxX_Variable = m_cb.GetMemberByName<int>( VariableName + "_CheckerX" ); NumBoxY_Variable = m_cb.GetMemberByName<int>( VariableName + "_CheckerY" ); // set the default values NumBoxX_Variable.Set(_NumBoxX); NumBoxY_Variable.Set(_NumBoxY); }
/// <summary> /// Add the resource from shader base on the name /// </summary> /// <param name="effect"></param> /// <param name="Name"></param> public void AddResourceFromShader(FXEffect effect, String Name) { FXResourceVariableItem newItem = new FXResourceVariableItem(); // set the name of the item newItem.Name = Name; // get the item from the effect newItem.resource = effect.GetResourceByName(Name); // add the new item to the list ListWithResourceVariables.Add(newItem); }
public override void Init( FXEffect m_effect, FXConstantBuffer m_cb ) { // bind the local variables with the shader BrickWidth_Variable = m_cb.GetMemberByName<float>( VariableName + "_BrickWidth" ); BrickHeight_Variable = m_cb.GetMemberByName<float>( VariableName + "_BrickHeight" ); BrickShift_Variable = m_cb.GetMemberByName<float>( VariableName + "_BrickShift" ); MortarThickness_Variable = m_cb.GetMemberByName<float>( VariableName + "_MortarThickness" ); // set the default values BrickWidth_Variable.Set(_BrickWidth); BrickHeight_Variable.Set(_BrickHeight); BrickShift_Variable.Set(_BrickShift); MortarThickness_Variable.Set(_MortarThickness); }
protected override void Read(BinaryReaderEx br) { br.BigEndian = false; br.AssertASCII("DLsE"); br.AssertByte(1); br.AssertByte(3); br.AssertByte(0); br.AssertByte(0); br.AssertInt32(0); br.AssertInt32(0); br.AssertByte(0); br.AssertInt32(1); short classNameCount = br.ReadInt16(); var classNames = new List <string>(classNameCount); for (int i = 0; i < classNameCount; i++) { int length = br.ReadInt32(); classNames.Add(br.ReadASCII(length)); } Effect = new FXEffect(br, classNames); }
public override void Init( FXEffect m_effect , FXConstantBuffer m_cb ) { /// Bind the random Texture RandomTex_Variable = m_effect.GetResourceByName(VariableName + "_RandomTex"); /// Get the variables from Constant buffer MinValue_Variable = m_cb.GetMemberByName<float>( VariableName + "_MinValue" ); MaxValue_Variable = m_cb.GetMemberByName<float>( VariableName + "_MaxValue" ); Tile_X_Variable = m_cb.GetMemberByName<float>( VariableName + "_Tile_X" ); Tile_Y_Variable = m_cb.GetMemberByName<float>( VariableName + "_Tile_Y" ); Loops_Variable = m_cb.GetMemberByName<int>( VariableName + "_Loops" ); // create and set random texture SetRandomTex(_Seed); // set the values of the variables MinValue_Variable.Set(_MinValue); MaxValue_Variable.Set(_MaxValue); Loops_Variable.Set(_Loops); Tile_X_Variable.Set(_Tile_X); Tile_Y_Variable.Set(_Tile_Y); }
/// <summary> /// Precompile the shader /// </summary> /// <param name="Name"></param> public ComputeShader( String Name ) { Device dev = Engine.g_device; IncludeFX includeFX = new IncludeFX(); ShaderBytecode bytecode= null; // check that the shader is exist if ( File.Exists( ShaderRootPath + Name ) ) { // open the file to read it FileStream fileStream = new FileStream( ShaderRootPath + Name, FileMode.Open ); // allocate the byte stream byte []fileByte = new byte[fileStream.Length]; // read the file stream fileStream.Read( fileByte, 0, (int)fileStream.Length ); // close the file stream fileStream.Close(); bytecode = new ShaderBytecode(fileByte); } else { System.Windows.Forms.MessageBox.Show( "Shader:" + ShaderRootPath + Name + " is not exist " ); return; } // init effect m_effect = new FXEffect( dev, csByteCode: bytecode ); }
/// <summary> /// Compile Runtime the shader /// </summary> /// <param name="Name"></param> /// <param name="entryPoint"></param> public ComputeShader( String Name, String entryPoint , String IncludePath = null) { Device dev = Engine.g_device; // init the include class and subpath IncludeFX includeFX = new IncludeFX(); if ( IncludePath == null ) { includeFX.IncludeDirectory = System.Windows.Forms.Application.StartupPath + "\\ComputeHLSL\\"; } else { includeFX.IncludeDirectory = IncludePath; } ShaderBytecode bytecode= null; ShaderFlags sf; // select the shaders flags for if ( Settings.Debug ) { sf = ShaderFlags.SkipOptimization | ShaderFlags.Debug | ShaderFlags.PreferFlowControl; } else { sf = ShaderFlags.OptimizationLevel3; } // set the compile level base on running Feature level. String CompileLevelCS; if (Settings.FeatureLevel == FeatureLevel.Level_11_0) { CompileLevelCS = "cs_5_0"; } else { CompileLevelCS = "cs_4_0"; } /// compile the shader to byte code bytecode = ShaderBytecode.CompileFromFile( ShaderRootPath + Name, /// File Path of the file containing the code entryPoint, /// The name of the executable function CompileLevelCS, /// What specifications (shader version) to compile with cs_4_0 for directX10 and cs_5_0 for directx11 sf, EffectFlags.None, null, includeFX); // init effect m_effect = new FXEffect( dev, csByteCode: bytecode ); }
public Shader(String Name, String VS_EntryPoint = "VS_Main", String PS_EntryPoint = "PS_Main", String GS_EntryPoint = "GS_Main", Boolean PreCompiled = false) { Device dev = Engine.g_device; IncludeFX includeFX = new IncludeFX(); if ( PreCompiled ) { // check that the shader is exist if ( File.Exists( ShaderRootPath + Name + "o" ) ) { // open the file to read it FileStream fileStream = new FileStream( ShaderRootPath + Name + "o", FileMode.Open ); // allocate the byte stream byte[] fileByte = new byte[fileStream.Length]; // read the file stream fileStream.Read( fileByte, 0, (int)fileStream.Length ); // close the file stream fileStream.Close(); DataStream preBuildShaderStream = new DataStream( fileByte.Length, true, true ); preBuildShaderStream.Write(fileByte, 0, fileByte.Length); m_PixelShaderByteCode = new ShaderBytecode( preBuildShaderStream ); m_VertexShaderByteCode = new ShaderBytecode( preBuildShaderStream ); } else { System.Windows.Forms.MessageBox.Show( "Shader:" + ShaderRootPath + Name + "o" + " is not exist " ); return; } } else { // set the shader flags base on the debugging ShaderFlags sf; if ( Settings.Debug ) { sf = ShaderFlags.SkipOptimization | ShaderFlags.Debug | ShaderFlags.PreferFlowControl; } else { sf = ShaderFlags.OptimizationLevel3; } // set the compile feature String CompileLevelPS; String CompileLevelVS; String CompileLevelGS; if (Settings.FeatureLevel == FeatureLevel.Level_11_0) { CompileLevelPS = "ps_5_0"; CompileLevelVS = "vs_5_0"; CompileLevelGS = "gs_5_0"; } else { CompileLevelPS = "ps_4_0"; CompileLevelVS = "vs_4_0"; CompileLevelGS = "gs_4_0"; } try { /// compile the shader to byte code m_PixelShaderByteCode = ShaderBytecode.CompileFromFile( ShaderRootPath + Name, /// File Path of the file containing the code PS_EntryPoint, /// The entry point for the shader CompileLevelPS, /// What specifications (shader version) to compile with sf, EffectFlags.None, null, includeFX); /// compile the shader to byte code m_VertexShaderByteCode = ShaderBytecode.CompileFromFile( ShaderRootPath + Name, /// File Path of the file containing the code VS_EntryPoint, /// The entry point for the shader CompileLevelVS, /// What specifications (shader version) to compile with sf, EffectFlags.None, null, includeFX); try { /// compile the shader to byte code m_GeometryShaderByteCode = ShaderBytecode.CompileFromFile( ShaderRootPath + Name, /// File Path of the file containing the code GS_EntryPoint, /// The entry point for the shader CompileLevelGS, /// What specifications (shader version) to compile with sf, EffectFlags.None, null, includeFX); }catch(Exception ex) { // the geometry shader is not mandatory } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } /// init effect m_effect = new FXEffect( dev, m_PixelShaderByteCode, m_VertexShaderByteCode, null, m_GeometryShaderByteCode ); /// init all the variables InitVariables(); }
public FFXDLSE() { Effect = new FXEffect(); }
public virtual void Init( FXEffect m_effect, FXConstantBuffer m_cb ) { }