0

可能であれば、カスタム頂点プロパティをシェーダーに送信してアクセスするにはどうすればよいですか?モデルはVBOでレンダリングされることに注意してください。たとえば、次のような頂点構造があるとします。

struct myVertStruct{
    double x, y, z; // for spacial coords
    double nx, ny, nz; // for normals
    double u, v; // for texture coords
    double a, b; // just a couple of custom properties

たとえば、法線にアクセスするには、シェーダーを呼び出します。

varying vec3 normal;

カスタムプロパティに対してこれはどのように行われますか?

4

1 に答える 1

1

まず、倍精度浮動小数点数はほぼすべてのGPUでサポートされていないため、使用できません。したがって、構造体のメンバーを浮動小数点数に変更するだけです...

glslで同じ構造体を定義します。

struct myVertStruct
{
    float x, y, z; // for spacial coords
    float nx, ny, nz; // for normals
    float u, v; // for texture coords
    float a, b; // just a couple of custom properties
} myStructName;

次に、c / c ++で構造体配列をインスタンス化し、vboを​​作成し、それにメモリを割り当ててから、シェーダーにバインドします。

struct myVertStruct
{
    float x, y, z; // for spacial coords
    float nx, ny, nz; // for normals
    float u, v; // for texture coords
    float a, b; // just a couple of custom properties
};

GLuint vboID;
myVertStruct myStructs[100]; // just using 100 verts for the sake of the example
// .... fill struct array;

glGenBuffers(1,&vboID);

次に、属性をバインドすると、次のようになります。

glBindBuffer(GL_ARRAY_BUFFER, vboID);
glVertexAttribPointer(0, sizeof(myVertStruct) * 100, GL_FLOAT, GL_FALSE, 0, &struct);
glBindBuffer(GL_ARRAY_BUFFER, 0);

...次に、上記で使用したglslセグメントを使用して作成したシェーダープログラムにvboをバインドします。

于 2013-02-27T17:26:31.120 に答える