MOving forward with PBR rendering, cleaning up the lighting shaders and the packi/unpack deferredBuffer shaders

This commit is contained in:
samcake 2016-02-19 18:43:07 -08:00
parent d7b3945c4a
commit 39a7852979
38 changed files with 248 additions and 114 deletions

View file

@ -26,8 +26,20 @@ Column {
ExclusiveGroup { id: bufferGroup }
Repeater {
model: [
"Off", "Diffuse", "Metallic", "Roughness", "Normal", "Depth",
"Lighting", "Shadow", "Pyramid Depth", "Ambient Occlusion", "Custom Shader"
"Off",
"Depth",
"Diffuse",
"Normal",
"Roughness",
"Metallic",
"Fresnel",
"Emissive",
"Lightmap",
"Lighting",
"Shadow",
"Pyramid Depth",
"Ambient Occlusion",
"Custom Shader"
]
RadioButton {
text: qsTr(modelData)

View file

@ -28,9 +28,6 @@ void main(void) {
vec3 worldNormal = cross(dFdy(_worldPosition.xyz), dFdx(_worldPosition.xyz));
worldNormal = normalize(worldNormal);
vec3 specular = DEFAULT_SPECULAR;
float shininess = DEFAULT_SHININESS;
float inPositionX = (_worldPosition.x - 0.5) / voxelVolumeSize.x;
float inPositionY = (_worldPosition.y - 0.5) / voxelVolumeSize.y;
float inPositionZ = (_worldPosition.z - 0.5) / voxelVolumeSize.z;
@ -44,5 +41,5 @@ void main(void) {
vec3 yzDiffuseScaled = yzDiffuse.rgb * abs(worldNormal.x);
vec4 diffuse = vec4(xyDiffuseScaled + xzDiffuseScaled + yzDiffuseScaled, 1.0);
packDeferredFragment(_normal, 1.0, vec3(diffuse), specular, shininess);
packDeferredFragment(_normal, 1.0, vec3(diffuse), DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_SPECULAR);
}

View file

@ -162,8 +162,6 @@ GLBackend::GLShader* compileShader(const Shader& shader) {
char* temp = new char[infoLength] ;
glGetShaderInfoLog(glshader, infoLength, NULL, temp);
qCWarning(gpulogging) << "GLShader::compileShader - failed to compile the gl shader object:";
qCWarning(gpulogging) << temp;
/*
filestream.open("debugshader.glsl.info.txt");
@ -173,7 +171,10 @@ GLBackend::GLShader* compileShader(const Shader& shader) {
}
*/
qCWarning(gpulogging) << "GLShader::compileShader - failed to compile the gl shader object:";
qCWarning(gpulogging) << srcstr;
qCWarning(gpulogging) << "GLShader::compileShader - errors:";
qCWarning(gpulogging) << temp;
delete[] temp;
glDeleteShader(glshader);

View file

@ -177,7 +177,7 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u
auto glossMap = model::TextureMapPointer(new model::TextureMap());
glossMap->setTextureSource(material->specularTexture->_textureSource);
networkMaterial->setTextureMap(model::MaterialKey::GLOSS_MAP, glossMap);
networkMaterial->setTextureMap(model::MaterialKey::ROUGHNESS_MAP, glossMap);
} else if (material->emissiveTextureName == name) {
material->emissiveTexture = textureCache->getTexture(url);
@ -350,6 +350,15 @@ static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const
material._material->setTextureMap(model::MaterialKey::METALLIC_MAP, specularMap);
}
if (!material.metallicTexture.filename.isEmpty()) {
networkMaterial->specularTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.metallicTexture.filename)), SPECULAR_TEXTURE, material.metallicTexture.content);
networkMaterial->specularTextureName = material.metallicTexture.name;
auto metallicMap = model::TextureMapPointer(new model::TextureMap());
metallicMap->setTextureSource(networkMaterial->specularTexture->_textureSource);
material._material->setTextureMap(model::MaterialKey::METALLIC_MAP, metallicMap);
}
if (!material.roughnessTexture.filename.isEmpty()) {
networkMaterial->roughnessTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.roughnessTexture.filename)), ROUGHNESS_TEXTURE, material.roughnessTexture.content);
networkMaterial->roughnessTextureName = material.roughnessTexture.name;
@ -357,7 +366,7 @@ static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const
auto roughnessMap = model::TextureMapPointer(new model::TextureMap());
roughnessMap->setTextureSource(networkMaterial->roughnessTexture->_textureSource);
material._material->setTextureMap(model::MaterialKey::GLOSS_MAP, roughnessMap);
material._material->setTextureMap(model::MaterialKey::ROUGHNESS_MAP, roughnessMap);
}
if (!material.emissiveTexture.filename.isEmpty()) {
networkMaterial->emissiveTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.emissiveTexture.filename)), EMISSIVE_TEXTURE, material.emissiveTexture.content);

View file

@ -61,7 +61,7 @@ void Material::setAlbedo(const Color& albedo, bool isSRGB) {
void Material::setRoughness(float roughness) {
roughness = std::min(1.0f, std::max(roughness, 0.0f));
_key.setGloss((roughness < 1.0f));
_key.setGlossy((roughness < 1.0f));
_schemaBuffer.edit<Schema>()._roughness = roughness;
}

View file

@ -30,13 +30,13 @@ public:
EMISSIVE_VAL_BIT = 0,
ALBEDO_VAL_BIT,
METALLIC_VAL_BIT,
GLOSS_VAL_BIT,
GLOSSY_VAL_BIT,
TRANSPARENT_VAL_BIT,
EMISSIVE_MAP_BIT,
ALBEDO_MAP_BIT,
METALLIC_MAP_BIT,
GLOSS_MAP_BIT,
ROUGHNESS_MAP_BIT,
TRANSPARENT_MAP_BIT,
NORMAL_MAP_BIT,
LIGHTMAP_MAP_BIT,
@ -49,7 +49,7 @@ public:
EMISSIVE_MAP = 0,
ALBEDO_MAP,
METALLIC_MAP,
GLOSS_MAP,
ROUGHNESS_MAP,
TRANSPARENT_MAP,
NORMAL_MAP,
LIGHTMAP_MAP,
@ -73,13 +73,13 @@ public:
Builder& withEmissive() { _flags.set(EMISSIVE_VAL_BIT); return (*this); }
Builder& withAlbedo() { _flags.set(ALBEDO_VAL_BIT); return (*this); }
Builder& withMetallic() { _flags.set(METALLIC_VAL_BIT); return (*this); }
Builder& withGloss() { _flags.set(GLOSS_VAL_BIT); return (*this); }
Builder& withGlossy() { _flags.set(GLOSSY_VAL_BIT); return (*this); }
Builder& withTransparent() { _flags.set(TRANSPARENT_VAL_BIT); return (*this); }
Builder& withEmissiveMap() { _flags.set(EMISSIVE_MAP_BIT); return (*this); }
Builder& withAlbedoMap() { _flags.set(ALBEDO_MAP_BIT); return (*this); }
Builder& withMetallicMap() { _flags.set(METALLIC_MAP_BIT); return (*this); }
Builder& withGlossMap() { _flags.set(GLOSS_MAP_BIT); return (*this); }
Builder& withRoughnessMap() { _flags.set(ROUGHNESS_MAP_BIT); return (*this); }
Builder& withTransparentMap() { _flags.set(TRANSPARENT_MAP_BIT); return (*this); }
Builder& withNormalMap() { _flags.set(NORMAL_MAP_BIT); return (*this); }
@ -107,11 +107,12 @@ public:
void setMetallicMap(bool value) { _flags.set(METALLIC_MAP_BIT, value); }
bool isMetallicMap() const { return _flags[METALLIC_MAP_BIT]; }
void setGloss(bool value) { _flags.set(GLOSS_VAL_BIT, value); }
bool isGloss() const { return _flags[GLOSS_VAL_BIT]; }
void setGlossy(bool value) { _flags.set(GLOSSY_VAL_BIT, value); }
bool isGlossy() const { return _flags[GLOSSY_VAL_BIT]; }
bool isRough() const { return !_flags[GLOSSY_VAL_BIT]; }
void setGlossMap(bool value) { _flags.set(GLOSS_MAP_BIT, value); }
bool isGlossMap() const { return _flags[GLOSS_MAP_BIT]; }
void setRoughnessMap(bool value) { _flags.set(ROUGHNESS_MAP_BIT, value); }
bool isRoughnessMap() const { return _flags[ROUGHNESS_MAP_BIT]; }
void setTransparent(bool value) { _flags.set(TRANSPARENT_VAL_BIT, value); }
bool isTransparent() const { return _flags[TRANSPARENT_VAL_BIT]; }
@ -166,11 +167,11 @@ public:
Builder& withoutMetallicMap() { _value.reset(MaterialKey::METALLIC_MAP_BIT); _mask.set(MaterialKey::METALLIC_MAP_BIT); return (*this); }
Builder& withMetallicMap() { _value.set(MaterialKey::METALLIC_MAP_BIT); _mask.set(MaterialKey::METALLIC_MAP_BIT); return (*this); }
Builder& withoutGloss() { _value.reset(MaterialKey::GLOSS_VAL_BIT); _mask.set(MaterialKey::GLOSS_VAL_BIT); return (*this); }
Builder& withGloss() { _value.set(MaterialKey::GLOSS_VAL_BIT); _mask.set(MaterialKey::GLOSS_VAL_BIT); return (*this); }
Builder& withoutGlossy() { _value.reset(MaterialKey::GLOSSY_VAL_BIT); _mask.set(MaterialKey::GLOSSY_VAL_BIT); return (*this); }
Builder& withGlossy() { _value.set(MaterialKey::GLOSSY_VAL_BIT); _mask.set(MaterialKey::GLOSSY_VAL_BIT); return (*this); }
Builder& withoutGlossMap() { _value.reset(MaterialKey::GLOSS_MAP_BIT); _mask.set(MaterialKey::GLOSS_MAP_BIT); return (*this); }
Builder& withGlossMap() { _value.set(MaterialKey::GLOSS_MAP_BIT); _mask.set(MaterialKey::GLOSS_MAP_BIT); return (*this); }
Builder& withoutRoughnessMap() { _value.reset(MaterialKey::ROUGHNESS_MAP_BIT); _mask.set(MaterialKey::ROUGHNESS_MAP_BIT); return (*this); }
Builder& withRoughnessMap() { _value.set(MaterialKey::ROUGHNESS_MAP_BIT); _mask.set(MaterialKey::ROUGHNESS_MAP_BIT); return (*this); }
Builder& withoutTransparent() { _value.reset(MaterialKey::TRANSPARENT_VAL_BIT); _mask.set(MaterialKey::TRANSPARENT_VAL_BIT); return (*this); }
Builder& withTransparent() { _value.set(MaterialKey::TRANSPARENT_VAL_BIT); _mask.set(MaterialKey::TRANSPARENT_VAL_BIT); return (*this); }
@ -241,14 +242,14 @@ public:
// Schema to access the attribute values of the material
class Schema {
public:
glm::vec3 _emissive{ 0.0f };
float _opacity{ 1.f };
glm::vec3 _emissive{ 0.0f }; // No Emissive
float _opacity{ 1.f }; // Opacity = 1 => Not Transparent
glm::vec3 _albedo{ 0.5f };
float _roughness{ 0.9f };
glm::vec3 _albedo{ 0.5f }; // Grey albedo => isAlbedo
float _roughness{ 1.0f }; // Roughness = 1 => Not Glossy
glm::vec3 _fresnel{ 0.03f };
float _metallic{ 0.0f };
glm::vec3 _fresnel{ 0.03f }; // Fresnel value for a default non metallic
float _metallic{ 0.0f }; // Not Metallic
glm::vec4 _spare0{ 0.0f };

View file

@ -54,25 +54,51 @@ enum Slot {
static const std::string DEFAULT_ALBEDO_SHADER {
"vec4 getFragmentColor() {"
" return vec4(pow(texture(albedoMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return vec4(pow(frag.diffuse, vec3(1.0 / 2.2)), 1.0);"
" }"
};
static const std::string DEFAULT_SPECULAR_SHADER {
static const std::string DEFAULT_FRESNEL_SHADER{
"vec4 getFragmentColor() {"
" return vec4(texture(specularMap, uv).xyz, 1.0);"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return vec4(pow(frag.specular, vec3(1.0 / 2.2)), 1.0);"
" }"
};
static const std::string DEFAULT_METALLIC_SHADER {
"vec4 getFragmentColor() {"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return vec4(vec3(frag.metallic), 1.0);"
" }"
};
static const std::string DEFAULT_ROUGHNESS_SHADER {
"vec4 getFragmentColor() {"
" return vec4(vec3(texture(specularMap, uv).a), 1.0);"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return vec4(vec3(frag.roughness), 1.0);"
" }"
};
static const std::string DEFAULT_NORMAL_SHADER {
"vec4 getFragmentColor() {"
" return vec4(normalize(texture(normalMap, uv).xyz * 2.0 - vec3(1.0)), 1.0);"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return vec4(normalize(frag.normal), 1.0);"
" }"
};
static const std::string DEFAULT_EMISSIVE_SHADER{
"vec4 getFragmentColor() {"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return (frag.mode != LIGHT_MAPPED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));"
" }"
};
static const std::string DEFAULT_LIGHTMAP_SHADER{
"vec4 getFragmentColor() {"
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
" return (frag.mode == LIGHT_MAPPED ? vec4(frag.emissive, 1.0) : vec4(vec3(0.0), 1.0));"
" }"
};
static const std::string DEFAULT_DEPTH_SHADER {
"vec4 getFragmentColor() {"
" return vec4(vec3(texture(depthMap, uv).x), 1.0);"
@ -146,14 +172,20 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust
switch (mode) {
case AlbedoMode:
return DEFAULT_ALBEDO_SHADER;
case SpecularMode:
return DEFAULT_SPECULAR_SHADER;
case FresnelMode:
return DEFAULT_FRESNEL_SHADER;
case MetallicMode:
return DEFAULT_METALLIC_SHADER;
case RoughnessMode:
return DEFAULT_ROUGHNESS_SHADER;
case NormalMode:
return DEFAULT_NORMAL_SHADER;
case DepthMode:
return DEFAULT_DEPTH_SHADER;
case EmissiveMode:
return DEFAULT_EMISSIVE_SHADER;
case LightmapMode:
return DEFAULT_LIGHTMAP_SHADER;
case LightingMode:
return DEFAULT_LIGHTING_SHADER;
case ShadowMode:

View file

@ -47,11 +47,14 @@ protected:
enum Mode : uint8_t {
// Use Mode suffix to avoid collisions
AlbedoMode = 0,
SpecularMode,
RoughnessMode,
DepthMode = 0,
AlbedoMode,
NormalMode,
DepthMode,
RoughnessMode,
MetallicMode,
FresnelMode,
EmissiveMode,
LightmapMode,
LightingMode,
ShadowMode,
PyramidDepthMode,

View file

@ -64,52 +64,73 @@ vec4 evalEyePositionFromZ(DeferredTransform deferredTransform, float depthVal, v
}
struct DeferredFragment {
float depthVal;
vec4 normalVal;
vec4 diffuseVal;
vec4 specularVal;
vec4 position;
vec3 normal;
float metallic;
vec3 diffuse;
float obscurance;
vec3 specular;
float gloss;
float roughness;
vec3 emissive;
int mode;
float depthVal;
};
const int LIGHT_MAPPED = 1;
DeferredFragment unpackDeferredFragment(DeferredTransform deferredTransform, vec2 texcoord) {
DeferredFragment frag;
frag.depthVal = texture(depthMap, texcoord).r;
frag.normalVal = texture(normalMap, texcoord);
frag.diffuseVal = texture(albedoMap, texcoord);
frag.specularVal = texture(specularMap, texcoord);
frag.obscurance = texture(obscuranceMap, texcoord).x;
vec4 unpackDeferredPosition(DeferredTransform deferredTransform, float depthValue, vec2 texcoord) {
if (getStereoMode(deferredTransform)) {
if (texcoord.x > 0.5) {
texcoord.x -= 0.5;
}
texcoord.x *= 2.0;
}
frag.position = evalEyePositionFromZ(deferredTransform, frag.depthVal, texcoord);
return evalEyePositionFromZ(deferredTransform, depthValue, texcoord);
}
DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) {
DeferredFragment frag;
frag.depthVal = -1;
frag.normalVal = texture(normalMap, texcoord);
frag.diffuseVal = texture(albedoMap, texcoord);
frag.specularVal = texture(specularMap, texcoord);
frag.obscurance = texture(obscuranceMap, texcoord).x;
// Unpack the normal from the map
frag.normal = normalize(frag.normalVal.xyz * 2.0 - vec3(1.0));
frag.mode = 0;
frag.emissive = vec3(0.0);
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
frag.mode = LIGHT_MAPPED;
frag.emissive = frag.specularVal.xyz;
}
frag.diffuse = frag.diffuseVal.xyz;
frag.specular = frag.specularVal.xyz;
frag.gloss = (frag.specularVal.w * 125)*(frag.specularVal.w * 125);
frag.metallic = length(frag.specularVal);
frag.roughness = frag.specularVal.w;
return frag;
}
DeferredFragment unpackDeferredFragment(DeferredTransform deferredTransform, vec2 texcoord) {
float depthValue = texture(depthMap, texcoord).r;
DeferredFragment frag = unpackDeferredFragmentNoPosition(texcoord);
frag.depthVal = depthValue;
frag.position = unpackDeferredPosition(deferredTransform, frag.depthVal, texcoord);
return frag;
}
<@endif@>

View file

@ -40,37 +40,40 @@ float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold));
}
const vec3 DEFAULT_SPECULAR = vec3(0.1);
const float DEFAULT_ROUGHNESS = 0.9;
const float DEFAULT_SHININESS = 10;
const float DEFAULT_METALLIC = 0;
const vec3 DEFAULT_SPECULAR = vec3(0.1);
void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float shininess) {
void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel) {
if (alpha != 1.0) {
discard;
}
_fragColor0 = vec4(albedo.rgb, 1.0); // Opaque
_fragColor1 = vec4(bestFitNormal(normal), 1.0);
_fragColor2 = vec4(fresnel, shininess);
_fragColor2 = vec4(fresnel, roughness);
}
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float shininess, vec3 emissive) {
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 emissive) {
if (alpha != 1.0) {
discard;
}
_fragColor0 = vec4(albedo.rgb, 0.5);
_fragColor1 = vec4(bestFitNormal(normal), 0.5);
_fragColor2 = vec4(emissive, shininess);
_fragColor2 = vec4(emissive, roughness);
}
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float shininess) {
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) {
if (alpha <= 0.0) {
discard;
}
_fragColor0 = vec4(albedo.rgb, alpha);
// _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
// _fragColor2 = vec4(fresnel, shininess);
// _fragColor2 = vec4(fresnel, roughness);
}
<@endif@>

View file

@ -30,7 +30,7 @@ vec4 evalSkyboxLight(vec3 direction, float lod) {
<@include model/Light.slh@>
<@func declareEvalAmbientGlobalColor()@>
vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float gloss) {
vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 fresnel, float roughness) {
// Need the light now
Light light = getLight();
@ -41,7 +41,7 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc
vec3 color = albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, fresnel, gloss);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, fresnel, roughness);
color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light);
@ -52,7 +52,7 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc
<@func declareEvalAmbientSphereGlobalColor()@>
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float gloss) {
vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 fresnel, float roughness) {
// Need the light now
Light light = getLight();
@ -64,7 +64,7 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa
vec3 color = albedo * evalSphericalLight(getLightAmbientSphere(light), ambientNormal).xyz * obscurance * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, fresnel, gloss);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, fresnel, roughness);
color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light);
@ -76,7 +76,7 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa
<$declareSkyboxMap()$>
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float gloss) {
vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 fresnel, float roughness) {
// Need the light now
Light light = getLight();
@ -87,7 +87,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu
vec3 color = albedo * evalSphericalLight(getLightAmbientSphere(light), fragNormal).xyz * obscurance * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, fresnel, gloss);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, fresnel, roughness);
color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light);

View file

@ -14,15 +14,17 @@
<@func declareEvalPBRShading()@>
// Frag Shading returns the diffuse amount as W and the specular rgb as xyz
vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) {
vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 specular, float roughness) {
// Diffuse Lighting
float diffuseDot = dot(fragNormal, fragLightDir);
float facingLight = step(0.0, diffuseDot);
float diffuse = diffuseDot * facingLight;
// Specular Lighting depends on the half vector and the gloss
// Specular Lighting depends on the half vector and the roughness
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
float gloss = (1.0 - roughness) * 128.0;
gloss *= gloss;
float specularPower = pow(max(0.0, dot(halfDir, fragNormal)), gloss);
specularPower *= (gloss * 0.125 + 0.25);
@ -38,15 +40,17 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp
<@func declareEvalBlinnRShading()@>
vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) {
vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float roughness) {
// Diffuse Lighting
float diffuseDot = dot(fragNormal, fragLightDir);
float facingLight = step(0.0, diffuseDot);
float diffuse = diffuseDot * facingLight;
// Specular Lighting depends on the half vector and the gloss
// Specular Lighting depends on the half vector and the roughness
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
float gloss = (1.0 - roughness) * 128.0;
glos *= gloss;
float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss);
vec3 reflect = specularPower * specular * diffuse;
@ -59,8 +63,8 @@ vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3
<$declareEvalPBRShading()$>
// Return xyz the specular/reflection component and w the diffuse component
vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) {
return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, specular, gloss);
vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 specular, float roughness) {
return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, specular, roughness);
}
<@endif@>

View file

@ -106,7 +106,7 @@ ShapeKey MeshPartPayload::getShapeKey() const {
if (drawMaterialKey.isNormalMap()) {
builder.withTangents();
}
if (drawMaterialKey.isGlossMap()) {
if (drawMaterialKey.isMetallicMap()) {
builder.withSpecular();
}
if (drawMaterialKey.isLightmapMap()) {
@ -175,6 +175,20 @@ 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];

View file

@ -44,8 +44,9 @@ void main(void) {
frag.position.xyz,
frag.normal,
frag.diffuse,
frag.metallic,
frag.specular,
frag.gloss);
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
}
}

View file

@ -46,8 +46,9 @@ void main(void) {
frag.position.xyz,
frag.normal,
frag.diffuse,
frag.metallic,
frag.specular,
frag.gloss);
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
}
}

View file

@ -45,8 +45,9 @@ void main(void) {
frag.position.xyz,
frag.normal,
frag.diffuse,
frag.metallic,
frag.specular,
frag.gloss);
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
}
}

View file

@ -47,8 +47,9 @@ void main(void) {
frag.position.xyz,
frag.normal,
frag.diffuse,
frag.metallic,
frag.specular,
frag.gloss);
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
}
}

View file

@ -45,8 +45,9 @@ void main(void) {
frag.position.xyz,
frag.normal,
frag.diffuse,
frag.metallic,
frag.specular,
frag.gloss);
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
}

View file

@ -47,8 +47,9 @@ void main(void) {
frag.position.xyz,
frag.normal,
frag.diffuse,
frag.metallic,
frag.specular,
frag.gloss);
frag.roughness);
_fragColor = vec4(color, frag.normalVal.a);
}

View file

@ -34,6 +34,7 @@ void main(void) {
normalize(_normal.xyz),
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
getMaterialAlbedo(mat) * albedo.rgb * _color,
getMaterialFresnel(mat),
getMaterialShininess(mat));
getMaterialRoughness(mat),
getMaterialMetallic(mat),
getMaterialFresnel(mat));
}

View file

@ -32,7 +32,8 @@ void main(void) {
normalize(_normal),
texel.a,
vec3(1.0),
getMaterialRoughness(mat),
getMaterialMetallic(mat),
getMaterialFresnel(mat),
getMaterialShininess(mat),
fragColor);
}

View file

@ -39,7 +39,8 @@ void main(void) {
normalize(_normal),
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
getMaterialAlbedo(mat) * albedo.rgb * _color,
getMaterialRoughness(mat),
getMaterialMetallic(mat),
getMaterialFresnel(mat),
getMaterialShininess(mat),
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
}

View file

@ -52,7 +52,8 @@ void main(void) {
normalize(viewNormal.xyz),
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
getMaterialAlbedo(mat) * albedo.rgb * _color,
getMaterialRoughness(mat),
getMaterialMetallic(mat),
getMaterialFresnel(mat),
getMaterialShininess(mat),
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
}

View file

@ -56,7 +56,8 @@ void main(void) {
normalize(viewNormal.xyz),
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
getMaterialAlbedo(mat) * albedo.rgb * _color,
getMaterialRoughness(mat),
getMaterialMetallic(mat),
specular, // no use of getMaterialFresnel(mat)
getMaterialShininess(mat),
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
}

View file

@ -44,7 +44,8 @@ void main(void) {
normalize(_normal),
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
getMaterialAlbedo(mat) * albedo.rgb * _color,
getMaterialRoughness(mat),
getMaterialMetallic(mat),
specular, // no use of getMaterialFresnel(mat)
getMaterialShininess(mat),
(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb));
}

View file

@ -45,6 +45,7 @@ void main(void) {
normalize(viewNormal.xyz),
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
getMaterialAlbedo(mat) * albedo.rgb * _color,
getMaterialFresnel(mat),
getMaterialShininess(mat));
getMaterialRoughness(mat),
getMaterialMetallic(mat),
getMaterialFresnel(mat));
}

View file

@ -50,6 +50,8 @@ void main(void) {
normalize(viewNormal.xyz),
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
getMaterialAlbedo(mat) * albedo.rgb * _color,
specular, //getMaterialFresnel(mat),
getMaterialShininess(mat));
getMaterialRoughness(mat),
getMaterialMetallic(mat),
specular //getMaterialFresnel(mat)
);
}

View file

@ -39,6 +39,8 @@ void main(void) {
normalize(_normal),
evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a),
getMaterialAlbedo(mat) * albedo.rgb * _color,
specular, //getMaterialFresnel(mat),
getMaterialShininess(mat));
getMaterialRoughness(mat),
getMaterialMetallic(mat),
specular //getMaterialFresnel(mat)
);
}

View file

@ -37,8 +37,9 @@ void main(void) {
vec3 fragPosition = _position.xyz;
vec3 fragNormal = normalize(_normal);
vec3 fragAlbedo = getMaterialAlbedo(mat) * albedo.rgb * _color;
float fragMetallic = getMaterialMetallic(mat);
vec3 fragFresnel = getMaterialFresnel(mat);
float fragGloss = getMaterialShininess(mat) / 128;
float fragRoughness = getMaterialRoughness(mat);
float fragOpacity = getMaterialOpacity(mat) * albedo.a * _alpha;
TransformCamera cam = getTransformCamera();
@ -50,7 +51,8 @@ void main(void) {
fragPosition,
fragNormal,
fragAlbedo,
fragMetallic,
fragFresnel,
fragGloss),
fragRoughness),
fragOpacity);
}

View file

@ -17,7 +17,7 @@
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, vec3 specular, float gloss, float opacity) {
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 specular, float roughness, float opacity) {
// Need the light now
Light light = getLight();
@ -30,7 +30,7 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a
vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, specular, roughness);
color += vec3(albedo * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
@ -53,8 +53,9 @@ void main(void) {
vec3 fragPosition = _position.xyz;
vec3 fragNormal = normalize(_normal);
vec3 fragAlbedo = albedo.rgb * _color;
float fragMetallic = 0.0;
vec3 fragSpecular = vec3(0.1);
float fragGloss = 10.0 / 128.0;
float fragRoughness = 0.9;
float fragOpacity = albedo.a;
if (fragOpacity <= 0.1) {
@ -65,8 +66,9 @@ void main(void) {
fragPosition,
fragNormal,
fragAlbedo,
fragMetallic,
fragSpecular,
fragGloss,
fragRoughness,
fragOpacity);
// Apply standard tone mapping

View file

@ -18,7 +18,7 @@
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, vec3 specular, float gloss, float opacity) {
vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 specular, float roughness, float opacity) {
// Need the light now
Light light = getLight();
@ -31,7 +31,7 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a
vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss);
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, specular, roughness);
color += vec3(albedo * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
@ -54,16 +54,18 @@ void main(void) {
vec3 fragPosition = _position.xyz;
vec3 fragNormal = normalize(_normal);
vec3 fragAlbedo = albedo.rgb * _color;
float fragMetallic = 0.0;
vec3 fragSpecular = vec3(0.1);
float fragGloss = 10.0 / 128.0;
float fragRoughness = 0.9;
float fragOpacity = albedo.a * _alpha;
vec4 color = evalGlobalColor(1.0,
fragPosition,
fragNormal,
fragAlbedo,
fragMetallic,
fragSpecular,
fragGloss,
fragRoughness,
fragOpacity);
// Apply standard tone mapping

View file

@ -60,7 +60,7 @@ void main(void) {
vec3 fragNormal = vec3(invViewMat * vec4(frag.normal, 0.0));
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.specular, frag.gloss);
vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.metallic, frag.specular, frag.roughness);
// Eval attenuation
float radialAttenuation = evalLightAttenuation(light, fragLightDistance);

View file

@ -10,6 +10,8 @@
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
<@include DeferredBufferWrite.slh@>
uniform sampler2D Font;
uniform bool Outline;
uniform vec4 Color;
@ -17,12 +19,11 @@ uniform vec4 Color;
// the interpolated normal
in vec3 _normal;
in vec2 _texCoord0;
/*
layout(location = 0) out vec4 _fragColor0;
layout(location = 1) out vec4 _fragColor1;
layout(location = 2) out vec4 _fragColor2;
const float DEFAULT_SHININESS = 10;
*/
const float gamma = 2.2;
const float smoothing = 256.0;
@ -53,7 +54,16 @@ void main() {
}
// final color
_fragColor0 = vec4(Color.rgb, Color.a * a);
/* _fragColor0 = vec4(Color.rgb, Color.a * a);
_fragColor1 = vec4(normalize(_normal.xyz), 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
_fragColor2 = vec4(Color.rgb, DEFAULT_SHININESS / 128.0);
_fragColor2 = vec4(Color.rgb, 10 / 128.0);
*/
packDeferredFragmentLightmap(
normalize(_normal),
Color.a * a,
Color.rgb,
DEFAULT_ROUGHNESS,
DEFAULT_METALLIC,
DEFAULT_SPECULAR,
Color.rgb);
}

View file

@ -51,9 +51,9 @@ void main(void) {
if (emissiveAmount > 0.0) {
packDeferredFragmentLightmap(
normal, 1.0, diffuse, specular, shininess, specular);
normal, 1.0, diffuse, max(0, 1.0 - shininess / 128.0), DEFAULT_METALLIC, specular, specular);
} else {
packDeferredFragment(
normal, 1.0, diffuse, specular, shininess);
normal, 1.0, diffuse, max(0, 1.0 - shininess / 128.0), DEFAULT_METALLIC, specular);
}
}

View file

@ -31,5 +31,7 @@ void main(void) {
normalize(_normal.xyz),
texel.a,
_color.rgb * texel.rgb,
DEFAULT_SPECULAR, DEFAULT_SHININESS);
DEFAULT_ROUGHNESS,
DEFAULT_METALLIC,
DEFAULT_SPECULAR);
}

View file

@ -29,6 +29,8 @@ void main(void) {
normalize(_normal),
texel.a,
_color.rgb,
DEFAULT_SPECULAR, DEFAULT_SHININESS,
DEFAULT_ROUGHNESS,
DEFAULT_METALLIC,
DEFAULT_SPECULAR,
texel.rgb);
}

View file

@ -66,7 +66,7 @@ void main(void) {
vec3 fragNormal = vec3(invViewMat * vec4(frag.normal, 0.0));
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.specular, frag.gloss);
vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.metallic, frag.specular, frag.roughness);
// Eval attenuation
float radialAttenuation = evalLightAttenuation(light, fragLightDistance);

View file

@ -24,5 +24,5 @@ void main(void) {
normalize(_normal.xyz),
1.0,
_color.rgb,
DEFAULT_SPECULAR, DEFAULT_SHININESS);
DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_SPECULAR);
}