#41135 - Locke - Mon Apr 25, 2005 9:37 pm
I've been trying to make a renderer using toon shading and textures, but all I get are textured, flat-shaded polygons. No cel-shading, no black edges around the model... (tested on ideas and real hardware)
I'm using this structure:
Code: |
glSetToonTableRange( 0, 13, RGB15(14,14,14) );
glSetToonTableRange( 14, 31, RGB15(31,31,31) );
glLight(0, RGB15(31,31,31) , floatov10(-1.0), floatov10(-1.0), floatov10(0.0));
glLight(1, RGB15(31,31,31), floatov10(-1.0), floatov10(-1.0), floatov10(-1.0));
glMaterialf(GL_AMBIENT, RGB15(8,8,8));
glMaterialf(GL_DIFFUSE, RGB15(24,24,24));
glMaterialf(GL_SPECULAR, RGB15(0,0,0));
glMaterialf(GL_EMISSION, RGB15(0,0,0));
glMaterialShinnyness();
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_TOON_SHADING );
glBindTexture(0, textureID);
loop
glNormal( );
glTexCoord2t16( );
glVertex3v16( );
end loop |
(Obviously, each sentence inside the loop is replaced with the adecuate data)
Is there any problem with my code or is it because of ndslib implementation? I tried to compile the toon shading example to see how it looks like, but all I get is a black screen... :(
Now, regarding lights, they alwais move with the model, it doesn't matter if I place them before any transformation of the modelview matrix, they rotate so I always get the face of my model lit...
And they can only be placed within the range [-1, 1][-1, 1][-1, 1] because of the v10 format (Am I wrong?) How can I place a light for example at (-1.5, 4.0, -11.0)?
Thanks for the help
Last edited by Locke on Mon Apr 25, 2005 10:38 pm; edited 1 time in total
#41139 - abigsmurf - Mon Apr 25, 2005 10:10 pm
Have you tried passing values to POLY_TOON_SHADING ?
It's hard to believe that there aren't any variables such as line thickness, colour etc.
This is coming from someone with a pretty basic knowledge of OpenGL though
#41144 - Locke - Mon Apr 25, 2005 10:41 pm
Oh, yeah, I forgot the firts two lines of the code (just added them). They are the different zones of shading... I think the line thickness is a standar value, and the only parameter needed is te toonTableRange.
But it was always in my code, so that's not the problem... :(
#41146 - ector - Mon Apr 25, 2005 10:55 pm
On hardware or emulator? The emulators are still very inaccurate.
#41148 - Locke - Mon Apr 25, 2005 11:03 pm
Both iDeaS emu and hardware. Same result...
#41161 - mike260 - Tue Apr 26, 2005 1:25 am
The problem is probably that you're over-lighting the model, so you're only get values from the upper half of the toon table.
The vector you pass into glLight isn't a position, it's the lights direction - you can only specify parallel (ie infinitely far away) light-sources. Therefore, this direction vector should be unit-length; if it's longer then lights will be brighter than intended.
So try normalising your light vectors, turn the brightnesses down and maybe start off with a single light. Being able to mess with light intensity using the dpad makes this process a lot easier too.
Edge-outlines don't automatically work when you enable toon-shading; the basic steps for switching them on are:
glEnable( GL_OUTLINE );
glSetOutlineColor( 0, colour );
glPolyFmt( your_other_params | POLY_ID(1) );
It's a bit more complicated than that but the above should get you started, let me know if you want more details.
#41182 - mymateo - Tue Apr 26, 2005 3:27 am
I wouldn't mind seeing a ds.gba file for download once you get something working. It would be really neat to see! Let me know if you need it hosted if you decide to do that.
#41197 - Locke - Tue Apr 26, 2005 9:06 am
mike260 wrote: |
The problem is probably that you're over-lighting the model, so you're only get values from the upper half of the toon table.
The vector you pass into glLight isn't a position, it's the lights direction - you can only specify parallel (ie infinitely far away) light-sources. Therefore, this direction vector should be unit-length; if it's longer then lights will be brighter than intended.
So try normalising your light vectors, turn the brightnesses down and maybe start off with a single light. Being able to mess with light intensity using the dpad makes this process a lot easier too.
Edge-outlines don't automatically work when you enable toon-shading; the basic steps for switching them on are:
glEnable( GL_OUTLINE );
glSetOutlineColor( 0, colour );
glPolyFmt( your_other_params | POLY_ID(1) );
It's a bit more complicated than that but the above should get you started, let me know if you want more details. |
Ok, that clarified things a bit. It still looks the same in iDeaS, but I'll try it on hardware in a few hours. I still have some questions left:
What is SetOutline id for? If it's for outlining only polygons with that ID, why I have to set POLY_ID to 1?
What is GL_TOON_HIGHLIGHT flag for?
Thanks for your help, I will be very grateful if you don't mind to give me some more details...
#41200 - mike260 - Tue Apr 26, 2005 10:40 am
Locke wrote: |
What is SetOutline id for? If it's for outlining only polygons with that ID, why I have to set POLY_ID to 1?
What is GL_TOON_HIGHLIGHT flag for?
Thanks for your help, I will be very grateful if you don't mind to give me some more details... |
What it does is, draw an outline wherever there's a border between two different IDs. The colour of the outline around an object is set by glSetOutlineColor, where if the poly has id X, you set its outline colour with glSetOutlineColor(X>>3,colour).
The reason you have to set the id to 1 is that the background has an id of 0.
Call glEnable(GL_TOON_HIGHLIGHT) to enable really ugly toon-shading - it seems to add some smooth on top of the toon lighting.
#41215 - Locke - Tue Apr 26, 2005 3:09 pm
Still the same result. No black borders, no shading (:(
If only someone can point me to some working code using toon shading and textures... It would be great
#41221 - Rinkwraith - Tue Apr 26, 2005 4:00 pm
Locke wrote: |
If only someone can point me to some working code using toon shading and textures... It would be great |
Never ran it but...
http://www.drunkencoders.com/index.php?system_id=1&page=Examples
Down near the bottom.
#41222 - Rinkwraith - Tue Apr 26, 2005 4:01 pm
Oh. BTW I haven't seen that many engines that can do both cell shading AND textures on the same model. Even on the PC.
Edit: if memory serves, most cell shading is implemented by using a type of texture to help set the boundries between colours. Using a regular bitmap texture and cell shading would seem to involve multi-texturing... are you sure the DS can do this?
#41223 - Rinkwraith - Tue Apr 26, 2005 4:11 pm
Got to learn to think about all of this before posting.
True hardware based cell shaders don't use a texture (I think)... but I still haven't seen many that can do it and still render a bitmap onto the object.
#41224 - Locke - Tue Apr 26, 2005 4:21 pm
That's the demo I tried and only got black screen. It doesn't use ink lines neither, so I can't have a reference on that.
Textured cel shaded is not so rare, nearly every cartoon game nowadays features that technique. (DBZ:Budokai, Naruto, Futurama, Zelda: WW, Viewtiful Joe...)
Here is an example:
http://jeux-france.com/images0_4_9400.html
#41225 - Rinkwraith - Tue Apr 26, 2005 4:29 pm
Pretty sure Zelda:WW isn't. But the others I don't know about.
Zelda's rendering is a bit odd - a lot of the screen doesn't seem to be cel shaded when you look closely. They've been very very clever.
Edit: If we're using the N64 as a bit of a benchmark of what the DS can do then I'd say we were lucky to get cel shading built-in. I'd love to see an example that proves it has the 3d power to compete with the kinda of graphics engines like the games you're taking about.
R
#41229 - dagamer34 - Tue Apr 26, 2005 5:36 pm
Rinkwraith wrote: |
Pretty sure Zelda:WW isn't. But the others I don't know about.
Zelda's rendering is a bit odd - a lot of the screen doesn't seem to be cel shaded when you look closely. They've been very very clever.
Edit: If we're using the N64 as a bit of a benchmark of what the DS can do then I'd say we were lucky to get cel shading built-in. I'd love to see an example that proves it has the 3d power to compete with the kinda of graphics engines like the games you're taking about.
R |
Models on the world itself often have textures. It's a lot more noticable that they also have cel-shading done on them if you have a light from a deku stick.
_________________
Little kids and Playstation 2's don't mix. :(
#41237 - mike260 - Tue Apr 26, 2005 8:32 pm
Locke wrote: |
Still the same result. No black borders, no shading (:(
If only someone can point me to some working code using toon shading and textures... It would be great |
Did you try disabling texturing? Because if it doesn't with with texturing off, it ain't going to work with it enabled either. Forget about textures until you've got the basics working.
Regarding edges, what colour's your background? Remember that since all of your model has the same poly ID, you won't get outlines where one part of the model is silhouetted against another part of it, but only where it's silhouetted against something with a different ID (like the background). So if your background is black then a black outline-colour is not too helpful.
If none of this works, take the ndslib toon-shading example and use that as a starting point; use it to figure out where you're going wrong.
#41248 - Locke - Tue Apr 26, 2005 11:17 pm
I finally got your toon demo to work. No shadows on iDeaS, but works really well on hardware.
After that I tried to add outlines with this lines just under the glSetToonTableRange statements:
glEnable( GL_OUTLINE );
glSetOutlineColor( 0, RGB15(0,0,0) );
And with POLY_ID(1) in my PolyFmt. Didn't work. Then I thought on adding a white quad with POLY_ID(2) just behind the model. I still have to try it on hw ('cos I don't have a flash and my beta-tester is not online right now xD ) but on the emu I only get white polygons, glColor and glColor3b seem to be broken.
Anybody else having this problem?
#41289 - The 9th Sage - Wed Apr 27, 2005 3:29 am
Locke wrote: |
I finally got your toon demo to work. No shadows on iDeaS, but works really well on hardware. |
I really need to figure out what I need to compile this interesting stuff one of these days.
_________________
Now with 20% More Old Man from Zelda 1 than ever before!
#41298 - Cleon I - Wed Apr 27, 2005 7:56 am
If you're on Windows, it's as easy as installing NDS Dev Env.
#41311 - mike260 - Wed Apr 27, 2005 2:04 pm
Locke wrote: |
I still have to try it on hw ('cos I don't have a flash and my beta-tester is not online right now xD ) but on the emu I only get white polygons, glColor and glColor3b seem to be broken. |
Emulation of toon-shading is going to be very inaccurate, and I don't think any of them even attempt to do outlines. So emulators are more or less useless for this, unfortunately.
#41328 - garlic - Wed Apr 27, 2005 5:43 pm
http://ideasemu.altervista.org/gfx/toon.gif
Might be in a build that isn't public yet. Unless my video card is the problem.
#41332 - Lino - Wed Apr 27, 2005 6:11 pm
It's an old screenshot and the toon shading on iDeaS is very approximate.
#41343 - Locke - Wed Apr 27, 2005 7:45 pm
Old screenshot? My iDeaS version can't do that... >_<
#41345 - Lino - Wed Apr 27, 2005 7:50 pm
With the last version 1.0.0.3?
#41348 - Locke - Wed Apr 27, 2005 8:05 pm
This is what I get with version 1.0.0.3:
http://img242.echo.cx/img242/4937/statue8ae.png
Although in hardware it looks fine.
I don't know it is my fault (probably), emulator's or because of ndslib, but i'm starting to desperate... :(
#41359 - mike260 - Wed Apr 27, 2005 10:08 pm
Locke wrote: |
This is what I get with version 1.0.0.3:
http://img242.echo.cx/img242/4937/statue8ae.png
Although in hardware it looks fine.
I don't know it is my fault (probably), emulator's or because of ndslib, but i'm starting to desperate... :( |
Don't get desperate, it's just the emulator. None of them accurately emulate the DSs toon-shading, plus they don't even try to emulate outline rendering. You *have* to be running hardware if you want to experiment with this.
#41371 - Locke - Wed Apr 27, 2005 10:45 pm
Ok, then I'll try to get a flash cart asap.
Sorry to have bothered you so much, all of you are going to be included in the "thanks to..."section of all my programs for now on xD
I'll be back with even more questions in a few days, beware!! ^.^
#41402 - Lino - Thu Apr 28, 2005 2:57 am
Locke wrote: |
This is what I get with version 1.0.0.3:
http://img242.echo.cx/img242/4937/statue8ae.png
Although in hardware it looks fine.
I don't know it is my fault (probably), emulator's or because of ndslib, but i'm starting to desperate... :( |
I do not use any GL extensions, it's very approximate for sure it but that is not the image i obtain.
#42094 - Locke - Thu May 05, 2005 8:56 pm
I got my DS Flash yesterday, so I ran some tests on harware and I'm not sattisfied yet.
Added textured toon shading, I fixed some problems regarding vertex normals, so shadows look better now (still buggy, they are far from perfect). But the real problem is still outlining.
I thought that the only lines needed where a initialization with
int poly = 1;
glEnable(GL_OUTLINE);
glSetOutlineColor( poly>>3, RGB15(0,0,0) );
and inside my loop, the following properties for the polys that I want to be outlined:
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_TOON_SHADING | POLY_ID(poly));
No outlines. Then I tried with a textured BG with this properties:
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 |POLY_ID(2));
Same result...
I think is something weird about this line:
glSetOutlineColor( poly>>3, RGB15(0,0,0) );
If poly is an int, then all polygons with POLY_ID lower than 8 will get outlined... Is that correct? Seems really strange for me...
#42097 - dankydoo - Thu May 05, 2005 9:59 pm
I think you are shifting the wrong way, I think you mean,
glSetOutlineColor( poly<<3, RGB15(0,0,0) );
which would make poly == 8
dankydoo
#42098 - mike260 - Thu May 05, 2005 10:03 pm
I think your problem might be glReset() - it resets what's enabled and what isn't, which will switch off GL_OUTLINE. All the examples call it at the top of their mainloop, so they lose a load of state every frame.
I just tried hacking outlining into the Toon_Shading example and it worked fine once I realised that I needed to say "glEnable(GL_OUTLINE)" every frame after glReset().
Hope this helps.
#42100 - Locke - Thu May 05, 2005 10:11 pm
mike260 wrote: |
I think your problem might be glReset() - it resets what's enabled and what isn't, which will switch off GL_OUTLINE. All the examples call it at the top of their mainloop, so they lose a load of state every frame.
I just tried hacking outlining into the Toon_Shading example and it worked fine once I realised that I needed to say "glEnable(GL_OUTLINE)" every frame after glReset().
Hope this helps. |
Really it did, I have all working correctly! Now I gess that if I want a polygon without outlines it need to have an ID greater than 7... (because of the ID>>3)
#42164 - The 9th Sage - Sat May 07, 2005 1:06 am
Locke wrote: |
Really it did, I have all working correctly! Now I gess that if I want a polygon without outlines it need to have an ID greater than 7... (because of the ID>>3) |
Cool...any chance of sharing? I'd absolutely love to see more examples of DS Cell Shading.
_________________
Now with 20% More Old Man from Zelda 1 than ever before!
#42167 - Locke - Sat May 07, 2005 1:44 am
I can say that it looks great (or nearly). But there is a problem. I'm planning to enter one compo next month with this project and I need to keep it private. :(
Sorry guys, but I prommiss to release the source for the 3d engine as soon as the deadline for the contest. May 30.
#42218 - The 9th Sage - Sun May 08, 2005 2:31 am
Locke wrote: |
I can say that it looks great (or nearly). But there is a problem. I'm planning to enter one compo next month with this project and I need to keep it private. :(
Sorry guys, but I prommiss to release the source for the 3d engine as soon as the deadline for the contest. May 30. |
Fair enough. :)
_________________
Now with 20% More Old Man from Zelda 1 than ever before!