Skip to content

Conversation

@zachrburke
Copy link

Background

I was inspired by this video that showcases applying a single texture across an entire tilemap while preserving the edges. They achieve this effect with a shader. I wanted to try recreating that effect in bevy, and I'm currently using bevy_ecs_tilemap as part of the bevy_ecs_ldtk crate.

Problem

One trick this shader relies on is using the world position of each vertex to apply the texture. The world texture is not part of the MeshVertexOutput that the default vertex shader returns. I tried to work around this by using the "local" position and the fract function but the result was the texture following the camera around.

I'm also not sure how to create my own vertex shader without the existing logic that runs today. I took a stab at it in my project but I couldn't get it to work and had to recreate a lot of code already present in the crate.

Proposed Solution

The world_position is already available in the mesh_data object and is being used to calculate the local position. This change exposes mesh_data.world_position so it can be used in the fragment shader without having to write a new vertex shader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant