1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    Dismiss Notice

Lux – an open source physically based shading framework

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

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

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi there,


    after having published this topic to the shader lab thread and getting nice feedback so far i think it is time to officially release Lux – an open source physically based shading framework.

    [​IMG]


    Why physically based Shading?
    First of all physically based shading will give you much more convincing results than traditional lambert or blinnphong shading: No more fights with washed out specular highlights or boring dark areas: everything is shiny!
    Second: psb will help you to get much more constant and predictable results under varying lighting conditions: Author once, use everywhere!

    Why open source?
    There are already some commercial solutions out there available at the asset store, but none of those is free, some even break other shaders. So it might be rather difficult for the community to develop and improve unity’s rendering capabilities. But that is the whole idea behind this framework.
    And i hope that there will be a tons of shaders out there supporting Lux soon.

    So any feedback, tips and tricks are highly appriciated.
    And in case you find any bug just let me know.

    Lars


    Latest version: 0.07 (3/10/2014)

    Test the webplayer (version 0.04)
    http://bit.ly/1dAiHxN
    Download the latest package (version 0.07)
    http://bit.ly/1gmApq1


    How does it work?
    The framework is mainly based on the work of Sebastién Lagarde and Dimitar Lazarov:
    http://seblagarde.wordpress.com/2011/08/17/hello-world/
    http://blog.selfshadow.com/publicati..._slides_v2.pdf

    It supports forward and deferred lighting, lightmaps and lightprobes and handles gamma and linear lighting – although linear lighting is more than a key to physically based shading.


    The ingredients

    Direct lighting
    - Specular: Blinn-Phong or Cook-Torrance (GGX Trowbridge Reitz)
    - Visibility: Schlick-Smith or Smith
    - Fresnel: Schlick-Fresnel approximation (deferred lighting only supports faked fresnel for direct specular lighting).

    Ambient lighting
    - Diffuse Cubemap IBL
    - Specular Cubemap IBL (gloss values stored in mip chain) with fresnel term based on roughness and specular color
    Both cubemaps can be sampled in gamma and linear space. Support for RGB or RGBM (HDR) cubemaps.
    - Spherical Harmonics in case you disabled "Diffuse Cubemap IBL"
    - Ambient Occlusion controlled by texture input


    The implementation

    Deferred rendering
    To make the shader work in deferred rendering i had to hack the "Internal-PrePassLighting“ shader, as i could not find another way yet to get the dotNL and especially the dot(h, lightDir) product. That is not as elegant as i would like to have it.
    And as i had to „compress“ the spec value in the "Internal-PrePassLighting“ shader (log2) and decompress it in the lighting prepass function (exp2) in order to avoid wrong shaded spots in the center of the highlights, built in shaders will be broken (too less specular) when using deferred lighting. So i highly recommend to rebuilt all needed shaders using the Lux lighting functions – which is not that big deal i hope.

    Ambient IBL
    I did not spent much time on this part of the framework and it is pretty much straight forward using common rbgm decoding and a roughness based fresnel term on the specular distribution.
    In case you disable ambient diffuse IBL the shaders will fall back to unity’s built in spherical harmonics.

    Inputs
    I have chosen an approach suggested by sebastién lagarde and only have a few parameters to feed the shader right now:
    http://seblagarde.wordpress.com/2011...lighting-mode/

    - Diffuse color as texture rgb
    - Specular color as texture rgb
    - Roughness (alpha in specular color)
    - Normal map
    - Diffuse and specular ambient cube (most of the time passed as global textures by script)

    And in case you miss parameters like metalness: Lux supports a metalness workflow since version 0.07.
    There is only one singe shader right now supporting this workflow but it is really easy to change all existing shaders. I guess more shaders natively supporting metalness will follow.


    Changelog

    version 0.07
    Terrain detail shaders
    All errors fixed for dx9 and dx11.
    Terrain shaders
    Possible division by zero fixed.
    Lux Internal-PrePassLighting shader
    doubled "max(0, dotNL)" removed.
    LuxLightingAmbient.cginc
    "o.Emission = 0.0;" added to make SH lighting work with the Lux diffuse shaders (Lux diffuse shader or the terrain detial shaders e.g.)
    Metalness Shader
    added
    Dualforward lightmaps
    docu entry added – so easily find out how to enable dualforward lightmaps in forward lighting
    Deferred lighting
    Disabling specular ambient lighting won’t let the faked fresnel go crazy in deferred lighting mode anymore
    Treecreatorleaves shader
    fixed

    version 0.061
    Lighting
    blinn phong: visibility term now is more robust (by adding saturate)
    cook torrance: sign corrected, no more magical numer needed to make deferred match forward
    Terrain shader
    normal blending enhanced
    Detail shader
    normal bending corrected

    version 0.06

    version 0.06 is a major update because it introduces a Cook Torrence based approach as second lighting model next to Blinn Phong.
    In order to make it possible to switch between these models I had to rewrite some parts of the framework. i took this chance to make the naming a bit more flexible and descriptive:
    "LuxLightingPhong.cginc" changed to "LuxLightingDirect.cginc"
    "LuxIBL.cginc" changed to "LuxLightingAmbient.cginc"


    Surface Shaders the name of the Lux lighting function changed to "LuxDirect":
    #pragma surface surf LuxDirect noambient
    the name of the direct lighting functions include changed:
    #include "LuxCore/LuxLightingDirect.cginc"
    A new pragma makes it possible to switch between the lighting models:
    #pragma multi_compile LUX_LIGHTING_BP LUX_LIGHTING_CT
    Writing to o.Specular has changed to a function call:
    o.Specular = LuxAdjustSpecular(spec_albedo.a);


    Minor changes and fixes
    - VertexBlend shaders added
    - Lux ambient lighting: if "diffuse cube IBL" is disabled the shader won’t add ambient lighting based spherical harmonics in case the object is lightmapped.
    - tree creator redertex shaders fixed but this will be an ongoing process...
    - terrain shader first pass: fixed for cook torrence using complex blending for detail normal


    version 0.05
    Example shaders !!! important !!!
    writing to o.DeferredFresnel changed to:
    o.DeferredFresnel = exp2(-OneOnLN2_x6 * max(0, dot(o.Normal, normalize(IN.viewDir) ))); as it could cause some lighting artifacts on dx9 / dx11. now it is even a bit faster, You should do so in all your individual shaders too.
    Ambient Lighting (LuxIBL.cginc)
    spec ambient IBL changed from spec_albeo.rgb and spec_albedo.a to o.SpecularColor and o.Specular – just to make it more flexible
    Lighting (LuxLightingPhong.cginc)
    optimized "Final Composition" (forward lighting)
    Tree creator shaders added

    version 0.046
    Ambient Lighting (LuxIBL.cginc)
    - Fixed errors from version 0.045.
    Shaders may declare "#define NORMAL_IS_WORLDNORMAL" to skip the calculation of the worldnormal and speed up rendering.
    Used e.g. by the terrain grass shaders as here normal equals worldnormal.
    Lux terrain shaders
    - Improved normal blending between different shader passes.
    Added a the possibility to use a second normal map on detail texture number 3 to hide tiling artifacts on high frequent and bumpy textures such as rock.
    Lux grass and vertex lit shaders added

    version 0.045
    Ambient Lighting(LuxIBL.cginc)
    - Due to a bug in unity terrain materials i had to make the "#ifdef DIFFCUBE_ON" a bit more complex.
    Now diffuse ambient IBL can be activated per material using the material inspector or globally for shaders in which the keyword "USE_GLOBAL_DIFFIBL_SETTINGS" is enabled.
    Sorry for that mess.
    Lighting (LuxLightingPhong.cginc)
    - color output.alpha is reduced to: c.a = s.Alpha;
    as long as anybody can tell me what the rest sould be good for i will keep it this simple.
    Lux terrain shaders added
    Documentation added
    DontnodGraphicChartForBlinnMicrofacet look up chart added

    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

    version 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

    version 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

    version 0.041
    Forward lighting
    - fixed for dx11

    version 0.04
    deferred lighting
    - internal prepass lighting shader fixed for dx11

    version 0.03
    deferred lighting
    - faked fresnel added based on n_dot_v (direct specular lighting)

    version 0.02
    deferred lighting
    - refactored
    - visibility term added
    - fresnel fixed (direct lighting): fresnel according only to ONE directional light, light position has to be passed by script. see: "Lux Bumped Specular" shader
    forward lighting
    - refactored
    - visibility term fixed
    lightmaps
    - lighting fixed when using lightmaps or lightprobes

    version 0.01
    initial release
     
    Last edited: Mar 11, 2014
    konsnos and Kirienko like this.
  2. IanStanbridge

    IanStanbridge

    Joined:
    Aug 26, 2013
    Posts:
    311
    This is super impressive. Thanks for sharing it. Can I ask why is the version number so low on it. 0.02 seems a bit harsh for something that seems pretty feature complete. What features do you have planned for version 1 ? Also would it be possible to add refraction to this on transparent shaders like the glass shader in unity has or a density option or something like that or does the phisically based nature of them make that more tricky ?
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi ian,

    thanks for your answer.
    the version number is so low because i still have to find a way to integrate correct fresnel into deferred shading ( now it is just calculated according to your main light position) and work on other features such as ao which is not that big deal.
    it would like this to be(come) an open source framework so i a bit of depend on the feedback of the community. the more i get the faster there will be a stable version i would call 1.0.
    i haven’t thought about refrection yet because it will be relayed on "grabpass" and is mainly a forward feature only (transparent). right now i am much more focused on deferred lighting and giving you a rock solid and flexible solution for that.
    and as it is open source: refrection could be done by someone else… ;-)

    lars
     
  4. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    894
    Hi Larsbertam1,

    thanks a lot for sharing, is a really interesting opportunity for the community.
    My shader programming skills aren't good enought until now, but I will try to improve fast. :)

    Cheers
    Kenshin
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi there,

    the last version of lux shipped with a "correct" fresnel for just ONE directional light when using deferred lighting.
    i am still working on a correct fresnel for all lights in deferred lighting but meanwhile i have finished a version using some kind of "faked fresnel" – well: it is not that bad and at least as good as skyshop’s fresnel – that work with all kind of lights and does not need any input by script.

    so get this version here:
    http://bit.ly/1b4jir6



    lars
     
  6. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I've not tried it yet but i will try to soon, this is a very generous and good idea, i hope some of the community do come along and contribute, i don't have the shader skills to add anything sadly
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    thank you.
    and in fact there is some help from and discussion with the community. unfortunately it is mostly bound to personal contacts.

    but if you would like to help there are also other things to do not only shaders like a nice and handy cubemap tool...

    lars
     
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    3,528
    what kind of tool that should be..?

    maybe you can also add some other points as todo-list somewhere ?
    and use github?
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    that tool would let you create convoluted diffuse cubemaps and mip mapped specular cubemaps containing the different reflections according to the roughness of the material in a mip chain. right now you can only create those cubemaps when either using skyshop (commercial on the asset store) or cubemapgen from ati (free but win only and not integrated into unity).
    a very good starting point might be this video:
    http://www.youtube.com/watch?v=vwjNc9FS_WI
    it is the talk by nicolas (co founder of unity) at unite 2013 and he shows a complete cubemap solution including some code.

    next to that any help on the shader side of course i highly appreciated: finding bugs, doing some more optimizations.

    the last public version of lux introduced "faked fresnel" for deferred rendering which is quite nice but not really physically accurate.
    right now i am working on a new version (nearly done) which brings "correct" fresnel even to deferred lighting but it is not written as surface shader.
    as i had to dig very deep to make it work within the unity rendering pipeline it is pure cg – and a real shader monster.
    this shader definitely will break any other deferred shader as i had to make some very major changes to the shared lighting prepass function.
    so all shaders will have to be rewritten… any help here would be great as well.

    lars
     
  10. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    3,528
    Collected the script pieces from this page,
    http://framebunker.com/blog/static-sky-unite-presentation/

    but it still has some missing parts/variables, also the shader in this package is bit different still..

    (source attached, code has couple FIXME notes, compare with the code in that pdf ^ )
     

    Attached Files:

  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi mgear,

    thanks for posting the script but some more words about how to use it would be very helpful ;-)

    lars
     
  12. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    3,528
    Its editor script, creates menu item: Test/Cubemapper

    First create new cubemap in project window (and enable all those 3 options for it [x]mipmaps, [x]reading, [x] ..)

    Then start the script, it opens wizard window: assign main camera, target cubemap, press create.

    And nothing really happens..since there is something missing :)

    * added source here, if someone knows how to fix it: https://github.com/unitycoder/CubeMapRenderer
     
    Last edited: Jan 21, 2014
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi there,

    today i was asked by a friend to have a look at skyshop and alloy and compare their functionality to lux.
    and although i just had a quick look at the shaders that ship with those packages i try to write a short summary.
    it might not be perfect, it might not even be correct so i would appreciate any comments on the following statements:

    diffuse
    skyshop: lambert
    alloy: lambert
    lux: lambert

    specular
    skyshop: normalized blinn phong, spec power 0 - 256
    alloy: normalized blinn phong, spec power 4 - 1024
    lux: normalized blinn phong, spec power 0.25 - 2048

    visibility
    skyshop: none
    alloy: none as far as i can say – although there is a function whose name makes one believe that there is some kind of visibility term…
    lux: schlick-smith

    fresnel
    skyshop: faked fresnel (in deferred – based on NdotV)
    alloy: none (in deferred)
    lux: faked fresnel (in deferred – based on NdotV)

    am i right?

    lars
     
  14. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    These shaders look really nice, and are actually perfect for what I am doing. Just a question though, what's the license on these?

    Thanks !
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi there,

    i am not into licensing – but i would like it to be open source.
    so everybody can use the lux core to write ones own shader, use these in free and commercial projects, give them away for free or even sell those shaders on the asset store.
    in order to keep all lux based shaders compatible i think it is best to not "allow" to change the lux core files and publish those. but of course i am open to any improvements and will try to incorporate those into the official release.
    so what license would fit best here?
    any tip will be appreciated.

    lars
     
  16. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    Well I am a big fan of MIT / BSD / Png / Zlib type licenses, where basically you say 'this is the product; you can use it however you want, don't take credit for making it, don't blame me for anything that goes wrong.' (read up on the individual licenses for the specifics).

    There is also GPL and L-GPL. I don't touch anything with GPL that I need to integrate into code. I am cautious about L-GPL because I don't fully understand it and what it requires me as a user to do, but the advantage to you is that the L-GPL asks anyone that makes changes to submit the changes so everyone can benefit.

    It's up to you to decide at the end of the day, but you should put a license on it if for no other reason then to protect yourself from any damages.

    This might help you:
    http://oss-watch.ac.uk/resources/licdiff
     
    Last edited: Jan 25, 2014
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364

    you are absolutely right.
    and publishing lux under a certain license should make thing pretty clear and easy to understand.
    so i will have a look at those licenses and pick the right one – hopefully.

    lars
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    after a first glance i would go with MIT or zLIB.
    any comments on this?

    lars
     
  19. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    I think MIT or zLIB could be the best for Lux since it overide internal-prepass, but are you sure you (or anyone that help creating lux) don't want to be credited? I know that it's not a must, but maybe there's some developer that at least want to put the lux author name in the Thank's To section :D.
     
  20. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    I like MIT and zlib, they are easy to work with. In regards to the point rea mentioned, it seems there are some variations of MIT where that is the case, but neither the standard MIT license nor the zlib license say you can't give credit to lars for using his work. The modified BSD license on the other hand does say that you can't credit lars to promote your work, without permission.

    The interesting thing is that zlib has a clause that says, while you don't have to give credit, you can't take credit either ("1. The origin of this software must not be misrepresented...").

    Because you want others to work with your work and make shader contributions, it might be easier with the MIT license where the author specifics are less of a sticking point.

    Source:
    http://en.wikipedia.org/wiki/MIT_License
    http://en.wikipedia.org/wiki/Zlib_License
    http://en.wikipedia.org/wiki/BSD_license#Terms
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi there,

    thanks a lot for your research and advice.
    as i would like to keep things as simple as possible i will probably go with the MIT license.

    lars
     
  22. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Thanks to tom's inclusion of lux-friendly implementation in the rtp beta, by the time I finally get the terrain i'm doing in shape (Not crashing because a ridiculous lack of 64bit editor) i'd like to try this out rather than buying skypshop etc (assuming Jove doesnt supply the tools) assuming it has a utility to create convolved cubemaps much as skyshop does. It just seems sense, should this arise. Will you be updating your foliage shaders to go along with it? If so i'll put some decent time into and give back what I can. I possibly almost near actually have a very large scale terrain usable within a sensible memory limit. With the rtp supporting pbr for the ground, if lux can then support the next natural step upwards, which is vegetation and detail, i dont see why not support this

    Your foliage shaders are great, i am no wizard at this technology however and the foliage might take some thinking, because there's going to be so much needed. With terrain composers useful ability to distribute foliage by colour, i feel confident that I can place it appropriately, the next step is creating a kind of foliage that can be distributed as such an amount, while 'harmonising' with rtp's new pbr features and lux, which really does make more sense to support, with the more people supporting it
     
  23. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    Hey Lars,
    I don't know if you already test it or not, but your shader are broken in dx 11,
    There's a weird bright white fringe on the surface side
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi rea,

    no, i haven’t as i am on mac.
    and the shaders compile fine so that is pretty strange. do you have a screen shoot?

    lars
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    @ lazygunn:
    right now lux does not ship with its own cubemap tool.
    you will have to use skyshop or some other solution like cubemapgen.

    the foliage shaders will be updated as soon as lux is released on the asset store and has a stable core.

    lars
     
  26. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    here you go
    i think it's the lights calculation got screwed
    $Lux.JPG
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    f***k,

    which lighting pass? forward or deferred?
    and which pacjage do you use? one directional fresnel or faked fresnel?
    at least: ibl and some other lighting works…

    lars
     
  28. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    Deffered, the latest release with faked fresnel.
    and about the IBL yes it works but not in the shaded area (notice the black color at the closest sphere)
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    well, could you please take another screen shoot not using any ibl at all?

    and have you made sure that there is only one version of lux in your scene? both "one directional light" and "faked fresnel" need their own "prepass lighting" shader which can not be used at the same time. you have to remove the one you do not need and restart unity.
    i wished it would be as simple as that… ;-)

    does anybody else have problems with dx11 and deferred lighting?

    lars
     
  30. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    This is what I get on the demo scene (bottom is dx11):
    [​IMG]

    Everything else is relatively normal, none of the pink/no texture issues that rea is getting.

    edit: This is in forward pass
     
    Last edited: Jan 29, 2014
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    and can you test deferred also?
     
  32. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
     
  33. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    3,528
    Last edited: Jan 29, 2014
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
  35. hd_

    hd_

    Joined:
    Jan 23, 2014
    Posts:
    29
    I don't currently own unity pro, so I can't test deferred. I am using version 0.021.
     
  36. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi there,

    o.DeferredFresnel is defined as float NOT float3 in "LuxLightingPhong"

    so "o.DeferredFresnel = float3(0,0,0);" should cause some errors…

    but it is the only output variable defined as float. may be changing it to "half" like all others will help.
    so please edit "LuxLightingPhong" and change "float DeferredFresnel;" to "half DeferredFresnel;" in "struct SurfaceOutputLux".
    then recompile the shader.

    lars
     
  38. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    Nothing happened after i change from float to half, or maybe i do something wrong?? to recompile we just need to right click and reimport isn't??

    EDIT:
    Oh wait it works, but only for Forward Path DX11, in Deffered DX11 it still broken
     
    Last edited: Jan 30, 2014
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hmm, forward does not need o.DeferredFresnel – only deferred.

    so lets nail it down and find out what going wrong.
    fresnel needs "s.DeferredFresnel" and "s.SpecularColor.rgb" so let’s see what misses in dx11.

    i have "changed" the "LightingLuxPhongNDF_PrePass" function in "LuxLightingPhong.cginc" so it just outputs o.DeferredFresnel.
    do so by adding:
    c.rgb = s.DeferredFresnel;
    just before the return statement.

    the result should look like this:

    $Bildschirmfoto 2014-01-30 um 13.55.24.png

    we can do the same for the specular color by adding:
    c.rgb = s.SpecularColor.rgb;
    just before the return statement.

    now the result should look like this:
    $Bildschirmfoto 2014-01-30 um 14.08.12.png

    it would be great if somebody could do this using dx11 and deferred lighting.

    lars
     
  40. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
     
    Last edited: Jan 30, 2014
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi rea,

    hdr scale is "6", but both exposure values are lowered to "0".

    and deferred fresnel and spec color looks allright.
    so if we have a look at the orignal term:
    c.rgb += (s.SpecularColor.rgb + ( 1.0 - s.SpecularColor.rgb) * s.DeferredFresnel) * spec * light.rgb;

    the only source for the problem is "spec"...
    and if i only output spec (c.rgb = spec;) this is what i get:

    $Bildschirmfoto 2014-01-30 um 18.40.23.png

    so if spec is "broken" there are 2 possible reasons:
    1. dx11 does not like the compressed specular value.
    2. there is something wrong with the prepass lighting shader


    test case 1. by:

    in file "LuxLightingPhong"

    replace line:
    fixed spec = exp2(light.a) - 1;
    with:
    fixed spec = light.a;

    and in file "Lux Internal-PrePassLighting"

    replace line:
    res.w = log2(spec + 1);
    with:
    res.w = spec;

    if that does not help we will have to have a look into case 2...

    lars
     
  42. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    Nope, still broken.
    Oh and i kinda forgot to tell you but maybe it's usefull. Every default shader are having the same problem in Dx11 so i think it's something on the internal-PreaPass
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    ok, then it is the lighting prepass shader…

    please try to comment the visibility function.
    so change line 264 from:
    spec *= visibility;
    to:
    // spec *= visibility;

    lars
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    and if this does not fix it you might try to uncomment line 247:
    //float dotNH = max (0, dot (normal, h)); // but it seems that we do not have to max dotNH
    and comment line 248:
    float dotNH = dot (normal, h);
     
  45. hd_

    hd_

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

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    This one fixed it,
    and i also trying to uncomment line 264 it's still works, so it's the dotNH that broken in dx11
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
  48. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    Dude, sorry for becoming bad news bringer.....
    but the latest update is still broken on dx11 and this time are in full forward path.. In deffered it was working fine
    When i'm saying full forward, it means both settings in player settings and camera are set to forward path (or the camera are using "Use player settings"), if one of them (camera and player settings) are in deffered it will becoming glitchy with the black artifact.
    $LuxDx11_deff_camFor2.JPG
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    3,364
    hi rea,

    strange as i haven’t made any changes to the forward lighting function.
    but may be it is just the same reason as for deferred lighting: dotNH must use max ?!

    so open "LuxLightingPhong.cginc" and find "LightingLuxPhongNDF" which is the lighting function used in forward.
    there find the 2 lines:
    Code (csharp):
    1.  
    2. //float dotNH = max (0, dot (s.Normal, h)); // but it seems that we do not have to max dotNH
    3. float dotNH = dot (s.Normal, h);
    4.  
    and replace those with:
    Code (csharp):
    1.  
    2. float dotNH = max (0, dot (s.Normal, h));
    3.  
    may be this will already fix it.

    lars
     
  50. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,743
    It Fixed :)
     
Thread Status:
Not open for further replies.