【问题标题】:Passing attribute into shader Libgdx将属性传递到着色器 Libgdx
【发布时间】:2014-06-02 22:19:46
【问题描述】:

我不知道如何使用 libgdx 将自定义属性传递到着色器。我的着色器中有一个浮点数:

attribute float a_ParticleStartTime;

我想在创建时将当前时间传递给我的着色器。我有我的网格,可以使用它来指定颜色和位置,如下所示:

 mesh = new Mesh(true, MAX_VERTS, 0, 
                    new VertexAttribute(Usage.Position, POSITION_COMPONENTS, "a_position"),
                    new VertexAttribute(Usage.Color, COLOR_COMPONENTS, "a_color"));

但是我不知道如何在 Usage 类中传递一个不是默认分类的属性。我需要通过当前时间。有人知道这样做的正确方法吗?我查看了示例,但一无所获。 :(

【问题讨论】:

    标签: java opengl-es libgdx glsl shader


    【解决方案1】:

    据我所知,对于 VertexAttribute,Usage 参数被忽略,因为 Libgdx 不再支持 OpenGL ES 1.0。

    因此,只需向您的网格添加一个具有通用用途的属性。

    mesh = new Mesh(false, MAX_VERTS, 0, //for a mesh that you're updating frequently, false is theoretically better (but maybe not in practice on most GPUs)
        new VertexAttribute(Usage.Position, 3, "a_position"),
        new VertexAttribute(Usage.Color, 4, "a_color"),
        new VertexAttribute(Usage.Generic, 1, "a_ParticleStartTime")); //The 1 is because it's a single float
    

    当您在浮点数组中放置或更新顶点以与mesh.setVertices 一起使用时,现在每个顶点有 8 个浮点数:x, y, z, r, g, b, a, startTime

    【讨论】:

      猜你喜欢
      • 2016-12-20
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多