Skip to content

Commit

Permalink
Merge pull request #313 from favreau/master
Browse files Browse the repository at this point in the history
Fixed clipping planes in OSPRay Advanced renderer
  • Loading branch information
favreau authored Oct 5, 2023
2 parents 9b11319 + d950026 commit d49b259
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 96 deletions.
92 changes: 84 additions & 8 deletions bioexplorer/pythonsdk/notebooks/widgets/BioExplorer_widgets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -24,15 +24,73 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
"# w.display_clipping_planes([-50, 50])"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
"core = be.core_api()\n",
"core.set_environment_map('/media/favreau/medias/hdri/0000.jpg')\n",
"status = core.set_renderer(\n",
" background_color=[0.2, 0.15, 0.3], head_light=False,\n",
" current='advanced',subsampling=4, max_accum_frames=64)\n",
"params = core.AdvancedRendererParams()\n",
"params.gi_samples = 1\n",
"params.gi_strength = 0.5\n",
"params.gi_ray_length = 100.0\n",
"params.shadow_intensity = 1.0\n",
"params.soft_shadow_strength = 0.0\n",
"params.epsilon_multiplier = 100.0\n",
"params.max_ray_depth = 10\n",
"params.show_background = True\n",
"params.main_exposure = 1.0\n",
"status = core.set_renderer_params(params)\n",
"status = core.set_renderer()"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b19eccf2f90247b2924291e07390e801",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HBox(children=(Select(description='Models:', options=('Demo scene',), value='Demo scene'), Sele…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"w.display_palette_for_models()"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d2fb0c7746f2465ca9f32a5b92ea3cf3",
"model_id": "020d85543ca745d9a35b0ca411b07846",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -50,20 +108,20 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 60,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f913a91cfdbc44299a7626165a4a1e23",
"model_id": "73eca5277dfa467fa9815b7340dd308c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HBox(children=(Select(description='Models:', options=('layer00001',), value='layer00001'), Sele…"
"VBox(children=(HBox(children=(Select(description='Models:', options=('Demo scene',), value='Demo scene'), Sele…"
]
},
"metadata": {},
Expand All @@ -76,13 +134,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 61,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'DEFAULT_GRID_LAYOUT' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/favreau/code/favreau/BioExplorer/bioexplorer/pythonsdk/notebooks/widgets/BioExplorer_widgets.ipynb Cell 8\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/favreau/code/favreau/BioExplorer/bioexplorer/pythonsdk/notebooks/widgets/BioExplorer_widgets.ipynb#X11sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m w\u001b[39m.\u001b[39;49mdisplay_model_visibility()\n",
"File \u001b[0;32m~/Notebooks/env/lib/python3.10/site-packages/bioexplorer/notebook_widgets.py:638\u001b[0m, in \u001b[0;36mWidgets.display_model_visibility\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 635\u001b[0m hide_aabb_btn\u001b[39m.\u001b[39mon_click(hide_aabbs)\n\u001b[1;32m 636\u001b[0m adjust_camera_btn\u001b[39m.\u001b[39mon_click(adjust_camera)\n\u001b[0;32m--> 638\u001b[0m hbox \u001b[39m=\u001b[39m HBox([model_select, hbox_params], layout\u001b[39m=\u001b[39mDEFAULT_GRID_LAYOUT)\n\u001b[1;32m 639\u001b[0m display(hbox)\n",
"\u001b[0;31mNameError\u001b[0m: name 'DEFAULT_GRID_LAYOUT' is not defined"
]
}
],
"source": [
"w.display_model_visibility()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 2 additions & 0 deletions platform/core/common/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static const char* RENDERER_PROPERTY_BACKGROUND_MATERIAL = "bgMaterial";
static const char* RENDERER_PROPERTY_LIGHTS = "lights";
static const char* RENDERER_PROPERTY_RANDOM_NUMBER = "randomNumber";

static constexpr bool DEFAULT_RENDERER_FAST_PREVIEW = false;
static constexpr bool DEFAULT_RENDERER_SHOW_BACKGROUND = true;
static constexpr int DEFAULT_RENDERER_MAX_RAY_DEPTH = 3;
static constexpr double DEFAULT_RENDERER_SHADOW_INTENSITY = 0.0;
Expand Down Expand Up @@ -130,6 +131,7 @@ static const Property RENDERER_PROPERTY_MAX_DISTANCE_TO_SECONDARY_MODEL = {
0.1,
100.0,
{"Maximum distance to secondary model"}};
static const Property RENDERER_PROPERTY_FAST_PREVIEW = {"fastPreview", DEFAULT_RENDERER_FAST_PREVIEW, {"Fast preview"}};

/*
Material properties
Expand Down
2 changes: 1 addition & 1 deletion platform/core/engineapi/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void Scene::buildDefault()
CORE_INFO("Building default Cornell Box scene");

auto model = createModel();
#if 1
#if 0
const Vector3f WHITE = {1.f, 1.f, 1.f};

const Vector3f positions[8] = {
Expand Down
7 changes: 5 additions & 2 deletions platform/engines/ospray/OSPRayEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void OSPRayEngine::_createRenderers()
{
PLUGIN_INFO("Registering '" << RENDERER_PROPERTY_TYPE_ADVANCED << "' renderer");
PropertyMap properties;
properties.setProperty(RENDERER_PROPERTY_FAST_PREVIEW);
properties.setProperty(RENDERER_PROPERTY_ALPHA_CORRECTION);
properties.setProperty(RENDERER_PROPERTY_MAX_DISTANCE_TO_SECONDARY_MODEL);
properties.setProperty(RENDERER_PROPERTY_GLOBAL_ILLUMINATION_RAY_LENGTH);
Expand Down Expand Up @@ -177,8 +178,10 @@ void OSPRayEngine::_createRenderers()
properties.setProperty(OSPRAY_RENDERER_SHADOW_ENABLED);
addRendererType(RENDERER_PROPERTY_TYPE_SCIVIS, properties);
}
PLUGIN_INFO("Registering '" << RENDERER_PROPERTY_TYPE_BASIC << "' renderer");
addRendererType(RENDERER_PROPERTY_TYPE_BASIC);
{
PLUGIN_INFO("Registering '" << RENDERER_PROPERTY_TYPE_BASIC << "' renderer");
addRendererType(RENDERER_PROPERTY_TYPE_BASIC);
}
}

FrameBufferPtr OSPRayEngine::createFrameBuffer(const std::string& name, const Vector2ui& frameSize,
Expand Down
5 changes: 5 additions & 0 deletions platform/engines/ospray/OSPRayMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ void OSPRayMaterial::commit()
osphelper::set(_ospMaterial, MATERIAL_PROPERTY_DIFFUSE_COLOR, Vector3f(_diffuseColor));
osphelper::set(_ospMaterial, MATERIAL_PROPERTY_SPECULAR_COLOR, Vector3f(_specularColor));
osphelper::set(_ospMaterial, MATERIAL_PROPERTY_SPECULAR_INDEX, static_cast<float>(_specularExponent));
#if 0
// For some unknown reason, this simply does not work!?!
osphelper::set(_ospMaterial, MATERIAL_PROPERTY_OPACITY, static_cast<float>(_opacity));
#else
osphelper::set(_ospMaterial, "opacity", static_cast<float>(_opacity));
#endif
osphelper::set(_ospMaterial, MATERIAL_PROPERTY_REFRACTION, static_cast<float>(_refractionIndex));
osphelper::set(_ospMaterial, MATERIAL_PROPERTY_REFLECTION, static_cast<float>(_reflectionIndex));
osphelper::set(_ospMaterial, MATERIAL_PROPERTY_EMISSION, static_cast<float>(_emission));
Expand Down
16 changes: 16 additions & 0 deletions platform/engines/ospray/OSPRayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ void OSPRayRenderer::commit()

ospSetObject(_renderer, OSPRAY_RENDERER_PROPERTY_CAMERA, _camera->impl());
ospSetObject(_renderer, OSPRAY_RENDERER_PROPERTY_WORLD, scene->getModel());

// Clip planes
if (!_clipPlanes.empty())
{
const auto clipPlanes = convertVectorToFloat(_clipPlanes);
auto clipPlaneData = ospNewData(clipPlanes.size(), OSP_FLOAT4, clipPlanes.data());
ospSetData(_renderer, CAMERA_PROPERTY_CLIPPING_PLANES, clipPlaneData);
ospRelease(clipPlaneData);
}
else
{
// ospRemoveParam leaks objects, so we set it to null first
ospSetData(_renderer, CAMERA_PROPERTY_CLIPPING_PLANES, nullptr);
ospRemoveParam(_renderer, CAMERA_PROPERTY_CLIPPING_PLANES);
}

ospCommit(_renderer);
}

Expand Down
13 changes: 2 additions & 11 deletions platform/engines/ospray/ispc/render/AdvancedRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,8 @@ void AdvancedRenderer::commit()
{
SimulationRenderer::commit();

_fastPreview = getParam(RENDERER_PROPERTY_FAST_PREVIEW.name.c_str(), DEFAULT_RENDERER_FAST_PREVIEW);
_alphaCorrection = getParam1f(RENDERER_PROPERTY_ALPHA_CORRECTION.name.c_str(), DEFAULT_RENDERER_ALPHA_CORRECTION);
_fogStart = getParam1f(RENDERER_PROPERTY_FOG_START.name.c_str(), DEFAULT_RENDERER_FOG_START);
_fogThickness = getParam1f(RENDERER_PROPERTY_FOG_THICKNESS.name.c_str(), DEFAULT_RENDERER_FOG_THICKNESS);
_exposure = getParam1f(COMMON_PROPERTY_EXPOSURE.name.c_str(), DEFAULT_COMMON_EXPOSURE);
_epsilonFactor = getParam1f(RENDERER_PROPERTY_EPSILON_MULTIPLIER.name.c_str(), DEFAULT_RENDERER_EPSILON_MULTIPLIER);
_maxRayDepth = getParam1i(RENDERER_PROPERTY_MAX_RAY_DEPTH.name.c_str(), DEFAULT_RENDERER_MAX_RAY_DEPTH);
_randomNumber = rand() % 1000;
_useHardwareRandomizer = getParam(COMMON_PROPERTY_USE_HARDWARE_RANDOMIZER.name.c_str(),
static_cast<int>(DEFAULT_COMMON_USE_HARDWARE_RANDOMIZER));
_showBackground = getParam(RENDERER_PROPERTY_SHOW_BACKGROUND.name.c_str(), DEFAULT_RENDERER_SHOW_BACKGROUND);
_shadows = getParam1f(RENDERER_PROPERTY_SHADOW_INTENSITY.name.c_str(), DEFAULT_RENDERER_SHADOW_INTENSITY);
_softShadows =
getParam1f(RENDERER_PROPERTY_SOFT_SHADOW_STRENGTH.name.c_str(), DEFAULT_RENDERER_SOFT_SHADOW_STRENGTH);
Expand All @@ -101,15 +93,14 @@ void AdvancedRenderer::commit()
clipPlanes = getParamData(CAMERA_PROPERTY_CLIPPING_PLANES, nullptr);
const auto clipPlaneData = clipPlanes ? clipPlanes->data : nullptr;
const uint32 numClipPlanes = clipPlanes ? clipPlanes->numItems : 0;

::ispc::AdvancedRenderer_set(getIE(), (_bgMaterial ? _bgMaterial->getIE() : nullptr), _shadows, _softShadows,
_softShadowsSamples, _giStrength, _giDistance, _giSamples, _randomNumber, _timestamp,
spp, _lightPtr, _lightArray.size(), _exposure, _epsilonFactor, _fogThickness,
_fogStart, _useHardwareRandomizer, _maxRayDepth, _showBackground, _matrixFilter,
_userData ? (float*)_userData->data : nullptr, _simulationDataSize,
_volumeSamplingThreshold, _volumeSpecularExponent, _volumeAlphaCorrection,
(const ::ispc::vec4f*)clipPlaneData, numClipPlanes, _anaglyphEnabled,
(ispc::vec3f&)_anaglyphIpdOffset);
(ispc::vec3f&)_anaglyphIpdOffset, _fastPreview);
}

AdvancedRenderer::AdvancedRenderer()
Expand Down
1 change: 1 addition & 0 deletions platform/engines/ospray/ispc/render/AdvancedRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class AdvancedRenderer : public SimulationRenderer

private:
// Shading
bool _fastPreview{false};
double _shadows{0.f};
double _softShadows{0.f};
::ospray::uint32 _softShadowsSamples{1};
Expand Down
1 change: 1 addition & 0 deletions platform/engines/ospray/ispc/render/AdvancedRenderer.ih
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct AdvancedRenderer
SimulationRenderer super;

// Shading
bool fastPreview;
float shadowIntensity;
float softShadowStrength;
uint32 shadowSamples;
Expand Down
Loading

0 comments on commit d49b259

Please sign in to comment.