Skip to content

Commit

Permalink
Fix rendering of two sided materials in some render paths
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzBrueckner committed Jan 31, 2024
1 parent 3c1c628 commit c733638
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions blender/arm/material/make_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def make_base(con_mesh, parse_opacity):
make_attrib.write_norpos(con_mesh, vert)
frag.write_attrib('vec3 n = normalize(wnormal);')

if mat_state.material.arm_two_sided:
frag.write('if (!gl_FrontFacing) n *= -1;') # Flip normal when drawing back-face

if not is_displacement and not vattr_written:
make_attrib.write_vertpos(vert)

Expand Down Expand Up @@ -240,9 +243,6 @@ def make_deferred(con_mesh, rpasses):
# Pack gbuffer
frag.add_include('std/gbuffer.glsl')

if mat_state.material.arm_two_sided:
frag.write('if (!gl_FrontFacing) n *= -1;') # Flip normal when drawing back-face

frag.write('n /= (abs(n.x) + abs(n.y) + abs(n.z));')
frag.write('n.xy = n.z >= 0.0 ? n.xy : octahedronWrap(n.xy);')

Expand Down Expand Up @@ -342,6 +342,9 @@ def make_forward_mobile(con_mesh):
make_attrib.write_norpos(con_mesh, vert)
frag.write_attrib('vec3 n = normalize(wnormal);')

if mat_state.material.arm_two_sided:
frag.write('if (!gl_FrontFacing) n *= -1;') # Flip normal when drawing back-face

make_attrib.write_vertpos(vert)

frag.add_include('std/math.glsl')
Expand Down

0 comments on commit c733638

Please sign in to comment.