// This does once-per-light work, as well as once-per-material-per-light work. // So this ends up being called multiple times with the same parameters, except // for matObjName. // matObjName is the name of the material being exported // lightObjectName is the name of the light public void ExportLight(LightPayload payload, IExportableMaterial exportableMaterial) { ObjectName lightNodeName = new ObjectName(payload.legacyUniqueName); // does need to be unique // Add the light to the scene -- this does _not_ need to be done per-material. // As a result, the node will generally have already been created. GlTF_Node node = GlTF_Node.GetOrCreate(G, lightNodeName, payload.xform, null, out _); node.lightNameThatDoesNothing = payload.name; // The names of the uniforms can be anything, really. Named after the light is the most // logical choice, but note that nobody checks that two lights don't have the same name. // Thankfully for Tilt Brush, they don't. // This should probably have used a guaranteed-unique name from the start but I don't want // to change it now because it'd break my diffs and be kind of ugly. string lightUniformPrefix = payload.name; AddUniform(exportableMaterial, lightUniformPrefix + "_matrix", GlTF_Technique.Type.FLOAT_MAT4, GlTF_Technique.Semantic.MODELVIEW, node); // Add light color. GlTF_Material mtl = G.materials[exportableMaterial]; var val = new GlTF_Material.ColorKV { key = lightUniformPrefix + "_color", color = payload.lightColor }; mtl.values.Add(val); AddUniform(exportableMaterial, val.key, GlTF_Technique.Type.FLOAT_VEC4, GlTF_Technique.Semantic.UNKNOWN, node); }
/// Convert the light colors to linear /// Beware that you will lose information when quantizing down from /// linear-float32 to linear-uint8. public static void ConvertToLinearColorspace(LightPayload lights) { // XXX: these values can be > 1 because they are pre-multiplied by intensity // Is it more appropriate to convert the base color from sRGB -> Linear, // _then_ multiply by intensity? lights.ambientColor = lights.ambientColor.linear; for (int i = 0; i < lights.Count; i++) { lights.lightColor[i] = lights.lightColor[i].linear; } }