Search Unity

ShaderBox

Discussion in 'Assets and Asset Store' started by andru, Dec 19, 2011.

  1. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20

    ShaderBox v1

    Shaders in ShaderBox were created for displaying Next Gen graphics in applications for low and middle range GPUs. All shaders work with shader model 2.0 and are targeted for use with forward render pipeline on Mac PC platform.

    Light Probes in the package is an in-house technology (not exactly the same thing as Light Probes planned for Unity 3.5). Light Probes come along with a toolset for automatic creating and positioning Probes on your level.

    Features
    • Blending of real-time shadows with near and far Beast light maps.
    • Realistic shading of objects in a shadow.
    • One shader for two pipelines: with light map and without light map.
    • Shader for imitating precalculated Global Illumination and color bleeding.
    • Specular, Self-Illumination and Transparent properties of shaders are understood by Beast when baking lightmaps. Light that is baked into a lightmap can change its color after passing through a transparent object.
    • Toolset for calculating light probes for characters.
    • A set of Blinn-Phong Light, Specular and Reflection mask, Reflection СubeMap, Normal map, Detail map shaders.
    Future
    • Shaders for imitating glass, cloth.
    • Advanced shaders for SM3.0 (fresnel, reflection, realtime reflection, refraction).
    • Toolset improvements for editing grids and probes.
    • Interpolating light values from several probes.
    • Improvement of probe grid generation algorithm.
    • Adding Spherical Harmonic algorithm for calculating light probes.
    • Hierarchical structure of Light Probes.
    • Integration with native Light Probes when Unity 3.5 is released.
    • Shaders for vegetation (trees, grass).
    • Shaders for decals.
    • Post-effect Screen glare, Screen dirt.(a-la Battlefield3).
    • Flares for fake light sources.
    This pack contains a set of shaders for imitation of complex lighting for surfaces of static and dynamic objects. With the help of these shaders, you will be able to imitate such surfaces as wood, plastic, metal etc.

    The pack also contains the system for calculating ambient lighting for dynamic objects. The system consists of a script for Unity editor which calculates probes for ambient lighting and scripts for applying light probes to objects in Play mode.

    Examples of using ShaderBox:

    DEMO1 - the scene is not optimized and its main purpose to be a showcase.
    DEMO2 - the scene is included with ShaderBox.

    Documentation:

    ShaderBox.pdf





    Screenshots:
     
    Last edited: Dec 27, 2011
  2. KITT

    KITT

    Joined:
    Jul 17, 2009
    Posts:
    221
    Ho-Lee Smokes.

    How much will the pack be?

    Wow this is just plain fantastic..
     
    Last edited: Dec 19, 2011
  3. MadHouseGames

    MadHouseGames

    Joined:
    Nov 24, 2011
    Posts:
    29
    Pure Amazing!!!
     
  4. Yusuf-AKDAG

    Yusuf-AKDAG

    Joined:
    May 13, 2009
    Posts:
    280
  5. Thomas-Pasieka

    Thomas-Pasieka

    Joined:
    Sep 19, 2005
    Posts:
    2,174
    That is looking most interesting I have to say! Will have to check it out :) Is there a demo or lite version available?
     
  6. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Wow! Impressing.

    A price tag?
     
  7. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Hello! The cost will be 100$.
     
  8. KITT

    KITT

    Joined:
    Jul 17, 2009
    Posts:
    221
    I'll be looking forward to release.
     
  9. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    First: Those assets are in amazing quallity.
    Second: Those shaders are beyond awesome. Cant wait to use them. Please post more showcase demos it wouldnt hurt to see more of those badboys in action. How are they in terms of performance comparing to standart bump_spec shader?

    Opaque_specular shader from box seem to have lot of abilities and texture inputs (which is great and exactly what i was looking for), but does that means that it uses all resources even if textures are not inputed?
     
    Last edited: Dec 20, 2011
  10. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    I am interested in the above 2 forthcoming features.

    When you say vegetation shaders, do you mean that we will be able to use unity like vegetation on a mesh terrain (with impostors for trees)?

    Also do you plan to add a decal placement tool?
     
  11. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    +1, would appretiate answer about vegetation shader too.
     
  12. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Thank you for your interest.

    We're going to add a video tutorial about using ShaderBox soon.

    All shaders have 3 versions - high, medium and low.
    This is done to enable using LODs and for better flexibility.
    You can use less/smaller textures on low shader versions.
    Here's an example of the same material, but with different shader quality levels:


    As for performance, out testing showed that shaders work pretty fast. To achieve maximum performance you can also use LODs, batching and switch to low shader quality level on low-end hardware.

    As for vegetation shaders - will lightmapping work with standard solution (LODs) or not, we are not yet sure yet. We are investigating.

    We don't plan to develop decals tool right now. Probably after all other features in the list are implemented.

    Decals will use mesh offset in shader, won't cast and receive shadows. Maybe there will be an option to bake them to lightmaps - a special toolset will be created for that (we are testing the technology).
     
    Last edited: Dec 21, 2011
  13. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    I love it !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    6R
     
  14. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Tried the demo 1.
    The lamps and posters flickers a lot here. Those sometimes become invisible, depending on camera's angle.
     
  15. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    You are right, this can happen. This issue will be solved when we add decal shader in the near future.
    Can you please attach a few screenshots? What hardware do you have?
     
    Last edited: Dec 21, 2011
  16. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    with your beast pipeline, are normal map details preserved?
     
  17. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Yes, normalmapping works OK both with and without beast lightmaps.
     
  18. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    WOOOOW. I am really impressed. $100 sounds like a steal!
    Definitely bookmarked.
     
  19. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    There're 2 webplayer demos,
    but no demo/lite version of the product available.
     
  20. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    sorry, my real question is does it also work with beast in unity free.
     
  21. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Yes. ShaderBox will work with free Unity version.
     
  22. sahid1317

    sahid1317

    Joined:
    Dec 27, 2011
    Posts:
    1
    Works for iOS?
     
  23. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    It's on the asset store, and I'm about to pick it up, but before I do, I want to know explicitly what / if anything does not work in unity free?
     
  24. larvantholos

    larvantholos

    Joined:
    Oct 29, 2009
    Posts:
    668
    Question, why is it raining inside the room in demo 1?
     
  25. Spike

    Spike

    Joined:
    Feb 2, 2010
    Posts:
    12
    IOS and Android not support now.
    Baking probe lights and real time shadows do not work in the free version of Unity3D. But all shaders, including shader for character, do work in free version of Unity.
    This is a demonstration of rain and drops effects. Which will be included in ShaderBox in the near future.
     
    Last edited: Dec 27, 2011
  26. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Available in the asset store.

     
  27. lcellentani74

    lcellentani74

    Joined:
    Dec 4, 2011
    Posts:
    31
    Hi Andrew

    Great job with this package!
    If I can ask, are the shaders inside the box Surface Shaders of Vert/Frag shaders?
     
  28. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Do you plan to support IOS with this?
    I realize you say "not now" just curious if that means ever or if there's a release plan that includes IOS.
    looks great!
    B
     
  29. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    All shaders are written in Cg and have 2 passes:
    1) for the closest light source.
    2) for all other light sources.
    http://unity3d.com/support/documentation/Components/RenderTech-ForwardRendering.html

    Every pass has a vertex shader and a pixel shader.

    ShaderBox shaders can't be written using surface shaders because of instruction limit for shader model 2.0.

    Not in the near future. Not until we finish all features from the list in the first post.
     
    Last edited: Dec 27, 2011
  30. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    I really really hope that you guys make foliage shader. That would be awesome.
     
  31. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Janpec, we are working on it right now.
    It will be added to the package soon.
     
  32. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Nice pack. Looking into it.
     
  33. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    I'm interested in the light probe stuff (given that I'm not in a position to wait for 3.5 to be final). Can you explain a bit more about exactly what you've implemented there, and where it gets lighting information from?
     
  34. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Holy S***! Please post reply to let us know when shader is ready.
     
  35. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    The purpose of native Probes and ours is the same.
    How our Probes are different from the native ones:
    + we created a toolset for automating placing Light Probes on your level.
    + our Light Probes have brightness and saturation parameters.
    + Light Probe baking is based on rendering the environment around a Probe in Unity Editor (baking is very fast).
    + our Probes are structured regularly (like in Half-Life), the native Light Probe system uses a hierarchical structure.
    + interpolation of Probe's color is based not on distance, but on time. That's why the interpolation in our case is more discrete.

     
  36. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    That looks F***IN' SWEET!! I've been looking for something like this for my project...is it possible to emulate the sky lighting with this... I don't want to wait for 3.5 and 100 bucks is a STEAL!!!
     
  37. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    That looks F***IN' SWEET!! I've been looking for something like this for my project...is it possible to emulate the sky lighting with this... I don't want to wait for 3.5 and 100 bucks is a STEAL!!! And will this work with my custom shaders?
     
  38. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Skylight can be imitated: Skybox is taken into account when baking Light Probes - brightness is controlled by skybox's alpha channel.

    Unfortunately you can't use Probes with your custom shaders by default. You'll need to modify your existing shader. If you won't be able to do it yourself - we can help you with that.
     
  39. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Will it matter if I used SSE to do my shaders? And what do you mean by the Skybox alpha channel? I generated my sky textures in Vue as TGA files
     
  40. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Your tga should be 32bit and have grayscale mask in alpha channel (like you would do for a sun shaft post effect). In order for SSE shader to work, you'll need to change shader code a bit.
     
  41. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    We could probably create a Light Probe node for SSE, but we need to investigate this a bit.
     
  42. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467

    Sweet deal...I will have to investigate the sky textures that come out of Vue... could I also copy the rgb channel and paste it in alpha? And how would I change the shader code? I have a few shaders that I have put together for my projects...
     
  43. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Yes, you can copy rgb into alpha channel.

    Please send us the source of your custom SSE shader, we'll make a Probe Light conversion example.
     
  44. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Here is the code for my shader... but it would be awesome, if SSE itself had an "Accept Light Probes" option for shader baking, but you can bake light probes to a moving character model... and I would have to convert all of my shaders to accept the Light Probes.

    Code (csharp):
    1. Shader "NeptuneImaging/NI_Supershader"
    2. {
    3.     Properties
    4.     {
    5. _FrontDiffuse("Front Diffuse Map", 2D) = "gray" {}
    6. _BackDiffuse("Back Diffuse Map", 2D) = "gray" {}
    7. _FrontNormalmap("Front Normal Map", 2D) = "gray" {}
    8. _BackNormalMap("Back Normal Map", 2D) = "gray" {}
    9. _FrontGlossMap("Front Gloss Map (A) Reflect", 2D) = "white" {}
    10. _FrontGlossStrength("_FrontGlossStrength", Float) = 0
    11. _FrontSpecPower("Front Specular Power", 2D) = "white" {}
    12. _FrontHightlightStrength("_FrontHightlightStrength", Float) = 0
    13. _BackGlossMap("Back Gloss Map", 2D) = "white" {}
    14. _BackGlossStrength("_BackGlossStrength", Float) = 0
    15. _BackSpecPower("Back Specular Power", 2D) = "white" {}
    16. _BackHighlightStrength("_BackHighlightStrength", Float) = 0
    17. _AdditiveGloss("Additive Masking", 2D) = "black" {}
    18. _FrontAdditiveSpread("_FrontAdditiveSpread", Float) = 0
    19. _FrontAdditiveStrength("_FrontAdditiveStrength", Float) = 0
    20. _BackAdditiveSpread("_BackAdditiveSpread", Float) = 0
    21. _BackAdditiveStrength("_BackAdditiveStrength", Float) = 0
    22. _EmissionColour("_EmissionColour", 2D) = "black" {}
    23. _EmissionStrength("_EmissionStrength", Float) = 0
    24. _ClipMap("_ClipMap", 2D) = "white" {}
    25. _ReflectionStrength("_ReflectionStrength", Float) = 0
    26. _Cubemap("_Cubemap", Cube) = "black" {}
    27.  
    28.     }
    29.    
    30.     SubShader
    31.     {
    32.         Tags
    33.         {
    34. "Queue"="Transparent-100"
    35. "IgnoreProjector"="False"
    36. "RenderType"="Opaque"
    37.  
    38.         }
    39.  
    40.        
    41. Cull Off
    42. ZWrite On
    43. ZTest LEqual
    44. ColorMask RGBA
    45. Fog{
    46. }
    47.  
    48.  
    49.         CGPROGRAM
    50. #pragma surface surf BlinnPhongEditor  vertex:vert
    51. #pragma target 3.0
    52.  
    53.  
    54. sampler2D _FrontDiffuse;
    55. sampler2D _BackDiffuse;
    56. sampler2D _FrontNormalmap;
    57. sampler2D _BackNormalMap;
    58. sampler2D _FrontGlossMap;
    59. float _FrontGlossStrength;
    60. sampler2D _FrontSpecPower;
    61. float _FrontHightlightStrength;
    62. sampler2D _BackGlossMap;
    63. float _BackGlossStrength;
    64. sampler2D _BackSpecPower;
    65. float _BackHighlightStrength;
    66. sampler2D _AdditiveGloss;
    67. float _FrontAdditiveSpread;
    68. float _FrontAdditiveStrength;
    69. float _BackAdditiveSpread;
    70. float _BackAdditiveStrength;
    71. sampler2D _EmissionColour;
    72. float _EmissionStrength;
    73. sampler2D _ClipMap;
    74. float _ReflectionStrength;
    75. samplerCUBE _Cubemap;
    76.  
    77.             struct EditorSurfaceOutput {
    78.                 half3 Albedo;
    79.                 half3 Normal;
    80.                 half3 Emission;
    81.                 half3 Gloss;
    82.                 half Specular;
    83.                 half Alpha;
    84.                 half4 Custom;
    85.             };
    86.            
    87.             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
    88.             {
    89. half3 spec = light.a * s.Gloss;
    90. half4 c;
    91. c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
    92. c.a = s.Alpha;
    93. return c;
    94.  
    95.             }
    96.  
    97.             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    98.             {
    99.                 half3 h = normalize (lightDir + viewDir);
    100.                
    101.                 half diff = max (0, dot ( lightDir, s.Normal ));
    102.                
    103.                 float nh = max (0, dot (s.Normal, h));
    104.                 float spec = pow (nh, s.Specular*128.0);
    105.                
    106.                 half4 res;
    107.                 res.rgb = _LightColor0.rgb * diff;
    108.                 res.w = spec * Luminance (_LightColor0.rgb);
    109.                 res *= atten * 2.0;
    110.  
    111.                 return LightingBlinnPhongEditor_PrePass( s, res );
    112.             }
    113.            
    114.             struct Input {
    115.                 float4 meshUV;
    116. float3 viewDir;
    117. float3 worldRefl;
    118. INTERNAL_DATA
    119.  
    120.             };
    121.  
    122.             void vert (inout appdata_full v, out Input o) {
    123. float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
    124. float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
    125. float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
    126. float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
    127.  
    128. o.meshUV.xy = v.texcoord.xy;
    129. o.meshUV.zw = v.texcoord1.xy;
    130.  
    131.             }
    132.            
    133.  
    134.             void surf (Input IN, inout EditorSurfaceOutput o) {
    135.                 o.Normal = float3(0.0,0.0,1.0);
    136.                 o.Alpha = 1.0;
    137.                 o.Albedo = 0.0;
    138.                 o.Emission = 0.0;
    139.                 o.Gloss = 0.0;
    140.                 o.Specular = 0.0;
    141.                 o.Custom = 0.0;
    142.                
    143. float4 Tex2D0=tex2D(_FrontDiffuse,(IN.meshUV.xyxy).xy);
    144. float4 Tex2D1=tex2D(_BackDiffuse,(IN.meshUV.xyxy).xy);
    145. float4 Step0=step(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ),float4( 0.0, 0.0, 0.0, 0.0 ));
    146. float4 Split0=Step0;
    147. float4 Lerp0=lerp(Tex2D0,Tex2D1,float4( Split0.z, Split0.z, Split0.z, Split0.z));
    148. float4 Multiply12=float4( 1,1,1,1 ) * Lerp0;
    149. float4 Sign0=sign(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ));
    150. float4 Assemble0_0_NoInput = float4(0,0,0,0);
    151. float4 Assemble0_1_NoInput = float4(0,0,0,0);
    152. float4 Assemble0_3_NoInput = float4(0,0,0,0);
    153. float4 Assemble0=float4(Assemble0_0_NoInput.x, Assemble0_1_NoInput.y, Sign0.z, Assemble0_3_NoInput.w);
    154. float4 Tex2DNormal0=float4(UnpackNormal( tex2D(_FrontNormalmap,(IN.meshUV.xyxy).xy)).xyz, 1.0 );
    155. float4 Multiply10=Tex2DNormal0 * float4( 2.5,2.5,1,1);
    156. float4 Tex2DNormal1=float4(UnpackNormal( tex2D(_BackNormalMap,(IN.meshUV.xyxy).xy)).xyz, 1.0 );
    157. float4 Multiply8=Tex2DNormal1 * float4( 2.5,2.5,-1,1);
    158. float4 Step3=step(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ),float4( 0.0, 0.0, 0.0, 0.0 ));
    159. float4 Split3=Step3;
    160. float4 Lerp4=lerp(Multiply10,Multiply8,float4( Split3.z, Split3.z, Split3.z, Split3.z));
    161. float4 Add8=Assemble0 + Lerp4;
    162. float4 WorldReflection0=float4( WorldReflectionVector (IN, Add8), 1.0);
    163. float4 TexCUBE0=texCUBE(_Cubemap,WorldReflection0);
    164. float4 Multiply14=_ReflectionStrength.xxxx * TexCUBE0;
    165. float4 Tex2D9=tex2D(_FrontGlossMap,(IN.meshUV.xyxy).xy);
    166. float4 Add10_1_NoInput = float4(0,0,0,0);
    167. float4 Add10=Tex2D9.aaaa + Add10_1_NoInput;
    168. float4 Multiply13=Multiply14 * Add10;
    169. float4 Add9=Multiply12 + Multiply13;
    170. float4 Tex2D11=tex2D(_EmissionColour,(IN.meshUV.xyxy).xy);
    171. float4 Multiply11=Tex2D11 * _EmissionStrength.xxxx;
    172. float4 Add11_1_NoInput = float4(0,0,0,0);
    173. float4 Add11=Multiply11 + Add11_1_NoInput;
    174. float4 Tex2D5=tex2D(_FrontSpecPower,(IN.meshUV.xyxy).xy);
    175. float4 Add2_1_NoInput = float4(0,0,0,0);
    176. float4 Add2=Tex2D5 + Add2_1_NoInput;
    177. float4 Tex2D4=tex2D(_AdditiveGloss,(IN.meshUV.xyxy).xy);
    178. float4 Multiply3=Tex2D4 * _FrontAdditiveSpread.xxxx;
    179. float4 Add3=_FrontHightlightStrength.xxxx + Multiply3;
    180. float4 Multiply2=Add2 * Add3;
    181. float4 Tex2D2=tex2D(_BackSpecPower,(IN.meshUV.xyxy).xy);
    182. float4 Add1_1_NoInput = float4(0,0,0,0);
    183. float4 Add1=Tex2D2 + Add1_1_NoInput;
    184. float4 Tex2D3=tex2D(_AdditiveGloss,(IN.meshUV.xyxy).xy);
    185. float4 Multiply1=Tex2D3 * _BackAdditiveSpread.xxxx;
    186. float4 Add0=_BackHighlightStrength.xxxx + Multiply1;
    187. float4 Multiply0=Add1 * Add0;
    188. float4 Step1=step(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ),float4( 0.0, 0.0, 0.0, 0.0 ));
    189. float4 Split1=Step1;
    190. float4 Lerp2=lerp(Multiply2,Multiply0,float4( Split1.z, Split1.z, Split1.z, Split1.z));
    191. float4 Add6_1_NoInput = float4(0,0,0,0);
    192. float4 Add6=Tex2D9 + Add6_1_NoInput;
    193. float4 Tex2D8=tex2D(_AdditiveGloss,(IN.meshUV.xyxy).xy);
    194. float4 Multiply7=Tex2D8 * _FrontAdditiveStrength.xxxx;
    195. float4 Add4=Multiply7 + _FrontGlossStrength.xxxx;
    196. float4 Multiply4=Add6 * Add4;
    197. float4 Tex2D7=tex2D(_BackGlossMap,(IN.meshUV.xyxy).xy);
    198. float4 Add7_1_NoInput = float4(0,0,0,0);
    199. float4 Add7=Tex2D7 + Add7_1_NoInput;
    200. float4 Tex2D6=tex2D(_AdditiveGloss,(IN.meshUV.xyxy).xy);
    201. float4 Multiply6=Tex2D6 * _BackAdditiveStrength.xxxx;
    202. float4 Add5=_BackGlossStrength.xxxx + Multiply6;
    203. float4 Multiply5=Add7 * Add5;
    204. float4 Step2=step(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ),float4( 0.0, 0.0, 0.0, 0.0 ));
    205. float4 Split2=Step2;
    206. float4 Lerp3=lerp(Multiply4,Multiply5,float4( Split2.z, Split2.z, Split2.z, Split2.z));
    207. float4 Tex2D10=tex2D(_ClipMap,(IN.meshUV.xyxy).xy);
    208. float4 Subtract0=Tex2D10.aaaa - float4( 0.5,0.5,0.5,0.5 );
    209. float4 Master0_5_NoInput = float4(1,1,1,1);
    210. float4 Master0_7_NoInput = float4(0,0,0,0);
    211. clip( Subtract0 );
    212. o.Albedo = Add9;
    213. o.Normal = Add8;
    214. o.Emission = Add11;
    215. o.Specular = Lerp2;
    216. o.Gloss = Lerp3;
    217.  
    218.                 o.Normal = normalize(o.Normal);
    219.             }
    220.         ENDCG
    221.     }
    222.     Fallback "Diffuse"
    223. }
     
  45. andru

    andru

    Joined:
    Aug 4, 2010
    Posts:
    20
    Light Probes will work with this shader. But lighting calculation in your shader is different from ours and that's why the result can be a bit different from our shaders.

    Code (csharp):
    1. Shader "ShaderBox/Probe/_High"
    2. {
    3.     Properties
    4.     {
    5. _FrontDiffuse("Front Diffuse Map", 2D) = "gray" {}
    6. _BackDiffuse("Back Diffuse Map", 2D) = "gray" {}
    7. _FrontNormalmap("Front Normal Map", 2D) = "gray" {}
    8. _BackNormalMap("Back Normal Map", 2D) = "gray" {}
    9. _FrontGlossMap("Front Gloss Map (A) Reflect", 2D) = "white" {}
    10. _FrontGlossStrength("_FrontGlossStrength", Float) = 0
    11. _FrontSpecPower("Front Specular Power", 2D) = "white" {}
    12. _FrontHightlightStrength("_FrontHightlightStrength", Float) = 0
    13. _BackGlossMap("Back Gloss Map", 2D) = "white" {}
    14. _BackGlossStrength("_BackGlossStrength", Float) = 0
    15. _BackSpecPower("Back Specular Power", 2D) = "white" {}
    16. _BackHighlightStrength("_BackHighlightStrength", Float) = 0
    17. _AdditiveGloss("Additive Masking", 2D) = "black" {}
    18. _FrontAdditiveSpread("_FrontAdditiveSpread", Float) = 0
    19. _FrontAdditiveStrength("_FrontAdditiveStrength", Float) = 0
    20. _BackAdditiveSpread("_BackAdditiveSpread", Float) = 0
    21. _BackAdditiveStrength("_BackAdditiveStrength", Float) = 0
    22. _EmissionColour("_EmissionColour", 2D) = "black" {}
    23. _EmissionStrength("_EmissionStrength", Float) = 0
    24. _ClipMap("_ClipMap", 2D) = "white" {}
    25. _ReflectionStrength("_ReflectionStrength", Float) = 0
    26. _Cubemap("_Cubemap", Cube) = "black" {}
    27.  
    28.     }
    29.    
    30.     SubShader
    31.     {
    32.         Tags
    33.         {
    34. "Queue"="Transparent-100"
    35. "IgnoreProjector"="False"
    36. "RenderType"="Opaque"
    37.  
    38.         }
    39.  
    40.        
    41. Cull Off
    42. ZWrite On
    43. ZTest LEqual
    44. ColorMask RGBA
    45. Fog{
    46. }
    47.  
    48.  
    49.         CGPROGRAM
    50. #pragma surface surf BlinnPhongEditor  vertex:vert
    51. #pragma target 3.0
    52.  
    53.  
    54. uniform half4 _ColorX;
    55. uniform half4 _ColorY;
    56. uniform half4 _ColorZ;
    57. uniform half4 _ColorNX;
    58. uniform half4 _ColorNY;
    59. uniform half4 _ColorNZ;
    60. sampler2D _FrontDiffuse;
    61. sampler2D _BackDiffuse;
    62. sampler2D _FrontNormalmap;
    63. sampler2D _BackNormalMap;
    64. sampler2D _FrontGlossMap;
    65. float _FrontGlossStrength;
    66. sampler2D _FrontSpecPower;
    67. float _FrontHightlightStrength;
    68. sampler2D _BackGlossMap;
    69. float _BackGlossStrength;
    70. sampler2D _BackSpecPower;
    71. float _BackHighlightStrength;
    72. sampler2D _AdditiveGloss;
    73. float _FrontAdditiveSpread;
    74. float _FrontAdditiveStrength;
    75. float _BackAdditiveSpread;
    76. float _BackAdditiveStrength;
    77. sampler2D _EmissionColour;
    78. float _EmissionStrength;
    79. sampler2D _ClipMap;
    80. float _ReflectionStrength;
    81. samplerCUBE _Cubemap;
    82.  
    83.  
    84.             struct EditorSurfaceOutput {
    85.                 half3 Albedo;
    86.                 half3 Normal;
    87.                 half3 Emission;
    88.                 half3 Gloss;
    89.                 half Specular;
    90.                 half Alpha;
    91.                 fixed3 CustomColor;
    92.                 //half atten;
    93.             };
    94.            
    95.             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
    96.             {
    97. fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.rgb;
    98. half3 spec = light.a * s.Gloss;
    99. half4 c;
    100.  
    101. c.rgb = (s.Albedo * light.rgb + light.rgb * spec) * s.CustomColor;
    102. c.a = s.Alpha;
    103. return c;
    104.  
    105.             }
    106.  
    107.             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    108.             {
    109.                 half3 h = normalize (lightDir + viewDir);
    110.                
    111.                 half diff = max (0, dot ( lightDir, s.Normal ));
    112.                
    113.                 float nh = max (0, dot (s.Normal, h));
    114.                 float spec = pow (nh, s.Specular*128.0);
    115.                
    116.                 half4 res;
    117.                 res.rgb = diff;
    118.                 res.w = spec * Luminance (_LightColor0.rgb);
    119.                 res *= atten * 2.0;
    120.                 //s.atten = atten;
    121.                 return LightingBlinnPhongEditor_PrePass( s, res );
    122.             }
    123.            
    124.             struct Input {
    125.                 float4 color : COLOR;
    126.                 float4 meshUV;
    127. float3 viewDir;
    128. float3 worldRefl;
    129. INTERNAL_DATA
    130.  
    131.  
    132.             };
    133.  
    134.             void vert (inout appdata_full v, out Input o) {
    135. float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
    136. float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
    137. float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
    138. float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
    139.  
    140.             float3 nSquared;
    141.             fixed3 aColor = fixed3(0,0,0);
    142.             float3 normal = normalize (mul((float3x3)_Object2World, v.normal).xyz);
    143.  
    144.             nSquared = normal * normal;
    145.  
    146.             if (normal.x > 0)
    147.                 aColor += nSquared.x * _ColorX.xyz;
    148.             else aColor += nSquared.x * _ColorNX.xyz;
    149.             if (normal.y > 0)
    150.                 aColor += nSquared.y * _ColorY.xyz;
    151.             else aColor += nSquared.y * _ColorNY.xyz;
    152.             if (normal.z > 0)
    153.                 aColor += nSquared.z * _ColorZ.xyz;
    154.             else aColor += nSquared.z * _ColorNZ.xyz;
    155.             v.color.rgb = aColor;
    156.             //o.color.rgb = aColor;
    157.  
    158. o.meshUV.xy = v.texcoord.xy;
    159. o.meshUV.zw = v.texcoord1.xy;
    160.  
    161.             }
    162.            
    163.  
    164.             void surf (Input IN, inout EditorSurfaceOutput o) {
    165.                 o.Normal = float3(0.0,0.0,1.0);
    166.                 o.Alpha = 1.0;
    167.                 o.Albedo = 0.0;
    168.                 o.Emission = 0.0;
    169.                 o.Gloss = 0.0;
    170.                 o.Specular = 0.0;
    171.                 //o.Custom = 0.0;
    172.                 o.CustomColor = IN.color.rgb;
    173.                 float2 meshUV = IN.meshUV.xy;
    174. float4 Tex2D0=tex2D(_FrontDiffuse,meshUV);
    175. float4 Tex2D1=tex2D(_BackDiffuse,meshUV);
    176. float4 Step0=step(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ),float4( 0.0, 0.0, 0.0, 0.0 ));
    177. float4 Split0=Step0;
    178. float4 Lerp0=lerp(Tex2D0,Tex2D1,float4( Split0.z, Split0.z, Split0.z, Split0.z));
    179. float4 Multiply12=float4( 1,1,1,1 ) * Lerp0;
    180. float4 Sign0=sign(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ));
    181. float4 Assemble0_0_NoInput = float4(0,0,0,0);
    182. float4 Assemble0_1_NoInput = float4(0,0,0,0);
    183. float4 Assemble0_3_NoInput = float4(0,0,0,0);
    184. float4 Assemble0=float4(Assemble0_0_NoInput.x, Assemble0_1_NoInput.y, Sign0.z, Assemble0_3_NoInput.w);
    185. float4 Tex2DNormal0=float4(UnpackNormal( tex2D(_FrontNormalmap,meshUV)).xyz, 1.0 );
    186. float4 Multiply10=Tex2DNormal0 * float4( 2.5,2.5,1,1);
    187. float4 Tex2DNormal1=float4(UnpackNormal( tex2D(_BackNormalMap,meshUV)).xyz, 1.0 );
    188. float4 Multiply8=Tex2DNormal1 * float4( 2.5,2.5,-1,1);
    189. float4 Step3=step(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ),float4( 0.0, 0.0, 0.0, 0.0 ));
    190. float4 Split3=Step3;
    191. float4 Lerp4=lerp(Multiply10,Multiply8,float4( Split3.z, Split3.z, Split3.z, Split3.z));
    192. float4 Add8=Assemble0 + Lerp4;
    193. float4 WorldReflection0=float4( WorldReflectionVector (IN, Add8), 1.0);
    194. float4 TexCUBE0=texCUBE(_Cubemap,WorldReflection0);
    195. float4 Multiply14=_ReflectionStrength.xxxx * TexCUBE0;
    196. float4 Tex2D9=tex2D(_FrontGlossMap,meshUV);
    197. float4 Add10_1_NoInput = float4(0,0,0,0);
    198. float4 Add10=Tex2D9.aaaa + Add10_1_NoInput;
    199. float4 Multiply13=Multiply14 * Add10;
    200. float4 Add9=Multiply12 + Multiply13;
    201. float4 Tex2D11=tex2D(_EmissionColour,meshUV);
    202. float4 Multiply11=Tex2D11 * _EmissionStrength.xxxx;
    203. float4 Add11_1_NoInput = float4(0,0,0,0);
    204. float4 Add11=Multiply11 + Add11_1_NoInput;
    205. float4 Tex2D5=tex2D(_FrontSpecPower,meshUV);
    206. float4 Add2_1_NoInput = float4(0,0,0,0);
    207. float4 Add2=Tex2D5 + Add2_1_NoInput;
    208. float4 Tex2D4=tex2D(_AdditiveGloss,meshUV);
    209. float4 Multiply3=Tex2D4 * _FrontAdditiveSpread.xxxx;
    210. float4 Add3=_FrontHightlightStrength.xxxx + Multiply3;
    211. float4 Multiply2=Add2 * Add3;
    212. float4 Tex2D2=tex2D(_BackSpecPower,meshUV);
    213. float4 Add1_1_NoInput = float4(0,0,0,0);
    214. float4 Add1=Tex2D2 + Add1_1_NoInput;
    215. float4 Tex2D3=tex2D(_AdditiveGloss,meshUV);
    216. float4 Multiply1=Tex2D3 * _BackAdditiveSpread.xxxx;
    217. float4 Add0=_BackHighlightStrength.xxxx + Multiply1;
    218. float4 Multiply0=Add1 * Add0;
    219. float4 Step1=step(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ),float4( 0.0, 0.0, 0.0, 0.0 ));
    220. float4 Split1=Step1;
    221. float4 Lerp2=lerp(Multiply2,Multiply0,float4( Split1.z, Split1.z, Split1.z, Split1.z));
    222. float4 Add6_1_NoInput = float4(0,0,0,0);
    223. float4 Add6=Tex2D9 + Add6_1_NoInput;
    224. float4 Tex2D8=tex2D(_AdditiveGloss,meshUV);
    225. float4 Multiply7=Tex2D8 * _FrontAdditiveStrength.xxxx;
    226. float4 Add4=Multiply7 + _FrontGlossStrength.xxxx;
    227. float4 Multiply4=Add6 * Add4;
    228. float4 Tex2D7=tex2D(_BackGlossMap,meshUV);
    229. float4 Add7_1_NoInput = float4(0,0,0,0);
    230. float4 Add7=Tex2D7 + Add7_1_NoInput;
    231. float4 Tex2D6=tex2D(_AdditiveGloss,meshUV);
    232. float4 Multiply6=Tex2D6 * _BackAdditiveStrength.xxxx;
    233. float4 Add5=_BackGlossStrength.xxxx + Multiply6;
    234. float4 Multiply5=Add7 * Add5;
    235. float4 Step2=step(float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ),float4( 0.0, 0.0, 0.0, 0.0 ));
    236. float4 Split2=Step2;
    237. float4 Lerp3=lerp(Multiply4,Multiply5,float4( Split2.z, Split2.z, Split2.z, Split2.z));
    238. float4 Tex2D10=tex2D(_ClipMap,meshUV);
    239. float4 Subtract0=Tex2D10.aaaa - float4( 0.5,0.5,0.5,0.5 );
    240. float4 Master0_5_NoInput = float4(1,1,1,1);
    241. float4 Master0_7_NoInput = float4(0,0,0,0);
    242. clip( Subtract0 );
    243. o.Albedo = Add9;
    244. o.Normal = Add8;
    245. o.Emission = Add11;
    246. o.Specular = Lerp2;
    247. o.Gloss = Lerp3;
    248.  
    249.                 o.Normal = normalize(o.Normal);
    250.             }
    251.         ENDCG
    252.     }
    253.     Fallback "Diffuse"
    254. }
     
  46. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Wow... so it looks like I will have to try out your light probe with my shader tweaks... :) thanks
     
  47. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Friendly bump...(still waiting for vegetation shader:D) One question, you mentioned that native probes are used for dynamic objects, but on that box screenshot it is done with static model. Does that mean that it can be used on any object?
     
  48. Spike

    Spike

    Joined:
    Feb 2, 2010
    Posts:
    12
    All objects on the screenshot are dynamic. It shows the difference between native probes and shaderbox probes. Probes can be used only for dynamic objects. Right now shaderbox has Probe Light system that works good with characters - and we are currently improving the system so large quantities of other dynamic objects (props) could work with probes without losing performance.
     
  49. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    +1 for a vegetation shader... I really hate how fake some of it looks in game with the default setup
     
  50. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Any news on vegetation shader?