From ef392a17b179f859bc4b04ee6ad917f8dd7330e1 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:24:00 +0530 Subject: [PATCH] make shaders more closer to orig mbu --- data/font/EXPON.fnt | 204 +++++++++++++++++++++++++++++++ src/gui/EnterNameDlg.hx | 8 -- src/gui/HelpCreditsGui.hx | 10 -- src/shaders/NoiseTileMaterial.hx | 5 +- src/shaders/PhongMaterial.hx | 7 +- 5 files changed, 212 insertions(+), 22 deletions(-) create mode 100644 data/font/EXPON.fnt diff --git a/data/font/EXPON.fnt b/data/font/EXPON.fnt new file mode 100644 index 00000000..49db9348 --- /dev/null +++ b/data/font/EXPON.fnt @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/gui/EnterNameDlg.hx b/src/gui/EnterNameDlg.hx index c1598492..930fdad1 100644 --- a/src/gui/EnterNameDlg.hx +++ b/src/gui/EnterNameDlg.hx @@ -33,12 +33,6 @@ class EnterNameDlg extends GuiControl { var domcasual32 = domcasual32b.toSdfFont(cast 26 * Settings.uiScale, MultiChannel); var domcasual48 = domcasual32b.toSdfFont(cast 42 * Settings.uiScale, MultiChannel); - var expo50fontdata = ResourceLoader.getFileEntry("data/font/EXPON.fnt"); - var expo50b = new BitmapFont(expo50fontdata.entry); - @:privateAccess expo50b.loader = ResourceLoader.loader; - var expo50 = expo50b.toSdfFont(cast 35 * Settings.uiScale, MultiChannel); - var expo32 = expo50b.toSdfFont(cast 24 * Settings.uiScale, MultiChannel); - function mlFontLoader(text:String) { switch (text) { case "DomCasual32": @@ -47,8 +41,6 @@ class EnterNameDlg extends GuiControl { return domcasual48; case "Arial14": return arial14; - case "Expo50": - return expo50; default: return null; } diff --git a/src/gui/HelpCreditsGui.hx b/src/gui/HelpCreditsGui.hx index 8986184c..fc885649 100644 --- a/src/gui/HelpCreditsGui.hx +++ b/src/gui/HelpCreditsGui.hx @@ -93,12 +93,6 @@ class HelpCreditsGui extends GuiImage { var markerFelt24 = markerFelt32b.toSdfFont(cast 18 * Settings.uiScale, MultiChannel); var markerFelt18 = markerFelt32b.toSdfFont(cast 14 * Settings.uiScale, MultiChannel); - var expo50fontdata = ResourceLoader.getFileEntry("data/font/EXPON.fnt"); - var expo50b = new BitmapFont(expo50fontdata.entry); - @:privateAccess expo50b.loader = ResourceLoader.loader; - var expo50 = expo50b.toSdfFont(cast 35 * Settings.uiScale, MultiChannel); - var expo32 = expo50b.toSdfFont(cast 24 * Settings.uiScale, MultiChannel); - function mlFontLoader(text:String) { switch (text) { case "MarkerFelt32": @@ -109,10 +103,6 @@ class HelpCreditsGui extends GuiImage { return markerFelt18; case "Arial16": return arial14; - case "Expo32": - return expo32; - case "Expo50": - return expo50; default: return null; } diff --git a/src/shaders/NoiseTileMaterial.hx b/src/shaders/NoiseTileMaterial.hx index 49a8aafa..369bd176 100644 --- a/src/shaders/NoiseTileMaterial.hx +++ b/src/shaders/NoiseTileMaterial.hx @@ -86,8 +86,9 @@ class NoiseTileMaterial extends hxsl.Shader { outCol.xyz *= bumpDot + ambientLight; - var r = reflect(dirLightDir, transformedNormal).normalize(); - var specValue = saturate(r.dot((camera.position - transformedPosition).normalize())) * fragLightW; + var eyeVec = (camera.position - transformedPosition).normalize(); + var halfAng = (eyeVec - dirLightDir).normalize(); + var specValue = saturate(transformedNormal.dot(halfAng)) * fragLightW; var specular = specularColor * pow(specValue, shininess); outCol += specular * diffuse.a; diff --git a/src/shaders/PhongMaterial.hx b/src/shaders/PhongMaterial.hx index ce0228fd..f3cb970b 100644 --- a/src/shaders/PhongMaterial.hx +++ b/src/shaders/PhongMaterial.hx @@ -30,6 +30,7 @@ class PhongMaterial extends hxsl.Shader { var transformedPosition:Vec3; var transformedNormal:Vec3; @var var transformedTangent:Vec4; + @var var fragLightW:Float; function __init__vertex() { transformedTangent = vec4(input.tangent * global.modelView.mat3(), input.tangent.dot(input.tangent) > 0.5 ? 1. : -1.); } @@ -39,6 +40,7 @@ class PhongMaterial extends hxsl.Shader { } function vertex() { calculatedUV = input.uv * uvScaleFactor; + fragLightW = step(0, dot(dirLight, input.normal)); } function fragment() { // Diffuse part @@ -54,8 +56,9 @@ class PhongMaterial extends hxsl.Shader { var bumpDot = dirLight * lambert(transformedNormal, -dirLightDir); outCol.xyz *= bumpDot + ambientLight; - var r = reflect(dirLightDir, transformedNormal).normalize(); - var specValue = saturate(r.dot((camera.position - transformedPosition).normalize())); + var eyeVec = (camera.position - transformedPosition).normalize(); + var halfAng = (eyeVec - dirLightDir).normalize(); + var specValue = saturate(transformedNormal.dot(halfAng)) * fragLightW; var specular = specularColor * pow(specValue, shininess); outCol += specular * diffuse.a;