Skip to main content
Don't invent a secondary tagging syntax. Work the keywords into the title sentence, or leave them in the tag section at the bottom.
Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

Passing a single float into a Vulkan compute shader -in Godot Vulcan

Source Link
DavidT
  • 716
  • 1
  • 8

Passing a single float into a compute shader - Godot Vulcan

I have written a compute shader to convert a height map into a normal map.

The shader definition (glsl) starts as follows:

#[compute]
#version 460

layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

layout(set = 0, binding = 0, std430) buffer Workload {
    float vertical_scale[];
} params;

layout(r8, binding = 1) restrict readonly uniform image2D heightMap;

layout(rgba8, binding = 2) restrict uniform image2D normal;

void main() {
    float height = params.vertical_scale[0];

The shader is working fine (generating the correct normal map), however the I need to create a float buffer with only one element in it to pass my vertical_scale parameter into the shader.

It's not causing any issue (works fine) to do this - it just looks ugly, is there a better way to pass the single float parameter to the compute shader?

Godot 4.2.2, Mac OSX 14.5 using Vulcan