Skip to content

Commit

Permalink
Fixed gamma correction on occlusion plane weights
Browse files Browse the repository at this point in the history
  • Loading branch information
sauraen committed Jun 12, 2024
1 parent 2354f17 commit 0ee9702
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions fast64_internal/f3d/occlusion_planes/exporter/functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
from mathutils import Vector, Matrix

from ....utility import PluginError
from ....utility import PluginError, colorToLuminance, gammaCorrect
from .classes import OcclusionPlaneCandidate, OcclusionPlaneCandidatesList
from ...f3d_writer import getColorLayer

Expand All @@ -20,20 +20,18 @@ def addOcclusionQuads(
f'Occlusion planes mesh {obj.name} must have a vertex colors layer named "Col", which you paint the weight for each plane into.'
)
for polygon in mesh.polygons:
# Weight is the average of R, G, and B across the four corners
totalColor = Vector((0.0, 0.0, 0.0))
# Weight is the average of the luminance across the four corners
weight = 0.0
verts = []
if polygon.loop_total != 4:
raise PluginError(
f"Occlusion planes mesh {obj.name} contains a polygon with {polygon.loop_total} verts. Occlusion planes must be quads."
)
for loopIndex in polygon.loop_indices:
loop = mesh.loops[loopIndex]
color = color_layer[loop.index].color
totalColor += Vector((color[0], color[1], color[2]))
weight += colorToLuminance(gammaCorrect(color_layer[loop.index].color))
verts.append(transformRelToScene @ obj.matrix_world @ mesh.vertices[loop.vertex_index].co)
totalColor *= 0.25
weight = (totalColor[0] + totalColor[1] + totalColor[2]) / 3.0
weight *= 0.25
# Check that the quad is planar. Are the normals to the two tris forming
# halves of the quad pointing in the same direction? If either tri is
# degenerate, it's OK.
Expand Down

0 comments on commit 0ee9702

Please sign in to comment.