Study of Qt 3D (vi): Toon Shader

Source: Internet
Author: User

Study of Qt 3D (vi): Toon Shader

In the last experiment, we implemented the Gooch Shader and gave the Gooch Shader settings that were personalized through the palette. Toon Shader, also known as cell Shader, is a discrete color to represent the intensity of the light. Many cartoons are rendered in a way that uses toon shader. The following diagram can be implemented using toon shader.

Saiyang original article, starting address: Welcome to come to discuss the peer.

Here is the code for Toon Shader:

//Toon.vert# Version 100//Qt 3D default supplied parameters attribute vec3 vertexposition;attribute vec3 vertexnormal;uniform mat4 modelview;uniform mat4 m Odelnormalmatrix;uniform mat4 mvp;//Self-supplied parameters uniform vec3 lightposition;varying vec3 reflectvec;varying vec3 Viewvec;    Varying float ndotl;void main (void) {VEC3 Ecpos = (Modelview * VEC4 (Vertexposition, 1.0)). xyz;    VEC3 normal = normalize (Modelnormalmatrix * VEC4 (Vertexnormal, 1.0)). xyz;    VEC3 Lightvec = normalize (Lightposition-ecpos);    Reflectvec = normalize (reflect (-lightvec, normal));    Viewvec = normalize (-ecpos);    Ndotl = (dot (lightvec, normal) + 1.0) * 0.5; gl_position = MVP * VEC4 (Vertexposition, 1.0);} 
Toon.frag#version 100//Self-supplied parameters varying vec3 reflectvec;varying vec3 viewvec;varying float ndotl;uniform sampler2d TexP Alette;float graytexture (vec4 color) {    return dot (, VEC3 (0.299, 0.587, 0.114));} void Main (void) {    Gl_fragcolor = texture2d (Texpalette, VEC2 (Ndotl, 1.0));}

The discrete textures we use are as follows:

The results of the program run are as follows:

Study of Qt 3D (vi): Toon Shader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

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.