(HLSL) Cel (Toon) Shading

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

well, i made that work in rendermonkey, just some step to get it work in irrlicht, but doesn't look so good with complex objects...
Image
Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Because of the recent interest in this, I have decided to improve it:

Image

Shader and Demo can be downloaded from: http://irrlichtirc.g0dsoft.com/BlindSide/celshading.zip
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Katsumi
Posts: 10
Joined: Fri Feb 27, 2009 9:26 am

Post by Katsumi »

Impressive! how rotate this donut in exe-file? its not better to rotate the camera around the donut? i can only move the donut.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I don't understand, what do you mean? Do you have trouble rotating the donut?

If I add this to the demo code:

Code: Select all

ISceneNodeAnimator* anim = smgr->createRotationAnimator(vector3df(0.5f, 0.0f, 0.0f));
torus->addAnimator(anim);
anim->drop();
The donut rotates fine.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

wow impressive effect...of course i directly tried it and canged the mesh. then i wondered why it looks wrong but after checking the shadersource i got it...it only works with deteiled meshes or at least with detailed normals.
Bc when using a normal cube u get the following.
Image
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Haha I only tried on the donut. :oops:

I did a quick touch up on it and added outlining and specular directly into the shader, if I was going the full route I would have made the outlining a post processing effect based on edge detection (Although this way may be more preferable to some as the performance is better and in general you get thicker lines, unless the object is far away).

You can disable the outline effect from the shader and do it the other way (With front face culling and wireframe) if you want to use it on a cube for example.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

yeah its good but i have the same problem

it looks cool in her arms, but not at his clothes and so on ><
outline should be everywhere the same width..
should i try that front face culling and wireframe thingy?
Last edited by B@z on Mon Mar 09, 2009 9:15 am, edited 1 time in total.
Image
Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Yeah, outline should be easy to disable in the shader, just comment out all the lines with "fresnal" in 'em. You can do the outline as a post processing effect if you use XEffects and render to depth map then add a post processing effect that compares the depth of different pixels and makes them dark if theres a reasonable difference, quite similar to simple ssao shader, check out jinquan's thread for an example of this type of shader.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
bicunisa
Posts: 34
Joined: Thu Apr 27, 2006 10:34 pm
Contact:

Post by bicunisa »

Hi BlindSide,

Is it Direct3d only? I tried running it on Linux with OpenGL and the program just shows a black torus. I wonder what am I missing...

I get these messages in the console:

Code: Select all

Irrlicht Engine version 1.5
Linux 2.6.27-12-generic #1 SMP Thu Feb 5 09:26:35 UTC 2009 i686
Creating X window...
Visual chosen: : 39
Using renderer: OpenGL 2.1.2
GeForce Go 7600/PCI/SSE2: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
GLSL version: 1.3
read ChunkNODE: Torus
read ChunkMESH
read ChunkVRTS
read ChunkTRIS
Loaded mesh: torus.b3d
Loaded texture: /home/lobot/development/NetBeansProjects/cellshad/lialique.bmp
Loaded texture: /home/lobot/development/NetBeansProjects/cellshad/cel.png
GLSL shader program failed to link
Vertex info
-----------
0(1) : warning C7506: OpenGL does not define the global type float4x4
0(2) : warning C7506: OpenGL does not define the global type float3
0(7) : warning C7506: OpenGL does not define the global type float4
0(8) : warning C7506: OpenGL does not define the global type float2
0(32) : warning C7554: OpenGL requires samplers to be explicitly declared as uniform
0(33) : warning C7554: OpenGL requires samplers to be explicitly declared as uniform
(0) : error C3001: no program defined

Fragment info
-------------
0(1) : warning C7506: OpenGL does not define the global type float4x4
0(2) : warning C7506: OpenGL does not define the global type float3
0(7) : warning C7506: OpenGL does not define the global type float4
0(8) : warning C7506: OpenGL does not define the global type float2
0(32) : warning C7554: OpenGL requires samplers to be explicitly declared as uniform
0(33) : warning C7554: OpenGL requires samplers to be explicitly declared as uniform
(0) : error C3001: no program defined
OMG another MMORPG project! AztlanRPG
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Yes this is HLSL shader for Direct3D9, I can translate into OpenGL for you if you really need it, I think there is another cel shader by sio2 that is glsl if you want that.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

yeah this is a hlsl file, so its dx only..
opengl goes with glsl

Blindside: nah i dun understand a thing -.-
downloaded something about xeffects and ssao, but dunno what to do.. xD
Image
Image
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

You can use it HLSL (Cg) shader via IrrCg if You need it for Direct3D9 and OpenGL without translating HLSL code to GLSL ;)
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Ah yes good point, CG == HLSL in most cases.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

This is weird. Why cant you just get the light position in the shader? Also, why do you keep passing all these different matrices from Irrlicht ? Are they not available to you in HLSL as they are in GLSL ?
Signature? I ain't signin nuthin!
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

they are avaible but noone uses them....
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Post Reply