Cartoon Shading

Blitz3D Forums/Blitz3D Programming/Cartoon Shading

mouss38(Posted 2004) [#1]
Where can I find good cartoon shading functions (with animated meshes supported)

Rob's tutorial is not available now and the codes found in the archive section, in this site, are not really usefull...


EOF(Posted 2004) [#2]
Here's a nice and simple one by Norc:
; norcs 3D Outline demo

Graphics3D 640,480,16,2
SetBuffer BackBuffer()
camera=CreateCamera()
MoveEntity camera,0,0,-3
CameraRange camera,1,2000
CameraClsColor camera,20,50,100
light=CreateLight()
RotateEntity light,30,30,30

n=200
Dim cubei(n),cubeo(n),sx#(n),sy#(n),sz#(n),x#(n),y#(n),z#(n)
min100=-30
max100=30
For i=0 To n
 cubei(i)=CreateSphere(7)
 EntityFX cubei(i),8 Or 4 					; no fog + flat shaded
 cubeo(i)=CreateSphere(7,cubei(i))
 EntityFX cubeo(i),1								; full bright
 FlipMesh cubeo(i)									; inverted
 EntityColor cubeo(i),0,0,0					; black
 x(i)=Rnd(min100,max100) : y(i)=Rnd(min100,max100) : z(i)=Rnd(max100)
 sx(i)=Rnd(.1,.2) : sy(i)=Rnd(.1,.2) : sz(i)=Rnd(.1,.2)
 EntityColor cubei(i),Rand(20,255),Rand(20,255),Rand(20,255)
Next

correct=1

While KeyDown(1)=0
 If KeyHit(57)
  correct=correct Xor 1
 EndIf
 For i=0 To n
  x(i)=x(i)+sx(i)
  If x(i)>max100 Then sx(i)=-Rnd(.1,.2)
  If x(i)<min100 Then sx(i)=Rnd(.1,.2)  
  y(i)=y(i)+sy(i)
  If y(i)>max100 Then sy(i)=-Rnd(.1,.2)
  If y(i)<min100 Then sy(i)=Rnd(.1,.2)
  z(i)=z(i)+sz(i)
  If z(i)>max100 Then sz(i)=-Rnd(.1,.2)
  If z(i)<1 Then sz(i)=Rnd(.1,.2)
  PositionEntity cubei(i),x(i),y(i),z(i),1
  TurnEntity cubei(i),1,1,1
  ; d#=EntityDistance(camera,cubei(i)) ; for a mobile camera
  d#=Abs(EntityZ(camera)-EntityZ(cubei(i))) ; pretty accureate, but only for a north-pointing camera
  s#=1.01+(d/80.0)
  If s>2 Then s=2
  If correct=1
   ScaleEntity cubeo(i),s,s,s
  Else
   ScaleEntity cubeo(i),1.2,1.2,1.2
  EndIf
 Next
 RenderWorld()
 Text 0,0,"Hit Space to toggle Scaling Correcture"
 If correct
  Text 0,16,"Correcture is on"
 Else
  Text 0,16,"Correcture is off"
 EndIf
 Flip
Wend

End



koekjesbaby(Posted 2004) [#3]
look for the one sswift made, that one rocked.


Genexi2(Posted 2004) [#4]
Here's a thread over at BlitzCoder which discussed cell-shading in Blitz3d, I'd recommend taking a look at CyberSeth's examples : http://www.blitzcoder.com/cgi-bin/ubb-cgi/postdisplay.cgi?forum=Forum14&topic=001338


RifRaf(Posted 2004) [#5]
is there any way to lock an environment map so it stops moving with camera ANGLE, i want to cel shade a world with the method of 2 environment maps, using blend and multiply. the result looks amazing, but when the camera moves the shadows move with it.. and that looks funny. any suggestions ?


Genexi2(Posted 2004) [#6]
Maybe not use them as Spherical Maps?
(and add an alpha flag instead?)


sswift(Posted 2004) [#7]
You have to use cubic maps or update the spherical maps every frame (or so) if you want the maps to not rotate with the camera.

Altenratively, you can limit your camera to rotating around the object in one direction, ie, left to right only, and have the light at a 90 degree angle to this... ie, directly above the character. Then the rotation of the camera won't affect it's angle relative to the light. But obviously this is very limiting for how you can move your camera.


RifRaf(Posted 2004) [#8]
i realy dont know alot about cube mapping, but did create one going from current help file instructions.. it looks ok still. but again it shifts with the camera.


sswift(Posted 2004) [#9]
Cube mapping will not shift with the camera. If it does, you've done it wrong, or used the wrong reflection mode.


RifRaf(Posted 2004) [#10]
Could you give me an example. i just load the tetxture with flag 128, and apply it to the world . The world set to fx 1. Since its a static texture, i shouldnt have to do anythign else should i ?


sswift(Posted 2004) [#11]
Huh? Cubic maps are special. You need to generate one at runtime. It requires six different views, and you have to set the cubic mapping mode.

I don't have time to write you a cubic mapping thing, but look int he code archives for my cel shading system. I think it's there at least. Maybe I put it in a thread. I forget. Maybe someone else knows. If you can't find it, email me and I will send the zip to you when I have time.

Once you have that find a function in the code archives for generating a cube map from a specific location in the world.

Now that you have both of those, combine the two.

My cel shading system loads a 1d texture... a gradient map. It then applies this to a sphere and renders the view of the sphere. This makes a sphere map.

What you need to do is instead of rendering the view from outside the sphere, you need to flip the sphere inside out, and render the view from the inside with a cubic map generator.

Once you've done this you will have a proper cubic map for a light from a specific direction.