📄 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
// 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 MeshSampler: register(s7);
/*
texture tMinMaxVolume;
texture tVolumeDen;
texture tGradient;
texture tPreIntOtf;
texture tRenderTarget;
// ( used in EmptySkipPShader )
sampler3D MinMaxVolumeSampler = sampler_state
{
Texture = (tMinMaxVolume);
MinFilter = Point; // Linear;
MagFilter = Point; // Linear;
BorderColor = 0x00000000;
AddressU = Border;
AddressV = Border;
AddressW = Border;
};
// volume data (L16)
sampler3D VolumeDenSampler = sampler_state
{
Texture = (tVolumeDen);
MinFilter = Linear;
MagFilter = Linear;
BorderColor = 0x00000000;
AddressU = Border;
AddressV = Border;
AddressW = Border;
};
// gradient data (rgb : gradient)
sampler3D GradientSampler = sampler_state
{
Texture = (tGradient);
MinFilter = Linear;
MagFilter = Linear;
BorderColor = 0x00000000;
AddressU = Border;
AddressV = Border;
AddressW = Border;
};
// pre-integrated texture
sampler2D PreIntOtfSampler = sampler_state
{
Texture = (tPreIntOtf);
MinFilter = Linear; // Point;
MagFilter = Linear; // Point;
AddressU = Clamp;
AddressV = Clamp;
// BorderColor = 0x00000000;
// AddressU = Border;
// AddressV = Border;
};
// render target (intermediate) texture
sampler2D RenderTargetSampler = sampler_state
{
Texture = (tRenderTarget);
MinFilter = Linear;
MagFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
*/
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
float4 OutInterTex : TEXCOORD2;
};
struct VS_OUTPUT2
{
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 );
*/
// 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_OUTPUT2 MeshRenderVShader( float4 inPos : POSITION,
float2 textureCoord : TEXCOORD0 )
{
VS_OUTPUT2 Out = (VS_OUTPUT2) 0;
Out.Pos = mul( inPos, meshTransMatrix );
Out.TextureCoord.xy = textureCoord.xy;
return Out;
}
VS_OUTPUT2 MPRRenderVShader( float4 inPos : POSITION,
float3 textureCoord : TEXCOORD0 )
{
VS_OUTPUT2 Out = (VS_OUTPUT2) 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;
float fSliceData = tex3D( VolumeDenSampler, FrontSliceTex ); // front slice volume data loading
float bSliceData = tex3D( VolumeDenSampler, 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 BackSliceTex : TEXCOORD1, // back slice
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 );
Out.Color.rgb = color;
Out.Color.a = 0.5f;
return Out;
}
//-------------------------------------------------------------------------------------------------------------
technique MVRenderTechnique
{
pass EmptySkipPass // pass0
{
ClipPlaneEnable=0;
AlphaBlendEnable=false;
ZEnable=true;
ZWriteEnable=true;
ZFunc=less;
CullMode=none;
VertexShader = compile vs_2_0 EmptySkipVShader();
PixelShader = compile ps_2_0 EmptySkipPShader();
}
pass VolumeRenderPass // pass1
{
ClipPlaneEnable=CLIPPLANE0 | CLIPPLANE1 | CLIPPLANE2 | CLIPPLANE3 | CLIPPLANE4 | CLIPPLANE5;
AlphaBlendEnable=true;
ZEnable=true;
ZWriteEnable=false; // FALSE !
ZFunc=greaterequal;
CullMode=none;
VertexShader = compile vs_2_0 VolumeRenderVShader();
PixelShader = compile ps_2_0 VolumeRenderPShader();
}
pass EarlyRayPass // pass2
{
ClipPlaneEnable=CLIPPLANE0 | CLIPPLANE1 | CLIPPLANE2 | CLIPPLANE3 | CLIPPLANE4 | CLIPPLANE5;
AlphaBlendEnable=true;
ZEnable=true; // D3DRS_ZENABLE 捞 拌加 TRUE 肺 汲沥登绢具 shader 郴何俊辑 depth 函版啊瓷窍骨肺 TRUE肺..
ZWriteEnable=true; // TRUE !
ZFunc=greaterequal;
CullMode=none;
VertexShader = compile vs_2_0 VolumeRenderVShader();
PixelShader = compile ps_2_0 EarlyRayPShader();
}
pass FinalPass // pass3
{
ClipPlaneEnable=0;
AlphaBlendEnable=false;
ZEnable=false;
ZWriteEnable=false;
CullMode=none;
VertexShader = NULL;
PixelShader = compile ps_2_0 FinalPShader();
}
pass ShowDepthPass // pass4
{
ClipPlaneEnable=0;
AlphaBlendEnable=false;
ZEnable=true;
ZWriteEnable=true;
ZFunc=less;
CullMode=none;
VertexShader = compile vs_2_0 EmptySkipVShader();
PixelShader = compile ps_2_0 EmptySkipPShaderShowDepth();
}
pass MeshRenderPass // pass5
{
ClipPlaneEnable=CLIPPLANE0 | CLIPPLANE1;
AlphaBlendEnable=true;
ZEnable=false;
CullMode=ccw;
VertexShader = compile vs_2_0 MeshRenderVShader();
PixelShader = compile ps_2_0 MeshRenderPShader();
}
pass MPRRenderPass // pass6
{
ClipPlaneEnable=CLIPPLANE0 | CLIPPLANE1;
AlphaBlendEnable=true;
ZEnable=false;
CullMode=none;
VertexShader = compile vs_2_0 MPRRenderVShader();
PixelShader = compile ps_2_0 MPRRenderPShader();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -