@@ -3563,6 +3563,11 @@ void CompilerGLSL::emit_resources()
3563
3563
fixup_implicit_builtin_block_names(execution.model);
3564
3564
break;
3565
3565
3566
+ case ExecutionModelFragment:
3567
+ if (options.fragment.emulate_alpha_test_func)
3568
+ statement("uniform float SPIRV_Cross_AlphaTestRef;");
3569
+ break;
3570
+
3566
3571
default:
3567
3572
break;
3568
3573
}
@@ -16613,6 +16618,28 @@ void CompilerGLSL::emit_fixup()
16613
16618
if (options.vertex.flip_vert_y)
16614
16619
statement("gl_Position.y = -gl_Position.y;");
16615
16620
}
16621
+ else if (get_entry_point().model == ExecutionModelFragment)
16622
+ {
16623
+ if (options.fragment.emulate_alpha_test_func == Options::Never)
16624
+ {
16625
+ statement("discard;");
16626
+ }
16627
+ else if (options.fragment.emulate_alpha_test_func != Options::Always)
16628
+ {
16629
+ auto *output_var = find_color_output_by_location(0);
16630
+ if (output_var && this->get<SPIRType>(output_var->basetype).vecsize >= 4)
16631
+ {
16632
+ // We check for test fail, so we use the opposite operator
16633
+ static const char *ops[Options::Always] = {
16634
+ "", ">=", "!=", ">", "<=", "==", "<",
16635
+ };
16636
+ assert(options.fragment.emulate_alpha_test_func < Options::Always);
16637
+ const char *op = ops[options.fragment.emulate_alpha_test_func];
16638
+ statement("if (", to_expression(output_var->self), ".a ", op,
16639
+ " SPIRV_Cross_AlphaTestRef) discard;");
16640
+ }
16641
+ }
16642
+ }
16616
16643
}
16617
16644
16618
16645
void CompilerGLSL::flush_phi(BlockID from, BlockID to)
0 commit comments