2014-04-05 2 views
1

의 INT 중 4 바이트 I 다음 정점 셰이더있다 : I 이렇게 채워을 풀고 GLSL

#version 330 core 

struct Bone 
{ 
    int parent; 
    float scale; 
    mat4 matrix; 
}; 

uniform mat4 MVP; 
uniform Bone[67] Bones; 

layout(location = 0) in vec3 position; 
layout(location = 1) in int boneIndex; 
layout(location = 2) in vec4 weight; 
layout(location = 3) in vec3 normal; 
layout(location = 4) in vec2 UVCords; 

out vec2 UV; 

void main() 
{ 
    gl_Position = MVP * vec4(position, 1.0f); 
    UV = UVCords; 
} 

(C++)

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0); //float position[3] 
glVertexAttribPointer(1, 1, GL_INT, GL_FALSE, sizeof(Vertex), (void*)12); //char boneIndex[4] 
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)16); //float weights[4] 
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)32); //float normals[3] 
glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)44); //float textureCords[2] 

버퍼 개체의 실제 데이터를 포함 이들의 배열은 다음과 같습니다

이제
struct Vertex 
{ 
    float position[3]; 
    char boneIndex[4]; 
    float weights[4]; 
    float normals[3]; 
    float textureCords[2]; 
}; 

, 내 질문에 내가,643,926,321에서 4 바이트를 추출 할 수있는 방법이다 GLSL 쪽에서 0? GLSL이 바이트 크기 타입을 지원하지 않는다는 것을 알고 있기 때문에 병이 4 개의 다른 int 변수로 추출해야한다고 생각합니다.

+1

google이 먼저 내게주었습니다. http://www.gamedev.net/topic/556757-unpack-4-bytes-from-an-int-in-glsl/ – SAKrisT

답변

1

여기에는 두 가지 문제가 있습니다. 우선, 정수 속성 포인터를 올바르게 설정하지 않았습니다. 데이터를 파이프 라인에서 정수로 사용하려면 glVertexAttribIPointer을 사용해야합니다.

단일 바이트에 액세스하려면 C에서 할 수있는 것처럼 GLSL의 표준 정수 비트 시프트 연산을 사용할 수 있습니다.하지만 부호없는 정수 (부호없는 문자)를 사용하는 것이 좋습니다. 예를 들어, 값에서 두 번째로 높은 바이트에 액세스하는 것은 (boneIndex >> 16) & 0xff으로 수행 할 수 있습니다.