Example #1
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;
        }