Esempio n. 1
0
    public void Scatter(DeviceContext context, ImageBasedLightingEnvironment lightingEnvironment, ShaderResourceView controlVertexInfosView)
    {
        context.WithEvent("Scatterer::Scatter", () => {
            context.ClearState();

            context.ComputeShader.Set(samplingShader);
            lightingEnvironment.Apply(context.ComputeShader);
            context.ComputeShader.SetShaderResources(ShaderSlots.MaterialTextureStart,
                                                     stencilSegments,
                                                     stencilElems,
                                                     controlVertexInfosView);
            context.ComputeShader.SetUnorderedAccessView(0, sampledIrrandiancesBufferManager.OutView);
            context.Dispatch(IntegerUtils.RoundUp(vertexCount, ShaderNumThreads), 1, 1);

            context.ClearState();

            context.ComputeShader.Set(scatteringShader);
            context.ComputeShader.SetShaderResources(0,
                                                     sampledIrrandiancesBufferManager.InView,
                                                     formFactorSegments,
                                                     formFactorElements);
            context.ComputeShader.SetUnorderedAccessView(0, scatteredIrrandiancesBufferManager.OutView);
            context.Dispatch(IntegerUtils.RoundUp(vertexCount, ShaderNumThreads), 1, 1);

            context.ClearState();
        });
    }
Esempio n. 2
0
    public void RenderPass(DeviceContext context, RenderingPass pass)
    {
        iblEnvironment.Apply(context.PixelShader);

        if (pass.Layer == RenderingLayer.OneSidedOpaque)
        {
            bool depthOnly = pass.OutputMode == OutputMode.FalseDepth;
            //backdrop.Render(context, depthOnly);
            floor.Render(context, depthOnly);
            renderModelRenderer.Render(context, depthOnly);
            //primitiveRenderer.Render(context, depthOnly);
        }

        actor.RenderPass(context, pass);
        menu.RenderPass(context, pass);
    }
    public void Run()
    {
        Device      device      = new Device(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug);
        ShaderCache shaderCache = new ShaderCache(device);

        var stamdardSamplers = new StandardSamplers(device);

        var dataDir     = UnpackedArchiveDirectory.Make(CommonPaths.WorkDir);
        var environment = new ImageBasedLightingEnvironment(device, stamdardSamplers, dataDir, "ruins", 0);

        DeviceContext context = device.ImmediateContext;

        Vector4[] samplePositions =
        {
            new Vector4(+1,  0,  0, 0),
            new Vector4(-1,  0,  0, 0),
            new Vector4(0,  +1,  0, 0),
            new Vector4(0,  -1,  0, 0),
            new Vector4(0,   0, +1, 0),
            new Vector4(0,   0, -1, 0),
        };

        var inBufferView = BufferUtilities.ToStructuredBufferView(device, samplePositions);

        ComputeShader shader = shaderCache.GetComputeShader <SampleCubeMapApp>("demos/cubemapsampler/SampleCubeMap");

        var outBuffer = new StageableStructuredBufferManager <Vector4>(device, samplePositions.Length);

        context.ComputeShader.Set(shader);
        environment.Apply(context.ComputeShader);
        context.ComputeShader.SetShaderResource(1, inBufferView);
        context.ComputeShader.SetUnorderedAccessView(0, outBuffer.View);

        context.Dispatch(samplePositions.Length, 1, 1);
        context.ClearState();

        Vector4[] results = outBuffer.ReadContents(context);

        for (int i = 0; i < samplePositions.Length; ++i)
        {
            Console.WriteLine(samplePositions[i]);
            Console.WriteLine("\t" + results[i].X);
            Console.WriteLine("\t" + results[i].Y);
            Console.WriteLine("\t" + results[i].Z);
            Console.WriteLine("\t" + results[i].W);
        }
    }