Skip to content

Commit

Permalink
Final tidy up and refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitronoid committed May 10, 2018
1 parent 9a4fd4e commit 27c6671
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 781 deletions.
11 changes: 1 addition & 10 deletions Criminowl.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@ HEADERS += \
include/MaterialPBR.h \
include/Scene.h \
include/DemoScene.h \
include/MaterialPhong.h \
include/ShaderLib.h \
include/MeshVBO.h \
include/MaterialWireframe.h \
include/MaterialFractal.h \
include/MaterialEnvMap.h \
include/MaterialBump.h \
include/TriMesh.h \
include/Edge.h

Expand All @@ -58,13 +53,8 @@ SOURCES += \
src/MaterialPBR.cpp \
src/Scene.cpp \
src/DemoScene.cpp \
src/MaterialPhong.cpp \
src/ShaderLib.cpp \
src/MeshVBO.cpp \
src/MaterialWireframe.cpp \
src/MaterialFractal.cpp \
src/MaterialEnvMap.cpp \
src/MaterialBump.cpp \
src/TriMesh.cpp

OTHER_FILES += \
Expand All @@ -74,6 +64,7 @@ OTHER_FILES += \

FORMS += ui/mainwindow.ui


linux:{
LIBS += -lGL -lGLU -lGLEW -lassimp
}
Expand Down
1 change: 0 additions & 1 deletion include/DemoScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "Scene.h"
#include "MaterialPBR.h"
#include "MaterialPhong.h"
#include "ShaderLib.h"


Expand Down
33 changes: 0 additions & 33 deletions include/MaterialBump.h

This file was deleted.

34 changes: 0 additions & 34 deletions include/MaterialEnvMap.h

This file was deleted.

34 changes: 0 additions & 34 deletions include/MaterialFractal.h

This file was deleted.

26 changes: 0 additions & 26 deletions include/MaterialPhong.h

This file was deleted.

26 changes: 0 additions & 26 deletions include/MaterialWireframe.h

This file was deleted.

133 changes: 45 additions & 88 deletions shaders/hdr_cubemap_brdf_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,114 +1,71 @@
#version 410 core

layout(location=0) out vec2 FragColor;
layout(location=0) out vec2 fragColor;
in vec2 vs_texCoords;

const float k_PI = 3.14159265359;
#include "shaders/include/pbr_funcs.h"

// ----------------------------------------------------------------------------
// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
// efficient VanDerCorpus calculation.
float RadicalInverse_VdC(uint bits)
{
bits = (bits << 16u) | (bits >> 16u);
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}
// ----------------------------------------------------------------------------
vec2 Hammersley(uint i, uint N)
{
return vec2(float(i)/float(N), RadicalInverse_VdC(i));
}
// ----------------------------------------------------------------------------
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
float brdfSchlickGGX(float n_dot_v, float roughness)
{
float a = roughness*roughness;

float phi = 2.0 * k_PI * Xi.x;
float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y));
float sinTheta = sqrt(1.0 - cosTheta*cosTheta);

// from spherical coordinates to cartesian coordinates - halfway vector
vec3 H;
H.x = cos(phi) * sinTheta;
H.y = sin(phi) * sinTheta;
H.z = cosTheta;

// from tangent-space H vector to world-space sample vector
vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 tangent = normalize(cross(up, N));
vec3 bitangent = cross(N, tangent);

vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
return normalize(sampleVec);
// note that we use a different k for IBL
float k = (roughness * roughness) * 0.5;
return n_dot_v / (n_dot_v * (1.0 - k) + k);
}
// ----------------------------------------------------------------------------
float GeometrySchlickGGX(float NdotV, float roughness)
float brdfGeometrySmith(vec3 n, vec3 v, vec3 l, float roughness)
{
// note that we use a different k for IBL
float a = roughness;
float k = (a * a) / 2.0;
float n_dot_v = max(dot(n, v), 0.0);
float n_dot_l = max(dot(n, l), 0.0);
float ggx2 = brdfSchlickGGX(n_dot_v, roughness);
float ggx1 = brdfSchlickGGX(n_dot_l, roughness);

float nom = NdotV;
float denom = NdotV * (1.0 - k) + k;

return nom / denom;
return ggx1 * ggx2;
}
// ----------------------------------------------------------------------------
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
{
float NdotV = max(dot(N, V), 0.0);
float NdotL = max(dot(N, L), 0.0);
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
float ggx1 = GeometrySchlickGGX(NdotL, roughness);

return ggx1 * ggx2;
}
// ----------------------------------------------------------------------------
vec2 IntegrateBRDF(float NdotV, float roughness)
vec2 integrateBRDF(float n_dot_v, float roughness)
{
vec3 V;
V.x = sqrt(1.0 - NdotV*NdotV);
V.y = 0.0;
V.z = NdotV;
vec3 v;
v.x = sqrt(1.0 - n_dot_v*n_dot_v);
v.y = 0.0;
v.z = n_dot_v;

float A = 0.0;
float B = 0.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)
{
// generates a sample vector that's biased towards the
// preferred alignment direction (importance sampling).
vec2 Xi = Hammersley(i, SAMPLE_COUNT);
vec3 H = ImportanceSampleGGX(Xi, N, roughness);
vec3 L = normalize(2.0 * dot(V, H) * H - V);
vec3 n = vec3(0.0, 0.0, 1.0);

const uint k_sample_count = 1024u;
for(uint i = 0u; i < k_sample_count; ++i)
{
// generates a sample vector that's biased towards the
// preferred alignment direction (importance sampling).
vec3 h, l;
generateImportanceSample(i, k_sample_count, roughness, n, v, h, l);

float NdotL = max(L.z, 0.0);
float NdotH = max(H.z, 0.0);
float VdotH = max(dot(V, H), 0.0);
float n_dot_l = max(l.z, 0.0);
float n_dot_h = max(h.z, 0.0);
float v_dot_h = max(dot(v, h), 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);
if(n_dot_l > 0.0)
{
float g = brdfGeometrySmith(n, v, l, roughness);
float g_vis = (g * v_dot_h) / (n_dot_h * n_dot_v);
float fc = pow(1.0 - v_dot_h, 5.0);

A += (1.0 - Fc) * G_Vis;
B += Fc * G_Vis;
}
a += (1.0 - fc) * g_vis;
b += fc * g_vis;
}
A /= float(SAMPLE_COUNT);
B /= float(SAMPLE_COUNT);
return vec2(A, B);
}
a /= float(k_sample_count);
b /= float(k_sample_count);
return vec2(a, b);
}
// ----------------------------------------------------------------------------
void main()
{
vec2 integratedBRDF = IntegrateBRDF(vs_texCoords.x, vs_texCoords.y);
FragColor = integratedBRDF;
vec2 integratedBRDF = integrateBRDF(vs_texCoords.x, vs_texCoords.y);
fragColor = integratedBRDF;
}
Loading

0 comments on commit 27c6671

Please sign in to comment.