Wednesday, August 18, 2010

LO-SL BRDF Additional Test Materials

As part of my test materials on my previous post about LO-SL BRDF, here are some more materials. The furthest 2 rows are from the older test(refer to previous post).  The 2nd to the closest rows, starting from left is matte finish, leather, rough wood, polished varnished wood and plastic. The closest row, opal, jade, ruby, clear glass and my default Phong-Blinn with a nice-and-easy specularity. My favorite material is the clear glass (2nd from the right, closest row), obviously I'm not doing any transparency yet. It seems to really simulate how light reacts to clear glass materials. You would notice that it seems that I'm only rendering a specular fresnel but if you look closely, after the fresnel shade there's a very thin line running a long the outline. It adds some realism or complexity on the rendering, which a normal fresnel rendering would never accomplish.

Currently, I'm using a 256x128 texture look-up tables. I noticed that N.V and Phi I+R can be reduced half of precision and would not make obvious banding. N.V makes sense to be reduced because we can only see the front hemisphere of the Normal according to the view.

Each of the material has a look-up table texture which is a 2 channels 256x128. All of these are then stored in a texture array and is used in the light accumulation pass in a light prepass rendering pipeline. The pipeline is running on view space data, considering how much we save on computing with this space. Each affecting light will react with similar light response and thus adds awesome almost-free complexities to the rendering. I'm really amazed how simple yet how much this technique contributes to the overall rendering. With a simple 2 texture sample taps, it does wonders! A W E S O M E!

Sunday, August 15, 2010

LO-SL BRDF Explained... (Part 2)

Time fly so fast... wheew. I've been so busy this month but as I have promised, here's the continuation of the LO-SL BRDF. Much thanks to Alberto Demichelis for giving me this challenging task even with some heated discussions along the way, but all for the sake of pointing me to the right direction.

The screenshot above is a material test running on our pipeline. I removed the ambient light and turned off any AO or postprocesses so its easier to see their light response. Currently, these are just directional diffuse+specularity as our requirement does not need realtime reflection so far. All of the objects are RGB(128,128,128) meaning real gray to purposely visualize the high, mid and low tone light response. The light is directional light with a white color RGB(255, 255, 255). The further 4 materials are actually simulating Blinn-Phong lighting model having the specularity size differences and some factor to simulate roughness. The nearer 4 materials are metals, (at least I tried to mimic). Starting from the left is rough iron, brushed metal (notice some anisotropic effect to it), copper, gold and chrome. Ofcourse, the effect will be much visible once normal mapping is applied to them.


What is Light Oriented-Spike and Lobe BRDF? It is a modified-simplified approach of the Bidirectional Reflectance Distribution Function so much so that it can be use for realtime-game application. It is not however, an exact math replacement of the full Oren-Nayer reflection model. Its goal is not to be precise but rather to just be convincing enough. In researching about photometry, I found out that there are different ways in gathering reflectance distribution data of different materials. Some plot the reflectance into a 3D or volume data. LO-SL BRDF simplify this volume of data by mimicking the values into 'strategicly aligned' 1D waves along the Normal (no tangents needed). This waves are then stored into a lookup table shrinking its math into a simple texture sample. The beauty of this is that, in possible future implementation this can be extended to doing away with waves and instead use curves or vector data for better plotting precision before they are save in the look-up table texture.

Here is a screenshot of the look-up generator for the LO-SL BRDF...


You'll notice in the right part of the screenshot are 4 groups of control values. Theta Incident, Theta Reflectance, Phi Incident+Reflectance and Specularity. Right now, the Specularity part is an anomaly in my implementation. I still have to research the actual relation of specularity in my implementation. (I'll be delighted if anyone can help me with this or even to point me to the right direction). You may also notice that it only deals with monochromatic distortions. Currently, this is only our requirement so we decided to only use monochromatic. Of course, tri-color distortion (meaning individual/independent distortions of RGB colors), example reflectance of bubbles or oil sheen in water, can still be implemented by storing 3 channels per angle. Plus we are saving the remaining channels for something special....a 'SS' special. (*wink**wink*). Each of these control values (except Specularity) represents the 1D wave slicing the full BRDF into 3 1D waves.

The control values are...
Theta θ - represents the angle with highest spike or the peak of the wave
- is the differential angle or range/size/cone angle of the lobe
C. Pow - is a pow function to steepen the curve
Factor - is the wave magnitude factor

You can also notice that the left part of the of screenshot are composed of 4 viewports. The upper left, is the preview. The rest are each channel of the look-up table. The upper right is the look-up table preview of  the Theta Incident and Theta Reflectance 'combined' together (will  be explained later). The lower left is the Phi Incident+Reflectance combined with Specularity. This one I'm still not convinced if my assumptions are correct on this. Previously, I separated the Phi I+R and Specularity as they are not possible to combine. So before they were in the lower left and lower right.

Combining these waves into a single 2D channel is possible due to its one important commonality... the Normal. The T or time of the wave/curve is Normal 0 to 1 (actual represents -1 to 1 of the Normal). Another relation is 'multiplication', so each of the result of the 1D wave are eventually multiplied together, hence we can pre-multiply it.

I know its quite confusing. I guess I'm not really good translating this into words. I need some sort of illustration for this. Anyway, to those who are still with me, here's the formula,

Theta Incident = N.L
Theta Reflectance = N.V
Phi Incident+Reflectance = V.(normalize(N-L))
Specularity = N.H (I'm still not sure to keep this)

Maybe in the future I can produce a study papers on this. Or maybe someone wants to offer me to write an article for their awesome highly anticipated graphics book. Yes? No? No takers? Oh well. hehhehe...

Monday, July 12, 2010

LO-SL BRDF Explained...

...sort of. As the screenshot persists, I'm still tinkering on BRDF. I turned off other effects including shadows so I have a better feel on what I'm doing. Its better to reduce our parameter control points, otherwise we'll end up alchemisticly mixing one variables or attributes to another (which I often do), the outcome is we less understand the result and we'll ultimately waste time. In my approach on BRDF, I use the same concept in breaking down this function into true realtime game application. Before I expound on this, I must explain first what BRDF is (as I understood it).

Bidirectional Reflectance Distribution Function or BRDF means, in its literal meaning, 2 direction composing how light reflection is distributed on the surface of a material. These 2 direction are light direction towards the surface, which is the 'IN' hence they call this 'incident light', and eye-to-surface direction or view direction, which is the 'OUT' or they this called 'reflectance'. Each type of material surface reacts differently with light. This reaction is more of a distortion of the light. Because of this distortion, we perceive textures and colors reflecting directly or indirectly from objects. If its a reflection of light, this means if the surface is perfect flat, the reflection can be off when it hits our eyes. Of course this perception is based from the characteristics of the light we use. You lit a red light, we see red light blending on the surfaces. A very good example is shooting a billiard ball on table sides, the direction of the force will determine how it will react on the side wall texture and will ultimately bounce after some energy distortion or absorption. And also by its result will show how far will the ball be off from the hole.


This diagram is based from Oren-Nayar reflection model. Here is a very informative link of a series of lectures regarding reflectance and other photometric phenomenon.


Now here comes the technical part. In order for a BRDF to be used in graphics rendering, typically, one would need the following, light direction, view direction, normals and tangents. Addition to that, we need to have the Theta and Phi of both Incident and Reflectance light as we are dealing with 3D angles called Solid Angles.

My implementation is composed of 2 ideas/theories in reducing the Function's complexities.

The first part is 'LO' or Light Oriented,  to reduce the required data, everything will be oriented to Phi Incident direction. With this, we do not need the tangents and (considering we do not care about subsurface scattering) we just add the Phi Incident to the Phi Reflectance. By doing so, we reduce 1D of the BRDF dimension requirements. We then assume that the Incident light on the Phi angle is perfectly aligned to the Oren-Nayar model. With the sum of Phi Incident and Phi Reflectance angles we still have almost to perfect similarity of light distortion/absorption as compare to the complete function.

The second part is 'SL' or Spike and Lobe theory. The standard illustration of 'light lobes' of this function is always against the light direction. In my theory, I use the functions lobe and spike but this time, not only against the light but also towards it. This lobe represents how much energy/light was absorbed and bounced by the surface before it reflects light.

This data is then stored somewhere, it can  be a N.L/N.H lookup table like in STALKER in GPU Gems or for Lafortune lighting model (using a matrix to mimic distortion of light). In my implementation I used the flattening of Phi Incident/Phi Reflectance, which I hope to explain on later posts.

So there you have it, Light Oriented - Spike and Lobe BRDF implementation.... (batteries sold separately). Kinda' neat-o-burrito aye?

Btw. regarding the screenshot. I just guessed the BRDF parameters hence the '?' on the labels. hehehhe

Friday, July 2, 2010

Fast Diet "LO-SL" BRDF


After a long absent from my blogging, I'm finally back for some graphics goodies! As you may notice in the screenshot, I'm doing some BRDF or Bidirectional Reflectance Distribution Function magic. This past few days I was in deep photometry(optics) waters... dived and almost drowned. Anyway back to the topic at hand, BRDF in a nut shell is a formula or process in understanding how light reacts differently to different material. Example is when a light beam hits a matte material such as leather, the light is diffused along the material, thus spreading the light into the surface. Compare this when you do that to a mirror, the light instead of being diffused it reflects the beam and you see a contrasting(not spread) lit in the mirror. Another example is when a white light hits a prism, it splits into visible chroma colors.

Now the tricky part here is implementing this to games. Considering so much computations are involved in BRDF, its likely impossible with our current technology to perform a full BRDF applied on a real-time game. Several games and game engines came up with tricks and simplifications to try to mimic this function.

So put it simply, this is my humble attempt in implementing BRDF into a real-time application. As of now, this screenshot is fresh from the oven. And right now, I cannot disclosed how I implemented this. (Need some permission from the big 'squirrel' guy, lolz). Anyway, I hope to follow up on this when the coast is clear.