Simplify materials

- Remove specular parameter (shininess is enough)
- Explicit default material is removed
- Default roughness is set to 0.5
This commit is contained in:
Vsevolod Kremianskii 2021-05-12 12:20:43 +07:00
parent 4a2c507c0f
commit 277a94bec7
8 changed files with 10 additions and 80 deletions

View file

@ -1,211 +1,175 @@
{ {
"rows": [ "rows": [
{
"tex": "_default",
"specular": "0.1",
"shininess": "8.0",
"metallic": "0.0",
"roughness": "0.8"
},
{ {
"tex": "lhr_flr01", "tex": "lhr_flr01",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.6" "roughness": "0.6"
}, },
{ {
"tex": "lhr_flr02", "tex": "lhr_flr02",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.6" "roughness": "0.6"
}, },
{ {
"tex": "lhr_red01", "tex": "lhr_red01",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.5" "roughness": "0.5"
}, },
{ {
"tex": "lhr_red02", "tex": "lhr_red02",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.5" "roughness": "0.5"
}, },
{ {
"tex": "lhr_wall01", "tex": "lhr_wall01",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_wall02", "tex": "lhr_wall02",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_wall03", "tex": "lhr_wall03",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_wall04", "tex": "lhr_wall04",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_wall05", "tex": "lhr_wall05",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_wall06", "tex": "lhr_wall06",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_wall07", "tex": "lhr_wall07",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_wall08", "tex": "lhr_wall08",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_wall09", "tex": "lhr_wall09",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "lhr_panl01", "tex": "lhr_panl01",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.5" "roughness": "0.5"
}, },
{ {
"tex": "lhr_panl02", "tex": "lhr_panl02",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.5" "roughness": "0.5"
}, },
{ {
"tex": "lhr_tech01", "tex": "lhr_tech01",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.5" "roughness": "0.5"
}, },
{ {
"tex": "lhr_trim01", "tex": "lhr_trim01",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.5" "roughness": "0.5"
}, },
{ {
"tex": "lhr_trim02", "tex": "lhr_trim02",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.5" "roughness": "0.5"
}, },
{ {
"tex": "plc_chair1", "tex": "plc_chair1",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "plc_chair2", "tex": "plc_chair2",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "plc_footlker", "tex": "plc_footlker",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "plc_metalbox", "tex": "plc_metalbox",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "plc_koltank", "tex": "plc_koltank",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "c_drdastro01", "tex": "c_drdastro01",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "c_drdastro02", "tex": "c_drdastro02",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "c_drdastro03", "tex": "c_drdastro03",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.7" "roughness": "0.7"
}, },
{ {
"tex": "n_sithsoldier01", "tex": "n_sithsoldier01",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.3" "roughness": "0.3"
}, },
{ {
"tex": "n_sithsoldier02", "tex": "n_sithsoldier02",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.3" "roughness": "0.3"
}, },
{ {
"tex": "n_sithsoldier03", "tex": "n_sithsoldier03",
"specular": "0.1",
"shininess": "8.0", "shininess": "8.0",
"metallic": "1.0", "metallic": "1.0",
"roughness": "0.3" "roughness": "0.3"

View file

@ -22,15 +22,12 @@ namespace reone {
namespace graphics { namespace graphics {
struct Material { struct Material {
bool custom { false };
// Blinn-Phong // Blinn-Phong
float specular { 0.1f };
float shininess { 8.0f }; float shininess { 8.0f };
// PBR // PBR
float metallic { 0.0f }; float metallic { 0.0f };
float roughness { 0.8f }; float roughness { 0.5f };
}; };
} // namespace graphics } // namespace graphics

View file

@ -19,6 +19,7 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "../common/collectionutil.h"
#include "../resource/resources.h" #include "../resource/resources.h"
using namespace std; using namespace std;
@ -29,8 +30,6 @@ namespace reone {
namespace graphics { namespace graphics {
static constexpr char kDefaultMaterialTex[] = "_default";
Materials &Materials::instance() { Materials &Materials::instance() {
static Materials instance; static Materials instance;
return instance; return instance;
@ -42,18 +41,11 @@ void Materials::init() {
if (materials) { if (materials) {
for (int row = 0; row < materials->getRowCount(); ++row) { for (int row = 0; row < materials->getRowCount(); ++row) {
string tex(boost::to_lower_copy(materials->getString(row, "tex"))); string tex(boost::to_lower_copy(materials->getString(row, "tex")));
float specular = materials->getFloat(row, "specular", -1.0f);
float shininess = materials->getFloat(row, "shininess", -1.0f); float shininess = materials->getFloat(row, "shininess", -1.0f);
float metallic = materials->getFloat(row, "metallic", -1.0f); float metallic = materials->getFloat(row, "metallic", -1.0f);
float roughness = materials->getFloat(row, "roughness", -1.0f); float roughness = materials->getFloat(row, "roughness", -1.0f);
auto material = make_shared<Material>(); auto material = make_shared<Material>();
if (tex != kDefaultMaterialTex) {
material->custom = true;
}
if (specular != -1.0f) {
material->specular = specular;
}
if (shininess != -1.0f) { if (shininess != -1.0f) {
material->shininess = shininess; material->shininess = shininess;
} }
@ -82,13 +74,7 @@ void Materials::deinit() {
} }
shared_ptr<Material> Materials::get(const string &texResRef) const { shared_ptr<Material> Materials::get(const string &texResRef) const {
auto maybeMaterial = _materials.find(texResRef); return getFromLookupOrNull(_materials, texResRef);
if (maybeMaterial != _materials.end()) return maybeMaterial->second;
auto maybeDefault = _materials.find(kDefaultMaterialTex);
if (maybeDefault != _materials.end()) return maybeDefault->second;
return nullptr;
} }
} // namespace graphics } // namespace graphics

View file

@ -68,7 +68,6 @@ struct UniformFeatureFlags {
static constexpr int particles = 0x400; static constexpr int particles = 0x400;
static constexpr int water = 0x800; static constexpr int water = 0x800;
static constexpr int hdr = 0x1000; static constexpr int hdr = 0x1000;
static constexpr int customMat = 0x2000;
static constexpr int blur = 0x4000; static constexpr int blur = 0x4000;
static constexpr int text = 0x8000; static constexpr int text = 0x8000;
static constexpr int grass = 0x10000; static constexpr int grass = 0x10000;
@ -98,10 +97,10 @@ struct ShaderGeneral {
struct ShaderMaterial { struct ShaderMaterial {
glm::vec4 ambient { 1.0f }; glm::vec4 ambient { 1.0f };
glm::vec4 diffuse { 0.0f }; glm::vec4 diffuse { 0.0f };
float specular { 0.0f };
float shininess { 0.0f }; float shininess { 0.0f };
float metallic { 0.0f }; float metallic { 0.0f };
float roughness { 1.0f }; float roughness { 1.0f };
char padding[4];
}; };
struct ShaderShadows { struct ShaderShadows {

View file

@ -41,7 +41,6 @@ const int FEATURE_SHADOWS = 0x200;
const int FEATURE_PARTICLES = 0x400; const int FEATURE_PARTICLES = 0x400;
const int FEATURE_WATER = 0x800; const int FEATURE_WATER = 0x800;
const int FEATURE_HDR = 0x1000; const int FEATURE_HDR = 0x1000;
const int FEATURE_CUSTOMMAT = 0x2000;
const int FEATURE_BLUR = 0x4000; const int FEATURE_BLUR = 0x4000;
const int FEATURE_TEXT = 0x8000; const int FEATURE_TEXT = 0x8000;
const int FEATURE_GRASS = 0x10000; const int FEATURE_GRASS = 0x10000;
@ -86,7 +85,6 @@ struct General {
struct Material { struct Material {
vec4 ambient; vec4 ambient;
vec4 diffuse; vec4 diffuse;
float specular;
float shininess; float shininess;
float metallic; float metallic;
float roughness; float roughness;

View file

@ -227,16 +227,6 @@ uniform sampler2D uBRDFLookup;
uniform samplerCube uIrradianceMap; uniform samplerCube uIrradianceMap;
uniform samplerCube uPrefilterMap; uniform samplerCube uPrefilterMap;
void getMetallicRoughness(vec4 diffuseSample, out float metallic, out float roughness) {
if (isFeatureEnabled(FEATURE_CUSTOMMAT) || !isFeatureEnabled(FEATURE_ENVMAP)) {
metallic = uMaterial.metallic;
roughness = uMaterial.roughness;
} else {
metallic = mix(uMaterial.metallic, 1.0, 1.0 - diffuseSample.a);
roughness = mix(uMaterial.roughness, 0.1, 1.0 - diffuseSample.a);
}
}
void main() { void main() {
vec2 uv = getUV(); vec2 uv = getUV();
float shadow = getShadow(); float shadow = getShadow();
@ -252,8 +242,8 @@ void main() {
} }
vec3 albedo = diffuseSample.rgb; vec3 albedo = diffuseSample.rgb;
float ao = 1.0; float ao = 1.0;
float metallic, roughness; float metallic = uMaterial.metallic;
getMetallicRoughness(diffuseSample, metallic, roughness); float roughness = uMaterial.roughness;
vec3 objectColor; vec3 objectColor;
if (isFeatureEnabled(FEATURE_LIGHTMAP)) { if (isFeatureEnabled(FEATURE_LIGHTMAP)) {
@ -321,9 +311,9 @@ void main() {
float G = GeometrySmith(N, V, L, roughness); float G = GeometrySmith(N, V, L, roughness);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0); vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
vec3 nominator = NDF * G * F; vec3 nom = NDF * G * F;
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001; float denom = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001;
vec3 specular = nominator / denominator; vec3 specular = nom / denom;
vec3 kS = F; vec3 kS = F;
vec3 kD = vec3(1.0) - kS; vec3 kD = vec3(1.0) - kS;

View file

@ -41,7 +41,7 @@ vec3 getLightingDirect(vec3 N) {
vec3 diff = uMaterial.diffuse.rgb * max(dot(L, N), 0.0); vec3 diff = uMaterial.diffuse.rgb * max(dot(L, N), 0.0);
vec3 diffuse = uLights[i].multiplier * uLights[i].color.rgb * diff; vec3 diffuse = uLights[i].multiplier * uLights[i].color.rgb * diff;
float spec = uMaterial.specular * pow(max(dot(N, H), 0.0), uMaterial.shininess); float spec = pow(max(dot(N, H), 0.0), uMaterial.shininess);
vec3 specular = uLights[i].multiplier * uLights[i].color.rgb * spec; vec3 specular = uLights[i].multiplier * uLights[i].color.rgb * spec;
float attenuation = getAttenuationQuadratic(i); float attenuation = getAttenuationQuadratic(i);

View file

@ -311,12 +311,8 @@ void ModelNodeSceneNode::drawSingle(bool shadowPass) {
const vector<LightSceneNode *> &lights = _sceneGraph->closestLights(); const vector<LightSceneNode *> &lights = _sceneGraph->closestLights();
uniforms.combined.featureMask |= UniformFeatureFlags::lighting; uniforms.combined.featureMask |= UniformFeatureFlags::lighting;
if (_material.custom) {
uniforms.combined.featureMask |= UniformFeatureFlags::customMat;
}
uniforms.combined.material.ambient = glm::vec4(mesh->ambientColor, 1.0f); uniforms.combined.material.ambient = glm::vec4(mesh->ambientColor, 1.0f);
uniforms.combined.material.diffuse = glm::vec4(mesh->diffuseColor, 1.0f); uniforms.combined.material.diffuse = glm::vec4(mesh->diffuseColor, 1.0f);
uniforms.combined.material.specular = _material.specular;
uniforms.combined.material.shininess = _material.shininess; uniforms.combined.material.shininess = _material.shininess;
uniforms.combined.material.metallic = _material.metallic; uniforms.combined.material.metallic = _material.metallic;
uniforms.combined.material.roughness = _material.roughness; uniforms.combined.material.roughness = _material.roughness;