-
I want to access (read) a large table of static floats from within a fragment shader. Can this be done in BGFX, and how? It sounds like setBuffer() is BGFX substitute for UBOs and the like. But the little documentation I can find on setBuffer() suggests that it can only be used for compute shaders. Is there a way to use this in a fragment shader? Also, how?
shader:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can use buffers inside fragment shaders as well
// the 3 is the bind slot, not the size
BUFFER_RO(myBuffer, float, 3);
float x = myBuffer[0]; Then in C++: const float data[] = {1.0f, 2.0f, 3.0f, 4.0f};
// at init:
bgfx::VertexLayout layout;
layout.begin()
.add(bgfx::Attrib::TexCoord0, 1, bgfx::AttribType::Float)
.end();
// note: on D3D backends you may also need BGFX_BUFFER_COMPUTE_TYPE_FLOAT | BGFX_BUFFER_COMPUTE_FORMAT_32X1
somehandle = createVertexBuffer(makeRef(&data[0], sizeof(data)), layout, BGFX_BUFFER_COMPUTE_READ);
// at draw time:
// the 3 matches whatever bind slot you used in BUFFER_RO
bgfx::setBuffer(3, somehandle, Read); |
Beta Was this translation helpful? Give feedback.
-
Thanks! |
Beta Was this translation helpful? Give feedback.
You can use buffers inside fragment shaders as well☺️ It's just not available on some older APIs like WebGL or ancient OpenGL
Then in C++: