Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose emulated *Unorm4x8 glsl functions in non-android builds #69521

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions drivers/gles3/shaders/canvas.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,9 @@ vec3 light_normal_compute(vec3 light_vec, vec3 normal, vec3 base_color, vec3 lig

#endif

#define SHADOW_TEST(m_uv) \
{ \
highp float sd = SHADOW_DEPTH(m_uv); \
shadow += step(sd, shadow_uv.z / shadow_uv.w); \
}
/* clang-format off */
#define SHADOW_TEST(m_uv) { highp float sd = SHADOW_DEPTH(m_uv); shadow += step(sd, shadow_uv.z / shadow_uv.w); }
/* clang-format on */

//float distance = length(shadow_pos);
vec4 light_shadow_compute(uint light_base, vec4 light_color, vec4 shadow_uv
Expand Down Expand Up @@ -332,7 +330,7 @@ vec4 light_shadow_compute(uint light_base, vec4 light_color, vec4 shadow_uv
shadow /= 13.0;
}

vec4 shadow_color = unpackUnorm4x8(light_array[light_base].shadow_color);
vec4 shadow_color = godot_unpackUnorm4x8(light_array[light_base].shadow_color);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could likely keep using the unpackUnorm4x8 name since you #defined it as alias to our godot_ function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on chat, this was kept like this on purpose to make it clear we're using emulated functions.

#ifdef LIGHT_CODE_USED
shadow_color.rgb *= shadow_modulate;
#endif
Expand Down Expand Up @@ -499,7 +497,7 @@ void main() {

if (specular_shininess_used || (using_light && normal_used && bool(draw_data[draw_data_instance].flags & FLAGS_DEFAULT_SPECULAR_MAP_USED))) {
specular_shininess = texture(specular_texture, uv);
specular_shininess *= unpackUnorm4x8(draw_data[draw_data_instance].specular_shininess);
specular_shininess *= godot_unpackUnorm4x8(draw_data[draw_data_instance].specular_shininess);
specular_shininess_used = true;
} else {
specular_shininess = vec4(1.0);
Expand Down
19 changes: 14 additions & 5 deletions drivers/gles3/shaders/stdlib_inc.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,32 @@ vec2 unpackSnorm2x16(uint p) {
return clamp((v - 32767.0) * vec2(0.00003051851), vec2(-1.0), vec2(1.0));
}

uint packUnorm4x8(vec4 v) {
#endif

// Compatibility renames. These are exposed with the "godot_" prefix
// to work around an Adreno bug which was exposing these ES310 functions
// in ES300 shaders. Internally, we must use the "godot_" prefix, but user shaders
// will be mapped automatically.
uint godot_packUnorm4x8(vec4 v) {
uvec4 uv = uvec4(round(clamp(v, vec4(0.0), vec4(1.0)) * 255.0));
return uv.x | (uv.y << uint(8)) | (uv.z << uint(16)) | (uv.w << uint(24));
}

vec4 unpackUnorm4x8(uint p) {
vec4 godot_unpackUnorm4x8(uint p) {
return vec4(float(p & uint(0xff)), float((p >> uint(8)) & uint(0xff)), float((p >> uint(16)) & uint(0xff)), float(p >> uint(24))) * 0.00392156862; // 1.0 / 255.0
}

uint packSnorm4x8(vec4 v) {
uint godot_packSnorm4x8(vec4 v) {
uvec4 uv = uvec4(round(clamp(v, vec4(-1.0), vec4(1.0)) * 127.0) + 127.0);
return uv.x | uv.y << uint(8) | uv.z << uint(16) | uv.w << uint(24);
}

vec4 unpackSnorm4x8(uint p) {
vec4 godot_unpackSnorm4x8(uint p) {
vec4 v = vec4(float(p & uint(0xff)), float((p >> uint(8)) & uint(0xff)), float((p >> uint(16)) & uint(0xff)), float(p >> uint(24)));
return clamp((v - vec4(127.0)) * vec4(0.00787401574), vec4(-1.0), vec4(1.0));
}

#endif
#define packUnorm4x8 godot_packUnorm4x8
#define unpackUnorm4x8 godot_unpackUnorm4x8
#define packSnorm4x8 godot_packSnorm4x8
#define unpackSnorm4x8 godot_unpackSnorm4x8