The flame shader now only turns on when facing an enemy. Next is tagging enemies with specific shaders to apply at a specific time.
This commit is contained in:
parent
5ffa3b0d1e
commit
1b4f55804c
6 changed files with 29 additions and 13 deletions
|
@ -7,11 +7,11 @@
|
|||
"file_name": "assets/shaders/ui_error.frag",
|
||||
"type": "fragment"
|
||||
},
|
||||
"flame": {
|
||||
"rayview_sprites": {
|
||||
"file_name": "assets/shaders/rayview_sprites.frag",
|
||||
"type": "fragment"
|
||||
},
|
||||
"rayview_sprites": {
|
||||
"flame": {
|
||||
"file_name": "assets/shaders/flame_trash.frag",
|
||||
"type": "fragment"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D source;
|
||||
uniform float u_mouse;
|
||||
uniform float value = 0.2;
|
||||
|
||||
|
@ -69,9 +69,9 @@ void main() {
|
|||
|
||||
color *= (f*f*f+0.5*f*f+0.6*f) * value;
|
||||
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
|
||||
vec4 pixel = texture2D(source, gl_TexCoord[0].xy);
|
||||
|
||||
float mask = color.r * pixel.a;
|
||||
|
||||
gl_FragColor = gl_Color * vec4(color, pixel.a) + pixel;
|
||||
gl_FragColor = gl_Color * vec4(color, mask) + pixel;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace gui {
|
|||
void CombatUI::make_button(std::string name, std::wstring label, Events::GUI event) {
|
||||
auto button = $gui.entity(name);
|
||||
$gui.set<Sprite>(button, {"leather_pouch-128"});
|
||||
// $gui.set<Rectangle>(button, {});
|
||||
$gui.set<Rectangle>(button, {});
|
||||
$gui.set<Sound>(button, {"ui_click"});
|
||||
$gui.set<Label>(button, {label});
|
||||
$gui.set<Effect>(button, {.duration=0.1f});
|
||||
|
|
|
@ -72,6 +72,14 @@ void Raycaster::draw_pixel_buffer() {
|
|||
$view_texture.update((uint8_t *)$pixels.get(), {(unsigned int)$width, (unsigned int)$height}, {0, 0});
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
||||
constexpr const int texture_width = TEXTURE_WIDTH;
|
||||
constexpr const int texture_height = TEXTURE_HEIGHT;
|
||||
|
@ -171,14 +179,18 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
|||
// the actual distance we need to sqrt that.
|
||||
// float level = sqrt(rec.first);
|
||||
float level = lights[sprite_pos.location.y][sprite_pos.location.x] * PERCENT;
|
||||
if(rec.second == aiming_at) level += 0.2;
|
||||
$brightness->setUniform("darkness", level);
|
||||
|
||||
$brightness->setUniform("u_time", $clock.getElapsedTime().asSeconds());
|
||||
sf::Vector2f sprite_size{(float)sprite_width, (float)sprite_height};
|
||||
$brightness->setUniform("u_resolution", sprite_size);
|
||||
shared_ptr<sf::Shader> effect = nullptr;
|
||||
|
||||
target.draw(*sf_sprite, $brightness.get());
|
||||
if(rec.second == aiming_at) {
|
||||
effect = $flame;
|
||||
apply_sprite_effect(effect, sprite_width, sprite_height);
|
||||
} else {
|
||||
effect = $brightness;
|
||||
effect->setUniform("darkness", level);
|
||||
}
|
||||
|
||||
target.draw(*sf_sprite, effect.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -400,4 +412,6 @@ void Raycaster::update_level(GameLevel level) {
|
|||
void Raycaster::init_shaders() {
|
||||
$brightness = shaders::get("rayview_sprites");
|
||||
$brightness->setUniform("source", sf::Shader::CurrentTexture);
|
||||
$flame = shaders::get("flame");
|
||||
$flame->setUniform("source", sf::Shader::CurrentTexture);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ struct Raycaster {
|
|||
int $pitch=0;
|
||||
sf::Clock $clock;
|
||||
std::shared_ptr<sf::Shader> $brightness = nullptr;
|
||||
std::shared_ptr<sf::Shader> $flame = nullptr;
|
||||
double $pos_x = 0;
|
||||
double $pos_y = 0;
|
||||
|
||||
|
@ -62,4 +63,5 @@ struct Raycaster {
|
|||
void update_level(GameLevel level);
|
||||
void update_sprite(DinkyECS::Entity ent, components::Sprite& sprite);
|
||||
void init_shaders();
|
||||
void apply_sprite_effect(shared_ptr<sf::Shader> effect, float width, float height);
|
||||
};
|
||||
|
|
|
@ -84,7 +84,7 @@ int main(int argc, char *argv[]) {
|
|||
sf::Vector2f scale{u_resolution.x / bounds.size.x,
|
||||
u_resolution.y / bounds.size.y};
|
||||
sprite_texture.sprite->setScale(scale);
|
||||
shader.setUniform("texture", sf::Shader::CurrentTexture);
|
||||
shader.setUniform("source", sf::Shader::CurrentTexture);
|
||||
} else {
|
||||
rect.setPosition({0,0});
|
||||
rect.setSize(u_resolution);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue