Graphics Programming
정점 셰이더 본문
정점 셰이더의 역할: 정점의 위치를 정하여 다음 단계에 넘긴다
그리고 기타 사용자 정의 출력 또는 내장된 출력을 설정한다
vertex fetch: 모든 OpenGL 그래픽스 파이프라인의 시작(vertex attribute가 필요하다면)
- 정점 셰이더 전에 실행된다
- glVertexAttribPointer()는 버퍼 내의 데이터를 정점 셰이더 입력으로 돌린다. 이 함수는 다음 함수들을 합친 것이다.
- glVertexAttribFormat()
- glVertexAttribBinding()
- glBindVertexBuffer()
정점 셰이더 |
애플리케이션 |
layout (location = 0) in vec4 position; layout (location = 1) in vec3 normal; layout (location = 2) in vec2 tex_coord; layout (location = 4) in vec4 color; layout (location = 5) in int material_id; |
glVertexAttribFormat(attribindex, size, type, normalized, relativeoffset) glVertexAttribFormat(0, 4, GL_FLOAT, GL_FALSE, offset(VERTEX, position)); glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, offset(VERTEX, normal)); glVertexAttribFormat(2, 2, GL_FLOAT, GL_FALSE, offset(VERTEX, tex_coord)); glVertexAttribFormat(4, 3, GL_UNSIGNED_BYTE, GL_TRUE, offset(VERTEX, color)); glVertexAttribIFormat(5, 1, GL_INT, GL_FALSE, offset(VERTEX, material_id));
glVertexAttribBinding(attribindex, bindingindex) glVertexAttribBinding(0, 0); glVertexAttribBinding(1, 0); glVertexAttribBinding(2, 0); glVertexAttribBinding(4, 0); glVertexAttribBinding(5, 0);
glBindVertexBuffer(bindingindex, buffer, offset, stride) |
정점 셰이더 출력
내장 출력 변수들
out gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];
}
gl_PointSize를 사용하려면 glEnable(GL_PROGRAM_POINT_SIZE)
"거리 기반 point size attenuation"
$$ \text{size} = \text{clamp} \Big( \sqrt {\frac{1.0}{a + bd + cd^2}} \Big) $$