Home Unity

ComputeBuffers in OpenGLES3.1 Shader

polycounter lvl 4
Offline / Send Message
echofourpapa polycounter lvl 4
Hi everyone,

I'm curious about something. I'm using structured buffers to send data in a vert/frag shader wrapped in a DX11 api check.

With the new experimental OpenGL stuff I was hoping that those might "just work" like compute shaders. This is sadly not the case.

Has anyone else tried this? From what I understand about OpenGL(which isn't a lot), there isn't an exact cross over for DX StructuredBuffers, but is there something else that Unity's compute buffers will work with?

Replies

  • echofourpapa
    Offline / Send Message
    echofourpapa polycounter lvl 4
    Update!

    It turns out using surface shaders are what's failing, not the structured buffer conversion:

    This works just fine:
                CGPROGRAM
                #include "UnityCG.cginc"
                #pragma vertex vert
                #pragma fragment frag
                #pragma target 5.0
     
                StructuredBuffer<float4> Buffer_A;
    

    This does not:
            CGPROGRAM
     
           
            #include "UnityCG.cginc"
           
            #pragma surface surf StandardSpecular vertex:vert
            #pragma target 5.0
     
            StructuredBuffer<float4> Buffer_A;
    
    it fails at the line StructuredBuffer with "Syntax Error"
  • RyanB
    Maybe what you want.
    http://forum.unity3d.com/threads/structuredbuffer-with-surface-shader.173000/

    I think it should work. Here's a snipped that will be in the documentation really soon:

    "DirectX 11 HLSL syntax and Surface Shaders

    Currently some parts of surface shader compilation pipeline do not understand DX11-specific HLSL syntax. If you're HLSL features like StructuredBuffers, RWTextures and other non-DX9 syntax, you have to wrap it into a DX11-only preprocessor macro:

    #ifdef SHADER_API_D3D11
    // DX11-specific code, e.g.
    StructuredBuffer<float4> myColors;
    RWTexture2D<float4> myRandomWriteTexture;
    #endif
    "
  • echofourpapa
    Offline / Send Message
    echofourpapa polycounter lvl 4
    Right, this is with the new/experimental OpenGL backend to bring these features to OpenGL.

    I normally have it wrapped in the API checks, but I can't do that if compiling to OpenGL or OpenGLES.
  • cupsster
    Offline / Send Message
    cupsster polycounter lvl 11
    You need to add RW to be able to write to them. I did not tested this only from my own experience with compute shaders. RW prepend works.
Sign In or Register to comment.