Browse Source

Improve blendspan criteria stuff.

This allows blend textures to be used for mesh transparency without
having to fiddle around too much. It was also a stab at fixing some
regressions in the MOUL engine around decals, but that bit failed,
sadly.
pull/172/head
Adam Johnson 5 years ago
parent
commit
dd467547d2
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 9
      korman/exporter/material.py
  2. 25
      korman/exporter/mesh.py
  3. 14
      korman/properties/modifiers/base.py
  4. 4
      korman/properties/modifiers/render.py

9
korman/exporter/material.py

@ -429,8 +429,6 @@ class MaterialConverter:
if canStencil: if canStencil:
hsgmat.compFlags |= hsGMaterial.kCompNeedsBlendChannel hsgmat.compFlags |= hsGMaterial.kCompNeedsBlendChannel
state.blendFlags |= hsGMatState.kBlendAlpha | hsGMatState.kBlendAlphaMult | hsGMatState.kBlendNoTexColor state.blendFlags |= hsGMatState.kBlendAlpha | hsGMatState.kBlendAlphaMult | hsGMatState.kBlendNoTexColor
if slot.texture.type == "BLEND":
state.clampFlags |= hsGMatState.kClampTexture
state.ZFlags |= hsGMatState.kZNoZWrite state.ZFlags |= hsGMatState.kZNoZWrite
layer.ambient = hsColorRGBA(1.0, 1.0, 1.0, 1.0) layer.ambient = hsColorRGBA(1.0, 1.0, 1.0, 1.0)
elif blend_flags: elif blend_flags:
@ -453,6 +451,8 @@ class MaterialConverter:
layer.specularPower = 1.0 layer.specularPower = 1.0
texture = slot.texture texture = slot.texture
if texture.type == "BLEND":
hsgmat.compFlags |= hsGMaterial.kCompNeedsBlendChannel
# Apply custom layer properties # Apply custom layer properties
wantBumpmap = bm is not None and slot.use_map_normal wantBumpmap = bm is not None and slot.use_map_normal
@ -788,6 +788,11 @@ class MaterialConverter:
pass pass
def _export_texture_type_blend(self, bo, layer, slot): def _export_texture_type_blend(self, bo, layer, slot):
state = layer.state
state.blendFlags |= hsGMatState.kBlendAlpha | hsGMatState.kBlendAlphaMult | hsGMatState.kBlendNoTexColor
state.clampFlags |= hsGMatState.kClampTexture
state.ZFlags |= hsGMatState.kZNoZWrite
# This has been separated out because other things may need alpha blend textures. # This has been separated out because other things may need alpha blend textures.
texture = slot.texture texture = slot.texture
self.export_alpha_blend(texture.progression, texture.use_flip_axis, layer) self.export_alpha_blend(texture.progression, texture.use_flip_axis, layer)

25
korman/exporter/mesh.py

@ -39,11 +39,13 @@ class _RenderLevel:
_MAJOR_SHIFT = 28 _MAJOR_SHIFT = 28
_MINOR_MASK = ((1 << _MAJOR_SHIFT) - 1) _MINOR_MASK = ((1 << _MAJOR_SHIFT) - 1)
def __init__(self, bo, hsgmat, pass_index, blendSpan=False): def __init__(self, bo, hsgmat, pass_index, blend_span=False):
self.level = 0 self.level = 0
if pass_index > 0:
if blendSpan: self.major = self.MAJOR_FRAMEBUF
self.major = self.MAJOR_DEFAULT self.minor = pass_index * 4
else:
self.major = self.MAJOR_BLEND if blend_span else self.MAJOR_OPAQUE
# We use the blender material's pass index (which we stashed in the hsGMaterial) to increment # We use the blender material's pass index (which we stashed in the hsGMaterial) to increment
# the render pass, just like it says... # the render pass, just like it says...
@ -74,10 +76,9 @@ class _DrawableCriteria:
self.criteria = 0 self.criteria = 0
if self.blend_span: if self.blend_span:
for mod in bo.plasma_modifiers.modifiers: if self._face_sort_allowed(bo):
if mod.requires_face_sort:
self.criteria |= plDrawable.kCritSortFaces self.criteria |= plDrawable.kCritSortFaces
if mod.requires_span_sort: if self._span_sort_allowed(bo):
self.criteria |= plDrawable.kCritSortSpans self.criteria |= plDrawable.kCritSortSpans
self.render_level = _RenderLevel(bo, hsgmat, pass_index, self.blend_span) self.render_level = _RenderLevel(bo, hsgmat, pass_index, self.blend_span)
@ -92,6 +93,16 @@ class _DrawableCriteria:
def __hash__(self): def __hash__(self):
return hash(self.render_level) ^ hash(self.blend_span) ^ hash(self.criteria) return hash(self.render_level) ^ hash(self.blend_span) ^ hash(self.criteria)
def _face_sort_allowed(self, bo):
# For now, only test the modifiers
# This will need to be tweaked further for GUIs...
return not any((i.no_face_sort for i in bo.plasma_modifiers.modifiers))
def _span_sort_allowed(self, bo):
# For now, only test the modifiers
# This will need to be tweaked further for GUIs...
return not any((i.no_face_sort for i in bo.plasma_modifiers.modifiers))
@property @property
def span_type(self): def span_type(self):
if self.blend_span: if self.blend_span:

14
korman/properties/modifiers/base.py

@ -37,19 +37,19 @@ class PlasmaModifierProperties(bpy.types.PropertyGroup):
return self.id_data.name return self.id_data.name
@property @property
def requires_actor(self): def no_face_sort(self):
"""Indicates if this modifier requires the object to be a movable actor""" """Indicates that the geometry's faces should never be sorted by the engine"""
return False return False
@property @property
def requires_face_sort(self): def no_span_sort(self):
"""Indicates that the geometry's faces must be sorted by the engine""" """Indicates that the geometry's Spans should never be sorted with those from other
Drawables that will render in the same pass"""
return False return False
@property @property
def requires_span_sort(self): def requires_actor(self):
"""Indicates that the geometry's Spans must be sorted with those from other Drawables that """Indicates if this modifier requires the object to be a movable actor"""
will render in the same pass"""
return False return False
# Guess what? # Guess what?

4
korman/properties/modifiers/render.py

@ -114,10 +114,6 @@ class PlasmaFadeMod(PlasmaModifierProperties):
mod.farOpaq = self.far_opaq mod.farOpaq = self.far_opaq
mod.farTrans = self.far_trans mod.farTrans = self.far_trans
@property
def requires_span_sort(self):
return True
class PlasmaFollowMod(idprops.IDPropObjectMixin, PlasmaModifierProperties): class PlasmaFollowMod(idprops.IDPropObjectMixin, PlasmaModifierProperties):
pl_id = "followmod" pl_id = "followmod"

Loading…
Cancel
Save