卡通渲染--Dot3 Cel Shading

來源:互聯網
上載者:User

           按ShadeX 3中《Dot3 Cel Shading》的方法所渲染的卡通茶壺,簡單的代碼效果居然如此好。因為是卡通渲染,所以除了最後著色以外的大部分計算都可以移動到vertex shader中,不過因為My Code是在普通渲染的基礎上改的,所以vertex shader中只是做了基本的變換。另外如果加上高光,效果反而不真實了,直接用普通光照模型計算出的漫反射進行調整就能得出不錯的效果。

普通渲染(漫反射+高光)+ 邊緣輪廓線:

卡通著色:

多條過渡帶:

完整的pixel shader代碼:

void PixelShader(out half4 color : COLOR0,
 in float3 worldPos :TEXCOORD0,
 in float3 normal : TEXCOORD1)
{
   normal = normalize(normal);
   float3 lightVect = normalize( lightPos - worldPos);
   float diffuse = saturate( dot ( normal,lightVect));

    float3 eyeVect = normalize( eyePos - worldPos);
 
   half scale = saturate(dot( normal, eyeVect));
   int scaleFactor = floor(scale * shaders);
   scale = scaleFactor / shaders; 
 
    if(scale < exclude / shaders)
   {
     color.xyz = 0;
   }
    else
  {
    diffuseColor = lightColor * diffuseColor * diffuse;
    color.xyz = diffuseColor * scale + diffuse / shaders;
  }
  color.w = 1.0;   
}

      shaders是顏色帶的數量,exclude是邊緣輪廓線寬度,上面中間的三幅圖中shaders=4,exclude=1。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.