/// <summary> /// Initializes a new instance of the <see cref="UserInterfaceRenderer10"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="width">The width of the renderable area.</param> /// <param name="height">The height of the renderable area.</param> public UserInterfaceRenderer10(D3D.Device device, int width, int height) { if (device == null) throw new ArgumentNullException("device"); if (width < 0) throw new ArgumentException("Value must be positive.", "width"); if (height < 0) throw new ArgumentException("Value must be positive.", "height"); this.device = device; halfWidth = width / 2; halfHeight = height / 2; font = new D3D.Font(device, 18, 0, D3D.FontWeight.Bold, 0, false, D3D.FontCharacterSet.Default, D3D.FontPrecision.Default, D3D.FontQuality.Antialiased, D3D.FontPitchAndFamily.Default, "Arial"); sprite = new SlimDX.Direct3D10.Sprite(device, 0); lineBuffer = new DynamicPrimitiveBuffer10<ColoredVertex>(device); Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream("SampleFramework.Resources.UserInterface10.fx")) using (StreamReader reader = new StreamReader(stream)) { effect = D3D.Effect.FromString(device, reader.ReadToEnd(), "fx_4_0"); } technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); ShaderSignature signature = pass.Description.Signature; inputLayout = new D3D.InputLayout(device, signature, new[] { new D3D.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0), new D3D.InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, D3D.InputElement.AppendAligned, 0 ) }); }
public D3D.InputLayout GetOrCreateLayout(VertexBufferBinding[] vbuffers, int numBuffers) { //Take care of the trivial cases if (numBuffers == 1) { return(GetOrCreateLayout(vbuffers[0])); } else if (numBuffers == 0) { throw new TeslaException("Error creating input layout - cannot draw!"); } //Clear semantic index array ClearSemanticIndices(); //Make sure we aren't trying to do too much if (numBuffers >= vbuffers.Length) { throw new ArgumentOutOfRangeException("numBuffers", "Number of vertex declarations to merge is greater than number of vertex buffers given."); } //Do we have an input layout that matches? int key = GenerateKey(vbuffers, numBuffers); D3D.InputLayout layout; if (!_layoutMap.TryGetValue(key, out layout)) { //If not, need to loop over each vertex buffer and create a layout from each declaration try { D3D.InputElement[] elements = new D3D.InputElement[GetVertexElementCount(vbuffers, numBuffers)]; int index = 0; for (int i = 0; i < numBuffers; i++) { VertexBufferBinding binding = vbuffers[i]; VertexDeclaration decl = binding.VertexBuffer.VertexDeclaration; int offset = 0; //Every new stream, reset offset for (int j = 0; j < decl.ElementCount; j++) { VertexElement element = decl[j]; element.SemanticIndex = IncrementSemanticIndex(element.SemanticName); element.Offset = offset; elements[index++] = GenerateInputElement(element, i, binding.InstanceFrequency); offset += VertexDeclaration.GetVertexElementSize(element.Format); } } layout = new D3D.InputLayout(_device, _sig, elements); } catch (Exception e) { throw new TeslaException("Error setting vertex declaration, it does not match the shader's input signature. Either there is an invalid element, or the declaration does not have enough elements.", e); } //If we're good, add it to the map _layoutMap.Add(key, layout); } return(layout); }
/// <summary> /// Initializes a new instance of the <see cref="UserInterfaceRenderer10"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="width">The width of the renderable area.</param> /// <param name="height">The height of the renderable area.</param> public UserInterfaceRenderer10(D3D.Device device, int width, int height) { if (device == null) { throw new ArgumentNullException("device"); } if (width < 0) { throw new ArgumentException("Value must be positive.", "width"); } if (height < 0) { throw new ArgumentException("Value must be positive.", "height"); } this.device = device; halfWidth = width / 2; halfHeight = height / 2; font = new D3D.Font(device, 18, 0, D3D.FontWeight.Bold, 0, false, D3D.FontCharacterSet.Default, D3D.FontPrecision.Default, D3D.FontQuality.Antialiased, D3D.FontPitchAndFamily.Default, "Arial"); sprite = new SlimDX.Direct3D10.Sprite(device, 0); lineBuffer = new DynamicPrimitiveBuffer10 <ColoredVertex>(device); Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream("SampleFramework.Resources.UserInterface10.fx")) using (StreamReader reader = new StreamReader(stream)) { effect = D3D.Effect.FromString(device, reader.ReadToEnd(), "fx_4_0"); } technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); ShaderSignature signature = pass.Description.Signature; inputLayout = new D3D.InputLayout(device, signature, new[] { new D3D.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0), new D3D.InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, D3D.InputElement.AppendAligned, 0) }); }
public D3D.InputLayout CreateLayout(VertexDeclaration declaration) { int key = declaration.GetHashCode(); D3D.InputLayout layout; if (!_layoutMap.TryGetValue(key, out layout)) { try { D3D.InputElement[] elements = new D3D.InputElement[declaration.ElementCount]; for (int i = 0; i < elements.Length; i++) { elements[i] = GenerateInputElement(declaration[i], 0, 0); } layout = new D3D.InputLayout(_device, _sig, elements); } catch (Exception e) { throw new TeslaException("Error setting vertex declaration, it does not match the shader's input signature. Either there is an invalid element, or the declaration does not have enough elements.", e); } _layoutMap.Add(key, layout); } return(layout); }
public Sky(Vector3 lightDir, StreamReader file) { /// // outerRadius = innerRadius * 1.0157313f; // atmScale = 1f / (outerRadius - innerRadius); dome.CreateDome((int)size.X, (int)size.Y); // waveLength4 = new Vector3((float)Math.Pow(waveLength.X, 4), (float)Math.Pow(waveLength.Y, 4), (float)Math.Pow(waveLength.Z, 4)); // double pow = -0.84; // waveLength084 = new Vector3((float)Math.Pow(waveLength.X, pow), (float)Math.Pow(waveLength.Y, pow), (float)Math.Pow(waveLength.Z, pow)); effect = ResourceManager.mainManager.LoadEffect("Resources\\Effects\\Sky.fx", ResourceManager.mainManager.GetDefaultEffectPool()); pass = effect.GetTechniqueByName("Render").GetPassByIndex(0); updatePass = effect.GetTechniqueByName("Update").GetPassByIndex(0); D3D10.InputElement[] elements = new SlimDX.Direct3D10.InputElement[2]; elements[0] = new SlimDX.Direct3D10.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0); elements[1] = new D3D10.InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 12, 0); layout = new SlimDX.Direct3D10.InputLayout(Game.gameClass.GetDevice(), elements, pass.Description.Signature); layoutUpdate = Quad.GetLayout(updatePass); translation = effect.GetVariableByName("translation").AsVector(); sunPosition = effect.GetVariableByName("sunPos").AsVector(); // Vector4 mieTemps = new Vector4((3 * (1 - g * g)) / (2 * (2 + g * g)), 1 + g * g, g, 1); mieTemps = effect.GetVariableByName("mieTemps").AsVector(); K = effect.GetVariableByName("K").AsVector(); waveLengthRay = effect.GetVariableByName("waveLengthRay").AsVector(); waveLengthMie = effect.GetVariableByName("waveLengthMie").AsVector(); scaleDepth = effect.GetVariableByName("scaleDepth").AsVector(); sunIntensity = effect.GetVariableByName("sunIntensity").AsScalar(); //textures D3D10.Texture2DDescription desc = new SlimDX.Direct3D10.Texture2DDescription(); desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.ShaderResource | SlimDX.Direct3D10.BindFlags.RenderTarget; desc.CpuAccessFlags = D3D10.CpuAccessFlags.None; desc.Format = SlimDX.DXGI.Format.R16G16B16A16_Float; desc.Height = (int)size.Y; desc.MipLevels = 1; desc.OptionFlags = D3D10.ResourceOptionFlags.None; desc.Usage = D3D10.ResourceUsage.Default; desc.Width = (int)size.X; SlimDX.DXGI.SampleDescription sampleDescription = new SlimDX.DXGI.SampleDescription(); sampleDescription.Count = 1; sampleDescription.Quality = 0; desc.SampleDescription = sampleDescription; rayLookupTexture = new D3D10.Texture2D(Game.gameClass.GetDevice(), desc); mieLookupTexture = new D3D10.Texture2D(Game.gameClass.GetDevice(), desc); /* desc.BindFlags = D3D10.BindFlags.None; desc.CpuAccessFlags = D3D10.CpuAccessFlags.Write; desc.Usage = D3D10.ResourceUsage.Staging; mieUpdateTexture = new D3D10.Texture2D(Game.gameClass.GetDevice(), desc); rayUpdateTexture = new D3D10.Texture2D(Game.gameClass.GetDevice(), desc); mieUpdateTextureMap = mieUpdateTexture.Map(0, D3D10.MapMode.Write, D3D10.MapFlags.DoNotWait); mieUpdateTexture.Unmap(0); rayUpdateTextureMap = rayUpdateTexture.Map(0, D3D10.MapMode.Write, D3D10.MapFlags.DoNotWait); rayUpdateTexture.Unmap(0);*/ using (D3D10.ShaderResourceView view = new SlimDX.Direct3D10.ShaderResourceView(Game.gameClass.GetDevice(), rayLookupTexture)) effect.GetVariableByName("rayLookupTex").AsResource().SetResource(view); using (D3D10.ShaderResourceView view = new SlimDX.Direct3D10.ShaderResourceView(Game.gameClass.GetDevice(), mieLookupTexture)) effect.GetVariableByName("mieLookupTex").AsResource().SetResource(view); viewPort = new Viewport(); viewPort.Height = (int)size.Y; viewPort.Width = (int)size.X; viewPort.MaxZ = 1.0f; viewPort.MinZ = 0.0f; viewPort.X = 0; viewPort.Y = 0; renderTargets[0] = new SlimDX.Direct3D10.RenderTargetView(Game.gameClass.GetDevice(), rayLookupTexture); renderTargets[1] = new SlimDX.Direct3D10.RenderTargetView(Game.gameClass.GetDevice(), mieLookupTexture); Load(file); CalculateLookupOnGPU(-lightDir); }
public static D3D.InputLayout GetInputLayout(D3D.Device device, D3D.EffectPass pass, Type vertexType) { D3D.InputElement[] inputElements = GetInputElements(vertexType); D3D.InputLayout layout = new D3D.InputLayout(device, pass.Description.Signature, inputElements); return layout; }
//creation functions public Terrain(int q, StreamReader file) { quadSize = q; //loading effect effect = ResourceManager.mainManager.LoadEffect("Resources\\Effects\\Terrain.fx", ResourceManager.mainManager.GetDefaultEffectPool()); technique = effect.GetTechniqueByName("Render"); pass = technique.GetPassByIndex(0); //creating layout D3D10.InputElement[] elements = new SlimDX.Direct3D10.InputElement[1]; elements[0] = new SlimDX.Direct3D10.InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 0, 0, D3D10.InputClassification.PerVertexData, 0); layout = new SlimDX.Direct3D10.InputLayout(Game.gameClass.GetDevice(), elements, pass.Description.Signature); //loading texture D3D10.ImageLoadInformation load = new SlimDX.Direct3D10.ImageLoadInformation(); load.BindFlags = D3D10.BindFlags.ShaderResource; load.CpuAccessFlags = D3D10.CpuAccessFlags.None; load.MipLevels = 1; load.Usage=D3D10.ResourceUsage.Default; load.OptionFlags = D3D10.ResourceOptionFlags.None; load.FilterFlags = D3D10.FilterFlags.Point; load.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm; normalTexture = D3D10.Texture2D.FromFile(Game.gameClass.GetDevice(), Path.GetDirectoryName(Game.gameClass.GetLvLFilePath()) + "\\normals.png", load); Globals.mapSize = normalTexture.Description.Width; if (Game.gameClass.GetEngineState() != EngineState.play) { D3D10.Texture2DDescription desc = new SlimDX.Direct3D10.Texture2DDescription(); desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.None; desc.CpuAccessFlags = D3D10.CpuAccessFlags.Write; desc.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm; desc.Height = Globals.mapSize; desc.Width = Globals.mapSize; desc.Usage = D3D10.ResourceUsage.Staging; desc.MipLevels = 1; SlimDX.DXGI.SampleDescription sampleDescription = new SlimDX.DXGI.SampleDescription(); sampleDescription.Count = 1; sampleDescription.Quality = 0; desc.SampleDescription = sampleDescription; normalTexUpdater = new SlimDX.Direct3D10.Texture2D(Game.gameClass.GetDevice(), desc); normalData = normalTexUpdater.Map(0, D3D10.MapMode.Write, D3D10.MapFlags.DoNotWait); normalTexUpdater.Unmap(0); } // LoadTextureArray(file); //setting up vertices and creating vertex buffer LoadVertexInfo(); CreateVertexBuffer(); //constant buffer variables effect.GetVariableByName("mapSize").AsScalar().Set(Globals.mapSize); using(D3D10.ShaderResourceView normalView=new D3D10.ShaderResourceView(Game.gameClass.GetDevice(),normalTexture)) effect.GetVariableByName("normalMap").AsResource().SetResource(normalView); // using (D3D10.ShaderResourceView texturesView = new D3D10.ShaderResourceView(Game.gameClass.GetDevice(), textures)) // effect.GetVariableByName("textures").AsResource().SetResource(texturesView); orientations=effect.GetVariableByName("orientations").AsVector(); // effect.GetVariableByName("texCoordMul").AsScalar().Set(TextureInfo.texCoordMul); heightMul = effect.GetVariableByName("heightMul").AsScalar(); heightMul.Set(Globals.heightMultiplier); //handles edit mode if (Game.gameClass.GetEngineState() != EngineState.play) { techniqueEdit = effect.GetTechniqueByName("Edit"); passEdit = techniqueEdit.GetPassByIndex(0); mousePick = effect.GetVariableByName("mousePick").AsVector(); pickOptions = effect.GetVariableByName("pickOpt").AsVector(); } Globals.SetMap(map); }
public void BindToRenderPass(D3DDevice device, Effect effect, int passIndex) { renderPassIndex = passIndex; renderPassLayout = VertexTypes.GetInputLayout(this.Device.Device, effect[passIndex], typeof(VertexTypes.Pos3Norm3Tex3)); }
void DisposeManaged() { if (gsOutput != null) gsOutput.Dispose(); gsOutput = null; if (renderPassLayout != null) renderPassLayout.Dispose(); renderPassLayout = null; }