예제 #1
0
    def __init__(self, **object_data):
        self.name = object_data.get('name', 'atmosphere')
        self.attributes = Attributes()
        self.is_render_atmosphere = object_data.get('is_render_atmosphere', True)
        self.use_constant_solar_spectrum = False
        self.use_ozone = True
        self.use_combined_textures = True
        self.luminance_type = Luminance.NONE
        self.num_precomputed_wavelengths = 15 if Luminance.PRECOMPUTED == self.luminance_type else 3
        self.do_white_balance = False
        self.show_help = True
        self.view_distance_meters = 9000.0
        self.view_zenith_angle_radians = 1.47
        self.view_azimuth_angle_radians = -0.1
        self.sun_zenith_angle_radians = 1.3
        self.sun_azimuth_angle_radians = 2.9
        self.sun_direction = Float3()

        self.white_point = Float3()
        self.earth_center = Float3(0.0, -kBottomRadius / kLengthUnitInMeters, 0.0)
        self.sun_size = Float2(math.tan(kSunAngularRadius), math.cos(kSunAngularRadius))

        self.kSky = Float3(1.0, 1.0, 1.0)
        self.kSun = Float3(1.0, 1.0, 1.0)

        self.atmosphere_exposure = 0.0001

        # cloud constants
        self.cloud_altitude = 100.0
        self.cloud_height = 500.0
        self.cloud_speed = 0.01
        self.cloud_absorption = 0.15

        self.cloud_contrast = 2.0
        self.cloud_coverage = 0.8
        self.cloud_tiling = 0.0004

        self.noise_contrast = 1.0
        self.noise_coverage = 1.0
        self.noise_tiling = 0.0003

        self.model = None
        self.atmosphere_material_instance = None

        self.transmittance_texture = None
        self.scattering_texture = None
        self.irradiance_texture = None
        self.optional_single_mie_scattering_texture = None

        self.cloud_texture = None
        self.noise_texture = None

        self.quad = ScreenQuad.get_vertex_array_buffer()

        self.load_data(object_data)

        self.initialize()
예제 #2
0
    def initialize(self):
        self.fft_seed = Ocean.DEFAULT_FFT_SEED
        self.fft_init = self.resource_manager.get_material_instance(
            'fft_ocean.init')
        self.fft_x = self.resource_manager.get_material_instance(
            'fft_ocean.fft_x')
        self.fft_y = self.resource_manager.get_material_instance(
            'fft_ocean.fft_y')
        self.fft_render = self.resource_manager.get_material_instance(
            'fft_ocean.render')
        self.fft_variance = self.resource_manager.get_material_instance(
            'fft_ocean.fft_variance')

        self.texture_spectrum_1_2 = self.resource_manager.get_texture(
            "fft_ocean.spectrum_1_2", default_texture=False)
        self.texture_spectrum_3_4 = self.resource_manager.get_texture(
            "fft_ocean.spectrum_3_4", default_texture=False)
        self.texture_slope_variance = self.resource_manager.get_texture(
            "fft_ocean.slope_variance", default_texture=False)
        self.texture_butterfly = self.resource_manager.get_texture(
            "fft_ocean.butterfly", default_texture=False)

        self.quad = ScreenQuad.get_vertex_array_buffer()
        self.fft_grid = Plane("FFT_Grid",
                              mode=GL_QUADS,
                              width=GRID_VERTEX_COUNT,
                              height=GRID_VERTEX_COUNT,
                              xz_plane=False)

        if None in (self.texture_spectrum_1_2, self.texture_spectrum_3_4,
                    self.texture_slope_variance, self.texture_butterfly):
            self.generate_texture()

        self.caustic_index = 0
        self.texture_caustics = []
        i = 0
        while True:
            resource_name = "common.water_caustic_%02d" % i
            if self.resource_manager.texture_loader.hasResource(resource_name):
                self.texture_caustics.append(
                    self.resource_manager.get_texture(resource_name))
                i += 1
                continue
            break

        self.texture_foam = self.resource_manager.get_texture(
            "common.water_foam")
        self.texture_noise = self.resource_manager.get_texture("common.noise")
예제 #3
0
    def initialize(self, core_manager):
        self.touch_event = False
        self.core_manager = core_manager
        self.resource_manager = core_manager.resource_manager
        self.renderer = core_manager.renderer
        self.framebuffer_manager = FrameBufferManager.instance()

        self.quad = ScreenQuad.get_vertex_array_buffer()
        self.render_widget = self.resource_manager.get_material_instance('ui.render_widget')

        width, height = self.core_manager.get_window_size()

        self.root = Widget(name="root", width=width, height=height)
        self.main_viewport = Widget(name="Main viewport", dragable=False, size_hint_x=1.0,  size_hint_y=1.0)
        self.root.add_widget(self.main_viewport)

        # Set static members
        Widget.core_manager = core_manager
        Widget.viewport_manager = self
        Widget.root = self.root
예제 #4
0
    def __init__(self, wavelengths, solar_irradiance, sun_angular_radius,
                 bottom_radius, top_radius, rayleigh_density,
                 rayleigh_scattering, mie_density, mie_scattering,
                 mie_extinction, mie_phase_function_g, absorption_density,
                 absorption_extinction, ground_albedo, max_sun_zenith_angle,
                 length_unit_in_meters, num_precomputed_wavelengths,
                 precompute_illuminance, use_combined_textures):

        self.wavelengths = wavelengths
        self.solar_irradiance = solar_irradiance
        self.sun_angular_radius = sun_angular_radius
        self.bottom_radius = bottom_radius
        self.top_radius = top_radius
        self.rayleigh_density = rayleigh_density
        self.rayleigh_scattering = rayleigh_scattering
        self.mie_density = mie_density
        self.mie_scattering = mie_scattering
        self.mie_extinction = mie_extinction
        self.mie_phase_function_g = mie_phase_function_g
        self.absorption_density = absorption_density
        self.absorption_extinction = absorption_extinction
        self.ground_albedo = ground_albedo
        self.max_sun_zenith_angle = max_sun_zenith_angle
        self.length_unit_in_meters = length_unit_in_meters
        self.num_precomputed_wavelengths = num_precomputed_wavelengths
        self.precompute_illuminance = precompute_illuminance
        self.use_combined_textures = use_combined_textures

        self.material_instance_macros = {
            'COMBINED_SCATTERING_TEXTURES': 1 if use_combined_textures else 0
        }

        # Atmosphere shader code
        resource_manager = CoreManager.instance().resource_manager
        shaderLoader = resource_manager.shader_loader
        shader_name = 'precomputed_atmosphere.atmosphere_predefine'
        recompute_atmosphere_predefine = resource_manager.get_shader(
            shader_name)
        recompute_atmosphere_predefine.shader_code = self.glsl_header_factory(
            [kLambdaR, kLambdaG, kLambdaB])
        shaderLoader.save_resource(shader_name)
        shaderLoader.load_resource(shader_name)

        self.transmittance_texture = CreateTexture(
            name="precomputed_atmosphere.transmittance",
            texture_type=Texture2D,
            width=TRANSMITTANCE_TEXTURE_WIDTH,
            height=TRANSMITTANCE_TEXTURE_HEIGHT,
            internal_format=GL_RGBA32F,
            texture_format=GL_RGBA,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_CLAMP_TO_EDGE)

        self.scattering_texture = CreateTexture(
            name="precomputed_atmosphere.scattering",
            texture_type=Texture3D,
            width=SCATTERING_TEXTURE_WIDTH,
            height=SCATTERING_TEXTURE_HEIGHT,
            depth=SCATTERING_TEXTURE_DEPTH,
            internal_format=GL_RGBA32F,
            texture_format=GL_RGBA,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_CLAMP_TO_EDGE)

        self.irradiance_texture = CreateTexture(
            name="precomputed_atmosphere.irradiance",
            texture_type=Texture2D,
            width=IRRADIANCE_TEXTURE_WIDTH,
            height=IRRADIANCE_TEXTURE_HEIGHT,
            internal_format=GL_RGBA32F,
            texture_format=GL_RGBA,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_CLAMP)

        self.optional_single_mie_scattering_texture = None
        if not self.use_combined_textures:
            self.optional_single_mie_scattering_texture = CreateTexture(
                name=
                "precomputed_atmosphere.optional_single_mie_scattering_texture",
                texture_type=Texture3D,
                width=SCATTERING_TEXTURE_WIDTH,
                height=SCATTERING_TEXTURE_HEIGHT,
                depth=SCATTERING_TEXTURE_DEPTH,
                internal_format=GL_RGBA32F,
                texture_format=GL_RGBA,
                min_filter=GL_LINEAR,
                mag_filter=GL_LINEAR,
                data_type=GL_FLOAT,
                wrap=GL_CLAMP)

        self.delta_irradiance_texture = CreateTexture(
            name="precomputed_atmosphere.delta_irradiance_texture",
            texture_type=Texture2D,
            width=IRRADIANCE_TEXTURE_WIDTH,
            height=IRRADIANCE_TEXTURE_HEIGHT,
            internal_format=GL_RGBA32F,
            texture_format=GL_RGBA,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_CLAMP)

        self.delta_rayleigh_scattering_texture = CreateTexture(
            name="precomputed_atmosphere.delta_rayleigh_scattering_texture",
            texture_type=Texture3D,
            width=SCATTERING_TEXTURE_WIDTH,
            height=SCATTERING_TEXTURE_HEIGHT,
            depth=SCATTERING_TEXTURE_DEPTH,
            internal_format=GL_RGBA32F,
            texture_format=GL_RGBA,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_CLAMP)

        self.delta_mie_scattering_texture = CreateTexture(
            name="precomputed_atmosphere.delta_mie_scattering_texture",
            texture_type=Texture3D,
            width=SCATTERING_TEXTURE_WIDTH,
            height=SCATTERING_TEXTURE_HEIGHT,
            depth=SCATTERING_TEXTURE_DEPTH,
            internal_format=GL_RGBA32F,
            texture_format=GL_RGBA,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_CLAMP)

        self.delta_scattering_density_texture = CreateTexture(
            name="precomputed_atmosphere.delta_scattering_density_texture",
            texture_type=Texture3D,
            width=SCATTERING_TEXTURE_WIDTH,
            height=SCATTERING_TEXTURE_HEIGHT,
            depth=SCATTERING_TEXTURE_DEPTH,
            internal_format=GL_RGBA32F,
            texture_format=GL_RGBA,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_CLAMP)

        self.delta_multiple_scattering_texture = self.delta_rayleigh_scattering_texture

        self.quad = ScreenQuad.get_vertex_array_buffer()
예제 #5
0
파일: Ocean.py 프로젝트: idkwim/PyEngine3D
    def __init__(self, **object_data):
        self.name = object_data.get('name', 'ocean')
        self.height = object_data.get('height', 0.0)
        self.wind = object_data.get('wind', WIND)
        self.omega = object_data.get('omega', OMEGA)
        self.amplitude = object_data.get('amplitude', AMPLITUDE)

        self.simulation_wind = object_data.get('simulation_wind', 1.0)
        self.simulation_amplitude = object_data.get('simulation_amplitude',
                                                    3.0)
        self.simulation_scale = object_data.get('simulation_scale', 1.0)

        self.is_render_ocean = object_data.get('is_render_ocean', True)
        self.attributes = Attributes()

        self.acc_time = 0.0
        self.fft_seed = 1234

        self.renderer = CoreManager.instance().renderer
        self.scene_manager = CoreManager.instance().scene_manager
        self.resource_manager = CoreManager.instance().resource_manager

        self.fft_init = self.resource_manager.get_material_instance(
            'fft_ocean.init')
        self.fft_x = self.resource_manager.get_material_instance(
            'fft_ocean.fft_x')
        self.fft_y = self.resource_manager.get_material_instance(
            'fft_ocean.fft_y')
        self.fft_render = self.resource_manager.get_material_instance(
            'fft_ocean.render')
        self.fft_variance = self.resource_manager.get_material_instance(
            'fft_ocean.fft_variance')

        self.texture_spectrum_1_2 = self.resource_manager.get_texture(
            "fft_ocean.spectrum_1_2", default_texture=False)
        self.texture_spectrum_3_4 = self.resource_manager.get_texture(
            "fft_ocean.spectrum_3_4", default_texture=False)
        self.texture_slope_variance = self.resource_manager.get_texture(
            "fft_ocean.slope_variance", default_texture=False)
        self.texture_butterfly = self.resource_manager.get_texture(
            "fft_ocean.butterfly", default_texture=False)

        self.quad = ScreenQuad.get_vertex_array_buffer()
        self.fft_grid = Plane("FFT_Grid",
                              mode=GL_QUADS,
                              width=GRID_VERTEX_COUNT,
                              height=GRID_VERTEX_COUNT,
                              xz_plane=False)

        self.simulation_size = GRID_SIZES * self.simulation_scale

        if None in (self.texture_spectrum_1_2, self.texture_spectrum_3_4,
                    self.texture_slope_variance, self.texture_butterfly):
            self.generate_texture()

        self.caustic_index = 0
        self.texture_caustics = []
        i = 0
        while True:
            resource_name = "common.water_caustic_%02d" % i
            if self.resource_manager.texture_loader.hasResource(resource_name):
                self.texture_caustics.append(
                    self.resource_manager.get_texture(resource_name))
                i += 1
                continue
            break

        self.texture_foam = self.resource_manager.get_texture(
            "common.water_foam")
        self.texture_noise = self.resource_manager.get_texture("common.noise")
예제 #6
0
    def initialize(self):
        resource_manager = CoreManager.instance().resource_manager

        self.quad = ScreenQuad.get_vertex_array_buffer()

        self.atmosphere_material_instance = resource_manager.get_material_instance(
            'precomputed_atmosphere.atmosphere',
            macros={
                'USE_LUMINANCE':
                1 if self.luminance_type else 0,
                'COMBINED_SCATTERING_TEXTURES':
                1 if self.use_combined_textures else 0
            })

        # precompute constants
        max_sun_zenith_angle = 120.0 / 180.0 * kPi

        rayleigh_layer = DensityProfileLayer(0.0, 1.0,
                                             -1.0 / kRayleighScaleHeight, 0.0,
                                             0.0)
        mie_layer = DensityProfileLayer(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0,
                                        0.0)

        ozone_density = [
            DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0),
            DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)
        ]

        wavelengths = []
        solar_irradiance = []
        rayleigh_scattering = []
        mie_scattering = []
        mie_extinction = []
        absorption_extinction = []
        ground_albedo = []

        for i in range(kLambdaMin, kLambdaMax + 1, 10):
            L = float(i) * 1e-3  # micro-meters
            mie = kMieAngstromBeta / kMieScaleHeight * math.pow(
                L, -kMieAngstromAlpha)
            wavelengths.append(i)
            if self.use_constant_solar_spectrum:
                solar_irradiance.append(kConstantSolarIrradiance)
            else:
                solar_irradiance.append(kSolarIrradiance[int(
                    (i - kLambdaMin) / 10)])
            rayleigh_scattering.append(kRayleigh * math.pow(L, -4))
            mie_scattering.append(mie * kMieSingleScatteringAlbedo)
            mie_extinction.append(mie)
            if self.use_ozone:
                absorption_extinction.append(kMaxOzoneNumberDensity *
                                             kOzoneCrossSection[int(
                                                 (i - kLambdaMin) / 10)])
            else:
                absorption_extinction.append(0.0)
            ground_albedo.append(kGroundAlbedo)

        rayleigh_density = [
            rayleigh_layer,
        ]
        mie_density = [
            mie_layer,
        ]

        if Luminance.PRECOMPUTED == self.luminance_type:
            self.kSky[...] = [
                MAX_LUMINOUS_EFFICACY, MAX_LUMINOUS_EFFICACY,
                MAX_LUMINOUS_EFFICACY
            ]
        else:
            self.kSky[...] = ComputeSpectralRadianceToLuminanceFactors(
                wavelengths, solar_irradiance, -3)
        self.kSun[...] = ComputeSpectralRadianceToLuminanceFactors(
            wavelengths, solar_irradiance, 0)

        # generate precomputed textures
        if not resource_manager.texture_loader.hasResource('precomputed_atmosphere.transmittance') or \
                not resource_manager.texture_loader.hasResource('precomputed_atmosphere.scattering') or \
                not resource_manager.texture_loader.hasResource('precomputed_atmosphere.irradiance') or \
                not resource_manager.texture_loader.hasResource(
                    'precomputed_atmosphere.optional_single_mie_scattering') and not self.use_combined_textures:
            model = Model(wavelengths, solar_irradiance, kSunAngularRadius,
                          kBottomRadius, kTopRadius, rayleigh_density,
                          rayleigh_scattering, mie_density, mie_scattering,
                          mie_extinction, kMiePhaseFunctionG, ozone_density,
                          absorption_extinction, ground_albedo,
                          max_sun_zenith_angle, kLengthUnitInMeters,
                          self.num_precomputed_wavelengths,
                          Luminance.PRECOMPUTED == self.luminance_type,
                          self.use_combined_textures)
            model.generate()

        self.transmittance_texture = resource_manager.get_texture(
            'precomputed_atmosphere.transmittance')
        self.scattering_texture = resource_manager.get_texture(
            'precomputed_atmosphere.scattering')
        self.irradiance_texture = resource_manager.get_texture(
            'precomputed_atmosphere.irradiance')

        if not self.use_combined_textures:
            self.optional_single_mie_scattering_texture = resource_manager.get_texture(
                'precomputed_atmosphere.optional_single_mie_scattering')

        self.cloud_texture = resource_manager.get_texture(
            'precomputed_atmosphere.cloud_3d')
        self.noise_texture = resource_manager.get_texture(
            'precomputed_atmosphere.noise_3d')