Skip to content

Commit c727627

Browse files
committed
Fix scene shader crash due to rename of view matrix and inverse view matrix
1 parent c01c7b8 commit c727627

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,10 @@ void SceneShaderForwardClustered::init(const String p_defines) {
762762
actions.renames["LIGHT_VERTEX"] = "light_vertex";
763763

764764
actions.renames["NODE_POSITION_WORLD"] = "read_model_matrix[3].xyz";
765-
actions.renames["CAMERA_POSITION_WORLD"] = "scene_data.inv_view_matrix[3].xyz";
766-
actions.renames["CAMERA_DIRECTION_WORLD"] = "scene_data.inv_view_matrix[2].xyz";
765+
actions.renames["CAMERA_POSITION_WORLD"] = "inv_view_matrix[3].xyz";
766+
actions.renames["CAMERA_DIRECTION_WORLD"] = "inv_view_matrix[2].xyz";
767767
actions.renames["CAMERA_VISIBLE_LAYERS"] = "scene_data.camera_visible_layers";
768-
actions.renames["NODE_POSITION_VIEW"] = "(scene_data.view_matrix * read_model_matrix)[3].xyz";
768+
actions.renames["NODE_POSITION_VIEW"] = "(read_view_matrix * read_model_matrix)[3].xyz";
769769

770770
actions.renames["VIEW_INDEX"] = "ViewIndex";
771771
actions.renames["VIEW_MONO_LEFT"] = "0";

servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,10 @@ void SceneShaderForwardMobile::init(const String p_defines) {
696696
actions.renames["LIGHT_VERTEX"] = "light_vertex";
697697

698698
actions.renames["NODE_POSITION_WORLD"] = "read_model_matrix[3].xyz";
699-
actions.renames["CAMERA_POSITION_WORLD"] = "scene_data.inv_view_matrix[3].xyz";
700-
actions.renames["CAMERA_DIRECTION_WORLD"] = "scene_data.inv_view_matrix[2].xyz";
699+
actions.renames["CAMERA_POSITION_WORLD"] = "inv_view_matrix[3].xyz";
700+
actions.renames["CAMERA_DIRECTION_WORLD"] = "inv_view_matrix[2].xyz";
701701
actions.renames["CAMERA_VISIBLE_LAYERS"] = "scene_data.camera_visible_layers";
702-
actions.renames["NODE_POSITION_VIEW"] = "(scene_data.view_matrix * read_model_matrix)[3].xyz";
702+
actions.renames["NODE_POSITION_VIEW"] = "(read_view_matrix * read_model_matrix)[3].xyz";
703703

704704
actions.renames["VIEW_INDEX"] = "ViewIndex";
705705
actions.renames["VIEW_MONO_LEFT"] = "0";

servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,26 @@ void light_compute(hvec3 N, hvec3 L, hvec3 V, half A, hvec3 light_color, bool is
8181
inout hvec3 diffuse_light, inout hvec3 specular_light) {
8282
#if defined(LIGHT_CODE_USED)
8383
// Light is written by the user shader.
84-
mat4 inv_view_matrix = scene_data_block.data.inv_view_matrix;
85-
mat4 read_view_matrix = scene_data_block.data.view_matrix;
84+
mat4 inv_view_matrix = transpose(mat4(scene_data_block.data.inv_view_matrix[0],
85+
scene_data_block.data.inv_view_matrix[1],
86+
scene_data_block.data.inv_view_matrix[2],
87+
vec4(0.0, 0.0, 0.0, 1.0)));
88+
mat4 read_view_matrix = transpose(mat4(scene_data_block.data.view_matrix[0],
89+
scene_data_block.data.view_matrix[1],
90+
scene_data_block.data.view_matrix[2],
91+
vec4(0.0, 0.0, 0.0, 1.0)));
8692

8793
#ifdef USING_MOBILE_RENDERER
88-
mat4 read_model_matrix = instances.data[draw_call.instance_index].transform;
94+
uint instance_index = draw_call.instance_index;
8995
#else
90-
mat4 read_model_matrix = instances.data[instance_index_interp].transform;
96+
uint instance_index = instance_index_interp;
9197
#endif
9298

99+
mat4 read_model_matrix = transpose(mat4(instances.data[instance_index].transform[0],
100+
instances.data[instance_index].transform[1],
101+
instances.data[instance_index].transform[2],
102+
vec4(0.0, 0.0, 0.0, 1.0)));
103+
93104
#undef projection_matrix
94105
#define projection_matrix scene_data_block.data.projection_matrix
95106
#undef inv_projection_matrix

0 commit comments

Comments
 (0)