Compare commits

...

2 Commits
master ... ssao

Author SHA1 Message Date
87a7e2919f poprawa geometrypass 2023-02-12 12:28:21 +01:00
01bae3ab44 g-buffer i geometry pass 2023-02-11 20:41:41 +01:00
8 changed files with 112 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -43,6 +43,10 @@
<None Include="shaders\shader_8_sun.vert" />
<None Include="shaders\shader_blur.frag" />
<None Include="shaders\shader_blur.vert" />
<None Include="shaders\shader_gbuffer.frag" />
<None Include="shaders\shader_gbuffer.vert" />
<None Include="shaders\shader_geometrypass.frag" />
<None Include="shaders\shader_geometrypass.vert" />
<None Include="shaders\shader_shadowmapsun.frag" />
<None Include="shaders\shader_shadowmapsun.vert" />
<None Include="shaders\shader_skybox.frag" />

View File

@ -127,5 +127,9 @@
<None Include="shaders\shader_blur.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_gbuffer.frag" />
<None Include="shaders\shader_gbuffer.vert" />
<None Include="shaders\shader_geometrypass.vert" />
<None Include="shaders\shader_geometrypass.frag" />
</ItemGroup>
</Project>

View File

@ -11,4 +11,4 @@ void main()
{
gl_Position = vec4(vertexPosition, 1.0);
TexCoords = vertexTexCoord;
}
}

View File

@ -0,0 +1,18 @@
#version 430
layout (location = 0) out vec3 gPosition;
layout (location = 1) out vec3 gNormal;
layout (location = 2) out vec3 gAlbedo;
in vec2 TexCoords;
in vec3 FragPos;
in vec3 Normal;
void main()
{
// store the fragment position vector in the first gbuffer texture
gPosition = FragPos;
// also store the per-fragment normals into the gbuffer
gNormal = normalize(Normal);
// and the diffuse per-fragment color
gAlbedo.rgb = vec3(0.95);
}

View File

@ -0,0 +1,28 @@
#version 430 core
layout (location = 0) out vec3 vertexPosition;
layout (location = 1) out vec3 vertexNormal;
layout (location = 2) in vec2 vertexTexCoords;
out vec3 FragPos;
out vec2 TexCoords;
out vec3 Normal;
uniform bool invertedNormals;
uniform mat4 modelMatrix;
uniform mat3 transformation;
uniform mat4 view;
uniform mat4 projection;
void main()
{
vec4 viewPos = transformation * vec4(vertexPosition, 1.0);
FragPos = viewPos.xyz;
TexCoord = vertexTexCoords;
mat3 normalMatrix = transpose(inverse(mat3( * model)));
Normal = normalMatrix * (invertedNormals ? -aNormal : aNormal);
gl_Position = viewPos;
}

View File

@ -78,6 +78,8 @@ std::vector<std::string> faces =
GLuint depthMapFBO;
GLuint depthMap;
GLuint gBuffer;
GLuint depthMapShipFBO;
GLuint depthMapShip;
@ -90,6 +92,7 @@ GLuint programTex;
GLuint programDepth;
GLuint programSkybox;
GLuint programBlur;
GLuint programGeometryPass;
Core::Shader_Loader shaderLoader;
@ -110,6 +113,8 @@ unsigned int colorBuffers[2];
unsigned int pingpongFBO[2];
unsigned int pingpongBuffer[2];
unsigned int gPosition, gNormal, gAlbedo;
GLuint VAO,VBO;
float aspectRatio = 1.f;
@ -248,6 +253,9 @@ void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
geometryPass(modelMatrix);
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glUniform1i(glGetUniformLocation(program, "depthMap"), 0);
glBindTexture(GL_TEXTURE_2D, depthMap);
@ -260,6 +268,7 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
@ -396,6 +405,51 @@ void renderShadowapSun(GLuint depthFBO, glm::mat4 light) {
glViewport(0, 0, WIDTH, HEIGHT);
}
void initgBuffer()
{
glGenFramebuffers(1, &gBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
// position color buffer
glGenTextures(1, &gPosition);
glBindTexture(GL_TEXTURE_2D, gPosition);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, WIDTH, HEIGHT, 0, GL_RGB, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// normal color buffer
glGenTextures(1, &gNormal);
glBindTexture(GL_TEXTURE_2D, gNormal);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, WIDTH, HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, gNormal, 0);
// color + specular color buffer
glGenTextures(1, &gAlbedo);
glBindTexture(GL_TEXTURE_2D, gAlbedo);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, gAlbedo, 0);
unsigned int attachments[3] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, attachments);
}
void geometryPass(glm::mat4 modelMatrix)
{
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programGeometryPass);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programGeometryPass, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programGeometryPass, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform1i(glGetUniformLocation(programGeometryPass, "invertedNormals"), 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void initDepthMap()
{
glGenFramebuffers(1, &depthMapFBO);
@ -640,6 +694,7 @@ void init(GLFWwindow* window)
glEnable(GL_DEPTH_TEST);
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
programGeometryPass = shaderLoader.CreateProgram("shaders/shader_geometrypass.vert", "shaders/shader_geometrypass.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
programDepth = shaderLoader.CreateProgram("shaders/shader_shadowmapsun.vert", "shaders/shader_shadowmapsun.frag");
@ -687,6 +742,8 @@ void init(GLFWwindow* window)
loadModelToContext("./models/car/car.obj", models::carContext);
loadModelToContext("./models/ceramic_vase_02_4k.obj", models::vaseContext);
initgBuffer();
initDepthMap();
initDepthMapShip();