mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 10:17:40 +02:00
Introducing the unlit material
This commit is contained in:
parent
3c80767ec3
commit
2d573963bb
18 changed files with 109 additions and 163 deletions
|
@ -991,7 +991,6 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
QString propname = subobject.name.data();
|
QString propname = subobject.name.data();
|
||||||
int unknown = 0;
|
int unknown = 0;
|
||||||
if ( (propname == "Version")
|
if ( (propname == "Version")
|
||||||
||(propname == "ShadingModel")
|
|
||||||
||(propname == "Multilayer")) {
|
||(propname == "Multilayer")) {
|
||||||
} else {
|
} else {
|
||||||
unknown++;
|
unknown++;
|
||||||
|
|
|
@ -212,6 +212,13 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
material._material->setRoughness(model::Material::shininessToRoughness(material.shininess));
|
material._material->setRoughness(model::Material::shininessToRoughness(material.shininess));
|
||||||
float metallic = std::max(material.specularColor.x, std::max(material.specularColor.y, material.specularColor.z));
|
float metallic = std::max(material.specularColor.x, std::max(material.specularColor.y, material.specularColor.z));
|
||||||
material._material->setMetallic(metallic);
|
material._material->setMetallic(metallic);
|
||||||
|
|
||||||
|
if (material.shadingModel == "lambert") {
|
||||||
|
if (!material._material->getKey().isAlbedo()) {
|
||||||
|
material._material->setUnlit(true);
|
||||||
|
std::cout << emissive;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material.opacity <= 0.0f) {
|
if (material.opacity <= 0.0f) {
|
||||||
|
|
|
@ -74,6 +74,11 @@ void Material::setOpacity(float opacity) {
|
||||||
_schemaBuffer.edit<Schema>()._opacity = opacity;
|
_schemaBuffer.edit<Schema>()._opacity = opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Material::setUnlit(bool value) {
|
||||||
|
_key.setUnlit(value);
|
||||||
|
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||||
|
}
|
||||||
|
|
||||||
void Material::setAlbedo(const Color& albedo, bool isSRGB) {
|
void Material::setAlbedo(const Color& albedo, bool isSRGB) {
|
||||||
_key.setAlbedo(glm::any(glm::greaterThan(albedo, Color(0.0f))));
|
_key.setAlbedo(glm::any(glm::greaterThan(albedo, Color(0.0f))));
|
||||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||||
|
|
|
@ -28,14 +28,15 @@ class MaterialKey {
|
||||||
public:
|
public:
|
||||||
enum FlagBit {
|
enum FlagBit {
|
||||||
EMISSIVE_VAL_BIT = 0,
|
EMISSIVE_VAL_BIT = 0,
|
||||||
|
UNLIT_VAL_BIT,
|
||||||
ALBEDO_VAL_BIT,
|
ALBEDO_VAL_BIT,
|
||||||
METALLIC_VAL_BIT,
|
METALLIC_VAL_BIT,
|
||||||
GLOSSY_VAL_BIT,
|
GLOSSY_VAL_BIT,
|
||||||
OPACITY_VAL_BIT,
|
OPACITY_VAL_BIT,
|
||||||
OPACITY_MASK_MAP_BIT, // OPacity Map and Opacity MASK map are mutually exclusive
|
OPACITY_MASK_MAP_BIT, // Opacity Map and Opacity MASK map are mutually exclusive
|
||||||
OPACITY_TRANSLUCENT_MAP_BIT,
|
OPACITY_TRANSLUCENT_MAP_BIT,
|
||||||
|
|
||||||
// THe map bits must be in the smae sequence as the enum names for the map channels
|
// THe map bits must be in the same sequence as the enum names for the map channels
|
||||||
EMISSIVE_MAP_BIT,
|
EMISSIVE_MAP_BIT,
|
||||||
ALBEDO_MAP_BIT,
|
ALBEDO_MAP_BIT,
|
||||||
METALLIC_MAP_BIT,
|
METALLIC_MAP_BIT,
|
||||||
|
@ -74,9 +75,12 @@ public:
|
||||||
MaterialKey build() const { return MaterialKey(_flags); }
|
MaterialKey build() const { return MaterialKey(_flags); }
|
||||||
|
|
||||||
Builder& withEmissive() { _flags.set(EMISSIVE_VAL_BIT); return (*this); }
|
Builder& withEmissive() { _flags.set(EMISSIVE_VAL_BIT); return (*this); }
|
||||||
|
Builder& withUnlit() { _flags.set(UNLIT_VAL_BIT); return (*this); }
|
||||||
|
|
||||||
Builder& withAlbedo() { _flags.set(ALBEDO_VAL_BIT); return (*this); }
|
Builder& withAlbedo() { _flags.set(ALBEDO_VAL_BIT); return (*this); }
|
||||||
Builder& withMetallic() { _flags.set(METALLIC_VAL_BIT); return (*this); }
|
Builder& withMetallic() { _flags.set(METALLIC_VAL_BIT); return (*this); }
|
||||||
Builder& withGlossy() { _flags.set(GLOSSY_VAL_BIT); return (*this); }
|
Builder& withGlossy() { _flags.set(GLOSSY_VAL_BIT); return (*this); }
|
||||||
|
|
||||||
Builder& withTranslucentFactor() { _flags.set(OPACITY_VAL_BIT); return (*this); }
|
Builder& withTranslucentFactor() { _flags.set(OPACITY_VAL_BIT); return (*this); }
|
||||||
|
|
||||||
Builder& withEmissiveMap() { _flags.set(EMISSIVE_MAP_BIT); return (*this); }
|
Builder& withEmissiveMap() { _flags.set(EMISSIVE_MAP_BIT); return (*this); }
|
||||||
|
@ -98,6 +102,9 @@ public:
|
||||||
void setEmissive(bool value) { _flags.set(EMISSIVE_VAL_BIT, value); }
|
void setEmissive(bool value) { _flags.set(EMISSIVE_VAL_BIT, value); }
|
||||||
bool isEmissive() const { return _flags[EMISSIVE_VAL_BIT]; }
|
bool isEmissive() const { return _flags[EMISSIVE_VAL_BIT]; }
|
||||||
|
|
||||||
|
void setUnlit(bool value) { _flags.set(UNLIT_VAL_BIT, value); }
|
||||||
|
bool isUnlit() const { return _flags[UNLIT_VAL_BIT]; }
|
||||||
|
|
||||||
void setEmissiveMap(bool value) { _flags.set(EMISSIVE_MAP_BIT, value); }
|
void setEmissiveMap(bool value) { _flags.set(EMISSIVE_MAP_BIT, value); }
|
||||||
bool isEmissiveMap() const { return _flags[EMISSIVE_MAP_BIT]; }
|
bool isEmissiveMap() const { return _flags[EMISSIVE_MAP_BIT]; }
|
||||||
|
|
||||||
|
@ -172,6 +179,9 @@ public:
|
||||||
Builder& withoutEmissiveMap() { _value.reset(MaterialKey::EMISSIVE_MAP_BIT); _mask.set(MaterialKey::EMISSIVE_MAP_BIT); return (*this); }
|
Builder& withoutEmissiveMap() { _value.reset(MaterialKey::EMISSIVE_MAP_BIT); _mask.set(MaterialKey::EMISSIVE_MAP_BIT); return (*this); }
|
||||||
Builder& withEmissiveMap() { _value.set(MaterialKey::EMISSIVE_MAP_BIT); _mask.set(MaterialKey::EMISSIVE_MAP_BIT); return (*this); }
|
Builder& withEmissiveMap() { _value.set(MaterialKey::EMISSIVE_MAP_BIT); _mask.set(MaterialKey::EMISSIVE_MAP_BIT); return (*this); }
|
||||||
|
|
||||||
|
Builder& withoutUnlit() { _value.reset(MaterialKey::UNLIT_VAL_BIT); _mask.set(MaterialKey::UNLIT_VAL_BIT); return (*this); }
|
||||||
|
Builder& withUnlit() { _value.set(MaterialKey::UNLIT_VAL_BIT); _mask.set(MaterialKey::UNLIT_VAL_BIT); return (*this); }
|
||||||
|
|
||||||
Builder& withoutAlbedo() { _value.reset(MaterialKey::ALBEDO_VAL_BIT); _mask.set(MaterialKey::ALBEDO_VAL_BIT); return (*this); }
|
Builder& withoutAlbedo() { _value.reset(MaterialKey::ALBEDO_VAL_BIT); _mask.set(MaterialKey::ALBEDO_VAL_BIT); return (*this); }
|
||||||
Builder& withAlbedo() { _value.set(MaterialKey::ALBEDO_VAL_BIT); _mask.set(MaterialKey::ALBEDO_VAL_BIT); return (*this); }
|
Builder& withAlbedo() { _value.set(MaterialKey::ALBEDO_VAL_BIT); _mask.set(MaterialKey::ALBEDO_VAL_BIT); return (*this); }
|
||||||
|
|
||||||
|
@ -250,6 +260,9 @@ public:
|
||||||
void setOpacity(float opacity);
|
void setOpacity(float opacity);
|
||||||
float getOpacity() const { return _schemaBuffer.get<Schema>()._opacity; }
|
float getOpacity() const { return _schemaBuffer.get<Schema>()._opacity; }
|
||||||
|
|
||||||
|
void setUnlit(bool value);
|
||||||
|
bool isUnlit() const { return _key.isUnlit(); }
|
||||||
|
|
||||||
void setAlbedo(const Color& albedo, bool isSRGB = true);
|
void setAlbedo(const Color& albedo, bool isSRGB = true);
|
||||||
Color getAlbedo(bool SRGB = true) const { return (SRGB ? ColorUtils::tosRGBVec3(_schemaBuffer.get<Schema>()._albedo) : _schemaBuffer.get<Schema>()._albedo); }
|
Color getAlbedo(bool SRGB = true) const { return (SRGB ? ColorUtils::tosRGBVec3(_schemaBuffer.get<Schema>()._albedo) : _schemaBuffer.get<Schema>()._albedo); }
|
||||||
|
|
||||||
|
|
|
@ -40,20 +40,21 @@ float getMaterialShininess(Material m) { return 1.0 - getMaterialRoughness(m); }
|
||||||
int getMaterialKey(Material m) { return floatBitsToInt(m._spareKey.w); }
|
int getMaterialKey(Material m) { return floatBitsToInt(m._spareKey.w); }
|
||||||
|
|
||||||
const int EMISSIVE_VAL_BIT = 0x00000001;
|
const int EMISSIVE_VAL_BIT = 0x00000001;
|
||||||
const int ALBEDO_VAL_BIT = 0x00000002;
|
const int UNLIT_VAL_BIT = 0x00000002;
|
||||||
const int METALLIC_VAL_BIT = 0x00000004;
|
const int ALBEDO_VAL_BIT = 0x00000004;
|
||||||
const int GLOSSY_VAL_BIT = 0x00000008;
|
const int METALLIC_VAL_BIT = 0x00000008;
|
||||||
const int OPACITY_VAL_BIT = 0x00000010;
|
const int GLOSSY_VAL_BIT = 0x00000010;
|
||||||
const int OPACITY_MASK_MAP_BIT = 0x00000020;
|
const int OPACITY_VAL_BIT = 0x00000020;
|
||||||
const int OPACITY_TRANSLUCENT_MAP_BIT = 0x00000040;
|
const int OPACITY_MASK_MAP_BIT = 0x00000040;
|
||||||
|
const int OPACITY_TRANSLUCENT_MAP_BIT = 0x00000080;
|
||||||
|
|
||||||
const int EMISSIVE_MAP_BIT = 0x00000080;
|
const int EMISSIVE_MAP_BIT = 0x00000100;
|
||||||
const int ALBEDO_MAP_BIT = 0x00000100;
|
const int ALBEDO_MAP_BIT = 0x00000200;
|
||||||
const int METALLIC_MAP_BIT = 0x00000200;
|
const int METALLIC_MAP_BIT = 0x00000400;
|
||||||
const int ROUGHNESS_MAP_BIT = 0x00000400;
|
const int ROUGHNESS_MAP_BIT = 0x00000800;
|
||||||
const int NORMAL_MAP_BIT = 0x00000800;
|
const int NORMAL_MAP_BIT = 0x00001000;
|
||||||
const int OCCLUSION_MAP_BIT = 0x00001000;
|
const int OCCLUSION_MAP_BIT = 0x00002000;
|
||||||
const int LIGHTMAP_MAP_BIT = 0x00002000;
|
const int LIGHTMAP_MAP_BIT = 0x00004000;
|
||||||
|
|
||||||
|
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
|
@ -90,14 +90,14 @@ static const std::string DEFAULT_OCCLUSION_SHADER{
|
||||||
static const std::string DEFAULT_EMISSIVE_SHADER{
|
static const std::string DEFAULT_EMISSIVE_SHADER{
|
||||||
"vec4 getFragmentColor() {"
|
"vec4 getFragmentColor() {"
|
||||||
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
" 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));"
|
" return (frag.mode != FRAG_MODE_LIGHTMAPPED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));"
|
||||||
" }"
|
" }"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::string DEFAULT_LIGHTMAP_SHADER{
|
static const std::string DEFAULT_LIGHTMAP_SHADER{
|
||||||
"vec4 getFragmentColor() {"
|
"vec4 getFragmentColor() {"
|
||||||
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
||||||
" return (frag.mode == LIGHT_MAPPED ? vec4(frag.emissive, 1.0) : vec4(vec3(0.0), 1.0));"
|
" return (frag.mode == FRAG_MODE_LIGHTMAPPED ? vec4(frag.emissive, 1.0) : vec4(vec3(0.0), 1.0));"
|
||||||
" }"
|
" }"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,135 +11,40 @@
|
||||||
<@if not DEFERRED_BUFFER_SLH@>
|
<@if not DEFERRED_BUFFER_SLH@>
|
||||||
<@def DEFERRED_BUFFER_SLH@>
|
<@def DEFERRED_BUFFER_SLH@>
|
||||||
|
|
||||||
|
// Unpack the metallic-mode value
|
||||||
|
const float FRAG_TYPE_UNLIT = 0.0;
|
||||||
|
const float FRAG_TYPE_SHADED_NON_METALLIC = 0.1;
|
||||||
|
const float FRAG_TYPE_SHADED_METALLIC = 0.2;
|
||||||
|
const float FRAG_TYPE_SHADED_RANGE_INV = 1.0 / (FRAG_TYPE_SHADED_METALLIC - FRAG_TYPE_SHADED_NON_METALLIC);
|
||||||
|
|
||||||
// the albedo texture
|
const float FRAG_TYPE_LIGHTMAPPED_NON_METALLIC = 0.3;
|
||||||
uniform sampler2D albedoMap;
|
const float FRAG_TYPE_LIGHTMAPPED_METALLIC = 0.4;
|
||||||
|
const float FRAG_TYPE_LIGHTMAPPED_RANGE_INV = 1.0 / (FRAG_TYPE_LIGHTMAPPED_METALLIC - FRAG_TYPE_LIGHTMAPPED_NON_METALLIC);
|
||||||
|
|
||||||
// the normal texture
|
const int FRAG_MODE_UNLIT = 0;
|
||||||
uniform sampler2D normalMap;
|
const int FRAG_MODE_SHADED = 1;
|
||||||
|
const int FRAG_MODE_LIGHTMAPPED = 2;
|
||||||
|
|
||||||
// the specular texture
|
void unpackModeMetallic(float rawValue, out int mode, out float metallic) {
|
||||||
uniform sampler2D specularMap;
|
if (rawValue < FRAG_TYPE_SHADED_NON_METALLIC) {
|
||||||
|
mode = FRAG_MODE_UNLIT;
|
||||||
// the depth texture
|
metallic = 0.0;
|
||||||
uniform sampler2D depthMap;
|
} else if (rawValue <= FRAG_TYPE_SHADED_METALLIC) {
|
||||||
|
mode = FRAG_MODE_SHADED;
|
||||||
// the obscurance texture
|
metallic = clamp((rawValue - FRAG_TYPE_SHADED_NON_METALLIC) * FRAG_TYPE_SHADED_RANGE_INV, 0.0, 1.0);
|
||||||
uniform sampler2D obscuranceMap;
|
} else if (rawValue <= FRAG_TYPE_LIGHTMAPPED_METALLIC) {
|
||||||
|
mode = FRAG_MODE_LIGHTMAPPED;
|
||||||
// the lighting texture
|
metallic = clamp((rawValue - FRAG_TYPE_LIGHTMAPPED_NON_METALLIC) * FRAG_TYPE_SHADED_RANGE_INV, 0.0, 1.0);
|
||||||
uniform sampler2D lightingMap;
|
}
|
||||||
|
|
||||||
|
|
||||||
struct DeferredTransform {
|
|
||||||
mat4 projection;
|
|
||||||
mat4 viewInverse;
|
|
||||||
float stereoSide;
|
|
||||||
vec3 _spareABC;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform deferredTransformBuffer {
|
|
||||||
DeferredTransform _deferredTransform;
|
|
||||||
};
|
|
||||||
DeferredTransform getDeferredTransform() {
|
|
||||||
return _deferredTransform;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getStereoMode(DeferredTransform deferredTransform) {
|
float packShadedMetallic(float metallic) {
|
||||||
return (deferredTransform.stereoSide != 0.0);
|
return mix(FRAG_TYPE_SHADED_NON_METALLIC, FRAG_TYPE_SHADED_METALLIC, metallic);
|
||||||
}
|
|
||||||
float getStereoSide(DeferredTransform deferredTransform) {
|
|
||||||
return (deferredTransform.stereoSide);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 evalEyePositionFromZ(DeferredTransform deferredTransform, float depthVal, vec2 texcoord) {
|
float packLightmappedMetallic(float metallic) {
|
||||||
vec3 nPos = vec3(texcoord.xy * 2.0f - 1.0f, depthVal * 2.0f - 1.0f);
|
return mix(FRAG_TYPE_LIGHTMAPPED_NON_METALLIC, FRAG_TYPE_LIGHTMAPPED_METALLIC, metallic);
|
||||||
|
|
||||||
// compute the view space position using the depth
|
|
||||||
// basically manually pick the proj matrix components to do the inverse
|
|
||||||
float Ze = -deferredTransform.projection[3][2] / (nPos.z + deferredTransform.projection[2][2]);
|
|
||||||
float Xe = (-Ze * nPos.x - Ze * deferredTransform.projection[2][0] - deferredTransform.projection[3][0]) / deferredTransform.projection[0][0];
|
|
||||||
float Ye = (-Ze * nPos.y - Ze * deferredTransform.projection[2][1] - deferredTransform.projection[3][1]) / deferredTransform.projection[1][1];
|
|
||||||
return vec4(Xe, Ye, Ze, 1.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DeferredFragment {
|
|
||||||
vec4 normalVal;
|
|
||||||
vec4 diffuseVal;
|
|
||||||
vec4 specularVal;
|
|
||||||
vec4 position;
|
|
||||||
vec3 normal;
|
|
||||||
float metallic;
|
|
||||||
vec3 diffuse;
|
|
||||||
float obscurance;
|
|
||||||
vec3 specular;
|
|
||||||
float roughness;
|
|
||||||
vec3 emissive;
|
|
||||||
int mode;
|
|
||||||
float depthVal;
|
|
||||||
};
|
|
||||||
|
|
||||||
const int LIGHT_MAPPED = 1;
|
|
||||||
|
|
||||||
vec4 unpackDeferredPosition(DeferredTransform deferredTransform, float depthValue, vec2 texcoord) {
|
|
||||||
if (getStereoMode(deferredTransform)) {
|
|
||||||
if (texcoord.x > 0.5) {
|
|
||||||
texcoord.x -= 0.5;
|
|
||||||
}
|
|
||||||
texcoord.x *= 2.0;
|
|
||||||
}
|
|
||||||
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 = frag.specularVal.xyz;
|
|
||||||
if (frag.normalVal.a < 0.5) {
|
|
||||||
frag.mode = 0;
|
|
||||||
frag.roughness = 2.0 * frag.normalVal.a;
|
|
||||||
} else {
|
|
||||||
frag.mode = LIGHT_MAPPED;
|
|
||||||
frag.roughness = 2.0 * frag.normalVal.a - 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
frag.metallic = frag.diffuseVal.a;
|
|
||||||
frag.diffuse = frag.diffuseVal.xyz;
|
|
||||||
if (frag.metallic <= 0.5) {
|
|
||||||
frag.metallic = 0.0;
|
|
||||||
frag.specular = vec3(0.03); // Default Di-electric fresnel value
|
|
||||||
} else {
|
|
||||||
frag.specular = vec3(frag.diffuseVal.xyz);
|
|
||||||
frag.metallic = 1.0;
|
|
||||||
}
|
|
||||||
frag.obscurance = min(frag.specularVal.w, frag.obscurance);
|
|
||||||
|
|
||||||
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@>
|
<@endif@>
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
<@if not DEFERRED_BUFFER_WRITE_SLH@>
|
<@if not DEFERRED_BUFFER_WRITE_SLH@>
|
||||||
<@def DEFERRED_BUFFER_WRITE_SLH@>
|
<@def DEFERRED_BUFFER_WRITE_SLH@>
|
||||||
|
|
||||||
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
layout(location = 0) out vec4 _fragColor0;
|
layout(location = 0) out vec4 _fragColor0;
|
||||||
layout(location = 1) out vec4 _fragColor1;
|
layout(location = 1) out vec4 _fragColor1;
|
||||||
layout(location = 2) out vec4 _fragColor2;
|
layout(location = 2) out vec4 _fragColor2;
|
||||||
|
@ -48,13 +50,12 @@ const vec3 DEFAULT_EMISSIVE = vec3(0.0);
|
||||||
const float DEFAULT_OCCLUSION = 1.0;
|
const float DEFAULT_OCCLUSION = 1.0;
|
||||||
const vec3 DEFAULT_FRESNEL = DEFAULT_EMISSIVE;
|
const vec3 DEFAULT_FRESNEL = DEFAULT_EMISSIVE;
|
||||||
|
|
||||||
|
|
||||||
void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion) {
|
void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion) {
|
||||||
if (alpha != 1.0) {
|
if (alpha != 1.0) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
_fragColor0 = vec4(albedo, metallic);
|
_fragColor0 = vec4(albedo, packShadedMetallic(metallic));
|
||||||
_fragColor1 = vec4(bestFitNormal(normal), 0.5 * clamp(roughness, 0.0, 1.0));
|
_fragColor1 = vec4(bestFitNormal(normal), clamp(roughness, 0.0, 1.0));
|
||||||
_fragColor2 = vec4(emissive, occlusion);
|
_fragColor2 = vec4(emissive, occlusion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,19 +64,25 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r
|
||||||
if (alpha != 1.0) {
|
if (alpha != 1.0) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
_fragColor0 = vec4(albedo, metallic);
|
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
|
||||||
_fragColor1 = vec4(bestFitNormal(normal), 0.5 + 0.5 * clamp(roughness, 0.0, 1.0));
|
_fragColor1 = vec4(bestFitNormal(normal), clamp(roughness, 0.0, 1.0));
|
||||||
_fragColor2 = vec4(emissive, 1.0);
|
_fragColor2 = vec4(emissive, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) {
|
||||||
|
if (alpha != 1.0) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
_fragColor0 = vec4(color, FRAG_TYPE_UNLIT);
|
||||||
|
_fragColor1 = vec4(bestFitNormal(normal), 1.0);
|
||||||
|
//_fragColor2 = vec4(vec3(0.0), 1.0); // If unlit, do not worry about the emissive color target
|
||||||
|
}
|
||||||
|
|
||||||
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) {
|
void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) {
|
||||||
if (alpha <= 0.0) {
|
if (alpha <= 0.0) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
_fragColor0 = vec4(albedo.rgb, alpha);
|
_fragColor0 = vec4(albedo.rgb, alpha);
|
||||||
// _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
|
||||||
// _fragColor2 = vec4(fresnel, roughness);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
|
|
||||||
uniform sampler2D pyramidMap;
|
uniform sampler2D pyramidMap;
|
||||||
uniform sampler2D occlusionMap;
|
uniform sampler2D occlusionMap;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
<@include DeferredGlobalLight.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
<$declareEvalLightmappedColor()$>
|
<$declareEvalLightmappedColor()$>
|
||||||
|
@ -27,7 +27,7 @@ void main(void) {
|
||||||
|
|
||||||
float shadowAttenuation = 1.0;
|
float shadowAttenuation = 1.0;
|
||||||
|
|
||||||
if (frag.mode == LIGHT_MAPPED) {
|
if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||||
vec3 color = evalLightmappedColor(
|
vec3 color = evalLightmappedColor(
|
||||||
deferredTransform.viewInverse,
|
deferredTransform.viewInverse,
|
||||||
shadowAttenuation,
|
shadowAttenuation,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
<@include Shadow.slh@>
|
<@include Shadow.slh@>
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
<@include DeferredGlobalLight.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
<$declareEvalLightmappedColor()$>
|
<$declareEvalLightmappedColor()$>
|
||||||
|
@ -29,7 +29,7 @@ void main(void) {
|
||||||
vec4 worldPos = deferredTransform.viewInverse * vec4(frag.position.xyz, 1.0);
|
vec4 worldPos = deferredTransform.viewInverse * vec4(frag.position.xyz, 1.0);
|
||||||
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
||||||
|
|
||||||
if (frag.mode == LIGHT_MAPPED) {
|
if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||||
vec3 color = evalLightmappedColor(
|
vec3 color = evalLightmappedColor(
|
||||||
deferredTransform.viewInverse,
|
deferredTransform.viewInverse,
|
||||||
shadowAttenuation,
|
shadowAttenuation,
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
<@include DeferredGlobalLight.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
<$declareEvalLightmappedColor()$>
|
<$declareEvalLightmappedColor()$>
|
||||||
|
@ -28,7 +28,7 @@ void main(void) {
|
||||||
float shadowAttenuation = 1.0;
|
float shadowAttenuation = 1.0;
|
||||||
|
|
||||||
// Light mapped or not ?
|
// Light mapped or not ?
|
||||||
if (frag.mode == LIGHT_MAPPED) {
|
if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||||
vec3 color = evalLightmappedColor(
|
vec3 color = evalLightmappedColor(
|
||||||
deferredTransform.viewInverse,
|
deferredTransform.viewInverse,
|
||||||
shadowAttenuation,
|
shadowAttenuation,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
<@include Shadow.slh@>
|
<@include Shadow.slh@>
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
<@include DeferredGlobalLight.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
<$declareEvalLightmappedColor()$>
|
<$declareEvalLightmappedColor()$>
|
||||||
|
@ -30,7 +30,7 @@ void main(void) {
|
||||||
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
||||||
|
|
||||||
// Light mapped or not ?
|
// Light mapped or not ?
|
||||||
if (frag.mode == LIGHT_MAPPED) {
|
if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||||
vec3 color = evalLightmappedColor(
|
vec3 color = evalLightmappedColor(
|
||||||
deferredTransform.viewInverse,
|
deferredTransform.viewInverse,
|
||||||
shadowAttenuation,
|
shadowAttenuation,
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
<@include DeferredGlobalLight.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
<$declareEvalLightmappedColor()$>
|
<$declareEvalLightmappedColor()$>
|
||||||
|
@ -28,7 +28,7 @@ void main(void) {
|
||||||
float shadowAttenuation = 1.0;
|
float shadowAttenuation = 1.0;
|
||||||
|
|
||||||
// Light mapped or not ?
|
// Light mapped or not ?
|
||||||
if (frag.mode == LIGHT_MAPPED) {
|
if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||||
vec3 color = evalLightmappedColor(
|
vec3 color = evalLightmappedColor(
|
||||||
deferredTransform.viewInverse,
|
deferredTransform.viewInverse,
|
||||||
shadowAttenuation,
|
shadowAttenuation,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//!>
|
//!>
|
||||||
|
|
||||||
<@include Shadow.slh@>
|
<@include Shadow.slh@>
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
<@include DeferredGlobalLight.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
<$declareEvalLightmappedColor()$>
|
<$declareEvalLightmappedColor()$>
|
||||||
|
@ -30,7 +30,7 @@ void main(void) {
|
||||||
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
||||||
|
|
||||||
// Light mapped or not ?
|
// Light mapped or not ?
|
||||||
if (frag.mode == LIGHT_MAPPED) {
|
if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||||
vec3 color = evalLightmappedColor(
|
vec3 color = evalLightmappedColor(
|
||||||
deferredTransform.viewInverse,
|
deferredTransform.viewInverse,
|
||||||
shadowAttenuation,
|
shadowAttenuation,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
|
|
||||||
//Everything about deferred lighting
|
//Everything about deferred lighting
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredLighting.slh@>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBufferRead.slh@>
|
||||||
|
|
||||||
//Everything about deferred lighting
|
//Everything about deferred lighting
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredLighting.slh@>
|
||||||
|
|
|
@ -191,10 +191,19 @@ int main (int argc, char** argv) {
|
||||||
targetStringStream << "#ifndef scribe_" << targetName << "_h" << std::endl;
|
targetStringStream << "#ifndef scribe_" << targetName << "_h" << std::endl;
|
||||||
targetStringStream << "#define scribe_" << targetName << "_h" << std::endl << std::endl;
|
targetStringStream << "#define scribe_" << targetName << "_h" << std::endl << std::endl;
|
||||||
|
|
||||||
// targetStringStream << "const char " << targetName << "[] = R\"XXXX(" << destStringStream.str() << ")XXXX\";";
|
std::istringstream destStringStreamAgain(destStringStream.str());
|
||||||
|
targetStringStream << "const char " << targetName << "[] = \n";
|
||||||
|
while (!destStringStreamAgain.eof()) {
|
||||||
|
std::string lineToken;
|
||||||
|
std::getline(destStringStreamAgain, lineToken);
|
||||||
|
targetStringStream << "R\"XXX(" << lineToken << ")XXX\"\"\\n\"\n";
|
||||||
|
}
|
||||||
|
targetStringStream << ";\n" << std::endl << std::endl;
|
||||||
|
/*
|
||||||
targetStringStream << "const char " << targetName << "[] = R\"SCRIBE(";
|
targetStringStream << "const char " << targetName << "[] = R\"SCRIBE(";
|
||||||
targetStringStream << destStringStream.str();
|
targetStringStream << destStringStream.str();
|
||||||
targetStringStream << "\n)SCRIBE\";\n\n";
|
targetStringStream << "\n)SCRIBE\";\n\n";
|
||||||
|
*/
|
||||||
targetStringStream << "#endif" << std::endl;
|
targetStringStream << "#endif" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
targetStringStream << destStringStream.str();
|
targetStringStream << destStringStream.str();
|
||||||
|
|
Loading…
Reference in a new issue