Tool : ATI Rendermonkey
Language: HLSL
Concept:
First, I use 3D-Based edge detection. Basically, all I need is the dot production of view-to-vertex vector and the vertex normal. Then, if the dot production is bigger than x (x can be thought as the ink width or the angle between the normal and view vector), I draw black texture on it. If the dot production smaller than x, I draw another texture on it.
Key Code:
VS_OUTPUT vs_main( VS_INPUT Input)
{
VS_OUTPUT Output;
float3 Nrm = normalize(Input.Normal);
float3 ViewVec = normalize(Input.Position - viewPos);
Output.edge = dot(Nrm, ViewVec);
Output.Position = mul( Input.Position, mul(mul(view,projection),world));
Output.Normal = Nrm;
return( Output );
}
float4 ps_main(float edge:TEXCOORD0, float3 N1: TEXCOORD1) : COLOR0
{
float4 color;
float absV = abs(edge);
if(absV
{
float2 findColor = float2(absV*2.5f, N1.x/2.0f+N1.y/2.0f);
color = tex2D(Texture1, findColor);
}
else
{
float2 findColor = float2((1-absV)*1.666f, N1.x/2.0f+0.5f);
color = tex2D(Texture0, 1-findColor);
}
return color;
}
Here is another test: Ink Shading + Lambert Shading
0 意見:
Post a Comment