Skip to content

Commit

Permalink
Aircraft/VC lighting tweaks separated
Browse files Browse the repository at this point in the history
Switched from label to textblock for preset name
  • Loading branch information
LB767 committed Mar 22, 2018
1 parent f5751b9 commit 0d82121
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 57 deletions.
10 changes: 9 additions & 1 deletion OpenShade/Classes/Tweak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,15 @@ public static void GenerateTweaksData(List<Tweak> tweaks)
newTweak.parameters.Add(new Parameter("MoonAmbientCoeff", "Ambient moonlight ratio", 1, 1, 0.1, 5, UIType.Text));
newTweak.parameters.Add(new Parameter("MoonDiffuseCoeff", "Diffuse moonlight ratio", 1, 1, 0.1, 5, UIType.Text));
newTweak.parameters.Add(new Parameter("SaturateRatio", "Saturation", 1, 1, 0, 2, UIType.Text));
newTweak.parameters.Add(new Parameter("VCOnly", "Adjust only internal/virtual cockpit view", 0, 0, 0, 1, UIType.Checkbox));
// newTweak.parameters.Add(new Parameter("VCOnly", "Adjust only internal/virtual cockpit view", 0, 0, 0, 1, UIType.Checkbox));
tweaks.Add(newTweak);

newTweak = new Tweak("LIGHTING_VC_LIGHTING", Category.Lighting, "Cockpit lighting and saturation", "");
newTweak.parameters.Add(new Parameter("SunAmbientCoeff", "Ambient sunlight ratio", 1, 1, 0.1, 5, UIType.Text));
newTweak.parameters.Add(new Parameter("SunDiffuseCoeff", "Diffuse sunlight ratio", 1, 1, 0.1, 5, UIType.Text));
newTweak.parameters.Add(new Parameter("MoonAmbientCoeff", "Ambient moonlight ratio", 1, 1, 0.1, 5, UIType.Text));
newTweak.parameters.Add(new Parameter("MoonDiffuseCoeff", "Diffuse moonlight ratio", 1, 1, 0.1, 5, UIType.Text));
newTweak.parameters.Add(new Parameter("SaturateRatio", "Saturation", 1, 1, 0, 2, UIType.Text));
tweaks.Add(newTweak);

newTweak = new Tweak("LIGHTING_AUTOGEN_EMISSIVE", Category.Lighting, "Autogen emissive lighting", "");
Expand Down
4 changes: 2 additions & 2 deletions OpenShade/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@
</StackPanel>

<Label Grid.Column="1" Grid.Row="0" VerticalAlignment="Bottom" Content="Loaded Preset:"/>
<Label Grid.Column="2" Grid.Row="0" VerticalAlignment="Bottom" Content="" x:Name="LoadedPreset_Label" Width="Auto"/>
<TextBlock Grid.Column="2" Grid.Row="0" VerticalAlignment="Bottom" Text="" x:Name="LoadedPreset_TextBlock" Width="Auto" Foreground="{DynamicResource TextColor}"/>

<Label Grid.Column="1" Grid.Row="1" VerticalAlignment="Bottom" Content="Active Preset:"/>
<Label Grid.Column="2" Grid.Row="1" VerticalAlignment="Bottom" Content="" x:Name="ActivePreset_Label" Width="Auto"/>
<TextBlock Grid.Column="2" Grid.Row="1" VerticalAlignment="Bottom" Text="" x:Name="ActivePreset_TextBlock" Width="Auto" Foreground="{DynamicResource TextColor}"/>

</Grid>

Expand Down
169 changes: 116 additions & 53 deletions OpenShade/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
try
{
loadedPreset = new IniFile(loadedPresetPath);
LoadedPreset_Label.Content = loadedPreset.filename;
LoadedPreset_TextBlock.Text = loadedPreset.filename;
LoadPreset(loadedPreset, false);
Log(ErrorType.None, "Preset [" + loadedPreset.filename + "] loaded");
}
Expand All @@ -172,7 +172,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
if (File.Exists(activePresetPath))
{
activePreset = new IniFile(activePresetPath);
ActivePreset_Label.Content = activePreset.filename;
ActivePreset_TextBlock.Text = activePreset.filename;
}
else
{
Expand Down Expand Up @@ -866,7 +866,7 @@ private void NewPreset_Click(object sender, RoutedEventArgs e)
}

loadedPreset = new IniFile(loadedPresetPath);
LoadedPreset_Label.Content = loadedPreset.filename;
LoadedPreset_TextBlock.Text = loadedPreset.filename;

Log(ErrorType.None, "New Preset [" + loadedPreset.filename + "] created");
}
Expand Down Expand Up @@ -895,7 +895,7 @@ private void OpenPreset_Click(object sender, RoutedEventArgs e)
{
loadedPresetPath = dlg.FileName;
loadedPreset = new IniFile(loadedPresetPath);
LoadedPreset_Label.Content = loadedPreset.filename;
LoadedPreset_TextBlock.Text = loadedPreset.filename;
LoadPreset(loadedPreset, true);
Log(ErrorType.None, "Preset [" + loadedPreset.filename + "] loaded");
}
Expand All @@ -906,7 +906,7 @@ private void OpenPreset_Click(object sender, RoutedEventArgs e)
// Revert to previous preset
loadedPresetPath = backupPresetPath;
loadedPreset = new IniFile(backupPresetPath);
LoadedPreset_Label.Content = loadedPreset.filename;
LoadedPreset_TextBlock.Text = loadedPreset.filename;
LoadPreset(loadedPreset, true);
}
}
Expand Down Expand Up @@ -947,7 +947,7 @@ private void SavePreset_Click(object sender, RoutedEventArgs e)
}

loadedPreset = new IniFile(loadedPresetPath);
LoadedPreset_Label.Content = loadedPreset.filename;
LoadedPreset_TextBlock.Text = loadedPreset.filename;
}

comment = PresetComments_TextBox.Text;
Expand Down Expand Up @@ -992,7 +992,7 @@ private void SavePresetAs_Click(object sender, RoutedEventArgs e)

loadedPresetPath = newPresetPath;
loadedPreset = newPreset;
LoadedPreset_Label.Content = loadedPreset.filename;
LoadedPreset_TextBlock.Text = loadedPreset.filename;
Log(ErrorType.None, "Preset [" + loadedPreset.filename + "] saved in " + loadedPreset.filepath);
}
catch (Exception ex)
Expand Down Expand Up @@ -1108,10 +1108,11 @@ private void ApplyPreset(object sender, RoutedEventArgs e)
// NOTE: Object lighting and Aircraft lighting and saturation interract quite heavily with each other
// Making something clearer might be a decent idea to avoid headaches...
case "Objects lighting":
currentFile = FileIO.funclibFile;
{
currentFile = FileIO.funclibFile;

funclibText = funclibText.AddBefore(ref success, "void DirectionalLighting",
$@"void DirectionalLightingTweak(const float3 vNormalWS, const float shadowContrib, float tweak1, float tweak2, float tweak3, float tweak4,
funclibText = funclibText.AddBefore(ref success, "void DirectionalLighting",
$@"void DirectionalLightingTweak(const float3 vNormalWS, const float shadowContrib, float tweak1, float tweak2, float tweak3, float tweak4,
out float3 diffuseAndAmbient)
{{
#if defined(SHD_VERTICAL_NORMAL)
Expand All @@ -1127,32 +1128,36 @@ private void ApplyPreset(object sender, RoutedEventArgs e)
}}
");

currentFile = FileIO.generalFile;
currentFile = FileIO.generalFile;

string aircraftLighting = "";
Tweak aircraft = tweaks.First(p => p.name == "Aircraft lighting and saturation");
if (aircraft.isEnabled)
{
aircraftLighting = "&&& ADD THE AIRCRAFT LIGHTING TWEAK HERE &&&";
}
string aircraftLighting = "";
Tweak aircraft = tweaks.First(p => p.name == "Aircraft lighting and saturation");
if (aircraft.isEnabled)
{
aircraftLighting = "&&& ADD THE AIRCRAFT LIGHTING TWEAK HERE &&&";
}

generalText = generalText.ReplaceAll(ref success, "DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);",
$@"if (cb_mObjectType != 19)
generalText = generalText.ReplaceAll(ref success, "DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);",
$@"if (cb_mObjectType != 19)
DirectionalLightingTweak(vNormalWS, shadowContrib, {tweak.parameters[0].value}, {tweak.parameters[1].value}, {tweak.parameters[2].value}, {tweak.parameters[3].value}, directionalDiffuse);
{aircraftLighting}
else
DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);
"
);

break;
);

break;
}

case "Aircraft lighting and saturation":
if (funclibText.IndexOf("DirectionalLightingTweak") < 0) {
currentFile = FileIO.funclibFile;
{
// Check if the tweaked function already exists (comes from objects lighting)
if (funclibText.IndexOf("DirectionalLightingTweak") < 0)
{
currentFile = FileIO.funclibFile;

funclibText = funclibText.AddBefore(ref success, "void DirectionalLighting",
$@"void DirectionalLightingTweak(const float3 vNormalWS, const float shadowContrib, float tweak1, float tweak2, float tweak3, float tweak4,
funclibText = funclibText.AddBefore(ref success, "void DirectionalLighting",
$@"void DirectionalLightingTweak(const float3 vNormalWS, const float shadowContrib, float tweak1, float tweak2, float tweak3, float tweak4,
out float3 diffuseAndAmbient)
{{
#if defined(SHD_VERTICAL_NORMAL)
Expand All @@ -1167,48 +1172,106 @@ private void ApplyPreset(object sender, RoutedEventArgs e)
(cb_mMoon.mAmbient.xyz * tweak3 + (shadowContrib * (cb_mMoon.mDiffuse.xyz * tweak4 * fDotMoon))));
}}
");
}
}


currentFile = FileIO.generalFile;
currentFile = FileIO.generalFile;

string replaceText = "DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);";
string elseText = "";
string finalText = @"else
string replaceText = "DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);";
string elseText = "";
string finalText = @"else
DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);";

if (generalText.IndexOf("&&& ADD THE AIRCRAFT LIGHTING TWEAK HERE &&&") >= 0)
{
replaceText = "&&& ADD THE AIRCRAFT LIGHTING TWEAK HERE &&&";
elseText = "else ";
finalText = "";
}
if (generalText.IndexOf("&&& ADD THE AIRCRAFT LIGHTING TWEAK HERE &&&") >= 0)
{
replaceText = "&&& ADD THE AIRCRAFT LIGHTING TWEAK HERE &&&";
elseText = "else ";
finalText = "";
}

if (tweak.parameters[5].value == "1")
{
// 1st - VC/interior
// 2nd - Aircraft
generalText = generalText.ReplaceAll(ref success, replaceText,

$@"#if !defined(PS_NEEDS_TANSPACE)
$@"#if !defined(PS_NEEDS_TANSPACE)
{elseText}if (cb_mObjectType == 19)
DirectionalLightingTweak(vNormalWS, shadowContrib, {tweak.parameters[0].value}, {tweak.parameters[1].value}, {tweak.parameters[2].value}, {tweak.parameters[3].value}, directionalDiffuse);
DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);
#else
{elseText}if (cb_mObjectType == 19)
DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);
DirectionalLightingTweak(vNormalWS, shadowContrib, {tweak.parameters[0].value}, {tweak.parameters[1].value}, {tweak.parameters[2].value}, {tweak.parameters[3].value}, directionalDiffuse);
#endif
{finalText}");

generalText = generalText.AddBefore(ref success, "// Apply IR if active", "if ((cb_mObjectType == (uint)0) || (cb_mObjectType == (uint)19))\r\n {\r\n cColor.rgb = saturate(lerp(dot(cColor.rgb, float3(0.299f, 0.587f, 0.114f)), cColor.rgb, " + tweak.parameters[4].value.ToString() + "));\r\n }\r\n");

break;
}
else

case "Cockpit lighting and saturation":
{
generalText = generalText.ReplaceAll(ref success, replaceText,

$@"{elseText}if (cb_mObjectType == 19)
DirectionalLightingTweak(vNormalWS, shadowContrib, {tweak.parameters[0].value}, {tweak.parameters[1].value}, {tweak.parameters[2].value}, {tweak.parameters[3].value}, directionalDiffuse);
// Check if the tweaked function already exists (comes from objects lighting or Aircraft lighting)
if (funclibText.IndexOf("DirectionalLightingTweak") < 0)
{
currentFile = FileIO.funclibFile;

funclibText = funclibText.AddBefore(ref success, "void DirectionalLighting",
$@"void DirectionalLightingTweak(const float3 vNormalWS, const float shadowContrib, float tweak1, float tweak2, float tweak3, float tweak4,
out float3 diffuseAndAmbient)
{{
#if defined(SHD_VERTICAL_NORMAL)
const float fDotSun = max(cb_mSun.mDirection.y, 0);
const float fDotMoon = max(cb_mMoon.mDirection.y, 0);
#else
const float fDotSun = saturate(dot(vNormalWS, normalize(cb_mSun.mDirection)));
const float fDotMoon = saturate(dot(vNormalWS, normalize(cb_mMoon.mDirection)));
#endif
diffuseAndAmbient = saturate((cb_mSun.mAmbient.xyz * tweak1 + (shadowContrib * (cb_mSun.mDiffuse.xyz * tweak2 * fDotSun))) +
(cb_mMoon.mAmbient.xyz * tweak3 + (shadowContrib * (cb_mMoon.mDiffuse.xyz * tweak4 * fDotMoon))));
}}
");
}


currentFile = FileIO.generalFile;

string replaceText = "DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);";
string elseText = "";
string finalText = @"else
DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);";

if (generalText.IndexOf("&&& ADD THE AIRCRAFT LIGHTING TWEAK HERE &&&") >= 0)
{
replaceText = "&&& ADD THE AIRCRAFT LIGHTING TWEAK HERE &&&";
elseText = "else ";
finalText = "";
}

Tweak aircraft = tweaks.First(p => p.name == "Aircraft lighting and saturation");
if (aircraft.isEnabled) {
generalText = generalText.ReplaceFirst(ref success, replaceText, $"DirectionalLightingTweak(vNormalWS, shadowContrib, { tweak.parameters[0].value}, { tweak.parameters[1].value}, { tweak.parameters[2].value}, { tweak.parameters[3].value}, directionalDiffuse);");
}
else {
// 1st - VC/interior
// 2nd - Aircraft
generalText = generalText.ReplaceAll(ref success, replaceText,

$@"#if !defined(PS_NEEDS_TANSPACE)
{elseText}if (cb_mObjectType == 19)
DirectionalLightingTweak(vNormalWS, shadowContrib, {tweak.parameters[0].value}, {tweak.parameters[1].value}, {tweak.parameters[2].value}, {tweak.parameters[3].value}, directionalDiffuse);
#else
{elseText}if (cb_mObjectType == 19)
DirectionalLighting(vNormalWS, shadowContrib, directionalDiffuse);
#endif
{finalText}");
}

generalText = generalText.AddBefore(ref success, "// Apply IR if active", "if ((cb_mObjectType == (uint)0) || (cb_mObjectType == (uint)19))\r\n {\r\n cColor.rgb = saturate(lerp(dot(cColor.rgb, float3(0.299f, 0.587f, 0.114f)), cColor.rgb, " + tweak.parameters[4].value.ToString() + "));\r\n }\r\n");
generalText = generalText.AddBefore(ref success, "// Apply IR if active", "if ((cb_mObjectType == (uint)0) || (cb_mObjectType == (uint)19))\r\n {\r\n cColor.rgb = saturate(lerp(dot(cColor.rgb, float3(0.299f, 0.587f, 0.114f)), cColor.rgb, " + tweak.parameters[4].value.ToString() + "));\r\n }\r\n");
}

break;
}

break;

case "Autogen emissive lighting":
currentFile = FileIO.generalFile;
Expand Down Expand Up @@ -2044,7 +2107,7 @@ float4 TechnicolorMain(PsQuad vert, float4 color) : SV_Target
{
activePresetPath = loadedPresetPath;
activePreset = loadedPreset;
ActivePreset_Label.Content = activePreset.filename;
ActivePreset_TextBlock.Text = activePreset.filename;

Log(ErrorType.None, "Preset [" + activePreset.filename + "] applied. "
+ tweakCount + "/" + tweaks.Count(p => p.isEnabled == true) + " tweaks applied. "
Expand All @@ -2054,7 +2117,7 @@ float4 TechnicolorMain(PsQuad vert, float4 color) : SV_Target
else {
activePresetPath = loadedPresetPath; // becomes null
activePreset = loadedPreset; // becomes null
ActivePreset_Label.Content = "";
ActivePreset_TextBlock.Text = "";

Log(ErrorType.None, "Tweaks applied. "
+ tweakCount + "/" + tweaks.Count(p => p.isEnabled == true) + " tweaks applied. "
Expand Down Expand Up @@ -2082,7 +2145,7 @@ private void ResetShaderFiles(object sender, RoutedEventArgs e)
{
activePresetPath = null;
activePreset = null;
ActivePreset_Label.Content = "";
ActivePreset_TextBlock.Text = "";

Log(ErrorType.None, "Shader files restored");

Expand Down Expand Up @@ -2114,7 +2177,7 @@ private void ResetToPreset(object sender, RoutedEventArgs e)
{
loadedPresetPath = activePresetPath;
loadedPreset = activePreset;
LoadedPreset_Label.Content = loadedPreset.filename;
LoadedPreset_TextBlock.Text = loadedPreset.filename;
LoadPreset(activePreset, false);

List_SelectionChanged(Tweak_List, TweakStack, TweakClearStack, TweakTitleTextblock, TweakDescriptionTextblock);
Expand Down
Loading

0 comments on commit 0d82121

Please sign in to comment.