// 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); }
// Should be called per material. public void ExportAmbientLight(IExportableMaterial exportableMaterial, Color color) { GlTF_Material mtl = G.materials[exportableMaterial]; var val = new GlTF_Material.ColorKV { key = "ambient_light_color", color = color }; mtl.values.Add(val); AddUniform(exportableMaterial, val.key, GlTF_Technique.Type.FLOAT_VEC4, GlTF_Technique.Semantic.UNKNOWN); }
// Export a single shader color uniform public void ExportShaderUniform( IExportableMaterial exportableMaterial, string name, Color value) { GlTF_Material mtl = G.materials[exportableMaterial]; var color_val = new GlTF_Material.ColorKV { key = name, color = value }; mtl.values.Add(color_val); AddUniform(exportableMaterial, color_val.key, GlTF_Technique.Type.FLOAT_VEC4, GlTF_Technique.Semantic.UNKNOWN); }