Skip to content

Commit

Permalink
Pretty much done, just need to open up colour layers to the api
Browse files Browse the repository at this point in the history
  • Loading branch information
nitronoid committed May 9, 2018
1 parent ed60ab8 commit 58502e9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
13 changes: 13 additions & 0 deletions include/MaterialPBR.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ class MaterialPBR : public Material
);

std::array<QMatrix4x4, 6> m_captureViews;
std::array<QVector4D, 9> m_colours = {
{
{0.093f, 0.02f, 0.003f, 0.0f},
{0.036f, 0.008f, 0.001f, 0.0f},
{ 0.03f, 0.009f, 0.0f, 0.0f},
{ 0.08f, 0.002f, 0.0f, 0.0f},
{0.703f, 0.188f, 0.108f, 0.0f},
{0.707f, 0.090f, 0.021f, 0.0f},
{0.960f, 0.436f, 0.149f, 0.0f},
{0.843f, 0.326f, 0.176f, 0.0f},
{ 1.0f, 0.31f, 0.171f, 0.0f}
}
};
QMatrix4x4 m_captureProjection;

std::unique_ptr<QOpenGLTexture> m_sphereMap;
Expand Down
2 changes: 1 addition & 1 deletion include/TrackballCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class TrackballCamera : public Camera
//-----------------------------------------------------------------------------------------------------
/// @brief The current zoom of the camera.
//-----------------------------------------------------------------------------------------------------
float m_zoom = 2.5f;
float m_zoom = 7.5f;
//-----------------------------------------------------------------------------------------------------
/// @brief The current yaw of the camera.
//-----------------------------------------------------------------------------------------------------
Expand Down
18 changes: 4 additions & 14 deletions shaders/owl_noise_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 410 core
#version 430 core

layout(location=0) out vec4 FragColor;
in vec2 vs_texCoords;
Expand All @@ -7,6 +7,7 @@ const float k_scale = 5.0;

uniform float u_zDepth;
uniform vec3 u_offsetPos = vec3(1.0);
uniform vec4 u_cols[9];

#include "shaders/include/perlin_noise.h"
#include "shaders/include/owl_noise_funcs.h"
Expand All @@ -33,23 +34,12 @@ vec4 calcAlbedoDisp()
// wood chips
slicednoise(randP, 2.0, 0.04, 0.4)
);

vec3 cols[] = vec3[](
vec3(0.036, 0.008, 0.001),
vec3(0.03, 0.009, 0.0),
vec3(0.08, 0.002, 0.0),
vec3(0.703, 0.188, 0.108),
vec3(0.707, 0.090, 0.021),
vec3(0.960, 0.436, 0.149),
vec3(0.843, 0.326, 0.176),
vec3(1, 0.31, 0.171)
);

vec4 result = vec4(0.093, 0.02, 0.003, 0.0);
vec4 result = u_cols[0];

for (int i = 0; i < 8; ++i)
{
result.xyz = mix(result.xyz, cols[i], layers[i]);
result.xyz = mix(result.xyz, u_cols[i + 1].xyz, layers[i]);
result.w += layers[i];
}

Expand Down
14 changes: 10 additions & 4 deletions src/MaterialPBR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
void MaterialPBR::init()
{
auto shaderPtr = m_shaderLib->getShader(m_shaderName);

auto funcs = m_context->versionFunctions<QOpenGLFunctions_4_3_Core>();
QOpenGLVertexArrayObject vao;
// Create and bind our Vertex Array Object
vao.create();
Expand Down Expand Up @@ -62,8 +62,14 @@ void MaterialPBR::init()
vbo.setIndices(plane.getIndicesData());
}
initBrdfLUTMap(plane, vbo);

// Generate the albedo map
generate3DTexture(plane, vbo, m_albedoMap, 512, "shaderPrograms/owl_noise.json", QOpenGLTexture::RGBA16F);
generate3DTexture(plane, vbo, m_albedoMap, 512, "shaderPrograms/owl_noise.json", QOpenGLTexture::RGBA16F,
[&cols = m_colours](auto shader)
{
shader->setUniformValueArray("u_cols", cols.data(), static_cast<int>(cols.size()));
});

// Generate the normal map
generate3DTexture(plane, vbo, m_normalMap, 512, "shaderPrograms/owl_normal.json", QOpenGLTexture::RGB16F,
[&bumpMap = m_albedoMap](auto shader)
Expand All @@ -87,7 +93,7 @@ void MaterialPBR::init()
shaderPtr->setUniformValue("u_metallic", m_metallic);
shaderPtr->setUniformValue("u_baseSpec", m_baseSpec);
shaderPtr->setUniformValue("u_normalStrength", m_normalStrength);
m_context->versionFunctions<QOpenGLFunctions_4_3_Core>()->glUniformSubroutinesuiv(GL_TESS_EVALUATION_SHADER, 1, &m_tessType);
funcs->glUniformSubroutinesuiv(GL_TESS_EVALUATION_SHADER, 1, &m_tessType);
shaderPtr->setUniformValue("u_tessLevelInner", m_tessLevelInner);
shaderPtr->setUniformValue("u_tessLevelOuter", m_tessLevelOuter);

Expand All @@ -112,7 +118,7 @@ void MaterialPBR::update()
auto now = high_resolution_clock::now();
m_time += (duration_cast<milliseconds>(now - m_last).count() * !m_paused);
m_last = now;
const auto blend = std::fmod(m_time * 0.001f * m_morphTargetFPS, static_cast<float>(m_morphTargetCount));
const auto blend = std::fmod(m_time * 0.001f * m_morphTargetFPS, static_cast<float>(m_morphTargetCount - 1));
shaderPtr->setUniformValue("u_blend", blend);
auto eye = m_cam->getCameraEye();
shaderPtr->setUniformValue("u_camPos", QVector3D{eye.x, eye.y, eye.z});
Expand Down
2 changes: 1 addition & 1 deletion src/TrackballCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void TrackballCamera::mouseZoom(const glm::vec2 &_mousePos)
{
m_zoom += (_mousePos.y - m_lastPos.y) * 0.25f * m_sensitivity;
m_lastPos = _mousePos;
m_zoom = glm::clamp(m_zoom, 0.0f, 10.0f);
m_zoom = glm::clamp(m_zoom, 2.5f, 15.0f);
}

glm::vec3 TrackballCamera::getCameraEye() const noexcept
Expand Down

0 comments on commit 58502e9

Please sign in to comment.