mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 13:03:11 +02:00
Merge pull request #7859 from samcake/lemon
Introduce the "Unlit" shading model support and apply it to Web Enitities
This commit is contained in:
commit
85272a87ba
45 changed files with 484 additions and 305 deletions
|
@ -104,7 +104,7 @@ void Image3DOverlay::render(RenderArgs* args) {
|
||||||
const render::ShapeKey Image3DOverlay::getShapeKey() {
|
const render::ShapeKey Image3DOverlay::getShapeKey() {
|
||||||
auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias();
|
auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias();
|
||||||
if (_emissive) {
|
if (_emissive) {
|
||||||
builder.withEmissive();
|
builder.withUnlit();
|
||||||
}
|
}
|
||||||
if (getAlpha() != 1.0f) {
|
if (getAlpha() != 1.0f) {
|
||||||
builder.withTranslucent();
|
builder.withTranslucent();
|
||||||
|
|
|
@ -210,7 +210,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->bindSimpleProgram(batch, textured, culled, emissive);
|
DependencyManager::get<GeometryCache>()->bindSimpleProgram(batch, textured, culled, emissive);
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f));
|
DependencyManager::get<GeometryCache>()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f, 1.0f, 1.0f, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::setSourceUrl(const QString& value) {
|
void RenderableWebEntityItem::setSourceUrl(const QString& value) {
|
||||||
|
|
|
@ -892,7 +892,10 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
properties = true;
|
properties = true;
|
||||||
propertyName = "P";
|
propertyName = "P";
|
||||||
index = 4;
|
index = 4;
|
||||||
|
} else if (subobject.name == "ShadingModel") {
|
||||||
|
material.shadingModel = subobject.properties.at(0).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties) {
|
if (properties) {
|
||||||
std::vector<std::string> unknowns;
|
std::vector<std::string> unknowns;
|
||||||
foreach(const FBXNode& property, subobject.children) {
|
foreach(const FBXNode& property, subobject.children) {
|
||||||
|
@ -988,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++;
|
||||||
|
@ -1130,7 +1132,6 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
ambientTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
ambientTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||||
} else if (type.contains("tex_ao_map")) {
|
} else if (type.contains("tex_ao_map")) {
|
||||||
occlusionTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
occlusionTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||||
|
|
||||||
} else if (type == "lcl rotation") {
|
} else if (type == "lcl rotation") {
|
||||||
localRotations.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
localRotations.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||||
} else if (type == "lcl translation") {
|
} else if (type == "lcl translation") {
|
||||||
|
|
|
@ -154,6 +154,7 @@ public:
|
||||||
|
|
||||||
QString materialID;
|
QString materialID;
|
||||||
QString name;
|
QString name;
|
||||||
|
QString shadingModel;
|
||||||
model::MaterialPointer _material;
|
model::MaterialPointer _material;
|
||||||
|
|
||||||
FBXTexture normalTexture;
|
FBXTexture normalTexture;
|
||||||
|
|
|
@ -72,6 +72,10 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
// foreach (const QString& materialID, materials) {
|
// foreach (const QString& materialID, materials) {
|
||||||
for (QHash<QString, FBXMaterial>::iterator it = _fbxMaterials.begin(); it != _fbxMaterials.end(); it++) {
|
for (QHash<QString, FBXMaterial>::iterator it = _fbxMaterials.begin(); it != _fbxMaterials.end(); it++) {
|
||||||
FBXMaterial& material = (*it);
|
FBXMaterial& material = (*it);
|
||||||
|
|
||||||
|
// Maya is the exporting the shading model and we aretrying to use it
|
||||||
|
bool isMaterialLambert = (material.shadingModel.toLower() == "lambert");
|
||||||
|
|
||||||
// the pure material associated with this part
|
// the pure material associated with this part
|
||||||
bool detectDifferentUVs = false;
|
bool detectDifferentUVs = false;
|
||||||
FBXTexture diffuseTexture;
|
FBXTexture diffuseTexture;
|
||||||
|
@ -171,6 +175,13 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
emissiveTexture = getTexture(emissiveTextureID);
|
emissiveTexture = getTexture(emissiveTextureID);
|
||||||
detectDifferentUVs |= (emissiveTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity());
|
detectDifferentUVs |= (emissiveTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity());
|
||||||
material.emissiveTexture = emissiveTexture;
|
material.emissiveTexture = emissiveTexture;
|
||||||
|
|
||||||
|
if (isMaterialLambert) {
|
||||||
|
// If the emissiveTextureID comes from the Texture bound to Emissive when material is lambert, we know it s exported from maya
|
||||||
|
// And the EMissiveColor is forced to 0.5 by Maya which is bad
|
||||||
|
// So we need to force it to 1.0
|
||||||
|
material.emissiveColor = vec3(1.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FBXTexture occlusionTexture;
|
FBXTexture occlusionTexture;
|
||||||
|
@ -198,7 +209,7 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
material._material = std::make_shared<model::Material>();
|
material._material = std::make_shared<model::Material>();
|
||||||
|
|
||||||
// Emissive color is the mix of emissiveColor with emissiveFactor
|
// Emissive color is the mix of emissiveColor with emissiveFactor
|
||||||
auto emissive = material.emissiveColor * material.emissiveFactor;
|
auto emissive = material.emissiveColor * (isMaterialLambert ? 1.0f : material.emissiveFactor); // In lambert there is not emissiveFactor
|
||||||
material._material->setEmissive(emissive);
|
material._material->setEmissive(emissive);
|
||||||
|
|
||||||
// Final diffuse color is the mix of diffuseColor with diffuseFactor
|
// Final diffuse color is the mix of diffuseColor with diffuseFactor
|
||||||
|
@ -212,6 +223,18 @@ 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 (isMaterialLambert) {
|
||||||
|
if (!material._material->getKey().isAlbedo()) {
|
||||||
|
// switch emissive to material albedo as we tag the material to unlit
|
||||||
|
material._material->setUnlit(true);
|
||||||
|
material._material->setAlbedo(emissive);
|
||||||
|
|
||||||
|
if (!material.emissiveTexture.isNull()) {
|
||||||
|
material.albedoTexture = material.emissiveTexture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,21 @@ 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_SHADED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));"
|
||||||
|
" }"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const std::string DEFAULT_UNLIT_SHADER{
|
||||||
|
"vec4 getFragmentColor() {"
|
||||||
|
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
||||||
|
" return (frag.mode == FRAG_MODE_UNLIT ? vec4(pow(frag.diffuse, 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(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));"
|
||||||
" }"
|
" }"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -184,6 +191,8 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust
|
||||||
return DEFAULT_DEPTH_SHADER;
|
return DEFAULT_DEPTH_SHADER;
|
||||||
case EmissiveMode:
|
case EmissiveMode:
|
||||||
return DEFAULT_EMISSIVE_SHADER;
|
return DEFAULT_EMISSIVE_SHADER;
|
||||||
|
case UnlitMode:
|
||||||
|
return DEFAULT_UNLIT_SHADER;
|
||||||
case OcclusionMode:
|
case OcclusionMode:
|
||||||
return DEFAULT_OCCLUSION_SHADER;
|
return DEFAULT_OCCLUSION_SHADER;
|
||||||
case LightmapMode:
|
case LightmapMode:
|
||||||
|
|
|
@ -53,6 +53,7 @@ protected:
|
||||||
RoughnessMode,
|
RoughnessMode,
|
||||||
MetallicMode,
|
MetallicMode,
|
||||||
EmissiveMode,
|
EmissiveMode,
|
||||||
|
UnlitMode,
|
||||||
OcclusionMode,
|
OcclusionMode,
|
||||||
LightmapMode,
|
LightmapMode,
|
||||||
LightingMode,
|
LightingMode,
|
||||||
|
|
|
@ -11,135 +11,44 @@
|
||||||
<@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_PACK_SHADED_NON_METALLIC = 0.0;
|
||||||
|
const float FRAG_PACK_SHADED_METALLIC = 0.1;
|
||||||
|
const float FRAG_PACK_SHADED_RANGE_INV = 1.0 / (FRAG_PACK_SHADED_METALLIC - FRAG_PACK_SHADED_NON_METALLIC);
|
||||||
|
|
||||||
// the albedo texture
|
const float FRAG_PACK_LIGHTMAPPED_NON_METALLIC = 0.2;
|
||||||
uniform sampler2D albedoMap;
|
const float FRAG_PACK_LIGHTMAPPED_METALLIC = 0.3;
|
||||||
|
const float FRAG_PACK_LIGHTMAPPED_RANGE_INV = 1.0 / (FRAG_PACK_LIGHTMAPPED_METALLIC - FRAG_PACK_LIGHTMAPPED_NON_METALLIC);
|
||||||
|
|
||||||
// the normal texture
|
const float FRAG_PACK_UNLIT = 0.5;
|
||||||
uniform sampler2D normalMap;
|
|
||||||
|
|
||||||
// the specular texture
|
const int FRAG_MODE_UNLIT = 0;
|
||||||
uniform sampler2D specularMap;
|
const int FRAG_MODE_SHADED = 1;
|
||||||
|
const int FRAG_MODE_LIGHTMAPPED = 2;
|
||||||
|
|
||||||
// the depth texture
|
void unpackModeMetallic(float rawValue, out int mode, out float metallic) {
|
||||||
uniform sampler2D depthMap;
|
if (rawValue <= FRAG_PACK_SHADED_METALLIC) {
|
||||||
|
mode = FRAG_MODE_SHADED;
|
||||||
// the obscurance texture
|
metallic = clamp((rawValue - FRAG_PACK_SHADED_NON_METALLIC) * FRAG_PACK_SHADED_RANGE_INV, 0.0, 1.0);
|
||||||
uniform sampler2D obscuranceMap;
|
} else if (rawValue <= FRAG_PACK_LIGHTMAPPED_METALLIC) {
|
||||||
|
mode = FRAG_MODE_LIGHTMAPPED;
|
||||||
// the lighting texture
|
metallic = clamp((rawValue - FRAG_PACK_LIGHTMAPPED_NON_METALLIC) * FRAG_PACK_SHADED_RANGE_INV, 0.0, 1.0);
|
||||||
uniform sampler2D lightingMap;
|
} else if (rawValue >= FRAG_PACK_UNLIT) {
|
||||||
|
mode = FRAG_MODE_UNLIT;
|
||||||
|
metallic = 0.0;
|
||||||
struct DeferredTransform {
|
|
||||||
mat4 projection;
|
|
||||||
mat4 viewInverse;
|
|
||||||
float stereoSide;
|
|
||||||
vec3 _spareABC;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform deferredTransformBuffer {
|
|
||||||
DeferredTransform _deferredTransform;
|
|
||||||
};
|
|
||||||
DeferredTransform getDeferredTransform() {
|
|
||||||
return _deferredTransform;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getStereoMode(DeferredTransform deferredTransform) {
|
|
||||||
return (deferredTransform.stereoSide != 0.0);
|
|
||||||
}
|
|
||||||
float getStereoSide(DeferredTransform deferredTransform) {
|
|
||||||
return (deferredTransform.stereoSide);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 evalEyePositionFromZ(DeferredTransform deferredTransform, float depthVal, vec2 texcoord) {
|
|
||||||
vec3 nPos = vec3(texcoord.xy * 2.0f - 1.0f, depthVal * 2.0f - 1.0f);
|
|
||||||
|
|
||||||
// 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) {
|
float packShadedMetallic(float metallic) {
|
||||||
|
return mix(FRAG_PACK_SHADED_NON_METALLIC, FRAG_PACK_SHADED_METALLIC, metallic);
|
||||||
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 packLightmappedMetallic(float metallic) {
|
||||||
|
return mix(FRAG_PACK_LIGHTMAPPED_NON_METALLIC, FRAG_PACK_LIGHTMAPPED_METALLIC, metallic);
|
||||||
float depthValue = texture(depthMap, texcoord).r;
|
|
||||||
|
|
||||||
DeferredFragment frag = unpackDeferredFragmentNoPosition(texcoord);
|
|
||||||
|
|
||||||
frag.depthVal = depthValue;
|
|
||||||
frag.position = unpackDeferredPosition(deferredTransform, frag.depthVal, texcoord);
|
|
||||||
|
|
||||||
return frag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float packUnlit() {
|
||||||
|
return FRAG_PACK_UNLIT;
|
||||||
|
}
|
||||||
|
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
140
libraries/render-utils/src/DeferredBufferRead.slh
Normal file
140
libraries/render-utils/src/DeferredBufferRead.slh
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
<!
|
||||||
|
// DeferredBufferRead.slh
|
||||||
|
// libraries/render-utils/src
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 5/4/16.
|
||||||
|
// Copyright 2013 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
!>
|
||||||
|
<@if not DEFERRED_BUFFER_READ_SLH@>
|
||||||
|
<@def DEFERRED_BUFFER_READ_SLH@>
|
||||||
|
|
||||||
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
|
// the albedo texture
|
||||||
|
uniform sampler2D albedoMap;
|
||||||
|
|
||||||
|
// the normal texture
|
||||||
|
uniform sampler2D normalMap;
|
||||||
|
|
||||||
|
// the specular texture
|
||||||
|
uniform sampler2D specularMap;
|
||||||
|
|
||||||
|
// the depth texture
|
||||||
|
uniform sampler2D depthMap;
|
||||||
|
|
||||||
|
// the obscurance texture
|
||||||
|
uniform sampler2D obscuranceMap;
|
||||||
|
|
||||||
|
// the lighting texture
|
||||||
|
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) {
|
||||||
|
return (deferredTransform.stereoSide != 0.0);
|
||||||
|
}
|
||||||
|
float getStereoSide(DeferredTransform deferredTransform) {
|
||||||
|
return (deferredTransform.stereoSide);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 evalEyePositionFromZ(DeferredTransform deferredTransform, float depthVal, vec2 texcoord) {
|
||||||
|
vec3 nPos = vec3(texcoord.xy * 2.0f - 1.0f, depthVal * 2.0f - 1.0f);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
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.roughness = 2.0 * frag.normalVal.a;
|
||||||
|
|
||||||
|
// Diffuse color and unpack the mode and the metallicness
|
||||||
|
frag.diffuse = frag.diffuseVal.xyz;
|
||||||
|
unpackModeMetallic(frag.diffuseVal.w, frag.mode, frag.metallic);
|
||||||
|
|
||||||
|
|
||||||
|
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.emissive = frag.specularVal.xyz;
|
||||||
|
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@>
|
|
@ -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, packUnlit());
|
||||||
|
_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@>
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
#include "simple_vert.h"
|
#include "simple_vert.h"
|
||||||
#include "simple_textured_frag.h"
|
#include "simple_textured_frag.h"
|
||||||
#include "simple_textured_emisive_frag.h"
|
#include "simple_textured_unlit_frag.h"
|
||||||
|
|
||||||
#include "grid_frag.h"
|
#include "grid_frag.h"
|
||||||
|
|
||||||
|
@ -1687,7 +1687,7 @@ public:
|
||||||
enum FlagBit {
|
enum FlagBit {
|
||||||
IS_TEXTURED_FLAG = 0,
|
IS_TEXTURED_FLAG = 0,
|
||||||
IS_CULLED_FLAG,
|
IS_CULLED_FLAG,
|
||||||
IS_EMISSIVE_FLAG,
|
IS_UNLIT_FLAG,
|
||||||
HAS_DEPTH_BIAS_FLAG,
|
HAS_DEPTH_BIAS_FLAG,
|
||||||
|
|
||||||
NUM_FLAGS,
|
NUM_FLAGS,
|
||||||
|
@ -1696,7 +1696,7 @@ public:
|
||||||
enum Flag {
|
enum Flag {
|
||||||
IS_TEXTURED = (1 << IS_TEXTURED_FLAG),
|
IS_TEXTURED = (1 << IS_TEXTURED_FLAG),
|
||||||
IS_CULLED = (1 << IS_CULLED_FLAG),
|
IS_CULLED = (1 << IS_CULLED_FLAG),
|
||||||
IS_EMISSIVE = (1 << IS_EMISSIVE_FLAG),
|
IS_UNLIT = (1 << IS_UNLIT_FLAG),
|
||||||
HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG),
|
HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG),
|
||||||
};
|
};
|
||||||
typedef unsigned short Flags;
|
typedef unsigned short Flags;
|
||||||
|
@ -1705,7 +1705,7 @@ public:
|
||||||
|
|
||||||
bool isTextured() const { return isFlag(IS_TEXTURED); }
|
bool isTextured() const { return isFlag(IS_TEXTURED); }
|
||||||
bool isCulled() const { return isFlag(IS_CULLED); }
|
bool isCulled() const { return isFlag(IS_CULLED); }
|
||||||
bool isEmissive() const { return isFlag(IS_EMISSIVE); }
|
bool isUnlit() const { return isFlag(IS_UNLIT); }
|
||||||
bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); }
|
bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); }
|
||||||
|
|
||||||
Flags _flags = 0;
|
Flags _flags = 0;
|
||||||
|
@ -1715,9 +1715,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
SimpleProgramKey(bool textured = false, bool culled = true,
|
SimpleProgramKey(bool textured = false, bool culled = true,
|
||||||
bool emissive = false, bool depthBias = false) {
|
bool unlit = false, bool depthBias = false) {
|
||||||
_flags = (textured ? IS_TEXTURED : 0) | (culled ? IS_CULLED : 0) |
|
_flags = (textured ? IS_TEXTURED : 0) | (culled ? IS_CULLED : 0) |
|
||||||
(emissive ? IS_EMISSIVE : 0) | (depthBias ? HAS_DEPTH_BIAS : 0);
|
(unlit ? IS_UNLIT : 0) | (depthBias ? HAS_DEPTH_BIAS : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleProgramKey(int bitmask) : _flags(bitmask) {}
|
SimpleProgramKey(int bitmask) : _flags(bitmask) {}
|
||||||
|
@ -1731,8 +1731,8 @@ inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) {
|
||||||
return a.getRaw() == b.getRaw();
|
return a.getRaw() == b.getRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool emissive, bool depthBiased) {
|
void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool unlit, bool depthBiased) {
|
||||||
batch.setPipeline(getSimplePipeline(textured, culled, emissive, depthBiased));
|
batch.setPipeline(getSimplePipeline(textured, culled, unlit, depthBiased));
|
||||||
|
|
||||||
// If not textured, set a default albedo map
|
// If not textured, set a default albedo map
|
||||||
if (!textured) {
|
if (!textured) {
|
||||||
|
@ -1744,23 +1744,23 @@ void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool cul
|
||||||
DependencyManager::get<TextureCache>()->getNormalFittingTexture());
|
DependencyManager::get<TextureCache>()->getNormalFittingTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled, bool emissive, bool depthBiased) {
|
gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled, bool unlit, bool depthBiased) {
|
||||||
SimpleProgramKey config{textured, culled, emissive, depthBiased};
|
SimpleProgramKey config{ textured, culled, unlit, depthBiased };
|
||||||
|
|
||||||
// Compile the shaders
|
// Compile the shaders
|
||||||
static std::once_flag once;
|
static std::once_flag once;
|
||||||
std::call_once(once, [&]() {
|
std::call_once(once, [&]() {
|
||||||
auto VS = gpu::Shader::createVertex(std::string(simple_vert));
|
auto VS = gpu::Shader::createVertex(std::string(simple_vert));
|
||||||
auto PS = gpu::Shader::createPixel(std::string(simple_textured_frag));
|
auto PS = gpu::Shader::createPixel(std::string(simple_textured_frag));
|
||||||
auto PSEmissive = gpu::Shader::createPixel(std::string(simple_textured_emisive_frag));
|
auto PSUnlit = gpu::Shader::createPixel(std::string(simple_textured_unlit_frag));
|
||||||
|
|
||||||
_simpleShader = gpu::Shader::createProgram(VS, PS);
|
_simpleShader = gpu::Shader::createProgram(VS, PS);
|
||||||
_emissiveShader = gpu::Shader::createProgram(VS, PSEmissive);
|
_unlitShader = gpu::Shader::createProgram(VS, PSUnlit);
|
||||||
|
|
||||||
gpu::Shader::BindingSet slotBindings;
|
gpu::Shader::BindingSet slotBindings;
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::MAP::NORMAL_FITTING));
|
slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::MAP::NORMAL_FITTING));
|
||||||
gpu::Shader::makeProgram(*_simpleShader, slotBindings);
|
gpu::Shader::makeProgram(*_simpleShader, slotBindings);
|
||||||
gpu::Shader::makeProgram(*_emissiveShader, slotBindings);
|
gpu::Shader::makeProgram(*_unlitShader, slotBindings);
|
||||||
});
|
});
|
||||||
|
|
||||||
// If the pipeline already exists, return it
|
// If the pipeline already exists, return it
|
||||||
|
@ -1785,7 +1785,7 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled
|
||||||
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||||
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||||
|
|
||||||
gpu::ShaderPointer program = (config.isEmissive()) ? _emissiveShader : _simpleShader;
|
gpu::ShaderPointer program = (config.isUnlit()) ? _unlitShader : _simpleShader;
|
||||||
gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state);
|
gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state);
|
||||||
_simplePrograms.insert(config, pipeline);
|
_simplePrograms.insert(config, pipeline);
|
||||||
return pipeline;
|
return pipeline;
|
||||||
|
|
|
@ -153,10 +153,10 @@ public:
|
||||||
|
|
||||||
// Bind the pipeline and get the state to render static geometry
|
// Bind the pipeline and get the state to render static geometry
|
||||||
void bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true,
|
void bindSimpleProgram(gpu::Batch& batch, bool textured = false, bool culled = true,
|
||||||
bool emissive = false, bool depthBias = false);
|
bool unlit = false, bool depthBias = false);
|
||||||
// Get the pipeline to render static geometry
|
// Get the pipeline to render static geometry
|
||||||
gpu::PipelinePointer getSimplePipeline(bool textured = false, bool culled = true,
|
gpu::PipelinePointer getSimplePipeline(bool textured = false, bool culled = true,
|
||||||
bool emissive = false, bool depthBias = false);
|
bool unlit = false, bool depthBias = false);
|
||||||
render::ShapePipelinePointer getShapePipeline() { return GeometryCache::_simplePipeline; }
|
render::ShapePipelinePointer getShapePipeline() { return GeometryCache::_simplePipeline; }
|
||||||
|
|
||||||
// Static (instanced) geometry
|
// Static (instanced) geometry
|
||||||
|
@ -393,7 +393,7 @@ private:
|
||||||
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
||||||
|
|
||||||
gpu::ShaderPointer _simpleShader;
|
gpu::ShaderPointer _simpleShader;
|
||||||
gpu::ShaderPointer _emissiveShader;
|
gpu::ShaderPointer _unlitShader;
|
||||||
static render::ShapePipelinePointer _simplePipeline;
|
static render::ShapePipelinePointer _simplePipeline;
|
||||||
QHash<SimpleProgramKey, gpu::PipelinePointer> _simplePrograms;
|
QHash<SimpleProgramKey, gpu::PipelinePointer> _simplePrograms;
|
||||||
};
|
};
|
||||||
|
|
|
@ -157,7 +157,7 @@ vec3 fetchLightmapMap(vec2 uv) {
|
||||||
}
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
<@func $discardTransparent(opacity)@>
|
<@func discardTransparent(opacity)@>
|
||||||
{
|
{
|
||||||
if (<$opacity$> < 1.0) {
|
if (<$opacity$> < 1.0) {
|
||||||
discard;
|
discard;
|
||||||
|
|
|
@ -144,6 +144,11 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
|
||||||
auto materialKey = _drawMaterial->getKey();
|
auto materialKey = _drawMaterial->getKey();
|
||||||
auto textureMaps = _drawMaterial->getTextureMaps();
|
auto textureMaps = _drawMaterial->getTextureMaps();
|
||||||
|
|
||||||
|
int numUnlit = 0;
|
||||||
|
if (materialKey.isUnlit()) {
|
||||||
|
numUnlit++;
|
||||||
|
}
|
||||||
|
|
||||||
// Albedo
|
// Albedo
|
||||||
if (materialKey.isAlbedoMap()) {
|
if (materialKey.isAlbedoMap()) {
|
||||||
auto albedoMap = textureMaps[model::MaterialKey::ALBEDO_MAP];
|
auto albedoMap = textureMaps[model::MaterialKey::ALBEDO_MAP];
|
||||||
|
@ -414,6 +419,7 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
|
||||||
bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty();
|
bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty();
|
||||||
bool hasSpecular = drawMaterialKey.isMetallicMap();
|
bool hasSpecular = drawMaterialKey.isMetallicMap();
|
||||||
bool hasLightmap = drawMaterialKey.isLightmapMap();
|
bool hasLightmap = drawMaterialKey.isLightmapMap();
|
||||||
|
bool isUnlit = drawMaterialKey.isUnlit();
|
||||||
|
|
||||||
bool isSkinned = _isSkinned;
|
bool isSkinned = _isSkinned;
|
||||||
bool wireframe = _model->isWireframe();
|
bool wireframe = _model->isWireframe();
|
||||||
|
@ -435,6 +441,9 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
|
||||||
if (hasLightmap) {
|
if (hasLightmap) {
|
||||||
builder.withLightmap();
|
builder.withLightmap();
|
||||||
}
|
}
|
||||||
|
if (isUnlit) {
|
||||||
|
builder.withUnlit();
|
||||||
|
}
|
||||||
if (isSkinned) {
|
if (isSkinned) {
|
||||||
builder.withSkinned();
|
builder.withSkinned();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "skin_model_normal_map_vert.h"
|
#include "skin_model_normal_map_vert.h"
|
||||||
|
|
||||||
#include "model_frag.h"
|
#include "model_frag.h"
|
||||||
#include "model_emissive_frag.h"
|
#include "model_unlit_frag.h"
|
||||||
#include "model_shadow_frag.h"
|
#include "model_shadow_frag.h"
|
||||||
#include "model_normal_map_frag.h"
|
#include "model_normal_map_frag.h"
|
||||||
#include "model_normal_specular_map_frag.h"
|
#include "model_normal_specular_map_frag.h"
|
||||||
|
@ -37,13 +37,13 @@
|
||||||
#include "model_lightmap_normal_specular_map_frag.h"
|
#include "model_lightmap_normal_specular_map_frag.h"
|
||||||
#include "model_lightmap_specular_map_frag.h"
|
#include "model_lightmap_specular_map_frag.h"
|
||||||
#include "model_translucent_frag.h"
|
#include "model_translucent_frag.h"
|
||||||
#include "model_translucent_emissive_frag.h"
|
#include "model_translucent_unlit_frag.h"
|
||||||
|
|
||||||
#include "overlay3D_vert.h"
|
#include "overlay3D_vert.h"
|
||||||
#include "overlay3D_frag.h"
|
#include "overlay3D_frag.h"
|
||||||
#include "overlay3D_translucent_frag.h"
|
#include "overlay3D_translucent_frag.h"
|
||||||
#include "overlay3D_emissive_frag.h"
|
#include "overlay3D_unlit_frag.h"
|
||||||
#include "overlay3D_translucent_emissive_frag.h"
|
#include "overlay3D_translucent_unlit_frag.h"
|
||||||
|
|
||||||
#include "drawOpaqueStencil_frag.h"
|
#include "drawOpaqueStencil_frag.h"
|
||||||
|
|
||||||
|
@ -102,13 +102,13 @@ void initOverlay3DPipelines(ShapePlumber& plumber) {
|
||||||
auto vertex = gpu::Shader::createVertex(std::string(overlay3D_vert));
|
auto vertex = gpu::Shader::createVertex(std::string(overlay3D_vert));
|
||||||
auto pixel = gpu::Shader::createPixel(std::string(overlay3D_frag));
|
auto pixel = gpu::Shader::createPixel(std::string(overlay3D_frag));
|
||||||
auto pixelTranslucent = gpu::Shader::createPixel(std::string(overlay3D_translucent_frag));
|
auto pixelTranslucent = gpu::Shader::createPixel(std::string(overlay3D_translucent_frag));
|
||||||
auto pixelEmissive = gpu::Shader::createPixel(std::string(overlay3D_emissive_frag));
|
auto pixelUnlit = gpu::Shader::createPixel(std::string(overlay3D_unlit_frag));
|
||||||
auto pixelTranslucentEmissive = gpu::Shader::createPixel(std::string(overlay3D_translucent_emissive_frag));
|
auto pixelTranslucentUnlit = gpu::Shader::createPixel(std::string(overlay3D_translucent_unlit_frag));
|
||||||
|
|
||||||
auto opaqueProgram = gpu::Shader::createProgram(vertex, pixel);
|
auto opaqueProgram = gpu::Shader::createProgram(vertex, pixel);
|
||||||
auto translucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucent);
|
auto translucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucent);
|
||||||
auto emissiveOpaqueProgram = gpu::Shader::createProgram(vertex, pixelEmissive);
|
auto unlitOpaqueProgram = gpu::Shader::createProgram(vertex, pixelUnlit);
|
||||||
auto emissiveTranslucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucentEmissive);
|
auto unlitTranslucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucentUnlit);
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
bool isCulled = (i & 1);
|
bool isCulled = (i & 1);
|
||||||
|
@ -138,9 +138,9 @@ void initOverlay3DPipelines(ShapePlumber& plumber) {
|
||||||
isOpaque ? builder.withOpaque() : builder.withTranslucent();
|
isOpaque ? builder.withOpaque() : builder.withTranslucent();
|
||||||
|
|
||||||
auto simpleProgram = isOpaque ? opaqueProgram : translucentProgram;
|
auto simpleProgram = isOpaque ? opaqueProgram : translucentProgram;
|
||||||
auto emissiveProgram = isOpaque ? emissiveOpaqueProgram : emissiveTranslucentProgram;
|
auto unlitProgram = isOpaque ? unlitOpaqueProgram : unlitTranslucentProgram;
|
||||||
plumber.addPipeline(builder.withoutEmissive().build(), simpleProgram, state, &lightBatchSetter);
|
plumber.addPipeline(builder.withoutUnlit().build(), simpleProgram, state, &lightBatchSetter);
|
||||||
plumber.addPipeline(builder.withEmissive().build(), emissiveProgram, state, &batchSetter);
|
plumber.addPipeline(builder.withUnlit().build(), unlitProgram, state, &batchSetter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,12 +201,12 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
||||||
|
|
||||||
// Pixel shaders
|
// Pixel shaders
|
||||||
auto modelPixel = gpu::Shader::createPixel(std::string(model_frag));
|
auto modelPixel = gpu::Shader::createPixel(std::string(model_frag));
|
||||||
auto modelEmissivePixel = gpu::Shader::createPixel(std::string(model_emissive_frag));
|
auto modelUnlitPixel = gpu::Shader::createPixel(std::string(model_unlit_frag));
|
||||||
auto modelNormalMapPixel = gpu::Shader::createPixel(std::string(model_normal_map_frag));
|
auto modelNormalMapPixel = gpu::Shader::createPixel(std::string(model_normal_map_frag));
|
||||||
auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_specular_map_frag));
|
auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_specular_map_frag));
|
||||||
auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_frag));
|
auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_frag));
|
||||||
auto modelTranslucentPixel = gpu::Shader::createPixel(std::string(model_translucent_frag));
|
auto modelTranslucentPixel = gpu::Shader::createPixel(std::string(model_translucent_frag));
|
||||||
auto modelTranslucentEmissivePixel = gpu::Shader::createPixel(std::string(model_translucent_emissive_frag));
|
auto modelTranslucentUnlitPixel = gpu::Shader::createPixel(std::string(model_translucent_unlit_frag));
|
||||||
auto modelShadowPixel = gpu::Shader::createPixel(std::string(model_shadow_frag));
|
auto modelShadowPixel = gpu::Shader::createPixel(std::string(model_shadow_frag));
|
||||||
auto modelLightmapPixel = gpu::Shader::createPixel(std::string(model_lightmap_frag));
|
auto modelLightmapPixel = gpu::Shader::createPixel(std::string(model_lightmap_frag));
|
||||||
auto modelLightmapNormalMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag));
|
auto modelLightmapNormalMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag));
|
||||||
|
@ -219,8 +219,8 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
||||||
Key::Builder(),
|
Key::Builder(),
|
||||||
modelVertex, modelPixel);
|
modelVertex, modelPixel);
|
||||||
addPipeline(
|
addPipeline(
|
||||||
Key::Builder().withEmissive(),
|
Key::Builder().withUnlit(),
|
||||||
modelVertex, modelEmissivePixel);
|
modelVertex, modelUnlitPixel);
|
||||||
addPipeline(
|
addPipeline(
|
||||||
Key::Builder().withTangents(),
|
Key::Builder().withTangents(),
|
||||||
modelNormalMapVertex, modelNormalMapPixel);
|
modelNormalMapVertex, modelNormalMapPixel);
|
||||||
|
@ -235,8 +235,8 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
||||||
Key::Builder().withTranslucent(),
|
Key::Builder().withTranslucent(),
|
||||||
modelVertex, modelTranslucentPixel);
|
modelVertex, modelTranslucentPixel);
|
||||||
addPipeline(
|
addPipeline(
|
||||||
Key::Builder().withTranslucent().withEmissive(),
|
Key::Builder().withTranslucent().withUnlit(),
|
||||||
modelVertex, modelTranslucentEmissivePixel);
|
modelVertex, modelTranslucentUnlitPixel);
|
||||||
addPipeline(
|
addPipeline(
|
||||||
Key::Builder().withTranslucent().withTangents(),
|
Key::Builder().withTranslucent().withTangents(),
|
||||||
modelNormalMapVertex, modelTranslucentPixel);
|
modelNormalMapVertex, modelTranslucentPixel);
|
||||||
|
@ -296,4 +296,5 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
||||||
addPipeline(
|
addPipeline(
|
||||||
Key::Builder().withSkinned().withDepthOnly(),
|
Key::Builder().withSkinned().withDepthOnly(),
|
||||||
skinModelShadowVertex, modelShadowPixel);
|
skinModelShadowVertex, modelShadowPixel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,9 @@ void main(void) {
|
||||||
|
|
||||||
float shadowAttenuation = 1.0;
|
float shadowAttenuation = 1.0;
|
||||||
|
|
||||||
if (frag.mode == LIGHT_MAPPED) {
|
if (frag.mode == FRAG_MODE_UNLIT) {
|
||||||
|
_fragColor = vec4(frag.diffuse, 1.0);
|
||||||
|
} else 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,9 @@ 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_UNLIT) {
|
||||||
|
_fragColor = vec4(frag.diffuse, 1.0);
|
||||||
|
} else 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,9 @@ 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_UNLIT) {
|
||||||
|
_fragColor = vec4(frag.diffuse, 1.0);
|
||||||
|
} else 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,9 @@ 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_UNLIT) {
|
||||||
|
_fragColor = vec4(frag.diffuse, 1.0);
|
||||||
|
} else 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,9 @@ 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_UNLIT) {
|
||||||
|
_fragColor = vec4(frag.diffuse, 1.0);
|
||||||
|
} else 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,9 @@ 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_UNLIT) {
|
||||||
|
_fragColor = vec4(frag.diffuse, 1.0);
|
||||||
|
} else if (frag.mode == FRAG_MODE_LIGHTMAPPED) {
|
||||||
vec3 color = evalLightmappedColor(
|
vec3 color = evalLightmappedColor(
|
||||||
deferredTransform.viewInverse,
|
deferredTransform.viewInverse,
|
||||||
shadowAttenuation,
|
shadowAttenuation,
|
||||||
|
|
|
@ -30,7 +30,7 @@ void main(void) {
|
||||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
||||||
|
|
||||||
float opacity = 1.0;
|
float opacity = 1.0;
|
||||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||||
<$discardTransparent(opacity)$>;
|
<$discardTransparent(opacity)$>;
|
||||||
|
|
||||||
vec3 albedo = getMaterialAlbedo(mat);
|
vec3 albedo = getMaterialAlbedo(mat);
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
<@include gpu/Config.slh@>
|
|
||||||
<$VERSION_HEADER$>
|
|
||||||
// Generated on <$_SCRIBE_DATE$>
|
|
||||||
//
|
|
||||||
// model_emissive.frag
|
|
||||||
// fragment shader
|
|
||||||
//
|
|
||||||
// Created by Zach Pomerantz on 2/3/2016.
|
|
||||||
// Copyright 2016 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// 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@>
|
|
||||||
<@include model/Material.slh@>
|
|
||||||
|
|
||||||
uniform sampler2D albedoMap;
|
|
||||||
|
|
||||||
in vec2 _texCoord0;
|
|
||||||
in vec3 _normal;
|
|
||||||
in vec3 _color;
|
|
||||||
in float _alpha;
|
|
||||||
|
|
||||||
void main(void) {
|
|
||||||
vec4 texel = texture(albedoMap, _texCoord0);
|
|
||||||
|
|
||||||
Material mat = getMaterial();
|
|
||||||
vec3 fragColor = getMaterialAlbedo(mat) * texel.rgb * _color;
|
|
||||||
|
|
||||||
packDeferredFragmentLightmap(
|
|
||||||
normalize(_normal),
|
|
||||||
texel.a,
|
|
||||||
vec3(1.0),
|
|
||||||
getMaterialRoughness(mat),
|
|
||||||
getMaterialMetallic(mat),
|
|
||||||
getMaterialFresnel(mat),
|
|
||||||
fragColor);
|
|
||||||
}
|
|
|
@ -31,7 +31,7 @@ void main(void) {
|
||||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
||||||
|
|
||||||
float opacity = 1.0;
|
float opacity = 1.0;
|
||||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||||
<$discardTransparent(opacity)$>;
|
<$discardTransparent(opacity)$>;
|
||||||
|
|
||||||
vec3 albedo = getMaterialAlbedo(mat);
|
vec3 albedo = getMaterialAlbedo(mat);
|
||||||
|
|
|
@ -31,7 +31,7 @@ void main(void) {
|
||||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex, occlusionTex)$>
|
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex, occlusionTex)$>
|
||||||
|
|
||||||
float opacity = 1.0;
|
float opacity = 1.0;
|
||||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||||
<$discardTransparent(opacity)$>;
|
<$discardTransparent(opacity)$>;
|
||||||
|
|
||||||
vec3 albedo = getMaterialAlbedo(mat);
|
vec3 albedo = getMaterialAlbedo(mat);
|
||||||
|
|
|
@ -38,8 +38,7 @@ void main(void) {
|
||||||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
||||||
|
|
||||||
float opacity = getMaterialOpacity(mat) * _alpha;
|
float opacity = getMaterialOpacity(mat) * _alpha;
|
||||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||||
<$discardTransparent(opacity)$>;
|
|
||||||
|
|
||||||
vec3 albedo = getMaterialAlbedo(mat);
|
vec3 albedo = getMaterialAlbedo(mat);
|
||||||
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
<@include gpu/Config.slh@>
|
|
||||||
<$VERSION_HEADER$>
|
|
||||||
// Generated on <$_SCRIBE_DATE$>
|
|
||||||
//
|
|
||||||
// model_translucent_emissive.frag
|
|
||||||
// fragment shader
|
|
||||||
//
|
|
||||||
// Created by Zach Pomerantz on 2/3/2016.
|
|
||||||
// Copyright 2016 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
<@include model/Material.slh@>
|
|
||||||
|
|
||||||
uniform sampler2D albedoMap;
|
|
||||||
|
|
||||||
in vec2 _texCoord0;
|
|
||||||
in vec3 _color;
|
|
||||||
in float _alpha;
|
|
||||||
|
|
||||||
out vec4 _fragColor;
|
|
||||||
|
|
||||||
void main(void) {
|
|
||||||
vec4 albedo = texture(albedoMap, _texCoord0);
|
|
||||||
|
|
||||||
Material mat = getMaterial();
|
|
||||||
vec3 fragColor = getMaterialAlbedo(mat) * albedo.rgb * _color;
|
|
||||||
float fragOpacity = getMaterialOpacity(mat) * albedo.a * _alpha;
|
|
||||||
|
|
||||||
_fragColor = vec4(fragColor, fragOpacity);
|
|
||||||
}
|
|
39
libraries/render-utils/src/model_translucent_unlit.slf
Normal file
39
libraries/render-utils/src/model_translucent_unlit.slf
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<@include gpu/Config.slh@>
|
||||||
|
<$VERSION_HEADER$>
|
||||||
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
|
//
|
||||||
|
// model_translucent_unlit.frag
|
||||||
|
// fragment shader
|
||||||
|
//
|
||||||
|
// Created by Zach Pomerantz on 2/3/2016.
|
||||||
|
// Copyright 2016 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
<@include model/Material.slh@>
|
||||||
|
|
||||||
|
<@include MaterialTextures.slh@>
|
||||||
|
<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$>
|
||||||
|
|
||||||
|
in vec2 _texCoord0;
|
||||||
|
in vec3 _color;
|
||||||
|
in float _alpha;
|
||||||
|
|
||||||
|
out vec4 _fragColor;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
Material mat = getMaterial();
|
||||||
|
int matKey = getMaterialKey(mat);
|
||||||
|
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL)$>
|
||||||
|
|
||||||
|
float opacity = getMaterialOpacity(mat) * _alpha;
|
||||||
|
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||||
|
|
||||||
|
vec3 albedo = getMaterialAlbedo(mat);
|
||||||
|
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
||||||
|
albedo *= _color;
|
||||||
|
|
||||||
|
_fragColor = vec4(albedo, opacity);
|
||||||
|
}
|
44
libraries/render-utils/src/model_unlit.slf
Normal file
44
libraries/render-utils/src/model_unlit.slf
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<@include gpu/Config.slh@>
|
||||||
|
<$VERSION_HEADER$>
|
||||||
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
|
//
|
||||||
|
// material_opaque_unlit.frag
|
||||||
|
// fragment shader
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 5/5/2016.
|
||||||
|
// Copyright 2016 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// 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@>
|
||||||
|
<@include model/Material.slh@>
|
||||||
|
|
||||||
|
<@include MaterialTextures.slh@>
|
||||||
|
<$declareMaterialTextures(ALBEDO, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL)$>
|
||||||
|
|
||||||
|
in vec2 _texCoord0;
|
||||||
|
in vec3 _normal;
|
||||||
|
in vec3 _color;
|
||||||
|
in float _alpha;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
|
||||||
|
Material mat = getMaterial();
|
||||||
|
int matKey = getMaterialKey(mat);
|
||||||
|
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL)$>
|
||||||
|
|
||||||
|
float opacity = 1.0;
|
||||||
|
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||||
|
<$discardTransparent(opacity)$>;
|
||||||
|
|
||||||
|
vec3 albedo = getMaterialAlbedo(mat);
|
||||||
|
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
|
||||||
|
albedo *= _color;
|
||||||
|
|
||||||
|
packDeferredFragmentUnlit(
|
||||||
|
normalize(_normal),
|
||||||
|
opacity,
|
||||||
|
albedo);
|
||||||
|
}
|
|
@ -71,6 +71,7 @@ void main(void) {
|
||||||
fragRoughness,
|
fragRoughness,
|
||||||
fragOpacity);
|
fragOpacity);
|
||||||
|
|
||||||
|
|
||||||
// Apply standard tone mapping
|
// Apply standard tone mapping
|
||||||
_fragColor = vec4(pow(color.xyz, vec3(1.0 / 2.2)), color.w);
|
_fragColor = vec4(pow(color.xyz, vec3(1.0 / 2.2)), color.w);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<$VERSION_HEADER$>
|
<$VERSION_HEADER$>
|
||||||
// Generated on <$_SCRIBE_DATE$>
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
//
|
//
|
||||||
// overlay3D_translucent_emissive.frag
|
// overlay3D_translucent_unlit.frag
|
||||||
// fragment shader
|
// fragment shader
|
||||||
//
|
//
|
||||||
// Created by Zach Pomerantz on 2/2/2016.
|
// Created by Zach Pomerantz on 2/2/2016.
|
|
@ -2,7 +2,7 @@
|
||||||
<$VERSION_HEADER$>
|
<$VERSION_HEADER$>
|
||||||
// Generated on <$_SCRIBE_DATE$>
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
//
|
//
|
||||||
// overlay3D_emissive.frag
|
// overlay3D_unlit.frag
|
||||||
// fragment shader
|
// fragment shader
|
||||||
//
|
//
|
||||||
// Created by Zach Pomerantz on 2/2/2016.
|
// Created by Zach Pomerantz on 2/2/2016.
|
|
@ -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@>
|
||||||
|
@ -32,6 +32,10 @@ void main(void) {
|
||||||
vec2 texCoord = _texCoord0.st / _texCoord0.q;
|
vec2 texCoord = _texCoord0.st / _texCoord0.q;
|
||||||
DeferredFragment frag = unpackDeferredFragment(deferredTransform, texCoord);
|
DeferredFragment frag = unpackDeferredFragment(deferredTransform, texCoord);
|
||||||
|
|
||||||
|
if (frag.mode == FRAG_MODE_UNLIT) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
mat4 invViewMat = deferredTransform.viewInverse;
|
mat4 invViewMat = deferredTransform.viewInverse;
|
||||||
|
|
||||||
// Kill if in front of the light volume
|
// Kill if in front of the light volume
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
// the interpolated normal
|
// the interpolated normal
|
||||||
out vec3 _normal;
|
out vec3 _normal;
|
||||||
out vec3 _modelNormal;
|
out vec3 _modelNormal;
|
||||||
out vec3 _color;
|
out vec4 _color;
|
||||||
out vec2 _texCoord0;
|
out vec2 _texCoord0;
|
||||||
out vec4 _position;
|
out vec4 _position;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
_color = colorToLinearRGB(inColor.rgb);
|
_color = colorToLinearRGBA(inColor);
|
||||||
_texCoord0 = inTexCoord0.st;
|
_texCoord0 = inTexCoord0.st;
|
||||||
_position = inPosition;
|
_position = inPosition;
|
||||||
_modelNormal = inNormal.xyz;
|
_modelNormal = inNormal.xyz;
|
||||||
|
|
|
@ -12,6 +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 gpu/Color.slh@>
|
||||||
<@include DeferredBufferWrite.slh@>
|
<@include DeferredBufferWrite.slh@>
|
||||||
<@include model/Material.slh@>
|
<@include model/Material.slh@>
|
||||||
|
|
||||||
|
@ -20,13 +21,14 @@ uniform sampler2D originalTexture;
|
||||||
|
|
||||||
// the interpolated normal
|
// the interpolated normal
|
||||||
in vec3 _normal;
|
in vec3 _normal;
|
||||||
in vec3 _color;
|
in vec4 _color;
|
||||||
in vec2 _texCoord0;
|
in vec2 _texCoord0;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
Material material = getMaterial();
|
|
||||||
vec4 texel = texture(originalTexture, _texCoord0);
|
vec4 texel = texture(originalTexture, _texCoord0);
|
||||||
|
if (_color.a <= 0.0) {
|
||||||
|
texel = colorToLinearRGBA(texel);
|
||||||
|
}
|
||||||
packDeferredFragment(
|
packDeferredFragment(
|
||||||
normalize(_normal.xyz),
|
normalize(_normal.xyz),
|
||||||
texel.a,
|
texel.a,
|
||||||
|
|
|
@ -12,6 +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 gpu/Color.slh@>
|
||||||
<@include DeferredBufferWrite.slh@>
|
<@include DeferredBufferWrite.slh@>
|
||||||
|
|
||||||
// the albedo texture
|
// the albedo texture
|
||||||
|
@ -19,18 +20,17 @@ uniform sampler2D originalTexture;
|
||||||
|
|
||||||
// the interpolated normal
|
// the interpolated normal
|
||||||
in vec3 _normal;
|
in vec3 _normal;
|
||||||
in vec3 _color;
|
in vec4 _color;
|
||||||
in vec2 _texCoord0;
|
in vec2 _texCoord0;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
vec4 texel = texture(originalTexture, _texCoord0.st);
|
vec4 texel = texture(originalTexture, _texCoord0.st);
|
||||||
|
if (_color.a <= 0.0) {
|
||||||
packDeferredFragmentLightmap(
|
texel = colorToLinearRGBA(texel);
|
||||||
|
}
|
||||||
|
|
||||||
|
packDeferredFragmentUnlit(
|
||||||
normalize(_normal),
|
normalize(_normal),
|
||||||
texel.a,
|
texel.a,
|
||||||
_color.rgb,
|
_color.rgb * texel.rgb);
|
||||||
DEFAULT_ROUGHNESS,
|
|
||||||
DEFAULT_METALLIC,
|
|
||||||
DEFAULT_SPECULAR,
|
|
||||||
texel.rgb);
|
|
||||||
}
|
}
|
|
@ -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@>
|
||||||
|
@ -32,6 +32,10 @@ void main(void) {
|
||||||
vec2 texCoord = _texCoord0.st / _texCoord0.q;
|
vec2 texCoord = _texCoord0.st / _texCoord0.q;
|
||||||
DeferredFragment frag = unpackDeferredFragment(deferredTransform, texCoord);
|
DeferredFragment frag = unpackDeferredFragment(deferredTransform, texCoord);
|
||||||
|
|
||||||
|
if (frag.mode == FRAG_MODE_UNLIT) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
mat4 invViewMat = deferredTransform.viewInverse;
|
mat4 invViewMat = deferredTransform.viewInverse;
|
||||||
|
|
||||||
// Kill if in front of the light volume
|
// Kill if in front of the light volume
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
LIGHTMAP,
|
LIGHTMAP,
|
||||||
TANGENTS,
|
TANGENTS,
|
||||||
SPECULAR,
|
SPECULAR,
|
||||||
EMISSIVE,
|
UNLIT,
|
||||||
SKINNED,
|
SKINNED,
|
||||||
STEREO,
|
STEREO,
|
||||||
DEPTH_ONLY,
|
DEPTH_ONLY,
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
Builder& withLightmap() { _flags.set(LIGHTMAP); return (*this); }
|
Builder& withLightmap() { _flags.set(LIGHTMAP); return (*this); }
|
||||||
Builder& withTangents() { _flags.set(TANGENTS); return (*this); }
|
Builder& withTangents() { _flags.set(TANGENTS); return (*this); }
|
||||||
Builder& withSpecular() { _flags.set(SPECULAR); return (*this); }
|
Builder& withSpecular() { _flags.set(SPECULAR); return (*this); }
|
||||||
Builder& withEmissive() { _flags.set(EMISSIVE); return (*this); }
|
Builder& withUnlit() { _flags.set(UNLIT); return (*this); }
|
||||||
Builder& withSkinned() { _flags.set(SKINNED); return (*this); }
|
Builder& withSkinned() { _flags.set(SKINNED); return (*this); }
|
||||||
Builder& withStereo() { _flags.set(STEREO); return (*this); }
|
Builder& withStereo() { _flags.set(STEREO); return (*this); }
|
||||||
Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); return (*this); }
|
Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); return (*this); }
|
||||||
|
@ -101,8 +101,8 @@ public:
|
||||||
Builder& withSpecular() { _flags.set(SPECULAR); _mask.set(SPECULAR); return (*this); }
|
Builder& withSpecular() { _flags.set(SPECULAR); _mask.set(SPECULAR); return (*this); }
|
||||||
Builder& withoutSpecular() { _flags.reset(SPECULAR); _mask.set(SPECULAR); return (*this); }
|
Builder& withoutSpecular() { _flags.reset(SPECULAR); _mask.set(SPECULAR); return (*this); }
|
||||||
|
|
||||||
Builder& withEmissive() { _flags.set(EMISSIVE); _mask.set(EMISSIVE); return (*this); }
|
Builder& withUnlit() { _flags.set(UNLIT); _mask.set(UNLIT); return (*this); }
|
||||||
Builder& withoutEmissive() { _flags.reset(EMISSIVE); _mask.set(EMISSIVE); return (*this); }
|
Builder& withoutUnlit() { _flags.reset(UNLIT); _mask.set(UNLIT); return (*this); }
|
||||||
|
|
||||||
Builder& withSkinned() { _flags.set(SKINNED); _mask.set(SKINNED); return (*this); }
|
Builder& withSkinned() { _flags.set(SKINNED); _mask.set(SKINNED); return (*this); }
|
||||||
Builder& withoutSkinned() { _flags.reset(SKINNED); _mask.set(SKINNED); return (*this); }
|
Builder& withoutSkinned() { _flags.reset(SKINNED); _mask.set(SKINNED); return (*this); }
|
||||||
|
@ -137,7 +137,7 @@ public:
|
||||||
bool hasLightmap() const { return _flags[LIGHTMAP]; }
|
bool hasLightmap() const { return _flags[LIGHTMAP]; }
|
||||||
bool hasTangents() const { return _flags[TANGENTS]; }
|
bool hasTangents() const { return _flags[TANGENTS]; }
|
||||||
bool hasSpecular() const { return _flags[SPECULAR]; }
|
bool hasSpecular() const { return _flags[SPECULAR]; }
|
||||||
bool hasEmissive() const { return _flags[EMISSIVE]; }
|
bool isUnlit() const { return _flags[UNLIT]; }
|
||||||
bool isTranslucent() const { return _flags[TRANSLUCENT]; }
|
bool isTranslucent() const { return _flags[TRANSLUCENT]; }
|
||||||
bool isSkinned() const { return _flags[SKINNED]; }
|
bool isSkinned() const { return _flags[SKINNED]; }
|
||||||
bool isStereo() const { return _flags[STEREO]; }
|
bool isStereo() const { return _flags[STEREO]; }
|
||||||
|
@ -173,7 +173,7 @@ inline QDebug operator<<(QDebug debug, const ShapeKey& key) {
|
||||||
<< "hasLightmap:" << key.hasLightmap()
|
<< "hasLightmap:" << key.hasLightmap()
|
||||||
<< "hasTangents:" << key.hasTangents()
|
<< "hasTangents:" << key.hasTangents()
|
||||||
<< "hasSpecular:" << key.hasSpecular()
|
<< "hasSpecular:" << key.hasSpecular()
|
||||||
<< "hasEmissive:" << key.hasEmissive()
|
<< "isUnlit:" << key.isUnlit()
|
||||||
<< "isTranslucent:" << key.isTranslucent()
|
<< "isTranslucent:" << key.isTranslucent()
|
||||||
<< "isSkinned:" << key.isSkinned()
|
<< "isSkinned:" << key.isSkinned()
|
||||||
<< "isStereo:" << key.isStereo()
|
<< "isStereo:" << key.isStereo()
|
||||||
|
|
|
@ -33,6 +33,7 @@ Column {
|
||||||
"Roughness",
|
"Roughness",
|
||||||
"Metallic",
|
"Metallic",
|
||||||
"Emissive",
|
"Emissive",
|
||||||
|
"Shaded/Lightmapped/Unlit",
|
||||||
"Occlusion",
|
"Occlusion",
|
||||||
"Lightmap",
|
"Lightmap",
|
||||||
"Lighting",
|
"Lighting",
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <render-utils/simple_vert.h>
|
#include <render-utils/simple_vert.h>
|
||||||
#include <render-utils/simple_frag.h>
|
#include <render-utils/simple_frag.h>
|
||||||
#include <render-utils/simple_textured_frag.h>
|
#include <render-utils/simple_textured_frag.h>
|
||||||
#include <render-utils/simple_textured_emisive_frag.h>
|
#include <render-utils/simple_textured_unlit_frag.h>
|
||||||
|
|
||||||
#include <render-utils/deferred_light_vert.h>
|
#include <render-utils/deferred_light_vert.h>
|
||||||
#include <render-utils/deferred_light_limited_vert.h>
|
#include <render-utils/deferred_light_limited_vert.h>
|
||||||
|
@ -160,7 +160,7 @@ void QTestWindow::draw() {
|
||||||
testShaderBuild(skybox_vert, skybox_frag);
|
testShaderBuild(skybox_vert, skybox_frag);
|
||||||
testShaderBuild(simple_vert, simple_frag);
|
testShaderBuild(simple_vert, simple_frag);
|
||||||
testShaderBuild(simple_vert, simple_textured_frag);
|
testShaderBuild(simple_vert, simple_textured_frag);
|
||||||
testShaderBuild(simple_vert, simple_textured_emisive_frag);
|
testShaderBuild(simple_vert, simple_textured_unlit_frag);
|
||||||
testShaderBuild(deferred_light_vert, directional_light_frag);
|
testShaderBuild(deferred_light_vert, directional_light_frag);
|
||||||
testShaderBuild(deferred_light_vert, directional_ambient_light_frag);
|
testShaderBuild(deferred_light_vert, directional_ambient_light_frag);
|
||||||
testShaderBuild(deferred_light_vert, directional_skybox_light_frag);
|
testShaderBuild(deferred_light_vert, directional_skybox_light_frag);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "TextTemplate.h"
|
#include "TextTemplate.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
|
@ -168,7 +169,7 @@ int main (int argc, char** argv) {
|
||||||
auto scribe = std::make_shared<TextTemplate>(srcFilename, config);
|
auto scribe = std::make_shared<TextTemplate>(srcFilename, config);
|
||||||
|
|
||||||
// ready to parse and generate
|
// ready to parse and generate
|
||||||
std::ostringstream destStringStream;
|
std::stringstream destStringStream;
|
||||||
int numErrors = scribe->scribe(destStringStream, srcStream, vars);
|
int numErrors = scribe->scribe(destStringStream, srcStream, vars);
|
||||||
if (numErrors) {
|
if (numErrors) {
|
||||||
cerr << "Scribe " << srcFilename << "> failed: " << numErrors << " errors." << endl;
|
cerr << "Scribe " << srcFilename << "> failed: " << numErrors << " errors." << endl;
|
||||||
|
@ -187,14 +188,38 @@ int main (int argc, char** argv) {
|
||||||
|
|
||||||
std::ostringstream targetStringStream;
|
std::ostringstream targetStringStream;
|
||||||
if (makeCPlusPlus) {
|
if (makeCPlusPlus) {
|
||||||
|
// Because there is a maximum size for literal strings declared in source we need to partition the
|
||||||
|
// full source string stream into pages that seems to be around that value...
|
||||||
|
const int MAX_STRING_LITERAL = 10000;
|
||||||
|
std::string lineToken;
|
||||||
|
auto pageSize = lineToken.length();
|
||||||
|
std::vector<std::shared_ptr<std::stringstream>> pages(1, std::make_shared<std::stringstream>());
|
||||||
|
while (!destStringStream.eof()) {
|
||||||
|
std::getline(destStringStream, lineToken);
|
||||||
|
auto lineSize = lineToken.length() + 1;
|
||||||
|
|
||||||
|
if (pageSize + lineSize > MAX_STRING_LITERAL) {
|
||||||
|
pages.push_back(std::make_shared<std::stringstream>());
|
||||||
|
// reset pageStringStream
|
||||||
|
pageSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*pages.back()) << lineToken << std::endl;
|
||||||
|
pageSize += lineSize;
|
||||||
|
}
|
||||||
|
|
||||||
targetStringStream << "// File generated by Scribe " << vars["_SCRIBE_DATE"] << std::endl;
|
targetStringStream << "// File generated by Scribe " << vars["_SCRIBE_DATE"] << std::endl;
|
||||||
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\";";
|
targetStringStream << "const char " << targetName << "[] = \n";
|
||||||
targetStringStream << "const char " << targetName << "[] = R\"SCRIBE(";
|
|
||||||
targetStringStream << destStringStream.str();
|
// Write the pages content
|
||||||
targetStringStream << "\n)SCRIBE\";\n\n";
|
for (auto page : pages) {
|
||||||
|
targetStringStream << "R\"SCRIBE(\n" << page->str() << "\n)SCRIBE\"\n";
|
||||||
|
}
|
||||||
|
targetStringStream << ";\n" << std::endl << std::endl;
|
||||||
|
|
||||||
targetStringStream << "#endif" << std::endl;
|
targetStringStream << "#endif" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
targetStringStream << destStringStream.str();
|
targetStringStream << destStringStream.str();
|
||||||
|
|
Loading…
Reference in a new issue