簡體   English   中英

GLSL 幾何着色器在 RenderDoc 中導致“繪制時沒有綁定頂點着色器”

[英]GLSL Geometry Shader causes "No vertex shader bound at draw" in RenderDoc

我試圖讓一個基本的幾何着色器工作,但我完全失敗了。 在檢查了無數資源后,我仍然找不到解決問題的辦法。

這是我的頂點、幾何和片段着色器的代碼。

頂點着色器:

#version 330 core

// Vertex Shader Inputs
layout (location = 0) in vec3 Pos;
layout (location = 1) in vec3 Norm;
layout (location = 2) in vec3 Color;

// Vertex to Fragment Shader Outputs
out DATA {
    vec3 vsPos;
    vec3 vsNorm;
    vec4 vsColor;
} data_out;

// Main.cpp Imports
uniform mat4 camMatrix; // viewProjection Matrix
uniform mat4 model;

void main()
{
    vec3 vsPos   = vec3(model * vec4(Pos, 1.0f));
    vec3 vsNorm  = mat3(transpose(inverse(model))) * Norm; // Normal vector correction
    vec4 vsColor = vec4(Color, 1.0f);

    gl_Position = camMatrix * vec4(vsPos, 1.0f);
}

幾何着色器:

#version 330 core

layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;

out vec3 gsPos;
out vec3 gsNorm;
out vec3 gsColor;

in DATA {
    vec3 vsPos;
    vec3 vsNorm;
    vec4 vsColor;
} data_in[];

uniform mat4 camMatrix;

void main()
{
    for (int i=0; i<3; i++)
    {   
            gsPos = data_in[i].vsPos;
            gsNorm = data_in[i].vsNorm;
            gsColor = data_in[i].vsColor;
        gl_Position = camMatrix * vec4(data_in[i].vsPos, 1.0f);
        EmitVertex();
    }
    EndPrimitive();
}

片段着色器:

#version 330 core

out vec4 FragColor;

// Fragment Shader Inputs
in vec3 gsPos;
in vec3 gsNorm;
in vec4 gsColor;

// Fragment Shader Uniforms
uniform sampler2D diffuse0;
uniform sampler2D specular0;

uniform vec4 lightColor;
uniform vec3 lightPos;

uniform vec3 camPos;

vec4 pointLight()
{   
    vec3 lightVec = (lightPos - vsPos);

// intensity of light with respect to distance
    float dist  = length(lightVec);
    float a     = 0.7;
    float b     = 0.4;
    float c     = 1.0;
    float inten = 1.0f / (a * dist * dist + b * dist + c);

// ambient lighting
    float ambient = 0.75f;

// diffuse lighting
    vec3  fsNorm         =  normalize(gsNorm);
    vec3  lightDirection =  normalize(lightVec);
    float diffuse        =  max(dot(fsNorm, lightDirection), 0.0f);

// specular lighting
    float specular = 0.0f;
    if (diffuse != 0.0f)
    {
        float specularLight  =  0.50f;
        vec3  viewDirection  =  normalize(gsNorm - gsPos);
        vec3  halfwayVec     =  normalize(viewDirection + lightDirection);
        float specAmount     =  pow(max(dot(fsNorm, halfwayVec), 0.0f), 32);
        
        specular = specAmount * specularLight;
    };

    return inten * (gsColor * (diffuse + ambient) + gsColor * specular) * lightColor;
}

void main()
{// outputs final color
    FragColor = pointLight();
}

我的網格生成函數:

void genMesh()
    {
        VAO.Bind();
        VBO VBO(vtx);
        EBO EBO(idx);
        VAO.LinkAttrib(VBO, 0, 3, GL_FLOAT, sizeof(Vertex), (void*)0);
        VAO.LinkAttrib(VBO, 1, 3, GL_FLOAT, sizeof(Vertex), (void*)(3 * sizeof(float)));
        VAO.LinkAttrib(VBO, 2, 4, GL_FLOAT, sizeof(Vertex), (void*)(6 * sizeof(float)));

        VAO.Unbind();
        VBO.Unbind();
        EBO.Unbind();
    };

我的網格繪制功能:

void Mesh::Draw(Shader& shader, Camera& camera)
{
    shader.Activate();
    VAO.Bind();

    // Take care of the camera Matrix
    glUniform3f(glGetUniformLocation(shader.ID, "camPos"),
        camera.Position.x,
        camera.Position.y,
        camera.Position.z);
    camera.Matrix(shader, "camMatrix");

    // Draw the actual mesh
    glDrawElements(GL_TRIANGLES, idx.size() * sizeof(GLuint), GL_UNSIGNED_INT, 0);
};

我在主 while 循環之外調用網格生成函數,然后在主 while 循環中繪制網格。

通過 RenderDoc 調試我的程序會出現錯誤,“繪制時沒有綁定頂點着色器”,沒有幾何着色器(保持其他一切大致相同)。 我在 RenderDoc 中沒有收到任何錯誤,我嘗試更新我的圖形驅動程序。 但我只是得到同樣的錯誤,請幫助我。 我覺得我快瘋了。

在片段着色器中,gsColor 在 vec4 變量中定義,但在幾何着色器中,它被聲明為 vec3 變量

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM