예제 #1
0
 private void FillMipSlice(SharpDX.Toolkit.Graphics.GraphicsDevice device, Material computeShader, int textureSize, UnorderedAccessView UAVMip, Vector4 fillColour)
 {
     computeShader.SetParameterResource("gOutput", UAVMip);
     computeShader.SetParameterValue("fillColour", fillColour);
     computeShader.Apply();
     device.Dispatch(1, textureSize, 1);
 }
예제 #2
0
        private void MipGenerationSimple2LevelsOn2DTexture()
        {
            //Given
            Material computeShader = LoadComputeShader(device);

            Texture2DDescription emptyTextureDesc = CreateTextureDescription();

            SharpDX.Direct3D11.Texture2D emptyTexture = new SharpDX.Direct3D11.Texture2D(device, emptyTextureDesc);

            ShaderResourceViewDescription srvDesc = CreateSRVDescription();
            ShaderResourceView            srv     = new ShaderResourceView(device, emptyTexture, srvDesc);

            UnorderedAccessViewDescription uavDesc = CreateUAVDescription(0);
            UnorderedAccessView            uavMip0 = new UnorderedAccessView(device, emptyTexture, uavDesc);

            uavDesc = CreateUAVDescription(1);
            UnorderedAccessView uavMip1 = new UnorderedAccessView(device, emptyTexture, uavDesc);

            uavDesc = CreateUAVDescription(2);
            UnorderedAccessView uavMip2 = new UnorderedAccessView(device, emptyTexture, uavDesc);

            BufferDescription bufferDesc = CreateLocalBufferDesc();

            SharpDX.Direct3D11.Buffer localbuffer = new SharpDX.Direct3D11.Buffer(device, bufferDesc);

            int mipSize  = 0;
            int subIndex = emptyTexture.CalculateSubResourceIndex(1, 0, out mipSize);

            //When
            computeShader.SetParameterResource("gOutput", uavMip0);
            computeShader.SetParameterValue("fillColour", new Vector4(0.1f, 0.2f, 0.3f, 1.0f));

            computeShader.Apply();

            //IS THIS ACTUALLY DOING ANYTHING AT ALL? Do we need to set up more of the pipeline before this will actually work??
            device.Dispatch(1, 32, 1);

            device.Copy(emptyTexture, 1, localbuffer, 0);

            DataStream data = new DataStream(8 * 32 * 32, true, true);

            ((DeviceContext)device).MapSubresource(localbuffer, MapMode.Read, MapFlags.None, out data);


            Half4 quickTest;

            for (int i = 0; i < 32 * 32; i++)
            {
                quickTest = data.ReadHalf4();
            }

            ((DeviceContext)device).UnmapSubresource(localbuffer, 0);
        }
예제 #3
0
        public ShaderResourceView GenerateIrradianceCubemapFromTextureCube(TextureCube originalCube)
        {
            Texture2DDescription emptyTextureDesc = CreateTextureDescription();
            Texture2D            emptyTexture     = new Texture2D(device, emptyTextureDesc);

            UnorderedAccessViewDescription uavDesc = CreateUAVDescription(0);
            UnorderedAccessView            view    = new UnorderedAccessView(device, emptyTexture, uavDesc);

            computeShader.SetParameterResource("gSource", originalCube.ShaderView);
            computeShader.SetParameterResource("gOutput", view);
            computeShader.Apply();

            int groups = textureSize / 64;

            device.Dispatch(groups, textureSize, numOfSlices);

            return(null);
        }