Skip to content

Commit

Permalink
Fix Textures when Empty
Browse files Browse the repository at this point in the history
  • Loading branch information
maikramer committed Mar 13, 2019
1 parent 549e8fc commit 4503e33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
32 changes: 13 additions & 19 deletions Assets/Scripts/General/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void SetFullMaterial()
}
else
{
FullMaterialInstance.SetTexture(HeightMapId, Texture2D.blackTexture);
FullMaterialInstance.SetTexture(HeightMapId, null);
}

if (DiffuseMap != null)
Expand All @@ -207,12 +207,10 @@ public void SetFullMaterial()
// ReSharper disable once StringLiteralTypo
FullMaterialInstance.EnableKeyword("_NORMALMAP");
StartCoroutine(PackNormalAndSet());


}
else
{
FullMaterialInstance.SetTexture(NormalMapId, Texture2D.normalTexture);
FullMaterialInstance.SetTexture(NormalMapId, null);
}

if (MaskMap)
Expand All @@ -223,7 +221,7 @@ public void SetFullMaterial()
}
else
{
FullMaterialInstance.SetTexture(MaskMapId, _blackTexture);
FullMaterialInstance.SetTexture(MaskMapId, null);
}

ProgramManager.Instance.TestObject.GetComponent<Renderer>().material = FullMaterialInstance;
Expand All @@ -239,25 +237,18 @@ private IEnumerator PackNormalAndSet()
PackNormalCompute.SetTexture(kernel, "NormalInput", NormalMap);
PackNormalCompute.SetTexture(kernel, "Result", tempRenderTexture);
PackNormalCompute.Dispatch(kernel, size.x / 8, size.y / 8, 1);

yield return null;
GetTextureFromRender(tempRenderTexture, out _packedNormal);
FullMaterialInstance.SetTexture(NormalMapId, _packedNormal);
}

public Texture2D GetStandardTexture(int width, int height, bool linear = true)
{
if (Hdr)
{
return GetStandardHdrTexture(width, height, linear);
}
else
{
return GetStandardLdrTexture(width, height, linear);
}
return Hdr ? GetStandardHdrTexture(width, height, linear) : GetStandardLdrTexture(width, height, linear);
}

public static Texture2D GetStandardHdrTexture(int width, int height, bool linear = true)
private static Texture2D GetStandardHdrTexture(int width, int height, bool linear = true)
{
var texture = new Texture2D(width, height, DefaultHdrTextureFormat, true, linear)
{
Expand All @@ -268,7 +259,7 @@ public static Texture2D GetStandardHdrTexture(int width, int height, bool linear
}


public static Texture2D GetStandardLdrTexture(int width, int height, bool linear = true)
private static Texture2D GetStandardLdrTexture(int width, int height, bool linear = true)
{
var texture = new Texture2D(width, height, DefaultLdrTextureFormat, true, linear)
{
Expand Down Expand Up @@ -298,12 +289,12 @@ public void GetTextureFromRender(RenderTexture input, ProgramEnums.MapType mapTy
GetTextureFromRender(input, mapType, out _);
}

public void GetTextureFromRender(RenderTexture input, out Texture2D outTexture)
private void GetTextureFromRender(RenderTexture input, out Texture2D outTexture)
{
GetTextureFromRender(input, ProgramEnums.MapType.None, out outTexture);
}

public void GetTextureFromRender(RenderTexture input, ProgramEnums.MapType mapType, out Texture2D outTexture)
private void GetTextureFromRender(RenderTexture input, ProgramEnums.MapType mapType, out Texture2D outTexture)
{
RenderTexture.active = input;
var texture = GetStandardTexture(input.width, input.height);
Expand Down Expand Up @@ -465,6 +456,7 @@ public void ClearTexture(ProgramEnums.MapType mapType)
}
}

[UsedImplicitly]
public void ClearAllButtonCallback()
{
ClearAllTextures();
Expand Down Expand Up @@ -542,17 +534,19 @@ public void FixSize()
FixSizeSize(size.x, size.y);
}

[UsedImplicitly]
public static void FixSizeMap(Texture mapToUse)
{
FixSizeSize(mapToUse.width, mapToUse.height);
}

[UsedImplicitly]
public static void FixSizeMap(RenderTexture mapToUse)
{
FixSizeSize(mapToUse.width, mapToUse.height);
}

public static void FixSizeSize(float width, float height)
private static void FixSizeSize(float width, float height)
{
var testObjectScale = new Vector3(1, 1, 1);
const float area = 1.0f;
Expand Down
9 changes: 6 additions & 3 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ PlayerSettings:
switchNVNShaderPoolsGranularity: 33554432
switchNVNDefaultPoolsGranularity: 16777216
switchNVNOtherPoolsGranularity: 16777216
vulkanEnableSetSRGBWrite: 0
vulkanEnableSetSRGBWrite: 1
m_SupportedAspectRatios:
4:3: 0
5:4: 0
Expand Down Expand Up @@ -334,8 +334,11 @@ PlayerSettings:
m_APIs: 15000000
m_Automatic: 0
- m_BuildTarget: WindowsStandaloneSupport
m_APIs: 02000000
m_Automatic: 1
m_APIs: 020000001500000012000000
m_Automatic: 0
- m_BuildTarget: MacStandaloneSupport
m_APIs: 10000000
m_Automatic: 0
m_BuildTargetVRSettings: []
m_BuildTargetEnableVuforiaSettings: []
openGLRequireES31: 0
Expand Down

0 comments on commit 4503e33

Please sign in to comment.