Update normal_utils.py
Flipped OGL vs DX logic
This commit is contained in:
+21
-19
@@ -760,9 +760,9 @@ class NormalFormatValidator:
|
||||
below_half = (green < 0.5).float().mean().item()
|
||||
|
||||
# Calculate histogram-based detection
|
||||
# DirectX (Y-): Green channel inverted → typical normal maps appear GREENISH (more pixels > 0.5)
|
||||
# OpenGL (Y+): Green channel standard → typical normal maps appear BLUISH (more pixels < 0.5)
|
||||
# This is because DirectX flips the Y-axis encoding, shifting the overall distribution
|
||||
# DirectX (Y-): Green channel inverted → typical normal maps appear GREENISH (more pixels > 0.5)
|
||||
# Blue/purple appearance = OpenGL | Green/yellow appearance = DirectX
|
||||
|
||||
# Detect format based on bias
|
||||
bias = above_half - below_half
|
||||
@@ -773,8 +773,8 @@ class NormalFormatValidator:
|
||||
confidence = "Low"
|
||||
reason = "Flat or equal distribution"
|
||||
elif bias > 0:
|
||||
# More pixels above 0.5 = DirectX (green looks brighter overall)
|
||||
detected = "DirectX"
|
||||
# More pixels above 0.5 = OpenGL (blue/purple appearance)
|
||||
detected = "OpenGL"
|
||||
confidence_value = abs(bias) * 100
|
||||
if confidence_value > 20:
|
||||
confidence = "High"
|
||||
@@ -784,8 +784,8 @@ class NormalFormatValidator:
|
||||
confidence = "Low"
|
||||
reason = f"Green bias: +{bias:.2%}"
|
||||
else:
|
||||
# More pixels below 0.5 = OpenGL (green looks darker overall)
|
||||
detected = "OpenGL"
|
||||
# More pixels below 0.5 = DirectX (green/yellow appearance)
|
||||
detected = "DirectX"
|
||||
confidence_value = abs(bias) * 100
|
||||
if confidence_value > 20:
|
||||
confidence = "High"
|
||||
@@ -816,14 +816,14 @@ class NormalFormatValidator:
|
||||
|
||||
if detected == "OpenGL":
|
||||
print(f"\n✓ OpenGL Format (Y+)")
|
||||
print(f" • Green channel: Standard Y-axis (up = +Y)")
|
||||
print(f" • Appearance: Bluish/purplish tint")
|
||||
print(f" • Green channel: Standard Y-axis (Y+ = up)")
|
||||
print(f" • Appearance: Blue/purple tint (like your image!)")
|
||||
print(f" • Compatible with: Unity, Blender, Three.js")
|
||||
print(f" • Standard in most modern engines")
|
||||
elif detected == "DirectX":
|
||||
print(f"\n✓ DirectX Format (Y-)")
|
||||
print(f" • Green channel: Inverted Y-axis (up = -Y)")
|
||||
print(f" • Appearance: Greenish/yellowish tint")
|
||||
print(f" • Green channel: Inverted Y-axis (Y- = up)")
|
||||
print(f" • Appearance: Green/yellow tint")
|
||||
print(f" • Compatible with: Unreal Engine, 3ds Max, Maya")
|
||||
print(f" • 💡 Use 'Normal Format Converter' to flip to OpenGL")
|
||||
else:
|
||||
@@ -860,13 +860,13 @@ class NormalFormatValidator:
|
||||
)
|
||||
panel3 = threshold_vis
|
||||
|
||||
# Panel 4: Color-coded format indicator (matches actual normal map appearance)
|
||||
# Panel 4: Color-coded format indicator
|
||||
if "OpenGL" in detected:
|
||||
# Blue/Purple = OpenGL (bluish appearance, Y+)
|
||||
color = torch.tensor([0.3, 0.3, 1.0], device=device, dtype=dtype)
|
||||
# Green = OpenGL (up-facing dominant)
|
||||
color = torch.tensor([0.2, 1.0, 0.2], device=device, dtype=dtype)
|
||||
elif "DirectX" in detected:
|
||||
# Green/Yellow = DirectX (greenish appearance, Y-)
|
||||
color = torch.tensor([0.3, 1.0, 0.3], device=device, dtype=dtype)
|
||||
# Red = DirectX (down-facing dominant)
|
||||
color = torch.tensor([1.0, 0.2, 0.2], device=device, dtype=dtype)
|
||||
else:
|
||||
# Yellow = Ambiguous
|
||||
color = torch.tensor([1.0, 1.0, 0.2], device=device, dtype=dtype)
|
||||
@@ -1215,8 +1215,8 @@ class NormalFormatAuto:
|
||||
below_half = (green < 0.5).float().mean().item()
|
||||
|
||||
# Calculate bias to detect format
|
||||
# DirectX (Y-): Inverted Y-axis → greenish appearance → more pixels > 0.5 → bias > 0
|
||||
# OpenGL (Y+): Standard Y-axis → bluish appearance → more pixels < 0.5 → bias < 0
|
||||
# OpenGL (Y+): Standard Y-axis → bluish appearance → more pixels > 0.5 → bias > 0
|
||||
# DirectX (Y-): Inverted Y-axis → greenish appearance → more pixels < 0.5 → bias < 0
|
||||
bias = above_half - below_half
|
||||
|
||||
# Detect current format
|
||||
@@ -1234,7 +1234,7 @@ class NormalFormatAuto:
|
||||
print(f" • Equal distribution of up/down normals")
|
||||
print(f" • Lower detection threshold for stricter detection")
|
||||
elif bias > 0:
|
||||
detected_format = "DirectX"
|
||||
detected_format = "OpenGL"
|
||||
confidence_value = abs(bias) * 100
|
||||
if confidence_value > 20:
|
||||
confidence = "High"
|
||||
@@ -1243,7 +1243,7 @@ class NormalFormatAuto:
|
||||
else:
|
||||
confidence = "Low"
|
||||
else:
|
||||
detected_format = "OpenGL"
|
||||
detected_format = "DirectX"
|
||||
confidence_value = abs(bias) * 100
|
||||
if confidence_value > 20:
|
||||
confidence = "High"
|
||||
@@ -1331,4 +1331,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"NormalFormatAuto": "Normal Format Auto-Converter",
|
||||
"NormalIntensity": "Normal Intensity Adjuster",
|
||||
"SharpenNormal": "Sharpen Normal",
|
||||
"SharpenDepth": "Sharpen Depth",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user