V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
PTLin
V2EX  ›  程序员

请教一个 GLSL 的问题

  •  
  •   PTLin · 313 天前 · 1262 次点击
    这是一个创建于 313 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #version 450
    layout(location = 0) in vec2 v_Uv;
    
    layout(location = 0) out vec4 o_Target;
    
    layout(set = 1, binding = 0) uniform CustomMaterial {
        vec4 Color;
    };
    
    layout(set = 1, binding = 1) uniform texture2D CustomMaterial_texture;
    layout(set = 1, binding = 2) uniform sampler CustomMaterial_sampler;
    
    
    void main() {
        o_Target = Color * texture(sampler2D(CustomMaterial_texture,CustomMaterial_sampler), v_Uv);
    }
    
    #version 450
    
    layout(location = 0) in vec3 Vertex_Position;
    layout(location = 1) in vec3 Vertex_Normal;
    layout(location = 2) in vec2 Vertex_Uv;
    
    layout(location = 0) out vec2 v_Uv;
    
    layout(set = 0, binding = 0) uniform CameraViewProj {
        mat4 ViewProj;
        mat4 View;
        mat4 InverseView;
        mat4 Projection;
        vec3 WorldPosition;
        float width;
        float height;
    };
    
    layout(set = 2, binding = 0) uniform Mesh {
        mat4 Model;
        mat4 InverseTransposeModel;
        uint flags;
    };
    
    void main() {
        v_Uv = Vertex_Uv;
        gl_Position = ViewProj * Model * vec4(Vertex_Position, 1.0);
    }
    

    我想问一下这两个着色器里面 uniform 的 layout 里的 set 修饰符是什么意思,我知道后面的 binding 是 uniform 缓冲对象的绑定点,那顶点和片段着色器 uniform 前面的 set 代表什么呢,我翻阅 khronos 的文档也没查到这个修饰符。

    8 条回复    2023-06-26 14:34:11 +08:00
    Anarchy
        1
    Anarchy  
       313 天前
    不懂这个,不过直接 google 搜 layout(set = 0, binding = 0)是有结果的,好像都指向 vulkan 。
    misdake
        2
    misdake  
       313 天前 via Android
    这个是给 vulkan 用的 glsl 吧,set 是 descriptor set ,可以往这个方向搜
    nightwitch
        3
    nightwitch  
       313 天前 via Android
    Vulkan glsl 和 opengl glsl 的语法有些细微区别
    PTLin
        4
    PTLin  
    OP
       313 天前
    @misdake 明白了,确实是 vulkan 的 DescriptorSet ,我看 wgsl 也有和这个类似的 group 属性我还以为这个是通用的什么语法。
    besto
        5
    besto  
       313 天前
    PTLin
        6
    PTLin  
    OP
       313 天前
    @besto 我看的就是这个文档,只不过看的是 4.50 的。。。
    PTLin
        7
    PTLin  
    OP
       313 天前
    @besto 因为文件上那句#version 450 我就直接找的 4.50 的文档看的 就是你这个链接把 4.60 换成 4.50 里的 59 页
    PTLin
        8
    PTLin  
    OP
       312 天前
    终于破案了,这段 glsl 在代码里最后会被转换成 wgsl ,里面的 set 对应的是 wgsl 里的 group ,也就是 webgpu 里的 bind group 的概念。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2264 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 07:41 · PVG 15:41 · LAX 00:41 · JFK 03:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.