"Cartoon shading" with cubemaps - how?

Blitz3D Forums/Blitz3D Programming/"Cartoon shading" with cubemaps - how?

JustLuke(Posted 2007) [#1]
I've been looking at the old spherical mapping technique used to approximate cel shading (the lighting effect rather than outlining the model) in blitz3d.

It's a pretty neat effect but unusably flawed when you add in a dynamically moving camera, because - obviously - due to the nature of spherical mapping, the lighting is relative to the camera, and it changes whenever the camera is repositioned.

So I was wondering if there was any way to somehow "clamp" the light texture when the camera is moved?

EDIT:
after searching the forums I have found that using a cubemap is a way to solve the problem. Has anyone used cubemaps to create improved cel shading?

FURTHER EDIT:
on another thread regarding cel shading, sswift wrote (in reference to solving the above problem that I mentioned):

To avoid that, you could apply the shading map to a sphere, point the top of the sphere towards the desired light source, flip the sphere so it is inside out, and then render a cubemap from inside the sphere with the sphere set to fullbright. Then you could use the cubemap instead of the spherical environment map, and the light would stay in the right direction no matter how you moved the camera around the obejct in question.

My first reacton to this was "Yay!" but, inevitably, my second was "Er, what?", so does someone have a working example that I could learn from (steal)?


JustLuke(Posted 2007) [#2]
C'mon guys - surely someone can give me some pointers about this?


Beaker(Posted 2007) [#3]
How about this?:
1) Use LightMesh() (check latest online docs for this) to light your sphere.
2) Place a camera at 0,0 inside sphere.
3) Invert (FlipMesh) sphere.
4) Render your cubemap texture (see UpdateCubeMap() function here -> http://www.blitzbasic.com/codearcs/codearcs.php?code=1167 )
5) Save cubemap texture to your harddisk.
6) Load and apply cubemap texture to your mesh.


Paolo(Posted 2007) [#4]
This method sometimes works and sometimes it doesn't ...

load this texture using the next code and then apply it to any
mesh in the second layer (layer 1):




cube_texture=LoadTexture("cellshadecubemapif4.png",1+128)
	TextureBlend cube_texture,5
	SetCubeMode cube_texture,4


Hope it helps :)
Paolo.

[edit]
Oops, I have just seen you said "cartoon shading", I was thinking about "cellshading",
to make the cube map remains in a fixed position independent
from the camera position and rotation use SetCubeMode texture,2 with the loaded texture ...


JustLuke(Posted 2007) [#5]
That's just what I was looking for - thanks!