我试图用液体效果渲染我的液体模拟器,
这是我的渲染结果:
但我希望得到这个结果
这是我的几何和像素着色器
[maxvertexcount(4)]
void mainGS(point GSPS_INPUT gInput[1],inout TriangleStream<GSPS_OUTPUT> TriStream)
{
float size = 0.065;
matrix mv = View;
float3 right = normalize(float3(mv._11,mv._21,mv._31));
float3 up = normalize(float3(mv._12,mv._22,mv._32));
//
float3 posEye = mul( float4(gInput[0].Pos.xyz, 1.0),world).xyz;
//
float halfWidth = size/length(posEye);
float halfHeight = size/length(posEye);
//
float4 v[4];
v[0] = float4(gInput[0].Pos + halfWidth*right - halfHeight*up, 1.0f);
v[1] = float4(gInput[0].Pos + halfWidth*right + halfHeight*up, 1.0f);
v[2] = float4(gInput[0].Pos - halfWidth*right - halfHeight*up, 1.0f);
v[3] = float4(gInput[0].Pos - halfWidth*right + halfHeight*up, 1.0f);
//
//
GSPS_OUTPUT output;
[unroll]
for(int i=0; i<4; ++i)
{
//
output.Pos = mul(v[i], View);
output.PosW = (output.Pos.xyz);
output.Pos = mul(output.Pos, Projection);
output.Tex = gQuadTexC[i];
TriStream.Append(output);
}
TriStream.RestartStrip();
}
//pixel shader
float4 PS(GSPS_OUTPUT input) : SV_TARGET
{
float3 N;
N.xy = input.Tex*float2(2.0f,-2.0f) + float2(-1.0f,1.0f);
float mag = dot(N.xy, N.xy);
if (mag > 1.0)
{
discard;
}
N.z = sqrt(1.0f-mag);
N = N * 0.5 + 0.5;
float4 pixelPos = float4(input.PosW + N*(1/32), 1.0);
float4 clipSpacePos = mul(pixelPos, Projection);
float depthval = (clipSpacePos.z / clipSpacePos.w);
我在这里找到了这个,但它并没有完全解释 Link