GLSL PBR Shader for viewport

@hypersomniac: This is really great work! Have you seen the work being done in the GOSC viewport branch, I think your work might fit nicely there. Why don’t you join the devs on IRC and see how both projects can merge together.

Sorry for being sillent for a few days. I’m still working on this!

The next build will have a lot of improvements but is still some days away.

@NinthJake : Linux build are not portable by default so unless you have the same libs as me it will surely break. I’ll investigate this later. I prefer to concentrate on feature now.

@Samir_osman : I’ll see what i can merge in the trunk with the devs after everything is completed.

Great work :wink:

I know it’s been a while since the last post on this, but I’m curious how things are going on this. This seems like an incredibly useful tool for game development so I hope it’s still being updated!

hell yes! Make it happen!

Very interested in seeing an update when you have time

Hypersomniac- Are you aware of current status of viewport fx? Psy-fi and jwilkins are working on it now under “viewport experiments” branch.
https://developer.blender.org/diffusion/B/repository/viewport_experiments/

Maybe you can contribute to this branch? Writing viewport extensions will be much easier when viewport fx is finished. This things are going to master in next few months. Eventually every blender user will benefit from your shader if you decide to work with guys behind new viewport. :slight_smile:

^^^ +1 +1 this needs to be included in blender

LordOdin, you are not joking - this is the kind of thing that could take the texture paint and material prep for game right up there

Very sorry guys about not keeping track of the progression of this project.

I’ve basically worked on this half time for more than 1 month. I have setup a github repo so anybody can compile my build. I have not pushed all the work yet to the repo. I’m reviewing the code and formating it. Memory leak issue are here and I’m dealing with it.

I achieved to integrate cubemaps to the viewport. You can use the Environement texture with a texture with File option selected but the mapping vector for the reflection is not correct.

Cubemaps give better looking result so each map is converted to a cubemap before being used by the shader.

I was not satisfied with the previous result in both efficiency and quality.

So I tried to get more close to my cycles reference. Using noise pattern to disturb the reflection we can use higher mips when sampling for low roughness and then be more accurate. This technique add a grainy look but the grain amount is IMHO not perturbing with textures applied to a model even with 32 samples. That being said it’s a bit more expensive than the previous technique. Even though you get great result you still lose some light information specially the small lights due to the mipmaps.

For a more performance oriented technique I went for the split sum approximation from Epic’s Unreal Engine 4. The mipmaps are precalculated by choosing Pre-filtered setting in the shader and clicking the refresh arrows. For the moment the Undo (Ctrl Z) command is purging the filtered version (i’m working on that).

I found out that Opengl does not interpolate between mipmaps when using textureCubeLod with a non integer value (DirectX does it with SampleLevel). So I’m mixing between the 2 nearest mips. That means there is in fact 2 times more texture samples than what is written in the node.

Here is a chart with the diferent techniques. I’m using the last 2. The roughness goes from 0 (left) to 1 (right) by 0.2 increments.


As you can see the other methods give bad and incorrect result with low roughness. But neither method is perfect.

I decided for simplicity reason to stay with one node and just leave multiple outputs.

I’m giving you a TEST FILE with one of my model. It should look like this.


So to sum up the new “features” :

  • You can plug a mapping node to control the envmap rotation.
  • You can use your Cubemap captured with blender. (Cubemap should be in blender conventional orientation).
  • More “accurate” but grainy Image based ligthing.
  • You can prefilter the cubemap and have “better” light approximation. (This calculation is multithreaded)
  • The normalmap node works for all type of normal maps (objectspace, worldspace, tangentspace).
  • The Spherical Harmonics are weighted by solid angle and more accurate.
  • A fresnel input let you tweak the fresnel effect intensity.
  • An input to tweak the power of the envmap.
  • An energy conservation checkbox (should be turned off but in case you need it, it’s here).
  • Horizon fade factor.

Todo list :

  • I plan to add a progress bar for the filtering and avoid freezing the UI :D.
  • Add mirror ball support.

WARNING

I have not tested on any other computer so things might fail with other graphic hardware.

The github repo is up! So i encourage you to build this branch, test it, and give feedback. I’ll provide windows x64 tomorrow.
If you can build for linux popular distros (ubuntu, fedora…) I also encourage you to post a link to your build and I’ll update the first post with your build.

Please report bugs to Github.

Concerning the future :

I still have features I would like to implement. I have reach a point where the core implementation is done so I’ll talk to the guys of the viewport fx branch to see what we can do.
Keep in mind that this initial implementation is still rather crappy in the inside from a coder point of view.

I hope psy-fi and jwilkins help you with this. Great work! :slight_smile:

I’ve updated the download link for the new version in the first post.

Please test it!

Woo…Working stable & great for a first easy spin using test file. Plays Lovely… so f***ing great man!
Thank you and a wish, if not hard to implement, noise to have an arbitrary input (to use less for play and more for finals)?
Calculations are a bit slow on GTS450 1GB (less than a second for a shader & a few more for ibl… as expected). Will test more.
Just amazing :slight_smile:

Edit:
Noticed your object hadn’t had Rotation applied (was 90°) & after lighting changed (normals?)… so what to do to be correct again?

The object uses object space normal map so yeah applying the rotation will have undesirable effects.

If you are talking about changing parameters then it’s normal as the node tree is re-executed by the Cpu before sending the shader to the GPU. So i will be “slow” even with good Graphic Cards. For the Ibl it’s longer because it re-compute the cubemap and Sh derived from it. The prefiltering depends on the CPU too and can take up to 1min with 6 thread @ 2.8Ghz on a 2k*1k Equirect map.

I already found some bugs in my build like Spherical harmonics that doesn’t recompute and some vector orientation that are false. I’m correcting that right now.

WOW!!! just get to this be a friends link

does this “Stuff” works using the current Opengl version that trunk blender uses, i guess its ¿OpGl 1.5? (im not a developer, just an standar user)

This is looking at working amazingly! Going to have to do some test runs with this soon! :smiley:

Will it work for OS X?

@lich : it’s a custom build. But the opengl version required is a bit higher than the stock blender. I think it might be Opengl 2.0.

@Beardbotnik : Thanks :). Don’t hesitate to post some of your test here.

@beep : It should. But you have to compile my branch. I have not tested and I don’t have any feedback from OSX users.

To everyone :

The current build still have some issues like the normal map node doing strange things. I have also some hard time figuring what goes wrong with texture color correctness in the viewport. I need to find time to fix theses and commit.

Great work! I have a few questions though - does the shader have shadowing, or is shading and reflection based purely on surface direction in relation to the cube map? Also, will this ever support reflection between actual geometry i.e. one suzanne reflecting another?

The shader support shadowing for light but does not for cube map reflections. If you want shadowing from the cubemap use Cycles and bake the shadows.

The reflection between actual geometry will be supported eventually, it is called screen space reflections.