使用显式位置进行结构统一时出现重复位置错误

时间:2019-06-18 08:04:11

标签: c# opengl glsl opentk

这是我的VS的一部分:

#version 450
#extension GL_ARB_explicit_uniform_location : enable
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_gpu_shader5 : enable


//Imports
#include "/common.glsl"
#include "/common_structs.glsl"

//Mesh Attributes
layout(location=0) in vec4 vPosition;
layout(location=1) in vec2 uvPosition0;
layout(location=2) in vec4 nPosition; //normals
layout(location=3) in vec4 tPosition; //tangents
layout(location=4) in vec4 bPosition; //bitangents
layout(location=5) in vec4 blendIndices;
layout(location=6) in vec4 blendWeights;

//Uniform Blocks
layout (std140) uniform Uniforms
{
    CommonPerFrameUniforms mpCommonPerFrame;
    CommonPerMeshUniforms mpCommonPerMesh;
};

//Outputs
out vec3 E;
out vec3 N;
out vec2 uv0;
out float l_distance;
out mat3 TBN;
out vec3 default_color;
out vec4 finalPos;
out vec4 finalNormal;

void main()
{...}

这是我FS的一部分:

#version 450
#extension GL_ARB_explicit_uniform_location : enable
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_texture_query_lod : enable
#extension GL_ARB_gpu_shader5 : enable

//Includes
#include "/common.glsl"
#include "/common_structs.glsl"

layout(location = 200) uniform MaterialUniforms  mpCustomPerMaterial;


//Uniform Blocks
layout (std140) uniform Uniforms
{
    CommonPerFrameUniforms mpCommonPerFrame;
    CommonPerMeshUniforms mpCommonPerMesh;
};


in vec3 E;
in vec3 N;
in vec2 uv0;
in float l_distance;
in mat3 TBN;
in vec3 default_color;
in vec4 finalPos;

//Deferred Shading outputs
out vec4 outcolors[3];

void main
{...}

#include语句实际上是预处理程序语句,我使用了这些预处理程序语句以将通用结构和功能包括到着色器中。其中之一是以下内容:

struct MaterialUniforms 
{
    bool matflags[64];

    sampler2DArray diffuseTex;
    sampler2DArray maskTex;
    sampler2DArray normalTex;

    vec4 ColourVec4;
    vec4 ParamsVec4;
};

所以问题是,如果我使用 layout(location = 200) uniform MaterialUniforms mpCustomPerMaterial;

然后我从链接器中收到以下错误:

Link info
---------
Error Duplicate location 201 for uniform mpCustomPerMaterial.diffuseTex
Error Duplicate location 202 for uniform mpCustomPerMaterial.maskTex
Error Duplicate location 203 for uniform mpCustomPerMaterial.normalTex
Error Duplicate location 204 for uniform mpCustomPerMaterial.gMaterialColourVec4
Error Duplicate location 205 for uniform mpCustomPerMaterial.gMaterialParamsVec4

当我从统一定义中删除layout(location=200)时,着色器将成功编译。我已经尝试过使用不同的位置值,但是我不明白为什么会这样。我使用的统一块是否有可能与结构统一冲突?

0 个答案:

没有答案