Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Lux – an open source physically based shading framework

Discussion in 'Works In Progress - Archive' started by larsbertram1, Jan 10, 2014.

Thread Status:
Not open for further replies.
  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    great!
    i have just updated the latest package:
    http://bit.ly/1aWXX8S

    now it is version 0.041

    lars
     
    Last edited: Feb 3, 2014
  2. IanStanbridge

    IanStanbridge

    Joined:
    Aug 26, 2013
    Posts:
    334
    Are you sure you uploaded your new version correctly. If I click on the link for version 0.04 I get a drop box error and if I click on the link at the start of this forum post it downloads 0.021 ?
     
  3. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    sorry, you are right: bitly did not update the link.
    so i have created a new one:
    http://bit.ly/1aWXX8S

    lars
     
    Last edited: Feb 3, 2014
  5. Deleted User

    Deleted User

    Guest

    hm looks interesting.
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    just get the package and play around with it a little bit.
    writing your own lux based shaders is pretty simple and will totally change the look of your scene (in a positiv way i guess ;-) )

    lars
     
  7. IanStanbridge

    IanStanbridge

    Joined:
    Aug 26, 2013
    Posts:
    334
    The new version is great. I'm surprised how fast it runs on opengl es3 mobile devices. I didn't expect a mobile device to be able to handle the shaders but it is running over 30fps at 1080p on my nexus 5. How did you do this, is it magic ? I even got it supporting linear lighting on mobile by recompiling the shaders with go linear functions. Great work.
     
  8. ChipNinja

    ChipNinja

    Joined:
    Oct 20, 2012
    Posts:
    26
    I just want to say officially - you're awesome. You deserve massive amounts of respect and praise for releasing higher quality assets as open source so that everyone benefits from it and has the chance to improve on it. Now if only we could get the rest of the software developers out there to move towards open source...
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    wow, that sounds astonishing.
    and to be honest: i did not do much optimization. most work was already be done by others, i just had to combine ;-)

    lars
     
  10. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    What do you mean with go linear functions??
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    thanks for your kind words. i hope you will enjoy lux.
    any feedback, wish and suggestion will be highly appreciated,

    lars
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
  13. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
  14. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,521
    I would like to contribute my SSLR to this framework sometime. It currently only works in deferred lighting as post processing.
    Usually there is moderator for this kind of open source package so who is that moderator? is it lars?
     
  15. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Yep, just pm him :)
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi there,

    if any moderation is needed i will be glad to do it.

    lars
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi there,

    i am just updating lux to version 0.042.

    changelog v 0.042

    ambient lighting
    (LuxIBL.cginc)- Spherical Harmonics added: In case you deactivate "diffuse Cube IBL" in the material inspector the shader falls back to unity’s SH lighting. Use this function if you want to make the shader react to lightprobes or speed up rendering.
    This makes the old Lux Lightprobes Shader obsolet (so i have removed it from the package)
    - Ambient Occlusion added: now you may add an Ambient Occlusion texture which controls diffuse and specular ambient lighting

    forward lighting
    - late dotNL to get rid of most artifacts on backsides and speed up rendering

    surface shaders
    - o.DeferredFresnel is only written #if defined(UNITY_PASS_PREPASSFINAL) to speed up forward rendering.
    see e.g.: "Lux Bumped Specular.shader"
    - sampler for ambient occlusion added
    - sampler for diff Cube IBL and spec Cube IBL won’t be declared unless you activate diffuse and specular IBL lighting
    - "#pragma multi_compile LUX_AO_OFF LUX_AO_ON" added to let you control the use o ambient occlusion via the material inspector


    get the latest built here:
    http://bit.ly/1lHQFdE

    watch the updated webplayer here:
    http://bit.ly/1dAiHxN


    i hope you will like it,

    lars
     
  18. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    Great update with the ambient occlusion, I was looking to add something similar for a detail layer. Something else that might be useful is an option to affect the cubemap reflectivity directly, but from a quick look I'd have to make a change in the lux core to do that?

    Thanks for the awesome work on this !
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    thank you as well!

    but what exactly do you mean by "to effect the cubemap reflectivity directly"?
    right now you have
    - roughness: per material / per texel, stored as texture: effects sharpness and brightness of spec reflection
    - ambient occlusion: per material / per texel, stored as texture: effects brightness of spec reflection
    - spec Exposure: overall, controlled by script: effects brightness of spec reflection

    what else would you need?

    lars
     
  20. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    You're right, I misunderstood what roughness was doing. After a few experiments it seems it can do what I want if I play with it exactly right, but the behavior is quite complex. I will experiment further to try and get my workflow smoothed over.

    Edit:

    After adding a slider for roughness to the shader, I see roughness is working like I originally thought, so it's likely something in my workflow causing the unexpected reflectivity.
     
    Last edited: Feb 8, 2014
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi there,

    i have not written much about authoring materials yet.
    but you can download the original dontnot specular and glossiness chart from here:
    http://seblagarde.wordpress.com/2012/04/30/dontnod-specular-and-glossiness-chart/
    (please read the download instructions carefully!)

    using this chart will make it easy to create the right textures needed by lux.

    lars
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    ups,
    i have found out that i did not do it correctly… will be fixed soon.
     
    Last edited: Feb 9, 2014
  23. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Hi Lars, just curious did you ever planning to add slider for the material properties ie for roughness, metalness, reflection etc??
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi rea,

    probably no because adding sliders would break 1) physically based shading and/or 2) the "multimaterial" approach of lux.

    1)
    specularColor and roughness already store all information to correctly control direct and ambient specular lighting.
    adding sliders would simply overdetermine your material or even break it.

    2)
    right now, lux stores roughness, metalness (combination of specular color and diffuse color) and reflection (depends on roughness) per texel which will let you create materials which are both: metalic and dielectric (have a look at the matte wood/vanished wood/gold/copper/iron material from the demo scene).
    being able to combine different material properties into just one material the shader has to handle will likely save you a lot of draw calls and speed up rendering.
    sliders always effect the whole material and do not allow per texel control.

    not to mention that adding sliders will make the shader slower...

    however i might think about adding a "material testing shader":
    - single diffuse texture (rgb)
    - single specularColor texture (rgb) + specularColor Colorfield
    - single roughness texture (grayscale) + roughness Slider
    using this shader might make it a bit easier to fine tune your roughness and specularColor textures, but you should never use it in your final built as it would just be not as fast as it could be: too many texture lookups, loo many arithmetical operations.

    anyway: using the dontnot specular and glossiness chart mentioned above makes it pretty easy to author physically correct materials.
    please see http://seblagarde.wordpress.com/2011/08/17/feeding-a-physical-based-lighting-mode/ for further details.

    lars
     
  25. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    Thanks for that link, that will be useful. I've already been getting the right kinds of materials just by feeling it out-- I'm using Substance Designer 4 to author my materials, so it's pretty easy with the 3d Preview. One problem I was having was that the shaders that come with SD4 are obviously different than Lux, so there was a lot of back and forth between Unity and SD4.

    So today I spent a few hours to make a Lux port to SD4. It's a bit of a Frankensteins monster, but if it's ok I'd like to share it so maybe others could benefit?

    I agree with your sentiments about not wanting to break physically based shading, but on the other hand being able to get a rapid result without blind guessing is useful too. And also, sometimes it's just necessary to fake it up to get an artistic result in games, rather than 100% real :p The test shader is a good compromise either way.
     
  26. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    @Lars : ah i see no worries, actually what i thinking is basically the same as what hd_ said. it could help especially for artist.
    but hey i understand your reason :)
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi there,

    can you tell me which changes you had to make?
    i am not familiar with sd4 but maybe you just have to invert some outputs? so e.g. roughness might be 1-roughness.

    i agree, that getting results fast should be a major goal.
    but getting fast results should be even more ;-)
    so the test shader will probably the best choice to provide both.

    lars
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi there,

    version 0.043 is online:
    http://bit.ly/M2W5zU

    changelog v. 0.043
    - ambient lighting (LuxIBL.cginc):
    -- specular ambient lighting fixed
    - example shaders:
    -- material test shader added which lets you adjust roughness and specularColor within unity

    lars
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi rea,

    all articles i have read so far dealing with physically based shading included some notes about how artists have slightly have to change their thinking as they have to get a deeper understanding of what is going on e.g.:how to tweak the size of the specular highlights (roughness AND specularColor in our case). that is no excuse and i hope that the look up chart will do a good job.
    for the final release i will have to write some words about how to author materials and give some examples.

    lars
     
  30. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    Here's a link to the Lux port for the Substance Designer 3d view: https://github.com/hdunderscore/Lux4SD

    It's a glsl shader, and thankfully it didn't require much of a change. It's not necessarily a 100% pixel for pixel match of Unity, but it definitely works well enough as a preview. Here's an image as an example:
    http://i.imgur.com/hAEAt0q.png
    (Left is SD4, right is Unity)

    The shader accepts diffuse, normal, specgloss (same format as Lux in unity expects), ambient occlusion (same format as Lux in unity) and emissive inputs.

    There are a few options that can be tweaked in the shader edit tab, so it can look closer to the Unity result.

    Edit:
    You can see this type of thing is wanted by other users:
    http://forum.allegorithmic.com/index.php/topic,827.0.html
     
    Last edited: Feb 12, 2014
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    nice!
     
  32. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,373
    Trying out Lux with a weapon from my game (the model/texture quality is bad, so the results could be better in both situations)

    Looks very good

    $LUXUNITY.jpg

    Have you thought about making a cubemap that records at low/blurry quality the environment around? It would be perfect for these types of situations (weapons, characters, etc) and would work for dynamic time of day/weather situations too.
     
    Last edited: Feb 11, 2014
  33. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Looks nice eskovas..
    @Lars, o yeah i was about to ask how did you create your cubemap? any workflow that you can share?
    i know that we don't have a envProbe capture tool yet.
     
  34. PixelMind

    PixelMind

    Joined:
    Aug 16, 2013
    Posts:
    101
    Shaders look great! Thanks for sharing!

    I was just wondering if these work as intended on Unity free?
    I might be wrong but Unity free doesn't support linear color space lighting. Will these shaders look wrong if you're using gamma space or is this taken care of by the shaders?
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi eskovas,

    i am glad that you like lux.

    well, the whole cubemap thing is out of my focus right now.
    there are some free cubemapper on the assetstore. and there is a hdr cupemap script somewhere on the wiki that lets you create real time reflection cubemaps.
    unfortunately they all miss roughness relevant mip chained reflection cubemaps…

    lars
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    unfortunately, no.
    the cubemaps that come with the package were generated using skyshop.

    you can use ati’s cubemapgen to convert a skybox into a convolved ambient diffuse cubemap.
    but you can’t get a mip chained cubemap into unity. you will have to write your own script to combine different cubemaps (or textures) into one cubemap (writing to different mip levels).

    i would be glad if somene else would contribute by doinfg so…

    lars
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi pixelmind,


    lux takes care of gamma. but i think you can use linear in unity free too, can’t you?

    lars
     
  38. Ulven2

    Ulven2

    Joined:
    Apr 23, 2012
    Posts:
    64
    I got an error when trying this with the latest version of SD (4.0.3)
    $LuxRendererError.jpg
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi there,

    lux version 0.044 is ready to download shipping with 2 new example shaders: parallax mapping and a pretty advanced detail shader.

    get version 0.044:
    http://bit.ly/1dG3NWC

    $lux_pm_detail.jpg

    changelog version 0.044
    - shader folder structure refactored: "Resources" is now subfloder of "LuxCore"

    - ambient lighting (LuxIBL.cginc)
    -- specular ambient lighting: added alternativ fresnel calculation which would give you only colorized specular reflections to match skyshop (deactivated by default, you will have to edit the cginc)

    - example shaders
    -- advanced detail shader added
    -- parallax mapping shader added
    -- material test shader: small fix

    lars
     
    Last edited: Feb 11, 2014
  40. PixelMind

    PixelMind

    Joined:
    Aug 16, 2013
    Posts:
    101
    Oh you're right, it does seem to work. It's odd because the documentation still states that its pro only feature though (https://docs.unity3d.com/Documentation/Manual/LinearLighting.html).

    Had some time to play with these shaders and I have to say they look brilliant with good input textures. Especially on metals and other reflective materials.
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    thanks,

    but especially the reflections belong to the IBL part of the shader – really nothing special here.
    all you have to have are the right cubemaps. which still is a problem in unity.

    lars
     
  42. Beardbotnik

    Beardbotnik

    Joined:
    Jul 27, 2013
    Posts:
    49
    hey, I tried to open your link to the new version of Lux but dropbox is saying nothing is there.
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    it is still uploading. will take about 30 min… sorry.

    lars
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    0.044 is online now.
     
  45. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
  46. Ulven2

    Ulven2

    Joined:
    Apr 23, 2012
    Posts:
    64
    @hd_:
    Cheers. Indeed, the first error is still there, It appears to be because of
    c.a = s.Alpha + _LightColor0.a * fresnel * atten;
    fresnel is a vec3, so changing it to for example fresnel.r works, or multiplying all channels individually.
    $LuxRendererError2.jpg
     
  47. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    Nice spot, I've changed it on github. I went with the multiplying all channels way, but not sure if that's the intended behavior. It looks the same for me on my materials.
     
  48. Ulven2

    Ulven2

    Joined:
    Apr 23, 2012
    Posts:
    64
    @hd_: I guess it will at least compute the same as in Lux and without error, so that's good.

    @larsbertram1: Looking a bit deeper into the source, there was something that I spotted visually with this shader (And many other physically based shaders) that I think we should update. It was already explained very well here: http://filmicgames.com/archives/557
    Basically it is generally not correct to assume that if a material is very diffuse (rough), it would not still have a specular highlight at grazing angle (fresnel).
    In order to try to illustrate the concept I mocked up a microstructure drawing in photoshop.
    $GrazingAngle.jpg
    Green lines are coming in roughly perpendicular to eachother and are the ray from the light to the microstructure. The approximate reflection vector (the red line) will gradually hit fewer of the grooves that are able to reflect in any other direction, and thus appear more like a smooth surface as more of them go in (roughly) the same direction (hitting the eye).
    So although a rough surface still has slightly less lighting impact from the fresnel effect, something as simple as fresnel *= specularity; is actually further from correct than leaving it unmodified by the amount of specularity in many cases.
     
    Last edited: Feb 12, 2014
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,913
    hi ulven,

    i am not sure if i get you right, sorry.
    you think that even rough surfaces should have specular highlights at grazing angles, right?

    the image attached shows how lux handles hightlights according roughness at grazing angles:

    $fresnel.jpg

    lars
     
  50. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    It could be that Ulven2 was observing the shaders in SD4, where the specular was weakened by improper linear lighting support. But I updated the shader for SD4, now it has better linear lighting support and should look closer to the Unity result.

    @lars, not sure if the 0.044 download is working at the moment.
     
Thread Status:
Not open for further replies.