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:
parent
4a2c507c0f
commit
277a94bec7
8 changed files with 10 additions and 80 deletions
|
@ -1,211 +1,175 @@
|
|||
{
|
||||
"rows": [
|
||||
{
|
||||
"tex": "_default",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "0.0",
|
||||
"roughness": "0.8"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_flr01",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.6"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_flr02",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.6"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_red01",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.5"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_red02",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.5"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall01",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall02",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall03",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall04",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall05",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall06",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall07",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall08",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_wall09",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_panl01",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.5"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_panl02",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.5"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_tech01",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.5"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_trim01",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.5"
|
||||
},
|
||||
{
|
||||
"tex": "lhr_trim02",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.5"
|
||||
},
|
||||
{
|
||||
"tex": "plc_chair1",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "plc_chair2",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "plc_footlker",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "plc_metalbox",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "plc_koltank",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "c_drdastro01",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "c_drdastro02",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "c_drdastro03",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.7"
|
||||
},
|
||||
{
|
||||
"tex": "n_sithsoldier01",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.3"
|
||||
},
|
||||
{
|
||||
"tex": "n_sithsoldier02",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.3"
|
||||
},
|
||||
{
|
||||
"tex": "n_sithsoldier03",
|
||||
"specular": "0.1",
|
||||
"shininess": "8.0",
|
||||
"metallic": "1.0",
|
||||
"roughness": "0.3"
|
||||
|
|
|
@ -22,15 +22,12 @@ namespace reone {
|
|||
namespace graphics {
|
||||
|
||||
struct Material {
|
||||
bool custom { false };
|
||||
|
||||
// Blinn-Phong
|
||||
float specular { 0.1f };
|
||||
float shininess { 8.0f };
|
||||
|
||||
// PBR
|
||||
float metallic { 0.0f };
|
||||
float roughness { 0.8f };
|
||||
float roughness { 0.5f };
|
||||
};
|
||||
|
||||
} // namespace graphics
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "../common/collectionutil.h"
|
||||
#include "../resource/resources.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -29,8 +30,6 @@ namespace reone {
|
|||
|
||||
namespace graphics {
|
||||
|
||||
static constexpr char kDefaultMaterialTex[] = "_default";
|
||||
|
||||
Materials &Materials::instance() {
|
||||
static Materials instance;
|
||||
return instance;
|
||||
|
@ -42,18 +41,11 @@ void Materials::init() {
|
|||
if (materials) {
|
||||
for (int row = 0; row < materials->getRowCount(); ++row) {
|
||||
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 metallic = materials->getFloat(row, "metallic", -1.0f);
|
||||
float roughness = materials->getFloat(row, "roughness", -1.0f);
|
||||
|
||||
auto material = make_shared<Material>();
|
||||
if (tex != kDefaultMaterialTex) {
|
||||
material->custom = true;
|
||||
}
|
||||
if (specular != -1.0f) {
|
||||
material->specular = specular;
|
||||
}
|
||||
if (shininess != -1.0f) {
|
||||
material->shininess = shininess;
|
||||
}
|
||||
|
@ -82,13 +74,7 @@ void Materials::deinit() {
|
|||
}
|
||||
|
||||
shared_ptr<Material> Materials::get(const string &texResRef) const {
|
||||
auto maybeMaterial = _materials.find(texResRef);
|
||||
if (maybeMaterial != _materials.end()) return maybeMaterial->second;
|
||||
|
||||
auto maybeDefault = _materials.find(kDefaultMaterialTex);
|
||||
if (maybeDefault != _materials.end()) return maybeDefault->second;
|
||||
|
||||
return nullptr;
|
||||
return getFromLookupOrNull(_materials, texResRef);
|
||||
}
|
||||
|
||||
} // namespace graphics
|
||||
|
|
|
@ -68,7 +68,6 @@ struct UniformFeatureFlags {
|
|||
static constexpr int particles = 0x400;
|
||||
static constexpr int water = 0x800;
|
||||
static constexpr int hdr = 0x1000;
|
||||
static constexpr int customMat = 0x2000;
|
||||
static constexpr int blur = 0x4000;
|
||||
static constexpr int text = 0x8000;
|
||||
static constexpr int grass = 0x10000;
|
||||
|
@ -98,10 +97,10 @@ struct ShaderGeneral {
|
|||
struct ShaderMaterial {
|
||||
glm::vec4 ambient { 1.0f };
|
||||
glm::vec4 diffuse { 0.0f };
|
||||
float specular { 0.0f };
|
||||
float shininess { 0.0f };
|
||||
float metallic { 0.0f };
|
||||
float roughness { 1.0f };
|
||||
char padding[4];
|
||||
};
|
||||
|
||||
struct ShaderShadows {
|
||||
|
|
|
@ -41,7 +41,6 @@ const int FEATURE_SHADOWS = 0x200;
|
|||
const int FEATURE_PARTICLES = 0x400;
|
||||
const int FEATURE_WATER = 0x800;
|
||||
const int FEATURE_HDR = 0x1000;
|
||||
const int FEATURE_CUSTOMMAT = 0x2000;
|
||||
const int FEATURE_BLUR = 0x4000;
|
||||
const int FEATURE_TEXT = 0x8000;
|
||||
const int FEATURE_GRASS = 0x10000;
|
||||
|
@ -86,7 +85,6 @@ struct General {
|
|||
struct Material {
|
||||
vec4 ambient;
|
||||
vec4 diffuse;
|
||||
float specular;
|
||||
float shininess;
|
||||
float metallic;
|
||||
float roughness;
|
||||
|
|
|
@ -227,16 +227,6 @@ uniform sampler2D uBRDFLookup;
|
|||
uniform samplerCube uIrradianceMap;
|
||||
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() {
|
||||
vec2 uv = getUV();
|
||||
float shadow = getShadow();
|
||||
|
@ -252,8 +242,8 @@ void main() {
|
|||
}
|
||||
vec3 albedo = diffuseSample.rgb;
|
||||
float ao = 1.0;
|
||||
float metallic, roughness;
|
||||
getMetallicRoughness(diffuseSample, metallic, roughness);
|
||||
float metallic = uMaterial.metallic;
|
||||
float roughness = uMaterial.roughness;
|
||||
|
||||
vec3 objectColor;
|
||||
if (isFeatureEnabled(FEATURE_LIGHTMAP)) {
|
||||
|
@ -321,9 +311,9 @@ void main() {
|
|||
float G = GeometrySmith(N, V, L, roughness);
|
||||
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
|
||||
|
||||
vec3 nominator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001;
|
||||
vec3 specular = nominator / denominator;
|
||||
vec3 nom = NDF * G * F;
|
||||
float denom = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001;
|
||||
vec3 specular = nom / denom;
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = vec3(1.0) - kS;
|
||||
|
|
|
@ -41,7 +41,7 @@ vec3 getLightingDirect(vec3 N) {
|
|||
vec3 diff = uMaterial.diffuse.rgb * max(dot(L, N), 0.0);
|
||||
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;
|
||||
|
||||
float attenuation = getAttenuationQuadratic(i);
|
||||
|
|
|
@ -311,12 +311,8 @@ void ModelNodeSceneNode::drawSingle(bool shadowPass) {
|
|||
const vector<LightSceneNode *> &lights = _sceneGraph->closestLights();
|
||||
|
||||
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.diffuse = glm::vec4(mesh->diffuseColor, 1.0f);
|
||||
uniforms.combined.material.specular = _material.specular;
|
||||
uniforms.combined.material.shininess = _material.shininess;
|
||||
uniforms.combined.material.metallic = _material.metallic;
|
||||
uniforms.combined.material.roughness = _material.roughness;
|
||||
|
|
Loading…
Reference in a new issue