protected void SetupRenderer() { try { Renderable.Initialize(Device); FieldPlane.Initialize(); ColorMapping.Initialize(Device); PointCloud.Initialize(); LineBall.Initialize(); Mesh.Initialize(); Device.ImmediateContext.OutputMerger.SetTargets(_host.RenderTargetView); Device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, _host.RenderTargetWidth, _host.RenderTargetHeight, 0.0f, 1.0f)); _renderables = new List <Renderable>(); Camera = new Camera(Device, ((float)_host.RenderTargetWidth) / _host.RenderTargetHeight); var desc = new RasterizerStateDescription { CullMode = CullMode.None, FillMode = FillMode.Solid }; Device.ImmediateContext.Rasterizer.State = RasterizerState.FromDescription(Device, desc); SetupCuda(); AlgorithmCuda.Initialize(ContextCuda, Device); FlowMapUncertain.Initialize(); CutDiffusion.Initialize(); LocalDiffusion.Initialize(); } catch (Exception e) { Console.WriteLine(e); } }
/// <summary> /// When a colormap is set, set the associated texture as colormap. /// </summary> protected void SetColormapResources() { if (UsedMap == null) { return; } System.Diagnostics.Debug.Assert(_effect != null); _effect?.GetVariableByName("colormap")?.AsResource().SetResource(ColorMapping.GetColormapTexture((Colormap)UsedMap)); _effect?.GetVariableByName("minMap")?.AsScalar().Set(LowerBound); _effect?.GetVariableByName("maxMap")?.AsScalar().Set(UpperBound); }
/// <summary> /// Add one field given as texture. /// </summary> /// <param name="field"></param> public void AddScalar(ScalarField field) { ShaderResourceView[] cpy = _fieldTextures; _fieldTextures = new ShaderResourceView[_fieldTextures.Length + 1]; Array.Copy(cpy, _fieldTextures, cpy.Length); Texture2D tex = ColorMapping.GenerateTextureFromField(_device, field); _fieldTextures[cpy.Length] = new ShaderResourceView(_device, tex); SetRenderEffect(Effect); }
/// <summary> /// Plane to display scalar/vector field data on. Condition: Fields domain is 2D. /// </summary> /// <param name="origin"></param> /// <param name="xAxis"></param> /// <param name="yAxis"></param> /// <param name="scale">Scaling the field extent.</param> /// <param name="field"></param> public FieldPlane(Plane plane, VectorField fields, RenderEffect effect = RenderEffect.DEFAULT, Colormap map = Colormap.Parula) { #if DEBUG // Assert that the fields are 2 dimensional. foreach (Field field in fields.Scalars) { System.Diagnostics.Debug.Assert(field.Size.Length >= 2); } #endif this._effect = _planeEffect; this._vertexSizeBytes = 32; this._numVertices = 6; this.UsedMap = map; this._width = fields[0].Size[0]; this._height = fields[0].Size[1]; this._invalid = fields.InvalidValue ?? float.MaxValue; this._field = fields; // Setting up the vertex buffer. GenerateGeometry(plane, fields[0].Size.ToInt2(), fields.TimeSlice ?? 0); // Generating Textures from the fields. _fieldTextures = new ShaderResourceView[fields.Scalars.Length]; for (int f = 0; f < _field.NumVectorDimensions; ++f) { Texture2D tex = ColorMapping.GenerateTextureFromField(_device, fields[f]); _fieldTextures[f] = new ShaderResourceView(_device, tex); } this.SetRenderEffect(effect); this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXTURE", 0, Format.R32G32B32A32_Float, 16, 0) }); }
private void RefreshPlane() { _dataMap = new FieldPlane[1]; switch (_currentSetting.Shader) { case FieldPlane.RenderEffect.LIC: { var tmp = _velocity.GetTimeSlice(_currentSetting.SliceTimeMain); tmp.TimeSlice = null; _dataMap[0] = new FieldPlane(_subrangePlane, tmp, _currentSetting.Shader, _currentSetting.Colormap); _dataMap[0].AddScalar(_diffusionMap.Map); RefreshBoundsPlanes(); break; } case FieldPlane.RenderEffect.LIC_LENGTH: { _dataMap = new FieldPlane[2]; var tmp = _velocity.GetTimeSlice(_currentSetting.SliceTimeMain); tmp.TimeSlice = null; _dataMap[0] = new FieldPlane(_subrangePlane, tmp, _currentSetting.Shader, ColorMapping.GetComplementary(_currentSetting.Colormap)); _dataMap[0].LowerBound = 0; _dataMap[0].UpperBound = 20; _dataMap[1] = new FieldPlane(_subrangePlane, _diffusionMap.Map, (_velocity.Size).ToInt2(), 0, 0, FieldPlane.RenderEffect.OVERLAY, _currentSetting.Colormap); _dataMap[1].LowerBound = 0; _dataMap[1].UpperBound = _currentSetting.WindowWidth; //if (_currentSetting.Shader == FieldPlane.RenderEffect.LIC) // _dataMap[0].AddScalar(_diffusionMap.ReferenceMap); break; } case FieldPlane.RenderEffect.OVERLAY: default: _dataMap[0] = _diffusionMap.GetPlane(_subrangePlane); _dataMap[0].UsedMap = _currentSetting.Colormap; _dataMap[0].SetRenderEffect(_currentSetting.Shader); RefreshBoundsPlanes(); break; } }