mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 11:43:16 +02:00
IMproving the shading model and the loading, added the roughness, needt to clean up
This commit is contained in:
parent
5e38aee0ba
commit
2f5800a4cc
13 changed files with 89 additions and 41 deletions
|
@ -152,6 +152,7 @@ void FBXReader::consolidateFBXMaterials() {
|
|||
glm::vec2 lightmapParams(0.f, 1.f);
|
||||
lightmapParams.x = _lightmapOffset;
|
||||
lightmapParams.y = _lightmapLevel;
|
||||
|
||||
FBXTexture ambientTexture;
|
||||
QString ambientTextureID = ambientTextures.value(material.materialID);
|
||||
if (_loadLightmaps && !ambientTextureID.isNull()) {
|
||||
|
@ -179,7 +180,6 @@ void FBXReader::consolidateFBXMaterials() {
|
|||
// FIXME: Do not use the Specular Factor yet as some FBX models have it set to 0
|
||||
// metallic *= material.specularFactor;
|
||||
material._material->setMetallic(metallic);
|
||||
|
||||
}
|
||||
|
||||
if (material.opacity <= 0.0f) {
|
||||
|
|
|
@ -37,5 +37,24 @@ float getMaterialMetallic(Material m) { return m._fresnelMetallic.a; }
|
|||
|
||||
float getMaterialShininess(Material m) { return 1.0 - getMaterialRoughness(m); }
|
||||
|
||||
int getMaterialKey(Material m) { return floatBitsToInt(m._spare.w); }
|
||||
|
||||
const int EMISSIVE_VAL_BIT = 0x00000001;
|
||||
const int ALBEDO_VAL_BIT = 0x00000002;
|
||||
const int METALLIC_VAL_BIT = 0x00000004;
|
||||
const int GLOSSY_VAL_BIT = 0x00000008;
|
||||
const int TRANSPARENT_VAL_BIT = 0x00000010;
|
||||
|
||||
|
||||
const int EMISSIVE_MAP_BIT = 0x00000020;
|
||||
const int ALBEDO_MAP_BIT = 0x00000040;
|
||||
const int METALLIC_MAP_BIT = 0x00000080;
|
||||
const int ROUGHNESS_MAP_BIT = 0x00000100;
|
||||
const int TRANSPARENT_MAP_BIT = 0x00000200;
|
||||
const int NORMAL_MAP_BIT = 0x00000400;
|
||||
|
||||
const int LIGHTMAP_MAP_BIT = 0x00000800;
|
||||
|
||||
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -120,7 +120,9 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
|
|||
// }
|
||||
|
||||
frag.metallic = frag.diffuseVal.a;
|
||||
if (frag.metallic > 0.5) {
|
||||
frag.diffuse = frag.diffuseVal.xyz;
|
||||
frag.specular = vec3(frag.metallic);
|
||||
/* if (frag.metallic > 0.5) {
|
||||
frag.diffuse = vec3(0);
|
||||
//frag.metallic = length(frag.specularVal);
|
||||
frag.specular = frag.diffuseVal.xyz;
|
||||
|
@ -130,6 +132,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
|
|||
//frag.metallic = length(frag.specularVal);
|
||||
frag.specular = vec3(0.03);
|
||||
}
|
||||
*/
|
||||
// frag.diffuse = frag.diffuseVal.xyz;
|
||||
//frag.metallic = length(frag.specularVal);
|
||||
//frag.specular = frag.specularVal.xyz;
|
||||
|
|
|
@ -50,8 +50,8 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness
|
|||
if (alpha != 1.0) {
|
||||
discard;
|
||||
}
|
||||
vec3 baseColor = ((metallic < 0.5) ? albedo : fresnel);
|
||||
_fragColor0 = vec4(baseColor, metallic);
|
||||
// vec3 baseColor = ((metallic < 0.5) ? albedo : fresnel);
|
||||
_fragColor0 = vec4(albedo, metallic);
|
||||
_fragColor1 = vec4(bestFitNormal(normal), 0.5 * clamp(roughness, 0.0, 1.0));
|
||||
_fragColor2 = vec4(fresnel, roughness);
|
||||
}
|
||||
|
@ -60,9 +60,7 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r
|
|||
if (alpha != 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec3 baseColor = ((metallic < 0.5) ? albedo : fresnel);
|
||||
_fragColor0 = vec4(baseColor, metallic);
|
||||
_fragColor0 = vec4(albedo, metallic);
|
||||
_fragColor1 = vec4(bestFitNormal(normal), 0.5 + 0.5 * clamp(roughness, 0.0, 1.0));
|
||||
_fragColor2 = vec4(emissive, roughness);
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ float specularDistribution(float roughness, vec3 normal, vec3 halfDir) {
|
|||
// Frag Shading returns the diffuse amount as W and the specular rgb as xyz
|
||||
vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 fresnel, float roughness) {
|
||||
// Diffuse Lighting
|
||||
//float diffuseDot = dot(fragNormal, fragLightDir);
|
||||
//float facingLight = step(0.0, diffuseDot);
|
||||
float diffuse = clamp(dot(fragNormal, fragLightDir), 0.0, 1.0);
|
||||
|
||||
// Specular Lighting
|
||||
|
|
|
@ -20,14 +20,12 @@ vec4 fetchAlbedoMap(vec2 uv) {
|
|||
}
|
||||
<@endif@>
|
||||
|
||||
<!
|
||||
<@if withRoughness@>
|
||||
uniform sampler2D roughnessMap;
|
||||
float fetchRoughnessMap(vec2 uv) {
|
||||
return texture(roughnessMap, uv).r;
|
||||
}
|
||||
<@endif@>
|
||||
!>
|
||||
|
||||
<@if withNormal@>
|
||||
uniform sampler2D normalMap;
|
||||
|
@ -38,8 +36,8 @@ vec3 fetchNormalMap(vec2 uv) {
|
|||
|
||||
<@if withMetallic@>
|
||||
uniform sampler2D specularMap;
|
||||
vec3 fetchMetallicMap(vec2 uv) {
|
||||
return texture(specularMap, uv).rgb;
|
||||
float fetchMetallicMap(vec2 uv) {
|
||||
return texture(specularMap, uv).r;
|
||||
}
|
||||
<@endif@>
|
||||
|
||||
|
@ -51,13 +49,13 @@ vec3 fetchMetallicMap(vec2 uv) {
|
|||
vec4 <$albedo$> = fetchAlbedoMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@if roughness@>
|
||||
float <$roughness$> = 1.0; //fetchRoughnessMap(<$texcoord0$>);
|
||||
float <$roughness$> = fetchRoughnessMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@if normal@>
|
||||
vec3 <$normal$> = fetchNormalMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@if metallic@>
|
||||
vec3 <$metallic$> = fetchMetallicMap(<$texcoord0$>);
|
||||
float <$metallic$> = fetchMetallicMap(<$texcoord0$>);
|
||||
<@endif@>
|
||||
<@endfunc@>
|
||||
|
||||
|
@ -85,4 +83,18 @@ vec3 fetchLightmapMap(vec2 uv) {
|
|||
}
|
||||
<@endfunc@>
|
||||
|
||||
|
||||
<@func evalMaterialRoughness(fetchedRoughness, materialRoughness, matKey, roughness)@>
|
||||
{
|
||||
<$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? <$fetchedRoughness$> : <$materialRoughness$>);
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func evalMaterialMetallic(fetchedMetallic, materialMetallic, matKey, metallic)@>
|
||||
{
|
||||
<$metallic$> = (((<$matKey$> & METALLIC_MAP_BIT) != 0) ? <$fetchedMetallic$> : <$materialMetallic$>);
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
|
||||
<@endif@>
|
|
@ -161,6 +161,20 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
|
|||
batch.setResourceTexture(ShapePipeline::Slot::ALBEDO_MAP, textureCache->getWhiteTexture());
|
||||
}
|
||||
|
||||
// Roughness map
|
||||
if (materialKey.isRoughnessMap()) {
|
||||
auto roughnessMap = textureMaps[model::MaterialKey::ROUGHNESS_MAP];
|
||||
if (roughnessMap && roughnessMap->isDefined()) {
|
||||
batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, roughnessMap->getTextureView());
|
||||
|
||||
// texcoord are assumed to be the same has albedo
|
||||
} else {
|
||||
batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, textureCache->getWhiteTexture());
|
||||
}
|
||||
} else {
|
||||
batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, textureCache->getWhiteTexture());
|
||||
}
|
||||
|
||||
// Normal map
|
||||
if (materialKey.isNormalMap()) {
|
||||
auto normalMap = textureMaps[model::MaterialKey::NORMAL_MAP];
|
||||
|
@ -175,20 +189,6 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
|
|||
batch.setResourceTexture(ShapePipeline::Slot::NORMAL_MAP, nullptr);
|
||||
}
|
||||
|
||||
// Roughness map
|
||||
/* if (materialKey.isRoughnessMap()) {
|
||||
auto roughnessMap = textureMaps[model::MaterialKey::ROUGHNESS_MAP];
|
||||
if (roughnessMap && roughnessMap->isDefined()) {
|
||||
batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, roughnessMap->getTextureView());
|
||||
|
||||
// texcoord are assumed to be the same has albedo
|
||||
} else {
|
||||
batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, textureCache->getBlackTexture());
|
||||
}
|
||||
} else {
|
||||
batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, nullptr);
|
||||
}*/
|
||||
|
||||
// Metallic map
|
||||
if (materialKey.isMetallicMap()) {
|
||||
auto specularMap = textureMaps[model::MaterialKey::METALLIC_MAP];
|
||||
|
|
|
@ -28,7 +28,7 @@ in vec3 _tangent;
|
|||
in vec3 _color;
|
||||
|
||||
void main(void) {
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, normalTexel, specular)$>
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, normalTexel, metalllicTex)$>
|
||||
<$fetchMaterialLightmap(_texCoord1, lightmapVal)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
|
@ -41,7 +41,7 @@ void main(void) {
|
|||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
|
||||
getMaterialAlbedo(mat) * albedo.rgb * _color,
|
||||
getMaterialRoughness(mat) * roughness,
|
||||
getMaterialMetallic(mat),
|
||||
specular, // no use of getMaterialFresnel(mat)
|
||||
getMaterialMetallic(mat) * metalllicTex,
|
||||
/*specular, // no use of */ getMaterialFresnel(mat),
|
||||
lightmapVal);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,6 @@ void main(void) {
|
|||
getMaterialAlbedo(mat) * albedo.rgb * _color,
|
||||
getMaterialRoughness(mat) * roughness,
|
||||
getMaterialMetallic(mat),
|
||||
specular, // no use of getMaterialFresnel(mat)
|
||||
/*specular, // no use of */getMaterialFresnel(mat),
|
||||
lightmapVal);
|
||||
}
|
||||
|
|
|
@ -27,19 +27,28 @@ in vec3 _color;
|
|||
|
||||
void main(void) {
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, normalTexel, specular)$>
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughnessTex, normalTexel, metallicTex)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
int matKey = getMaterialKey(mat);
|
||||
|
||||
float roughness = getMaterialRoughness(mat);
|
||||
<$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>;
|
||||
|
||||
|
||||
vec3 viewNormal;
|
||||
<$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
|
||||
|
||||
|
||||
float metallic = getMaterialMetallic(mat);
|
||||
<$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>;
|
||||
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(viewNormal.xyz),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
|
||||
getMaterialAlbedo(mat) * albedo.rgb * _color,
|
||||
getMaterialRoughness(mat) * roughness,
|
||||
getMaterialMetallic(mat),
|
||||
vec3(specular) //getMaterialFresnel(mat)
|
||||
roughness,
|
||||
metallic,
|
||||
/*vec3(specular) //*/getMaterialFresnel(mat)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -27,16 +27,20 @@ in vec3 _color;
|
|||
|
||||
void main(void) {
|
||||
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, _SCRIBE_NULL, specular)$>
|
||||
<$fetchMaterialTextures(_texCoord0, albedo, roughness, _SCRIBE_NULL, metallicTex)$>
|
||||
|
||||
Material mat = getMaterial();
|
||||
int matKey = getMaterialKey(mat);
|
||||
|
||||
float metallic = getMaterialMetallic(mat);
|
||||
<$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>;
|
||||
|
||||
packDeferredFragment(
|
||||
normalize(_normal),
|
||||
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
|
||||
getMaterialAlbedo(mat) * albedo.rgb * _color,
|
||||
getMaterialRoughness(mat) * roughness,
|
||||
getMaterialMetallic(mat),
|
||||
vec3(specular) //getMaterialFresnel(mat)
|
||||
metallic,
|
||||
/*vec3(specular) //*/ getMaterialFresnel(mat)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p
|
|||
slotBindings.insert(gpu::Shader::Binding(std::string("skinClusterBuffer"), Slot::SKINNING_GPU));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("materialBuffer"), Slot::MATERIAL_GPU));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("albedoMap"), Slot::ALBEDO_MAP));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("roughnessMap"), Slot::ROUGHNESS_MAP));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("normalMap"), Slot::NORMAL_MAP));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("specularMap"), Slot::SPECULAR_MAP));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("emissiveMap"), Slot::LIGHTMAP_MAP));
|
||||
|
@ -67,6 +68,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p
|
|||
locations->emissiveParams = program->getUniforms().findLocation("emissiveParams");
|
||||
locations->normalFittingMapUnit = program->getTextures().findLocation("normalFittingMap");
|
||||
locations->albedoTextureUnit = program->getTextures().findLocation("albedoMap");
|
||||
locations->roughnessTextureUnit = program->getTextures().findLocation("roughnessMap");
|
||||
locations->normalTextureUnit = program->getTextures().findLocation("normalMap");
|
||||
locations->specularTextureUnit = program->getTextures().findLocation("specularMap");
|
||||
locations->emissiveTextureUnit = program->getTextures().findLocation("emissiveMap");
|
||||
|
|
|
@ -199,6 +199,8 @@ public:
|
|||
static const int NORMAL_MAP = 1;
|
||||
static const int SPECULAR_MAP = 2;
|
||||
static const int LIGHTMAP_MAP = 3;
|
||||
static const int ROUGHNESS_MAP = 4;
|
||||
|
||||
static const int LIGHT_BUFFER = 4;
|
||||
static const int NORMAL_FITTING_MAP = 10;
|
||||
};
|
||||
|
@ -208,6 +210,7 @@ public:
|
|||
int texcoordMatrices;
|
||||
int albedoTextureUnit;
|
||||
int normalTextureUnit;
|
||||
int roughnessTextureUnit;
|
||||
int specularTextureUnit;
|
||||
int emissiveTextureUnit;
|
||||
int emissiveParams;
|
||||
|
|
Loading…
Reference in a new issue