정점 셰이더의 out 변수는 어떻게 보간됩니까? (How are the out variables of vertex shader interpolated?)


문제 설명

정점 셰이더의 out 변수는 어떻게 보간됩니까? (How are the out variables of vertex shader interpolated?)

꼭짓점에서 계산된 꼭짓점의 입력 속성은 현재 픽셀의 무게 중심 좌표에 따라 보간됩니다. 그리고 속성 을 보간하거나 현재 픽셀의 무게 중심 좌표를 계산할 수 있는 것은 정점 셰이더 이후 정점 스트림이 삼각형 스트림으로 전환되기 때문입니다. 현재 픽셀의 무게 중심 좌표는 gl_Position에서 제공하는 삼각형 꼭짓점의 화면 위치와 픽셀 위치에 의해 파생될 수 있습니다.

하지만 in 프래그먼트 셰이더의 변수. 다음은 셰이더의 예입니다.

  • 정점 셰이더
layout(binding = 0) uniform WorldMVP {
    mat4 worldMvp;
};
layout(binding = 0) uniform LightMVP{
    mat4 lightMvp;
};
layout(location = 0) in vec3 aVertexPosition;
layout(location = 1) in vec3 aVertexNormal;
layout(location = 2) in vec2 aTextureCoord;
layout(location = 0) out vec4 vPositionFromLight;
layout(location = 1) out vec2 vTextureCoord;
layout(location = 2) out vec3 vNormal;
void mian()
{
    gl_Position = worldMvp * vec4(aVertexPosition, 1.0);
    vPositionFromLight = lightMvp * vec4(aVertexPosition, 1.0);
    vTextureCoord = aTextureCoord;
    vNormal = aVertexNormal;
}
  • 조각 셰이더
layout(location = 0) in vec4 vPositionFromLight;
layout(location = 1) in vec2 vTextureCoord;
layout(location = 2) in vec3 vNormal;
layout(location = 0) out vec4 outColor;
void main()
{
    outColor = vec4(1.0, 1.0, 1.0, 1.0);
}

vPositionFromLight 보간에 사용된 무게 중심 좌표가 vTextureCoordvNormal과 같은 속성 보간에서 사용된 것과 동일하면 비정상적으로 보입니다. vPositionFromLightgl_Position은 다른 MVP에 의해 다른 클립 공간으로 변환되기 때문입니다.

vPositionFromLight는 어떻게 보간됩니까? vPositionFromLight를 보간하는 데 사용되는 무게 중심 좌표는 무엇입니까?

code>vPositionFromLight 및 gl_Position은 다른 MVP에 의해 다른 클립 공간으로 변환됩니다.

vPositionFromLight는 어떻게 보간됩니까? vPositionFromLight를 보간하는 데 사용되는 무게 중심 좌표는 무엇입니까?

code>vPositionFromLight 및 gl_Position은 다른 MVP에 의해 다른 클립 공간으로 변환됩니다.

vPositionFromLight는 어떻게 보간됩니까? vPositionFromLight를 보간하는 데 사용되는 무게 중심 좌표는 무엇입니까?


참조 솔루션

방법 1:

Because vPositionFromLight and gl_Position are transformed into different clip spaces by different MVP.

As far as OpenGL is concerned, they're just numbers. Is vPositionFromLight in a "clip space"? OpenGL doesn't care; they are a vec4, and that vec4 will get the same interpolation math as any other vertex shader output.

The space of the post‑interpolation value is the same space as the pre‑interpolation result.

(by wangsyNicol Bolas)

참조 문서

  1. How are the out variables of vertex shader interpolated? (CC BY‑SA 2.5/3.0/4.0)

#graphics #vulkan #opengl #glsl






관련 질문

Triangulate a quad with a hole in it using tessellation (Triangulate a quad with a hole in it using tessellation)

기존 이미지가 화면에 그려지지 않는 이유는 무엇입니까? (Why won't my existing image draw to the screen?)

barplot()에서 정보를 저장하고 그래프를 표시하지 않는 방법 (How to save information from barplot() and not displaying the graph)

Java 시간에 따라 사각형을 이동하는 방법 (java how to make a rectangle move by time)

큐브맵을 2D 텍스처로 투영 (Project cubemap to 2D texture)

OpenGL & Qt : 마우스 오버 시 레이블 표시 (OpenGL & Qt : display a label on the mouseover)

프리파스칼에서 기능적 그래픽을 얻으려면 어떻게 해야 합니까? (How do I get functional graphics from freepascal?)

스크래치 및 승리 (Scratch and win)

벡터 병합 알고리즘 도움말 (Help with algorithm for merging vectors)

WPF - ScreenSaver 그래픽 성능 향상 (WPF - ScreenSaver graphics performance improvements)

Java, 패널용 그래픽 개체 생성 및 편집? (Java, create and edit a Graphics Object for Panel?)

정점 셰이더의 out 변수는 어떻게 보간됩니까? (How are the out variables of vertex shader interpolated?)







코멘트