Playing around with shaders for effects on the scene.

This commit is contained in:
Zed A. Shaw 2025-01-27 11:36:00 -05:00
parent 3519c73079
commit 071808a0f8
8 changed files with 68 additions and 4 deletions

View file

@ -36,7 +36,8 @@ Raycaster::Raycaster(sf::RenderWindow& window, Matrix &map, int width, int heigh
$map(map),
spriteOrder(NUM_SPRITES),
spriteDistance(NUM_SPRITES),
ZBuffer(width)
ZBuffer(width),
$anim(256, 256, 10, "assets/monster-1.ogg")
{
$view_sprite.setPosition({0, 0});
$pixels = make_unique<RGBA[]>($width * $height);
@ -46,6 +47,13 @@ Raycaster::Raycaster(sf::RenderWindow& window, Matrix &map, int width, int heigh
$view_texture.setSmooth(false);
}
void Raycaster::init_shaders() {
bool good = $paused.loadFromFile("shaders/modal.frag", sf::Shader::Type::Fragment);
dbc::check(good, "shader could not be loaded");
$paused.setUniform("offsetFactor", sf::Glsl::Vec2{0.01f, 0.01f});
$paused.setUniform("darkness", 0.01f);
}
void Raycaster::set_position(int x, int y) {
$view_sprite.setPosition({(float)x, (float)y});
}
@ -58,7 +66,7 @@ void Raycaster::position_camera(float player_x, float player_y) {
void Raycaster::draw_pixel_buffer() {
$view_texture.update((uint8_t *)$pixels.get(), {(unsigned int)$width, (unsigned int)$height}, {0, 0});
$window.draw($view_sprite);
$window.draw($view_sprite, $active_shader);
}
void Raycaster::clear() {
@ -152,7 +160,7 @@ void Raycaster::sprite_casting() {
$anim.step(*sf_sprite, texX, texY, texX_end - texX, textureHeight);
sf_sprite->setPosition({x, y});
$window.draw(*sf_sprite);
$window.draw(*sf_sprite, $active_shader);
}
}
}