Inside3D!
     

How to make DP render flat-shaded?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Wed May 05, 2010 5:54 pm    Post subject: Reply with quote

gl_smoothmodels looks bad though. It applies one vertex's colour over the whole triangle. But you don't want the colour of a certain arbitrary vertex, you want lighting according to the triangle normal. glShadeModel is probably just another one of those holdovers from the 1991 days of OpenGL that nobody should ever use (like the old "lighting" functions).

By the way, I checked and the QWalk argument is "-facet", not "-facetize". And I'm not sure if it's available in the build of it, you might have to compile it from SVN. And for some reason when I processed and resaved armor.mdl it lost the rotate flag... so maybe I should take a look into QWalk for the first time in months.

I'll also get on that MDL utility today.
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Wed May 05, 2010 7:03 pm    Post subject: Reply with quote

how to not mark triangles to not smooth lighting over edges: create a separate copy of the vertex just for that triangle.
Do NOT merge duplicate triangles.
And then hope that the engine doesn't merge identical verticies...
Yes. This means triangles will no longer have any neighbours which will make stencil shadows slightly slower.
I don't know what tools there are that allow splitting them up.
-facet sounds appropriate.

glShadeModel(GL_FLAT) is useful for software implementations, or where you're too lazy to specify different colours for each vertex.
like so much in the world today, it sucks.
Like sajt says, in this case, it'll pull out the colour of a vertex facing in one direction and assume the entire triangle should get the same lighting. But that vertex direction is the average direction of all the triangles that are connected to that vertex, not just the current triangle, so will give random colours on an otherwise regular cube.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Wed May 05, 2010 10:05 pm    Post subject: Reply with quote

Seems odd to me that this spawns such complicated discussion. I've always viewed it as faceted illumination is simpler, and smoothed is a step further, requires additional code and computing or whatever. I remember modeling in Milkshape3D on my old Pentium 200mhz and having to use flatshaded because the smoothed rendering was too slow.

Yes, I'd prefer if LH or someone else on the team simply reinstated or added this, it can't possibly be a hard thing to do :S

I didn't manage to find another cvar which did the same thing in DP.

Here's an example, the image is even called flatshaded.jpg Razz

I'd obviously want it to still be textured just like normally. Flatshaded doesn't have to mean vertex-colored or whatever.
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Wed May 05, 2010 10:27 pm    Post subject: Reply with quote

The way hardware rendering works (using vertex arrays) is, understandably, not built with fast flat-shading in mind.

A triangle is defined as three vertex indices. A vertex can have attributes such as position, colour, normal, etc. The triangle cannot contain separate "vertex position" and "vertex colour" indices. When you run a shader, first the vertices are set up, then the fragment shader is run interpolating vertex values across triangles. It's not set up for "triangle attributes".

The only way it could be implemented on the engine would be:
- To split the vertices up at load-time, the same thing that an offline model tool would do, resulting in 3x as many vertices as triangles.
- Draw models not using vertex arrays, which is much slower.
- Possibly some complicated shader trick which could hack in "triangle attributes", but at the cost of speed (both batching overhead and fillrate would suffer).
- Maybe there is some brand-new feature in DX10 or DX11 which allows triangles to have indices to different attributes? I don't know if it would be worth it, if they did...

The fastest solution is the brutest: to give each triangle its very own vertices. Even if those vertices are in the same position as other triangles' vertices, they can have different colour/normal attributes. Yes, you end up with more vertices than you think you should need, but flat-shaded games are usually low-poly anyway so it shouldn't matter.
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Sat May 08, 2010 10:46 pm    Post subject: Reply with quote

http://www.icculus.org/qshed/fixmdl/FixMDL-0.1-ALPHA.zip

Urre, try this pre-release version of FixMDL. It has a "facetize" feature which should work. Although I haven't tested it much (that is, more than once, right before uploading).
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Sun May 09, 2010 10:54 am    Post subject: Reply with quote

Seems to work great, thanks! Not sure if I like the effect enough though.
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Sun May 09, 2010 4:38 pm    Post subject: Reply with quote

Hehe. The preferable thing would be to half-flat-shaded... like select in a modelling app which edges should be "hard" and which not (I think most programs call this smoothing groups). Then for example, for a wheel, the flat part around the tire (with the tread) could be smooth, but the seam between the sides and this could be hard...
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Sun May 09, 2010 4:43 pm    Post subject: Reply with quote

Well, with the ass-backwards facetize method it's easy to have that Smile
Back to top
View user's profile Send private message
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Mon May 10, 2010 12:13 am    Post subject: Reply with quote

Sajt wrote:
Hehe. The preferable thing would be to half-flat-shaded... like select in a modelling app which edges should be "hard" and which not (I think most programs call this smoothing groups). Then for example, for a wheel, the flat part around the tire (with the tread) could be smooth, but the seam between the sides and this could be hard...


True, that'd be cool. No can do with good ol' QME :/
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
leileilol



Joined: 15 Oct 2004
Posts: 1321

PostPosted: Mon May 10, 2010 12:42 am    Post subject: Reply with quote

If you use Blender, just turn on the Edgesplit modifier, select the edge angle to be 0 (for ALL edges to go flat) then apply. FACETIZED!
_________________
Back to top
View user's profile Send private message
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Mon May 10, 2010 12:44 am    Post subject: Reply with quote

Yes but blender is a real modeling app, I forgot how those work a long time ago.
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Mon May 10, 2010 3:26 am    Post subject: Reply with quote

To tell you the truth, I had planned for an edge-faceting feature in the QWalk model viewer. You would be able to just select and deselect edges with the mouse to make them sharp or smooth. It would not be difficult (still a day's work though), you don't need any UI or 2D views. But I'm kind of sick of this sort of thing by now...
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Mon May 10, 2010 4:44 am    Post subject: Reply with quote

Well, I'd love it for one Razz

I plan to make more low-poly games using mdl's, so it'd likely come to use.
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Mon May 10, 2010 5:31 am    Post subject: Reply with quote

If you were looking to make sleek, almost vector-graphic-like games, as it looks like your car game is going to be, then MDL seems like the wrong choice... just because it will screw with nice, smooth shapes and round curves. Smile
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group