Skip to content

Commit

Permalink
Added option to change BRDF parameters from Python module.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismile committed Sep 5, 2024
1 parent 6647d29 commit f45ab5c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/PathTracer/VolumetricPathTracingPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,35 @@ void VolumetricPathTracingPass::setSurfaceBrdf(SurfaceBrdf _surfaceBrdf) {
}
}

void VolumetricPathTracingPass::setBrdfParameter(const std::string& key, const std::string& value) {
if (key == "subsurface") {
subsurface = sgl::fromString<float>(value);
} else if (key == "metallic") {
metallic = sgl::fromString<float>(value);
} else if (key == "specular") {
specular = sgl::fromString<float>(value);
} else if (key == "specular_tint") {
specularTint = sgl::fromString<float>(value);
} else if (key == "roughness") {
roughness = sgl::fromString<float>(value);
} else if (key == "anisotropic") {
anisotropic = sgl::fromString<float>(value);
} else if (key == "sheen") {
sheen = sgl::fromString<float>(value);
} else if (key == "sheen_tint") {
sheenTint = sgl::fromString<float>(value);
} else if (key == "clearcoat") {
clearcoat = sgl::fromString<float>(value);
} else if (key == "clearcoat_gloss") {
clearcoatGloss = sgl::fromString<float>(value);
} else {
sgl::Logfile::get()->writeError(
"Error in VolumetricPathTracingPass::setBrdfParameter: Unsupported parameter \"" + key + "\".");
}
reRender = true;
frameInfo.frameCount = 0;
}

void VolumetricPathTracingPass::setUseIsosurfaceTf(bool _useIsosurfaceTf) {
if (useIsosurfaceTf != _useIsosurfaceTf) {
useIsosurfaceTf = _useIsosurfaceTf;
Expand Down Expand Up @@ -2764,52 +2793,42 @@ bool VolumetricPathTracingPass::renderGuiPropertyEditorNodes(sgl::PropertyEditor

if (useIsosurfaces && surfaceBrdf == SurfaceBrdf::DISNEY && propertyEditor.beginNode("Disney BRDF Parameters")) {
if (propertyEditor.addSliderFloat("subsurface", (float*)&subsurface, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("metallic", (float*)&metallic, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("specular", (float*)&specular, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("specularTint", (float*)&specularTint, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("roughness", (float*)&roughness, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("anisotropic", (float*)&anisotropic, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("sheen", (float*)&sheen, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("sheenTint", (float*)&sheenTint, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("clearcoat", (float*)&clearcoat, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("clearcoatGloss", (float*)&clearcoatGloss, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
Expand All @@ -2819,17 +2838,14 @@ bool VolumetricPathTracingPass::renderGuiPropertyEditorNodes(sgl::PropertyEditor

if (useIsosurfaces && surfaceBrdf == SurfaceBrdf::COOK_TORRANCE && propertyEditor.beginNode("Cook Torrance BRDF Parameters")) {
if (propertyEditor.addSliderFloat("metallic", (float*)&metallic, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("specular", (float*)&specular, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
if (propertyEditor.addSliderFloat("roughness", (float*)&roughness, 0.0, 1.0)) {
setShaderDirty();
reRender = true;
frameInfo.frameCount = 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/PathTracer/VolumetricPathTracingPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class VolumetricPathTracingPass : public sgl::vk::ComputePass {
void setIsoSurfaceColor(const glm::vec3& _isoSurfaceColor);
void setIsosurfaceType(IsosurfaceType _isosurfaceType);
void setSurfaceBrdf(SurfaceBrdf _surfaceBrdf);
void setBrdfParameter(const std::string& key, const std::string& value);
void setUseIsosurfaceTf(bool _useIsosurfaceTf);
void setNumIsosurfaceSubdivisions(int _subdivs);
[[nodiscard]] float getIsoValue() const { return isoValue; }
Expand Down
6 changes: 6 additions & 0 deletions src/PyTorch/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ TORCH_LIBRARY(vpt, m) {
m.def("vpt::set_iso_surface_color", setIsoSurfaceColor);
m.def("vpt::set_isosurface_type", setIsosurfaceType);
m.def("vpt::set_surface_brdf", setSurfaceBrdf);
m.def("vpt::set_brdf_parameter", setBrdfParameter);
m.def("vpt::set_use_isosurface_tf", setUseIsosurfaceTf);
m.def("vpt::set_num_isosurface_subdivisions", setNumIsosurfaceSubdivisions);
m.def("vpt::set_use_clip_plane", setUseClipPlane);
Expand Down Expand Up @@ -930,6 +931,11 @@ void setSurfaceBrdf(const std::string& _surfaceBrdf) {
}
}

void setBrdfParameter(const std::string& key, const std::string& value) {
auto* vptPass = vptRenderer->getVptPass();
vptPass->setBrdfParameter(key, value);
}

void setUseIsosurfaceTf(bool _useIsosurfaceTf) {
vptRenderer->getVptPass()->setUseIsosurfaceTf(_useIsosurfaceTf);
}
Expand Down
1 change: 1 addition & 0 deletions src/PyTorch/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ MODULE_OP_API void setIsoValue(double _isoValue);
MODULE_OP_API void setIsoSurfaceColor(std::vector<double> _isoSurfaceColor);
MODULE_OP_API void setIsosurfaceType(const std::string& _isosurfaceType);
MODULE_OP_API void setSurfaceBrdf(const std::string& _surfaceBrdf);
MODULE_OP_API void setBrdfParameter(const std::string& key, const std::string& value);
MODULE_OP_API void setUseIsosurfaceTf(bool _useIsosurfaceTf);
MODULE_OP_API void setNumIsosurfaceSubdivisions(int64_t _subdivs);

Expand Down

0 comments on commit f45ab5c

Please sign in to comment.