Skip to content

Commit

Permalink
Fix compatibility mode (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit authored Feb 12, 2024
1 parent e6a174f commit ba45f8a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
7 changes: 7 additions & 0 deletions OpenDreamClient/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public sealed class EntryPoint : GameClient {
[Dependency] private readonly IDreamSoundEngine _soundEngine = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly ILightManager _lightManager = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;

private const string UserAgent =
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)";
Expand Down Expand Up @@ -76,6 +77,12 @@ public override void PostInit() {

_dreamInterface.Initialize();
IoCManager.Resolve<IDreamSoundEngine>().Initialize();

if (_configurationManager.GetCVar(CVars.DisplayCompat))
_dreamInterface.OpenAlert(
"Compatibility Mode Warning",
"You are using compatibility mode. Clicking in-game objects is not supported in this mode.",
"Ok", null, null, null);
}

protected override void Dispose(bool disposing) {
Expand Down
1 change: 1 addition & 0 deletions OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ public interface IDreamInterfaceManager {
void SaveScreenshot(bool openDialog);
void LoadInterfaceFromSource(string source);

public void OpenAlert(string title, string message, string button1, string? button2, string? button3, Action<DreamValueType, object?>? onClose);
void Prompt(DreamValueType types, string title, string message, string defaultValue, Action<DreamValueType, object?>? onClose);
void RunCommand(string fullCommand);
void StartRepeatingCommand(string command);
Expand Down
4 changes: 4 additions & 0 deletions OpenDreamClient/Interface/DummyDreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void WinSet(string? controlId, string winsetParams) {

}

public void OpenAlert(string title, string message, string button1, string? button2, string? button3, Action<DreamValueType, object?>? onClose) {

}

public void Prompt(DreamValueType types, string title, string message, string defaultValue, Action<DreamValueType, object?>? onClose) {

}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Shaders/alpha.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void fragment() {

// The mask is the average of RGB multiplied by A
// Haven't actually tested this in BYOND, but it does give us behavior seen in SS13
highp float mask = (mask_color.r + mask_color.g + mask_color.b) / 3 * mask_color.a;
highp float mask = (mask_color.r + mask_color.g + mask_color.b) / 3.0 * mask_color.a;

if(mask_invert_flag){
new_color.a *= 1.0-mask;
Expand Down
2 changes: 1 addition & 1 deletion Resources/Shaders/blendoverlay.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ void fragment() {
oldColor[2] * colorMatrix[3][2] +
oldColor[3] * colorMatrix[3][3];
COLOR = zFromSrgb(COLOR + offsetVector);
COLOR.rgb *= isPlaneMaster ? 1 : COLOR.a;
COLOR.rgb *= isPlaneMaster ? 1.0 : COLOR.a;
}
8 changes: 4 additions & 4 deletions Resources/Shaders/blur.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ highp vec4 blur(sampler2D sp, highp vec2 uv, highp vec2 scale) {
highp vec4 col = texture(sp, uv) * weight;
highp float accum = weight;

for (highp int x = 0; x <= size*5; ++x) {
for (highp int y = 1; y <= size*5; ++y) {
for (highp int x = 0; x <= int(size)*5; ++x) {
for (highp int y = 1; y <= int(size)*5; ++y) {
offset = vec2(x, y);
weight = gaussian(offset);
col += texture(sp, uv + scale * offset) * weight;
Expand All @@ -49,8 +49,8 @@ void vertex()
{
VERTEX = apply_mvp(VERTEX);
pos = (VERTEX + vec2(1.0)) / 2.0;
sigma = float(size*5) * 0.25;
sigma2 = 2. * sigma * sigma;
sigma = float(size*5.0) * 0.25;
sigma2 = 2.0 * sigma * sigma;
pisigma2 = pi * sigma2;
}

Expand Down
14 changes: 6 additions & 8 deletions Resources/Shaders/displacement.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ void fragment() {
highp vec2 iResolution = vec2(textureSize(TEXTURE, 0))/2.0; //input texture is doubled in size, but we need the original size
highp vec2 dResolution = vec2(textureSize(displacement_map, 0)); //this one is its original size

vec2 offset = vec2(x,y)/iResolution.xy;
vec2 maxdistortion = size/iResolution.xy;

highp vec2 offset = vec2(x,y)/iResolution.xy;
highp vec2 maxdistortion = size/iResolution.xy;

vec2 subcoord = ((UV * textureSize(TEXTURE, 0)/dResolution) + (0.5 - (textureSize(TEXTURE, 0)/dResolution)/2.0)) + offset;
highp vec2 subcoord = ((UV * vec2(textureSize(TEXTURE, 0))/dResolution) + (0.5 - (vec2(textureSize(TEXTURE, 0))/dResolution)/2.0)) + offset;
//sample the displacement map
vec4 dis = texture(displacement_map, subcoord);
highp vec4 dis = texture(displacement_map, subcoord);
dis.r = (clamp(dis.r, 0.5-maxdistortion.x, 0.5+maxdistortion.x) - 0.5) * dis.a;//center them and apply alpha
dis.g = (clamp(dis.g, 0.5-maxdistortion.y, 0.5+maxdistortion.y) - 0.5) * dis.a;


vec2 dis_coord = vec2(dis.r, -dis.g)/2.0;
highp vec2 dis_coord = vec2(dis.r, -dis.g)/2.0;
// Sample the texture
vec4 col = texture(TEXTURE, UV+dis_coord);
highp vec4 col = texture(TEXTURE, UV+dis_coord);

// Output to screen
COLOR = vec4(col);
Expand Down
12 changes: 6 additions & 6 deletions Resources/Shaders/drop_shadow.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ uniform highp float y;
uniform highp vec4 shadow_color;

void fragment() {
highp float shadow_blur_samples = pow(size * 2 + 1, 2);
highp float shadow_blur_samples = pow((size * 2.0 + 1.0), 2.0);
highp vec4 texture_color = zTexture(UV);
highp vec2 ps = TEXTURE_PIXEL_SIZE;
highp vec2 shadow_uv = UV - (ps * vec2(x, -y)); // Y is up

highp float sampled_shadow_alpha = 0;
highp float sampled_shadow_alpha = 0.0;
for (highp float blur_x = -size; blur_x <= size; blur_x++) {
for (highp float blur_y = -size; blur_y <= size; blur_y++) {
vec2 blur_uv = shadow_uv + ps * vec2(blur_x, blur_y);
highp vec2 blur_uv = shadow_uv + ps * vec2(blur_x, blur_y);

sampled_shadow_alpha += zTexture(blur_uv).a / shadow_blur_samples;
}
}

vec4 final_shadow_color = vec4(shadow_color.rgb, shadow_color.a * sampled_shadow_alpha);
highp vec4 final_shadow_color = vec4(shadow_color.rgb, shadow_color.a * sampled_shadow_alpha);

// Mix the shadow with the initial image based on the image's alpha
COLOR.rgb = final_shadow_color.rgb * (1 - texture_color.a) + (texture_color.rgb / texture_color.a); //texture color needs to be divided by alpha to account for alpha premultiplication in the overlay shader
COLOR.a = clamp(final_shadow_color.a + texture_color.a, 0, 1);
COLOR.rgb = final_shadow_color.rgb * (1.0 - texture_color.a) + (texture_color.rgb / texture_color.a); //texture color needs to be divided by alpha to account for alpha premultiplication in the overlay shader
COLOR.a = clamp(final_shadow_color.a + texture_color.a, 0.0, 1.0);
COLOR.rgb *= COLOR.a;
}

0 comments on commit ba45f8a

Please sign in to comment.