volume rendering 座標分析-2

來源:互聯網
上載者:User

座標關鍵代碼如下:

//將uv轉換為-1到1之間的浮點數    float u = (x / (float) imageW)*2.0f-1.0f;    float v = (y / (float) imageH)*2.0f-1.0f;    // calculate eye ray in world space    Ray eyeRay;    eyeRay.o = make_float3(mul(c_invViewMatrix, make_float4(0.0f, 0.0f, 0.0f, 1.0f)));    eyeRay.d = normalize(make_float3(u, v, -2.0f));//    eyeRay.d = mul(c_invViewMatrix, eyeRay.d);//    // find intersection with boxfloat tnear, tfar;int hit = intersectBox(eyeRay, boxMin, boxMax, &tnear, &tfar);    if (!hit) return;if (tnear < 0.0f) tnear = 0.0f;     // clamp to near plane    // march along ray from front to back, accumulating color    float4 sum = make_float4(0.0f);    float t = tnear;    float3 pos = eyeRay.o + eyeRay.d*tnear;    float3 step = eyeRay.d*tstep;    for(int i=0; i<maxSteps; i++) {        // read from 3D texture        // remap position to [0, 1] coordinates        float sample = tex3D(tex, pos.x*0.5f+0.5f, pos.y*0.5f+0.5f, pos.z*0.5f+0.5f);//?

1、先聲明,全局座標係為x [-1, 1]; y [-1, 1]; z[-1, 1]。(自己隨便說是全局座標系)

2、u,v可以肯定是在[-1, 1]之間變化的,因為x和y 的變化範圍分別在[0,imageW]和[0,imageH]變化(x / (float) imageW)在[0,1]變化乘以2在[0,2]變化,再減1,在[-1, 1]變化。

3、說明視線的變化。首先規定眼睛的位置:make_float4(0.0f, 0.0f, 0.0f, 1.0f);然後對眼睛的位置進行仿射變換:mul(c_invViewMatrix, make_float4(0.0f, 0.0f, 0.0f, 1.0f)),這裡變換矩陣是變換視點的矩陣,所以是模型變換的逆矩陣。最後,mul(c_invViewMatrix, eyeRay.d); 對視線進行變換。

4、求交,求交也是在全局座標系下。

5、求紋理座標。由於紋理產生時,使用了:tex.normalized = true;  所以會對座標進行標準化範圍[0, 1],所以又需要將座標變換到[0, 1]之間,tex3D(tex, pos.x*0.5f+0.5f, pos.y*0.5f+0.5f, pos.z*0.5f+0.5f); 意思是:[-1, 1]*0.5 + 0.5 = [0, 1]

 

至此座標變換完成。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.