Skip to content

Commit

Permalink
Add model_normal_matrix for fragment shader
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjtxietian committed Aug 20, 2024
1 parent ee363af commit e698351
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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

0 comments on commit e698351

Please sign in to comment.