簡體   English   中英

使用GLSL在體積渲染中TransferFunc的功能是什么?

[英]What is the function of the TransferFunc in Volume Rendering using GLSL?

我在使用GLSL進行體積渲染時遇到問題。 源代碼可以在以下鏈接https://github.com/toolchainX/Volume_Rendering_Using_GLSL中找到 在片段着色器命名raycasting.frag ,sampler1D TransferFunc出現,但我不知道實際的功能(用途或意義) TransferFunc 以下是raycasting.frag的詳細信息。

具體代碼是: colorSample = texture(TransferFunc,intensity);

#version 400
in vec3 EntryPoint;
in vec4 ExitPointCoord;

uniform sampler2D ExitPoints;
uniform sampler3D VolumeTex;
uniform sampler1D TransferFunc;  
uniform float     StepSize;
uniform vec2      ScreenSize;
layout (location = 0) out vec4 FragColor;

void main()
{
    // ExitPointCoord 的坐標是設備規范化坐標
    // 出現了和紋理坐標有關的問題。
    vec3 exitPoint = texture(ExitPoints, gl_FragCoord.st/ScreenSize).xyz;
    // that will actually give you clip-space coordinates rather than
    // normalised device coordinates, since you're not performing the perspective
    // division which happens during the rasterisation process (between the vertex
    // shader and fragment shader
    // vec2 exitFragCoord = (ExitPointCoord.xy / ExitPointCoord.w + 1.0)/2.0;
    // vec3 exitPoint  = texture(ExitPoints, exitFragCoord).xyz;
    if (EntryPoint == exitPoint)
        //background need no raycasting
        discard;
    vec3 dir = exitPoint - EntryPoint;
    float len = length(dir); // the length from front to back is calculated and used to terminate the ray
    vec3 deltaDir = normalize(dir) * StepSize;
    float deltaDirLen = length(deltaDir);
    vec3 voxelCoord = EntryPoint;
    vec4 colorAcum = vec4(0.0); // The dest color
    float alphaAcum = 0.0;                // The  dest alpha for blending
    /* 定義顏色查找的坐標 */
    float intensity;
    float lengthAcum = 0.0;
    vec4 colorSample; // The src color 
    float alphaSample; // The src alpha
    // backgroundColor
    vec4 bgColor = vec4(1.0, 1.0, 1.0, 0.0);

    for(int i = 0; i < 1600; i++){
        // 獲得體數據中的標量值scaler value
        intensity =  texture(VolumeTex, voxelCoord).x;
        // 查找傳輸函數中映射后的值
        // 依賴性紋理讀取  
        colorSample = texture(TransferFunc, intensity);
        // modulate the value of colorSample.a
        // front-to-back integration
        if (colorSample.a > 0.0) {
            // accomodate for variable sampling rates (base interval defined by mod_compositing.frag)
            colorSample.a = 1.0 - pow(1.0 - colorSample.a, StepSize*200.0f);
            colorAcum.rgb += (1.0 - colorAcum.a) * colorSample.rgb * colorSample.a;
            colorAcum.a += (1.0 - colorAcum.a) * colorSample.a;
        }
        voxelCoord += deltaDir;
        lengthAcum += deltaDirLen;
        if (lengthAcum >= len ){    
            colorAcum.rgb = colorAcum.rgb*colorAcum.a + (1 - colorAcum.a)*bgColor.rgb;      
            break;  // terminate if opacity > 1 or the ray is outside the volume    
        }else if (colorAcum.a > 1.0){
            colorAcum.a = 1.0;
            break;
        }
    }
    FragColor = colorAcum;
    // for test
    // FragColor = vec4(EntryPoint, 1.0);
    // FragColor = vec4(exitPoint, 1.0);

}

我希望你能幫助我解決問題。 謝謝!

傳遞函數確定3D體積數據集的強度如何映射到顏色。

許多3D數據集(例如來自醫學成像)每個體素包含單個值。 例如,對於CT掃描,這將是X射線吸收量(至少這是我認為的......)。

渲染3D數據集時,您希望將不同的強度編碼為不同的顏色。 這就是傳遞函數的作用。 如果使用1D紋理對傳遞函數進行編碼,則此紋理將包含每種可能強度值的RGBA顏色。

這些傳遞函數可以是您想要使結果圖像看起來很好/有用的任何東西。 非常典型的傳遞函數具有以下形式:

  • 完全透明(alpha = 0.0)低於某個強度值。
  • 線性斜坡,α從0.0增加到1.0,高於該范圍的值。 為獲得最佳視覺效果,通常包括使用3種不同顏色。 例如,alpha = 0.0時為黑色,alpha = 0.5時為紅色,alpha = 1.0時為白色,在這些值之間插入顏色。
  • 完全不透明(alpha = 1.0)高於此值。

如果從DICOM文件讀取圖像數據,它可以包含標記,告訴您應該用於傳遞函數的這些不同部分的值的范圍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM