Skip to content

Commit

Permalink
Allow transparent segmentations
Browse files Browse the repository at this point in the history
  • Loading branch information
mlavik1 committed Oct 5, 2024
1 parent 04d0c0e commit 602bddb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
14 changes: 8 additions & 6 deletions Assets/Scripts/VolumeObject/VolumeRenderedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,19 @@ public void UpdateSegmentationLabels()
float minDataValue = secondaryDataset.GetMinDataValue();
float maxDataValue = secondaryDataset.GetMaxDataValue();
secondaryTransferFunction.alphaControlPoints.Add(new TFAlphaControlPoint(0.0f, 0.0f));
secondaryTransferFunction.alphaControlPoints.Add(new TFAlphaControlPoint(1.0f, 1.0f));
for (int i = 0; i < segmentationLabels.Count; i++)
{
SegmentationLabel segmentationLabel = segmentationLabels[i];
float t = segmentationLabel.id / maxDataValue;
float segmAlpha = segmentationLabel.colour.a;
secondaryTransferFunction.colourControlPoints.Add(new TFColourControlPoint(t, segmentationLabel.colour));
if (i == 0)
{
secondaryTransferFunction.alphaControlPoints.Add(new TFAlphaControlPoint(t - 0.01f, 0.0f));
secondaryTransferFunction.alphaControlPoints.Add(new TFAlphaControlPoint(t, 1.0f));
}
if (t > 0.0f)
secondaryTransferFunction.alphaControlPoints.Add(new TFAlphaControlPoint(Mathf.Max(t - 0.001f, 0.0f), segmAlpha));
secondaryTransferFunction.alphaControlPoints.Add(new TFAlphaControlPoint(t, segmAlpha));
if (i == segmentationLabels.Count - 1)
secondaryTransferFunction.alphaControlPoints.Add(new TFAlphaControlPoint(1.0f, segmAlpha));
else
secondaryTransferFunction.alphaControlPoints.Add(new TFAlphaControlPoint(t + 0.001f, segmAlpha));
}
secondaryTransferFunction.GenerateTexture();
secondaryTransferFunction.GetTexture().filterMode = FilterMode.Point;
Expand Down
18 changes: 11 additions & 7 deletions Assets/Shaders/DirectVolumeRenderingShader.shader
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,17 @@
const float secondaryDensity = getSecondaryDensity(currPos);
if (secondaryDensity > 0.0)
{
col = getSecondaryTF1DColour(secondaryDensity);
float3 gradient = getGradient(currPos);
float gradMag = length(gradient);
float3 normal = gradient / gradMag;
col.rgb = calculateLighting(col.rgb, normal, getLightDirection(-ray.direction), -ray.direction, 0.15);
col.a = 1.0;
break;
float4 secondaryColour = getSecondaryTF1DColour(secondaryDensity);
if (secondaryColour.a > 0.0)
{
col = secondaryColour;
float3 gradient = getGradient(currPos);
float gradMag = length(gradient);
float3 normal = gradient / gradMag;
col.rgb = calculateLighting(col.rgb, normal, getLightDirection(-ray.direction), -ray.direction, 0.15);
col.a = 1.0;
break;
}
}
#endif
if (density > _MinVal && density < _MaxVal)
Expand Down

0 comments on commit 602bddb

Please sign in to comment.