/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> /// <param name="deviceContext">The device context.</param> protected override void OnRender(IRenderContext context, DeviceContextProxy deviceContext) { perFrameCB.UploadDataToBuffer(deviceContext, ref FrameVariables); // Clear binding updatePass.GetShader(ShaderStage.Compute).BindUAV(deviceContext, currentStateSlot, null); updatePass.GetShader(ShaderStage.Compute).BindUAV(deviceContext, newStateSlot, null); OnTextureChanged(); OnBlendStateChanged(); // Render existing particles renderPass.BindShader(deviceContext); renderPass.BindStates(deviceContext, StateType.RasterState | StateType.DepthStencilState); renderPass.GetShader(ShaderStage.Vertex).BindTexture(deviceContext, renderStateSlot, BufferProxies[0].SRV); renderPass.GetShader(ShaderStage.Pixel).BindTexture(deviceContext, textureSlot, textureView); renderPass.GetShader(ShaderStage.Pixel).BindSampler(deviceContext, samplerSlot, textureSampler); deviceContext.DeviceContext.InputAssembler.InputLayout = VertexLayout; deviceContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList; int firstSlot = 0; InstanceBuffer?.AttachBuffer(deviceContext, ref firstSlot); deviceContext.DeviceContext.OutputMerger.SetBlendState(blendState, null, 0xFFFFFFFF); deviceContext.DeviceContext.DrawInstancedIndirect(particleCountGSIABuffer.Buffer, 0); InvalidateRenderer();//Since particle is running all the time. Invalidate once finished rendering }
public override void OnEnable() { base.OnEnable(); if (m_mesh == null) { return; } if (m_data_transfer_mode == DataTransferMode.Buffer && !SystemInfo.supportsComputeShaders) { Debug.Log("BatchRenderer: ComputeBuffer is not available. fallback to Texture data transfer mode."); m_data_transfer_mode = DataTransferMode.Texture; } if (m_data_transfer_mode == DataTransferMode.TextureWithPlugin && !BatchRendererUtil.IsCopyToTextureAvailable()) { Debug.Log("BatchRenderer: CopyToTexture plugin is not available. fallback to Texture data transfer mode."); m_data_transfer_mode = DataTransferMode.Texture; } m_instance_data = new InstanceData(); if (m_data_transfer_mode == DataTransferMode.Buffer) { m_instance_buffer = new InstanceBuffer(); } else { m_instance_texture = new InstanceTexture(); } ResetGPUData(); }
/// <summary> /// Attach vertex buffer routine /// </summary> /// <param name="context"></param> /// <param name="vertStartSlot"></param> protected override bool OnAttachBuffers(DeviceContextProxy context, ref int vertStartSlot) { bool succ = GeometryBuffer.AttachBuffers(context, this.VertexLayout, ref vertStartSlot, EffectTechnique.EffectsManager); InstanceBuffer?.AttachBuffer(context, ref vertStartSlot); return(succ); }
/// <summary> /// Used to override Detach /// </summary> protected override void OnDetach() { bufferModelInternal = null; InstanceBuffer.DisposeAndClear(); BoundManager.DisposeAndClear(); base.OnDetach(); }
public override void OnEnable() { base.OnEnable(); if (m_mesh == null) { return; } m_instance_data = new InstanceData(); ReleaseGPUData(); if (m_data_transfer_mode == DataTransferMode.Buffer) { m_instance_buffer = new InstanceBuffer(); } else { m_instance_texture = new InstanceTexture(); if (m_data_transfer_mode == DataTransferMode.TextureWithMesh) { m_data_transfer_mesh = BatchRendererUtil.CreateDataTransferMesh(m_max_instances); } } ResetGPUData(); }
public void Dispose() { InstanceBuffer.Dispose(); MaterialBuffer.Dispose(); PassCB.Dispose(); CmdListAlloc.Dispose(); }
/// <summary> /// Called when [attach]. /// </summary> /// <param name="host">The host.</param> /// <returns></returns> protected override bool OnAttach(IRenderHost host) { base.OnAttach(host); InstanceBuffer.Initialize(); InstanceBuffer.Elements = Instances; particleCore.InstanceBuffer = InstanceBuffer; return(true); }
protected override bool OnAttach(IEffectsManager effectsManager) { base.OnAttach(effectsManager); InstanceBuffer.Initialize(); InstanceBuffer.Elements = Instances; particleCore.InstanceBuffer = InstanceBuffer; return(true); }
protected override void OnRender(RenderContext renderContext) { /// --- set constant paramerers var worldMatrix = modelMatrix * renderContext.WorldMatrix; EffectTransforms.mWorld.SetMatrix(ref worldMatrix); /// --- check shadowmaps hasShadowMap = renderHost.IsShadowMapEnabled; effectMaterial.bHasShadowMapVariable.Set(hasShadowMap); effectMaterial.AttachMaterial(geometryInternal as MeshGeometry3D); /// --- check instancing hasInstances = (Instances != null) && (Instances.Any()); if (bHasInstances != null) { bHasInstances.Set(hasInstances); } /// --- set context Device.ImmediateContext.InputAssembler.InputLayout = vertexLayout; Device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; Device.ImmediateContext.InputAssembler.SetIndexBuffer(IndexBuffer.Buffer, Format.R32_UInt, 0); /// --- set rasterstate Device.ImmediateContext.Rasterizer.State = RasterState; if (hasInstances) { /// --- update instance buffer if (isInstanceChanged) { InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, Instances.ToArray()); isInstanceChanged = false; } /// --- INSTANCING: need to set 2 buffers Device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new[] { new VertexBufferBinding(VertexBuffer.Buffer, VertexBuffer.StructureSize, 0), new VertexBufferBinding(InstanceBuffer.Buffer, InstanceBuffer.StructureSize, 0), }); /// --- render the geometry effectTechnique.GetPassByIndex(0).Apply(Device.ImmediateContext); /// --- draw Device.ImmediateContext.DrawIndexedInstanced(Geometry.Indices.Count, Instances.Count, 0, 0, 0); } else { /// --- bind buffer Device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer.Buffer, VertexBuffer.StructureSize, 0)); /// --- render the geometry effectTechnique.GetPassByIndex(0).Apply(Device.ImmediateContext); /// --- draw Device.ImmediateContext.DrawIndexed(Geometry.Indices.Count, 0, 0); } }
private void ShutdownBuffers() { // Release the Instance buffer. InstanceBuffer?.Dispose(); InstanceBuffer = null; // Release the vertex buffer. VertexBuffer?.Dispose(); VertexBuffer = null; }
public void UpdateGPUInstanceBuffer() { InstanceBuffer.SetDynamicData(InstanceBuffer.GraphicsDevice, (ptr) => { System.Runtime.InteropServices.Marshal.Copy(InstanceDataRAM.ToArray(), 0, ptr, InstanceDataRAM.Count); }, 0, SetDataOptions.Discard); }
public void Dispose() { foreach (var batch in DrawCalls.Values) { batch.Dispose(); } InstanceBuffer.Dispose(); }
protected override void OnRender(RenderContext renderContext) { // --- set constant paramerers var worldMatrix = this.modelMatrix * renderContext.WorldMatrix; this.effectTransforms.mWorld.SetMatrix(ref worldMatrix); // --- check shadowmaps this.hasShadowMap = this.renderHost.IsShadowMapEnabled; this.effectMaterial.bHasShadowMapVariable.Set(this.hasShadowMap); // --- set material params this.effectMaterial.AttachMaterial(); this.bHasInstances.Set(this.hasInstances); // --- set context renderContext.DeviceContext.InputAssembler.InputLayout = this.vertexLayout; renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; renderContext.DeviceContext.InputAssembler.SetIndexBuffer(this.IndexBuffer.Buffer, Format.R32_UInt, 0); // --- set rasterstate renderContext.DeviceContext.Rasterizer.State = this.rasterState; if (this.hasInstances) { // --- update instance buffer if (this.isInstanceChanged) { InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.instanceInternal); this.isInstanceChanged = false; } // --- INSTANCING: need to set 2 buffers renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new[] { new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0), new VertexBufferBinding(this.InstanceBuffer.Buffer, this.InstanceBuffer.StructureSize, 0), }); // --- render the geometry this.effectTechnique.GetPassByIndex(0).Apply(renderContext.DeviceContext); // --- draw renderContext.DeviceContext.DrawIndexedInstanced(this.geometryInternal.Indices.Count, this.instanceInternal.Count, 0, 0, 0); this.bHasInstances.Set(false); } else { // --- bind buffer renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0)); // --- render the geometry // var pass = this.effectTechnique.GetPassByIndex(0); pass.Apply(renderContext.DeviceContext); // --- draw renderContext.DeviceContext.DrawIndexed(this.geometryInternal.Indices.Count, 0, 0); } }
private void ShutdownBuffers() { InstanceBuffer?.Dispose(); InstanceBuffer = null; VertexBuffer?.Dispose(); VertexBuffer = null; Instances = null; }
/// <summary> /// Used to override Detach /// </summary> protected override void OnDetach() { if (RenderCore is IGeometryRenderCore core) { core.GeometryBuffer = null; } RemoveAndDispose(ref bufferModelInternal); InstanceBuffer.DisposeAndClear(); BoundManager.DisposeAndClear(); base.OnDetach(); }
/// <summary> /// Attach vertex buffer routine /// </summary> /// <param name="context"></param> /// <param name="vertStartSlot"></param> protected virtual bool OnAttachBuffers(DeviceContextProxy context, ref int vertStartSlot) { if (GeometryBuffer.AttachBuffers(context, ref vertStartSlot, EffectTechnique.EffectsManager)) { InstanceBuffer.AttachBuffer(context, ref vertStartSlot); return(true); } else { return(false); } }
protected override void OnRender(RenderContext renderContext) { this.bHasInstances.Set(this.hasInstances); // --- set constant paramerers var worldMatrix = this.modelMatrix * renderContext.worldMatrix; this.EffectTransforms.mWorld.SetMatrix(ref worldMatrix); // --- check shadowmaps this.hasShadowMap = this.renderHost.IsShadowMapEnabled; this.effectMaterial.bHasShadowMapVariable.Set(this.hasShadowMap); this.effectMaterial.AttachMaterial(geometryInternal as MeshGeometry3D); // --- set context renderContext.DeviceContext.InputAssembler.InputLayout = this.vertexLayout; renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; renderContext.DeviceContext.InputAssembler.SetIndexBuffer(this.IndexBuffer.Buffer, Format.R32_UInt, 0); // --- set rasterstate renderContext.DeviceContext.Rasterizer.State = this.RasterState; renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0)); hasBonesVar.Set(hasBoneParameter && hasBoneMatrices); if (hasBoneMatrices) { boneMatricesVar.SetMatrix(mBones.Bones); } if (this.hasBoneParameter) { if (isBoneParamChanged && this.VertexBoneIds.Count >= geometryInternal.Positions.Count) { vertexBoneParamsBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.VertexBoneIds); this.isBoneParamChanged = false; } renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(this.vertexBoneParamsBuffer.Buffer, this.vertexBoneParamsBuffer.StructureSize, 0)); } if (this.hasInstances) { // --- update instance buffer if (this.isInstanceChanged) { InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.instanceInternal); this.isInstanceChanged = false; } renderContext.DeviceContext.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(this.InstanceBuffer.Buffer, this.InstanceBuffer.StructureSize, 0)); OnInstancedDrawCall(renderContext); } else { // --- bind buffer renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0)); OnDrawCall(renderContext); } }
protected override void OnRender(RenderContext renderContext) { // --- set constant paramerers var worldMatrix = this.modelMatrix * renderContext.worldMatrix; this.EffectTransforms.mWorld.SetMatrix(ref worldMatrix); // --- check shadowmaps this.hasShadowMap = this.renderHost.IsShadowMapEnabled; this.effectMaterial.bHasShadowMapVariable.Set(this.hasShadowMap); // --- set material params this.effectMaterial.AttachMaterial(geometryInternal as MeshGeometry3D); this.bInvertNormalVar.Set(invertNormal); this.bHasInstances.Set(this.hasInstances); // --- set context renderContext.DeviceContext.InputAssembler.InputLayout = this.vertexLayout; renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; renderContext.DeviceContext.InputAssembler.SetIndexBuffer(this.IndexBuffer.Buffer, Format.R32_UInt, 0); // --- set rasterstate renderContext.DeviceContext.Rasterizer.State = this.RasterState; if (this.hasInstances) { // --- update instance buffer if (this.isInstanceChanged) { InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.instanceInternal); this.isInstanceChanged = false; } // --- INSTANCING: need to set 2 buffers renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new[] { new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0), new VertexBufferBinding(this.InstanceBuffer.Buffer, this.InstanceBuffer.StructureSize, 0), }); OnInstancedDrawCall(renderContext); this.bHasInstances.Set(false); } else { // --- bind buffer renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0)); OnDrawCall(renderContext); } this.bInvertNormalVar.Set(false); }
public void SetInstanceBuffer(VertexBuffer NewInstanceBuffer, List <Matrix> InstanceCollisionData) { if (InstanceBuffer != null) { InstanceBuffer.Dispose(); } if (InstanceCollisionBuffer.Count > 0) { InstanceCollisionBuffer.Clear(); } InstanceCollisionBuffer.AddRange(InstanceCollisionData); InstanceBuffer = NewInstanceBuffer; }
public ParticleList(RTSRenderer renderer, int maxCount, ParticleType pt) { Type = pt; // Make The Lists particles = new List <PType>(); vertices = new VType[maxCount]; // Create The Instance Buffer InstanceBuffer = renderer.CreateDynamicVertexBuffer(vertices[0].VertexDeclaration, MaxCount, BufferUsage.WriteOnly); InstanceBuffer.SetData(vertices); VBBinds = new VertexBufferBinding[2]; VBBinds[1] = new VertexBufferBinding(InstanceBuffer, 0, 1); }
public void OnEnable() { if (!SystemInfo.supportsComputeShaders) { Debug.Log("ProceduralGBuffer: ComputeBuffer is not available."); } if (m_mesh == null) { return; } m_instance_data = new InstanceData(); m_instance_buffer = new InstanceBuffer(); ResetGPUData(); }
/// <summary> /// This function initialize the Geometry Buffer and Instance Buffer /// </summary> /// <param name="host"></param> /// <returns> /// Return true if attached /// </returns> protected override bool OnAttach(IRenderHost host) { if (base.OnAttach(host)) { CreateGeometryBuffer(); BoundManager.Geometry = Geometry; InstanceBuffer.Initialize(); InstanceBuffer.Elements = this.Instances; if (RenderCore is IGeometryRenderCore r) { r.InstanceBuffer = InstanceBuffer; } return(true); } else { return(false); } }
/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> /// <param name="deviceContext">The device context.</param> protected override void OnRender(RenderContext context, DeviceContextProxy deviceContext) { perFrameCB.UploadDataToBuffer(deviceContext, ref FrameVariables); // Clear binding updatePass.ComputeShader.BindUAV(deviceContext, currentStateSlot, null); updatePass.ComputeShader.BindUAV(deviceContext, newStateSlot, null); // Render existing particles renderPass.BindShader(deviceContext); renderPass.BindStates(deviceContext, StateType.RasterState | StateType.DepthStencilState); renderPass.VertexShader.BindTexture(deviceContext, renderStateSlot, BufferProxies[0]); renderPass.PixelShader.BindTexture(deviceContext, textureSlot, textureView); renderPass.PixelShader.BindSampler(deviceContext, samplerSlot, textureSampler); deviceContext.InputLayout = VertexLayout; int firstSlot = 0; InstanceBuffer?.AttachBuffer(deviceContext, ref firstSlot); deviceContext.SetBlendState(blendState, blendFactor, sampleMask); deviceContext.DrawInstancedIndirect(particleCountGSIABuffer.Buffer, 0); InvalidateRenderer();//Since particle is running all the time. Invalidate once finished rendering }
public void Update(List <Particle> newParticles, float dt) { // Update The Particles Action <Particle> fp = (p) => { p.Update(dt); }; particles.AsParallel().ForAll(fp); bool add = particles.RemoveAll(Particle.IsParticleDead) > 0; // Add New Particles for (int i = 0; i < newParticles.Count; i++) { if (newParticles[i] == null) { continue; } if (newParticles[i].Type == Type) { particles.Add(newParticles[i] as PType); add = true; } } if (add) { // Make Sure We Don't Run Over if (particles.Count > MaxCount) { particles.RemoveRange(0, particles.Count - MaxCount); } for (int i = 0; i < particles.Count; i++) { vertices[i] = (VType)particles[i].Vertex; } InstanceBuffer.SetData(vertices); } }
/// <summary> /// Attach vertex buffer routine /// </summary> /// <param name="context"></param> /// <param name="vertStartSlot"></param> protected override void OnAttachBuffers(DeviceContext context, ref int vertStartSlot) { GeometryBuffer.AttachBuffers(context, this.VertexLayout, ref vertStartSlot, EffectTechnique.EffectsManager); InstanceBuffer?.AttachBuffer(context, ref vertStartSlot); }
public override void OnEnable() { base.OnEnable(); if (m_mesh == null) return; if (m_data_transfer_mode == DataTransferMode.Buffer && !SystemInfo.supportsComputeShaders) { Debug.Log("BatchRenderer: ComputeBuffer is not available. fallback to Texture data transfer mode."); m_data_transfer_mode = DataTransferMode.Texture; } if (m_data_transfer_mode == DataTransferMode.TextureWithPlugin && !BatchRendererUtil.IsCopyToTextureAvailable()) { Debug.Log("BatchRenderer: CopyToTexture plugin is not available. fallback to Texture data transfer mode."); m_data_transfer_mode = DataTransferMode.Texture; } m_instance_data = new InstanceData(); if (m_data_transfer_mode == DataTransferMode.Buffer) { m_instance_buffer = new InstanceBuffer(); } else { m_instance_texture = new InstanceTexture(); } ResetGPUData(); }
public override void OnEnable() { base.OnEnable(); if (m_mesh == null) return; m_instance_data = new InstanceData(); ReleaseGPUData(); if (m_data_transfer_mode == DataTransferMode.Buffer) { m_instance_buffer = new InstanceBuffer(); } else { m_instance_texture = new InstanceTexture(); if (m_data_transfer_mode == DataTransferMode.TextureWithMesh) { m_data_transfer_mesh = BatchRendererUtil.CreateDataTransferMesh(m_max_instances); } } ResetGPUData(); }
/// <summary> /// Called when [detach]. /// </summary> protected override void OnDetach() { InstanceBuffer.Dispose(); base.OnDetach(); }
protected override void OnRender(RenderContext renderContext) { // --- since these values are changed only per window resize, we set them only once here //if (this.isResized || renderContext.Camera != this.lastCamera) { //this.isResized = false; //this.lastCamera = renderContext.Camera; if (renderContext.Camera is ProjectionCamera) { var c = renderContext.Camera as ProjectionCamera; // viewport: W,H,0,0 var viewport = new Vector4((float)renderContext.Canvas.ActualWidth, (float)renderContext.Canvas.ActualHeight, 0, 0); var ar = viewport.X / viewport.Y; this.vViewport.Set(ref viewport); // Actually, we don't really need vFrustum because we already know the depth of the projected line. //var fov = 100.0; // this is a fake value, since the line shader does not use it! //var zn = c.NearPlaneDistance > 0 ? c.NearPlaneDistance : 0.1; //var zf = c.FarPlaneDistance + 0.0; // frustum: FOV,AR,N,F //var frustum = new Vector4((float)fov, (float)ar, (float)zn, (float)zf); //this.vFrustum.Set(ref frustum); } } // --- set transform paramerers var worldMatrix = this.modelMatrix * renderContext.worldMatrix; this.EffectTransforms.mWorld.SetMatrix(ref worldMatrix); // --- set effect per object const vars this.vLineParams.Set(lineParams); // --- set context renderContext.DeviceContext.InputAssembler.InputLayout = this.vertexLayout; renderContext.DeviceContext.InputAssembler.SetIndexBuffer(this.IndexBuffer.Buffer, Format.R32_UInt, 0); renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList; this.bHasInstances.Set(this.hasInstances); // --- set rasterstate renderContext.DeviceContext.Rasterizer.State = this.RasterState; if (this.hasInstances) { // --- update instance buffer if (this.isInstanceChanged) { InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.instanceInternal); this.isInstanceChanged = false; } // --- INSTANCING: need to set 2 buffers renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new[] { new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0), new VertexBufferBinding(this.InstanceBuffer.Buffer, this.InstanceBuffer.StructureSize, 0), }); // --- render the geometry for (int i = 0; i < this.effectTechnique.Description.PassCount; i++) { this.effectTechnique.GetPassByIndex(i).Apply(renderContext.DeviceContext); renderContext.DeviceContext.DrawIndexedInstanced(this.geometryInternal.Indices.Count, this.instanceInternal.Count, 0, 0, 0); } this.bHasInstances.Set(false); } else { // --- bind buffer renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0)); // --- render the geometry this.effectTechnique.GetPassByIndex(0).Apply(renderContext.DeviceContext); renderContext.DeviceContext.DrawIndexed(this.geometryInternal.Indices.Count, 0, 0); } }
public void OnEnable() { if (!SystemInfo.supportsComputeShaders) { Debug.Log("ProceduralGBuffer: ComputeBuffer is not available."); } if (m_mesh == null) return; m_instance_data = new InstanceData(); m_instance_buffer = new InstanceBuffer(); ResetGPUData(); }
protected override void OnRender(RenderContext renderContext) { // --- check to render the model var geometry = geometryInternal as IBillboardText; if (geometry == null) { throw new System.Exception("Geometry must implement IBillboardText"); } this.bHasInstances.Set(this.hasInstances); this.hasInstanceParamVar.Set(this.hasInstanceParams); // --- set constant paramerers var worldMatrix = modelMatrix * renderContext.worldMatrix; EffectTransforms.mWorld.SetMatrix(ref worldMatrix); this.bFixedSizeVariable.Set(FixedSize); // --- check shadowmaps //this.hasShadowMap = this.renderHost.IsShadowMapEnabled; //this.effectMaterial.bHasShadowMapVariable.Set(this.hasShadowMap); // --- set context renderContext.DeviceContext.InputAssembler.InputLayout = vertexLayout; renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip; // --- set rasterstate renderContext.DeviceContext.Rasterizer.State = RasterState; // --- bind buffer renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer.Buffer, VertexBuffer.StructureSize, 0)); // --- render the geometry this.bHasBillboardTexture.Set(geometry.Texture != null); if (geometry.Texture != null) { billboardTextureVariable.SetResource(billboardTextureView); } this.bHasBillboardAlphaTexture.Set(geometry.AlphaTexture != null); if (geometry.AlphaTexture != null) { billboardAlphaTextureVariable.SetResource(billboardAlphaTextureView); } var vertexCount = geometryInternal.Positions.Count; if (this.hasInstances) { if (this.isInstanceChanged) { InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.instanceInternal); this.isInstanceChanged = false; } renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(this.InstanceBuffer.Buffer, this.InstanceBuffer.StructureSize, 0)); if (this.hasInstanceParams) { if (instanceParamArrayChanged) { instanceParamBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.InstanceParamArray); this.instanceParamArrayChanged = false; } renderContext.DeviceContext.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(this.instanceParamBuffer.Buffer, this.instanceParamBuffer.StructureSize, 0)); } switch (billboardType) { case BillboardType.SingleImage: // Use foreground shader to draw text effectTechnique.GetPassByIndex(2).Apply(renderContext.DeviceContext); // --- draw text, foreground vertex is beginning from 0. renderContext.DeviceContext.DrawInstanced(vertexCount, this.instanceInternal.Count, 0, 0); break; case BillboardType.SingleText: if (vertexCount == 8) { var half = vertexCount / 2; // Use background shader to draw background first effectTechnique.GetPassByIndex(1).Apply(renderContext.DeviceContext); // --- draw background, background vertex is beginning from middle. <see cref="BillboardSingleText3D"/> renderContext.DeviceContext.DrawInstanced(half, this.instanceInternal.Count, half, 0); // Use foreground shader to draw text effectTechnique.GetPassByIndex(0).Apply(renderContext.DeviceContext); // --- draw text, foreground vertex is beginning from 0. renderContext.DeviceContext.DrawInstanced(half, this.instanceInternal.Count, 0, 0); } break; } } this.bHasInstances.Set(false); this.hasInstanceParamVar.Set(false); }
public void Dispose() { EffectParameters.Dispose(); InstanceBuffer.Dispose(); }
public void UpdateInstanceBuffer() { // dirty flag? InstanceBuffer.SetData(Instances_); }
public StaticInstancedMeshGeometry(int maxInstances, IDrawBatch geometry) { this.geometry = geometry; //setup the data for static instancing //create the static instance buffer this.staticInstanceBuffer = new InstanceBuffer(maxInstances); }