mirror of
https://github.com/godotengine/godot.git
synced 2024-11-25 13:43:15 +00:00
Merge pull request #68673 from clayjohn/RD-alpha-hash
Fix alpha hash by correcting typos and doing calculations in object space
This commit is contained in:
commit
245e6454a0
@ -826,7 +826,8 @@ void fragment_shader(in SceneData scene_data) {
|
||||
|
||||
// alpha hash can be used in unison with alpha antialiasing
|
||||
#ifdef ALPHA_HASH_USED
|
||||
if (alpha < compute_alpha_hash_threshold(vertex, alpha_hash_scale)) {
|
||||
vec3 object_pos = (inverse(read_model_matrix) * inv_view_matrix * vec4(vertex, 1.0)).xyz;
|
||||
if (alpha < compute_alpha_hash_threshold(object_pos, alpha_hash_scale)) {
|
||||
discard;
|
||||
}
|
||||
#endif // ALPHA_HASH_USED
|
||||
|
@ -779,7 +779,8 @@ void main() {
|
||||
|
||||
// alpha hash can be used in unison with alpha antialiasing
|
||||
#ifdef ALPHA_HASH_USED
|
||||
if (alpha < compute_alpha_hash_threshold(vertex, alpha_hash_scale)) {
|
||||
vec3 object_pos = (inverse(read_model_matrix) * inv_view_matrix * vec4(vertex, 1.0)).xyz;
|
||||
if (alpha < compute_alpha_hash_threshold(object_pos, alpha_hash_scale)) {
|
||||
discard;
|
||||
}
|
||||
#endif // ALPHA_HASH_USED
|
||||
|
@ -11,7 +11,8 @@ float hash_3d(vec3 p) {
|
||||
|
||||
float compute_alpha_hash_threshold(vec3 pos, float hash_scale) {
|
||||
vec3 dx = dFdx(pos);
|
||||
vec3 dy = dFdx(pos);
|
||||
vec3 dy = dFdy(pos);
|
||||
|
||||
float delta_max_sqr = max(length(dx), length(dy));
|
||||
float pix_scale = 1.0 / (hash_scale * delta_max_sqr);
|
||||
|
||||
@ -32,9 +33,9 @@ float compute_alpha_hash_threshold(vec3 pos, float hash_scale) {
|
||||
1.0 - ((1.0 - a_interp) * (1.0 - a_interp) / (2.0 * min_lerp * (1.0 - min_lerp))));
|
||||
|
||||
float alpha_hash_threshold =
|
||||
(lerp_factor < (1.0 - min_lerp)) ? ((lerp_factor < min_lerp) ? cases.x : cases.y) : cases.z;
|
||||
(a_interp < (1.0 - min_lerp)) ? ((a_interp < min_lerp) ? cases.x : cases.y) : cases.z;
|
||||
|
||||
return clamp(alpha_hash_threshold, 0.0, 1.0);
|
||||
return clamp(alpha_hash_threshold, 0.00001, 1.0);
|
||||
}
|
||||
|
||||
#endif // ALPHA_HASH_USED
|
||||
|
Loading…
Reference in New Issue
Block a user