[英]Volume rendering from inside volume
僅渲染一次。
在此過程中,您僅渲染背面。 需要將攝像機的位置從世界坐標轉換為一個坐標系,該坐標系由3個軸及其渲染的體積框的大小構成。 您的目標是創建一個4x4矩陣,其中所有列向量均為vec4(...,0),並且這些向量的x,y,z由帶有體積框長度的x,y,z軸方向定義。 如果框平行於x軸,則該向量為(1,0,0)。 如果將其拉伸到(2,0,0),則它就是它自己的x軸,它將成為矩陣中第0列的列向量。 使用y和z軸的長度進行操作。 矩陣中的最后一列向量是框的位置,為vec4(tx,ty,tz,1),因為此矩陣定義了坐標系,然后使用它將攝像機位置轉換為統一的(0,0,0 )-(1,1,1)框的音量。
創建該體積框矩陣的逆,然后從右側到invVolMatrix將cam乘以vec4(campos,1)。 將生成的vec3作為UNIFORM發送到着色器。
如您已經做過的那樣,僅渲染在它們各自的volBox角上具有(0,0,0)到(1,1,1)坐標的背面。 現在您在着色器中
在着色器中執行以下操作:
varying vec3 vLocalUnitTexCoord; // backface interpolated coordinate
uniform vec3 LOCAL_CAM_POS; // localised camPos
struct AABB {
vec3 min; // (0,0,0)
vec3 max; // (1,1,1)
};
struct Ray {
vec3 origin; vec3 dir;
};
float getUnitAABBEntry( in Ray r ) {
AABB b;
b.min = vec3( 0 );
b.max = vec3( 1 );
// compute clipping for box.min and box.max corner
vec3 rInvDir = vec3( 1.0 ) / r.dir;
vec3 tMinima = ( b.min - r.origin ) * rInvDir;
vec3 tMaxima = ( b.max - r.origin ) * rInvDir;
// sort for nearest corner
vec3 tEntries = min( tMinima, tMaxima );
// find first real entry value of 3 t-distance values in vec3 container
vec2 tMaxEntryCandidates = max( vec2( tEntries.st ), vec2( tEntries.pp ) );
float tMaxEntry = max( tMaxEntryCandidates.s, tMaxEntryCandidates.t );
}
vec3 getCloserPos( in vec3 camera, in vec3 frontFaceIntersection, in float t ) {
float useFrontCoord = 0.5 + 0.5 * sign( t );
vec3 startPos = mix( camera, frontFaceIntersection, useFrontCoord );
return startPos;
}
vec4 main(void)
{
Ray r;
r.origin = LOCAL_CAM_POS;
r.dir = normalize( vLocalUnitTexCoord - LOCAL_CAM_POS );
float t = getUnitAABBEntry( r );
vec3 frontFaceLocalUnitTexCoord = r.origin + r.dir * t;
vec3 startPos = getCloserPos( LOCAL_CAM_POS, frontFaceLocalUnitTexCoord, t );
// loop for integration follows here
vec3 start = startpos;
vec3 end = vLocalUnitTexCoord;
...for loop..etc...
}
編碼愉快!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.