Search Unity

Alloy Physical Shader Framework Version 3 For Unity 5

Discussion in 'Assets and Asset Store' started by xenius, Mar 2, 2015.

  1. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    I hope new releases and changes won't break Asset Store plugins and people projects too much.
    Sometimes i feel Unity is adopting Unreal 4 changes each release that is a real disaster :D
     
  2. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    Yeah... if I'm being frank, I would imagine the first year of 5.0 is probably going to have a bunch of things. I know there's a fairly long list of things that they probably wished they could have gotten into 5.0, but didn't, so I'm personally braced for breaking changes/improvements (however necessary), for 5.1/5.2/etc. There's just still so much obvious improvement work to be done on the rendering/lighting front.
     
  3. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    This does mean of course, if you're in it for the long haul with Alloy, you should probably be prepared to do the version-jump in sync with us (ie. always check this thread to see where our version compatibility is), as between the custom lighting, inspector wizardy(hackery) and a few other things, it's probably best for you guys to check with us and see if the way forward is safe yet :).
     
  4. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    @xenius Wow, that's really cool. So are you using an Alloy shader for that? One of the transmission ones?

    Probably what I'll do for now is just try some subtle dirt and scratches texturing on a regular transparent shader. I may try something fancier like your example later if I have time.
     
  5. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    That is some nicely scratched glass... I was thinking about this effect too... I might put something together for you guys using the glass shader. Also I will look into ways to faking iridescence, such as for pearls...
     
  6. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @Steve Tack It's using the glass shader. The tranmission one wouldn't achieve the effect one would want, as its only transmitting diffuse light. The optical effect of radial scratches is hot specular points.

    As i said though, the hard thing is that its an importantly.. double sided effect in real life, so to both get that behaviour and have it be able to be front-lit would require either two geo layers (of the high quality glass shader) (ie kinda expensive) or a custom shader.
     
  7. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    If the only downside is that the outside of the glass wouldn't be rendered, that's not an issue at all. Hmm, I may have to play with it. I haven't been able to get results like your screenshot with the glass shader so far.
     
  8. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Hey guys... I have a quick question? Do you guys know when you will be adding opacity and transmission to the Substance Painter Alloy shader? I have started doing things like painting hair and using the transmission map from Knald, and it would be a little easier to visualize all of this without have to jump into Unity to see my results...

    Cheers! :D
     
  9. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @Neptune_Imaging At current the Substance Painter custom shader system doesn't expose the things we would need to do that. Moreso, it would be a fair amount of work, so I wouldn't be waiting on us to do it.
     
  10. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Yes for the projects using Alloy we will simply sync with you guys.
     
  11. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    Tethys, zenGarden, John-G and 3 others like this.
  12. garyhaus

    garyhaus

    Joined:
    Dec 16, 2006
    Posts:
    601
    Thank you for the shader set and for the roadmap. Looking forward to seeing what's next!
     
    xenius likes this.
  13. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    We have recently purchased Alloy for use in our game and I was hoping that the Transmission shaders would work for our sails but I have run into a problem so far. Our meshes are single sided and the shader works great for the fronts when facing the directional light for the sun, but the back sides are not rendering correctly. They show the ambient light only and not the direct light source.

    Before suggesting two meshes (one for front and one for back) know that we are going to be using the cloth renderer and that causes all sorts of other issues. We want to stay with a single mesh with one set of vertices. I tested the loot scene and converted the map into cloth and it completely blew it up. I am guessing that it cannot handle the cloth rendering with the shader.

    Front of sails facing directional light


    backs of sails facing directional light


    loot scene map as cloth

    The second question I have is if there is a way to soften the shadows on the back sides of the object during transmission. The front shadows remaining sharp is correct, but the back sides would have a bit of a softer appearance and would not normally show a very detailed shadow on them, more of a softened version. Possible a shadow strength variable in addition to the weight.

    This is the current appearance on the backside of the mesh


    This is closer to what we are going for

    Any help would be appreciated. I am a programmer, not much of a shader artist.
     
  14. Deleted User

    Deleted User

    Guest

    @CaptainMurphy
    Ironically, you caught us right as we were discussing how to fix these issues for Alloy 3.2. I'm fixing the lighting for the DoubleSided variants of our shaders by having them render the backfaces with their normals inverted. Also, I'm planning to try out a "Shadow Influence" slider that will allow you to blend the shadows to white for the transmission effect.

    Hopefully those will be sufficient to solve your problems. ;)
     
    John-G likes this.
  15. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    Well if you need them beta tested just let me know. I have a test scene waiting on the sail shader to work correctly and so far Alloy is the closest we have come to it being right. I am working on the Substance Designer output to adjust the weight map as well so I am hoping to test that soon, too. That way seams will look correct with the backlighting.
     
    xenius likes this.
  16. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    Hi,

    I use Unity 5.0.2 and the latest alloy asset from the asset store. I have the problem, that if i activate HDR on the camera, the game mode, after starting the game, is black and is froozen. I use defered alloy shader, as it was described in the doc. Sometimes i get also laggy game environment... All these things not happens, if i use the Unity physical based shader.

    Any idea what could be wrong?
     
  17. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    Hi @mkgame Please shoot me an pm with the following info:
    - Your full hardware setup
    - Screenshot showing all postfx attached to camera
    - Screenshot of your player settings->other
    - Screenshot of your quality settings (currently selected one)
     
  18. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Hi- Really enjoying transfering my project over to Alloy. Some brilliant shaders there that fit some fairly obscure use cases I have. Can quickly see lots of interesting changes I can make to enhance atmosphere, just scratching the surface still! Also really inspired by the Null Operator blog- both aesthetically and philosophically- I think that trailer with the robots sold me on Alloy actually.

    Just wondering if there's any potential for a height blended variation on the 'Weighted Blend' shader that blends heightmaps on the two materials? Similar to this

    Also having trouble with vertex alpha out of Blender, looks like it's simply not possible. Is there any way to use, say red and green vertex channels instead?

    Cheers,

    Nick
     
    Last edited: May 22, 2015
    xenius likes this.
  19. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    Hi @ddnharris
    Thanks for your kind words about Null Op :)

    Though the param setup is a touch different, the Weighted Blend shader already has very similar functionality. You can simultaneously provide a blend map, and use vertex colors, then use the cutoff and blend params to fiddle with how you want them to be blended.

    Re: vAlpha we're keeping with a structure of alpha for single channel blend, RGB/RGBA for multi. You might have better luck using a vertex color painting asset from the unity asset store. I know the folks at camouflaj use one as they're making huge use of Weighted Blend for their next episode of Republique. I'll ping them as ask then which UAS asset they found best for that and post back here when I find out.
     
  20. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Cheers- I had a play around with cutoff/blend just after I wrote that post and did indeed get some great results. I've been using a Blender plugin to generate some quite sophisticated vertex colour effects, therefore keen to keep the vert colour pipeline on that side if I can. Alternatively, I'm not too bothered if I have to generate some low res maps to control blending using uv1 if need be.

    I was able to get the vert colour 4Splat shader working really well with the above. Would love to have more cutoff/blend control as for the weighted blend shader, but it suits needs as is.

    Thanks,

    Nick
     
    xenius likes this.
  21. jalapen0

    jalapen0

    Joined:
    Feb 20, 2013
    Posts:
    136
    Hello,

    Could someone show me (or point me documentation of) how to create an alloy material in code? I need to be able to do that for my current project. I am doing it with unity shaders but am swapping them out for Alloy. Thanks.
     
  22. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @jalapen0

    I'm not sure actually. The way multicompile materials (like Alloy/SS) work is that one needs to have a version of that material type (ie with the exact same features turned on/off) in the project/scene/forced include, so that that variant (amongst the 100s of thousands) is actually included.

    Sometime this weekend I'll give it a shot and get back to you ok? (this is really something I should know how to do frankly) Just to make sure everything works as expected. I do know in 5.1 they deprecated the creation of a material using a "string" name lookup, so I don't actually know off the top of my head what the 'right' way to do it anymore is.
     
  23. jalapen0

    jalapen0

    Joined:
    Feb 20, 2013
    Posts:
    136

    That would be great. I guess maybe another way would be to create a prefab and just copy the prefab, then set the sliders with code. That would be acceptable to me...except I don't really know how to do that either. :/
     
  24. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @jalapen0

    So this works.
    When you create a material (line 14), you can also plug a material in, which it will copy of the values from the referenced material, INCLUDING added property groups. This is probably how you want to go about things, as the fact that you've created a material of the multi-compiled type you want, and plugged it into a script guarantees it's been compiled to your build.

    Code (CSharp):
    1. public class AlloyCreateMaterialInScript : MonoBehaviour {
    2.  
    3.     public Material CopyMat;
    4.     public Renderer RendererToApplyTo;
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.         CreateNewMat();
    9.     }
    10.  
    11.     // Update is called once per frame
    12.     void CreateNewMat()
    13.     {
    14.         Material NewMat = new Material(CopyMat);
    15.         RendererToApplyTo.material = NewMat;
    16.  
    17.         //Now Apply Whatever Settings To Material here
    18.         NewMat.SetColor("_Color", Color.red);
    19.     }
    20. }
     
    jalapen0 likes this.
  25. jalapen0

    jalapen0

    Joined:
    Feb 20, 2013
    Posts:
    136

    Cool I will give it a shot tomorrow.
     
    xenius likes this.
  26. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    It isn't your shaders fault. HDR just works with forward rendering and the lags are there without unsing your shader. Unity 5.0.2f acts very weird, sorry for the post!
     
  27. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    What happened to the right click on the material header "Copy/Paste Material Properties"?
    Did Unity remove it?
    I used that a lot to get my materials (Alloy) to match up quickly.
    Now there is a ReDux It (copy?) which just freezes Unity.
     
  28. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Hi,

    Currently having trouble with the terrain shader on PC, DX9- it runs out of samplers with the far detail colour and normal maps:

    Shader error in 'Alloy/Terrain/4Splat': Program 'AlloyFragmentDeferred', error X4510: maximum number of samplers exceeded. ps_3_0 target can have a maximum of 16 samplers (on d3d9)

    Compiling Fragment program with LIGHTMAP_OFF DIRLIGHTMAP_SEPARATE DYNAMICLIGHTMAP_ON HDR_LIGHT_PREPASS_OFF _DETAIL_ON _TERRAIN_NORMAL_MAP

    Shader warning in 'Alloy/Terrain/4Splat': pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them at UnityCG.cginc(378) (on d3d9)

    Removing the detail colour fixes the errors/warnings and removes the pink error colour, but I'd obviously prefer to use the detail textures. It's fine on Mac, but occurs when I open the project on PC.
     
  29. Deleted User

    Deleted User

    Guest

    @ddnharris
    That's a sadly common problem when it comes to the Terrain shader. You see, most GPUs have a 16 texture limit per shader. By default, the terrain uses 9, then our detail feature adds another 3, then Unity can take anywhere from 1-7 depending on what ambient lighting features you have enabled and their quality settings (1-2 for reflection probes, 1-2 for static lightmaps, 1-3 for dynamic lightmaps).

    So basically, you have to decide whether you want all the crazy ambient lighting features or the detail mapping code.
     
  30. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @ddnharris:
    Make sure in the terrain Reflection Probe option is set to 'simple'
    In your lighting settings, do you have dynamic and baked GI enabled? Do you reeeeally need them both? In General GI, what is your directional Mode? If its Directional/Directional Specular, are you sure you need it so? All the of the things I mentioned munch on samplers.
     
  31. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Hi @n00body and @xenius , thanks for your guidance.

    I'm on a fairly antique GPU, GTX285, which hasn't been helping lately. I suspect that it's fussier about available samplers than the integrated GPU on my MacBook pro.. Turning off reflection probes on the object in question brings it into line, and I'll reconsider using directional specular. Out of interest, I'm running realtime GI + directional specular- it looks so good I don't quite have the heart to give up on it yet!
     
    xenius likes this.
  32. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Looks like if I set directional mode to directional, the irradiance doesn't show up on the shaded mesh. I can see it if I view the irradiance path in the scene view, but when I set it back to shaded it dissappears. If I go back to directional specular, it reappears.

    I should add, this is on a weighted blend shader- I have everything else on the core Alloy shader and those objects behave as expected.
     
  33. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @ddnharris What property groups do you have enabled on the Weighted Blend material?
     
  34. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    The main and secondary textures and physical properties, plus detail and blend properties.
     
  35. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    Hmmm. Lets see, that 3+3+1+4 = 11 Samplers before Probes/GI. If you're exceeding the number of samplers that can be bound (especially due to an older gpu), it maybe? is disabling features there isn't 'space' for.

    Would you do me a favor? Could you put together a fresh repro project with a small selection of objects/spheres with materials setup how you have them, with lighting how you want for me to review? (the lighter the project file the better).

    I'd be willing to take a look in the off chance that some flag isn't being set right, though my intuition is that too many things are active at once. All of Unity's Enlighten stuff + Probes being active is rather sampler-heavy.

    If its working in a more expensive mode though, and not in a less expensive mode... I'm not sure why that might be happening, but I can take a look nonetheless.
     
  36. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Sure, I'll do that today, thanks. I've been having trouble with Unity caching scene information that shouldn't be there since updating to 5.0.2f1. It's been incredibly frustrating and I wonder if this is something similar.

    One thing that often helps is clearing the baked information, closing/opening Unity, and rebaking, if any shaders are added to the project. I'll try that next..
     
  37. Karearea

    Karearea

    Joined:
    Sep 3, 2012
    Posts:
    386
    Hi, sorry for my confusion! I worked out the problem while making a repro project. I had a fairly high occlusion value for the M,S,AO,R texture, ie. slightly lighter than black if generated using the Alloy DM generator. This meant that without directional spec, the renderer couldn't pick up much of the irradiance, so it hardly showed. Generating a placeholder one from grey solved the issue, although there's a firefly problem over the mesh at a distance.

    There's also quite a marked difference in lightness between the two directional mode settings, which I hope to fix by reauthoring correct M,S,AO,R maps in Substance Designer.
     

    Attached Files:

  38. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
    Is there a new plan for the mobile version.. since UT is giving more love to the OpenGL implemenation?
     
  39. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @DennG At the moment, I see no mention of Unity adding linear color space support for high-end mobile platforms (i know that hardware like the Tegra can support it), so until that moment we aren't able to consider any sort of mobile support.
     
  40. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
  41. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @CaptainMurphy We're revising the Transmission shader for Alloy 3.2. It will have more control over shadowing behavior (as it relates to transmittance). I'll make sure to post an example when we push the update early next month :).
     
    CaptainMurphy likes this.
  42. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    I have a weird issue with the emission tint in the core shader. When set from code, the color displays correctly on the mesh in play mode. However, in play mode, when I click the drop down of the material on the mesh, the emission tint color gets reset to white (could be the original color set in the material?) in both the material and on the mesh.
     
  43. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @Korindian It's due to the inspector code rolling together UI params to generate a final HDR Color. If you need to BOTH set things via script and adjust them in play mode, you will have the essentially 'warm' the UI params (_WeightUI, GainUI, TintUI) with the same values you are using to set your HDR color by script.

    Good News Tho: In Alloy 3.2 (for Unity 5.1+) we're ditching this system, as there's a real HDR color picker coming.
     
  44. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    quick question regarding an effect i see in unreal engine. they seem to be doing an anylitic AO hack that looks really pretty! been playing with it myself and am wondering if you would consider adding something similar?
    AO effect.png
    ambientOcclusion = pow(Clamp 0-1(worldNormal.y+1), userPowerValue);
    it fakes contact occlusion on surfaces! plus if we had a slider to change the amount of this effect it could be tied to the players distance from the ground from script!

    one thing that this made me think of as well(just a random tangent here) if you could do something like spherical harmonics but with AO as well. you could have some bitchin AO on dynamic objects for cheap =3
     
  45. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @Cynicat Might play around with it, but there are a couple reasons why this probs. wouldn't make it into the Alloy core:

    1. Each pow is ~6 core instructions in effective cost. Would need to add in at the very least another static uniform to toggle the behavior so that it could be per-mat enabled. We guard changes like this jealously as they introduce further entropy into an already very complex system.
    2. Due to the way our spec. occlusion formulation, I'm not sure how this would exactly play, might have a chaotic/unwanted reaction
    3. This is a very.. how to put it... assumptive effect. It assumes a great deal about what a 'contact' shadow is, and where it should be most visible, as well as only applying it to one side of a pair. My geeeneral feeling is that SSAO touches the same use case, and despite its issues is at least dealing with things in a more... axially unbiased/unassumptive way.

    Regardless, we might take a look at it at some point once we've cleared our current todo log out.
     
  46. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    yeah i can see what you're saying. i wish unity had a better shader system so it wasn't such a hassle to add stuff like this. keep up the awesome! =3
     
  47. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    @Cynicat Truthfully, its not a matter of 'better or worse'. Just different. In UE4 you can't change core lighting functions. The insane node spaghetti that folks due to get a hair-ish shader in UE4 would be straight forward and (relatively speaking) easy in a single file in Unity. Both systems have tradeoffs. We sure wouldn't have been able to build something like Alloy in UE4 (if we had wanted/if it were needed).
     
  48. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    yeah i didn't mean like UE4. i mean't a more modular shading system. something where i could write a little effect on my own without knowing all the in's and outs of shader programming and use it in the standard shader, alloy or something of that nature. this could easily be an effect layered into the occlusion input. even if just for my demo's. i hope unity gets a node editor soon though. that way shaders can be more extendable. plus hacks like this would be a lot easier and therefor can be fitted to the current conditions more often. there are only so many effects i can do with just meshes/textures.

    as to node fuzz. its a matter of knowing the system and being clean with it. i made a PBR system using blender's node editor without it being a gross node-net. just need to group things into tasks. runs faster than most materials people make and even supports PBR material layering. no text code. its a matter of what you are used to, less to do with node graphs being innately messier. think of your very early code, it was prolly a mess right? same goes with graphs. artists who have used graphs for years are able to write clean graphs the way programmers write clean code. yet i see a lot of programmers dive in and try to do something the way they have always done it and be really mad when it doesn't work the same. its a different system with different strengths. its just a matter of tools. artists don't know how to optimize because they have never been allowed access shader code that needed optimizing. they don't know how to build lighting because they have never been given the tools to make it. i learned to make PBR using artist tools, not programming ones. and the implementation is cleaner than the code ones in my opinion. not the case with everything(math especially). but code flow is sooo much cleaner in a graph. at the end of the day its about how you prefer to think about your code. i hope there is a time when programmers and artists have the same level of tools within the engine. currently most engines favor programmers. which is good in a lot of ways(gameplay especially). however the visual side is missing out on the people who are actually really good at visuals. my best realtime effects where prototyped in blender.

    wow that turned into a long post fast. TLDR: Node Fuzz is on the same level as messy code. it goes away with time. [insert rant about artist equality].
     
  49. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
  50. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    In order for this to happen, you should use the glass shader which uses distortion based on your normal mapping. I'm not home atm, but there is a slider called distortion weight or something like that.

    And in the base colour set alpha to white for maximum effect.