Skip to content

Commit

Permalink
Fix shadow to opacity not working in vertex lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmaa committed May 24, 2024
1 parent 475419e commit 3a01651
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 48 deletions.
5 changes: 5 additions & 0 deletions drivers/gles3/shaders/scene_lights_inc.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ struct DirectionalLightData {
mediump float energy;
mediump vec3 color;
mediump float size;
lowp uint unused;
lowp uint bake_mode;
mediump vec2 pad;
mediump float shadow_opacity;
mediump float specular;
Expand Down Expand Up @@ -39,6 +41,9 @@ struct LightData { // This structure needs to be as packed as possible.
mediump float cone_angle;
mediump float specular_amount;
mediump float shadow_opacity;

lowp vec3 pad;
lowp uint bake_mode;
};

#if !defined(DISABLE_LIGHT_OMNI) || defined(ADDITIVE_OMNI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ void vertex_shader(vec3 vertex_input,
#endif // USE_VERTEX_LIGHTING
// VERTEX LIGHTING
#if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)
vec3 ambient_light = vec3(0.0, 0.0, 0.0);
diffuse_light_interp = vec4(0.0);
specular_light_interp = vec4(0.0);

Expand Down Expand Up @@ -856,27 +855,6 @@ void vertex_shader(vec3 vertex_input,
}
}

#ifdef USE_SHADOW_TO_OPACITY
alpha = min(alpha, clamp(length(ambient_light), 0.0, 1.0));

#if defined(ALPHA_SCISSOR_USED)
if (alpha < alpha_scissor) {
discard;
}
#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

#endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)

#ifdef MODE_RENDER_DEPTH
Expand Down Expand Up @@ -2637,6 +2615,8 @@ void fragment_shader(in SceneData scene_data) {
}
}

#endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && !defined(USE_VERTEX_LIGHTING)

#ifdef USE_SHADOW_TO_OPACITY
#ifndef MODE_RENDER_DEPTH
alpha = min(alpha, clamp(length(ambient_light), 0.0, 1.0));
Expand All @@ -2650,8 +2630,6 @@ void fragment_shader(in SceneData scene_data) {
#endif // !MODE_RENDER_DEPTH
#endif // USE_SHADOW_TO_OPACITY

#endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && !defined(USE_VERTEX_LIGHTING)

#ifdef MODE_RENDER_DEPTH

#ifdef MODE_RENDER_SDF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ void main() {

// VERTEX LIGHTING
#if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)
vec3 ambient_light = vec3(0.0, 0.0, 0.0);
#ifdef USE_MULTIVIEW
vec3 view = -normalize(vertex_interp - eye_offset);
#else
Expand Down Expand Up @@ -698,27 +697,6 @@ void main() {
}
} //spot lights

#ifdef USE_SHADOW_TO_OPACITY
alpha = min(alpha, clamp(length(ambient_light), 0.0, 1.0));

#if defined(ALPHA_SCISSOR_USED)
if (alpha < alpha_scissor) {
discard;
}
#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

#endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && defined(USE_VERTEX_LIGHTING)

#ifdef MODE_RENDER_DEPTH
Expand Down Expand Up @@ -2042,6 +2020,8 @@ void main() {
}
} //spot lights

#endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && !defined(USE_VERTEX_LIGHTING)

#ifdef USE_SHADOW_TO_OPACITY
#ifndef MODE_RENDER_DEPTH
alpha = min(alpha, clamp(length(ambient_light), 0.0, 1.0));
Expand All @@ -2055,8 +2035,6 @@ void main() {
#endif // !MODE_RENDER_DEPTH
#endif // USE_SHADOW_TO_OPACITY

#endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) && !defined(USE_VERTEX_LIGHTING)

#ifdef MODE_RENDER_DEPTH

#ifdef MODE_RENDER_MATERIAL
Expand Down

0 comments on commit 3a01651

Please sign in to comment.