Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{"anti-aliasing", "a", R"(Select anti-aliasing method ("none", "fxaa", "ssaa" or "taa"))", "<string>", "fxaa"},
{"anti-aliasing-mode", "", R"(Select anti-aliasing method ("fxaa", "ssaa" or "taa") (deprecated))", "<string>", "fxaa"},
{"tone-mapping", "t", "Enable Tone Mapping, providing balanced coloring", "<bool>", "1"},
{"final-shader", "", "Execute the final shader at the end of the rendering pipeline", "<GLSL code>", ""} } },
{"final-shader", "", "Execute the final shader at the end of the rendering pipeline", "<GLSL code>", ""},
{"display-depth", "", "Display depth buffer as grayscale image or with a colormap if \"--scalar-coloring\" is specified", "<bool>", "1"} } },
{"Testing",
{ {"reference", "", "Reference", "<png file>", ""},
{"reference-threshold", "", "Testing threshold", "<threshold>", ""},
Expand Down
1 change: 1 addition & 0 deletions application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ static inline const std::map<std::string_view, std::string_view> LibOptionsNames
{ "ambient-occlusion", "render.effect.ambient_occlusion" },
{ "tone-mapping", "render.effect.tone_mapping" },
{ "final-shader", "render.effect.final_shader" },
{ "display-depth", "render.effect.display_depth" },
{ "textures-transform", "model.textures_transform" },
};

Expand Down
4 changes: 4 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,10 @@ f3d_test(NAME TestFinalShaderNegativeFileName DATA cow.vtp ARGS --filename --fin
f3d_test(NAME TestFinalShaderUndefined DATA cow.vtp ARGS --final-shader "undefined" REGEXP "Final shader must define a function" NO_BASELINE)
f3d_test(NAME TestFinalShaderCompilationFailure DATA cow.vtp ARGS --final-shader "vec4 pixel(vec2 uv){}" --verbose REGEXP " build the shader program" NO_BASELINE)

f3d_test(NAME TestDisplayDepth DATA dragon.vtu ARGS --display-depth)
f3d_test(NAME TestDisplayDepthColorMap DATA dragon.vtu ARGS --display-depth --scalar-coloring=True)
f3d_test(NAME TestDisplayDepthCustomColorMap DATA dragon.vtu ARGS --display-depth --scalar-coloring --colormap=0,red,1,blue)

## Interaction Tests
# Test hotkeys
f3d_test(NAME TestInteractionPostFX DATA cow.vtp INTERACTION TONE_MAPPING LONG_TIMEOUT) #PQAAAAT
Expand Down
7 changes: 7 additions & 0 deletions doc/libf3d/03-OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ Add a final shader to the output image. See [user documentation](../user/10-FINA

CLI: `--final-shader`

### `render.effect.display_depth` (_bool_, default: `false`)

Display the depth buffer as a grayscale image or with a colormap if `model.scivis.enable` is specified.
Only opaque objects are displayed, translucent and volumetric objects are ignored.

CLI: `--display-depth`

### `render.line_width` (_double_, optional)

Set the _width_ of lines when showing edges. Model-specified by default.
Expand Down
5 changes: 5 additions & 0 deletions doc/user/03-OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ Enable generic filmic _Tone Mapping Pass_. This technique is used to map colors

Add a final shader to the output image. See the [dedicated documentation](10-FINAL_SHADER.md) for more details.

### `--display-depth` (_bool_, default: `false`)

Display the depth buffer as a grayscale image or with a colormap if `--scalar-coloring` is specified.
Only opaque objects are displayed, translucent and volumetric objects are ignored.

## Testing options

### `--ref=<png file>` (_string_)
Expand Down
4 changes: 4 additions & 0 deletions library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
},
"final_shader": {
"type": "string"
},
"display_depth": {
"type": "bool",
"default_value": "false"
}
},
"hdri": {
Expand Down
2 changes: 2 additions & 0 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ void window_impl::UpdateDynamicOptions()
renderer->SetUseSSAOPass(opt.render.effect.ambient_occlusion);
renderer->SetAntiAliasingMode(aaMode);
renderer->SetUseToneMappingPass(opt.render.effect.tone_mapping);
renderer->SetDisplayDepth(opt.render.effect.display_depth);
renderer->SetDisplayDepthScalarColoring(opt.model.scivis.enable);
renderer->SetBlendingMode(blendMode);
renderer->SetBackfaceType(opt.render.backface_type);
renderer->SetFinalShader(opt.render.effect.final_shader);
Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestDisplayDepth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestDisplayDepthColorMap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestDisplayDepthCustomColorMap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions vtkext/private/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ set(classes
vtkF3DUIActor
vtkF3DUserRenderPass
vtkF3DTAAResolvePass
vtkF3DDisplayDepthRenderPass
)

if (F3D_MODULE_UI)
Expand Down
190 changes: 190 additions & 0 deletions vtkext/private/module/vtkF3DDisplayDepthRenderPass.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#include "vtkF3DDisplayDepthRenderPass.h"

#include <vtkDiscretizableColorTransferFunction.h>
#include <vtkObjectFactory.h>
#include <vtkOpenGLError.h>
#include <vtkOpenGLFramebufferObject.h>
#include <vtkOpenGLQuadHelper.h>
#include <vtkOpenGLRenderUtilities.h>
#include <vtkOpenGLRenderWindow.h>
#include <vtkOpenGLRenderer.h>
#include <vtkOpenGLShaderCache.h>
#include <vtkOpenGLState.h>
#include <vtkRenderState.h>
#include <vtkRenderer.h>
#include <vtkShaderProgram.h>
#include <vtkTextureObject.h>

vtkStandardNewMacro(vtkF3DDisplayDepthRenderPass);

//------------------------------------------------------------------------------
void vtkF3DDisplayDepthRenderPass::Render(const vtkRenderState* state)
{
vtkOpenGLClearErrorMacro();
this->NumberOfRenderedProps = 0;

vtkRenderer* renderer = state->GetRenderer();
vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(renderer->GetRenderWindow());
vtkOpenGLState* ostate = renWin->GetState();

vtkOpenGLState::ScopedglEnableDisable bsaver(ostate, GL_BLEND);
vtkOpenGLState::ScopedglEnableDisable dsaver(ostate, GL_DEPTH_TEST);

assert(this->DelegatePass != nullptr);

int pos[2];
int size[2];
renderer->GetTiledSizeAndOrigin(&size[0], &size[1], &pos[0], &pos[1]);

InitializeResources(renWin, size[0], size[1]);

// render to color and depth texture
renWin->GetState()->PushFramebufferBindings();
this->RenderDelegate(state, size[0], size[1], size[0], size[1], this->FrameBufferObject,
this->ColorTexture, this->DepthTexture);
renWin->GetState()->PopFramebufferBindings();

// depth displaying pass
if (!this->QuadHelper)
{
std::string depthDisplayingFS =
vtkOpenGLRenderUtilities::GetFullScreenQuadFragmentShaderTemplate();
vtkShaderProgram::Substitute(depthDisplayingFS, "//VTK::FSQ::Decl",
"uniform sampler2D texDepth;\n"
"uniform bool useColorMap;\n"
"uniform sampler1D colorMapTexture;\n"
"//VTK::FSQ::Decl");

vtkShaderProgram::Substitute(depthDisplayingFS, "//VTK::FSQ::Impl",
"float depth = texture(texDepth, texCoord).r;\n"
"if (useColorMap)\n"
"{\n"
" vec4 colorMapped = texture(colorMapTexture, depth);\n"
" gl_FragData[0] = vec4(colorMapped.rgb, 1.0);\n"
" return;\n"
"}\n"
"gl_FragData[0] = vec4(depth, depth, depth, 1.0);\n"
"//VTK::FSQ::Impl");
this->QuadHelper =
std::make_shared<vtkOpenGLQuadHelper>(renWin, nullptr, depthDisplayingFS.c_str(), nullptr);
this->QuadHelper->ShaderChangeValue = this->GetMTime();
}
else
{
renWin->GetShaderCache()->ReadyShaderProgram(this->QuadHelper->Program);
}

assert(this->QuadHelper->Program && this->QuadHelper->Program->GetCompiled());

this->ColorTexture->Activate();
this->DepthTexture->Activate();
this->ColorMapTexture->Activate();

this->QuadHelper->Program->SetUniformi("texDepth", this->DepthTexture->GetTextureUnit());
this->QuadHelper->Program->SetUniformi("useColorMap", this->ColorMap != nullptr ? 1 : 0);
this->QuadHelper->Program->SetUniformi(
"colorMapTexture", this->ColorMapTexture->GetTextureUnit());

ostate->vtkglEnable(GL_DEPTH_TEST);
ostate->vtkglDepthFunc(GL_LEQUAL);
ostate->vtkglClear(GL_DEPTH_BUFFER_BIT);

this->QuadHelper->Render();

this->ColorTexture->Deactivate();
this->DepthTexture->Deactivate();
this->ColorMapTexture->Deactivate();
vtkOpenGLCheckErrorMacro("failed after Render");
}

//------------------------------------------------------------------------------
void vtkF3DDisplayDepthRenderPass::InitializeResources(vtkOpenGLRenderWindow* renWin, int w, int h)
{
if (this->DepthTexture == nullptr)
{
this->DepthTexture = vtkSmartPointer<vtkTextureObject>::New();
this->DepthTexture->SetContext(renWin);
this->DepthTexture->AllocateDepth(w, h, vtkTextureObject::Float32);
}
this->DepthTexture->Resize(w, h);

if (this->ColorTexture == nullptr)
{
this->ColorTexture = vtkSmartPointer<vtkTextureObject>::New();
this->ColorTexture->SetContext(renWin);
this->ColorTexture->SetFormat(GL_RGBA);
this->ColorTexture->SetInternalFormat(GL_RGBA8);
this->ColorTexture->SetDataType(GL_UNSIGNED_BYTE);
this->ColorTexture->SetMinificationFilter(vtkTextureObject::Linear);
this->ColorTexture->SetMagnificationFilter(vtkTextureObject::Linear);
this->ColorTexture->SetWrapS(vtkTextureObject::ClampToEdge);
this->ColorTexture->SetWrapT(vtkTextureObject::ClampToEdge);
this->ColorTexture->Allocate2D(w, h, 4, VTK_UNSIGNED_CHAR);
}
this->ColorTexture->Resize(w, h);

if (this->ColorMapTexture == nullptr)
{
this->ColorMapTexture = vtkSmartPointer<vtkTextureObject>::New();
this->ColorMapTexture->SetContext(renWin);
this->ColorMapTexture->Allocate1D(256, 3, VTK_FLOAT);
this->ColorMapTexture->SetWrapS(vtkTextureObject::ClampToEdge);
this->ColorMapTexture->SetWrapT(vtkTextureObject::ClampToEdge);
this->ColorMapTexture->SetMinificationFilter(vtkTextureObject::Linear);
this->ColorMapTexture->SetMagnificationFilter(vtkTextureObject::Linear);

this->ColorMapTexture->SetFormat(GL_RGB);
this->ColorMapTexture->SetInternalFormat(GL_RGB16F);
this->ColorMapTexture->SetDataType(GL_FLOAT);

if (this->ColorMap && this->ColorMapBuildTime.GetMTime() < this->ColorMap->GetMTime())
{
constexpr int tableSize = 256;
this->ColorMap->SetNumberOfValues(tableSize);
this->ColorMap->Build();
double range[2];
this->ColorMap->GetRange(range);

std::vector<float> table(tableSize * 3);
this->ColorMap->GetTable(range[0], range[1], tableSize, table.data());

this->ColorMapTexture->Create1DFromRaw(tableSize, 3, VTK_FLOAT, table.data());
this->ColorMapBuildTime.Modified();
}
}

if (this->FrameBufferObject == nullptr)
{
this->FrameBufferObject = vtkSmartPointer<vtkOpenGLFramebufferObject>::New();
this->FrameBufferObject->SetContext(renWin);
}
}

///------------------------------------------------------------------------------
void vtkF3DDisplayDepthRenderPass::ReleaseGraphicsResources(vtkWindow* window)
{
this->Superclass::ReleaseGraphicsResources(window);

if (this->FrameBufferObject)
{
this->FrameBufferObject->ReleaseGraphicsResources(window);
}
if (this->ColorTexture)
{
this->ColorTexture->ReleaseGraphicsResources(window);
}
if (this->DepthTexture)
{
this->DepthTexture->ReleaseGraphicsResources(window);
}
if (this->ColorMapTexture)
{
this->ColorMapTexture->ReleaseGraphicsResources(window);
}
}

///------------------------------------------------------------------------------
void vtkF3DDisplayDepthRenderPass::SetColorMap(vtkDiscretizableColorTransferFunction* colorMap)
{
this->ColorMap = colorMap;
}
41 changes: 41 additions & 0 deletions vtkext/private/module/vtkF3DDisplayDepthRenderPass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef vtkF3DDepthRenderPass_h
#define vtkF3DDepthRenderPass_h

#include "vtkImageProcessingPass.h"

#include <vtkDepthImageProcessingPass.h>
#include <vtkSmartPointer.h>

#include <memory>

class vtkOpenGLFramebufferObject;
class vtkOpenGLQuadHelper;
class vtkTextureObject;
class vtkDiscretizableColorTransferFunction;

class vtkF3DDisplayDepthRenderPass : public vtkDepthImageProcessingPass
{
public:
static vtkF3DDisplayDepthRenderPass* New();
vtkTypeMacro(vtkF3DDisplayDepthRenderPass, vtkDepthImageProcessingPass);
void Render(const vtkRenderState* state) override;
void ReleaseGraphicsResources(vtkWindow* window) override;

void SetColorMap(vtkDiscretizableColorTransferFunction* colorMap);

private:
vtkF3DDisplayDepthRenderPass() = default;
~vtkF3DDisplayDepthRenderPass() override = default;

void InitializeResources(vtkOpenGLRenderWindow* renWin, int w, int h);

vtkSmartPointer<vtkDiscretizableColorTransferFunction> ColorMap;
vtkTimeStamp ColorMapBuildTime;

vtkSmartPointer<vtkTextureObject> ColorTexture;
vtkSmartPointer<vtkTextureObject> DepthTexture;
vtkSmartPointer<vtkTextureObject> ColorMapTexture;
vtkSmartPointer<vtkOpenGLFramebufferObject> FrameBufferObject;
std::shared_ptr<vtkOpenGLQuadHelper> QuadHelper;
};
#endif
Loading
Loading