<s> """<STR_LIT>""" <EOL> from rplibs . six . moves import range <EOL> from panda3d . core import SamplerState , Vec4 <EOL> from rpcore . globals import Globals <EOL> from rpcore . render_stage import RenderStage <EOL> from rpcore . image import Image <EOL> class BloomStage ( RenderStage ) : <EOL> required_pipes = [ "<STR_LIT>" ] <EOL> required_inputs = [ ] <EOL> def __init__ ( self , pipeline ) : <EOL> RenderStage . __init__ ( self , pipeline ) <EOL> self . num_mips = <NUM_LIT:6> <EOL> self . remove_fireflies = False <EOL> @ property <EOL> def produced_pipes ( self ) : <EOL> return { "<STR_LIT>" : self . target_apply . color_tex } <EOL> def create ( self ) : <EOL> if self . remove_fireflies : <EOL> self . target_firefly = self . create_target ( "<STR_LIT>" ) <EOL> self . target_firefly . add_color_attachment ( bits = <NUM_LIT:16> ) <EOL> self . target_firefly . prepare_buffer ( ) <EOL> self . scene_target_img = Image . create_2d ( "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> self . scene_target_img . set_minfilter ( SamplerState . FT_linear_mipmap_linear ) <EOL> self . scene_target_img . set_magfilter ( SamplerState . FT_linear ) <EOL> self . scene_target_img . set_wrap_u ( SamplerState . WM_clamp ) <EOL> self . scene_target_img . set_wrap_v ( SamplerState . WM_clamp ) <EOL> self . scene_target_img . set_clear_color ( Vec4 ( <NUM_LIT:0.1> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> ) ) <EOL> self . scene_target_img . clear_image ( ) <EOL> self . target_extract = self . create_target ( "<STR_LIT>" ) <EOL> self . target_extract . prepare_buffer ( ) <EOL> self . target_extract . set_shader_input ( "<STR_LIT>" , self . scene_target_img , False , True , - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> if self . remove_fireflies : <EOL> self . target_extract . set_shader_input ( "<STR_LIT>" , self . target_firefly . color_tex , <NUM_LIT:1000> ) <EOL> self . downsample_targets = [ ] <EOL> self . upsample_targets = [ ] <EOL> for i in range ( self . num_mips ) : <EOL> scale_multiplier = <NUM_LIT:2> ** ( <NUM_LIT:1> + i ) <EOL> target = self . create_target ( "<STR_LIT>" + str ( i ) ) <EOL> target . size = - scale_multiplier , - scale_multiplier <EOL> target . prepare_buffer ( ) <EOL> target . set_shader_input ( "<STR_LIT>" , i ) <EOL> target . set_shader_input ( "<STR_LIT>" , self . scene_target_img ) <EOL> target . set_shader_input ( "<STR_LIT>" , self . scene_target_img , False , True , - <NUM_LIT:1> , i + <NUM_LIT:1> ) <EOL> self . downsample_targets . append ( target ) <EOL> for i in range ( self . num_mips ) : <EOL> scale_multiplier = <NUM_LIT:2> ** ( self . num_mips - i - <NUM_LIT:1> ) <EOL> target = self . create_target ( "<STR_LIT>" + str ( i ) ) <EOL> target . size = - scale_multiplier , - scale_multiplier <EOL> target . prepare_buffer ( ) <EOL> target . set_shader_input ( "<STR_LIT>" , i == <NUM_LIT:0> ) <EOL> target . set_shader_input ( "<STR_LIT>" , self . num_mips - i ) <EOL> target . set_shader_input ( "<STR_LIT>" , self . scene_target_img ) <EOL> target . set_shader_input ( "<STR_LIT>" , self . scene_target_img , <EOL> False , True , - <NUM_LIT:1> , self . num_mips - i - <NUM_LIT:1> ) <EOL> self . upsample_targets . append ( target ) <EOL> self . target_apply = self . create_target ( "<STR_LIT>" ) <EOL> self . target_apply . add_color_attachment ( bits = <NUM_LIT:16> ) <EOL> self . target_apply . prepare_buffer ( ) <EOL> self . target_apply . set_shader_input ( "<STR_LIT>" , self . scene_target_img ) <EOL> def set_dimensions ( self ) : <EOL> self . scene_target_img . set_x_size ( Globals . resolution . x ) <EOL> self . scene_target_img . set_y_size ( Globals . resolution . y ) <EOL> def reload_shaders ( self ) : <EOL> self . target_extract . shader = self . load_plugin_shader ( "<STR_LIT>" ) <EOL> if self . remove_fireflies : <EOL> self . target_firefly . shader = self . load_plugin_shader ( "<STR_LIT>" ) <EOL> self . target_apply . shader = self . load_plugin_shader ( "<STR_LIT>" ) <EOL> downsample_shader = self . load_plugin_shader ( "<STR_LIT>" ) <EOL> for target in self . downsample_targets : <EOL> target . shader = downsample_shader <EOL> upsample_shader = self . load_plugin_shader ( "<STR_LIT>" ) <EOL> for target in self . upsample_targets : <EOL> target . shader = upsample_shader </s>
