我的顶点着色器需要输出什么值?

时间:2014-08-19 23:58:32

标签: opengl vertex-shader

我正在使用openGL,并试图绘制一个立方体,但它不会出现。我使用了变换反馈,发现我的顶点着色器正在输出这些值

    [0] -0.500000000    float
    [1] -0.500000000    float
    [2] -3.54020095 float
    [3] -4.50000000 float
    [4] -0.500000000    float
    [5] -0.500000000    float
    [6] -4.55025101 float
    [7] -5.50000000 float
    [8] -0.500000000    float
    [9] 0.500000000 float
    [10]    -3.54020095 float
    [11]    -4.50000000 float
    [12]    -0.500000000    float
    [13]    0.500000000 float
    [14]    -3.54020095 float
    [15]    -4.50000000 float
    [16]    -0.500000000    float
    [17]    -0.500000000    float
    [18]    -4.55025101 float
    [19]    -5.50000000 float
    [20]    -0.500000000    float
    [21]    0.500000000 float
    [22]    -4.55025101 float
    [23]    -5.50000000 float
    [24]    -0.500000000    float
    [25]    0.500000000 float
    [26]    -3.54020095 float
    [27]    -4.50000000 float
    [28]    -0.500000000    float
    [29]    0.500000000 float
    [30]    -4.55025101 float
    [31]    -5.50000000 float
    [32]    0.500000000 float
    [33]    0.500000000 float
    [34]    -3.54020095 float
    [35]    -4.50000000 float
    [36]    0.500000000 float
    [37]    0.500000000 float
    [38]    -3.54020095 float
    [39]    -4.50000000 float
    [40]    -0.500000000    float
    [41]    0.500000000 float
    [42]    -4.55025101 float
    [43]    -5.50000000 float
    [44]    0.500000000 float
    [45]    0.500000000 float
    [46]    -4.55025101 float
    [47]    -5.50000000 float
    [48]    0.500000000 float
    [49]    0.500000000 float
    [50]    -3.54020095 float
    [51]    -4.50000000 float
    [52]    0.500000000 float
    [53]    0.500000000 float
    [54]    -4.55025101 float
    [55]    -5.50000000 float
    [56]    0.500000000 float
    [57]    -0.500000000    float
    [58]    -3.54020095 float
    [59]    -4.50000000 float
    [60]    0.500000000 float
    [61]    -0.500000000    float
    [62]    -3.54020095 float
    [63]    -4.50000000 float
    [64]    0.500000000 float
    [65]    0.500000000 float
    [66]    -4.55025101 float
    [67]    -5.50000000 float
    [68]    0.500000000 float
    [69]    -0.500000000    float
    [70]    -4.55025101 float
    [71]    -5.50000000 float
    [72]    -0.500000000    float
    [73]    0.500000000 float
    [74]    -3.54020095 float
    [75]    -4.50000000 float
    [76]    0.500000000 float
    [77]    0.500000000 float
    [78]    -3.54020095 float
    [79]    -4.50000000 float
    [80]    -0.500000000    float
    [81]    -0.500000000    float
    [82]    -3.54020095 float
    [83]    -4.50000000 float
    [84]    -0.500000000    float
    [85]    -0.500000000    float
    [86]    -3.54020095 float
    [87]    -4.50000000 float
    [88]    0.500000000 float
    [89]    0.500000000 float
    [90]    -3.54020095 float
    [91]    -4.50000000 float
    [92]    0.500000000 float
    [93]    -0.500000000    float
    [94]    -3.54020095 float
    [95]    -4.50000000 float
    [96]    -0.500000000    float
    [97]    -0.500000000    float
    [98]    -3.54020095 float
    [99]    -4.50000000 float
    [100]   0.500000000 float
    [101]   -0.500000000    float
    [102]   -3.54020095 float
    [103]   -4.50000000 float
    [104]   -0.500000000    float
    [105]   -0.500000000    float
    [106]   -4.55025101 float
    [107]   -5.50000000 float
    [108]   -0.500000000    float
    [109]   -0.500000000    float
    [110]   -4.55025101 float
    [111]   -5.50000000 float
    [112]   0.500000000 float
    [113]   -0.500000000    float
    [114]   -3.54020095 float
    [115]   -4.50000000 float
    [116]   0.500000000 float
    [117]   -0.500000000    float
    [118]   -4.55025101 float
    [119]   -5.50000000 float
    [120]   -0.500000000    float
    [121]   -0.500000000    float
    [122]   -4.55025101 float
    [123]   -5.50000000 float
    [124]   0.500000000 float
    [125]   -0.500000000    float
    [126]   -4.55025101 float
    [127]   -5.50000000 float

[0]是x,[1]是y,[2]是z,[3]是w,[4]是下一个顶点&x; s等等。 这些值出了什么问题,因为什么都没出现?

如果有帮助,当我在顶点着色器中手动除以w时,它会起作用。


编辑 更多细节是:


我的顶点着色器是

#version 410 core
uniform mat4 View, Model, Project;
in vec4 vPosition;
out vec4 position;

void main(){
    position=Project*Model*View*vPosition;
    gl_Position=position;
}

out vec4的位置正在被反馈。


我的片段着色器只是将任何碎片染成红色。


矩阵

模型

1,0,0,0
0,1,0,0
0,0,1,0
0,0,0,1

视图

1,0,0,0
0,1,0,0
0,0,1,5
0,0,0,1

投影

1,0,0,0
0,1,0,0
0,0,-1.01005030,1.00502515
0,0,-1,0

vPositions

const GLfloat cube_positions[] =
{
    -.5f, -.5f, -.5f, 1.0f,
    -.5f, -.5f, .5f, 1.0f,
    -.5f, .5f, -.5f, 1.0f,
    -.5f, .5f, .5f, 1.0f,
    .5f, -.5f, -.5f, 1.0f,
    .5f, -.5f, .5f, 1.0f,
    .5f, .5f, -.5f, 1.0f,
    .5f, .5f, .5f, 1.0f
};

由glDrawElements和Element Array Buffer

中的索引编制索引
const GLushort cube_indices[] =
{
    0, 1, 2, 3, 6, 7, 4, 5,
    0xFFFF,
    2, 6, 0, 4, 1, 5, 3, 7
};

和0xFFFF是重启索引

1 个答案:

答案 0 :(得分:1)

顶点着色器需要输出的值范围是[-1.0,1.0],表示视图体积内的坐标。此范围在除w之后。

看起来您的坐标在此范围内。例如,对于第一个顶点:

[0] -0.500000000    float
[1] -0.500000000    float
[2] -3.54020095 float
[3] -4.50000000 float

w应用除法符合xyz坐标:

0.11111
0.11111
0.78671

此顶点位于视图体积内,以及所有其他坐标。