卡通(Toon)着色

CPU端代码设置:

// This function does any needed initialization on the rendering
// context. 
void SetupRC(void)
	{
	// Background
	glClearColor(0.025f, 0.25f, 0.25f, 1.0f );

	glEnable(GL_DEPTH_TEST);

    shaderManager.InitializeStockShaders();
    viewFrame.MoveForward(4.0f);
    // Make the torus
    gltMakeTorus(torusBatch, .80f, 0.25f, 52, 26);

	toonShader = gltLoadShaderPairWithAttributes("ToonShader.vp", "ToonShader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex",
			GLT_ATTRIBUTE_NORMAL, "vNormal");

	locLight = glGetUniformLocation(toonShader, "vLightPosition");
	locMVP = glGetUniformLocation(toonShader, "mvpMatrix");
	locMV  = glGetUniformLocation(toonShader, "mvMatrix");
	locNM  = glGetUniformLocation(toonShader, "normalMatrix");
        locColorTable = glGetUniformLocation(toonShader, "colorTable");

	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_1D, texture);
	GLubyte textureData[4][3] = { 32,  0, 0,
                                      64,  0, 0,            
                                      128, 0, 0,
	                              255, 0, 0};

	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, textureData);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
}


顶点着色器:

// Cell lighting Shader
// Vertex Shader
// Richard S. Wright Jr.
// OpenGL SuperBible
#version 130

// Incoming per vertex... position and normal
in vec4 vVertex;
in vec3 vNormal;

smooth out float textureCoordinate;

uniform vec3	vLightPosition;
uniform mat4	mvpMatrix;
uniform mat4	mvMatrix;
uniform mat3	normalMatrix;


void main(void) 
    { 
    // Get surface normal in eye coordinates
    vec3 vEyeNormal = normalMatrix * vNormal;

    // Get vertex position in eye coordinates
    vec4 vPosition4 = mvMatrix * vVertex;
    vec3 vPosition3 = vPosition4.xyz / vPosition4.w;

    // Get vector to light source
    vec3 vLightDir = normalize(vLightPosition - vPosition3);

    // Dot product gives us diffuse intensity
    textureCoordinate = max(0.0, dot(vEyeNormal, vLightDir)); // cos(theta), 值越大说明夹角越小, 对应的颜色越亮

    // Don't forget to transform the geometry!
    gl_Position = mvpMatrix * vVertex;
    }

片断着色器:

// Cell lighting Shader
// Fragment Shader
// Richard S. Wright Jr.
// OpenGL SuperBible
#version 130

uniform sampler1D colorTable;
out vec4 vFragColor;

smooth in float textureCoordinate;


void main(void)
   { 
   vFragColor = texture(colorTable, textureCoordinate);
   }

 

截图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Requires Unity 5.6.0 or higher. RealToon v5.1.2 An AAA Anime/Toon Shader to make your characters & objects to look as close to real Anime/Cartoon. Toon/Cel shading shader. (For Games, Film/Animations & Illustrations/Arts) - It is Fully Multi-Lighting. Features: - Smooth Object Normal: *Smooth object normal for better or clean shading. - Self Shadow: *(Adjust Size/Threshold and Hardness without using any texture) - Normal Map: *(For more details) - FReflection: *(Use images/textures as reflection.) *(Can also adjust the size and position) *(This is not a matcap style reflection or cubemap.) - Outline: *(Can change the Color and Width) *(With noise/distort outline for sketch style outline and dynamic) *(You can choose to use outline or without outline "for less drawcalls"). - Gloss (Texture) (Custom Gloss): *(Use images/textures as gloss) *(Can choose to follow light position & object rotation.) - ShadowT (Texture): *(Gradient or Flat base shadow/shade.) - RealToon Refraction: *Anime/cartoon style glass, ice, liquid, etc. - Reduce Shadow: *Reduce real-time shadow of an object - material without affecting other parts of an object. - Fade Transparency with outline and transparent affects shadow. - Vertex color support for Outline, Self Shadow & Smooth Object Normal features. - Includes RealToon (Lite Version) shaders for mobile or lite type games. - Includes RealToon (Tessellation Version) shaders. - Includes RealToon (LWRP Version) (Unity 2018 with LWRP V4.0.0 to latest) - Includes effects like sobel outline. - More... Other Features - Use Directional Light and Point & Spot light or multiple lights at the same time without problem and maintaining that anime/cartoon style shadow color & brightness. - Fully color shadow and maintain light falloff. - Fog affect Outline. - Receive GI with Flat/Smooth shade & Skylight/Environment Light. - Do baked/real-time reflection. - Can use patterned textures for manga/comics like shadow. - Use it with or without shadow. - Computer (PC,Mac & Linux), Mobile & Video Game Console (Nintendo Switch) in one shader. - You can also use this in creating Anime/Cartoon film & Illustrations/Arts in unity3d. - You can also use this in making VTuber works with or without real-time shadows. - Can now be used in 2D type games. - Includes a simple tool/script Frame By Frame Rendering for animation & illustration/art use. *Renders frames to Image Sequence or PNG Sequence file. - Includes a simple custom shadow resolution script for higher quality shadow. (For Film/Animation & Illustration/Art use) - This can also be use in VRChat/VRC. - More features to come so be sure to check my social network/media.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值