{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:imperial-school:space-layer-bindings:1.0",
  "title": "Optional render.space_layers 1.0 — implementation specification",
  "type": "object",
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "frame": {
      "type": "object",
      "properties": {
        "mode": {
          "const": "hourly_snapshot"
        },
        "at_field": {
          "const": "at"
        },
        "interval_seconds": {
          "const": 3600
        },
        "interpolation": {
          "const": "none"
        }
      },
      "required": [
        "mode",
        "at_field",
        "interval_seconds",
        "interpolation"
      ],
      "additionalProperties": true
    },
    "failure_policy": {
      "type": "object",
      "properties": {
        "geometry_or_resources": {
          "const": "legacy_recipe"
        },
        "stars_only": {
          "const": "omit_stars"
        }
      },
      "required": [
        "geometry_or_resources",
        "stars_only"
      ],
      "additionalProperties": true
    },
    "inputs": {
      "type": "object",
      "properties": {
        "frame_at": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "status": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "camera_position_gcrs": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "station_position_gcrs": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "camera_to_gcrs": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "gcrs_to_camera": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "rtn_to_gcrs": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "horizontal_fov_deg": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "earth_radius_km": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "gcrs_to_itrs": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "earth_sun_direction_itrs": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "station_sunlit_fraction": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "stars_status": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "stars_columns": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "stars_points": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "sun": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "moon": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        }
      },
      "required": [
        "frame_at",
        "status",
        "camera_position_gcrs",
        "station_position_gcrs",
        "camera_to_gcrs",
        "gcrs_to_camera",
        "rtn_to_gcrs",
        "horizontal_fov_deg",
        "earth_radius_km",
        "gcrs_to_itrs",
        "earth_sun_direction_itrs",
        "station_sunlit_fraction",
        "stars_status",
        "stars_columns",
        "stars_points",
        "sun",
        "moon"
      ],
      "additionalProperties": true
    },
    "resources": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_-]*$"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "file": {
            "type": "string",
            "pattern": "^[^\\\\]+\\.png$"
          },
          "kind": {
            "enum": [
              "rgba_sprite",
              "rgb_equirectangular",
              "rgba_disc",
              "rgba_albedo",
              "rgb_normal_rtn",
              "rgb_emission",
              "l_occlusion"
            ]
          }
        },
        "required": [
          "file",
          "kind"
        ],
        "additionalProperties": true
      }
    },
    "drop_layers": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_-]*$"
      }
    },
    "lighting": {
      "type": "object",
      "properties": {
        "ambient_rgb": {
          "type": "array",
          "minItems": 3,
          "maxItems": 3,
          "items": {
            "type": "number",
            "minimum": 0
          }
        },
        "direct_rgb": {
          "type": "array",
          "minItems": 3,
          "maxItems": 3,
          "items": {
            "type": "number",
            "minimum": 0
          }
        },
        "emission_gain": {
          "type": "number",
          "minimum": 0
        }
      },
      "required": [
        "ambient_rgb",
        "direct_rgb",
        "emission_gain"
      ],
      "additionalProperties": true
    },
    "materials": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_-]*$"
      },
      "additionalProperties": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "mode": {
                "const": "unlit"
              }
            },
            "required": [
              "mode"
            ],
            "additionalProperties": true
          },
          {
            "type": "object",
            "properties": {
              "mode": {
                "const": "normal_rtn"
              },
              "albedo": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "normal": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "emission": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_-]*$"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "mode",
              "albedo",
              "normal",
              "emission"
            ],
            "additionalProperties": true
          }
        ]
      }
    },
    "outputs": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "kind": {
                "const": "solid_rgb"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "opacity": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "color_rgb": {
                "type": "array",
                "minItems": 3,
                "maxItems": 3,
                "items": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 255
                }
              }
            },
            "required": [
              "id",
              "kind",
              "order",
              "opacity",
              "color_rgb"
            ],
            "additionalProperties": true
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "kind": {
                "const": "catalog_sprites"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "opacity": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "sprite": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "style": {
                "type": "object",
                "properties": {
                  "reference_height_px": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "reference_magnitude": {
                    "type": "number"
                  },
                  "reference_diameter_px": {
                    "type": "number",
                    "minimum": 0
                  },
                  "min_diameter_px": {
                    "type": "number",
                    "minimum": 0
                  },
                  "max_diameter_px": {
                    "type": "number",
                    "minimum": 0
                  },
                  "reference_opacity": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "diameter_exponent": {
                    "type": "number",
                    "minimum": 0
                  },
                  "opacity_exponent": {
                    "type": "number",
                    "minimum": 0
                  },
                  "null_bv_rgb": {
                    "type": "array",
                    "minItems": 3,
                    "maxItems": 3,
                    "items": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 255
                    }
                  },
                  "bv_palette": {
                    "type": "array",
                    "minItems": 2,
                    "items": {
                      "type": "object",
                      "properties": {
                        "bv": {
                          "type": "number"
                        },
                        "rgb": {
                          "type": "array",
                          "minItems": 3,
                          "maxItems": 3,
                          "items": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 255
                          }
                        }
                      },
                      "required": [
                        "bv",
                        "rgb"
                      ],
                      "additionalProperties": true
                    }
                  }
                },
                "required": [
                  "reference_height_px",
                  "reference_magnitude",
                  "reference_diameter_px",
                  "min_diameter_px",
                  "max_diameter_px",
                  "reference_opacity",
                  "diameter_exponent",
                  "opacity_exponent",
                  "null_bv_rgb",
                  "bv_palette"
                ],
                "additionalProperties": true
              }
            },
            "required": [
              "id",
              "kind",
              "order",
              "opacity",
              "sprite",
              "style"
            ],
            "additionalProperties": true
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "kind": {
                "const": "sun_disc"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "opacity": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "color_rgb": {
                "type": "array",
                "minItems": 3,
                "maxItems": 3,
                "items": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 255
                }
              }
            },
            "required": [
              "id",
              "kind",
              "order",
              "opacity",
              "color_rgb"
            ],
            "additionalProperties": true
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "kind": {
                "const": "earth_sphere"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "opacity": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "albedo": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "night_emission": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_-]*$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "ambient": {
                "type": "number",
                "minimum": 0
              },
              "direct": {
                "type": "number",
                "minimum": 0
              },
              "night_gain": {
                "type": "number",
                "minimum": 0
              },
              "cloud_map": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "clouds": {
                "type": "object",
                "properties": {
                  "height_km": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 20
                  },
                  "opacity": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "ambient": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "direct": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "coverage_exponent": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "maximum": 4
                  },
                  "color_rgb": {
                    "type": "array",
                    "minItems": 3,
                    "maxItems": 3,
                    "items": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 255
                    }
                  }
                },
                "required": [
                  "height_km",
                  "opacity",
                  "ambient",
                  "direct",
                  "color_rgb"
                ],
                "additionalProperties": true
              },
              "atmosphere": {
                "type": "object",
                "properties": {
                  "height_km": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "maximum": 160
                  },
                  "scale_height_km": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "maximum": 30
                  },
                  "samples": {
                    "type": "integer",
                    "minimum": 4,
                    "maximum": 32
                  },
                  "exposure": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 4
                  },
                  "color_rgb": {
                    "type": "array",
                    "minItems": 3,
                    "maxItems": 3,
                    "items": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 255
                    }
                  },
                  "rayleigh_per_km": {
                    "type": "array",
                    "minItems": 3,
                    "maxItems": 3,
                    "items": {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 1
                    }
                  }
                },
                "required": [
                  "height_km",
                  "scale_height_km",
                  "exposure",
                  "color_rgb",
                  "rayleigh_per_km"
                ],
                "additionalProperties": true
              }
            },
            "required": [
              "id",
              "kind",
              "order",
              "opacity",
              "albedo",
              "night_emission",
              "ambient",
              "direct",
              "night_gain"
            ],
            "additionalProperties": true
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "kind": {
                "const": "moon_camera_disc"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "opacity": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "albedo": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "texture_rotation_deg": {
                "type": "number"
              },
              "ambient": {
                "type": "number",
                "minimum": 0
              },
              "direct": {
                "type": "number",
                "minimum": 0
              }
            },
            "required": [
              "id",
              "kind",
              "order",
              "opacity",
              "albedo",
              "texture_rotation_deg",
              "ambient",
              "direct"
            ],
            "additionalProperties": true
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "kind": {
                "const": "surface_group"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "opacity": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "source_layers": {
                "type": "array",
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_-]*$"
                }
              },
              "cutout_layers": {
                "type": "array",
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_-]*$"
                }
              }
            },
            "required": [
              "id",
              "kind",
              "order",
              "opacity",
              "source_layers",
              "cutout_layers"
            ],
            "additionalProperties": true
          }
        ]
      }
    },
    "relight_layers": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_-]*$"
      }
    },
    "unmapped_material": {
      "const": "error"
    },
    "occlusion_masks": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_-]*$"
      },
      "additionalProperties": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_-]*$"
      }
    }
  },
  "required": [
    "schema_version",
    "frame",
    "failure_policy",
    "inputs",
    "resources",
    "drop_layers",
    "lighting",
    "materials",
    "outputs",
    "relight_layers",
    "unmapped_material"
  ],
  "additionalProperties": true
}
