📄 mv_render.fx
字号:
//-------- global (uniform) var. -----------------------------------------------------------------
float isFrontFace; // front face : 1 / back face : -1 / else : 0 ( used in EmptySkipVertexShader )
float3 lightVec; // ( used in VolumeRenderPShader )
//float3 viewVec;
float4 faceNormal; // object face normal (in object space, used in EmptySkipVertexShader )
float4x4 objectTransMatrix; // texture coordinate transformation matrix ( used in EmptySkipVertexShader )
float4x4 viewProjMatrix; // view projection matrix ( used in VolumeRenderVShader )
float4x4 textureTransMatrix; // texture coordinate transformation matrix ( used in VolumeRenderVShader )
row_major float4x4 clipPlaneMatrix; // clip plane matrix
float4x4 meshTransMatrix; // Mesh coordinate transformation matrix
float4x4 customMPRMatrix; // Custom MPR transformation matrix
//float4x4 customMPRTex; // Custom MPR tex coordinate
float4 stencilLevelTestColor; // MPRFinalPShaderTransed 窃荐俊辑 level 抛胶飘侩 漠扼蔼栏肺 荤侩凳. //added by JUN
// added by taeki
float3 sizeOfSubvolume;
float3 redunRealSlot;
float3 volumeSize;
float3 virtualSubvolumeSize;
float4 forOptimize;
//
// sampler register 绊沥
sampler VolumeDenSampler: register(s0); // volume data (L16)
sampler GradientSampler: register(s1); // gradient data (rgb : gradient)
sampler PreIntOtfSampler: register(s2); // pre-integrated texture
sampler RenderTargetSampler: register(s3);
sampler MinMaxVolumeSampler: register(s4); // volume data (rgb : gradient, a : den)
sampler MPRRenderTargetTex: register(s5); // MPR 坊歹鸥百 咆胶媚
sampler MPRTexMapper: register(s6); // MPR 概欺 咆胶苗
sampler VirtualVolume: register(s7); // 啊惑皋葛府
//sampler MeshSampler: register(s7);
struct VS_OUTPUT0
{
float4 Pos : POSITION; // position
float4 FrontSliceTex : TEXCOORD0; // Front slice Texture Coordinate
float4 OutInterTex : TEXCOORD2;
};
struct VS_OUTPUT1
{
float4 Pos : POSITION; // position
float4 FrontSliceTex : TEXCOORD0; // Front slice Texture Coordinate
float4 BackSliceTex : TEXCOORD1; // Back slice Texture Coordinate
float4 ClipTex : TEXCOORD7; // clip plane texture coordinate
};
struct VS_OUTPUT2
{
float4 Pos : POSITION; // position
float4 OutInterTex : TEXCOORD2;
};
struct VS_OUTPUT3
{
float4 Pos : POSITION;
float3 TextureCoord : TEXCOORD0;
};
struct PS_OUTPUT0
{
float4 Color : COLOR0;
float Depth : DEPTH;
};
struct PS_OUTPUT1
{
float4 Color : COLOR0;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------- EmptySkipVShader (vs_pass0) -------------------------------------------------------
VS_OUTPUT0 EmptySkipVShader( float4 inPos : POSITION,
float4 inFrontTex : TEXCOORD0 )
{
VS_OUTPUT0 Out = (VS_OUTPUT0) 0;
float4 ttt = inPos + sign(isFrontFace)*faceNormal; // < 0.270632939
// float4 ttt = inPos + sign(isFrontFace)*0.26800*faceNormal;
Out.Pos = mul( ttt, objectTransMatrix ); // transform vertices by objectTransMatrix matrix
Out.FrontSliceTex = inFrontTex;
// to NDC
Out.OutInterTex = Out.Pos;
return Out;
}
//-------------------------------------------------------------------------------------------------------------
//---------------------- VolumeRenderVShader (vs_pass1) -------------------------------------------------------
VS_OUTPUT1 VolumeRenderVShader( float4 inPos : POSITION,
float4 inFrontTex : TEXCOORD0,
float4 inBackTex : TEXCOORD1 )
{
VS_OUTPUT1 Out = (VS_OUTPUT1) 0;
Out.Pos = mul( inPos, viewProjMatrix ); // transform vertices by view/projection matrix
Out.FrontSliceTex = mul( inFrontTex, textureTransMatrix ); // transform volume texture coordinate by Texture transformation matrix
Out.BackSliceTex = mul( inBackTex, textureTransMatrix ); // transform volume texture coordinate by Texture transformation matrix
Out.ClipTex.x = dot( clipPlaneMatrix[0], inPos ); // transform position by clipplane in 'world space'
Out.ClipTex.y = dot( clipPlaneMatrix[1], inPos );
// Out.ClipTex.z = dot( clipPlaneMatrix[2], inPos );
return Out;
}
//-------------------------------------------------------------------------------------------------------------
//---------------------- EarlyRayVShader (vs_pass2) -------------------------------------------------------
VS_OUTPUT2 EarlyRayVShader( float4 inPos : POSITION )
{
VS_OUTPUT2 Out = (VS_OUTPUT2) 0;
Out.Pos = mul( inPos, viewProjMatrix ); // transform vertices by view/projection matrix
// to NDC
float4 ttt = Out.Pos;
// y 绵 谅钎 芭操肺,. and -1 ~ 1 -> 0 ~ 1 裹困肺..
// ttt.x = ttt.x ;
ttt.y = -ttt.y ;
Out.OutInterTex.xy = ((ttt.xy + 1)/2);
Out.OutInterTex.zw = ttt.zw; // z (depth) 绰 弊措肺..
return Out;
}
//-------------------------------------------------------------------------------------------------------------
//---------------------- MeshRenderVShader -------------------------------------------------------
VS_OUTPUT3 MeshRenderVShader( float4 inPos : POSITION,
float2 textureCoord : TEXCOORD0 )
{
VS_OUTPUT3 Out = (VS_OUTPUT3) 0;
Out.Pos = mul( inPos, meshTransMatrix );
Out.TextureCoord.xy = textureCoord.xy;
return Out;
}
VS_OUTPUT3 MPRRenderVShader( float4 inPos : POSITION,
float3 textureCoord : TEXCOORD0 )
{
VS_OUTPUT3 Out = (VS_OUTPUT3) 0;
Out.Pos = mul( inPos, objectTransMatrix );
Out.TextureCoord = textureCoord;
return Out;
}
//-------------------------------------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------- EmptySkipPShader (ps_pass0) ----------------------------------------------------------
PS_OUTPUT0 EmptySkipPShader( float4 FrontSliceTex : TEXCOORD0, // front slice
float4 InterTex : TEXCOORD2 )
{
PS_OUTPUT0 Out = (PS_OUTPUT0) 0;
float sliceData = tex3D( MinMaxVolumeSampler, FrontSliceTex ); // front slice volume data loading
Out.Color = float4(0, 0, 0, 0.0);
Out.Depth = 100.0;
if( sliceData != 0) {
Out.Depth = InterTex.b - 0.02; // z 蔼阑 depth 肺 免仿
}
return Out;
}
//-------------------------------------------------------------------------------------------------------------
//---------------------- EmptySkipPShaderShowDepth (ps_pass0_showDepth) ---------------------------------------
PS_OUTPUT0 EmptySkipPShaderShowDepth( float4 FrontSliceTex : TEXCOORD0, // front slice
float4 InterTex : TEXCOORD2 )
{
PS_OUTPUT0 Out = (PS_OUTPUT0) 0;
float sliceData = tex3D( MinMaxVolumeSampler, FrontSliceTex ); // front slice volume data loading
Out.Color = float4(0, 0, 0, 0.0);
Out.Depth = 100.0;
if(sliceData != 0) {
Out.Depth = InterTex.b;// - 0.02; //!!!
Out.Color.rgb = InterTex.bbb;
Out.Color.a = 1.0;
}
return Out;
}
//-------------------------------------------------------------------------------------------------------------
//---------------------- VolumeRenderPShader (ps_pass1) --------------------------------------------------------
PS_OUTPUT1 VolumeRenderPShader( float4 FrontSliceTex : TEXCOORD0, // front slice
float4 BackSliceTex : TEXCOORD1, // back slice
float4 ClipTest : TEXCOORD7 )
{
PS_OUTPUT1 Out = (PS_OUTPUT1) 0;
// clip(ClipTest);
if(ClipTest.r > 0 && ClipTest.g > 0)
{
float fSliceData = tex3D( VolumeDenSampler, FrontSliceTex ); // front slice volume data loading
float bSliceData = tex3D( VolumeDenSampler, BackSliceTex ); // back slice volume data loading
// float fSliceData = tex3D( VirtualVolume, FrontSliceTex ); // front slice volume data loading
// float bSliceData = tex3D( VirtualVolume, BackSliceTex ); // back slice volume data loading
// FTB 捞骨肺 preInt 老锭档 front slice 俊辑 gradient 啊廉颗.
float3 gradient = tex3D( GradientSampler, FrontSliceTex ).rgb; // gradient from front slice
gradient = normalize( gradient - 0.5 ); // normalize
// float4 diff = saturate( dot( gradient, lightVec )); // diffuse component N.L
float4 diff = abs( dot( gradient, lightVec )); // diffuse component N.L
// float4 diff = abs( dot( gradient, float3(0,1,0) )); // light 绊沥
float4 otfCAlpha = tex2D( PreIntOtfSampler, float2(fSliceData, bSliceData) ); // load otf color & alpha value
// Out.Color = 0.2 + 0.8 * diff;
Out.Color = 0.1 + 0.8 * diff;
/* // 2. using shader alpha blending
float4 interColor = tex2D( IntermediateRenderTarget, InterTex.rg );
float invAlphaIn = 1-interColor.a;
Out.Color.rgb = interColor.rgb + invAlphaIn*Out.Color.rgb*otfCAlpha.a; // mul otf color value
Out.Color.a = interColor.a + otfCAlpha.a*invAlphaIn; // set out alpha to otf alpha value
*/
// 1. using FF alpha blending
// Out.Color.rgb *= otfCAlpha.a; // nonPre-Int 老 版快
Out.Color.rgb *= otfCAlpha.rgb; // pre-Int 老 版快 OW 烙..
Out.Color.a = otfCAlpha.a;
}
return Out;
}
//-------------------------------------------------------------------------------------------------------------
//---------------------- EarlyRayPShader (ps_pass2) -----------------------------------------------------------
PS_OUTPUT0 EarlyRayPShader( float4 InterTex : TEXCOORD2 )
{
PS_OUTPUT0 Out = (PS_OUTPUT0) 0;
//------- for Early RayTermination --------------
float4 interColor = tex2D( RenderTargetSampler, InterTex.rg );
Out.Depth = 0.0;
Out.Color = 0.0;
// early ray termination
if( interColor.a >= 0.99 ) {
Out.Depth = 100.0;
}
return Out;
}
//-------------------------------------------------------------------------------------------------------------
//---------------------- FinalPShader (ps_passFinall) ------------------------------------------------------
float4 FinalPShader( float4 QuadTex : TEXCOORD0 ) : COLOR0
{
float4 Color = tex2D( RenderTargetSampler, QuadTex );
// Color.a = 1;
// Color.r = 1;
return Color;
}
//-------------------------------------------------------------------------------------------------------------
/*
//---------------------- Mesh shader ------------------------------------------------------
PS_OUTPUT1 MeshRenderPShader( float3 MeshTex : TEXCOORD0 )
{
PS_OUTPUT1 Out;
Out.Color = tex2D( MeshSampler, MeshTex );
return Out;
}
*/
PS_OUTPUT1 MPRRenderPShader( float3 MeshTex : TEXCOORD0 )
{
PS_OUTPUT1 Out;
float color;
color = tex3D( VolumeDenSampler, MeshTex );
// color = tex3D( VirtualVolume, MeshTex );
Out.Color.rgb = color;
Out.Color.a = 1.0f;
return Out;
}
//-------------------------------------------------------------------------------------------------------------
//---------------------- Custom MPR Shader -------------------------------------------------------
struct VS_OUTPUT4
{
float4 Pos : POSITION; // position
float4 MPRTex : TEXCOORD0; // Front slice Texture Coordinate
};
VS_OUTPUT4 CustomMPRVShader( float4 inPos : POSITION,
float4 inTex : TEXCOORD0 )
{
VS_OUTPUT4 Out = (VS_OUTPUT4) 0;
Out.Pos = mul( inPos, customMPRMatrix ); // transform vertices by customMPRMatrix matrix
// Out.MPRTex = mul( inTex, customMPRTex );
Out.MPRTex = inTex;
return Out;
}
PS_OUTPUT1 CustomMPRPShader( float4 inMPRTex : TEXCOORD0 )
{
PS_OUTPUT1 Out = (PS_OUTPUT1) 0;
float fSliceData = tex3D( VolumeDenSampler, inMPRTex );
// float fSliceData = tex3D( VirtualVolume, inMPRTex );
Out.Color = float4(fSliceData, fSliceData ,fSliceData, 1.0); // volume density 蝶客辑 免仿.
return Out;
}
PS_OUTPUT1 CustomMPRPShaderWire( float4 inMPRTex : TEXCOORD0 )
{
PS_OUTPUT1 Out = (PS_OUTPUT1) 0;
Out.Color = float4(0.5, 0, 0, 1); // 公炼扒 red 肺 免仿.
return Out;
}
///////////////////////////////////////////////////////////////////////////////////////////
//------------- MPR tex 谅钎甫 color 免仿栏肺..-------------------
PS_OUTPUT1 MPRQuadTexColorPShader( float4 inMPRTex : TEXCOORD0 )
{
PS_OUTPUT1 Out = (PS_OUTPUT1) 0;
// TODO: Add ........................
inMPRTex.a = 1;
if ( inMPRTex.r <0)
{
inMPRTex.a = 0;
inMPRTex.r = 0;
inMPRTex.g = 0;
inMPRTex.b = 0;
}
if (inMPRTex.g <0)
{
inMPRTex.a = 0;
inMPRTex.r = 0;
inMPRTex.g = 0;
inMPRTex.b = 0;
}
if (inMPRTex.b <0)
{
inMPRTex.a = 0;
inMPRTex.r = 0;
inMPRTex.g = 0;
inMPRTex.b = 0;
}
if ( inMPRTex.r >1)
{
inMPRTex.a = 0;
inMPRTex.r = 0;
inMPRTex.g = 0;
inMPRTex.b = 0;
}
if (inMPRTex.g >1)
{
inMPRTex.a = 0;
inMPRTex.r = 0;
inMPRTex.g = 0;
inMPRTex.b = 0;
}
if (inMPRTex.b >1)
{
inMPRTex.a = 0;
inMPRTex.r = 0;
inMPRTex.g = 0;
inMPRTex.b = 0;
}
Out.Color = float4(inMPRTex.r, inMPRTex.g, inMPRTex.b, inMPRTex.a);
return Out;
}
////////////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -