Shader effects should be controlled by components::Animation #103

Open
opened 2026-01-03 05:32:35 +00:00 by zedshaw · 0 comments
Owner

In raycaster.cpp I have this function:

void Raycaster::apply_sprite_effect(shared_ptr<sf::Shader> effect, float width, float height) {
  effect->setUniform("u_time", $clock.getElapsedTime().asSeconds());
  sf::Vector2f u_resolution{width, height};
  effect->setUniform("u_resolution", u_resolution);
}

And in scene.cpp I have this code:

          actor.effect->setUniform("u_time", actor.anim.subframe);
          sf::Vector2f u_resolution{float(actor.anim.frame_width), float(actor.anim.frame_height)};
          actor.effect->setUniform("u_resolution", u_resolution);

This caused me a problem because for the shader to work u_resolution has to be set, but I only set it in the raycaster or in guecs::Effect. The shaders only worked if I had them on a GUI element.

Really, the animation knows the size of the image, and when the effect is supposed to play, so that should be the thing that controls the shader.

In raycaster.cpp I have this function: ```cpp void Raycaster::apply_sprite_effect(shared_ptr<sf::Shader> effect, float width, float height) { effect->setUniform("u_time", $clock.getElapsedTime().asSeconds()); sf::Vector2f u_resolution{width, height}; effect->setUniform("u_resolution", u_resolution); } ``` And in scene.cpp I have this code: ```cpp actor.effect->setUniform("u_time", actor.anim.subframe); sf::Vector2f u_resolution{float(actor.anim.frame_width), float(actor.anim.frame_height)}; actor.effect->setUniform("u_resolution", u_resolution); ``` This caused me a problem because for the shader to work u_resolution has to be set, but I only set it in the raycaster or in guecs::Effect. The shaders only worked if I had them on a GUI element. Really, the animation knows the size of the image, and when the effect is supposed to play, so that should be the thing that controls the shader.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: games/raycaster#103
No description provided.