<s> """<STR_LIT>""" <EOL> import math <EOL> from rplibs . six . moves import range <EOL> from rplibs . six import iteritems , itervalues <EOL> from direct . stdpy . file import listdir , isfile , join <EOL> from panda3d . core import SamplerState , ShaderAttrib , NodePath <EOL> from rpcore . globals import Globals <EOL> from rpcore . rpobject import RPObject <EOL> from rpcore . image import Image <EOL> from rpcore . loader import RPLoader <EOL> class ScatteringMethod ( RPObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , plugin_handle ) : <EOL> RPObject . __init__ ( self ) <EOL> self . handle = plugin_handle <EOL> def load ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def compute ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> class ScatteringMethodHosekWilkie ( ScatteringMethod ) : <EOL> """<STR_LIT>""" <EOL> def load ( self ) : <EOL> """<STR_LIT>""" <EOL> lut_src = self . handle . get_resource ( <EOL> "<STR_LIT>" ) <EOL> if not isfile ( lut_src ) : <EOL> self . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return <EOL> lut_tex = RPLoader . load_sliced_3d_texture ( lut_src , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:100> ) <EOL> lut_tex . set_wrap_u ( SamplerState . WM_repeat ) <EOL> lut_tex . set_wrap_v ( SamplerState . WM_clamp ) <EOL> lut_tex . set_wrap_w ( SamplerState . WM_clamp ) <EOL> lut_tex . set_minfilter ( SamplerState . FT_linear ) <EOL> lut_tex . set_magfilter ( SamplerState . FT_linear ) <EOL> self . handle . display_stage . set_shader_input ( "<STR_LIT>" , lut_tex ) <EOL> self . handle . envmap_stage . set_shader_input ( "<STR_LIT>" , lut_tex ) <EOL> def compute ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ScatteringMethodEricBruneton ( ScatteringMethod ) : <EOL> """<STR_LIT>""" <EOL> def load ( self ) : <EOL> """<STR_LIT>""" <EOL> self . use_32_bit = False <EOL> self . trans_w , self . trans_h = <NUM_LIT> * <NUM_LIT:4> , <NUM_LIT:64> * <NUM_LIT:4> <EOL> self . sky_w , self . sky_h = <NUM_LIT:64> * <NUM_LIT:4> , <NUM_LIT:16> * <NUM_LIT:4> <EOL> self . res_r , self . res_mu , self . res_mu_s , self . res_nu = <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT:8> <EOL> self . res_mu_s_nu = self . res_mu_s * self . res_nu <EOL> self . create_shaders ( ) <EOL> self . create_textures ( ) <EOL> def create_textures ( self ) : <EOL> """<STR_LIT>""" <EOL> tex_format = "<STR_LIT>" if self . use_32_bit else "<STR_LIT>" <EOL> img_2d , img_3d = Image . create_2d , Image . create_3d <EOL> self . textures = { <EOL> "<STR_LIT>" : img_2d ( "<STR_LIT>" , self . trans_w , self . trans_h , tex_format ) , <EOL> "<STR_LIT>" : img_2d ( "<STR_LIT>" , self . sky_w , self . sky_h , tex_format ) , <EOL> "<STR_LIT>" : img_3d ( "<STR_LIT>" , self . res_mu_s_nu , self . res_mu , self . res_r , tex_format ) , <EOL> "<STR_LIT>" : img_2d ( "<STR_LIT>" , self . sky_w , self . sky_h , tex_format ) , <EOL> "<STR_LIT>" : img_3d ( "<STR_LIT>" , self . res_mu_s_nu , self . res_mu , self . res_r , tex_format ) , <EOL> "<STR_LIT>" : img_3d ( "<STR_LIT>" , self . res_mu_s_nu , self . res_mu , self . res_r , tex_format ) , <EOL> "<STR_LIT>" : img_3d ( "<STR_LIT>" , self . res_mu_s_nu , self . res_mu , self . res_r , tex_format ) , <EOL> } <EOL> for img in itervalues ( self . textures ) : <EOL> img . set_minfilter ( SamplerState . FT_linear ) <EOL> img . set_magfilter ( SamplerState . FT_linear ) <EOL> img . set_wrap_u ( SamplerState . WM_clamp ) <EOL> img . set_wrap_v ( SamplerState . WM_clamp ) <EOL> img . set_wrap_w ( SamplerState . WM_clamp ) <EOL> def create_shaders ( self ) : <EOL> """<STR_LIT>""" <EOL> self . shaders = { } <EOL> resource_path = self . handle . get_shader_resource ( "<STR_LIT>" ) <EOL> for fname in listdir ( resource_path ) : <EOL> fpath = join ( resource_path , fname ) <EOL> if isfile ( fpath ) and fname . endswith ( "<STR_LIT>" ) : <EOL> shader_name = fname . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> shader_obj = RPLoader . load_shader ( fpath ) <EOL> self . shaders [ shader_name ] = shader_obj <EOL> def exec_compute_shader ( self , shader_obj , shader_inputs , exec_size , <EOL> workgroup_size = ( <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:1> ) ) : <EOL> """<STR_LIT>""" <EOL> ntx = int ( math . ceil ( exec_size [ <NUM_LIT:0> ] / workgroup_size [ <NUM_LIT:0> ] ) ) <EOL> nty = int ( math . ceil ( exec_size [ <NUM_LIT:1> ] / workgroup_size [ <NUM_LIT:1> ] ) ) <EOL> ntz = int ( math . ceil ( exec_size [ <NUM_LIT:2> ] / workgroup_size [ <NUM_LIT:2> ] ) ) <EOL> nodepath = NodePath ( "<STR_LIT>" ) <EOL> nodepath . set_shader ( shader_obj ) <EOL> for key , val in iteritems ( shader_inputs ) : <EOL> nodepath . set_shader_input ( key , val ) <EOL> attr = nodepath . get_attrib ( ShaderAttrib ) <EOL> Globals . base . graphicsEngine . dispatch_compute ( <EOL> ( ntx , nty , ntz ) , attr , Globals . base . win . gsg ) <EOL> def compute ( self ) : <EOL> """<STR_LIT>""" <EOL> self . debug ( "<STR_LIT>" ) <EOL> exec_cshader = self . exec_compute_shader <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] <EOL> } , ( self . trans_w , self . trans_h , <NUM_LIT:1> ) ) <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] <EOL> } , ( self . sky_w , self . sky_h , <NUM_LIT:1> ) ) <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] <EOL> } , ( self . res_mu_s_nu , self . res_mu , self . res_r ) , ( <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT:k>" : <NUM_LIT:0.0> , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] <EOL> } , ( self . sky_w , self . sky_h , <NUM_LIT:1> ) ) <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] <EOL> } , ( self . res_mu_s_nu , self . res_mu , self . res_r ) , ( <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> for order in range ( <NUM_LIT:2> , <NUM_LIT:5> ) : <EOL> first = order == <NUM_LIT:2> <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : first <EOL> } , ( self . res_mu_s_nu , self . res_mu , self . res_r ) , ( <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : first <EOL> } , ( self . sky_w , self . sky_h , <NUM_LIT:1> ) ) <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : first <EOL> } , ( self . res_mu_s_nu , self . res_mu , self . res_r ) , ( <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> } , ( self . sky_w , self . sky_h , <NUM_LIT:1> ) ) <EOL> exec_cshader ( <EOL> self . shaders [ "<STR_LIT>" ] , { <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : self . textures [ "<STR_LIT>" ] <EOL> } , ( self . res_mu_s_nu , self . res_mu , self . res_r ) , ( <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> for stage in [ self . handle . display_stage , self . handle . envmap_stage ] : <EOL> stage . set_shader_input ( "<STR_LIT>" , self . textures [ "<STR_LIT>" ] ) <EOL> stage . set_shader_input ( "<STR_LIT>" , self . textures [ "<STR_LIT>" ] ) <EOL> stage . set_shader_input ( "<STR_LIT>" , self . textures [ "<STR_LIT>" ] ) </s>
