Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="deviceContext"></param>
        protected override void OnUpdate(IRenderContext context, DeviceContextProxy deviceContext)
        {
            UpdateTime(context, ref totalElapsed);
            //Set correct instance count from instance buffer
            drawArgument.InstanceCount = InstanceBuffer == null || !InstanceBuffer.HasElements ? 1 : (uint)InstanceBuffer.Buffer.ElementCount;
            //Upload the draw argument
            particleCountGSIABuffer.UploadDataToBuffer(deviceContext, ref drawArgument);

            updatePass.BindShader(deviceContext);
            updatePass.GetShader(ShaderStage.Compute).BindUAV(deviceContext, currentStateSlot, BufferProxies[0].UAV);
            updatePass.GetShader(ShaderStage.Compute).BindUAV(deviceContext, newStateSlot, BufferProxies[1].UAV);

            if (isRestart)
            {
                FrameVariables.NumParticles = 0;
                perFrameCB.UploadDataToBuffer(deviceContext, ref FrameVariables);
                // Call ComputeShader to add initial particles
                deviceContext.DeviceContext.Dispatch(1, 1, 1);
                isRestart = false;
            }
            else
            {
                #region Get consume buffer count
                // Get consume buffer count.
                //Due to some intel integrated graphic card having issue copy structure count directly into constant buffer.
                //Has to use staging buffer to read and pass into constant buffer
                FrameVariables.NumParticles = (uint)ReadCount("", deviceContext, BufferProxies[0]);
                perFrameCB.UploadDataToBuffer(deviceContext, ref FrameVariables);
                #endregion

                deviceContext.DeviceContext.Dispatch(Math.Max(1, (int)Math.Ceiling((double)FrameVariables.NumParticles / 512)), 1, 1);
                // Get append buffer count
                BufferProxies[1].CopyCount(deviceContext, particleCountGSIABuffer.Buffer, 0);
            }

#if OUTPUTDEBUGGING
            ReadCount("UAV 0", deviceContext, BufferProxies[0].UAV);
#endif


            if (totalElapsed > InsertElapseThrottle)
            {
                insertCB.UploadDataToBuffer(deviceContext, ref InsertVariables);
                // Add more particles
                insertPass.BindShader(deviceContext);
                insertPass.GetShader(ShaderStage.Compute).BindUAV(deviceContext, newStateSlot, BufferProxies[1].UAV);
                deviceContext.DeviceContext.Dispatch(1, 1, 1);
                totalElapsed = 0;
#if OUTPUTDEBUGGING
                ReadCount("UAV 1", deviceContext, BufferProxies[1].UAV);
#endif
            }

            // Swap UAV buffers for next frame
            var bproxy = BufferProxies[0];
            BufferProxies[0] = BufferProxies[1];
            BufferProxies[1] = bproxy;
        }
        /// <summary>
        /// Sets the screen spaced coordinates.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="deviceContext">The device context.</param>
        /// <param name="clearDepthBuffer">if set to <c>true</c> [clear depth buffer].</param>
        protected virtual void SetScreenSpacedCoordinates(IRenderContext context, DeviceContextProxy deviceContext, bool clearDepthBuffer)
        {
            context.WorldMatrix = Matrix.Identity;
            DepthStencilView dsView;

            if (clearDepthBuffer)
            {
                deviceContext.DeviceContext.OutputMerger.GetRenderTargets(out dsView);
                if (dsView == null)
                {
                    return;
                }

                deviceContext.DeviceContext.ClearDepthStencilView(dsView, DepthStencilClearFlags.Depth, 1f, 0);
                dsView.Dispose();
            }

            float viewportSize = Size * SizeScale;
            var   globalTrans  = context.GlobalTransform;

            UpdateProjectionMatrix((float)context.ActualWidth, (float)context.ActualHeight);
            globalTrans.View           = CreateViewMatrix(context, out globalTrans.EyePos);
            globalTrans.Projection     = projectionMatrix;
            globalTrans.ViewProjection = globalTrans.View * globalTrans.Projection;
            globalTrans.Viewport       = new Vector4(viewportSize, viewportSize, 0, 0);
            globalTransformCB.UploadDataToBuffer(deviceContext, ref globalTrans);
            GlobalTransform = globalTrans;
            int offX = (int)(Width / 2 * (1 + RelativeScreenLocationX) - viewportSize / 2);
            int offY = (int)(Height / 2 * (1 - RelativeScreenLocationY) - viewportSize / 2);

            deviceContext.DeviceContext.Rasterizer.SetViewport(offX, offY, viewportSize, viewportSize);
            deviceContext.DeviceContext.Rasterizer.SetScissorRectangle(offX, offY, (int)viewportSize + offX, (int)viewportSize + offY);
        }
Beispiel #3
0
 protected override void OnUploadPerModelConstantBuffers(DeviceContext context)
 {
     base.OnUploadPerModelConstantBuffers(context);
     if (BoneMatrices.Bones != null)
     {
         boneCB.UploadDataToBuffer(context, BoneMatrices.Bones, BoneMatricesStruct.NumberOfBones);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Call to update constant buffer for per frame
 /// </summary>
 public void UpdatePerFrameData()
 {
     if (matrixChanged)
     {
         globalTransform.View           = ViewMatrix;
         globalTransform.Projection     = ProjectionMatrix;
         globalTransform.ViewProjection = globalTransform.View * globalTransform.Projection;
         screenViewProjectionMatrix     = ViewMatrix * ProjectionMatrix * ViewportMatrix;
         matrixChanged = false;
     }
     cbuffer.UploadDataToBuffer(DeviceContext, ref globalTransform);
     LightScene.UploadToBuffer(DeviceContext);
 }
 protected override void OnUploadPerModelConstantBuffers(DeviceContext context)
 {
     base.OnUploadPerModelConstantBuffers(context);
     clipParamCB.UploadDataToBuffer(context, ref clipParameter);
 }