Search Unity

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

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

  1. maxwood

    maxwood

    Joined:
    Mar 28, 2012
    Posts:
    30
    Thanks Lars :) I will let you know how we get on!
     
  2. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey lars. Is there be a way to disable/enable the diffuse and specular IBL on all materials without going to every material? Thanks
     
  3. larsbertram1

    larsbertram1

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

    you could edit the according shader(s) (like bumped specular) and comment:
    #pragma multi_compile DIFFCUBE_ON DIFFCUBE_OFF
    #pragma multi_compile SPECCUBE_ON SPECCUBE_OFF

    and define:

    #define DIFFCUBE_OFF
    #define SPECCUBE_OFF

    lars
     
    cadviz likes this.
  4. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Cool. Thanks
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you are welcome!
     
  6. cadviz

    cadviz

    Joined:
    Jan 17, 2012
    Posts:
    28
    Hi everybody...
    I tried to create Glass material; but failed
    Any Advice..?
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    you may start with the "Lux Transparent Bumped Specular" shader.
     
    cadviz likes this.
  8. Botanika

    Botanika

    Joined:
    Nov 2, 2013
    Posts:
    60
    Use Lux/transparent/Bumped Specular shader.

    >Set the Main Color alpha to about 40%
    >Set the Main Color Rgb to a somewhat black desaturated color. (rgb (38,46,51) should be good)
    >Leave the Base Color slot empty.
    >Plug a desaturated Texture (RGBA (71,84,84, 240)) to the Specular Color slot.

    If the glass material is dirty, add some details into the alpha channel of the spec map.
     
    cadviz likes this.
  9. cadviz

    cadviz

    Joined:
    Jan 17, 2012
    Posts:
    28
    I'll see If can make it..
    I wish if there would be a "Ready (pre-made) LUX Materials library", especially those for Box Projection...;)
    Thanks for help :) & Best Regards
     
  10. x_african_warrior_x

    x_african_warrior_x

    Joined:
    Jun 24, 2014
    Posts:
    80
    Hi Lars,

    been having fun with your shaders and im impressed. I like the terrain shader although its not as complex as the ultrashader which i have. i am almost getting same results with the lux terrain one. one thing i would really like to work with the lux setup is the colormap editor. it makes everything worthwhile. the iamges below aare done with lux shaders aand results r nice.
     

    Attached Files:

  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    i have not tested the color map painting tool with lux but i think it should work… why not?
    as far as your images are concerned: nice but i could imagine that adding more variety to the roughness and spec textures will help a lot to distinguish concrete from rusted metal e.g.
    and using ambient occlusion (most likely linked to uv2) should enhance lighting of the canopy.

    lars
     
  12. SememeS

    SememeS

    Joined:
    Nov 27, 2012
    Posts:
    127
    Been testing lux skin shader with makehuman. Here are some results.

    AO_OFF (I don't like the AO on skin)
    DIFFCUBE_OFF
    SPECCUBE_ON

    I'm not using very realistic IBL and cubemaps though(own choice). Rather only to influence spec lighting cause I plan on mixing with light probes/baked light.
    I'm using LDR cubemaps made with panorma_to_cubemap and then convolved with lux's Env Probe script.



     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi steve,

    that looks pretty cool!
    lars
     
  14. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I think the eyes could do with a touch of work but thats possibly doable mainly with giving them highlights and that is pretty swanky work, nice
     
  15. SememeS

    SememeS

    Joined:
    Nov 27, 2012
    Posts:
    127
    :) thanks!

    Yeah, I just used the default eyes for now.
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    talking about eyes: i guess it is important to add ambient occlusion by adding some extra geometry which only darkens the eyes close to the lids (using the lux transparent shader).
    see: http://docs.cryengine.com/display/SDKDOC2/Eye Shader for details

    lars
     
  17. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    How does Lux handle reflections?
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    lux supports specular ambient lighting which means: convolved specular cubemaps.
    lux also supports box projected cubemaps.

    lars
     
  19. thephoenix

    thephoenix

    Joined:
    May 21, 2014
    Posts:
    15
    Lars,

    When i try to build my game it comes up with this:

    Assets/Lux/Lux Scripts/Lux Cubemapper/Scripts/LuxCubeProcessor.cs(1057,1): error CS8025: Parsing error

    Please can you help me to get it working.
     
  20. larsbertram1

    larsbertram1

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

    make sure, you have the latest version from the github repository.
    that should fix your issue.
    it also comes with some additional nice features like specular AA.

    lars
     
  21. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    Hi, Lars. Just wanna say thanks for great (and free!) shaders, this is exactly what I'm looking for! Keep it up! And couple screenshots I made with lux today :)



    э



     

    Attached Files:

    SememeS likes this.
  22. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    I suggest you put a little "Unkostenbeitrag" fee on your Asset Store package and in turn, update it more frequently. I'd gladly pay a little convenience fee to not have to start messing with git or manual download+merge regularly when Unity has such a nice package subscription mechanism :D

    I guess it's too late now most of us have the free license to it. Perhaps make a new "Pro, updates more regularly" one for a fiver or tenner.

    OK maybe I'm just a lazy old bastard :p
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi id0,

    thanks fpr sharing the screenshoots.
    they look really nice.

    lars
     
  24. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    That is incredibly awesome id0. Great job.
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi metaleap,

    the fact that i havn’t updated the regular asset store package is simply caused by the fact that i am very short on time.
    and it takes some to create all the includes sub packages.
    and it also takes some time (about 5 days) for the updated package to get approved.

    so using a github repo is much, much faster for both sides: me and you.

    but you are right: it is time to update the regular package.

    lars
     
  26. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey lars. Could you put a Rain Amount option in the Lux Setup like you did with AFS. Do not know how much more expensive this makes the shaders but it works great. Also when you add Setup AFS it uses that Rain Amount. So with one slider you control the entire scenes shininess. If that could work it would be awesome.
     
  27. larsbertram1

    larsbertram1

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

    having one general slider for vegetation and wetness might be ok as pretty much most plants will be exposed to the same weather conditions – but doing the same with all materials of your scene is not really a good idea i guess: just think about a simple outdoor/indoor scene: when it is raining it would be wet outside and inside!

    and there is a lot more going on than just raising the roughness/smoothness.
    so i think it will take some more thinking…

    lars
     
  28. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    Hi again, Lars! Everything is cool, but the eye shader is a bit wrong. That's what I mean:

     

    Attached Files:

    • eye.jpg
      eye.jpg
      File size:
      297.3 KB
      Views:
      2,019
  29. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Use this settings
    Link
     
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi id0,

    your explanation makes sense, thank you.
    but unfortunately it is not that easy to use the normal for specular highlights and the inverted normal for diffuse highlights – unless you drop deferred lighting (as it would cause a new lighting function) or write a multipass shader (which is not that easy using surface shaders).
    but i guess it is only visible if you have very big close ups – so i hope you can live with that "bug" for a while.

    lars
     
  31. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    We could probably live with a forward-only version of the eye shader. Eyes are so small that the benefits of deferred rendering probably don't even matter that much.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, i they are so small i think one could also live with both specular and diffuse rendered convex… ;-)
    but i will have a look into it.

    lars
     
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi id0,

    please check the eye shader i have added below:
    it renders diffuse lighting using the "inversed" normal (convex) and specular using the regular normal (concave).
    it is still not 100% accurate as also the iris (which should be convex) contributes to the specular lighting but might be better than the previous shader.

    to make the shader compile it should be placed in the same folder as the old one: Lux -> Lux Shader -> Human -> Eye
    you may name it: "Lux Eye Ball FW.shader"

    lars


    Code (csharp):
    1.  
    2. Shader "Lux/Human/Eye Ball FW" {
    3.     Properties {
    4.         _MainTex ("Base (RGB) Heightmap (A)", 2D) = "white" {}
    5.         _SpecTex ("Specular Color (RGB) Roughness (A)", 2D) = "black" {}
    6.         _BumpMap ("Normalmap", 2D) = "bump" {}
    7.         _DiffCubeIBL ("Custom Diffuse Cube", Cube) = "black" {}
    8.         _SpecCubeIBL ("Custom Specular Cube", Cube) = "black" {}
    9.  
    10.         _PupilSize ("PupilSize", Range (0.01, 1)) = 0.5
    11.         _Parallax ("Height", Range (0.005, 0.08)) = 0.08
    12.  
    13.         // _Shininess property is needed by the lightmapper - otherwise it throws errors
    14.         [HideInInspector] _Shininess ("Shininess (only for Lightmapper)", Float) = 0.5
    15.  
    16.     }
    17.     SubShader {
    18.         Tags { "RenderType"="Opaque" }
    19.         LOD 200
    20.  
    21.         CGPROGRAM
    22.         #pragma surface surf LuxDirectEye fullforwardshadows exclude_path:prepass nolightmap nodirlightmap noambient
    23.         #pragma glsl
    24.         #pragma target 3.0
    25.  
    26.         #pragma multi_compile LUX_LIGHTING_BP LUX_LIGHTING_CT
    27.         #pragma multi_compile LUX_LINEAR LUX_GAMMA
    28.         #pragma multi_compile DIFFCUBE_ON DIFFCUBE_OFF
    29.         #pragma multi_compile SPECCUBE_ON SPECCUBE_OFF
    30.  
    31. //        #define LUX_LIGHTING_BP
    32. //        #define LUX_LINEAR
    33. //        #define DIFFCUBE_ON
    34. //        #define SPECCUBE_ON
    35.  
    36.         // We cant use AO here as the eye ball tends to move...
    37.         #define LUX_AO_OFF
    38.  
    39.         // include should be called after all defines
    40.         #include "../../LuxCore/LuxLightingDirect.cginc"
    41.  
    42.         sampler2D _MainTex;
    43.         sampler2D _SpecTex;
    44.         sampler2D _BumpMap;
    45.         #ifdef DIFFCUBE_ON
    46.             samplerCUBE _DiffCubeIBL;
    47.         #endif
    48.         #ifdef SPECCUBE_ON
    49.             samplerCUBE _SpecCubeIBL;
    50.         #endif
    51.  
    52.         // shader specific inputs
    53.         float _PupilSize;
    54.         float _Parallax;
    55.  
    56.         // Is set by script
    57.         float4 ExposureIBL;
    58.  
    59.         struct Input {
    60.             float2 uv_MainTex;
    61.             float3 viewDir;
    62.             float3 worldNormal;
    63.             float3 worldRefl;
    64.             INTERNAL_DATA
    65.         };
    66.  
    67.         void surf (Input IN, inout SurfaceOutputLux o) {
    68.  
    69.         //    Calculate Parallax
    70.             half h = tex2D (_MainTex, IN.uv_MainTex).a;
    71.             float2 offset = ParallaxOffset (h, _Parallax, IN.viewDir);
    72.  
    73.         //    Apply Pupil Size
    74.             float2 UVs = IN.uv_MainTex;
    75.             float2 delta = float2(0.5, 0.5) - UVs;
    76.             // Calculate pow(distance,2) to center (pythagoras...)
    77.             float factor = (delta.x*delta.x + delta.y*delta.y);
    78.             // Clamp it in order to mask our pixels, then bring it back into 0 - 1 range
    79.             // Max distance = 0.15 --> pow(max,2) = 0.0225
    80.             factor = saturate(0.0225 - factor) * 44.444;
    81.             UVs += delta * factor * _PupilSize;
    82.  
    83.         //    Now sample albedo and spec maps according to the pupil’s size and parallax
    84.             o.Albedo = tex2D(_MainTex, UVs + offset).rgb;
    85.             o.Alpha = 1;
    86.             fixed4 spec_albedo = tex2D(_SpecTex, UVs + offset);
    87.         //    Normal map
    88.             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex - offset));
    89.         //    Specular Color
    90.             o.SpecularColor = spec_albedo.rgb;
    91.         //    Roughness – gamma for BlinnPhong / linear for CookTorrence
    92.             o.Specular = LuxAdjustSpecular(spec_albedo.a);
    93.  
    94.             //#include "../../LuxCore/LuxLightingAmbient.cginc"
    95.  
    96.  
    97.  
    98.         //        ///////////////////////////////////////
    99. //         Further functions to keep the surf function rather simple
    100.      
    101.         #ifdef SPECCUBE_ON
    102.             float NdotV = max(0, dot(o.Normal, normalize(IN.viewDir.xyz)));
    103.         #endif
    104.  
    105. //        ///////////////////////////////////////
    106. //         Lux IBL / ambient lighting
    107.      
    108.         // set o.Emission = 0.0 to make diffuse shaders work correctly
    109.         o.Emission = 0.0;
    110.         float3 worldNormal = WorldNormalVector(IN, float3( -o.Normal.x, -o.Normal.y, o.Normal.z));
    111.      
    112. //        add diffuse IBL
    113.         #ifdef DIFFCUBE_ON
    114.             fixed4    diff_ibl = texCUBE (_DiffCubeIBL, worldNormal);
    115.             #ifdef LUX_LINEAR
    116.                 // if colorspace = linear alpha has to be brought to linear too (rgb already is): alpha = pow(alpha,2.233333333).
    117.                 // approximation taken from http://chilliant.blogspot.de/2012/08/srgb-approximations-for-hlsl.html
    118.                 diff_ibl.a *= diff_ibl.a * (diff_ibl.a * 0.305306011 + 0.682171111) + 0.012522878;
    119.             #endif
    120.             diff_ibl.rgb = diff_ibl.rgb * diff_ibl.a;
    121.             o.Emission = diff_ibl.rgb * ExposureIBL.x * o.Albedo;
    122.         #else
    123.             o.Emission = ShadeSH9 ( float4(worldNormal.xyz, 1.0)) * o.Albedo;
    124.         #endif
    125.      
    126. //        add specular IBL      
    127.         #ifdef SPECCUBE_ON
    128.             half3 worldRefl = WorldReflectionVector (IN, o.Normal);  
    129.  
    130.             #if defined (LUX_LIGHTING_CT)
    131.                 o.Specular *= o.Specular * (o.Specular * 0.305306011 + 0.682171111) + 0.012522878;
    132.             #endif
    133.  
    134.             float mipSelect = 1.0f - o.Specular;
    135.             mipSelect = mipSelect * mipSelect * 7; // but * 6 would look better...
    136.             fixed4 spec_ibl = texCUBElod (_SpecCubeIBL, float4(worldRefl, mipSelect));
    137.             #ifdef LUX_LINEAR
    138.                 // if colorspace = linear alpha has to be brought to linear too (rgb already is): alpha = pow(alpha,2.233333333) / approximation taken from http://chilliant.blogspot.de/2012/08/srgb-approximations-for-hlsl.html
    139.                 spec_ibl.a *= spec_ibl.a * (spec_ibl.a * 0.305306011 + 0.682171111) + 0.012522878;
    140.             #endif
    141.             spec_ibl.rgb = spec_ibl.rgb * spec_ibl.a;
    142.             // fresnel based on spec_albedo.rgb and roughness (spec_albedo.a) / taken from: http://seblagarde.wordpress.com/2011/08/17/hello-world/
    143.             float3 FresnelSchlickWithRoughness = o.SpecularColor + ( max(o.Specular, o.SpecularColor ) - o.SpecularColor) * exp2(-OneOnLN2_x6 * NdotV);
    144.             // colorize fresnel highlights and make it look like marmoset:
    145.             // float3 FresnelSchlickWithRoughness = o.SpecularColor + o.Specular.xxx * o.SpecularColor * exp2(-OneOnLN2_x6 * NdotV);  
    146.             spec_ibl.rgb *= FresnelSchlickWithRoughness * ExposureIBL.y;
    147.             // add diffuse and specular and conserve energy
    148.             o.Emission = (1 - spec_ibl.rgb) * o.Emission + spec_ibl.rgb;
    149.  
    150.         #endif
    151.  
    152.  
    153.         }
    154.  
    155.  
    156.         /////////////////////////////// forward lighting
    157.  
    158.         float4 LightingLuxDirectEye (SurfaceOutputLux s, fixed3 lightDir, half3 viewDir, fixed atten){
    159.             // get base variables
    160.  
    161.             // normalizing lightDir makes fresnel smoother
    162.             lightDir = normalize(lightDir);
    163.             // normalizing viewDir does not help here, so we skip it
    164.             half3 h = normalize (lightDir + viewDir);
    165.             // dotNL has to have max
    166.             float dotNL = max (0, dot (s.Normal, lightDir));
    167.             float dotNH = max (0, dot (s.Normal, h));
    168.          
    169.             #if !defined (LUX_LIGHTING_BP) && !defined (LUX_LIGHTING_CT)
    170.                 #define LUX_LIGHTING_BP
    171.             #endif
    172.  
    173.         //    ////////////////////////////////////////////////////////////
    174.         //    Blinn Phong  
    175.             #if defined (LUX_LIGHTING_BP)
    176.             // bring specPower into a range of 0.25 – 2048
    177.             float specPower = exp2(10 * s.Specular + 1) - 1.75;
    178.  
    179.         //    Normalized Lighting Model:
    180.             // L = (c_diff * dotNL + F_Schlick(c_spec, l_c, h) * ( (spec + 2)/8) * dotNH˄spec * dotNL) * c_light
    181.          
    182.         //    Specular: Phong lobe normal distribution function
    183.             //float spec = ((specPower + 2.0) * 0.125 ) * pow(dotNH, specPower) * dotNL; // would be the correct term
    184.             // we use late * dotNL to get rid of any artifacts on the backsides
    185.             float spec = specPower * 0.125 * pow(dotNH, specPower);
    186.  
    187.         //    Visibility: Schlick-Smith
    188.             float alpha = 2.0 / sqrt( Pi * (specPower + 2) );
    189.             float visibility = 1.0 / ( (dotNL * (1 - alpha) + alpha) * ( saturate(dot(s.Normal, viewDir)) * (1 - alpha) + alpha) );
    190.             spec *= visibility;
    191.             #endif
    192.          
    193.         //    ////////////////////////////////////////////////////////////
    194.         //    Cook Torrrence like
    195.         //    from The Order 1886 // http://blog.selfshadow.com/publications/s2013-shading-course/rad/s2013_pbs_rad_notes.pdf
    196.  
    197.             #if defined (LUX_LIGHTING_CT)
    198.             float dotNV = max(0, dot(s.Normal, normalize(viewDir) ) );
    199.  
    200.         //    Please note: s.Specular must be linear
    201.             float alpha = (1.0 - s.Specular); // alpha is roughness
    202.             alpha *= alpha;
    203.             float alpha2 = alpha * alpha;
    204.  
    205.         //    Specular Normal Distribution Function: GGX Trowbridge Reitz
    206.             float denominator = (dotNH * dotNH) * (alpha2 - 1) + 1;
    207.             denominator = Pi * denominator * denominator;
    208.             float spec = alpha2 / denominator;
    209.  
    210.         //    Geometric Shadowing: Smith
    211.             float V_ONE = dotNL + sqrt(alpha2 + (1 - alpha2) * dotNL * dotNL );
    212.             float V_TWO = dotNV + sqrt(alpha2 + (1 - alpha2) * dotNV * dotNV );
    213.             spec /= V_ONE * V_TWO;
    214.             #endif
    215.  
    216.         //    Fresnel: Schlick
    217.             // fast fresnel approximation:
    218.             fixed3 fresnel = s.SpecularColor.rgb + ( 1.0 - s.SpecularColor.rgb) * exp2(-OneOnLN2_x6 * dot(h, lightDir));
    219.             // from here on we use fresnel instead of spec as it is fixed3 = color
    220.             fresnel *= spec;
    221.          
    222.         // Final Composition
    223.             fixed4 c;
    224.             // we only use fresnel here / and apply late dotNL
    225.  
    226.             // we have to use the "concave" normal for diffuse here
    227.             //s.Albedo
    228.             c.rgb = ( s.Albedo * _LightColor0.rgb * max (0, dot ( float3( -s.Normal.x, -s.Normal.y, s.Normal.z), lightDir)) + fresnel * _LightColor0.rgb * dotNL) * (atten * 2);
    229.  
    230.             c.a = s.Alpha; // + _LightColor0.a * fresnel * atten;
    231.             return c;
    232.         }
    233.  
    234.  
    235.         ENDCG
    236.     }
    237.     FallBack "Diffuse"
    238.     CustomEditor "LuxMaterialInspector"
    239. }
    240.  
     
  34. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    Hey Lars, I dont understand correctly difference between this renderers, but everything work and look just great for me. Thank you very much! :D
     
  35. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    Got some new renders in lux (and made $30 off the model), god I love it. PLEASE make it compatible with new marmoset!!!!!!!!!
    Anyways here it is.



    Feedback would be a thumbs up from me!
     
    SememeS likes this.
  36. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Hm.... what kind of metal is the gun supposed to be made of?
    The diffuse looks a bit bright, I'd imagine it should be a bit darker, and the specular increased.

    Very good texture work otherwise.
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    well, the new shader uses a special lighting function (for both direct and ambient) which renders the specular lighting using the regular normal (from the normal map) which is convex following the shape of the lens.
    the calculation of the diffuse lighting is based on the "inverse" normal (concave) following the concave shape of the iris.
    this shader always uses the forward lighting path.

    lars
     
    Last edited: Jul 8, 2014
  38. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    Too much smart words :eek: I show the screenshot better



    So, evrething looks fine for me, thanks again :)
     

    Attached Files:

    • eyes.jpg
      eyes.jpg
      File size:
      33.6 KB
      Views:
      1,984
    SememeS likes this.
  39. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Yeah, that looks loads better.
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    that looks pretty cool indeed!
    so i will update the shader in the repo (replacing the old one).

    lars
     
  41. ludiares

    ludiares

    Joined:
    Jul 14, 2011
    Posts:
    242
    Well, in fact I worked on something that would enable one to do precisely that, having some materials with a Wetness value that you could adjust in the editor/runtime. It mixes the specular/roughness texture with that of a water material(0.04 specular value, 1 roughness value) given the Wetness value set on the inspector, a mask texture and a Wetness ignore value for metals and semi-metals.
    So, this is the shader(Bumped Specular):
    Code (CSharp):
    1.  
    2. Properties {
    3.     _Color ("Diffuse Color", Color) = (1,1,1,1)
    4.     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
    5.     _SpecTex ("Specular Color (RGB) Roughness (A)", 2D) = "black" {}
    6.     _waterSpecTex(" Water Specular Color (RGB) Roughness (A)", 2D) = "black" {}
    7.     _waterMask(" Water Mask (A)", 2D) = "white" {}
    8.     _BumpMap ("Normalmap", 2D) = "bump" {}
    9.     _DiffCubeIBL ("Custom Diffuse Cube", Cube) = "black" {}
    10.     _SpecCubeIBL ("Custom Specular Cube", Cube) = "black" {}
    11.     _WetnessIgnore ("Diffuse Color Invariation by Water", Range(0,1)) = 0.5
    12.  
    13.     // _Shininess property is needed by the lightmapper - otherwise it throws errors
    14.     [HideInInspector] _Shininess ("Shininess (only for Lightmapper)", Float) = 0.5
    15.     [HideInInspector] _AO ("Ambient Occlusion Alpha (A)", 2D) = "white" {}
    16. }
    17.  
    18. SubShader {
    19.     Tags { "RenderType"="Opaque" }
    20.     LOD 400
    21.  
    22.     CGPROGRAM
    23.     #pragma surface surf LuxDirect noambient
    24.     #pragma glsl
    25.     #pragma target 3.0
    26.  
    27.  
    28.     // #pragma debug
    29.  
    30.     #pragma multi_compile LUX_LIGHTING_BP LUX_LIGHTING_CT
    31.     #pragma multi_compile LUX_LINEAR LUX_GAMMA
    32.     #pragma multi_compile DIFFCUBE_ON DIFFCUBE_OFF
    33.     #pragma multi_compile SPECCUBE_ON SPECCUBE_OFF
    34.     #pragma multi_compile LUX_AO_OFF LUX_AO_ON
    35.  
    36. //    #define LUX_LIGHTING_BP
    37. //    #define LUX_LINEAR
    38. //    #define DIFFCUBE_ON
    39. //    #define SPECCUBE_ON
    40. //    #define LUX_AO_OFF
    41.  
    42.     // include should be called after all defines
    43.     #include "../LuxCore/LuxLightingDirect.cginc"
    44.  
    45.     float4 _Color;
    46.     sampler2D _MainTex;
    47.     sampler2D _SpecTex;
    48.     sampler2D _BumpMap;
    49.     sampler2D _waterSpecTex;
    50.     sampler2D _waterMask;
    51.     float _WetnessIgnore;
    52.     #ifdef DIFFCUBE_ON
    53.         samplerCUBE _DiffCubeIBL;
    54.     #endif
    55.     #ifdef SPECCUBE_ON
    56.         samplerCUBE _SpecCubeIBL;
    57.     #endif
    58.     #ifdef LUX_AO_ON
    59.         sampler2D _AO;
    60.     #endif
    61.     float _Wetness;
    62.     // Is set by script
    63.     float4 ExposureIBL;
    64.  
    65.     struct Input {
    66.         float2 uv_MainTex;
    67.         float2 uv_BumpMap;
    68.         #ifdef LUX_AO_ON
    69.             float2 uv_AO;
    70.         #endif
    71.         float3 viewDir;
    72.         float3 worldNormal;
    73.         float3 worldRefl;
    74.         INTERNAL_DATA
    75.     };
    76.  
    77.     void surf (Input IN, inout SurfaceOutputLux o) {
    78.         fixed4 diff_albedo = tex2D(_MainTex, IN.uv_MainTex);
    79.         fixed4 spec_albedo = tex2D(_SpecTex, IN.uv_MainTex);
    80.         fixed4 spec_water = tex2D(_waterSpecTex, IN.uv_MainTex);
    81.         fixed4 water_mask = tex2D(_waterMask, IN.uv_MainTex);
    82.         float cut = water_mask.a;
    83.         if(cut < _Wetness)
    84.              cut = 0;
    85.          else
    86.              cut = 1;
    87.         // Diffuse Albedo
    88.         o.Albedo = diff_albedo.rgb * _Color.rgb*(1-(0.5f*_Wetness*cut*(1-_WetnessIgnore)));
    89.         o.Alpha = diff_albedo.a * _Color.a;
    90.         o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    91.         // Specular Color
    92.         o.SpecularColor = spec_albedo.rgb*(1-_Wetness*cut*(1-_WetnessIgnore)) + spec_water.rgb*_Wetness*cut*(1-_WetnessIgnore);
    93.         // Roughness – gamma for BlinnPhong / linear for CookTorrence
    94.         o.Specular = LuxAdjustSpecular(spec_albedo.a*(1-_Wetness*cut) + spec_water.a*_Wetness*cut);
    95.  
    96.         #include "../LuxCore/LuxLightingAmbient.cginc"
    97.     }
    98. ENDCG
    99. }
    100. FallBack "Specular"
    101. CustomEditor "LuxMaterialInspector"
    102. }
    103.  
    And then, the modified setup script:
    Code (CSharp):
    1. using UnityEngine;
    2. #if UNITY_EDITOR
    3. using UnityEditor;
    4. #endif
    5. using System.Collections;
    6.  
    7.  
    8. public enum LuxLightingModels
    9. {
    10.     BlinnPhong = 0,
    11.     CookTorrence = 1
    12. }
    13.  
    14. [ExecuteInEditMode]
    15. [AddComponentMenu("Lux/Lux Setup")]
    16. public class SetupLux : MonoBehaviour {
    17.  
    18.     public float Lux_HDR_Scale = 6.0f;
    19.     public bool isLinear;
    20.  
    21.     public LuxLightingModels LuxLighting;
    22.  
    23.     // IBL
    24.     public float Lux_IBL_DiffuseExposure = 1.0f;
    25.     private float DiffuseExposure;
    26.     public float Lux_IBL_SpecularExposure = 1.0f;
    27.     private float SpecularExposure;
    28.     public Cubemap diffuseCube = null;
    29.     public bool diffuseIsHDR;
    30.     public Cubemap specularCube = null;
    31.     public bool specularIsHDR;
    32.     private Cubemap PlaceHolderCube = null;
    33.     public float wetness;
    34.  
    35.     // not needed as we use faked fresnel in deferred
    36.     // public GameObject MainLightReference = null;
    37.  
    38.     private float linearFactorDiffuse;
    39.     private float linearFactorSpecular;
    40.  
    41.     // Use this for initialization
    42.     void Start () {
    43.         UpdateLuxIBLSettings();
    44.     }
    45.  
    46.     // Update is called once per frame
    47.     void Update () {
    48.         #if UNITY_EDITOR
    49.         if(!Application.isPlaying) {
    50.             UpdateLuxIBLSettings();
    51.         }
    52.         #endif
    53.         //if (MainLightReference != null) {
    54.         //    Shader.SetGlobalVector("Lux_MainLightDir", MainLightReference.transform.forward );
    55.         //}
    56.         if(wetness <0)
    57.         {
    58.             wetness=0;
    59.         }
    60.         if(wetness>1)
    61.         {
    62.             wetness = 1;
    63.         }
    64.     }
    65.  
    66.     void UpdateLuxIBLSettings () {
    67.         #if UNITY_EDITOR
    68.         // LINEAR
    69.         if (PlayerSettings.colorSpace == ColorSpace.Linear) {
    70.             isLinear = true;
    71.         }
    72.         // GAMMA
    73.         else {
    74.             isLinear = false;
    75.         }
    76.         #endif
    77.         if (LuxLighting == LuxLightingModels.CookTorrence) {
    78.             Shader.EnableKeyword("LUX_LIGHTING_CT");
    79.             Shader.DisableKeyword("LUX_LIGHTING_BP");
    80.         }
    81.         else {
    82.             Shader.DisableKeyword("LUX_LIGHTING_CT");
    83.             Shader.EnableKeyword("LUX_LIGHTING_BP");
    84.         }
    85.         // LINEAR
    86.         if (isLinear) {
    87.             Shader.DisableKeyword("LUX_GAMMA");
    88.             Shader.EnableKeyword("LUX_LINEAR");
    89.          
    90.             // exposure is already in linear space
    91.             // Lux_HDR_Scale is in srgb so we convert it to linear space
    92.             DiffuseExposure = Lux_IBL_DiffuseExposure;
    93.             if (diffuseIsHDR) {
    94.                 DiffuseExposure *= Mathf.Pow(Lux_HDR_Scale,2.2333333f);
    95.             }
    96.             SpecularExposure = Lux_IBL_SpecularExposure;
    97.             if (specularIsHDR) {
    98.                 SpecularExposure *= Mathf.Pow(Lux_HDR_Scale,2.2333333f);
    99.             }
    100.          
    101.         }
    102.         // GAMMA
    103.         else {
    104.             Shader.EnableKeyword("LUX_GAMMA");
    105.             Shader.DisableKeyword("LUX_LINEAR");
    106.          
    107.             // exposure is in linear space so we convert it to srgb
    108.             // Lux_HDR_Scale is already in srgb
    109.             DiffuseExposure = Mathf.Pow(Lux_IBL_DiffuseExposure, 1.0f / 2.2333333f);
    110.          
    111.             if (diffuseIsHDR) {
    112.                 DiffuseExposure *= Lux_HDR_Scale;
    113.             }
    114.             SpecularExposure = Mathf.Pow(Lux_IBL_SpecularExposure, 1.0f / 2.2333333f);
    115.             if (specularIsHDR) {
    116.                 SpecularExposure *= Lux_HDR_Scale;
    117.             }
    118.          
    119.         }
    120.         /// IBL
    121.         Shader.SetGlobalFloat("_Wetness", wetness);
    122.         Shader.SetGlobalVector("ExposureIBL", new Vector4(DiffuseExposure, SpecularExposure, 1.0f, 1.0f) );
    123.         if(diffuseCube) {
    124.             Shader.SetGlobalTexture("_DiffCubeIBL", diffuseCube);
    125.         }
    126.         if(specularCube) {
    127.             Shader.SetGlobalTexture("_SpecCubeIBL", specularCube);
    128.         }
    129.  
    130.         else {
    131.             createPlaceHolderCube ();
    132.             Shader.SetGlobalTexture("_SpecCubeIBL", PlaceHolderCube);
    133.             #if UNITY_EDITOR
    134.                 DestroyImmediate(PlaceHolderCube, true);
    135.             #endif
    136.         }
    137.  
    138.     }
    139.  
    140.  
    141.     void createPlaceHolderCube () {
    142.         if( PlaceHolderCube == null ) {
    143.             PlaceHolderCube = new Cubemap(16,TextureFormat.ARGB32,true);
    144.             for(int face = 0; face < 6; face++) {
    145.                 for(int x = 0; x < 16; x++) {
    146.                     for(int y = 0; y < 16; y++) {
    147.                         PlaceHolderCube.SetPixel((CubemapFace)face, x, y, Color.black);
    148.                     }
    149.                 }
    150.             }
    151.             PlaceHolderCube.Apply(true);
    152.         }
    153.     }
    154. }
    155.  
     
    Last edited: Jul 8, 2014
    SememeS likes this.
  42. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    eye ball shader updated.
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    great – and do you also have some screen shoots for us?
    lars
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,
    i like your rendering – although the metal in fact might be a little bit too bright.
    have you already thought about adding ambient occlusion?
    as far as skyshop is concerned: according to its thread 1.07 breaks batching… nothing i would like to introduce to lux.

    lars
     
  45. ludiares

    ludiares

    Joined:
    Jul 14, 2011
    Posts:
    242
    There you go. Two pictures of a gravel material, both wet and dry, two pictures of a brick material, wet and dry, and one of the same brick material using a mask. In both cases the ground uses the same wet material, and thus, is affected by wetness. brick_dry.jpg brick_wet_mask.jpg brick_wet.jpg gravel_dry.jpg gravel_wet.jpg
     
    SememeS likes this.
  46. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    It might appear too bright due to the use of a really bright directional light (strength 2.5, from the standard 0.5), the the metal is based off megascans values that I toned down quite a lot (their steel value, but I made the microsurface go down a lot an also the specular I slightly reduced).
    Might increase the specular and the diffuse which is nearly black.
    Thanks for the feedback though, helps improve the model
     
  47. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    Well I took in people's opinion on the model to try and improve it (because that's what makes artists better)

    I think personally the model looks a lot better now with these small tweaks.

    I reduced the diffuse of all the metals down to like 5, before they were 20.
    I increased the spec on the metals making their spec values fit with Megascan's values.
    I improved the occlusion map by merging it with the cavity map which helps occlude the little details in the normal map.

    Further feedback would be appreciated!
     
  48. SememeS

    SememeS

    Joined:
    Nov 27, 2012
    Posts:
    127

    Love this screen @id0 this is looking great
     
  49. SememeS

    SememeS

    Joined:
    Nov 27, 2012
    Posts:
    127
    Great stuff @Tiny Man that gun is looking amazing
    Hmm.. I'm not sure what to criticize.. maybe only that the grip seems a bit shiny buts that's it. all the metal is just right
     
  50. SememeS

    SememeS

    Joined:
    Nov 27, 2012
    Posts:
    127