Skip to content

Commit 3b60706

Browse files
authored
Merge branch 'master' into volumeShadowExample
2 parents a03d515 + 24a8d15 commit 3b60706

File tree

3 files changed

+344
-54
lines changed

3 files changed

+344
-54
lines changed

Sources/Rendering/Core/VolumeMapper/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ function vtkVolumeMapper(publicAPI, model) {
7272
publicAPI.setFilterModeToRaw = () => {
7373
publicAPI.setFilterMode(FilterMode.RAW);
7474
};
75+
76+
publicAPI.setGlobalIlluminationReach = (gl) => {
77+
model.globalIlluminationReach = vtkMath.clampValue(gl, 0.0, 1.0);
78+
publicAPI.modified();
79+
};
80+
81+
publicAPI.setVolumetricScatteringBlending = (vsb) => {
82+
model.volumetricScatteringBlending = vtkMath.clampValue(vsb, 0.0, 1.0);
83+
84+
publicAPI.modified();
85+
};
86+
87+
publicAPI.setVlumeShadowSamplingDistFactor = (vsdf) => {
88+
model.volumeShadowSamplingDistFactor = vsdf >= 1.0 ? vsdf : 1.0;
89+
publicAPI.modified();
90+
};
91+
92+
publicAPI.setAnisotropy = (at) => {
93+
model.anisotropy = vtkMath.clampValue(at, -0.99, 0.99);
94+
publicAPI.modified();
95+
};
7596
}
7697

7798
// ----------------------------------------------------------------------------
@@ -90,6 +111,11 @@ const DEFAULT_VALUES = {
90111
filterMode: FilterMode.OFF, // ignored by WebGL so no behavior change
91112
preferSizeOverAccuracy: false, // Whether to use halfFloat representation of float, when it is inaccurate
92113
computeNormalFromOpacity: false,
114+
// volume shadow parameters
115+
globalIlluminationReach: 0.0,
116+
volumetricScatteringBlending: 0.0,
117+
volumeShadowSamplingDistFactor: 5.0,
118+
anisotropy: 0.0,
93119
};
94120

95121
// ----------------------------------------------------------------------------
@@ -108,6 +134,10 @@ export function extend(publicAPI, model, initialValues = {}) {
108134
'filterMode',
109135
'preferSizeOverAccuracy',
110136
'computeNormalFromOpacity',
137+
'globalIlluminationReach',
138+
'volumetricScatteringBlending',
139+
'volumeShadowSamplingDistFactor',
140+
'anisotropy',
111141
]);
112142

113143
macro.setGetArray(publicAPI, model, ['ipScalarRange'], 2);

Sources/Rendering/OpenGL/VolumeMapper/index.js

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
191191
`#define vtkLightComplexity ${model.lastLightComplexity}`
192192
).result;
193193

194+
// set shadow blending flag
195+
if (model.lastLightComplexity > 0) {
196+
if (model.renderable.getVolumetricScatteringBlending() > 0.0) {
197+
FSSource = vtkShaderProgram.substitute(
198+
FSSource,
199+
'//VTK::VolumeShadowOn',
200+
`#define VolumeShadowOn`
201+
).result;
202+
}
203+
if (model.renderable.getVolumetricScatteringBlending() < 1.0) {
204+
FSSource = vtkShaderProgram.substitute(
205+
FSSource,
206+
'//VTK::SurfaceShadowOn',
207+
`#define SurfaceShadowOn`
208+
).result;
209+
}
210+
}
211+
194212
// if using gradient opacity define that
195213
model.gopacity = actor.getProperty().getUseGradientOpacity(0);
196214
for (let nc = 1; iComps && !model.gopacity && nc < numComp; ++nc) {
@@ -290,6 +308,22 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
290308
false
291309
).result;
292310
}
311+
312+
if (model.renderable.getVolumetricScatteringBlending() > 0.0) {
313+
FSSource = vtkShaderProgram.substitute(
314+
FSSource,
315+
'//VTK::VolumeShadow::Dec',
316+
[
317+
`uniform float volumetricScatteringBlending;`,
318+
`uniform float giReach;`,
319+
`uniform float volumeShadowSamplingDistFactor;`,
320+
`uniform float anisotropy;`,
321+
`uniform float anisotropy2;`,
322+
],
323+
false
324+
).result;
325+
}
326+
293327
shaders.Fragment = FSSource;
294328
};
295329

@@ -738,26 +772,26 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
738772
// specify the planes in view coordinates
739773
program.setUniform3f(`vPlaneNormal${i}`, normal[0], normal[1], normal[2]);
740774
program.setUniformf(`vPlaneDistance${i}`, dist);
775+
}
741776

742-
if (actor.getProperty().getUseLabelOutline()) {
743-
const image = model.currentInput;
744-
const worldToIndex = image.getWorldToIndex();
777+
if (actor.getProperty().getUseLabelOutline()) {
778+
const image = model.currentInput;
779+
const worldToIndex = image.getWorldToIndex();
745780

746-
program.setUniformMatrix('vWCtoIDX', worldToIndex);
781+
program.setUniformMatrix('vWCtoIDX', worldToIndex);
747782

748-
// Get the projection coordinate to world coordinate transformation matrix.
749-
mat4.invert(model.projectionToWorld, keyMats.wcpc);
750-
program.setUniformMatrix('PCWCMatrix', model.projectionToWorld);
783+
// Get the projection coordinate to world coordinate transformation matrix.
784+
mat4.invert(model.projectionToWorld, keyMats.wcpc);
785+
program.setUniformMatrix('PCWCMatrix', model.projectionToWorld);
751786

752-
const size = publicAPI.getRenderTargetSize();
787+
const size = publicAPI.getRenderTargetSize();
753788

754-
program.setUniformf('vpWidth', size[0]);
755-
program.setUniformf('vpHeight', size[1]);
789+
program.setUniformf('vpWidth', size[0]);
790+
program.setUniformf('vpHeight', size[1]);
756791

757-
const offset = publicAPI.getRenderTargetOffset();
758-
program.setUniformf('vpOffsetX', offset[0] / size[0]);
759-
program.setUniformf('vpOffsetY', offset[1] / size[1]);
760-
}
792+
const offset = publicAPI.getRenderTargetOffset();
793+
program.setUniformf('vpOffsetX', offset[0] / size[0]);
794+
program.setUniformf('vpOffsetY', offset[1] / size[1]);
761795
}
762796

763797
mat4.invert(model.projectionToView, keyMats.vcpc);
@@ -830,6 +864,25 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
830864
program.setUniformfv('lightExponent', lightExponent);
831865
program.setUniformiv('lightPositional', lightPositional);
832866
}
867+
if (model.renderable.getVolumetricScatteringBlending() > 0.0) {
868+
program.setUniformf(
869+
'giReach',
870+
model.renderable.getGlobalIlluminationReach()
871+
);
872+
program.setUniformf(
873+
'volumetricScatteringBlending',
874+
model.renderable.getVolumetricScatteringBlending()
875+
);
876+
program.setUniformf(
877+
'volumeShadowSamplingDistFactor',
878+
model.renderable.getVolumeShadowSamplingDistFactor()
879+
);
880+
program.setUniformf('anisotropy', model.renderable.getAnisotropy());
881+
program.setUniformf(
882+
'anisotropy2',
883+
model.renderable.getAnisotropy() ** 2.0
884+
);
885+
}
833886
};
834887

835888
publicAPI.setPropertyShaderParameters = (cellBO, ren, actor) => {

0 commit comments

Comments
 (0)