Skip to content

Commit

Permalink
Merge pull request #667 from MOARdV/master
Browse files Browse the repository at this point in the history
And yet another take on the y-inversion issue
  • Loading branch information
MOARdV authored May 19, 2018
2 parents 96ad0d4 + ec494b4 commit fadbce1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion GameData/JSI/RasterPropMonitor/RasterPropMonitor.version
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"VERSION": {
"MAJOR": 0,
"MINOR": 30,
"PATCH": 2
"PATCH": 3
},
"KSP_VERSION": {
"MAJOR": 1,
Expand Down
2 changes: 1 addition & 1 deletion RasterPropMonitor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ Global
$36.inheritsSet = Mono
$36.inheritsScope = text/plain
$36.scope = text/plain
version = 0.30.2
version = 0.30.3
EndGlobalSection
EndGlobal
9 changes: 8 additions & 1 deletion RasterPropMonitor/Core/RasterPropMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,19 @@ public void Start()

screenTexture = new RenderTexture(screenPixelWidth, screenPixelHeight, 24, RenderTextureFormat.ARGB32);
screenMat = internalProp.FindModelTransform(screenTransform).GetComponent<Renderer>().material;

bool manuallyInvertY = false;
if (SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 9") || SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 12"))
{
manuallyInvertY = (UnityEngine.QualitySettings.antiAliasing > 0);
}

foreach (string layerID in textureLayerID.Split())
{
screenMat.SetTexture(layerID.Trim(), screenTexture);
// This code was written for a much older flavor of Unity, and the Unity 2017.1 update broke
// some assumptions about who managed the y-inversion issue between OpenGL and DX9.
if (JUtil.manuallyInvertY)
if (manuallyInvertY)
{
screenMat.SetTextureScale(layerID.Trim(), new Vector2(1.0f, -1.0f));
screenMat.SetTextureOffset(layerID.Trim(), new Vector2(0.0f, 1.0f));
Expand Down
20 changes: 14 additions & 6 deletions RasterPropMonitor/Core/TextRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ internal void Destroy()
private int cachedTextHash = -1;
private int cachedOverlayTextHash = -1;

private readonly bool manuallyInvertY;

private GameObject cameraBody;
private Camera textCamera;

Expand Down Expand Up @@ -156,12 +158,18 @@ public TextRenderer(List<Texture2D> fontTexture, Vector2 fontLetterSize, string
throw new Exception("No font textures found");
}

manuallyInvertY = false;
if (SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 9") || SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 12"))
{
manuallyInvertY = (UnityEngine.QualitySettings.antiAliasing > 0);
}

screenPixelWidth = screenWidth;
screenPixelHeight = screenHeight;

screenXOffset = (float)screenPixelWidth * -0.5f;
screenYOffset = (float)screenPixelHeight * 0.5f - fontLetterSize.y;
if (JUtil.manuallyInvertY)
if (manuallyInvertY)
{
// This code was written for a much older flavor of Unity, and the Unity 2017.1 update broke
// some assumptions about who managed the y-inversion issue between OpenGL and DX9.
Expand Down Expand Up @@ -410,7 +418,7 @@ private bool DrawChar(FontRenderer fr, char letter, float xPos, float yPos, Colo
// This code was written for a much older flavor of Unity, and the Unity 2017.1 update broke
// some assumptions about who managed the y-inversion issue between OpenGL and DX9.
float yPosition;
if (JUtil.manuallyInvertY)
if (manuallyInvertY)
{
yPosition = screenYOffset + ((scriptType == Script.Superscript) ? yPos + fontLetterHalfHeight : yPos);
}
Expand All @@ -428,10 +436,10 @@ private bool DrawChar(FontRenderer fr, char letter, float xPos, float yPos, Colo
fr.vertices.Add(new Vector3(pos.xMax, pos.yMax, 0.0f));

Rect uv = fontCharacters[letter];
fr.uvs.Add(new Vector2(uv.xMin, (JUtil.manuallyInvertY) ? uv.yMax : uv.yMin));
fr.uvs.Add(new Vector2(uv.xMax, (JUtil.manuallyInvertY) ? uv.yMax : uv.yMin));
fr.uvs.Add(new Vector2(uv.xMin, (JUtil.manuallyInvertY) ? uv.yMin : uv.yMax));
fr.uvs.Add(new Vector2(uv.xMax, (JUtil.manuallyInvertY) ? uv.yMin : uv.yMax));
fr.uvs.Add(new Vector2(uv.xMin, (manuallyInvertY) ? uv.yMax : uv.yMin));
fr.uvs.Add(new Vector2(uv.xMax, (manuallyInvertY) ? uv.yMax : uv.yMin));
fr.uvs.Add(new Vector2(uv.xMin, (manuallyInvertY) ? uv.yMin : uv.yMax));
fr.uvs.Add(new Vector2(uv.xMax, (manuallyInvertY) ? uv.yMin : uv.yMax));

fr.colors32.Add(letterColor);
}
Expand Down
7 changes: 0 additions & 7 deletions RasterPropMonitor/Core/UtilityFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ public static class JUtil
internal static Dictionary<string, Font> loadedFonts = new Dictionary<string, Font>();
internal static Dictionary<string, Color32> globalColors = new Dictionary<string, Color32>();

internal static bool manuallyInvertY = false;

internal static GameObject CreateSimplePlane(string name, float vectorSize, int drawingLayer)
{
return CreateSimplePlane(name, new Vector2(vectorSize, vectorSize), new Rect(0.0f, 0.0f, 1.0f, 1.0f), drawingLayer);
Expand Down Expand Up @@ -1859,11 +1857,6 @@ private void Awake()
}
}

if (SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 9") || SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 12"))
{
JUtil.manuallyInvertY = true;
}

LoadAssets();

StartCoroutine("LoadRasterPropMonitorValues");
Expand Down
2 changes: 1 addition & 1 deletion SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
// Revision number is altered automatically.
[assembly: AssemblyVersion("0.30.2.*")]
[assembly: AssemblyVersion("0.30.3.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down

0 comments on commit fadbce1

Please sign in to comment.