Author Topic: Lux4SD - PBR shader for SD4 viewport  (Read 13659 times)

hd_


Hey all, I posted this as a reply in another topic, but I wanted to make a topic where Unity users will see it.

Lux is an open source physically based shader being developed by larsbertram1 on the Unity forums. You can see the topic here:
Lux for Unity Development Topic

To ease the workflow between Unity and Substance Designer, I ported the Lux shader to Substance Designer, so you can see what it will look like in Unity, from Substance Designer.
Grab the shaders for Substance Designer from github

Update:
14/Feb: You can now feed a custom diffuse and specular cubemap for the IBL (diffuse via environment map, specular via reflection map)
14/Feb: I added linear lighting support, so now it should look much closer to the Unity result than before (if you are using linear lighting in Unity).
Last Edit: February 14, 2014, 04:04:04 am

Thanks for the heads up!

Awesome work! Very helpful.
Integrations Product Manager / Training
wes.mcdermott@allegorithmic.com
Twitter: The3DNinja

We've got a workflow for using Skyshop (we've been in dev for a few months now, so our workflow is already established), and was wondering if this shader will get me closer to that workflow instead of the default substance designer shader. LUX uses roughness map embedded inside its spec alpha, while skyshop uses a glossiness map in that same alpha. I wonder if it would be possible to have a setting in the shader to flip the values in there, since roughness/glossiness are basically opposites. Just that simple change would make this shader much more useful to all Skyshop users as well!

Hope this is possible, keep up the excellent work!

hd_


Thanks Wes and Jeremie !

@contact_2
I have made the change, let me know if you get the expected results. There might be some other factors to consider though, depending on if skyshop expects glossiness as linear or gamma corrected.

Thanks for the quick response and update!

I will have a thorough look at it tomorrow, and provide feedback if possible. It is my understanding that Skyshop can work with both linear and gamma space. At least, for output it does. I am not certain if it expects input textures to be in one space or the other.

At any rate, I look forward to giving it a go.

Hello again,

Just gave that shader of yours a quick look-see, and I was wondering what the expected output node usage is? I currently output the following to unity:

diffuse
specular color (with glossiness inside the alpha)
normal

I was under the impression from the LUX documentation in the forum post that it expects diffuse, specular color (with roughness in the alpha) and normals. Since I am not sure what the actual used outputs are, I cannot tell for sure if the update you graciously made is working or not. Thanks, and I look forward to hearing from you.


hd_


Yeah it's just as you expect, when you make your graph and use Lux4SD, you should be using these output nodes:
-Diffuse (with 'diffuse' usage)
-Specular (RGB) Roughness (Alpha) (with 'specular' usage)
-Normal (with 'normal' usage)

If you didn't notice, you can go to the 3d viewport -> 'Materials -> Default -> Edit' and edit the settings exposed for Lux4SD. At the bottom under 'Skyshop' there is an 'Invert Roughness?' button (you might have to scroll down), that will simply invert the the alpha channel when it renders.

That way you put in only what you need for Unity, and the shader will render it as you should hopefully see it in Unity.

If you want to change which settings are enabled by default, then in the 'Lux4SD.glslfx' file (it's a simple xml file), near the bottom there are the gui options that you can change from true to false, etc.

Some extra things you can do are:
Linear Lighting:
Under 'Lux Setup' there is the option 'Linear Lighting?'. This is enabled by default. This option lets you get the same effect as turning from linear space to gamma space in the Unity Player settings.

Emissive:
You can use the 'emissive' usage output node to get light emission into your preview.

IBL:
Drag a panorama into the 3d view, select 'Environment' or 'Reflection', and then in the Shader settings under 'Lux Setup', you can enable 'Use Custom Environment/Diffuse Map?' and 'Use Custom Specular Reflection Map?'.

This will potentially let you see the same IBL you would get in Unity, if you feed the same images (I believe SD only takes panorama's though, so you'll need to convert from a cubemap or use the source image, etc).

Under 'Lux', there are settings to enable 'Diffuse is HDR' and 'Specular is HDR', however these don't react the same as in Lux yet. Leaving them off is usually better. The setting 'Diffuse Exposure', 'Specular Exposure' and 'HDR Scale' is associated with these options.

The 'Diffuse LOD' option is there if you don't use custom environment maps. When you don't use a custom map, the diffuse IBL will just blur the standard environment map, which will potentially create visible artifacts. Adjust this to reduce them.

Note: You will need to drag the panorama's each time you change material preview/model preview.

Gamma Method:
You shouldn't need to change this for Unity, but if you unselect 'Accurate', it will use the simple 'Pow(col,gamma)' approximation, where 'Gamma' can be selected from the slider.


I have no doubt that I will be able to get this all up and running when I get to it tomorow. I will keep you posted on things then, thanks again for your time and help, it is much appreciated.

I have been able to get some results out of LUX SD, but depending on the level of reflectivity, it is closer/farther from the same look inside Unity. I think the main trouble is that I don't have the same representation of the specular reflection map. I tried drag-and-drop into the 3d view as suggested, but I am also reading in the edit settings that the shader wants output nodes inside the graph of the reflection maps.

hd_


Both options give the same result. If you have the output nodes, you don't need to drag the maps onto the 3d view which can be more convenient, but it will clutter your graph.

I was getting an unknown error when trying to load this shader.

After looking through the log files to find the problem (Call to undeclared function 'textureCubeLod') and looking at the code for Substance Designer's built in PBR shader, I took a wild stab in the dark and added this line of code to the fs.glsl file just after the line #version 120.

#extension GL_ARB_shader_texture_lod : require

This seems to have fixed the error I was getting.  :)

hd_


Thanks for that !

I've updated it on GitHub.

Yay! Thanks for this :)
Now I just need to figure out how to use Lux.

hd_


It shouldn't be too difficult, there is an demo scene included with the package. The new topic for Lux is here, btw:

http://forum.unity3d.com/threads/235027-Lux-an-open-source-physically-based-shading-framework

One 'gotcha' to Lux is that you need one object with the setup script (like you can see in the demo scene), otherwise it works like any other material. Just pay attention to the formats expected for the inputs (in particular, the way the alpha channels are used on the diffuse, specular, etc).