Что бы я ни пробовал, все мои вызовы отрисовки для этого фреймбуфера не записывают фрагментов. p>
(Обратите внимание, что я рисую как в G-буфере, так и непосредственно в фреймбуфере по умолчанию в других частях программы, и у меня вообще нет таких проблем)

Nsight Framecapture показывает, что для каждого из этих вызовов отрисовки не записывается ни один фрагмент.
Обратите внимание, что эти фрагменты не проходят тесты глубины/трафарета (как сказал бы Nsight, если бы они были).(Я думаю, что все они выходят за пределы усеченного поля зрения?)
Однако ситуация становится еще страннее.
Если я использую в процессе рендеринга совершенно неинициализированную шейдерную программу, то отрисовываются фрагменты! Естественно, к ним не применены правильные матричные проекции и т. д. Тем не менее, для меня это было шоком.

(Я предполагал, что OpenGL возвращается к ранее подключенной программе шейдеров и использует ее. Однако, если я явно использую любую из этих предыдущих программ шейдеров для рисования в этом фреймбуфере, я не получу результаты те же, а фрагменты по-прежнему не записываются.)
В любом случае, мне просто очень хочется, чтобы мои собственные шейдеры корректно записывали фрагменты в кубическую карту буфера глубины.
========
Это все для того, чтобы внедрить точечное освещение в мой проект.
Для этого , я использую текстуру кубической карты (глубина_компонента).
Код: Выделить всё
glGenTextures(1, &Shadow_Cubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, Shadow_Cubemap);
for (size_t W = 0; W < 6; W++)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + W, 0u, GL_DEPTH_COMPONENT32F,
Shadow_Mapper::Shadow_Map_Width, Shadow_Mapper::Shadow_Map_Height, 0u,
GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, Shadow_Cubemap, 0u); // This is likely redundant as I later use the glFramebufferTexture2D() function to attach specific faces to the framebuffer. Note that removing or modifying this line yielded no fix
Код: Выделить всё
void Render_All_Shadows()
{
Bind_Shadow_Frame_Buffer(); // See below for elaboration
Shadow_Object_Shader.Activate(); // This function just uses the shader program
for (size_t Face = 0; Face < 6; Face++)
{
glUniformMatrix4fv(glGetUniformLocation(Shadow_Object_Shader.Program_ID, "Shadow_Matrix"), 1, GL_FALSE, &View_Matrices[Face][0][0]); // This gives the desired view/projection matrix to the shader
glBindTexture(GL_TEXTURE_CUBE_MAP, Shadow_Cubemap);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + Face, Shadow_Cubemap, 0u); // This sets the desired face of the cubemap to be the framebuffer's depth attachment.
glClear(GL_DEPTH_BUFFER_BIT); // For shadow mapping, we only care about the depth buffer. This call just clears the depth buffer of the currently selected face
for (size_t W = 0; W < Scene_Models.size(); W++)
Render_Object_To_Shadow_Map(Scene_Models[W]); // This function just binds vertex/uniform buffers and then makes the draw call. Nothing crazy
}
Unbind_Shadow_Frame_Buffer(); // See below for elaboration
}
Код: Выделить всё
// (Initialisation function)
glGenFramebuffers(1, &Shadow_Frame_Buffer);
glBindFramebuffer(GL_FRAMEBUFFER, Shadow_Frame_Buffer);
Shadow_Object_Shader.Create_Shader("Shader_Code/Shadow_Test_2.vert", "Shader_Code/Shadow_Test_2.frag", nullptr); // This is the line that I commented out to make sure the shader isn't initialised. With this line here, no fragments are written. However, when this line is removed, the fragments are written (albeit incorrectly).
Shadow_Projection_Matrix = glm::perspective(glm::radians(90.0f), 1.0f, 0.01f, 25.0f);
// Later in the program, I initialise the view-matrices like so:
View_Matrices[0] = Shadow_Mapper::Shadow_Projection_Matrix * glm::lookAt(Position, Position + glm::vec3( 1.f, 0.f, 0.f), glm::vec3( 0.f,-1.f, 0.f));
View_Matrices[1] = Shadow_Mapper::Shadow_Projection_Matrix * glm::lookAt(Position, Position + glm::vec3(-1.f, 0.f, 0.f), glm::vec3( 0.f,-1.f, 0.f));
View_Matrices[2] = Shadow_Mapper::Shadow_Projection_Matrix * glm::lookAt(Position, Position + glm::vec3( 0.f, 1.f, 0.f), glm::vec3( 0.f, 0.f, 1.f));
View_Matrices[3] = Shadow_Mapper::Shadow_Projection_Matrix * glm::lookAt(Position, Position + glm::vec3( 0.f,-1.f, 0.f), glm::vec3( 0.f, 0.f,-1.f));
View_Matrices[4] = Shadow_Mapper::Shadow_Projection_Matrix * glm::lookAt(Position, Position + glm::vec3( 0.f, 0.f, 1.f), glm::vec3( 0.f,-1.f, 0.f));
View_Matrices[5] = Shadow_Mapper::Shadow_Projection_Matrix * glm::lookAt(Position, Position + glm::vec3( 0.f, 0.f,-1.f), glm::vec3( 0.f,-1.f, 0.f));
// Note that "Position" is just the position of the point-light. In both the debugger and in Nsight, these matrices seem to be okay
// However, there may be problems with it that I don't see
// And here are the bind/unbind shadow framebuffer functions:
void Bind_Shadow_Frame_Buffer()
{
glViewport(0, 0, Shadow_Map_Width, Shadow_Map_Height);
glBindFramebuffer(GL_FRAMEBUFFER, Shadow_Frame_Buffer);
glDisable(GL_CULL_FACE); // This is just to ensure that the lack of fragments isn't due to back-face culling
}
void Unbind_Shadow_Frame_Buffer()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0u);
glViewport(0, 0, Window_Width, Window_Height);
glEnable(GL_CULL_FACE); // Returns to normal after rendering to shadow-map
}
Код: Выделить всё
#version 440
layout(location = 0) in vec3 In_Position;
layout(location = 1) in vec3 In_Normal;
layout(location = 2) in vec2 In_UV;
uniform mat4 Model_Matrix;
uniform mat4 Shadow_Matrix;
void main()
{
// gl_Position = vec4(In_Position, 0.0f); //
gl_Position = Shadow_Matrix * Model_Matrix * vec4(In_Position, 0.0f);
}
Код: Выделить всё
#version 440
void main()
{
// gl_FragColor = vec4(0, 0, 0, 0);
// gl_FragDepth = gl_FragCoord.z;
}
// Note that I've tried with/without explicit writes to gl_FragDepth and I've experimented with writing values like 0.0f straight to gl_FragDepth among other things.
// I've also tried creating and attaching a colour buffer to see if I could write to that with this shader but, as previously, no fragments were written.
Подробнее здесь: https://stackoverflow.com/questions/786 ... er-is-comp