// Shader to draw the world texture onto the window
struct CameraUniform {
    view_proj: mat4x4<f32>,
};
@group(1) @binding(0) // 1.
var<uniform> camera: CameraUniform;

struct RenderOptions {
    gamma: f32,  
    _padding: vec3<f32>,
};
@group(2) @binding(0)
var<uniform> render_options: RenderOptions;

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

struct VertexOutput {
    @builtin(position) clip_position: vec4<f32>,
    @location(0) tex_coords: vec2<f32>,
    @location(1) color: vec4<f32>,
}

@vertex
fn vs_main(model: VertexInput) -> VertexOutput {
    var out: VertexOutput;
    let tc = camera.view_proj * vec4<f32>(model.tex_coords, 0.0, 1.0);
    out.tex_coords = tc.xy / tc.w;
    out.clip_position = vec4<f32>(model.position.xyz, 1.0);
    // out.clip_position = vec4<f32>(model.position.xy, 0.0, 1.0);
    // out.color = vec4<f32>(out.clip_position);
    out.color = model.color;
    // out.color = vec4<f32>(out.tex_coords, 0.0, 1.0);
    return out;
}

@group(0) @binding(0)
var t_world: texture_2d<f32>;
@group(0) @binding(1)
var s_world: sampler;

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
    // let textureDims = vec2<f32>(textureDimensions(t_world));
    let t_tex_coords = in.tex_coords;
    
    var textureOffset = vec2<f32>(1) / vec2<f32>(textureDimensions(t_world));
    var result = in.color * textureSample(t_world, s_world, t_tex_coords);
    return result;
}