Toon lighting swaps R and B channels in bare polygons

Previous topic - Next topic

Ruidesco

When using the toon lighting, bare polygons' colours are swapped in a way that the red channel value will become the blue channel value, and vice versa.
Example:

Code (glbasic) Select
// PRESS SPACE TO SWITCH BETWEEN NORMAL LIGHT AND TOON LIGHT

LOCAL spacePressed = FALSE
LOCAL lightIndex = 0
LOCAL lightNames$[]; DIMDATA lightNames$[], "NORMAL", "CARTOON"
LOCAL x, y
LOCAL spotx = -50, spoty = 50, spotz = 50

X_OBJSTART 0

X_OBJADDVERTEX x - 1, y - 1, 0, 0, 0, RGB(255, 0, 0)
X_OBJADDVERTEX x, y + 1, 0, 0, 0, RGB(0, 255, 0)
X_OBJADDVERTEX x + 1, y - 1, 0, 0, 0, RGB(0, 0, 255)

X_OBJEND

WHILE TRUE

IF KEY(57)

IF NOT spacePressed

lightIndex = 1 - lightIndex
spacePressed = TRUE

ENDIF

ELSE

spacePressed = FALSE

ENDIF

X_MAKE3D 1, 1000, 45
X_CAMERA 0, 0, 20, 0, 0, 0
X_CULLMODE 1

X_AMBIENT_LT lightIndex * -2, RGB(255, 255, 255)

X_DRAWOBJ 0, 0

X_MAKE2D
PRINT lightNames$[lightIndex], 4, 4

SHOWSCREEN

WEND

END


Another thing I've noticed (not in the example code) is that spot lights coordinates seem to work different than the normal objects ones, probably completely reversed. (?)

Kitty Hello

Yes. I think it's not the colour you see, it's some sort of normals displayed. I'm uncertain.
You really should think about using a texture because it's a) much faster than glColourArray, and b) works  :D

Ruidesco

I will do better not using any kind of lighting then. :doubt:

Kitty Hello

textures objects and cel shading work properly.

Ruidesco

Yes, I tried and they do.
Luckily I found a workaround to keep simple coloured polygons in use, which consists of just feeding the colours backwards. :P

The thing is that I'm using Sproxel (a voxel editor) to create the 3D sprites I want to use, and that just draws them using single-colour cubes (which is what I want anyway). Then I load the CSV file it saves the models in, parse it and build an X_OBJ of the model at runtime.

Thank you for your patience. :-[

PS. Here's a double screenshot, with Sproxel showing the fugly red eye of doomy death model and GLBasic showing it as well using flat polygons; just because. :P

Kitty Hello

make a texture with 1 pixel per used colour and use texture coords to set the colour of the cube. It renders a lot faster. Great screenshot!

Ruidesco

Aaaagh #@*!%+& :help:

It finally works but one thing I didn't know had me stuck for yesterday and the best part of today: the texture having to be a square bitmap that is either 16x16 pixels in size or its double/quadruple/octuple/etc (you get the idea), otherwise it goes haywire and shows garbage.

Such are the tribulations of the complete 3D beginner.  :D
Well, one less problem now.

Kitty Hello

yes. Textures must be power-of-2 sizes. GLBasic does all this internally for you. But the 3D coords must be mapped to the real power of 2 size, not the bitmap size. If I'd change that, I'd have to use a multiplication per vertex when drawing -> totally unacceptable.