コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
ffd205469e
|
||
|
|
80bd1e1fd8
|
||
|
|
c950fb2534
|
||
|
|
8f5fb260e3
|
||
|
|
a55d24e768
|
||
|
|
88c696a103
|
||
|
|
b1af805936
|
||
|
|
235383ee56
|
||
|
|
a7bd8f1f9a
|
||
|
|
fc8e209123
|
||
|
|
b532b3d33a
|
||
|
|
d60b74cb74
|
||
|
|
6c819fda9d
|
||
|
|
1394a61cb3
|
||
|
|
966b6b7c28
|
||
|
|
1c4ee7a031
|
||
|
|
d9070bdeac
|
||
|
|
2b7a929669
|
||
|
|
eb67256ca1
|
||
|
|
8a5f7b53e1
|
||
|
|
9c116a1260
|
||
|
|
79862b930d
|
||
|
|
81b545739b
|
||
|
|
ee7a85cd9c
|
||
|
|
9ec24b00fe
|
||
|
|
ff13c1a766
|
||
|
|
0cdcf11fbe
|
||
|
|
dd06777c08
|
||
|
|
1e18582f44
|
||
|
|
4252c58810
|
||
|
|
60b2370b82
|
||
|
|
7a0034f3ad
|
||
|
|
1a21a9e60c
|
||
|
|
33cc856772
|
||
|
|
bff0005769
|
||
|
|
81ce384127
|
||
|
|
b0d741c590
|
||
|
|
13c92459e4
|
||
|
|
a9dcc62828
|
||
|
|
cef5bdd32f
|
||
|
|
26da97454b
|
||
|
|
de2e58b75d
|
||
|
|
5d76712859
|
||
|
|
daa74d6a66
|
||
|
|
b348f039d8
|
||
|
|
b68951b020
|
||
|
|
87de86e372
|
||
|
|
b6fdbdb6ca
|
||
|
|
4181291a5a
|
||
|
|
c7188970d6
|
||
|
|
6f93866bb2
|
||
|
|
7ee8eaf92a
|
||
|
|
ceee21d1b1
|
||
|
|
8943b353bd
|
||
|
|
f3eafcb2f2
|
||
|
|
76237f3fe9
|
||
|
|
7bc3784133
|
||
|
|
1c09cde8d1
|
||
|
|
ea67ece300
|
||
|
|
86b7446190
|
||
|
|
7b74727703
|
||
|
|
c0a797c436
|
||
|
|
389414db87
|
||
|
|
d03ae855e3
|
||
|
|
052c926a43
|
||
|
|
ab1399f8f7
|
||
|
|
f44e0f0fc5
|
||
|
|
3bef9e7353
|
||
|
|
a673d151e8
|
||
|
|
c85d29d8f9
|
||
|
|
e06396093e
|
||
|
|
be4d5f5b52
|
||
|
|
57536e67b2
|
||
|
|
263615fd37
|
||
|
|
6fa812ba9b
|
||
|
|
5c1b0c717c
|
||
|
|
95633e7a88
|
||
|
|
60b6ab5c54
|
||
|
|
a0bc80d957
|
||
|
|
7d784e6811
|
||
|
|
6f5f11da4d
|
||
|
|
bd19d3263f
|
||
|
|
c8917d688a
|
||
|
|
946e63a30a
|
||
|
|
b572d93956
|
||
|
|
c8c5f57c89
|
||
|
|
1e10978857
|
||
|
|
ef8993a73d
|
||
|
|
12b2aa7dcd
|
||
|
|
9c35c5e265
|
||
|
|
66b0f80a36
|
||
|
|
1bf2d66f3c
|
||
|
|
54f0cbef64
|
||
|
|
3c867295c7
|
||
|
|
374ed3111d
|
||
|
|
e7eae442e1
|
||
|
|
0db60b534e
|
||
|
|
c448a6a8b5
|
||
|
|
ccff20b9f1
|
||
|
|
8c683bd5a4
|
||
|
|
1155a6883c
|
||
|
|
69fa2015d1
|
||
|
|
c922142b96
|
検索条件に一致するファイルはありません
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"isRoot": true,
|
||||||
|
"tools": {
|
||||||
|
"dotnet-stryker": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"commands": [
|
||||||
|
"dotnet-stryker"
|
||||||
|
],
|
||||||
|
"rollForward": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,538 @@
|
|||||||
|
name: リリース
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: リリースするタグ
|
||||||
|
required: true
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-release:
|
||||||
|
runs-on: windows-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: ソースコードのチェックアウト
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
env:
|
||||||
|
GIT_CONFIG_COUNT: "2"
|
||||||
|
GIT_CONFIG_KEY_0: url.https://git.routersys.com/routersys/.insteadOf
|
||||||
|
GIT_CONFIG_VALUE_0: https://github.com/routersys/
|
||||||
|
GIT_CONFIG_KEY_1: url.https://git.routersys.com/manju-summoner/YukkuriMovieMaker.Generator.insteadOf
|
||||||
|
GIT_CONFIG_VALUE_1: https://github.com/manju-summoner/YukkuriMovieMaker.Generator
|
||||||
|
with:
|
||||||
|
ref: ${{ inputs.tag || github.ref_name }}
|
||||||
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: MSBuild のセットアップ
|
||||||
|
uses: microsoft/setup-msbuild@v3
|
||||||
|
|
||||||
|
- name: YMM4 最新リリースの取得と解凍
|
||||||
|
id: ymm4
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$list = 'C:\runner\cache\ymm4\releases.json'
|
||||||
|
New-Item -ItemType Directory -Force -Path (Split-Path $list) | Out-Null
|
||||||
|
if (-not (Test-Path $list) -or (Get-Item $list).Length -lt 1000 -or ((Get-Date) - (Get-Item $list).LastWriteTime).TotalHours -gt 6) {
|
||||||
|
$fetched = $null
|
||||||
|
for ($attempt = 1; $attempt -le 6 -and -not $fetched; $attempt++) {
|
||||||
|
try {
|
||||||
|
$fetched = Invoke-RestMethod -Uri "https://api.github.com/repos/manju-summoner/YukkuriMovieMaker4/releases?per_page=100" `
|
||||||
|
-Headers @{ "User-Agent" = "InkDispersion-CI" } -ErrorAction Stop
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$message = $_.Exception.Message
|
||||||
|
Write-Host "リリース一覧の取得に失敗しました($attempt 回目): $($message.Substring(0, [Math]::Min(80, $message.Length)))"
|
||||||
|
Start-Sleep -Seconds (5 * $attempt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (@($fetched).Count -gt 0) {
|
||||||
|
$fetched | Select-Object tag_name, published_at, prerelease, draft, assets |
|
||||||
|
ConvertTo-Json -Depth 6 | Set-Content -Path $list -Encoding UTF8
|
||||||
|
}
|
||||||
|
elseif (-not (Test-Path $list)) { throw 'the list of releases could not be fetched' }
|
||||||
|
else { Write-Host '保存済みのリリース一覧を使います' }
|
||||||
|
}
|
||||||
|
$when = [DateTimeOffset](git log -1 --format=%cI)
|
||||||
|
$releases = @(Get-Content -Raw -Path $list | ConvertFrom-Json | Where-Object { -not $_.draft -and -not $_.prerelease })
|
||||||
|
$release = $releases | Where-Object { [DateTimeOffset]$_.published_at -le $when } | Select-Object -First 1
|
||||||
|
if (-not $release) { $release = $releases | Select-Object -Last 1 }
|
||||||
|
Write-Host "最後のコミット $when に合わせた YMM4: $($release.tag_name)"
|
||||||
|
$asset = $release.assets | Where-Object { $_.name -like "*_Lite.zip" } | Select-Object -First 1
|
||||||
|
if (-not $asset) {
|
||||||
|
$asset = $release.assets | Where-Object { $_.name -like "*.zip" } | Select-Object -First 1
|
||||||
|
}
|
||||||
|
Write-Host "ダウンロード対象: $($asset.name)"
|
||||||
|
$cache = Join-Path 'C:\runner\cache\ymm4' $asset.name
|
||||||
|
$extracted = "$cache.extracted"
|
||||||
|
$lock = New-Object System.Threading.Mutex($false, 'Global\ci-ymm4-cache')
|
||||||
|
[void]$lock.WaitOne()
|
||||||
|
try {
|
||||||
|
if (-not (Test-Path "$extracted\.complete")) {
|
||||||
|
New-Item -ItemType Directory -Force -Path (Split-Path $cache) | Out-Null
|
||||||
|
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $cache
|
||||||
|
Remove-Item -Recurse -Force $extracted -ErrorAction SilentlyContinue
|
||||||
|
Expand-Archive -Path $cache -DestinationPath $extracted -Force
|
||||||
|
New-Item -ItemType File -Path "$extracted\.complete" | Out-Null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host "保存済みの YMM4 を使います: $extracted"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
$lock.ReleaseMutex()
|
||||||
|
}
|
||||||
|
$ymm4Dir = (Get-ChildItem -Path $extracted -Recurse -Filter "YukkuriMovieMaker.dll" |
|
||||||
|
Select-Object -First 1).DirectoryName
|
||||||
|
Write-Host "YMM4 DLL ディレクトリ: $ymm4Dir"
|
||||||
|
echo "YMM4_DIR=$ymm4Dir\" >> $env:GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: タグ名からバージョンを取得
|
||||||
|
id: version
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$tag = "${{ inputs.tag || github.ref_name }}"
|
||||||
|
echo "TAG=$tag" >> $env:GITHUB_OUTPUT
|
||||||
|
echo "VERSION=$($tag.TrimStart('v'))" >> $env:GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: バージョン記載の照合
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$tag = "${{ steps.version.outputs.TAG }}"
|
||||||
|
$version = "${{ steps.version.outputs.VERSION }}"
|
||||||
|
$problems = @()
|
||||||
|
|
||||||
|
$csprojPath = "InkDispersion/InkDispersion.csproj"
|
||||||
|
$csproj = Get-Content $csprojPath -Raw
|
||||||
|
if (-not $csproj.Contains("<Version>$version</Version>")) {
|
||||||
|
$current = if ($csproj -match '<Version>([^<]*)</Version>') { $Matches[1] } else { "記載なし" }
|
||||||
|
$problems += "$csprojPath の <Version> が $current です。$version にしてください。"
|
||||||
|
}
|
||||||
|
|
||||||
|
$readmePath = ".github/Plugin_Readme.txt"
|
||||||
|
$readme = Get-Content $readmePath -Raw
|
||||||
|
if (-not $readme.Contains(" 墨拡散 for YMM4 $tag")) {
|
||||||
|
$current = if ($readme -match '(?m)^ 墨拡散 for YMM4 (\S+)') { $Matches[1] } else { "記載なし" }
|
||||||
|
$problems += "$readmePath の見出しが $current です。$tag にしてください。"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($problems.Count -eq 0) {
|
||||||
|
Write-Host "バージョン記載は $tag と一致しています"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($problem in $problems) {
|
||||||
|
Write-Host "::error::$problem"
|
||||||
|
}
|
||||||
|
Write-Host "::error::リリースの対象は $tag が指すコミットです。タグを付けた後で main へ訂正を積んでも、その訂正はリリースに入りません。タグを削除し、記載を直したコミットを積んでから付け直してください。"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: シェーダーのビルド
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
msbuild InkDispersion.Shader/InkDispersion.Shader.vcxproj `
|
||||||
|
/p:Configuration=Release `
|
||||||
|
/p:Platform=Win32 `
|
||||||
|
/nologo
|
||||||
|
|
||||||
|
- name: プロジェクトのビルド
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$proj = "InkDispersion/InkDispersion.csproj"
|
||||||
|
dotnet build "$proj" `
|
||||||
|
-c Release `
|
||||||
|
-p:YMM4DirPath="${{ steps.ymm4.outputs.YMM4_DIR }}" `
|
||||||
|
-p:Platform=x64 `
|
||||||
|
-p:SkipPluginDeploy=true
|
||||||
|
|
||||||
|
- name: テストプロジェクトのビルド
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
dotnet build InkDispersion.Tests/InkDispersion.Tests.csproj `
|
||||||
|
-c Release `
|
||||||
|
-p:YMM4DirPath="${{ steps.ymm4.outputs.YMM4_DIR }}" `
|
||||||
|
-p:Platform=x64 `
|
||||||
|
-p:SkipPluginDeploy=true `
|
||||||
|
-maxcpucount:1
|
||||||
|
|
||||||
|
- name: テストの実行
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
dotnet test InkDispersion.Tests/InkDispersion.Tests.csproj `
|
||||||
|
--no-build `
|
||||||
|
--no-restore `
|
||||||
|
-c Release `
|
||||||
|
-p:Platform=x64 `
|
||||||
|
-p:SkipPluginDeploy=true
|
||||||
|
|
||||||
|
- name: パッケージの作成
|
||||||
|
id: package
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$version = "${{ steps.version.outputs.TAG }}"
|
||||||
|
$outDir = "InkDispersion/bin/x64/Release/net10.0-windows10.0.19041.0"
|
||||||
|
$stageRoot = "stage/InkDispersion"
|
||||||
|
$pkgName = "InkDispersion_$version.ymme"
|
||||||
|
|
||||||
|
New-Item -ItemType Directory -Path $stageRoot -Force | Out-Null
|
||||||
|
New-Item -ItemType Directory -Path "$stageRoot/LICENSE" -Force | Out-Null
|
||||||
|
|
||||||
|
$dll = "$outDir/plugin/InkDispersion.dll"
|
||||||
|
if (-not (Test-Path $dll)) {
|
||||||
|
Write-Error "ビルド結果に InkDispersion.dll が見つかりませんでした: $dll"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Copy-Item $dll "$stageRoot/"
|
||||||
|
|
||||||
|
foreach ($lang in @("ar-sa", "en-us", "es-es", "id-id", "ko-kr", "zh-cn", "zh-tw")) {
|
||||||
|
$src = "$outDir/$lang"
|
||||||
|
if (Test-Path $src) {
|
||||||
|
New-Item -ItemType Directory -Path "$stageRoot/$lang" -Force | Out-Null
|
||||||
|
Copy-Item "$src/*.dll" "$stageRoot/$lang/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Copy-Item ".github/LICENSE/*.txt" "$stageRoot/LICENSE/"
|
||||||
|
Copy-Item ".github/Plugin_Readme.txt" "$stageRoot/Readme.txt"
|
||||||
|
|
||||||
|
$readme = Get-Content "$stageRoot/Readme.txt" -Raw
|
||||||
|
if (-not $readme.Contains(" 墨拡散 for YMM4 $version")) {
|
||||||
|
Write-Error "同梱する Readme.txt の見出しが $version と一致しません"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Compress-Archive -Path "stage/*" -DestinationPath $pkgName -CompressionLevel Optimal
|
||||||
|
echo "PKG_NAME=$pkgName" >> $env:GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: 変更履歴の作成
|
||||||
|
id: changelog
|
||||||
|
shell: pwsh
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ github.token }}
|
||||||
|
TAG: ${{ steps.version.outputs.TAG }}
|
||||||
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
SERVER_URL: ${{ github.server_url }}
|
||||||
|
PACKAGE: ${{ steps.package.outputs.PKG_NAME }}
|
||||||
|
run: |
|
||||||
|
$tag = $env:TAG
|
||||||
|
$repository = $env:REPOSITORY
|
||||||
|
$server = $env:SERVER_URL
|
||||||
|
$code = [char]0x60
|
||||||
|
$fence = [string]::new($code, 3)
|
||||||
|
$unit = [char]0x1f
|
||||||
|
$record = [char]0x1e
|
||||||
|
|
||||||
|
$previous = ""
|
||||||
|
$candidates = @(git tag --list "v*" --merged $tag --sort=-creatordate | Where-Object { $_ -ne $tag })
|
||||||
|
if ($candidates.Count -gt 0) {
|
||||||
|
$previous = $candidates[0]
|
||||||
|
}
|
||||||
|
Write-Host "直前のタグ: $previous"
|
||||||
|
|
||||||
|
$range = if ($previous) { "$previous..$tag" } else { $tag }
|
||||||
|
$log = (@(git log "--format=%H%x1f%s%x1f%an%x1f%ad%x1f%b%x1e" --date=short $range) -join "`n") -split $record
|
||||||
|
|
||||||
|
$commits = @()
|
||||||
|
foreach ($entry in $log) {
|
||||||
|
if (-not $entry.Trim()) { continue }
|
||||||
|
$fields = $entry.TrimStart("`n") -split $unit
|
||||||
|
if ($fields.Count -lt 5) { continue }
|
||||||
|
$commits += [pscustomobject]@{
|
||||||
|
Sha = $fields[0]
|
||||||
|
Subject = $fields[1]
|
||||||
|
Name = $fields[2]
|
||||||
|
Date = $fields[3]
|
||||||
|
Body = $fields[4]
|
||||||
|
Login = ""
|
||||||
|
Avatar = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "コミット数: $($commits.Count)"
|
||||||
|
|
||||||
|
$categories = [ordered]@{
|
||||||
|
A = @{ Title = "追加"; Symbol = "+"; Items = [System.Collections.Generic.List[pscustomobject]]::new() }
|
||||||
|
M = @{ Title = "変更"; Symbol = "~"; Items = [System.Collections.Generic.List[pscustomobject]]::new() }
|
||||||
|
D = @{ Title = "削除"; Symbol = "-"; Items = [System.Collections.Generic.List[pscustomobject]]::new() }
|
||||||
|
F = @{ Title = "修正"; Symbol = "!"; Items = [System.Collections.Generic.List[pscustomobject]]::new() }
|
||||||
|
}
|
||||||
|
foreach ($commit in $commits) {
|
||||||
|
if (-not $commit.Body) { continue }
|
||||||
|
foreach ($bodyLine in ($commit.Body -split "`n")) {
|
||||||
|
$trimmed = $bodyLine.Trim()
|
||||||
|
if ($trimmed -notmatch '^・(.+)-([AMDF])$') { continue }
|
||||||
|
$categories[$Matches[2]].Items.Add([pscustomobject]@{ Text = $Matches[1]; Sha = $commit.Sha })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pending = [System.Collections.Generic.HashSet[string]]::new()
|
||||||
|
foreach ($commit in $commits) {
|
||||||
|
[void]$pending.Add($commit.Sha)
|
||||||
|
}
|
||||||
|
|
||||||
|
$headers = @{ Authorization = "token $env:GITEA_TOKEN" }
|
||||||
|
|
||||||
|
$accounts = @{}
|
||||||
|
$page = 1
|
||||||
|
while ($pending.Count -gt 0 -and $page -le 20) {
|
||||||
|
$rows = @()
|
||||||
|
try {
|
||||||
|
$rows = @(Invoke-RestMethod -Uri "$server/api/v1/repos/$repository/commits?sha=$tag&limit=50&page=$page&stat=false&verification=false&files=false" -Headers $headers)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "コミットの作者を取得できませんでした: $($_.Exception.Message)"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if ($rows.Count -eq 0) { break }
|
||||||
|
|
||||||
|
foreach ($row in $rows) {
|
||||||
|
if ($pending.Remove($row.sha)) {
|
||||||
|
$login = ""
|
||||||
|
$avatar = ""
|
||||||
|
if ($row.author) {
|
||||||
|
$login = [string]$row.author.login
|
||||||
|
$avatar = [string]$row.author.avatar_url
|
||||||
|
}
|
||||||
|
$accounts[$row.sha] = @{ Login = $login; Avatar = $avatar }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($rows.Count -lt 50) { break }
|
||||||
|
$page++
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($commit in $commits) {
|
||||||
|
if ($accounts.ContainsKey($commit.Sha)) {
|
||||||
|
$commit.Login = $accounts[$commit.Sha].Login
|
||||||
|
$commit.Avatar = $accounts[$commit.Sha].Avatar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$emptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||||
|
$base = if ($previous) { $previous } else { $emptyTree }
|
||||||
|
$shortstat = (@(git diff --shortstat $base $tag) -join " ")
|
||||||
|
$changedFiles = 0
|
||||||
|
$insertions = 0
|
||||||
|
$deletions = 0
|
||||||
|
if ($shortstat -match "(\d+) file") { $changedFiles = [int]$Matches[1] }
|
||||||
|
if ($shortstat -match "(\d+) insertion") { $insertions = [int]$Matches[1] }
|
||||||
|
if ($shortstat -match "(\d+) deletion") { $deletions = [int]$Matches[1] }
|
||||||
|
$diffStat = @(git diff --stat $base $tag)
|
||||||
|
$tagDate = (git log -1 "--format=%ad" --date=short $tag)
|
||||||
|
|
||||||
|
$contributors = @($commits |
|
||||||
|
Group-Object -Property { if ($_.Login) { $_.Login } else { $_.Name } } |
|
||||||
|
Sort-Object -Property Count -Descending)
|
||||||
|
|
||||||
|
function Get-Icon($avatar, $login, $size) {
|
||||||
|
if (-not $avatar) { return "" }
|
||||||
|
$sized = if ($avatar.Contains("?")) { "$avatar&s=$($size * 2)" } else { "$avatar" + "?s=$($size * 2)" }
|
||||||
|
return "<img src=""$sized"" width=""$size"" height=""$size"" alt=""$login""> "
|
||||||
|
}
|
||||||
|
|
||||||
|
$package = Get-Item $env:PACKAGE
|
||||||
|
$size = [math]::Round($package.Length / 1MB, 2)
|
||||||
|
|
||||||
|
$body = [System.Collections.Generic.List[string]]::new()
|
||||||
|
$body.Add("## 概要")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("| 項目 | 内容 |")
|
||||||
|
$body.Add("|---|---|")
|
||||||
|
$body.Add("| タグ | [$tag]($server/$repository/tree/$tag) |")
|
||||||
|
$body.Add("| 公開日 | $tagDate |")
|
||||||
|
if ($previous) {
|
||||||
|
$body.Add("| 直前のリリース | [$previous]($server/$repository/releases/tag/$previous) |")
|
||||||
|
}
|
||||||
|
$body.Add("| コミット数 | $($commits.Count) |")
|
||||||
|
$body.Add("| 貢献者 | $($contributors.Count) 名 |")
|
||||||
|
$body.Add("| 変更されたファイル | $changedFiles |")
|
||||||
|
$body.Add("| 追加された行 | $insertions |")
|
||||||
|
$body.Add("| 削除された行 | $deletions |")
|
||||||
|
|
||||||
|
$hasHighlights = ($categories.Values | ForEach-Object { $_.Items.Count } | Measure-Object -Sum).Sum -gt 0
|
||||||
|
if ($hasHighlights) {
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 主な変更")
|
||||||
|
foreach ($key in $categories.Keys) {
|
||||||
|
$category = $categories[$key]
|
||||||
|
if ($category.Items.Count -eq 0) { continue }
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("### [$($category.Symbol)] $($category.Title)")
|
||||||
|
$body.Add("")
|
||||||
|
foreach ($item in $category.Items) {
|
||||||
|
$short = $item.Sha.Substring(0, 7)
|
||||||
|
$body.Add("- $($item.Text) ([$code$short$code]($server/$repository/commit/$($item.Sha)))")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## ダウンロード")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("| ファイル | サイズ |")
|
||||||
|
$body.Add("|---|---|")
|
||||||
|
$body.Add("| $($package.Name) | $size MB |")
|
||||||
|
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 貢献者")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("| 貢献者 | コミット数 |")
|
||||||
|
$body.Add("|---|---|")
|
||||||
|
foreach ($contributor in $contributors) {
|
||||||
|
$first = $contributor.Group[0]
|
||||||
|
if ($first.Login) {
|
||||||
|
$name = (Get-Icon $first.Avatar $first.Login 40) + "[@$($first.Login)]($server/$($first.Login))"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$name = $first.Name
|
||||||
|
}
|
||||||
|
$body.Add("| $name | $($contributor.Count) |")
|
||||||
|
}
|
||||||
|
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 変更履歴")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("| コミット | 内容 | 貢献者 | 日付 |")
|
||||||
|
$body.Add("|---|---|---|---|")
|
||||||
|
$maximumCommits = 300
|
||||||
|
$listed = 0
|
||||||
|
foreach ($commit in $commits) {
|
||||||
|
if ($listed -ge $maximumCommits) { break }
|
||||||
|
$short = $commit.Sha.Substring(0, 7)
|
||||||
|
$subject = $commit.Subject -replace '\|', '\|'
|
||||||
|
if ($commit.Login) {
|
||||||
|
$author = (Get-Icon $commit.Avatar $commit.Login 20) + "[@$($commit.Login)]($server/$($commit.Login))"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$author = $commit.Name
|
||||||
|
}
|
||||||
|
$body.Add("| [$code$short$code]($server/$repository/commit/$($commit.Sha)) | $subject | $author | $($commit.Date) |")
|
||||||
|
$listed++
|
||||||
|
}
|
||||||
|
if ($commits.Count -gt $maximumCommits) {
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("残り $($commits.Count - $maximumCommits) 件のコミットは省略しました。")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($diffStat.Count -gt 0) {
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 変更されたファイル")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("<details>")
|
||||||
|
$body.Add("<summary>差分の統計</summary>")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add($fence)
|
||||||
|
$maximumStatLines = 200
|
||||||
|
$shown = 0
|
||||||
|
foreach ($line in $diffStat) {
|
||||||
|
if ($shown -ge $maximumStatLines) { break }
|
||||||
|
$body.Add($line)
|
||||||
|
$shown++
|
||||||
|
}
|
||||||
|
if ($diffStat.Count -gt $maximumStatLines) {
|
||||||
|
$body.Add("... 残り $($diffStat.Count - $maximumStatLines) 行は省略しました。")
|
||||||
|
}
|
||||||
|
$body.Add($fence)
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("</details>")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($previous) {
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 全ての変更")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("$server/$repository/compare/$previous...$tag")
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = "release-body.md"
|
||||||
|
Set-Content -Path $path -Value ($body -join "`n") -Encoding utf8NoBOM
|
||||||
|
if (-not (Test-Path $path)) {
|
||||||
|
throw "変更履歴を作成できませんでした。"
|
||||||
|
}
|
||||||
|
Write-Host "変更履歴の行数: $($body.Count)"
|
||||||
|
$global:LASTEXITCODE = 0
|
||||||
|
|
||||||
|
- name: Gitea リリースの作成
|
||||||
|
shell: pwsh
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ github.token }}
|
||||||
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
SERVER_URL: ${{ github.server_url }}
|
||||||
|
EVENT_NAME: ${{ github.event_name }}
|
||||||
|
WORKFLOW_NAME: ${{ github.workflow }}
|
||||||
|
JOB_NAME: ${{ github.job }}
|
||||||
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_number }}
|
||||||
|
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
|
||||||
|
RELEASE_NAME: ${{ steps.version.outputs.TAG }}
|
||||||
|
RELEASE_BODY: ''
|
||||||
|
RELEASE_BODY_PATH: release-body.md
|
||||||
|
RELEASE_DRAFT: false
|
||||||
|
RELEASE_PRERELEASE: false
|
||||||
|
RELEASE_FILES: |
|
||||||
|
${{ steps.package.outputs.PKG_NAME }}
|
||||||
|
run: |
|
||||||
|
$headers = @{ Authorization = "token $env:GITEA_TOKEN" }
|
||||||
|
$api = "$env:SERVER_URL/api/v1/repos/$env:REPOSITORY"
|
||||||
|
$tag = $env:RELEASE_TAG
|
||||||
|
|
||||||
|
$body = $env:RELEASE_BODY
|
||||||
|
if ($env:RELEASE_BODY_PATH -and (Test-Path $env:RELEASE_BODY_PATH)) {
|
||||||
|
$body = Get-Content $env:RELEASE_BODY_PATH -Raw -Encoding utf8
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = @()
|
||||||
|
foreach ($pattern in ($env:RELEASE_FILES -split "[`r`n,]+" | Where-Object { $_.Trim() })) {
|
||||||
|
$found = @(Get-ChildItem -Path $pattern.Trim() -File -ErrorAction SilentlyContinue)
|
||||||
|
if ($found.Count -eq 0) { throw "リリースに付けるファイルが見つかりません: $pattern" }
|
||||||
|
$files += $found
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = @{
|
||||||
|
tag_name = $tag
|
||||||
|
name = $env:RELEASE_NAME
|
||||||
|
body = [string]$body
|
||||||
|
draft = ($env:RELEASE_DRAFT -eq 'true')
|
||||||
|
prerelease = ($env:RELEASE_PRERELEASE -eq 'true')
|
||||||
|
} | ConvertTo-Json
|
||||||
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes($payload)
|
||||||
|
|
||||||
|
$existing = $null
|
||||||
|
try { $existing = Invoke-RestMethod -Uri "$api/releases/tags/$([System.Uri]::EscapeDataString($tag))" -Headers $headers } catch { }
|
||||||
|
if ($existing) {
|
||||||
|
$release = Invoke-RestMethod -Method Patch -Uri "$api/releases/$($existing.id)" -Headers $headers -ContentType "application/json; charset=utf-8" -Body $bytes
|
||||||
|
foreach ($asset in @($existing.assets)) {
|
||||||
|
Invoke-RestMethod -Method Delete -Uri "$api/releases/$($existing.id)/assets/$($asset.id)" -Headers $headers | Out-Null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$release = Invoke-RestMethod -Method Post -Uri "$api/releases" -Headers $headers -ContentType "application/json; charset=utf-8" -Body $bytes
|
||||||
|
}
|
||||||
|
foreach ($file in $files) {
|
||||||
|
$name = [System.Uri]::EscapeDataString($file.Name)
|
||||||
|
Invoke-RestMethod -Method Post -Uri "$api/releases/$($release.id)/assets?name=$name" -Headers $headers -Form @{ attachment = Get-Item $file.FullName } | Out-Null
|
||||||
|
Write-Host "添付しました: $($file.Name)"
|
||||||
|
}
|
||||||
|
Write-Host "リリースを作成しました: $($release.html_url)"
|
||||||
|
|
||||||
|
if ($env:EVENT_NAME -eq 'workflow_dispatch') {
|
||||||
|
try {
|
||||||
|
$sha = (git rev-parse HEAD).Trim()
|
||||||
|
$status = @{
|
||||||
|
state = 'success'
|
||||||
|
context = "$env:WORKFLOW_NAME / $env:JOB_NAME (workflow_dispatch)"
|
||||||
|
description = "Actions がタグ $tag のコミットから作成しました"
|
||||||
|
target_url = $env:RUN_URL
|
||||||
|
} | ConvertTo-Json
|
||||||
|
Invoke-RestMethod -Method Post -Uri "$api/statuses/$sha" -Headers $headers -ContentType "application/json; charset=utf-8" -Body ([System.Text.Encoding]::UTF8.GetBytes($status)) | Out-Null
|
||||||
|
Write-Host "タグのコミット $sha に成功の状態を付けました"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "タグのコミットに状態を付けられませんでした: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
# v1.0.0 - 墨拡散 for YMM4
|
|
||||||
|
|
||||||
YukkuriMovieMaker4向けの墨拡散エフェクトプラグインの初回リリースです。
|
|
||||||
素材を墨の付置とみなし、Chu and TaiのMoXiモデルの格子ボルツマン方程式で吸水紙中の浸透流を正方格子の上に解き、墨として描画します。
|
|
||||||
にじみの形は紙の繊維とシードから決定論的に決まり、拡散度のパラメータで素材から墨がにじみ広がっていく遷移を表現できます。
|
|
||||||
計算はComputeSharpの計算シェーダーがDirect3D 12で実行し、YMM4のDirect3D 11側とは共有テクスチャおよび共有フェンスで接続します。
|
|
||||||
8言語のリソース構成のUIを備えます。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 新機能
|
|
||||||
|
|
||||||
### 1. 墨拡散の計算パイプライン
|
|
||||||
|
|
||||||
`InkDispersionPipeline`は、シルエット、浸透、描画の3段階の計算シェーダーを`ComputeContext`へ記録して実行します。浸透格子のバッファーは計算領域の大きさと品質に応じて確保し、サイズが変わらないフレームでは再利用します。処理の流れは次のとおりです。
|
|
||||||
|
|
||||||
1. `SilhouetteShader`が、各格子セルに対応する画素のアルファ値の平均を調べ、素材の墨だまりとして記録します。
|
|
||||||
2. `InitFieldShader`が、分布関数と流動層と定着層を初期化し、墨だまりのアルファ値と水量から表面層の水を設定します。
|
|
||||||
3. `JumpFloodSeedShader`と`JumpFloodPassShader`が、格子解像度のジャンプフラッドで各セルから最も近い墨だまりのセルを求め、`ReachMaskShader`が到達距離の内側のセルだけを浸透の対象として記録します。
|
|
||||||
4. `SupplyShader`・`KappaShader`・`StreamCollideShader`・`PigmentShader`が、浸透の1ステップを4回のディスパッチとして実行し、ステップ数の分だけ記録を繰り返します。
|
|
||||||
5. `FinalFixShader`が、流動層に残った顔料をすべて定着層へ移します。
|
|
||||||
6. `RenderShader`が、画素ごとに近傍セルの定着顔料と湿潤度を双一次補間で集計し、被覆、かすれ、濃度を計算して出力します。
|
|
||||||
|
|
||||||
| シェーダー | 役割 |
|
|
||||||
|---|---|
|
|
||||||
| `SilhouetteShader` | 画素のアルファ値から素材の墨だまりを求める |
|
|
||||||
| `MaskHashShader` | 墨だまりのハッシュを集計する |
|
|
||||||
| `InitFieldShader` | 分布関数と各層の場を初期化する |
|
|
||||||
| `JumpFloodSeedShader` / `JumpFloodPassShader` | 最近傍の墨だまりのセルを求める |
|
|
||||||
| `ReachMaskShader` | 到達距離の内側のセルへ印を付ける |
|
|
||||||
| `SupplyShader` | 表面層の水と顔料を流動層へ供給する |
|
|
||||||
| `KappaShader` | 阻害係数とピン止めを判定する |
|
|
||||||
| `StreamCollideShader` | 分布関数の流走と衝突を更新する |
|
|
||||||
| `PigmentShader` | 顔料の移流と定着を更新する |
|
|
||||||
| `FinalFixShader` | 残った顔料を定着させる |
|
|
||||||
| `RenderShader` | 墨を描画する |
|
|
||||||
|
|
||||||
### 2. MoXiモデルの浸透ステップ
|
|
||||||
|
|
||||||
浸透の計算は、Chu and Taiの論文「MoXi: Real-Time Ink Dispersion in Absorbent Paper」(SIGGRAPH 2005)の格子ボルツマン方程式に基づきます。格子は各セルが9方向の格子ベクトルを持つD2Q9の正方格子です。各セルは9個の分布関数、表面層の水、流動層の顔料、定着層の顔料の状態を持ちます。
|
|
||||||
|
|
||||||
1ステップの更新は次の順で行います。
|
|
||||||
|
|
||||||
- 供給: 表面層の水を`φ = clamp(s, 0, π − ρ)`(紙の容量`π = 1`)だけ流動層へ吸い込み、格子の重みで分布関数へ加えます。顔料は水の比`(pf・ρ + φ) / (ρ + φ)`で混合します。
|
|
||||||
- 阻害係数: 各セルの阻害係数を、繊維場と礬水の点模様と膠の濃度と定着顔料の蓄積の重み付き和として求め、`0.95`を上限とします。乾いたセルは、8近傍の水の密度がすべてしきい値を下回る間はピン止めされ、対角近傍のしきい値は最近傍の√2倍です。
|
|
||||||
- 流走: 半跳ね返り方式で、繋がった2つのセルの阻害係数の平均に応じて分布関数の一部を跳ね返します。この平均により、両方向の跳ね返り量が等しくなり、運動量と水の量が保存されます。ピン止めされた境界で跳ね返る分布関数は割合`5×10⁻⁵`で減衰させます。
|
|
||||||
- 衝突: 平衡分布はHe and Luoの非圧縮変種を使い、水の少ない場所では`ψ = smoothstep(0, 0.35, ρ)`の重みで移流の項を弱めて負の密度を防ぎます。数値安定化のため格子速度の大きさに上限`0.3`を設けます。蒸発は全分布関数を割合`ε`で減衰させます。
|
|
||||||
- 顔料: 新しく濡れたセルへは上流からの分布関数の重み`Σ f_i・pf(x − e_i) / ρ`で運び、すでに濡れたセルでは速度を遡る特性曲線法で運びます。流速の低い場所と繊維の濃い場所では顔料が流れから遅れます。水を失うセルでは損失の比率に応じて顔料を定着層へ移し、定着した顔料へ到達ステップを記録します。
|
|
||||||
|
|
||||||
緩和係数`ω`は粘度のパラメータから0.5〜1.5、表面層の水の量は水量のパラメータから0.4〜3.0、ピン止めのしきい値はにじみ止めのパラメータから0.0015〜0.0515、蒸発の割合`ε`は乾燥のパラメータから0〜0.005へ割り当てます。繊維場と礬水の点模様とピン止めの筋模様は、シードとセル位置のハッシュによる値ノイズとして決定論的に生成します。乱数は使用せず、すべての値が入力から決定論的に決まります。浸透は到達距離の印を持つセルへ限定し、にじみの広がりを素材からの距離で制限します。
|
|
||||||
|
|
||||||
流走と顔料のシェーダーは、分布関数と顔料をそれぞれ2枚のバッファーで交互に読み書きし、全ステップを1つの`ComputeContext`へ記録して送出します。
|
|
||||||
|
|
||||||
### 3. 可視範囲への出力矩形の最小化
|
|
||||||
|
|
||||||
浸透の完了後、顔料到達ステップの記録をCPUへ読み戻します。読み戻す量は格子1面の整数だけで、画素は読み戻しません。到達ステップごとの境界を累積した配列を1回の走査で構築するため、拡散度が定める可視セルのバウンディングボックスはフレームごとに一定時間で求まります。
|
|
||||||
|
|
||||||
- 矩形には双一次補間の1セル分の余白を加え、4画素境界へそろえます。
|
|
||||||
- 出力テクスチャは矩形の大きさで確保し、Direct2Dの`Crop`と`AffineTransform2D`で元の位置へ合成します。
|
|
||||||
- 矩形の外側は描画も合成も行わないため、到達距離を大きくしても処理量は墨が実在する範囲に比例します。
|
|
||||||
|
|
||||||
### 4. 構造キャッシュ
|
|
||||||
|
|
||||||
にじみの形を決める入力が変わらないフレームでは、浸透の計算を再利用します。
|
|
||||||
|
|
||||||
- 素材の墨だまりは、シルエットの計算後にセル位置と量子化したアルファ値のハッシュの総和とXORの2値へ集約し、8個の整数の読み戻しで前フレームと比較します。
|
|
||||||
- 墨だまりのハッシュ、計算領域の大きさ、品質、シード、到達距離、水量、繊維、にじみ止め、粘度、乾燥が一致する場合は、浸透段階と記録の読み戻しを実行しません。
|
|
||||||
- 構造が同じで、拡散度、濃度、かすれ、墨色、出力矩形も変わらないフレームでは、描画段階も実行せず、前フレームの出力テクスチャを使用します。
|
|
||||||
|
|
||||||
### 5. Direct3D 11・Direct3D 12相互運用
|
|
||||||
|
|
||||||
`InkDispersionGpuInterop`は、YMM4のDirect3D 11・Direct2D側と、ComputeSharpのDirect3D 12側を接続します。ComputeSharpの`GraphicsDevice`は、YMM4が使うDXGIアダプターのLUIDと一致するものを選びます。
|
|
||||||
|
|
||||||
入力と出力は、ComputeSharpで確保した共有テクスチャをDirect3D 11のテクスチャとして開き、Direct2Dのビットマップとして扱います。入力のテクスチャは素材の大きさで確保し、出力のテクスチャは可視範囲の矩形を収める容量で確保して拡大時だけ作り直します。両デバイスの同期は、Direct3D 12のフェンスを共有フェンスとしてDirect3D 11側で開いて行います。
|
|
||||||
|
|
||||||
`BeginCompute`は、Direct3D 11のコマンドを送出したうえでDirect3D 12側を待機させ、`EndCompute`は、Direct3D 12側の完了をDirect3D 11側で待ちます。
|
|
||||||
|
|
||||||
Direct3D 12デバイスの取得や共有リソースの作成に失敗した場合は、`TryCreate`が`null`を返し、エフェクトを適用せず入力映像を表示します。
|
|
||||||
|
|
||||||
### 6. カスタムシェーダーによる合成
|
|
||||||
|
|
||||||
`InkDispersionCustomEffect`は、`[CustomEffect(2)]`の2入力エフェクトです。入力0は元映像、入力1は描画した墨です。ピクセルシェーダー`InkDispersion.hlsl`の`main`は、`amount`が0以下のとき元映像をそのまま返し、そうでないときは墨のRGBをアルファでクランプし、`ink + source * (1 - ink.a)`のアルファ合成で墨を元映像の上へ重ねます。墨の濃淡は描画段階で画素へ焼き込むため、合成は単純な重ね合わせです。
|
|
||||||
|
|
||||||
定数バッファーは`Amount`と3つの詰め物で16バイトです。`MapInputRectsToOutputRect`は2つの入力矩形の和集合を出力矩形とします。墨は素材の外側へ広がるため、出力範囲は素材より大きくなります。
|
|
||||||
|
|
||||||
シェーダーリソース: `pack://application:,,,/InkDispersion;component/Shaders/InkDispersion.cso`(ps_5_0、`ShaderResourceUri.Get`が生成)
|
|
||||||
|
|
||||||
### 7. エフェクト定義とパラメータ
|
|
||||||
|
|
||||||
`InkDispersionEffect`は、YMM4の映像エフェクトとして宣言されます。
|
|
||||||
|
|
||||||
`[VideoEffect]`属性は以下のパラメーターで宣言されます。
|
|
||||||
|
|
||||||
- 表示名: `Texts.InkDispersion`(ローカライズキー、日本語では「墨拡散」)
|
|
||||||
- カテゴリー: `VideoEffectCategories.Decoration`・`VideoEffectCategories.Animation`
|
|
||||||
- 検索タグ: `TagInk`・`TagBlot`・`TagJapanese`
|
|
||||||
- `IsAviUtlSupported = false`によりAviUtl向けEXO出力は非対応
|
|
||||||
- `ResourceType = typeof(Texts)`でローカライズリソースを指定
|
|
||||||
|
|
||||||
公開プロパティは以下のとおりです。基本項目は「基本」グループ、浸透項目は「浸透」グループ、描画項目は「描画」グループに属します。
|
|
||||||
|
|
||||||
| プロパティ | 型 | デフォルト | 内部範囲 | アニメーション |
|
|
||||||
|---|---|---|---|---|
|
|
||||||
| `Amount` | `Animation` | 100 | 0〜100 | あり |
|
|
||||||
| `Spread` | `Animation` | 100 | 0〜100 | あり |
|
|
||||||
| `Quality` | `InkDispersionQuality` | `High` | — | なし |
|
|
||||||
| `Water` | `Animation` | 60 | 0〜100 | あり |
|
|
||||||
| `Reach` | `Animation` | 25 | 1〜400 | あり |
|
|
||||||
| `Fiber` | `Animation` | 50 | 0〜100 | あり |
|
|
||||||
| `Sizing` | `Animation` | 30 | 0〜100 | あり |
|
|
||||||
| `Viscosity` | `Animation` | 30 | 0〜100 | あり |
|
|
||||||
| `Drying` | `Animation` | 40 | 0〜100 | あり |
|
|
||||||
| `Seed` | `int` | 0 | 0〜int.MaxValue | なし |
|
|
||||||
| `Density` | `Animation` | 80 | 0〜100 | あり |
|
|
||||||
| `Grain` | `Animation` | 40 | 0〜100 | あり |
|
|
||||||
| `InkColor` | `Color` | #FF1E1A18 | — | なし |
|
|
||||||
|
|
||||||
`GetAnimatables`は`Amount`・`Spread`・`Water`・`Reach`・`Fiber`・`Sizing`・`Viscosity`・`Drying`・`Density`・`Grain`を返します。`Seed`は負値を代入すると0へ丸めます。
|
|
||||||
|
|
||||||
`CreateExoVideoFilters`は空のシーケンスを返します(EXO非対応)。`CreateVideoEffect`は映像処理用のインスタンスを生成します。エフェクトを最初に生成したときに、更新確認を一度だけ開始します。
|
|
||||||
|
|
||||||
### 8. フレームごとの更新
|
|
||||||
|
|
||||||
各フレームでYMM4の`EffectDescription`からフレーム位置、アイテム長、FPSを取得し、アニメーション値を評価します。値をパイプラインが前提とする範囲へ制限してから転送します。
|
|
||||||
|
|
||||||
| パラメータ | 変換 |
|
|
||||||
|---|---|
|
|
||||||
| `Amount` | `value / 100` をカスタムシェーダーの`Amount`へ |
|
|
||||||
| `Spread` | `value / 100` を0〜1へクランプ |
|
|
||||||
| `Water` | `value / 100` を0〜1へクランプし、表面層の水0.4〜3.0へ |
|
|
||||||
| `Reach` | `value / 100` を0.01〜4へクランプし、素材の長辺に掛けて画素数へ |
|
|
||||||
| `Fiber` | `value / 100` を0〜1へクランプ |
|
|
||||||
| `Sizing` | `value / 100` を0〜1へクランプし、ピン止めのしきい値0.0015〜0.0515へ |
|
|
||||||
| `Viscosity` | `value / 100` を0〜1へクランプし、緩和係数1.5〜0.5へ |
|
|
||||||
| `Drying` | `value / 100` を0〜1へクランプし、蒸発の割合0〜0.005へ |
|
|
||||||
| `Density` | `value / 100` を0〜1へクランプ |
|
|
||||||
| `Grain` | `value / 100` を0〜1へクランプ |
|
|
||||||
| `InkColor` | RGB各成分を0〜1へ |
|
|
||||||
| `Seed` | 0以上へクランプ |
|
|
||||||
|
|
||||||
強さが0以下のとき、または拡散度が0以下のときは、墨を描画せず入力映像をそのまま出力します。入力の範囲が有限でない場合や、計算領域の余白を確保できない場合も、入力映像を表示します。
|
|
||||||
|
|
||||||
### 9. 品質設定
|
|
||||||
|
|
||||||
品質は、浸透格子の解像度と浸透ステップ数の上限をまとめて切り替えます。
|
|
||||||
|
|
||||||
| 品質 | 格子解像度 | 浸透ステップ上限 |
|
|
||||||
|---|---:|---:|
|
|
||||||
| 標準 | 160 | 720回 |
|
|
||||||
| 高品質 | 224 | 1080回 |
|
|
||||||
| 最高品質 | 288 | 1440回 |
|
|
||||||
|
|
||||||
格子解像度は計算領域の長辺のセル数です。短辺のセル数は計算領域の縦横比に合わせ、最小4セルとします。実際のステップ数は到達距離に応じたセル数から決まり、上限で打ち切ります。
|
|
||||||
|
|
||||||
### 10. ローカライズ
|
|
||||||
|
|
||||||
`Texts`クラスは`[AutoGenLocalizer]`属性を持つ`partial`クラスとして宣言されます。
|
|
||||||
`YukkuriMovieMaker.Generator`のソースジェネレーターが`Texts.csv`を処理し、各ロケールのリソースファイルを自動生成します。
|
|
||||||
|
|
||||||
対応リソース: 日本語(`ja-jp`)・英語(`en-us`)・中国語簡体字(`zh-cn`)・中国語繁体字(`zh-tw`)・韓国語(`ko-kr`)・スペイン語(`es-es`)・アラビア語(`ar-sa`)・インドネシア語(`id-id`)
|
|
||||||
|
|
||||||
主なローカライズキーは以下のとおりです。
|
|
||||||
|
|
||||||
| キー | ja-jp |
|
|
||||||
|---|---|
|
|
||||||
| `InkDispersion` | 墨拡散 |
|
|
||||||
| `BasicGroup` | 基本 |
|
|
||||||
| `FlowGroup` | 浸透 |
|
|
||||||
| `AppearanceGroup` | 描画 |
|
|
||||||
| `Amount` | 強さ |
|
|
||||||
| `Spread` | 拡散度 |
|
|
||||||
| `Quality` | 品質 |
|
|
||||||
| `Water` | 水量 |
|
|
||||||
| `Reach` | 到達距離 |
|
|
||||||
| `Fiber` | 繊維 |
|
|
||||||
| `Sizing` | にじみ止め |
|
|
||||||
| `Viscosity` | 粘度 |
|
|
||||||
| `Drying` | 乾燥 |
|
|
||||||
| `Seed` | シード |
|
|
||||||
| `Density` | 濃度 |
|
|
||||||
| `Grain` | かすれ |
|
|
||||||
| `InkColor` | 墨色 |
|
|
||||||
| `QualityBalanced` | 標準 |
|
|
||||||
| `QualityHigh` | 高品質 |
|
|
||||||
| `QualityUltra` | 最高品質 |
|
|
||||||
| `TagInk` | 墨 |
|
|
||||||
| `TagBlot` | にじみ |
|
|
||||||
| `TagJapanese` | 和風 |
|
|
||||||
| `UpdateAvailableMessage` | 新しいバージョン {0} が公開されています。 |
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
github: routersys
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
name: 不具合の報告
|
||||||
|
description: エラーが出る、強制終了する、出力が乱れる、README と違う動きをする、といった不具合を報告します。
|
||||||
|
title: "[Bug] "
|
||||||
|
labels: ["bug"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
脆弱性はここに書かず、リポジトリのセキュリティポリシーに従って非公開で報告してください。
|
||||||
|
README と実際の動きが違い、文書のほうが誤りだと考えるときは、文書の不備を使ってください。
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: plugin-version
|
||||||
|
attributes:
|
||||||
|
label: プラグインのバージョン
|
||||||
|
description: GitHub のリリースか、配布パッケージの Readme.txt の見出しで確かめられます。
|
||||||
|
placeholder: v1.0.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: ymm4-version
|
||||||
|
attributes:
|
||||||
|
label: YukkuriMovieMaker4 のバージョン
|
||||||
|
description: YukkuriMovieMaker4 のメインウィンドウのタイトルに表示されるバージョンを、そのまま書いてください。
|
||||||
|
placeholder: v4.56.1.0 Lite
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: os
|
||||||
|
attributes:
|
||||||
|
label: Windows のバージョン
|
||||||
|
description: winver を実行し、ビルド番号まで書いてください。
|
||||||
|
placeholder: Windows 11 24H2, 26100.2605
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: gpu
|
||||||
|
attributes:
|
||||||
|
label: GPU とドライバー
|
||||||
|
description: 描画や GPU に関わる不具合では必ず書いてください。デバイスマネージャーか dxdiag に表示される GPU の名前と、ドライバーのバージョンです。
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: expected
|
||||||
|
attributes:
|
||||||
|
label: 期待した動き
|
||||||
|
description: 何が起きると考えたか。README に根拠があれば、その箇所も書いてください。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: actual
|
||||||
|
attributes:
|
||||||
|
label: 実際の動き
|
||||||
|
description: 実際に起きたこと。エラー画面が出たときは、その内容を省略せずに貼ってください。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: steps
|
||||||
|
attributes:
|
||||||
|
label: 再現の手順
|
||||||
|
description: |
|
||||||
|
新しいプロジェクトから不具合が起きるまでの操作を、番号を付けて書いてください。変えた設定の項目と値も書いてください。
|
||||||
|
プロジェクトファイルや素材は、zip に圧縮して添付できます。添付したファイルは誰でも見られます。プロジェクトファイルには素材を置いたフォルダーのパスが記録されるので、公開できない情報が無いかを確かめてください。
|
||||||
|
placeholder: |
|
||||||
|
1. 新しいプロジェクトを作る
|
||||||
|
2. アイテムを置き、本プラグインを使う
|
||||||
|
3. 設定を変える
|
||||||
|
4. 不具合が起きる
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: dropdown
|
||||||
|
id: frequency
|
||||||
|
attributes:
|
||||||
|
label: 起きる頻度
|
||||||
|
description: ときどき起きるときは、何回試して何回起きたかを、下の「その他」の欄に書いてください。
|
||||||
|
options:
|
||||||
|
- 毎回起きる
|
||||||
|
- ときどき起きる
|
||||||
|
- 一度だけ起きた
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: context
|
||||||
|
attributes:
|
||||||
|
label: その他
|
||||||
|
description: 一緒に使っているほかのプラグインや、関係すると思われることを書いてください。
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
id: checks
|
||||||
|
attributes:
|
||||||
|
label: 報告の前に
|
||||||
|
options:
|
||||||
|
- label: 最新のリリースを使っています。
|
||||||
|
required: true
|
||||||
|
- label: 既存の Issue を検索し、同じ報告が無いことを確かめました。
|
||||||
|
required: true
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: YukkuriMovieMaker4 本体の不具合
|
||||||
|
url: https://manjubox.net/contact/
|
||||||
|
about: 本体に原因がある不具合は、YukkuriMovieMaker4 の「ヘルプ」の「フィードバックを送信」か、公式サイトのお問い合わせから報告してください。
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
name: 文書の不備
|
||||||
|
description: 誤り、書き漏れ、実際の動きとの食い違いがある文書を報告します。
|
||||||
|
title: "[Docs] "
|
||||||
|
labels: ["documentation"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
実際の動きと文書が食い違うときは、ここで報告して構いません。動きのほうが誤りだと考えるときは、不具合の報告を使ってください。
|
||||||
|
|
||||||
|
- type: dropdown
|
||||||
|
id: location
|
||||||
|
attributes:
|
||||||
|
label: 文書
|
||||||
|
options:
|
||||||
|
- README
|
||||||
|
- 配布パッケージの Readme.txt
|
||||||
|
- 設定の項目の名前や説明
|
||||||
|
- 貢献の手引き、セキュリティポリシー、行動規範
|
||||||
|
- その他
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: reference
|
||||||
|
attributes:
|
||||||
|
label: 文書の中の位置
|
||||||
|
description: 見出し、行番号、設定の項目の名前のどれかを書いてください。
|
||||||
|
placeholder: README の「制限事項」の 2 つ目の項目
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: says
|
||||||
|
attributes:
|
||||||
|
label: 今の記述
|
||||||
|
description: そのまま引用してください。元の文書を開かずに検討できるようにするためです。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: problem
|
||||||
|
attributes:
|
||||||
|
label: どこが問題か
|
||||||
|
description: |
|
||||||
|
誤り、書き漏れ、曖昧さのどれに当たるかを書いてください。それによって読む人が何を取り違えるかも書いてください。
|
||||||
|
実際の動きと食い違っているときは、文書と動きのどちらを直すべきと考えるかも書いてください。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: suggestion
|
||||||
|
attributes:
|
||||||
|
label: 提案する文面
|
||||||
|
description: 具体的な文面があると、早く直せます。
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
id: checks
|
||||||
|
attributes:
|
||||||
|
label: 報告の前に
|
||||||
|
options:
|
||||||
|
- label: 最新のリリースか、既定のブランチの最新の文書で確かめました。
|
||||||
|
required: true
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
name: 機能の提案
|
||||||
|
description: 新しい機能や設定の項目、既存の動きの変更を提案します。
|
||||||
|
title: "[Proposal] "
|
||||||
|
labels: ["enhancement"]
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: problem
|
||||||
|
attributes:
|
||||||
|
label: 困っていること
|
||||||
|
description: 今のプラグインでできないことや、手間がかかることを、利用者の立場で書いてください。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: workaround
|
||||||
|
attributes:
|
||||||
|
label: 今はどうしているか
|
||||||
|
description: 今の回避策と、それにかかる手間を書いてください。回避策が無ければ、その旨を書いてください。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: proposal
|
||||||
|
attributes:
|
||||||
|
label: 提案する動き
|
||||||
|
description: どう動いてほしいかを書いてください。設定の項目を増やす提案では、項目の名前、範囲、既定値の案も書いてください。
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: alternatives
|
||||||
|
attributes:
|
||||||
|
label: 検討したほかの方法
|
||||||
|
description: ほかに考えた方法があれば、それでは足りない理由と一緒に書いてください。
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
id: checks
|
||||||
|
attributes:
|
||||||
|
label: 提案の前に
|
||||||
|
options:
|
||||||
|
- label: 既存の Issue を検索し、同じ提案が無いことを確かめました。
|
||||||
|
required: true
|
||||||
|
- label: 最新のリリースに同じ機能が無いことを確かめました。
|
||||||
|
required: true
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
name: 使い方の質問
|
||||||
|
description: 使い方や、実際の動きが仕様どおりかを尋ねます。
|
||||||
|
title: "[Question] "
|
||||||
|
labels: ["question"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
プラグインの不具合だと分かっているときは、不具合の報告を使ってください。
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: question
|
||||||
|
attributes:
|
||||||
|
label: 質問
|
||||||
|
description: 背景を書く前に、質問を 1 文か 2 文で書いてください。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: goal
|
||||||
|
attributes:
|
||||||
|
label: 何をしようとしているか
|
||||||
|
description: つまずいている操作だけでなく、最終的に何を作りたいかを書いてください。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: tried
|
||||||
|
attributes:
|
||||||
|
label: 試したこと
|
||||||
|
description: 試した設定と、そのとき実際に起きたことを書いてください。
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: plugin-version
|
||||||
|
attributes:
|
||||||
|
label: プラグインのバージョン
|
||||||
|
placeholder: v1.0.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
id: checks
|
||||||
|
attributes:
|
||||||
|
label: 質問の前に
|
||||||
|
options:
|
||||||
|
- label: README の該当する節を読みました。
|
||||||
|
required: true
|
||||||
|
- label: 既存の Issue を検索し、同じ質問が無いことを確かめました。
|
||||||
|
required: true
|
||||||
+60
-8
@@ -1,5 +1,5 @@
|
|||||||
========================================
|
========================================
|
||||||
墨拡散 for YMM4 v1.0.0
|
墨拡散 for YMM4 v1.1.2
|
||||||
========================================
|
========================================
|
||||||
YukkuriMovieMaker4上で動作する、素材を墨の付置とみなし、
|
YukkuriMovieMaker4上で動作する、素材を墨の付置とみなし、
|
||||||
格子ボルツマン方程式による吸水紙中の浸透流で墨を外へにじませて描画する
|
格子ボルツマン方程式による吸水紙中の浸透流で墨を外へにじませて描画する
|
||||||
@@ -34,8 +34,9 @@ Absorbent Paper」(SIGGRAPH 2005)に基づきます。
|
|||||||
輝度と色は判定に影響しません。履歴フレーム、外部画像、深度情報、
|
輝度と色は判定に影響しません。履歴フレーム、外部画像、深度情報、
|
||||||
学習済みモデルは使用しません。
|
学習済みモデルは使用しません。
|
||||||
|
|
||||||
- 計算領域: 素材の範囲に到達距離と描画の余白を加えた大きさを計算領域とし、
|
- 計算領域: 素材の範囲に到達距離と64画素の余白を加えた大きさを計算領域とし、
|
||||||
長辺は8192画素が上限です。素材が大きく余白を確保できない場合は、
|
長辺が8192画素に収まるように到達距離を縮めます。到達距離は1画素までしか
|
||||||
|
縮めません。素材の長辺が8160画素を超えて余白を確保できない場合は、
|
||||||
エフェクトを適用せず入力映像を表示します。
|
エフェクトを適用せず入力映像を表示します。
|
||||||
|
|
||||||
- 処理負荷: 計算領域の大きさと品質に応じて処理量とGPUメモリ使用量が
|
- 処理負荷: 計算領域の大きさと品質に応じて処理量とGPUメモリ使用量が
|
||||||
@@ -43,8 +44,8 @@ Absorbent Paper」(SIGGRAPH 2005)に基づきます。
|
|||||||
高品質と標準より処理負荷が高くなります。描画は墨が存在する最小の
|
高品質と標準より処理負荷が高くなります。描画は墨が存在する最小の
|
||||||
矩形の範囲だけを計算します。
|
矩形の範囲だけを計算します。
|
||||||
|
|
||||||
- キャッシュ: 素材の形とにじみを決めるパラメータが変わらないフレームでは、
|
- キャッシュ: 素材の形と不透明度、にじみを決めるパラメータが変わらない
|
||||||
浸透の計算を再利用します。
|
フレームでは、浸透の計算を再利用します。
|
||||||
|
|
||||||
- 拡散度0%と強さ0%: 拡散度が0%のときは何も描画しません。強さが0%のときは
|
- 拡散度0%と強さ0%: 拡散度が0%のときは何も描画しません。強さが0%のときは
|
||||||
入力を変更しません。
|
入力を変更しません。
|
||||||
@@ -61,6 +62,57 @@ Absorbent Paper」(SIGGRAPH 2005)に基づきます。
|
|||||||
|
|
||||||
- 本プラグインを使用する前に、YMM4のプロジェクトファイルのバックアップを
|
- 本プラグインを使用する前に、YMM4のプロジェクトファイルのバックアップを
|
||||||
作成することを推奨します。
|
作成することを推奨します。
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
■ 不具合の報告
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
本プラグインは、想定していない例外が起きたときに、その内容を開発者へ自動で
|
||||||
|
送信します。同意は求めません。止める設定もありません。
|
||||||
|
|
||||||
|
送信する数には上限があります。YMM4の1回の起動で送る報告は、
|
||||||
|
YMM4-Telemetryで報告する別のプラグインと合わせて20件までです。
|
||||||
|
例外の型と発生位置が同じ報告は3件までです。上限を超えた報告と、
|
||||||
|
送信先から待つよう求められている間に起きた報告は、送信も退避もしません。
|
||||||
|
|
||||||
|
送信する情報は次のとおりです。
|
||||||
|
例外 : 型の完全名、メッセージ、スタックトレース
|
||||||
|
発生位置 : モジュール名、関数名、ファイル名、行番号、
|
||||||
|
プラグイン自身のコードかどうか
|
||||||
|
プラグイン : アセンブリ名、バージョン
|
||||||
|
実行環境 : OSの名前とバージョン、.NETのバージョン、
|
||||||
|
CPUのアーキテクチャ、論理プロセッサ数
|
||||||
|
識別子 : YMM4の起動ごとに決まるセッション識別子、報告ごとの識別子
|
||||||
|
時刻 : 報告を作った時刻(UTC)
|
||||||
|
|
||||||
|
映像の中身とプロジェクトの内容は送信しません。継続して個人を追跡する
|
||||||
|
識別子も持ちません。セッション識別子はYMM4を起動し直すと別の値に
|
||||||
|
なります。メッセージとファイル名に含まれる利用者名などの文字列は、送信の
|
||||||
|
前に置き換えます。送信元のIPアドレスは受信側へ渡す手前で取り除いています。
|
||||||
|
|
||||||
|
送信するのは想定していない例外だけです。YMM4が本プラグインのエフェクトを
|
||||||
|
作るとき、フレームごとに更新するとき、入力をつなぎ直すとき、破棄するときと、
|
||||||
|
Direct2Dがシェーダーの定数を書き込むときに起きた例外を報告し、その後は
|
||||||
|
YMM4へそのまま渡します。更新の確認では、更新情報の取得と比較で起きた例外は
|
||||||
|
報告しません。通知の文を組み立てて表示するときに起きた例外は報告し、
|
||||||
|
YMM4へは渡しません。画面の操作やバックグラウンドの処理で未処理になった
|
||||||
|
例外も報告しますが、本プラグインのコードが関わる例外に限ります。
|
||||||
|
本プラグインの外で起きた例外は送信しません。
|
||||||
|
|
||||||
|
次の失敗は送信しません。
|
||||||
|
効果をかけないだけで済ませるもの : Direct3D 12デバイスを取得できない、
|
||||||
|
YMM4のDirect3D 11デバイスとの共有
|
||||||
|
テクスチャや共有フェンスを作成できない、
|
||||||
|
計算領域の余白を取れないときに、
|
||||||
|
エフェクトを適用せず入力映像を
|
||||||
|
表示したとき
|
||||||
|
更新の確認の通信の失敗 : manjubox.netとGitHubのどちらへも
|
||||||
|
接続できない
|
||||||
|
|
||||||
|
送信できなかった報告はYMM4のユーザーフォルダーへ退避します。
|
||||||
|
次にYMM4を起動したあと、本プラグインのエフェクトを生成するか、
|
||||||
|
同じくYMM4-Telemetryで報告する別のプラグインが動き始めると、
|
||||||
|
退避した報告を1回の起動で10件まで送り直します。
|
||||||
|
送信も再送も非同期に行うため、通信を待って起動と描画が遅くなることは
|
||||||
|
ありません。
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
■ 免責事項
|
■ 免責事項
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@@ -74,9 +126,9 @@ Absorbent Paper」(SIGGRAPH 2005)に基づきます。
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
■ サードパーティライセンス
|
■ サードパーティライセンス
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
本プラグインはComputeSharp(MIT License)を同梱しています。
|
本プラグインはComputeWeave(MIT License)を同梱しています。
|
||||||
ライセンスの全文は同梱のLICENSEフォルダー(ComputeSharp.txt)に収録しています。
|
ライセンスの全文は同梱のLICENSEフォルダー(ComputeWeave.txt)に収録しています。
|
||||||
ComputeSharp : Copyright (c) 2024 Sergio Pedri
|
ComputeWeave : Copyright (c) 2024 Sergio Pedri
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
■ ライセンス
|
■ ライセンス
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<!--
|
||||||
|
当てはまらない節は消してください。「関連する Issue」と「動きの変更」の節は残し、該当しないときは「なし」と書いてください。
|
||||||
|
-->
|
||||||
|
|
||||||
|
## 概要
|
||||||
|
|
||||||
|
<!--
|
||||||
|
何をどう変えたか。なぜその変更が必要か。
|
||||||
|
-->
|
||||||
|
|
||||||
|
## 関連する Issue
|
||||||
|
|
||||||
|
<!--
|
||||||
|
新しい機能、設定の項目や既定値の変更、大きめの不具合の修正、意図して出力を変える変更、互換性を損なう変更、コードの構成を大きく変える変更は、先に Issue で合意してください。
|
||||||
|
Issue が無い変更では、下の行を「なし」に書き換えてください。
|
||||||
|
-->
|
||||||
|
|
||||||
|
Closes #
|
||||||
|
|
||||||
|
## 変更の種類
|
||||||
|
|
||||||
|
<!-- 当てはまるものを残してください。 -->
|
||||||
|
|
||||||
|
- 不具合の修正
|
||||||
|
- 機能の追加
|
||||||
|
- 動きの変更
|
||||||
|
- 性能の改善
|
||||||
|
- テストの追加
|
||||||
|
- 依存関係の更新
|
||||||
|
- 文書
|
||||||
|
- ビルド、リリース
|
||||||
|
|
||||||
|
## 動きの変更
|
||||||
|
|
||||||
|
<!--
|
||||||
|
利用者から見て何が変わるか。設定の項目、既定値、出力の結果、エラーの出方の変化も含みます。
|
||||||
|
保存済みのプロジェクトの結果が変わるなら、必ず書いてください。
|
||||||
|
-->
|
||||||
|
|
||||||
|
## 検証
|
||||||
|
|
||||||
|
<!--
|
||||||
|
手元で実際に確かめた結果を書いてください。
|
||||||
|
- ビルドの結果と、テストのプロジェクトがあればテストの結果
|
||||||
|
- YukkuriMovieMaker4 で実際に動かして確かめたこと
|
||||||
|
- 実行できなかったテストと、その理由
|
||||||
|
実際に動かして観察したこと、コードを読んで判断したこと、推測したことを分けて書いてください。
|
||||||
|
-->
|
||||||
|
|
||||||
|
使った YukkuriMovieMaker4 のバージョン:
|
||||||
|
|
||||||
|
GPU に関わる変更では、使った GPU とドライバー:
|
||||||
|
|
||||||
|
## 確認
|
||||||
|
|
||||||
|
<!-- テストのプロジェクトが無いリポジトリでは、実装とテストを分ける項目を消してください。 -->
|
||||||
|
|
||||||
|
- [ ] 1 つの目的の変更だけを含み、関係の無い整理や整形を含めていない。
|
||||||
|
- [ ] どのコミットも、それ単独でビルドが通る。
|
||||||
|
- [ ] 実装の変更と、それを確かめるテストを、別のコミットに分けた。
|
||||||
|
- [ ] コミットの件名は日本語で書き、50 文字以内に収め、「〜する」の形で終えた。日本語で書けない場合は、その旨を「レビューで見てほしい点」に書いた。
|
||||||
|
- [ ] コミットの本文は、リリースノートでの変更の分類を指定する行を求められたときだけ書いた。
|
||||||
|
- [ ] 変更する箇所で既に使われている実装のパターンに従った。
|
||||||
|
- [ ] 新しく書いたコードにコメントを入れず、コメントアウトしたコードも残していない。既存のコメントとドキュメントコメントは残した。
|
||||||
|
- [ ] 自分の変更で増えたビルドの警告を直した。
|
||||||
|
- [ ] 出力を変えるつもりの無い変更では、変更前と変更後で出力が一致することを確かめた。
|
||||||
|
- [ ] この変更と関係の無い依存関係の更新を含めていない。
|
||||||
|
- [ ] 動きを変えた場合、README を直した。`.github/Plugin_Readme.txt` があるリポジトリでは、それも直した。
|
||||||
|
- [ ] バージョンを上げる変更を含めていない。
|
||||||
|
|
||||||
|
## 性能の改善を主張する場合
|
||||||
|
|
||||||
|
<!-- それ以外の場合は、この節ごと消してください。 -->
|
||||||
|
|
||||||
|
- [ ] 同じ機材、ドライバー、設定、電源の条件で、変更前と変更後のビルドを交互に繰り返し測った。
|
||||||
|
- [ ] 測定の間を空け、ほかのプロセスが GPU を使っていない状態で測った。
|
||||||
|
- [ ] 正しさの確認と性能の測定を、別々に実行した。
|
||||||
|
|
||||||
|
<!--
|
||||||
|
測定の条件と、測定値。
|
||||||
|
-->
|
||||||
|
|
||||||
|
## レビューで見てほしい点
|
||||||
|
|
||||||
|
<!--
|
||||||
|
判断に迷った点、意見を聞きたい点、意図して外した部分とその理由。
|
||||||
|
-->
|
||||||
+306
-47
@@ -14,31 +14,20 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: ソースコードのチェックアウト
|
- name: ソースコードのチェックアウト
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v7
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: .NET SDKのセットアップ
|
- name: .NET SDK のセットアップ
|
||||||
uses: actions/setup-dotnet@v4
|
uses: actions/setup-dotnet@v6
|
||||||
with:
|
with:
|
||||||
dotnet-version: '10.0.x'
|
dotnet-version: '10.0.x'
|
||||||
|
|
||||||
- name: fxc.exeの検索
|
- name: MSBuild のセットアップ
|
||||||
id: fxc
|
uses: microsoft/setup-msbuild@v3
|
||||||
shell: pwsh
|
|
||||||
run: |
|
|
||||||
$fxc = Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\bin" -Recurse -Filter "fxc.exe" |
|
|
||||||
Where-Object { $_.FullName -like "*x64*" } |
|
|
||||||
Sort-Object FullName -Descending |
|
|
||||||
Select-Object -First 1
|
|
||||||
if (-not $fxc) {
|
|
||||||
Write-Error "fxc.exeが見つかりませんでした。"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Write-Host "fxc.exeの場所: $($fxc.FullName)"
|
|
||||||
echo "FXC_PATH=$($fxc.FullName)" >> $env:GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: YMM4最新リリースの取得と解凍
|
- name: YMM4 最新リリースの取得と解凍
|
||||||
id: ymm4
|
id: ymm4
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
@@ -48,20 +37,12 @@ jobs:
|
|||||||
if (-not $asset) {
|
if (-not $asset) {
|
||||||
$asset = $release.assets | Where-Object { $_.name -like "*.zip" } | Select-Object -First 1
|
$asset = $release.assets | Where-Object { $_.name -like "*.zip" } | Select-Object -First 1
|
||||||
}
|
}
|
||||||
if (-not $asset) {
|
|
||||||
Write-Error "YMM4のリリースにZIPファイルが見つかりませんでした。"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Write-Host "ダウンロード対象: $($asset.name)"
|
Write-Host "ダウンロード対象: $($asset.name)"
|
||||||
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile "ymm4.zip"
|
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile "ymm4.zip"
|
||||||
Expand-Archive -Path "ymm4.zip" -DestinationPath "ymm4_extracted" -Force
|
Expand-Archive -Path "ymm4.zip" -DestinationPath "ymm4_extracted" -Force
|
||||||
$ymm4Dir = (Get-ChildItem -Path "ymm4_extracted" -Recurse -Filter "YukkuriMovieMaker.dll" |
|
$ymm4Dir = (Get-ChildItem -Path "ymm4_extracted" -Recurse -Filter "YukkuriMovieMaker.dll" |
|
||||||
Select-Object -First 1).DirectoryName
|
Select-Object -First 1).DirectoryName
|
||||||
if (-not $ymm4Dir) {
|
Write-Host "YMM4 DLL ディレクトリ: $ymm4Dir"
|
||||||
Write-Error "YukkuriMovieMaker.dllが見つかりませんでした。"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Write-Host "YMM4 DLLディレクトリ: $ymm4Dir"
|
|
||||||
echo "YMM4_DIR=$ymm4Dir\" >> $env:GITHUB_OUTPUT
|
echo "YMM4_DIR=$ymm4Dir\" >> $env:GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: タグ名からバージョンを取得
|
- name: タグ名からバージョンを取得
|
||||||
@@ -70,17 +51,47 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
$tag = "${{ github.ref_name }}"
|
$tag = "${{ github.ref_name }}"
|
||||||
echo "TAG=$tag" >> $env:GITHUB_OUTPUT
|
echo "TAG=$tag" >> $env:GITHUB_OUTPUT
|
||||||
|
echo "VERSION=$($tag.TrimStart('v'))" >> $env:GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: resxファイルの生成
|
- name: バージョン記載の照合
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
$proj = "InkDispersion/InkDispersion.csproj"
|
$tag = "${{ steps.version.outputs.TAG }}"
|
||||||
dotnet build "$proj" `
|
$version = "${{ steps.version.outputs.VERSION }}"
|
||||||
-c Release `
|
$problems = @()
|
||||||
-p:YMM4DirPath="${{ steps.ymm4.outputs.YMM4_DIR }}" `
|
|
||||||
-p:FxcPath="${{ steps.fxc.outputs.FXC_PATH }}" `
|
$csprojPath = "InkDispersion/InkDispersion.csproj"
|
||||||
-p:Platform=x64 `
|
$csproj = Get-Content $csprojPath -Raw
|
||||||
-p:SkipPluginDeploy=true
|
if (-not $csproj.Contains("<Version>$version</Version>")) {
|
||||||
|
$current = if ($csproj -match '<Version>([^<]*)</Version>') { $Matches[1] } else { "記載なし" }
|
||||||
|
$problems += "$csprojPath の <Version> が $current です。$version にしてください。"
|
||||||
|
}
|
||||||
|
|
||||||
|
$readmePath = ".github/Plugin_Readme.txt"
|
||||||
|
$readme = Get-Content $readmePath -Raw
|
||||||
|
if (-not $readme.Contains(" 墨拡散 for YMM4 $tag")) {
|
||||||
|
$current = if ($readme -match '(?m)^ 墨拡散 for YMM4 (\S+)') { $Matches[1] } else { "記載なし" }
|
||||||
|
$problems += "$readmePath の見出しが $current です。$tag にしてください。"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($problems.Count -eq 0) {
|
||||||
|
Write-Host "バージョン記載は $tag と一致しています"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($problem in $problems) {
|
||||||
|
Write-Host "::error::$problem"
|
||||||
|
}
|
||||||
|
Write-Host "::error::リリースの対象は $tag が指すコミットです。タグを付けた後で main へ訂正を積んでも、その訂正はリリースに入りません。タグを削除し、記載を直したコミットを積んでから付け直してください。"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: シェーダーのビルド
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
msbuild InkDispersion.Shader/InkDispersion.Shader.vcxproj `
|
||||||
|
/p:Configuration=Release `
|
||||||
|
/p:Platform=Win32 `
|
||||||
|
/nologo
|
||||||
|
|
||||||
- name: プロジェクトのビルド
|
- name: プロジェクトのビルド
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
@@ -89,7 +100,6 @@ jobs:
|
|||||||
dotnet build "$proj" `
|
dotnet build "$proj" `
|
||||||
-c Release `
|
-c Release `
|
||||||
-p:YMM4DirPath="${{ steps.ymm4.outputs.YMM4_DIR }}" `
|
-p:YMM4DirPath="${{ steps.ymm4.outputs.YMM4_DIR }}" `
|
||||||
-p:FxcPath="${{ steps.fxc.outputs.FXC_PATH }}" `
|
|
||||||
-p:Platform=x64 `
|
-p:Platform=x64 `
|
||||||
-p:SkipPluginDeploy=true
|
-p:SkipPluginDeploy=true
|
||||||
|
|
||||||
@@ -99,7 +109,6 @@ jobs:
|
|||||||
dotnet build InkDispersion.Tests/InkDispersion.Tests.csproj `
|
dotnet build InkDispersion.Tests/InkDispersion.Tests.csproj `
|
||||||
-c Release `
|
-c Release `
|
||||||
-p:YMM4DirPath="${{ steps.ymm4.outputs.YMM4_DIR }}" `
|
-p:YMM4DirPath="${{ steps.ymm4.outputs.YMM4_DIR }}" `
|
||||||
-p:FxcPath="${{ steps.fxc.outputs.FXC_PATH }}" `
|
|
||||||
-p:Platform=x64 `
|
-p:Platform=x64 `
|
||||||
-p:SkipPluginDeploy=true `
|
-p:SkipPluginDeploy=true `
|
||||||
-maxcpucount:1
|
-maxcpucount:1
|
||||||
@@ -118,17 +127,20 @@ jobs:
|
|||||||
id: package
|
id: package
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
$version = "${{ steps.version.outputs.TAG }}"
|
$version = "${{ steps.version.outputs.TAG }}"
|
||||||
$outDir = "InkDispersion/bin/x64/Release/net10.0-windows10.0.19041.0"
|
$outDir = "InkDispersion/bin/x64/Release/net10.0-windows10.0.19041.0"
|
||||||
$stageRoot = "stage/InkDispersion"
|
$stageRoot = "stage/InkDispersion"
|
||||||
$pkgName = "InkDispersion_$version.ymme"
|
$pkgName = "InkDispersion_$version.ymme"
|
||||||
|
|
||||||
New-Item -ItemType Directory -Path $stageRoot -Force | Out-Null
|
New-Item -ItemType Directory -Path $stageRoot -Force | Out-Null
|
||||||
New-Item -ItemType Directory -Path "$stageRoot/LICENSE" -Force | Out-Null
|
New-Item -ItemType Directory -Path "$stageRoot/LICENSE" -Force | Out-Null
|
||||||
|
|
||||||
Copy-Item "$outDir/InkDispersion.dll" "$stageRoot/"
|
$dll = "$outDir/plugin/InkDispersion.dll"
|
||||||
Copy-Item "$outDir/InkDispersion.ComputeSharp.dll" "$stageRoot/"
|
if (-not (Test-Path $dll)) {
|
||||||
Copy-Item "$outDir/InkDispersion.ComputeSharp.Core.dll" "$stageRoot/"
|
Write-Error "ビルド結果に InkDispersion.dll が見つかりませんでした: $dll"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Copy-Item $dll "$stageRoot/"
|
||||||
|
|
||||||
foreach ($lang in @("ar-sa", "en-us", "es-es", "id-id", "ko-kr", "zh-cn", "zh-tw")) {
|
foreach ($lang in @("ar-sa", "en-us", "es-es", "id-id", "ko-kr", "zh-cn", "zh-tw")) {
|
||||||
$src = "$outDir/$lang"
|
$src = "$outDir/$lang"
|
||||||
@@ -138,17 +150,264 @@ jobs:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Copy-Item ".github/LICENSE/*.txt" "$stageRoot/LICENSE/"
|
Copy-Item ".github/LICENSE/*.txt" "$stageRoot/LICENSE/"
|
||||||
Copy-Item ".github/Plugin_Readme.txt" "$stageRoot/Readme.txt"
|
Copy-Item ".github/Plugin_Readme.txt" "$stageRoot/Readme.txt"
|
||||||
|
|
||||||
|
$readme = Get-Content "$stageRoot/Readme.txt" -Raw
|
||||||
|
if (-not $readme.Contains(" 墨拡散 for YMM4 $version")) {
|
||||||
|
Write-Error "同梱する Readme.txt の見出しが $version と一致しません"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
Compress-Archive -Path "stage/*" -DestinationPath $pkgName -CompressionLevel Optimal
|
Compress-Archive -Path "stage/*" -DestinationPath $pkgName -CompressionLevel Optimal
|
||||||
echo "PKG_NAME=$pkgName" >> $env:GITHUB_OUTPUT
|
echo "PKG_NAME=$pkgName" >> $env:GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: GitHubリリースの作成
|
- name: 変更履歴の作成
|
||||||
uses: softprops/action-gh-release@v2
|
id: changelog
|
||||||
|
shell: pwsh
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
TAG: ${{ steps.version.outputs.TAG }}
|
||||||
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
SERVER_URL: ${{ github.server_url }}
|
||||||
|
PACKAGE: ${{ steps.package.outputs.PKG_NAME }}
|
||||||
|
run: |
|
||||||
|
$tag = $env:TAG
|
||||||
|
$repository = $env:REPOSITORY
|
||||||
|
$server = $env:SERVER_URL
|
||||||
|
$code = [char]0x60
|
||||||
|
$fence = [string]::new($code, 3)
|
||||||
|
$unit = [char]0x1f
|
||||||
|
$record = [char]0x1e
|
||||||
|
|
||||||
|
$previous = ""
|
||||||
|
$candidates = @(git tag --list "v*" --merged $tag --sort=-creatordate | Where-Object { $_ -ne $tag })
|
||||||
|
if ($candidates.Count -gt 0) {
|
||||||
|
$previous = $candidates[0]
|
||||||
|
}
|
||||||
|
Write-Host "直前のタグ: $previous"
|
||||||
|
|
||||||
|
$range = if ($previous) { "$previous..$tag" } else { $tag }
|
||||||
|
$log = (@(git log "--format=%H%x1f%s%x1f%an%x1f%ad%x1f%b%x1e" --date=short $range) -join "`n") -split $record
|
||||||
|
|
||||||
|
$commits = @()
|
||||||
|
foreach ($entry in $log) {
|
||||||
|
if (-not $entry.Trim()) { continue }
|
||||||
|
$fields = $entry.TrimStart("`n") -split $unit
|
||||||
|
if ($fields.Count -lt 5) { continue }
|
||||||
|
$commits += [pscustomobject]@{
|
||||||
|
Sha = $fields[0]
|
||||||
|
Subject = $fields[1]
|
||||||
|
Name = $fields[2]
|
||||||
|
Date = $fields[3]
|
||||||
|
Body = $fields[4]
|
||||||
|
Login = ""
|
||||||
|
Avatar = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "コミット数: $($commits.Count)"
|
||||||
|
|
||||||
|
$categories = [ordered]@{
|
||||||
|
A = @{ Title = "追加"; Symbol = "+"; Items = [System.Collections.Generic.List[pscustomobject]]::new() }
|
||||||
|
M = @{ Title = "変更"; Symbol = "~"; Items = [System.Collections.Generic.List[pscustomobject]]::new() }
|
||||||
|
D = @{ Title = "削除"; Symbol = "-"; Items = [System.Collections.Generic.List[pscustomobject]]::new() }
|
||||||
|
F = @{ Title = "修正"; Symbol = "!"; Items = [System.Collections.Generic.List[pscustomobject]]::new() }
|
||||||
|
}
|
||||||
|
foreach ($commit in $commits) {
|
||||||
|
if (-not $commit.Body) { continue }
|
||||||
|
foreach ($bodyLine in ($commit.Body -split "`n")) {
|
||||||
|
$trimmed = $bodyLine.Trim()
|
||||||
|
if ($trimmed -notmatch '^・(.+)-([AMDF])$') { continue }
|
||||||
|
$categories[$Matches[2]].Items.Add([pscustomobject]@{ Text = $Matches[1]; Sha = $commit.Sha })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pending = [System.Collections.Generic.HashSet[string]]::new()
|
||||||
|
foreach ($commit in $commits) {
|
||||||
|
[void]$pending.Add($commit.Sha)
|
||||||
|
}
|
||||||
|
|
||||||
|
$accounts = @{}
|
||||||
|
$page = 1
|
||||||
|
while ($pending.Count -gt 0 -and $page -le 20) {
|
||||||
|
$rows = @()
|
||||||
|
try {
|
||||||
|
$rows = @(gh api "repos/$repository/commits?sha=$tag&per_page=100&page=$page" --jq '.[] | [.sha, (.author.login // ""), (.author.avatar_url // "")] | @tsv')
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "コミットの作者を取得できませんでした: $($_.Exception.Message)"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if ($LASTEXITCODE -ne 0 -or $rows.Count -eq 0) { break }
|
||||||
|
|
||||||
|
foreach ($row in $rows) {
|
||||||
|
$fields = $row -split "`t"
|
||||||
|
if ($fields.Count -lt 3) { continue }
|
||||||
|
if ($pending.Remove($fields[0])) {
|
||||||
|
$accounts[$fields[0]] = @{ Login = $fields[1]; Avatar = $fields[2] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($rows.Count -lt 100) { break }
|
||||||
|
$page++
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($commit in $commits) {
|
||||||
|
if ($accounts.ContainsKey($commit.Sha)) {
|
||||||
|
$commit.Login = $accounts[$commit.Sha].Login
|
||||||
|
$commit.Avatar = $accounts[$commit.Sha].Avatar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$emptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||||
|
$base = if ($previous) { $previous } else { $emptyTree }
|
||||||
|
$shortstat = (@(git diff --shortstat $base $tag) -join " ")
|
||||||
|
$changedFiles = 0
|
||||||
|
$insertions = 0
|
||||||
|
$deletions = 0
|
||||||
|
if ($shortstat -match "(\d+) file") { $changedFiles = [int]$Matches[1] }
|
||||||
|
if ($shortstat -match "(\d+) insertion") { $insertions = [int]$Matches[1] }
|
||||||
|
if ($shortstat -match "(\d+) deletion") { $deletions = [int]$Matches[1] }
|
||||||
|
$diffStat = @(git diff --stat $base $tag)
|
||||||
|
$tagDate = (git log -1 "--format=%ad" --date=short $tag)
|
||||||
|
|
||||||
|
$contributors = @($commits |
|
||||||
|
Group-Object -Property { if ($_.Login) { $_.Login } else { $_.Name } } |
|
||||||
|
Sort-Object -Property Count -Descending)
|
||||||
|
|
||||||
|
function Get-Icon($avatar, $login, $size) {
|
||||||
|
if (-not $avatar) { return "" }
|
||||||
|
$sized = if ($avatar.Contains("?")) { "$avatar&s=$($size * 2)" } else { "$avatar" + "?s=$($size * 2)" }
|
||||||
|
return "<img src=""$sized"" width=""$size"" height=""$size"" alt=""$login""> "
|
||||||
|
}
|
||||||
|
|
||||||
|
$package = Get-Item $env:PACKAGE
|
||||||
|
$size = [math]::Round($package.Length / 1MB, 2)
|
||||||
|
|
||||||
|
$body = [System.Collections.Generic.List[string]]::new()
|
||||||
|
$body.Add("## 概要")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("| 項目 | 内容 |")
|
||||||
|
$body.Add("|---|---|")
|
||||||
|
$body.Add("| タグ | [$tag]($server/$repository/tree/$tag) |")
|
||||||
|
$body.Add("| 公開日 | $tagDate |")
|
||||||
|
if ($previous) {
|
||||||
|
$body.Add("| 直前のリリース | [$previous]($server/$repository/releases/tag/$previous) |")
|
||||||
|
}
|
||||||
|
$body.Add("| コミット数 | $($commits.Count) |")
|
||||||
|
$body.Add("| 貢献者 | $($contributors.Count) 名 |")
|
||||||
|
$body.Add("| 変更されたファイル | $changedFiles |")
|
||||||
|
$body.Add("| 追加された行 | $insertions |")
|
||||||
|
$body.Add("| 削除された行 | $deletions |")
|
||||||
|
|
||||||
|
$hasHighlights = ($categories.Values | ForEach-Object { $_.Items.Count } | Measure-Object -Sum).Sum -gt 0
|
||||||
|
if ($hasHighlights) {
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 主な変更")
|
||||||
|
foreach ($key in $categories.Keys) {
|
||||||
|
$category = $categories[$key]
|
||||||
|
if ($category.Items.Count -eq 0) { continue }
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("### [$($category.Symbol)] $($category.Title)")
|
||||||
|
$body.Add("")
|
||||||
|
foreach ($item in $category.Items) {
|
||||||
|
$short = $item.Sha.Substring(0, 7)
|
||||||
|
$body.Add("- $($item.Text) ([$code$short$code]($server/$repository/commit/$($item.Sha)))")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## ダウンロード")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("| ファイル | サイズ |")
|
||||||
|
$body.Add("|---|---|")
|
||||||
|
$body.Add("| $($package.Name) | $size MB |")
|
||||||
|
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 貢献者")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("| 貢献者 | コミット数 |")
|
||||||
|
$body.Add("|---|---|")
|
||||||
|
foreach ($contributor in $contributors) {
|
||||||
|
$first = $contributor.Group[0]
|
||||||
|
if ($first.Login) {
|
||||||
|
$name = (Get-Icon $first.Avatar $first.Login 40) + "[@$($first.Login)]($server/$($first.Login))"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$name = $first.Name
|
||||||
|
}
|
||||||
|
$body.Add("| $name | $($contributor.Count) |")
|
||||||
|
}
|
||||||
|
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 変更履歴")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("| コミット | 内容 | 貢献者 | 日付 |")
|
||||||
|
$body.Add("|---|---|---|---|")
|
||||||
|
$maximumCommits = 300
|
||||||
|
$listed = 0
|
||||||
|
foreach ($commit in $commits) {
|
||||||
|
if ($listed -ge $maximumCommits) { break }
|
||||||
|
$short = $commit.Sha.Substring(0, 7)
|
||||||
|
$subject = $commit.Subject -replace '\|', '\|'
|
||||||
|
if ($commit.Login) {
|
||||||
|
$author = (Get-Icon $commit.Avatar $commit.Login 20) + "[@$($commit.Login)]($server/$($commit.Login))"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$author = $commit.Name
|
||||||
|
}
|
||||||
|
$body.Add("| [$code$short$code]($server/$repository/commit/$($commit.Sha)) | $subject | $author | $($commit.Date) |")
|
||||||
|
$listed++
|
||||||
|
}
|
||||||
|
if ($commits.Count -gt $maximumCommits) {
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("残り $($commits.Count - $maximumCommits) 件のコミットは省略しました。")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($diffStat.Count -gt 0) {
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 変更されたファイル")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("<details>")
|
||||||
|
$body.Add("<summary>差分の統計</summary>")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add($fence)
|
||||||
|
$maximumStatLines = 200
|
||||||
|
$shown = 0
|
||||||
|
foreach ($line in $diffStat) {
|
||||||
|
if ($shown -ge $maximumStatLines) { break }
|
||||||
|
$body.Add($line)
|
||||||
|
$shown++
|
||||||
|
}
|
||||||
|
if ($diffStat.Count -gt $maximumStatLines) {
|
||||||
|
$body.Add("... 残り $($diffStat.Count - $maximumStatLines) 行は省略しました。")
|
||||||
|
}
|
||||||
|
$body.Add($fence)
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("</details>")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($previous) {
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("## 全ての変更")
|
||||||
|
$body.Add("")
|
||||||
|
$body.Add("$server/$repository/compare/$previous...$tag")
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = "release-body.md"
|
||||||
|
Set-Content -Path $path -Value ($body -join "`n") -Encoding utf8NoBOM
|
||||||
|
if (-not (Test-Path $path)) {
|
||||||
|
throw "変更履歴を作成できませんでした。"
|
||||||
|
}
|
||||||
|
Write-Host "変更履歴の行数: $($body.Count)"
|
||||||
|
$global:LASTEXITCODE = 0
|
||||||
|
|
||||||
|
- name: GitHub リリースの作成
|
||||||
|
uses: softprops/action-gh-release@v3
|
||||||
with:
|
with:
|
||||||
name: ${{ steps.version.outputs.TAG }}
|
name: ${{ steps.version.outputs.TAG }}
|
||||||
body_path: .github/CHANGELOG.md
|
body_path: release-body.md
|
||||||
files: ${{ steps.package.outputs.PKG_NAME }}
|
files: ${{ steps.package.outputs.PKG_NAME }}
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: false
|
prerelease: false
|
||||||
+3
-1
@@ -362,4 +362,6 @@ MigrationBackup/
|
|||||||
.ionide/
|
.ionide/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
# Stryker.NET
|
||||||
|
StrykerOutput/
|
||||||
+5
-5
@@ -1,9 +1,9 @@
|
|||||||
[submodule "YukkuriMovieMaker.Generator"]
|
[submodule "YukkuriMovieMaker.Generator"]
|
||||||
path = YukkuriMovieMaker.Generator
|
path = YukkuriMovieMaker.Generator
|
||||||
url = https://github.com/manju-summoner/YukkuriMovieMaker.Generator.git
|
url = https://git.routersys.com/manju-summoner/YukkuriMovieMaker.Generator.git
|
||||||
[submodule "YMM4-GitHubUpdateNotifier"]
|
[submodule "YMM4-GitHubUpdateNotifier"]
|
||||||
path = YMM4-GitHubUpdateNotifier
|
path = YMM4-GitHubUpdateNotifier
|
||||||
url = https://github.com/routersys/YMM4-GitHubUpdateNotifier.git
|
url = https://git.routersys.com/routersys/YMM4-GitHubUpdateNotifier.git
|
||||||
[submodule "ComputeSharp"]
|
[submodule "YMM4-Telemetry"]
|
||||||
path = ComputeSharp
|
path = YMM4-Telemetry
|
||||||
url = https://github.com/routersys/ComputeSharp.git
|
url = https://git.routersys.com/routersys/YMM4-Telemetry.git
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
# Contributor Covenant 行動規範
|
||||||
|
|
||||||
|
## 私たちの約束
|
||||||
|
|
||||||
|
メンバー、貢献者、リーダーである私たちは、年齢、体格、目に見える障害と目に見えない障害、民族、性的特徴、性自認と性表現、経験の程度、教育、社会経済的地位、国籍、外見、人種、宗教、性的アイデンティティと性的指向を問わず、コミュニティへの参加を誰にとっても嫌がらせの無いものにすることを誓います。
|
||||||
|
|
||||||
|
私たちは、開かれていて誰もが歓迎される、多様で包摂的な、健全なコミュニティを作るように行動し、交流することを誓います。
|
||||||
|
|
||||||
|
## 私たちの基準
|
||||||
|
|
||||||
|
コミュニティのよい環境を作る行動の例は、次のとおりです。
|
||||||
|
|
||||||
|
- ほかの人に共感と思いやりを示す
|
||||||
|
- 異なる意見、視点、経験を尊重する
|
||||||
|
- 建設的な意見を伝え、また快く受け入れる
|
||||||
|
- 自分たちの誤りに責任を持ち、影響を受けた人に謝り、その経験から学ぶ
|
||||||
|
- 自分個人にとってだけでなく、コミュニティ全体にとって最善のことを考える
|
||||||
|
|
||||||
|
受け入れられない行動の例は、次のとおりです。
|
||||||
|
|
||||||
|
- 性的な言葉や画像を使うこと、どのような形であれ、相手に性的な関心を向けることや言い寄ること
|
||||||
|
- 荒らし、侮辱的または軽蔑的な発言、個人攻撃や政治的な攻撃
|
||||||
|
- 公の場か私的な場かを問わない嫌がらせ
|
||||||
|
- 住所やメールアドレスなど、ほかの人の個人情報を明示の許可なく公開すること
|
||||||
|
- 仕事の場で不適切と合理的に考えられるその他の行為
|
||||||
|
|
||||||
|
## 執行の責任
|
||||||
|
|
||||||
|
コミュニティリーダーは、受け入れられる行動の基準を明確にし、それを守らせる責任を負います。不適切、脅迫的、攻撃的、または有害と判断した行動には、適切で公正な是正措置をとります。
|
||||||
|
|
||||||
|
コミュニティリーダーは、この行動規範に沿わないコメント、コミット、コード、Wiki の編集、Issue、その他の貢献を削除、編集、または却下する権利と責任を持ちます。モデレーションの判断については、適切な場合に理由を伝えます。
|
||||||
|
|
||||||
|
## 適用範囲
|
||||||
|
|
||||||
|
この行動規範は、コミュニティのあらゆる場で適用されます。個人が公の場でコミュニティを公式に代表しているときにも適用されます。コミュニティを代表しているときとは、たとえば、公式のメールアドレスを使うとき、公式のソーシャルメディアのアカウントから投稿するとき、オンラインやオフラインのイベントで任命された代表として行動するときです。
|
||||||
|
|
||||||
|
## 執行
|
||||||
|
|
||||||
|
虐待的な言動、嫌がらせ、その他の受け入れられない行動は、執行を担当するコミュニティリーダーへ github.routersys@gmail.com で報告できます。コミュニティリーダーは、すべての苦情を速やかかつ公正に確認し、調査します。
|
||||||
|
|
||||||
|
すべてのコミュニティリーダーは、事案を報告した人のプライバシーと安全を尊重する義務を負います。
|
||||||
|
|
||||||
|
## 執行のガイドライン
|
||||||
|
|
||||||
|
コミュニティリーダーは、この行動規範に違反すると判断した行動への処置を決めるとき、次に示すコミュニティへの影響に応じたガイドラインに従います。
|
||||||
|
|
||||||
|
### 1. 是正
|
||||||
|
|
||||||
|
コミュニティへの影響: 不適切な言葉づかいや、コミュニティの中で、仕事の場にふさわしくない、または歓迎されないと判断されるその他の行動。
|
||||||
|
|
||||||
|
処置: コミュニティリーダーが、非公開の書面による警告を送ります。違反の内容を明らかにし、その行動がなぜ不適切だったかを説明します。公の場での謝罪を求めることがあります。
|
||||||
|
|
||||||
|
### 2. 警告
|
||||||
|
|
||||||
|
コミュニティへの影響: 1 回の出来事、または一連の行動による違反。
|
||||||
|
|
||||||
|
処置: 行動が続いた場合の処置を示した警告を送ります。警告を受けた人は、定められた期間、関係する人々とやり取りしてはいけません。行動規範を執行する人々へ、求められていないのに接触することも、これに含まれます。コミュニティの場だけでなく、ソーシャルメディアなど外部の場でのやり取りも避けなければなりません。これらの条件に違反すると、一時的または永久的な参加禁止につながることがあります。
|
||||||
|
|
||||||
|
### 3. 一時的な参加禁止
|
||||||
|
|
||||||
|
コミュニティへの影響: 不適切な行動を続けることを含む、コミュニティの基準への重大な違反。
|
||||||
|
|
||||||
|
処置: 定められた期間、コミュニティとのあらゆるやり取りと、コミュニティに向けた公の発信を禁止します。この期間中は、公の場か私的な場かを問わず、関係する人々とのやり取りを認めません。行動規範を執行する人々へ、求められていないのに接触することも、これに含まれます。これらの条件に違反すると、永久的な参加禁止につながることがあります。
|
||||||
|
|
||||||
|
### 4. 永久的な参加禁止
|
||||||
|
|
||||||
|
コミュニティへの影響: コミュニティの基準に繰り返し違反すること。不適切な行動を続けること、個人への嫌がらせ、特定の属性を持つ人々への攻撃や中傷も、これに当たります。
|
||||||
|
|
||||||
|
処置: コミュニティの中でのあらゆる公のやり取りを、永久に禁止します。
|
||||||
|
|
||||||
|
## 出典
|
||||||
|
|
||||||
|
この行動規範は、[Contributor Covenant][homepage] のバージョン 2.0 を基にしています。原文は https://www.contributor-covenant.org/version/2/0/code_of_conduct.html にあります。日本語の文は、公式の日本語訳 https://www.contributor-covenant.org/ja/version/2/0/code_of_conduct/ を基に、原文と照らし合わせて改めたものです。
|
||||||
|
|
||||||
|
Contributor Covenant は、[クリエイティブ・コモンズ 表示 4.0 国際 ライセンス](https://creativecommons.org/licenses/by/4.0/deed.ja)のもとで提供されています。
|
||||||
|
|
||||||
|
コミュニティへの影響に応じたガイドラインは、[Mozilla の行動規範の執行の段階](https://github.com/mozilla/diversity)に着想を得ています。
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
この行動規範についてのよくある質問と回答は、https://www.contributor-covenant.org/faq にあります。ほかの言語の訳は、https://www.contributor-covenant.org/translations にあります。
|
||||||
+168
@@ -0,0 +1,168 @@
|
|||||||
|
# 貢献の手引き
|
||||||
|
|
||||||
|
本プラグインへの貢献に関心を持っていただき、ありがとうございます。この手引きは、Issue の立て方、プルリクエストの作り方、変更の確かめ方、コードとコミットの書き方を定めます。
|
||||||
|
|
||||||
|
本プラグインでできることとできないことは、[README](README.md) に書いてあります。まず README を読んでください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 目次
|
||||||
|
|
||||||
|
1. [貢献の進め方](#貢献の進め方)
|
||||||
|
2. [開発環境](#開発環境)
|
||||||
|
3. [Issue](#issue)
|
||||||
|
4. [プルリクエスト](#プルリクエスト)
|
||||||
|
5. [検証](#検証)
|
||||||
|
6. [コードの規約](#コードの規約)
|
||||||
|
7. [コミットの規約](#コミットの規約)
|
||||||
|
8. [行動規範](#行動規範)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 貢献の進め方
|
||||||
|
|
||||||
|
誤字の修正、文書の修正、軽微な不具合の修正は、そのままプルリクエストを送ってください。
|
||||||
|
|
||||||
|
新しい機能、設定の項目や既定値の変更、大きめの不具合の修正、意図して出力を変える変更、互換性を損なう変更、コードの構成を大きく変える変更は、先に Issue を立ててください。実装を始める前に、意図する動きと変更の範囲について合意するためです。どちらに当たるか迷ったときも、Issue を立ててください。
|
||||||
|
|
||||||
|
脆弱性は Issue に書かず、[セキュリティポリシー](SECURITY.md)に従って非公開で報告してください。
|
||||||
|
|
||||||
|
Issue とプルリクエストは、日本語か英語で書いてください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 開発環境
|
||||||
|
|
||||||
|
| 項目 | 要件 |
|
||||||
|
|---|---|
|
||||||
|
| OS | Windows 10 バージョン 2004 以降の 64bit 版 |
|
||||||
|
| SDK | .NET 10 |
|
||||||
|
| YukkuriMovieMaker4 | ビルドがインストール先の DLL を参照するため、手元に入れておく |
|
||||||
|
| シェーダーのビルド | HLSL をビルドのときにコンパイルするリポジトリでは Windows SDK が要る。シェーダーを `.vcxproj` でビルドするリポジトリでは、Visual Studio 2026 の「C++ によるデスクトップ開発」も要る |
|
||||||
|
|
||||||
|
### 取得
|
||||||
|
|
||||||
|
リポジトリをフォークし、自分のフォークをクローンしてください。リポジトリはサブモジュールを含むことがあるので、`--recursive` を付けます。
|
||||||
|
|
||||||
|
```console
|
||||||
|
git clone --recursive https://github.com/<自分のアカウント>/<リポジトリ名>.git
|
||||||
|
```
|
||||||
|
|
||||||
|
`--recursive` を付けずにクローンしたときは、後から次のコマンドでサブモジュールを取得できます。
|
||||||
|
|
||||||
|
```console
|
||||||
|
git submodule update --init --recursive
|
||||||
|
```
|
||||||
|
|
||||||
|
作業は `main` から切ったブランチで行ってください。
|
||||||
|
|
||||||
|
### YukkuriMovieMaker4 の場所
|
||||||
|
|
||||||
|
YukkuriMovieMaker4 のインストール先は、MSBuild のプロパティ `YMM4DirPath` で渡します。値の末尾には `\` を付けてください。
|
||||||
|
|
||||||
|
- コマンドラインでは、`-p:YMM4DirPath="<インストール先>\"` を付けてビルドします。PowerShell 7 以降で実行してください。Windows PowerShell 5.1 と cmd では、末尾の `\"` が正しく渡らないため、末尾を `\\"` と書いてください。
|
||||||
|
- Visual Studio でビルドするときは、プラグインのプロジェクトのフォルダーか、その上のフォルダーに `Directory.Build.props` があれば、その `YMM4DirPath` を手元で書き換えます。無ければ、環境変数 `YMM4DirPath` を設定します。書き換えた `Directory.Build.props` はコミットに含めないでください。サブモジュールの中にある `Directory.Build.props` は書き換えないでください。
|
||||||
|
|
||||||
|
### ビルド
|
||||||
|
|
||||||
|
ソリューションを開き、Release でビルドしてください。
|
||||||
|
|
||||||
|
シェーダーを `.vcxproj` でビルドするリポジトリでは、コマンドラインのビルドに Visual Studio の MSBuild を使ってください。.NET SDK の `dotnet` コマンドは `.vcxproj` を扱えません。テストは、`dotnet test <名前>.Tests\<名前>.Tests.csproj` のようにテストのプロジェクトのファイルを指定して実行してください。ビルドの手順は、`.github/workflows/release.yml` があればそこに書いてあります。
|
||||||
|
|
||||||
|
多くのリポジトリでは、ビルドの後にプラグインが YukkuriMovieMaker4 の `user\plugin` フォルダーへ自動でコピーされます。
|
||||||
|
|
||||||
|
- YukkuriMovieMaker4 を起動したままだと、コピーの段階で失敗します。ビルドの前に終了してください。
|
||||||
|
- 配布版のプラグインを入れているときは、同じ名前のファイルが上書きされます。
|
||||||
|
- コマンドラインでソリューションをビルドしたときはコピーしないリポジトリがあります。その場合は、プラグインのプロジェクトを指定してビルドしてください。
|
||||||
|
- `.csproj` に `SkipPluginDeploy` の条件があるリポジトリでは、`-p:SkipPluginDeploy=true` を付けるとコピーせずにビルドできます。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Issue
|
||||||
|
|
||||||
|
Issue はテンプレートから立ててください。不具合の報告、文書の不備、機能の提案、使い方の質問の 4 つがあります。
|
||||||
|
|
||||||
|
不具合の報告には、次の内容を書いてください。
|
||||||
|
|
||||||
|
- 期待した動きと、実際の動き
|
||||||
|
- 再現の手順。できれば、問題が起きる最小のプロジェクトファイルや素材
|
||||||
|
- プラグインのバージョン、YukkuriMovieMaker4 のバージョン、Windows のバージョン
|
||||||
|
- 描画や GPU に関わる不具合では、GPU の名前とドライバーのバージョン
|
||||||
|
- エラー画面に出た内容。省略せずに貼ってください
|
||||||
|
|
||||||
|
ときどきしか起きない不具合も、確実な再現の手順が無いまま報告して構いません。何回試して何回起きたかと、どの操作の後に起きたかを書いてください。
|
||||||
|
|
||||||
|
コードを読んで見つけた不具合を報告するときは、実際に再現を確かめたかどうかも書いてください。
|
||||||
|
|
||||||
|
Issue に添付したファイルは、誰でも見られます。プロジェクトファイルには、素材を置いたフォルダーのパスが記録されています。パスにユーザー名が含まれることがあるので、公開できない情報が無いかを確かめてから添付してください。
|
||||||
|
|
||||||
|
不具合の情報を自動で送信するプラグインでも、Issue での報告には意味があります。自動で送られるのは、例外の内容と実行環境の一部です。そこに至った操作、YukkuriMovieMaker4 のバージョン、GPU、例外を伴わない描画の乱れは届きません。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## プルリクエスト
|
||||||
|
|
||||||
|
1 つのプルリクエストには、1 つの目的の変更だけを含めてください。関係の無い整理、整形、依存関係の更新を含めないでください。依存関係を更新するのは、必要な機能を使うため、不具合やセキュリティの問題を直すため、互換性を保つためなど、具体的な理由があるときだけにしてください。
|
||||||
|
|
||||||
|
特に注意が要るのは、次の箇所です。
|
||||||
|
|
||||||
|
- 設定の項目と、その既定値と範囲。保存済みのプロジェクトの結果が変わるおそれがある
|
||||||
|
- 出力の結果。変えるつもりの無い変更で、映像や音が変わっていないか
|
||||||
|
- GPU のリソース、ファイル、ハンドルの寿命
|
||||||
|
- 破棄の処理と、失敗したときの処理
|
||||||
|
- YukkuriMovieMaker4 の内部に手を入れるプラグインでは、YukkuriMovieMaker4 のバージョンによる違い
|
||||||
|
|
||||||
|
動きを変えたときは、同じプルリクエストで README を直してください。`.github/Plugin_Readme.txt` があるリポジトリでは、それも直してください。`Plugin_Readme.txt` は配布パッケージに `Readme.txt` として入り、利用者の手元に残ります。
|
||||||
|
|
||||||
|
バージョンを上げる変更は、プルリクエストに含めないでください。バージョンの更新とリリースは、開発者が行います。
|
||||||
|
|
||||||
|
レビューを受けて直すときは、コミットを目的ごとのまとまりに保つため、ブランチの履歴を組み直して強制プッシュして構いません。
|
||||||
|
|
||||||
|
プルリクエストを送った時点で、その貢献をリポジトリと同じライセンスで提供することに同意したものとみなします。リポジトリのライセンスは、リポジトリの直下にあるライセンスのファイルに書いてあります。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 検証
|
||||||
|
|
||||||
|
プルリクエストには、手元で実際に確かめた結果を書いてください。
|
||||||
|
|
||||||
|
- ビルドの結果と、テストのプロジェクトがあればテストの結果
|
||||||
|
- YukkuriMovieMaker4 で実際に動かして確かめたこと。使った YukkuriMovieMaker4 のバージョンを添え、GPU に関わる変更では GPU の名前とドライバーのバージョンも添えてください
|
||||||
|
- 実行できなかったテストと、その理由
|
||||||
|
|
||||||
|
実際に動かして観察したこと、コードを読んで判断したこと、推測したことを分けて書いてください。
|
||||||
|
|
||||||
|
出力を変えるつもりの無い変更では、変更前と変更後で出力が一致することを確かめてください。`--golden` と `--verify` を持つハーネスのプロジェクトがあるリポジトリでは、それで描画を比べられます。基準値は、手元の環境で変更前のコミットから作り直し、作り直した基準値はコミットに含めないでください。そのようなハーネスが無いリポジトリでは、変更前と変更後の出力を比べてください。サブモジュールの中にあるハーネスは、この確認には使いません。
|
||||||
|
|
||||||
|
性能の改善を主張するときは、1 回の測定で判断しないでください。
|
||||||
|
|
||||||
|
- 同じ機材、ドライバー、設定、電源の条件で、変更前と変更後のビルドを交互に繰り返し測ってください。
|
||||||
|
- GPU と CPU の温度で値が変わるため、測定の間を空けてください。
|
||||||
|
- ほかのプロセスが GPU を使っていない状態で測ってください。
|
||||||
|
- 正しさの確認と性能の測定は、別々に実行してください。確認のための処理が、測定値を変えるためです。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## コードの規約
|
||||||
|
|
||||||
|
変更する箇所で既に使われている実装のパターンと書き方に従ってください。既存の実装どうしが食い違っているときは、どちらかを機械的にまねず、README とテストに照らして意図された動きを確かめ、それに合うほうへ揃えてください。
|
||||||
|
|
||||||
|
自分の変更で増えたビルドの警告は、放置せず原因を直してください。
|
||||||
|
|
||||||
|
新しく書くコードには、コメントを入れず、コメントアウトしたコードも残さないでください。既存のコードにあるコメントとドキュメントコメントは残してください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## コミットの規約
|
||||||
|
|
||||||
|
- 1 つのコミットは、目的ごとのまとまりを保てる範囲で、できるだけ小さくしてください。どのコミットも、それ単独でビルドが通るようにしてください。
|
||||||
|
- 実装の変更と、それを確かめるテストは、別のコミットに分けてください。
|
||||||
|
- 件名は日本語で書き、50 文字以内に収め、「〜する」の形で終えてください。「〜を追加する」「〜を直す」はよい例です。「〜の追加」「〜を修正」のように名詞で終える形は使いません。
|
||||||
|
- 件名を日本語で書けないときは、プルリクエストにその旨を書いてください。
|
||||||
|
- 本文は書かないでください。例外は、リリースノートでの変更の分類を指定する行だけです。この行が要るときは、書き方をレビューで伝えます。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 行動規範
|
||||||
|
|
||||||
|
貢献するすべての人に、[行動規範](CODE_OF_CONDUCT.md)に従うことを求めます。
|
||||||
-1
サブモジュール ComputeSharp が 7c4145d5f2 から削除されました。
@@ -1,15 +1,5 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<YMM4DirPath>C:\Program Files\YukkuriMovieMaker_v4_Lite_Dev\</YMM4DirPath>
|
<YMM4DirPath>C:\Program Files\YukkuriMovieMaker_v4_Lite_Dev\</YMM4DirPath>
|
||||||
|
|
||||||
<WindowsKitRoot>C:\Program Files (x86)\Windows Kits\10\bin</WindowsKitRoot>
|
|
||||||
|
|
||||||
<FxcPath Condition="'$(FxcPath)' == '' AND Exists('$(WindowsKitRoot)\10.0.26100.0\x64\fxc.exe')">$(WindowsKitRoot)\10.0.26100.0\x64\fxc.exe</FxcPath>
|
|
||||||
<FxcPath Condition="'$(FxcPath)' == '' AND Exists('$(WindowsKitRoot)\10.0.22621.0\x64\fxc.exe')">$(WindowsKitRoot)\10.0.22621.0\x64\fxc.exe</FxcPath>
|
|
||||||
<FxcPath Condition="'$(FxcPath)' == '' AND Exists('$(WindowsKitRoot)\10.0.19041.0\x64\fxc.exe')">$(WindowsKitRoot)\10.0.19041.0\x64\fxc.exe</FxcPath>
|
|
||||||
<FxcPath Condition="'$(FxcPath)' == '' AND Exists('$(WindowsKitRoot)\10.0.18362.0\x64\fxc.exe')">$(WindowsKitRoot)\10.0.18362.0\x64\fxc.exe</FxcPath>
|
|
||||||
<FxcPath Condition="'$(FxcPath)' == '' AND Exists('$(WindowsKitRoot)\10.0.17763.0\x64\fxc.exe')">$(WindowsKitRoot)\10.0.17763.0\x64\fxc.exe</FxcPath>
|
|
||||||
|
|
||||||
<FxcPath Condition="'$(FxcPath)' == ''">fxc.exe</FxcPath>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal sealed record GoldenCase(string Name, IReadOnlyList<int> Frames, string Hash);
|
||||||
|
|
||||||
|
internal sealed record Golden(string Adapter, string Driver, string Input, string Canvas, IReadOnlyList<GoldenCase> Cases)
|
||||||
|
{
|
||||||
|
const string FileName = "golden.json";
|
||||||
|
const string DirectoryKey = "HarnessDirectory";
|
||||||
|
|
||||||
|
static readonly JsonSerializerOptions Options = new()
|
||||||
|
{
|
||||||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||||
|
WriteIndented = true,
|
||||||
|
NewLine = "\n",
|
||||||
|
};
|
||||||
|
|
||||||
|
public static string PathFor(HarnessImage image)
|
||||||
|
=> Path.Combine(ReadDirectory(), image.Key is null ? FileName : $"golden-{image.Key}.json");
|
||||||
|
|
||||||
|
public static Golden Load(string path)
|
||||||
|
{
|
||||||
|
if (!File.Exists(path))
|
||||||
|
throw new HarnessException($"基準値がありません。先に --golden で書いてください。{path}");
|
||||||
|
Golden? golden;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
golden = JsonSerializer.Deserialize<Golden>(File.ReadAllBytes(path), Options);
|
||||||
|
}
|
||||||
|
catch (JsonException exception)
|
||||||
|
{
|
||||||
|
throw new HarnessException($"基準値を読めません。{path} {exception.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (golden is not { Adapter: not null, Driver: not null, Input: not null, Canvas: not null, Cases: not null }
|
||||||
|
|| golden.Cases.Any(item => item is not { Name: not null, Frames: not null, Hash: not null }))
|
||||||
|
throw new HarnessException($"基準値の項目が足りません。{path}");
|
||||||
|
if (golden.Cases.Select(item => item.Name).Distinct(StringComparer.Ordinal).Count() != golden.Cases.Count)
|
||||||
|
throw new HarnessException($"基準値のケース名が重複しています。{path}");
|
||||||
|
return golden;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save(string path) => File.WriteAllBytes(path, JsonSerializer.SerializeToUtf8Bytes(this, Options));
|
||||||
|
|
||||||
|
static string ReadDirectory()
|
||||||
|
=> typeof(Golden).Assembly
|
||||||
|
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||||
|
.FirstOrDefault(attribute => string.Equals(attribute.Key, DirectoryKey, StringComparison.Ordinal))
|
||||||
|
?.Value ?? throw new HarnessException($"アセンブリに {DirectoryKey} がありません。");
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using Vortice.Direct3D11;
|
||||||
|
|
||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal sealed class GpuTimer : IDisposable
|
||||||
|
{
|
||||||
|
static readonly TimeSpan ResolveTimeout = TimeSpan.FromSeconds(5);
|
||||||
|
|
||||||
|
readonly ID3D11DeviceContext context;
|
||||||
|
readonly ID3D11Query disjoint;
|
||||||
|
readonly ID3D11Query start;
|
||||||
|
readonly ID3D11Query stop;
|
||||||
|
|
||||||
|
public GpuTimer(ID3D11Device device, ID3D11DeviceContext context)
|
||||||
|
{
|
||||||
|
this.context = context;
|
||||||
|
disjoint = device.CreateQuery(new QueryDescription(QueryType.TimestampDisjoint, QueryFlags.None));
|
||||||
|
start = device.CreateQuery(new QueryDescription(QueryType.Timestamp, QueryFlags.None));
|
||||||
|
stop = device.CreateQuery(new QueryDescription(QueryType.Timestamp, QueryFlags.None));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Begin()
|
||||||
|
{
|
||||||
|
context.Begin(disjoint);
|
||||||
|
context.End(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void End()
|
||||||
|
{
|
||||||
|
context.End(stop);
|
||||||
|
context.End(disjoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeSpan? Resolve()
|
||||||
|
{
|
||||||
|
if (!Wait<QueryDataTimestampDisjoint>(disjoint, out var timing) || timing.Disjoint || timing.Frequency == 0UL)
|
||||||
|
return null;
|
||||||
|
if (!Wait<ulong>(start, out var began) || !Wait<ulong>(stop, out var ended) || ended < began)
|
||||||
|
return null;
|
||||||
|
return TimeSpan.FromSeconds((ended - began) / (double)timing.Frequency);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Wait<T>(ID3D11Query query, out T value) where T : unmanaged
|
||||||
|
{
|
||||||
|
var elapsed = Stopwatch.StartNew();
|
||||||
|
while (!context.GetData(query, out value))
|
||||||
|
{
|
||||||
|
if (elapsed.Elapsed > ResolveTimeout)
|
||||||
|
return false;
|
||||||
|
Thread.Yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
stop.Dispose();
|
||||||
|
start.Dispose();
|
||||||
|
disjoint.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal sealed class HarnessException(string message) : Exception(message);
|
||||||
|
|
||||||
|
internal enum HarnessMode
|
||||||
|
{
|
||||||
|
Render,
|
||||||
|
Golden,
|
||||||
|
Verify,
|
||||||
|
Transition,
|
||||||
|
Compare,
|
||||||
|
Benchmark,
|
||||||
|
Structure,
|
||||||
|
Recompute,
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed record HarnessArguments(HarnessMode Mode, string? Input, string? OutputDirectory, string? Before, string? After)
|
||||||
|
{
|
||||||
|
public const string Usage = """
|
||||||
|
使い方:
|
||||||
|
[<出力先>] [--input <画像>] ケースを描き、PNG とハッシュを出します
|
||||||
|
--golden [--input <画像>] 基準値を golden.json に書きます
|
||||||
|
--verify [--input <画像>] 基準値と照合します
|
||||||
|
--transition [<出力先>] [--input <画像>] 設定を変えた後とフレームを進めた後の描画を、作り直した描画と照合します
|
||||||
|
--compare <前> <後> 2 つの出力先の PNG を画素ごとに比べます
|
||||||
|
--benchmark [--input <画像>] 描画を計測します
|
||||||
|
--structure 構造の再計算がパラメータごとに掛かる時間を内訳で計測します
|
||||||
|
--recompute [--input <画像>] 構造の再計算を休止を挟んで繰り返し計測します
|
||||||
|
""";
|
||||||
|
|
||||||
|
public static HarnessArguments Parse(string[] arguments)
|
||||||
|
{
|
||||||
|
HarnessMode? mode = null;
|
||||||
|
string? input = null;
|
||||||
|
var positionals = new List<string>();
|
||||||
|
for (var index = 0; index < arguments.Length; index++)
|
||||||
|
{
|
||||||
|
var argument = arguments[index];
|
||||||
|
switch (argument)
|
||||||
|
{
|
||||||
|
case "--golden":
|
||||||
|
mode = Select(mode, HarnessMode.Golden);
|
||||||
|
break;
|
||||||
|
case "--verify":
|
||||||
|
mode = Select(mode, HarnessMode.Verify);
|
||||||
|
break;
|
||||||
|
case "--transition":
|
||||||
|
mode = Select(mode, HarnessMode.Transition);
|
||||||
|
break;
|
||||||
|
case "--compare":
|
||||||
|
mode = Select(mode, HarnessMode.Compare);
|
||||||
|
break;
|
||||||
|
case "--benchmark":
|
||||||
|
mode = Select(mode, HarnessMode.Benchmark);
|
||||||
|
break;
|
||||||
|
case "--structure":
|
||||||
|
mode = Select(mode, HarnessMode.Structure);
|
||||||
|
break;
|
||||||
|
case "--recompute":
|
||||||
|
mode = Select(mode, HarnessMode.Recompute);
|
||||||
|
break;
|
||||||
|
case "--input":
|
||||||
|
if (index + 1 >= arguments.Length)
|
||||||
|
throw new HarnessException("--input には画像のパスを続けてください。");
|
||||||
|
input = arguments[++index];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (argument.StartsWith('-'))
|
||||||
|
throw new HarnessException($"不明なオプションです。{argument}");
|
||||||
|
positionals.Add(argument);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var selected = mode ?? HarnessMode.Render;
|
||||||
|
switch (selected)
|
||||||
|
{
|
||||||
|
case HarnessMode.Compare:
|
||||||
|
if (positionals.Count != 2)
|
||||||
|
throw new HarnessException("--compare には前と後の出力先を続けてください。");
|
||||||
|
if (input is not null)
|
||||||
|
throw new HarnessException("--compare に --input は使えません。");
|
||||||
|
return new HarnessArguments(HarnessMode.Compare, null, null, positionals[0], positionals[1]);
|
||||||
|
case HarnessMode.Render:
|
||||||
|
case HarnessMode.Transition:
|
||||||
|
if (positionals.Count > 1)
|
||||||
|
throw new HarnessException($"余分な引数です。{positionals[1]}");
|
||||||
|
return new HarnessArguments(selected, input, positionals.FirstOrDefault(), null, null);
|
||||||
|
default:
|
||||||
|
if (positionals.Count > 0)
|
||||||
|
throw new HarnessException($"余分な引数です。{positionals[0]}");
|
||||||
|
return new HarnessArguments(selected, input, null, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static HarnessMode Select(HarnessMode? current, HarnessMode next)
|
||||||
|
=> current is null ? next : throw new HarnessException("モードは 1 つだけ指定してください。");
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal static class HarnessCases
|
||||||
|
{
|
||||||
|
public static IEnumerable<(string Name, InkDispersionEffect Effect, IReadOnlyList<int> Frames)> All()
|
||||||
|
{
|
||||||
|
yield return ("default", Create(), [0]);
|
||||||
|
yield return ("default-frames-0-8", Create(), Enumerable.Range(0, 9).ToArray());
|
||||||
|
yield return ("amount-0", Create(effect => effect.Amount.Values[0].Value = 0), [0]);
|
||||||
|
yield return ("spread-35", Create(effect => effect.Spread.Values[0].Value = 35), [0]);
|
||||||
|
yield return ("quality-balanced", Create(effect => effect.Quality = InkDispersionQuality.Balanced), [0]);
|
||||||
|
yield return ("quality-ultra", Create(effect => effect.Quality = InkDispersionQuality.Ultra), [0]);
|
||||||
|
yield return ("water-0", Create(effect => effect.Water.Values[0].Value = 0), [0]);
|
||||||
|
yield return ("water-100", Create(effect => effect.Water.Values[0].Value = 100), [0]);
|
||||||
|
yield return ("reach-5", Create(effect => effect.Reach.Values[0].Value = 5), [0]);
|
||||||
|
yield return ("reach-100", Create(effect => effect.Reach.Values[0].Value = 100), [0]);
|
||||||
|
yield return ("fiber-0", Create(effect => effect.Fiber.Values[0].Value = 0), [0]);
|
||||||
|
yield return ("fiber-100", Create(effect => effect.Fiber.Values[0].Value = 100), [0]);
|
||||||
|
yield return ("sizing-0", Create(effect => effect.Sizing.Values[0].Value = 0), [0]);
|
||||||
|
yield return ("sizing-100", Create(effect => effect.Sizing.Values[0].Value = 100), [0]);
|
||||||
|
yield return ("viscosity-0", Create(effect => effect.Viscosity.Values[0].Value = 0), [0]);
|
||||||
|
yield return ("viscosity-100", Create(effect => effect.Viscosity.Values[0].Value = 100), [0]);
|
||||||
|
yield return ("drying-0", Create(effect => effect.Drying.Values[0].Value = 0), [0]);
|
||||||
|
yield return ("drying-100", Create(effect => effect.Drying.Values[0].Value = 100), [0]);
|
||||||
|
yield return ("density-20", Create(effect => effect.Density.Values[0].Value = 20), [0]);
|
||||||
|
yield return ("density-100", Create(effect => effect.Density.Values[0].Value = 100), [0]);
|
||||||
|
yield return ("grain-0", Create(effect => effect.Grain.Values[0].Value = 0), [0]);
|
||||||
|
yield return ("grain-100", Create(effect => effect.Grain.Values[0].Value = 100), [0]);
|
||||||
|
yield return ("seed-42", Create(effect => effect.Seed = 42), [0]);
|
||||||
|
yield return ("ink-color", Create(effect => effect.InkColor = Color.FromArgb(255, 200, 20, 20)), [0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<(string Name, Func<InkDispersionEffect> Create, Action<InkDispersionEffect> Change, int Frame)> Transitions()
|
||||||
|
{
|
||||||
|
yield return ("spread-100-to-35", () => Create(), effect => effect.Spread.Values[0].Value = 35, 0);
|
||||||
|
yield return ("quality-high-to-ultra", () => Create(), effect => effect.Quality = InkDispersionQuality.Ultra, 0);
|
||||||
|
yield return ("water-60-to-100", () => Create(), effect => effect.Water.Values[0].Value = 100, 0);
|
||||||
|
yield return ("reach-25-to-100", () => Create(), effect => effect.Reach.Values[0].Value = 100, 0);
|
||||||
|
yield return ("fiber-50-to-100", () => Create(), effect => effect.Fiber.Values[0].Value = 100, 0);
|
||||||
|
yield return ("sizing-30-to-100", () => Create(), effect => effect.Sizing.Values[0].Value = 100, 0);
|
||||||
|
yield return ("viscosity-30-to-100", () => Create(), effect => effect.Viscosity.Values[0].Value = 100, 0);
|
||||||
|
yield return ("drying-40-to-100", () => Create(), effect => effect.Drying.Values[0].Value = 100, 0);
|
||||||
|
yield return ("density-80-to-20", () => Create(), effect => effect.Density.Values[0].Value = 20, 0);
|
||||||
|
yield return ("grain-40-to-100", () => Create(), effect => effect.Grain.Values[0].Value = 100, 0);
|
||||||
|
yield return ("seed-0-to-42", () => Create(), effect => effect.Seed = 42, 0);
|
||||||
|
yield return ("ink-color-change", () => Create(), effect => effect.InkColor = Color.FromArgb(255, 200, 20, 20), 0);
|
||||||
|
yield return ("amount-100-to-0", () => Create(), effect => effect.Amount.Values[0].Value = 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<(string Name, InkDispersionEffect Effect)> Benchmarks()
|
||||||
|
{
|
||||||
|
yield return ("quality-balanced", Create(effect => effect.Quality = InkDispersionQuality.Balanced));
|
||||||
|
yield return ("default", Create());
|
||||||
|
yield return ("quality-ultra", Create(effect => effect.Quality = InkDispersionQuality.Ultra));
|
||||||
|
yield return ("reach-100", Create(effect => effect.Reach.Values[0].Value = 100));
|
||||||
|
yield return ("amount-0", Create(effect => effect.Amount.Values[0].Value = 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InkDispersionEffect Create(Action<InkDispersionEffect>? configure = null)
|
||||||
|
{
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
configure?.Invoke(effect);
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal sealed record HarnessImage(int Width, int Height, byte[] Pixels, string Identity, string? Key)
|
||||||
|
{
|
||||||
|
public const int BytesPerPixel = 4;
|
||||||
|
const int KeyLength = 16;
|
||||||
|
|
||||||
|
public static HarnessImage Synthetic(int width, int height)
|
||||||
|
{
|
||||||
|
var pixels = SyntheticImage.Create(width, height);
|
||||||
|
return new HarnessImage(width, height, pixels, $"synthetic {width}x{height} {Convert.ToHexString(SHA256.HashData(pixels))[..KeyLength]}", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HarnessImage Load(string path)
|
||||||
|
{
|
||||||
|
if (!File.Exists(path))
|
||||||
|
throw new HarnessException($"入力の画像がありません。{path}");
|
||||||
|
|
||||||
|
var bytes = File.ReadAllBytes(path);
|
||||||
|
var (width, height, pixels) = Decode(bytes, path);
|
||||||
|
var hash = Convert.ToHexString(SHA256.HashData(bytes));
|
||||||
|
return new HarnessImage(width, height, pixels, $"{hash} {width}x{height}", hash[..KeyLength]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (int Width, int Height, byte[] Pixels) LoadPremultiplied(string path) => Decode(File.ReadAllBytes(path), path);
|
||||||
|
|
||||||
|
public static void Save(string path, byte[] pixels, int width, int height)
|
||||||
|
{
|
||||||
|
var source = BitmapSource.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, pixels, width * BytesPerPixel);
|
||||||
|
var encoder = new PngBitmapEncoder();
|
||||||
|
encoder.Frames.Add(BitmapFrame.Create(source));
|
||||||
|
using var stream = File.Create(path);
|
||||||
|
encoder.Save(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
static (int Width, int Height, byte[] Pixels) Decode(byte[] bytes, string path)
|
||||||
|
{
|
||||||
|
using var stream = new MemoryStream(bytes);
|
||||||
|
BitmapDecoder decoder;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
|
||||||
|
}
|
||||||
|
catch (Exception exception) when (exception is NotSupportedException or FileFormatException)
|
||||||
|
{
|
||||||
|
throw new HarnessException($"画像として読めません。{path}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var converted = new FormatConvertedBitmap(decoder.Frames[0], PixelFormats.Pbgra32, null, 0d);
|
||||||
|
var pixels = new byte[converted.PixelWidth * converted.PixelHeight * BytesPerPixel];
|
||||||
|
converted.CopyPixels(pixels, converted.PixelWidth * BytesPerPixel, 0);
|
||||||
|
return (converted.PixelWidth, converted.PixelHeight, pixels);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Numerics;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Vortice.DCommon;
|
||||||
|
using Vortice.Direct2D1;
|
||||||
|
using Vortice.Direct2D1.Effects;
|
||||||
|
using Vortice.DXGI;
|
||||||
|
using Vortice.Mathematics;
|
||||||
|
using YukkuriMovieMaker.Commons;
|
||||||
|
using YukkuriMovieMaker.Player.Video;
|
||||||
|
using YukkuriMovieMaker.Plugin.Effects;
|
||||||
|
|
||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal sealed class HarnessRenderer : IDisposable
|
||||||
|
{
|
||||||
|
const int Fps = 30;
|
||||||
|
const int Length = 300;
|
||||||
|
const int WarmupUpdates = 2000;
|
||||||
|
const int UpdateRepeats = 20;
|
||||||
|
const float Dpi = 96f;
|
||||||
|
|
||||||
|
static readonly PixelFormat PixelFormat = new(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied);
|
||||||
|
|
||||||
|
readonly GraphicsDevices devices;
|
||||||
|
readonly IGraphicsDevicesAndContext context;
|
||||||
|
readonly ID2D1Bitmap1 image;
|
||||||
|
readonly ID2D1Bitmap1 target;
|
||||||
|
readonly ID2D1Bitmap1 readback;
|
||||||
|
readonly ID2D1Bitmap1 sync;
|
||||||
|
readonly GpuTimer timer;
|
||||||
|
readonly AffineTransform2D placement;
|
||||||
|
readonly ID2D1Image centered;
|
||||||
|
|
||||||
|
public HarnessRenderer(int canvasWidth, int canvasHeight, HarnessImage source)
|
||||||
|
{
|
||||||
|
CanvasWidth = canvasWidth;
|
||||||
|
CanvasHeight = canvasHeight;
|
||||||
|
|
||||||
|
devices = new GraphicsDevices();
|
||||||
|
context = devices.CreateContext();
|
||||||
|
var deviceContext = context.DeviceContext;
|
||||||
|
var adapter = devices.DXGI.Adapter;
|
||||||
|
Adapter = adapter.Description.Description;
|
||||||
|
Driver = adapter.CheckInterfaceSupport<IDXGIDevice>(out var version) ? FormatDriverVersion(version) : "不明";
|
||||||
|
|
||||||
|
image = CreateBitmap(deviceContext, source.Width, source.Height, BitmapOptions.None);
|
||||||
|
image.CopyFromMemory(source.Pixels, source.Width * HarnessImage.BytesPerPixel);
|
||||||
|
target = CreateBitmap(deviceContext, canvasWidth, canvasHeight, BitmapOptions.Target);
|
||||||
|
readback = CreateBitmap(deviceContext, canvasWidth, canvasHeight, BitmapOptions.CpuRead | BitmapOptions.CannotDraw);
|
||||||
|
sync = CreateBitmap(deviceContext, 1, 1, BitmapOptions.CpuRead | BitmapOptions.CannotDraw);
|
||||||
|
timer = new GpuTimer(devices.D3D.Device, devices.D3D.DeviceContext);
|
||||||
|
|
||||||
|
placement = new AffineTransform2D(deviceContext)
|
||||||
|
{
|
||||||
|
TransformMatrix = Matrix3x2.CreateTranslation(-source.Width * 0.5f, -source.Height * 0.5f),
|
||||||
|
};
|
||||||
|
placement.SetInput(0, image, true);
|
||||||
|
centered = placement.Output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CanvasWidth { get; }
|
||||||
|
|
||||||
|
public int CanvasHeight { get; }
|
||||||
|
|
||||||
|
public string Adapter { get; }
|
||||||
|
|
||||||
|
public string Driver { get; }
|
||||||
|
|
||||||
|
public byte[][] Render(IVideoEffect effect, IReadOnlyList<int> frames)
|
||||||
|
{
|
||||||
|
if (frames.Count == 0)
|
||||||
|
throw new ArgumentException("フレームを 1 つ以上指定してください。", nameof(frames));
|
||||||
|
|
||||||
|
using var processor = effect.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(centered);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var rendered = new byte[frames.Count][];
|
||||||
|
for (var index = 0; index < frames.Count; index++)
|
||||||
|
{
|
||||||
|
processor.Update(Describe(frames[index]));
|
||||||
|
rendered[index] = Capture(processor.Output);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rendered;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
processor.ClearInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public (byte[] Direct, byte[] Transitioned) RenderTransition<TEffect>(Func<TEffect> create, Action<TEffect> change, int frame)
|
||||||
|
where TEffect : IVideoEffect
|
||||||
|
{
|
||||||
|
var settled = create();
|
||||||
|
change(settled);
|
||||||
|
var direct = Render(settled, [frame])[0];
|
||||||
|
|
||||||
|
var live = create();
|
||||||
|
using var processor = live.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(centered);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
processor.Update(Describe(frame));
|
||||||
|
_ = Capture(processor.Output);
|
||||||
|
change(live);
|
||||||
|
processor.Update(Describe(frame));
|
||||||
|
return (direct, Capture(processor.Output));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
processor.ClearInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Measurement Measure(IVideoEffect effect, int frames, bool moving)
|
||||||
|
{
|
||||||
|
var descriptions = new EffectDescription[frames];
|
||||||
|
for (var frame = 0; frame < frames; frame++)
|
||||||
|
descriptions[frame] = Describe(moving ? frame : 0);
|
||||||
|
|
||||||
|
using var processor = effect.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(centered);
|
||||||
|
var output = processor.Output;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (var index = 0; index < WarmupUpdates; index++)
|
||||||
|
processor.Update(descriptions[index % frames]);
|
||||||
|
for (var frame = 0; frame < frames; frame++)
|
||||||
|
{
|
||||||
|
processor.Update(descriptions[frame]);
|
||||||
|
Submit(output);
|
||||||
|
}
|
||||||
|
Synchronize();
|
||||||
|
|
||||||
|
var cpu = TimeSpan.MaxValue;
|
||||||
|
for (var frame = 0; frame < frames; frame++)
|
||||||
|
{
|
||||||
|
var elapsed = Stopwatch.StartNew();
|
||||||
|
processor.Update(descriptions[frame]);
|
||||||
|
Submit(output);
|
||||||
|
elapsed.Stop();
|
||||||
|
cpu = elapsed.Elapsed < cpu ? elapsed.Elapsed : cpu;
|
||||||
|
}
|
||||||
|
Synchronize();
|
||||||
|
|
||||||
|
TimeSpan? gpu = null;
|
||||||
|
for (var frame = 0; frame < frames; frame++)
|
||||||
|
{
|
||||||
|
processor.Update(descriptions[frame]);
|
||||||
|
timer.Begin();
|
||||||
|
Submit(output);
|
||||||
|
timer.End();
|
||||||
|
if (timer.Resolve() is { } resolved && (gpu is null || resolved < gpu))
|
||||||
|
gpu = resolved;
|
||||||
|
}
|
||||||
|
Synchronize();
|
||||||
|
|
||||||
|
var repeats = frames * UpdateRepeats;
|
||||||
|
var updates = Stopwatch.StartNew();
|
||||||
|
for (var index = 0; index < repeats; index++)
|
||||||
|
processor.Update(descriptions[index % frames]);
|
||||||
|
updates.Stop();
|
||||||
|
|
||||||
|
GC.Collect();
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
|
GC.Collect();
|
||||||
|
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||||
|
var collections = GC.CollectionCount(0);
|
||||||
|
for (var frame = 0; frame < frames; frame++)
|
||||||
|
processor.Update(descriptions[frame]);
|
||||||
|
var allocated = (GC.GetAllocatedBytesForCurrentThread() - before) / frames;
|
||||||
|
var gen0 = GC.CollectionCount(0) - collections;
|
||||||
|
|
||||||
|
return new Measurement(gpu, cpu, updates.Elapsed / repeats, allocated, gen0);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
processor.ClearInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] Capture(ID2D1Image output)
|
||||||
|
{
|
||||||
|
Submit(output);
|
||||||
|
readback.CopyFromBitmap(target);
|
||||||
|
|
||||||
|
var stride = CanvasWidth * HarnessImage.BytesPerPixel;
|
||||||
|
var pixels = new byte[stride * CanvasHeight];
|
||||||
|
var mapped = readback.Map(MapOptions.Read);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (var y = 0; y < CanvasHeight; y++)
|
||||||
|
Marshal.Copy(mapped.Bits + y * (int)mapped.Pitch, pixels, y * stride, stride);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
readback.Unmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Submit(ID2D1Image output)
|
||||||
|
{
|
||||||
|
var deviceContext = context.DeviceContext;
|
||||||
|
deviceContext.Target = target;
|
||||||
|
deviceContext.BeginDraw();
|
||||||
|
deviceContext.Clear(new Color4(0f, 0f, 0f, 0f));
|
||||||
|
deviceContext.DrawImage(output, new Vector2(CanvasWidth * 0.5f, CanvasHeight * 0.5f), null, InterpolationMode.NearestNeighbor, CompositeMode.SourceOver);
|
||||||
|
deviceContext.EndDraw();
|
||||||
|
deviceContext.Target = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Synchronize()
|
||||||
|
{
|
||||||
|
sync.CopyFromBitmap(Int2.Zero, target, new RectI(0, 0, 1, 1));
|
||||||
|
_ = sync.Map(MapOptions.Read);
|
||||||
|
sync.Unmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
EffectDescription Describe(int frame)
|
||||||
|
{
|
||||||
|
var timeline = new TimelineSourceDescription(
|
||||||
|
new System.Drawing.Size(CanvasWidth, CanvasHeight),
|
||||||
|
new YukkuriMovieMaker.Player.Video.FrameTime(frame, Fps),
|
||||||
|
new YukkuriMovieMaker.Player.Video.FrameTime(Length, Fps),
|
||||||
|
Fps,
|
||||||
|
TimelineSourceUsage.Playing,
|
||||||
|
Guid.Empty,
|
||||||
|
[]);
|
||||||
|
var item = new TimelineItemSourceDescription(timeline, frame, Length, 0);
|
||||||
|
var draw = new DrawDescription(Vector3.Zero, Vector2.Zero, Vector2.One, Vector3.Zero, Matrix4x4.Identity, InterpolationMode.Linear, 1d, false, []);
|
||||||
|
return new EffectDescription(item, draw, 0, 1, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ID2D1Bitmap1 CreateBitmap(ID2D1DeviceContext6 deviceContext, int width, int height, BitmapOptions options)
|
||||||
|
=> deviceContext.CreateBitmap(
|
||||||
|
new SizeI(width, height), nint.Zero, width * HarnessImage.BytesPerPixel,
|
||||||
|
new BitmapProperties1(PixelFormat, Dpi, Dpi, options));
|
||||||
|
|
||||||
|
static string FormatDriverVersion(long version)
|
||||||
|
=> $"{(version >> 48) & 0xFFFF}.{(version >> 32) & 0xFFFF}.{(version >> 16) & 0xFFFF}.{version & 0xFFFF}";
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
placement.SetInput(0, null, true);
|
||||||
|
centered.Dispose();
|
||||||
|
placement.Dispose();
|
||||||
|
timer.Dispose();
|
||||||
|
sync.Dispose();
|
||||||
|
readback.Dispose();
|
||||||
|
target.Dispose();
|
||||||
|
image.Dispose();
|
||||||
|
context.Dispose();
|
||||||
|
devices.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly record struct Measurement(TimeSpan? Gpu, TimeSpan Cpu, TimeSpan Update, long Allocated, int Gen0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal static class HostAssemblyResolver
|
||||||
|
{
|
||||||
|
const string MetadataKey = "HostDirectory";
|
||||||
|
const string AssemblyExtension = ".dll";
|
||||||
|
|
||||||
|
public static string Directory { get; } = ReadDirectory();
|
||||||
|
|
||||||
|
public static bool IsConfigured => Directory.Length != 0 && System.IO.Directory.Exists(Directory);
|
||||||
|
|
||||||
|
[ModuleInitializer]
|
||||||
|
internal static void Initialize()
|
||||||
|
{
|
||||||
|
if (!IsConfigured)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.AssemblyResolve += (_, arguments) =>
|
||||||
|
{
|
||||||
|
var name = new AssemblyName(arguments.Name).Name;
|
||||||
|
if (name is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var candidate = Path.Combine(Directory, name + AssemblyExtension);
|
||||||
|
return File.Exists(candidate) ? Assembly.LoadFrom(candidate) : null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static string ReadDirectory() => typeof(HostAssemblyResolver).Assembly
|
||||||
|
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||||
|
.FirstOrDefault(attribute => string.Equals(attribute.Key, MetadataKey, StringComparison.Ordinal))
|
||||||
|
?.Value ?? string.Empty;
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal readonly record struct ImageDifference(int Differing, int MaxDelta, int Left, int Top, int Right, int Bottom)
|
||||||
|
{
|
||||||
|
public bool IsEmpty => Differing == 0;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
=> IsEmpty ? "一致" : $"differing={Differing} maxDelta={MaxDelta} box=({Left},{Top})-({Right},{Bottom})";
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class ImageComparison
|
||||||
|
{
|
||||||
|
public static ImageDifference Of(byte[] first, byte[] second, int width, int height)
|
||||||
|
{
|
||||||
|
if (first.Length != second.Length || first.Length != width * height * HarnessImage.BytesPerPixel)
|
||||||
|
throw new ArgumentException("画像の寸法が一致しません。");
|
||||||
|
|
||||||
|
var differing = 0;
|
||||||
|
var maxDelta = 0;
|
||||||
|
var left = width;
|
||||||
|
var top = height;
|
||||||
|
var right = -1;
|
||||||
|
var bottom = -1;
|
||||||
|
for (var y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
for (var x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
var offset = (y * width + x) * HarnessImage.BytesPerPixel;
|
||||||
|
var delta = 0;
|
||||||
|
for (var channel = 0; channel < HarnessImage.BytesPerPixel; channel++)
|
||||||
|
delta = Math.Max(delta, Math.Abs(first[offset + channel] - second[offset + channel]));
|
||||||
|
if (delta == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
differing++;
|
||||||
|
maxDelta = Math.Max(maxDelta, delta);
|
||||||
|
left = Math.Min(left, x);
|
||||||
|
top = Math.Min(top, y);
|
||||||
|
right = Math.Max(right, x);
|
||||||
|
bottom = Math.Max(bottom, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return differing == 0 ? default : new ImageDifference(differing, maxDelta, left, top, right, bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<AssemblyName>InkDispersion.Harness</AssemblyName>
|
<AssemblyName>InkDispersion.Harness</AssemblyName>
|
||||||
<RootNamespace>InkDispersion.Harness</RootNamespace>
|
<RootNamespace>InkDispersion.Harness</RootNamespace>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
<TieredCompilation>false</TieredCompilation>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -18,14 +20,43 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="YukkuriMovieMaker.Plugin">
|
<AssemblyMetadata Include="HostDirectory" Value="$(YMM4DirPath)" />
|
||||||
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Plugin.dll</HintPath>
|
<AssemblyMetadata Include="HarnessDirectory" Value="$(MSBuildProjectDirectory)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="SharpGen.Runtime">
|
||||||
|
<HintPath>$(YMM4DirPath)SharpGen.Runtime.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Vortice.Direct2D1">
|
||||||
|
<HintPath>$(YMM4DirPath)Vortice.Direct2D1.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Vortice.Direct3D11">
|
||||||
|
<HintPath>$(YMM4DirPath)Vortice.Direct3D11.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Vortice.DirectX">
|
||||||
|
<HintPath>$(YMM4DirPath)Vortice.DirectX.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Vortice.DXGI">
|
||||||
|
<HintPath>$(YMM4DirPath)Vortice.DXGI.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Vortice.Mathematics">
|
||||||
|
<HintPath>$(YMM4DirPath)Vortice.Mathematics.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="YukkuriMovieMaker.Controls">
|
<Reference Include="YukkuriMovieMaker.Controls">
|
||||||
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Controls.dll</HintPath>
|
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Controls.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="YukkuriMovieMaker.Plugin">
|
||||||
|
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Plugin.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project="..\InkDispersion\ComputeSharp.Reference.props" />
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
+455
-166
@@ -1,212 +1,501 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using ComputeSharp;
|
using System.IO;
|
||||||
|
using System.IO.Packaging;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using ComputeWeave;
|
||||||
using InkDispersion;
|
using InkDispersion;
|
||||||
|
using InkDispersion.Harness;
|
||||||
|
using SharpGen.Runtime;
|
||||||
|
|
||||||
var width = 1280;
|
const int CanvasWidth = 1280;
|
||||||
var height = 720;
|
const int CanvasHeight = 720;
|
||||||
var outputDirectory = args.Length > 0 && !args[0].StartsWith("--") ? args[0] : Path.Combine(AppContext.BaseDirectory, "harness-output");
|
const int ImageWidth = 640;
|
||||||
Directory.CreateDirectory(outputDirectory);
|
const int ImageHeight = 480;
|
||||||
|
const int FullHdWidth = 1920;
|
||||||
|
const int FullHdHeight = 1080;
|
||||||
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
_ = PackUriHelper.UriSchemePack;
|
||||||
if (pipeline is null)
|
|
||||||
|
HarnessArguments arguments;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("Direct3D 12 is unavailable.");
|
arguments = HarnessArguments.Parse(args);
|
||||||
return 1;
|
}
|
||||||
|
catch (HarnessException exception)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.Error.WriteLine(HarnessArguments.Usage);
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
var source = CreateTestImage(width, height);
|
try
|
||||||
var destination = new int[source.Length];
|
|
||||||
|
|
||||||
if (args.Contains("--golden"))
|
|
||||||
{
|
{
|
||||||
var goldenCases = new (string Name, InkDispersionPipeline.Parameters Parameters)[]
|
if (arguments.Mode == HarnessMode.Compare)
|
||||||
|
return Compare(arguments.Before!, arguments.After!);
|
||||||
|
|
||||||
|
if (arguments.Mode == HarnessMode.Structure)
|
||||||
{
|
{
|
||||||
("balanced-default", new(InkDispersionQuality.Balanced, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 120f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7)),
|
var structureImage = arguments.Input is { } structureInput ? HarnessImage.Load(structureInput) : HarnessImage.Synthetic(CanvasWidth, CanvasHeight);
|
||||||
("high-default", new(InkDispersionQuality.High, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 120f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7)),
|
return Structure(structureImage);
|
||||||
("seed-42", new(InkDispersionQuality.Balanced, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 120f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 42)),
|
|
||||||
("partial-spread", new(InkDispersionQuality.Balanced, 0.35f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 120f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7)),
|
|
||||||
("smooth", new(InkDispersionQuality.Balanced, 1f, 0.6f, 0f, 0f, 0.3f, 0.4f, 120f, 0.8f, 0f, 0.12f, 0.1f, 0.09f, 7)),
|
|
||||||
("branching", new(InkDispersionQuality.Balanced, 1f, 1f, 1f, 0.8f, 0f, 0.2f, 120f, 1f, 1f, 0.12f, 0.1f, 0.09f, 7)),
|
|
||||||
("viscous", new(InkDispersionQuality.Balanced, 1f, 0.6f, 0.5f, 0.3f, 1f, 0.8f, 120f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7)),
|
|
||||||
("short-reach", new(InkDispersionQuality.Balanced, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 24f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7)),
|
|
||||||
};
|
|
||||||
foreach (var (name, goldenParameters) in goldenCases)
|
|
||||||
{
|
|
||||||
var parameters = goldenParameters;
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
var bytes = new byte[destination.Length * sizeof(int)];
|
|
||||||
Buffer.BlockCopy(destination, 0, bytes, 0, bytes.Length);
|
|
||||||
Console.WriteLine($"{name}: {Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(bytes))}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arguments.Mode == HarnessMode.Recompute)
|
||||||
|
{
|
||||||
|
var recomputeImage = arguments.Input is { } recomputeInput ? HarnessImage.Load(recomputeInput) : HarnessImage.Synthetic(CanvasWidth, CanvasHeight);
|
||||||
|
return Recompute(recomputeImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
var outputDirectory = arguments.OutputDirectory ?? Path.Combine(AppContext.BaseDirectory, "harness-output");
|
||||||
|
if (arguments.Mode == HarnessMode.Benchmark)
|
||||||
|
{
|
||||||
|
if (arguments.Input is { } benchmarkInput)
|
||||||
|
{
|
||||||
|
Benchmark(HarnessImage.Load(benchmarkInput));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Benchmark(HarnessImage.Synthetic(CanvasWidth, CanvasHeight));
|
||||||
|
Benchmark(HarnessImage.Synthetic(FullHdWidth, FullHdHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var image = arguments.Input is { } input ? HarnessImage.Load(input) : HarnessImage.Synthetic(ImageWidth, ImageHeight);
|
||||||
|
using var renderer = new HarnessRenderer(CanvasWidth, CanvasHeight, image);
|
||||||
|
return arguments.Mode switch
|
||||||
|
{
|
||||||
|
HarnessMode.Golden => WriteGolden(renderer, image),
|
||||||
|
HarnessMode.Verify => Verify(renderer, image),
|
||||||
|
HarnessMode.Transition => Transition(renderer, outputDirectory),
|
||||||
|
_ => Render(renderer, outputDirectory),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception exception) when (exception is HarnessException or SharpGenException)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Render(HarnessRenderer renderer, string outputDirectory)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(outputDirectory);
|
||||||
|
var failures = 0;
|
||||||
|
var cases = Evaluate(renderer, (golden, files, frames) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{golden.Name}: {golden.Hash}");
|
||||||
|
for (var index = 0; index < files.Length; index++)
|
||||||
|
{
|
||||||
|
HarnessImage.Save(Path.Combine(outputDirectory, files[index]), frames[index], renderer.CanvasWidth, renderer.CanvasHeight);
|
||||||
|
var opaque = CountOpaque(frames[index]);
|
||||||
|
Console.WriteLine($" {files[index]} opaque={opaque}");
|
||||||
|
if (opaque == 0)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"{files[index]}: 出力が完全に透明です。");
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Console.WriteLine($"-> {outputDirectory}");
|
||||||
|
return failures + CountDuplicates(cases) == 0 ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int WriteGolden(HarnessRenderer renderer, HarnessImage image)
|
||||||
|
{
|
||||||
|
var cases = Evaluate(renderer, null);
|
||||||
|
if (CountDuplicates(cases) != 0)
|
||||||
|
return 1;
|
||||||
|
if (cases.Count == 0)
|
||||||
|
Console.Error.WriteLine("ケースがありません。HarnessCases に書き足してください。");
|
||||||
|
|
||||||
|
var golden = new Golden(renderer.Adapter, renderer.Driver, image.Identity, $"{renderer.CanvasWidth}x{renderer.CanvasHeight}", cases);
|
||||||
|
var path = Golden.PathFor(image);
|
||||||
|
golden.Save(path);
|
||||||
|
Console.WriteLine($"adapter: {golden.Adapter} (driver {golden.Driver})");
|
||||||
|
Console.WriteLine($"input: {golden.Input}");
|
||||||
|
foreach (var (name, _, hash) in cases)
|
||||||
|
Console.WriteLine($"{name}: {hash}");
|
||||||
|
Console.WriteLine($"-> {path}");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var quality in new[] { InkDispersionQuality.Balanced, InkDispersionQuality.High, InkDispersionQuality.Ultra })
|
static int Verify(HarnessRenderer renderer, HarnessImage image)
|
||||||
{
|
{
|
||||||
var parameters = new InkDispersionPipeline.Parameters(quality, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 160f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7);
|
var golden = Golden.Load(Golden.PathFor(image));
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
var canvas = $"{renderer.CanvasWidth}x{renderer.CanvasHeight}";
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
if (golden.Input != image.Identity || golden.Canvas != canvas)
|
||||||
var stopwatch = Stopwatch.StartNew();
|
{
|
||||||
const int frames = 5;
|
Console.Error.WriteLine($"基準値は入力 {golden.Input} とキャンバス {golden.Canvas} で書かれています。今回は入力 {image.Identity} とキャンバス {canvas} です。");
|
||||||
for (var frame = 0; frame < frames; frame++)
|
return 1;
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
}
|
||||||
stopwatch.Stop();
|
|
||||||
Console.WriteLine($"{quality}: {stopwatch.Elapsed.TotalMilliseconds / frames:F2} ms/frame ({width}x{height}) litPixels={CountLit(destination)}");
|
if (golden.Adapter != renderer.Adapter || golden.Driver != renderer.Driver)
|
||||||
|
Console.Error.WriteLine($"基準値は {golden.Adapter} (driver {golden.Driver}) で書かれています。今回は {renderer.Adapter} (driver {renderer.Driver}) です。画素の差はこの違いから来ることがあります。");
|
||||||
|
|
||||||
|
var failures = 0;
|
||||||
|
var current = Evaluate(renderer, null).ToDictionary(item => item.Name, StringComparer.Ordinal);
|
||||||
|
if (golden.Cases.Count == 0 && current.Count == 0)
|
||||||
|
Console.Error.WriteLine("ケースがありません。HarnessCases に書き足してください。");
|
||||||
|
foreach (var (name, frames, hash) in golden.Cases)
|
||||||
|
{
|
||||||
|
if (!current.Remove(name, out var actual))
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"{name}: ケースがありません。基準値を書き直してください。");
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
|
else if (!actual.Frames.SequenceEqual(frames))
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"{name}: フレームが違います。基準値 [{string.Join(", ", frames)}]、今回 [{string.Join(", ", actual.Frames)}]。基準値を書き直してください。");
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
|
else if (actual.Hash != hash)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"{name}: 一致しません。基準値 {hash}、今回 {actual.Hash}");
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{name}: 一致");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var name in current.Keys)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"{name}: 基準値にありません。基準値を書き直してください。");
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return failures == 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int Transition(HarnessRenderer renderer, string outputDirectory)
|
||||||
{
|
{
|
||||||
|
var failures = 0;
|
||||||
|
foreach (var (name, create, change, frame) in HarnessCases.Transitions())
|
||||||
|
{
|
||||||
|
var (direct, transitioned) = renderer.RenderTransition(create, change, frame);
|
||||||
|
var difference = ImageComparison.Of(direct, transitioned, renderer.CanvasWidth, renderer.CanvasHeight);
|
||||||
|
if (difference.IsEmpty)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{name}: 一致");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
failures++;
|
||||||
|
Directory.CreateDirectory(outputDirectory);
|
||||||
|
HarnessImage.Save(Path.Combine(outputDirectory, name + "-direct.png"), direct, renderer.CanvasWidth, renderer.CanvasHeight);
|
||||||
|
HarnessImage.Save(Path.Combine(outputDirectory, name + "-transitioned.png"), transitioned, renderer.CanvasWidth, renderer.CanvasHeight);
|
||||||
|
Console.Error.WriteLine($"{name}: {difference}。設定を変えた後の描画が作り直した場合と違います。-> {outputDirectory}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!HarnessCases.Transitions().Any() && !HarnessCases.All().Any(item => item.Frames.Count > 1))
|
||||||
|
Console.Error.WriteLine("ケースがありません。HarnessCases に書き足してください。");
|
||||||
|
|
||||||
|
foreach (var (name, effect, frames) in HarnessCases.All())
|
||||||
|
{
|
||||||
|
if (frames.Count < 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var sequential = renderer.Render(effect, frames);
|
||||||
|
for (var index = 0; index < frames.Count; index++)
|
||||||
|
{
|
||||||
|
var fresh = renderer.Render(effect, [frames[index]])[0];
|
||||||
|
var difference = ImageComparison.Of(fresh, sequential[index], renderer.CanvasWidth, renderer.CanvasHeight);
|
||||||
|
var label = $"{name}-f{frames[index]:D3}";
|
||||||
|
if (difference.IsEmpty)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{label}: 一致");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
failures++;
|
||||||
|
Directory.CreateDirectory(outputDirectory);
|
||||||
|
HarnessImage.Save(Path.Combine(outputDirectory, label + "-direct.png"), fresh, renderer.CanvasWidth, renderer.CanvasHeight);
|
||||||
|
HarnessImage.Save(Path.Combine(outputDirectory, label + "-transitioned.png"), sequential[index], renderer.CanvasWidth, renderer.CanvasHeight);
|
||||||
|
Console.Error.WriteLine($"{label}: {difference}。前のフレームから進めた描画が作り直した場合と違います。-> {outputDirectory}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return failures == 0 ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Structure(HarnessImage image)
|
||||||
|
{
|
||||||
|
const int Rounds = 12;
|
||||||
|
const int Seed = 17;
|
||||||
|
const int RectFrames = 20;
|
||||||
|
|
||||||
|
using var pipeline = InkDispersionPipeline.TryCreate();
|
||||||
|
if (pipeline is null)
|
||||||
|
throw new HarnessException("Direct3D 12を利用できません。");
|
||||||
|
|
||||||
var device = GraphicsDevice.GetDefault();
|
var device = GraphicsDevice.GetDefault();
|
||||||
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(width, height);
|
using var sourceTexture = LoadSourceTexture(device, image);
|
||||||
var pixels = new Bgra32[source.Length];
|
|
||||||
for (var index = 0; index < source.Length; index++)
|
|
||||||
pixels[index].PackedValue = unchecked((uint)source[index]);
|
|
||||||
sourceTexture.CopyFrom(pixels);
|
|
||||||
var parameters = new InkDispersionPipeline.Parameters(InkDispersionQuality.High, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 160f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7);
|
|
||||||
|
|
||||||
pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters);
|
var parameters = StructureParameters();
|
||||||
var stopwatch = Stopwatch.StartNew();
|
pipeline.Simulate(sourceTexture, image.Width, image.Height, 0, 0, image.Width, image.Height, in parameters);
|
||||||
pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, parameters with { Seed = 8 });
|
pipeline.WaitForCompletion();
|
||||||
stopwatch.Stop();
|
var stopwatch = new Stopwatch();
|
||||||
Console.WriteLine($"structure recompute: {stopwatch.Elapsed.TotalMilliseconds:F2} ms");
|
|
||||||
|
|
||||||
if (pipeline.TryGetVisibleBounds(width, height, in parameters, out var rect))
|
var variants = new (string Name, Func<bool, InkDispersionPipeline.Parameters> Make)[]
|
||||||
|
{
|
||||||
|
("cached", _ => parameters),
|
||||||
|
("water", flip => parameters with { Water = flip ? 0.70f : 0.60f }),
|
||||||
|
("reach", flip => parameters with { ReachPixels = flip ? 176f : 160f }),
|
||||||
|
("fiber", flip => parameters with { Fiber = flip ? 0.60f : 0.50f }),
|
||||||
|
("sizing", flip => parameters with { Sizing = flip ? 0.40f : 0.30f }),
|
||||||
|
("viscosity", flip => parameters with { Viscosity = flip ? 0.40f : 0.30f }),
|
||||||
|
("drying", flip => parameters with { Drying = flip ? 0.50f : 0.40f }),
|
||||||
|
("seed", flip => parameters with { Seed = flip ? 8 : 7 }),
|
||||||
|
("all", flip => parameters with
|
||||||
|
{
|
||||||
|
Water = flip ? 0.70f : 0.60f,
|
||||||
|
ReachPixels = flip ? 176f : 160f,
|
||||||
|
Fiber = flip ? 0.60f : 0.50f,
|
||||||
|
Sizing = flip ? 0.40f : 0.30f,
|
||||||
|
Viscosity = flip ? 0.40f : 0.30f,
|
||||||
|
Drying = flip ? 0.50f : 0.40f,
|
||||||
|
Seed = flip ? 8 : 7,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
var samples = new List<double>[variants.Length];
|
||||||
|
for (var index = 0; index < samples.Length; index++)
|
||||||
|
samples[index] = new List<double>(Rounds);
|
||||||
|
|
||||||
|
foreach (var (_, make) in variants)
|
||||||
|
{
|
||||||
|
var warmup = make(true);
|
||||||
|
pipeline.Simulate(sourceTexture, image.Width, image.Height, 0, 0, image.Width, image.Height, in warmup);
|
||||||
|
pipeline.WaitForCompletion();
|
||||||
|
}
|
||||||
|
|
||||||
|
var order = Enumerable.Range(0, variants.Length).ToArray();
|
||||||
|
var random = new Random(Seed);
|
||||||
|
for (var round = 0; round < Rounds; round++)
|
||||||
|
{
|
||||||
|
for (var index = order.Length - 1; index > 0; index--)
|
||||||
|
{
|
||||||
|
var swap = random.Next(index + 1);
|
||||||
|
(order[index], order[swap]) = (order[swap], order[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var index in order)
|
||||||
|
{
|
||||||
|
var settled = variants[index].Make(false);
|
||||||
|
pipeline.Simulate(sourceTexture, image.Width, image.Height, 0, 0, image.Width, image.Height, in settled);
|
||||||
|
pipeline.WaitForCompletion();
|
||||||
|
|
||||||
|
var measured = variants[index].Make(true);
|
||||||
|
stopwatch.Restart();
|
||||||
|
pipeline.Simulate(sourceTexture, image.Width, image.Height, 0, 0, image.Width, image.Height, in measured);
|
||||||
|
pipeline.WaitForCompletion();
|
||||||
|
stopwatch.Stop();
|
||||||
|
samples[index].Add(stopwatch.Elapsed.TotalMilliseconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"structure recompute over {Rounds} interleaved rounds (ms)");
|
||||||
|
for (var index = 0; index < variants.Length; index++)
|
||||||
|
{
|
||||||
|
var sorted = samples[index].OrderBy(static value => value).ToArray();
|
||||||
|
var median = sorted[sorted.Length / 2];
|
||||||
|
Console.WriteLine($" {variants[index].Name,-11} min={sorted[0],7:F2} median={median,7:F2} max={sorted[^1],7:F2}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pipeline.TryGetVisibleBounds(image.Width, image.Height, in parameters, out var rect))
|
||||||
{
|
{
|
||||||
using var rectOutput = device.AllocateReadWriteTexture2D<Bgra32, Float4>(rect.Width, rect.Height);
|
using var rectOutput = device.AllocateReadWriteTexture2D<Bgra32, Float4>(rect.Width, rect.Height);
|
||||||
pipeline.RenderVisible(rectOutput, width, height, rect, in parameters);
|
pipeline.RenderVisible(rectOutput, image.Width, image.Height, rect, in parameters);
|
||||||
pipeline.WaitForCompletion();
|
pipeline.WaitForCompletion();
|
||||||
stopwatch.Restart();
|
stopwatch.Restart();
|
||||||
const int rectFrames = 20;
|
for (var frame = 0; frame < RectFrames; frame++)
|
||||||
for (var frame = 0; frame < rectFrames; frame++)
|
|
||||||
{
|
{
|
||||||
pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters);
|
pipeline.Simulate(sourceTexture, image.Width, image.Height, 0, 0, image.Width, image.Height, in parameters);
|
||||||
pipeline.TryGetVisibleBounds(width, height, in parameters, out rect);
|
pipeline.TryGetVisibleBounds(image.Width, image.Height, in parameters, out rect);
|
||||||
pipeline.RenderVisible(rectOutput, width, height, rect, in parameters);
|
pipeline.RenderVisible(rectOutput, image.Width, image.Height, rect, in parameters);
|
||||||
}
|
}
|
||||||
pipeline.WaitForCompletion();
|
pipeline.WaitForCompletion();
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Console.WriteLine($"cached frame with rect {rect.Width}x{rect.Height} at ({rect.X},{rect.Y}): {stopwatch.Elapsed.TotalMilliseconds / rectFrames:F2} ms/frame");
|
Console.WriteLine($"cached frame with rect {rect.Width}x{rect.Height} at ({rect.X},{rect.Y}): {stopwatch.Elapsed.TotalMilliseconds / RectFrames:F2} ms/frame");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Recompute(HarnessImage image)
|
||||||
|
{
|
||||||
|
const int Samples = 24;
|
||||||
|
const int IdleMilliseconds = 500;
|
||||||
|
|
||||||
|
using var pipeline = InkDispersionPipeline.TryCreate();
|
||||||
|
if (pipeline is null)
|
||||||
|
throw new HarnessException("Direct3D 12を利用できません。");
|
||||||
|
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var sourceTexture = LoadSourceTexture(device, image);
|
||||||
|
|
||||||
|
var settled = StructureParameters();
|
||||||
|
var alternate = settled with { Seed = settled.Seed + 1 };
|
||||||
|
pipeline.Simulate(sourceTexture, image.Width, image.Height, 0, 0, image.Width, image.Height, in settled);
|
||||||
|
pipeline.WaitForCompletion();
|
||||||
|
pipeline.Simulate(sourceTexture, image.Width, image.Height, 0, 0, image.Width, image.Height, in alternate);
|
||||||
|
pipeline.WaitForCompletion();
|
||||||
|
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
var samples = new List<double>(Samples);
|
||||||
|
for (var sample = 0; sample < Samples; sample++)
|
||||||
|
{
|
||||||
|
Thread.Sleep(IdleMilliseconds);
|
||||||
|
var measured = (sample & 1) == 0 ? settled : alternate;
|
||||||
|
stopwatch.Restart();
|
||||||
|
pipeline.Simulate(sourceTexture, image.Width, image.Height, 0, 0, image.Width, image.Height, in measured);
|
||||||
|
pipeline.WaitForCompletion();
|
||||||
|
stopwatch.Stop();
|
||||||
|
samples.Add(stopwatch.Elapsed.TotalMilliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
var sorted = samples.OrderBy(static value => value).ToArray();
|
||||||
|
Console.WriteLine($"structure recompute over {Samples} samples with {IdleMilliseconds} ms idle between (ms)");
|
||||||
|
Console.WriteLine($" min={sorted[0]:F2} median={sorted[sorted.Length / 2]:F2} max={sorted[^1]:F2}");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static InkDispersionPipeline.Parameters StructureParameters()
|
||||||
|
=> new(InkDispersionQuality.High, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 160f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7);
|
||||||
|
|
||||||
|
static ReadWriteTexture2D<Bgra32, Float4> LoadSourceTexture(GraphicsDevice device, HarnessImage image)
|
||||||
|
{
|
||||||
|
var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(image.Width, image.Height);
|
||||||
|
var pixels = new Bgra32[image.Width * image.Height];
|
||||||
|
for (var index = 0; index < pixels.Length; index++)
|
||||||
|
{
|
||||||
|
var offset = index * HarnessImage.BytesPerPixel;
|
||||||
|
pixels[index] = new Bgra32(image.Pixels[offset + 2], image.Pixels[offset + 1], image.Pixels[offset], image.Pixels[offset + 3]);
|
||||||
|
}
|
||||||
|
sourceTexture.CopyFrom(pixels);
|
||||||
|
return sourceTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Compare(string beforeDirectory, string afterDirectory)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(beforeDirectory) || !Directory.Exists(afterDirectory))
|
||||||
|
throw new HarnessException("比べる出力先がありません。");
|
||||||
|
|
||||||
|
var failures = 0;
|
||||||
|
var names = Directory.EnumerateFiles(beforeDirectory, "*.png")
|
||||||
|
.Concat(Directory.EnumerateFiles(afterDirectory, "*.png"))
|
||||||
|
.Select(path => Path.GetFileName(path))
|
||||||
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||||
|
.Order(StringComparer.OrdinalIgnoreCase)
|
||||||
|
.ToArray();
|
||||||
|
if (names.Length == 0)
|
||||||
|
throw new HarnessException("比べる PNG がありません。");
|
||||||
|
|
||||||
|
foreach (var name in names)
|
||||||
|
{
|
||||||
|
var before = Path.Combine(beforeDirectory, name);
|
||||||
|
var after = Path.Combine(afterDirectory, name);
|
||||||
|
if (!File.Exists(before) || !File.Exists(after))
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"{name}: {(File.Exists(before) ? "後" : "前")}にありません。");
|
||||||
|
failures++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var (beforeWidth, beforeHeight, beforePixels) = HarnessImage.LoadPremultiplied(before);
|
||||||
|
var (afterWidth, afterHeight, afterPixels) = HarnessImage.LoadPremultiplied(after);
|
||||||
|
if (beforeWidth != afterWidth || beforeHeight != afterHeight)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"{name}: 寸法が違います。前 {beforeWidth}x{beforeHeight}、後 {afterWidth}x{afterHeight}");
|
||||||
|
failures++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var difference = ImageComparison.Of(beforePixels, afterPixels, beforeWidth, beforeHeight);
|
||||||
|
Console.WriteLine($"{name}: {difference}");
|
||||||
|
if (!difference.IsEmpty)
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return failures == 0 ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Benchmark(HarnessImage image)
|
||||||
|
{
|
||||||
|
const int Frames = 60;
|
||||||
|
|
||||||
|
using var renderer = new HarnessRenderer(image.Width, image.Height, image);
|
||||||
|
Console.WriteLine($"adapter: {renderer.Adapter} (driver {renderer.Driver})");
|
||||||
|
foreach (var (name, effect) in HarnessCases.Benchmarks())
|
||||||
|
{
|
||||||
|
Report(image, name, "still", renderer.Measure(effect, Frames, moving: false));
|
||||||
|
Report(image, name, "moving", renderer.Measure(effect, Frames, moving: true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var spread in new[] { 0.25f, 0.5f, 0.75f, 1f })
|
static void Report(HarnessImage image, string name, string motion, HarnessRenderer.Measurement measurement)
|
||||||
{
|
=> Console.WriteLine(
|
||||||
var parameters = new InkDispersionPipeline.Parameters(InkDispersionQuality.High, spread, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 160f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7);
|
$"{image.Width}x{image.Height} {name,-15} {motion,-6} " +
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
$"gpu={(measurement.Gpu is { } gpu ? gpu.TotalMilliseconds.ToString("F3") : "n/a"),7} " +
|
||||||
Console.WriteLine($"spread={spread:F2} litPixels={CountLit(destination)}");
|
$"cpu={measurement.Cpu.TotalMilliseconds,7:F3} " +
|
||||||
WriteBmp(Path.Combine(outputDirectory, $"spread{(int)(spread * 100):D3}.bmp"), Composite(source, destination), width, height);
|
$"update={measurement.Update.TotalMilliseconds,6:F3} " +
|
||||||
}
|
$"alloc={measurement.Allocated,6} gen0={measurement.Gen0}");
|
||||||
|
|
||||||
foreach (var fiber in new[] { 0f, 0.5f, 1f })
|
static List<GoldenCase> Evaluate(HarnessRenderer renderer, Action<GoldenCase, string[], byte[][]>? report)
|
||||||
{
|
{
|
||||||
var parameters = new InkDispersionPipeline.Parameters(InkDispersionQuality.High, 1f, 0.6f, fiber, 0.3f, 0.3f, 0.4f, 160f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7);
|
var cases = new List<GoldenCase>();
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
var names = new HashSet<string>(StringComparer.Ordinal);
|
||||||
Console.WriteLine($"fiber={fiber:F2} litPixels={CountLit(destination)}");
|
foreach (var (name, effect, frames) in HarnessCases.All())
|
||||||
WriteBmp(Path.Combine(outputDirectory, $"fiber{(int)(fiber * 100):D3}.bmp"), Composite(source, destination), width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var sizing in new[] { 0f, 0.5f, 1f })
|
|
||||||
{
|
|
||||||
var parameters = new InkDispersionPipeline.Parameters(InkDispersionQuality.High, 1f, 0.6f, 0.5f, sizing, 0.3f, 0.4f, 160f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7);
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
Console.WriteLine($"sizing={sizing:F2} litPixels={CountLit(destination)}");
|
|
||||||
WriteBmp(Path.Combine(outputDirectory, $"sizing{(int)(sizing * 100):D3}.bmp"), Composite(source, destination), width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var water in new[] { 0f, 0.5f, 1f })
|
|
||||||
{
|
|
||||||
var parameters = new InkDispersionPipeline.Parameters(InkDispersionQuality.High, 1f, water, 0.5f, 0.3f, 0.3f, 0.4f, 160f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 7);
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
Console.WriteLine($"water={water:F2} litPixels={CountLit(destination)}");
|
|
||||||
WriteBmp(Path.Combine(outputDirectory, $"water{(int)(water * 100):D3}.bmp"), Composite(source, destination), width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
WriteBmp(Path.Combine(outputDirectory, "source.bmp"), source, width, height);
|
|
||||||
Console.WriteLine($"images written to {outputDirectory}");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
static int[] CreateTestImage(int width, int height)
|
|
||||||
{
|
|
||||||
var pixels = new int[width * height];
|
|
||||||
var left = width / 2 - 100;
|
|
||||||
var top = height / 2 - 40;
|
|
||||||
for (var y = top; y < top + 80; y++)
|
|
||||||
{
|
{
|
||||||
for (var x = left; x < left + 200; x++)
|
if (!names.Add(name))
|
||||||
|
throw new HarnessException($"ケース名が重複しています。{name}");
|
||||||
|
|
||||||
|
var rendered = renderer.Render(effect, frames);
|
||||||
|
var files = new string[frames.Count];
|
||||||
|
using var hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA256);
|
||||||
|
for (var index = 0; index < frames.Count; index++)
|
||||||
{
|
{
|
||||||
if (x < 0 || x >= width || y < 0 || y >= height)
|
hash.AppendData(rendered[index]);
|
||||||
continue;
|
files[index] = frames.Count == 1 ? name + ".png" : $"{name}-f{frames[index]:D3}.png";
|
||||||
pixels[y * width + x] = unchecked((int)0xFF303030);
|
}
|
||||||
|
|
||||||
|
var golden = new GoldenCase(name, frames, Convert.ToHexString(hash.GetHashAndReset()));
|
||||||
|
cases.Add(golden);
|
||||||
|
report?.Invoke(golden, files, rendered);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cases;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int CountDuplicates(IReadOnlyList<GoldenCase> cases)
|
||||||
|
{
|
||||||
|
var duplicates = 0;
|
||||||
|
var seen = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||||
|
foreach (var (name, _, hash) in cases)
|
||||||
|
{
|
||||||
|
if (seen.TryGetValue(hash, out var first))
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"{name}: {first} と出力が一致します。設定がシェーダーへ届いていません。");
|
||||||
|
duplicates++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
seen.Add(hash, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pixels;
|
|
||||||
|
return duplicates;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CountLit(int[] pixels)
|
static int CountOpaque(byte[] pixels)
|
||||||
{
|
{
|
||||||
var count = 0;
|
var count = 0;
|
||||||
foreach (var pixel in pixels)
|
for (var offset = HarnessImage.BytesPerPixel - 1; offset < pixels.Length; offset += HarnessImage.BytesPerPixel)
|
||||||
{
|
{
|
||||||
if (((pixel >> 24) & 255) > 8)
|
if (pixels[offset] != 0)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int[] Composite(int[] source, int[] ink)
|
|
||||||
{
|
|
||||||
var result = new int[source.Length];
|
|
||||||
for (var index = 0; index < source.Length; index++)
|
|
||||||
{
|
|
||||||
var s = source[index];
|
|
||||||
var i = ink[index];
|
|
||||||
var sa = (s >> 24) & 255;
|
|
||||||
var ia = (i >> 24) & 255;
|
|
||||||
var a = Math.Min(ia + sa * (255 - ia) / 255, 255);
|
|
||||||
var r = Over((s >> 16) & 255, (i >> 16) & 255, ia);
|
|
||||||
var g = Over((s >> 8) & 255, (i >> 8) & 255, ia);
|
|
||||||
var b = Over(s & 255, i & 255, ia);
|
|
||||||
result[index] = 255 << 24 | OverWhite(r, a) << 16 | OverWhite(g, a) << 8 | OverWhite(b, a);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
|
|
||||||
static int Over(int s, int i, int ia) => Math.Min(i + s * (255 - ia) / 255, 255);
|
|
||||||
|
|
||||||
static int OverWhite(int c, int a) => Math.Min(c + 255 - a, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void WriteBmp(string path, int[] pixels, int width, int height)
|
|
||||||
{
|
|
||||||
var stride = width * 3;
|
|
||||||
var padding = (4 - stride % 4) % 4;
|
|
||||||
var dataSize = (stride + padding) * height;
|
|
||||||
using var stream = new FileStream(path, FileMode.Create, FileAccess.Write);
|
|
||||||
using var writer = new BinaryWriter(stream);
|
|
||||||
writer.Write((byte)'B');
|
|
||||||
writer.Write((byte)'M');
|
|
||||||
writer.Write(54 + dataSize);
|
|
||||||
writer.Write(0);
|
|
||||||
writer.Write(54);
|
|
||||||
writer.Write(40);
|
|
||||||
writer.Write(width);
|
|
||||||
writer.Write(height);
|
|
||||||
writer.Write((short)1);
|
|
||||||
writer.Write((short)24);
|
|
||||||
writer.Write(0);
|
|
||||||
writer.Write(dataSize);
|
|
||||||
writer.Write(2835);
|
|
||||||
writer.Write(2835);
|
|
||||||
writer.Write(0);
|
|
||||||
writer.Write(0);
|
|
||||||
var pad = new byte[padding];
|
|
||||||
for (var y = height - 1; y >= 0; y--)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
var pixel = pixels[y * width + x];
|
|
||||||
writer.Write((byte)(pixel & 255));
|
|
||||||
writer.Write((byte)((pixel >> 8) & 255));
|
|
||||||
writer.Write((byte)((pixel >> 16) & 255));
|
|
||||||
}
|
|
||||||
writer.Write(pad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
namespace InkDispersion.Harness;
|
||||||
|
|
||||||
|
internal static class SyntheticImage
|
||||||
|
{
|
||||||
|
const int GridPitch = 32;
|
||||||
|
|
||||||
|
public static byte[] Create(int width, int height)
|
||||||
|
{
|
||||||
|
var pixels = new byte[width * height * HarnessImage.BytesPerPixel];
|
||||||
|
var plateLeft = width * 0.10f;
|
||||||
|
var plateRight = width * 0.56f;
|
||||||
|
var plateTop = height * 0.14f;
|
||||||
|
var plateBottom = height * 0.86f;
|
||||||
|
var discCenterX = width * 0.70f;
|
||||||
|
var discCenterY = height * 0.50f;
|
||||||
|
var discRadius = MathF.Min(width, height) * 0.28f;
|
||||||
|
|
||||||
|
for (var y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
for (var x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
var positionX = x + 0.5f;
|
||||||
|
var positionY = y + 0.5f;
|
||||||
|
var plateInset = MathF.Min(MathF.Min(positionX - plateLeft, plateRight - positionX), MathF.Min(positionY - plateTop, plateBottom - positionY));
|
||||||
|
var plateCoverage = Math.Clamp(plateInset + 0.5f, 0f, 1f);
|
||||||
|
var distance = MathF.Sqrt((positionX - discCenterX) * (positionX - discCenterX) + (positionY - discCenterY) * (positionY - discCenterY));
|
||||||
|
var discCoverage = Math.Clamp(discRadius - distance + 0.5f, 0f, 1f);
|
||||||
|
if (plateCoverage == 0f && discCoverage == 0f)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var onGrid = x % GridPitch == 0 || y % GridPitch == 0;
|
||||||
|
var plateWeight = plateCoverage * (1f - discCoverage);
|
||||||
|
var shade = 1f - distance / discRadius * 0.5f;
|
||||||
|
var red = (onGrid ? 0.25f : 0.82f) * plateWeight + 0.90f * shade * discCoverage;
|
||||||
|
var green = (onGrid ? 0.30f : 0.86f) * plateWeight + 0.45f * shade * discCoverage;
|
||||||
|
var blue = (onGrid ? 0.40f : 0.90f) * plateWeight + 0.30f * shade * discCoverage;
|
||||||
|
var alpha = plateWeight + discCoverage;
|
||||||
|
|
||||||
|
var offset = (y * width + x) * HarnessImage.BytesPerPixel;
|
||||||
|
pixels[offset] = ToByte(blue);
|
||||||
|
pixels[offset + 1] = ToByte(green);
|
||||||
|
pixels[offset + 2] = ToByte(red);
|
||||||
|
pixels[offset + 3] = ToByte(alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte ToByte(float premultiplied) => (byte)MathF.Round(Math.Clamp(premultiplied, 0f, 1f) * byte.MaxValue);
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
{
|
||||||
|
"adapter": "Intel(R) Iris(R) Xe Graphics",
|
||||||
|
"driver": "32.0.101.7085",
|
||||||
|
"input": "synthetic 640x480 89838D8976198E40",
|
||||||
|
"canvas": "1280x720",
|
||||||
|
"cases": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "113DFDEA266926477973E98AE6206E6E298E742156AA4C6D1A8081FC99165B0F"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "default-frames-0-8",
|
||||||
|
"frames": [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
8
|
||||||
|
],
|
||||||
|
"hash": "4653381D89BBF5C2D9F29E1FAEB2822DAF4A44531FB86D41A652D4A7D58A2DDA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "amount-0",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "0A700F76CEDDBAD7C4B6A2C19D46939C1A93940E86C6EFEF1E5A53DB48D2A020"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "spread-35",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "2044C449FFA2EF1710F87E316F67A84FF0C65A4D702C361F616BE54DB1CB0D14"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "quality-balanced",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "E92F4034561AC95343AD3219F3A3136BB4EC837B2821E7BEBB0F01041426D614"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "quality-ultra",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "A2EF7866CAF0DE8DD6956B87DA0201CA09B5756D6E86589A4A0A4987329BE99B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "water-0",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "6EEE4F9E922BE90793EBAC22294CE3D4FD93AD558B7F4871A0C4AF19B7E8052C"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "water-100",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "DBC385C9E9D360CD7389F8BF246029B3755BC45D6C096DD13F1FD93AEBF08048"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "reach-5",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "4BBE0349A16CE6900E0FE6A7C377DDD067ACE06EC874F7DBA29E82DD4D8D70A2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "reach-100",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "35E77F455F45CC4D77E29E28C57E961632817D6D091C626B6F3D10FD9AA00CBB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "fiber-0",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "04A35B75273746A7D5C75FD95C54D0AC7BA22E218FD204D2C8C0B1B04ABC6F16"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "fiber-100",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "6E6A13A2375BD6921BCEB73E1645F01F264415D9F93C624E2FCEFF09313EE765"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "sizing-0",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "C6C5845EE3137EFF91466779BEC27BD99A20D67AD9AF0A51F13E5A396B78A2E7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "sizing-100",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "596DE879C4F54E499A66BBFA297F3E6E4606B3D41EE217BB3E06181B131D5F54"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "viscosity-0",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "3F2C41AA4D05FF0705CB6A4BE8319720A8C2B5D14AA3E6E08A15FD1D6EFA1706"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "viscosity-100",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "6E6A03CA3974EAFB62F13733A0E0FB32EA5DC1F66F46F6EC9D81B1E4366FEA08"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "drying-0",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "85E2D827928F912387FD99F1E823A9D7BC818165F2AD584EE92AD892F30C4616"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "drying-100",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "693FB39C5E31205DA071B5A25A727DD0D9E43F3B7FEE0C8F9675A2E279639F60"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "density-20",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "3A9AD2B483E1FEC9CE17F89DB4A644A861303F40F2156A0DD53C1D1B3D81ED0B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "density-100",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "1062F6A23B59C4BD299A8A1D2DFDE67A7DF408DA253539852E8CD6DE4B6325E6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "grain-0",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "8A28925D962C7E78663F013D0C762B55FE2F1814726C38F5256E5BA4B4943F8A"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "grain-100",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "BEC09BDABBFA8BAA56724AC155B08B27216C570D88F5C17C56EB0461F09AEBC7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "seed-42",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "EBC1618FEA6112B2A7A90F770495E920773D1685D048B336460C573870DD0DE0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ink-color",
|
||||||
|
"frames": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"hash": "7F958DC79DC050C1A41B763BF3E6BC8E93126948F95AD864D685F2A9D472EF0C"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{F984A222-27F6-43B5-9156-BC62484E3AD3}</ProjectGuid>
|
||||||
|
<RootNamespace>InkDispersionShader</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v145</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v145</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v145</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v145</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutDir>$(MSBuildThisFileDirectory)..\Release\</OutDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
<FxCompile>
|
||||||
|
<ShaderModel>4.1</ShaderModel>
|
||||||
|
</FxCompile>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
<FxCompile>
|
||||||
|
<ShaderModel>4.1</ShaderModel>
|
||||||
|
<CompileD2DCustomEffect>
|
||||||
|
</CompileD2DCustomEffect>
|
||||||
|
</FxCompile>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
<FxCompile>
|
||||||
|
<ShaderModel>4.1</ShaderModel>
|
||||||
|
</FxCompile>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
<FxCompile>
|
||||||
|
<ShaderModel>4.1</ShaderModel>
|
||||||
|
</FxCompile>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<FxCompile Include="InkDispersion.hlsl">
|
||||||
|
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||||
|
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
|
||||||
|
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
|
||||||
|
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
|
||||||
|
</FxCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="ソース ファイル">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="ヘッダー ファイル">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="リソース ファイル">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<FxCompile Include="InkDispersion.hlsl">
|
||||||
|
<Filter>ソース ファイル</Filter>
|
||||||
|
</FxCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
差分なしでファイル名を変更。
@@ -0,0 +1,12 @@
|
|||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
internal readonly record struct Bgra(byte Blue, byte Green, byte Red, byte Alpha)
|
||||||
|
{
|
||||||
|
public static Bgra Transparent => default;
|
||||||
|
|
||||||
|
public static Bgra Opaque(byte blue, byte green, byte red) => new(blue, green, red, byte.MaxValue);
|
||||||
|
|
||||||
|
public Bgra Premultiplied() => new(Premultiply(Blue), Premultiply(Green), Premultiply(Red), Alpha);
|
||||||
|
|
||||||
|
byte Premultiply(byte value) => (byte)Math.Round(value * (double)Alpha / byte.MaxValue, MidpointRounding.AwayFromZero);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using System.Numerics;
|
||||||
|
using Vortice.Direct2D1;
|
||||||
|
using YukkuriMovieMaker.Player.Video;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
internal static class EffectDescriptions
|
||||||
|
{
|
||||||
|
public const int Fps = 30;
|
||||||
|
|
||||||
|
static readonly Size ScreenSize = new(1920, 1080);
|
||||||
|
|
||||||
|
public static EffectDescription At(int frame, int length)
|
||||||
|
{
|
||||||
|
var timeline = new TimelineSourceDescription(
|
||||||
|
ScreenSize,
|
||||||
|
new FrameTime(frame, Fps),
|
||||||
|
new FrameTime(length, Fps),
|
||||||
|
Fps,
|
||||||
|
TimelineSourceUsage.Playing,
|
||||||
|
Guid.Empty,
|
||||||
|
[]);
|
||||||
|
var item = new TimelineItemSourceDescription(timeline, frame, length, 0);
|
||||||
|
var draw = new DrawDescription(Vector3.Zero, Vector2.Zero, Vector2.One, Vector3.Zero, Matrix4x4.Identity, InterpolationMode.Linear, 1d, false, []);
|
||||||
|
return new EffectDescription(item, draw, 0, 1, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
internal static class HostAssemblyResolver
|
||||||
|
{
|
||||||
|
const string MetadataKey = "HostDirectory";
|
||||||
|
const string AssemblyExtension = ".dll";
|
||||||
|
|
||||||
|
public static string Directory { get; } = ReadDirectory();
|
||||||
|
|
||||||
|
public static bool IsConfigured => Directory.Length != 0 && System.IO.Directory.Exists(Directory);
|
||||||
|
|
||||||
|
[ModuleInitializer]
|
||||||
|
internal static void Initialize()
|
||||||
|
{
|
||||||
|
if (!IsConfigured)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.AssemblyResolve += (_, arguments) =>
|
||||||
|
{
|
||||||
|
var name = new AssemblyName(arguments.Name).Name;
|
||||||
|
if (name is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var candidate = Path.Combine(Directory, name + AssemblyExtension);
|
||||||
|
return File.Exists(candidate) ? Assembly.LoadFrom(candidate) : null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static string ReadDirectory() => typeof(HostAssemblyResolver).Assembly
|
||||||
|
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||||
|
.FirstOrDefault(attribute => string.Equals(attribute.Key, MetadataKey, StringComparison.Ordinal))
|
||||||
|
?.Value ?? string.Empty;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using Telemetry;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
public sealed class HostIntegrationTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void OutsideAWpfApplicationNoTelemetryIsStartedOrSent()
|
||||||
|
{
|
||||||
|
Assert.Null(Application.Current);
|
||||||
|
|
||||||
|
InkDispersionTelemetry.EnsureStartedOnce();
|
||||||
|
InkDispersionTelemetry.Report(new InvalidOperationException());
|
||||||
|
|
||||||
|
Assert.Null(ProcessState.Read("DrainClaimed"));
|
||||||
|
Assert.Null(ProcessState.Read("SentCount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OutsideAWpfApplicationTheEffectCanStillBeCreated()
|
||||||
|
{
|
||||||
|
Assert.Null(Application.Current);
|
||||||
|
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
|
||||||
|
Assert.Equal(Texts.InkDispersion, effect.Label);
|
||||||
|
Assert.Null(ProcessState.Read("DrainClaimed"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
@@ -12,50 +13,67 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="xunit.v3" Version="4.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\InkDispersion\InkDispersion.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=x64">
|
<ProjectReference Include="..\InkDispersion\InkDispersion.csproj" SetConfiguration="Configuration=$(Configuration)">
|
||||||
<AdditionalProperties Condition="'$(BuildingSolutionFile)' != 'true'">SkipPluginDeploy=true</AdditionalProperties>
|
<AdditionalProperties Condition="'$(BuildingSolutionFile)' != 'true'">SkipPluginDeploy=true</AdditionalProperties>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<AssemblyMetadata Include="HostDirectory" Value="$(YMM4DirPath)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Newtonsoft.Json">
|
||||||
|
<HintPath>$(YMM4DirPath)Newtonsoft.Json.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="SharpGen.Runtime">
|
<Reference Include="SharpGen.Runtime">
|
||||||
<HintPath>$(YMM4DirPath)SharpGen.Runtime.dll</HintPath>
|
<HintPath>$(YMM4DirPath)SharpGen.Runtime.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="SharpGen.Runtime.COM">
|
<Reference Include="SharpGen.Runtime.COM">
|
||||||
<HintPath>$(YMM4DirPath)SharpGen.Runtime.COM.dll</HintPath>
|
<HintPath>$(YMM4DirPath)SharpGen.Runtime.COM.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Vortice.Direct2D1">
|
<Reference Include="Vortice.Direct2D1">
|
||||||
<HintPath>$(YMM4DirPath)Vortice.Direct2D1.dll</HintPath>
|
<HintPath>$(YMM4DirPath)Vortice.Direct2D1.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Vortice.Direct3D11">
|
<Reference Include="Vortice.Direct3D11">
|
||||||
<HintPath>$(YMM4DirPath)Vortice.Direct3D11.dll</HintPath>
|
<HintPath>$(YMM4DirPath)Vortice.Direct3D11.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Vortice.DirectX">
|
<Reference Include="Vortice.DirectX">
|
||||||
<HintPath>$(YMM4DirPath)Vortice.DirectX.dll</HintPath>
|
<HintPath>$(YMM4DirPath)Vortice.DirectX.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Vortice.DXGI">
|
<Reference Include="Vortice.DXGI">
|
||||||
<HintPath>$(YMM4DirPath)Vortice.DXGI.dll</HintPath>
|
<HintPath>$(YMM4DirPath)Vortice.DXGI.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Vortice.Mathematics">
|
<Reference Include="Vortice.Mathematics">
|
||||||
<HintPath>$(YMM4DirPath)Vortice.Mathematics.dll</HintPath>
|
<HintPath>$(YMM4DirPath)Vortice.Mathematics.dll</HintPath>
|
||||||
</Reference>
|
<Private>false</Private>
|
||||||
<Reference Include="YukkuriMovieMaker.Plugin">
|
|
||||||
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Plugin.dll</HintPath>
|
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="YukkuriMovieMaker.Controls">
|
<Reference Include="YukkuriMovieMaker.Controls">
|
||||||
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Controls.dll</HintPath>
|
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Controls.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="YukkuriMovieMaker.Plugin">
|
||||||
|
<HintPath>$(YMM4DirPath)YukkuriMovieMaker.Plugin.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@@ -63,6 +81,4 @@
|
|||||||
<Using Include="Xunit" />
|
<Using Include="Xunit" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project="..\InkDispersion\ComputeSharp.Reference.props" />
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
using System.Numerics;
|
||||||
|
using Vortice.Direct2D1;
|
||||||
|
using Vortice.Direct2D1.Effects;
|
||||||
|
using YukkuriMovieMaker.Commons;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
[Collection("Direct2D")]
|
||||||
|
public sealed class InkDispersionCustomEffectTests
|
||||||
|
{
|
||||||
|
const int AmountIndex = 0;
|
||||||
|
const int Width = 40;
|
||||||
|
const int Height = 24;
|
||||||
|
|
||||||
|
static readonly Bgra Blue = Bgra.Opaque(255, 0, 0);
|
||||||
|
static readonly Bgra HalfInk = new(0, 0, 0, 128);
|
||||||
|
|
||||||
|
static Rendering Render(IGraphicsDevicesAndContext devices, ID2D1Image source, ID2D1Image ink, float amount)
|
||||||
|
{
|
||||||
|
using var effect = new InkDispersionCustomEffect(devices);
|
||||||
|
effect.SetInput(0, source, true);
|
||||||
|
effect.SetInput(1, ink, true);
|
||||||
|
effect.Amount = amount;
|
||||||
|
using var output = effect.Output;
|
||||||
|
return Rendering.Capture(devices, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
static AffineTransform2D Translate(IGraphicsDevicesAndContext devices, ID2D1Image image, float dx, float dy)
|
||||||
|
{
|
||||||
|
var transform = new AffineTransform2D(devices.DeviceContext)
|
||||||
|
{
|
||||||
|
InterPolationMode = AffineTransform2DInterpolationMode.NearestNeighbor,
|
||||||
|
BorderMode = BorderMode.Hard,
|
||||||
|
TransformMatrix = Matrix3x2.CreateTranslation(dx, dy),
|
||||||
|
};
|
||||||
|
transform.SetInput(0, image, true);
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool WithinRounding(Bgra expected, Bgra actual)
|
||||||
|
=> Math.Abs(expected.Blue - actual.Blue) <= 1 && Math.Abs(expected.Green - actual.Green) <= 1 && Math.Abs(expected.Red - actual.Red) <= 1 && Math.Abs(expected.Alpha - actual.Alpha) <= 1;
|
||||||
|
|
||||||
|
static Bgra Over(Bgra ink, Bgra source, float amount)
|
||||||
|
{
|
||||||
|
var inkAlpha = ink.Alpha * amount;
|
||||||
|
var keep = 1d - inkAlpha / byte.MaxValue;
|
||||||
|
byte Channel(byte inkValue, byte sourceValue) => (byte)Math.Round(inkValue * amount + sourceValue * keep, MidpointRounding.AwayFromZero);
|
||||||
|
return new Bgra(Channel(ink.Blue, source.Blue), Channel(ink.Green, source.Green), Channel(ink.Red, source.Red), Channel(ink.Alpha, source.Alpha));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheEffectIsEnabledOnceCreated()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var effect = new InkDispersionCustomEffect(context);
|
||||||
|
|
||||||
|
Assert.True(effect.IsEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheAmountStartsFromZero()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var effect = new InkDispersionCustomEffect(context);
|
||||||
|
|
||||||
|
Assert.Equal(0f, effect.GetFloatValue(AmountIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(-0.5f, 0f)]
|
||||||
|
[InlineData(0f, 0f)]
|
||||||
|
[InlineData(0.4f, 0.4f)]
|
||||||
|
[InlineData(1f, 1f)]
|
||||||
|
[InlineData(1.5f, 1f)]
|
||||||
|
[InlineData(float.MaxValue, 1f)]
|
||||||
|
public void TheAmountIsClampedToTheUnitRange(float value, float expected)
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var effect = new InkDispersionCustomEffect(context);
|
||||||
|
|
||||||
|
effect.Amount = value;
|
||||||
|
|
||||||
|
Assert.Equal(expected, effect.GetFloatValue(AmountIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheOutputBoundsCoverTheSourceAndTheInk()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var source = SourceImage.Solid(context, Width, Height, Blue);
|
||||||
|
using var ink = SourceImage.Solid(context, 8, 8, HalfInk);
|
||||||
|
using var moved = Translate(context, ink.Bitmap, 50f, -6f);
|
||||||
|
using var movedOutput = moved.Output;
|
||||||
|
using var effect = new InkDispersionCustomEffect(context);
|
||||||
|
effect.SetInput(0, source.Bitmap, true);
|
||||||
|
effect.SetInput(1, movedOutput, true);
|
||||||
|
using var output = effect.Output;
|
||||||
|
|
||||||
|
var bounds = context.DeviceContext.GetImageLocalBounds(output);
|
||||||
|
|
||||||
|
Assert.Equal(0f, bounds.Left);
|
||||||
|
Assert.Equal(-6f, bounds.Top);
|
||||||
|
Assert.Equal(58f, bounds.Right);
|
||||||
|
Assert.Equal((float)Height, bounds.Bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0f)]
|
||||||
|
[InlineData(-1f)]
|
||||||
|
public void WithoutAmountTheSourcePassesThroughUntouched(float amount)
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var source = SourceImage.Solid(context, Width, Height, Blue);
|
||||||
|
using var ink = SourceImage.Solid(context, Width, Height, HalfInk);
|
||||||
|
|
||||||
|
var rendering = Render(context, source.Bitmap, ink.Bitmap, amount);
|
||||||
|
|
||||||
|
Assert.All(rendering.Coordinates(), point => Assert.Equal(source[point.X, point.Y], rendering[point.X, point.Y]));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1f)]
|
||||||
|
[InlineData(0.5f)]
|
||||||
|
[InlineData(0.25f)]
|
||||||
|
public void TheInkIsLaidOverTheSourceScaledByTheAmount(float amount)
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var source = SourceImage.Solid(context, Width, Height, Blue);
|
||||||
|
using var ink = SourceImage.Solid(context, Width, Height, HalfInk);
|
||||||
|
var expected = Over(HalfInk.Premultiplied(), Blue.Premultiplied(), amount);
|
||||||
|
|
||||||
|
var rendering = Render(context, source.Bitmap, ink.Bitmap, amount);
|
||||||
|
|
||||||
|
Assert.All(rendering.Coordinates(), point => Assert.True(WithinRounding(expected, rendering[point.X, point.Y]), $"({point.X}, {point.Y}) {rendering[point.X, point.Y]}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InkOutsideTheSourceIsDrawnOnItsOwn()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var source = SourceImage.Solid(context, Width, Height, Blue);
|
||||||
|
using var ink = SourceImage.Solid(context, 8, 8, HalfInk);
|
||||||
|
using var moved = Translate(context, ink.Bitmap, 50f, 4f);
|
||||||
|
using var movedOutput = moved.Output;
|
||||||
|
var expected = Over(HalfInk.Premultiplied(), Bgra.Transparent, 1f);
|
||||||
|
|
||||||
|
var rendering = Render(context, source.Bitmap, movedOutput, 1f);
|
||||||
|
|
||||||
|
Assert.True(WithinRounding(expected, rendering[53, 7]), $"{rendering[53, 7]}");
|
||||||
|
Assert.Equal(Blue.Premultiplied(), rendering[10, 10]);
|
||||||
|
Assert.Equal(Bgra.Transparent, rendering[45, 10]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,394 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Numerics;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using ComputeWeave;
|
||||||
|
using Vortice.Direct2D1;
|
||||||
|
using Vortice.Direct2D1.Effects;
|
||||||
|
using YukkuriMovieMaker.Commons;
|
||||||
|
using YukkuriMovieMaker.Json;
|
||||||
|
using YukkuriMovieMaker.Player.Video;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
[Collection("Direct2D")]
|
||||||
|
public sealed class InkDispersionEffectProcessorTests
|
||||||
|
{
|
||||||
|
const int Size = 64;
|
||||||
|
const int Length = 30;
|
||||||
|
|
||||||
|
static readonly Bgra Gray = Bgra.Opaque(192, 192, 192);
|
||||||
|
|
||||||
|
static Bgra CenteredSquare(int x, int y) => x is >= 16 and < 48 && y is >= 16 and < 48 ? Gray : Bgra.Transparent;
|
||||||
|
|
||||||
|
static void RequireInterop(IGraphicsDevicesAndContext devices)
|
||||||
|
{
|
||||||
|
using var scheduler = ComputeExternalQueueScheduler.Create();
|
||||||
|
using var provider = InkDispersionInteropProvider.TryCreate(devices, scheduler, out var device);
|
||||||
|
if (provider is null || device is null)
|
||||||
|
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
static Animation Linear(double from, double to)
|
||||||
|
=> Json.LoadFromText<Animation>(string.Create(CultureInfo.InvariantCulture, $$"""{"AnimationType":"直線移動","Values":[{"Value":{{from}}},{"Value":{{to}}}]}"""))!;
|
||||||
|
|
||||||
|
static Rendering RenderFrame(IGraphicsDevicesAndContext devices, IVideoEffectProcessor processor, int frame)
|
||||||
|
{
|
||||||
|
processor.Update(EffectDescriptions.At(frame, Length));
|
||||||
|
return Rendering.Capture(devices, processor.Output);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AssertSameAsSource(Rendering rendering, SourceImage source)
|
||||||
|
{
|
||||||
|
Assert.Equal((0, 0, source.Width, source.Height), (rendering.Left, rendering.Top, rendering.Width, rendering.Height));
|
||||||
|
Assert.All(rendering.Coordinates(), point => Assert.Equal(source[point.X, point.Y], rendering[point.X, point.Y]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool HasInkOutside(Rendering rendering, SourceImage source)
|
||||||
|
=> rendering.Coordinates().Any(point => (!source.Contains(point.X, point.Y) || source[point.X, point.Y].Alpha == 0) && rendering[point.X, point.Y].Alpha > 0);
|
||||||
|
|
||||||
|
static bool Tinted(byte channel, byte alpha, byte color) => Math.Abs(channel - color * alpha / 255d) <= 2d;
|
||||||
|
|
||||||
|
static double DistanceFrom(SourceImage source, int x, int y)
|
||||||
|
{
|
||||||
|
var dx = Math.Max(Math.Max(-x, x - (source.Width - 1)), 0);
|
||||||
|
var dy = Math.Max(Math.Max(-y, y - (source.Height - 1)), 0);
|
||||||
|
return Math.Sqrt(dx * dx + dy * dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheProcessorHandsTheDrawDescriptionBackUnchanged()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
var description = EffectDescriptions.At(0, Length);
|
||||||
|
|
||||||
|
var draw = processor.Update(description);
|
||||||
|
|
||||||
|
Assert.Same(description.DrawDescription, draw);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheInkSpreadsOutOfTheSource()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var rendering = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
Assert.True(HasInkOutside(rendering, source));
|
||||||
|
Assert.All(rendering.Coordinates(), point =>
|
||||||
|
{
|
||||||
|
var pixel = rendering[point.X, point.Y];
|
||||||
|
Assert.InRange(pixel.Blue, 0, pixel.Alpha);
|
||||||
|
Assert.InRange(pixel.Green, 0, pixel.Alpha);
|
||||||
|
Assert.InRange(pixel.Red, 0, pixel.Alpha);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheInkTakesTheChosenColor()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
using var processor = new InkDispersionEffect { InkColor = Color.FromRgb(32, 96, 160) }.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var rendering = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
Assert.True(HasInkOutside(rendering, source));
|
||||||
|
Assert.All(rendering.Coordinates().Where(point => !source.Contains(point.X, point.Y) || source[point.X, point.Y].Alpha == 0), point =>
|
||||||
|
{
|
||||||
|
var pixel = rendering[point.X, point.Y];
|
||||||
|
Assert.True(Tinted(pixel.Red, pixel.Alpha, 32) && Tinted(pixel.Green, pixel.Alpha, 96) && Tinted(pixel.Blue, pixel.Alpha, 160), $"({point.X}, {point.Y}) {pixel}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(100, 50)]
|
||||||
|
[InlineData(-37, 21)]
|
||||||
|
public void TheInkTravelsWithTheImage(int dx, int dy)
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
using var moved = new AffineTransform2D(context.DeviceContext)
|
||||||
|
{
|
||||||
|
InterPolationMode = AffineTransform2DInterpolationMode.NearestNeighbor,
|
||||||
|
BorderMode = BorderMode.Hard,
|
||||||
|
TransformMatrix = Matrix3x2.CreateTranslation(dx, dy),
|
||||||
|
};
|
||||||
|
moved.SetInput(0, source.Bitmap, true);
|
||||||
|
using var movedOutput = moved.Output;
|
||||||
|
using var inPlaceProcessor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
inPlaceProcessor.SetInput(source.Bitmap);
|
||||||
|
var inPlace = RenderFrame(context, inPlaceProcessor, 0);
|
||||||
|
using var travelledProcessor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
travelledProcessor.SetInput(movedOutput);
|
||||||
|
|
||||||
|
var travelled = RenderFrame(context, travelledProcessor, 0);
|
||||||
|
|
||||||
|
Assert.Equal((inPlace.Left + dx, inPlace.Top + dy, inPlace.Width, inPlace.Height), (travelled.Left, travelled.Top, travelled.Width, travelled.Height));
|
||||||
|
Assert.All(inPlace.Coordinates(), point => Assert.True(inPlace[point.X, point.Y] == travelled[point.X + dx, point.Y + dy], $"({point.X}, {point.Y})"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheReachIsMeasuredAgainstTheLongSideOfTheImage()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = SourceImage.Solid(context, 96, 24, Gray);
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
effect.Water.Values[0].Value = 100d;
|
||||||
|
effect.Reach.Values[0].Value = 25d;
|
||||||
|
using var processor = effect.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var rendering = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
var distances = rendering.Coordinates()
|
||||||
|
.Where(point => !source.Contains(point.X, point.Y) && rendering[point.X, point.Y].Alpha > 0)
|
||||||
|
.Select(point => DistanceFrom(source, point.X, point.Y))
|
||||||
|
.ToArray();
|
||||||
|
Assert.Contains(distances, distance => distance > 12d);
|
||||||
|
Assert.All(distances, distance => Assert.True(distance <= 30d, $"{distance}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly TheoryData<string, Action<InkDispersionEffect>> PassThroughSettings = new()
|
||||||
|
{
|
||||||
|
{ nameof(InkDispersionEffect.Amount), effect => effect.Amount.Values[0].Value = 0d },
|
||||||
|
{ nameof(InkDispersionEffect.Spread), effect => effect.Spread.Values[0].Value = 0d },
|
||||||
|
};
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(PassThroughSettings))]
|
||||||
|
public void AZeroAmountOrSpreadPassesTheImageThrough(string setting, Action<InkDispersionEffect> configure)
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
configure(effect);
|
||||||
|
using var processor = effect.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var rendering = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
Assert.Equal((0, 0, Size, Size), (rendering.Left, rendering.Top, rendering.Width, rendering.Height));
|
||||||
|
Assert.All(rendering.Coordinates(), point => Assert.True(source[point.X, point.Y] == rendering[point.X, point.Y], $"{setting} ({point.X}, {point.Y})"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AnImageThatLeavesNoRoomForTheInkPassesThroughUntouched()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var source = SourceImage.Solid(context, InkDispersionSettings.MaximumCanvasSize - 16, 8, Gray);
|
||||||
|
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var rendering = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
AssertSameAsSource(rendering, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ReturningToAFrameReproducesItExactly()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var first = RenderFrame(context, processor, 4);
|
||||||
|
RenderFrame(context, processor, 9);
|
||||||
|
var again = RenderFrame(context, processor, 4);
|
||||||
|
|
||||||
|
Assert.True(first.SamePixelsAs(again));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ANewProcessorDrawsTheSameInk()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
var effect = new InkDispersionEffect { Seed = 9 };
|
||||||
|
using var firstProcessor = effect.CreateVideoEffect(context);
|
||||||
|
firstProcessor.SetInput(source.Bitmap);
|
||||||
|
var first = RenderFrame(context, firstProcessor, 0);
|
||||||
|
using var secondProcessor = effect.CreateVideoEffect(context);
|
||||||
|
secondProcessor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var second = RenderFrame(context, secondProcessor, 0);
|
||||||
|
|
||||||
|
Assert.True(first.SamePixelsAs(second));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AnimatedSpreadIsReadAtEachFrame()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
effect.Spread.CopyFrom(Linear(0d, 100d));
|
||||||
|
using var processor = effect.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var start = RenderFrame(context, processor, 0);
|
||||||
|
var end = RenderFrame(context, processor, Length - 1);
|
||||||
|
|
||||||
|
AssertSameAsSource(start, source);
|
||||||
|
Assert.True(HasInkOutside(end, source));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(100d, 30d)]
|
||||||
|
[InlineData(30d, 100d)]
|
||||||
|
public void AProcessorThatDrewAnotherSpreadDrawsLikeAFreshOne(double firstSpread, double secondSpread)
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
effect.Spread.Values[0].Value = firstSpread;
|
||||||
|
using var processor = effect.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
RenderFrame(context, processor, 0);
|
||||||
|
effect.Spread.Values[0].Value = secondSpread;
|
||||||
|
using var fresh = effect.CreateVideoEffect(context);
|
||||||
|
fresh.SetInput(source.Bitmap);
|
||||||
|
var expected = RenderFrame(context, fresh, 0);
|
||||||
|
|
||||||
|
var reused = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
Assert.True(reused.SamePixelsAs(expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly TheoryData<string, Action<InkDispersionEffect>> LaterChanges = new()
|
||||||
|
{
|
||||||
|
{ nameof(InkDispersionEffect.Amount), effect => effect.Amount.Values[0].Value = 50d },
|
||||||
|
{ nameof(InkDispersionEffect.Spread), effect => effect.Spread.Values[0].Value = 30d },
|
||||||
|
{ nameof(InkDispersionEffect.Quality), effect => effect.Quality = InkDispersionQuality.Balanced },
|
||||||
|
{ nameof(InkDispersionEffect.Water), effect => effect.Water.Values[0].Value = 100d },
|
||||||
|
{ nameof(InkDispersionEffect.Reach), effect => effect.Reach.Values[0].Value = 10d },
|
||||||
|
{ nameof(InkDispersionEffect.Fiber), effect => effect.Fiber.Values[0].Value = 100d },
|
||||||
|
{ nameof(InkDispersionEffect.Sizing), effect => effect.Sizing.Values[0].Value = 100d },
|
||||||
|
{ nameof(InkDispersionEffect.Viscosity), effect => effect.Viscosity.Values[0].Value = 100d },
|
||||||
|
{ nameof(InkDispersionEffect.Drying), effect => effect.Drying.Values[0].Value = 100d },
|
||||||
|
{ nameof(InkDispersionEffect.Seed), effect => effect.Seed = 1 },
|
||||||
|
{ nameof(InkDispersionEffect.Density), effect => effect.Density.Values[0].Value = 20d },
|
||||||
|
{ nameof(InkDispersionEffect.Grain), effect => effect.Grain.Values[0].Value = 100d },
|
||||||
|
{ nameof(InkDispersionEffect.InkColor), effect => effect.InkColor = Colors.Crimson },
|
||||||
|
};
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(LaterChanges))]
|
||||||
|
public void EverySettingChangedAfterTheFirstFrameReachesTheEffect(string setting, Action<InkDispersionEffect> change)
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
using var processor = effect.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
|
||||||
|
var before = RenderFrame(context, processor, 0);
|
||||||
|
change(effect);
|
||||||
|
var after = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
Assert.False(before.SamePixelsAs(after), setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(32, 128)]
|
||||||
|
[InlineData(128, 32)]
|
||||||
|
public void AResizedSourceKeepsProducingInk(int firstSize, int secondSize)
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var first = new SourceImage(context, firstSize, firstSize, (x, y) => Gray);
|
||||||
|
using var second = new SourceImage(context, secondSize, secondSize, (x, y) => Gray);
|
||||||
|
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
processor.SetInput(first.Bitmap);
|
||||||
|
var before = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
processor.SetInput(second.Bitmap);
|
||||||
|
var after = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
Assert.True(HasInkOutside(before, first));
|
||||||
|
Assert.True(HasInkOutside(after, second));
|
||||||
|
Assert.Equal(secondSize > firstSize, after.Width > before.Width);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InkAppearsOnceATransparentSourceTakesShape()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var empty = SourceImage.Solid(context, Size, Size, Bgra.Transparent);
|
||||||
|
using var source = new SourceImage(context, Size, Size, CenteredSquare);
|
||||||
|
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
processor.SetInput(empty.Bitmap);
|
||||||
|
var before = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
var after = RenderFrame(context, processor, 0);
|
||||||
|
|
||||||
|
Assert.False(HasInkOutside(before, empty));
|
||||||
|
Assert.True(HasInkOutside(after, source));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact(Timeout = 60000)]
|
||||||
|
public async Task AProcessorDrawsLikeAFreshOneAfterTheDeviceReclaimsIdleMemory()
|
||||||
|
{
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
RequireInterop(context);
|
||||||
|
using var source = new SourceImage(context, Size, Size, (x, y) => x is >= 16 and < 48 && y is >= 16 and < 48 ? Bgra.Opaque(80, 200, 255) : Bgra.Transparent);
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
using var processor = effect.CreateVideoEffect(context);
|
||||||
|
processor.SetInput(source.Bitmap);
|
||||||
|
RenderFrame(context, processor, 0);
|
||||||
|
GraphicsDevice.GetDefault().TrimMemory();
|
||||||
|
|
||||||
|
var reclaimed = RenderFrame(context, processor, 0);
|
||||||
|
using var fresh = effect.CreateVideoEffect(context);
|
||||||
|
fresh.SetInput(source.Bitmap);
|
||||||
|
var expected = RenderFrame(context, fresh, 0);
|
||||||
|
|
||||||
|
Assert.True(reclaimed.SamePixelsAs(expected));
|
||||||
|
}, TestContext.Current.CancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AFailureWhileUpdatingIsNotSwallowed()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var processor = new InkDispersionEffect().CreateVideoEffect(context);
|
||||||
|
|
||||||
|
Assert.ThrowsAny<Exception>(() => processor.Update(null!));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,51 +1,58 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.ComponentModel;
|
||||||
using ComputeSharp;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using ComputeSharp.Interop;
|
using System.Reflection;
|
||||||
using Vortice;
|
using System.Windows.Media;
|
||||||
using Vortice.Direct2D1;
|
|
||||||
using Vortice.DXGI;
|
|
||||||
using Vortice.Mathematics;
|
|
||||||
using YukkuriMovieMaker.Commons;
|
using YukkuriMovieMaker.Commons;
|
||||||
using PixelFormat = Vortice.DCommon.PixelFormat;
|
using YukkuriMovieMaker.Controls;
|
||||||
|
using YukkuriMovieMaker.Exo;
|
||||||
|
using YukkuriMovieMaker.Json;
|
||||||
|
using YukkuriMovieMaker.Plugin.Effects;
|
||||||
|
using YukkuriMovieMaker.Project;
|
||||||
|
|
||||||
namespace InkDispersion.Tests;
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
public sealed class InkDispersionEffectTests
|
public sealed class InkDispersionEffectTests
|
||||||
{
|
{
|
||||||
private static double ValueAt(YukkuriMovieMaker.Commons.Animation animation) => animation.GetValue(0, 1, 30);
|
static readonly Color DefaultInkColor = Color.FromArgb(255, 30, 26, 24);
|
||||||
|
|
||||||
private static InkDispersionPipeline.Parameters CreateParameters(
|
static PropertyInfo Property(string name) => typeof(InkDispersionEffect).GetProperty(name)!;
|
||||||
InkDispersionQuality quality = InkDispersionQuality.Balanced,
|
|
||||||
float spread = 1f,
|
|
||||||
float water = 0.6f,
|
|
||||||
float fiber = 0.5f,
|
|
||||||
float sizing = 0.3f,
|
|
||||||
float viscosity = 0.3f,
|
|
||||||
float drying = 0.4f,
|
|
||||||
float reachPixels = 40f,
|
|
||||||
float density = 0.8f,
|
|
||||||
float grain = 0.4f,
|
|
||||||
int seed = 0)
|
|
||||||
=> new(quality, spread, water, fiber, sizing, viscosity, drying, reachPixels, density, grain, 0.12f, 0.1f, 0.09f, seed);
|
|
||||||
|
|
||||||
|
static T Attribute<T>(string property) where T : Attribute => Property(property).GetCustomAttribute<T>()!;
|
||||||
|
|
||||||
|
static Animation[] Animations(InkDispersionEffect effect)
|
||||||
|
=> [effect.Amount, effect.Spread, effect.Water, effect.Reach, effect.Fiber, effect.Sizing, effect.Viscosity, effect.Drying, effect.Density, effect.Grain];
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Amount), 100d, 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Spread), 100d, 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Water), 60d, 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Reach), 25d, 1d, 400d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Fiber), 50d, 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Sizing), 30d, 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Viscosity), 30d, 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Drying), 40d, 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Density), 80d, 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Grain), 40d, 0d, 100d)]
|
||||||
|
public void AnimatedParametersStartFromTheirDefaultsWithinTheirRange(string name, double defaultValue, double minimum, double maximum)
|
||||||
|
{
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
|
||||||
|
var animation = (Animation)Property(name).GetValue(effect)!;
|
||||||
|
|
||||||
|
Assert.Equal(defaultValue, animation.DefaultValue);
|
||||||
|
Assert.Equal(minimum, animation.MinValue);
|
||||||
|
Assert.Equal(maximum, animation.MaxValue);
|
||||||
|
Assert.Equal(defaultValue, animation.GetValue(0, 1, EffectDescriptions.Fps));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DefaultParameterValuesMatchSpecification()
|
public void QualitySeedAndInkColorStartFromTheirDefaults()
|
||||||
{
|
{
|
||||||
var effect = new InkDispersionEffect();
|
var effect = new InkDispersionEffect();
|
||||||
|
|
||||||
Assert.Equal(100d, ValueAt(effect.Amount), 6);
|
|
||||||
Assert.Equal(100d, ValueAt(effect.Spread), 6);
|
|
||||||
Assert.Equal(60d, ValueAt(effect.Water), 6);
|
|
||||||
Assert.Equal(25d, ValueAt(effect.Reach), 6);
|
|
||||||
Assert.Equal(50d, ValueAt(effect.Fiber), 6);
|
|
||||||
Assert.Equal(30d, ValueAt(effect.Sizing), 6);
|
|
||||||
Assert.Equal(30d, ValueAt(effect.Viscosity), 6);
|
|
||||||
Assert.Equal(40d, ValueAt(effect.Drying), 6);
|
|
||||||
Assert.Equal(80d, ValueAt(effect.Density), 6);
|
|
||||||
Assert.Equal(40d, ValueAt(effect.Grain), 6);
|
|
||||||
Assert.Equal(InkDispersionQuality.High, effect.Quality);
|
Assert.Equal(InkDispersionQuality.High, effect.Quality);
|
||||||
Assert.Equal(0, effect.Seed);
|
Assert.Equal(0, effect.Seed);
|
||||||
Assert.Equal(System.Windows.Media.Color.FromArgb(255, 30, 26, 24), effect.InkColor);
|
Assert.Equal(DefaultInkColor, effect.InkColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@@ -53,618 +60,193 @@ public sealed class InkDispersionEffectTests
|
|||||||
[InlineData(-1, 0)]
|
[InlineData(-1, 0)]
|
||||||
[InlineData(0, 0)]
|
[InlineData(0, 0)]
|
||||||
[InlineData(1234, 1234)]
|
[InlineData(1234, 1234)]
|
||||||
public void SeedClampsNegativeInputToZero(int input, int expected)
|
[InlineData(10000, 10000)]
|
||||||
|
[InlineData(int.MaxValue, int.MaxValue)]
|
||||||
|
public void SeedNeverDropsBelowZero(int value, int expected)
|
||||||
{
|
{
|
||||||
var effect = new InkDispersionEffect { Seed = input };
|
var effect = new InkDispersionEffect { Seed = 5 };
|
||||||
|
|
||||||
|
effect.Seed = value;
|
||||||
|
|
||||||
Assert.Equal(expected, effect.Seed);
|
Assert.Equal(expected, effect.Seed);
|
||||||
|
Assert.False(effect.HasErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CreateExoVideoFiltersReturnsEmpty()
|
public void ChangingQualitySeedOrInkColorNotifiesTheEditor()
|
||||||
|
{
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
var changed = new List<string?>();
|
||||||
|
effect.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
|
||||||
|
|
||||||
|
effect.Quality = InkDispersionQuality.Ultra;
|
||||||
|
effect.Seed = 7;
|
||||||
|
effect.InkColor = Colors.Crimson;
|
||||||
|
|
||||||
|
Assert.Equal([nameof(InkDispersionEffect.Quality), nameof(InkDispersionEffect.Seed), nameof(InkDispersionEffect.InkColor)], changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AssigningAnUnchangedOrClampedValueDoesNotNotify()
|
||||||
|
{
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
var changed = new List<string?>();
|
||||||
|
effect.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
|
||||||
|
|
||||||
|
effect.Quality = InkDispersionQuality.High;
|
||||||
|
effect.Seed = 0;
|
||||||
|
effect.Seed = -1;
|
||||||
|
effect.InkColor = DefaultInkColor;
|
||||||
|
|
||||||
|
Assert.Empty(changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheLabelIsTheLocalizedEffectName()
|
||||||
{
|
{
|
||||||
var effect = new InkDispersionEffect();
|
var effect = new InkDispersionEffect();
|
||||||
|
|
||||||
Assert.Empty(effect.CreateExoVideoFilters(0, null!));
|
Assert.Equal(Texts.InkDispersion, effect.Label);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheTenNumericParametersReceiveTheAnimationParameters()
|
||||||
|
{
|
||||||
|
var effect = new InkDispersionEffect();
|
||||||
|
|
||||||
|
effect.SetAnimationParameters(120, EffectDescriptions.Fps);
|
||||||
|
|
||||||
|
Assert.All(Animations(effect), animation => Assert.Equal(120, animation.Length));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(InkDispersionQuality.Balanced, 160, 720)]
|
[InlineData(0)]
|
||||||
[InlineData(InkDispersionQuality.High, 224, 1080)]
|
[InlineData(1)]
|
||||||
[InlineData(InkDispersionQuality.Ultra, 288, 1440)]
|
[InlineData(int.MaxValue)]
|
||||||
public void QualitySettingsMatchSpecification(InkDispersionQuality quality, int resolution, int maxSteps)
|
public void NoExoFilterIsWrittenForAviUtl(int keyFrameIndex)
|
||||||
{
|
{
|
||||||
var settings = InkDispersionSettings.GetQuality(quality);
|
var effect = new InkDispersionEffect();
|
||||||
|
|
||||||
Assert.Equal(resolution, settings.GridResolution);
|
var description = new ExoOutputDescription(new VideoInfo(), string.Empty, new AviUtlDirectories(string.Empty, string.Empty));
|
||||||
Assert.Equal(maxSteps, settings.MaxSteps);
|
|
||||||
|
Assert.Empty(effect.CreateExoVideoFilters(keyFrameIndex, description));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheEffectIsRegisteredForDecorationAndAnimationWithoutAviUtlSupport()
|
||||||
|
{
|
||||||
|
var attribute = typeof(InkDispersionEffect).GetCustomAttribute<VideoEffectAttribute>()!;
|
||||||
|
|
||||||
|
Assert.Equal(nameof(Texts.InkDispersion), attribute.Name);
|
||||||
|
Assert.Equal([VideoEffectCategories.Decoration, VideoEffectCategories.Animation], attribute.Categories);
|
||||||
|
Assert.Equal([nameof(Texts.TagInk), nameof(Texts.TagBlot), nameof(Texts.TagJapanese)], attribute.Keywords);
|
||||||
|
Assert.False(attribute.IsAviUtlSupported);
|
||||||
|
Assert.True(attribute.IsEffectItemSupported);
|
||||||
|
Assert.Equal(typeof(Texts), attribute.ResourceType);
|
||||||
|
Assert.Equal(Texts.InkDispersion, attribute.GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(1920, 1080, 224)]
|
[InlineData(nameof(InkDispersionEffect.Amount), nameof(Texts.BasicGroup), nameof(Texts.Amount), nameof(Texts.AmountDescription), 0)]
|
||||||
[InlineData(1080, 1920, 224)]
|
[InlineData(nameof(InkDispersionEffect.Spread), nameof(Texts.BasicGroup), nameof(Texts.Spread), nameof(Texts.SpreadDescription), 1)]
|
||||||
[InlineData(8, 8, 224)]
|
[InlineData(nameof(InkDispersionEffect.Quality), nameof(Texts.BasicGroup), nameof(Texts.Quality), nameof(Texts.QualityDescription), 2)]
|
||||||
[InlineData(4096, 16, 160)]
|
[InlineData(nameof(InkDispersionEffect.Water), nameof(Texts.FlowGroup), nameof(Texts.Water), nameof(Texts.WaterDescription), 10)]
|
||||||
[InlineData(100, 100, 288)]
|
[InlineData(nameof(InkDispersionEffect.Reach), nameof(Texts.FlowGroup), nameof(Texts.Reach), nameof(Texts.ReachDescription), 11)]
|
||||||
public void GridSizeCoversCanvas(int width, int height, int resolution)
|
[InlineData(nameof(InkDispersionEffect.Fiber), nameof(Texts.FlowGroup), nameof(Texts.Fiber), nameof(Texts.FiberDescription), 12)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Sizing), nameof(Texts.FlowGroup), nameof(Texts.Sizing), nameof(Texts.SizingDescription), 13)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Viscosity), nameof(Texts.FlowGroup), nameof(Texts.Viscosity), nameof(Texts.ViscosityDescription), 14)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Drying), nameof(Texts.FlowGroup), nameof(Texts.Drying), nameof(Texts.DryingDescription), 15)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Seed), nameof(Texts.FlowGroup), nameof(Texts.Seed), nameof(Texts.SeedDescription), 16)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Density), nameof(Texts.AppearanceGroup), nameof(Texts.Density), nameof(Texts.DensityDescription), 20)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Grain), nameof(Texts.AppearanceGroup), nameof(Texts.Grain), nameof(Texts.GrainDescription), 21)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.InkColor), nameof(Texts.AppearanceGroup), nameof(Texts.InkColor), nameof(Texts.InkColorDescription), 22)]
|
||||||
|
public void EveryParameterIsDisplayedInItsGroupInOrder(string property, string group, string name, string description, int order)
|
||||||
{
|
{
|
||||||
var (gridWidth, gridHeight, cellSize) = InkDispersionSettings.GetGridSize(width, height, resolution);
|
var display = Attribute<DisplayAttribute>(property);
|
||||||
|
|
||||||
Assert.True(gridWidth >= InkDispersionSettings.MinimumGridSize);
|
Assert.Equal(group, display.GroupName);
|
||||||
Assert.True(gridHeight >= InkDispersionSettings.MinimumGridSize);
|
Assert.Equal(name, display.Name);
|
||||||
Assert.True(cellSize > 0f);
|
Assert.Equal(description, display.Description);
|
||||||
Assert.True(gridWidth * cellSize >= width);
|
Assert.Equal(order, display.Order);
|
||||||
Assert.True(gridHeight * cellSize >= height);
|
Assert.Equal(typeof(Texts), display.ResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(0f, 720, 192)]
|
[InlineData(nameof(InkDispersionEffect.Amount), 0d, 100d)]
|
||||||
[InlineData(10f, 720, 228)]
|
[InlineData(nameof(InkDispersionEffect.Spread), 0d, 100d)]
|
||||||
[InlineData(60f, 1080, 728)]
|
[InlineData(nameof(InkDispersionEffect.Water), 0d, 100d)]
|
||||||
[InlineData(500f, 1080, 1080)]
|
[InlineData(nameof(InkDispersionEffect.Reach), 5d, 100d)]
|
||||||
[InlineData(500f, 720, 720)]
|
[InlineData(nameof(InkDispersionEffect.Fiber), 0d, 100d)]
|
||||||
public void StepCountScalesWithReachAndRespectsCap(float reachCells, int maxSteps, int expected)
|
[InlineData(nameof(InkDispersionEffect.Sizing), 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Viscosity), 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Drying), 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Density), 0d, 100d)]
|
||||||
|
[InlineData(nameof(InkDispersionEffect.Grain), 0d, 100d)]
|
||||||
|
public void AnimatedParametersAreEditedAsPercentagesWithAnimationSliders(string property, double minimum, double maximum)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, InkDispersionSettings.GetStepCount(reachCells, maxSteps));
|
var slider = Attribute<AnimationSliderAttribute>(property);
|
||||||
|
|
||||||
|
Assert.Equal("F1", slider.StringFormat);
|
||||||
|
Assert.Equal("%", slider.UnitText);
|
||||||
|
Assert.Equal(minimum, slider.DefaultMin);
|
||||||
|
Assert.Equal(maximum, slider.DefaultMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParameterMappingsAreMonotonicAndBounded()
|
public void TheQualityIsChosenFromACombo()
|
||||||
{
|
{
|
||||||
Assert.Equal(InkDispersionSettings.MinimumDeposit, InkDispersionSettings.GetDeposit(0f), 5);
|
Assert.NotNull(Attribute<EnumComboBoxAttribute>(nameof(InkDispersionEffect.Quality)));
|
||||||
Assert.Equal(InkDispersionSettings.MaximumDeposit, InkDispersionSettings.GetDeposit(1f), 5);
|
Assert.Equal([InkDispersionQuality.Balanced, InkDispersionQuality.High, InkDispersionQuality.Ultra], Enum.GetValues<InkDispersionQuality>());
|
||||||
Assert.Equal(InkDispersionSettings.MinimumDeposit, InkDispersionSettings.GetDeposit(-5f), 5);
|
|
||||||
Assert.Equal(InkDispersionSettings.MaximumDeposit, InkDispersionSettings.GetDeposit(5f), 5);
|
|
||||||
Assert.True(InkDispersionSettings.GetDeposit(0.75f) > InkDispersionSettings.GetDeposit(0.25f));
|
|
||||||
|
|
||||||
Assert.Equal(InkDispersionSettings.MaximumOmega, InkDispersionSettings.GetOmega(0f), 5);
|
|
||||||
Assert.Equal(InkDispersionSettings.MinimumOmega, InkDispersionSettings.GetOmega(1f), 5);
|
|
||||||
Assert.True(InkDispersionSettings.GetOmega(0.25f) > InkDispersionSettings.GetOmega(0.75f));
|
|
||||||
|
|
||||||
Assert.Equal(InkDispersionSettings.SigmaFloor, InkDispersionSettings.GetPinningSigma(0f), 6);
|
|
||||||
Assert.Equal(InkDispersionSettings.SigmaFloor + InkDispersionSettings.MaximumSigma, InkDispersionSettings.GetPinningSigma(1f), 6);
|
|
||||||
Assert.True(InkDispersionSettings.GetPinningSigma(0.75f) > InkDispersionSettings.GetPinningSigma(0.25f));
|
|
||||||
|
|
||||||
Assert.Equal(0f, InkDispersionSettings.GetSurfaceEvaporation(0f), 7);
|
|
||||||
Assert.Equal(InkDispersionSettings.MaximumSurfaceEvaporation, InkDispersionSettings.GetSurfaceEvaporation(1f), 7);
|
|
||||||
Assert.Equal(0f, InkDispersionSettings.GetSurfaceEvaporation(-1f), 7);
|
|
||||||
Assert.Equal(InkDispersionSettings.MaximumSurfaceEvaporation, InkDispersionSettings.GetSurfaceEvaporation(2f), 7);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(0, 0)]
|
[InlineData(InkDispersionQuality.Balanced, nameof(Texts.QualityBalanced), nameof(Texts.QualityBalancedDescription))]
|
||||||
[InlineData(1, 3)]
|
[InlineData(InkDispersionQuality.High, nameof(Texts.QualityHigh), nameof(Texts.QualityHighDescription))]
|
||||||
[InlineData(2, 4)]
|
[InlineData(InkDispersionQuality.Ultra, nameof(Texts.QualityUltra), nameof(Texts.QualityUltraDescription))]
|
||||||
[InlineData(3, 1)]
|
public void EveryQualityIsDisplayedWithItsLocalizedName(InkDispersionQuality quality, string name, string description)
|
||||||
[InlineData(4, 2)]
|
|
||||||
[InlineData(5, 7)]
|
|
||||||
[InlineData(6, 8)]
|
|
||||||
[InlineData(7, 5)]
|
|
||||||
[InlineData(8, 6)]
|
|
||||||
public void LatticeOppositeDirectionsAreInvolutions(int direction, int expected)
|
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, InkDispersionShaderMath.Opposite(direction));
|
var display = typeof(InkDispersionQuality).GetField(quality.ToString())!.GetCustomAttribute<DisplayAttribute>()!;
|
||||||
Assert.Equal(direction, InkDispersionShaderMath.Opposite(expected));
|
|
||||||
Assert.Equal(-InkDispersionShaderMath.Ex(direction), InkDispersionShaderMath.Ex(expected));
|
Assert.Equal(name, display.Name);
|
||||||
Assert.Equal(-InkDispersionShaderMath.Ey(direction), InkDispersionShaderMath.Ey(expected));
|
Assert.Equal(description, display.Description);
|
||||||
|
Assert.Equal(typeof(Texts), display.ResourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LatticeWeightsSumToOne()
|
public void TheSeedIsEditedWithoutAUnitFromZero()
|
||||||
{
|
{
|
||||||
var sum = 0f;
|
var slider = Attribute<TextBoxSliderAttribute>(nameof(InkDispersionEffect.Seed));
|
||||||
for (var i = 0; i < 9; i++)
|
var range = Attribute<RangeAttribute>(nameof(InkDispersionEffect.Seed));
|
||||||
sum += InkDispersionShaderMath.Weight(i);
|
|
||||||
|
|
||||||
Assert.Equal(1f, sum, 6);
|
Assert.Equal("F0", slider.StringFormat);
|
||||||
|
Assert.Equal(string.Empty, slider.UnitText);
|
||||||
|
Assert.Equal(0d, slider.DefaultMin);
|
||||||
|
Assert.Equal(10000d, slider.DefaultMax);
|
||||||
|
Assert.Equal(0, range.Minimum);
|
||||||
|
Assert.Equal(int.MaxValue, range.Maximum);
|
||||||
|
Assert.Equal(0, Attribute<DefaultValueAttribute>(nameof(InkDispersionEffect.Seed)).Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TransparentInputYieldsTransparentOutput()
|
public void TheInkColorIsPickedWithAColorPicker()
|
||||||
{
|
{
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
Assert.NotNull(Attribute<ColorPickerAttribute>(nameof(InkDispersionEffect.InkColor)));
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 64;
|
|
||||||
const int height = 64;
|
|
||||||
var source = new int[width * height];
|
|
||||||
var destination = new int[source.Length];
|
|
||||||
Array.Fill(destination, -1);
|
|
||||||
var parameters = CreateParameters();
|
|
||||||
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
|
|
||||||
Assert.All(destination, pixel => Assert.Equal(0, pixel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SpreadZeroYieldsTransparentOutput()
|
public void EverySettingSurvivesAProjectRoundTrip()
|
||||||
{
|
{
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
var effect = new InkDispersionEffect { Quality = InkDispersionQuality.Ultra, Seed = 42, InkColor = Colors.Crimson };
|
||||||
if (pipeline is null)
|
var values = new[] { 55d, 45d, 70d, 120d, 20d, 65d, 15d, 85d, 35d, 90d };
|
||||||
{
|
foreach (var (animation, value) in Animations(effect).Zip(values))
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
animation.Values[0].Value = value;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 96;
|
var clone = Json.GetClone(effect)!;
|
||||||
const int height = 96;
|
|
||||||
var source = CreateSquareSource(width, height, 32, 32, 32, 32);
|
|
||||||
var destination = new int[source.Length];
|
|
||||||
Array.Fill(destination, -1);
|
|
||||||
var parameters = CreateParameters(spread: 0f);
|
|
||||||
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
Assert.NotSame(effect, clone);
|
||||||
|
Assert.Equal(InkDispersionQuality.Ultra, clone.Quality);
|
||||||
Assert.All(destination, pixel => Assert.Equal(0, pixel));
|
Assert.Equal(42, clone.Seed);
|
||||||
}
|
Assert.Equal(Colors.Crimson, clone.InkColor);
|
||||||
|
Assert.Equal(values, Animations(clone).Select(animation => animation.GetValue(0, 1, EffectDescriptions.Fps)));
|
||||||
[Fact]
|
|
||||||
public void FullSpreadProducesInk()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 128;
|
|
||||||
const int height = 128;
|
|
||||||
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
|
|
||||||
var destination = new int[source.Length];
|
|
||||||
var parameters = CreateParameters();
|
|
||||||
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
|
|
||||||
Assert.True(CountLitPixels(destination) > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void GpuPipelineIsDeterministic()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 128;
|
|
||||||
const int height = 128;
|
|
||||||
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
|
|
||||||
var first = new int[source.Length];
|
|
||||||
var second = new int[source.Length];
|
|
||||||
var parameters = CreateParameters(fiber: 0.8f, seed: 42);
|
|
||||||
|
|
||||||
pipeline.Process(source, first, width, height, in parameters);
|
|
||||||
pipeline.Process(source, second, width, height, in parameters);
|
|
||||||
|
|
||||||
Assert.Equal(first, second);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void DifferentSeedsProduceDifferentInkMarks()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 128;
|
|
||||||
const int height = 128;
|
|
||||||
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
|
|
||||||
var first = new int[source.Length];
|
|
||||||
var second = new int[source.Length];
|
|
||||||
|
|
||||||
var parametersA = CreateParameters(fiber: 0.8f, seed: 1);
|
|
||||||
var parametersB = CreateParameters(fiber: 0.8f, seed: 2);
|
|
||||||
pipeline.Process(source, first, width, height, in parametersA);
|
|
||||||
pipeline.Process(source, second, width, height, in parametersB);
|
|
||||||
|
|
||||||
Assert.NotEqual(first, second);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void OutputAlphaStaysPremultipliedAndBounded()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 128;
|
|
||||||
const int height = 128;
|
|
||||||
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
|
|
||||||
var destination = new int[source.Length];
|
|
||||||
var parameters = CreateParameters(water: 1f, density: 1f, grain: 1f);
|
|
||||||
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
|
|
||||||
foreach (var pixel in destination)
|
|
||||||
{
|
|
||||||
var alpha = (pixel >> 24) & 255;
|
|
||||||
Assert.InRange((pixel >> 16) & 255, 0, alpha);
|
|
||||||
Assert.InRange((pixel >> 8) & 255, 0, alpha);
|
|
||||||
Assert.InRange(pixel & 255, 0, alpha);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SpreadIncreasesLitArea()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 128;
|
|
||||||
const int height = 128;
|
|
||||||
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
|
|
||||||
var partial = new int[source.Length];
|
|
||||||
var full = new int[source.Length];
|
|
||||||
|
|
||||||
var partialParameters = CreateParameters(spread: 0.1f);
|
|
||||||
var fullParameters = CreateParameters(spread: 1f);
|
|
||||||
pipeline.Process(source, partial, width, height, in partialParameters);
|
|
||||||
pipeline.Process(source, full, width, height, in fullParameters);
|
|
||||||
|
|
||||||
Assert.True(CountLitPixels(full) > CountLitPixels(partial));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ReachLimitsInkExtent()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 192;
|
|
||||||
const int height = 192;
|
|
||||||
var source = CreateSquareSource(width, height, 80, 80, 32, 32);
|
|
||||||
var shortReach = new int[source.Length];
|
|
||||||
var longReach = new int[source.Length];
|
|
||||||
|
|
||||||
var shortParameters = CreateParameters(reachPixels: 12f, water: 1f);
|
|
||||||
var longParameters = CreateParameters(reachPixels: 48f, water: 1f);
|
|
||||||
pipeline.Process(source, shortReach, width, height, in shortParameters);
|
|
||||||
pipeline.Process(source, longReach, width, height, in longParameters);
|
|
||||||
|
|
||||||
var shortMaxY = MaxLitY(shortReach, width, height);
|
|
||||||
var longMaxY = MaxLitY(longReach, width, height);
|
|
||||||
Assert.True(shortMaxY > 0);
|
|
||||||
Assert.True(longMaxY >= shortMaxY);
|
|
||||||
Assert.True(shortMaxY <= 80 + 32 + 12 + 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void GpuPipelineDoesNotAllocateManagedMemoryAfterWarmup()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 64;
|
|
||||||
const int height = 64;
|
|
||||||
var source = CreateSquareSource(width, height, 24, 24, 16, 16);
|
|
||||||
var destination = new int[source.Length];
|
|
||||||
var parameters = CreateParameters();
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
|
|
||||||
GC.Collect();
|
|
||||||
GC.WaitForPendingFinalizers();
|
|
||||||
GC.Collect();
|
|
||||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
var allocated = GC.GetAllocatedBytesForCurrentThread() - before;
|
|
||||||
|
|
||||||
Assert.Equal(0, allocated);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SharedTexturePipelineMatchesPackedBufferPipeline()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 96;
|
|
||||||
const int height = 96;
|
|
||||||
var source = CreateSquareSource(width, height, 32, 32, 32, 32);
|
|
||||||
var expected = new int[source.Length];
|
|
||||||
var parameters = CreateParameters(fiber: 0.7f, seed: 11);
|
|
||||||
pipeline.Process(source, expected, width, height, in parameters);
|
|
||||||
|
|
||||||
var device = GraphicsDevice.GetDefault();
|
|
||||||
using var sourceTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, width, height);
|
|
||||||
using var outputTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, width, height);
|
|
||||||
var sourcePixels = new Bgra32[source.Length];
|
|
||||||
for (var index = 0; index < source.Length; index++)
|
|
||||||
sourcePixels[index].PackedValue = unchecked((uint)source[index]);
|
|
||||||
sourceTexture.CopyFrom(sourcePixels);
|
|
||||||
pipeline.ProcessSharedAndWait(sourceTexture, outputTexture, width, height, in parameters);
|
|
||||||
var result = new Bgra32[source.Length];
|
|
||||||
outputTexture.CopyTo(result);
|
|
||||||
|
|
||||||
for (var index = 0; index < expected.Length; index++)
|
|
||||||
Assert.Equal(unchecked((uint)expected[index]), result[index].PackedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SubmittedSharedTexturePipelineAllocationsAmortizeToZero()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 64;
|
|
||||||
const int height = 64;
|
|
||||||
var device = GraphicsDevice.GetDefault();
|
|
||||||
using var source = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, width, height);
|
|
||||||
using var destination = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, width, height);
|
|
||||||
var parameters = CreateParameters();
|
|
||||||
for (var iteration = 0; iteration < 4; iteration++)
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
pipeline.WaitForCompletion();
|
|
||||||
|
|
||||||
GC.Collect();
|
|
||||||
GC.WaitForPendingFinalizers();
|
|
||||||
GC.Collect();
|
|
||||||
var minimum = long.MaxValue;
|
|
||||||
for (var iteration = 0; iteration < 16; iteration++)
|
|
||||||
{
|
|
||||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
|
||||||
pipeline.Process(source, destination, width, height, in parameters);
|
|
||||||
minimum = Math.Min(minimum, GC.GetAllocatedBytesForCurrentThread() - before);
|
|
||||||
}
|
|
||||||
pipeline.WaitForCompletion();
|
|
||||||
|
|
||||||
Assert.Equal(0, minimum);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(0.3f)]
|
|
||||||
[InlineData(1f)]
|
|
||||||
public void VisibleBoundsCoverAllLitPixelsAndMatchFullRender(float spread)
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 192;
|
|
||||||
const int height = 192;
|
|
||||||
var source = CreateSquareSource(width, height, 80, 80, 32, 24);
|
|
||||||
var full = new int[source.Length];
|
|
||||||
var parameters = CreateParameters(spread: spread, reachPixels: 32f, seed: 5);
|
|
||||||
pipeline.Process(source, full, width, height, in parameters);
|
|
||||||
|
|
||||||
var device = GraphicsDevice.GetDefault();
|
|
||||||
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(width, height);
|
|
||||||
var sourcePixels = new Bgra32[source.Length];
|
|
||||||
for (var index = 0; index < source.Length; index++)
|
|
||||||
sourcePixels[index].PackedValue = unchecked((uint)source[index]);
|
|
||||||
sourceTexture.CopyFrom(sourcePixels);
|
|
||||||
|
|
||||||
pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters);
|
|
||||||
Assert.True(pipeline.TryGetVisibleBounds(width, height, in parameters, out var rect));
|
|
||||||
Assert.True(rect.Width > 0 && rect.Height > 0);
|
|
||||||
Assert.True(rect.X >= 0 && rect.Y >= 0);
|
|
||||||
Assert.True(rect.X + rect.Width <= width && rect.Y + rect.Height <= height);
|
|
||||||
|
|
||||||
for (var y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
if (full[y * width + x] == 0)
|
|
||||||
continue;
|
|
||||||
Assert.InRange(x, rect.X, rect.X + rect.Width - 1);
|
|
||||||
Assert.InRange(y, rect.Y, rect.Y + rect.Height - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using var outputTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(rect.Width, rect.Height);
|
|
||||||
pipeline.RenderVisible(outputTexture, width, height, rect, in parameters);
|
|
||||||
var result = new Bgra32[rect.Width * rect.Height];
|
|
||||||
outputTexture.CopyTo(result);
|
|
||||||
|
|
||||||
for (var y = 0; y < rect.Height; y++)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < rect.Width; x++)
|
|
||||||
{
|
|
||||||
var expected = unchecked((uint)full[(rect.Y + y) * width + rect.X + x]);
|
|
||||||
Assert.Equal(expected, result[y * rect.Width + x].PackedValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SimulateCachesStructureUntilInputsChange()
|
|
||||||
{
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate();
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 12 is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int width = 128;
|
|
||||||
const int height = 128;
|
|
||||||
var source = CreateSquareSource(width, height, 48, 48, 32, 32);
|
|
||||||
var device = GraphicsDevice.GetDefault();
|
|
||||||
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(width, height);
|
|
||||||
var sourcePixels = new Bgra32[source.Length];
|
|
||||||
for (var index = 0; index < source.Length; index++)
|
|
||||||
sourcePixels[index].PackedValue = unchecked((uint)source[index]);
|
|
||||||
sourceTexture.CopyFrom(sourcePixels);
|
|
||||||
|
|
||||||
var parameters = CreateParameters(seed: 3);
|
|
||||||
Assert.True(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters));
|
|
||||||
Assert.False(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters));
|
|
||||||
|
|
||||||
var spreadChanged = parameters with { Spread = 0.5f };
|
|
||||||
Assert.False(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in spreadChanged));
|
|
||||||
|
|
||||||
var densityChanged = parameters with { Density = 0.5f };
|
|
||||||
Assert.False(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in densityChanged));
|
|
||||||
|
|
||||||
var seedChanged = parameters with { Seed = 4 };
|
|
||||||
Assert.True(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in seedChanged));
|
|
||||||
|
|
||||||
var movedSource = CreateSquareSource(width, height, 32, 32, 32, 32);
|
|
||||||
for (var index = 0; index < movedSource.Length; index++)
|
|
||||||
sourcePixels[index].PackedValue = unchecked((uint)movedSource[index]);
|
|
||||||
sourceTexture.CopyFrom(sourcePixels);
|
|
||||||
Assert.True(pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in seedChanged));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Direct2DInteropProducesInkFromOpaqueCore()
|
|
||||||
{
|
|
||||||
using var devices = new GraphicsDevices();
|
|
||||||
using var graphicsContext = devices.CreateContext();
|
|
||||||
using var interop = InkDispersionGpuInterop.TryCreate(graphicsContext);
|
|
||||||
if (interop is null)
|
|
||||||
{
|
|
||||||
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
using var pipeline = InkDispersionPipeline.TryCreate(interop.Device);
|
|
||||||
Assert.NotNull(pipeline);
|
|
||||||
|
|
||||||
const int width = 96;
|
|
||||||
const int height = 96;
|
|
||||||
var pixels = CreateSquareSource(width, height, 32, 32, 32, 32);
|
|
||||||
var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
|
|
||||||
using var inputBitmap = graphicsContext.DeviceContext.CreateBitmap(
|
|
||||||
new SizeI(width, height),
|
|
||||||
new BitmapProperties1(
|
|
||||||
new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied),
|
|
||||||
96f,
|
|
||||||
96f,
|
|
||||||
BitmapOptions.None));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
inputBitmap.CopyFromMemory(handle.AddrOfPinnedObject(), width * sizeof(int));
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
handle.Free();
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.True(interop.EnsureResources(width, height));
|
|
||||||
var bounds = new RawRectF(0f, 0f, width, height);
|
|
||||||
var parameters = CreateParameters();
|
|
||||||
for (var iteration = 0; iteration < 2; iteration++)
|
|
||||||
{
|
|
||||||
interop.RenderInput(inputBitmap, bounds);
|
|
||||||
interop.BeginCompute();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pipeline!.Process(interop.SourceTexture, interop.OutputTexture, width, height, in parameters);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
interop.EndCompute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
interop.WaitForIdle();
|
|
||||||
|
|
||||||
using var staging = graphicsContext.DeviceContext.CreateBitmap(
|
|
||||||
new SizeI(width, height),
|
|
||||||
new BitmapProperties1(
|
|
||||||
new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied),
|
|
||||||
96f,
|
|
||||||
96f,
|
|
||||||
BitmapOptions.CpuRead | BitmapOptions.CannotDraw));
|
|
||||||
staging.CopyFromBitmap(interop.OutputBitmap);
|
|
||||||
var mapped = staging.Map(MapOptions.Read);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var lit = 0;
|
|
||||||
for (var y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
var actual = Marshal.ReadInt32(mapped.Bits + (nint)(y * mapped.Pitch + x * sizeof(int)));
|
|
||||||
var alpha = (actual >> 24) & 255;
|
|
||||||
Assert.InRange((actual >> 16) & 255, 0, alpha);
|
|
||||||
Assert.InRange((actual >> 8) & 255, 0, alpha);
|
|
||||||
Assert.InRange(actual & 255, 0, alpha);
|
|
||||||
if (alpha > 0)
|
|
||||||
lit++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Assert.True(lit > 0);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
staging.Unmap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int[] CreateSquareSource(int width, int height, int left, int top, int squareWidth, int squareHeight)
|
|
||||||
{
|
|
||||||
var source = new int[width * height];
|
|
||||||
for (var y = top; y < top + squareHeight; y++)
|
|
||||||
{
|
|
||||||
for (var x = left; x < left + squareWidth; x++)
|
|
||||||
{
|
|
||||||
if (x < 0 || x >= width || y < 0 || y >= height)
|
|
||||||
continue;
|
|
||||||
source[y * width + x] = unchecked((int)0xFFC0C0C0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int CountLitPixels(int[] pixels)
|
|
||||||
{
|
|
||||||
var count = 0;
|
|
||||||
foreach (var pixel in pixels)
|
|
||||||
{
|
|
||||||
if (((pixel >> 24) & 255) > 8)
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int MaxLitY(int[] pixels, int width, int height)
|
|
||||||
{
|
|
||||||
for (var y = height - 1; y >= 0; y--)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
if (((pixels[y * width + x] >> 24) & 255) >= 32)
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
using System.Numerics;
|
||||||
|
using ComputeWeave;
|
||||||
|
using Vortice.Direct2D1;
|
||||||
|
using YukkuriMovieMaker.Commons;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
[Collection("Direct2D")]
|
||||||
|
public sealed class InkDispersionInteropTests
|
||||||
|
{
|
||||||
|
static readonly Bgra Gray = Bgra.Opaque(192, 192, 192);
|
||||||
|
|
||||||
|
static InkDispersionPipeline.Parameters Parameters()
|
||||||
|
=> new(InkDispersionQuality.Balanced, 1f, 0.6f, 0.5f, 0.3f, 0.3f, 0.4f, 40f, 0.8f, 0.4f, 0.12f, 0.1f, 0.09f, 0);
|
||||||
|
|
||||||
|
static Func<int, int, Bgra> CenteredSquare(int size, int square)
|
||||||
|
{
|
||||||
|
var start = (size - square) / 2;
|
||||||
|
return (x, y) => x >= start && x < start + square && y >= start && y < start + square ? Gray : Bgra.Transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class Interop : IDisposable
|
||||||
|
{
|
||||||
|
readonly ComputeExternalQueueScheduler scheduler;
|
||||||
|
readonly InkDispersionInteropProvider provider;
|
||||||
|
readonly ComputeInteropDomain domain;
|
||||||
|
|
||||||
|
public InkDispersionResourceSet Resources { get; }
|
||||||
|
|
||||||
|
public InkDispersionPipeline Pipeline { get; }
|
||||||
|
|
||||||
|
Interop(ComputeExternalQueueScheduler scheduler, InkDispersionInteropProvider provider, GraphicsDevice device)
|
||||||
|
{
|
||||||
|
this.scheduler = scheduler;
|
||||||
|
this.provider = provider;
|
||||||
|
domain = device.RegisterExternalDomain(provider);
|
||||||
|
Resources = InkDispersionResourceSet.Create(device, domain);
|
||||||
|
Pipeline = InkDispersionPipeline.TryCreate(device)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Interop Create(IGraphicsDevicesAndContext devices)
|
||||||
|
{
|
||||||
|
var scheduler = ComputeExternalQueueScheduler.Create();
|
||||||
|
var provider = InkDispersionInteropProvider.TryCreate(devices, scheduler, out var device);
|
||||||
|
if (provider is null || device is null)
|
||||||
|
{
|
||||||
|
scheduler.Dispose();
|
||||||
|
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Interop(scheduler, provider, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(ID2D1Image image)
|
||||||
|
{
|
||||||
|
var context = provider.RenderContext;
|
||||||
|
using var borrow = Resources.BeginSourceExternalOperation();
|
||||||
|
var previousTarget = context.Target;
|
||||||
|
using var target = new ID2D1Bitmap1(borrow.DangerousGetView().AddRefBitmap());
|
||||||
|
context.Target = target;
|
||||||
|
context.BeginDraw();
|
||||||
|
context.Clear(null);
|
||||||
|
context.DrawImage(image, Vector2.Zero, null, InterpolationMode.NearestNeighbor, CompositeMode.SourceCopy);
|
||||||
|
context.EndDraw();
|
||||||
|
context.Target = previousTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rendering CaptureOutput(IGraphicsDevicesAndContext devices, out int width, out int height)
|
||||||
|
{
|
||||||
|
using var lease = Resources.AcquireOutputExternalViewLease();
|
||||||
|
width = lease.Width;
|
||||||
|
height = lease.Height;
|
||||||
|
using var bitmap = new ID2D1Bitmap1(lease.DangerousGetView().AddRefBitmap());
|
||||||
|
return Rendering.Capture(devices, bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Pipeline.Dispose();
|
||||||
|
Resources.Dispose();
|
||||||
|
Resources.WaitForDisposal();
|
||||||
|
domain.Dispose();
|
||||||
|
domain.WaitForDisposal();
|
||||||
|
provider.Dispose();
|
||||||
|
scheduler.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int LitPixels(Rendering rendering, InkDispersionPipeline.PixelRect visible)
|
||||||
|
{
|
||||||
|
var lit = 0;
|
||||||
|
for (var y = 0; y < visible.Height; y++)
|
||||||
|
{
|
||||||
|
for (var x = 0; x < visible.Width; x++)
|
||||||
|
{
|
||||||
|
var pixel = rendering[x, y];
|
||||||
|
Assert.InRange(pixel.Blue, 0, pixel.Alpha);
|
||||||
|
Assert.InRange(pixel.Green, 0, pixel.Alpha);
|
||||||
|
Assert.InRange(pixel.Red, 0, pixel.Alpha);
|
||||||
|
if (pixel.Alpha > 0)
|
||||||
|
lit++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lit;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InkIsDrawnAfterTheOutputGrowsToFullHd()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var interop = Interop.Create(context);
|
||||||
|
using var source = new SourceImage(context, 96, 96, CenteredSquare(96, 32));
|
||||||
|
var parameters = Parameters();
|
||||||
|
Assert.True(interop.Resources.TryEnsureSource(96, 96, out _));
|
||||||
|
InkDispersionPipeline.PixelRect RenderInto(Func<InkDispersionPipeline.PixelRect, (int Width, int Height)> outputSize)
|
||||||
|
{
|
||||||
|
interop.Draw(source.Bitmap);
|
||||||
|
interop.Pipeline.Simulate(interop.Resources.GetSourceComputeBinding(), 96, 96, 0, 0, 96, 96, in parameters);
|
||||||
|
Assert.True(interop.Pipeline.TryGetVisibleBounds(96, 96, in parameters, out var visible));
|
||||||
|
var (width, height) = outputSize(visible);
|
||||||
|
Assert.True(interop.Resources.TryEnsureOutput(width, height, out _));
|
||||||
|
interop.Pipeline.RenderVisible(interop.Resources.GetOutputComputeBinding(), 96, 96, visible, in parameters);
|
||||||
|
return visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
var first = RenderInto(visible => (visible.Width, visible.Height));
|
||||||
|
interop.CaptureOutput(context, out var firstWidth, out var firstHeight);
|
||||||
|
var second = RenderInto(_ => (1920, 1080));
|
||||||
|
var output = interop.CaptureOutput(context, out var secondWidth, out var secondHeight);
|
||||||
|
|
||||||
|
Assert.Equal((first.Width, first.Height), (firstWidth, firstHeight));
|
||||||
|
Assert.Equal((1920, 1080), (secondWidth, secondHeight));
|
||||||
|
Assert.True(LitPixels(output, second) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InkIsDrawnAfterTheSourceIsReplacedByALargerOne()
|
||||||
|
{
|
||||||
|
using var devices = new GraphicsDevices();
|
||||||
|
using var context = devices.CreateContext();
|
||||||
|
using var interop = Interop.Create(context);
|
||||||
|
var parameters = Parameters();
|
||||||
|
var previous = default(InkDispersionPipeline.PixelRect);
|
||||||
|
|
||||||
|
foreach (var (size, square) in new[] { (96, 32), (128, 64) })
|
||||||
|
{
|
||||||
|
using var source = new SourceImage(context, size, size, CenteredSquare(size, square));
|
||||||
|
Assert.True(interop.Resources.TryEnsureSource(size, size, out var sourceChanged));
|
||||||
|
interop.Draw(source.Bitmap);
|
||||||
|
Assert.True(interop.Pipeline.Simulate(interop.Resources.GetSourceComputeBinding(), size, size, 0, 0, size, size, in parameters));
|
||||||
|
Assert.True(interop.Pipeline.TryGetVisibleBounds(size, size, in parameters, out var visible));
|
||||||
|
Assert.True(interop.Resources.TryEnsureOutput(visible.Width, visible.Height, out _));
|
||||||
|
interop.Pipeline.RenderVisible(interop.Resources.GetOutputComputeBinding(), size, size, visible, in parameters);
|
||||||
|
var output = interop.CaptureOutput(context, out var width, out var height);
|
||||||
|
|
||||||
|
Assert.True(sourceChanged);
|
||||||
|
Assert.True(visible.Width > previous.Width && visible.Height > previous.Height);
|
||||||
|
Assert.Equal((visible.Width, visible.Height), (width, height));
|
||||||
|
Assert.True(LitPixels(output, visible) > square * square);
|
||||||
|
previous = visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,425 @@
|
|||||||
|
using ComputeWeave;
|
||||||
|
using ComputeWeave.Interop;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
[Collection("Direct3D12")]
|
||||||
|
public sealed class InkDispersionPipelineTests
|
||||||
|
{
|
||||||
|
const int Opaque = unchecked((int)0xFFC0C0C0);
|
||||||
|
|
||||||
|
static readonly bool Direct3D12IsAvailable = GraphicsDevice.EnumerateDevices().Any();
|
||||||
|
|
||||||
|
static InkDispersionPipeline CreatePipeline()
|
||||||
|
{
|
||||||
|
if (!Direct3D12IsAvailable)
|
||||||
|
Assert.Skip("Direct3D 12 is unavailable.");
|
||||||
|
var pipeline = InkDispersionPipeline.TryCreate();
|
||||||
|
Assert.NotNull(pipeline);
|
||||||
|
return pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
static InkDispersionPipeline.Parameters Parameters(
|
||||||
|
InkDispersionQuality quality = InkDispersionQuality.Balanced,
|
||||||
|
float spread = 1f,
|
||||||
|
float water = 0.6f,
|
||||||
|
float fiber = 0.5f,
|
||||||
|
float sizing = 0.3f,
|
||||||
|
float viscosity = 0.3f,
|
||||||
|
float drying = 0.4f,
|
||||||
|
float reachPixels = 40f,
|
||||||
|
float density = 0.8f,
|
||||||
|
float grain = 0.4f,
|
||||||
|
int seed = 0)
|
||||||
|
=> new(quality, spread, water, fiber, sizing, viscosity, drying, reachPixels, density, grain, 0.12f, 0.1f, 0.09f, seed);
|
||||||
|
|
||||||
|
static int[] Square(int width, int height, int left, int top, int squareWidth, int squareHeight)
|
||||||
|
{
|
||||||
|
var pixels = new int[width * height];
|
||||||
|
for (var y = Math.Max(top, 0); y < Math.Min(top + squareHeight, height); y++)
|
||||||
|
{
|
||||||
|
for (var x = Math.Max(left, 0); x < Math.Min(left + squareWidth, width); x++)
|
||||||
|
pixels[y * width + x] = Opaque;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Alpha(int pixel) => (pixel >> 24) & 255;
|
||||||
|
|
||||||
|
static int LitPixels(int[] pixels) => pixels.Count(pixel => Alpha(pixel) > 8);
|
||||||
|
|
||||||
|
static (int Left, int Top, int Right, int Bottom) InkBounds(int[] pixels, int width)
|
||||||
|
{
|
||||||
|
var (left, top, right, bottom) = (int.MaxValue, int.MaxValue, int.MinValue, int.MinValue);
|
||||||
|
for (var index = 0; index < pixels.Length; index++)
|
||||||
|
{
|
||||||
|
if (Alpha(pixels[index]) == 0)
|
||||||
|
continue;
|
||||||
|
left = Math.Min(left, index % width);
|
||||||
|
top = Math.Min(top, index / width);
|
||||||
|
right = Math.Max(right, index % width + 1);
|
||||||
|
bottom = Math.Max(bottom, index / width + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (left, top, right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int LowestLitRow(int[] pixels, int width)
|
||||||
|
{
|
||||||
|
for (var index = pixels.Length - 1; index >= 0; index--)
|
||||||
|
{
|
||||||
|
if (Alpha(pixels[index]) >= 32)
|
||||||
|
return index / width;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Upload(ReadWriteTexture2D<Bgra32, Float4> texture, int[] pixels)
|
||||||
|
=> texture.CopyFrom(pixels.Select(pixel => new Bgra32 { PackedValue = unchecked((uint)pixel) }).ToArray());
|
||||||
|
|
||||||
|
static int[] Render(InkDispersionPipeline pipeline, int[] source, int width, int height, InkDispersionPipeline.Parameters parameters)
|
||||||
|
{
|
||||||
|
var destination = new int[source.Length];
|
||||||
|
pipeline.Process(source, destination, width, height, in parameters);
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ATransparentSourceProducesNoInk()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var destination = Enumerable.Repeat(-1, 64 * 64).ToArray();
|
||||||
|
var parameters = Parameters();
|
||||||
|
|
||||||
|
pipeline.Process(new int[64 * 64], destination, 64, 64, in parameters);
|
||||||
|
|
||||||
|
Assert.All(destination, pixel => Assert.Equal(0, pixel));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AZeroSpreadProducesNoInk()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(96, 96, 32, 32, 32, 32);
|
||||||
|
var destination = Enumerable.Repeat(-1, source.Length).ToArray();
|
||||||
|
var parameters = Parameters(spread: 0f);
|
||||||
|
|
||||||
|
pipeline.Process(source, destination, 96, 96, in parameters);
|
||||||
|
|
||||||
|
Assert.All(destination, pixel => Assert.Equal(0, pixel));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AFullSpreadProducesInk()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
|
||||||
|
var rendering = Render(pipeline, Square(128, 128, 48, 48, 32, 32), 128, 128, Parameters());
|
||||||
|
|
||||||
|
Assert.True(LitPixels(rendering) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheSameSettingsAlwaysProduceTheSameInk()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(128, 128, 48, 48, 32, 32);
|
||||||
|
|
||||||
|
var first = Render(pipeline, source, 128, 128, Parameters(fiber: 0.8f, seed: 42));
|
||||||
|
var second = Render(pipeline, source, 128, 128, Parameters(fiber: 0.8f, seed: 42));
|
||||||
|
|
||||||
|
Assert.Equal(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ADifferentSeedSpreadsTheInkDifferently()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(128, 128, 48, 48, 32, 32);
|
||||||
|
|
||||||
|
var first = Render(pipeline, source, 128, 128, Parameters(fiber: 0.8f, seed: 1));
|
||||||
|
var second = Render(pipeline, source, 128, 128, Parameters(fiber: 0.8f, seed: 2));
|
||||||
|
|
||||||
|
Assert.NotEqual(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheInkStaysPremultiplied()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
|
||||||
|
var rendering = Render(pipeline, Square(128, 128, 48, 48, 32, 32), 128, 128, Parameters(water: 1f, density: 1f, grain: 1f));
|
||||||
|
|
||||||
|
Assert.All(rendering, pixel =>
|
||||||
|
{
|
||||||
|
Assert.InRange((pixel >> 16) & 255, 0, Alpha(pixel));
|
||||||
|
Assert.InRange((pixel >> 8) & 255, 0, Alpha(pixel));
|
||||||
|
Assert.InRange(pixel & 255, 0, Alpha(pixel));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AWiderSpreadCoversMorePixels()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(128, 128, 48, 48, 32, 32);
|
||||||
|
|
||||||
|
var partial = Render(pipeline, source, 128, 128, Parameters(spread: 0.1f));
|
||||||
|
var full = Render(pipeline, source, 128, 128, Parameters(spread: 1f));
|
||||||
|
|
||||||
|
Assert.True(LitPixels(full) > LitPixels(partial));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheReachLimitsHowFarTheInkTravels()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(192, 192, 80, 80, 32, 32);
|
||||||
|
|
||||||
|
var shortReach = LowestLitRow(Render(pipeline, source, 192, 192, Parameters(reachPixels: 12f, water: 1f)), 192);
|
||||||
|
var longReach = LowestLitRow(Render(pipeline, source, 192, 192, Parameters(reachPixels: 48f, water: 1f)), 192);
|
||||||
|
|
||||||
|
Assert.True(shortReach > 0);
|
||||||
|
Assert.True(longReach >= shortReach);
|
||||||
|
Assert.True(shortReach <= 80 + 32 + 12 + 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void APipelineWhoseGridWasReclaimedDrawsLikeAFreshOne()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
using var fresh = CreatePipeline();
|
||||||
|
var source = Square(64, 64, 16, 16, 32, 32);
|
||||||
|
var parameters = Parameters();
|
||||||
|
Render(pipeline, source, 64, 64, parameters);
|
||||||
|
GraphicsDevice.GetDefault().TrimMemory();
|
||||||
|
|
||||||
|
var reused = Render(pipeline, source, 64, 64, parameters);
|
||||||
|
var expected = Render(fresh, source, 64, 64, parameters);
|
||||||
|
|
||||||
|
Assert.Equal(expected, reused);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AReclaimedGridIsSimulatedAgain()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var parameters = Parameters();
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var texture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(64, 64);
|
||||||
|
Upload(texture, Square(64, 64, 16, 16, 32, 32));
|
||||||
|
|
||||||
|
var first = pipeline.Simulate(texture, 64, 64, 0, 0, 64, 64, in parameters);
|
||||||
|
var repeated = pipeline.Simulate(texture, 64, 64, 0, 0, 64, 64, in parameters);
|
||||||
|
device.TrimMemory();
|
||||||
|
var reclaimed = pipeline.Simulate(texture, 64, 64, 0, 0, 64, 64, in parameters);
|
||||||
|
|
||||||
|
Assert.True(first);
|
||||||
|
Assert.False(repeated);
|
||||||
|
Assert.True(reclaimed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AWarmPipelineAllocatesNoManagedMemory()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(64, 64, 24, 24, 16, 16);
|
||||||
|
var destination = new int[source.Length];
|
||||||
|
var parameters = Parameters();
|
||||||
|
for (var iteration = 0; iteration < 4; iteration++)
|
||||||
|
pipeline.Process(source, destination, 64, 64, in parameters);
|
||||||
|
GC.Collect();
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
|
GC.Collect();
|
||||||
|
|
||||||
|
var minimum = long.MaxValue;
|
||||||
|
for (var iteration = 0; iteration < 16; iteration++)
|
||||||
|
{
|
||||||
|
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||||
|
pipeline.Process(source, destination, 64, 64, in parameters);
|
||||||
|
minimum = Math.Min(minimum, GC.GetAllocatedBytesForCurrentThread() - before);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(0, minimum);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SharedTexturesProduceTheSameInkAsPackedBuffers()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(96, 96, 32, 32, 32, 32);
|
||||||
|
var parameters = Parameters(fiber: 0.7f, seed: 11);
|
||||||
|
var expected = Render(pipeline, source, 96, 96, parameters);
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var sourceTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, 96, 96);
|
||||||
|
using var outputTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, 96, 96);
|
||||||
|
Upload(sourceTexture, source);
|
||||||
|
|
||||||
|
pipeline.ProcessSharedAndWait(sourceTexture, outputTexture, 96, 96, in parameters);
|
||||||
|
var result = new Bgra32[source.Length];
|
||||||
|
outputTexture.CopyTo(result);
|
||||||
|
|
||||||
|
Assert.Equal(expected.Select(pixel => unchecked((uint)pixel)), result.Select(pixel => pixel.PackedValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RepeatedSharedTextureSubmissionsAllocateNoManagedMemory()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var source = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, 64, 64);
|
||||||
|
using var destination = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(device, 64, 64);
|
||||||
|
var parameters = Parameters();
|
||||||
|
for (var iteration = 0; iteration < 4; iteration++)
|
||||||
|
pipeline.Process(source, destination, 64, 64, in parameters);
|
||||||
|
pipeline.WaitForCompletion();
|
||||||
|
GC.Collect();
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
|
GC.Collect();
|
||||||
|
|
||||||
|
var minimum = long.MaxValue;
|
||||||
|
for (var iteration = 0; iteration < 16; iteration++)
|
||||||
|
{
|
||||||
|
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||||
|
pipeline.Process(source, destination, 64, 64, in parameters);
|
||||||
|
minimum = Math.Min(minimum, GC.GetAllocatedBytesForCurrentThread() - before);
|
||||||
|
}
|
||||||
|
pipeline.WaitForCompletion();
|
||||||
|
|
||||||
|
Assert.Equal(0, minimum);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0.3f, 0.6f, 32f)]
|
||||||
|
[InlineData(1f, 0.6f, 32f)]
|
||||||
|
[InlineData(1f, 1f, 12f)]
|
||||||
|
public void TheVisibleBoundsHoldEveryInkedPixelAndRenderTheSameInk(float spread, float water, float reachPixels)
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(192, 192, 80, 80, 32, 24);
|
||||||
|
var parameters = Parameters(spread: spread, water: water, reachPixels: reachPixels, seed: 5);
|
||||||
|
var full = Render(pipeline, source, 192, 192, parameters);
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(192, 192);
|
||||||
|
Upload(sourceTexture, source);
|
||||||
|
|
||||||
|
pipeline.Simulate(sourceTexture, 192, 192, 0, 0, 192, 192, in parameters);
|
||||||
|
Assert.True(pipeline.TryGetVisibleBounds(192, 192, in parameters, out var rect));
|
||||||
|
using var outputTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(rect.Width, rect.Height);
|
||||||
|
pipeline.RenderVisible(outputTexture, 192, 192, rect, in parameters);
|
||||||
|
var visible = new Bgra32[rect.Width * rect.Height];
|
||||||
|
outputTexture.CopyTo(visible);
|
||||||
|
|
||||||
|
Assert.True(rect is { Width: > 0, Height: > 0, X: >= 0, Y: >= 0 });
|
||||||
|
Assert.True(rect.X + rect.Width <= 192 && rect.Y + rect.Height <= 192);
|
||||||
|
for (var y = 0; y < 192; y++)
|
||||||
|
{
|
||||||
|
for (var x = 0; x < 192; x++)
|
||||||
|
{
|
||||||
|
var inside = x >= rect.X && x < rect.X + rect.Width && y >= rect.Y && y < rect.Y + rect.Height;
|
||||||
|
if (!inside)
|
||||||
|
Assert.Equal(0, full[y * 192 + x]);
|
||||||
|
else
|
||||||
|
Assert.Equal(unchecked((uint)full[y * 192 + x]), visible[(y - rect.Y) * rect.Width + x - rect.X].PackedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheVisibleBoundsHugTheInkOnAFourPixelGrid()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var source = Square(480, 480, 192, 192, 96, 96);
|
||||||
|
var parameters = Parameters(reachPixels: 48f, seed: 5);
|
||||||
|
var ink = InkBounds(Render(pipeline, source, 480, 480, parameters), 480);
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(480, 480);
|
||||||
|
Upload(sourceTexture, source);
|
||||||
|
|
||||||
|
pipeline.Simulate(sourceTexture, 480, 480, 0, 0, 480, 480, in parameters);
|
||||||
|
Assert.True(pipeline.TryGetVisibleBounds(480, 480, in parameters, out var rect));
|
||||||
|
|
||||||
|
Assert.Equal((0, 0), (rect.X % 4, rect.Y % 4));
|
||||||
|
Assert.InRange(ink.Left - rect.X, 0, 24);
|
||||||
|
Assert.InRange(ink.Top - rect.Y, 0, 24);
|
||||||
|
Assert.InRange(rect.X + rect.Width - ink.Right, 0, 24);
|
||||||
|
Assert.InRange(rect.Y + rect.Height - ink.Bottom, 0, 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ASmallerSpreadNarrowsTheVisibleBounds()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(192, 192);
|
||||||
|
Upload(sourceTexture, Square(192, 192, 80, 80, 32, 32));
|
||||||
|
var full = Parameters(reachPixels: 48f, seed: 5);
|
||||||
|
var partial = full with { Spread = 0.3f };
|
||||||
|
|
||||||
|
pipeline.Simulate(sourceTexture, 192, 192, 0, 0, 192, 192, in full);
|
||||||
|
Assert.True(pipeline.TryGetVisibleBounds(192, 192, in full, out var wide));
|
||||||
|
Assert.True(pipeline.TryGetVisibleBounds(192, 192, in partial, out var narrow));
|
||||||
|
|
||||||
|
Assert.True(narrow.X >= wide.X && narrow.Y >= wide.Y);
|
||||||
|
Assert.True(narrow.X + narrow.Width <= wide.X + wide.Width && narrow.Y + narrow.Height <= wide.Y + wide.Height);
|
||||||
|
Assert.True(narrow.Width * narrow.Height < wide.Width * wide.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(false, 1f)]
|
||||||
|
[InlineData(true, 0f)]
|
||||||
|
public void NothingIsVisibleWithoutInkOrSpread(bool shaped, float spread)
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(128, 128);
|
||||||
|
Upload(sourceTexture, shaped ? Square(128, 128, 48, 48, 32, 32) : new int[128 * 128]);
|
||||||
|
var parameters = Parameters(spread: spread);
|
||||||
|
|
||||||
|
pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in parameters);
|
||||||
|
|
||||||
|
Assert.False(pipeline.TryGetVisibleBounds(128, 128, in parameters, out _));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void APipelineUsedAtAnotherSizeDrawsLikeAFreshOne()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
using var fresh = CreatePipeline();
|
||||||
|
var parameters = Parameters(seed: 7);
|
||||||
|
Render(pipeline, Square(128, 64, 48, 16, 32, 32), 128, 64, parameters);
|
||||||
|
var source = Square(64, 64, 16, 16, 32, 32);
|
||||||
|
|
||||||
|
var reused = Render(pipeline, source, 64, 64, parameters);
|
||||||
|
var expected = Render(fresh, source, 64, 64, parameters);
|
||||||
|
|
||||||
|
Assert.Equal(expected, reused);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheFlowIsSimulatedAgainOnlyWhenTheShapeOrTheFlowSettingsChange()
|
||||||
|
{
|
||||||
|
using var pipeline = CreatePipeline();
|
||||||
|
var device = GraphicsDevice.GetDefault();
|
||||||
|
using var sourceTexture = device.AllocateReadWriteTexture2D<Bgra32, Float4>(128, 128);
|
||||||
|
Upload(sourceTexture, Square(128, 128, 48, 48, 32, 32));
|
||||||
|
var parameters = Parameters(seed: 3);
|
||||||
|
|
||||||
|
Assert.True(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in parameters));
|
||||||
|
Assert.False(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in parameters));
|
||||||
|
|
||||||
|
var spreadChanged = parameters with { Spread = 0.5f };
|
||||||
|
Assert.False(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in spreadChanged));
|
||||||
|
|
||||||
|
var densityChanged = parameters with { Density = 0.5f };
|
||||||
|
Assert.False(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in densityChanged));
|
||||||
|
|
||||||
|
var seedChanged = parameters with { Seed = 4 };
|
||||||
|
Assert.True(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in seedChanged));
|
||||||
|
|
||||||
|
Upload(sourceTexture, Square(128, 128, 32, 32, 32, 32));
|
||||||
|
Assert.True(pipeline.Simulate(sourceTexture, 128, 128, 0, 0, 128, 128, in seedChanged));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
public sealed class InkDispersionSettingsTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(InkDispersionQuality.Balanced, 160, 720)]
|
||||||
|
[InlineData(InkDispersionQuality.High, 224, 1080)]
|
||||||
|
[InlineData(InkDispersionQuality.Ultra, 288, 1440)]
|
||||||
|
public void EveryQualityChoosesItsGridResolutionAndStepLimit(InkDispersionQuality quality, int resolution, int maxSteps)
|
||||||
|
{
|
||||||
|
var settings = InkDispersionSettings.GetQuality(quality);
|
||||||
|
|
||||||
|
Assert.Equal(resolution, settings.GridResolution);
|
||||||
|
Assert.Equal(maxSteps, settings.MaxSteps);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1920, 1080, 224)]
|
||||||
|
[InlineData(1080, 1920, 224)]
|
||||||
|
[InlineData(8, 8, 224)]
|
||||||
|
[InlineData(4096, 16, 160)]
|
||||||
|
[InlineData(100, 100, 288)]
|
||||||
|
public void TheGridCoversTheWholeCanvas(int width, int height, int resolution)
|
||||||
|
{
|
||||||
|
var (gridWidth, gridHeight, cellSize) = InkDispersionSettings.GetGridSize(width, height, resolution);
|
||||||
|
|
||||||
|
Assert.True(gridWidth >= InkDispersionSettings.MinimumGridSize);
|
||||||
|
Assert.True(gridHeight >= InkDispersionSettings.MinimumGridSize);
|
||||||
|
Assert.True(cellSize > 0f);
|
||||||
|
Assert.True(gridWidth * cellSize >= width);
|
||||||
|
Assert.True(gridHeight * cellSize >= height);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1920, 1080, 224, 224)]
|
||||||
|
[InlineData(1080, 1920, 224, 224)]
|
||||||
|
[InlineData(8, 8, 224, 8)]
|
||||||
|
[InlineData(4096, 16, 160, 160)]
|
||||||
|
[InlineData(100, 100, 288, 100)]
|
||||||
|
public void TheLongSideIsSplitIntoTheResolutionOrIntoSinglePixels(int width, int height, int resolution, int cells)
|
||||||
|
{
|
||||||
|
var (gridWidth, gridHeight, _) = InkDispersionSettings.GetGridSize(width, height, resolution);
|
||||||
|
|
||||||
|
Assert.InRange(Math.Max(gridWidth, gridHeight), cells + 1, cells + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0f, 720, 192)]
|
||||||
|
[InlineData(10f, 720, 228)]
|
||||||
|
[InlineData(60f, 1080, 728)]
|
||||||
|
[InlineData(500f, 1080, 1080)]
|
||||||
|
[InlineData(500f, 720, 720)]
|
||||||
|
public void TheStepCountGrowsWithTheReachWithinItsLimits(float reachCells, int maxSteps, int expected)
|
||||||
|
=> Assert.Equal(expected, InkDispersionSettings.GetStepCount(reachCells, maxSteps));
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(-5f, InkDispersionSettings.MinimumDeposit)]
|
||||||
|
[InlineData(0f, InkDispersionSettings.MinimumDeposit)]
|
||||||
|
[InlineData(1f, InkDispersionSettings.MaximumDeposit)]
|
||||||
|
[InlineData(5f, InkDispersionSettings.MaximumDeposit)]
|
||||||
|
public void TheWaterDepositStaysWithinItsRange(float water, float expected)
|
||||||
|
=> Assert.Equal(expected, InkDispersionSettings.GetDeposit(water), 5);
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MoreWaterDepositsMore()
|
||||||
|
=> Assert.True(InkDispersionSettings.GetDeposit(0.75f) > InkDispersionSettings.GetDeposit(0.25f));
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0f, InkDispersionSettings.MaximumOmega)]
|
||||||
|
[InlineData(1f, InkDispersionSettings.MinimumOmega)]
|
||||||
|
public void TheRelaxationSpansItsRangeOverTheViscosity(float viscosity, float expected)
|
||||||
|
=> Assert.Equal(expected, InkDispersionSettings.GetOmega(viscosity), 5);
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AHigherViscosityRelaxesMoreSlowly()
|
||||||
|
=> Assert.True(InkDispersionSettings.GetOmega(0.25f) > InkDispersionSettings.GetOmega(0.75f));
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0f, InkDispersionSettings.SigmaFloor)]
|
||||||
|
[InlineData(1f, InkDispersionSettings.SigmaFloor + InkDispersionSettings.MaximumSigma)]
|
||||||
|
public void ThePinningThresholdSpansItsRangeOverTheSizing(float sizing, float expected)
|
||||||
|
=> Assert.Equal(expected, InkDispersionSettings.GetPinningSigma(sizing), 6);
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MoreSizingPinsTheFrontHarder()
|
||||||
|
=> Assert.True(InkDispersionSettings.GetPinningSigma(0.75f) > InkDispersionSettings.GetPinningSigma(0.25f));
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(-1f, 0f)]
|
||||||
|
[InlineData(0f, 0f)]
|
||||||
|
[InlineData(1f, InkDispersionSettings.MaximumSurfaceEvaporation)]
|
||||||
|
[InlineData(2f, InkDispersionSettings.MaximumSurfaceEvaporation)]
|
||||||
|
public void TheEvaporationStaysWithinItsRange(float drying, float expected)
|
||||||
|
=> Assert.Equal(expected, InkDispersionSettings.GetSurfaceEvaporation(drying), 7);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
public sealed class InkDispersionShaderMathTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0, 0)]
|
||||||
|
[InlineData(1, 3)]
|
||||||
|
[InlineData(2, 4)]
|
||||||
|
[InlineData(3, 1)]
|
||||||
|
[InlineData(4, 2)]
|
||||||
|
[InlineData(5, 7)]
|
||||||
|
[InlineData(6, 8)]
|
||||||
|
[InlineData(7, 5)]
|
||||||
|
[InlineData(8, 6)]
|
||||||
|
public void EveryLatticeDirectionHasAnOppositeThatPointsBack(int direction, int expected)
|
||||||
|
{
|
||||||
|
Assert.Equal(expected, InkDispersionShaderMath.Opposite(direction));
|
||||||
|
Assert.Equal(direction, InkDispersionShaderMath.Opposite(expected));
|
||||||
|
Assert.Equal(-InkDispersionShaderMath.Ex(direction), InkDispersionShaderMath.Ex(expected));
|
||||||
|
Assert.Equal(-InkDispersionShaderMath.Ey(direction), InkDispersionShaderMath.Ey(expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheLatticeWeightsSumToOne()
|
||||||
|
=> Assert.Equal(1f, Enumerable.Range(0, 9).Sum(InkDispersionShaderMath.Weight), 6);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.IO.Packaging;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
internal static class PackUriScheme
|
||||||
|
{
|
||||||
|
[ModuleInitializer]
|
||||||
|
internal static void Register() => _ = PackUriHelper.UriSchemePack;
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
using System.Numerics;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Vortice.Direct2D1;
|
||||||
|
using Vortice.Mathematics;
|
||||||
|
using YukkuriMovieMaker.Commons;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
internal sealed class Rendering
|
||||||
|
{
|
||||||
|
readonly byte[] pixels;
|
||||||
|
|
||||||
|
public int Left { get; }
|
||||||
|
|
||||||
|
public int Top { get; }
|
||||||
|
|
||||||
|
public int Width { get; }
|
||||||
|
|
||||||
|
public int Height { get; }
|
||||||
|
|
||||||
|
public int Right => Left + Width;
|
||||||
|
|
||||||
|
public int Bottom => Top + Height;
|
||||||
|
|
||||||
|
Rendering(int left, int top, int width, int height, byte[] pixels)
|
||||||
|
{
|
||||||
|
Left = left;
|
||||||
|
Top = top;
|
||||||
|
Width = width;
|
||||||
|
Height = height;
|
||||||
|
this.pixels = pixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Rendering Capture(IGraphicsDevicesAndContext devices, ID2D1Image image)
|
||||||
|
{
|
||||||
|
var context = devices.DeviceContext;
|
||||||
|
var bounds = context.GetImageLocalBounds(image);
|
||||||
|
var left = (int)Math.Floor(bounds.Left);
|
||||||
|
var top = (int)Math.Floor(bounds.Top);
|
||||||
|
var width = (int)Math.Ceiling(bounds.Right) - left;
|
||||||
|
var height = (int)Math.Ceiling(bounds.Bottom) - top;
|
||||||
|
var stride = width * SourceImage.BytesPerPixel;
|
||||||
|
var size = new SizeI(width, height);
|
||||||
|
|
||||||
|
using var target = context.CreateBitmap(size, nint.Zero, stride,
|
||||||
|
new BitmapProperties1(SourceImage.PixelFormat, SourceImage.Dpi, SourceImage.Dpi, BitmapOptions.Target));
|
||||||
|
using var readback = context.CreateBitmap(size, nint.Zero, stride,
|
||||||
|
new BitmapProperties1(SourceImage.PixelFormat, SourceImage.Dpi, SourceImage.Dpi, BitmapOptions.CpuRead | BitmapOptions.CannotDraw));
|
||||||
|
|
||||||
|
context.Target = target;
|
||||||
|
context.BeginDraw();
|
||||||
|
context.Clear(new Color4(0f, 0f, 0f, 0f));
|
||||||
|
context.DrawImage(image, new Vector2(-left, -top), null, InterpolationMode.NearestNeighbor, CompositeMode.SourceCopy);
|
||||||
|
context.EndDraw();
|
||||||
|
context.Target = null;
|
||||||
|
|
||||||
|
readback.CopyFromBitmap(target);
|
||||||
|
var pixels = new byte[stride * height];
|
||||||
|
var mapped = readback.Map(MapOptions.Read);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (var y = 0; y < height; y++)
|
||||||
|
Marshal.Copy(mapped.Bits + y * (int)mapped.Pitch, pixels, y * stride, stride);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
readback.Unmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Rendering(left, top, width, height, pixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bgra this[int x, int y]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var offset = ((y - Top) * Width + (x - Left)) * SourceImage.BytesPerPixel;
|
||||||
|
return new Bgra(pixels[offset], pixels[offset + 1], pixels[offset + 2], pixels[offset + 3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains(int x, int y) => x >= Left && y >= Top && x < Right && y < Bottom;
|
||||||
|
|
||||||
|
public bool SamePixelsAs(Rendering other)
|
||||||
|
=> Left == other.Left && Top == other.Top && Width == other.Width && Height == other.Height && pixels.AsSpan().SequenceEqual(other.pixels);
|
||||||
|
|
||||||
|
public IEnumerable<(int X, int Y)> Coordinates()
|
||||||
|
{
|
||||||
|
for (var y = Top; y < Bottom; y++)
|
||||||
|
{
|
||||||
|
for (var x = Left; x < Right; x++)
|
||||||
|
yield return (x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
using Vortice.DCommon;
|
||||||
|
using Vortice.Direct2D1;
|
||||||
|
using Vortice.DXGI;
|
||||||
|
using Vortice.Mathematics;
|
||||||
|
using YukkuriMovieMaker.Commons;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
internal sealed class SourceImage : IDisposable
|
||||||
|
{
|
||||||
|
public const float Dpi = 96f;
|
||||||
|
public const int BytesPerPixel = 4;
|
||||||
|
|
||||||
|
public static readonly PixelFormat PixelFormat = new(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied);
|
||||||
|
|
||||||
|
readonly Func<int, int, Bgra> pixelOf;
|
||||||
|
|
||||||
|
public int Width { get; }
|
||||||
|
|
||||||
|
public int Height { get; }
|
||||||
|
|
||||||
|
public ID2D1Bitmap1 Bitmap { get; }
|
||||||
|
|
||||||
|
public SourceImage(IGraphicsDevicesAndContext devices, int width, int height, Func<int, int, Bgra> pixelOf)
|
||||||
|
{
|
||||||
|
this.pixelOf = pixelOf;
|
||||||
|
Width = width;
|
||||||
|
Height = height;
|
||||||
|
|
||||||
|
var stride = width * BytesPerPixel;
|
||||||
|
var pixels = new byte[stride * height];
|
||||||
|
for (var y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
for (var x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
var (blue, green, red, alpha) = pixelOf(x, y).Premultiplied();
|
||||||
|
var offset = y * stride + x * BytesPerPixel;
|
||||||
|
pixels[offset] = blue;
|
||||||
|
pixels[offset + 1] = green;
|
||||||
|
pixels[offset + 2] = red;
|
||||||
|
pixels[offset + 3] = alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap = devices.DeviceContext.CreateBitmap(
|
||||||
|
new SizeI(width, height), nint.Zero, stride,
|
||||||
|
new BitmapProperties1(PixelFormat, Dpi, Dpi, BitmapOptions.None));
|
||||||
|
Bitmap.CopyFromMemory(pixels, stride);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SourceImage Solid(IGraphicsDevicesAndContext devices, int width, int height, Bgra color)
|
||||||
|
=> new(devices, width, height, (_, _) => color);
|
||||||
|
|
||||||
|
public Bgra this[int x, int y] => pixelOf(x, y).Premultiplied();
|
||||||
|
|
||||||
|
public bool Contains(int x, int y) => x >= 0 && y >= 0 && x < Width && y < Height;
|
||||||
|
|
||||||
|
public void Dispose() => Bitmap.Dispose();
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace InkDispersion.Tests;
|
||||||
|
|
||||||
|
public sealed class TextsTests
|
||||||
|
{
|
||||||
|
public static readonly TheoryData<string> Cultures = ["ja-JP", "en-US", "zh-CN", "zh-TW", "ko-KR", "es-ES", "ar-SA", "id-ID"];
|
||||||
|
|
||||||
|
static readonly string[] Keys = typeof(Texts)
|
||||||
|
.GetProperties(BindingFlags.Public | BindingFlags.Static)
|
||||||
|
.Where(property => property.PropertyType == typeof(string) && property.Name != nameof(Texts.CurrentCulture))
|
||||||
|
.Select(property => property.Name)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EveryLocalizedKeyHasAProperty()
|
||||||
|
{
|
||||||
|
var resources = Texts.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, false)!;
|
||||||
|
var keys = resources.Cast<DictionaryEntry>().Select(entry => (string)entry.Key).Where(key => key != nameof(Texts.CurrentCulture));
|
||||||
|
|
||||||
|
Assert.Equal(keys.Order(), Keys.Order());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(Cultures))]
|
||||||
|
public void EveryKeyIsTranslated(string culture)
|
||||||
|
{
|
||||||
|
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
||||||
|
|
||||||
|
Assert.All(Keys, key => Assert.False(string.IsNullOrWhiteSpace(Texts.ResourceManager.GetString(key, cultureInfo)), key));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(Cultures))]
|
||||||
|
public void EveryCultureCarriesItsOwnTranslations(string culture)
|
||||||
|
{
|
||||||
|
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
||||||
|
|
||||||
|
Assert.Equal(culture.ToLowerInvariant(), Texts.ResourceManager.GetString(nameof(Texts.CurrentCulture), cultureInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JapaneseIsTheNeutralLanguage()
|
||||||
|
{
|
||||||
|
var neutral = Texts.ResourceManager.GetString(nameof(Texts.InkDispersion), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
|
Assert.Equal("墨拡散", neutral);
|
||||||
|
Assert.Equal(neutral, Texts.ResourceManager.GetString(nameof(Texts.InkDispersion), CultureInfo.GetCultureInfo("ja-JP")));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TheUpdateMessageEmbedsTheVersion()
|
||||||
|
{
|
||||||
|
var message = string.Format(CultureInfo.InvariantCulture, Texts.ResourceManager.GetString(nameof(Texts.UpdateAvailableMessage), CultureInfo.InvariantCulture)!, "v1.2.3");
|
||||||
|
|
||||||
|
Assert.Contains("v1.2.3", message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"stryker-config": {
|
||||||
|
"project": "InkDispersion.csproj",
|
||||||
|
"test-runner": "mtp",
|
||||||
|
"coverage-analysis": "off",
|
||||||
|
"concurrency": 4,
|
||||||
|
"additional-timeout": 30000,
|
||||||
|
"mutate": [
|
||||||
|
"**/*.cs",
|
||||||
|
"!**/YMM4-GitHubUpdateNotifier/**",
|
||||||
|
"!**/YMM4-Telemetry/**",
|
||||||
|
"!**/InkDispersionTelemetry.cs",
|
||||||
|
"!**/InkDispersionUpdateNotifier.cs"
|
||||||
|
],
|
||||||
|
"reporters": [
|
||||||
|
"progress",
|
||||||
|
"cleartext",
|
||||||
|
"html"
|
||||||
|
],
|
||||||
|
"thresholds": {
|
||||||
|
"high": 80,
|
||||||
|
"low": 60,
|
||||||
|
"break": 55
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-8
@@ -3,18 +3,23 @@
|
|||||||
<Platform Name="Any CPU" />
|
<Platform Name="Any CPU" />
|
||||||
<Platform Name="x64" />
|
<Platform Name="x64" />
|
||||||
</Configurations>
|
</Configurations>
|
||||||
<Project Path="ComputeSharp/src/ComputeSharp.Core/ComputeSharp.Core.csproj">
|
<Folder Name="/Solution Items/">
|
||||||
<Platform Solution="*|x64" Project="Any CPU" />
|
<File Path=".gitattributes" />
|
||||||
</Project>
|
<File Path=".gitignore" />
|
||||||
<Project Path="ComputeSharp/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj" />
|
<File Path=".gitmodules" />
|
||||||
<Project Path="ComputeSharp/src/ComputeSharp/ComputeSharp.csproj">
|
<File Path="Directory.Build.props" />
|
||||||
<Platform Solution="*|x64" Project="Any CPU" />
|
<File Path="LICENSE.txt" />
|
||||||
</Project>
|
<File Path="README.md" />
|
||||||
<Project Path="ComputeSharp/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj" />
|
</Folder>
|
||||||
<Project Path="InkDispersion/InkDispersion.csproj">
|
<Project Path="InkDispersion/InkDispersion.csproj">
|
||||||
<Platform Solution="*|x64" Project="x64" />
|
<Platform Solution="*|x64" Project="x64" />
|
||||||
|
<BuildDependency Project="InkDispersion.Shader/InkDispersion.Shader.vcxproj" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project Path="InkDispersion.Tests/InkDispersion.Tests.csproj" />
|
<Project Path="InkDispersion.Tests/InkDispersion.Tests.csproj" />
|
||||||
<Project Path="InkDispersion.Harness/InkDispersion.Harness.csproj" />
|
<Project Path="InkDispersion.Harness/InkDispersion.Harness.csproj" />
|
||||||
|
<Project Path="InkDispersion.Shader/InkDispersion.Shader.vcxproj">
|
||||||
|
<BuildType Solution="*|*" Project="Release" />
|
||||||
|
<Platform Solution="*|*" Project="Win32" />
|
||||||
|
</Project>
|
||||||
<Project Path="YukkuriMovieMaker.Generator/YukkuriMovieMaker.Generator/YukkuriMovieMaker.Generator.csproj" />
|
<Project Path="YukkuriMovieMaker.Generator/YukkuriMovieMaker.Generator/YukkuriMovieMaker.Generator.csproj" />
|
||||||
</Solution>
|
</Solution>
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<Project>
|
|
||||||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp' or '$(MSBuildProjectName)' == 'ComputeSharp.Core'">
|
|
||||||
<IsPackagedProject>false</IsPackagedProject>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp.Core'">
|
|
||||||
<InternalsVisibleTo Include="InkDispersion.ComputeSharp, PublicKey=$(AssemblySignPublicKey)" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<Project>
|
|
||||||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp' or '$(MSBuildProjectName)' == 'ComputeSharp.Core'">
|
|
||||||
<BaseOutputPath>$(MSBuildProjectDirectory)\bin\InkDispersion\</BaseOutputPath>
|
|
||||||
<BaseIntermediateOutputPath>$(MSBuildProjectDirectory)\obj\InkDispersion\</BaseIntermediateOutputPath>
|
|
||||||
<MSBuildProjectExtensionsPath>$(MSBuildProjectDirectory)\obj\</MSBuildProjectExtensionsPath>
|
|
||||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)\obj\**</DefaultItemExcludes>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp'">
|
|
||||||
<AssemblyName>InkDispersion.ComputeSharp</AssemblyName>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp.Core'">
|
|
||||||
<AssemblyName>InkDispersion.ComputeSharp.Core</AssemblyName>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<Project>
|
|
||||||
<PropertyGroup>
|
|
||||||
<PrivateComputeSharpBuildProperties Condition="'$(BuildingSolutionFile)' != 'true'">CustomBeforeDirectoryBuildProps=$(MSBuildThisFileDirectory)ComputeSharp.Build.props;CustomAfterDirectoryBuildProps=$(MSBuildThisFileDirectory)ComputeSharp.Build.after.props</PrivateComputeSharpBuildProperties>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\ComputeSharp\src\ComputeSharp.Core\ComputeSharp.Core.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" AdditionalProperties="$(PrivateComputeSharpBuildProperties)" GlobalPropertiesToRemove="SkipPluginDeploy" />
|
|
||||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\ComputeSharp\src\ComputeSharp\ComputeSharp.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" AdditionalProperties="$(PrivateComputeSharpBuildProperties)" GlobalPropertiesToRemove="SkipPluginDeploy" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -5,32 +5,18 @@
|
|||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Version>1.0.0</Version>
|
<Version>1.1.2</Version>
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
<ShaderDirPath>..\Release\</ShaderDirPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<HlslShader Include="Shaders\**\*.hlsl" />
|
<Resource Include="$(ShaderDirPath)InkDispersion.cso" Link="Resources\Shader\InkDispersion.cso" />
|
||||||
<Resource Include="@(HlslShader->'%(RelativeDir)%(Filename).cso')" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemDefinitionGroup>
|
|
||||||
<HlslShader>
|
|
||||||
<ShaderType>ps_5_0</ShaderType>
|
|
||||||
<EntryPoint>main</EntryPoint>
|
|
||||||
<ObjectFileOutput>%(RelativeDir)%(Filename).cso</ObjectFileOutput>
|
|
||||||
</HlslShader>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
|
|
||||||
<Target Name="CompileHLSLShaders" BeforeTargets="BeforeBuild" Inputs="@(HlslShader)" Outputs="@(HlslShader->'%(ObjectFileOutput)')">
|
|
||||||
<Message Text="Compiling HLSL Shader: %(HlslShader.Identity) [Type: %(HlslShader.ShaderType), Entry: %(HlslShader.EntryPoint)]" Importance="high" />
|
|
||||||
<Error Text="fxc.exe not found at path: $(FxcPath)" Condition="!Exists('$(FxcPath)') AND '$(FxcPath)' != 'fxc.exe'" />
|
|
||||||
<Exec Command=""$(FxcPath)" /nologo /T %(HlslShader.ShaderType) /E %(HlslShader.EntryPoint) /Fo "%(HlslShader.ObjectFileOutput)" "%(HlslShader.FullPath)"" Condition="Exists('%(HlslShader.FullPath)')" />
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="SharpGen.Runtime">
|
<Reference Include="SharpGen.Runtime">
|
||||||
<HintPath>$(YMM4DirPath)SharpGen.Runtime.dll</HintPath>
|
<HintPath>$(YMM4DirPath)SharpGen.Runtime.dll</HintPath>
|
||||||
@@ -82,7 +68,11 @@
|
|||||||
<Compile Include="..\YMM4-GitHubUpdateNotifier\GitHubUpdateNotifier\*.cs" LinkBase="GitHubUpdateNotifier" />
|
<Compile Include="..\YMM4-GitHubUpdateNotifier\GitHubUpdateNotifier\*.cs" LinkBase="GitHubUpdateNotifier" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="..\YMM4-Telemetry\Telemetry.props" />
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ComputeWeave" Version="2.6.0" />
|
||||||
|
<PackageReference Include="ILRepack" Version="2.0.46" PrivateAssets="all" ExcludeAssets="all" GeneratePathProperty="true" />
|
||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.142" />
|
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.142" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@@ -96,20 +86,17 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ComputeSharp\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" GlobalPropertiesToRemove="SkipPluginDeploy" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
|
||||||
<ProjectReference Include="..\ComputeSharp\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" GlobalPropertiesToRemove="SkipPluginDeploy" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
|
||||||
<ProjectReference Include="..\YukkuriMovieMaker.Generator\YukkuriMovieMaker.Generator\YukkuriMovieMaker.Generator.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" GlobalPropertiesToRemove="SkipPluginDeploy" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
<ProjectReference Include="..\YukkuriMovieMaker.Generator\YukkuriMovieMaker.Generator\YukkuriMovieMaker.Generator.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" GlobalPropertiesToRemove="SkipPluginDeploy" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||||
<AdditionalFiles Include="**/*.csv" />
|
<AdditionalFiles Include="**/*.csv" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project="ComputeSharp.Reference.props" />
|
<Target Name="MergePluginAssembly" AfterTargets="PostBuildEvent" Inputs="$(TargetPath);$(TargetDir)ComputeWeave.dll;$(TargetDir)ComputeWeave.Core.dll" Outputs="$(TargetDir)plugin\$(TargetFileName)">
|
||||||
|
<MakeDir Directories="$(TargetDir)plugin" />
|
||||||
|
<Exec Command=""$(PkgILRepack)\tools\ILRepack.exe" /out:"$(TargetDir)plugin\$(TargetFileName)" /lib:"$([System.IO.Path]::GetDirectoryName('$(TargetPath)'))" /lib:"$([System.IO.Path]::GetDirectoryName('$(YMM4DirPath)'))" /internalize "$(TargetPath)" "$(TargetDir)ComputeWeave.dll" "$(TargetDir)ComputeWeave.Core.dll"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<Target Name="PostBuild" AfterTargets="MergePluginAssembly" Condition="'$(SkipPluginDeploy)' != 'true' AND '$(BuildingSolutionFile)' != 'true'">
|
||||||
<Folder Include="Shaders\" />
|
<Exec Command="mkdir "$(YMM4DirPath)user\plugin\$(ProjectName)" > NUL 2>&1
del "$(YMM4DirPath)user\plugin\$(ProjectName)\ComputeWeave.dll" > NUL 2>&1
del "$(YMM4DirPath)user\plugin\$(ProjectName)\ComputeWeave.Core.dll" > NUL 2>&1
copy "$(TargetDir)plugin\$(TargetFileName)" "$(YMM4DirPath)user\plugin\$(ProjectName)\"" />
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(SkipPluginDeploy)' != 'true' AND '$(BuildingSolutionFile)' != 'true'">
|
|
||||||
<Exec Command="mkdir "$(YMM4DirPath)user\plugin\$(ProjectName)" > NUL 2>&1
copy "$(TargetPath)" "$(YMM4DirPath)user\plugin\$(ProjectName)\"
copy "$(TargetDir)InkDispersion.ComputeSharp.dll" "$(YMM4DirPath)user\plugin\$(ProjectName)\"
copy "$(TargetDir)InkDispersion.ComputeSharp.Core.dll" "$(YMM4DirPath)user\plugin\$(ProjectName)\"" />
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -33,7 +33,18 @@ internal sealed class InkDispersionCustomEffect(IGraphicsDevicesAndContext devic
|
|||||||
|
|
||||||
protected override void UpdateConstants()
|
protected override void UpdateConstants()
|
||||||
{
|
{
|
||||||
drawInformation?.SetPixelShaderConstantBuffer(_cb);
|
if (drawInformation is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
drawInformation.SetPixelShaderConstantBuffer(_cb);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
InkDispersionTelemetry.Report(exception);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MapInputRectsToOutputRect(
|
public override void MapInputRectsToOutputRect(
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public sealed class InkDispersionEffect : VideoEffectBase
|
|||||||
|
|
||||||
public InkDispersionEffect()
|
public InkDispersionEffect()
|
||||||
{
|
{
|
||||||
|
InkDispersionTelemetry.EnsureStartedOnce();
|
||||||
InkDispersionUpdateNotifier.EnsureCheckedOnce();
|
InkDispersionUpdateNotifier.EnsureCheckedOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +90,17 @@ public sealed class InkDispersionEffect : VideoEffectBase
|
|||||||
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription) => [];
|
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription) => [];
|
||||||
|
|
||||||
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
|
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
|
||||||
=> new InkDispersionEffectProcessor(devices, this);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new InkDispersionEffectProcessor(devices, this);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
InkDispersionTelemetry.Report(exception);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override IEnumerable<IAnimatable> GetAnimatables()
|
protected override IEnumerable<IAnimatable> GetAnimatables()
|
||||||
=> _animatables ??= [Amount, Spread, Water, Reach, Fiber, Sizing, Viscosity, Drying, Density, Grain];
|
=> _animatables ??= [Amount, Spread, Water, Reach, Fiber, Sizing, Viscosity, Drying, Density, Grain];
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using ComputeWeave;
|
||||||
using Vortice.Direct2D1;
|
using Vortice.Direct2D1;
|
||||||
using Vortice.Direct2D1.Effects;
|
using Vortice.Direct2D1.Effects;
|
||||||
using YukkuriMovieMaker.Commons;
|
using YukkuriMovieMaker.Commons;
|
||||||
@@ -11,7 +13,11 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
{
|
{
|
||||||
private readonly IGraphicsDevicesAndContext _devices;
|
private readonly IGraphicsDevicesAndContext _devices;
|
||||||
private readonly InkDispersionEffect _item;
|
private readonly InkDispersionEffect _item;
|
||||||
private InkDispersionGpuInterop? _interop;
|
private ComputeExternalQueueScheduler? _scheduler;
|
||||||
|
private InkDispersionInteropProvider? _interopProvider;
|
||||||
|
private ComputeInteropDomain? _interopDomain;
|
||||||
|
private InkDispersionResourceSet? _resourceSet;
|
||||||
|
private ExternalTextureLease<ExternalDirect3D11TextureView>? _outputLease;
|
||||||
private InkDispersionPipeline? _pipeline;
|
private InkDispersionPipeline? _pipeline;
|
||||||
private InkDispersionCustomEffect? _effect;
|
private InkDispersionCustomEffect? _effect;
|
||||||
private Crop? _outputCrop;
|
private Crop? _outputCrop;
|
||||||
@@ -37,7 +43,20 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
|
|
||||||
public override DrawDescription Update(EffectDescription effectDescription)
|
public override DrawDescription Update(EffectDescription effectDescription)
|
||||||
{
|
{
|
||||||
if (IsPassThroughEffect || _effect is null || _outputCrop is null || _outputTransform is null || _outputTransformOutput is null || _interop is null || _pipeline is null || input is null)
|
try
|
||||||
|
{
|
||||||
|
return UpdateCore(effectDescription);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
InkDispersionTelemetry.Report(exception);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DrawDescription UpdateCore(EffectDescription effectDescription)
|
||||||
|
{
|
||||||
|
if (IsPassThroughEffect || _effect is null || _outputCrop is null || _outputTransform is null || _outputTransformOutput is null || _resourceSet is null || _interopProvider is null || _pipeline is null || input is null)
|
||||||
return effectDescription.DrawDescription;
|
return effectDescription.DrawDescription;
|
||||||
|
|
||||||
var frame = effectDescription.ItemPosition.Frame;
|
var frame = effectDescription.ItemPosition.Frame;
|
||||||
@@ -106,8 +125,14 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
var itemWidth = (int)widthValue;
|
var itemWidth = (int)widthValue;
|
||||||
var itemHeight = (int)heightValue;
|
var itemHeight = (int)heightValue;
|
||||||
|
|
||||||
_interop.EnsureSource(itemWidth, itemHeight);
|
if (!EnsureSource(itemWidth, itemHeight))
|
||||||
_interop.RenderInput(input, new Vortice.RawRectF(bounds.Left, bounds.Top, bounds.Left + itemWidth, bounds.Top + itemHeight));
|
{
|
||||||
|
_effect.Amount = 0f;
|
||||||
|
_isFirst = true;
|
||||||
|
return effectDescription.DrawDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderInput(new Vortice.RawRectF(bounds.Left, bounds.Top, bounds.Left + itemWidth, bounds.Top + itemHeight));
|
||||||
|
|
||||||
var pipelineParameters = new InkDispersionPipeline.Parameters(
|
var pipelineParameters = new InkDispersionPipeline.Parameters(
|
||||||
parameters.Quality,
|
parameters.Quality,
|
||||||
@@ -125,24 +150,15 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
parameters.Color.B / 255f,
|
parameters.Color.B / 255f,
|
||||||
Math.Max(parameters.Seed, 0));
|
Math.Max(parameters.Seed, 0));
|
||||||
|
|
||||||
bool structureChanged;
|
var structureChanged = _pipeline.Simulate(
|
||||||
_interop.BeginCompute();
|
_resourceSet.GetSourceComputeBinding(),
|
||||||
try
|
canvasWidth,
|
||||||
{
|
canvasHeight,
|
||||||
structureChanged = _pipeline.Simulate(
|
margin,
|
||||||
_interop.SourceTexture,
|
margin,
|
||||||
canvasWidth,
|
itemWidth,
|
||||||
canvasHeight,
|
itemHeight,
|
||||||
margin,
|
in pipelineParameters);
|
||||||
margin,
|
|
||||||
itemWidth,
|
|
||||||
itemHeight,
|
|
||||||
in pipelineParameters);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_interop.EndCompute();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_pipeline.TryGetVisibleBounds(canvasWidth, canvasHeight, in pipelineParameters, out var rect))
|
if (!_pipeline.TryGetVisibleBounds(canvasWidth, canvasHeight, in pipelineParameters, out var rect))
|
||||||
{
|
{
|
||||||
@@ -153,9 +169,16 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
return effectDescription.DrawDescription;
|
return effectDescription.DrawDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_interop.OutputCovers(rect.Width, rect.Height))
|
if (!OutputCovers(rect.Width, rect.Height))
|
||||||
_outputCrop.SetInput(0, null, true);
|
_outputCrop.SetInput(0, null, true);
|
||||||
var outputChanged = _interop.EnsureOutput(rect.Width, rect.Height);
|
if (!EnsureOutput(rect.Width, rect.Height, out var outputChanged))
|
||||||
|
{
|
||||||
|
_effect.Amount = 0f;
|
||||||
|
_parameters = parameters;
|
||||||
|
_isFirst = true;
|
||||||
|
_hasRenderState = false;
|
||||||
|
return effectDescription.DrawDescription;
|
||||||
|
}
|
||||||
var renderState = new RenderState(
|
var renderState = new RenderState(
|
||||||
pipelineParameters.Spread,
|
pipelineParameters.Spread,
|
||||||
pipelineParameters.Density,
|
pipelineParameters.Density,
|
||||||
@@ -166,27 +189,22 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
rect);
|
rect);
|
||||||
if (structureChanged || outputChanged || !_hasOutput || !_hasRenderState || _renderState != renderState)
|
if (structureChanged || outputChanged || !_hasOutput || !_hasRenderState || _renderState != renderState)
|
||||||
{
|
{
|
||||||
_interop.BeginCompute();
|
_pipeline.RenderVisible(
|
||||||
try
|
_resourceSet.GetOutputComputeBinding(),
|
||||||
{
|
canvasWidth,
|
||||||
_pipeline.RenderVisible(
|
canvasHeight,
|
||||||
_interop.OutputTexture,
|
rect,
|
||||||
canvasWidth,
|
in pipelineParameters);
|
||||||
canvasHeight,
|
|
||||||
rect,
|
|
||||||
in pipelineParameters);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_interop.EndCompute();
|
|
||||||
}
|
|
||||||
_renderState = renderState;
|
_renderState = renderState;
|
||||||
_hasRenderState = true;
|
_hasRenderState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_outputLease ??= _resourceSet.AcquireOutputExternalViewLease();
|
||||||
|
|
||||||
if (outputChanged || !_hasOutput)
|
if (outputChanged || !_hasOutput)
|
||||||
{
|
{
|
||||||
_outputCrop.SetInput(0, _interop.OutputBitmap, true);
|
using var outputBitmap = new ID2D1Bitmap1(_outputLease.DangerousGetView().AddRefBitmap());
|
||||||
|
_outputCrop.SetInput(0, outputBitmap, true);
|
||||||
_effect.SetInput(1, _outputTransformOutput, true);
|
_effect.SetInput(1, _outputTransformOutput, true);
|
||||||
}
|
}
|
||||||
var cropRect = new Vector4(0f, 0f, rect.Width, rect.Height);
|
var cropRect = new Vector4(0f, 0f, rect.Width, rect.Height);
|
||||||
@@ -209,15 +227,97 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
return effectDescription.DrawDescription;
|
return effectDescription.DrawDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool EnsureSource(int width, int height)
|
||||||
|
{
|
||||||
|
return _resourceSet!.TryEnsureSource(width, height, out _);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool OutputCovers(int width, int height)
|
||||||
|
=> _outputLease is { IsDisposed: false } lease &&
|
||||||
|
lease.Width >= width &&
|
||||||
|
lease.Height >= height;
|
||||||
|
|
||||||
|
private bool EnsureOutput(int width, int height, out bool changed)
|
||||||
|
{
|
||||||
|
changed = false;
|
||||||
|
if (OutputCovers(width, height))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
_outputLease?.Dispose();
|
||||||
|
_outputLease = null;
|
||||||
|
return _resourceSet!.TryEnsureOutput(width, height, out changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RenderInput(Vortice.RawRectF bounds)
|
||||||
|
{
|
||||||
|
var renderContext = _interopProvider!.RenderContext;
|
||||||
|
using var borrow = _resourceSet!.BeginSourceExternalOperation();
|
||||||
|
var previousTarget = renderContext.Target;
|
||||||
|
using var sourceBitmap = new ID2D1Bitmap1(borrow.DangerousGetView().AddRefBitmap());
|
||||||
|
renderContext.Target = sourceBitmap;
|
||||||
|
renderContext.BeginDraw();
|
||||||
|
renderContext.Clear(null);
|
||||||
|
renderContext.DrawImage(
|
||||||
|
input,
|
||||||
|
new Vector2(-bounds.Left, -bounds.Top),
|
||||||
|
null,
|
||||||
|
InterpolationMode.NearestNeighbor,
|
||||||
|
CompositeMode.SourceCopy);
|
||||||
|
renderContext.EndDraw();
|
||||||
|
renderContext.Target = previousTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReleaseInterop()
|
||||||
|
{
|
||||||
|
_outputLease?.Dispose();
|
||||||
|
_outputLease = null;
|
||||||
|
_pipeline?.Dispose();
|
||||||
|
_pipeline = null;
|
||||||
|
_resourceSet?.Dispose();
|
||||||
|
_resourceSet?.WaitForDisposal();
|
||||||
|
_resourceSet = null;
|
||||||
|
_interopDomain?.Dispose();
|
||||||
|
_interopDomain?.WaitForDisposal();
|
||||||
|
_interopDomain = null;
|
||||||
|
_interopProvider?.Dispose();
|
||||||
|
_interopProvider = null;
|
||||||
|
_scheduler?.Dispose();
|
||||||
|
_scheduler = null;
|
||||||
|
}
|
||||||
|
|
||||||
protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices)
|
protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices)
|
||||||
{
|
{
|
||||||
var interop = InkDispersionGpuInterop.TryCreate(devices);
|
var scheduler = ComputeExternalQueueScheduler.Create();
|
||||||
if (interop is null)
|
var interopProvider = InkDispersionInteropProvider.TryCreate(devices, scheduler, out var interopDevice);
|
||||||
return null;
|
if (interopProvider is null || interopDevice is null)
|
||||||
var pipeline = InkDispersionPipeline.TryCreate(interop.Device);
|
|
||||||
if (pipeline is null)
|
|
||||||
{
|
{
|
||||||
interop.Dispose();
|
scheduler.Dispose();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_scheduler = scheduler;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_interopProvider = interopProvider;
|
||||||
|
_interopDomain = interopDevice.RegisterExternalDomain(interopProvider);
|
||||||
|
_resourceSet = InkDispersionResourceSet.Create(interopDevice, _interopDomain);
|
||||||
|
_pipeline = InkDispersionPipeline.TryCreate(interopDevice);
|
||||||
|
}
|
||||||
|
catch (Win32Exception)
|
||||||
|
{
|
||||||
|
ReleaseInterop();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
ReleaseInterop();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_pipeline is null)
|
||||||
|
{
|
||||||
|
ReleaseInterop();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,8 +333,7 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
if (!effect.IsEnabled)
|
if (!effect.IsEnabled)
|
||||||
{
|
{
|
||||||
effect.Dispose();
|
effect.Dispose();
|
||||||
pipeline.Dispose();
|
ReleaseInterop();
|
||||||
interop.Dispose();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
outputCrop = new Crop(devices.DeviceContext);
|
outputCrop = new Crop(devices.DeviceContext);
|
||||||
@@ -246,8 +345,6 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
outputTransform.SetInput(0, outputCropOutput, true);
|
outputTransform.SetInput(0, outputCropOutput, true);
|
||||||
outputTransformOutput = outputTransform.Output;
|
outputTransformOutput = outputTransform.Output;
|
||||||
output = effect.Output;
|
output = effect.Output;
|
||||||
_interop = interop;
|
|
||||||
_pipeline = pipeline;
|
|
||||||
_effect = effect;
|
_effect = effect;
|
||||||
_outputCrop = outputCrop;
|
_outputCrop = outputCrop;
|
||||||
_outputCropOutput = outputCropOutput;
|
_outputCropOutput = outputCropOutput;
|
||||||
@@ -269,13 +366,25 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
outputCropOutput?.Dispose();
|
outputCropOutput?.Dispose();
|
||||||
outputCrop?.Dispose();
|
outputCrop?.Dispose();
|
||||||
effect?.Dispose();
|
effect?.Dispose();
|
||||||
pipeline.Dispose();
|
ReleaseInterop();
|
||||||
interop.Dispose();
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void setInput(ID2D1Image? inputImage)
|
protected override void setInput(ID2D1Image? inputImage)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SetInputCore(inputImage);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
InkDispersionTelemetry.Report(exception);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetInputCore(ID2D1Image? inputImage)
|
||||||
{
|
{
|
||||||
_effect?.SetInput(0, inputImage, true);
|
_effect?.SetInput(0, inputImage, true);
|
||||||
if (!_hasOutput)
|
if (!_hasOutput)
|
||||||
@@ -301,13 +410,14 @@ internal sealed class InkDispersionEffectProcessor : VideoEffectProcessorBase
|
|||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
ClearEffectChain();
|
ClearEffectChain();
|
||||||
_interop?.WaitForIdle();
|
ReleaseInterop();
|
||||||
_pipeline?.Dispose();
|
|
||||||
_pipeline = null;
|
|
||||||
_interop?.Dispose();
|
|
||||||
_interop = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
InkDispersionTelemetry.Report(exception);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
|
|||||||
@@ -1,323 +1,89 @@
|
|||||||
using System.Runtime.InteropServices;
|
using ComputeWeave;
|
||||||
using ComputeSharp;
|
|
||||||
using ComputeSharp.Interop;
|
|
||||||
using Vortice;
|
|
||||||
using Vortice.Direct2D1;
|
using Vortice.Direct2D1;
|
||||||
using Vortice.Direct3D11;
|
using Vortice.Direct3D11;
|
||||||
using Vortice.DXGI;
|
|
||||||
using YukkuriMovieMaker.Commons;
|
using YukkuriMovieMaker.Commons;
|
||||||
using PixelFormat = Vortice.DCommon.PixelFormat;
|
|
||||||
|
|
||||||
namespace InkDispersion;
|
namespace InkDispersion;
|
||||||
|
|
||||||
internal sealed class InkDispersionGpuInterop : IDisposable
|
internal sealed class InkDispersionInteropProvider : ComputeExternalDirect3D11Provider
|
||||||
{
|
{
|
||||||
private static readonly Guid D3D12FenceGuid = new("0a753dcf-c4d8-4b91-adf6-be5a60d95a76");
|
|
||||||
|
|
||||||
private readonly GraphicsDevice _device;
|
|
||||||
private readonly ID3D11Device1 _d3dDevice;
|
|
||||||
private readonly ID3D11DeviceContext4 _d3dContext;
|
|
||||||
private readonly ID3D11Fence _fence;
|
|
||||||
private readonly ID2D1DeviceContext6 _renderContext;
|
private readonly ID2D1DeviceContext6 _renderContext;
|
||||||
private nint _d3d12Fence;
|
|
||||||
private ReadWriteTexture2D<Bgra32, Float4>? _sourceTexture;
|
|
||||||
private ReadWriteTexture2D<Bgra32, Float4>? _outputTexture;
|
|
||||||
private ID3D11Texture2D? _sourceD3D11Texture;
|
|
||||||
private ID3D11Texture2D? _outputD3D11Texture;
|
|
||||||
private ID2D1Bitmap1? _sourceBitmap;
|
|
||||||
private ID2D1Bitmap1? _outputBitmap;
|
|
||||||
private int _sourceWidth;
|
|
||||||
private int _sourceHeight;
|
|
||||||
private int _outputWidth;
|
|
||||||
private int _outputHeight;
|
|
||||||
private ulong _fenceValue;
|
|
||||||
private bool _computeActive;
|
|
||||||
private bool _disposed;
|
|
||||||
|
|
||||||
private InkDispersionGpuInterop(
|
private InkDispersionInteropProvider(
|
||||||
GraphicsDevice device,
|
ID3D11Device1 device,
|
||||||
ID3D11Device1 d3dDevice,
|
ID3D11DeviceContext4 context,
|
||||||
ID3D11DeviceContext4 d3dContext,
|
|
||||||
ID3D11Fence fence,
|
|
||||||
ID2D1DeviceContext6 renderContext,
|
ID2D1DeviceContext6 renderContext,
|
||||||
nint d3d12Fence)
|
ComputeExternalQueueScheduler scheduler)
|
||||||
|
: base(device.NativePointer, context.NativePointer, renderContext.NativePointer, scheduler)
|
||||||
{
|
{
|
||||||
_device = device;
|
|
||||||
_d3dDevice = d3dDevice;
|
|
||||||
_d3dContext = d3dContext;
|
|
||||||
_fence = fence;
|
|
||||||
_renderContext = renderContext;
|
_renderContext = renderContext;
|
||||||
_d3d12Fence = d3d12Fence;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GraphicsDevice Device => _device;
|
public ID2D1DeviceContext6 RenderContext => _renderContext;
|
||||||
|
|
||||||
public ReadWriteTexture2D<Bgra32, Float4> SourceTexture => _sourceTexture!;
|
public static InkDispersionInteropProvider? TryCreate(
|
||||||
|
IGraphicsDevicesAndContext devices,
|
||||||
public ReadWriteTexture2D<Bgra32, Float4> OutputTexture => _outputTexture!;
|
ComputeExternalQueueScheduler scheduler,
|
||||||
|
out GraphicsDevice? graphicsDevice)
|
||||||
public ID2D1Bitmap1 OutputBitmap => _outputBitmap!;
|
|
||||||
|
|
||||||
public bool SourceMatches(int width, int height)
|
|
||||||
=> _sourceTexture is not null && _sourceWidth == width && _sourceHeight == height;
|
|
||||||
|
|
||||||
public bool OutputCovers(int width, int height)
|
|
||||||
=> _outputTexture is not null && _outputWidth >= width && _outputHeight >= height;
|
|
||||||
|
|
||||||
public static unsafe InkDispersionGpuInterop? TryCreate(IGraphicsDevicesAndContext devices)
|
|
||||||
{
|
{
|
||||||
ID3D11Device1? d3dDevice = null;
|
ArgumentNullException.ThrowIfNull(scheduler);
|
||||||
ID3D11DeviceContext4? d3dContext = null;
|
|
||||||
ID3D11Fence? fence = null;
|
graphicsDevice = null;
|
||||||
|
|
||||||
|
ID3D11Device1? device = null;
|
||||||
|
ID3D11DeviceContext4? context = null;
|
||||||
ID2D1DeviceContext6? renderContext = null;
|
ID2D1DeviceContext6? renderContext = null;
|
||||||
nint d3d12Fence = 0;
|
|
||||||
nint fenceHandle = 0;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var device = GetMatchingDevice(devices);
|
if (!GraphicsDevice.TryGetDevice(new ExternalAdapterIdentity(devices.DXGI.Adapter.Description.Luid), out graphicsDevice))
|
||||||
d3dDevice = devices.D3D.Device.QueryInterface<ID3D11Device1>();
|
return null;
|
||||||
d3dContext = devices.D3D.DeviceContext.QueryInterface<ID3D11DeviceContext4>();
|
|
||||||
using var d3dDevice5 = devices.D3D.Device.QueryInterface<ID3D11Device5>();
|
device = devices.D3D.Device.QueryInterface<ID3D11Device1>();
|
||||||
var fenceGuid = D3D12FenceGuid;
|
context = devices.D3D.DeviceContext.QueryInterface<ID3D11DeviceContext4>();
|
||||||
InteropServices.CreateSharedFence(device, &fenceGuid, (void**)&d3d12Fence, &fenceHandle);
|
|
||||||
fence = d3dDevice5.OpenSharedFence(fenceHandle);
|
|
||||||
renderContext = devices.D2D.Device.CreateDeviceContext(DeviceContextOptions.EnableMultithreadedOptimizations);
|
renderContext = devices.D2D.Device.CreateDeviceContext(DeviceContextOptions.EnableMultithreadedOptimizations);
|
||||||
return new InkDispersionGpuInterop(device, d3dDevice, d3dContext, fence, renderContext, d3d12Fence);
|
var provider = new InkDispersionInteropProvider(device, context, renderContext, scheduler);
|
||||||
|
renderContext = null;
|
||||||
|
return provider;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
renderContext?.Dispose();
|
graphicsDevice = null;
|
||||||
fence?.Dispose();
|
|
||||||
d3dContext?.Dispose();
|
|
||||||
d3dDevice?.Dispose();
|
|
||||||
if (d3d12Fence != 0)
|
|
||||||
Marshal.Release(d3d12Fence);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (fenceHandle != 0)
|
renderContext?.Dispose();
|
||||||
CloseHandle(fenceHandle);
|
context?.Dispose();
|
||||||
|
device?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool EnsureResources(int width, int height)
|
protected override void DisposeCore()
|
||||||
{
|
{
|
||||||
var sourceChanged = EnsureSource(width, height);
|
_renderContext.Dispose();
|
||||||
var outputChanged = EnsureOutput(width, height);
|
|
||||||
return sourceChanged || outputChanged;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public bool EnsureSource(int width, int height)
|
|
||||||
{
|
[ComputeInteropResourceSet]
|
||||||
if (SourceMatches(width, height))
|
internal sealed partial class InkDispersionResourceSet
|
||||||
return false;
|
{
|
||||||
|
[ComputeSharedTexture(
|
||||||
if (_sourceTexture is not null)
|
ComputeResourceResizePolicy.Exact,
|
||||||
WaitForIdle();
|
ComputeResourceAccess.ReadWrite,
|
||||||
ReleaseSourceResources();
|
ExternalResourceAccess.Write,
|
||||||
CreateSourceResources(width, height);
|
ExternalTextureUsage.RenderTarget,
|
||||||
return true;
|
ComputeAlphaMode.Premultiplied,
|
||||||
}
|
ComputeSharedTextureInitialOwner.External,
|
||||||
|
ComputeResourceRecovery.RecreateFromHost)]
|
||||||
public bool EnsureOutput(int width, int height)
|
private readonly SharedTextureSlot<Bgra32, Float4, ExternalDirect3D11TextureView> _source;
|
||||||
{
|
|
||||||
if (OutputCovers(width, height))
|
[ComputeSharedTexture(
|
||||||
return false;
|
ComputeResourceResizePolicy.GrowOnly,
|
||||||
|
ComputeResourceAccess.ReadWrite,
|
||||||
var capacityWidth = Math.Max(width, _outputWidth);
|
ExternalResourceAccess.Read,
|
||||||
var capacityHeight = Math.Max(height, _outputHeight);
|
ExternalTextureUsage.Sampled,
|
||||||
if (_outputTexture is not null)
|
ComputeAlphaMode.Premultiplied,
|
||||||
WaitForIdle();
|
ComputeSharedTextureInitialOwner.Compute,
|
||||||
ReleaseOutputResources();
|
ComputeResourceRecovery.Recompute)]
|
||||||
CreateOutputResources(capacityWidth, capacityHeight);
|
private readonly SharedTextureSlot<Bgra32, Float4, ExternalDirect3D11TextureView> _output;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RenderInput(ID2D1Image source, RawRectF bounds)
|
|
||||||
{
|
|
||||||
_renderContext.BeginDraw();
|
|
||||||
_renderContext.Clear(null);
|
|
||||||
_renderContext.DrawImage(
|
|
||||||
source,
|
|
||||||
new System.Numerics.Vector2(-bounds.Left, -bounds.Top),
|
|
||||||
null,
|
|
||||||
InterpolationMode.NearestNeighbor,
|
|
||||||
CompositeMode.SourceCopy);
|
|
||||||
_renderContext.EndDraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void BeginCompute()
|
|
||||||
{
|
|
||||||
if (_computeActive)
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
var value = ++_fenceValue;
|
|
||||||
_d3dContext.Signal(_fence, value);
|
|
||||||
_d3dContext.Flush();
|
|
||||||
InteropServices.WaitForSharedFence(_device, (void*)_d3d12Fence, value);
|
|
||||||
_computeActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void EndCompute()
|
|
||||||
{
|
|
||||||
if (!_computeActive)
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var value = ++_fenceValue;
|
|
||||||
InteropServices.SignalSharedFence(_device, (void*)_d3d12Fence, value);
|
|
||||||
_d3dContext.Wait(_fence, value);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_computeActive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WaitForIdle()
|
|
||||||
{
|
|
||||||
if (_computeActive)
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
var value = ++_fenceValue;
|
|
||||||
_d3dContext.Signal(_fence, value);
|
|
||||||
_d3dContext.Flush();
|
|
||||||
_fence.SetEventOnCompletion(value, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GraphicsDevice GetMatchingDevice(IGraphicsDevicesAndContext devices)
|
|
||||||
{
|
|
||||||
var adapterLuid = devices.DXGI.Adapter.Description.Luid.ToString();
|
|
||||||
using var enumerator = GraphicsDevice.QueryDevices(
|
|
||||||
device => string.Equals(device.Luid.ToString(), adapterLuid, StringComparison.Ordinal)).GetEnumerator();
|
|
||||||
if (!enumerator.MoveNext())
|
|
||||||
throw new NotSupportedException();
|
|
||||||
return enumerator.Current;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateSourceResources(int width, int height)
|
|
||||||
{
|
|
||||||
ReadWriteTexture2D<Bgra32, Float4>? sourceTexture = null;
|
|
||||||
ID3D11Texture2D? sourceD3D11Texture = null;
|
|
||||||
ID2D1Bitmap1? sourceBitmap = null;
|
|
||||||
nint sourceHandle = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sourceTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(_device, width, height);
|
|
||||||
sourceHandle = InteropServices.CreateSharedHandle(sourceTexture);
|
|
||||||
sourceD3D11Texture = _d3dDevice.OpenSharedResource1<ID3D11Texture2D>(sourceHandle);
|
|
||||||
using var sourceSurface = sourceD3D11Texture.QueryInterface<IDXGISurface>();
|
|
||||||
var pixelFormat = new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied);
|
|
||||||
sourceBitmap = _renderContext.CreateBitmapFromDxgiSurface(
|
|
||||||
sourceSurface,
|
|
||||||
new BitmapProperties1(pixelFormat, 96f, 96f, BitmapOptions.Target));
|
|
||||||
_renderContext.Target = sourceBitmap;
|
|
||||||
|
|
||||||
_sourceTexture = sourceTexture;
|
|
||||||
_sourceD3D11Texture = sourceD3D11Texture;
|
|
||||||
_sourceBitmap = sourceBitmap;
|
|
||||||
_sourceWidth = width;
|
|
||||||
_sourceHeight = height;
|
|
||||||
sourceTexture = null;
|
|
||||||
sourceD3D11Texture = null;
|
|
||||||
sourceBitmap = null;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (sourceHandle != 0)
|
|
||||||
CloseHandle(sourceHandle);
|
|
||||||
sourceBitmap?.Dispose();
|
|
||||||
sourceD3D11Texture?.Dispose();
|
|
||||||
sourceTexture?.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateOutputResources(int width, int height)
|
|
||||||
{
|
|
||||||
ReadWriteTexture2D<Bgra32, Float4>? outputTexture = null;
|
|
||||||
ID3D11Texture2D? outputD3D11Texture = null;
|
|
||||||
ID2D1Bitmap1? outputBitmap = null;
|
|
||||||
nint outputHandle = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
outputTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(_device, width, height);
|
|
||||||
outputHandle = InteropServices.CreateSharedHandle(outputTexture);
|
|
||||||
outputD3D11Texture = _d3dDevice.OpenSharedResource1<ID3D11Texture2D>(outputHandle);
|
|
||||||
using var outputSurface = outputD3D11Texture.QueryInterface<IDXGISurface>();
|
|
||||||
var pixelFormat = new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied);
|
|
||||||
outputBitmap = _renderContext.CreateBitmapFromDxgiSurface(
|
|
||||||
outputSurface,
|
|
||||||
new BitmapProperties1(pixelFormat, 96f, 96f, BitmapOptions.None));
|
|
||||||
|
|
||||||
_outputTexture = outputTexture;
|
|
||||||
_outputD3D11Texture = outputD3D11Texture;
|
|
||||||
_outputBitmap = outputBitmap;
|
|
||||||
_outputWidth = width;
|
|
||||||
_outputHeight = height;
|
|
||||||
outputTexture = null;
|
|
||||||
outputD3D11Texture = null;
|
|
||||||
outputBitmap = null;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (outputHandle != 0)
|
|
||||||
CloseHandle(outputHandle);
|
|
||||||
outputBitmap?.Dispose();
|
|
||||||
outputD3D11Texture?.Dispose();
|
|
||||||
outputTexture?.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReleaseSourceResources()
|
|
||||||
{
|
|
||||||
_renderContext.Target = null;
|
|
||||||
_sourceBitmap?.Dispose();
|
|
||||||
_sourceD3D11Texture?.Dispose();
|
|
||||||
_sourceTexture?.Dispose();
|
|
||||||
_sourceBitmap = null;
|
|
||||||
_sourceD3D11Texture = null;
|
|
||||||
_sourceTexture = null;
|
|
||||||
_sourceWidth = 0;
|
|
||||||
_sourceHeight = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReleaseOutputResources()
|
|
||||||
{
|
|
||||||
_outputBitmap?.Dispose();
|
|
||||||
_outputD3D11Texture?.Dispose();
|
|
||||||
_outputTexture?.Dispose();
|
|
||||||
_outputBitmap = null;
|
|
||||||
_outputD3D11Texture = null;
|
|
||||||
_outputTexture = null;
|
|
||||||
_outputWidth = 0;
|
|
||||||
_outputHeight = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (_disposed)
|
|
||||||
return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
WaitForIdle();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_disposed = true;
|
|
||||||
ReleaseOutputResources();
|
|
||||||
ReleaseSourceResources();
|
|
||||||
_renderContext.Dispose();
|
|
||||||
_fence.Dispose();
|
|
||||||
_d3dContext.Dispose();
|
|
||||||
_d3dDevice.Dispose();
|
|
||||||
if (_d3d12Fence != 0)
|
|
||||||
{
|
|
||||||
Marshal.Release(_d3d12Fence);
|
|
||||||
_d3d12Fence = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
|
||||||
private static extern bool CloseHandle(nint handle);
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using ComputeSharp;
|
// Stryker disable all
|
||||||
|
using ComputeWeave;
|
||||||
|
|
||||||
namespace InkDispersion;
|
namespace InkDispersion;
|
||||||
|
|
||||||
@@ -104,6 +105,10 @@ internal readonly partial struct MaskHashResetShader(
|
|||||||
{
|
{
|
||||||
if (ThreadIds.X != 0)
|
if (ThreadIds.X != 0)
|
||||||
return;
|
return;
|
||||||
|
scratch[2] = int.MaxValue;
|
||||||
|
scratch[3] = int.MaxValue;
|
||||||
|
scratch[4] = int.MinValue;
|
||||||
|
scratch[5] = int.MinValue;
|
||||||
scratch[6] = 0;
|
scratch[6] = 0;
|
||||||
scratch[7] = 0;
|
scratch[7] = 0;
|
||||||
}
|
}
|
||||||
@@ -130,7 +135,15 @@ internal readonly partial struct MaskHashShader(
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var index = gy * gridWidth + gx;
|
var index = gy * gridWidth + gx;
|
||||||
var quantized = (int)(deposit[index] * 255f + 0.5f);
|
var value = deposit[index];
|
||||||
|
if (value != 0f)
|
||||||
|
{
|
||||||
|
Hlsl.InterlockedMin(ref scratch[2], gx);
|
||||||
|
Hlsl.InterlockedMin(ref scratch[3], gy);
|
||||||
|
Hlsl.InterlockedMax(ref scratch[4], gx);
|
||||||
|
Hlsl.InterlockedMax(ref scratch[5], gy);
|
||||||
|
}
|
||||||
|
var quantized = (int)(value * 255f + 0.5f);
|
||||||
if (quantized <= 0)
|
if (quantized <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -146,31 +159,45 @@ internal readonly partial struct MaskHashShader(
|
|||||||
[ThreadGroupSize(DefaultThreadGroupSizes.XY)]
|
[ThreadGroupSize(DefaultThreadGroupSizes.XY)]
|
||||||
[GeneratedComputeShaderDescriptor]
|
[GeneratedComputeShaderDescriptor]
|
||||||
internal readonly partial struct InitFieldShader(
|
internal readonly partial struct InitFieldShader(
|
||||||
ReadWriteBuffer<float> distributions,
|
ReadWriteBuffer<float> distributionsA,
|
||||||
|
ReadWriteBuffer<float> distributionsB,
|
||||||
ReadWriteBuffer<float> deposit,
|
ReadWriteBuffer<float> deposit,
|
||||||
ReadWriteBuffer<float> surface,
|
ReadWriteBuffer<float> surface,
|
||||||
ReadWriteBuffer<float> flowPigment,
|
ReadWriteBuffer<float> flowPigmentA,
|
||||||
|
ReadWriteBuffer<float> flowPigmentB,
|
||||||
ReadWriteBuffer<float> fixedPigment,
|
ReadWriteBuffer<float> fixedPigment,
|
||||||
ReadWriteBuffer<float> density,
|
ReadWriteBuffer<float> densityA,
|
||||||
|
ReadWriteBuffer<float> densityB,
|
||||||
ReadWriteBuffer<float> wetness,
|
ReadWriteBuffer<float> wetness,
|
||||||
ReadWriteBuffer<Float2> velocity,
|
ReadWriteBuffer<Float2> velocity,
|
||||||
ReadWriteBuffer<int> inkStep,
|
ReadWriteBuffer<int> inkStep,
|
||||||
|
ReadWriteBuffer<float> fiberField,
|
||||||
|
ReadWriteBuffer<float> alumField,
|
||||||
|
ReadWriteBuffer<float> pinField,
|
||||||
int gridWidth,
|
int gridWidth,
|
||||||
int gridHeight,
|
int gridHeight,
|
||||||
float depositScale) : IComputeShader
|
float depositScale,
|
||||||
|
int seed) : IComputeShader
|
||||||
{
|
{
|
||||||
private readonly ReadWriteBuffer<float> distributions = distributions;
|
private readonly ReadWriteBuffer<float> distributionsA = distributionsA;
|
||||||
|
private readonly ReadWriteBuffer<float> distributionsB = distributionsB;
|
||||||
private readonly ReadWriteBuffer<float> deposit = deposit;
|
private readonly ReadWriteBuffer<float> deposit = deposit;
|
||||||
private readonly ReadWriteBuffer<float> surface = surface;
|
private readonly ReadWriteBuffer<float> surface = surface;
|
||||||
private readonly ReadWriteBuffer<float> flowPigment = flowPigment;
|
private readonly ReadWriteBuffer<float> flowPigmentA = flowPigmentA;
|
||||||
|
private readonly ReadWriteBuffer<float> flowPigmentB = flowPigmentB;
|
||||||
private readonly ReadWriteBuffer<float> fixedPigment = fixedPigment;
|
private readonly ReadWriteBuffer<float> fixedPigment = fixedPigment;
|
||||||
private readonly ReadWriteBuffer<float> density = density;
|
private readonly ReadWriteBuffer<float> densityA = densityA;
|
||||||
|
private readonly ReadWriteBuffer<float> densityB = densityB;
|
||||||
private readonly ReadWriteBuffer<float> wetness = wetness;
|
private readonly ReadWriteBuffer<float> wetness = wetness;
|
||||||
private readonly ReadWriteBuffer<Float2> velocity = velocity;
|
private readonly ReadWriteBuffer<Float2> velocity = velocity;
|
||||||
private readonly ReadWriteBuffer<int> inkStep = inkStep;
|
private readonly ReadWriteBuffer<int> inkStep = inkStep;
|
||||||
|
private readonly ReadWriteBuffer<float> fiberField = fiberField;
|
||||||
|
private readonly ReadWriteBuffer<float> alumField = alumField;
|
||||||
|
private readonly ReadWriteBuffer<float> pinField = pinField;
|
||||||
private readonly int gridWidth = gridWidth;
|
private readonly int gridWidth = gridWidth;
|
||||||
private readonly int gridHeight = gridHeight;
|
private readonly int gridHeight = gridHeight;
|
||||||
private readonly float depositScale = depositScale;
|
private readonly float depositScale = depositScale;
|
||||||
|
private readonly int seed = seed;
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
@@ -182,14 +209,22 @@ internal readonly partial struct InitFieldShader(
|
|||||||
var index = gy * gridWidth + gx;
|
var index = gy * gridWidth + gx;
|
||||||
var gridLength = gridWidth * gridHeight;
|
var gridLength = gridWidth * gridHeight;
|
||||||
for (var i = 0; i < 9; i++)
|
for (var i = 0; i < 9; i++)
|
||||||
distributions[i * gridLength + index] = 0f;
|
{
|
||||||
|
distributionsA[i * gridLength + index] = 0f;
|
||||||
|
distributionsB[i * gridLength + index] = 0f;
|
||||||
|
}
|
||||||
surface[index] = deposit[index] * depositScale;
|
surface[index] = deposit[index] * depositScale;
|
||||||
flowPigment[index] = 0f;
|
flowPigmentA[index] = 0f;
|
||||||
|
flowPigmentB[index] = 0f;
|
||||||
fixedPigment[index] = 0f;
|
fixedPigment[index] = 0f;
|
||||||
density[index] = 0f;
|
densityA[index] = 0f;
|
||||||
|
densityB[index] = 0f;
|
||||||
wetness[index] = 0f;
|
wetness[index] = 0f;
|
||||||
velocity[index] = new Float2(0f, 0f);
|
velocity[index] = new Float2(0f, 0f);
|
||||||
inkStep[index] = InkDispersionSettings.BirthSentinel;
|
inkStep[index] = InkDispersionSettings.BirthSentinel;
|
||||||
|
fiberField[index] = InkDispersionShaderMath.FiberField(gx, gy, seed);
|
||||||
|
alumField[index] = InkDispersionShaderMath.AlumField(gx, gy, seed);
|
||||||
|
pinField[index] = InkDispersionShaderMath.PinField(gx, gy, seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,6 +307,7 @@ internal readonly partial struct JumpFloodPassShader(
|
|||||||
internal readonly partial struct ReachMaskShader(
|
internal readonly partial struct ReachMaskShader(
|
||||||
ReadWriteBuffer<int> jumpFlood,
|
ReadWriteBuffer<int> jumpFlood,
|
||||||
ReadWriteBuffer<int> reachMask,
|
ReadWriteBuffer<int> reachMask,
|
||||||
|
ReadWriteBuffer<float> kappa,
|
||||||
int gridWidth,
|
int gridWidth,
|
||||||
int gridHeight,
|
int gridHeight,
|
||||||
float cellSize,
|
float cellSize,
|
||||||
@@ -279,6 +315,7 @@ internal readonly partial struct ReachMaskShader(
|
|||||||
{
|
{
|
||||||
private readonly ReadWriteBuffer<int> jumpFlood = jumpFlood;
|
private readonly ReadWriteBuffer<int> jumpFlood = jumpFlood;
|
||||||
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
||||||
|
private readonly ReadWriteBuffer<float> kappa = kappa;
|
||||||
private readonly int gridWidth = gridWidth;
|
private readonly int gridWidth = gridWidth;
|
||||||
private readonly int gridHeight = gridHeight;
|
private readonly int gridHeight = gridHeight;
|
||||||
private readonly float cellSize = cellSize;
|
private readonly float cellSize = cellSize;
|
||||||
@@ -293,14 +330,16 @@ internal readonly partial struct ReachMaskShader(
|
|||||||
|
|
||||||
var index = y * gridWidth + x;
|
var index = y * gridWidth + x;
|
||||||
var seed = jumpFlood[index];
|
var seed = jumpFlood[index];
|
||||||
if (seed < 0)
|
var inside = 0;
|
||||||
|
if (seed >= 0)
|
||||||
{
|
{
|
||||||
reachMask[index] = 0;
|
var deltaX = (x - seed % gridWidth) * cellSize;
|
||||||
return;
|
var deltaY = (y - seed / gridWidth) * cellSize;
|
||||||
|
inside = deltaX * deltaX + deltaY * deltaY <= reachPixels * reachPixels ? 1 : 0;
|
||||||
}
|
}
|
||||||
var deltaX = (x - seed % gridWidth) * cellSize;
|
reachMask[index] = inside;
|
||||||
var deltaY = (y - seed / gridWidth) * cellSize;
|
if (inside == 0)
|
||||||
reachMask[index] = deltaX * deltaX + deltaY * deltaY <= reachPixels * reachPixels ? 1 : 0;
|
kappa[index] = 1f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,6 +350,10 @@ internal readonly partial struct SupplyShader(
|
|||||||
ReadWriteBuffer<float> surface,
|
ReadWriteBuffer<float> surface,
|
||||||
ReadWriteBuffer<float> flowPigment,
|
ReadWriteBuffer<float> flowPigment,
|
||||||
ReadWriteBuffer<float> density,
|
ReadWriteBuffer<float> density,
|
||||||
|
ReadWriteBuffer<int> reachMask,
|
||||||
|
ReadWriteBuffer<float> deposit,
|
||||||
|
int regionX,
|
||||||
|
int regionY,
|
||||||
int gridWidth,
|
int gridWidth,
|
||||||
int gridHeight) : IComputeShader
|
int gridHeight) : IComputeShader
|
||||||
{
|
{
|
||||||
@@ -318,17 +361,23 @@ internal readonly partial struct SupplyShader(
|
|||||||
private readonly ReadWriteBuffer<float> surface = surface;
|
private readonly ReadWriteBuffer<float> surface = surface;
|
||||||
private readonly ReadWriteBuffer<float> flowPigment = flowPigment;
|
private readonly ReadWriteBuffer<float> flowPigment = flowPigment;
|
||||||
private readonly ReadWriteBuffer<float> density = density;
|
private readonly ReadWriteBuffer<float> density = density;
|
||||||
|
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
||||||
|
private readonly ReadWriteBuffer<float> deposit = deposit;
|
||||||
|
private readonly int regionX = regionX;
|
||||||
|
private readonly int regionY = regionY;
|
||||||
private readonly int gridWidth = gridWidth;
|
private readonly int gridWidth = gridWidth;
|
||||||
private readonly int gridHeight = gridHeight;
|
private readonly int gridHeight = gridHeight;
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
var gx = ThreadIds.X;
|
var gx = ThreadIds.X + regionX;
|
||||||
var gy = ThreadIds.Y;
|
var gy = ThreadIds.Y + regionY;
|
||||||
if (gx >= gridWidth || gy >= gridHeight)
|
if (gx >= gridWidth || gy >= gridHeight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var index = gy * gridWidth + gx;
|
var index = gy * gridWidth + gx;
|
||||||
|
if (reachMask[index] == 0 && deposit[index] == 0f)
|
||||||
|
return;
|
||||||
var gridLength = gridWidth * gridHeight;
|
var gridLength = gridWidth * gridHeight;
|
||||||
var rho = 0f;
|
var rho = 0f;
|
||||||
for (var i = 0; i < 9; i++)
|
for (var i = 0; i < 9; i++)
|
||||||
@@ -354,10 +403,14 @@ internal readonly partial struct KappaShader(
|
|||||||
ReadWriteBuffer<float> density,
|
ReadWriteBuffer<float> density,
|
||||||
ReadWriteBuffer<float> fixedPigment,
|
ReadWriteBuffer<float> fixedPigment,
|
||||||
ReadWriteBuffer<int> reachMask,
|
ReadWriteBuffer<int> reachMask,
|
||||||
|
ReadWriteBuffer<float> fiberField,
|
||||||
|
ReadWriteBuffer<float> alumField,
|
||||||
|
ReadWriteBuffer<float> pinField,
|
||||||
ReadWriteBuffer<float> kappa,
|
ReadWriteBuffer<float> kappa,
|
||||||
|
int regionX,
|
||||||
|
int regionY,
|
||||||
int gridWidth,
|
int gridWidth,
|
||||||
int gridHeight,
|
int gridHeight,
|
||||||
int seed,
|
|
||||||
float fiber,
|
float fiber,
|
||||||
float sizing,
|
float sizing,
|
||||||
float viscosity,
|
float viscosity,
|
||||||
@@ -366,10 +419,14 @@ internal readonly partial struct KappaShader(
|
|||||||
private readonly ReadWriteBuffer<float> density = density;
|
private readonly ReadWriteBuffer<float> density = density;
|
||||||
private readonly ReadWriteBuffer<float> fixedPigment = fixedPigment;
|
private readonly ReadWriteBuffer<float> fixedPigment = fixedPigment;
|
||||||
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
||||||
|
private readonly ReadWriteBuffer<float> fiberField = fiberField;
|
||||||
|
private readonly ReadWriteBuffer<float> alumField = alumField;
|
||||||
|
private readonly ReadWriteBuffer<float> pinField = pinField;
|
||||||
private readonly ReadWriteBuffer<float> kappa = kappa;
|
private readonly ReadWriteBuffer<float> kappa = kappa;
|
||||||
|
private readonly int regionX = regionX;
|
||||||
|
private readonly int regionY = regionY;
|
||||||
private readonly int gridWidth = gridWidth;
|
private readonly int gridWidth = gridWidth;
|
||||||
private readonly int gridHeight = gridHeight;
|
private readonly int gridHeight = gridHeight;
|
||||||
private readonly int seed = seed;
|
|
||||||
private readonly float fiber = fiber;
|
private readonly float fiber = fiber;
|
||||||
private readonly float sizing = sizing;
|
private readonly float sizing = sizing;
|
||||||
private readonly float viscosity = viscosity;
|
private readonly float viscosity = viscosity;
|
||||||
@@ -377,21 +434,18 @@ internal readonly partial struct KappaShader(
|
|||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
var gx = ThreadIds.X;
|
var gx = ThreadIds.X + regionX;
|
||||||
var gy = ThreadIds.Y;
|
var gy = ThreadIds.Y + regionY;
|
||||||
if (gx >= gridWidth || gy >= gridHeight)
|
if (gx >= gridWidth || gy >= gridHeight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var index = gy * gridWidth + gx;
|
var index = gy * gridWidth + gx;
|
||||||
if (reachMask[index] == 0)
|
if (reachMask[index] == 0)
|
||||||
{
|
|
||||||
kappa[index] = 1f;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (density[index] <= InkDispersionSettings.WetEpsilon)
|
if (density[index] <= InkDispersionSettings.WetEpsilon)
|
||||||
{
|
{
|
||||||
var pin = InkDispersionShaderMath.PinField(gx, gy, seed);
|
var pin = pinField[index];
|
||||||
var accumulated = Hlsl.Min(fixedPigment[index], 1f);
|
var accumulated = Hlsl.Min(fixedPigment[index], 1f);
|
||||||
var threshold = sigma * (0.4f + 0.6f * pin) * (1f + accumulated);
|
var threshold = sigma * (0.4f + 0.6f * pin) * (1f + accumulated);
|
||||||
var pinned = true;
|
var pinned = true;
|
||||||
@@ -413,8 +467,8 @@ internal readonly partial struct KappaShader(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var grain = InkDispersionShaderMath.FiberField(gx, gy, seed);
|
var grain = fiberField[index];
|
||||||
var alum = InkDispersionShaderMath.AlumField(gx, gy, seed);
|
var alum = alumField[index];
|
||||||
var blocking = InkDispersionSettings.KappaBase
|
var blocking = InkDispersionSettings.KappaBase
|
||||||
+ InkDispersionSettings.KappaFiber * fiber * grain
|
+ InkDispersionSettings.KappaFiber * fiber * grain
|
||||||
+ InkDispersionSettings.KappaAlum * sizing * alum
|
+ InkDispersionSettings.KappaAlum * sizing * alum
|
||||||
@@ -431,8 +485,11 @@ internal readonly partial struct StreamCollideShader(
|
|||||||
ReadWriteBuffer<float> distributionsOut,
|
ReadWriteBuffer<float> distributionsOut,
|
||||||
ReadWriteBuffer<float> kappa,
|
ReadWriteBuffer<float> kappa,
|
||||||
ReadWriteBuffer<int> reachMask,
|
ReadWriteBuffer<int> reachMask,
|
||||||
|
ReadWriteBuffer<float> deposit,
|
||||||
ReadWriteBuffer<float> densityOut,
|
ReadWriteBuffer<float> densityOut,
|
||||||
ReadWriteBuffer<Float2> velocity,
|
ReadWriteBuffer<Float2> velocity,
|
||||||
|
int regionX,
|
||||||
|
int regionY,
|
||||||
int gridWidth,
|
int gridWidth,
|
||||||
int gridHeight,
|
int gridHeight,
|
||||||
float omega,
|
float omega,
|
||||||
@@ -442,8 +499,11 @@ internal readonly partial struct StreamCollideShader(
|
|||||||
private readonly ReadWriteBuffer<float> distributionsOut = distributionsOut;
|
private readonly ReadWriteBuffer<float> distributionsOut = distributionsOut;
|
||||||
private readonly ReadWriteBuffer<float> kappa = kappa;
|
private readonly ReadWriteBuffer<float> kappa = kappa;
|
||||||
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
||||||
|
private readonly ReadWriteBuffer<float> deposit = deposit;
|
||||||
private readonly ReadWriteBuffer<float> densityOut = densityOut;
|
private readonly ReadWriteBuffer<float> densityOut = densityOut;
|
||||||
private readonly ReadWriteBuffer<Float2> velocity = velocity;
|
private readonly ReadWriteBuffer<Float2> velocity = velocity;
|
||||||
|
private readonly int regionX = regionX;
|
||||||
|
private readonly int regionY = regionY;
|
||||||
private readonly int gridWidth = gridWidth;
|
private readonly int gridWidth = gridWidth;
|
||||||
private readonly int gridHeight = gridHeight;
|
private readonly int gridHeight = gridHeight;
|
||||||
private readonly float omega = omega;
|
private readonly float omega = omega;
|
||||||
@@ -451,8 +511,8 @@ internal readonly partial struct StreamCollideShader(
|
|||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
var gx = ThreadIds.X;
|
var gx = ThreadIds.X + regionX;
|
||||||
var gy = ThreadIds.Y;
|
var gy = ThreadIds.Y + regionY;
|
||||||
if (gx >= gridWidth || gy >= gridHeight)
|
if (gx >= gridWidth || gy >= gridHeight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -460,6 +520,8 @@ internal readonly partial struct StreamCollideShader(
|
|||||||
var gridLength = gridWidth * gridHeight;
|
var gridLength = gridWidth * gridHeight;
|
||||||
if (reachMask[index] == 0)
|
if (reachMask[index] == 0)
|
||||||
{
|
{
|
||||||
|
if (deposit[index] == 0f)
|
||||||
|
return;
|
||||||
for (var i = 0; i < 9; i++)
|
for (var i = 0; i < 9; i++)
|
||||||
distributionsOut[i * gridLength + index] = 0f;
|
distributionsOut[i * gridLength + index] = 0f;
|
||||||
densityOut[index] = 0f;
|
densityOut[index] = 0f;
|
||||||
@@ -559,11 +621,14 @@ internal readonly partial struct PigmentShader(
|
|||||||
ReadWriteBuffer<float> wetness,
|
ReadWriteBuffer<float> wetness,
|
||||||
ReadWriteBuffer<int> inkStep,
|
ReadWriteBuffer<int> inkStep,
|
||||||
ReadWriteBuffer<int> reachMask,
|
ReadWriteBuffer<int> reachMask,
|
||||||
|
ReadWriteBuffer<float> deposit,
|
||||||
|
ReadWriteBuffer<float> fiberField,
|
||||||
ReadWriteBuffer<int> scratch,
|
ReadWriteBuffer<int> scratch,
|
||||||
|
int regionX,
|
||||||
|
int regionY,
|
||||||
int gridWidth,
|
int gridWidth,
|
||||||
int gridHeight,
|
int gridHeight,
|
||||||
int step,
|
int step,
|
||||||
int seed,
|
|
||||||
float fiber,
|
float fiber,
|
||||||
float viscosity) : IComputeShader
|
float viscosity) : IComputeShader
|
||||||
{
|
{
|
||||||
@@ -577,25 +642,29 @@ internal readonly partial struct PigmentShader(
|
|||||||
private readonly ReadWriteBuffer<float> wetness = wetness;
|
private readonly ReadWriteBuffer<float> wetness = wetness;
|
||||||
private readonly ReadWriteBuffer<int> inkStep = inkStep;
|
private readonly ReadWriteBuffer<int> inkStep = inkStep;
|
||||||
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
||||||
|
private readonly ReadWriteBuffer<float> deposit = deposit;
|
||||||
|
private readonly ReadWriteBuffer<float> fiberField = fiberField;
|
||||||
private readonly ReadWriteBuffer<int> scratch = scratch;
|
private readonly ReadWriteBuffer<int> scratch = scratch;
|
||||||
|
private readonly int regionX = regionX;
|
||||||
|
private readonly int regionY = regionY;
|
||||||
private readonly int gridWidth = gridWidth;
|
private readonly int gridWidth = gridWidth;
|
||||||
private readonly int gridHeight = gridHeight;
|
private readonly int gridHeight = gridHeight;
|
||||||
private readonly int step = step;
|
private readonly int step = step;
|
||||||
private readonly int seed = seed;
|
|
||||||
private readonly float fiber = fiber;
|
private readonly float fiber = fiber;
|
||||||
private readonly float viscosity = viscosity;
|
private readonly float viscosity = viscosity;
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
var gx = ThreadIds.X;
|
var gx = ThreadIds.X + regionX;
|
||||||
var gy = ThreadIds.Y;
|
var gy = ThreadIds.Y + regionY;
|
||||||
if (gx >= gridWidth || gy >= gridHeight)
|
if (gx >= gridWidth || gy >= gridHeight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var index = gy * gridWidth + gx;
|
var index = gy * gridWidth + gx;
|
||||||
if (reachMask[index] == 0)
|
if (reachMask[index] == 0)
|
||||||
{
|
{
|
||||||
flowPigmentOut[index] = 0f;
|
if (deposit[index] != 0f)
|
||||||
|
flowPigmentOut[index] = 0f;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,7 +720,7 @@ internal readonly partial struct PigmentShader(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var speed = Hlsl.Sqrt(u.X * u.X + u.Y * u.Y);
|
var speed = Hlsl.Sqrt(u.X * u.X + u.Y * u.Y);
|
||||||
var grain = InkDispersionShaderMath.FiberField(gx, gy, seed);
|
var grain = fiberField[index];
|
||||||
var hindrance = Hlsl.Saturate(InkDispersionSettings.HindranceBase + InkDispersionSettings.HindranceFiber * fiber * grain);
|
var hindrance = Hlsl.Saturate(InkDispersionSettings.HindranceBase + InkDispersionSettings.HindranceFiber * fiber * grain);
|
||||||
var mix = Hlsl.Lerp(1f, hindrance, Hlsl.SmoothStep(0f, InkDispersionSettings.HindranceSpeed, speed));
|
var mix = Hlsl.Lerp(1f, hindrance, Hlsl.SmoothStep(0f, InkDispersionSettings.HindranceSpeed, speed));
|
||||||
advected = Hlsl.Lerp(advected, pigment, mix);
|
advected = Hlsl.Lerp(advected, pigment, mix);
|
||||||
|
|||||||
@@ -1,33 +1,20 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using ComputeSharp;
|
using ComputeWeave;
|
||||||
|
|
||||||
namespace InkDispersion;
|
namespace InkDispersion;
|
||||||
|
|
||||||
internal sealed class InkDispersionPipeline : IDisposable
|
internal sealed class InkDispersionPipeline : IDisposable
|
||||||
{
|
{
|
||||||
private readonly GraphicsDevice _device;
|
private readonly GraphicsDevice _device;
|
||||||
|
private readonly InkDispersionPipelineHost _host;
|
||||||
private readonly ReadWriteBuffer<int> _scratch;
|
private readonly ReadWriteBuffer<int> _scratch;
|
||||||
private readonly ReadBackBuffer<int> _scratchReadBack;
|
private readonly ReadBackBuffer<int> _scratchReadBack;
|
||||||
private readonly int[] _boundsMinX;
|
private readonly int[] _boundsMinX;
|
||||||
private readonly int[] _boundsMinY;
|
private readonly int[] _boundsMinY;
|
||||||
private readonly int[] _boundsMaxX;
|
private readonly int[] _boundsMaxX;
|
||||||
private readonly int[] _boundsMaxY;
|
private readonly int[] _boundsMaxY;
|
||||||
private ReadWriteBuffer<float>? _distributionsA;
|
|
||||||
private ReadWriteBuffer<float>? _distributionsB;
|
|
||||||
private ReadWriteBuffer<float>? _deposit;
|
|
||||||
private ReadWriteBuffer<float>? _surface;
|
|
||||||
private ReadWriteBuffer<float>? _flowPigmentA;
|
|
||||||
private ReadWriteBuffer<float>? _flowPigmentB;
|
|
||||||
private ReadWriteBuffer<float>? _fixedPigment;
|
|
||||||
private ReadWriteBuffer<float>? _densityA;
|
|
||||||
private ReadWriteBuffer<float>? _densityB;
|
|
||||||
private ReadWriteBuffer<float>? _kappa;
|
|
||||||
private ReadWriteBuffer<float>? _wetness;
|
|
||||||
private ReadWriteBuffer<Float2>? _velocity;
|
|
||||||
private ReadWriteBuffer<int>? _inkStep;
|
private ReadWriteBuffer<int>? _inkStep;
|
||||||
private ReadWriteBuffer<int>? _reachMask;
|
|
||||||
private ReadWriteBuffer<int>? _jumpFloodA;
|
|
||||||
private ReadWriteBuffer<int>? _jumpFloodB;
|
|
||||||
private ReadBackBuffer<int>? _inkStepReadBack;
|
private ReadBackBuffer<int>? _inkStepReadBack;
|
||||||
private int[]? _cachedInkStep;
|
private int[]? _cachedInkStep;
|
||||||
private int _cachedMaxInkStep;
|
private int _cachedMaxInkStep;
|
||||||
@@ -40,9 +27,10 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
private int _packedWidth;
|
private int _packedWidth;
|
||||||
private int _packedHeight;
|
private int _packedHeight;
|
||||||
|
|
||||||
private InkDispersionPipeline(GraphicsDevice device)
|
private InkDispersionPipeline(GraphicsDevice device, InkDispersionPipelineHost host)
|
||||||
{
|
{
|
||||||
_device = device;
|
_device = device;
|
||||||
|
_host = host;
|
||||||
_scratch = device.AllocateReadWriteBuffer<int>(InkDispersionSettings.ScratchLength);
|
_scratch = device.AllocateReadWriteBuffer<int>(InkDispersionSettings.ScratchLength);
|
||||||
_scratchReadBack = device.AllocateReadBackBuffer<int>(InkDispersionSettings.ScratchLength);
|
_scratchReadBack = device.AllocateReadBackBuffer<int>(InkDispersionSettings.ScratchLength);
|
||||||
_boundsMinX = new int[InkDispersionSettings.MaximumStepCount + 1];
|
_boundsMinX = new int[InkDispersionSettings.MaximumStepCount + 1];
|
||||||
@@ -55,7 +43,7 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new InkDispersionPipeline(GraphicsDevice.GetDefault());
|
return TryCreate(GraphicsDevice.GetDefault());
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -65,14 +53,23 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
|
|
||||||
public static InkDispersionPipeline? TryCreate(GraphicsDevice device)
|
public static InkDispersionPipeline? TryCreate(GraphicsDevice device)
|
||||||
{
|
{
|
||||||
|
InkDispersionPipelineHost? host = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new InkDispersionPipeline(device);
|
host = InkDispersionPipelineHost.Create(device, InkDispersionSettings.MaximumPendingSubmissions);
|
||||||
|
var pipeline = new InkDispersionPipeline(device, host);
|
||||||
|
host = null;
|
||||||
|
return pipeline;
|
||||||
}
|
}
|
||||||
catch
|
catch (Win32Exception)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
host?.Dispose();
|
||||||
|
host?.WaitForDisposal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void WaitForCompletion()
|
internal void WaitForCompletion()
|
||||||
@@ -88,8 +85,7 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
var sourceTexture = _packedSource!;
|
var sourceTexture = _packedSource!;
|
||||||
var outputTexture = _packedOutput!;
|
var outputTexture = _packedOutput!;
|
||||||
sourceTexture.CopyFrom(MemoryMarshal.Cast<int, Bgra32>(source[..pixelCount]));
|
sourceTexture.CopyFrom(MemoryMarshal.Cast<int, Bgra32>(source[..pixelCount]));
|
||||||
using (ComputeContext context = _device.CreateComputeContext())
|
SubmitFullPipeline(sourceTexture, outputTexture, width, height, in parameters).Wait();
|
||||||
RecordFullPipeline(in context, sourceTexture, outputTexture, width, height, in parameters);
|
|
||||||
outputTexture.CopyTo(MemoryMarshal.Cast<int, Bgra32>(destination[..pixelCount]));
|
outputTexture.CopyTo(MemoryMarshal.Cast<int, Bgra32>(destination[..pixelCount]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,9 +97,7 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
in Parameters parameters)
|
in Parameters parameters)
|
||||||
{
|
{
|
||||||
EnsureGridFor(width, height, parameters.Quality);
|
EnsureGridFor(width, height, parameters.Quality);
|
||||||
using ComputeContext context = _device.CreateComputeContext();
|
_ = SubmitFullPipeline(source, destination, width, height, in parameters);
|
||||||
RecordFullPipeline(in context, source, destination, width, height, in parameters);
|
|
||||||
context.Submit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ProcessSharedAndWait(
|
internal void ProcessSharedAndWait(
|
||||||
@@ -114,8 +108,7 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
in Parameters parameters)
|
in Parameters parameters)
|
||||||
{
|
{
|
||||||
EnsureGridFor(width, height, parameters.Quality);
|
EnsureGridFor(width, height, parameters.Quality);
|
||||||
using ComputeContext context = _device.CreateComputeContext();
|
SubmitFullPipeline(source, destination, width, height, in parameters).Wait();
|
||||||
RecordFullPipeline(in context, source, destination, width, height, in parameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool Simulate(
|
internal bool Simulate(
|
||||||
@@ -127,19 +120,42 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
int sourceWidth,
|
int sourceWidth,
|
||||||
int sourceHeight,
|
int sourceHeight,
|
||||||
in Parameters parameters)
|
in Parameters parameters)
|
||||||
|
{
|
||||||
|
var derived = BeginSimulate(canvasWidth, canvasHeight, in parameters);
|
||||||
|
_host.RecordSilhouetteAndMaskHash(
|
||||||
|
source, _scratch, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, _gridWidth, _gridHeight, in derived).Wait();
|
||||||
|
return CompleteSimulate(canvasWidth, canvasHeight, in parameters, in derived);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool Simulate(
|
||||||
|
ComputeResourceBinding<ReadWriteTexture2D<Bgra32, Float4>> source,
|
||||||
|
int canvasWidth,
|
||||||
|
int canvasHeight,
|
||||||
|
int sourceOffsetX,
|
||||||
|
int sourceOffsetY,
|
||||||
|
int sourceWidth,
|
||||||
|
int sourceHeight,
|
||||||
|
in Parameters parameters)
|
||||||
|
{
|
||||||
|
var derived = BeginSimulate(canvasWidth, canvasHeight, in parameters);
|
||||||
|
_host.RecordSharedSilhouetteAndMaskHash(
|
||||||
|
source, _scratch, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, _gridWidth, _gridHeight, in derived).Wait();
|
||||||
|
return CompleteSimulate(canvasWidth, canvasHeight, in parameters, in derived);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DerivedValues BeginSimulate(int canvasWidth, int canvasHeight, in Parameters parameters)
|
||||||
{
|
{
|
||||||
EnsureGridFor(canvasWidth, canvasHeight, parameters.Quality);
|
EnsureGridFor(canvasWidth, canvasHeight, parameters.Quality);
|
||||||
var derived = Derive(canvasWidth, canvasHeight, in parameters);
|
return Derive(canvasWidth, canvasHeight, in parameters);
|
||||||
using (ComputeContext context = _device.CreateComputeContext())
|
}
|
||||||
{
|
|
||||||
RecordSilhouetteStage(in context, source, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, in derived);
|
private bool CompleteSimulate(int canvasWidth, int canvasHeight, in Parameters parameters, in DerivedValues derived)
|
||||||
RecordMaskHashStage(in context);
|
{
|
||||||
}
|
|
||||||
_scratchReadBack.CopyFrom(_scratch);
|
_scratchReadBack.CopyFrom(_scratch);
|
||||||
var hashed = _scratchReadBack.Span;
|
var hashed = _scratchReadBack.Span;
|
||||||
var key = new StructureKey(
|
var key = new StructureKey(
|
||||||
hashed[6],
|
hashed[InkDispersionSettings.ScratchMaskHashSum],
|
||||||
hashed[7],
|
hashed[InkDispersionSettings.ScratchMaskHashMix],
|
||||||
canvasWidth,
|
canvasWidth,
|
||||||
canvasHeight,
|
canvasHeight,
|
||||||
parameters.Quality,
|
parameters.Quality,
|
||||||
@@ -153,14 +169,25 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
if (_structureKey == key)
|
if (_structureKey == key)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
using (ComputeContext context = _device.CreateComputeContext())
|
var region = GetFlowRegion(
|
||||||
RecordFlowStage(in context, in derived, in parameters);
|
hashed[InkDispersionSettings.ScratchBoundsMinX],
|
||||||
|
hashed[InkDispersionSettings.ScratchBoundsMinY],
|
||||||
|
hashed[InkDispersionSettings.ScratchBoundsMaxX],
|
||||||
|
hashed[InkDispersionSettings.ScratchBoundsMaxY],
|
||||||
|
in derived);
|
||||||
|
_ = _host.RecordFlowSetup(_scratch, _inkStep!, _gridWidth, _gridHeight, in derived, in parameters);
|
||||||
|
for (var firstStep = 0; firstStep < derived.Steps; firstStep += InkDispersionSettings.FlowStepsPerSubmission)
|
||||||
|
{
|
||||||
|
var stepCount = Math.Min(InkDispersionSettings.FlowStepsPerSubmission, derived.Steps - firstStep);
|
||||||
|
_ = _host.RecordFlowSteps(_scratch, _inkStep!, in region, _gridWidth, _gridHeight, in derived, firstStep, stepCount);
|
||||||
|
}
|
||||||
|
_host.RecordFlowFinish(_scratch, _gridWidth, _gridHeight, in derived).Wait();
|
||||||
_scratchReadBack.CopyFrom(_scratch);
|
_scratchReadBack.CopyFrom(_scratch);
|
||||||
var wetStepReadBack = _inkStepReadBack!;
|
var wetStepReadBack = _inkStepReadBack!;
|
||||||
wetStepReadBack.CopyFrom(_inkStep!);
|
wetStepReadBack.CopyFrom(_inkStep!);
|
||||||
var scratch = _scratchReadBack.Span;
|
var scratch = _scratchReadBack.Span;
|
||||||
_cachedInkCount = scratch[0];
|
_cachedInkCount = scratch[InkDispersionSettings.ScratchWetCount];
|
||||||
_cachedMaxInkStep = scratch[1];
|
_cachedMaxInkStep = scratch[InkDispersionSettings.ScratchMaxWetStep];
|
||||||
wetStepReadBack.Span.CopyTo(_cachedInkStep!);
|
wetStepReadBack.Span.CopyTo(_cachedInkStep!);
|
||||||
BuildBoundsPrefix();
|
BuildBoundsPrefix();
|
||||||
_structureKey = key;
|
_structureKey = key;
|
||||||
@@ -204,12 +231,21 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
in Parameters parameters)
|
in Parameters parameters)
|
||||||
{
|
{
|
||||||
var derived = Derive(canvasWidth, canvasHeight, in parameters);
|
var derived = Derive(canvasWidth, canvasHeight, in parameters);
|
||||||
using ComputeContext context = _device.CreateComputeContext();
|
_host.RecordRender(output, _scratch, _inkStep!, in rect, _gridWidth, _gridHeight, in derived, in parameters).Wait();
|
||||||
RecordRenderStage(in context, output, rect, in derived, in parameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RecordFullPipeline(
|
internal void RenderVisible(
|
||||||
in ComputeContext context,
|
ComputeResourceBinding<ReadWriteTexture2D<Bgra32, Float4>> output,
|
||||||
|
int canvasWidth,
|
||||||
|
int canvasHeight,
|
||||||
|
PixelRect rect,
|
||||||
|
in Parameters parameters)
|
||||||
|
{
|
||||||
|
var derived = Derive(canvasWidth, canvasHeight, in parameters);
|
||||||
|
_host.RecordSharedRender(output, _scratch, _inkStep!, in rect, _gridWidth, _gridHeight, in derived, in parameters).Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ComputeSubmission SubmitFullPipeline(
|
||||||
ReadWriteTexture2D<Bgra32, Float4> source,
|
ReadWriteTexture2D<Bgra32, Float4> source,
|
||||||
ReadWriteTexture2D<Bgra32, Float4> output,
|
ReadWriteTexture2D<Bgra32, Float4> output,
|
||||||
int width,
|
int width,
|
||||||
@@ -218,125 +254,20 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
{
|
{
|
||||||
_structureKey = null;
|
_structureKey = null;
|
||||||
var derived = Derive(width, height, in parameters);
|
var derived = Derive(width, height, in parameters);
|
||||||
RecordSilhouetteStage(in context, source, 0, 0, width, height, in derived);
|
return _host.RecordFullPipeline(source, output, _scratch, _inkStep!, width, height, _gridWidth, _gridHeight, in derived, in parameters);
|
||||||
RecordFlowStage(in context, in derived, in parameters);
|
|
||||||
RecordRenderStage(in context, output, new PixelRect(0, 0, width, height), in derived, in parameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RecordSilhouetteStage(
|
private CellRect GetFlowRegion(int minX, int minY, int maxX, int maxY, in DerivedValues derived)
|
||||||
in ComputeContext context,
|
|
||||||
ReadWriteTexture2D<Bgra32, Float4> source,
|
|
||||||
int sourceOffsetX,
|
|
||||||
int sourceOffsetY,
|
|
||||||
int sourceWidth,
|
|
||||||
int sourceHeight,
|
|
||||||
in DerivedValues derived)
|
|
||||||
{
|
{
|
||||||
context.For(_gridWidth, _gridHeight, new SilhouetteShader(
|
if (minX > maxX || minY > maxY)
|
||||||
source, _deposit!, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, _gridWidth, _gridHeight, derived.CellSize));
|
return new CellRect(0, 0, _gridWidth, _gridHeight);
|
||||||
context.Barrier(_deposit!);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RecordMaskHashStage(in ComputeContext context)
|
var dilation = (int)MathF.Ceiling(derived.ReachPixels / derived.CellSize);
|
||||||
{
|
var left = Math.Max(minX - dilation, 0);
|
||||||
context.For(1, new MaskHashResetShader(_scratch));
|
var top = Math.Max(minY - dilation, 0);
|
||||||
context.Barrier(_scratch);
|
var right = Math.Min(maxX + dilation + 1, _gridWidth);
|
||||||
context.For(_gridWidth, _gridHeight, new MaskHashShader(_deposit!, _scratch, _gridWidth, _gridHeight));
|
var bottom = Math.Min(maxY + dilation + 1, _gridHeight);
|
||||||
context.Barrier(_scratch);
|
return new CellRect(left, top, right - left, bottom - top);
|
||||||
}
|
|
||||||
|
|
||||||
private void RecordFlowStage(
|
|
||||||
in ComputeContext context,
|
|
||||||
in DerivedValues derived,
|
|
||||||
in Parameters parameters)
|
|
||||||
{
|
|
||||||
var gridWidth = _gridWidth;
|
|
||||||
var gridHeight = _gridHeight;
|
|
||||||
|
|
||||||
context.For(1, new InitScratchShader(_scratch));
|
|
||||||
context.Barrier(_scratch);
|
|
||||||
context.For(gridWidth, gridHeight, new InitFieldShader(
|
|
||||||
_distributionsA!, _deposit!, _surface!, _flowPigmentA!, _fixedPigment!, _densityA!, _wetness!, _velocity!, _inkStep!,
|
|
||||||
gridWidth, gridHeight, derived.Deposit));
|
|
||||||
context.Barrier(_distributionsA!);
|
|
||||||
context.Barrier(_surface!);
|
|
||||||
context.Barrier(_flowPigmentA!);
|
|
||||||
context.Barrier(_fixedPigment!);
|
|
||||||
context.Barrier(_densityA!);
|
|
||||||
context.Barrier(_wetness!);
|
|
||||||
context.Barrier(_velocity!);
|
|
||||||
context.Barrier(_inkStep!);
|
|
||||||
|
|
||||||
context.For(gridWidth, gridHeight, new JumpFloodSeedShader(_deposit!, _jumpFloodA!, gridWidth, gridHeight));
|
|
||||||
context.Barrier(_jumpFloodA!);
|
|
||||||
var reading = _jumpFloodA!;
|
|
||||||
var writing = _jumpFloodB!;
|
|
||||||
var stepSize = 1;
|
|
||||||
var maxSide = Math.Max(gridWidth, gridHeight);
|
|
||||||
while (stepSize < maxSide)
|
|
||||||
stepSize <<= 1;
|
|
||||||
stepSize >>= 1;
|
|
||||||
while (stepSize >= 1)
|
|
||||||
{
|
|
||||||
context.For(gridWidth, gridHeight, new JumpFloodPassShader(reading, writing, gridWidth, gridHeight, stepSize));
|
|
||||||
context.Barrier(writing);
|
|
||||||
(reading, writing) = (writing, reading);
|
|
||||||
stepSize >>= 1;
|
|
||||||
}
|
|
||||||
context.For(gridWidth, gridHeight, new ReachMaskShader(reading, _reachMask!, gridWidth, gridHeight, derived.CellSize, derived.ReachPixels));
|
|
||||||
context.Barrier(_reachMask!);
|
|
||||||
|
|
||||||
var distributionsIn = _distributionsA!;
|
|
||||||
var distributionsOut = _distributionsB!;
|
|
||||||
var pigmentIn = _flowPigmentA!;
|
|
||||||
var pigmentOut = _flowPigmentB!;
|
|
||||||
for (var step = 0; step < derived.Steps; step++)
|
|
||||||
{
|
|
||||||
context.For(gridWidth, gridHeight, new SupplyShader(
|
|
||||||
distributionsIn, _surface!, pigmentIn, _densityA!, gridWidth, gridHeight));
|
|
||||||
context.Barrier(distributionsIn);
|
|
||||||
context.Barrier(_surface!);
|
|
||||||
context.Barrier(pigmentIn);
|
|
||||||
context.Barrier(_densityA!);
|
|
||||||
context.For(gridWidth, gridHeight, new KappaShader(
|
|
||||||
_densityA!, _fixedPigment!, _reachMask!, _kappa!, gridWidth, gridHeight,
|
|
||||||
parameters.Seed, derived.Fiber, derived.Sizing, derived.Viscosity, derived.Sigma));
|
|
||||||
context.Barrier(_kappa!);
|
|
||||||
context.For(gridWidth, gridHeight, new StreamCollideShader(
|
|
||||||
distributionsIn, distributionsOut, _kappa!, _reachMask!, _densityB!, _velocity!,
|
|
||||||
gridWidth, gridHeight, derived.Omega, derived.SurfaceEvaporation));
|
|
||||||
context.Barrier(distributionsOut);
|
|
||||||
context.Barrier(_densityB!);
|
|
||||||
context.Barrier(_velocity!);
|
|
||||||
context.For(gridWidth, gridHeight, new PigmentShader(
|
|
||||||
distributionsOut, _densityA!, _densityB!, _velocity!, pigmentIn, pigmentOut,
|
|
||||||
_fixedPigment!, _wetness!, _inkStep!, _reachMask!, _scratch,
|
|
||||||
gridWidth, gridHeight, step, parameters.Seed, derived.Fiber, derived.Viscosity));
|
|
||||||
context.Barrier(pigmentOut);
|
|
||||||
context.Barrier(_fixedPigment!);
|
|
||||||
context.Barrier(_wetness!);
|
|
||||||
context.Barrier(_inkStep!);
|
|
||||||
(distributionsIn, distributionsOut) = (distributionsOut, distributionsIn);
|
|
||||||
(pigmentIn, pigmentOut) = (pigmentOut, pigmentIn);
|
|
||||||
}
|
|
||||||
context.For(gridWidth, gridHeight, new FinalFixShader(pigmentIn, _fixedPigment!, gridWidth, gridHeight));
|
|
||||||
context.Barrier(_fixedPigment!);
|
|
||||||
context.Barrier(_scratch);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RecordRenderStage(
|
|
||||||
in ComputeContext context,
|
|
||||||
ReadWriteTexture2D<Bgra32, Float4> output,
|
|
||||||
PixelRect rect,
|
|
||||||
in DerivedValues derived,
|
|
||||||
in Parameters parameters)
|
|
||||||
{
|
|
||||||
context.For(rect.Width, rect.Height, new RenderShader(
|
|
||||||
_inkStep!, _fixedPigment!, _wetness!, _scratch, output,
|
|
||||||
rect.X, rect.Y, rect.Width, rect.Height, _gridWidth, _gridHeight,
|
|
||||||
derived.CellSize, Math.Clamp(parameters.Spread, 0f, 1f),
|
|
||||||
Math.Clamp(parameters.Density, 0f, 1f), Math.Clamp(parameters.Grain, 0f, 1f),
|
|
||||||
parameters.ColorR, parameters.ColorG, parameters.ColorB, parameters.Seed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildBoundsPrefix()
|
private void BuildBoundsPrefix()
|
||||||
@@ -409,28 +340,43 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
|
|
||||||
private void EnsureGrid(int gridWidth, int gridHeight)
|
private void EnsureGrid(int gridWidth, int gridHeight)
|
||||||
{
|
{
|
||||||
if (_gridWidth == gridWidth && _gridHeight == gridHeight)
|
var resized = _gridWidth != gridWidth || _gridHeight != gridHeight;
|
||||||
return;
|
if (resized)
|
||||||
|
DisposeGridBuffers();
|
||||||
|
|
||||||
DisposeGridBuffers();
|
|
||||||
var gridLength = gridWidth * gridHeight;
|
var gridLength = gridWidth * gridHeight;
|
||||||
var distributionLength = gridLength * 9;
|
var distributionLength = gridLength * 9;
|
||||||
_distributionsA = _device.AllocateReadWriteBuffer<float>(distributionLength);
|
if (!_host.TryEnsureGrid(
|
||||||
_distributionsB = _device.AllocateReadWriteBuffer<float>(distributionLength);
|
new InkDispersionGridResources.Plan(
|
||||||
_deposit = _device.AllocateReadWriteBuffer<float>(gridLength);
|
alumFieldLength: gridLength,
|
||||||
_surface = _device.AllocateReadWriteBuffer<float>(gridLength);
|
densityALength: gridLength,
|
||||||
_flowPigmentA = _device.AllocateReadWriteBuffer<float>(gridLength);
|
densityBLength: gridLength,
|
||||||
_flowPigmentB = _device.AllocateReadWriteBuffer<float>(gridLength);
|
depositLength: gridLength,
|
||||||
_fixedPigment = _device.AllocateReadWriteBuffer<float>(gridLength);
|
distributionsALength: distributionLength,
|
||||||
_densityA = _device.AllocateReadWriteBuffer<float>(gridLength);
|
distributionsBLength: distributionLength,
|
||||||
_densityB = _device.AllocateReadWriteBuffer<float>(gridLength);
|
fiberFieldLength: gridLength,
|
||||||
_kappa = _device.AllocateReadWriteBuffer<float>(gridLength);
|
fixedPigmentLength: gridLength,
|
||||||
_wetness = _device.AllocateReadWriteBuffer<float>(gridLength);
|
flowPigmentALength: gridLength,
|
||||||
_velocity = _device.AllocateReadWriteBuffer<Float2>(gridLength);
|
flowPigmentBLength: gridLength,
|
||||||
|
jumpFloodALength: gridLength,
|
||||||
|
jumpFloodBLength: gridLength,
|
||||||
|
kappaLength: gridLength,
|
||||||
|
pinFieldLength: gridLength,
|
||||||
|
reachMaskLength: gridLength,
|
||||||
|
surfaceLength: gridLength,
|
||||||
|
velocityLength: gridLength,
|
||||||
|
wetnessLength: gridLength),
|
||||||
|
out var changed))
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
|
||||||
|
if (!resized)
|
||||||
|
{
|
||||||
|
if (changed)
|
||||||
|
_structureKey = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_inkStep = _device.AllocateReadWriteBuffer<int>(gridLength);
|
_inkStep = _device.AllocateReadWriteBuffer<int>(gridLength);
|
||||||
_reachMask = _device.AllocateReadWriteBuffer<int>(gridLength);
|
|
||||||
_jumpFloodA = _device.AllocateReadWriteBuffer<int>(gridLength);
|
|
||||||
_jumpFloodB = _device.AllocateReadWriteBuffer<int>(gridLength);
|
|
||||||
_inkStepReadBack = _device.AllocateReadBackBuffer<int>(gridLength);
|
_inkStepReadBack = _device.AllocateReadBackBuffer<int>(gridLength);
|
||||||
_cachedInkStep = new int[gridLength];
|
_cachedInkStep = new int[gridLength];
|
||||||
_cachedMaxInkStep = -1;
|
_cachedMaxInkStep = -1;
|
||||||
@@ -454,39 +400,9 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
|
|
||||||
private void DisposeGridBuffers()
|
private void DisposeGridBuffers()
|
||||||
{
|
{
|
||||||
_distributionsA?.Dispose();
|
|
||||||
_distributionsB?.Dispose();
|
|
||||||
_deposit?.Dispose();
|
|
||||||
_surface?.Dispose();
|
|
||||||
_flowPigmentA?.Dispose();
|
|
||||||
_flowPigmentB?.Dispose();
|
|
||||||
_fixedPigment?.Dispose();
|
|
||||||
_densityA?.Dispose();
|
|
||||||
_densityB?.Dispose();
|
|
||||||
_kappa?.Dispose();
|
|
||||||
_wetness?.Dispose();
|
|
||||||
_velocity?.Dispose();
|
|
||||||
_inkStep?.Dispose();
|
_inkStep?.Dispose();
|
||||||
_reachMask?.Dispose();
|
|
||||||
_jumpFloodA?.Dispose();
|
|
||||||
_jumpFloodB?.Dispose();
|
|
||||||
_inkStepReadBack?.Dispose();
|
_inkStepReadBack?.Dispose();
|
||||||
_distributionsA = null;
|
|
||||||
_distributionsB = null;
|
|
||||||
_deposit = null;
|
|
||||||
_surface = null;
|
|
||||||
_flowPigmentA = null;
|
|
||||||
_flowPigmentB = null;
|
|
||||||
_fixedPigment = null;
|
|
||||||
_densityA = null;
|
|
||||||
_densityB = null;
|
|
||||||
_kappa = null;
|
|
||||||
_wetness = null;
|
|
||||||
_velocity = null;
|
|
||||||
_inkStep = null;
|
_inkStep = null;
|
||||||
_reachMask = null;
|
|
||||||
_jumpFloodA = null;
|
|
||||||
_jumpFloodB = null;
|
|
||||||
_inkStepReadBack = null;
|
_inkStepReadBack = null;
|
||||||
_cachedInkStep = null;
|
_cachedInkStep = null;
|
||||||
_cachedMaxInkStep = -1;
|
_cachedMaxInkStep = -1;
|
||||||
@@ -498,6 +414,8 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
_host.Dispose();
|
||||||
|
_host.WaitForDisposal();
|
||||||
DisposeGridBuffers();
|
DisposeGridBuffers();
|
||||||
_packedSource?.Dispose();
|
_packedSource?.Dispose();
|
||||||
_packedOutput?.Dispose();
|
_packedOutput?.Dispose();
|
||||||
@@ -511,6 +429,8 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
|
|
||||||
internal readonly record struct PixelRect(int X, int Y, int Width, int Height);
|
internal readonly record struct PixelRect(int X, int Y, int Width, int Height);
|
||||||
|
|
||||||
|
internal readonly record struct CellRect(int X, int Y, int Width, int Height);
|
||||||
|
|
||||||
private readonly record struct StructureKey(
|
private readonly record struct StructureKey(
|
||||||
int MaskHashSum,
|
int MaskHashSum,
|
||||||
int MaskHashMix,
|
int MaskHashMix,
|
||||||
@@ -525,7 +445,7 @@ internal sealed class InkDispersionPipeline : IDisposable
|
|||||||
float Viscosity,
|
float Viscosity,
|
||||||
float Drying);
|
float Drying);
|
||||||
|
|
||||||
private readonly record struct DerivedValues(
|
internal readonly record struct DerivedValues(
|
||||||
float CellSize,
|
float CellSize,
|
||||||
int Steps,
|
int Steps,
|
||||||
float Deposit,
|
float Deposit,
|
||||||
|
|||||||
@@ -0,0 +1,398 @@
|
|||||||
|
using ComputeWeave;
|
||||||
|
|
||||||
|
namespace InkDispersion;
|
||||||
|
|
||||||
|
[ComputeResourceGroup]
|
||||||
|
internal sealed partial class InkDispersionGridResources
|
||||||
|
{
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> DistributionsA { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> DistributionsB { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> Deposit { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> Surface { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> FlowPigmentA { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> FlowPigmentB { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> FixedPigment { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> DensityA { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> DensityB { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> Kappa { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> Wetness { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<Float2> Velocity { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<int> ReachMask { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<int> JumpFloodA { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<int> JumpFloodB { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> FiberField { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> AlumField { get; }
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||||
|
internal ReadWriteBuffer<float> PinField { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComputePipelineHost("_device", 1)]
|
||||||
|
internal sealed partial class InkDispersionPipelineHost
|
||||||
|
{
|
||||||
|
private readonly GraphicsDevice _device;
|
||||||
|
|
||||||
|
[ComputePipelineResource(ComputeResourceAccess.ReadWrite, ComputeResourceRecovery.Recompute)]
|
||||||
|
private readonly ComputeResourceGroupSlot<InkDispersionGridResources> _grid = new();
|
||||||
|
|
||||||
|
[ComputePipeline]
|
||||||
|
private void RecordFullPipeline(
|
||||||
|
in ComputeContext context,
|
||||||
|
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteTexture2D<Bgra32, Float4> source,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteTexture2D<Bgra32, Float4> output,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> inkStep,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
in InkDispersionPipeline.Parameters parameters)
|
||||||
|
{
|
||||||
|
_ = _device;
|
||||||
|
|
||||||
|
RecordSilhouetteStage(in context, grid, source, 0, 0, width, height, gridWidth, gridHeight, in derived);
|
||||||
|
RecordFlowStage(in context, grid, scratch, inkStep, new InkDispersionPipeline.CellRect(0, 0, gridWidth, gridHeight), gridWidth, gridHeight, in derived, in parameters);
|
||||||
|
RecordRenderStage(in context, grid, output, scratch, inkStep, new InkDispersionPipeline.PixelRect(0, 0, width, height), gridWidth, gridHeight, in derived, in parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComputePipeline]
|
||||||
|
private void RecordSilhouetteAndMaskHash(
|
||||||
|
in ComputeContext context,
|
||||||
|
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteTexture2D<Bgra32, Float4> source,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||||
|
int sourceOffsetX,
|
||||||
|
int sourceOffsetY,
|
||||||
|
int sourceWidth,
|
||||||
|
int sourceHeight,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived)
|
||||||
|
{
|
||||||
|
_ = _device;
|
||||||
|
|
||||||
|
RecordSilhouetteStage(in context, grid, source, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, gridWidth, gridHeight, in derived);
|
||||||
|
RecordMaskHashStage(in context, grid, scratch, gridWidth, gridHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComputePipeline]
|
||||||
|
[ComputeInterop]
|
||||||
|
private void RecordSharedSilhouetteAndMaskHash(
|
||||||
|
in ComputeContext context,
|
||||||
|
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite, Sharing = ComputeResourceSharing.External)] ReadWriteTexture2D<Bgra32, Float4> source,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||||
|
int sourceOffsetX,
|
||||||
|
int sourceOffsetY,
|
||||||
|
int sourceWidth,
|
||||||
|
int sourceHeight,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived)
|
||||||
|
{
|
||||||
|
_ = _device;
|
||||||
|
|
||||||
|
RecordSilhouetteStage(in context, grid, source, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, gridWidth, gridHeight, in derived);
|
||||||
|
RecordMaskHashStage(in context, grid, scratch, gridWidth, gridHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComputePipeline]
|
||||||
|
[ComputeInterop]
|
||||||
|
private void RecordSharedRender(
|
||||||
|
in ComputeContext context,
|
||||||
|
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite, Sharing = ComputeResourceSharing.External)] ReadWriteTexture2D<Bgra32, Float4> output,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> inkStep,
|
||||||
|
in InkDispersionPipeline.PixelRect rect,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
in InkDispersionPipeline.Parameters parameters)
|
||||||
|
{
|
||||||
|
_ = _device;
|
||||||
|
|
||||||
|
RecordRenderStage(in context, grid, output, scratch, inkStep, rect, gridWidth, gridHeight, in derived, in parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComputePipeline]
|
||||||
|
private void RecordFlowSetup(
|
||||||
|
in ComputeContext context,
|
||||||
|
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> inkStep,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
in InkDispersionPipeline.Parameters parameters)
|
||||||
|
{
|
||||||
|
_ = _device;
|
||||||
|
|
||||||
|
RecordFlowSetupStage(in context, grid, scratch, inkStep, gridWidth, gridHeight, in derived, in parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComputePipeline]
|
||||||
|
private void RecordFlowSteps(
|
||||||
|
in ComputeContext context,
|
||||||
|
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> inkStep,
|
||||||
|
in InkDispersionPipeline.CellRect region,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
int firstStep,
|
||||||
|
int stepCount)
|
||||||
|
{
|
||||||
|
_ = _device;
|
||||||
|
|
||||||
|
RecordFlowStepsStage(in context, grid, scratch, inkStep, region, gridWidth, gridHeight, in derived, firstStep, stepCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComputePipeline]
|
||||||
|
private void RecordFlowFinish(
|
||||||
|
in ComputeContext context,
|
||||||
|
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived)
|
||||||
|
{
|
||||||
|
_ = _device;
|
||||||
|
|
||||||
|
RecordFlowFinishStage(in context, grid, scratch, gridWidth, gridHeight, in derived);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ComputePipeline]
|
||||||
|
private void RecordRender(
|
||||||
|
in ComputeContext context,
|
||||||
|
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteTexture2D<Bgra32, Float4> output,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||||
|
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> inkStep,
|
||||||
|
in InkDispersionPipeline.PixelRect rect,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
in InkDispersionPipeline.Parameters parameters)
|
||||||
|
{
|
||||||
|
_ = _device;
|
||||||
|
|
||||||
|
RecordRenderStage(in context, grid, output, scratch, inkStep, rect, gridWidth, gridHeight, in derived, in parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RecordSilhouetteStage(
|
||||||
|
in ComputeContext context,
|
||||||
|
InkDispersionGridResources grid,
|
||||||
|
ReadWriteTexture2D<Bgra32, Float4> source,
|
||||||
|
int sourceOffsetX,
|
||||||
|
int sourceOffsetY,
|
||||||
|
int sourceWidth,
|
||||||
|
int sourceHeight,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived)
|
||||||
|
{
|
||||||
|
context.For(gridWidth, gridHeight, new SilhouetteShader(
|
||||||
|
source, grid.Deposit, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, gridWidth, gridHeight, derived.CellSize));
|
||||||
|
context.Barrier(grid.Deposit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RecordMaskHashStage(
|
||||||
|
in ComputeContext context,
|
||||||
|
InkDispersionGridResources grid,
|
||||||
|
ReadWriteBuffer<int> scratch,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight)
|
||||||
|
{
|
||||||
|
context.For(1, new MaskHashResetShader(scratch));
|
||||||
|
context.Barrier(scratch);
|
||||||
|
context.For(gridWidth, gridHeight, new MaskHashShader(grid.Deposit, scratch, gridWidth, gridHeight));
|
||||||
|
context.Barrier(scratch);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RecordFlowStage(
|
||||||
|
in ComputeContext context,
|
||||||
|
InkDispersionGridResources grid,
|
||||||
|
ReadWriteBuffer<int> scratch,
|
||||||
|
ReadWriteBuffer<int> inkStep,
|
||||||
|
in InkDispersionPipeline.CellRect region,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
in InkDispersionPipeline.Parameters parameters)
|
||||||
|
{
|
||||||
|
RecordFlowSetupStage(in context, grid, scratch, inkStep, gridWidth, gridHeight, in derived, in parameters);
|
||||||
|
RecordFlowStepsStage(in context, grid, scratch, inkStep, region, gridWidth, gridHeight, in derived, 0, derived.Steps);
|
||||||
|
RecordFlowFinishStage(in context, grid, scratch, gridWidth, gridHeight, in derived);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RecordFlowSetupStage(
|
||||||
|
in ComputeContext context,
|
||||||
|
InkDispersionGridResources grid,
|
||||||
|
ReadWriteBuffer<int> scratch,
|
||||||
|
ReadWriteBuffer<int> inkStep,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
in InkDispersionPipeline.Parameters parameters)
|
||||||
|
{
|
||||||
|
context.For(1, new InitScratchShader(scratch));
|
||||||
|
context.Barrier(scratch);
|
||||||
|
context.For(gridWidth, gridHeight, new InitFieldShader(
|
||||||
|
grid.DistributionsA, grid.DistributionsB, grid.Deposit, grid.Surface, grid.FlowPigmentA, grid.FlowPigmentB, grid.FixedPigment,
|
||||||
|
grid.DensityA, grid.DensityB, grid.Wetness, grid.Velocity, inkStep, grid.FiberField, grid.AlumField, grid.PinField,
|
||||||
|
gridWidth, gridHeight, derived.Deposit, parameters.Seed));
|
||||||
|
context.Barrier(grid.DistributionsA);
|
||||||
|
context.Barrier(grid.DistributionsB);
|
||||||
|
context.Barrier(grid.Surface);
|
||||||
|
context.Barrier(grid.FlowPigmentA);
|
||||||
|
context.Barrier(grid.FlowPigmentB);
|
||||||
|
context.Barrier(grid.FixedPigment);
|
||||||
|
context.Barrier(grid.DensityA);
|
||||||
|
context.Barrier(grid.DensityB);
|
||||||
|
context.Barrier(grid.Wetness);
|
||||||
|
context.Barrier(grid.Velocity);
|
||||||
|
context.Barrier(inkStep);
|
||||||
|
context.Barrier(grid.FiberField);
|
||||||
|
context.Barrier(grid.AlumField);
|
||||||
|
context.Barrier(grid.PinField);
|
||||||
|
|
||||||
|
context.For(gridWidth, gridHeight, new JumpFloodSeedShader(grid.Deposit, grid.JumpFloodA, gridWidth, gridHeight));
|
||||||
|
context.Barrier(grid.JumpFloodA);
|
||||||
|
var reading = grid.JumpFloodA;
|
||||||
|
var writing = grid.JumpFloodB;
|
||||||
|
var stepSize = 1;
|
||||||
|
var maxSide = Math.Max(gridWidth, gridHeight);
|
||||||
|
while (stepSize < maxSide)
|
||||||
|
stepSize <<= 1;
|
||||||
|
stepSize >>= 1;
|
||||||
|
while (stepSize >= 1)
|
||||||
|
{
|
||||||
|
context.For(gridWidth, gridHeight, new JumpFloodPassShader(reading, writing, gridWidth, gridHeight, stepSize));
|
||||||
|
context.Barrier(writing);
|
||||||
|
(reading, writing) = (writing, reading);
|
||||||
|
stepSize >>= 1;
|
||||||
|
}
|
||||||
|
context.For(gridWidth, gridHeight, new ReachMaskShader(reading, grid.ReachMask, grid.Kappa, gridWidth, gridHeight, derived.CellSize, derived.ReachPixels));
|
||||||
|
context.Barrier(grid.ReachMask);
|
||||||
|
context.Barrier(grid.Kappa);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RecordFlowStepsStage(
|
||||||
|
in ComputeContext context,
|
||||||
|
InkDispersionGridResources grid,
|
||||||
|
ReadWriteBuffer<int> scratch,
|
||||||
|
ReadWriteBuffer<int> inkStep,
|
||||||
|
in InkDispersionPipeline.CellRect region,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
int firstStep,
|
||||||
|
int stepCount)
|
||||||
|
{
|
||||||
|
var swapped = (firstStep & 1) != 0;
|
||||||
|
var distributionsIn = swapped ? grid.DistributionsB : grid.DistributionsA;
|
||||||
|
var distributionsOut = swapped ? grid.DistributionsA : grid.DistributionsB;
|
||||||
|
var pigmentIn = swapped ? grid.FlowPigmentB : grid.FlowPigmentA;
|
||||||
|
var pigmentOut = swapped ? grid.FlowPigmentA : grid.FlowPigmentB;
|
||||||
|
for (var step = firstStep; step < firstStep + stepCount; step++)
|
||||||
|
{
|
||||||
|
context.For(region.Width, region.Height, new SupplyShader(
|
||||||
|
distributionsIn, grid.Surface, pigmentIn, grid.DensityA, grid.ReachMask, grid.Deposit, region.X, region.Y, gridWidth, gridHeight));
|
||||||
|
context.Barrier(distributionsIn);
|
||||||
|
context.Barrier(grid.Surface);
|
||||||
|
context.Barrier(pigmentIn);
|
||||||
|
context.Barrier(grid.DensityA);
|
||||||
|
context.For(region.Width, region.Height, new KappaShader(
|
||||||
|
grid.DensityA, grid.FixedPigment, grid.ReachMask, grid.FiberField, grid.AlumField, grid.PinField, grid.Kappa, region.X, region.Y, gridWidth, gridHeight,
|
||||||
|
derived.Fiber, derived.Sizing, derived.Viscosity, derived.Sigma));
|
||||||
|
context.Barrier(grid.Kappa);
|
||||||
|
context.For(region.Width, region.Height, new StreamCollideShader(
|
||||||
|
distributionsIn, distributionsOut, grid.Kappa, grid.ReachMask, grid.Deposit, grid.DensityB, grid.Velocity,
|
||||||
|
region.X, region.Y, gridWidth, gridHeight, derived.Omega, derived.SurfaceEvaporation));
|
||||||
|
context.Barrier(distributionsOut);
|
||||||
|
context.Barrier(grid.DensityB);
|
||||||
|
context.Barrier(grid.Velocity);
|
||||||
|
context.For(region.Width, region.Height, new PigmentShader(
|
||||||
|
distributionsOut, grid.DensityA, grid.DensityB, grid.Velocity, pigmentIn, pigmentOut,
|
||||||
|
grid.FixedPigment, grid.Wetness, inkStep, grid.ReachMask, grid.Deposit, grid.FiberField, scratch,
|
||||||
|
region.X, region.Y, gridWidth, gridHeight, step, derived.Fiber, derived.Viscosity));
|
||||||
|
context.Barrier(pigmentOut);
|
||||||
|
context.Barrier(grid.FixedPigment);
|
||||||
|
context.Barrier(grid.Wetness);
|
||||||
|
context.Barrier(inkStep);
|
||||||
|
(distributionsIn, distributionsOut) = (distributionsOut, distributionsIn);
|
||||||
|
(pigmentIn, pigmentOut) = (pigmentOut, pigmentIn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RecordFlowFinishStage(
|
||||||
|
in ComputeContext context,
|
||||||
|
InkDispersionGridResources grid,
|
||||||
|
ReadWriteBuffer<int> scratch,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived)
|
||||||
|
{
|
||||||
|
var pigmentIn = (derived.Steps & 1) == 0 ? grid.FlowPigmentA : grid.FlowPigmentB;
|
||||||
|
context.For(gridWidth, gridHeight, new FinalFixShader(pigmentIn, grid.FixedPigment, gridWidth, gridHeight));
|
||||||
|
context.Barrier(grid.FixedPigment);
|
||||||
|
context.Barrier(scratch);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RecordRenderStage(
|
||||||
|
in ComputeContext context,
|
||||||
|
InkDispersionGridResources grid,
|
||||||
|
ReadWriteTexture2D<Bgra32, Float4> output,
|
||||||
|
ReadWriteBuffer<int> scratch,
|
||||||
|
ReadWriteBuffer<int> inkStep,
|
||||||
|
in InkDispersionPipeline.PixelRect rect,
|
||||||
|
int gridWidth,
|
||||||
|
int gridHeight,
|
||||||
|
in InkDispersionPipeline.DerivedValues derived,
|
||||||
|
in InkDispersionPipeline.Parameters parameters)
|
||||||
|
{
|
||||||
|
context.For(rect.Width, rect.Height, new RenderShader(
|
||||||
|
inkStep, grid.FixedPigment, grid.Wetness, scratch, output,
|
||||||
|
rect.X, rect.Y, rect.Width, rect.Height, gridWidth, gridHeight,
|
||||||
|
derived.CellSize, Math.Clamp(parameters.Spread, 0f, 1f),
|
||||||
|
Math.Clamp(parameters.Density, 0f, 1f), Math.Clamp(parameters.Grain, 0f, 1f),
|
||||||
|
parameters.ColorR, parameters.ColorG, parameters.ColorB, parameters.Seed));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,8 +46,14 @@ internal static class InkDispersionSettings
|
|||||||
public const int ScratchLength = 8;
|
public const int ScratchLength = 8;
|
||||||
public const int ScratchWetCount = 0;
|
public const int ScratchWetCount = 0;
|
||||||
public const int ScratchMaxWetStep = 1;
|
public const int ScratchMaxWetStep = 1;
|
||||||
|
public const int ScratchBoundsMinX = 2;
|
||||||
|
public const int ScratchBoundsMinY = 3;
|
||||||
|
public const int ScratchBoundsMaxX = 4;
|
||||||
|
public const int ScratchBoundsMaxY = 5;
|
||||||
public const int ScratchMaskHashSum = 6;
|
public const int ScratchMaskHashSum = 6;
|
||||||
public const int ScratchMaskHashMix = 7;
|
public const int ScratchMaskHashMix = 7;
|
||||||
|
public const int MaximumPendingSubmissions = 32;
|
||||||
|
public const int FlowStepsPerSubmission = 128;
|
||||||
|
|
||||||
public static QualitySettings GetQuality(InkDispersionQuality quality)
|
public static QualitySettings GetQuality(InkDispersionQuality quality)
|
||||||
=> quality switch
|
=> quality switch
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
using Telemetry;
|
||||||
|
|
||||||
|
namespace InkDispersion;
|
||||||
|
|
||||||
|
internal static class InkDispersionTelemetry
|
||||||
|
{
|
||||||
|
private const int MaxChainLength = 5;
|
||||||
|
private const int MaxFrames = 100;
|
||||||
|
|
||||||
|
private static readonly Assembly Own = typeof(InkDispersionTelemetry).Assembly;
|
||||||
|
private static int _started;
|
||||||
|
|
||||||
|
public static void EnsureStartedOnce()
|
||||||
|
{
|
||||||
|
var application = Application.Current;
|
||||||
|
if (application is null || Interlocked.Exchange(ref _started, 1) != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||||
|
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
|
||||||
|
application.DispatcherUnhandledException += OnDispatcherUnhandledException;
|
||||||
|
|
||||||
|
TelemetryReporter.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Report(Exception exception)
|
||||||
|
{
|
||||||
|
if (Volatile.Read(ref _started) != 0)
|
||||||
|
TelemetryReporter.Report(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||||
|
=> ReportOwn(e.ExceptionObject as Exception);
|
||||||
|
|
||||||
|
private static void OnUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
|
||||||
|
=> ReportOwn(e.Exception);
|
||||||
|
|
||||||
|
private static void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||||
|
=> ReportOwn(e.Exception);
|
||||||
|
|
||||||
|
private static void ReportOwn(Exception? exception)
|
||||||
|
{
|
||||||
|
if (exception is not null && IsOwn(exception))
|
||||||
|
TelemetryReporter.Report(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsOwn(Exception exception)
|
||||||
|
{
|
||||||
|
var current = exception;
|
||||||
|
for (var depth = 0; current is not null && depth < MaxChainLength; depth++)
|
||||||
|
{
|
||||||
|
if (HasOwnFrame(current))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
current = current is AggregateException aggregate && aggregate.InnerExceptions.Count > 0
|
||||||
|
? aggregate.InnerExceptions[0]
|
||||||
|
: current.InnerException;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HasOwnFrame(Exception exception)
|
||||||
|
{
|
||||||
|
StackFrame[]? frames;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
frames = new StackTrace(exception, false).GetFrames();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frames is null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (var index = 0; index < Math.Min(frames.Length, MaxFrames); index++)
|
||||||
|
{
|
||||||
|
MethodBase? method;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
method = frames[index].GetMethod();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method?.DeclaringType is { } declaringType && ReferenceEquals(declaringType.Assembly, Own))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ internal static class InkDispersionUpdateNotifier
|
|||||||
|
|
||||||
public static void EnsureCheckedOnce()
|
public static void EnsureCheckedOnce()
|
||||||
{
|
{
|
||||||
if (Interlocked.Exchange(ref _started, 1) != 0)
|
if (Application.Current is null || Interlocked.Exchange(ref _started, 1) != 0)
|
||||||
return;
|
return;
|
||||||
_ = RunAsync();
|
_ = RunAsync();
|
||||||
}
|
}
|
||||||
@@ -31,8 +31,10 @@ internal static class InkDispersionUpdateNotifier
|
|||||||
};
|
};
|
||||||
await new Notifier(Owner, Repository, options).NotifyAsync().ConfigureAwait(false);
|
await new Notifier(Owner, Repository, options).NotifyAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
if (exception is not UpdateCheckException)
|
||||||
|
InkDispersionTelemetry.Report(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ namespace InkDispersion;
|
|||||||
|
|
||||||
internal static class ShaderResourceUri
|
internal static class ShaderResourceUri
|
||||||
{
|
{
|
||||||
public static Uri Get(string shaderName) => new($"pack://application:,,,/InkDispersion;component/Shaders/{shaderName}.cso", UriKind.Absolute);
|
public static Uri Get(string shaderName) => new($"pack://application:,,,/InkDispersion;component/Resources/Shader/{shaderName}.cso", UriKind.Absolute);
|
||||||
}
|
}
|
||||||
@@ -6,13 +6,11 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
YukkuriMovieMaker4(YMM4)上で動作する、素材を墨の付置とみなし、格子ボルツマン方程式による吸水紙中の浸透流で墨を外へにじませて描画する映像エフェクトプラグインです。
|
YukkuriMovieMaker4(YMM4)上で動作する、素材の形に置いた墨が紙へにじみ広がる様子を描く映像エフェクトプラグインです。
|
||||||
浸透流のモデルはChu and Taiの論文「MoXi: Real-Time Ink Dispersion in Absorbent Paper」(SIGGRAPH 2005)に基づきます。
|
素材の不透明な部分に墨を置き、紙の中を水が浸透していく流れを計算して、水に運ばれた墨が定着した形を描きます。
|
||||||
履歴フレーム、参照画像、学習済みモデルを使わず、入力された一枚の映像だけを処理します。
|
「拡散度」を時間で変えると、文字や図形が紙へにじんでいく動きになります。
|
||||||
にじみの形は紙の繊維とシードから決定論的に決まり、同じ設定では常に同じ形になります。
|
|
||||||
強さ、拡散度、水量、到達距離、繊維、にじみ止め、粘度、乾燥、濃度、かすれの10項目はアニメーションに対応しています。
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -22,35 +20,31 @@ YukkuriMovieMaker4(YMM4)上で動作する、素材を墨の付置とみな
|
|||||||
2. [動作要件](#動作要件)
|
2. [動作要件](#動作要件)
|
||||||
3. [インストール方法](#インストール方法)
|
3. [インストール方法](#インストール方法)
|
||||||
4. [主な機能](#主な機能)
|
4. [主な機能](#主な機能)
|
||||||
- [1. 格子ボルツマン法による浸透流](#1-格子ボルツマン法による浸透流)
|
- [1. 浸透の計算](#1-浸透の計算)
|
||||||
- [2. 拡散度によるにじみの遷移](#2-拡散度によるにじみの遷移)
|
- [2. 拡散度によるにじみの進み](#2-拡散度によるにじみの進み)
|
||||||
- [3. 紙の繊維と枝分かれ](#3-紙の繊維と枝分かれ)
|
- [3. 紙と墨の性質](#3-紙と墨の性質)
|
||||||
- [4. にじみ止めと縁の荒れ](#4-にじみ止めと縁の荒れ)
|
- [4. にじみの広がり](#4-にじみの広がり)
|
||||||
- [5. 水量・粘度・乾燥](#5-水量粘度乾燥)
|
- [5. 墨の描画](#5-墨の描画)
|
||||||
- [6. 品質の選択](#6-品質の選択)
|
- [6. 計算領域と品質](#6-計算領域と品質)
|
||||||
5. [パラメータ一覧](#パラメータ一覧)
|
5. [パラメータ一覧](#パラメータ一覧)
|
||||||
- [基本グループ](#基本グループ)
|
|
||||||
- [浸透グループ](#浸透グループ)
|
|
||||||
- [描画グループ](#描画グループ)
|
|
||||||
6. [制限事項](#制限事項)
|
6. [制限事項](#制限事項)
|
||||||
7. [注意事項](#注意事項)
|
7. [注意事項](#注意事項)
|
||||||
8. [免責事項](#免責事項)
|
8. [不具合の報告](#不具合の報告)
|
||||||
9. [サードパーティライセンス](#サードパーティライセンス)
|
9. [免責事項](#免責事項)
|
||||||
10. [ライセンス](#ライセンス)
|
10. [サードパーティライセンス](#サードパーティライセンス)
|
||||||
|
11. [ライセンス](#ライセンス)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 概要
|
## 概要
|
||||||
|
|
||||||
本プラグインはYMM4の映像エフェクトとして動作し、エフェクトの種類一覧では「墨拡散」として表示されます。カテゴリは装飾とアニメーションです。
|
本プラグインは YMM4 の映像エフェクトとして動作します。エフェクトの一覧の「装飾」と「アニメーション」に「墨拡散」として表示されます。現在のフレームの不透明度から素材の形を求め、素材を覆う格子のセルに墨を含んだ水を置き、水が紙の中を広がる様子を格子ボルツマン法で計算します。格子ボルツマン法は、セルからセルへ移る水の量を短い時間の刻みごとに求める計算法です。浸透の計算は、Chu と Tai の論文「MoXi: Real-Time Ink Dispersion in Absorbent Paper」(SIGGRAPH 2005)に基づきます。
|
||||||
|
|
||||||
入力された現在のフレームのアルファ値から素材の形を求め、素材のセルを表面層の墨だまりとして正方格子の上に置きます。浸透の計算はChu and Taiの論文「MoXi: Real-Time Ink Dispersion in Absorbent Paper」(SIGGRAPH 2005)の格子ボルツマン方程式に基づきます。各セルはD2Q9格子の9方向の分布関数、表面層の水、流動層の顔料、定着層の顔料の状態を持ち、表面からの供給、透過率つきの流走、衝突、顔料の移流と定着のステップを繰り返して墨をにじませます。透過率は紙の繊維むらと礬水と膠と定着した顔料から決まり、乾いた前線のピン止めと蒸発が縁の荒れと縁の濃さを作ります。浸透は決定論的で、同じシードと同じパラメータでは常に同じ形になります。
|
計算に使うのは現在のフレームだけです。前後のフレーム、外部の画像、学習済みのモデルは使いません。乱数は「シード」と位置だけから決めます。時刻や描画の回数は使わないため、同じフレームは何度描いても同じ結果になります。
|
||||||
|
|
||||||
拡散度のパラメータは、にじみの記録をどこまで表示するかを決めます。各セルには顔料が届いたステップが記録されるため、拡散度を時間で変えると、素材から墨がにじみ広がっていく遷移になります。求めた墨は、定着した顔料の濃さと紙目のかすれを持つ墨として描画し、元映像の上へ合成します。
|
計算は Direct3D 12 の計算シェーダーで行います。YMM4 が描画に使う Direct3D 11 との間では、素材と描いた墨を共有テクスチャと共有フェンスで受け渡します。設定はアイテムのエフェクトの項目としてプロジェクトに保存します。プラグイン自体の設定ファイルはありません。
|
||||||
|
|
||||||
計算はComputeSharpの計算シェーダーがDirect3D 12で実行します。YMM4のDirect3D 11側とComputeSharpのDirect3D 12側は、共有テクスチャと共有フェンスで接続します。通常のフレーム処理では、CPUへの画素の読み戻しを行わず、顔料到達ステップの記録だけを読み戻します。墨が存在する最小の矩形の範囲だけを描画し、素材の形状とパラメータが変わらないフレームでは浸透の計算を再利用します。
|
画面の表示は日本語のほか、英語、簡体字と繁体字の中国語、韓国語、スペイン語、アラビア語、インドネシア語に対応します。
|
||||||
|
|
||||||
このエフェクトはAviUtl向けのEXO出力には対応していません。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -58,145 +52,178 @@ YukkuriMovieMaker4(YMM4)上で動作する、素材を墨の付置とみな
|
|||||||
|
|
||||||
| 項目 | 要件 |
|
| 項目 | 要件 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| OS | Windows 10 バージョン2004(ビルド19041)以降 / Windows 11(64bit) |
|
| OS | Windows 10 バージョン 2004(ビルド 19041)以降 / Windows 11(64bit) |
|
||||||
| YukkuriMovieMaker4 | 最新版を推奨 |
|
| YukkuriMovieMaker4 | 最新版を推奨 |
|
||||||
| ランタイム | .NET 10.0 |
|
| ランタイム | .NET 10.0 |
|
||||||
| GPU | Direct3D 12とDirect3D 11・12間の共有テクスチャおよび共有フェンスを利用できるGPU |
|
| GPU | Direct3D 12 に対応し、Direct3D 11 と共有テクスチャおよび共有フェンスをやり取りできる GPU |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## インストール方法
|
## インストール方法
|
||||||
|
|
||||||
1. [Releases](https://github.com/routersys/YMM4-InkDispersion/releases/latest)ページから最新のプラグインファイル(`.ymme`)をダウンロードしてください。
|
1. [Releases](https://github.com/routersys/YMM4-InkDispersion/releases/latest) ページから最新のプラグインファイル(`.ymme`)をダウンロードしてください。
|
||||||
2. YMM4が起動していないことを確認し、ダウンロードしたファイルを実行してインストールします。
|
2. YMM4 が起動していないことを確認し、ダウンロードしたファイルを実行してインストールします。
|
||||||
3. YMM4を起動し、タイムライン上のアイテムに映像エフェクトを追加します。
|
3. YMM4 を起動し、アイテムの映像エフェクトから「装飾」か「アニメーション」の「墨拡散」を追加します。
|
||||||
4. 映像エフェクトの種類として「墨拡散」を選択してください。
|
4. 既定の設定では、墨がにじむ距離の上限は素材の長辺の 25% です。「到達距離」と「水量」で広がりを、「拡散度」で進み具合を調整します。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 主な機能
|
## 主な機能
|
||||||
|
|
||||||
### 1. 格子ボルツマン法による浸透流
|
### 1. 浸透の計算
|
||||||
|
|
||||||
現在のフレームのアルファ値から素材の形を求め、素材のセルへ水と墨を置きます。水の流れはD2Q9格子の格子ボルツマン方程式で解きます。分布関数の平衡分布はHe and Luoの非圧縮変種を使い、水の少ない場所では移流の項を弱めて負の密度を防ぎます。
|
素材のうち不透明な部分を、浸透を計算する格子のセルに写します。各セルは、その範囲に含まれる画素の不透明度の平均に応じた量の水を、墨を溶かした状態で表面に持ちます。その量は「水量」で増減します。
|
||||||
|
|
||||||
流走のステップでは、隣接セルとの間の透過率に応じて分布関数の一部を跳ね返します。透過率は繋がった2つのセルの阻害係数の平均で決まるため、運動量と水の量が保存されます。乾いた前線のセルは、周囲の水の密度がしきい値を下回る間はピン止めされ、水が溜まると解放されます。この繰り返しが、にじみの前線の不規則な進みと縁の荒れを作ります。
|
水は 1 ステップに隣のセルへ 1 セル分だけ進みます。各セルには、隣へ水をどれだけ通すかを表す透過率があります。隣り合うセルの間の透過率は、両方のセルの透過率を平均した値です。通れなかった分の水は元のセルへ跳ね返ります。「繊維」「にじみ止め」「粘度」を上げるほど、また墨が定着したセルほど、透過率は下がります。
|
||||||
|
|
||||||
顔料は水の流れに運ばれます。新しく濡れたセルへは上流からの分布関数の重みで運び、すでに濡れたセルでは速度を遡る特性曲線法で運びます。紙の繊維に妨げられた顔料は流れから遅れ、乾くにつれて定着層へ移ります。
|
水の進む先端を前線と呼びます。乾いたセルは、隣のセルの水が一定の量に達するまで水を受け入れにくく、前線はそこで足止めされます。足止めの起きやすさは場所ごとに違うため、前線は一様に進まず、縁が荒れます。
|
||||||
|
|
||||||
### 2. 拡散度によるにじみの遷移
|
墨は水に運ばれます。水が初めて届いたセルでは、流れ込んだ水の量に応じて上流のセルの墨を受け取ります。すでに濡れているセルでは、流れの向きと速さから 1 ステップ前にどこの墨がここへ来たかを求め、その墨を受け取ります。水が減る場所では墨がその場に定着し、定着した墨は以後の流れを妨げます。ステップをすべて終えると、まだ水に溶けている墨もその場に定着します。
|
||||||
|
|
||||||
拡散度は、にじみの記録をどこまで表示するかを決めます。0%では何も描画せず、値を上げると墨が素材から外へにじみ広がっていきます。各セルには定着した顔料が届いたステップが記録されるため、表示はにじみの順序どおりに進みます。
|
### 2. 拡散度によるにじみの進み
|
||||||
|
|
||||||
拡散度を時間で変えると、文字や模様が紙へにじんでいく演出になります。
|
各セルは、墨が最初に定着したステップの番号を覚えています。「拡散度」は、何ステップ目までのにじみを描くかを決めます。0% では何も描かず、100% では最後のステップまで描きます。描く範囲の境目は 1 ステップ分の幅で滑らかにつなぎます。番号の順に描くため、「拡散度」を時間で上げると、素材から外へ墨がにじみ広がる動きになります。
|
||||||
|
|
||||||
### 3. 紙の繊維と枝分かれ
|
### 3. 紙と墨の性質
|
||||||
|
|
||||||
繊維は、紙の繊維むらの強さを決めます。繊維むらはシードから決定論的にハッシュ生成した繊維場で、値の高い場所ほど水が通りにくくなります。高いほど流れが妨げられて枝分かれし、低いほど滑らかににじみます。
|
「繊維」は、紙の繊維むらの強さです。繊維むらは「シード」から作る模様で、模様の濃い場所ほど水が通りにくく、墨も流れから遅れます。「繊維」を上げるほど流れが妨げられて枝分かれし、下げるほど滑らかに広がります。
|
||||||
|
|
||||||
シードは、繊維場とにじみの形を決める固定値です。シードとセル位置から決定論的に生成するため、同じシードと同じパラメータでは常に同じ形になります。
|
「にじみ止め」は、礬水による浸透の妨げです。礬水は、明礬と膠を溶いて紙に引き、にじみを抑える液です。紙に引いた礬水は一様ではないため、「にじみ止め」を高くすると、濃い場所ほど透過率が下がります。前線の足止めが解ける水の量も増えるため、縁が荒れて広がりが抑えられます。
|
||||||
|
|
||||||
### 4. にじみ止めと縁の荒れ
|
「粘度」は、膠による墨の粘りです。高くするほど水の流れが遅くなり、透過率が下がり、墨が定着しやすくなります。
|
||||||
|
|
||||||
にじみ止めは、礬水による浸透の妨げを決めます。高いほどピン止めのしきい値が上がり、前線が止まりやすくなって縁が荒れ、広がりが抑えられます。
|
「シード」は、紙の模様を決める値です。繊維むら、にじみ止めのむら、前線の足止めのむら、描画のときの紙目がこの値から決まります。同じ設定のアイテムを複数置くときに、シードを変えると別々の形になります。
|
||||||
|
|
||||||
かすれは、紙目によるかすれと縁の荒れの強さを決めます。描画の際に、墨の薄い場所を画素単位の紙目で削り、境界を紙目で荒らします。
|
### 4. にじみの広がり
|
||||||
|
|
||||||
### 5. 水量・粘度・乾燥
|
「水量」は、素材に置く水の量です。置いた水は、1 ステップごとにセルの空いた分だけ紙へ移ります。多いほど供給が長く続き、水が遠くまで届きます。
|
||||||
|
|
||||||
水量は、素材に置く水の量を決めます。表面層の水は紙の繊維の容量に合わせて少しずつ流動層へ吸い込まれるため、多いほど長くにじみ続けて遠くまで届きます。
|
「乾燥」は、水が蒸発する速さです。1 ステップごとに水が減り、減った分に応じて墨が定着します。高くするほど早くにじみが止まり、水を失う縁で墨が濃くなります。
|
||||||
|
|
||||||
粘度は、膠による墨の粘りを決めます。高いほど緩和係数が下がって流れが遅くなり、透過率の阻害と定着も強まって墨がその場に留まります。
|
「到達距離」は、墨が届く距離の上限です。素材の長辺に対する割合で指定し、素材の縁からこの距離より遠いセルには水を通しません。長くするほど、水を通すセルの数とステップ数が増え、計算に時間がかかります。
|
||||||
|
|
||||||
乾燥は、水の蒸発の速さを決めます。乾きの速いほどにじみは早く止まり、水を失う場所で顔料が定着するため縁が濃くなります。
|
### 5. 墨の描画
|
||||||
|
|
||||||
到達距離は、墨が届く距離の上限を素材の長辺に対する割合で決めます。距離はジャンプフラッドで求めた素材からの距離で判定します。到達距離を大きくするほど計算領域が広がり、処理量が増えます。
|
各セルは、定着した墨の量とともに、最も濡れたときの水の量を覚えています。描画では、この 2 つから画素ごとに墨の不透明度を決めます。
|
||||||
|
|
||||||
### 6. 品質の選択
|
「濃度」は、同じ量の墨をどれだけ濃く描くかです。「かすれ」は、紙目によるかすれと縁の荒れの強さです。紙目は、紙の表面の細かい凹凸です。「かすれ」を高くするほど、水が少なかった場所の墨を紙目に沿って削り、墨の境界を荒らします。「墨色」は描く墨の色で、不透明度は使いません。
|
||||||
|
|
||||||
品質は、浸透格子の解像度と浸透ステップ数の上限をまとめて切り替えます。
|
描いた墨は「強さ」の分だけ元の映像の上に重ねます。0% にすると映像をそのまま通します。
|
||||||
|
|
||||||
| 品質 | 格子解像度 | 浸透ステップ上限 |
|
### 6. 計算領域と品質
|
||||||
|---|---:|---:|
|
|
||||||
| 標準 | 160 | 720回 |
|
|
||||||
| 高品質 | 224 | 1080回 |
|
|
||||||
| 最高品質 | 288 | 1440回 |
|
|
||||||
|
|
||||||
格子解像度は計算領域の長辺のセル数です。短辺のセル数は計算領域の縦横比に合わせて決めます。実際のステップ数は到達距離に応じて決まり、上限で打ち切ります。
|
計算領域は、素材の範囲を「到達距離」と 64px の余白の分だけ四方へ広げた大きさです。計算領域の長辺が 8192px に収まるように「到達距離」を縮めます。到達距離は 1px までしか縮めません。
|
||||||
|
|
||||||
|
「品質」は、計算領域を覆う格子の細かさと、ステップ数の上限を決めます。
|
||||||
|
|
||||||
|
| 品質 | 格子の解像度 | ステップ数の上限 |
|
||||||
|
|---|---|---|
|
||||||
|
| 標準 | 160 | 720 回 |
|
||||||
|
| 高品質 | 224 | 1080 回 |
|
||||||
|
| 最高品質 | 288 | 1440 回 |
|
||||||
|
|
||||||
|
格子の解像度は、計算領域の長辺をいくつのセルに分けるかの数です。1 セルの大きさは、長辺をこの数で割った長さになります。短辺のセルの数は縦横比に合わせて決まります。ステップ数は、「到達距離」をセルの数に直した値を 10 倍して 128 を足した回数です。ただし 192 回を下回らず、品質の上限を超えません。
|
||||||
|
|
||||||
|
描画するのは、墨が存在する最小の矩形だけです。この矩形が素材の外へはみ出す分だけ、エフェクトの出力範囲を広げます。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## パラメータ一覧
|
## パラメータ一覧
|
||||||
|
|
||||||
### 基本グループ
|
| 項目 | 既定値 | 内容 |
|
||||||
|
|---|---|---|
|
||||||
|
| 強さ | 100% | 墨を元の映像に重ねる割合です。0% から 100% までで、0% にすると映像をそのまま通します。 |
|
||||||
|
| 拡散度 | 100% | 描くにじみの範囲です。0% から 100% までで、0% にすると何も描きません。 |
|
||||||
|
| 品質 | 高品質 | 格子の細かさとステップ数の上限です。「標準」「高品質」「最高品質」から選びます。 |
|
||||||
|
| 水量 | 60% | 素材に置く水の量です。0% から 100% までです。 |
|
||||||
|
| 到達距離 | 25% | 墨が届く距離の上限で、素材の長辺に対する割合です。スライダーでは 5% から 100% まで、直接入力では 1% から 400% までです。 |
|
||||||
|
| 繊維 | 50% | 紙の繊維むらの強さです。0% から 100% までです。 |
|
||||||
|
| にじみ止め | 30% | 礬水による浸透の妨げです。0% から 100% までです。 |
|
||||||
|
| 粘度 | 30% | 膠による墨の粘りです。0% から 100% までです。 |
|
||||||
|
| 乾燥 | 40% | 水が蒸発する速さです。0% から 100% までです。 |
|
||||||
|
| シード | 0 | 紙の模様とにじみの形を決める値です。0 以上の整数で、スライダーでは 10000 までです。 |
|
||||||
|
| 濃度 | 80% | 墨の濃さです。0% から 100% までです。 |
|
||||||
|
| かすれ | 40% | 紙目によるかすれと縁の荒れの強さです。0% から 100% までです。 |
|
||||||
|
| 墨色 | #1E1A18 | 描く墨の色です。不透明度は使いません。 |
|
||||||
|
|
||||||
| パラメータ名 | 型 | デフォルト | スライダー表示範囲 | アニメーション | 説明 |
|
「強さ」「拡散度」「品質」は「基本」、「水量」から「シード」までは「浸透」、「濃度」「かすれ」「墨色」は「描画」のグループにあります。「品質」「シード」「墨色」はアニメーションできません。ほかの 10 項目は、YMM4 のアニメーションの設定で時間に沿って変えられます。
|
||||||
|---|---|---|---|---|---|
|
|
||||||
| 強さ | 数値 | 100% | 0〜100% | 対応 | 墨の合成量です。0%では入力を変更しません。 |
|
|
||||||
| 拡散度 | 数値 | 100% | 0〜100% | 対応 | にじみの進行度です。素材から墨がにじみ広がっていきます。 |
|
|
||||||
| 品質 | 列挙 | 高品質 | 標準 / 高品質 / 最高品質 | 非対応 | 浸透格子の解像度と浸透ステップ数を選択します。 |
|
|
||||||
|
|
||||||
### 浸透グループ
|
|
||||||
|
|
||||||
| パラメータ名 | 型 | デフォルト | スライダー表示範囲 | アニメーション | 説明 |
|
|
||||||
|---|---|---|---|---|---|
|
|
||||||
| 水量 | 数値 | 60% | 0〜100% | 対応 | 素材に置く水の量です。多いほど遠くまでにじみます。 |
|
|
||||||
| 到達距離 | 数値 | 25% | 5〜100% | 対応 | 縁から墨が届く距離の上限です。素材の長辺に対する割合で指定します。直接入力では1〜400%まで指定できます。 |
|
|
||||||
| 繊維 | 数値 | 50% | 0〜100% | 対応 | 紙の繊維むらの強さです。高いほど枝分かれした流れになります。 |
|
|
||||||
| にじみ止め | 数値 | 30% | 0〜100% | 対応 | 礬水による浸透の妨げです。高いほど縁が荒れて広がりが抑えられます。 |
|
|
||||||
| 粘度 | 数値 | 30% | 0〜100% | 対応 | 膠による墨の粘りです。高いほど流れが遅く留まりやすくなります。 |
|
|
||||||
| 乾燥 | 数値 | 40% | 0〜100% | 対応 | 水の蒸発の速さです。高いほど早く乾いて縁が濃くなります。 |
|
|
||||||
| シード | 整数 | 0 | 0〜10000 | 非対応 | 紙の繊維とにじみの形を決める固定値です。直接入力では2147483647まで指定できます。 |
|
|
||||||
|
|
||||||
### 描画グループ
|
|
||||||
|
|
||||||
| パラメータ名 | 型 | デフォルト | スライダー表示範囲 | アニメーション | 説明 |
|
|
||||||
|---|---|---|---|---|---|
|
|
||||||
| 濃度 | 数値 | 80% | 0〜100% | 対応 | 墨の濃さです。 |
|
|
||||||
| かすれ | 数値 | 40% | 0〜100% | 対応 | 紙目によるかすれと縁の荒れの強さです。 |
|
|
||||||
| 墨色 | 色 | #1E1A18 | — | 非対応 | 墨の色です。 |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 制限事項
|
## 制限事項
|
||||||
|
|
||||||
- AviUtl向けのEXO出力には対応していません。
|
- 墨を置く場所の判定には、現在のフレームの不透明度だけを使います。色と明るさは判定に影響しません。
|
||||||
- Direct3D 12デバイスを取得できない場合や、YMM4が使うDirect3D 11デバイスとの共有テクスチャおよび共有フェンスを作成できない場合は、エフェクトを適用せず入力映像を表示します。
|
- 素材の長辺が 8160px を超えるときは、計算領域の余白を取れないため、映像をそのまま通します。
|
||||||
- 墨の付置の判定には現在のフレームのアルファ値だけを使用します。輝度と色は判定に影響しません。履歴フレーム、外部画像、学習済みモデルは使用しません。
|
- 「品質」が高いほど格子が細かくなり、計算の量と GPU のメモリの使用量が増えます。「到達距離」が長いほどステップ数が増えます。
|
||||||
- 計算領域は素材の範囲に到達距離と描画の余白を加えた大きさで、長辺は8192画素が上限です。素材が大きく余白を確保できない場合は、エフェクトを適用せず入力映像を表示します。
|
- 墨は素材の外側にも描くため、出力範囲は素材の範囲より広がります。
|
||||||
- 処理量とGPUメモリ使用量は、計算領域の大きさと品質に応じて増えます。
|
- Direct3D 12 のデバイスか、YMM4 の Direct3D 11 との共有テクスチャや共有フェンスを作れないときは、映像をそのまま通します。
|
||||||
|
- AviUtl の exo ファイルへの書き出しには対応していません。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 注意事項
|
## 注意事項
|
||||||
|
|
||||||
- 処理負荷: 最高品質は格子解像度と浸透ステップ数が最も多いため、高品質と標準より処理負荷が高くなります。到達距離を大きくするほど計算領域が広がります。描画は墨が存在する最小の矩形の範囲だけを計算します。
|
- 処理の重さ: 浸透の結果は、素材の形と不透明度と、「水量」から「シード」までの浸透の設定と、「品質」が変わらない限り使い回します。「強さ」「拡散度」「濃度」「かすれ」「墨色」だけを変えても計算し直しません。形が変わり続けるアイテムでは毎フレーム計算し直すため、重いときは「品質」を「標準」にするか、「到達距離」を短くしてください。
|
||||||
- キャッシュ: 素材の形とにじみを決めるパラメータが変わらないフレームでは、浸透の計算を再利用します。拡散度、濃度、かすれ、墨色だけを変えたフレームでは、にじみを再計算しません。
|
- 更新の確認: アイテムに墨拡散を追加するか、墨拡散を含むプロジェクトを開いたときに、YMM4 の起動ごとに一度だけ GitHub のリリースを確認し、新しいものがあればメッセージで知らせます。プレリリースは対象に含めません。
|
||||||
- 拡散度0%と強さ0%: 拡散度が0%のときは何も描画しません。強さが0%のときは入力を変更しません。
|
- 不具合の自動送信: 想定していない例外が起きたときは、その内容を開発者へ自動で送信します。内容は「不具合の報告」に書いています。
|
||||||
- シードと再現性: にじみの形は、シード、セル位置、浸透ステップから決定論的に算出します。時間値はにじみの生成に使用しません。
|
- 本プラグインを使用する前に、YMM4 プロジェクトファイルのバックアップを作成することを推奨します。
|
||||||
- 透明部分: 墨は素材の外側にも描画されるため、出力範囲は素材より広がります。墨は元映像の上へアルファ合成します。
|
|
||||||
- 更新通知: エフェクトを最初に生成したときに、YMM4の実行中に一度だけ新しい正式版を確認します。更新情報を取得できない場合は通知せず、そのまま動作します。プレリリースは通知の対象に含めません。
|
---
|
||||||
- 本プラグインを使用する前に、YMM4のプロジェクトファイルのバックアップを作成することを推奨します。
|
|
||||||
|
## 不具合の報告
|
||||||
|
|
||||||
|
本プラグインは、想定していない例外が起きたときに、その内容を開発者へ自動で送信します。同意は求めません。止める設定もありません。
|
||||||
|
|
||||||
|
送信する数には上限があります。YMM4 の 1 回の起動で送る報告は、YMM4-Telemetry で報告する別のプラグインと合わせて 20 件までです。例外の型と発生位置が同じ報告は 3 件までです。上限を超えた報告と、送信先から待つよう求められている間に起きた報告は、送信も退避もしません。
|
||||||
|
|
||||||
|
送信する情報は次のとおりです。
|
||||||
|
|
||||||
|
| 種類 | 内容 |
|
||||||
|
|---|---|
|
||||||
|
| 例外 | 型の完全名、メッセージ、スタックトレース |
|
||||||
|
| 発生位置 | モジュール名、関数名、ファイル名、行番号、プラグイン自身のコードかどうか |
|
||||||
|
| プラグイン | アセンブリ名、バージョン |
|
||||||
|
| 実行環境 | OS の名前とバージョン、.NET のバージョン、CPU のアーキテクチャ、論理プロセッサ数 |
|
||||||
|
| 識別子 | YMM4 の起動ごとに決まるセッション識別子、報告ごとの識別子 |
|
||||||
|
| 時刻 | 報告を作った時刻(UTC) |
|
||||||
|
|
||||||
|
メッセージとファイル名は、送信の前に置き換えを通します。置き換えるのは、Windows のユーザー名、ユーザーフォルダー、AppData のパス、マシン名、ドメイン名、メールアドレス、IPv4 アドレスです。送信元の IP アドレスは受信側へ渡す手前で取り除いています。
|
||||||
|
|
||||||
|
映像の中身とプロジェクトの内容は送信しません。継続して個人を追跡する識別子も持ちません。セッション識別子は YMM4 を起動し直すと別の値になります。
|
||||||
|
|
||||||
|
送信するのは想定していない例外だけです。YMM4 が本プラグインのエフェクトを作るとき、フレームごとに更新するとき、入力をつなぎ直すとき、破棄するときと、Direct2D がシェーダーの定数を書き込むときに起きた例外を報告し、その後は YMM4 へそのまま渡します。更新の確認では、更新情報の取得と比較で起きた例外は報告しません。通知の文を組み立てて表示するときに起きた例外は報告し、YMM4 へは渡しません。画面の操作やバックグラウンドの処理で未処理になった例外も報告しますが、本プラグインのコードが関わる例外に限ります。本プラグインの外で起きた例外は送信しません。
|
||||||
|
|
||||||
|
次の失敗は送信しません。
|
||||||
|
|
||||||
|
| 種類 | 例 |
|
||||||
|
|---|---|
|
||||||
|
| 効果をかけないだけで済ませるもの | Direct3D 12 のデバイスを作れない、YMM4 の Direct3D 11 との共有テクスチャや共有フェンスを作れない、計算領域の余白を取れないときに、映像をそのまま通したとき |
|
||||||
|
| 更新の確認の通信の失敗 | manjubox.net と GitHub のどちらへも接続できない |
|
||||||
|
|
||||||
|
送信できなかった報告は YMM4 のユーザーフォルダーへ退避します。次に YMM4 を起動したあと、本プラグインのエフェクトを生成するか、同じく YMM4-Telemetry で報告する別のプラグインが動き始めると、退避した報告を 1 回の起動で 10 件まで送り直します。送信も再送も非同期に行うため、通信を待って起動と描画が遅くなることはありません。
|
||||||
|
|
||||||
|
実装は [YMM4-Telemetry](https://github.com/routersys/YMM4-Telemetry) をサブモジュールとして取り込んでいます。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 免責事項
|
## 免責事項
|
||||||
|
|
||||||
本プラグインはMITライセンスのもとで公開されています。
|
本プラグインは MIT ライセンスのもとで公開されています。
|
||||||
|
|
||||||
本ソフトウェアは「現状のまま」提供されており、明示または黙示を問わず、商品性、特定目的への適合性、および権利非侵害に関する保証を含む、いかなる種類の保証も行いません。
|
本ソフトウェアは「現状のまま」提供されており、明示・黙示を問わず、商品性、特定目的への適合性、および権利非侵害に関する保証を含む、いかなる種類の保証も行いません。
|
||||||
|
|
||||||
作者は、本プラグインの使用または使用不能に起因するいかなる損害についても、一切の責任を負いません。ご利用は自己責任でお願いします。
|
作者は、本プラグインの使用または使用不能に起因するいかなる損害についても、一切の責任を負いません。
|
||||||
|
ご利用は自己責任でお願いします。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## サードパーティライセンス
|
## サードパーティライセンス
|
||||||
|
|
||||||
本プラグインは以下のサードパーティソフトウェアを同梱・使用しています。ライセンスの全文は、リポジトリの [`.github/LICENSE/ComputeSharp.txt`](.github/LICENSE/ComputeSharp.txt) と、配布パッケージの `LICENSE` フォルダーに収録しています。
|
本プラグインは次のサードパーティソフトウェアを同梱しています。ライセンスの全文は、リポジトリの [`.github/LICENSE/ComputeWeave.txt`](.github/LICENSE/ComputeWeave.txt) と、配布パッケージの `LICENSE` フォルダーに収録しています。
|
||||||
|
|
||||||
| ソフトウェア | 用途 | ライセンス | 著作権表示 |
|
| ソフトウェア | 用途 | ライセンス | 著作権表示 |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| [ComputeSharp](https://github.com/routersys/ComputeSharp) | Direct3D 12計算シェーダーとDirect3D 11・12共有処理 | MIT License | Copyright (c) 2024 Sergio Pedri |
|
| [ComputeWeave](https://github.com/routersys/ComputeWeave) | Direct3D 12 の計算シェーダーと、Direct3D 11 との共有処理 | MIT License | Copyright (c) 2024 Sergio Pedri |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
# セキュリティポリシー
|
||||||
|
|
||||||
|
## サポートするバージョン
|
||||||
|
|
||||||
|
セキュリティの修正は、最新のリリースだけを対象にします。
|
||||||
|
|
||||||
|
| バージョン | サポート |
|
||||||
|
|---|---|
|
||||||
|
| 最新のリリース | 対象 |
|
||||||
|
| それより前のリリース | 対象外 |
|
||||||
|
|
||||||
|
修正は、最新のリリースの次のバージョンとして公開します。報告する前に、最新のリリースでも問題が起きるかを確かめてください。
|
||||||
|
|
||||||
|
## 対象とする問題
|
||||||
|
|
||||||
|
本プラグインのコードと配布パッケージに原因がある問題を対象にします。たとえば次のようなものです。
|
||||||
|
|
||||||
|
- 細工したプロジェクトファイルや素材を開くと、意図しない処理が実行される
|
||||||
|
- 更新の確認などで行う通信の内容を、第三者が書き換えられる
|
||||||
|
- 不具合の情報を自動で送信するプラグインで、個人を特定できる情報が伏せられないまま送信される
|
||||||
|
|
||||||
|
配布パッケージに同梱したライブラリの脆弱性は、本プラグインを通じて悪用できる場合に対象にします。
|
||||||
|
|
||||||
|
YukkuriMovieMaker4 本体や、ほかのプラグインに原因がある問題は対象外です。それぞれの開発者へ報告してください。
|
||||||
|
|
||||||
|
## 報告の方法
|
||||||
|
|
||||||
|
脆弱性は、公開の Issue に書かないでください。修正を公開する前に悪用されるおそれがあります。
|
||||||
|
|
||||||
|
1. リポジトリの URL の末尾に `/security` を付けたページを開き、「Report a vulnerability」から非公開で報告してください。報告の内容を見られるのは、開発者と報告した人、開発者が招いた人だけです。
|
||||||
|
2. この方法が使えないときは、github.routersys@gmail.com へメールで報告してください。
|
||||||
|
|
||||||
|
報告には、次の内容を書いてください。分からない項目は書かなくて構いません。
|
||||||
|
|
||||||
|
| 項目 | 内容 |
|
||||||
|
|---|---|
|
||||||
|
| バージョン | 問題を確かめたプラグインのバージョンと、YukkuriMovieMaker4 のバージョン |
|
||||||
|
| 再現の手順 | 問題を起こす操作と、使ったプロジェクトファイルや素材 |
|
||||||
|
| 影響 | 問題によって何ができてしまうか |
|
||||||
|
| 回避策 | 分かっていれば、修正までの間に被害を避ける方法 |
|
||||||
|
|
||||||
|
## 報告の後
|
||||||
|
|
||||||
|
開発者は、報告を受け取ったら内容を確かめ、修正の見込みを返信します。
|
||||||
|
|
||||||
|
報告した人は、修正を含むバージョンが出るまで、報告の内容を明かさないでください。問題の詳細は、修正版の公開後に開発者が公表します。
|
||||||
サブモジュール
+1
サブモジュール YMM4-Telemetry が 04010903ca で追加されました。
バイナリファイルは表示されません。
|
変更前 幅: | 高さ: | サイズ: 658 KiB 変更後 幅: | 高さ: | サイズ: 1005 KiB |
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"test": {
|
||||||
|
"runner": "Microsoft.Testing.Platform"
|
||||||
|
}
|
||||||
|
}
|
||||||
新しいイシューから参照
ユーザーをブロックする