It’s possible to update a shader uniform array with go.set()
:
go.set(url, "example", vmath.vector4(1), { index = 5 } )
But there is no way to do it with a constants buffer created by render.constant_buffer()
.
Would like to do it by this way:
self.constants = render.constant_buffer()
self.constants.example[5] = vmath.vector4(1)
Use case
I’m trying to implement forward shading using additional texture data with positions and colors of light sources. That’s a 32x32 texture that I update every frame because of lights movement. It takes time to extract values from the texture data in the fragment shader program. For example, 20 light sources require to find and read 100 pixels of data per a fragment.
This looks adequate for 20 light sources, but not for 60 light sources.
I know, forward shading is not the best way of rendering lighting. But maybe performance could be better if iterating over uniform arrays instead of reading 5 pixels per light source and extracting all the parameters from them?
For example, look at this method of extracting the light source position from 3 pixels that I use now:
vec3 get_data(int index) {
float x = float(index % texture_size) / float(texture_size);
float y = float(index / texture_size) / float(texture_size);
vec2 coord = vec2(x, y);
return texture2D(illumination, coord).rgb;
}
float data_to_axis(vec3 data) {
float r = 255.0 * data.r * 256.0 * 256.0;
float g = 255.0 * data.g * 256.0;
float b = 255.0 * data.b;
float value = r + g + b;
value = value - (max_uint24 * 0.5);
value = value * (axis_capacity / max_uint24);
return value;
}
...
vec3 light_position = vec3(
data_to_axis(get_data(pixel + 1)),
data_to_axis(get_data(pixel + 2)),
data_to_axis(get_data(pixel + 3))
);
...
Voting
If you’d like to have forward shading like that more optimized, please upvote for #6529