Skip to content

Commit

Permalink
Start to implement the environment map plugin, fix pylint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tobspr committed Feb 20, 2016
1 parent 6318c39 commit c881c57
Show file tree
Hide file tree
Showing 79 changed files with 693 additions and 232 deletions.
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS,rplibs,.git,scripts
ignore=CVS,rplibs,.git,scripts,build.py

# Pickle collected data for later comparisons.
persistent=yes
Expand Down Expand Up @@ -95,10 +95,10 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme
bad-functions=map,filter,input,xrange,iteritems

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_,x,y,r,g,b,a,uv,w,h
good-names=i,j,k,ex,Run,_,x,y,r,g,b,a,uv,w,h,np

# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
bad-names=foo,bar,baz,toto,tutu,tata,

# Colon-delimited sets of names that determine each other's naming style when
# the name regexes allow several styles.
Expand Down
Empty file added __init__.py
Empty file.
2 changes: 1 addition & 1 deletion config/plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ overrides:
color_correction.film_grain_strength: 0.13
color_correction.color_lut: color_lut.png
color_correction.use_chromatic_aberration: True
color_correction.chromatic_aberration_strength: 0.15
color_correction.chromatic_aberration_strength: 0.009
color_correction.chromatic_aberration_samples: 1
color_correction.use_auto_exposure: True
color_correction.min_exposure: 0.001
Expand Down
4 changes: 3 additions & 1 deletion config/stages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

global_stage_order:

# Shadows and Voxelization
# Shadows, Environment and Voxelization
- PSSMShadowStage
- PSSMDistShadowStage
- VXGISunShadowStage
- VoxelizationStage
- ScatteringEnvmapStage
- EnvironmentCaptureStage

# Main scene
- GBufferStage
Expand All @@ -29,6 +30,7 @@ global_stage_order:
- ApplyLightsStage
- PSSMStage
- ScatteringStage
- ApplyCubemapsStage
- VXGIStage
- AmbientStage
- SSLRStage
Expand Down
3 changes: 3 additions & 0 deletions effects/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ shadows:

voxelize:
template: default

envmap:
template: default
3 changes: 3 additions & 0 deletions effects/skybox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ shadows:

voxelize:
template: default

envmap:
template: default
Empty file added mklink
Empty file.
3 changes: 2 additions & 1 deletion rpcore/common_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from panda3d.core import SamplerState, PNMImage
from direct.stdpy.file import open

from rpcore.image import Image
from rpcore.globals import Globals
from rpcore.base_manager import BaseManager

Expand Down Expand Up @@ -146,7 +147,7 @@ def _load_noise_tex(self):
img = PNMImage(4, 4, 3)
for x in range(16):
img.set_xel(x % 4, x // 4, random.random(), random.random(), random.random())
tex = Texture("Random4x4")
tex = Image("Random4x4")
tex.load(img)
self._pipeline.stage_mgr.add_input("Noise4x4", tex)

Expand Down
12 changes: 7 additions & 5 deletions rpcore/effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import copy

from rplibs.six import iteritems, iterkeys
from rplibs.yaml import load_yaml_file

from panda3d.core import Shader, Filename

from rpcore.rp_object import RPObject
from rplibs.yaml import load_yaml_file
from rpcore.util.shader_template import ShaderTemplate

class Effect(RPObject):
Expand All @@ -43,12 +43,13 @@ class Effect(RPObject):
"render_gbuffer": True,
"render_shadows": True,
"render_voxel": True,
"render_envmap": True,
"alpha_testing": True,
"normal_mapping": True,
"parallax_mapping": False,
}

_PASSES = ("gbuffer", "shadows", "voxelize")
_PASSES = ("gbuffer", "shadows", "voxelize", "envmap")
_GLOBAL_CACHE = {}
_EFFECT_ID = 0

Expand All @@ -63,7 +64,7 @@ def load(cls, filename, options):
return cls._GLOBAL_CACHE[effect_hash]
effect = cls()
effect.set_options(options)
if not effect._load(filename):
if not effect.do_load(filename):
RPObject.global_error("Effect", "Could not load effect!")
return None
return effect
Expand Down Expand Up @@ -120,8 +121,9 @@ def set_options(self, options):
continue
self._options[key] = val

def _load(self, filename):
""" Loads the effect from the given filename """
def do_load(self, filename):
""" Internal method to load the effect from the given filename, do
not use this directly, instead use load(). """
self._source = filename
self._effect_name = self._convert_filename_to_name(filename)
self._shader_paths = {}
Expand Down
2 changes: 1 addition & 1 deletion rpcore/gpu_command_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from panda3d.core import PTAInt, Texture, Shader

from rpcore.rp_object import RPObject
from rpcore.util.image import Image
from rpcore.image import Image
from rpcore.render_target import RenderTarget

from rpcore.native import GPUCommand, GPUCommandList
Expand Down
4 changes: 2 additions & 2 deletions rpcore/gui/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def node(self):
""" Returns a handle to the internally used node """
return self._node

def _update_status(self, status, *args):
def _update_status(self, status):
""" Internal method when another checkbox in the same radio group
changed it's value """

Expand All @@ -105,7 +105,7 @@ def _update_status(self, status, *args):

if self._collection:
if status:
self._collection._changed(self)
self._collection.on_checkbox_changed(self)
# A radio box can't be unchecked
# self._node["state"] = DGG.DISABLED

Expand Down
2 changes: 1 addition & 1 deletion rpcore/gui/checkbox_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def remove(self, chb):
chb.collection = None
self._items.remove(chb)

def _changed(self, chb):
def on_checkbox_changed(self, chb):
""" Internal callback when a checkbox got changed """
for item in self._items:
if item is not chb:
Expand Down
4 changes: 2 additions & 2 deletions rpcore/gui/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

from rpcore.native import NATIVE_CXX_LOADED
from rpcore.render_target import RenderTarget
from rpcore.util.image import Image
from rpcore.image import Image

class Debugger(BaseManager):

Expand Down Expand Up @@ -179,7 +179,7 @@ def _update_stats(self):
text += "{:5d} render targets | {:3d} plugins"
tex_info = self._buffer_viewer.stage_information
self._debug_lines[2].text = text.format(
tex_info["memory"] / (1024**2) ,
tex_info["memory"] / (1024**2),
Image.get_image_count(),
tex_info["count"],
RenderTarget.get_num_buffers(),
Expand Down
2 changes: 1 addition & 1 deletion rpcore/gui/exposure_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from rpcore.gui.text import Text

from rpcore.rp_object import RPObject
from rpcore.util.image import Image
from rpcore.image import Image
from rpcore.globals import Globals

class ExposureWidget(RPObject):
Expand Down
3 changes: 2 additions & 1 deletion rpcore/ies_profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from panda3d.core import Filename, Texture, VirtualFileSystem, get_model_path
from panda3d.core import SamplerState

from rpcore.image import Image
from rpcore.rp_object import RPObject
from rpcore.util.ies_profile_loader import IESProfileLoader, IESLoaderException

Expand All @@ -45,7 +46,7 @@ def __init__(self, pipeline):

def _create_storage(self):
""" Internal method to create the storage for the profile dataset textures """
self._storage_tex = Texture("IESDatasets")
self._storage_tex = Image("IESDatasets")
self._storage_tex.setup_3d_texture(
512, 512, self._max_entries, Texture.T_float, Texture.F_r16)
self._storage_tex.set_minfilter(SamplerState.FT_linear)
Expand Down
3 changes: 2 additions & 1 deletion rpcore/util/image.py → rpcore/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class Image(RPObject, Texture):

""" This is a wrapper arround the Texture class from Panda3D, which keeps
track of all images and registers / unregisters them aswell as counting
the memory used. """
the memory used. This is used by all classes instead of pandas builtin
Texture. """

# Total amount of images
_NUM_IMAGES = 0
Expand Down
2 changes: 1 addition & 1 deletion rpcore/light_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from panda3d.core import LVecBase2i, Texture, PTAInt

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

from rpcore.stages.flag_used_cells_stage import FlagUsedCellsStage
Expand Down
2 changes: 1 addition & 1 deletion rpcore/mount_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _try_remove(self, fname):
try:
os.remove(fname)
return True
except:
except IOError:
pass
return False

Expand Down
13 changes: 8 additions & 5 deletions rpcore/native/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,31 @@
"""

# Disable the invalid constant name warning
# pylint: disable=C0103

# This file includes all modules from the native module.

from __future__ import print_function
import sys
import importlib
from os.path import dirname, realpath

from direct.stdpy.file import join, isfile
from os.path import dirname, realpath
from rpcore.rp_object import RPObject

# Store a global flag, indicating whether the C++ modules were loaded or the python
# implemetation of them
NATIVE_CXX_LOADED = False

# Read the configuration from the flag-file
curr_path = dirname(realpath(__file__))
flag_path = join(curr_path, "use_cxx.flag")
if not isfile(flag_path):
current_path = dirname(realpath(__file__))
cxx_flag_path = join(current_path, "use_cxx.flag")
if not isfile(cxx_flag_path):
RPObject.global_error("CORE", "Could not find cxx flag, please run the setup.py!")
sys.exit(1)
else:
with open(join(curr_path, "use_cxx.flag"), "r") as handle:
with open(join(current_path, "use_cxx.flag"), "r") as handle:
NATIVE_CXX_LOADED = handle.read().strip() == "1"

# The native module should only be imported once, and that by the internal pipeline code
Expand Down
8 changes: 7 additions & 1 deletion rpcore/native/source/light_system/tag_state_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ TagStateManager::TagStateManager(NodePath main_cam_node) {
_shadow_container.mask = get_shadow_mask();
_voxelize_container.tag_name = "Voxelize";
_voxelize_container.mask = get_voxelize_mask();
_envmap_container.tag_name = "Envmap";
_envmap_container.mask = get_envmap_mask();
}

/**
Expand Down Expand Up @@ -125,6 +127,7 @@ void TagStateManager::cleanup_states() {
// Clear the containers
cleanup_container_states(_shadow_container);
cleanup_container_states(_voxelize_container);
cleanup_container_states(_envmap_container);
}

/**
Expand Down Expand Up @@ -156,7 +159,10 @@ void TagStateManager::register_camera(StateContainer& container, Camera* source)
// Construct an initial state which also disables color write, additionally
// to the ColorWriteAttrib on each unique state.
CPT(RenderState) state = RenderState::make_empty();
state = state->set_attrib(ColorWriteAttrib::make(ColorWriteAttrib::C_off), 10000);

if (&container != &_envmap_container) {
state = state->set_attrib(ColorWriteAttrib::make(ColorWriteAttrib::C_off), 10000);
}
source->set_initial_state(state);

// Store the camera so we can keep track of it
Expand Down
16 changes: 12 additions & 4 deletions rpcore/pipeline_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ def set_empty_loading_screen(self):
""" Tells the pipeline to use no loading screen """
self._loading_screen = EmptyLoadingScreen()

def set_image_loading_screen(self, image_pth):
""" Tells the pipeline to load an image loading screen """
raise NotImplementedError("TODO")

@property
def loading_screen(self):
""" Returns the current loading screen """
Expand All @@ -88,8 +84,11 @@ def _create_default_skybox(self, size=40000):
skybox.reparent_to(Globals.render)
self.set_effect(skybox, "effects/skybox.yaml", {
"render_shadows": False,
"render_envmap": False,
"render_voxel": False,
"alpha_testing": False,
"normal_mapping": False,
"parallax_mapping": False
}, 1000)
return skybox

Expand Down Expand Up @@ -135,6 +134,15 @@ def set_effect(self, nodepath, effect_src, options=None, sort=30):
nodepath, shader, str(effect.effect_id), 35 + sort)
nodepath.show(self._tag_mgr.get_voxelize_mask())

# Apply envmap stage shader
if not effect.get_option("render_envmap"):
nodepath.hide(self._tag_mgr.get_envmap_mask())
else:
shader = effect.get_shader_obj("envmap")
self._tag_mgr.apply_envmap_state(
nodepath, shader, str(effect.effect_id), 45 + sort)
nodepath.show(self._tag_mgr.get_envmap_mask())

def _check_version(self):
""" Internal method to check if the required Panda3D version is met. Returns
True if the version is new enough, and false if the version is outdated. """
Expand Down
2 changes: 1 addition & 1 deletion rpcore/pluginbase/base_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

from direct.stdpy.file import isfile, open, join
from direct.stdpy.file import isfile, join

from rplibs.yaml import load_yaml_file
from rpcore.rp_object import RPObject
Expand Down
Loading

0 comments on commit c881c57

Please sign in to comment.