Skip to content

Commit

Permalink
Smaller fixes to the plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
tobspr committed Feb 20, 2016
1 parent 4d4aa65 commit 6318c39
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 76 deletions.
3 changes: 1 addition & 2 deletions config/plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

enabled:
# - sslr
- clouds
- pssm
- color_correction
- scattering
# - clouds
- ao
- smaa
# - env_probes
# - vxgi
- fxaa
- bloom


overrides:
clouds.cloud_decay: 5.78
clouds.raymarch_steps: 64
Expand Down
1 change: 1 addition & 0 deletions effects/material_blend4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ gbuffer:
m.roughness = mOutput.roughness;
m.metallic = mOutput.metallic;
m.translucency = mOutput.translucency;
m.emissive = 0.0;
shadows:
template: default
Expand Down
1 change: 1 addition & 0 deletions effects/skybox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gbuffer:
m.roughness = 1.0;
m.translucency = 0.0;
m.normal = vOutput.normal;
m.emissive = 0.0;
shadows:
template: default
Expand Down
2 changes: 1 addition & 1 deletion rpcore/pipeline_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def remove_light(self, light):
remove_light documentation for further information. """
self.light_mgr.remove_light(light)

def create_default_skybox(self, size=40000):
def _create_default_skybox(self, size=40000):
""" Returns the default skybox, with a scale of <size>, and all
proper effects and shaders already applied. The skybox is already
parented to render as well. """
Expand Down
17 changes: 14 additions & 3 deletions rpcore/pluginbase/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,18 @@ def load(self):
handle = self._load_plugin(plugin_id)
if handle:
self._instances[plugin_id] = handle

else:
self.disable_plugin(plugin_id)

def disable_plugin(self, plugin_id):
""" Disables a plugin, given its plugin_id. This will remove it from
the list of enabled plugins, if it ever was there """
if plugin_id in self._enabled_plugins:
self.warn("Disabling", plugin_id)
self._enabled_plugins.remove(plugin_id)
for instance in itervalues(self._instances):
if plugin_id in instance.required_plugins:
self.disable_plugin(instance.plugin_id)

def unload(self):
""" Unloads all plugins """
Expand Down Expand Up @@ -196,11 +207,11 @@ def _load_plugin(self, plugin_id):
module = importlib.import_module(plugin_class, package=__package__)
instance = module.Plugin(self._pipeline)
if instance.native_only and not NATIVE_CXX_LOADED:
self.warn("Disabling", plugin_id,"since it requires the C++ modules.")
self.warn("Cannot load", plugin_id,"since it requires the C++ modules.")
return None
for required_plugin in instance.required_plugins:
if required_plugin not in self._enabled_plugins:
self.warn("Disabling", plugin_id,"since it requires", required_plugin)
self.warn("Cannot load", plugin_id,"since it requires", required_plugin)
return None
return instance

Expand Down
3 changes: 1 addition & 2 deletions rpcore/plugins/sslr/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"""


from rpcore.pluginbase.base_plugin import BasePlugin

from .sslr_stage import SSLRStage

class Plugin(BasePlugin):
Expand All @@ -37,5 +37,4 @@ class Plugin(BasePlugin):
version = "alpha (!)"

def on_stage_setup(self):
self.debug("Setting up SSLR stage ..")
self._sslr_stage = self.create_stage(SSLRStage)
40 changes: 16 additions & 24 deletions rpcore/plugins/vxgi/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

from __future__ import division

from rpcore.globals import Globals
from rpcore.pluginbase.base_plugin import BasePlugin
from rpcore.util.repeated_task_queue import RepeatedTaskQueue

from math import sin, cos, pi
from panda3d.core import Vec3
Expand All @@ -47,10 +49,10 @@ def on_stage_setup(self):
self._voxel_stage = self.create_stage(VoxelizationStage)
self._vxgi_stage = self.create_stage(VXGIStage)

self._voxel_stage.set_voxel_resolution(self.get_setting("grid_resolution"))
self._voxel_stage.set_voxel_grid_size(self.get_setting("grid_ws_size"))
self._voxel_stage.voxel_resolution = self.get_setting("grid_resolution")
self._voxel_stage.voxel_grid_size = self.get_setting("grid_ws_size")

if self.is_plugin_loaded("scattering"):
if self.is_plugin_enabled("scattering"):
self._shadow_stage = self.create_stage(VXGISunShadowStage)

# Add shadow map as requirement
Expand All @@ -66,8 +68,7 @@ def on_pipeline_created(self):
self._queue.add(self._generate_mipmaps)

def _set_grid_pos(self):

""" Finds the new grid position """
""" Finds the new voxel grid position """
grid_pos = Globals.base.camera.get_pos(Globals.base.render)

# Snap the voxel grid
Expand All @@ -82,32 +83,23 @@ def _set_grid_pos(self):

def _update_shadow_pos(self):
""" Updates the sun shadow map """
if self.is_plugin_loaded("scattering"):

# Get sun vector
sun_altitude = self.get_daytime_setting(
"sun_altitude", plugin_id="scattering")
sun_azimuth = self.get_daytime_setting(
"sun_azimuth", plugin_id="scattering")
theta = (90 - sun_altitude) / 180.0 * pi
phi = sun_azimuth / 180.0 * pi
sun_vector = Vec3(
sin(theta) * cos(phi),
sin(theta) * sin(phi),
cos(theta))

self._shadow_stage.set_sun_vector(sun_vector)
if self.is_plugin_enabled("scattering"):
self._shadow_stage.sun_vector = self.get_plugin_instance("scattering").sun_vector

def _voxelize_x(self):
""" Voxelizes the scene from the x axis """
self._set_grid_pos()
self._update_shadow_pos()
self._voxel_stage.set_state(VoxelizationStage.S_voxelize_x)
self._voxel_stage.state = VoxelizationStage.S_voxelize_x

def _voxelize_y(self):
self._voxel_stage.set_state(VoxelizationStage.S_voxelize_y)
""" Voxelizes the scene from the y axis """
self._voxel_stage.state = VoxelizationStage.S_voxelize_y

def _voxelize_z(self):
self._voxel_stage.set_state(VoxelizationStage.S_voxelize_z)
""" Voxelizes the scene from the z axis """
self._voxel_stage.state = VoxelizationStage.S_voxelize_z

def _generate_mipmaps(self):
self._voxel_stage.set_state(VoxelizationStage.S_gen_mipmaps)
""" Generates the mipmaps for the voxel grid """
self._voxel_stage.state = VoxelizationStage.S_gen_mipmaps
51 changes: 22 additions & 29 deletions rpcore/plugins/vxgi/voxelization_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

from __future__ import division

from rpcore.globals import Globals
from rpcore.util.image import Image
from rpcore.render_stage import RenderStage

from panda3d.core import Camera, OrthographicLens, NodePath, CullFaceAttrib
Expand All @@ -48,20 +50,11 @@ class VoxelizationStage(RenderStage):

def __init__(self, pipeline):
RenderStage.__init__(self, "VoxelizationStage", pipeline)
self._voxel_res = 256
self._voxel_ws = 20.0
self._state = self.S_disabled
self.voxel_resolution = 256
self.voxel_world_size = 20.0
self.state = self.S_disabled
self._create_ptas()

def set_voxel_resolution(self, res):
self._voxel_res = res

def set_voxel_grid_size(self, size):
self._voxel_ws = size

def set_state(self, state):
self._state = state

def set_grid_position(self, pos):
self._pta_next_grid_pos[0] = pos

Expand All @@ -80,17 +73,17 @@ def produced_pipes(self):
def create(self):
# Create the voxel grid used to generate the voxels
self._voxel_temp_grid = Image.create_3d(
"VoxelsTemp", self._voxel_res, self._voxel_res, self._voxel_res,
"VoxelsTemp", self.voxel_resolution, self.voxel_resolution, self.voxel_resolution,
Texture.T_float, Texture.F_rgba8)
self._voxel_temp_grid.set_clear_color(Vec4(0))
self._voxel_temp_nrm_grid = Image.create_3d(
"VoxelsTemp", self._voxel_res, self._voxel_res, self._voxel_res,
"VoxelsTemp", self.voxel_resolution, self.voxel_resolution, self.voxel_resolution,
Texture.T_float, Texture.F_r11_g11_b10)
self._voxel_temp_nrm_grid.set_clear_color(Vec4(0))

# Create the voxel grid which is a copy of the temporary grid, but stable
self._voxel_grid = Image.create_3d(
"Voxels", self._voxel_res, self._voxel_res, self._voxel_res,
"Voxels", self.voxel_resolution, self.voxel_resolution, self.voxel_resolution,
Texture.T_float, Texture.F_rgba8)
self._voxel_grid.set_clear_color(Vec4(0))
self._voxel_grid.set_minfilter(SamplerState.FT_linear_mipmap_linear)
Expand All @@ -99,30 +92,30 @@ def create(self):
self._voxel_cam = Camera("VoxelizeCam")
self._voxel_cam.set_camera_mask(self._pipeline.tag_mgr.get_voxelize_mask())
self._voxel_cam_lens = OrthographicLens()
self._voxel_cam_lens.set_film_size(-2.0 * self._voxel_ws, 2.0 * self._voxel_ws)
self._voxel_cam_lens.set_near_far(0.0, 2.0 * self._voxel_ws)
self._voxel_cam_lens.set_film_size(-2.0 * self.voxel_world_size, 2.0 * self.voxel_world_size)
self._voxel_cam_lens.set_near_far(0.0, 2.0 * self.voxel_world_size)
self._voxel_cam.set_lens(self._voxel_cam_lens)
self._voxel_cam_np = Globals.base.render.attach_new_node(self._voxel_cam)
self._pipeline.tag_mgr.register_voxelize_camera(self._voxel_cam)

# Create the voxelization target
self._voxel_target = self.make_target("VoxelizeScene")
self._voxel_target.set_source(source_cam=self._voxel_cam_np, source_win=Globals.base.win)
self._voxel_target.size = self._voxel_res, self._voxel_res
self._voxel_target.size = self.voxel_resolution, self.voxel_resolution
self._voxel_target.create_overlay_quad = False
self._voxel_target.prepare_scene_render()

# Create the target which copies the voxel grid
self._copy_target = self.make_target("CopyVoxels")
self._copy_target.size = self._voxel_res, self._voxel_res
self._copy_target.size = self.voxel_resolution, self.voxel_resolution
self._copy_target.prepare_offscreen_buffer()
self._copy_target.quad.set_instance_count(self._voxel_res)
self._copy_target.quad.set_instance_count(self.voxel_resolution)
self._copy_target.set_shader_input("SourceTex", self._voxel_temp_grid)
self._copy_target.set_shader_input("DestTex", self._voxel_grid)

# Create the target which generates the mipmaps
self._mip_targets = []
mip_size, mip = self._voxel_res, 0
mip_size, mip = self.voxel_resolution, 0
while mip_size > 1:
mip_size, mip = mip_size // 2, mip + 1
mip_target = self.make_target("GenMipmaps:" + str(mip))
Expand Down Expand Up @@ -153,29 +146,29 @@ def update(self):
target.set_active(False)

# Voxelization disable
if self._state == self.S_disabled:
if self.state == self.S_disabled:
self._voxel_cam_np.hide()
self._voxel_target.set_active(False)

# Voxelization from X-Axis
elif self._state == self.S_voxelize_x:
elif self.state == self.S_voxelize_x:
# Clear voxel grid
self._voxel_temp_grid.clear_image()
self._voxel_cam_np.set_pos(self._pta_next_grid_pos[0] + Vec3(self._voxel_ws, 0, 0))
self._voxel_cam_np.set_pos(self._pta_next_grid_pos[0] + Vec3(self.voxel_world_size, 0, 0))
self._voxel_cam_np.look_at(self._pta_next_grid_pos[0])

# Voxelization from Y-Axis
elif self._state == self.S_voxelize_y:
self._voxel_cam_np.set_pos(self._pta_next_grid_pos[0] + Vec3(0, self._voxel_ws, 0))
elif self.state == self.S_voxelize_y:
self._voxel_cam_np.set_pos(self._pta_next_grid_pos[0] + Vec3(0, self.voxel_world_size, 0))
self._voxel_cam_np.look_at(self._pta_next_grid_pos[0])

# Voxelization from Z-Axis
elif self._state == self.S_voxelize_z:
self._voxel_cam_np.set_pos(self._pta_next_grid_pos[0] + Vec3(0, 0, self._voxel_ws))
elif self.state == self.S_voxelize_z:
self._voxel_cam_np.set_pos(self._pta_next_grid_pos[0] + Vec3(0, 0, self.voxel_world_size))
self._voxel_cam_np.look_at(self._pta_next_grid_pos[0])

# Generate mipmaps
elif self._state == self.S_gen_mipmaps:
elif self.state == self.S_gen_mipmaps:
self._voxel_target.set_active(False)
self._copy_target.set_active(True)
self._voxel_cam_np.hide()
Expand Down
11 changes: 4 additions & 7 deletions rpcore/plugins/vxgi/vxgi_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
"""
from __future__ import division

from rpcore.render_stage import RenderStage
from panda3d.core import SamplerState, LVecBase2i

from rpcore.render_stage import RenderStage
from rpcore.stages.ambient_stage import AmbientStage

class VXGIStage(RenderStage):

required_inputs = ["voxelGridPosition", "Noise4x4"]
Expand All @@ -45,7 +47,6 @@ def produced_pipes(self):
}

def create(self):

# Create a target for the specular GI
self._target_spec = self.make_target("SpecularGI")
self._target_spec.add_color_texture(bits=16)
Expand Down Expand Up @@ -90,11 +91,8 @@ def create(self):
self._target_blur_v.set_shader_input("blur_direction", LVecBase2i(0, 1))
self._target_blur_h.set_shader_input("blur_direction", LVecBase2i(1, 0))


# Make the ambient stage use the GI result
ambient_stage = get_internal_stage("ambient_stage", "AmbientStage")
ambient_stage.required_pipes.append("VXGISpecular")
ambient_stage.required_pipes.append("VXGIDiffuse")
AmbientStage.required_pipes += ["VXGISpecular", "VXGIDiffuse"]

def set_shaders(self):
self._target_spec.set_shader(
Expand All @@ -105,7 +103,6 @@ def set_shaders(self):
self.load_plugin_shader("$$shader/merge_interleaved_target.frag.glsl"))
self._target_upscale_diff.set_shader(
self.load_plugin_shader("$$shader/bilateral_upscale.frag.glsl"))

blur_shader = self.load_plugin_shader("$$shader/bilateral_halfres_blur.frag.glsl")
self._target_blur_v.set_shader(blur_shader)
self._target_blur_h.set_shader(blur_shader)
17 changes: 10 additions & 7 deletions rpcore/plugins/vxgi/vxgi_sun_shadow_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
from __future__ import division
from rplibs.six.moves import range

from rpcore.render_stage import RenderStage

from panda3d.core import Vec3, Camera, OrthographicLens, PTAMat4, SamplerState

from rpcore.globals import Globals
from rpcore.render_stage import RenderStage

class VXGISunShadowStage(RenderStage):

""" This stage creates the shadow map which covers the whole voxel grid,
Expand All @@ -40,7 +41,7 @@ class VXGISunShadowStage(RenderStage):

def __init__(self, pipeline):
RenderStage.__init__(self, "VXGISunShadowStage", pipeline)
self._resolution = 2048
self.resolution = 2048
self._sun_vector = Vec3(0, 0, 1)
self._pta_mvp = PTAMat4.empty_array(1)

Expand All @@ -58,10 +59,12 @@ def make_pcf_state(self):
state.set_magfilter(SamplerState.FT_shadow)
return state

def set_resolution(self, res):
self._resolution = res
@property
def sun_vector(self):
return self._sun_vector

def set_sun_vector(self, direction):
@sun_vector.setter
def sun_vector(self, direction):
self._sun_vector = direction

distance = 400.0
Expand All @@ -84,7 +87,7 @@ def create(self):

self._target = self.make_target("PSSMDistShadowMap")
self._target.set_source(self._cam_node, Globals.base.win)
self._target.size = self._resolution
self._target.size = self.resolution
self._target.add_depth_texture(bits=32)
self._target.create_overlay_quad = False
self._target.color_write = False
Expand Down
Loading

0 comments on commit 6318c39

Please sign in to comment.