Skip to content

Commit 788a95d

Browse files
committed
YAY YIPPIE WOOHOO SOFT LIGHT!!
1 parent 2fa1c55 commit 788a95d

5 files changed

Lines changed: 44 additions & 1 deletion

File tree

TextureOverlayer/Textures/CombinedTexture.Addons.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,35 @@ private void MultiplyPixels(int y, ParallelLoopState _)
7474
_centerStorage.RgbaPixels[offset + 3] = rgba.A;
7575
}
7676
}
77+
private void SoftLight(int y, ParallelLoopState _)
78+
{
79+
for (var x = 0; x < _leftPixels.Width; ++x)
80+
{
81+
var offset = (_leftPixels.Width * y + x) * 4;
82+
var left = DataLeft(offset);
83+
var right = DataRight(x, y);
84+
var alpha = left.W;
85+
var product = new Vector4();
86+
product.W = right.W;
87+
product.X = (float)(right.X < .5
88+
? (2 * left.X *right.X) + (left.X * left.X * (1 - (2 * right.X))) : (2 * left.X *
89+
(1 - right.X)) + (Math.Sqrt(left.X) * ((2 * right.X) - 1)));
90+
product.Y = (float)(right.Y < .5
91+
? (2 * left.Y *right.Y ) + (left.Y * left.Y * (1 - (2 * right.Y))) : (2 * left.Y *
92+
(1 - right.Y)) + (Math.Sqrt(left.Y) * ((2 * right.Y) - 1)));
93+
product.Z = (float)(right.Z < .5
94+
? (2 * left.Z * right.Z) + (left.Z * left.Z * (1 - (2 * right.Z))) : (2 * left.Z *
95+
(1 - right.Z)) + (Math.Sqrt(left.Z) * ((2 * right.Z) - 1)));
96+
97+
var rgba = alpha == 0
98+
? new Rgba32()
99+
: new Rgba32(((product * product.W + left * left.W * (1 - product.W)) / alpha) with { W = alpha });
100+
_centerStorage.RgbaPixels[offset] = rgba.R;
101+
_centerStorage.RgbaPixels[offset + 1] = rgba.G;
102+
_centerStorage.RgbaPixels[offset + 2] = rgba.B;
103+
_centerStorage.RgbaPixels[offset + 3] = rgba.A;
104+
}
105+
}
106+
77107

78108
}

TextureOverlayer/Textures/CombinedTexture.Manipulation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private void MultiplyPixelsRight(int y, ParallelLoopState _)
189189
CombineOp.CopyChannels => ChannelMergePixelsMultiplied,
190190
CombineOp.SubtractChannels => SubtractPixels,
191191
CombineOp.MultiplyChannels => MultiplyPixels,
192+
CombineOp.SoftLight => SoftLight,
192193
_ => throw new InvalidOperationException($"Cannot combine images with operation {combineOp}"),
193194
});
194195
}

TextureOverlayer/Textures/CombinedTexture.Operations.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private enum CombineOp
1818
CopyChannels = 3,
1919
SubtractChannels = 4,
2020
MultiplyChannels = 5,
21+
SoftLight = 6,
2122
}
2223

2324
private enum ResizeOp
@@ -73,6 +74,7 @@ private static ResizeOp GetActualResizeOp(ResizeOp resizeOp, CombineOp combineOp
7374
CombineOp.CopyChannels => resizeOp,
7475
CombineOp.SubtractChannels => resizeOp,
7576
CombineOp.MultiplyChannels => resizeOp,
77+
CombineOp.SoftLight => resizeOp,
7678
_ => throw new ArgumentException($"Invalid combine operation {combineOp}"),
7779
};
7880

TextureOverlayer/Utils/TextureHandler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public enum CombineOp
3636
CopyChannels = 3,
3737
SubtractChannels = 4,
3838
MultiplyChannels = 5,
39+
SoftLight = 6,
3940
}
4041

4142

@@ -314,7 +315,8 @@ public static class TextureHandler
314315
"Right Multiply",
315316
"Copy Channels",
316317
"Subtract",
317-
"Multiply"
318+
"Multiply",
319+
"Soft Light"
318320
};
319321
public static IList<T> Swap<T>(IList<T> list, int indexA, int indexB)
320322
{

TextureOverlayer/Windows/MainWindow.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ public override void Draw()
440440
selectedCombination.Layers[selectedIndex]._combineOp = CombineOp.SubtractChannels;
441441
selectedCombination.Compile();
442442
}
443+
if (ImGui.Selectable(TextureHandler.ResizeOpLabels[6]))
444+
{
445+
selectedCombination.Layers[selectedIndex]._combineOp = CombineOp.SoftLight;
446+
selectedCombination.Compile();
447+
}
443448
/*if (ImGui.Selectable(TextureHandler.ResizeOpLabels[5]))
444449
{
445450
selectedCombination.Layers[selectedIndex]._combineOp = CombineOp.MultiplyChannels;
@@ -454,6 +459,9 @@ public override void Draw()
454459
}
455460
}
456461

462+
463+
//TODO: Add a library based on cached textures
464+
//TODO: Fix penumbra interface
457465
ImGui.TextUnformatted("New Layer from:");
458466

459467
/*if(ImGui.Button("Penumbra mod"))

0 commit comments

Comments
 (0)