Skip to content

Commit 5db09a0

Browse files
committed
misc fixes
1 parent 6d06b72 commit 5db09a0

8 files changed

Lines changed: 75 additions & 23 deletions

File tree

LuaLUT.Tests/LuaLUT.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
@@ -17,13 +17,13 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
21-
<PackageReference Include="xunit" Version="2.4.2" />
22-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
21+
<PackageReference Include="xunit" Version="2.9.2" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
<PrivateAssets>all</PrivateAssets>
2525
</PackageReference>
26-
<PackageReference Include="coverlet.collector" Version="3.2.0">
26+
<PackageReference Include="coverlet.collector" Version="6.0.2">
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2828
<PrivateAssets>all</PrivateAssets>
2929
</PackageReference>

LuaLUT/Internal/ImageWriter/StandardImageWriter.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ internal class StandardImageWriter : ImageWriterBase
1313
{
1414
private readonly ImageType imageType;
1515

16-
public int DepthSlice {get; set;}
16+
public int? SliceX {get; set;}
17+
public int? SliceY {get; set;}
18+
public int? SliceZ {get; set;}
1719

1820

1921
public StandardImageWriter(Stream stream, ImageType imageType) : base(stream)
2022
{
2123
this.imageType = imageType;
22-
23-
DepthSlice = 0;
2424
}
2525

2626
public override async Task ProcessAsync(string luaScript, CancellationToken token = default)
@@ -47,12 +47,29 @@ public override async Task ProcessAsync(string luaScript, CancellationToken toke
4747
processor.Initialize();
4848

4949
for (var x = 0; x < ImageWidth; x++) {
50-
var pixel = ImageDimensions switch {
51-
3 => processor.ProcessPixel(point.X + x, point.Y, DepthSlice),
52-
2 => processor.ProcessPixel(point.X + x, point.Y),
53-
1 => processor.ProcessPixel(point.X + x),
54-
_ => throw new ApplicationException($"Unsupported dimension count '{ImageDimensions}'!"),
55-
};
50+
object[] pixel;
51+
52+
switch (ImageDimensions) {
53+
case 3:
54+
if (SliceX.HasValue) {
55+
pixel = processor.ProcessPixel(SliceX.Value, point.X + x, point.Y);
56+
}
57+
else if (SliceY.HasValue) {
58+
pixel = processor.ProcessPixel(point.X + x, SliceY.Value, point.Y);
59+
}
60+
else {
61+
pixel = processor.ProcessPixel(point.X + x, point.Y, SliceZ ?? 0);
62+
}
63+
break;
64+
case 2:
65+
pixel = processor.ProcessPixel(point.X + x, point.Y);
66+
break;
67+
case 1:
68+
pixel = processor.ProcessPixel(point.X + x);
69+
break;
70+
default:
71+
throw new ApplicationException($"Unsupported dimension count '{ImageDimensions}'!");
72+
}
5673

5774
if (PixelFormat is PixelFormat.R_NORM or PixelFormat.R_INT) {
5875
var value = Convert.ToSingle((double)pixel[0]);

LuaLUT/Internal/MainOptions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ internal class MainOptions
3030
[Option('d', "depth", Required = false, HelpText = "The depth [z] of the LUT image to generate.")]
3131
public int? ImageDepth { get; set; }
3232

33-
[Option('z', "slice", Required = false, HelpText = "The depth slice [z] of the LUT image to generate.")]
34-
public int? DepthSlice { get; set; }
33+
[Option('x', Required = false, HelpText = "The Y/Z slice [x] of the LUT image to generate.")]
34+
public int? SliceX { get; set; }
35+
36+
[Option('y', Required = false, HelpText = "The X/Z slice [y] of the LUT image to generate.")]
37+
public int? SliceY { get; set; }
38+
39+
[Option('z', "slice", Required = false, HelpText = "The X/Y slice [z] of the LUT image to generate.")]
40+
public int? SliceZ { get; set; }
3541

3642
[Option('v', "var", Required = false, Separator = '|', HelpText = "An optional list of variables.")]
3743
public IEnumerable<string> CustomVariables { get; set; }

LuaLUT/LuaLUT.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Authors>null511</Authors>
77
<AssemblyVersion>0.4</AssemblyVersion>
88
<FileVersion>0.4</FileVersion>
@@ -19,9 +19,9 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="CommandLineParser" Version="2.9.1" />
22-
<PackageReference Include="NLua" Version="1.6.2" />
23-
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
24-
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="7.0.0" />
22+
<PackageReference Include="NLua" Version="1.7.3" />
23+
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.4" />
24+
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="9.0.0" />
2525
</ItemGroup>
2626

2727
</Project>

LuaLUT/LuaScripts/GLSL.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,24 @@ function mod(a, b)
9090
return a % b
9191
end
9292

93+
function modf(a, b)
94+
if vec.isVec(a) or vec.isVec(b) then
95+
return vec.modf(a, b)
96+
else
97+
return math.modf(a, b)
98+
end
99+
end
100+
93101
function normalize(val)
94102
return vec.normalize(val)
95103
end
96104

97105
function pow(val, power)
98-
return val ^ power
106+
if vec.isVec(val) or vec.isVec(power) then
107+
return vec.pow(val, power)
108+
else
109+
return val ^ power
110+
end
99111
end
100112

101113
function rcp(val)
@@ -133,3 +145,7 @@ end
133145
function vec3(val)
134146
return vec(val, val, val)
135147
end
148+
149+
function vec4(val)
150+
return vec(val, val, val, val)
151+
end

LuaLUT/LuaScripts/GLSL_vec.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ end
444444
apiTable.max = makeBinaryOp (math.max)
445445
apiTable.min = makeBinaryOp (math.min)
446446
apiTable.mix = makeTertiaryOp(math.mix)
447+
--apiTable.mod = makeUnaryOp (math.mod)
447448
apiTable.modf = function(a)
448449
local intPart = {}
449450
local fracPart = {}

LuaLUT/Program.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
using LuaLUT.Internal.ImageWriter;
44
using LuaLUT.Internal.PixelWriter;
55
using LuaLUT.Internal.Samplers;
6+
using NLua.Exceptions;
67
using System;
78
using System.Diagnostics;
89
using System.IO;
910
using System.Linq;
1011
using System.Threading;
1112
using System.Threading.Tasks;
12-
using NLua.Exceptions;
1313

1414
namespace LuaLUT;
1515

@@ -77,6 +77,11 @@ private static async Task RunOptionsAsync(MainOptions options)
7777
writer.ImageHeight = options.ImageHeight ?? 1;
7878
writer.ImageDepth = options.ImageDepth ?? 1;
7979

80+
if (options.ImageDepth.HasValue) {
81+
if (options.SliceX.HasValue || options.SliceY.HasValue)
82+
writer.ImageHeight = writer.ImageDepth;
83+
}
84+
8085
writer.ImageDimensions = 1;
8186
if (options.ImageHeight.HasValue)
8287
writer.ImageDimensions = options.ImageDepth.HasValue ? 3 : 2;
@@ -154,7 +159,9 @@ private static IImageWriter GetImageWriter(Stream outputStream, MainOptions opti
154159

155160
if (imageType != ImageType.Raw)
156161
return new StandardImageWriter(outputStream, imageType) {
157-
DepthSlice = options.DepthSlice ?? 0,
162+
SliceX = options.SliceX,
163+
SliceY = options.SliceY,
164+
SliceZ = options.SliceZ,
158165
PixelFormat = pixelFormat,
159166
PixelType = pixelType,
160167
};

LuaLUT/Properties/launchSettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
"commandName": "Project",
1414
"commandLineArgs": "--script \"D:\\\\MC-Shader\\\\Shrimple\\\\tools\\\\lua\\\\noise.lua\"\r\n--out \"D:\\\\MC-Shader\\\\Shrimple\\\\tools\\\\preview\\\\\"\r\n--img \"PNG\" --format \"RG\" --type UNSIGNED_BYTE\r\n-w 512 -h 512",
1515
"workingDirectory": "D:\\\\MC-Shader\\\\Shrimple\\\\tools"
16+
},
17+
"Detail-Atlas": {
18+
"commandName": "Project",
19+
"commandLineArgs": "--script \"D:\\\\MC-Shader\\\\Shrimple\\\\tools\\\\lua\\\\detail-atlas.lua\"\r\n--out \"D:\\\\MC-Shader\\\\Shrimple\\\\tools\\\\preview\\\\\"\r\n--img \"PNG\" --format \"RGB\" --type UNSIGNED_BYTE\r\n-w 256 -h 256",
20+
"workingDirectory": "D:\\\\MC-Shader\\\\Shrimple\\\\tools"
1621
}
1722
}
1823
}

0 commit comments

Comments
 (0)