When prefiltering an envmap, take envmap resolution as uniform

This commit is contained in:
Vsevolod Kremianskii 2021-05-07 16:53:16 +07:00
parent df7939de1a
commit 133949fe3e
3 changed files with 12 additions and 12 deletions

View file

@ -166,6 +166,7 @@ shared_ptr<Texture> PBRIBL::computePrefilterMap(const Texture *envmap) {
uniforms.combined.general.projection = g_captureProjection;
uniforms.combined.general.view = g_captureViews[face];
uniforms.combined.general.roughness = mip / static_cast<float>(kNumPrefilterMipMaps - 1);
uniforms.combined.general.envmapResolution = static_cast<float>(envmap->width());
Shaders::instance().activate(ShaderProgram::SimplePrefilter, uniforms);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View file

@ -92,6 +92,8 @@ struct ShaderGeneral {
float exposure { 1.0f };
float fogNear { 0.0f };
float fogFar { 0.0f };
float envmapResolution { 0.0f };
char padding[12];
};
struct ShaderMaterial {

View file

@ -81,6 +81,7 @@ struct General {
float exposure;
float fogNear;
float fogFar;
float envmapResolution;
};
struct Material {
@ -388,18 +389,14 @@ vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness) {
}
vec2 IntegrateBRDF(float NdotV, float roughness) {
vec3 V;
V.x = sqrt(1.0 - NdotV * NdotV);
V.y = 0.0;
V.z = NdotV;
const uint SAMPLE_COUNT = 1024u;
vec3 V = vec3(sqrt(1.0 - NdotV * NdotV), 0.0, NdotV);
vec3 N = vec3(0.0, 0.0, 1.0);
float A = 0.0;
float B = 0.0;
vec3 N = vec3(0.0, 0.0, 1.0);
const uint SAMPLE_COUNT = 1024u;
for(uint i = 0u; i < SAMPLE_COUNT; ++i) {
for (uint i = 0u; i < SAMPLE_COUNT; ++i) {
// generates a sample vector that's biased towards the
// preferred alignment direction (importance sampling).
vec2 Xi = Hammersley(i, SAMPLE_COUNT);
@ -410,8 +407,7 @@ vec2 IntegrateBRDF(float NdotV, float roughness) {
float NdotH = max(H.z, 0.0);
float VdotH = max(dot(V, H), 0.0);
if (NdotL > 0.0)
{
if (NdotL > 0.0) {
float G = GeometrySmith(N, V, L, roughness);
float G_Vis = (G * VdotH) / (NdotH * NdotV);
float Fc = pow(1.0 - VdotH, 5.0);
@ -422,6 +418,7 @@ vec2 IntegrateBRDF(float NdotV, float roughness) {
}
A /= float(SAMPLE_COUNT);
B /= float(SAMPLE_COUNT);
return vec2(A, B);
}
@ -1070,7 +1067,7 @@ void main() {
float HdotV = max(dot(H, V), 0.0);
float pdf = D * NdotH / (4.0 * HdotV) + 0.0001;
float resolution = 512.0; // resolution of source cubemap (per face)
float resolution = uGeneral.envmapResolution; // resolution of source cubemap (per face)
float saTexel = 4.0 * PI / (6.0 * resolution * resolution);
float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001);