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

Add model_normal_matrix for fragment shader #86000

Merged
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
10 changes: 10 additions & 0 deletions drivers/gles3/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ void main() {

#define SHADER_IS_SRGB true

#define FLAGS_NON_UNIFORM_SCALE (1 << 4)

/* Varyings */

#if defined(COLOR_USED)
Expand Down Expand Up @@ -955,6 +957,7 @@ ivec2 multiview_uv(ivec2 uv) {

uniform highp mat4 world_transform;
uniform mediump float opaque_prepass_threshold;
uniform highp uint model_flags;

#if defined(RENDER_MATERIAL)
layout(location = 0) out vec4 albedo_output_buffer;
Expand Down Expand Up @@ -1521,6 +1524,13 @@ void main() {
vec3 light_vertex = vertex;
#endif //LIGHT_VERTEX_USED

highp mat3 model_normal_matrix;
if (bool(model_flags & uint(FLAGS_NON_UNIFORM_SCALE))) {
model_normal_matrix = transpose(inverse(mat3(model_matrix)));
} else {
model_normal_matrix = mat3(model_matrix);
}

{
#CODE : FRAGMENT
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,13 @@ void fragment_shader(in SceneData scene_data) {
vec3 light_vertex = vertex;
#endif //LIGHT_VERTEX_USED

mat3 model_normal_matrix;
if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_NON_UNIFORM_SCALE)) {
model_normal_matrix = transpose(inverse(mat3(read_model_matrix)));
} else {
model_normal_matrix = mat3(read_model_matrix);
}

mat4 read_view_matrix = scene_data.view_matrix;
vec2 read_viewport_size = scene_data.viewport_size;
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,13 @@ void main() {
vec3 light_vertex = vertex;
#endif //LIGHT_VERTEX_USED

mat3 model_normal_matrix;
if (bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_NON_UNIFORM_SCALE)) {
model_normal_matrix = transpose(inverse(mat3(read_model_matrix)));
} else {
model_normal_matrix = mat3(read_model_matrix);
}

mat4 read_view_matrix = scene_data.view_matrix;
vec2 read_viewport_size = scene_data.viewport_size;

Expand Down
Loading