Skip to content

Commit ab407a1

Browse files
authored
Enable splats on Android/Wasm (f3d-app#2646)
1 parent 79696c1 commit ab407a1

5 files changed

Lines changed: 49 additions & 25 deletions

File tree

vtkext/private/module/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ if(F3D_MODULE_UI)
3333
list(APPEND private_headers ${CMAKE_CURRENT_BINARY_DIR}/F3DDefaultLogo.h)
3434
endif()
3535

36-
set(shader_files glsl/vtkF3DComputeDepthCS.glsl glsl/vtkF3DRandomFS.glsl)
36+
set(shader_files glsl/vtkF3DRandomFS.glsl)
37+
38+
if (NOT ANDROID AND NOT EMSCRIPTEN)
39+
list(APPEND shader_files glsl/vtkF3DComputeDepthCS.glsl)
40+
endif()
3741

3842
if(F3D_MODULE_UI)
3943
list(APPEND shader_files glsl/vtkF3DImguiFS.glsl glsl/vtkF3DImguiVS.glsl)
@@ -84,7 +88,7 @@ if (F3D_MODULE_UI)
8488
endif ()
8589

8690
# Needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10675
87-
if(NOT ANDROID AND NOT EMSCRIPTEN AND VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240203)
91+
if(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240203)
8892
set(classes ${classes} vtkF3DPointSplatMapper)
8993
endif()
9094

vtkext/private/module/vtkF3DObjectFactory.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
#include "vtkF3DPolyDataMapper.h"
66

7-
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && \
8-
VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240203)
7+
#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240203)
98
#include <vtkF3DPointSplatMapper.h>
109
#endif
1110

@@ -39,8 +38,7 @@ vtkF3DObjectFactory::vtkF3DObjectFactory()
3938
this->RegisterOverride("vtkPolyDataMapper", "vtkF3DPolyDataMapper",
4039
"vtkPolyDataMapper override for F3D", 1, ::Factory<vtkF3DPolyDataMapper>);
4140

42-
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) && \
43-
VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240203)
41+
#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240203)
4442
this->RegisterOverride("vtkPointGaussianMapper", "vtkF3DPointSplatMapper",
4543
"vtkPointGaussianMapper override for F3D", 1, ::Factory<vtkF3DPointSplatMapper>);
4644
#endif

vtkext/private/module/vtkF3DPointSplatMapper.cxx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "vtkF3DPointSplatMapper.h"
22

3+
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
34
#include "vtkF3DBitonicSort.h"
45
#include "vtkF3DComputeDepthCS.h"
6+
#endif
57
#include "vtkF3DRenderer.h"
68

79
#include <vtkCamera.h>
@@ -62,6 +64,7 @@ class vtkF3DSplatMapperHelper : public vtkOpenGLPointGaussianMapperHelper
6264
vtkOpenGLHelper& cellBO, vtkRenderer* ren, vtkActor* actor) override;
6365

6466
private:
67+
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
6568
void SortSplats(vtkRenderer* ren);
6669

6770
vtkNew<vtkShader> DepthComputeShader;
@@ -72,6 +75,7 @@ class vtkF3DSplatMapperHelper : public vtkOpenGLPointGaussianMapperHelper
7275

7376
double DirectionThreshold = 0.999;
7477
double LastDirection[3] = { 0.0, 0.0, 0.0 };
78+
#endif
7579

7680
int MaxTextureSize = 0;
7781
vtkNew<vtkTextureObject> SphericalHarmonicsTexture;
@@ -84,11 +88,13 @@ vtkStandardNewMacro(vtkF3DSplatMapperHelper);
8488
//----------------------------------------------------------------------------
8589
vtkF3DSplatMapperHelper::vtkF3DSplatMapperHelper()
8690
{
91+
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
8792
this->DepthComputeShader->SetType(vtkShader::Compute);
8893
this->DepthComputeShader->SetSource(vtkF3DComputeDepthCS);
8994
this->DepthProgram->SetComputeShader(this->DepthComputeShader);
9095

9196
this->Sorter->Initialize(512, VTK_FLOAT, VTK_UNSIGNED_INT);
97+
#endif
9298
}
9399

94100
//----------------------------------------------------------------------------
@@ -105,9 +111,11 @@ void vtkF3DSplatMapperHelper::BuildBufferObjects(vtkRenderer* ren, vtkActor* act
105111

106112
vtkOpenGLPointGaussianMapperHelper::BuildBufferObjects(ren, act);
107113

114+
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
108115
// allocate a buffer of depths used for sorting splats
109116
this->DepthBuffer->Allocate(splatCount * sizeof(float), vtkOpenGLBufferObject::ArrayBuffer,
110117
vtkOpenGLBufferObject::DynamicCopy);
118+
#endif
111119

112120
this->SphericalHarmonicsDegree = 0;
113121

@@ -269,6 +277,7 @@ void vtkF3DSplatMapperHelper::SetCameraShaderParameters(
269277
this->Superclass::SetCameraShaderParameters(cellBO, ren, actor);
270278
}
271279

280+
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
272281
//----------------------------------------------------------------------------
273282
void vtkF3DSplatMapperHelper::SortSplats(vtkRenderer* ren)
274283
{
@@ -319,18 +328,20 @@ void vtkF3DSplatMapperHelper::SortSplats(vtkRenderer* ren)
319328
}
320329
}
321330
}
331+
#endif
322332

323333
//----------------------------------------------------------------------------
324334
void vtkF3DSplatMapperHelper::RenderPieceDraw(vtkRenderer* ren, vtkActor* actor)
325335
{
336+
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
326337
const vtkF3DRenderer* renderer = vtkF3DRenderer::SafeDownCast(ren);
327338

328339
if (renderer->GetBlendingMode() == vtkF3DRenderer::BlendingMode::SORT &&
329-
vtkShader::IsComputeShaderSupported() && actor->GetForceTranslucent())
340+
vtkShader::IsComputeShaderSupported() && actor->HasTranslucentPolygonalGeometry())
330341
{
331342
this->SortSplats(ren);
332343
}
333-
344+
#endif
334345
vtkOpenGLPointGaussianMapperHelper::RenderPieceDraw(ren, actor);
335346
}
336347

@@ -342,16 +353,19 @@ void vtkF3DSplatMapperHelper::ReplaceShaderColor(
342353
{
343354
std::string VSSource = shaders[vtkShader::Vertex]->GetSource();
344355

345-
vtkShaderProgram::Substitute(VSSource, "//VTK::Color::Dec",
346-
"//VTK::Color::Dec\n\n"
347-
"uniform sampler2DArray sphericalHarmonics;\n"
348-
"uniform vec3 cameraDirection;\n"
349-
"vec3 decode(ivec3 texelIndex)\n"
350-
"{\n"
351-
" vec3 texel = texelFetch(sphericalHarmonics, texelIndex, 0).rgb;\n"
352-
" return texel * 2.0 - 1.0;\n"
353-
"}\n\n",
354-
false);
356+
if (this->SphericalHarmonicsDegree > 0)
357+
{
358+
vtkShaderProgram::Substitute(VSSource, "//VTK::Color::Dec",
359+
"//VTK::Color::Dec\n\n"
360+
"uniform sampler2DArray sphericalHarmonics;\n"
361+
"uniform vec3 cameraDirection;\n"
362+
"vec3 decode(ivec3 texelIndex)\n"
363+
"{\n"
364+
" vec3 texel = texelFetch(sphericalHarmonics, texelIndex, 0).rgb;\n"
365+
" return texel * 2.0 - 1.0;\n"
366+
"}\n\n",
367+
false);
368+
}
355369

356370
std::stringstream shStr;
357371
shStr << "//VTK::Color::Impl\n";

vtkext/private/module/vtkF3DPolyDataMapper.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/**
22
* @class vtkF3DPolyDataMapper
3-
* @brief Custom surface mapper used to include skinning and morphing for glTF format
3+
* @brief Custom surface mapper used to include F3D features
44
*
5+
* This mapper is used to add many F3D custom features:
6+
* - skinning and morphing capabilities
7+
* - support for MatCap rendering
8+
* - support for TAA jittering
59
*/
610

711
#ifndef vtkF3DPolyDataMapper_h

vtkext/public/module/CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
set(shader_files
2-
glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl
3-
glsl/vtkF3DBitonicSortGlobalFlipCS.glsl
4-
glsl/vtkF3DBitonicSortLocalDisperseCS.glsl
5-
glsl/vtkF3DBitonicSortLocalSortCS.glsl
6-
glsl/vtkF3DBitonicSortFunctions.glsl)
1+
set(shader_files "")
2+
3+
if(NOT ANDROID AND NOT EMSCRIPTEN)
4+
set(shader_files ${shader_files}
5+
glsl/vtkF3DBitonicSortGlobalDisperseCS.glsl
6+
glsl/vtkF3DBitonicSortGlobalFlipCS.glsl
7+
glsl/vtkF3DBitonicSortLocalDisperseCS.glsl
8+
glsl/vtkF3DBitonicSortLocalSortCS.glsl
9+
glsl/vtkF3DBitonicSortFunctions.glsl)
10+
endif()
711

812
foreach(file IN LISTS shader_files)
913
vtk_encode_string(

0 commit comments

Comments
 (0)