Browse Source

Initial PBR attempt

master
C. J. Howard 7 years ago
parent
commit
ddede4538d
6 changed files with 46 additions and 52 deletions
  1. +1
    -1
      data
  2. +1
    -1
      src/debug.cpp
  3. +14
    -30
      src/material-loader.cpp
  4. +10
    -16
      src/materials.hpp
  5. +19
    -3
      src/render-passes.cpp
  6. +1
    -1
      src/states/splash-state.cpp

+ 1
- 1
data

@ -1 +1 @@
Subproject commit 6fcdd9ea0fd3b66ee807c0f24f730a82734ec8fd
Subproject commit 3f2b504970e90fd476a682f4754d276bf162729c

+ 1
- 1
src/debug.cpp View File

@ -30,7 +30,7 @@ LineBatcher::LineBatcher(std::size_t lineCount):
range = batch.addRange();
range->material = &material;
material.color = Vector3(1.0f);
material.albedo = Vector3(1.0f);
}
void LineBatcher::begin()

+ 14
- 30
src/material-loader.cpp View File

@ -112,51 +112,35 @@ PhysicalMaterial* MaterialLoader::load(const std::string& filename)
arguments.push_back(argument);
}
if (command == "color" && arguments.size() == 3)
if (command == "albedo" && arguments.size() == 3)
{
std::stringstream(arguments[0]) >> material->color.x;
std::stringstream(arguments[1]) >> material->color.y;
std::stringstream(arguments[2]) >> material->color.z;
}
else if (command == "roughness" && arguments.size() == 1)
{
std::stringstream(arguments[0]) >> material->roughness;
}
else if (command == "metallic" && arguments.size() == 1)
{
std::stringstream(arguments[0]) >> material->metallic;
}
else if (command == "specular" && arguments.size() == 1)
{
std::stringstream(arguments[0]) >> material->specular;
std::stringstream(arguments[0]) >> material->albedo.x;
std::stringstream(arguments[1]) >> material->albedo.y;
std::stringstream(arguments[2]) >> material->albedo.z;
}
else if (command == "opacity" && arguments.size() == 1)
{
std::stringstream(arguments[0]) >> material->opacity;
}
else if (command == "color-map")
{
material->colorMap = loadTexture(argumentList);
}
else if (command == "roughness-map")
else if (command == "metalness" && arguments.size() == 1)
{
material->roughnessMap = loadTexture(argumentList);
std::stringstream(arguments[0]) >> material->metalness;
}
else if (command == "metallic-map")
else if (command == "roughness" && arguments.size() == 1)
{
material->metallicMap = loadTexture(argumentList);
std::stringstream(arguments[0]) >> material->roughness;
}
else if (command == "specular-map")
else if (command == "albedo-opacity-map")
{
material->specularMap = loadTexture(argumentList);
material->albedoOpacityMap = loadTexture(argumentList);
}
else if (command == "opacity-map")
else if (command == "metalness-roughness-map")
{
material->opacityMap = loadTexture(argumentList);
material->metalnessRoughnessMap = loadTexture(argumentList);
}
else if (command == "normal-map")
else if (command == "normal-occlusion-map")
{
material->normalMap = loadTexture(argumentList);
material->normalOcclusionMap = loadTexture(argumentList);
}
else if (command[0] != '#')
{

+ 10
- 16
src/materials.hpp View File

@ -46,32 +46,26 @@ inline unsigned int UIMaterial::getMaterialFormatID() const
return static_cast<unsigned int>(MaterialFormat::UI);
}
/// @see https://www.marmoset.co/posts/physically-based-rendering-and-you-can-too/
class PhysicalMaterial: public Material
{
public:
PhysicalMaterial():
colorMap(nullptr),
roughnessMap(nullptr),
metallicMap(nullptr),
specularMap(nullptr),
opacityMap(nullptr),
normalMap(nullptr)
albedoOpacityMap(nullptr),
metalnessRoughnessMap(nullptr),
normalOcclusionMap(nullptr)
{};
virtual ~PhysicalMaterial() {};
virtual unsigned int getMaterialFormatID() const;
Vector3 color;
float roughness;
float metallic;
float specular;
Vector3 albedo;
float opacity;
float metalness;
float roughness;
Texture* colorMap;
Texture* roughnessMap;
Texture* metallicMap;
Texture* specularMap;
Texture* opacityMap;
Texture* normalMap;
Texture* albedoOpacityMap;
Texture* metalnessRoughnessMap;
Texture* normalOcclusionMap;
bool shadowCaster;
bool shadowReceiver;

+ 19
- 3
src/render-passes.cpp View File

@ -739,6 +739,9 @@ void LightingRenderPass::render(const RenderContext* renderContext)
// Disable clipping
glDisable(GL_CLIP_DISTANCE0);
*/
const Camera& camera = *(renderContext->camera);
const std::list<RenderOperation>* operations = renderContext->queue->getOperations();
// Enable depth testing
glEnable(GL_DEPTH_TEST);
@ -757,15 +760,28 @@ void LightingRenderPass::render(const RenderContext* renderContext)
lightingShader->bind();
ShaderParameterSet* parameters = lightingShader->getParameters();
const Camera& camera = *(renderContext->camera);
const std::list<RenderOperation>* operations = renderContext->queue->getOperations();
int directionalLightCount = 1;
Vector3 directionalLightColor[3];
Vector3 directionalLightDirection[3];
directionalLightColor[0] = Vector3(1);
directionalLightDirection[0] = glm::normalize(Vector3(camera.getView() * -Vector4(0, 0, -1, 0)));
parameters->setValue(ShaderParameter::DIRECTIONAL_LIGHT_COLOR, 0, &directionalLightColor[0], directionalLightCount);
parameters->setValue(ShaderParameter::DIRECTIONAL_LIGHT_DIRECTION, 0, &directionalLightDirection[0], directionalLightCount);
// Render operations
for (const RenderOperation& operation: *operations)
{
const Matrix4& modelMatrix = operation.transform;
Matrix4 modelViewProjectionMatrix = camera.getViewProjection() * modelMatrix;
Matrix4 modelViewMatrix = camera.getView() * modelMatrix;
Matrix4 modelViewProjectionMatrix = camera.getViewProjection() * modelMatrix;
Matrix3 normalModelViewMatrix = glm::transpose(glm::inverse(Matrix3(modelViewMatrix)));
parameters->setValue(ShaderParameter::MODEL_VIEW_MATRIX, modelViewMatrix);
parameters->setValue(ShaderParameter::MODEL_VIEW_PROJECTION_MATRIX, modelViewProjectionMatrix);
parameters->setValue(ShaderParameter::NORMAL_MODEL_VIEW_MATRIX, normalModelViewMatrix);
glBindVertexArray(operation.vao);
glDrawElementsBaseVertex(GL_TRIANGLES, operation.triangleCount * 3, GL_UNSIGNED_INT, (void*)0, operation.indexOffset);
}

+ 1
- 1
src/states/splash-state.cpp View File

@ -490,7 +490,7 @@ void SplashState::enter()
application->selectMenuItem(application->selectedMenuItemIndex);
// Models
application->displayModel = application->modelLoader->load("data/models/display.mdl");
application->displayModel = application->modelLoader->load("data/models/monkey.mdl");
application->antModel = application->modelLoader->load("data/models/worker-ant.mdl");
// Model instances

Loading…
Cancel
Save