Esempio n. 1
0
    public Scene(IArchiveDirectory dataDir, Device device, ShaderCache shaderCache, StandardSamplers standardSamplers, TrackedDeviceBufferManager trackedDeviceBufferManager, ControllerManager controllerManager)
    {
        var textureCache = new TextureCache(device);

        toneMappingSettings = new ToneMappingSettings();
        iblEnvironment      = new ImageBasedLightingEnvironment(device, standardSamplers, dataDir, InitialSettings.Environment, InitialSettings.EnvironmentRotation);
        backdrop            = new Backdrop(device, shaderCache);
        floor = new PlayspaceFloor(device, shaderCache);
        renderModelRenderer = new RenderModelRenderer(device, shaderCache, trackedDeviceBufferManager);
        primitiveRenderer   = new MeshRenderer(device, shaderCache, Matrix.Translation(0, 1.25f, 0), GeometricPrimitiveFactory.MakeSphere(0.5f, 100).AsTriMesh());

        var shapeNormalsLoader   = new ShapeNormalsLoader(dataDir, device, textureCache);
        var figureRendererLoader = new FigureRendererLoader(dataDir, device, shaderCache, textureCache);
        var figureLoader         = new FigureLoader(dataDir, device, shaderCache, shapeNormalsLoader, figureRendererLoader);

        actor = Actor.Load(dataDir, device, shaderCache, controllerManager, figureLoader);

        var iblMenu = LightingEnvironmentMenu.MakeMenuLevel(dataDir, iblEnvironment);
        var toneMappingMenuLevel    = new ToneMappingMenuLevel(toneMappingSettings);
        var renderSettingsMenuLevel = new StaticMenuLevel(
            new SubLevelMenuItem("Lighting Enviroment", iblMenu),
            new SubLevelMenuItem("Tone Mapping", toneMappingMenuLevel),
            new FloorVisibilityToggleMenuItem(floor)
            );
        var scenePersistenceMenuLevel = ScenePersistenceMenuLevel.Make(this);
        var appMenuLevel = new StaticMenuLevel(
            new SubLevelMenuItem("Save/Load", scenePersistenceMenuLevel),
            new SubLevelMenuItem("Render Settings", renderSettingsMenuLevel)
            );

        var rootMenuLevel = new CombinedMenuLevel(appMenuLevel, actor.MenuLevel);

        menu = new Menu(device, shaderCache, trackedDeviceBufferManager, controllerManager, rootMenuLevel);
    }
Esempio n. 2
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. 3
0
    public void Update(DeviceContext context, ImageBasedLightingEnvironment lightingEnvironment)
    {
        if (!model.IsVisible)
        {
            return;
        }

        renderer.Update(context, lightingEnvironment, controlVertexProvider.ControlVertexInfosView);
    }
    private static IMenuItem MakeRotationItem(ImageBasedLightingEnvironment environment)
    {
        double epsilon = 1e-2;
        double max     = Math.PI + epsilon;
        double min     = -max;

        return(new GenericRangeMenuItem("Rotation", min, 0, max,
                                        () => environment.Rotation,
                                        (value) => environment.Rotation = (float)WrapRotation(value)));
    }
 public void Merge(ImageBasedLightingEnvironment environment)
 {
     if (Name != null)
     {
         environment.EnvironmentName = Name;
     }
     if (Rotation.HasValue)
     {
         environment.Rotation = Rotation.Value;
     }
 }
    public static IMenuLevel MakeMenuLevel(IArchiveDirectory dataDir, ImageBasedLightingEnvironment environment)
    {
        var environmentsDir = dataDir.Subdirectory("environments");

        List <IMenuItem> items = new List <IMenuItem>()
        {
            MakeRotationItem(environment)
        };

        items.AddRange(MakeEnvironmentsMenuItems(environmentsDir, environment));

        return(new StaticMenuLevel(items.ToArray()));
    }
Esempio n. 7
0
    public void Update(DeviceContext context, ImageBasedLightingEnvironment lightingEnvironment, ShaderResourceView controlVertexInfosView, ShapeNormals shapeNormals)
    {
        if (this.shapeNormals != shapeNormals || texturedVertexInfoPairsView == null)
        {
            this.shapeNormals = shapeNormals;

            texturedVertexInfoPairsView?.Dispose();
            var pairs = TexturedVertexInfoPair.Interleave(primaryTexturedVertexInfos, shapeNormals?.TexturedVertexInfos);
            texturedVertexInfoPairsView = BufferUtilities.ToStructuredBufferView(device, pairs);
        }

        scatterer?.Scatter(context, lightingEnvironment, controlVertexInfosView);
        vertexRefiner.RefineVertices(context, controlVertexInfosView, scatterer?.ScatteredIlluminationView);
    }
    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);
        }
    }
Esempio n. 9
0
    public void Update(DeviceContext context, FrameUpdateParameters updateParameters, ImageBasedLightingEnvironment lightingEnvironment)
    {
        modelToWorldTransform.Update(context, Matrix.Scaling(0.01f));

        foreach (var figure in childFigures)
        {
            figure.SyncWithModel();
        }
        parentFigure.SyncWithModel();

        var parentOutputs = parentFigure.UpdateFrame(context, updateParameters, null);

        foreach (var figure in childFigures)
        {
            figure.UpdateFrame(context, updateParameters, parentOutputs);
        }

        parentFigure.UpdateVertexPositionsAndGetDeltas(context, parentDeltas.OutView);
        foreach (var figure in childFigures)
        {
            figure.UpdateVertexPositions(context, parentDeltas.InView);
        }

        parentFigure.Update(context, lightingEnvironment);
        foreach (var figure in childFigures)
        {
            figure.Update(context, lightingEnvironment);
        }
    }
 private static List <IMenuItem> MakeEnvironmentsMenuItems(IArchiveDirectory environmentsDirectory, ImageBasedLightingEnvironment environment)
 {
     return(environmentsDirectory.Subdirectories
            .Select(environmentDir => (IMenuItem)SetLightingEnvironmentMenuItem.Make(environment, environmentDir))
            .ToList());
 }
 public static SetLightingEnvironmentMenuItem Make(ImageBasedLightingEnvironment environment, IArchiveDirectory environmentDir)
 {
     return(new SetLightingEnvironmentMenuItem(environment, environmentDir.Name));
 }
 public SetLightingEnvironmentMenuItem(ImageBasedLightingEnvironment environment, string name)
 {
     this.environment = environment;
     this.name        = name;
 }
 public void Update(DeviceContext context, FrameUpdateParameters updateParameters, ImageBasedLightingEnvironment iblEnvironment)
 {
     figureGroup.Update(context, updateParameters, iblEnvironment);
 }
Esempio n. 14
0
 public void Update(DeviceContext context, ImageBasedLightingEnvironment lightingEnvironment, ShaderResourceView controlVertexInfosView)
 {
     scatterer?.Scatter(context, lightingEnvironment, controlVertexInfosView);
     vertexRefiner.RefineVertices(context, controlVertexInfosView, scatterer?.ScatteredIlluminationView);
 }