diff --git a/res/data/material.2da.json b/res/data/material.2da.json index 75a9744d..58124bc7 100644 --- a/res/data/material.2da.json +++ b/res/data/material.2da.json @@ -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" diff --git a/src/engine/graphics/material.h b/src/engine/graphics/material.h index e8c547a2..cab4fdb1 100644 --- a/src/engine/graphics/material.h +++ b/src/engine/graphics/material.h @@ -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 diff --git a/src/engine/graphics/materials.cpp b/src/engine/graphics/materials.cpp index c9be8370..d7b482f2 100644 --- a/src/engine/graphics/materials.cpp +++ b/src/engine/graphics/materials.cpp @@ -19,6 +19,7 @@ #include +#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(); - 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 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 diff --git a/src/engine/graphics/shader/shaders.h b/src/engine/graphics/shader/shaders.h index c42b7445..020325f3 100644 --- a/src/engine/graphics/shader/shaders.h +++ b/src/engine/graphics/shader/shaders.h @@ -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 { diff --git a/src/engine/graphics/shader/shaders_common.cpp b/src/engine/graphics/shader/shaders_common.cpp index 5041db4e..4c541900 100644 --- a/src/engine/graphics/shader/shaders_common.cpp +++ b/src/engine/graphics/shader/shaders_common.cpp @@ -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; diff --git a/src/engine/graphics/shader/shaders_pbr.cpp b/src/engine/graphics/shader/shaders_pbr.cpp index 29a8d21f..788cd304 100644 --- a/src/engine/graphics/shader/shaders_pbr.cpp +++ b/src/engine/graphics/shader/shaders_pbr.cpp @@ -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; diff --git a/src/engine/graphics/shader/shaders_phong.cpp b/src/engine/graphics/shader/shaders_phong.cpp index b2c9e49e..ae7a6abe 100644 --- a/src/engine/graphics/shader/shaders_phong.cpp +++ b/src/engine/graphics/shader/shaders_phong.cpp @@ -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); diff --git a/src/engine/scene/node/modelnodescenenode.cpp b/src/engine/scene/node/modelnodescenenode.cpp index 26fe7ba7..668b13be 100644 --- a/src/engine/scene/node/modelnodescenenode.cpp +++ b/src/engine/scene/node/modelnodescenenode.cpp @@ -311,12 +311,8 @@ void ModelNodeSceneNode::drawSingle(bool shadowPass) { const vector &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;