Skip to content

Commit

Permalink
Merge pull request #2993 from MoritzBrueckner/fix-two-sided-mats
Browse files Browse the repository at this point in the history
Fix rendering of two sided materials in some render paths
  • Loading branch information
luboslenco committed Jan 31, 2024
2 parents 3c1c628 + c733638 commit c8a14cf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions blender/arm/material/make_mesh.py
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 c8a14cf

Please sign in to comment.