mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-20 04:02:25 +02:00
hack a separate emissive information in the g-buffer
This commit is contained in:
parent
cb1850e082
commit
77077f4e9c
6 changed files with 58 additions and 37 deletions
|
|
@ -36,25 +36,36 @@ uniform vec2 depthTexCoordOffset;
|
|||
uniform vec2 depthTexCoordScale;
|
||||
|
||||
void main(void) {
|
||||
float depthVal = texture2D(depthMap, gl_TexCoord[0].st).r;
|
||||
vec4 normalVal = texture2D(normalMap, gl_TexCoord[0].st);
|
||||
vec4 diffuseVal = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
vec4 specularVal = texture2D(specularMap, gl_TexCoord[0].st);
|
||||
|
||||
// compute the view space position using the depth
|
||||
float z = near / (texture2D(depthMap, gl_TexCoord[0].st).r * depthScale - 1.0);
|
||||
float z = near / (depthVal * depthScale - 1.0);
|
||||
vec4 position = vec4((depthTexCoordOffset + gl_TexCoord[0].st * depthTexCoordScale) * z, z, 0.0);
|
||||
|
||||
// get the normal from the map
|
||||
vec4 normal = texture2D(normalMap, gl_TexCoord[0].st);
|
||||
vec4 normalizedNormal = normalize(normal * 2.0 - vec4(1.0, 1.0, 1.0, 2.0));
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
vec4 baseColor = texture2D(diffuseMap, gl_TexCoord[0].st) * (gl_FrontLightModelProduct.sceneColor +
|
||||
gl_FrontLightProduct[0].ambient + gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
|
||||
|
||||
// compute the specular multiplier (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(position)),
|
||||
normalizedNormal));
|
||||
|
||||
// add specular contribution
|
||||
vec4 specularColor = texture2D(specularMap, gl_TexCoord[0].st);
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normal.a);
|
||||
vec4 normal = normalVal;
|
||||
if (normalVal.a == 0.5) {
|
||||
normal.a = 1.0;
|
||||
normalVal.a = 0.0;
|
||||
gl_FragColor = vec4(diffuseVal.rgb * specularColor.rgb, normal.a);
|
||||
} else {
|
||||
vec3 normalizedNormal = normalize(normal.xyz * 2.0 - vec3(1.0));
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position.xyz);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
vec3 baseColor = diffuseVal.rgb * (gl_FrontLightModelProduct.sceneColor.rgb +
|
||||
gl_FrontLightProduct[0].ambient.rgb + gl_FrontLightProduct[0].diffuse.rgb * (diffuse * facingLight));
|
||||
|
||||
// compute the specular multiplier (sans exponent)
|
||||
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position.xyz - normalize(position.xyz)),
|
||||
normalizedNormal));
|
||||
|
||||
// add specular contribution
|
||||
vec4 specularColor = specularVal;
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normal.a);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ void main(void) {
|
|||
// set the diffuse, normal, specular data
|
||||
vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st);
|
||||
vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0);
|
||||
gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0);
|
||||
gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold)));
|
||||
gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
|
||||
gl_FragData[2] = vec4((vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), gl_FrontMaterial.shininess / 128.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -829,10 +829,17 @@ void GeometryReader::run() {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&,
|
||||
std::string urlname = _url.path().toLower().toStdString();
|
||||
FBXGeometry fbxgeo;
|
||||
if (_url.path().toLower().endsWith(".svo")) {
|
||||
fbxgeo = readSVO(_reply->readAll());
|
||||
} else {
|
||||
fbxgeo = readFBX(_reply->readAll(), _mapping);
|
||||
}
|
||||
QMetaObject::invokeMethod(geometry.data(), "setGeometry", Q_ARG(const FBXGeometry&, fbxgeo));
|
||||
|
||||
|
||||
_url.path().toLower().endsWith(".svo") ? readSVO(_reply->readAll()) : readFBX(_reply->readAll(), _mapping)));
|
||||
// _url.path().toLower().endsWith(".svo") ? readSVO(_reply->readAll()) : readFBX(_reply->readAll(), _mapping)));
|
||||
|
||||
} catch (const QString& error) {
|
||||
qDebug() << "Error reading " << _url << ": " << error;
|
||||
|
|
|
|||
|
|
@ -2382,12 +2382,10 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
|
|||
}
|
||||
|
||||
if (locations->emissiveTextureUnit >= 0) {
|
||||
assert(locations->emissiveParams >= 0); // we should have the emissiveParams defined in the shader
|
||||
static float emissiveOffset = 0.1f;
|
||||
static float emissiveScale = 1.0f;
|
||||
//GLBATCH(glUniform2f)(locations->emissiveParams, 0.1f, 4.0f);
|
||||
// assert(locations->emissiveParams >= 0); // we should have the emissiveParams defined in the shader
|
||||
float emissiveOffset = part.emissiveParams.x;
|
||||
float emissiveScale = part.emissiveParams.y;
|
||||
GLBATCH(glUniform2f)(locations->emissiveParams, emissiveOffset, emissiveScale);
|
||||
|
||||
|
||||
GLBATCH(glActiveTexture)(GL_TEXTURE0 + locations->emissiveTextureUnit);
|
||||
Texture* emissiveMap = networkPart.emissiveTexture.data();
|
||||
|
|
|
|||
|
|
@ -1216,6 +1216,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||
QHash<QString, QString> bumpTextures;
|
||||
QHash<QString, QString> specularTextures;
|
||||
QHash<QString, QString> emissiveTextures;
|
||||
QHash<QString, QString> ambientTextures;
|
||||
QHash<QString, QString> localRotations;
|
||||
QHash<QString, QString> xComponents;
|
||||
QHash<QString, QString> yComponents;
|
||||
|
|
@ -1707,7 +1708,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||
emissiveTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
|
||||
} else if (type.contains("ambient")) {
|
||||
emissiveTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
ambientTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||
} else {
|
||||
std::string typenam = type.data();
|
||||
counter++;
|
||||
|
|
@ -1952,19 +1953,20 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||
}
|
||||
|
||||
FBXTexture emissiveTexture;
|
||||
glm::vec2 emissiveParams(0.f, 1.f);
|
||||
QString emissiveTextureID = emissiveTextures.value(childID);
|
||||
if (!emissiveTextureID.isNull()) {
|
||||
emissiveTexture = getTexture(emissiveTextureID, textureNames, textureFilenames, textureContent, textureParams);
|
||||
|
||||
// FBX files generated by 3DSMax have an intermediate texture parent, apparently
|
||||
foreach (const QString& childTextureID, childMap.values(diffuseTextureID)) {
|
||||
if (textureFilenames.contains(childTextureID)) {
|
||||
emissiveTexture = getTexture(emissiveTextureID, textureNames, textureFilenames, textureContent, textureParams);
|
||||
}
|
||||
QString ambientTextureID = ambientTextures.value(childID);
|
||||
if (!emissiveTextureID.isNull() || !ambientTextureID.isNull()) {
|
||||
|
||||
if (!emissiveTextureID.isNull()) {
|
||||
emissiveTexture = getTexture(emissiveTextureID, textureNames, textureFilenames, textureContent, textureParams);
|
||||
emissiveParams.y = 4.0f;
|
||||
} else if (!ambientTextureID.isNull()) {
|
||||
emissiveTexture = getTexture(ambientTextureID, textureNames, textureFilenames, textureContent, textureParams);
|
||||
}
|
||||
|
||||
emissiveTexture.texcoordSet = matchTextureUVSetToAttributeChannel(emissiveTexture.texcoordSetName, extracted.texcoordSetMap);
|
||||
|
||||
|
||||
detectDifferentUVs |= (emissiveTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity());
|
||||
}
|
||||
|
||||
|
|
@ -1992,6 +1994,8 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
|||
if (!emissiveTexture.filename.isNull()) {
|
||||
part.emissiveTexture = emissiveTexture;
|
||||
}
|
||||
part.emissiveParams = emissiveParams;
|
||||
|
||||
part.materialID = material.id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ public:
|
|||
glm::vec3 diffuseColor;
|
||||
glm::vec3 specularColor;
|
||||
glm::vec3 emissiveColor;
|
||||
glm::vec2 emissiveParams;
|
||||
float shininess;
|
||||
float opacity;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue