Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Lux-an-open-source-physically-based-shading-framework

Discussion in 'Assets and Asset Store' started by larsbertram1, Mar 19, 2014.

  1. dnnkeeper

    dnnkeeper

    Joined:
    Jul 7, 2013
    Posts:
    84
    Hey lars! Your project changes Unity graphics dramatically. But I've been thinking how to push it even further and stumbled upon Atmospheric Scattering project by Scrawk (based on Proland open-source project). I managed to re-write it and make an image-effect for Unity that can be easily attached to any dx11 project. Now I'm wondering how this can be combined with Lux materials... The ultimate goal is to have diffuse and specular computations in realtime. Our approach has a pretty efficient function for sampling sky color from the precomputed tables and I managed to apply precomputed diffuse lighting but I'm not sure if it's fast enough for getting blurred samples required for specular on rough surfaces. Another way is to calculate cubemaps per object instead of sampling environment per pixel. I'm not fully understand how does cubemaps precomputation work in your project so I can't answer myself if it is possible to make cubemaps generation realtime (semi-realtime) using gpu. If you could direct me I would dig it in my spare time. Sources are open and free (in attachment, DX11 DirectCompute required).
     

    Attached Files:

    ksam2 and Baldinoboy like this.
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hi dnnkeeper,
    i am on mac so no dx11 here, but your project looks pretty promising.
    as far as gpu powered specular cubemap convolution is concerned: charkes did a pretty good job on this.
    simply google/search for antonov suit and you should be able to find his git.
    nevertheless i do not think that you can do it in real time. so may be you will have to blend between e.g. 8 different presets like assassings creed black flag does for its gi.

    lars
     
    Eric2241 and dnnkeeper like this.
  3. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    Wouldn't that be possibel wit some variant of Radially Symmetric Reflection Maps? it seems llidke its rather uniform on some aspect
     
  4. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    Hi guys I just started using Lux and can already see the potential. I am not an artist but I am handling the art in my project for the time being so I have a few noob questions that some of you might answer for me.

    I understand more or less how the different maps work but not being an artist myself I am having a hard time understanding some basic PBS concepts. For instance when someone says set the rgb value above 0.5 for a certain texture how exactly would I do this. I use gimp for my texturing so a reference there would help. I am just not understanding where to find the general rgb setting. I have googled this many times but am still not able to find a simple answer. I just can't seem to find anywhere to set an rgb level such as this.
     
  5. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    It depend which map you are talking about. It's less artistic and more technical, being an artist can make it actually harder to understand :)

    Albedo (color for profane) is actually the reflectance value, that mean the quantity of light reflected back to the viewer under ideal lighting. As such you need to know the measure of the material, or guess it along the bound of real world value (charcoal and snow). To add difficulty you must know if your texture is in linear mode or gamma (srgb). The best practice is to hunt down some reference and pick reference colors then blend them to create new color that don't go out of bound.

    If you are using a spec pipeline, you can't cheat with the data, hunt and store given data, generally organize along two class metal and non metal, non metal if you don't know the data you can use a default of 0.04 (however non metal are all in the range of 0.017 to 0.067). Find reference and store them.

    note: fractional number is about a range of 0-1 instead of 0-255 in linear. To get the data back into the usual 255 range you simply multiply the fractional data by *255 (example: the default spec for dielectric is 0.04*256 = 10,24, in your example it is 0.5*256=128).
     
  6. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    Look at these link they give you data reference:
    http://www.marmoset.co/toolbag/learn/pbr-practice (the number under each material preview)



    In fact Google "pbr cheat sheet" give you some common one

    You can also find good PBR map you know have correct value and sample them to create your own pallette

    In truth the hard part is not to mess up the linear/gamma confusion when looking at data. So double check that.
     
    Baldinoboy likes this.
  7. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    In case you are meaning how to find the actual number value of the texture than I will show you a way.

    Open the texture in GIMP and then go to Colors - Threshold


    That will show the values of your texture


    As they said above 0-1 is 0-255. So the middle which is what will show up as 127 is .5. As you see my texture is mostly below .5. Mainly the mud part. The leaves and sticks are showing up in the higher value. You can drag the point higher or lower just to see exactly what is the brightest and darkest. Just cancel out of this window as we are just using it as a guide.

    To brighten or darken the texture go to Colors - Brightness Contrast. If you want a little more control over the color then you can go to Colors - Hue Saturation.

    Hope that helps some. Post some screenshots of your project in Lux soon. Like to see them.
     
    Last edited: Dec 25, 2014
    Eric2241 and ZJP like this.
  8. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    @Baldinoboy Thank you so much!

    That is exactly what I was looking for. There are so many parameters to change and fiddle with I was at a loss as to which one to actually pay attention to. Thanks for taking the time to show me that and for showing interest in my project. I have gotten swamped learning the new PBS workflow over the last few days but I about have it down. So much better looking already and almost no performance impact! I should have some new visuals up in the next day or two.
     
  9. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Cool man. Glad it helps. Here is a video that helped me some when it came to understanding PBS. I believe Lars linked it earlier in this thread. Good video to watch a few times.



    Definitely use the pbr cheat sheets like @neoshaman said. I believe Lars still has one in the Lux folder. They are needed guides.

    Remember to post some screenshots of PBS Dinosaurs when they are hatched;).
     
  10. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    I download Lux skin for the unity 5 and i'm really really disappointed that there is no parameter to changing diffuse color
    So how can I make it darker? I can make the standard shader darker to fit with my scene but can't do the same with Lux because it doesn't have any option to changing diffuse color
     
  11. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    To truly be physically based among many things the Albedo(PB diffuse) value should be correct in value. There should not be any more inputs other than the texture slots. I am actually really disappointed with the Standard Shader because of the shininess slider. That is what the legacy shaders are for. Except for the detail texture amount there should not be any other value changing. Not sure if anything has changed as all I have seen is the video for it.

    To make the texture darker bring it into Photoshop/GIMP and edit the brightness as needed. Export it back and it should work.
     
    Last edited: Dec 28, 2014
    ksam2 and Eric2241 like this.
  12. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    I don't understand why you can't add a parameter for changing diffuse color!
    I can't edit all of my textures in the Photoshop, there have to be a parameter for this purpose
    I'm using lots of image effects and bloom and other stuff
     
  13. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    you know that you can add those parameter by yourself if you really need it.

    The shininess slider became obsolete if you put a texture in the Spec Texture slot, kind of overriden by the texture. Not sure how it behave in the early beta, but that's how it is now.
     
    Last edited: Dec 28, 2014
    ksam2 likes this.
  14. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    Keep getting this error whenever I try using a transparent shader?

    Shader error in 'Lux/Transparent/BumpedSpec': failed to open source file: '../LuxCore/LuxLightingDirect.
     
  15. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Awesome. Thanks for letting me know.
     
  16. TrollHachem

    TrollHachem

    Joined:
    Dec 25, 2012
    Posts:
    65
    There are some problems with the Probe Creator,

    I tried changing the path in the scripts to use Assets/etc... , It gave the same error...
    I'm using Unity 4.6.0 Free
     
  17. TrollHachem

    TrollHachem

    Joined:
    Dec 25, 2012
    Posts:
    65
    Make it : .././LuxCore/LuxLightingDirect.cg (just add ./ after the ../)
     
  18. Arkham

    Arkham

    Joined:
    Dec 16, 2013
    Posts:
    9
    Like a couple of people that posted earlier, I am also trying to import a metalness/PBR-centric project from Substance Painter into Unity via the Lux metalness shader. However, I am having trouble getting it to show up in Unity properly, as seen below:

    pbr_help.jpg
    The Diffuse and Specular cubemaps are the default ones that come with Lux (sky_cloudy_free). The second texture does properly have each channel assigned correctly (AO in Green, Roughness in A, and R is all black since the metalness is 100% for this object). Only thing that stumped me was the inclusion of "Spec (B)" since as far as I know this workflow doesn't include a specular texture; nevertheless, changing this channel (from 100%/white, to 50%/gray, to 0%/black) appeared to effect no changes. Nothing I've changed thus far gets me even reasonably close to the asset's appearance in SP.

    I'm a bit stumped on what else to try tweaking next. Is there something obvious I'm missing?
     
  19. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey Arkham,

    You need to have the Setup Lux script in your scene. Add the script to a gameobject. Use this script to set your cubemaps. I believe they are HDR so set them to that. Remove the custom cubemaps from the material. With this setup the specular(aka reflections) will show up. Specular uses the cubemaps for reflection.

    Hope this helps.
     
    Jaqal likes this.
  20. 0tacun

    0tacun

    Joined:
    Jun 23, 2013
    Posts:
    245
    @Arkham: Another point to look into is if you use gamma color space, since it looks like the speculars are wrong. You need linear color space to fully utilize PBR . I think you can only activate it in Unity 4.3. If you are using a higher version you have to do the gamma correction in the shader. Here is one result, both in Unity 4.6, right picture with gamma correction:
    https://www.dropbox.com/s/2pejkgugcib8yoq/skin.png?dl=0

     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hi arkham,

    your results might be caused by a lot of different reasons like e.g. wrong texture import formats or wrong cubemap settings (ldr/hdr).
    as far as i can see: you do not get proper ambient specular reflections so most parts of your model are just black.
    so have a look at the ao and the specular cubemap.
     
  22. EddieLopes

    EddieLopes

    Joined:
    Apr 19, 2014
    Posts:
    11
    Problem of terrain multipass banding solved:
    before:
    upload_2015-1-2_12-20-9.png
    after:
    upload_2015-1-2_12-23-51.png

    Soon I'll commit in my git.
     

    Attached Files:

  23. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    I don't know if it is already mentioned since I normally use the U5 shader, but:

    LuxCubeProcessor.cs
    the last #endif needs to be before the last }, not after

    LuxEnvProbe.cs
    many methods need UnityEditor namespace for SerializedObject
     
  24. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Have you got it working in Unity5 beta ?
     
  25. Arkham

    Arkham

    Joined:
    Dec 16, 2013
    Posts:
    9
    Thanks to all who offered answers on my issue earlier.
    I put this off for a while and tried to get Shader Forge to work for this, but I ran into a blocking issue with that eventually, and have not been able to get help from SF's author. After getting frustrated there, I returned to this and managed to get it working reasonably well for that candlestick (plus two others).

    Currently, I'm a bit stymied on getting the HDR cubemaps to work with the Translucent shader for a set of wax candles, however. (I think it's the shader, anyway.) If I use LDR cubemaps, these candles look more or less correct (perhaps even a tad bright); but if I use HDR cubemaps, the wood and metal candlesticks all look correct, but the candles look very dim. Any idea what I might be missing here?

    lux_HDR.jpg
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    have you grabbed the latest version from github?
     
  27. Arkham

    Arkham

    Joined:
    Dec 16, 2013
    Posts:
    9
    Just checked github, and it looks like only one file has been changed since the last version I installed (LuxEnvProbe.cs in the Lux Cubemapper folder). Updated that one file, but it's not making any difference as far as I can see.
     
  28. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    Someone know how unity store light so I can use them for Vertex shader?
    I heard that it accumulate non important light in a SH to apply at vertex time, and the 4 most important light into a structure.
     
  29. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Check UnityCG.cginc , there's a function for that
     
  30. tynew

    tynew

    Joined:
    Sep 25, 2013
    Posts:
    122
    Whats better, LDR or HDR for cubemaps? How do I go about creating a HDR cubemap?
     
  31. Prosto_Lyubo

    Prosto_Lyubo

    Joined:
    Aug 15, 2013
    Posts:
    18
    Hi!
    I really like Lux and it's capabilities but I think I am doing something wrong. I am struggling with this for two days now and I need Your help because I run out of ideas.
    Here are two cubes. Both have:
    Metalness: 0.8
    Specular: 0.8
    AO: 1
    Enabled diffuse IBL Cube
    They differ in roughness.
    LuxRoughnessProblem.jpg
    Roughness parameter works fine for light reflections but doesn't affect reflections generated from Cubemap. What should I do to make it work correctly?
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    @prosto:lyubo: does your specular cubemap have proper mip levels?
    i guess it does not.
    and your diffuse cubemap is incorrect too i would say.
    so you may use the lux cubemapper to convolve your diffuse and specular cubemaps.
    important: please make sure that you use a rather low resolution on the specular cubemap (like 64x64 or 128x128px). otherwise it will take years to convolve the cubemap.
    for the diffuse cubemap a resolution of 16x16px is enough.

    you may also start just using the cubemaps that come with lux.
     
    Prosto_Lyubo likes this.
  33. Prosto_Lyubo

    Prosto_Lyubo

    Joined:
    Aug 15, 2013
    Posts:
    18
    Checking the "MipMaps" checkbox for my cubemap in inspector did the trick. Thank You very much for help and Your awesome work!
     
  34. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi there Lars,

    Shader forge have a PBL mode that includes fresnel, pixel accurate spherical harmonics and energy conserving Spec/gloss. You have to switch to PBL mode and mark the checkboxes that enable them.
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    you are right – but i just read the generated shader code i have been given and it was not in there...
    now that i opened sahder forge for the first time i saw the possibility to add fresnel and the geometry term.
    for this reason i deleted my post...
    lars
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    theoretically hdr. but lux does not capture "real" hdr probes: it converts ldr into hdr.
    in case you use probes generated with other tools hdr will give you slightly better results.
    lars
     
  37. thieum

    thieum

    Joined:
    Apr 8, 2011
    Posts:
    60
    Hi there,
    I just implemented Lux as to play around with my very first Substance workflow, and was happy to share the results with you.
    Top left car has a custom anisotropic shader that was working well (until I switched to linear color space), the one on right has the Lux/metallic shader. I just had to invert the Metalness output, but the final texture match correctly the Substance Painter render.
    Thanks to the suite friendly conception, I also found a quick workaround to dim the cubemaps depending on sun light (otherwise the texture would glow in the dark). The "Lux" car (!) is on foreground on the bottom screenshot. Not physically correct, but looks ok.
    Motorhackz_lux01.jpg

    But all my enthusiasm went suddenly off when I realized that some of my non Lux shaders are also affected!!!
    What the hell, there's now a flying saucer on the road! A big highlight displayed equally through the texture, instead of my nicely retouched specular map:
    Motorhackz_lux02.jpg
    How can Lux take over other shaders?
    The road has a custom blinn phong shader, basically overlaying different maps...

    I would be happy to learn how I can sort this... (but don't worry about my enthousiasm ;°)
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    depends on your camera’s render path.
    if it is set to "forward" lux does not do anything to your shaders as each single shader can have its own lighting function.
    but if it is set to "deferred lighting" lux will take over, as it overwrites the built in deferred lighting shader which handles lighting for all shaders.
    in this case you will have to:
    a) make your custom shaders use lux lighting functions. that should not be that difficult and you may start by just having a look into the most simple lux shader to find out which files to include and how to setup the shader outputs.
    b) make your custom shaders always using the forward pass by adding "exclude_path:prepass" to the first #pragma (if those are surface shaders – otherwise you will have to delete the deferred passes).

    lars
     
    thieum likes this.
  39. thieum

    thieum

    Joined:
    Apr 8, 2011
    Posts:
    60
    Thank you for your explanations Lars.
    I checked both options and still having some troubles. As you seem really attentive to your users, I keep on posting! I hope it will help others as well.
    - first option: I tried to adapt the Lux diff spec detail shader to my need, since the underlaying textures of my mat do the same, so I added another map on top of it, using a secondary UV set, and blend them through an alpha map. But I was prompted "Too many interpolators used (maybe you want #pragma target 3.0?) "... By the way, it took litterally minutes for the shader to compile. // Edit: the doc states that Lux shaders can't use 2 UV sets...
    - I also tried the second option: exclude prepass (stupid smiley ;°) Working better but I ran into a new issue: the specular highlight is now inverted regarding to the light source... I would be really grateful if you could point out what is going wrong in this case, because I can't update all my specular shaders to Lux (how would you say it: luxify?) . Also, the ground aside the road shouldn't be highlighted since the spec map is black right there.

    Motorhackz_lux03.jpg
     
    Last edited: Jan 28, 2015
  40. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Getting the parsing error trying to do a MacOS build. I've seen things here and there about it, but save me going through the entire thread - is this something that has a simple resolution?

     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    should be fixed in the latest version from github.
     
  42. ioFlow

    ioFlow

    Joined:
    May 30, 2014
    Posts:
    16
    Hi Guys,

    I'm trying to use Lux in Unity Pro 4.5.1f3 but it seems to be fubar when it comes to building.

    I get the cubemapper errors that several other people have posted about, when I get the latest version from GitHub (which is incomplete btw) and overwrite the existing install (because, again, the GitHub download only seems to have scripts in it) the build errors go from 2 to 7 :(

    Errors:

    Assets/Lux/Lux Scripts/Lux Cubemapper/Scripts/LuxCubeProcessor.cs(9,13): error CS0101: The namespace `global::' already contains a definition for `ConvoModes'

    Assets/Lux/Lux Scripts/Lux Cubemapper/Scripts/LuxCubeProcessor.cs(16,14): error CS0101: The namespace `global::' already contains a definition for `LuxCubeProcessor'

    Assets/Lux/Lux Scripts/Lux Cubemapper/Scripts/LuxEnvProbe.cs(18,14): error CS0101: The namespace `global::' already contains a definition for `LuxEnvProbe'

    Assets/Lux/Lux Scripts/Lux TexturePostprocessor/LuxTexturePostprocessor.cs(16,16): error CS0101: The namespace `global::' already contains a definition for `LuxTexturePostprocessor'

    Assets/Lux/Lux Scripts/SetupLux.cs(8,13): error CS0101: The namespace `global::' already contains a definition for `LuxLightingModels'

    Assets/Lux/Lux Scripts/SetupLux.cs(16,14): error CS0101: The namespace `global::' already contains a definition for `SetupLux'

    ain/Scripts/LuxTerrainControl.cs(12,14): error CS0101: The namespace `global::' already contains a definition for `LuxTerrainControl'

    ---

    What am I doing wrong?
     
  43. ioFlow

    ioFlow

    Joined:
    May 30, 2014
    Posts:
    16
    Gah, I noticed that I'd unzipped the lux-master from github inside my unity project so I removed lux and lux-master and reinstalled it from the asset store then re-overwrote from the github download (which I unzipped outside of my project folder this time) and now it (seems to be) building successfully...
     
  44. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Just forget about the Asset Store version and just use the github version. It has all the shaders and scripts. Even more than that of the Asset Store one. If it is working than fine but if you come across any problems than delete the Lux folder and just import the Github Lux.
     
  45. tynew

    tynew

    Joined:
    Sep 25, 2013
    Posts:
    122
    I'm just wondering with the metalness shader if I can customize it? Seeing how its working other software I'd like structured to work the same way. I don't need to use a specular input for dielectrics. Here's what I mean.

    -Albedo(RGB) Alpha(A)
    -Metalness(RGB) Roughness(A)

    So pretty much the same way the Lux bumped specular is structured :)
     
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hi there,
    the lux metalness shader will give you much more fidelity in its current form which is:
    Metal (R) AO (G) Spec (B) Roughness (A)

    you do not need rgb to store metalness – a single channel will be enough.
    so you have 2 channels free. i added ao (bound to uv 0) and specular color (dark gray = 1 channel) for dielectrics but of course you can skip specular color and set it to 0.04 (for linear color space) and use this channel for something else: heightmap, blend map, ...

    lars
     
  47. tynew

    tynew

    Joined:
    Sep 25, 2013
    Posts:
    122
    Thanks for the info. What about if I don't have an AO for the G channel because of the type of model? Would I just fill that with 100% white?
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    yes.
     
  49. tynew

    tynew

    Joined:
    Sep 25, 2013
    Posts:
    122
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    hi tynew, looks cool.
    but lux is open source which also means: open to any improvements you might do...
    cheers,
    lars