Search Unity

Question Shader storage buffers in native unity plugin [OpenGL]

Discussion in 'Shaders' started by wollyb, Nov 18, 2020.

  1. wollyb

    wollyb

    Joined:
    Sep 4, 2017
    Posts:
    2
    Hey everyone,

    I'm currently implementing a mesh shader in unity using a native plugin with OpenGL, but I'm having trouble with reading data passed to the shader using Shader Storage Buffers.

    The shader itself works fine when color and position data is passed manually in the shader, but not when reading it from a shader storage buffer object.

    The data is passed using the following method:

    Code (C++):
    1.     GLfloat vertices[4];
    2.     vertices[0] = 1.0;
    3.     vertices[1] = 1.0;
    4.     vertices[2] = 1.0;
    5.     vertices[3] = 1.0;
    6.  
    7.     GLuint ssboColor;
    8.     glGenBuffers(1, &ssboColor);
    9.  
    10.     glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssboColor);
    11.     glBufferData(GL_SHADER_STORAGE_BUFFER, 4 * (sizeof(GLfloat)), vertices, GL_STATIC_DRAW);
    12.     glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, ssboColor);
    13.  
    14.     glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
    and read in the shader like:

    Code (C++):
    1. layout (std430, binding = 2) buffer _colors {
    2.     vec4 vertices[];
    3. } vbColor;
    but when the block is accessed through vbColor.vertices[0] all values inside (x,y,z,w) are 0.

    Is there some kind of pre-existing limitation where unity does not support these kind of buffers?
     
    Last edited: Nov 20, 2020
  2. wollyb

    wollyb

    Joined:
    Sep 4, 2017
    Posts:
    2
    Apparently the there was a problem with the OpenGL Library and how it was linked to the native plugin.
    I switched from a static GLEW implementation to gl3w and everything seems to work fine.