January 26, 2010

Tone Shader

Tool: ATI Rendermonkey
Language: HLSL
Basically, this technique can be done by two pass. First, I create a basic infinite light shading to render to texture. The rendertarget uses the alpha to store the shading result. In the final pass, I use a 2D texture which is my "tone" map to lerp the last pass result. Done! 
Key Code:
float4 ps_main(float3 pos : TEXCOORD1, float3 nrm : TEXCOORD2) : COLOR
    float  diffuse = min(1.0,max(0,dot(-Light_Direction,nrm)));
    diffuse = pow(diffuse,5);
    diffuse = (diffuse*4)/3.0; 
    float4 Col = float4(1,1,1,diffuse);
    return Col;



float4 ps_main(float2 tex: TEXCOORD0) : COLOR0
   float4 color;
   float4 base = tex2D(Texture0,tex);
   float4 hatch = tex2D(Texture1, tex);
   color = lerp(hatch , base, base.a) ;
   return color * base; 


0 意見: