【OpenGL】卡通着色(Cell Shading)——将纹理单元作为光线
发布日期:2021-05-10 02:21:02 浏览次数:12 分类:精选文章

本文共 3103 字,大约阅读时间需要 10 分钟。

������������������������������������3D���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������OpenScene���OpenGL���������������������������������������������������������������

������������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

  • ���������������������������������(x, y)������������������������
  • ������������������������������������������(x, y)������������������������������������������������������������������������
  • ������������������������������������������������������������������������������������������������������
  • ���������������������������������������������������������������������������������

    OpenGL���������������

    ���������������������Cell lighting���������������������������������Vertex���Fragment������������������

    Vertex���������

    #version 130
    in vec4 vVertex;
    in vec3 vNormal;
    smooth out float textureCoordinate;
    uniform vec3 vLightPosition;
    uniform mat4 mvpMatrix;
    uniform mat4 mvMatrix;
    uniform mat3 normalMatrix;
    void main() {
    # moyen de convertir la normale en coordonn��es de l'��il
    vec3 vEyeNormal = normalMatrix * vNormal;
    # convertir la position du point en coordonn��es de l'��il
    vec4 vPosition4 = mvMatrix * vVertex;
    vec3 vPosition3 = vPosition4.xyz / vPosition4.w;
    # vecteur vers la source de lumi��re
    vec3 vLightDir = normalize(vLightPosition - vPosition3);
    # coordonn��es de texture en fonction de la r��flexion
    textureCoordinate = max(0.0, dot(vEyeNormal, vLightDir));
    # appliquer la transformation de la g��om��trie
    gl_Position = mvpMatrix * vVertex;
    }

    ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    Fragment���������

    #version 130
    uniform sampler1D colorTable;
    out vec4 vFragColor;
    smooth in float textureCoordinate;
    void main() {
    vFragColor = texture(colorTable, textureCoordinate);
    }

    ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    ������������

    ���"Cell (toon) shading"���������������������������������

  • ������������������������������������������
  • ���������������������������������
  • ���������������������������������������������������
  • ������������������������������
  • ���������������������������������������������������������������������������2D���������������������������������

    ������������������������������������������������������������������������������������������������������������������������������������3D���������������������������������������������������������������������

    上一篇:【OpenGL】蓝宝书第七章——纹理高级知识
    下一篇:【OpenGL】丢弃片段——消融案例

    发表评论

    最新留言

    能坚持,总会有不一样的收获!
    [***.219.124.196]2025年04月25日 09时49分01秒