Merge pull request #111227 from clayjohn/RD-scene-shader-crash

Fix scene shader crash due to rename of view matrix and inverse view matrix
This commit is contained in:
Thaddeus Crews 2025-10-07 17:15:11 -05:00
commit f457855148
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
3 changed files with 21 additions and 10 deletions

View file

@ -762,10 +762,10 @@ void SceneShaderForwardClustered::init(const String p_defines) {
actions.renames["LIGHT_VERTEX"] = "light_vertex"; actions.renames["LIGHT_VERTEX"] = "light_vertex";
actions.renames["NODE_POSITION_WORLD"] = "read_model_matrix[3].xyz"; actions.renames["NODE_POSITION_WORLD"] = "read_model_matrix[3].xyz";
actions.renames["CAMERA_POSITION_WORLD"] = "scene_data.inv_view_matrix[3].xyz"; actions.renames["CAMERA_POSITION_WORLD"] = "inv_view_matrix[3].xyz";
actions.renames["CAMERA_DIRECTION_WORLD"] = "scene_data.inv_view_matrix[2].xyz"; actions.renames["CAMERA_DIRECTION_WORLD"] = "inv_view_matrix[2].xyz";
actions.renames["CAMERA_VISIBLE_LAYERS"] = "scene_data.camera_visible_layers"; actions.renames["CAMERA_VISIBLE_LAYERS"] = "scene_data.camera_visible_layers";
actions.renames["NODE_POSITION_VIEW"] = "(scene_data.view_matrix * read_model_matrix)[3].xyz"; actions.renames["NODE_POSITION_VIEW"] = "(read_view_matrix * read_model_matrix)[3].xyz";
actions.renames["VIEW_INDEX"] = "ViewIndex"; actions.renames["VIEW_INDEX"] = "ViewIndex";
actions.renames["VIEW_MONO_LEFT"] = "0"; actions.renames["VIEW_MONO_LEFT"] = "0";

View file

@ -696,10 +696,10 @@ void SceneShaderForwardMobile::init(const String p_defines) {
actions.renames["LIGHT_VERTEX"] = "light_vertex"; actions.renames["LIGHT_VERTEX"] = "light_vertex";
actions.renames["NODE_POSITION_WORLD"] = "read_model_matrix[3].xyz"; actions.renames["NODE_POSITION_WORLD"] = "read_model_matrix[3].xyz";
actions.renames["CAMERA_POSITION_WORLD"] = "scene_data.inv_view_matrix[3].xyz"; actions.renames["CAMERA_POSITION_WORLD"] = "inv_view_matrix[3].xyz";
actions.renames["CAMERA_DIRECTION_WORLD"] = "scene_data.inv_view_matrix[2].xyz"; actions.renames["CAMERA_DIRECTION_WORLD"] = "inv_view_matrix[2].xyz";
actions.renames["CAMERA_VISIBLE_LAYERS"] = "scene_data.camera_visible_layers"; actions.renames["CAMERA_VISIBLE_LAYERS"] = "scene_data.camera_visible_layers";
actions.renames["NODE_POSITION_VIEW"] = "(scene_data.view_matrix * read_model_matrix)[3].xyz"; actions.renames["NODE_POSITION_VIEW"] = "(read_view_matrix * read_model_matrix)[3].xyz";
actions.renames["VIEW_INDEX"] = "ViewIndex"; actions.renames["VIEW_INDEX"] = "ViewIndex";
actions.renames["VIEW_MONO_LEFT"] = "0"; actions.renames["VIEW_MONO_LEFT"] = "0";

View file

@ -81,15 +81,26 @@ void light_compute(hvec3 N, hvec3 L, hvec3 V, half A, hvec3 light_color, bool is
inout hvec3 diffuse_light, inout hvec3 specular_light) { inout hvec3 diffuse_light, inout hvec3 specular_light) {
#if defined(LIGHT_CODE_USED) #if defined(LIGHT_CODE_USED)
// Light is written by the user shader. // Light is written by the user shader.
mat4 inv_view_matrix = scene_data_block.data.inv_view_matrix; mat4 inv_view_matrix = transpose(mat4(scene_data_block.data.inv_view_matrix[0],
mat4 read_view_matrix = scene_data_block.data.view_matrix; scene_data_block.data.inv_view_matrix[1],
scene_data_block.data.inv_view_matrix[2],
vec4(0.0, 0.0, 0.0, 1.0)));
mat4 read_view_matrix = transpose(mat4(scene_data_block.data.view_matrix[0],
scene_data_block.data.view_matrix[1],
scene_data_block.data.view_matrix[2],
vec4(0.0, 0.0, 0.0, 1.0)));
#ifdef USING_MOBILE_RENDERER #ifdef USING_MOBILE_RENDERER
mat4 read_model_matrix = instances.data[draw_call.instance_index].transform; uint instance_index = draw_call.instance_index;
#else #else
mat4 read_model_matrix = instances.data[instance_index_interp].transform; uint instance_index = instance_index_interp;
#endif #endif
mat4 read_model_matrix = transpose(mat4(instances.data[instance_index].transform[0],
instances.data[instance_index].transform[1],
instances.data[instance_index].transform[2],
vec4(0.0, 0.0, 0.0, 1.0)));
#undef projection_matrix #undef projection_matrix
#define projection_matrix scene_data_block.data.projection_matrix #define projection_matrix scene_data_block.data.projection_matrix
#undef inv_projection_matrix #undef inv_projection_matrix