Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ExperimentConfigTest/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
17 changes: 17 additions & 0 deletions ExperimentConfigTest/ExperimentConfigTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SeeSharp\SeeSharp.csproj" />
<!-- <PackageReference Include="SeeSharp" Version="2.1.0" /> -->

<ProjectReference Include="..\SeeSharp.Blazor\SeeSharp.Blazor.csproj" />
<!-- <PackageReference Include="SeeSharp.Blazor" Version="0.1.0" /> -->
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions ExperimentConfigTest/Imports.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma warning disable CS8019

global using System;
global using System.Collections.Concurrent;
global using System.Collections.Generic;
global using System.Diagnostics;
global using System.IO;
global using System.Linq;
global using System.Numerics;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using System.Threading;
global using System.Threading.Tasks;

global using TinyEmbree;
global using SimpleImageIO;

global using SeeSharp;
global using SeeSharp.Cameras;
global using SeeSharp.Common;
global using SeeSharp.Experiments;
global using SeeSharp.SceneManagement;
global using SeeSharp.Geometry;
global using SeeSharp.Images;
global using SeeSharp.Integrators;
global using SeeSharp.Integrators.Bidir;
global using SeeSharp.Integrators.Common;
global using SeeSharp.Integrators.Util;
global using SeeSharp.Sampling;
global using SeeSharp.Shading;
global using SeeSharp.Shading.Background;
global using SeeSharp.Shading.Emitters;
global using SeeSharp.Shading.Materials;

global using SeeSharp.Blazor;
3 changes: 3 additions & 0 deletions ExperimentConfigTest/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@inherits LayoutComponentBase

<main> @Body </main>
108 changes: 108 additions & 0 deletions ExperimentConfigTest/Pages/Experiment.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
@using SeeSharp.Experiments
@using SeeSharp
@using SeeSharp.Blazor

@inject IJSRuntime JS

@page "/Experiment"

<h1>Experiment Config</h1>

<SceneSelector @ref=sceneSelector OnSceneLoaded="@OnSceneLoaded"></SceneSelector>

<div style="display: flex; align-items: flex-start; gap: 1.5em;">
<div style="display: flex; flex-direction: column; gap: 1.5em; width: 250px; flex-shrink: 0;">
<IntegratorSelector
@ref="integratorSelector"
scene="@scene"
OnRunIntegrator="OnRunIntegrator"
OnDeleteIntegrator="OnDeleteIntegrator"
OnRunAllIntegrators="OnRunAllIntegrators"/>
</div>

@if (resultsAvailable)
{
<button @onclick="OnDownloadClick">Download results</button>
}

@if (!running)
{
@if (resultsAvailable)
{
<div class="experiment-results">
<FlipViewer Flip="@flip" OnClick="@OnFlipClick"></FlipViewer>

@if (selected.HasValue && selected.Value)
{
<table>
<tr><th>Mesh</th><td>@(selected.Value.Mesh.Name)</td></tr>
<tr><th>Material</th><td>@(selected.Value.Mesh.Material.Name) (roughness: @(selected.Value.Mesh.Material.GetRoughness(selected.Value)), transmissive: @(selected.Value.Mesh.Material.IsTransmissive(selected.Value)))</td></tr>
<tr><th>Distance</th><td>@(selected.Value.Distance)</td></tr>
<tr><th>Position</th><td>@(selected.Value.Position)</td></tr>
</table>
}
</div>
}
}
else
{
<p>Rendering...</p>
}
</div>

@code {
SceneSelector sceneSelector;
Scene scene;
bool running = false;
bool resultsAvailable = false;

SimpleImageIO.FlipBook flip;
IntegratorSelector integratorSelector;

async Task OnSceneLoaded(SceneDirectory sceneDir)
{
await Task.Run(() => scene = sceneDir.SceneLoader.Scene);
flip = null;
resultsAvailable = false;
}

async Task OnRunIntegrator(Integrator integrator)
{
running = true;
resultsAvailable = false;

integratorSelector.Names.TryGetValue(integrator, out string customName);
await Task.Run(() => RunSingleIntegrator(integrator, customName));

running = false;
resultsAvailable = true;
}

void OnDeleteIntegrator(Integrator integrator)
{
if (integrator == null || flip == null) return;
integratorSelector.Names.TryGetValue(integrator, out string customName);
string name = customName ?? IntegratorUtils.FormatClassName(integrator.GetType());
flip.Remove(name);
}

async Task OnRunAllIntegrators()
{
running = true;
resultsAvailable = false;

flip = new FlipBook(660, 580)
.SetZoom(FlipBook.InitialZoom.FillWidth)
.SetToneMapper(FlipBook.InitialTMO.Exposure(scene.RecommendedExposure))
.SetToolVisibility(false);

foreach (var integrator in integratorSelector.addedIntegrators)
{
integratorSelector.Names.TryGetValue(integrator, out string customName);
await Task.Run(() => RunSingleIntegrator(integrator, customName));
}

running = false;
resultsAvailable = true;
}
}
54 changes: 54 additions & 0 deletions ExperimentConfigTest/Pages/Experiment.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.AspNetCore.Components;

namespace ExperimentConfigTest.Pages;

public partial class Experiment : ComponentBase
{
const int Width = 1280;
const int Height = 720;

SurfacePoint? selected;

void OnFlipClick(FlipViewer.OnEventArgs args)
{
if (args.Control)
{
RNG rng = new(1241512);
var ray = scene.Camera.GenerateRay(new Vector2(args.MouseX + 0.5f, args.MouseY + 0.5f), ref rng).Ray;
selected = (SurfacePoint)scene.Raytracer.Trace(ray);

SurfaceShader shader = new(selected.Value, -ray.Direction, false);
var s = shader.Sample(rng.NextFloat(), rng.NextFloat2D());
Console.WriteLine(s);
}
}

async Task OnDownloadClick()
{
HtmlReport report = new();
report.AddMarkdown("""
# Example experiment
$$ L_\mathrm{o} = \int_\Omega L_\mathrm{i} f_\mathrm{r} |\cos\theta_\mathrm{i}| \, d\omega_\mathrm{i} $$
""");
report.AddFlipBook(flip);
await SeeSharp.Blazor.Scripts.DownloadAsFile(JS, "report.html", report.ToString());
}

void RunSingleIntegrator(Integrator integrator, string? name = null)
{
if (flip == null) {
flip = new FlipBook(660, 580)
.SetZoom(FlipBook.InitialZoom.FillWidth)
.SetToneMapper(FlipBook.InitialTMO.Exposure(scene.RecommendedExposure))
.SetToolVisibility(false);
}

scene.FrameBuffer = new(Width, Height, "");
scene.Prepare();
integrator.Render(scene);

string displayName = name ?? IntegratorUtils.FormatClassName(integrator.GetType());
flip.Remove(displayName);
flip.Add(displayName, scene.FrameBuffer.Image);
}
}
39 changes: 39 additions & 0 deletions ExperimentConfigTest/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@page "/"

@using System.Reflection
@using System.Text.RegularExpressions


<div>
<nav>
<ul>
@foreach (var (name, url) in GetExperimentPages())
{
<li><a href=@(url)>@(name)</a></li>
}
</ul>
</nav>
</div>


@code {
/// <summary>Enumerates all .razor components in this folder</summary>
public IEnumerable<(string Name, string Url)> GetExperimentPages()
{
var routableComponents = Assembly
.GetExecutingAssembly()
.ExportedTypes
.Where(t => t.IsSubclassOf(typeof(ComponentBase)))
.Where(c => c
.GetCustomAttributes(inherit: true)
.OfType<RouteAttribute>()
.Count() > 0);

foreach (var routableComponent in routableComponents)
{
string name = routableComponent.ToString().Replace("ExperimentConfigTest.Pages.", string.Empty);
if (name != "Index")
yield return (name, name);
}
}
}
34 changes: 34 additions & 0 deletions ExperimentConfigTest/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@page "/"
@using Microsoft.AspNetCore.Components.Web
@namespace ExperimentConfigTest.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="~/" />
<link href="css/site.css" rel="stylesheet" />
<link href="ExperimentConfigTest.styles.css" rel="stylesheet" />
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />

@Html.Raw(SeeSharp.Blazor.Scripts.AllScripts)

</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />

<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

<script src="_framework/blazor.server.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions ExperimentConfigTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

SceneRegistry.AddSourceRelativeToScript("../Data/Scenes");

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();
35 changes: 35 additions & 0 deletions ExperimentConfigTest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"iisSettings": {
"iisExpress": {
"applicationUrl": "http://localhost:18831",
"sslPort": 44326
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5229",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7055;http://localhost:5229",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
4 changes: 4 additions & 0 deletions ExperimentConfigTest/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using ExperimentConfigTest
9 changes: 9 additions & 0 deletions ExperimentConfigTest/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Loading