struct VertexInput {
    @location(0) position: vec3<f32>,
    @location(1) normal: vec3<f32>,
    @location(2) tex_coords: vec2<f32>,
};

struct VertexOutput {
    @builtin(position) position: vec4<f32>,
};

struct Uniforms {
    view: mat4x4<f32>,
    projection: mat4x4<f32>,
};

struct ModelMatrix {
    model: mat4x4<f32>,
};

struct ObjectData {
    transform_index: u32,
    mesh_id: u32,
    material_id: u32,
    batch_id: u32,
    morph_weights: array<f32, 8>,
    morph_target_count: u32,
    morph_displacement_offset: u32,
    mesh_vertex_offset: u32,
    mesh_vertex_count: u32,
    entity_id: u32,
    _entity_padding: array<u32, 3>,
};

@group(0) @binding(0)
var<uniform> uniforms: Uniforms;

@group(1) @binding(0)
var<storage, read> transforms: array<ModelMatrix>;

@group(1) @binding(1)
var<storage, read> objects: array<ObjectData>;

@vertex
fn vs_main(
    in: VertexInput,
    @builtin(instance_index) instance_id: u32
) -> VertexOutput {
    var out: VertexOutput;

    let object = objects[instance_id];
    let model = transforms[object.transform_index].model;
    let world_pos = model * vec4<f32>(in.position, 1.0);
    out.position = uniforms.projection * uniforms.view * world_pos;

    return out;
}

@fragment
fn fs_main(in: VertexOutput) -> @location(0) f32 {
    return 1.0;
}
