Commit 0038dd88 authored by Aashish Chaudhary's avatar Aashish Chaudhary

Added API to turn on/off jittering

(cherry picked from commit e509a788275dbf99324d721b0998f6a8e61a91e9)
parent 1f59f0e7
Pipeline #6134 passed with stage
......@@ -45,6 +45,7 @@ vtkGPUVolumeRayCastMapper::vtkGPUVolumeRayCastMapper()
this->MinimumImageSampleDistance = 1.0;
this->MaximumImageSampleDistance = 10.0;
this->RenderToImage = 0;
this->UseJittering = 1;
this->SampleDistance = 1.0;
this->SmallVolumeRender = 0;
this->BigTimeToDraw = 0.0;
......
......@@ -46,6 +46,14 @@ public:
vtkGetMacro( AutoAdjustSampleDistances, int );
vtkBooleanMacro( AutoAdjustSampleDistances, int );
// Description:
// If UseJittering is on, each ray traversal direction will be
// perturbed slightly using a noise-texture to get rid of wood-grain
// effect.
vtkSetClampMacro( UseJittering, int, 0, 1 );
vtkGetMacro( UseJittering, int );
vtkBooleanMacro( UseJittering, int );
// Description:
// Set/Get the distance between samples used for rendering
// when AutoAdjustSampleDistances is off, or when this mapper
......@@ -276,6 +284,9 @@ protected:
// Render to texture mode flag
int RenderToImage;
// Enable / disable stochasting jittering
int UseJittering;
// The distance between sample points along the ray
float SampleDistance;
......
......@@ -3165,6 +3165,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren,
1.0 / this->Impl->WindowSize[1], fvalue2);
this->Impl->ShaderProgram->SetUniform2fv("in_inverseWindowSize", 1, &fvalue2);
this->Impl->ShaderProgram->SetUniformi("in_useJittering", this->GetUseJittering());
this->Impl->ShaderProgram->SetUniformi("in_cellFlag", this->CellFlag);
// Updating cropping if enabled
......
......@@ -180,7 +180,10 @@ namespace vtkvolume
\nuniform vec3 in_ambient;\
\nuniform vec3 in_specular;\
\nuniform float in_shininess;\
\n\
\n// Others\
\nuniform bool in_cellFlag;\
\n uniform bool in_useJittering;\
");
if (hasGradientOpacity || lightingComplexity > 0)
......@@ -279,7 +282,15 @@ namespace vtkvolume
\n g_dirStep = (in_inverseTextureDatasetMatrix *\
\n vec4(rayDir, 0.0)).xyz * in_sampleDistance;\
\n\
\n g_dataPos += g_dirStep;\
\n float jitterValue = (texture2D(in_noiseSampler, g_dataPos.xy).x);\
\n if (in_useJittering)\
\n {\
\n g_dataPos += g_dirStep * jitterValue;\
\n }\
\n else\
\n {\
\n g_dataPos += g_dirStep;\
\n }\
\n\
\n // Flag to deternmine if voxel should be considered for the rendering\
\n bool l_skip = false;");
......@@ -1572,7 +1583,15 @@ namespace vtkvolume
\n in_textureDatasetMatrix;\
\n for (int i = 0; i < clippingPlanesSize; i = i + 6)\
\n {\
\n objDataPos = textureToObjMat * vec4(g_dataPos - g_dirStep, 1.0);\
\n if (in_useJittering)\
\n {\
\n objDataPos = textureToObjMat * vec4(g_dataPos - g_dirStep\
\n - jitterValue, 1.0);\
\n }\
\n else\
\n {\
\n objDataPos = textureToObjMat * vec4(g_dataPos - g_dirStep, 1.0);\
\n }\
\n if (objDataPos.w != 0.0)\
\n {\
\n objDataPos = objDataPos/objDataPos.w; objDataPos.w = 1.0;\
......@@ -1599,7 +1618,14 @@ namespace vtkvolume
\n {\
\n newObjDataPos /= newObjDataPos.w;\
\n }\
\n if (in_useJittering)\
\n {\
\n g_dataPos = newObjDataPos.xyz + g_dirStep * jitterValue;\
\n }\
\n else\
\n {\
\n g_dataPos = newObjDataPos.xyz + g_dirStep;\
\n }\
\n bool stop = dot(sign(g_dataPos - l_texMin), sign(l_texMax - g_dataPos))\
\n < 3.0;\
\n if (stop)\
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment