Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(multiple scatter): support experimental multiple scatter option #2490

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions Sources/Rendering/Core/VolumeMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ const DEFAULT_VALUES = {
globalIlluminationReach: 0.0,
volumeShadowSamplingDistFactor: 5.0,
anisotropy: 0.0,
// multiple scatter parameters
sphericalSampleNumber: 5.0,
multipleScatterSamplingDistFactor: 1.0,
multipleScatter: false,
};

// ----------------------------------------------------------------------------
Expand All @@ -138,6 +142,9 @@ export function extend(publicAPI, model, initialValues = {}) {
'globalIlluminationReach',
'volumeShadowSamplingDistFactor',
'anisotropy',
'multipleScatterSamplingDistFactor',
'sphericalSampleNumber',
'multipleScatter',
]);

macro.setGetArray(publicAPI, model, ['ipScalarRange'], 2);
Expand Down
67 changes: 51 additions & 16 deletions Sources/Rendering/OpenGL/VolumeMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,27 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {

// set shadow blending flag
if (model.lastLightComplexity > 0) {
if (model.renderable.getVolumetricScatteringBlending() > 0.0) {
if (model.renderable.getMultipleScatter()) {
FSSource = vtkShaderProgram.substitute(
FSSource,
'//VTK::VolumeShadowOn',
`#define VolumeShadowOn`
).result;
}
if (model.renderable.getVolumetricScatteringBlending() < 1.0) {
FSSource = vtkShaderProgram.substitute(
FSSource,
'//VTK::SurfaceShadowOn',
`#define SurfaceShadowOn`
'//VTK::MultipleScatterOn',
`#define MultipleScatterOn`
).result;
} else {
if (model.renderable.getVolumetricScatteringBlending() > 0.0) {
FSSource = vtkShaderProgram.substitute(
FSSource,
'//VTK::VolumeShadowOn',
`#define VolumeShadowOn`
).result;
}
if (model.renderable.getVolumetricScatteringBlending() < 1.0) {
FSSource = vtkShaderProgram.substitute(
FSSource,
'//VTK::SurfaceShadowOn',
`#define SurfaceShadowOn`
).result;
}
}
}

Expand Down Expand Up @@ -309,7 +317,19 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
).result;
}

if (model.renderable.getVolumetricScatteringBlending() > 0.0) {
if (model.renderable.getMultipleScatter()) {
FSSource = vtkShaderProgram.substitute(
FSSource,
'//VTK::VolumeShadow::Dec',
[
`uniform float multipleScatterSamplingDistFactor;`,
`uniform float sphericalSampleNumber;`,
`uniform float anisotropy;`,
`uniform float anisotropy2;`,
],
false
).result;
} else if (model.renderable.getVolumetricScatteringBlending() > 0.0) {
FSSource = vtkShaderProgram.substitute(
FSSource,
'//VTK::VolumeShadow::Dec',
Expand Down Expand Up @@ -864,7 +884,22 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
program.setUniformfv('lightExponent', lightExponent);
program.setUniformiv('lightPositional', lightPositional);
}
if (model.renderable.getVolumetricScatteringBlending() > 0.0) {

if (model.renderable.getMultipleScatter()) {
program.setUniformf(
'multipleScatterSamplingDistFactor',
model.renderable.getMultipleScatterSamplingDistFactor()
);
program.setUniformf(
'sphericalSampleNumber',
model.renderable.getSphericalSampleNumber()
);
program.setUniformf('anisotropy', model.renderable.getAnisotropy());
program.setUniformf(
'anisotropy2',
model.renderable.getAnisotropy() ** 2.0
);
} else if (model.renderable.getVolumetricScatteringBlending() > 0.0) {
program.setUniformf(
'giReach',
model.renderable.getGlobalIlluminationReach()
Expand Down Expand Up @@ -1330,15 +1365,15 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
const vprop = actor.getProperty();

if (!model.jitterTexture.getHandle()) {
const oTable = new Uint8Array(32 * 32);
for (let i = 0; i < 32 * 32; ++i) {
const oTable = new Uint8Array(512 * 512);
for (let i = 0; i < 512 * 512; ++i) {
oTable[i] = 255.0 * Math.random();
}
model.jitterTexture.setMinificationFilter(Filter.LINEAR);
model.jitterTexture.setMagnificationFilter(Filter.LINEAR);
model.jitterTexture.create2DFromRaw(
32,
32,
512,
512,
1,
VtkDataTypes.UNSIGNED_CHAR,
oTable
Expand Down
Loading