qbism / q2tools-220

Quake 2 map compiler tools with v220 map support, automatic phong, enhancements, and fixes.
GNU General Public License v2.0
61 stars 20 forks source link

Generate and store vertex normals in .bsp for smooth (phong) shading - possible ? #17

Open motorsep opened 2 years ago

motorsep commented 2 years ago

Since Q2RTX doesn't use lightmaps, currently it's not possible to have smoothed (phong) shading in Q2 maps.

Could you please add such functionality, if possible, to 4bsp? It would need to generate and store vertex normals somewhere (in the vertex lump?) in .bsp file.

Q2RTX dev will add support for that, if he has something to work with. Thanks!

Paril commented 2 years ago

I'm thinking the approach we'll be taking with another tool is to simply use an unused surface flag (0x400000 maybe?) to represent "this surface was compiled with phong", which would allow RTX to handle as appropriate to reconstruct the normals. The other option is to have qbism and other tools export a normal map, similar to a deluxemap, which RTX could use instead of reconstructing the normals.

qbism commented 2 years ago

How does Berserker Q2 do it? From overview.doc:

To improve the quality of the lighting of the map and its parts (brush models), inter-vertex smoothing is applied taking into account the mutual inclination of the planes. If the angle of intersection of two planes is close to 180 degrees (+/- angle, which can be changed), then we perform the smoothing of the TBN-basis of vectors (Tangent, Binormal, Normal) for them. Visually, it looks like this: berserker-phong

motorsep commented 2 years ago

@qbism I think it's all done in the lighting stage, but I am no pro in this subject 😊 Paril would probably have more input about that.

Paril commented 2 years ago

Yeah it's not really difficult implementation wise, phong has been a feature of lightmap pers forever, but the hard part is delivering the raw normals/tangents to the engine which rtx will need.

The main rtx dev (AlexP) , ericw and I discussed options (doing it at load time, surface flags, external normal map..) and we think BSPX is our best option. It's basically an extension footer that allows an existing bsp to add additional lumps without breaking the format. This would allow q2bsp and qbsp to do the phonging in the lightmap as usual, and the additional lump would be picked up by rtx for the additional data, without the maps not working in other engines as normal.

On Wed., Aug. 25, 2021, 9:50 p.m. motorsep, @.***> wrote:

@qbism https://github.com/qbism I think it's all done in the lighting stage, but I am no pro in this subject 😊 Paril would probably have more input about that.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/qbism/q2tools-220/issues/17#issuecomment-906011072, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJLAHX4OWBJUR3IFBEM5HTT6WMV5ANCNFSM5CZTDHRQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .