public TriadVoxelizer(ComputeShaderLinker csLinker, Shader voxelizer, AbstractVoxelBounds voxelBounds, int prefferedResolution) { this.csLinker = csLinker; this.voxelizer = voxelizer; this.shaderConstants = ShaderConstants.Instance; this.cameraDirection = new VoxelCameraDirection(); this.renderCam = new ManuallyRenderCamera((cam) => cameraDirection.FitCameraToVoxelBounds(cam, voxelBounds)); this.colorTextures = new VoxelTexture[DIRECTIONS.Length]; for (var i = 0; i < colorTextures.Length; i++) { colorTextures [i] = GenerateVoxelTexture(prefferedResolution); } this.resultTex = GenerateVoxelTexture(prefferedResolution); }
public TestSprite(Device device, DVector3 Position) { this.Position = Position; MMesh = ContentManager.LoadMesh("Content/Models/BaseSprite.mesh"); EEEM = ContentManager.LoadEffect("Content/Shaders/BaseSprite"); TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl"); // Подготовка константного буффера BufferDescription bd = new BufferDescription(); bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants)); bd.Usage = ResourceUsage.Dynamic; bd.BindFlags = BindFlags.ConstantBuffer; bd.CpuAccessFlags = CpuAccessFlags.Write; bd.OptionFlags = ResourceOptionFlags.None; bd.StructureByteStride = 0; constantsBuffer = new Buffer(device, bd); constants = new ShaderConstants(); }
public GSSprite(Device device, DVector3 Position) { //float3 Position //12 //half2 Size //16 //half4 AABBTexCoord //24 //half4 AditiveColor //32 InputElement[] elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R16G16_Float, 12, 0), new InputElement("TEXCOORD", 1, Format.R16G16B16A16_Float, 16, 0), new InputElement("TEXCOORD", 2, Format.R16G16B16A16_Float, 24, 0), }; BytesPerVertex = 32; VertexsCount = 1; var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true); vertices.Write(Conversion.ToVector3(Position)); vertices.Write(new Half2(10, 10)); vertices.Write(new Half4(0, 0, 1, 1)); vertices.Write(new Half4(1, 0, 0, 1)); vertices.Position = 0; Vertexs = new Buffer(device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0); binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0); vertices.Dispose(); this.Position = Position; EEEM = ContentManager.LoadEffect("Content/Shaders/GSSprite", elements); TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl"); // Подготовка константного буффера BufferDescription bd = new BufferDescription(); bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants)); bd.Usage = ResourceUsage.Dynamic; bd.BindFlags = BindFlags.ConstantBuffer; bd.CpuAccessFlags = CpuAccessFlags.Write; bd.OptionFlags = ResourceOptionFlags.None; bd.StructureByteStride = 0; constantsBuffer = new Buffer(device, bd); constants = new ShaderConstants(); }
public static void Init(Device device) { InputElement[] elements11 = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32_Float, 12, 0), }; EEEM = ContentManager.LoadEffect("Content/Shaders/Line", elements11); // Подготовка константного буффера BufferDescription bd = new BufferDescription(); bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants)); bd.Usage = ResourceUsage.Dynamic; bd.BindFlags = BindFlags.ConstantBuffer; bd.CpuAccessFlags = CpuAccessFlags.Write; bd.OptionFlags = ResourceOptionFlags.None; bd.StructureByteStride = 0; constantsBuffer = new Buffer(device, bd); constants = new ShaderConstants(); Vertexs = new Buffer(device, BytesPerVertex * VertexsCount, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0); binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0); CurrentBufferSize = 4; }
void OnEnable() { shaderConstants = ShaderConstants.Instance; viewSpaceBounds = new ViewSpaceBounds(); }
public static void Init(Device device) { #region Sampler SamplerStateDescription desc = new SamplerStateDescription(); desc.AddressU = TextureAddressMode.Wrap; desc.AddressV = TextureAddressMode.Wrap; desc.AddressW = TextureAddressMode.Wrap; desc.Filter = Filter.MinMagMipLinear; SamplLinWrap = new SamplerState(ModelViewer.Program.device, desc); desc.Filter = Filter.MinMagMipPoint; SamplPntWrap = new SamplerState(ModelViewer.Program.device, desc); desc.Filter = Filter.Anisotropic; if (Global.Settings.TextureFiltering > -1) desc.MaximumAnisotropy = System.Math.Min(Global.Settings.TextureFiltering, 16); else desc.MaximumAnisotropy = 0; SamplAnsWrap = new SamplerState(ModelViewer.Program.device, desc); desc.MaximumAnisotropy = 0; desc.MinimumLod = 0; desc.MaximumLod = 7; desc.Filter = Filter.MinMagMipLinear; SamplLinWrapMip = new SamplerState(ModelViewer.Program.device, desc); desc.Filter = Filter.MinMagMipPoint; SamplPntWrapMip = new SamplerState(ModelViewer.Program.device, desc); desc.Filter = Filter.Anisotropic; if (Global.Settings.TextureFiltering > -1) desc.MaximumAnisotropy = System.Math.Min(Global.Settings.TextureFiltering, 16); else desc.MaximumAnisotropy = 0; SamplAnsWrapMip = new SamplerState(ModelViewer.Program.device, desc); #endregion OcclViewport = new Viewport(0, 0, OcclPixelInTex, 1); OcclTexture = new Texture2D[1]; OcclSRV = new ShaderResourceView[1]; OcclRTV = new RenderTargetView[1]; InitOcclInd(0); MConteints = new MeshContainer(); MConteints.BytesPerVertex = 12; MConteints.FaceCount = 2; MConteints.VertexsCount = 4; var vertices = new DataStream(MConteints.BytesPerVertex * MConteints.VertexsCount, true, true); vertices.Write(new Vector3(0.0f, 0.0f, 0.5f)); vertices.Write(new Vector3(1.0f, 0.0f, 0.5f)); vertices.Write(new Vector3(1.0f, 1.0f, 0.5f)); vertices.Write(new Vector3(0.0f, 1.0f, 0.5f)); vertices.Position = 0; MConteints.Vertexs = new Buffer(device, vertices, MConteints.BytesPerVertex * MConteints.VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); var indices = new DataStream(4 * MConteints.FaceCount * 3, true, true); indices.Write(0); indices.Write(1); indices.Write(2); indices.Write(2); indices.Write(3); indices.Write(0); indices.Position = 0; MConteints.Indices = new Buffer(device, indices, 4 * MConteints.FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); MConteints.binding = new VertexBufferBinding(MConteints.Vertexs, MConteints.BytesPerVertex, 0); InputElement[] elements11 = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0) }; EEEM = ContentManager.LoadEffect("Content/Shaders/OcclusionTest", elements11); // Подготовка константного буффера BufferDescription bd = new BufferDescription(); bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants)); bd.Usage = ResourceUsage.Dynamic; bd.BindFlags = BindFlags.ConstantBuffer; bd.CpuAccessFlags = CpuAccessFlags.Write; bd.OptionFlags = ResourceOptionFlags.None; bd.StructureByteStride = 0; constantsBuffer = new Buffer(device, bd); constants = new ShaderConstants(); constants.Resolution = new Vector4(Global.Settings.Width, Global.Settings.Height, OcclPixelInTex, 1); constants.WM = Matrix.Transpose(Matrix.OrthoLH(constants.Resolution.X, constants.Resolution.Y, 0.1f, 1000)); LensBatching.Init(device); PSSMsHelper.Init(device); }
public static void Init(Device device) { MasterRequest = new Request[128]; SlaveRequest = new Request[128]; for (int i = 0; i < MasterRequest.Length; i++) { MasterRequest[i] = new Request(); SlaveRequest[i] = new Request(); } //float3 Position //12 //half2 Size //16 //half4 AABBTexCoord //24 //half4 AditiveColor //32 InputElement[] elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R16G16_Float, 12, 0), new InputElement("TEXCOORD", 1, Format.R16G16B16A16_Float, 16, 0), new InputElement("TEXCOORD", 2, Format.R16G16B16A16_Float, 24, 0), }; Vertexs = new Buffer(device, BytesPerVertex * MassSize, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0); //binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0); EEEM = ContentManager.LoadEffect("Content/Shaders/GSSprite", elements); // Подготовка константного буффера BufferDescription bd = new BufferDescription(); bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants)); bd.Usage = ResourceUsage.Dynamic; bd.BindFlags = BindFlags.ConstantBuffer; bd.CpuAccessFlags = CpuAccessFlags.Write; bd.OptionFlags = ResourceOptionFlags.None; bd.StructureByteStride = 0; constantsBuffer = new Buffer(device, bd); constants = new ShaderConstants(); //int t = Utils.GetBinResize(17); }
public static void Init(Device device, int W, int H) { #region Mesh _MConteints = new MeshContainer(); _MConteints.BytesPerVertex = 12; _MConteints.FaceCount = 2; _MConteints.VertexsCount = 4; var vertices = new DataStream(_MConteints.BytesPerVertex * _MConteints.VertexsCount, true, true); vertices.Write(new Vector3(0.0f, 0.0f, 0.5f)); vertices.Write(new Vector3(1.0f, 0.0f, 0.5f)); vertices.Write(new Vector3(1.0f, 1.0f, 0.5f)); vertices.Write(new Vector3(0.0f, 1.0f, 0.5f)); vertices.Position = 0; _MConteints.Vertexs = new Buffer(device, vertices, _MConteints.BytesPerVertex * _MConteints.VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); var indices = new DataStream(4 * _MConteints.FaceCount * 3, true, true); indices.Write(0); indices.Write(1); indices.Write(2); indices.Write(2); indices.Write(3); indices.Write(0); indices.Position = 0; _MConteints.Indices = new Buffer(device, indices, 4 * _MConteints.FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); _MConteints.binding = new VertexBufferBinding(_MConteints.Vertexs, _MConteints.BytesPerVertex, 0); InputElement[] elements11 = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0) }; EEEM = ContentManager.LoadEffect("Content/Shaders/QuadShader", elements11); // Подготовка константного буффера BufferDescription bd = new BufferDescription(); bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants)); bd.Usage = ResourceUsage.Dynamic; bd.BindFlags = BindFlags.ConstantBuffer; bd.CpuAccessFlags = CpuAccessFlags.Write; bd.OptionFlags = ResourceOptionFlags.None; bd.StructureByteStride = 0; constantsBuffer = new Buffer(device, bd); constants = new ShaderConstants(); constants.Resolution = new Vector4(W, H, 0, 0); constants.WM = Matrix.OrthoLH(constants.Resolution.X, constants.Resolution.Y, 0.1f, 1000); #endregion //RenderTargets Texture2DDescription BufDescription = new Texture2DDescription(); BufDescription.MipLevels = 1; BufDescription.ArraySize = 1; BufDescription.Width = W/4; BufDescription.Height = H/4; BufDescription.Format = Format.R8G8B8A8_UNorm; BufDescription.SampleDescription = new SampleDescription(1, 0); BufDescription.Usage = ResourceUsage.Default; BufDescription.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource; BufDescription.CpuAccessFlags = CpuAccessFlags.None; BufDescription.OptionFlags = ResourceOptionFlags.None; BufTexture_1 = new Texture2D(device, BufDescription); BufTexture_2 = new Texture2D(device, BufDescription); BufSRV_1 = new ShaderResourceView(device, BufTexture_1); BufSRV_2 = new ShaderResourceView(device, BufTexture_2); RenderTargetViewDescription RTVD = new RenderTargetViewDescription(); RTVD.Format = BufDescription.Format; RTVD.Dimension = RenderTargetViewDimension.Texture2D; RTVD.Texture2DArray.FirstArraySlice = 0; RTVD.Texture2DArray.ArraySize = 1; RTVD.Texture2D.MipSlice = 0; BufRTV_1 = new RenderTargetView(device, BufTexture_1, RTVD); BufRTV_2 = new RenderTargetView(device, BufTexture_2, RTVD); BufDescription.Width = W / 2; BufDescription.Height = H / 2; BufDescription.MipLevels = 0; BufDescription.OptionFlags = ResourceOptionFlags.GenerateMipMaps; BufDescription.Format = Format.R32G32B32A32_Float; RTVD.Format = BufDescription.Format; BufTexture_3 = new Texture2D(device, BufDescription); BufSRV_3 = new ShaderResourceView(device, BufTexture_3); BufRTV_3 = new RenderTargetView(device, BufTexture_3, RTVD); SamplerStateDescription sd = new SamplerStateDescription(); sd.AddressU = TextureAddressMode.Clamp; sd.AddressV = TextureAddressMode.Clamp; sd.AddressW = TextureAddressMode.Clamp; sd.Filter = Filter.MinMagMipLinear; sd.MinimumLod = 0; sd.MaximumLod = 16; BufSS = new SamplerState(device, ref sd); HDRViewport = new Viewport(0, 0, W / 4, H / 4); DoubleHDRViewport = new Viewport(0, 0, W / 2, H / 2); BufDescription = new Texture2DDescription(); BufDescription.MipLevels = 1; BufDescription.ArraySize = 1; BufDescription.Width = 1; BufDescription.Height = 1; BufDescription.Format = Format.R32G32B32A32_Float; BufDescription.SampleDescription = new SampleDescription(1, 0); BufDescription.Usage = ResourceUsage.Default; BufDescription.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource; BufDescription.CpuAccessFlags = CpuAccessFlags.None; BufDescription.OptionFlags = ResourceOptionFlags.None; RTVD = new RenderTargetViewDescription(); RTVD.Format = BufDescription.Format; RTVD.Dimension = RenderTargetViewDimension.Texture2D; RTVD.Texture2DArray.FirstArraySlice = 0; RTVD.Texture2DArray.ArraySize = 1; RTVD.Texture2D.MipSlice = 0; T1x1 = new Texture2D(device, BufDescription); V1x1 = new Viewport(0, 0, 1, 1); SRV1x1 = new ShaderResourceView(device, T1x1); RTV1x1 = new RenderTargetView(device, T1x1, RTVD); device.ImmediateContext.ClearRenderTargetView(BufRTV_3, new Color4(0.0f, 0.0f, 0.0f, 1f)); }
public MultiMeshContainer(Engine.Serialize.MeshesContainer MC) { if (MC != null) { //Transform = Matrix.Scaling(1); Hardpoints = MC.HardPoints; if (MC.Materials != null && MC.Geometry != null && MC.Geometry.Meshes != null) { BSP = MC.Geometry.BSP; LocalAABBMax = MC.Geometry.AABBMax; LocalAABBMin = MC.Geometry.AABBMin; Meshes = new Serialize.MeshLink[MC.Materials.Length]; Materials = new MaterialContainer[MC.Materials.Length]; for (int i = 0; i < MC.Materials.Length; i++) { Meshes[i] = MC.Geometry.Meshes[i]; Materials[i] = new MaterialContainer(MC.Materials[i]); } VertexsCount = MC.Geometry.VertexCount; BytesPerVertex = MC.Geometry.VertexData.Length / VertexsCount; FaceCount = MC.Geometry.IndexData.Length / 12; using (var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true)) { vertices.WriteRange<byte>(MC.Geometry.VertexData, 0, MC.Geometry.VertexData.Length); vertices.Position = 0; Vertexs = new Buffer(ModelViewer.Program.device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0); } using (var indices = new DataStream(4 * FaceCount * 3, true, true)) { indices.WriteRange<byte>(MC.Geometry.IndexData, 0, MC.Geometry.IndexData.Length); indices.Position = 0; Indices = new Buffer(ModelViewer.Program.device, indices, 4 * FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); } BufferDescription bd = new BufferDescription(); bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants)); bd.Usage = ResourceUsage.Dynamic; bd.BindFlags = BindFlags.ConstantBuffer; bd.CpuAccessFlags = CpuAccessFlags.Write; bd.OptionFlags = ResourceOptionFlags.None; bd.StructureByteStride = 0; constantsBuffer = new Buffer(ModelViewer.Program.device, bd); constants = new ShaderConstants(); } } }