为什么将值从顶点着色器输入复制到顶点着色器(平面)输出会导致不同的值?

时间:2020-01-16 11:56:09

标签: opengl glsl shader

我正在渲染带纹理的四边形(在屏幕空间中),我想在顶点数据中指定纹理,将其作为平面输出发送到片段着色器,并用于选择纹理。在此过程中将更改该值。在RenderDoc中,VS输入为2,输出为1073741824(对于每个顶点)。有人知道为什么吗? (4.6核心上下文,着色器#version 460)。我正在每个Quad上载6个顶点,并使用glDrawArrays()。 Texture Stage 0可以工作,但是任何非零值都可以转换。

<input _ngcontent-bqk-c14="" class="inputSearch input-textstyle mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-pristine ng-invalid ng-touched" formcontrolname="description" matinput="" type="text" ng-reflect-autocomplete="[object Object]" ng-reflect-name="description" ng-reflect-placeholder="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Buscar" ng-reflect-type="text" autocomplete="off" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-haspopup="true" id="mat-input-1" placeholder="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Buscar" aria-invalid="true" aria-required="false">
layout(location=0) in vec3 coord3d;
layout(location=1) in vec2 uvIn;
layout(location=2) in vec3 colorIn;
layout(location=3) in unsigned int textureStageIn;

out vec4 color;
out vec2 uv;
flat out unsigned int textureStage;

void main(void)
{
    gl_Position = vec4( coord3d, 1.0 );
    color = vec4(colorIn,1.0); 
    uv = uvIn;
    textureStage = textureStageIn;
}

1 个答案:

答案 0 :(得分:2)

您必须使用glVertexAttribIPointer(专注于I)来指定整数属性。与glVertexAttribPointer相比,它具有浮点属性。参见glVertexAttribPointer

请注意,此函数的 type 参数仅指定源数据的类型,但没有说明属性的类型。对于每种属性基本类型(浮点数,整数,64位双精度浮点数),都有一个不同的函数。