Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Advanced Surface Shaders - RELEASED

Discussion in 'Assets and Asset Store' started by MattCarr, Jul 23, 2011.

  1. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    Hi Matt,

    Any news on supporting DX11 in 4.0? Volume shader is coming up pink.

    Cheers.
     
  2. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    New update will be available soon with full Unity 4 support for all existing shaders.
     
  3. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    255
    Great looking forward to it!
     
  4. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    This is awesome... I may end up purchasing this if I can create the shaders I have already with it... a lot of my shaders were made in strumpy, so it would be nice to be able to have shaders that are fast...
     
    Last edited: Nov 18, 2012
  5. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    With the way the shader generator works, there aren't many shaders you can't make and there's new effects being added to choose from in each update. Just finishing up the latest version now for submission that removes all problems and warnings in DX11 mode in Unity 4. It also adds some DX11 only effects: Phong (smoothing) tessellation and tessellation effects for use with displacement maps: Fixed, Distance and Edge Based.

    I'll post a video showing these effects and how they compare to existing effects like Parallax Occlusion Mapping and Relief Mapping.
     
  6. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    Can't wait to get that dx11 update!
    Do you have a timeframe for releasing it?
     
  7. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    It's just about done. Should be submitted within the next 24 hours.
     
  8. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    Hard to complain there hehe :)
     
  9. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Well, would i be able to make shaders with a separate gloss and spec? That is one thing I dont like about the Unity defaults. Or better yet, two layer specular maps for use with SSS (sorry, got used to using MR rendering)
     
    Last edited: Nov 22, 2012
  10. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Besides standard specular without a map, there are 2 other specular effects to choose from. One is the Color Spec Map which uses the R,G,B channels to allow for coloured specular reflection, and the other is Gloss Map which uses the R and B channels of the texture to determine gloss and specular values separately. So yes, that can be achieved in the current version.

    In the current version of the package the skin shader doesn't use a spec map, but in the new version there's a version of the shader that takes a gloss/specular map as described above.
     
  11. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Sweet... because in my games, I use a very customised shader that allows fresnel and reflection masking... i am definitely getting this package and see what effects I can create... and I am sure they will be very fast
     
  12. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    I've submitted version 2.1.1 so it should be available shortly. The main new features as previously mentioned are the tessellation effects: Phong/Smoothing tessellation and displacement map tessellation effects (Fixed, Distance based or Edge Length based). These are added to the Shader Generator tool like effects so you can combine them to create your desired shader.

    I'll also be uploading a new video shortly to show the new effects and also to give a quick demonstration on how to use the Shader Generator. My intention is to make this a quick, 1 or 2 minute video that will serve as an introduction and demonstration of what the package provides. I'll upload the OP of the thread once this video is uploaded.




    Click for higher resolution image



    Click for higher resolution image



    Click for higher resolution image



    Click for higher resolution image



    Click for higher resolution image



    Click for higher resolution image
     
    Last edited: Nov 23, 2012
  13. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    I am tempted to purchase this :)
     
  14. garyhaus

    garyhaus

    Joined:
    Dec 16, 2006
    Posts:
    601
    Don't be tempted. Just DOOOOO EEEET!!!! Its awesome!

    G
     
  15. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
  16. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    Doesn't seem to have updated on the asset store and i'd like to be able to toy around with the new tesselation shaders this WE
    Could you mail the package to me if i mail you my invoice for it? I purchased this a while back and those tess shaders so soon after unity 4 come as a nice surprise.
     
  17. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Looks nice. Hard to tell exactly what's going on in the shader, but it certainly looks like something that could be replicated in AdvancedSS with a shader normal, spec map, emissive and reflection effects.

    If there's something else going on that requires a new effect, then I'm always happy to add more effects to the package. If one person needs something for their project then chances are someone else will too.

    The updates are usually accepted within 24 hours of submission. It might take bit longer because of the weekend, but shouldn't take too long. If you need the new version and can't wait then send me a PM and I'll see what i can do.
     
  18. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    Private message sent! :)
     
  19. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    $Shader%20Input%20List.jpg

    Hey Matt, this is the shader that i am using for the characters in my game... the Gloss Map has an alpha channel that drives the strength of the reflection and the spec map also has an alpha that allows me to drive the fresnel... and i am also using two gloss maps to drive the silk effects, which is also great for stuff like shiny gold. Here is the shader code, which may give you some ideas for updates. About to purchase this package :). I would be very happy to give you some feedback....and new ideas.

    And the modified version allows me to have two different textures on both sides of the polygon...

    Code (csharp):
    1. Shader "NeptuneImaging/Characters/Self-Illumin/NI_Supermaterial_Realistic_SingleSide"
    2. {
    3.     Properties
    4.     {
    5. _Diffuse("Diffuse Map (A) Masking", 2D) = "gray" {}
    6. _Normalmap("Normal Map", 2D) = "gray" {}
    7. _GlossMap("Gloss Map (A) Reflect", 2D) = "gray" {}
    8. _SpecPower("Specular Power (Falloff Alpha)", 2D) = "gray" {}
    9. _AdditiveGloss("Additive Gloss", 2D) = "black" {}
    10. _SecondarySpecular("Secondary Specular", Float) = 0
    11. _SecondaryGloss("Secondary Gloss", Float) = 0
    12. _Illum("Illumin", 2D) = "black" {}
    13. _GlowColour("_GlowColour", Color) = (1,1,1,1)
    14. _Cube("Reflective Cubemap", Cube) = "black" {}
    15. _EmissionLM("Emission (Lightmapper)", Range(0,12) ) = 1
    16. _ReflectionFalloff("_ReflectionFalloff", Float) = 0
    17. _Reflection("_Reflection", Float) = 1
    18. _GLOSSGraze("Gloss Falloff (On Skin Only)", Float) = 0
    19. _SPECULARGraze("Specular Falloff (On Skin Only", Float) = 0
    20.  
    21.     }
    22.    
    23.     SubShader
    24.     {
    25.         Tags
    26.         {
    27. "Queue"="Geometry+100"
    28. "IgnoreProjector"="False"
    29. "RenderType"="Opaque"
    30.  
    31.         }
    32.  
    33.        
    34. Cull Back
    35. ZWrite On
    36. ZTest LEqual
    37. ColorMask RGBA
    38. Fog{
    39. }
    40.  
    41.  
    42.         CGPROGRAM
    43. #pragma surface surf BlinnPhongEditor  nolightmap vertex:vert
    44. #pragma target 3.0
    45.  
    46.  
    47. sampler2D _Diffuse;
    48. sampler2D _Normalmap;
    49. sampler2D _GlossMap;
    50. sampler2D _SpecPower;
    51. sampler2D _AdditiveGloss;
    52. float _SecondarySpecular;
    53. float _SecondaryGloss;
    54. sampler2D _Illum;
    55. float4 _GlowColour;
    56. samplerCUBE _Cube;
    57. float _EmissionLM;
    58. float _ReflectionFalloff;
    59. float _Reflection;
    60. float _GLOSSGraze;
    61. float _SPECULARGraze;
    62.  
    63.             struct EditorSurfaceOutput {
    64.                 half3 Albedo;
    65.                 half3 Normal;
    66.                 half3 Emission;
    67.                 half3 Gloss;
    68.                 half Specular;
    69.                 half Alpha;
    70.                 half4 Custom;
    71.             };
    72.            
    73.             inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
    74.             {
    75. half3 spec = light.a * s.Gloss;
    76. half4 c;
    77. c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
    78. c.a = s.Alpha;
    79. return c;
    80.  
    81.             }
    82.  
    83.             inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    84.             {
    85.                 half3 h = normalize (lightDir + viewDir);
    86.                
    87.                 half diff = max (0, dot ( lightDir, s.Normal ));
    88.                
    89.                 float nh = max (0, dot (s.Normal, h));
    90.                 float spec = pow (nh, s.Specular*128.0);
    91.                
    92.                 half4 res;
    93.                 res.rgb = _LightColor0.rgb * diff;
    94.                 res.w = spec * Luminance (_LightColor0.rgb);
    95.                 res *= atten * 2.0;
    96.  
    97.                 return LightingBlinnPhongEditor_PrePass( s, res );
    98.             }
    99.            
    100.             struct Input {
    101.                 float4 meshUV;
    102. float3 viewDir;
    103. float3 worldRefl;
    104. INTERNAL_DATA
    105.  
    106.             };
    107.  
    108.             void vert (inout appdata_full v, out Input o) {
    109. float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
    110. float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
    111. float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
    112. float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
    113.  
    114. o.meshUV.xy = v.texcoord.xy;
    115. o.meshUV.zw = v.texcoord1.xy;
    116.  
    117.             }
    118.            
    119.  
    120.             void surf (Input IN, inout EditorSurfaceOutput o) {
    121.                 o.Normal = float3(0.0,0.0,1.0);
    122.                 o.Alpha = 1.0;
    123.                 o.Albedo = 0.0;
    124.                 o.Emission = 0.0;
    125.                 o.Gloss = 0.0;
    126.                 o.Specular = 0.0;
    127.                 o.Custom = 0.0;
    128.                
    129. float4 Tex2D0=tex2D(_Diffuse,(IN.meshUV.xyxy).xy);
    130. float4 Tex2DNormal0=float4(UnpackNormal( tex2D(_Normalmap,(IN.meshUV.xyxy).xy)).xyz, 1.0 );
    131. float4 Multiply10=Tex2DNormal0 * float4( 1.5,1.5,1,1);
    132. float4 Fresnel0=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Tex2DNormal0.xyz ) )).xxxx;
    133. float4 Invert0= float4(1.0, 1.0, 1.0, 1.0) - Fresnel0;
    134. float4 Pow0=pow(Invert0,_ReflectionFalloff.xxxx);
    135. float4 WorldReflection0=float4( WorldReflectionVector (IN, Multiply10), 1.0);
    136. float4 TexCUBE0=texCUBE(_Cube,WorldReflection0);
    137. float4 Multiply14=Pow0 * TexCUBE0;
    138. float4 Multiply15=Multiply14 * _Reflection.xxxx;
    139. float4 Tex2D9=tex2D(_GlossMap,(IN.meshUV.xyxy).xy);
    140. float4 SplatAlpha1=Tex2D9.aaaa.w;
    141. float4 Multiply12=Tex2D9 * SplatAlpha1;
    142. float4 Multiply13=Multiply15 * Multiply12;
    143. float4 Tex2D11=tex2D(_Illum,(IN.meshUV.xyxy).xy);
    144. float4 Multiply9=_GlowColour * Tex2D11;
    145. float4 Multiply11=Multiply9 * _EmissionLM.xxxx;
    146. float4 Add1=Multiply13 + Multiply11;
    147. float4 Fresnel1=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Multiply10.xyz ) )).xxxx;
    148. float4 Invert1= float4(1.0, 1.0, 1.0, 1.0) - Fresnel1;
    149. float4 Tex2D5=tex2D(_SpecPower,(IN.meshUV.xyxy).xy);
    150. float4 Multiply5=Tex2D5.aaaa * _GLOSSGraze.xxxx;
    151. float4 Pow1=pow(Invert1,Multiply5);
    152. float4 Multiply0=Pow1 * Tex2D5;
    153. float4 Tex2D4=tex2D(_AdditiveGloss,(IN.meshUV.xyxy).xy);
    154. float4 Multiply3=Tex2D4 * _SecondarySpecular.xxxx;
    155. float4 Add3=Multiply3 + float4( 1,1,1,1 );
    156. float4 Multiply2=Multiply0 * Add3;
    157. float4 Fresnel2=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Tex2DNormal0.xyz ) )).xxxx;
    158. float4 Invert2= float4(1.0, 1.0, 1.0, 1.0) - Fresnel2;
    159. float4 Multiply6=Tex2D5.aaaa * _SPECULARGraze.xxxx;
    160. float4 Pow2=pow(Invert2,Multiply6);
    161. float4 Multiply1=Pow2 * Tex2D9;
    162. float4 Tex2D8=tex2D(_AdditiveGloss,(IN.meshUV.xyxy).xy);
    163. float4 Multiply7=Tex2D8 * _SecondaryGloss.xxxx;
    164. float4 Add4=Multiply7 + float4( 1,1,1,1 );
    165. float4 Multiply4=Multiply1 * Add4;
    166. float4 Lerp1_1_NoInput = float4(0,0,0,0);
    167. float4 Lerp1_2_NoInput = float4(0,0,0,0);
    168. float4 Lerp1=lerp(Tex2D0.aaaa,Lerp1_1_NoInput,Lerp1_2_NoInput);
    169. float4 Subtract0=Lerp1 - float4( 0.05,0.05,0.05,0.05 );
    170. float4 SplatAlpha0=Subtract0.w;
    171. float4 Master0_5_NoInput = float4(1,1,1,1);
    172. float4 Master0_7_NoInput = float4(0,0,0,0);
    173. clip( SplatAlpha0 );
    174. o.Albedo = Tex2D0;
    175. o.Normal = Multiply10;
    176. o.Emission = Add1;
    177. o.Specular = Multiply2;
    178. o.Gloss = Multiply4;
    179.  
    180.                 o.Normal = normalize(o.Normal);
    181.             }
    182.         ENDCG
    183.     }
    184.     Fallback "Diffuse"
    185. }
     
  20. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Purchased :D
     
  21. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Wow. Well if nothing else then the shader will at least be faster now :). I think Strumpy's shader editor is great and obviously abstracts shader dev out to a form that makes it easier for people to create custom shaders, but just as a side effect of what it is and how it needs to be generated, that shader code is bananas :).

    You won't be able to replicate that shader entirely in the current version and you may need to shift some texture channels around, but have a look at what you can do with the current effects and let me know what modifications you thing you might need.

    I'd also recommend that if they aren't already, you separate the skin parts of the character(s) to use different a different material since they inherently require different shading methods being a very different type of surface to the clothing. There are specific skin shaders included in the package.
     
  22. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    I just saw the package... and I love what I see... how do I launch this?

    EDIT: I love how simple the skin shader is... I would love to control the specular with a texture... now trying to figure out how to launch the generator... and getting ideas on setting up a more advanced skin shader for things like Epidermal, Subdermal, Back, Primary/Secondary Specular, and reflection mapping :)
     
    Last edited: Nov 24, 2012
  23. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Shader Generator
    I personally don't like Asset Store stuff adding their own base menu since you can only have so many before it would become a problem, so the Advanced Surface Shaders menu is found under Window > Advanced Surface Shaders. There you can open the Shader Generator.

    Volumetric Objects
    You can create Volumetric Objects by either using the Create dropdown in the Hierarchy window or from the top menu through GameObject > Create Other. Select a volume shape option from the Volumetic Objects sub menu.

    Version 2.1.0 contains a skin shader with Gloss Map support. The current shader is based on the blended normals technique used by Naughty Dog in the Uncharted series, but there is more that can be done with it so I'll definitely look into adding support for more effects. I am currently looking at fast, art driven ways to have nice back scattering effects which could be used for things like ears and fingers.
     
  24. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Call me spoiled by the MR versions of the SSS shaders... and I better get used to embedding my textures in channels... And I will also have to seek a way to allow the spec/gloss of the generated shader to play nice with the SSS... making a masking that will allow users to keep it separate, otherwise forcing me to make many materials for different parts... this is a KICK ASS PURCHASE...

    EDIT: Apparently, using both spec and gloss maps cause a conflict in the shader... I usually use both in my shader... anyway to unlock these in the next update?

    EDIT 2: Apparently, i have version 2.0.1 :(
     
    Last edited: Nov 24, 2012
  25. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Yeah, 2.1.0 has been submitted but isn't on the store yet.

    The difference between Spec Map and Gloss Map in the package is that Spec Map governs the specular color though the R,G,B channels of the texture so you can have colored specular highlights. The overall luminance of that Spec Map influences the gloss.
    The Gloss Map is a separate effect that is more useful in typical cases. It uses the Red channel to set the gloss value and the Green channel to set the specular value.

    So I'd suspect what you're actually after is just the Gloss Map option. That is also what is available in the skin shader in version 2.1.0.

    On the subject of wrangling texture channels such that the textures contain the appropriate data per channel, I'm considering writing a separate little editor window to allow for combining channels from different textures into 1 texture to make the process simpler for those that have existing textures that aren't in this format or if outputting textures from something like CrazyBump which will output a separate displacement/height map which then needs to be
    put in the alpha channel of the Spec Map. I've kept texture channels the same as Unity's built-in shaders so for the most part it should be a non-issue. The only variance there is that I don't use the alpha channel of the main diffuse texture for gloss, only transparency. Unity's built-in shaders use it for both which doesn't make sense in transparency shaders that require a gloss map so for simplicity and consistency across the shader range the diffuse main texture alpha is only for transparency here.

    Here's some more detailed information from the included package documentation of the various textures and properties that you'll see in the generated shaders.

     
    Last edited: Nov 24, 2012
  26. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    This is great information, Matt... and I guess for reflective parts of my textures, I may have to work around that... since I use masks to determine relfective areas... maybe the B channel can be for reflections :)
     
  27. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    I'll look into what will work best for reflection masking. I've organised channels such that the minimal number of textures are required for each situation for optimisation reasons. I'll either slot in a mask channel into an existing spare channel that makes sense, add a new texture or I might look into another option I've been considering which I might think about implementing. I'll find the option that best balances simplicity, consistency, flexibility and performance.
     
  28. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Sweet... it would save me time from working with a monster shader :)
     
  29. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    I think adding a few more textures could help also... maybe an additive specular/gloss map with the floats (that is how I made silky clothes and the bloom on the HDR)...
     
  30. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Hey guys, here is a quick test of the skin shader... I must say, I am impressed :) and my fifty bucks was WELL spent... here is a render of my in-game character with his textures... there was minimal tweaking of the textures required :)

    $XavierSkinShader.jpg
     
  31. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Woooo!!!
     
  32. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Wow, that looks great. Really nice textures in use there.

    I'll definitely be looking at adding more high end features in the coming versions.

    The next version I'll be working on for release in the next couple of weeks will focus primarily on mobile shaders again. There are of options that should be added to the generator to expose and articulate the different optimisations available and ensure that mobile shaders that won't work with some optimisations (e.g. specular shaders with halfasview) have the appropriate restrictions.
     
  33. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Thanks dude... I felt kinda bad at first, screwing up the old texture to make this work... and I hope I will get separate gloss and spec map input... I love RGB...and I love how simple the skin shader is...
     
  34. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    What is half as view?
     
  35. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    It's an optimisation typically used in Unity's mobile shaders that calculates a vector halfway between the light direction and view direction per vertex which is then used in the mobile lighting function Unity uses for mobile shaders that have specular highlights. It's fine for certain situations, but when people don't realise this when developing shaders for mobile, it's a typical reason why people have trouble writing mobile specular shaders.

    It's the sort of thing that doesn't need to be known by most people and it's one of the prime reasons why this package exists :). Rather than everyone bashing their heads against the wall trying to figure out the different requirements for each type of shader effect for each type of platform and for each new version of Unity, I'll just do the bashing and give you guys the results as seamlessly as possible in updates.
     
  36. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    Is there any chance we could have the fog influence the volumetric shapes ?
    Right now they just turn black when the fog is enabled :)
     
  37. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Good to know...and I look forward to your next updates :)
     
  38. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Whoops, yep. Sorry about that, during initial development of the effect I'd made that happen and forgot to remove it. It will be fixed in the next update (the one after the already submitted 2.1.0) and you can fix it in the current version by opening the shaders for the volumetric objects (SphereVolume.shader, BoxVolume.shader, ConeVolume.shader) and remove this line from them:

    Code (csharp):
    1. Fog { Color (0,0,0,0) }
     
  39. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    Thanks mate, that was it ;)
     
  40. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    Version 2.1.0 is now available on the Asset Store. I'm currently working on 2.2.0 which will include a significant amount of new improvements to the shader generation for mobile platforms.

    After that I intend on adding new abilities to the generator to allow creating shaders containing multiple subshaders so that one shader can have different paths per platform or quality setting. This will simplify creating scale-able effects for multiplatform games and different hardware so you could easily have a shader that performs tessellation on DX11 cards, falls back to Relaxed Cone Step Mapping on high end DX9 or OpenGL systems, then to Parallax mapping on lower end systems, and then used a mobile optimised parallax mapping effect on iPads and high end mobiles and then down to normal mapping on other mobile devices.
     
  41. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    What would really rock is a single file format (encoding all of those info) that you'd add on a script and that converts at start time to the correct map (tesselation / normal etc) based on which shader will run, is that possible? So instead of a normal map a tesselation map etc we'd have a single map that retro targets the correct shader.
     
  42. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    I'm thinking of doing something like that. I don't think runtime would be the best time to do this because it would increase the build size (since data that isn't needed for a build type would be included) and it also adds some overhead to the initial loading time to generate the final textures. But doing this at build time or more likely as a separate process in the Shader Generator tool or another tool more specifically created for material setup would work well.

    What I would ultimately think is the best solution would be to have a more complicated "Material" assigned to the renderer that could contain different methods per platform or quality settings and the like. What I don't want to do is require anything that's different than how Unity does things, but I might look into including something like that as an option for people that would like that for certain situations. I know it's something I'd definitely like to use in my projects.
     
  43. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    Spoted online! Don't forget to check your emails we need to move forward :)
     
  44. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    :), I've seen the email. I've only just finished up on the other work I was doing over the last couple of days so I'll take a look asap and give you my thoughts.
     
  45. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Hey Matt, I was looking at the SIGGRAPH 2010 paper on the skin shader for Uncharted 2 and now I see the inspiration for it... do you think you could in the next update of the skin shader, you could use floats instead of sliders? I am trying to consistently match up a value and the sliders make it a bit tough at times...
     
  46. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    What would be a huge feature for me workflow wise is to decorelate your code from the inputs.
    While generating instead of just choosing effects you'd also configure the inputs for those offects, for exemple if you choose tesselation with heightmap, instead of heightmap (A) you'd have heightmap => single channel and you'd decide which channel of which texture it is (basically you'd state how textures you want, and provide the mapping between the inputs and logical representation, the shader would adapt to look for the information where you ask for).
    This would mean making specific shaders instead of having to rework any assets you buy to be compatible with certain shaders.
     
  47. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    That kinda hurt me a bit, when I was testing out the skin shader..., I had to tweak my gloss and spec maps that I already made, but it came out very well :) and I will be using the skin shader for all of the characters, except for the ones that have glowing skin... literally :)
     
    Last edited: Nov 29, 2012
  48. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    i got an error after updating
    Assets/AdvancedSurfaceShaders/AdvancedSSUtils.cs(201,18): error CS0117: `System.IO.File' does not contain a definition for `WriteAllText'
     
  49. MattCarr

    MattCarr

    Joined:
    Jul 5, 2009
    Posts:
    339
    That's very odd. It's not based on any new change on my end. I'm assuming you have Unity set to the Web Player or Native Client platform. That code is inside an #if UNITY_EDITOR preprocessor section and I can't see why Unity would fail to compile it when although it wouldn't work in a Web Player build, it should work fine always in the editor which is all it's compiling for.

    As a temporary workaround please switch platform to Win, Mac Linux Standalone when you want to use the shader generator and comment out the line with the error when in Web Player mode to bypass the error.

    Change
    Code (csharp):
    1. File.WriteAllText(filePath, GenerateShaderCode());
    To
    Code (csharp):
    1. //File.WriteAllText(filePath, GenerateShaderCode());
    I'll investigate further and see if there is any reason this would be happening. I think I'll have to contact Unity support to see if they can fix it in their next update. In the mean time I'll probably need to remove the ability to use the Shader Generator while the editor is set to those platforms in the next update.

    Edit:

    On second thoughts the best solution for now so that you don't need to switch that line from commented to uncommented would be to leave it as is (uncommented) and instead change this line:

    Code (csharp):
    1. #if UNITY_EDITOR
    to:

    Code (csharp):
    1. #if UNITY_EDITOR  !UNITY_WEBPLAYER  !UNITY_NACL
    I still believe this is a bug and have submitted it to Unity.
     
    Last edited: Dec 1, 2012
  50. snow404

    snow404

    Joined:
    Dec 1, 2012
    Posts:
    11
    Does the tesselation shaders included could be used to render very detailled portions of a large terrain in realtime right now? Is it possible to combine tesselation with normal maps ?

    The camera flies over a large empty terrain in a project i am working on right now. Implementing a detailled mesh generated by tesselation like in the following videos would simply be awesome!

    https://www.youtube.com/watch?v=bHh8D3AzZaU
    https://www.youtube.com/watch?v=kf6C0QLNW6o