OpenGL GLSL:Intel与NVIDIA

时间:2019-02-09 16:08:55

标签: opengl graphics glsl shader nvidia

我的笔记本电脑有一个集成显卡( Intel HD Graphics 620 )和一个专用显卡( NVIDIA GeForce 940MX )。

我有一个程序对象,该对象包含三个着色器(即顶点着色器,几何着色器和片段着色器),它们可以在Intel芯片上正常工作,但是当我尝试在NVIDIA卡上运行该程序时,在链接步骤

ProgramInfoLog : "frag.albedo" not declared as an output from the previous stage

这是三个着色器的代码。

顶点着色器

#version 450 core

layout (location = 0) in vec3 center;
layout (location = 1) in float radius;
layout (location = 2) in vec3 albedo;
layout (location = 3) in vec2 number;

out VertData
{
  vec3 center;
  float radius;
  vec3 albedo;
  vec2 number;
  vec3 colour;
} vert;

void main()
{
  float AtomNumber = number[0];
  uvec3 mask = uvec3(0x00FF0000, 0x0000FF00, 0x000000FF);
  uvec3 shift = uvec3(16, 8, 0);

  vec3 colour = ((uvec3(AtomNumber) & mask) >> shift) / 255.0f;

  vert.center = center;
  vert.radius = radius;
  vert.albedo = albedo;
  vert.number = number;
  vert.colour = colour;
}

几何着色器

#version 450 core

layout (points) in;
layout (triangle_strip, max_vertices = 4) out;

in VertData
{
  vec3 center;
  float radius;
  vec3 albedo;
  vec2 number;
  vec3 colour;
} vert[];

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

out FragData
{
  flat vec3 center;
  flat float radius;
  flat vec3 albedo;
  flat vec2 number;
  flat vec3 colour;
  smooth vec2 offset;
} frag;

void main()
{
  vec2 offsets[4];
  offsets[0] = vec2(-1.0f, -1.0f);
  offsets[1] = vec2(-1.0f, +1.0f);
  offsets[2] = vec2(+1.0f, -1.0f);
  offsets[3] = vec2(+1.0f, +1.0f);

  float BoxCorrection = 1.5f;

  for (int i = 0; i < 4; i++)
  {
    gl_Position = view * model * vec4(vert[0].center, 1.0f);

    frag.center = vec3(gl_Position);
    frag.radius = vert[0].radius;
    frag.albedo = vert[0].albedo;
    frag.number = vert[0].number;
    frag.colour = vert[0].colour;
    frag.offset = offsets[i] * BoxCorrection;

    gl_Position.xy += (frag.offset * frag.radius);
    gl_Position = projection * gl_Position;

    EmitVertex();
  }

  EndPrimitive();
}

片段着色器

#version 450

layout (location = 0) out vec3 center;
layout (location = 1) out vec3 normal;
layout (location = 2) out vec3 albedo;
layout (location = 3) out vec3 colour;

struct ImpostorData
{
  vec3 center;
  vec3 normal;
};

void SetImpostorData(out ImpostorData impostor);

in FragData
{
  flat vec3 center;
  flat float radius;
  flat vec3 albedo;
  flat vec2 number;
  flat vec3 colour;
  smooth vec2 offset;
} frag;

uniform mat4 projection;

void main()
{
  ImpostorData impostor;
  SetImpostorData(impostor);

  vec4 clip = projection * vec4(impostor.center, 1.0f);
  float depth = clip.z / clip.w;
  gl_FragDepth = ((gl_DepthRange.diff * depth) + gl_DepthRange.near + gl_DepthRange.far) * 0.5f;

  center = impostor.center;
  normal = impostor.normal;
  albedo = frag.albedo;
  colour = frag.colour;
}

void SetImpostorData(out ImpostorData impostor)
{
  // ...
}

如您所见,着色器之间的接口块可以放在一起。

我想知道NVIDIA卡是否需要所有着色器阶段,然后是否需要在顶点和几何着色器之间添加镶嵌细分着色器。

我试图以这种方式在使用frag.albedo的片段着色器中更改代码行:

// albedo = frag.albedo;
albedo = vec3(1.0f, 1.0f, 0.0f);

,现在错误消息已移至frag.center,该错误消息已在SetImpostorData()中使用:

ProgramInfoLog : "frag.center" not declared as an output from the previous stage

所以我认为几何图形和片段着色器之间有问题。

谢谢!

0 个答案:

没有答案