Skip to content

Commit

Permalink
Merge pull request #924 from dictoon/master
Browse files Browse the repository at this point in the history
Miscellaneous fixes and improvements
  • Loading branch information
est77 committed Nov 17, 2015
2 parents 6f72697 + 5b7dbea commit 2edc26e
Show file tree
Hide file tree
Showing 27 changed files with 315 additions and 347 deletions.
61 changes: 38 additions & 23 deletions sandbox/shaders/src/compile_shaders.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
#!/usr/bin/python

#
# This source file is part of appleseed.
# Visit http://appleseedhq.net/ for additional information and resources.
#
# This software is released under the MIT license.
#
# Copyright (c) 2015 Esteban Tovagliari, The appleseedhq Organization
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

from __future__ import print_function
import os
import shutil
import sys

if len(sys.argv) != 2:
print "Wrong number of arguments"
print "Usage compile_shaders [path to oslc]"
print("Usage: {0} [path-to-oslc]".format(sys.argv[0]))
sys.exit(0)

oslc_cmd = sys.argv[1]
include_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "include")

for root, dirname, files in os.walk("."):
for filename in files:
for dirpath, dirnames, filenames in os.walk("."):
for filename in filenames:
if filename.endswith(".osl"):
print "compiling shader: " + os.path.join(root, filename)

dest_dir = os.path.join("../", root)
src_filepath = os.path.join(dirpath, filename)

dest_dir = os.path.join("..", dirpath)
dst_filename = filename.replace(".osl", ".oso")
dst_filepath = os.path.join(dest_dir, dst_filename)

if not os.path.exists(dest_dir):
os.makedirs(dest_dir)

saved_wd = os.getcwd()
os.chdir(root)
retcode = os.system(oslc_cmd + " -v -I" + include_dir + ' ' + filename)
retcode = os.system("{0} -v -I{1} -o {2} {3}".format(oslc_cmd, include_dir, dst_filepath, src_filepath))

if retcode != 0:
print "Stopping because of errors..."
print("Compilation of {0} failed with error code {1}. Stopping.".format(src_filepath, retcode))
sys.exit(retcode)

oso_filename = filename.replace(".osl", ".oso")
dest_dir = os.path.join("..", dest_dir)

if os.path.exists(os.path.join(dest_dir, oso_filename)):
os.remove(os.path.join(dest_dir, oso_filename))

shutil.move(oso_filename, dest_dir)
os.chdir(saved_wd)

print "All shaders compiled!"
9 changes: 7 additions & 2 deletions scripts/appleseed.package.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# Constants.
#--------------------------------------------------------------------------------------------------

VERSION = "2.4.0"
VERSION = "2.4.1"
SETTINGS_FILENAME = "appleseed.package.configuration.xml"


Expand Down Expand Up @@ -320,13 +320,18 @@ def add_unix_dependencies_to_stage(self):

def add_headers_to_stage(self):
progress("Adding headers to staging directory")
safe_make_directory("appleseed/include")

# appleseed headers.
safe_make_directory("appleseed/include")
ignore_files = shutil.ignore_patterns("*.cpp", "*.c", "*.xsd", "stdosl.h", "oslutil.h", "snprintf", "version.h.in")
shutil.copytree(os.path.join(self.settings.headers_path, "foundation"), "appleseed/include/foundation", ignore = ignore_files)
shutil.copytree(os.path.join(self.settings.headers_path, "main"), "appleseed/include/main", ignore = ignore_files)
shutil.copytree(os.path.join(self.settings.headers_path, "renderer"), "appleseed/include/renderer", ignore = ignore_files)

# OSL headers.
shutil.copy(os.path.join(self.settings.headers_path, "renderer/kernel/shading/oslutil.h"), "appleseed/shaders/")
shutil.copy(os.path.join(self.settings.headers_path, "renderer/kernel/shading/stdosl.h"), "appleseed/shaders/")

def add_scripts_to_stage(self):
progress("Adding scripts to staging directory")
shutil.copy("convertmany.py", "appleseed/bin/")
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed.python/dict2dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace
// TODO: add conversions from bpy::tuple to Vector<T, N>.
// ...

// TODO: check more types here if needed... (est.)
// TODO: check more types here if needed...

// dict
{
Expand Down Expand Up @@ -189,7 +189,7 @@ namespace
}
catch (ExceptionStringConversionError&) {}

// TODO: check more types here if needed... (est.)
// TODO: check more types here if needed...

// as a fallback, return a string
return bpy::object(str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ bool DirectLightingIntegrator::compute_incoming_radiance(
if (sample.m_triangle)
{
const Material* material = sample.m_triangle->m_material;
const EDF* edf = material->get_edf();
const Material::RenderData& material_data = material->get_render_data();
const EDF* edf = material_data.m_edf;

// No contribution if we are computing indirect lighting but this light does not cast indirect light.
if (m_indirect && !(edf->get_flags() & EDF::CastIndirectLight))
Expand Down Expand Up @@ -429,8 +430,12 @@ bool DirectLightingIntegrator::compute_incoming_radiance(
m_shading_context.get_intersector());

#ifdef APPLESEED_WITH_OSL
if (const ShaderGroup* sg = material->get_osl_surface())
m_shading_context.execute_osl_emission(*sg, light_shading_point);
if (material_data.m_shader_group)
{
m_shading_context.execute_osl_emission(
*material_data.m_shader_group,
light_shading_point);
}
#endif

// Evaluate the EDF inputs.
Expand Down Expand Up @@ -534,9 +539,10 @@ void DirectLightingIntegrator::take_single_bsdf_sample(
const Material* material = light_shading_point.get_material();
if (material == 0)
return;
const Material::RenderData& material_data = material->get_render_data();

// Retrieve the EDF at the intersection point.
const EDF* edf = material->get_edf();
const EDF* edf = material_data.m_edf;
if (edf == 0)
return;

Expand All @@ -550,8 +556,12 @@ void DirectLightingIntegrator::take_single_bsdf_sample(
return;

#ifdef APPLESEED_WITH_OSL
if (const ShaderGroup* sg = material->get_osl_surface())
m_shading_context.execute_osl_emission(*sg, light_shading_point);
if (material_data.m_shader_group)
{
m_shading_context.execute_osl_emission(
*material_data.m_shader_group,
light_shading_point);
}
#endif

// Evaluate the EDF inputs.
Expand Down Expand Up @@ -647,7 +657,8 @@ void DirectLightingIntegrator::add_emitting_triangle_sample_contribution(
SpectrumStack& aovs) const
{
const Material* material = sample.m_triangle->m_material;
const EDF* edf = material->get_edf();
const Material::RenderData& material_data = material->get_render_data();
const EDF* edf = material_data.m_edf;

// No contribution if we are computing indirect lighting but this light does not cast indirect light.
if (m_indirect && !(edf->get_flags() & EDF::CastIndirectLight))
Expand Down Expand Up @@ -720,8 +731,12 @@ void DirectLightingIntegrator::add_emitting_triangle_sample_contribution(
m_shading_context.get_intersector());

#ifdef APPLESEED_WITH_OSL
if (const ShaderGroup* sg = material->get_osl_surface())
m_shading_context.execute_osl_emission(*sg, light_shading_point);
if (material_data.m_shader_group)
{
m_shading_context.execute_osl_emission(
*material_data.m_shader_group,
light_shading_point);
}
#endif

// Evaluate the EDF inputs.
Expand Down
1 change: 1 addition & 0 deletions src/appleseed/renderer/kernel/lighting/lightsampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ void LightSampler::collect_emitting_triangles(
}

#ifdef APPLESEED_WITH_OSL

void LightSampler::store_object_area_in_shadergroups(
const AssemblyInstance* assembly_instance,
const ObjectInstance* object_instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,10 @@ namespace
, m_light_sample_count(0)
, m_path_count(0)
{
const Scene::CachedInfo* scene_info = m_scene.get_cached_info();
assert(scene_info);
m_scene_center = scene_info->m_center;
m_scene_radius = scene_info->m_radius;
m_safe_scene_diameter = scene_info->m_safe_diameter;
const Scene::RenderData& scene_data = m_scene.get_render_data();
m_scene_center = scene_data.m_center;
m_scene_radius = scene_data.m_radius;
m_safe_scene_diameter = scene_data.m_safe_diameter;
m_disk_point_prob = 1.0 / (Pi * m_scene_radius * m_scene_radius);

const Camera* camera = scene.get_camera();
Expand Down Expand Up @@ -583,7 +582,7 @@ namespace
light_sample.m_shading_normal);

const Material* material = light_sample.m_triangle->m_material;
const EDF* edf = material->get_edf();
const Material::RenderData& material_data = material->get_render_data();

// Build a shading point on the light source.
ShadingPoint light_shading_point;
Expand All @@ -593,20 +592,24 @@ namespace
m_shading_context.get_intersector());

#ifdef APPLESEED_WITH_OSL
if (const ShaderGroup* sg = material->get_osl_surface())
m_shading_context.execute_osl_emission(*sg, light_shading_point);
if (material_data.m_shader_group)
{
m_shading_context.execute_osl_emission(
*material_data.m_shader_group,
light_shading_point);
}
#endif

// Evaluate the EDF inputs.
InputEvaluator input_evaluator(m_texture_cache);
edf->evaluate_inputs(input_evaluator, light_shading_point);
material_data.m_edf->evaluate_inputs(input_evaluator, light_shading_point);

// Sample the EDF.
sampling_context.split_in_place(2, 1);
Vector3d emission_direction;
Spectrum edf_value;
double edf_prob;
edf->sample(
material_data.m_edf->sample(
sampling_context,
input_evaluator.data(),
light_sample.m_geometric_normal,
Expand Down Expand Up @@ -658,7 +661,7 @@ namespace
m_params.m_rr_min_path_length,
m_params.m_max_path_length,
m_params.m_max_iterations,
edf->get_light_near_start()); // don't illuminate points closer than the light near start value
material_data.m_edf->get_light_near_start()); // don't illuminate points closer than the light near start value

// Handle the light vertex separately.
Spectrum light_particle_flux = edf_value; // todo: only works for diffuse EDF? What we need is the light exitance
Expand Down
24 changes: 13 additions & 11 deletions src/appleseed/renderer/kernel/lighting/pathtracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,23 @@ size_t PathTracer<PathVisitor, Adjoint>::trace(
if (material == 0)
break;

const Material::RenderData& material_data = material->get_render_data();

// Handle alpha mapping.
if (vertex.m_path_length > 1)
{
Alpha alpha = vertex.m_shading_point->get_alpha();

#ifdef APPLESEED_WITH_OSL
// Apply OSL transparency if needed.
if (material->get_osl_surface() && material->get_osl_surface()->has_transparency())
if (material_data.m_shader_group &&
material_data.m_shader_group->has_transparency())
{
Alpha a;
shading_context.execute_osl_transparency(
*material->get_osl_surface(),
*material_data.m_shader_group,
*vertex.m_shading_point,
a);

alpha *= a;
}
#endif
Expand Down Expand Up @@ -282,19 +284,19 @@ size_t PathTracer<PathVisitor, Adjoint>::trace(

#ifdef APPLESEED_WITH_OSL
// Execute the OSL shader if there is one.
if (material->get_osl_surface())
if (material_data.m_shader_group)
{
shading_context.execute_osl_shading(
*material->get_osl_surface(),
*material_data.m_shader_group,
*vertex.m_shading_point);
}
#endif

// Retrieve the EDF, the BSDF and the BSSRDF.
vertex.m_edf =
vertex.m_shading_point->is_curve_primitive() ? 0 : material->get_edf();
vertex.m_bsdf = material->get_bsdf();
vertex.m_bssrdf = material->get_bssrdf();
vertex.m_shading_point->is_curve_primitive() ? 0 : material_data.m_edf;
vertex.m_bsdf = material_data.m_bsdf;
vertex.m_bssrdf = material_data.m_bssrdf;

// If there is both a BSDF and a BSSRDF, pick one to extend the path.
if (vertex.m_bsdf && vertex.m_bssrdf)
Expand Down Expand Up @@ -376,10 +378,10 @@ size_t PathTracer<PathVisitor, Adjoint>::trace(

if (!Adjoint)
{
if (material->has_osl_surface())
if (material_data.m_shader_group)
{
shading_context.execute_osl_subsurface(
*material->get_osl_surface(),
*material_data.m_shader_group,
*vertex.m_incoming_point);
}

Expand All @@ -388,7 +390,7 @@ size_t PathTracer<PathVisitor, Adjoint>::trace(
bssrdf_input_evaluator,
*vertex.m_incoming_point);

if (material->has_osl_surface())
if (material_data.m_shader_group)
{
sampling_context.split_in_place(1, 1);
shading_context.choose_osl_subsurface_normal(
Expand Down
2 changes: 1 addition & 1 deletion src/appleseed/renderer/kernel/lighting/pathvertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void PathVertex::compute_emitted_radiance(
}

#ifdef APPLESEED_WITH_OSL
if (const ShaderGroup* sg = get_material()->get_osl_surface())
if (const ShaderGroup* sg = get_material()->get_render_data().m_shader_group)
shading_context.execute_osl_emission(*sg, *m_shading_point);
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ SPPMPassCallback::SPPMPassCallback(
, m_pass_number(0)
{
// Compute the initial lookup radius.
const Scene::CachedInfo* scene_info = scene.get_cached_info();
assert(scene_info);
const float diameter = static_cast<float>(scene_info->m_diameter);
const float diameter = static_cast<float>(scene.get_render_data().m_diameter);
const float diameter_factor = m_params.m_initial_radius_percents / 100.0f;
m_initial_lookup_radius = diameter * diameter_factor;

Expand Down
Loading

0 comments on commit 2edc26e

Please sign in to comment.