Add model_normal_matrix for fragment shader

This commit is contained in:
jsjtxietian 2023-12-10 21:32:36 +08:00
parent ee363af0ed
commit e698351db2
3 changed files with 24 additions and 0 deletions

View File

@ -583,6 +583,8 @@ void main() {
#define SHADER_IS_SRGB true #define SHADER_IS_SRGB true
#define FLAGS_NON_UNIFORM_SCALE (1 << 4)
/* Varyings */ /* Varyings */
#if defined(COLOR_USED) #if defined(COLOR_USED)
@ -955,6 +957,7 @@ ivec2 multiview_uv(ivec2 uv) {
uniform highp mat4 world_transform; uniform highp mat4 world_transform;
uniform mediump float opaque_prepass_threshold; uniform mediump float opaque_prepass_threshold;
uniform highp uint model_flags;
#if defined(RENDER_MATERIAL) #if defined(RENDER_MATERIAL)
layout(location = 0) out vec4 albedo_output_buffer; layout(location = 0) out vec4 albedo_output_buffer;
@ -1521,6 +1524,13 @@ void main() {
vec3 light_vertex = vertex; vec3 light_vertex = vertex;
#endif //LIGHT_VERTEX_USED #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 #CODE : FRAGMENT
} }

View File

@ -1030,6 +1030,13 @@ void fragment_shader(in SceneData scene_data) {
vec3 light_vertex = vertex; vec3 light_vertex = vertex;
#endif //LIGHT_VERTEX_USED #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; mat4 read_view_matrix = scene_data.view_matrix;
vec2 read_viewport_size = scene_data.viewport_size; vec2 read_viewport_size = scene_data.viewport_size;
{ {

View File

@ -839,6 +839,13 @@ void main() {
vec3 light_vertex = vertex; vec3 light_vertex = vertex;
#endif //LIGHT_VERTEX_USED #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; mat4 read_view_matrix = scene_data.view_matrix;
vec2 read_viewport_size = scene_data.viewport_size; vec2 read_viewport_size = scene_data.viewport_size;