mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge branch 'master' into 20918
This commit is contained in:
commit
ccd821118e
47 changed files with 495 additions and 314 deletions
|
@ -1071,6 +1071,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
|||
// in the queue, which can be pretty damn frequent. Hence the idle function has a bunch
|
||||
// of logic to abort early if it's being called too often.
|
||||
_idleTimer->start(0);
|
||||
|
||||
// After all of the constructor is completed, then set firstRun to false.
|
||||
Setting::Handle<bool> firstRun{ Settings::firstRun, true };
|
||||
firstRun.set(false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1088,11 +1092,6 @@ void Application::checkChangeCursor() {
|
|||
|
||||
_cursorNeedsChanging = false;
|
||||
}
|
||||
|
||||
|
||||
// After all of the constructor is completed, then set firstRun to false.
|
||||
Setting::Handle<bool> firstRun{ Settings::firstRun, true };
|
||||
firstRun.set(false);
|
||||
}
|
||||
|
||||
void Application::showCursor(const QCursor& cursor) {
|
||||
|
|
|
@ -104,7 +104,7 @@ void Image3DOverlay::render(RenderArgs* args) {
|
|||
const render::ShapeKey Image3DOverlay::getShapeKey() {
|
||||
auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias();
|
||||
if (_emissive) {
|
||||
builder.withEmissive();
|
||||
builder.withUnlit();
|
||||
}
|
||||
if (getAlpha() != 1.0f) {
|
||||
builder.withTranslucent();
|
||||
|
|
|
@ -210,7 +210,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -892,7 +892,10 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
properties = true;
|
||||
propertyName = "P";
|
||||
index = 4;
|
||||
} else if (subobject.name == "ShadingModel") {
|
||||
material.shadingModel = subobject.properties.at(0).toString();
|
||||
}
|
||||
|
||||
if (properties) {
|
||||
std::vector<std::string> unknowns;
|
||||
foreach(const FBXNode& property, subobject.children) {
|
||||
|
@ -988,7 +991,6 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
QString propname = subobject.name.data();
|
||||
int unknown = 0;
|
||||
if ( (propname == "Version")
|
||||
||(propname == "ShadingModel")
|
||||
||(propname == "Multilayer")) {
|
||||
} else {
|
||||
unknown++;
|
||||
|
@ -1130,7 +1132,6 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
ambientTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
} else if (type.contains("tex_ao_map")) {
|
||||
occlusionTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
|
||||
} else if (type == "lcl rotation") {
|
||||
localRotations.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
} else if (type == "lcl translation") {
|
||||
|
@ -1331,7 +1332,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
}
|
||||
|
||||
// NOTE: shapeVertices are in joint-frame
|
||||
QVector<ShapeVertices> shapeVertices;
|
||||
std::vector<ShapeVertices> shapeVertices;
|
||||
shapeVertices.resize(geometry.joints.size());
|
||||
|
||||
// find our special joints
|
||||
|
@ -1522,7 +1523,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
|
||||
float clusterScale = extractUniformScale(fbxCluster.inverseBindMatrix);
|
||||
glm::mat4 meshToJoint = glm::inverse(joint.bindTransform) * modelTransform;
|
||||
ShapeVertices& points = shapeVertices[jointIndex];
|
||||
ShapeVertices& points = shapeVertices.at(jointIndex);
|
||||
|
||||
float totalWeight = 0.0f;
|
||||
for (int j = 0; j < cluster.indices.size(); j++) {
|
||||
|
@ -1584,7 +1585,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
// transform cluster vertices to joint-frame and save for later
|
||||
float clusterScale = extractUniformScale(firstFBXCluster.inverseBindMatrix);
|
||||
glm::mat4 meshToJoint = glm::inverse(joint.bindTransform) * modelTransform;
|
||||
ShapeVertices& points = shapeVertices[jointIndex];
|
||||
ShapeVertices& points = shapeVertices.at(jointIndex);
|
||||
foreach (const glm::vec3& vertex, extracted.mesh.vertices) {
|
||||
const glm::mat4 vertexTransform = meshToJoint * glm::translate(vertex);
|
||||
points.push_back(extractTranslation(vertexTransform) * clusterScale);
|
||||
|
@ -1625,7 +1626,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
|||
FBXJoint& joint = geometry.joints[i];
|
||||
|
||||
// NOTE: points are in joint-frame
|
||||
ShapeVertices& points = shapeVertices[i];
|
||||
ShapeVertices& points = shapeVertices.at(i);
|
||||
if (points.size() > 0) {
|
||||
// compute average point
|
||||
glm::vec3 avgPoint = glm::vec3(0.0f);
|
||||
|
|
|
@ -154,6 +154,7 @@ public:
|
|||
|
||||
QString materialID;
|
||||
QString name;
|
||||
QString shadingModel;
|
||||
model::MaterialPointer _material;
|
||||
|
||||
FBXTexture normalTexture;
|
||||
|
|
|
@ -72,6 +72,10 @@ void FBXReader::consolidateFBXMaterials() {
|
|||
// foreach (const QString& materialID, materials) {
|
||||
for (QHash<QString, FBXMaterial>::iterator it = _fbxMaterials.begin(); it != _fbxMaterials.end(); 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
|
||||
bool detectDifferentUVs = false;
|
||||
FBXTexture diffuseTexture;
|
||||
|
@ -171,6 +175,13 @@ void FBXReader::consolidateFBXMaterials() {
|
|||
emissiveTexture = getTexture(emissiveTextureID);
|
||||
detectDifferentUVs |= (emissiveTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity());
|
||||
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;
|
||||
|
@ -198,7 +209,7 @@ void FBXReader::consolidateFBXMaterials() {
|
|||
material._material = std::make_shared<model::Material>();
|
||||
|
||||
// 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);
|
||||
|
||||
// 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));
|
||||
float metallic = std::max(material.specularColor.x, std::max(material.specularColor.y, material.specularColor.z));
|
||||
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) {
|
||||
|
|
|
@ -74,6 +74,11 @@ void Material::setOpacity(float 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) {
|
||||
_key.setAlbedo(glm::any(glm::greaterThan(albedo, Color(0.0f))));
|
||||
_schemaBuffer.edit<Schema>()._key = (uint32)_key._flags.to_ulong();
|
||||
|
|
|
@ -28,14 +28,15 @@ class MaterialKey {
|
|||
public:
|
||||
enum FlagBit {
|
||||
EMISSIVE_VAL_BIT = 0,
|
||||
UNLIT_VAL_BIT,
|
||||
ALBEDO_VAL_BIT,
|
||||
METALLIC_VAL_BIT,
|
||||
GLOSSY_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,
|
||||
|
||||
// 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,
|
||||
ALBEDO_MAP_BIT,
|
||||
METALLIC_MAP_BIT,
|
||||
|
@ -74,9 +75,12 @@ public:
|
|||
MaterialKey build() const { return MaterialKey(_flags); }
|
||||
|
||||
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& withMetallic() { _flags.set(METALLIC_VAL_BIT); return (*this); }
|
||||
Builder& withGlossy() { _flags.set(GLOSSY_VAL_BIT); return (*this); }
|
||||
|
||||
Builder& withTranslucentFactor() { _flags.set(OPACITY_VAL_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); }
|
||||
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); }
|
||||
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& 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& withAlbedo() { _value.set(MaterialKey::ALBEDO_VAL_BIT); _mask.set(MaterialKey::ALBEDO_VAL_BIT); return (*this); }
|
||||
|
||||
|
@ -250,6 +260,9 @@ public:
|
|||
void setOpacity(float 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);
|
||||
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); }
|
||||
|
||||
const int EMISSIVE_VAL_BIT = 0x00000001;
|
||||
const int ALBEDO_VAL_BIT = 0x00000002;
|
||||
const int METALLIC_VAL_BIT = 0x00000004;
|
||||
const int GLOSSY_VAL_BIT = 0x00000008;
|
||||
const int OPACITY_VAL_BIT = 0x00000010;
|
||||
const int OPACITY_MASK_MAP_BIT = 0x00000020;
|
||||
const int OPACITY_TRANSLUCENT_MAP_BIT = 0x00000040;
|
||||
const int UNLIT_VAL_BIT = 0x00000002;
|
||||
const int ALBEDO_VAL_BIT = 0x00000004;
|
||||
const int METALLIC_VAL_BIT = 0x00000008;
|
||||
const int GLOSSY_VAL_BIT = 0x00000010;
|
||||
const int OPACITY_VAL_BIT = 0x00000020;
|
||||
const int OPACITY_MASK_MAP_BIT = 0x00000040;
|
||||
const int OPACITY_TRANSLUCENT_MAP_BIT = 0x00000080;
|
||||
|
||||
const int EMISSIVE_MAP_BIT = 0x00000080;
|
||||
const int ALBEDO_MAP_BIT = 0x00000100;
|
||||
const int METALLIC_MAP_BIT = 0x00000200;
|
||||
const int ROUGHNESS_MAP_BIT = 0x00000400;
|
||||
const int NORMAL_MAP_BIT = 0x00000800;
|
||||
const int OCCLUSION_MAP_BIT = 0x00001000;
|
||||
const int LIGHTMAP_MAP_BIT = 0x00002000;
|
||||
const int EMISSIVE_MAP_BIT = 0x00000100;
|
||||
const int ALBEDO_MAP_BIT = 0x00000200;
|
||||
const int METALLIC_MAP_BIT = 0x00000400;
|
||||
const int ROUGHNESS_MAP_BIT = 0x00000800;
|
||||
const int NORMAL_MAP_BIT = 0x00001000;
|
||||
const int OCCLUSION_MAP_BIT = 0x00002000;
|
||||
const int LIGHTMAP_MAP_BIT = 0x00004000;
|
||||
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -90,14 +90,21 @@ static const std::string DEFAULT_OCCLUSION_SHADER{
|
|||
static const std::string DEFAULT_EMISSIVE_SHADER{
|
||||
"vec4 getFragmentColor() {"
|
||||
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
||||
" return (frag.mode != LIGHT_MAPPED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));"
|
||||
" 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{
|
||||
"vec4 getFragmentColor() {"
|
||||
" 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;
|
||||
case EmissiveMode:
|
||||
return DEFAULT_EMISSIVE_SHADER;
|
||||
case UnlitMode:
|
||||
return DEFAULT_UNLIT_SHADER;
|
||||
case OcclusionMode:
|
||||
return DEFAULT_OCCLUSION_SHADER;
|
||||
case LightmapMode:
|
||||
|
|
|
@ -53,6 +53,7 @@ protected:
|
|||
RoughnessMode,
|
||||
MetallicMode,
|
||||
EmissiveMode,
|
||||
UnlitMode,
|
||||
OcclusionMode,
|
||||
LightmapMode,
|
||||
LightingMode,
|
||||
|
|
|
@ -11,135 +11,44 @@
|
|||
<@if not 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
|
||||
uniform sampler2D albedoMap;
|
||||
const float FRAG_PACK_LIGHTMAPPED_NON_METALLIC = 0.2;
|
||||
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
|
||||
uniform sampler2D normalMap;
|
||||
const float FRAG_PACK_UNLIT = 0.5;
|
||||
|
||||
// the specular texture
|
||||
uniform sampler2D specularMap;
|
||||
const int FRAG_MODE_UNLIT = 0;
|
||||
const int FRAG_MODE_SHADED = 1;
|
||||
const int FRAG_MODE_LIGHTMAPPED = 2;
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
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;
|
||||
void unpackModeMetallic(float rawValue, out int mode, out float metallic) {
|
||||
if (rawValue <= FRAG_PACK_SHADED_METALLIC) {
|
||||
mode = FRAG_MODE_SHADED;
|
||||
metallic = clamp((rawValue - FRAG_PACK_SHADED_NON_METALLIC) * FRAG_PACK_SHADED_RANGE_INV, 0.0, 1.0);
|
||||
} else if (rawValue <= FRAG_PACK_LIGHTMAPPED_METALLIC) {
|
||||
mode = FRAG_MODE_LIGHTMAPPED;
|
||||
metallic = clamp((rawValue - FRAG_PACK_LIGHTMAPPED_NON_METALLIC) * FRAG_PACK_SHADED_RANGE_INV, 0.0, 1.0);
|
||||
} else if (rawValue >= FRAG_PACK_UNLIT) {
|
||||
mode = FRAG_MODE_UNLIT;
|
||||
metallic = 0.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;
|
||||
float packShadedMetallic(float metallic) {
|
||||
return mix(FRAG_PACK_SHADED_NON_METALLIC, FRAG_PACK_SHADED_METALLIC, metallic);
|
||||
}
|
||||
|
||||
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;
|
||||
float packLightmappedMetallic(float metallic) {
|
||||
return mix(FRAG_PACK_LIGHTMAPPED_NON_METALLIC, FRAG_PACK_LIGHTMAPPED_METALLIC, metallic);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float packUnlit() {
|
||||
return FRAG_PACK_UNLIT;
|
||||
}
|
||||
|
||||
<@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@>
|
||||
<@def DEFERRED_BUFFER_WRITE_SLH@>
|
||||
|
||||
<@include DeferredBuffer.slh@>
|
||||
|
||||
layout(location = 0) out vec4 _fragColor0;
|
||||
layout(location = 1) out vec4 _fragColor1;
|
||||
layout(location = 2) out vec4 _fragColor2;
|
||||
|
@ -48,13 +50,12 @@ const vec3 DEFAULT_EMISSIVE = vec3(0.0);
|
|||
const float DEFAULT_OCCLUSION = 1.0;
|
||||
const vec3 DEFAULT_FRESNEL = DEFAULT_EMISSIVE;
|
||||
|
||||
|
||||
void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion) {
|
||||
if (alpha != 1.0) {
|
||||
discard;
|
||||
}
|
||||
_fragColor0 = vec4(albedo, metallic);
|
||||
_fragColor1 = vec4(bestFitNormal(normal), 0.5 * clamp(roughness, 0.0, 1.0));
|
||||
_fragColor0 = vec4(albedo, packShadedMetallic(metallic));
|
||||
_fragColor1 = vec4(bestFitNormal(normal), clamp(roughness, 0.0, 1.0));
|
||||
_fragColor2 = vec4(emissive, occlusion);
|
||||
}
|
||||
|
||||
|
@ -63,19 +64,25 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r
|
|||
if (alpha != 1.0) {
|
||||
discard;
|
||||
}
|
||||
_fragColor0 = vec4(albedo, metallic);
|
||||
_fragColor1 = vec4(bestFitNormal(normal), 0.5 + 0.5 * clamp(roughness, 0.0, 1.0));
|
||||
_fragColor0 = vec4(albedo, packLightmappedMetallic(metallic));
|
||||
_fragColor1 = vec4(bestFitNormal(normal), clamp(roughness, 0.0, 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) {
|
||||
if (alpha <= 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
}
|
||||
_fragColor0 = vec4(albedo.rgb, alpha);
|
||||
// _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
// _fragColor2 = vec4(fresnel, roughness);
|
||||
}
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include "simple_vert.h"
|
||||
#include "simple_textured_frag.h"
|
||||
#include "simple_textured_emisive_frag.h"
|
||||
#include "simple_textured_unlit_frag.h"
|
||||
|
||||
#include "grid_frag.h"
|
||||
|
||||
|
@ -1687,7 +1687,7 @@ public:
|
|||
enum FlagBit {
|
||||
IS_TEXTURED_FLAG = 0,
|
||||
IS_CULLED_FLAG,
|
||||
IS_EMISSIVE_FLAG,
|
||||
IS_UNLIT_FLAG,
|
||||
HAS_DEPTH_BIAS_FLAG,
|
||||
|
||||
NUM_FLAGS,
|
||||
|
@ -1696,7 +1696,7 @@ public:
|
|||
enum Flag {
|
||||
IS_TEXTURED = (1 << IS_TEXTURED_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),
|
||||
};
|
||||
typedef unsigned short Flags;
|
||||
|
@ -1705,7 +1705,7 @@ public:
|
|||
|
||||
bool isTextured() const { return isFlag(IS_TEXTURED); }
|
||||
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); }
|
||||
|
||||
Flags _flags = 0;
|
||||
|
@ -1715,9 +1715,9 @@ public:
|
|||
|
||||
|
||||
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) |
|
||||
(emissive ? IS_EMISSIVE : 0) | (depthBias ? HAS_DEPTH_BIAS : 0);
|
||||
(unlit ? IS_UNLIT : 0) | (depthBias ? HAS_DEPTH_BIAS : 0);
|
||||
}
|
||||
|
||||
SimpleProgramKey(int bitmask) : _flags(bitmask) {}
|
||||
|
@ -1731,8 +1731,8 @@ inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) {
|
|||
return a.getRaw() == b.getRaw();
|
||||
}
|
||||
|
||||
void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool emissive, bool depthBiased) {
|
||||
batch.setPipeline(getSimplePipeline(textured, culled, emissive, depthBiased));
|
||||
void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool culled, bool unlit, bool depthBiased) {
|
||||
batch.setPipeline(getSimplePipeline(textured, culled, unlit, depthBiased));
|
||||
|
||||
// If not textured, set a default albedo map
|
||||
if (!textured) {
|
||||
|
@ -1744,23 +1744,23 @@ void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool cul
|
|||
DependencyManager::get<TextureCache>()->getNormalFittingTexture());
|
||||
}
|
||||
|
||||
gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled, bool emissive, bool depthBiased) {
|
||||
SimpleProgramKey config{textured, culled, emissive, depthBiased};
|
||||
gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool culled, bool unlit, bool depthBiased) {
|
||||
SimpleProgramKey config{ textured, culled, unlit, depthBiased };
|
||||
|
||||
// Compile the shaders
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [&]() {
|
||||
auto VS = gpu::Shader::createVertex(std::string(simple_vert));
|
||||
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);
|
||||
_emissiveShader = gpu::Shader::createProgram(VS, PSEmissive);
|
||||
_unlitShader = gpu::Shader::createProgram(VS, PSUnlit);
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::MAP::NORMAL_FITTING));
|
||||
gpu::Shader::makeProgram(*_simpleShader, slotBindings);
|
||||
gpu::Shader::makeProgram(*_emissiveShader, slotBindings);
|
||||
gpu::Shader::makeProgram(*_unlitShader, slotBindings);
|
||||
});
|
||||
|
||||
// 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::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);
|
||||
_simplePrograms.insert(config, pipeline);
|
||||
return pipeline;
|
||||
|
|
|
@ -153,10 +153,10 @@ public:
|
|||
|
||||
// Bind the pipeline and get the state to render static geometry
|
||||
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
|
||||
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; }
|
||||
|
||||
// Static (instanced) geometry
|
||||
|
@ -393,7 +393,7 @@ private:
|
|||
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
||||
|
||||
gpu::ShaderPointer _simpleShader;
|
||||
gpu::ShaderPointer _emissiveShader;
|
||||
gpu::ShaderPointer _unlitShader;
|
||||
static render::ShapePipelinePointer _simplePipeline;
|
||||
QHash<SimpleProgramKey, gpu::PipelinePointer> _simplePrograms;
|
||||
};
|
||||
|
|
|
@ -157,7 +157,7 @@ vec3 fetchLightmapMap(vec2 uv) {
|
|||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@func $discardTransparent(opacity)@>
|
||||
<@func discardTransparent(opacity)@>
|
||||
{
|
||||
if (<$opacity$> < 1.0) {
|
||||
discard;
|
||||
|
|
|
@ -144,6 +144,11 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
|
|||
auto materialKey = _drawMaterial->getKey();
|
||||
auto textureMaps = _drawMaterial->getTextureMaps();
|
||||
|
||||
int numUnlit = 0;
|
||||
if (materialKey.isUnlit()) {
|
||||
numUnlit++;
|
||||
}
|
||||
|
||||
// Albedo
|
||||
if (materialKey.isAlbedoMap()) {
|
||||
auto albedoMap = textureMaps[model::MaterialKey::ALBEDO_MAP];
|
||||
|
@ -414,6 +419,7 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
|
|||
bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty();
|
||||
bool hasSpecular = drawMaterialKey.isMetallicMap();
|
||||
bool hasLightmap = drawMaterialKey.isLightmapMap();
|
||||
bool isUnlit = drawMaterialKey.isUnlit();
|
||||
|
||||
bool isSkinned = _isSkinned;
|
||||
bool wireframe = _model->isWireframe();
|
||||
|
@ -435,6 +441,9 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
|
|||
if (hasLightmap) {
|
||||
builder.withLightmap();
|
||||
}
|
||||
if (isUnlit) {
|
||||
builder.withUnlit();
|
||||
}
|
||||
if (isSkinned) {
|
||||
builder.withSkinned();
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "skin_model_normal_map_vert.h"
|
||||
|
||||
#include "model_frag.h"
|
||||
#include "model_emissive_frag.h"
|
||||
#include "model_unlit_frag.h"
|
||||
#include "model_shadow_frag.h"
|
||||
#include "model_normal_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_specular_map_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_frag.h"
|
||||
#include "overlay3D_translucent_frag.h"
|
||||
#include "overlay3D_emissive_frag.h"
|
||||
#include "overlay3D_translucent_emissive_frag.h"
|
||||
#include "overlay3D_unlit_frag.h"
|
||||
#include "overlay3D_translucent_unlit_frag.h"
|
||||
|
||||
#include "drawOpaqueStencil_frag.h"
|
||||
|
||||
|
@ -102,13 +102,13 @@ void initOverlay3DPipelines(ShapePlumber& plumber) {
|
|||
auto vertex = gpu::Shader::createVertex(std::string(overlay3D_vert));
|
||||
auto pixel = gpu::Shader::createPixel(std::string(overlay3D_frag));
|
||||
auto pixelTranslucent = gpu::Shader::createPixel(std::string(overlay3D_translucent_frag));
|
||||
auto pixelEmissive = gpu::Shader::createPixel(std::string(overlay3D_emissive_frag));
|
||||
auto pixelTranslucentEmissive = gpu::Shader::createPixel(std::string(overlay3D_translucent_emissive_frag));
|
||||
auto pixelUnlit = gpu::Shader::createPixel(std::string(overlay3D_unlit_frag));
|
||||
auto pixelTranslucentUnlit = gpu::Shader::createPixel(std::string(overlay3D_translucent_unlit_frag));
|
||||
|
||||
auto opaqueProgram = gpu::Shader::createProgram(vertex, pixel);
|
||||
auto translucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucent);
|
||||
auto emissiveOpaqueProgram = gpu::Shader::createProgram(vertex, pixelEmissive);
|
||||
auto emissiveTranslucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucentEmissive);
|
||||
auto unlitOpaqueProgram = gpu::Shader::createProgram(vertex, pixelUnlit);
|
||||
auto unlitTranslucentProgram = gpu::Shader::createProgram(vertex, pixelTranslucentUnlit);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
bool isCulled = (i & 1);
|
||||
|
@ -138,9 +138,9 @@ void initOverlay3DPipelines(ShapePlumber& plumber) {
|
|||
isOpaque ? builder.withOpaque() : builder.withTranslucent();
|
||||
|
||||
auto simpleProgram = isOpaque ? opaqueProgram : translucentProgram;
|
||||
auto emissiveProgram = isOpaque ? emissiveOpaqueProgram : emissiveTranslucentProgram;
|
||||
plumber.addPipeline(builder.withoutEmissive().build(), simpleProgram, state, &lightBatchSetter);
|
||||
plumber.addPipeline(builder.withEmissive().build(), emissiveProgram, state, &batchSetter);
|
||||
auto unlitProgram = isOpaque ? unlitOpaqueProgram : unlitTranslucentProgram;
|
||||
plumber.addPipeline(builder.withoutUnlit().build(), simpleProgram, state, &lightBatchSetter);
|
||||
plumber.addPipeline(builder.withUnlit().build(), unlitProgram, state, &batchSetter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,12 +201,12 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
|||
|
||||
// Pixel shaders
|
||||
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 modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_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 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 modelLightmapPixel = gpu::Shader::createPixel(std::string(model_lightmap_frag));
|
||||
auto modelLightmapNormalMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag));
|
||||
|
@ -219,8 +219,8 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
|||
Key::Builder(),
|
||||
modelVertex, modelPixel);
|
||||
addPipeline(
|
||||
Key::Builder().withEmissive(),
|
||||
modelVertex, modelEmissivePixel);
|
||||
Key::Builder().withUnlit(),
|
||||
modelVertex, modelUnlitPixel);
|
||||
addPipeline(
|
||||
Key::Builder().withTangents(),
|
||||
modelNormalMapVertex, modelNormalMapPixel);
|
||||
|
@ -235,8 +235,8 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
|||
Key::Builder().withTranslucent(),
|
||||
modelVertex, modelTranslucentPixel);
|
||||
addPipeline(
|
||||
Key::Builder().withTranslucent().withEmissive(),
|
||||
modelVertex, modelTranslucentEmissivePixel);
|
||||
Key::Builder().withTranslucent().withUnlit(),
|
||||
modelVertex, modelTranslucentUnlitPixel);
|
||||
addPipeline(
|
||||
Key::Builder().withTranslucent().withTangents(),
|
||||
modelNormalMapVertex, modelTranslucentPixel);
|
||||
|
@ -296,4 +296,5 @@ void initDeferredPipelines(render::ShapePlumber& plumber) {
|
|||
addPipeline(
|
||||
Key::Builder().withSkinned().withDepthOnly(),
|
||||
skinModelShadowVertex, modelShadowPixel);
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// 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 occlusionMap;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBuffer.slh@>
|
||||
<@include DeferredBufferRead.slh@>
|
||||
<@include DeferredGlobalLight.slh@>
|
||||
|
||||
<$declareEvalLightmappedColor()$>
|
||||
|
@ -27,7 +27,9 @@ void main(void) {
|
|||
|
||||
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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//
|
||||
|
||||
<@include Shadow.slh@>
|
||||
<@include DeferredBuffer.slh@>
|
||||
<@include DeferredBufferRead.slh@>
|
||||
<@include DeferredGlobalLight.slh@>
|
||||
|
||||
<$declareEvalLightmappedColor()$>
|
||||
|
@ -29,7 +29,9 @@ void main(void) {
|
|||
vec4 worldPos = deferredTransform.viewInverse * vec4(frag.position.xyz, 1.0);
|
||||
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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBuffer.slh@>
|
||||
<@include DeferredBufferRead.slh@>
|
||||
<@include DeferredGlobalLight.slh@>
|
||||
|
||||
<$declareEvalLightmappedColor()$>
|
||||
|
@ -28,7 +28,9 @@ void main(void) {
|
|||
float shadowAttenuation = 1.0;
|
||||
|
||||
// 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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//
|
||||
|
||||
<@include Shadow.slh@>
|
||||
<@include DeferredBuffer.slh@>
|
||||
<@include DeferredBufferRead.slh@>
|
||||
<@include DeferredGlobalLight.slh@>
|
||||
|
||||
<$declareEvalLightmappedColor()$>
|
||||
|
@ -30,7 +30,9 @@ void main(void) {
|
|||
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
||||
|
||||
// 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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include DeferredBuffer.slh@>
|
||||
<@include DeferredBufferRead.slh@>
|
||||
<@include DeferredGlobalLight.slh@>
|
||||
|
||||
<$declareEvalLightmappedColor()$>
|
||||
|
@ -28,7 +28,9 @@ void main(void) {
|
|||
float shadowAttenuation = 1.0;
|
||||
|
||||
// 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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//!>
|
||||
|
||||
<@include Shadow.slh@>
|
||||
<@include DeferredBuffer.slh@>
|
||||
<@include DeferredBufferRead.slh@>
|
||||
<@include DeferredGlobalLight.slh@>
|
||||
|
||||
<$declareEvalLightmappedColor()$>
|
||||
|
@ -30,7 +30,9 @@ void main(void) {
|
|||
float shadowAttenuation = evalShadowAttenuation(worldPos);
|
||||
|
||||
// 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(
|
||||
deferredTransform.viewInverse,
|
||||
shadowAttenuation,
|
||||
|
|
|
@ -30,7 +30,7 @@ void main(void) {
|
|||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
||||
|
||||
float opacity = 1.0;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
|
||||
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)$>
|
||||
|
||||
float opacity = 1.0;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
|
||||
vec3 albedo = getMaterialAlbedo(mat);
|
||||
|
|
|
@ -31,7 +31,7 @@ void main(void) {
|
|||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex, occlusionTex)$>
|
||||
|
||||
float opacity = 1.0;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
|
||||
vec3 albedo = getMaterialAlbedo(mat);
|
||||
|
|
|
@ -38,8 +38,7 @@ void main(void) {
|
|||
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex, occlusionTex)$>
|
||||
|
||||
float opacity = getMaterialOpacity(mat) * _alpha;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
|
||||
<$discardTransparent(opacity)$>;
|
||||
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>;
|
||||
|
||||
vec3 albedo = getMaterialAlbedo(mat);
|
||||
<$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,
|
||||
fragOpacity);
|
||||
|
||||
|
||||
// Apply standard tone mapping
|
||||
_fragColor = vec4(pow(color.xyz, vec3(1.0 / 2.2)), color.w);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// overlay3D_translucent_emissive.frag
|
||||
// overlay3D_translucent_unlit.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Zach Pomerantz on 2/2/2016.
|
|
@ -2,7 +2,7 @@
|
|||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// overlay3D_emissive.frag
|
||||
// overlay3D_unlit.frag
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Zach Pomerantz on 2/2/2016.
|
|
@ -13,7 +13,7 @@
|
|||
//
|
||||
|
||||
// Everything about deferred buffer
|
||||
<@include DeferredBuffer.slh@>
|
||||
<@include DeferredBufferRead.slh@>
|
||||
|
||||
//Everything about deferred lighting
|
||||
<@include DeferredLighting.slh@>
|
||||
|
@ -32,6 +32,10 @@ void main(void) {
|
|||
vec2 texCoord = _texCoord0.st / _texCoord0.q;
|
||||
DeferredFragment frag = unpackDeferredFragment(deferredTransform, texCoord);
|
||||
|
||||
if (frag.mode == FRAG_MODE_UNLIT) {
|
||||
discard;
|
||||
}
|
||||
|
||||
mat4 invViewMat = deferredTransform.viewInverse;
|
||||
|
||||
// Kill if in front of the light volume
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
// the interpolated normal
|
||||
out vec3 _normal;
|
||||
out vec3 _modelNormal;
|
||||
out vec3 _color;
|
||||
out vec4 _color;
|
||||
out vec2 _texCoord0;
|
||||
out vec4 _position;
|
||||
|
||||
void main(void) {
|
||||
_color = colorToLinearRGB(inColor.rgb);
|
||||
_color = colorToLinearRGBA(inColor);
|
||||
_texCoord0 = inTexCoord0.st;
|
||||
_position = inPosition;
|
||||
_modelNormal = inNormal.xyz;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include gpu/Color.slh@>
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
<@include model/Material.slh@>
|
||||
|
||||
|
@ -20,13 +21,14 @@ uniform sampler2D originalTexture;
|
|||
|
||||
// the interpolated normal
|
||||
in vec3 _normal;
|
||||
in vec3 _color;
|
||||
in vec4 _color;
|
||||
in vec2 _texCoord0;
|
||||
|
||||
void main(void) {
|
||||
Material material = getMaterial();
|
||||
vec4 texel = texture(originalTexture, _texCoord0);
|
||||
|
||||
if (_color.a <= 0.0) {
|
||||
texel = colorToLinearRGBA(texel);
|
||||
}
|
||||
packDeferredFragment(
|
||||
normalize(_normal.xyz),
|
||||
texel.a,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include gpu/Color.slh@>
|
||||
<@include DeferredBufferWrite.slh@>
|
||||
|
||||
// the albedo texture
|
||||
|
@ -19,18 +20,17 @@ uniform sampler2D originalTexture;
|
|||
|
||||
// the interpolated normal
|
||||
in vec3 _normal;
|
||||
in vec3 _color;
|
||||
in vec4 _color;
|
||||
in vec2 _texCoord0;
|
||||
|
||||
void main(void) {
|
||||
vec4 texel = texture(originalTexture, _texCoord0.st);
|
||||
|
||||
packDeferredFragmentLightmap(
|
||||
if (_color.a <= 0.0) {
|
||||
texel = colorToLinearRGBA(texel);
|
||||
}
|
||||
|
||||
packDeferredFragmentUnlit(
|
||||
normalize(_normal),
|
||||
texel.a,
|
||||
_color.rgb,
|
||||
DEFAULT_ROUGHNESS,
|
||||
DEFAULT_METALLIC,
|
||||
DEFAULT_SPECULAR,
|
||||
texel.rgb);
|
||||
_color.rgb * texel.rgb);
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
//
|
||||
|
||||
// Everything about deferred buffer
|
||||
<@include DeferredBuffer.slh@>
|
||||
<@include DeferredBufferRead.slh@>
|
||||
|
||||
//Everything about deferred lighting
|
||||
<@include DeferredLighting.slh@>
|
||||
|
@ -32,6 +32,10 @@ void main(void) {
|
|||
vec2 texCoord = _texCoord0.st / _texCoord0.q;
|
||||
DeferredFragment frag = unpackDeferredFragment(deferredTransform, texCoord);
|
||||
|
||||
if (frag.mode == FRAG_MODE_UNLIT) {
|
||||
discard;
|
||||
}
|
||||
|
||||
mat4 invViewMat = deferredTransform.viewInverse;
|
||||
|
||||
// Kill if in front of the light volume
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
LIGHTMAP,
|
||||
TANGENTS,
|
||||
SPECULAR,
|
||||
EMISSIVE,
|
||||
UNLIT,
|
||||
SKINNED,
|
||||
STEREO,
|
||||
DEPTH_ONLY,
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
Builder& withLightmap() { _flags.set(LIGHTMAP); return (*this); }
|
||||
Builder& withTangents() { _flags.set(TANGENTS); 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& withStereo() { _flags.set(STEREO); 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& withoutSpecular() { _flags.reset(SPECULAR); _mask.set(SPECULAR); return (*this); }
|
||||
|
||||
Builder& withEmissive() { _flags.set(EMISSIVE); _mask.set(EMISSIVE); return (*this); }
|
||||
Builder& withoutEmissive() { _flags.reset(EMISSIVE); _mask.set(EMISSIVE); return (*this); }
|
||||
Builder& withUnlit() { _flags.set(UNLIT); _mask.set(UNLIT); return (*this); }
|
||||
Builder& withoutUnlit() { _flags.reset(UNLIT); _mask.set(UNLIT); return (*this); }
|
||||
|
||||
Builder& withSkinned() { _flags.set(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 hasTangents() const { return _flags[TANGENTS]; }
|
||||
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 isSkinned() const { return _flags[SKINNED]; }
|
||||
bool isStereo() const { return _flags[STEREO]; }
|
||||
|
@ -173,7 +173,7 @@ inline QDebug operator<<(QDebug debug, const ShapeKey& key) {
|
|||
<< "hasLightmap:" << key.hasLightmap()
|
||||
<< "hasTangents:" << key.hasTangents()
|
||||
<< "hasSpecular:" << key.hasSpecular()
|
||||
<< "hasEmissive:" << key.hasEmissive()
|
||||
<< "isUnlit:" << key.isUnlit()
|
||||
<< "isTranslucent:" << key.isTranslucent()
|
||||
<< "isSkinned:" << key.isSkinned()
|
||||
<< "isStereo:" << key.isStereo()
|
||||
|
|
|
@ -33,6 +33,7 @@ Column {
|
|||
"Roughness",
|
||||
"Metallic",
|
||||
"Emissive",
|
||||
"Shaded/Lightmapped/Unlit",
|
||||
"Occlusion",
|
||||
"Lightmap",
|
||||
"Lighting",
|
||||
|
|
|
@ -739,6 +739,9 @@ function MyController(hand) {
|
|||
};
|
||||
|
||||
this.propsArePhysical = function(props) {
|
||||
if (!props.dynamic) {
|
||||
return false;
|
||||
}
|
||||
var isPhysical = (props.shapeType && props.shapeType != 'none');
|
||||
return isPhysical;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <render-utils/simple_vert.h>
|
||||
#include <render-utils/simple_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_limited_vert.h>
|
||||
|
@ -160,7 +160,7 @@ void QTestWindow::draw() {
|
|||
testShaderBuild(skybox_vert, skybox_frag);
|
||||
testShaderBuild(simple_vert, simple_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_ambient_light_frag);
|
||||
testShaderBuild(deferred_light_vert, directional_skybox_light_frag);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "TextTemplate.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
|
||||
|
@ -168,7 +169,7 @@ int main (int argc, char** argv) {
|
|||
auto scribe = std::make_shared<TextTemplate>(srcFilename, config);
|
||||
|
||||
// ready to parse and generate
|
||||
std::ostringstream destStringStream;
|
||||
std::stringstream destStringStream;
|
||||
int numErrors = scribe->scribe(destStringStream, srcStream, vars);
|
||||
if (numErrors) {
|
||||
cerr << "Scribe " << srcFilename << "> failed: " << numErrors << " errors." << endl;
|
||||
|
@ -187,14 +188,38 @@ int main (int argc, char** argv) {
|
|||
|
||||
std::ostringstream targetStringStream;
|
||||
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 << "#ifndef scribe_" << targetName << "_h" << std::endl;
|
||||
targetStringStream << "#define scribe_" << targetName << "_h" << std::endl << std::endl;
|
||||
|
||||
// targetStringStream << "const char " << targetName << "[] = R\"XXXX(" << destStringStream.str() << ")XXXX\";";
|
||||
targetStringStream << "const char " << targetName << "[] = R\"SCRIBE(";
|
||||
targetStringStream << destStringStream.str();
|
||||
targetStringStream << "\n)SCRIBE\";\n\n";
|
||||
targetStringStream << "const char " << targetName << "[] = \n";
|
||||
|
||||
// Write the pages content
|
||||
for (auto page : pages) {
|
||||
targetStringStream << "R\"SCRIBE(\n" << page->str() << "\n)SCRIBE\"\n";
|
||||
}
|
||||
targetStringStream << ";\n" << std::endl << std::endl;
|
||||
|
||||
targetStringStream << "#endif" << std::endl;
|
||||
} else {
|
||||
targetStringStream << destStringStream.str();
|
||||
|
|
Loading…
Reference in a new issue