Skip to content

Commit

Permalink
Merge pull request #79865 from clayjohn/discard-shader
Browse files Browse the repository at this point in the history
Fix use of discard in shaders
  • Loading branch information
YuriSizov committed Jul 25, 2023
2 parents 08cffc1 + 7c812cd commit 3f2e901
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
18 changes: 8 additions & 10 deletions drivers/gles3/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -1039,17 +1039,16 @@ void main() {
if (alpha < alpha_scissor_threshold) {
discard;
}
#endif // ALPHA_SCISSOR_USED

#else
#ifdef MODE_RENDER_DEPTH
#ifdef USE_OPAQUE_PREPASS
#if !defined(ALPHA_SCISSOR_USED)

if (alpha < opaque_prepass_threshold) {
discard;
}

#endif // not ALPHA_SCISSOR_USED
#endif // USE_OPAQUE_PREPASS
#endif // MODE_RENDER_DEPTH
#endif // !ALPHA_SCISSOR_USED

#endif // !USE_SHADOW_TO_OPACITY

Expand Down Expand Up @@ -1270,17 +1269,16 @@ void main() {
if (alpha < alpha_scissor) {
discard;
}
#endif // ALPHA_SCISSOR_USED

#else
#ifdef MODE_RENDER_DEPTH
#ifdef USE_OPAQUE_PREPASS
#if !defined(ALPHA_SCISSOR_USED)

if (alpha < opaque_prepass_threshold) {
discard;
}

#endif // not ALPHA_SCISSOR_USED
#endif // USE_OPAQUE_PREPASS
#endif // MODE_RENDER_DEPTH
#endif // !ALPHA_SCISSOR_USED

#endif // USE_SHADOW_TO_OPACITY

Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/storage/material_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ MaterialStorage::MaterialStorage() {
actions.render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n";
actions.render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n";
actions.render_mode_defines["particle_trails"] = "#define USE_PARTICLE_TRAILS\n";
actions.render_mode_defines["depth_draw_opaque"] = "#define USE_OPAQUE_PREPASS\n";
actions.render_mode_defines["depth_prepass_alpha"] = "#define USE_OPAQUE_PREPASS\n";

bool force_lambert = GLOBAL_GET("rendering/shading/overrides/force_lambert_over_burley");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void SceneShaderForwardClustered::init(const String p_defines) {
actions.render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n";
actions.render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n";
actions.render_mode_defines["particle_trails"] = "#define USE_PARTICLE_TRAILS\n";
actions.render_mode_defines["depth_draw_opaque"] = "#define USE_OPAQUE_PREPASS\n";
actions.render_mode_defines["depth_prepass_alpha"] = "#define USE_OPAQUE_PREPASS\n";

bool force_lambert = GLOBAL_GET("rendering/shading/overrides/force_lambert_over_burley");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void SceneShaderForwardMobile::init(const String p_defines) {
actions.render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n";
actions.render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n";
actions.render_mode_defines["particle_trails"] = "#define USE_PARTICLE_TRAILS\n";
actions.render_mode_defines["depth_draw_opaque"] = "#define USE_OPAQUE_PREPASS\n";
actions.render_mode_defines["depth_prepass_alpha"] = "#define USE_OPAQUE_PREPASS\n";

bool force_lambert = GLOBAL_GET("rendering/shading/overrides/force_lambert_over_burley");
if (!force_lambert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,11 +875,15 @@ void fragment_shader(in SceneData scene_data) {
alpha = compute_alpha_antialiasing_edge(alpha, alpha_texture_coordinate, alpha_antialiasing_edge);
#endif // ALPHA_ANTIALIASING_EDGE_USED

#ifdef MODE_RENDER_DEPTH
#ifdef USE_OPAQUE_PREPASS
#ifndef ALPHA_SCISSOR_USED
if (alpha < scene_data.opaque_prepass_threshold) {
discard;
}
#endif // !ALPHA_SCISSOR_USED
#endif // USE_OPAQUE_PREPASS
#endif // MODE_RENDER_DEPTH

#endif // !USE_SHADOW_TO_OPACITY

Expand Down Expand Up @@ -2038,15 +2042,17 @@ void fragment_shader(in SceneData scene_data) {
if (alpha < alpha_scissor) {
discard;
}
#endif // ALPHA_SCISSOR_USED

#else
#ifdef MODE_RENDER_DEPTH
#ifdef USE_OPAQUE_PREPASS

if (alpha < scene_data.opaque_prepass_threshold) {
discard;
}

#endif // USE_OPAQUE_PREPASS
#endif // MODE_RENDER_DEPTH
#endif // ALPHA_SCISSOR_USED

#endif // USE_SHADOW_TO_OPACITY

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,15 @@ void main() {
alpha = compute_alpha_antialiasing_edge(alpha, alpha_texture_coordinate, alpha_antialiasing_edge);
#endif // ALPHA_ANTIALIASING_EDGE_USED

#ifdef MODE_RENDER_DEPTH
#ifdef USE_OPAQUE_PREPASS
#ifndef ALPHA_SCISSOR_USED
if (alpha < scene_data.opaque_prepass_threshold) {
discard;
}
#endif // !ALPHA_SCISSOR_USED
#endif // USE_OPAQUE_PREPASS
#endif // MODE_RENDER_DEPTH

#endif // !USE_SHADOW_TO_OPACITY

Expand Down Expand Up @@ -1685,15 +1689,17 @@ void main() {
if (alpha < alpha_scissor) {
discard;
}
#endif // ALPHA_SCISSOR_USED

#else
#ifdef MODE_RENDER_DEPTH
#ifdef USE_OPAQUE_PREPASS

if (alpha < scene_data.opaque_prepass_threshold) {
discard;
}

#endif // USE_OPAQUE_PREPASS
#endif // MODE_RENDER_DEPTH
#endif // !ALPHA_SCISSOR_USED

#endif // USE_SHADOW_TO_OPACITY

Expand Down

0 comments on commit 3f2e901

Please sign in to comment.