mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Final updates on PBR tutorials w/ updated code.
This commit is contained in:
@@ -15,7 +15,6 @@ uniform vec3 lightPositions[4];
|
||||
uniform vec3 lightColors[4];
|
||||
|
||||
uniform vec3 camPos;
|
||||
uniform float exposure;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <learnopengl/filesystem.h>
|
||||
#include <learnopengl/shader_m.h>
|
||||
#include <learnopengl/shader.h>
|
||||
#include <learnopengl/camera.h>
|
||||
#include <learnopengl/model.h>
|
||||
|
||||
@@ -127,7 +127,6 @@ int main()
|
||||
glm::mat4 view = camera.GetViewMatrix();
|
||||
shader.setMat4("view", view);
|
||||
shader.setVec3("camPos", camera.Position);
|
||||
shader.setFloat("exposure", 1.0f);
|
||||
|
||||
// render rows*column number of spheres with varying metallic/roughness values scaled by rows and columns respectively
|
||||
glm::mat4 model;
|
||||
|
||||
@@ -16,7 +16,6 @@ uniform vec3 lightPositions[4];
|
||||
uniform vec3 lightColors[4];
|
||||
|
||||
uniform vec3 camPos;
|
||||
uniform float exposure;
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <learnopengl/filesystem.h>
|
||||
#include <learnopengl/shader_m.h>
|
||||
#include <learnopengl/shader.h>
|
||||
#include <learnopengl/camera.h>
|
||||
#include <learnopengl/model.h>
|
||||
|
||||
@@ -132,7 +132,6 @@ int main()
|
||||
glm::mat4 view = camera.GetViewMatrix();
|
||||
shader.setMat4("view", view);
|
||||
shader.setVec3("camPos", camera.Position);
|
||||
shader.setFloat("exposure", 1.0f);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, albedo);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <learnopengl/filesystem.h>
|
||||
#include <learnopengl/shader_m.h>
|
||||
#include <learnopengl/shader.h>
|
||||
#include <learnopengl/camera.h>
|
||||
#include <learnopengl/model.h>
|
||||
|
||||
@@ -162,21 +162,21 @@ int main()
|
||||
glm::mat4 captureProjection = glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, 10.0f);
|
||||
glm::mat4 captureViews[] =
|
||||
{
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
|
||||
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))
|
||||
};
|
||||
|
||||
// pbr: convert HDR equirectangular environment map to cubemap equivalent
|
||||
// ----------------------------------------------------------------------
|
||||
equirectangularToCubemapShader.use();
|
||||
equirectangularToCubemapShader.setInt("equirectangularMap", 0);
|
||||
equirectangularToCubemapShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, hdrTexture);
|
||||
equirectangularToCubemapShader.setMat4("projection", captureProjection);
|
||||
|
||||
glViewport(0, 0, 512, 512); // don't forget to configure the viewport to the capture dimensions.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <learnopengl/filesystem.h>
|
||||
#include <learnopengl/shader_m.h>
|
||||
#include <learnopengl/shader.h>
|
||||
#include <learnopengl/camera.h>
|
||||
#include <learnopengl/model.h>
|
||||
|
||||
@@ -176,9 +176,9 @@ int main()
|
||||
// ----------------------------------------------------------------------
|
||||
equirectangularToCubemapShader.use();
|
||||
equirectangularToCubemapShader.setInt("equirectangularMap", 0);
|
||||
equirectangularToCubemapShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, hdrTexture);
|
||||
equirectangularToCubemapShader.setMat4("projection", captureProjection);
|
||||
|
||||
glViewport(0, 0, 512, 512); // don't forget to configure the viewport to the capture dimensions.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
@@ -199,7 +199,7 @@ int main()
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, irradianceMap);
|
||||
for (unsigned int i = 0; i < 6; ++i)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB32F, 32, 32, 0, GL_RGB, GL_FLOAT, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, 32, 32, 0, GL_RGB, GL_FLOAT, nullptr);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
@@ -215,9 +215,9 @@ int main()
|
||||
// -----------------------------------------------------------------------------
|
||||
irradianceShader.use();
|
||||
irradianceShader.setInt("environmentMap", 0);
|
||||
irradianceShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, envCubemap);
|
||||
irradianceShader.setMat4("projection", captureProjection);
|
||||
|
||||
glViewport(0, 0, 32, 32); // don't forget to configure the viewport to the capture dimensions.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <learnopengl/filesystem.h>
|
||||
#include <learnopengl/shader_m.h>
|
||||
#include <learnopengl/shader.h>
|
||||
#include <learnopengl/camera.h>
|
||||
#include <learnopengl/model.h>
|
||||
|
||||
@@ -183,9 +183,9 @@ int main()
|
||||
// ----------------------------------------------------------------------
|
||||
equirectangularToCubemapShader.use();
|
||||
equirectangularToCubemapShader.setInt("equirectangularMap", 0);
|
||||
equirectangularToCubemapShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, hdrTexture);
|
||||
equirectangularToCubemapShader.setMat4("projection", captureProjection);
|
||||
|
||||
glViewport(0, 0, 512, 512); // don't forget to configure the viewport to the capture dimensions.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
@@ -210,7 +210,7 @@ int main()
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, irradianceMap);
|
||||
for (unsigned int i = 0; i < 6; ++i)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB32F, 32, 32, 0, GL_RGB, GL_FLOAT, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, 32, 32, 0, GL_RGB, GL_FLOAT, nullptr);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
@@ -226,9 +226,9 @@ int main()
|
||||
// -----------------------------------------------------------------------------
|
||||
irradianceShader.use();
|
||||
irradianceShader.setInt("environmentMap", 0);
|
||||
irradianceShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, envCubemap);
|
||||
irradianceShader.setMat4("projection", captureProjection);
|
||||
|
||||
glViewport(0, 0, 32, 32); // don't forget to configure the viewport to the capture dimensions.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
@@ -263,16 +263,16 @@ int main()
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
prefilterShader.use();
|
||||
prefilterShader.setInt("environmentMap", 0);
|
||||
prefilterShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, envCubemap);
|
||||
prefilterShader.setMat4("projection", captureProjection);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
unsigned int maxMipLevels = 5;
|
||||
for (unsigned int mip = 0; mip < maxMipLevels; ++mip)
|
||||
{
|
||||
// reisze framebuffer according to mip-level size.
|
||||
unsigned int mipWidth = 128 * std::pow(0.5, mip);
|
||||
unsigned int mipWidth = 128 * std::pow(0.5, mip);
|
||||
unsigned int mipHeight = 128 * std::pow(0.5, mip);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, captureRBO);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mipWidth, mipHeight);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <learnopengl/filesystem.h>
|
||||
#include <learnopengl/shader_m.h>
|
||||
#include <learnopengl/shader.h>
|
||||
#include <learnopengl/camera.h>
|
||||
#include <learnopengl/model.h>
|
||||
|
||||
@@ -223,9 +223,9 @@ int main()
|
||||
// ----------------------------------------------------------------------
|
||||
equirectangularToCubemapShader.use();
|
||||
equirectangularToCubemapShader.setInt("equirectangularMap", 0);
|
||||
equirectangularToCubemapShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, hdrTexture);
|
||||
equirectangularToCubemapShader.setMat4("projection", captureProjection);
|
||||
|
||||
glViewport(0, 0, 512, 512); // don't forget to configure the viewport to the capture dimensions.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
@@ -250,7 +250,7 @@ int main()
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, irradianceMap);
|
||||
for (unsigned int i = 0; i < 6; ++i)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB32F, 32, 32, 0, GL_RGB, GL_FLOAT, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, 32, 32, 0, GL_RGB, GL_FLOAT, nullptr);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
@@ -266,9 +266,9 @@ int main()
|
||||
// -----------------------------------------------------------------------------
|
||||
irradianceShader.use();
|
||||
irradianceShader.setInt("environmentMap", 0);
|
||||
irradianceShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, envCubemap);
|
||||
irradianceShader.setMat4("projection", captureProjection);
|
||||
|
||||
glViewport(0, 0, 32, 32); // don't forget to configure the viewport to the capture dimensions.
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
@@ -303,9 +303,9 @@ int main()
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
prefilterShader.use();
|
||||
prefilterShader.setInt("environmentMap", 0);
|
||||
prefilterShader.setMat4("projection", captureProjection);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, envCubemap);
|
||||
prefilterShader.setMat4("projection", captureProjection);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
|
||||
unsigned int maxMipLevels = 5;
|
||||
|
||||
Reference in New Issue
Block a user