Skip to content
Discussion options

You must be logged in to vote

You can use buffers inside fragment shaders as well ☺️ It's just not available on some older APIs like WebGL or ancient OpenGL

??? (How do I read from the buffer in the shader?)

// 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…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by ChthonVII
Comment options

You must be logged in to vote
1 reply
@pezcode
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants