Class: Rendering::BloomEffect

Inherits:
Object
  • Object
show all
Includes:
Effect
Defined in:
lib/engine/rendering/post_processing/bloom_effect.rb

Instance Attribute Summary

Attributes included from Effect

#enabled

Instance Method Summary collapse

Constructor Details

#initialize(threshold: 0.7, intensity: 1.0, blur_passes: 2, blur_scale: 1.0) ⇒ BloomEffect

Returns a new instance of BloomEffect.



7
8
9
10
11
12
13
14
# File 'lib/engine/rendering/post_processing/bloom_effect.rb', line 7

def initialize(threshold: 0.7, intensity: 1.0, blur_passes: 2, blur_scale: 1.0)
  @threshold = threshold
  @intensity = intensity
  @blur_passes = blur_passes
  @blur_scale = blur_scale

  setup_materials
end

Instance Method Details

#apply(input_rt, output_rt, screen_quad) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/engine/rendering/post_processing/bloom_effect.rb', line 16

def apply(input_rt, output_rt, screen_quad)
  ensure_textures(input_rt.width, input_rt.height)
  Engine::GL.Disable(Engine::GL::DEPTH_TEST)

  # Pass 1: Extract bright pixels
  @ping.bind
  Engine::GL.Clear(Engine::GL::COLOR_BUFFER_BIT)
  screen_quad.draw(@threshold_material, input_rt.color_texture)

  # Pass 2+: Blur passes (ping-pong between internal textures)
  @blur_passes.times do
    # Horizontal blur
    @pong.bind
    Engine::GL.Clear(Engine::GL::COLOR_BUFFER_BIT)
    @blur_material.set_vec2("direction", [1.0, 0.0])
    screen_quad.draw(@blur_material, @ping.color_texture)

    # Vertical blur
    @ping.bind
    Engine::GL.Clear(Engine::GL::COLOR_BUFFER_BIT)
    @blur_material.set_vec2("direction", [0.0, 1.0])
    screen_quad.draw(@blur_material, @pong.color_texture)
  end

  # Pass 3: Combine original + bloom
  output_rt.bind
  Engine::GL.Clear(Engine::GL::COLOR_BUFFER_BIT)
  @combine_material.set_runtime_texture("screenTexture", input_rt.color_texture)
  @combine_material.set_runtime_texture("bloomTexture", @ping.color_texture)
  screen_quad.draw_with_material(@combine_material)
  output_rt
end