How to direct modify a shader param

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lanesun

I’m writing a Raymarching-based voxel rendering algorithm, and the shader used by the algorithm needs to be able to get the voxel map data in the Fragment function. I do this by setting a uniform of type int array.

Since Godot3 doesn’t support Uniform arrays, I migrated to Godot4 to implement my plan.

So far, everything works fine, except that whenever I modify the voxel data (type PackedInt32Array, 4096 length), I need to re-call set_shader_param to synchronize the result to the shader.

This process proved to be quite slow, taking about 200ms per data sync, making it impossible for me to maintain a stable frame rate.

So, I was looking for a way to write data directly to the Uniform’s corresponding data object at an offset. My ultimate goal was to manipulate the corresponding memory object directly.

After a lot of searching, I found the following information and tried to read the corresponding source code in Godot, but I still couldn’t find a suitable method:

  • Tried via the low-level API provided by the RenderingServer object, but the documentation was unclear, so I looked up the relevant source code in the engine and located (but wasn’t entirely sure) that the code for updating the Shader’s Uniform was located at this location link , but it was hard to find information beyond that.
  • I retrieved that the RenderingDevice object has a buffer_update method, which looks like what I need, but it’s hard to find any further hints in the source code.
  • I noticed that one of the features link added in an update to Godot4 includes low level access to RenderingDevice. But the page doesn’t give any further hints either.

So, I just noticed the above things, but had no clue if they could achieve my goals and how to use them, and I tried searching, but didn’t find any information on the web.

I’m using Godot version 4.0.alpha5.official.d7d528c15, running on GNU/Linux OS, with the core graphics provided by Intel Corporation AlderLake-S GT1 and the Vulkan driver provided by Mesa 22.0.0.

The message is generated by translator, sorry for my poor English :slight_smile: