def _create_components(self): """ Internal method to init the widgets components """ # Create the buffer which stores the last FPS values self._storage_buffer = Image.create_buffer("FPSValues", 250, "R16") self._storage_buffer.set_clear_color(Vec4(0)) self._storage_buffer.clear_image() self._store_index = PTAInt.empty_array(1) self._store_index[0] = 0 self._current_ftime = PTAFloat.empty_array(1) self._current_ftime[0] = 16.0 self._chart_ms_max = PTAFloat.empty_array(1) self._chart_ms_max[0] = 40 # Create the texture where the gui component is rendered inside self._display_tex = Image.create_2d("FPSChartRender", 250, 120, "RGBA8") self._display_tex.set_clear_color(Vec4(0)) self._display_tex.clear_image() self._display_img = Sprite(image=self._display_tex, parent=self._node, w=250, h=120, x=10, y=10) # Defer the further loading Globals.base.taskMgr.doMethodLater(0.3, self._late_init, "FPSChartInit")
def _create_components(self): """ Internal method to init the widgets components """ self._node.hide() # Create the texture where the gui component is rendered inside self._storage_tex = Image.create_2d("ExposureDisplay", 140, 20, "RGBA8") self._storage_tex.set_clear_color(Vec4(0.2, 0.6, 1.0, 1.0)) self._storage_tex.clear_image() self._bg_frame = DirectFrame( parent=self._node, frameColor=(0.1, 0.1, 0.1, 1.0), frameSize=(200, 0, -10, -85), pos=(0, 0, 0)) self._display_img = Sprite( image=self._storage_tex, parent=self._node, w=140, h=20, x=20, y=50) self._display_txt = Text( text="Current Exposure".upper(), parent=self._node, x=160, y=40, size=13, color=Vec3(0.8), align="right") # Create the shader which generates the visualization texture self._cshader_node = ComputeNode("ExposureWidget") self._cshader_node.add_dispatch(140 // 10, 20 // 4, 1) self._cshader_np = self._node.attach_new_node(self._cshader_node) # Defer the further loading Globals.base.taskMgr.doMethodLater(1.0, self._late_init, "ExposureLateInit")
def create(self): if self.remove_fireflies: self.target_firefly = self.create_target("RemoveFireflies") self.target_firefly.add_color_attachment(bits=16) self.target_firefly.prepare_buffer() self.scene_target_img = Image.create_2d("BloomDownsample", 0, 0, "RGBA16") self.scene_target_img.set_minfilter( SamplerState.FT_linear_mipmap_linear) self.scene_target_img.set_magfilter(SamplerState.FT_linear) self.scene_target_img.set_wrap_u(SamplerState.WM_clamp) self.scene_target_img.set_wrap_v(SamplerState.WM_clamp) self.scene_target_img.set_clear_color(Vec4(0.1, 0.0, 0.0, 1.0)) self.scene_target_img.clear_image() self.target_extract = self.create_target("ExtractBrightSpots") self.target_extract.prepare_buffer() self.target_extract.set_shader_input("DestTex", self.scene_target_img, False, True, -1, 0) if self.remove_fireflies: self.target_extract.set_shader_input("ShadedScene", self.target_firefly.color_tex, 1000) self.downsample_targets = [] self.upsample_targets = [] # Downsample passes for i in range(self.num_mips): scale_multiplier = 2**(1 + i) target = self.create_target("Downsample:Step-" + str(i)) target.size = -scale_multiplier, -scale_multiplier target.prepare_buffer() target.set_shader_input("sourceMip", i) target.set_shader_input("SourceTex", self.scene_target_img) target.set_shader_input("DestTex", self.scene_target_img, False, True, -1, i + 1) self.downsample_targets.append(target) # Upsample passes for i in range(self.num_mips): scale_multiplier = 2**(self.num_mips - i - 1) target = self.create_target("Upsample:Step-" + str(i)) target.size = -scale_multiplier, -scale_multiplier target.prepare_buffer() target.set_shader_input("FirstUpsamplePass", i == 0) target.set_shader_input("sourceMip", self.num_mips - i) target.set_shader_input("SourceTex", self.scene_target_img) target.set_shader_input("DestTex", self.scene_target_img, False, True, -1, self.num_mips - i - 1) self.upsample_targets.append(target) self.target_apply = self.create_target("ApplyBloom") self.target_apply.add_color_attachment(bits=16) self.target_apply.prepare_buffer() self.target_apply.set_shader_input("BloomTex", self.scene_target_img)
def _create_components(self): """ Internal method to init the widgets components """ # Create the buffer which stores the last FPS values self._storage_buffer = Image.create_buffer("FPSValues", 250, "R16") self._storage_buffer.set_clear_color(Vec4(0)) self._storage_buffer.clear_image() self._store_index = PTAInt.empty_array(1) self._store_index[0] = 0 self._current_ftime = PTAFloat.empty_array(1) self._current_ftime[0] = 16.0 self._chart_ms_max = PTAFloat.empty_array(1) self._chart_ms_max[0] = 40 # Create the texture where the gui component is rendered inside self._display_tex = Image.create_2d("FPSChartRender", 250, 120, "RGBA8") self._display_tex.set_clear_color(Vec4(0)) self._display_tex.clear_image() self._display_img = Sprite( image=self._display_tex, parent=self._node, w=250, h=120, x=10, y=10) # Defer the further loading Globals.base.taskMgr.doMethodLater(0.3, self._late_init, "FPSChartInit")
def create(self): if self.remove_fireflies: self.target_firefly = self.create_target("RemoveFireflies") self.target_firefly.add_color_attachment(bits=16) self.target_firefly.prepare_buffer() self.scene_target_img = Image.create_2d( "BloomDownsample", Globals.resolution.x, Globals.resolution.y, "R11G11B10") self.scene_target_img.set_minfilter(SamplerState.FT_linear_mipmap_linear) self.scene_target_img.set_magfilter(SamplerState.FT_linear) self.scene_target_img.set_wrap_u(SamplerState.WM_clamp) self.scene_target_img.set_wrap_v(SamplerState.WM_clamp) self.scene_target_img.set_clear_color(Vec4(0.1, 0.0, 0.0, 1.0)) self.scene_target_img.clear_image() self.target_extract = self.create_target("ExtractBrightSpots") self.target_extract.prepare_buffer() self.target_extract.set_shader_input("DestTex", self.scene_target_img, False, True, -1, 0) if self.remove_fireflies: self.target_extract.set_shader_input("ShadedScene", self.target_firefly.color_tex, 1000) self.downsample_targets = [] self.upsample_targets = [] # Downsample passes for i in range(self.num_mips): scale_multiplier = 2 ** (1 + i) target = self.create_target("Downsample:Step-" + str(i)) target.size = -scale_multiplier, -scale_multiplier target.prepare_buffer() target.set_shader_input("sourceMip", i) target.set_shader_input("SourceTex", self.scene_target_img) target.set_shader_input("DestTex", self.scene_target_img, False, True, -1, i + 1) self.downsample_targets.append(target) # Upsample passes for i in range(self.num_mips): scale_multiplier = 2 ** (self.num_mips - i - 1) target = self.create_target("Upsample:Step-" + str(i)) target.size = -scale_multiplier, -scale_multiplier target.prepare_buffer() target.set_shader_input("FirstUpsamplePass", i == 0) target.set_shader_input("sourceMip", self.num_mips - i) target.set_shader_input("SourceTex", self.scene_target_img) target.set_shader_input("DestTex", self.scene_target_img, False, True, -1, self.num_mips - i - 1) self.upsample_targets.append(target) self.target_apply = self.create_target("ApplyBloom") self.target_apply.add_color_attachment(bits=16) self.target_apply.prepare_buffer() self.target_apply.set_shader_input("BloomTex", self.scene_target_img)
def _bind_pipes_to_stage(self, stage): """ Sets all required pipes on a stage """ for pipe in stage.required_pipes: # Check if there is an input block named like the pipe if pipe in self.input_blocks: self.input_blocks[pipe].bind_to(stage) continue if pipe.startswith("PreviousFrame::"): # Special case: Pipes from the previous frame. We assume those # pipes have the same size as the window and a format of # F_rgba16. Could be subject to change. pipe_name = pipe.split("::")[-1] if pipe_name not in self.previous_pipes: tex_format = "RGBA16" # XXX: Assuming we have a depth texture whenever "depth" # occurs in the textures name if "depth" in pipe_name.lower(): tex_format = "R32" pipe_tex = Image.create_2d("Prev-" + pipe_name, Globals.resolution.x, Globals.resolution.y, tex_format) pipe_tex.clear_image() self.previous_pipes[pipe_name] = pipe_tex stage.set_shader_input("Previous_" + pipe_name, self.previous_pipes[pipe_name]) continue elif pipe.startswith("FuturePipe::"): # Special case: Future Pipes which are not available yet. # They will contain the unmodified data from the last # frame. pipe_name = pipe.split("::")[-1] self.debug("Awaiting future pipe", pipe_name) self.future_bindings.append((pipe_name, stage)) continue if pipe not in self.pipes: self.fatal("Pipe '" + pipe + "' is missing for", stage) return False pipe_value = self.pipes[pipe] if isinstance(pipe_value, list) or isinstance(pipe_value, tuple): stage.set_shader_input(pipe, *pipe_value) else: stage.set_shader_input(pipe, pipe_value) return True
def _bind_pipes_to_stage(self, stage): """ Sets all required pipes on a stage """ for pipe in stage.required_pipes: # Check if there is an input block named like the pipe if pipe in self.input_blocks: self.input_blocks[pipe].bind_to(stage) continue if pipe.startswith("PreviousFrame::"): # Special case: Pipes from the previous frame. We assume those # pipes have the same size as the window and a format of # F_rgba16. Could be subject to change. pipe_name = pipe.split("::")[-1] if pipe_name not in self.previous_pipes: tex_format = "RGBA16" # XXX: Assuming we have a depth texture whenever "depth" # occurs in the textures name if "depth" in pipe_name.lower(): tex_format = "R32" pipe_tex = Image.create_2d( "Prev-" + pipe_name, Globals.resolution.x, Globals.resolution.y, tex_format) pipe_tex.clear_image() self.previous_pipes[pipe_name] = pipe_tex stage.set_shader_input("Previous_" + pipe_name, self.previous_pipes[pipe_name]) continue elif pipe.startswith("FuturePipe::"): # Special case: Future Pipes which are not available yet. # They will contain the unmodified data from the last # frame. pipe_name = pipe.split("::")[-1] self.debug("Awaiting future pipe", pipe_name) self.future_bindings.append((pipe_name, stage)) continue if pipe not in self.pipes: self.fatal("Pipe '" + pipe + "' is missing for", stage) return False pipe_value = self.pipes[pipe] if isinstance(pipe_value, list) or isinstance(pipe_value, tuple): stage.set_shader_input(pipe, *pipe_value) else: stage.set_shader_input(pipe, pipe_value) return True
def create(self): x_size, y_size = Globals.resolution.x, Globals.resolution.y self.target = self.create_target("ComputeSSR") self.target.size = -2 self.target.add_color_attachment(bits=16) self.target.prepare_buffer() self.target.color_tex.set_minfilter(SamplerState.FT_nearest) self.target.color_tex.set_magfilter(SamplerState.FT_nearest) self.target_velocity = self.create_target("ReflectionVelocity") self.target_velocity.add_color_attachment(bits=(16, 16, 0, 0)) self.target_velocity.prepare_buffer() self.target_velocity.set_shader_input("TraceResult", self.target.color_tex) self.mipchain = Image.create_2d("SSRMipchain", x_size, y_size, "RGBA16") self.mipchain.set_minfilter(SamplerState.FT_linear_mipmap_linear) self.mipchain.set_wrap_u(SamplerState.WM_clamp) self.mipchain.set_wrap_v(SamplerState.WM_clamp) self.mipchain.set_clear_color(Vec4(0)) self.mipchain.clear_image() self.target_copy_lighting = self.create_target("CopyLighting") self.target_copy_lighting.prepare_buffer() self.target_copy_lighting.set_shader_input("DestTex", self.mipchain, False, True, -1, 0) self.blur_targets = [] for i in range(min(7, self.mipchain.get_expected_num_mipmap_levels() - 1)): target_blur = self.create_target("BlurSSR-" + str(i)) target_blur.size = - (2 ** i) target_blur.prepare_buffer() target_blur.set_shader_input("SourceTex", self.mipchain) target_blur.set_shader_input("sourceMip", i) target_blur.set_shader_input("DestTex", self.mipchain, False, True, -1, i + 1) self.blur_targets.append(target_blur) self.noise_reduce_targets = [] curr_tex = self.target.color_tex for i in range(0): target_remove_noise = self.create_target("RemoveNoise") target_remove_noise.size = -2 target_remove_noise.add_color_attachment(bits=16, alpha=True) target_remove_noise.prepare_buffer() target_remove_noise.set_shader_input("SourceTex", curr_tex) curr_tex = target_remove_noise.color_tex self.noise_reduce_targets.append(target_remove_noise) self.fill_hole_targets = [] for i in range(0): fill_target = self.create_target("FillHoles-" + str(i)) fill_target.size = -2 fill_target.add_color_attachment(bits=16, alpha=True) fill_target.prepare_buffer() fill_target.set_shader_input("SourceTex", curr_tex) curr_tex = fill_target.color_tex self.fill_hole_targets.append(fill_target) self.target_upscale = self.create_target("UpscaleSSR") self.target_upscale.add_color_attachment(bits=16, alpha=True) self.target_upscale.prepare_buffer() self.target_upscale.set_shader_input("SourceTex", curr_tex) self.target_upscale.set_shader_input("MipChain", self.mipchain) self.target_resolve = self.create_target("ResolveSSR") self.target_resolve.add_color_attachment(bits=16, alpha=True) self.target_resolve.prepare_buffer() self.target_resolve.set_shader_input("CurrentTex", self.target_upscale.color_tex) self.target_resolve.set_shader_input("VelocityTex", self.target_velocity.color_tex) self.target_post_blur = self.create_target("SSRPostBlur") self.target_post_blur.add_color_attachment(bits=16, alpha=True) self.target_post_blur.prepare_buffer() self.target_post_blur.set_shader_input("CurrentTex", self.target_resolve.color_tex) AmbientStage.required_pipes.append("SSRSpecular")