change world tiles texture from texture_2d_array to an atlas texture_2d
This commit is contained in:
+13
-7
@@ -37,9 +37,9 @@ struct Per_Frame_Data {
|
||||
var output: VertexShaderOutput;
|
||||
|
||||
let tile_type = extractBits(input.tile_info, 0, 16);
|
||||
let rotation = extractBits(input.tile_info, 16, 2);
|
||||
let rotation = extractBits(input.tile_info, 16, 2);
|
||||
|
||||
let tile_pos = vec2<f32>(f32(input.instance_index % per_frame.map_width), f32(input.instance_index / per_frame.map_width)) - vec2<f32>(0.5, 0.5);
|
||||
let tile_pos = vec2<f32>(f32(input.instance_index % per_frame.map_width), f32(input.instance_index / per_frame.map_width)) - vec2<f32>(0.5, 0.5);
|
||||
|
||||
output.tile = tile_type;
|
||||
output.pos = vec4<f32>(tile_pos + input.pos.xy, 0, 1) * view_projection_matrix;
|
||||
@@ -55,11 +55,13 @@ struct Per_Frame_Data {
|
||||
return output;
|
||||
}
|
||||
|
||||
@group(1) @binding(0) var texture1: texture_2d_array<f32>;
|
||||
@group(1) @binding(0) var texture1: texture_2d<f32>;
|
||||
@group(1) @binding(1) var sampler1: sampler;
|
||||
|
||||
@group(1) @binding(2) var<uniform> tint: vec3<f32>;
|
||||
|
||||
@group(1) @binding(3) var<storage> tile_uvs: array<vec4<f32>>;
|
||||
|
||||
@fragment fn main_fragment(input: VertexShaderOutput) -> FragmentShaderOutput {
|
||||
var output: FragmentShaderOutput;
|
||||
|
||||
@@ -69,11 +71,15 @@ struct Per_Frame_Data {
|
||||
return output;
|
||||
}
|
||||
|
||||
fn pixel_art_sample(input_texture: texture_2d_array<f32>, input_sampler: sampler, input_uv: vec2<f32>, index: u32) -> vec4<f32> {
|
||||
fn pixel_art_sample(input_texture: texture_2d<f32>, input_sampler: sampler, input_uv: vec2<f32>, tile: u32) -> vec4<f32> {
|
||||
let dimensions = vec2<f32>(textureDimensions(input_texture));
|
||||
|
||||
let texture_uv = input_uv * dimensions.xy;
|
||||
let sample_uv = (floor(texture_uv) + min(fract(texture_uv) / fwidth(texture_uv), vec2<f32>(1.0, 1.0)) - 0.5) / dimensions.xy;
|
||||
let tile_uv = tile_uvs[tile];
|
||||
|
||||
let texture_uv = mix(tile_uv.xy, tile_uv.zw, input_uv);
|
||||
let sample_uv = (floor(texture_uv) + saturate(fract(texture_uv) / fwidth(texture_uv)) - 0.5) / dimensions;
|
||||
|
||||
let uv = clamp(sample_uv, (tile_uv.xy + 0.5) / dimensions, (tile_uv.zw - 0.5) / dimensions);
|
||||
|
||||
return textureSample(input_texture, input_sampler, sample_uv, index);
|
||||
return textureSample(input_texture, input_sampler, uv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user