Author Topic: Physically-Based Rendering Guide for Freespace Open  (Read 20976 times)

0 Members and 1 Guest are viewing this topic.

Offline Swifty

  • 210
  • I reject your fantasy & substitute my own
Physically-Based Rendering Guide for Freespace Open
Introduction

Since about 2008, Freespace Open was given the capability for programmable shaders. With programmable shaders came per-pixel lighting which, for the most part, emulated the behavior of OpenGL’s adhoc lighting model. OpenGL’s lighting model has served us quite well and moving from the per-vertex fixed function lighting to per-pixel has breathed a lot of life into the engine. But as GPUs are getting faster and home consoles are getting more powerful, it’s time we looked into replacing this lighting model to take advantage of the unused GPU power our users are increasingly obtaining. Physically plausible lighting seems to be the trend this console generation and game engines are shipping with physically-based renderers.

In an effort to not fall behind modern game engines, I am proud to introduce physically-based rendering in Freespace Open. After finishing off most of the principal development of soft shadows and deferred lighting (which should hopefully be hitting trunk not too far into the future), I’ve transitioned most of my efforts into upgrading Freespace Open’s lighting model. This started by first introducing high-dynamic range rendering into the engine. Once that was ready, I went forth and crafted much more realistic lighting shaders that take advantage of the increased range of color luminance values.

Builds with physically-based rendering no longer use the legacy adhoc lighting model which was plagued with arbitrary terms and constants. Now, the engine is using a much more accurate lighting function based off of the Blinn-Phong lighting model and Shlick’s Approximation for Fresnel reflections. It’s not perfectly accurate and will likely require tweaking and additional changes in the future but I’d say it’s a pretty good start

This post will aim to introduce developers targeting assets for Freespace Open on how to best take advantage of the more realistic lighting in the rendering engine.

New Lighting Parameter: Gloss

A lot of modders in this community are familiar with specular power. Specular power is a parameter for lighting that determines the size of specular highlights. This parameter originally could only be set game-wide through a command line parameter called -ogl_spec. Now, gloss can be set per-pixel via texture mapping.

Though specular power was configurable, the behavior of the resulting highlight did not match that of reality. The overall brightness from the of the highlights lessened as the the highlight got smaller which doesn’t respect energy conservation for reflected light. Our new lighting model, however, accounts for this. In addition to specular power, gloss also controls the the size of reflections from environment maps via MIP map selection which is a very important visual cue for metallics and smooth objects.


(Gloss values of 0.0, 0.25, 0.5, 0.75 and 1.0)

Gloss has the subsequent effect of making surfaces look very smooth and shiny with high values. Subsequently, low gloss values make surfaces look rough and dull. Artist are encouraged to put a lot of detail into gloss textures. Much of the density of detail normally put into diffuse maps should instead be put into the gloss maps instead.

Gloss is stored in the alpha channel of Freespace’s Reflectance maps which will be explained in the next section.

Reflectance Maps

Reflectance maps are Freespace’s new specular texture format. Reflectance maps use the RGB channels for specular color while the alpha channel is used for per-pixel gloss. The RGB color channels are gamma corrected from the sRGB response curve into linear color space. Reflectance maps are defined by appending "-reflect" to the filenames of texture images.

Because the engine now uses a physically-based lighting model, specular color in reflectance maps should correspond to real-world specular reflectance values. When used in combination with diffuse maps, a wide range of real-life materials can be replicated.

Dielectrics (non-metal materials like rubber, plastic, cloth, stone, wood, etc), should have traditional diffuse maps while given very low specular monochrome color values in the reflectance map.


(A plastick-y looking Loki with a glossy finish thanks to a colored diffuse, low monochrome specular, and high gloss)

Metallic materials should be given a black or very dark diffuse map while given high specular color values; this is to simulate the fact that metals do not absorb or refract light but rather reflect all light. Metallics also change the color of their reflected light which means their specular colors do not have to be monochrome.


(Gold Ulysses created by having a black diffuse and specular reflectance colors for gold)

There are a variety of reference values available provided by the vendors of various commercial engines.

CryEngine (source)
Unity 5 (source)
Remember Me (source)

Deprecation Model for Shine Maps

Legacy specular maps, known as shine maps, are still accepted by appending “-shine” to texture maps. Legacy specular maps do not support gloss channels as the alpha channel is specified to attenuate environment map reflections. The RGB channels are not gamma corrected. A constant gloss factor will be applied to the corresponding model instead of per-pixel gloss.

Conclusion

This isn’t exactly the best guide on physically-based workflows but hopefully it’ll be enough for artists to get started. So tl;dr, things to remember:

  • Gloss is very important. Put a lot of detail into this.
  • Low gloss = blurry reflection. High gloss = sharp reflection.
  • Low gloss = wide, dull highlight. High gloss = small, bright highlight.
  • Reflectance maps should be used to take advantage of physically-based lighting.
  • Gloss lives in the alpha channel of reflectance maps.
  • Specular color lives in the RGB channels of reflectance maps and are gamma corrected from sRGB.
  • Reflectance maps are defined with “-reflect’.
  • “-shine” still works but you can’t apply per-pixel gloss with them and the RGB values will not be gamma corrected. If both -shine and -reflect are found, -reflect will be used instead.
  • When authoring a metallic texture map, apply black diffuse and high specular color. Specular does not have to be monochrome.
  • When authoring a non-metallic texture map, apply a colored diffuse and low specular color. Specular must be monochrome.
« Last Edit: April 19, 2015, 04:36:58 am by Swifty »

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Physically-Based Rendering Guide for Freespace Open
Builds incorporating this new behaviour, as well as a quick conversion for the Ulysses, can be found here: http://www.hard-light.net/forums/index.php?topic=89550
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: Physically-Based Rendering Guide for Freespace Open
This is just swell, I shall do my happy dance.  :wakka:

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Physically-Based Rendering Guide for Freespace Open
Since gifs are kinda poor for showing this off:

If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Luis Dias

  • 211
Re: Physically-Based Rendering Guide for Freespace Open
WOOOOooooooOOOOOOOOOOOO______OOOOOOOOoooo

 
Re: Physically-Based Rendering Guide for Freespace Open
Since gifs are kinda poor for showing this off:


Around 1:08 I think there's adjustment to the instantly-more-pretty slider. It goes from plain to insta-pretty.

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Physically-Based Rendering Guide for Freespace Open
Around 1:08 I think there's adjustment to the instantly-more-pretty slider. It goes from plain to insta-pretty.
That's the gloss override slider. Sliding it all the way to the right basically turns every surface into a mirror.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: Physically-Based Rendering Guide for Freespace Open
I've praised Swifty a lot on irc, but I feel it is important that everyone sees my all important praise to Swifty in public.

Swifty, you ****ing amazing wizard.
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 
Re: Physically-Based Rendering Guide for Freespace Open
o.O   Shiny  :D

 

Offline Kolgena

  • 211
Re: Physically-Based Rendering Guide for Freespace Open
What would you recommend as good parameters for colored glass? Do you think dark black diffuse + alpha with gold specular would work for the Pegasus/Ares/Erinyes to simulate instead of

(Same goes for Artemis cockpit glass)

And of course. Holy jeez this is wizardry. I guess the engine now supports materials. (Sorta, no subsurf shader, but that's only something mods could make use of)

 

Offline BirdofPrey

  • 28
  • Help! I see GIMP in my sleep
Re: Physically-Based Rendering Guide for Freespace Open
The first picture is actually silvered glass, not just colored glass; treated to be more reflective.

Are the cockpit canopies supposed to be like that?
The Great War ended 30 years ago.
Our elders tell stories of a glorious civilization; of people with myths of humanity everlasting, who hurled themselves into the void of space with no fear.

In testing: Radar Icons

 
Re: Physically-Based Rendering Guide for Freespace Open
They're not 'supposed' to be like anything, they're supposed to look good.
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Physically-Based Rendering Guide for Freespace Open
If anything, those canopies are supposed to be like the ones on the F-22 Raptor or F117 Nighthawk.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: Physically-Based Rendering Guide for Freespace Open
i.e. the same stuff as on the astronaut's helmet.
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline jr2

  • The Mail Man
  • 212
  • It's prounounced jayartoo 0x6A7232
    • Steam
Re: Physically-Based Rendering Guide for Freespace Open
SR-71 Helmet (windscreen, shown after, is clear):





F-22:










 
Re: Physically-Based Rendering Guide for Freespace Open
The gold coating visible in the third-last picture is just that: a very thin layer of gold. If you're trying to recreate it in the engine, treat it as such.
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline bkd86

  • 25
Re: Physically-Based Rendering Guide for Freespace Open
Are you going to need to bake AO into the diffuse or is the engine going to handle that?

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Physically-Based Rendering Guide for Freespace Open
Are you going to need to bake AO into the diffuse or is the engine going to handle that?
As I understand it, baked AO is going to become its own texture so you should not bake it into the diffuse.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline Swifty

  • 210
  • I reject your fantasy & substitute my own
Re: Physically-Based Rendering Guide for Freespace Open
Bake it into your diffuse maps for the time being if you can. The problem is with metallic materials as they usually have black or close to black diffuse maps. Then again, specular reflectance shouldn't really affect ambient diffuse anyway. I might introduce a separate map for ambient occlusion but I think I need to do a bit more research on ambient diffuse lighting.

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
Re: Physically-Based Rendering Guide for Freespace Open
SO
I decided to share some things I researched in terms of environment mapping. As the material is rougher,so gets the reflection it gives. Currently there is code in the shader which uses mip level 0 of the envcube at max gloss, and mip level 7 at 0 gloss. The gloss itself goes from iirc specpower 2 to 2048 (gloss goes from 0 to 1, and specpower = 2^(1 + 10*gloss)).
There is an old program called cubemapgen, originally developed by IIRC AMD, which allows certain operations on skyboxes. As it was abandoned, a modified version was made, which allows blurring the skybox using phong/blinn equation to precompute the way the skybox would be reflected at certain specppower of the material. I took my computation time to blur a sample saturn skybox at certain specpower levels to compare the results.

The input Skybox
Blur at 2^25 specpower, well beyond current gloss scale, no actual difference with input
Blur at 2^22 specpower, well beyond current gloss scale, minimal difference with input
Blur at 2^18 specpower, well beyond current gloss scale, stars are becoming blurry
Blur at 2^14 specpower, beyond current gloss scale, stars are too blurred to be visible
Blur at 2^11 specpower, current max specpower, blurry

The modified cubemapgen can be found at http://code.google.com/p/cubemapgen/downloads/list. It is a memory hog so don't give it skybox faces larger than 1kx1k each. It is also slow and literally takes hours.
Here is the sample skybox I used to generate the envmap http://www.mediafire.com/download/1yfj61pypwl8ca9/data.7z
Just to give some reference.
« Last Edit: May 03, 2015, 12:31:38 pm by Kobrar44 »
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/