Exemple #1
0
        private void RenderBasic(DX11RenderContext context)
        {
            quadshader.SelectTechnique("Render");
            quadgeometry.Bind(quadlayouts[0]);

            for (int i = 0; i < this.spmax; i++)
            {
                bool popstate = false;
                if (this.FInState.PluginIO.IsConnected)
                {
                    context.RenderStateStack.Push(this.FInState[i]);
                    popstate = true;
                }

                quadshader.SetBySemantic("COLOR", this.FInColor[i]);
                quadshader.SetBySemantic("WORLD", this.FInWorld[i]);
                quadshader.SetBySemantic("TEXTUREMATRIX", this.FInTexTransform[i]);

                quadshader.ApplyPass(0);

                quadgeometry.Draw();

                if (popstate)
                {
                    context.RenderStateStack.Pop();
                }
            }
        }
Exemple #2
0
        public void Update(DX11RenderContext context)
        {
            if (shaderSample == null)
            {
                shaderSample = new DX11ShaderInstance(context, effectSample);
                shaderLoad   = new DX11ShaderInstance(context, effectLoad);
            }

            DX11ShaderInstance instance = this.pixelCoords[0] ? shaderLoad : shaderSample;

            if (this.mipLevel.SliceCount > 1)
            {
                instance.SelectTechnique("ConstantLevel");
            }
            else
            {
                instance.SelectTechnique("DynamicLevel");
            }

            int totalCount;

            if (this.mipLevel.SliceCount > 1)
            {
                totalCount = SpreadUtils.SpreadMax(this.coordinates, this.mipLevel);

                instance.SetByName("UvCount", this.coordinates.SliceCount);
                instance.SetByName("LevelCount", this.mipLevel.SliceCount);
            }
            else
            {
                totalCount = this.coordinates.SliceCount;
                instance.SetByName("MipLevel", this.mipLevel[0]);
            }

            this.coordinateBuffer = this.coordinateBuffer.GetOrResize(context.Device, this.coordinates.SliceCount, 8);
            this.levelBuffer      = this.levelBuffer.GetOrResize(context.Device, this.mipLevel.SliceCount, 4);

            this.writeBuffer    = this.writeBuffer.GetOrResize(context.Device, totalCount, 16);
            this.readbackBuffer = this.readbackBuffer.GetOrResize(context.Device, totalCount, 16);

            instance.SetByName("TotalCount", totalCount);
            instance.SetByName("uvBuffer", coordinateBuffer.SRV);
            if (this.mipLevel.SliceCount > 1)
            {
                instance.SetByName("uvLevelBuffer", levelBuffer.SRV);
            }


            instance.SetByName("inputTexture", this.textureInput[0][context].SRV);
            instance.SetByName("OutputBuffer", writeBuffer.UAV);

            instance.ApplyPass(0);

            context.CurrentDeviceContext.CopyResource(this.writeBuffer.Buffer, this.readbackBuffer.Buffer);
        }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device        device = context.Device;
            DeviceContext ctx    = context.CurrentDeviceContext;

            if (!this.FOutPointcloudBuffer[0].Contains(context) || !this.FOutIndexBuffer[0].Contains(context) || this.FInEleCount.IsChanged)
            {
                this.FOutPointcloudBuffer[0].Dispose(context);
                this.FOutIndexBuffer[0].Dispose(context);
                DX11RWStructuredBuffer pcBuffer = new DX11RWStructuredBuffer(device, FInEleCount[0], FInStride[0], eDX11BufferMode.Counter);
                DX11RWStructuredBuffer idBuffer = new DX11RWStructuredBuffer(device, FInEleCount[0], 4, eDX11BufferMode.Counter);
                this.FOutPointcloudBuffer[0][context] = pcBuffer;
                this.FOutIndexBuffer[0][context]      = idBuffer;
            }

            // clear offsetbuffer
            int[] mask = new int[4] {
                -1, -1, -1, -1
            };
            ctx.ClearUnorderedAccessView(FOutIndexBuffer[0][context].UAV, mask);

            // load shader
            if (this.shader == null)
            {
                string     basepath = "RingBufferIndexing.effects.RingBufferIndexing.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);
                this.shader = new DX11ShaderInstance(context, effect);
            }

            if (this.FInPointcloudBuffer.PluginIO.IsConnected /* && currentFrame != FHDEHost.FrameTime*/)
            {
                currentFrame = FHDEHost.FrameTime; // prevents to execute this a second time

                shader.SelectTechnique("BuildHash");
                shader.SetBySemantic("POINTCLOUDBUFFERIN", FInPointcloudBuffer[0][context].SRV);
                shader.SetBySemantic("POINTCLOUDBUFFEROUT", FOutPointcloudBuffer[0][context].UAV, 0);
                shader.SetBySemantic("INDEXBUFFER", FOutIndexBuffer[0][context].UAV);

                shader.ApplyPass(0);
                ctx.Dispatch((FInEleCount[0] + 63) / 64, 1, 1);
                context.CleanUp();
                context.CleanUpCS();
            }
        }
Exemple #4
0
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device        device = context.Device;
            DeviceContext ctx    = context.CurrentDeviceContext;

            if (!this.FOutLinkBuffer[0].Contains(context) || !this.FOutOffsetBuffer[0].Contains(context) || FInGridcellCount.IsChanged)
            {
                this.FOutLinkBuffer[0].Dispose(context);
                this.FOutOffsetBuffer[0].Dispose(context);
                DX11RWStructuredBuffer lb = new DX11RWStructuredBuffer(device, FInEleCount[0], 8, eDX11BufferMode.Counter);
                DX11RWStructuredBuffer ob = new DX11RWStructuredBuffer(device, FInGridcellCount[0] * FInGridcellCount[0] * FInGridcellCount[0], 4, eDX11BufferMode.Counter);
                this.FOutLinkBuffer[0][context]   = lb;
                this.FOutOffsetBuffer[0][context] = ob;
            }

            // clear offsetbuffer
            int[] mask = new int[4] {
                -1, -1, -1, -1
            };
            ctx.ClearUnorderedAccessView(FOutOffsetBuffer[0][context].UAV, mask);

            // load shader
            if (this.shader == null)
            {
                string     basepath = "LinkedList.effects.LinkedList.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);
                this.shader = new DX11ShaderInstance(context, effect);
            }

            if (this.FInPcBuffer.PluginIO.IsConnected)
            {
                shader.SelectTechnique("BuildHash");
                shader.SetBySemantic("POINTCLOUDBUFFER", FInPcBuffer[0][context].SRV);
                shader.SetBySemantic("POINTTRANSFORM", FInTransform[0]);
                shader.SetBySemantic("RWLINKBUFFER", FOutLinkBuffer[0][context].UAV, 0);
                shader.SetBySemantic("RWOFFSETBUFFER", FOutOffsetBuffer[0][context].UAV);
                shader.SetBySemantic("GRIDCELLSIZE", FInGridcellCount[0]);

                shader.ApplyPass(0);
                ctx.Dispatch((FInEleCount[0] + 63) / 64, 1, 1);
                context.CleanUp();
                context.CleanUpCS();
            }
        }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device device = context.Device;
            DeviceContext ctx = context.CurrentDeviceContext;

            if ( !this.FOutPointcloudRingBuffer[0].Contains(context) || !this.FOutUpdatedBuffer[0].Contains(context) || !this.bCounter.Contains(context) || !this.bOffset.Contains(context) || this.FInPointcloudRingBufferSize.IsChanged || this.FInEleCount.IsChanged)
            {

                this.FOutPointcloudRingBuffer[0].Dispose(context);
                DX11RWStructuredBuffer brPointcloud = new DX11RWStructuredBuffer(device, FInPointcloudRingBufferSize[0], FInStride[0], eDX11BufferMode.Counter);
                this.FOutPointcloudRingBuffer[0][context] = brPointcloud;

                this.FOutUpdatedBuffer[0].Dispose(context);
                DX11RWStructuredBuffer brUpdated = new DX11RWStructuredBuffer(device, FInPointcloudRingBufferSize[0], 4, eDX11BufferMode.Counter);
                this.FOutUpdatedBuffer[0][context] = brUpdated;

                this.bOffset.Dispose(context);
                this.bOffset[context] = new DX11RawBuffer(device, 16);

                this.bCounter.Dispose(context);
                this.bCounter[context] = new DX11RWStructuredBuffer(device, FInEleCount[0], 4, eDX11BufferMode.Counter);

            }

            // load shader
            if (this.shader == null)
            {
                string basepath = "RingBuffer.effects.RingBuffer.fx";
                DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);
                this.shader = new DX11ShaderInstance(context, effect);
            }

            if (this.FInPointcloudBuffer.PluginIO.IsConnected && FInSet[0] && currentFrame != FHDEHost.FrameTime)
            {

                currentFrame = FHDEHost.FrameTime; // prevents to execute this a second time

                int[] mask = new int[4] { 0, 0, 0, 0 };
                ctx.ClearUnorderedAccessView(FOutUpdatedBuffer[0][context].UAV, mask);

                shader.SelectTechnique("AddPoints");
                shader.SetBySemantic("POINTCLOUDBUFFER", FInPointcloudBuffer[0][context].SRV);
                shader.SetBySemantic("POINTCLOUDCOUNTBUFFER", FInCountBuffer[0][context].SRV);
                shader.SetBySemantic("POINTCLOUDRINGBUFFER", FOutPointcloudRingBuffer[0][context].UAV, FInPointcloudRingBufferSize[0]);
                shader.SetBySemantic("UPDATEDRINGBUFFER", FOutUpdatedBuffer[0][context].UAV, FInPointcloudRingBufferSize[0]);
                shader.SetBySemantic("POINTCLOUDRINGBUFFERSIZE", FInPointcloudRingBufferSize[0]);
                shader.SetBySemantic("OFFSETBUFFER", this.bOffset[context].SRV);
                shader.SetBySemantic("COUNTERBUFFER", this.bCounter[context].UAV, 0);
                shader.ApplyPass(0);
                ctx.Dispatch((FInEleCount[0] + 63) / 64, 1, 1);

                ctx.CopyStructureCount(this.bCounter[context].UAV, this.bOffset[context].Buffer, 0);
                shader.SelectTechnique("CalcOffset");
                shader.ApplyPass(0);
                ctx.Dispatch(1, 1, 1);

                context.CleanUp();
                context.CleanUpCS();
                
            }

        }
Exemple #6
0
        public void Update(DX11RenderContext context)
        {
            if (resourceEntry != null)
            {
                resourceEntry.UnLock();
                resourceEntry = null;
            }

            if (!texture1.IsConnected)
            {
                this.textureOutput[0][context] = context.DefaultTextures.WhiteTexture;
                return;
            }

            if (this.texture1.SliceCount == 1)
            {
                this.textureOutput[0][context] = this.texture1[0][context];
                return;
            }

            if (instance == null)
            {
                instance = new DX11ShaderInstance(context, effect);
                vertexShadersInstance = new DX11ShaderInstance(context, vertexShadersEffect);
            }

            var width  = this.firstTextureAsSize[0] ? texture1[0][context].Width : (int)size[0].X;
            var height = this.firstTextureAsSize[0] ? texture1[0][context].Height : (int)size[0].Y;


            DX11ResourcePoolEntry <DX11RenderTarget2D> resourceRead  = context.ResourcePool.LockRenderTarget(width, height, SlimDX.DXGI.Format.R8G8B8A8_UNorm);
            DX11ResourcePoolEntry <DX11RenderTarget2D> resourceWrite = context.ResourcePool.LockRenderTarget(width, height, SlimDX.DXGI.Format.R8G8B8A8_UNorm);
            bool first = true;

            context.Primitives.FullScreenTriangle.Bind(null);

            for (int i = 0; i < this.texture1.SliceCount - 1; i++)
            {
                context.RenderTargetStack.Push(resourceWrite.Element);

                //First pass we need to apply both texture transform, next only second
                if (!first)
                {
                    instance.SetBySemantic("INPUTTEXTURE", resourceRead.Element.SRV);
                    vertexShadersInstance.SelectTechnique("ApplySecondOnly");
                }
                else
                {
                    instance.SetBySemantic("INPUTTEXTURE", texture1[0][context].SRV);
                    vertexShadersInstance.SelectTechnique("ApplyBoth");
                    vertexShadersInstance.SetByName("tTex1", this.textureTransform[0].AsTextureTransform());
                }

                instance.SetBySemantic("SECONDTEXTURE", texture1[i + 1][context].SRV);
                vertexShadersInstance.SetByName("tTex2", this.textureTransform[i + 1].AsTextureTransform());


                instance.SelectTechnique(mode[i].ToString());
                instance.SetByName("Opacity", alpha[i]);

                vertexShadersInstance.ApplyPass(0);
                instance.ApplyPass(0);


                context.Primitives.FullScreenTriangle.Draw();

                context.RenderTargetStack.Pop();
                first = false;

                var tmp = resourceWrite;
                resourceWrite = resourceRead;
                resourceRead  = tmp;
            }

            resourceWrite.UnLock();

            resourceEntry = resourceRead;
            this.textureOutput[0][context] = resourceRead.Element;
        }
        public void Update(DX11RenderContext context)
        {
            for (int i = 0; i < framePool.Count; i++)
            {
                framePool[i].UnLock();
            }
            framePool.Clear();

            if (this.textureHueOutput.SliceCount == 0)
            {
                return;
            }

            //

            //Compile shader if necessary
            if (shader == null)
            {
                using (DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), Consts.EffectPath + ".HSLSplit.fx"))
                {
                    shader = new DX11ShaderInstance(context, effect);
                }
            }

            for (int i = 0; i < this.textureHueOutput.SliceCount; i++)
            {
                if (this.textureInput[i] == null)
                {
                    this.SetDefault(context, i);
                }
                else if (this.textureInput[i].Contains(context))
                {
                    var input = this.textureInput[i][context];

                    var inputFormat = input.SRV.Description.Format;
                    inputFormat = inputFormat.DefaultOutputForCompressed();

                    if (inputFormat.IsSignedInt() || inputFormat.IsUnsignedInt())
                    {
                        this.message[i] = "Integer type textures are not supported for color conversion : " + inputFormat.ToString();
                        this.SetDefault(context, i);
                        continue;
                    }

                    var outputFormat = inputFormat;
                    if (this.singleChannelOut[i])
                    {
                        var singleFormat = outputFormat.GetSingleChannelEquivalent();
                        if (singleFormat == SlimDX.DXGI.Format.Unknown)
                        {
                            this.message[i] = "Could not find a single channel format suitable for : " + outputFormat.ToString();
                            this.SetDefault(context, i);
                            continue;
                        }
                        else
                        {
                            outputFormat = singleFormat;
                        }
                    }

                    string tech = "";

                    if (this.colorSpace[i] == HSLOrHSVSpace.HSL)
                    {
                        tech = this.singleChannelOut[i] ? "HSLSingle" : "HSLExpand";
                    }
                    else
                    {
                        tech = this.singleChannelOut[i] ? "HSVSingle" : "HSVExpand";
                    }
                    shader.SelectTechnique(tech);
                    shader.SetByName("InputTexture", input.SRV);

                    var outputRed   = context.ResourcePool.LockRenderTarget(input.Width, input.Height, outputFormat, false, 1, false);
                    var outputGreen = context.ResourcePool.LockRenderTarget(input.Width, input.Height, outputFormat, false, 1, false);
                    var outputBlue  = context.ResourcePool.LockRenderTarget(input.Width, input.Height, outputFormat, false, 1, false);
                    var outputAlpha = context.ResourcePool.LockRenderTarget(input.Width, input.Height, outputFormat, false, 1, false);

                    context.RenderTargetStack.Push(outputRed.Element, outputGreen.Element, outputBlue.Element, outputAlpha.Element);

                    context.Primitives.ApplyFullTriVSPosition();
                    shader.ApplyPass(0);
                    context.CurrentDeviceContext.Draw(3, 0);

                    context.RenderTargetStack.Pop();

                    this.framePool.Add(outputRed);
                    this.framePool.Add(outputGreen);
                    this.framePool.Add(outputBlue);
                    this.framePool.Add(outputAlpha);



                    this.textureHueOutput[i][context]        = outputRed.Element;
                    this.textureSaturationOutput[i][context] = outputGreen.Element;
                    this.textureBrightnessOutput[i][context] = outputBlue.Element;
                    this.textureAlphaOutput[i][context]      = outputAlpha.Element;

                    this.message[i] = "ok";
                }
                else
                {
                    this.SetDefault(context, i);
                }
            }

            if (this.BeginQuery != null)
            {
                this.BeginQuery(context);
            }

            if (this.EndQuery != null)
            {
                this.EndQuery(context);
            }
        }