Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to provide image dimensions type/layers count in ImageLoaderSettings #17145

Open
MatrixDev opened this issue Jan 4, 2025 · 0 comments
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@MatrixDev
Copy link

What problem does this solve or what need does it fill?

Makes the usage of stacked 2D array (and similar) textures much much easier and less error prone.

What solution would you like?

Adding enum specifying texture type during asset loading to ImageLoaderSettings:

enum ImageDimensions {
    D1,
    D2,
    D2Array(u32),
}

struct ImageLoaderSettings {
    // ...
    dimensions: ImageDimensions,
}

So it can be used after:

#[derive(Asset, AsBindGroup, Reflect, Debug, Default, Clone)]
struct MyMaterial {
    #[texture(0, dimension = "2d_array")]
    #[sampler(1)]
    pub textures: Handle<Image>,
}

let textures = assets.load_with_settings("assets/2d_array.png", |s: &mut ImageLoaderSettings| {
    s.dimentions = ImageDimensions::D2Array(3);
});

commands.spawn((
    Mesh3d(mesh),
    MeshMaterial3d(materials.add(MyMaterial { textures })),
));

What alternative(s) have you considered?

The only alternative so far is to track when the image was loaded and call reinterpret_stacked_2d_as_array manually. But this requires a lot of boiler plate code and feels like a workaround. Also if there is any delay in calling reinterpret_stacked_2d_as_array, program will crash because shader expects 2d-array texture, but receives 2d texture.

@MatrixDev MatrixDev added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jan 4, 2025
@BenjaminBrienen BenjaminBrienen added A-Rendering Drawing game state to the screen A-Assets Load files from disk to use for things like images, models, and sounds S-Needs-Design This issue requires design work to think about how it would best be accomplished D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes and removed S-Needs-Triage This issue needs to be labelled labels Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

2 participants