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 Dec 10, 2023
1 parent b94eb58 commit d2b855c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/gles3/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ void main() {

#define SHADER_IS_SRGB true

#define FLAGS_NON_UNIFORM_SCALE (1 << 4)

/* Varyings */

#if defined(COLOR_USED)
Expand Down Expand Up @@ -878,6 +880,7 @@ vec2 multiview_uv(vec2 uv) {

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

layout(location = 0) out vec4 frag_color;

Expand Down Expand Up @@ -1332,6 +1335,14 @@ void main() {
float alpha_antialiasing_edge = 0.0;
vec2 alpha_texture_coordinate = vec2(0.0, 0.0);
#endif // ALPHA_ANTIALIASING_EDGE_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 @@ -979,6 +979,14 @@ void fragment_shader(in SceneData scene_data) {
inv_view_matrix[1][3] = 0.0;
inv_view_matrix[2][3] = 0.0;
#endif

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 @@ -809,6 +809,13 @@ void main() {
inv_view_matrix[2][3] = 0.0;
#endif

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 d2b855c

Please sign in to comment.