1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Blender 自作シェーダー(OSL)で簡単なトゥーンシェーダー

Last updated at Posted at 2022-12-04

BlenderでOSL(Open Shading Language)を使用して、簡単なトゥーンシェーダーを実装してみようと思います。
1.png
イメージとして以下の図のような感じです。
ベクトルのなす角(θ)が小さければモデルを明るくし、大きければ暗くします(サンプルは少し違いますが・・・・)。
3.png

シェーダー

shader toon_shader(
    //テクスチャ
    color texture_color = color(0.0,0.0,0.0),
    //法線
    normal n = N,
    //ライトの方向
    vector light_direction = vector(1.0,1.0,-1.0),
    //ライトの色
    color light_color = color(1.0,1.0,1.0),
    //最終的なカラー
    output color final_color  = color(0.0,0.0,0.0)
)
{
    final_color = texture_color;
    color light = color(0.0,0.0,0.0);
   //ライト方向を正規化。
    vector light_dir = normalize(light_direction);
    
    //法線とライトの方向からランバート拡散反射光を計算。
    float lambert = clamp(dot(-n,light_dir),0.0,1.0);
    lambert *= lambert;
    //値を一定値で分ける。
    if(lambert > 0.15)
    {
        lambert = 1.0;
    }
    else 
    {
        lambert = 0.3;
    }
    light += light_color * lambert;
    
    //計算したライティングの値を乗算。
    final_color *= light;
}

ノード

2.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?