Skip to content

Commit 9c193e2

Browse files
committed
Fix #432: don't use normal maps in visual map for parallax continued
1 parent 338a072 commit 9c193e2

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SCANsat Changelog
22

3-
## 21.0 - 2025-09-15
3+
## Unreleased
44

55
- Added Chinese localization (thanks @AmazingWood)
66
- Fixed usages of .material in favor of .sharedMaterial (thanks @Gameslinx)

SCANsat/SCAN_Reflection/SCANparallaxContinued.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,28 @@ internal static void LoadParallax(CelestialBody body, ref Material material)
6060
Log.Message($"Loading Parallax Continued data for {body.name}");
6161
x_ParallaxScaledBody_Load.Invoke(parallaxBody, null);
6262
material = x_ParallaxScaledBody_scaledMaterial.GetValue(parallaxBody) as Material;
63+
64+
#if DEBUG
65+
for (int propertyIndex = 0; propertyIndex < material.shader.GetPropertyCount(); ++propertyIndex)
66+
{
67+
var propertyType = material.shader.GetPropertyType(propertyIndex);
68+
var propertyName = material.shader.GetPropertyName(propertyIndex);
69+
object propertyValue = null;
70+
71+
switch (propertyType)
72+
{
73+
case UnityEngine.Rendering.ShaderPropertyType.Color: propertyValue = material.GetColor(propertyName); break;
74+
case UnityEngine.Rendering.ShaderPropertyType.Vector: propertyValue = material.GetVector(propertyName); break;
75+
case UnityEngine.Rendering.ShaderPropertyType.Float: propertyValue = material.GetFloat(propertyName); break;
76+
case UnityEngine.Rendering.ShaderPropertyType.Range: propertyValue = material.GetFloat(propertyName); break;
77+
case UnityEngine.Rendering.ShaderPropertyType.Texture: propertyValue = material.GetTexture(propertyName); break;
78+
}
79+
80+
Log.Debug($"Property {propertyIndex} is {propertyType} named {propertyName} with value {propertyValue}");
81+
}
82+
#endif
6383
}
6484
}
65-
6685
}
6786
}
6887
}

SCANsat/SCANcontroller.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,11 +1600,12 @@ internal void LoadVisualMapTexture(CelestialBody b, mapSource s)
16001600

16011601
}
16021602

1603-
void GetVisualMapTexturesForBody(CelestialBody b, out Material material, out string colorMapTextureName, out string normalMapTextureName)
1603+
void GetVisualMapTexturesForBody(CelestialBody b, out Material material, out bool useMaterialForColorMap, out string colorMapTextureName, out string normalMapTextureName)
16041604
{
16051605
material = null;
16061606
colorMapTextureName = null;
16071607
normalMapTextureName = null;
1608+
useMaterialForColorMap = true;
16081609

16091610
if (b.scaledBody == null)
16101611
{
@@ -1630,7 +1631,10 @@ void GetVisualMapTexturesForBody(CelestialBody b, out Material material, out str
16301631
else if (shaderName.Contains("ParallaxScaled"))
16311632
{
16321633
SCANparallaxContinued.LoadParallax(b, ref material);
1634+
useMaterialForColorMap = false;
16331635
colorMapTextureName = "_ColorMap";
1636+
normalMapTextureName = null; // for whatever reason, the logic in ScANmap that uses the normal map doesn't work with parallax's normal maps
1637+
return;
16341638
}
16351639
else if (material.HasProperty("_MainTex"))
16361640
{
@@ -1662,7 +1666,7 @@ void CacheScaledSpaceTexture(Dictionary<CelestialBody, Texture2D> cache, Celesti
16621666
}
16631667
else
16641668
{
1665-
var colorMap = sourceTexture.isReadable ? sourceTexture : readableTexture(sourceTexture, material, true);
1669+
var colorMap = sourceTexture.isReadable ? sourceTexture : readableTexture(sourceTexture, useMaterial ? material : null);
16661670
cache.Add(b, colorMap);
16671671
}
16681672
}
@@ -1680,15 +1684,15 @@ internal void LoadVisualMapTexture_Renamed(CelestialBody b, mapSource s)
16801684
return;
16811685
}
16821686

1683-
GetVisualMapTexturesForBody(b, out Material material, out string colorMapTextureName, out string normalMapTextureName);
1687+
GetVisualMapTexturesForBody(b, out Material material, out bool useMaterialForColorMap, out string colorMapTextureName, out string normalMapTextureName);
16841688

16851689
if (material == null)
16861690
{
16871691
Log.Error($"GetVisualMapTexturesForBody returned a null material for body {b.name}");
16881692
}
16891693
else
16901694
{
1691-
CacheScaledSpaceTexture(readableScaledSpaceMaps, b, material, colorMapTextureName, true);
1695+
CacheScaledSpaceTexture(readableScaledSpaceMaps, b, material, colorMapTextureName, useMaterialForColorMap);
16921696
CacheScaledSpaceTexture(readableScaledSpaceNormalMaps, b, material, normalMapTextureName, false);
16931697
}
16941698

@@ -1752,7 +1756,7 @@ internal void UnloadVisualMapTexture(CelestialBody b, mapSource s)
17521756
}
17531757
}
17541758

1755-
private Texture2D readableTexture(Texture tex, Material mat, bool useMat)
1759+
private Texture2D readableTexture(Texture tex, Material mat)
17561760
{
17571761
if (tex == null)
17581762
{
@@ -1763,7 +1767,7 @@ private Texture2D readableTexture(Texture tex, Material mat, bool useMat)
17631767

17641768
var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB, 1);
17651769

1766-
if (useMat)
1770+
if (mat != null)
17671771
{
17681772
Graphics.Blit(tex, rt, mat);
17691773
}

0 commit comments

Comments
 (0)