Search Unity

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

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

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi marco,

    i have never tested it on mobile – but others have: it works at least on the latest generation of android devices.
    however, it might be a bit too expensive – at least if you have complex scenes and want to target a wide range of devices.
    nevertheless: you can simply try it out without any (financial) risk ;-)
    and i think a lot of people would be grateful to read your findings.

    lars
     
    hopeful likes this.
  2. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Sure, the scenes we plan to construct would be rather small so I'm slightly optimistic that this will work out :)
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    Otherwise just give me a call, and we can see what can be optimized for mobile... ;-)
     
  4. petkovas

    petkovas

    Joined:
    Oct 12, 2013
    Posts:
    28
    Should i expect integrtion of Lux with Shader Forge, for example?

    Is that feasible?

    I am new in the shader world and am looking for an easy entry. There is no release date for the project that i am working on at the moment, where the shader(s) will be used.
    Sooner (hopefully!) or later i will be confronted with the creating of a specific shader and using it inside an IBL scene.

    What would be the easiest workflow for a novice person to that field, like me, to create a material shader?

    The last thing for my question is that my project will be used in mobile (Android) devices. Is a project, where IBL is included, useable in a mobile scenario?

    Thank you for your answers!
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi there,
    making shader forge supporting lux is not my task but the author’s of shader forge one.
    and he is quite busy making it work with the upcoming unity 5 as far as i know.

    nevertheless, lux shaders are written as standard surface shaders making it "pretty easy" to modify existing ones to fit your needs.
    although i bought shader forge a while ago i have never given it a try which might be a big mistake.
    but having a look at some of the more advanced lux shaders (like the wetness shaders e.g.) i find it difficult to imagine how you could author those using a node based system as they really squeeze any little byte out of the input structure while being highly flexible.

    mobile:
    lux has not been written for mobile devices and it is quite demanding.
    one of course could optimize some parts of the lighting functions for mobile (how unity has announced for unity 5 using christian schüler’s simplified cook torrance lighting function). but that is not on my current list.
    nevertheless: Lux just let’s you get started: It will help you to get familiar with physically based shading, terms like "specular color" and "roughness" or "smoothness" so you will be ready for unity 5 when it comes out.
    but of course you can just stick with lux… ;-)

    lars
     
  6. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Hey, i've been trying out the wetness shaders, and they compile fine, but when i try to add the wetness flow shader to a material they flash on and and back to pink when selected and i get the error:

    Shader error in 'Lux/Wetness/Flow Bumped Specular': syntax error: unexpected token '.' at line 321

    There aren't 321 lines in that shader so i guess it could be one of the includes, but i'm not sure where, or if im doing something wrong. Any advice?
     
    John-G likes this.
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi lazugunn,

    have you got the latest version from the repo?
    and have you also updated the other core files?

    lars
     
  8. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Yep i've replaced all of core, added the wetness shader folder and replaced the editor script from the latest repo

    I'll put my self created shaders in another folder and replace the entire thing just in case and get back to you
     
  9. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Hmm yes, even completely replacing it throws the same error and the pink object of death. I installed NShader for visual studio so I can see if that will make it easier to identify the problem
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    well – i just grabbed the latest version from github and imported them to unity pro on windows (running dx11 on a dx10 gpu): no errors...
     
  11. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I've found it's a problem between forward and deferred lighting but not sure what is causing it, probably a mismatch of files although everything updated was replaced. I'm trying different combinations, but from replacing the entire thing the error doesnt appear anymore but lights are all pink in deferred, they're fine in forward. This wasnt an issue prior to this but I wonder if it was because i didnt reimport the the old install after replacing the changed files. I'll keep trying things, it may be pebcak but not sure
     
  12. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Very confused now as removing lux entirely and the problem persists. I'm going to open a new project and reimport things to see what's broken exactly, sorry for wasting your time if it turns out to not be lux, it's just it only manifested after i investigated the shader throwing the error
     
  13. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    edit:

    Right! I got to the bottom of it, i dont know if it was me being thick but it's worth posting just in case - I was making a shader that was essentially bump spec self illuminated translucent and transparent, and came to a strange idiosyncracy because it seemed to break the wetness flow shader (and only this initially) in deferred, i still don't know why. Adding the 'alpha' pragma fixed the issue it seems, at least for my uses, so hopefully that might help if anyone else runs into the problem while writing their own shaders with Lux (or it may be considered a bug, im not sure, i know translucent shading is not very straightforward in some situations)

    I'll have a little example of what i'm doing with it soon, once i have the wetness shaders working as i'd like, it'd just be a WIP as i'd like to make it lively and use it as a basis for demoing further models - its using mostly one Lux shaded model many times and seeing how much mileage i can get. Lux is very very pretty
     
    Last edited: Jul 29, 2014
  14. larsbertram1

    larsbertram1

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

    bump spec self illuminated translucent and transparent sounds very ambitious.
    looking forward to see it in action.

    lars
     
  15. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Thanks for this package!

    I made a modification to the hair shader to support an anisotropic texture map for curly and (mostly) kinky hair.
    However I haven't any good soft to draw anisomap correctly ...
    Beside that it works great!
    I'll try to make and post variant of the shader, I want to make a very compact vertex color based shader.
     
  16. larsbertram1

    larsbertram1

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

    i am looking forward to see what you will come up with!
    good luck.
    unfortunately farfarer’s original implementation got lost (as unifycoominity is not available anymore) but i guess that you can contact him about some more information. his original version used anisotropic textures to control specular reflections.

    http://www.farfarer.com/

    lars
     
  17. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    I know about farfarer, I use to toy with his skin shader from his site, haven't seen his hair shader there.

    But like I said I did it already.

    without

    with

    I need more tweak for my model but it's done.

    Code (csharp):
    1.  
    2. // Based on:
    3. // http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Scheuermann_HairRendering.pdf
    4. // http://blog.leocov.com/2010/08/lchairshadercgfx-maya-realtime-hair.html
    5.  
    6. Shader "custom/Human/Hair ANISO" {
    7.   Properties {
    8.   _Color ("Main Color", Color) = (1,1,1,1)
    9.   _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "white" {}
    10.   _SpecularTex ("Specular Shift (R) Roughness (G) Noise (B)", 2D) = "green" {}
    11.   _BumpMap ("Normal (Normal)", 2D) = "bump" {}
    12.  
    13.   _ANISOTex ("Anisotropic Direction (RGB)", 2D) = "red" {}//(1,0.5,0.5,0)//
    14.  
    15.   _SpecularColor1 ("Specular Color1", Color) = (1,1,1,1)
    16.   _PrimaryShift ("Primary Spec Shift", Float)  = 0.5
    17.   _Roughness1 ("Roughness1", Range(0,1)) = 0.5
    18.  
    19.   _SpecularColor2 ("Specular Color2", Color) = (1,1,1,1)
    20.   _SecondaryShift ("Secondary Spec Shift", Float)  = 0.5
    21.   _Roughness2 ("Roughness2", Range(0,1)) = 0.5
    22.  
    23.   _RimStrength("Rim Light Strength", Range(0,1)) = 0.5
    24.   _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    25.  
    26.   _DiffCubeIBL ("Custom Diffuse Cube", Cube) = "black" {}
    27.   _SpecCubeIBL ("Custom Specular Cube", Cube) = "black" {}
    28.    
    29.   // _Shininess property is needed by the lightmapper - otherwise it throws errors
    30.   [HideInInspector] _Shininess ("Shininess (only for Lightmapper)", Float) = 0.5
    31.    
    32.   }
    33.  
    34.   SubShader{
    35.   //  We have use LuxTransparentCutout here
    36.   Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="LuxTransparentCutout"}
    37.   //  Built in Fog breaks rendering using directX and only one pixel light
    38.   Fog { Mode Off }
    39.    
    40.   CGPROGRAM
    41.   #pragma surface surf LuxHair fullforwardshadows noambient nodirlightmap nolightmap alphatest:_Cutoff
    42.   //vertex:vert finalcolor:customFogExp2
    43.   #pragma target 3.0
    44.   #pragma glsl
    45.  
    46.   #pragma multi_compile LUX_LINEAR LUX_GAMMA
    47.   #pragma multi_compile DIFFCUBE_ON DIFFCUBE_OFF
    48.   #pragma multi_compile SPECCUBE_ON SPECCUBE_OFF
    49.  
    50.   //  #define LUX_LINEAR
    51.   //  #define DIFFCUBE_ON
    52.   //  #define SPECCUBE_ON
    53.    
    54.   //  Ambient Occlusion is stored in vertex color red
    55.   #define LUX_AO_OFF
    56.  
    57.   //  Needed in case the diffCUbe is disabled to fall back to sh
    58.   #define LUX_LIGHTMAP_OFF
    59.    
    60.   fixed4 _Color;
    61.   sampler2D _ANISOTex;
    62.   fixed4 _SpecularColor1;
    63.   fixed4 _SpecularColor2;
    64.  
    65.   float _PrimaryShift;
    66.   float _SecondaryShift;
    67.   float _Roughness1;
    68.   float _Roughness2;
    69.   float _RimStrength;
    70.  
    71.   sampler2D _MainTex;
    72.   sampler2D _SpecularTex;
    73.   sampler2D _BumpMap;
    74.  
    75.   #ifdef DIFFCUBE_ON
    76.   samplerCUBE _DiffCubeIBL;
    77.   #endif
    78.   #ifdef SPECCUBE_ON
    79.   samplerCUBE _SpecCubeIBL;
    80.   #endif
    81.    
    82.   // Is set by script
    83.   float4 ExposureIBL;
    84.  
    85.   // As we do not include Lux direct lighting functions we have to define these constants here
    86.   #define OneOnLN2_x6 8.656170
    87.   #define Pi 3.14159265358979323846
    88.  
    89.   struct SurfaceOutputLuxHair {
    90.   fixed3 Albedo;
    91.   fixed3 Normal;
    92.   fixed3 Emission;
    93.   half Specular;
    94.   half2 Specular12;
    95.   fixed3 SpecularColor;
    96.   fixed4 AnisoDir;
    97.   fixed SpecShift;
    98.   fixed SpecNoise;
    99.   fixed Alpha;
    100.   };
    101.  
    102.        
    103.        
    104.        
    105.        
    106.   struct Input
    107.   {
    108.   float2 uv_MainTex;
    109.   float4 color : COLOR; // R stores Ambient Occlusion
    110.   float4 worldPosLux; // needed by custom fog
    111.   float3 viewDir;
    112.   float3 worldNormal;
    113.   float3 worldRefl;
    114.   INTERNAL_DATA
    115.   };
    116.    
    117.   // Include CustomFog
    118.   // #define SurfaceOutputLux SurfaceOutputLuxHair
    119.    
    120.   // #include "../../LuxCore/LuxCustomFog.cginc"
    121.    
    122. //  void vert (inout appdata_full v, out Input o)
    123. //  {
    124. //  UNITY_INITIALIZE_OUTPUT(Input,o);
    125. //  o.worldPosLux.xyz = 0; //mul(_Object2World, v.vertex).xyz;
    126. //  o.worldPosLux.w = length(mul(UNITY_MATRIX_MV, v.vertex).xyz);
    127. //  }
    128.  
    129.  
    130.  
    131.  
    132.  
    133.   void surf (Input IN, inout SurfaceOutputLuxHair o)
    134.   {
    135.   fixed4 albedo = tex2D(_MainTex, IN.uv_MainTex);
    136.   o.Albedo = albedo.rgb * _Color.rgb;
    137.   o.Alpha = albedo.a * _Color.a;
    138.         o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
    139.    
    140.         // r: spec shift / g: roughness / b: noise
    141.   fixed3 spec = tex2D(_SpecularTex, IN.uv_MainTex).rgb;
    142.   // store per pixel Spec Shift
    143.   o.SpecShift = spec.r * 2 -1;
    144.   // Calculate primary per Pixel Roughness * Roughness1
    145.   o.Specular = spec.g * _Roughness1;
    146.   // Store Roughness for direct lighting
    147.   o.Specular12 = half2(o.Specular, spec.g * _Roughness2);
    148.   // store per pixel Spec Noise
    149.   o.SpecNoise = spec.b;
    150.          
    151.   // Lux Ambient Lighting functions also need o.SpecularColor(rgb)
    152.   // So we have to make it a bit more complicated here
    153.   // Tweak Roughness for ambient lighting
    154.   o.Specular *= o.Specular;
    155.   o.SpecularColor = _SpecularColor1.rgb;
    156.    
    157.   fixed4 ANISO = tex2D(_ANISOTex, IN.uv_MainTex);
    158.         o.AnisoDir = ANISO.rgba;
    159.  
    160.   #include "../../LuxCore/LuxLightingAmbient.cginc"
    161.    
    162.   // Add ambient occlusion stored in vertex color red
    163.   //o.Emission *= IN.color.r;
    164.   }
    165.  
    166. //  Custom Lighting
    167.    
    168.    
    169.    
    170.    
    171.    
    172.    
    173.    
    174.   inline float3 KajiyaKay (float3 N, float3 T, float3 H, float specNoise)
    175.   {
    176.   float3 B = normalize(T + N * specNoise);
    177.   //return sqrt(1-pow(dot(B,H),2));
    178.   float dotBH = dot(B,H);
    179.   return sqrt(1-dotBH*dotBH);
    180.   }
    181.    
    182.  
    183.        
    184.          
    185.          
    186.          
    187.      
    188.      
    189.        
    190.   inline fixed4 LightingLuxHair (SurfaceOutputLuxHair s, fixed3 lightDir, fixed3 viewDir, fixed atten)
    191.   {
    192.        
    193.        fixed3 norm = normalize(s.Normal);
    194.        
    195.   fixed3 h = normalize(normalize(lightDir) + normalize(viewDir));
    196.   float dotNL = max(0,dot(norm, lightDir));
    197.    
    198.   //  Spec
    199.   float2 specPower = exp2(10 * s.Specular12 + 1) - 1.75;
    200.  
    201.        
    202.        
    203.        
    204.         float3 ANISODIR = normalize (
    205.        (float3(s.AnisoDir.r,s.AnisoDir.g,0.5) *2 ) -1
    206.        )
    207.        ;
    208.   //normalize( (s.AnisoDir.rgb * 2) - 1 );
    209.   //;
    210.        
    211.        
    212.        
    213.        
    214.        
    215.   // First specular Highlight / Do not add specNoise here
    216.   float3 H = normalize(lightDir + viewDir);
    217.    
    218.        
    219.        
    220.   float3 spec1 = specPower.x * pow( KajiyaKay(norm, ANISODIR//s.AnisoDir
    221.        * s.SpecShift, H, _PrimaryShift), specPower.x);
    222.    
    223.        // Add 2nd specular Highlight
    224.   float3 spec2 = specPower.y * pow( KajiyaKay(norm, ANISODIR//s.AnisoDir
    225.        * s.SpecShift, H, _SecondaryShift ), specPower.y) * s.SpecNoise;
    226.    
    227.    
    228.    
    229.      
    230.      
    231.    
    232.   //  Fresnel
    233.   fixed fresnel = exp2(-OneOnLN2_x6 * dot(h, lightDir));
    234.   spec1 *= _SpecularColor1 + ( 1.0 - _SpecularColor1 ) * fresnel;
    235.   spec2 *= _SpecularColor2 + ( 1.0 - _SpecularColor2 ) * fresnel;  
    236.   spec1 += spec2;
    237.  
    238.   // Normalize
    239.   spec1 *= 0.125 * dotNL;
    240.  
    241.   // Rim
    242.   fixed RimPower = saturate (1.0 - dot(norm, viewDir));
    243.   fixed Rim = _RimStrength * RimPower*RimPower;
    244.  
    245.   fixed4 c;
    246.   // Diffuse Lighting: Lerp shifts the shadow boundrary for a softer look
    247.   float3 diffuse = saturate (lerp (0.25, 1.0, dotNL));
    248.   // Combine
    249.   c.rgb = //ANISODIR;
    250.   ((s.Albedo + Rim) * diffuse + spec1) * _LightColor0.rgb  * (atten * 2);
    251.   c.a = s.Alpha;
    252.   return c;
    253.   }
    254.  
    255.   ENDCG
    256.   }
    257.   Fallback "Transparent/Cutout/VertexLit"
    258.   CustomEditor "LuxMaterialInspector"
    259. }
    260.  
     
  18. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey lars. Finally diving into the wetness shaders. Works great. The only problem I am getting is with the flow shader. When I use the flow shader the objects that have that shader no longer receive ambient lighting. So the side opposite of the sun becomes pitch black. I am working in forward lighting and Dx11. I have re-imported the latest version but it still does this.
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi baldinoboy,

    i may have a look into this when i come to the office – although i only have a dx10 gpu there…
    lars
     
  20. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    It also does this for me in Dx9.

    Not sure if it is a forward lighting problem or a problem in my project. I am going to import the newest Lux into a new project.
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi baldinoboy,

    i have checked this for both dx9 and dx11, forward rendering, linear and gamma color space:
    image based ambient lighting works in all configurations!?
    (tested with windows 7, nvidia geforce gts 240 (dx11 on a dx10 gpu...) )

    but i have found a "problem" with the simple wetness shader using dx11 and forward rendering – which is fixed now.
    you will find the updated shader in the repo.

    lars
     
  22. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    It took a bit longer than expected cause of distraction and learning bumps but ive some screenshots of my silly learning adventure with Lux, seeing how far i could get with one model. I intend to make a set of models based around the general look of the repeated model in the screenshots for use by folks to play around with PBR things like Lux and any shader writers to test their creations on. Things always take longer than expected though I guess. There's a few assets used, lux of course, particle playground for the rain, environment gator for the the sky, fluidity for the ground mist, i'll get a video in a bit if wanted. I'll build on the scene to test models and other things, and I want to test out some ideas like adding an iridescent shader to lux to simulate oil, for a spreading oil leak type effect using a realtime 2D fluid simulation to create a mask for the effect



     
    SememeS, ludiares and John-G like this.
  23. SirDorius9

    SirDorius9

    Joined:
    Feb 3, 2014
    Posts:
    10
    This looks really nice! But when I try to compile it (both on Android and Windows standalone) it freezes when building assets for the scene (simply tried the demo scene). Any idea why? It just launches 4 UnityShaderCompiler.exe processes that chew up the CPU and the Editor stops responding. Waiting about and hour didn't solve it either. Otherwise works fine in the editor. Using Unity 4.5
     
  24. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    I am getting that build problem too. It does finish but it may take 4 hours for an empty scene to buildo_O.
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    well, it should not take 4 hours to built the built – but just the time it took to import lux in unity 4.4 which for was about 30 min.
    you can decrease built time by replacing the #pragma multi_compile directives with the #pragma define ones like described in the docs.

    lars
     
  26. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Alright. Will do that. My pc is not incredible but is still pretty good. Everything Unity though is crazy slow. Have no idea why. Thank god for Unity 4.5 though. Imports are so much faster:).

    Thanks for the help.
     
  27. SirDorius9

    SirDorius9

    Joined:
    Feb 3, 2014
    Posts:
    10
    I replaced the defines like you described but it's still taking an awful lot of time to finish. The imports took about 10 minutes, but that's not the issue. My laptop is not very powerful indeed, but this is the first time I've experienced performance issues like these i Unity. Maybe there's some kind of compile loop that only happens outside the Editor
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    well, may be you haven’t replaced all #pragma multi_compile
    if so it should go pretty fast. at last it does on my 4 years old mac book pro.

    lars
     
  29. SememeS

    SememeS

    Joined:
    Nov 27, 2012
    Posts:
    127
    yeah use #define as lars says. It makes compile time very fast.

    they're commented out below the #pragma multi_compile


    .
     
  30. SirDorius9

    SirDorius9

    Joined:
    Feb 3, 2014
    Posts:
    10
    No luck yet. I took the "Lux Bumped Specular Materialtest" shader and commented the multi_compile lines

    Code (CSharp):
    1.     //#pragma multi_compile LUX_LIGHTING_BP LUX_LIGHTING_CT
    2.     //#pragma multi_compile LUX_LINEAR LUX_GAMMA
    3.     //#pragma multi_compile DIFFCUBE_ON DIFFCUBE_OFF
    4.     //#pragma multi_compile SPECCUBE_ON SPECCUBE_OFF
    5.     //#pragma multi_compile LUX_AO_OFF LUX_AO_ON
    and uncommented the defines below

    Code (CSharp):
    1.     #define LUX_LIGHTING_CT
    2.     #define LUX_LINEAR
    3.     #define DIFFCUBE_OFF
    4.     #define SPECCUBE_OFF
    5.     #define LUX_AO_OFF
    But it still takes ages to compile (if it ever will finish... it didn't after 15 mins)
     
  31. SirDorius9

    SirDorius9

    Joined:
    Feb 3, 2014
    Posts:
    10
    Oh, never mind. I removed all the shaders I wasn't using from the project and it compiled. Though I think it's strange Unity was trying to compile the shaders that I wasn't using in the build scenes.
     
  32. tynew

    tynew

    Joined:
    Sep 25, 2013
    Posts:
    122
    Hi guys,

    I was wondering if someone could explain to me how Ambient occlusion works with Lux. It doesn't seem to work like a regular occlusion map like in marmoset.

    Most objects I have don't show AO. I thought AO shadows were meant to be present when an object has no direct light source affecting it.
     
  33. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Just a quick one to say it took some getting used to after using Lux chiefly with an i7 but the shaders work pretty well on android, least on my HTC One (H7), didnt take a hit on a reasonably detailed scene and it was extremely pretty. I don't know if it was a factor good or bad but it was doing this while rendering through two cams stereoscopically each with a UI cam. Thumbs up!

    Worth mentioning that when it comes to build you want to have as few permutations as possible or build will take forever, removing unused shaders and #define instead of #pragma multicompile makes the build time tiny

    When I have something i'd say was a good example and fill my own intentions for a public VR app i'll post it somewhere, i'll maintain i love the way Lux looks and quite surprisingly as i wasn't expecting it to run so well I can imagine making it my shader family of choice for mobile. Lack of shaderforge is still a bummer though altlthough not much can be done i spose, unless shaderforge's creator is able to offer a more general interface to systems like Lux than the skyshop interface (This may be a silly thing to say i dont really know how this is handled, just the nonclemature of 'shaderforge plugin' on behalf of skyshop offers the suggestion that plugins might become a regular thing for it. its not for me to speculate maybe)
     
  34. ludiares

    ludiares

    Joined:
    Jul 14, 2011
    Posts:
    242
    AO textures use the alpha channel of the texture, so you need to turn on the "generate alpha from grayscale" option on the texture import settings
     
  35. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Hi larsbertram

    I finally gave in and downloaded lux after months of telling myself to wait for Unity 5 shaders. But a month of using DDO for Texturing, playing some PBR enabled games as well as Tom from the Relief Terrain Package officially supporting Lux for his deffered PBR Functionality finally made me give in to temptation.

    Now, I do know some basics, but I still get confused a lot about the PBR Topics, and having switched one Asset to PBR and somehow not liking the results (using the PBR Outputs of DDO), I came to the conclusion that most probably, I am doing it wrong.

    Is there any good documentation about Lux, or PBR in general? I know the names of the maps, but I am totally confused as to what does what.

    More specific question:
    - is the Spec-color / Metalness shader giving the same results, just with different input maps? Or is there a particular reason to pick one over the other?
    - Are Gloss and Roughness Maps the same? Reason I ask is, DDO has no Roughness map, only Gloss. If its not, how do I convert Gloss to Roughness?
    - What is the easiest way to combine all the maps for the Metalness shaders? I found a way to do it in Photoshop, but I am not 100% I can just take a single channel from the output maps of DDO and copy it. Shouldn't I first combine all the channels of the DDO Output map before copying to the destination channel of the combined map?
    - There are no more controls to control shinyness or spec color.... I guess this is now all controlled by the respective input map?
    - To achieve that nice metallic look with reflectivity (which is where the metalness map has an effect, yes?), I need the diffuse cubemap, correct? What does the specular one do?


    Thanks for any help

    Gian-Reto
     
  36. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Ahh the metalness workflow is an alternate to the spec/rough as far as i took it, a good reference is in Lux\Helpers\ it has a guide to the general values for various materials using the Blinn-Phong reflectance model (Which is the lightest of the two principle Lux models). Rather than concentrate on a metalness workflow with the new dDo i concentrated on spec/rough and roughness can be seen as the same as gloss, you don't need to change the value its just the way you see it i suppose, there's no unified standard or terminology for pbr yet really

    Taking the spec/rough approach you have rgb channels of the texture for the specular and rough in the alpha, spec controls the degree of reflectivity and roughness controls the sharpness of the reflection, like a bright ball bearing would reflect a deal when it was polished and would still reflect a deal when smudged by light grease but the grease would widen the specular 'spread' i guess i've seen it called, blur the reflection

    PBR works mostly around the idea that is (almost) universally accepted that there are dialectrics and metals, metals have reflections that are the colour of the metal, dialectrics have reflections that that are the colour of the light contribution, so you'd be using the specular colour to reproduce metallic reflections - the metalness workflow iirc works so you specify which areas of a texture are metallic and which are not

    While this is my approach to creating an asset and might not be ideal, efficient or fast and i am still very much learning it might help you get set up, at least until you have the hang of it.

    Assuming I use dDo i'd create maps for a diffuse spec gloss (you can switch the term with roughness and its an artistic matter anyways so its no hard and fast) and normal and so on, i think the skyshop preset should work fine, it certainly helps that 3Do is based around skyshop for previews, and get your asset in 3Do looking quite nice under the selection of environment maps

    After a first run of baking out your maps into your asset folder, i'd have a few environment maps prepared, i find having having skyshop really useful here for convolving panoramic HDRIs in various conditions quickly with its gpu convolution as this lets you see how your asset is reflecting the environment in different conditions but you can readily create a few quick environments inside unity with varying lighting conditions and use Lux's probe component attached to a gameobject to grab some cubemaps which Lux can then convolve to very useful environment maps

    I suppose you have to decide on some central settings to your production, wether you work in linear or gamma colour space (linear recommended if you can), wether your cameras are rendering in HDR, wether you are using deferred or forward lighting paths (deferred has limited flexibility in lighting model so iirc it loses some of the quality the Cook-Torrance reflectance model can have in Forward rendering, but some gains), and wether you are using the Cook-Torrance or Blinn-Phong reflectance model. This last choice is one of Lux's great strengths I think and I think the Cook-Torrance model looks great, but is heavier and for learning, Blinn-Phong is probably more straightforward as it probably has more in common with 3Do and the above mentioned dontnod chart is good reference for this model

    You'd set this up with a Lux Setup script attached to a gameobject which will be the central place to control the IBL in your scene, using the spec and diffuse cubemap slots to place your convolved cubemaps, be they from photographic HDRI or probes taken from within Unity

    Put a Lux Bumped Specular IBL material on your asset and this is pretty much where you begin feeling it out after assigning some environment maps, assign diffuse, normal and spec.rgb+gloss.a maps and see what it looks like under the environment lighting, switch environment maps, adjust the hdr scale, spec and diffuse multiplier in Lux Setup to get a feekl, add light sources to the scene and from a variety of lighting situations decide what aspects of the material to you look unsatisfying and how you think they should reflect, if reflecting at all, to look more convincing. Then it really is feeling it out, using the dontnod chart as a general guide, adjusting the spec and roughness contributions by brightness and contrast to get a feeling for what kind of values give bright reflections, blurry reflections, sharp surface detail (the specular reflections along with the normal map work a great deal in tandem here), worn detail, identifying when the texture of the asset covers both metal and dialectric materials and how they should reflect colour and light intensity and sharpness accordingly and yeah, i find spending a while with one aset and a good variety of environment maps to switch betwen helps a lot, the IBL provided by the env maps being critical to the appearance of your asset when placed in the environment

    Finishing one asset to satisfaction, moving to another, learning more subtlety to the factors behind the result, possibly returning to the first with the new knowledge and so on can get you up to speed in not too large amount of time although as i'm finding i'm still always learning, every real world substance starts gaining some ballpark values in your head, and when it comes to placing the final asset you'd have to do something i've not fully broached yet and consider the management of multiple probes throughout an environment for accurate reflections, box correction for even more accurate reflections (in rectangular spaces or very vague positional reflections), the probe settings give you a variety of options for pulling to hdr, capturing the initial cubemap (check rendertocubemap) and so on

    So yes, sorry if that was a bit rambling, but my advice, or how i'm learning, is by using the spec/roughness maps rather than using the metalness shaders as they approximate i guess the 'natural' environment of 3Do as well as being a bit more straightforward to understand (and i think much more represented in the Lux shader collection) and starting with a Bumped Specular IBL shader is a natural point at which to learn then go on to the more exotic flavours.

    And yes, for starting i guess a forward rendering, blinn-phong based approach probably represents the most familiar referenced appearance although if you're anything like me you'll favour Cook-Torrance if you can get away with it because it looks really great when you've got your maps in the right spot

    And finally! Lux's shaders are based on Unity's surface shaders and this also is a great strength, as they're very easy to edit and understand whilst being very well featured, if there's a shader you want that doesn't seem to be there but combines the features of two or even more other shaders, it's often quite straightforward to knock up an ad-hoc shader of your own by merging their features. And when you're set on your main settings changing the multi-compiles to #defines saves a bunch of build time

    This might all not be helpful at all but it's how i'm getting to grips with it and i'm starting to feel very happy with some of the results, so i thought it could help
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi there,
    first of all, make sure that you get the latest version from the github repo!
    lux ships with a lot of doc files so i would recommend to start there.
    but you could also have a look here:
    http://seblagarde.wordpress.com/2011/08/17/feeding-a-physical-based-lighting-mode/
    http://www.marmoset.co/toolbag/learn/pbr-theory
    http://www.marmoset.co/toolbag/learn/pbr-practice

    it is more a personal choice which workflow you prefer. the rendering results of both should be nearly the same.
    unity 5 will use specular color so most lux shaders use specular color as well whereas udk uses metalness.
    naming... sorry about any confusion. using lux roughness = 0 (= black means: very rough) and roughness = 1 means very smooth. i should have named it smoothness but then there would be even 3 different words for more or less the same thing.
    i would simply use photoshop.
    yes: no more hacky tweaking any params until it looks fine. set up specular color and roughness e. g. using the provided lookup table and you should be done.
    no and no: the "metallic look with reflectivity" does NOT need a metallness map (or the metalness workflow): it also works with the specular color or better: specular reflectance workflow of course: metal usually have a specular color above 0.5 which is really colored whereas non metals (or dielectrics) only have grayscale specular color values around 0.03.
    And reflections come from the specular cubemap NOT the diffuse one.

    lars
     
  38. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi there,
    it more or less works like it does in marmoset: Black parts of the AO texture occlude ambient diffuse and specular lighting. NOT the direct lighting. Direct lighting would be occluded by real time shadows.

    you have to keep in mind that AO is taken from the alpha channel of the given texture.
    so the easiest way would be to check "create alpha from grayscale" in the import settings of the texture.

    lars
     
  39. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    guys, thank you so much for your posts. So much information thal I will have to read again tomorrow to make sure I got everything :)

    just one last question: what is the purpose of the diffuse cubemap? Ambient lighting?
     
  40. popawheelie

    popawheelie

    Joined:
    May 27, 2013
    Posts:
    23
    Firstly awesome asset.

    Just wondering if anyone had used shader forge to create compatible shaders? If so, if there was any images of the set up in shader forge.
     
  41. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    To start off, this is an amazing package! But when ever I use the lux terrain material the terrain is extremely bright when looking at distance, very unnatural. There are white specular highlights, looking at a texture from a distance of say 50 which disappear as I get closer to the texture. But these artifacts seem to disappear once I apply an arbitrary color map. The screenshots of terrains in this thread seem to provide results contrary to mine, I'll provide some screen shots later. Also what are some good ways of making realistic spec maps for rocks using the bump spec shader or which ever one that provides a gloss option. One last thing, how does one apply the far terrain and or grass billboard, is it automatically applied through importing or does one have to manually apply it? Thanks for reading.
     
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    yes, the diffuse cubemap is used to for ambient diffuse lighting (and replaces the "ambient light" you would setup editing the rendering settings).
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    have you downloaded the latest version from the github repo?
    and the terrain shader needs a color map as far as i can remeber.

    lars
     
  44. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    Thanks for the reply! I have not downloaded the lastest version although applying a color map still gives the the same result as it would with out the color map, which is weird. The advanced terrain shaders are applied automatically right?

    Got it!
     
    Last edited: Aug 17, 2014
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    nope! you ahve to create a material and assign it to the terrain.

    looks like you have done it!
    your scene looks pretty nice, well done!

    lars
     
  46. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    Thanks! Sorry for not making my question clear but is the far terrain, billboards fixes, etc applied when one adds the material to the terrain, it looks like the billboard lighting fix is fixed when the lux terrain control is applied to terrain, how about the other shaders?
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hmm. you should check the import format of the color map...
    at far distances only the color map is visible (plus the terrain normal).

    check the average colors you have applied.
    and please check your fog settings: right now only foge mode exp2 is supported.

    lars
     
  48. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    Thanks for the reply! I'll see about this. And get back.
     
  49. omgeric

    omgeric

    Joined:
    Aug 18, 2013
    Posts:
    18
    For some reason none of the shaders actually use the cubemaps I assign, I just get an ugly large white reflection. I've checked and unchecked disable diffuse/specular cube etc... has anyone else had this problem?
     
  50. Eric2241

    Eric2241

    Joined:
    Dec 2, 2012
    Posts:
    642
    The suggestion helped. Thanks!