What's new
  • Most issues reported these days stem from users not enabling their emulators to use the required amount of RAM.
    We also tend not to use the search feature but post our issues within the texture pack release page.
    Failure to load a texture pack should not be posted in the release thread unless you have already patched the emulator.

    If you don't have the resources to use Large/HD texture packs please do not attempt to do so.
    Users should have a minimum amount of System RAM not less then 4GB's.
    If you have less then 4GB's of RAM do not post about how your emulator crashes,
    RAM is dirt cheap so invest some money into your PC.

    I would like to say thanks to squall_leonhart
    for posting this Solution.

I wish ... someone to implement ... Cel-shading

Risio

Vectrex Fanboy
Honestly, I'd be so happy if one of you folks could make it possible for Mario to match the rest of my pack.
 
OP
Rice

Rice

Emulator Developer
Hi, my first post :) I'm a newbie with N64 emulation, so I might be missing something important, but, how about multiplying a 1D sharp lighting texture to the surface? Multitexturing is need, obviously.

1) Create a 1D sharp lighting texture.
2) Compute the coordinates of the 1D texture for every vertex using the dot product between the normal and the lighting direction.
3) Disable lighting.
4) Draw the polygons using the orignal RGB color, coordinate, texture (if any), and blend the sharp lighting texture by multiplication.

I see that Gonetz's implementation does exactly as Sami "MENTAL" Hamlaoui's article in the "Cel-Shading Textures" section says. Unfortunately, that section of the article is incorrect, as the RGB values for all points inside the triangle will be interpolated between the RGB values of the three vertex defining a triangle with gouraud shading, just as Rice pointed out. I guess flat shading wouldn't work either because it would be too blocky for coarse polygoned models.

-KoolSmoky


Koolsmoky, welcome to emutalk.

Your method may not work because vertex does not have RGB color if lighting is in use. In fact, vertex RGB colors are computed from lighting when lights are used. Because the vertex gets its RGB colors from lighting, lights with RGB colors cannot be replaced successfully by a grayscale texture. A full RGB color texture map must be used.


BTW, N64 has 2 texture units. To do cel-shading successfully, a video card needs to support multitexture with at least 3 texture units. This won't be a problem in general if the video card supports pixel-shader. Pixel-shader is needed anyway in order to efficiently implement the new multitexture color combiner models.
 
Last edited:

Driscol

annoying you for over a year!
woah, a bit to bright, and shadows need to be more intense, and no, shading into them, its a nice effect, just looks like the sun is about to crash into the earth.
 

KoolSmoky

Member
Koolsmoky, welcome to emutalk.

Your method may not work because vertex does not have RGB color if lighting is in use. In fact, vertex RGB colors are computed from lighting when lights are used. Because the vertex gets its RGB colors from lighting, lights with RGB colors cannot be replaced successfully by a grayscale texture. A full RGB color texture map must be used.


BTW, N64 has 2 texture units. To do cel-shading successfully, a video card needs to support multitexture with at least 3 texture units. This won't be a problem in general if the video card supports pixel-shader. Pixel-shader is needed anyway in order to efficiently implement the new multitexture color combiner models.

Hello Rice, thanks for the warm welcome. Yes, my method requires that the vertex has RGB colors without lighting. I see it wouldn't work this case. BTW, does the vertex get its RGB colors from ambient lighting and directional lighting?

-KoolSmoky
 
OP
Rice

Rice

Emulator Developer
KoolSmoky, vertex gets RGB colors (through lighting) from all lights. There are usually 1 ambient light, and 1 or more directional lights. Point lighting is not used in N64 games except Zelda MM.
 

mudlord

Banned
Dont forget this.

Elite Knight, that is not a proper solution.

We are trying to add cel shading via changing how light is processed, not by running additional post processing render passes by shaders.

Though, Orkin did use some shaders in conjunction with his per pixel lighting to get his cel shading.
 

M[u]ddy

New member
Outline Shader
Code:
// NPR outline shader
// c0-3 view matrix
// c4-7 view projection matrix
// c8
// c9 (0.0, 0.0, 0.0, 1.0f)
// c10 line width scalar
vs.1.1
m4x4 r0, v0, c0 // compute the view vector
dp3 r1, r0, r0 // normalize the view vector
rsq r1, r1
mul r0, r0, r1
m3x3 r1, v7, c0 // multiply normal 1 by the view matrix
m3x3 r2, v8, c0 // multiply normal 2 by the view matrix
dp3 r3, r0, r1 // dot normal 1 with the view vector
dp3 r4, r0, r2 // dot normal 2 with the view vector
mul r3, r3, r4 // multiply the dot products together
slt r3, r3, c9 // check if less than zero
mov oD0, c9 // set the output color
dp4 r0, v0, c6 // compute the vertex depth
mul r0, r0, c10 // multiply by a line thickness scalar
mul r3, r3, r0 // multiply the thickness by the smooth normal
mul r3, v3, r3 // multiply by the normal offset
add r0, v0, r3 // add in the offset
mov r0.w, c9.w // swizzle in a one for the w value
m4x4 oPos, r0, c4 // transform the vertex by the model view projection

Cartoon Vertex Shader
Code:
// Cartoon vertex shader
// c9 is the light position
// c10 is the view projection matrix
// c14 is the view matrix
vs.1.1
// output the vertex multiplied by the mvp matrix
m4x4 oPos, v0, c10
// compute the normal in eye space
m3x3 r0, v3, c14
mov oT0, r0 // write the normal to tex coord 0
// compute the light vector
sub r0, c9, v0
dp3 r1, r0, r0
rsq r1, r1
mul r0, r0, r1
m3x3 r1, r0, c14 // transform the light vector into eye space
mov oT1, r1 // write the light vector to tex coord 1
// compute half vector
m4x4 r0, v0, c14 // transform the vertex position into eye space
dp3 r3, r0, r0 // normalize to get the view vector
rsq r3, r3
mul r0, r0, r3
add r0, r1, -r0 // add the light vector and the view vector = half angle
dp3 r3, r0, r0 // normalize the half angle vector
rsq r3, r3
mul r0, r0, r3
mov oT2, r0 // write the half angle vector to tex coord 2

Cartoon shading Pixel Shader
Code:
// Cartoon shading pixel shader
//
ps.1.4
def c0, 0.1f, 0.1f, 0.1f, 0.1f // falloff 1
def c1, 0.8f, 0.8f, 0.8f, 0.8f // falloff 2
def c2, 0.2f, 0.2f, 0.2f, 1.0f // dark
def c3, 0.6f, 0.6f, 0.6f, 1.0f // average
def c4, 0.9f, 0.9f, 1.0f, 1.0f // bright
// get the normal and place it in register 0
texcrd r0.xyz, t0
// get the light vector and put it in register 1
texcrd r1.xyz, t1
// compute n dot l and place it in register 3
dp3 r3, r0, r1
// subtract falloff 1 from the n dot l computation
sub r4, r3, c0
// check if n dot l is greater than zero
// if yes use average color otherwise use the darker color
cmp_sat r0, r4, c3, c2
// subtract falloff 2 from the n dot l computation
sub r4, r3, c1
// check if n dot l is greater than zero
// if yes use bright color otherwise use whats there
cmp_sat r0, r4, c4, r0
 

KoolSmoky

Member
KoolSmoky, vertex gets RGB colors (through lighting) from all lights. There are usually 1 ambient light, and 1 or more directional lights. Point lighting is not used in N64 games except Zelda MM.

My bad, I totally ignored that the lights have colors. Hmm okay, back to the drawing board.

-KoolSmoky
 

mdtauk

Zelda Hi-Res Texturer
Hyrule Field as an example, shifts its colours based on the Day to Night cycle, and that would be done through lighting.

Vertex colours are also used for the environments, for example in the Temple of Time, the vertex colours go to black to hide the ceiling.
 

KoolSmoky

Member
Hyrule Field as an example, shifts its colours based on the Day to Night cycle, and that would be done through lighting.

Vertex colours are also used for the environments, for example in the Temple of Time, the vertex colours go to black to hide the ceiling.

Thanks for the info. Well the thing is, I'm trying to figure out an easy way to render a cell-shaded look without using special hardware capabilities. Thought it would be cool to get this working on low-mid range gfx cards, especially the 3dfx voodoos. Just posting ideas with my late night caffeine boosted brain. :)

-KoolSmoky
 

mudlord

Banned
Hyrule Field as an example, shifts its colours based on the Day to Night cycle, and that would be done through lighting.

Most likely ambient lighting.

Although, I did see a lookup method for cel shading which indeed uses 3 colours instead of grayscale, and uses a similar process to Sami's method.
 

KoolSmoky

Member
Another late night shot at this. How about preparing 1D textures for each R, G, B lighting and blend them by addition? I may be missing something important again, but my ideas are;

1) Create a 1D sharp lighting texture for each R, G, B channel.
2) Use the lighting R, G, B values for the vertex to compute the coordinates for the R, G, B sharp lighting texture.
3) Disable lighting.
4) Draw the polygons and blend the R, G, B sharp lighting textures by addition.

The down side is that this requires extra 3 texture units or 3 passes on a single unit to get done.

-KoolSmoky
 
OP
Rice

Rice

Emulator Developer
KoolSmokey, a 3D texture is much easier.

mudlord, where did you see the lookup method uses 3 colours instead of grayscale? Can you post your link?
 

KoolSmoky

Member
KoolSmokey, a 3D texture is much easier.

mudlord, where did you see the lookup method uses 3 colours instead of grayscale? Can you post your link?

I agree 3D texture is much easier. Merely trying to get this working on my ancient gfx hardware that does not even support 1D texture :corpse:. Anyway, it would be nice to know how the lookup method works.

-KoolSmoky
 

Cyberman

Moderator
Moderator
I think I still have my old Voodoo3 3dFx card .. talk about memory lane 16M or 32M? hmmm can't remember I replaced it with a GFX3 (yes I have one of those ancient things).

Erstwhile the real problem with the old 3dfx hardware is mother boards that still support AGP cards. Mine was PCI so I suppose it's still usable.

I remember so little about the 3dfx hardware I'm afraid my knowledge is useless (LOL).


Cyb
 

Top