Search Unity

[Best Tool Asset Store Award] Amplify Shader Editor - Node-based Shader Creation Tool

Discussion in 'Assets and Asset Store' started by Amplify_Ricardo, Sep 13, 2016.

  1. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    509
    Hi,

    For anyone interested, I made a Simple Lit template for Universal RP. Everything seems to work correctly so far, except for Smoothness. It doesn't work correctly in 0-1 range but I created a function to handle it and it seems to give the same result as the built-in Simple Lit shader. Also, the Specular color needs to be set to Gamma.

    Built-in left / ASE right
    upload_2019-10-18_16-33-8.png
    upload_2019-10-18_16-34-33.png
    upload_2019-10-18_16-35-8.png

    Cheers!
     

    Attached Files:

    Amplify_RnD_Rick likes this.
  2. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    Hey, so the problem is that we already have a pass called DepthOnly with the LightMode tag set to DepthOnly.
    I not completely sure but I think Unity only allows one pass per light mode, thus yours wont be called. You can maybe try to register your extra pass into a different light mode.
     
  3. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    That's really awesome, thank you for sharing this!
     
    BOXOPHOBIC likes this.
  4. tail_y

    tail_y

    Joined:
    Dec 9, 2018
    Posts:
    1
    (I use machine translation to write English.)

    I noticed that the latest ASE cannot preview the Function node.

    The preview of a function that has an input of ASE (v1.7.1 rev 01) will be a single color, or the value of input will be completely ignored.
    I didn't know what caused these two states to be displayed.
    I used v1.6.8 rev 00 from an old project. In this case, an accurate preview is displayed.

    The version of Unity I am using is Unity2018.4.9f1.
    I hope this situation will improve.
     

    Attached Files:

  5. OmarVector

    OmarVector

    Joined:
    Apr 18, 2018
    Posts:
    130
    In unreal engine there is a node called FeatureLevelSwitch , its a node that allows you to make simplified materials for lower powered devices. Example Usage: You might have a material with 10 textures overlapping and complex math, but just a single static texture for mobile (feature level ES2).

    Does Amplify Shader has something similar?
     
  6. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    Thank you for reporting this issue. We were already able to replicate it on our end and will release a fix on a future build.

    Unfortunately no, although this seems quite useful.
    You cannot have different shader models inside an ASE shader but you can have different behaviors for each API.
    It's a bit more low-level but this can be done using our Static Switch node as there are specific keywords that are defined for each platform.
    You need to set its Mode to Fetch and on the Keyword dropdown select Custom. Over the Custom textfield you'll need to specify the keyword which will indicate which API you are testing.
    Please check here for all API keywords.

    So, p.e. if you want to test GL ES 3.0 you would have your Static Switch like this.

     
    cyuxi and OmarVector like this.
  7. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    509
    Hi. I have an issue with URP and a shader with vertex offset. The shadow is "waving" on the objects but only in scene view. When I hit play, everything looks fine in game view. Any ideas what could cause the issue?
    line4.gif

    Another test:
    line4.gif upload_2019-10-21_15-34-6.png


    Also, is there a way to do the clip(alpha - cutoff) function based on _ALPHATEST_ON, like the URP Lit shader do it, without modifying the template? My shaders use a custom inspector to change the rendering modes.

    void AlphaDiscard(real alpha, real cutoff, real offset = 0.0h)
    {
    #ifdef _ALPHATEST_ON
    clip(alpha - cutoff + offset);
    #endif
    }

    Edit: Found something and it is only happening in scene view:
    line4.gif
     
    Last edited: Oct 21, 2019
  8. OmarVector

    OmarVector

    Joined:
    Apr 18, 2018
    Posts:
    130
    I think its what I'm looking for, however, does it strip out any unused texture samplers when its false? or it would be still loaded inside GPU?
     
  9. jxxxxst

    jxxxxst

    Joined:
    Nov 3, 2012
    Posts:
    50
    Hi there, I want to create a sort of reflection probe lighting shader.
    In a custom lighting shader is there a way to fix the rotation of a reflection probe cubemap?
    I want to utilize the indirect specular lighting node, but cant seem to find a way to have the reflection probe image not move on the objects surface.

    Thanks in advanace!
     
  10. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    Regarding the first issue, strangely this seems to be related to the Sin Time Node. It seems to have different values between the shadow caster and the forward pass thus creating that strange behavior.
    I took a look at Unity's time variables over URP and they have a new global _TimeParameters which on its y component has a sin time value.
    We'll make this variable available on ASE but on the meantime you can paste this on your canvas:
    http://paste.amplify.pt/view/raw/6543b89f

    Here's a shot of what you'll be pasting:

    This is a Vector 3 node set as Global and Fetch so it can grab the value of the already declared _TimeParameters.

    Regarding your second question. The only way I can think for now that doesn't involve modifying the template is through a Custom Expression:
    Something like this:
    http://paste.amplify.pt/view/raw/e348dad8

    Again, the shot is:



    Set its mode to Call, connect the Out output port to any fragment input port over the master node node. The In input port acts as a relay directly to the Out port.

    Yes it will strip any unused textures. Here's a quick test using the setup I mentioned earlier:
    TextureStripDownTest.png

    On the right red box is the material inspector for the current opened material which you see both the textures you are using.

    Over the left red box is the Frame Debugger, where we can check what resources the GPU is using for the selected object (which uses our material). As you can see only one of the textures is being used and the other one was stripped away.

    I do apologize but I'm not sure I quite what you've written. Can you clarify on what you mean when you say that you don't want the reflection probe image not move on the objects surface?

    The Indirect Specular Light gets the reflections from Unity GI/Reflection Probes but it cannot change its rotation.
    A reflection value depends both on the current object's normal and the camera view vector, so rotating either the camera or the object will make that value change.
     
  11. IRobin42

    IRobin42

    Joined:
    Jun 6, 2019
    Posts:
    2
    Hi Rick,

    Thanks for your reply, it helped us to find the solution to our issue! To anyone out there interested, here's our fix to add an extra depth pass to a LWRP shader:

    We deleted all the passes that were generated by Amplify but not actually used by our material, and we modified the beginning of the shader like this:
    Code (CSharp):
    1. Pass {
    2.             Name "Depth Fill"
    3.             Tags{"LightMode" = "LightweightForward"}
    4.             ZTest Less
    5.             ZWrite On
    6.             ColorMask 0
    7.         }
    8.  
    9.         Pass
    10.         {
    11.             Name "Base"
    12.  
    13.             Blend One One
    14.             ZWrite Off
    15.             ZTest LEqual
    16.             Offset 0,0
    17.             ColorMask RGBA
    It was very simple in the end, we added a Depth Fill pass before our main pass where all the calculations are made. We had to add the lightmode tag otherwise the pass wouldn't be read. (Blend is One One because I wanted additive but you can put any transparent blend calculation ofc)

    Cheers!
     
  12. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    509
    Thanks for looking into this! I didn't expect to see a different time parameter in URP. Both work as expected.
    Regarding the clip function here is the full working setup:
    upload_2019-10-23_9-47-25.png

    Thanks!
     
  13. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    Hey guys we uploaded a new build into our website.

    Here are the release notes.

    Release Notes v1.7.1 rev 07:
    • New Shader Functions:
      • Derive Tangent Basis
      • Height-based Blending
    • Improvements:
      • Clicking on node specific messages over ASE log now jumps to which node generated it
      • Changing ports types to matrix now sets the identity matrix into its internal data
        • Relevant on nodes like 'Custom Expression'
    • Fixes:
      • Fixed issue on incorrectly adding 0 to W channel when creating position vectors
      • Fixed issue on not auto-importing templates correctly over Unity 2019
      • Fixed multiple issues regarding shader function previews
      • Fixed compilation issue when using unreferenced 'Get Local Var' nodes
      • Fixed issue on changing 'Static Switch' name not being reflected on referenced list
      • Fixed issues with 'Texture Coordinates' and 'Texture Sampler' nodes with 'Relay' or 'Wire' nodes on Tex port
    Happy shader creations!
     
  14. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
    Hi, just to keeping you updated, I asked the same question on the Curved World forum, and they Developer was able to find the solution, as explained here It's not a problem with curved world itself, but something that happens because of the way Amplify Shader works.

    Anyways just so you're aware of that.
     
  15. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    Thank you for the update.

    We already tweaked the /*ase_pragmas*/ tag a while ago since we internally already had cases where we needed to have directives included after the templates native ones.
    At that time we also added the capability for the user to be able reorder the directives relatively to the native libraries as they wish since some may be needed before.

    You just need to drag and drop the directive item to where you want it to be:
     
    Last edited: Oct 24, 2019
    daville likes this.
  16. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    Is there any sort of official community repository of shaders or anything where people share shaders and such they have made, or is this thread the "go-to" place? I was just wondering if anyone happened to do anything neat for an HDRP skin shader? Using the default lit shader and trying to use the subsurface scattering seems way too intense, and trying to adjust it any doesn't seem to help much, so I was just curious if anyone else happened to have came up with anything nice? I tried searching this thread for hdrp skin, but didn't come up with much anytime recently.
     
  17. Amplify_Ricardo

    Amplify_Ricardo

    Joined:
    Jul 19, 2013
    Posts:
    2,389
    Not sure about Skin shaders but you can find samples on our official discord and on GitHub(you can also search for it on public repositories).

    No luck by adjusting the Diffusion profile?
     
  18. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    Hey guys,

    We've just uploaded a new build into our website.

    Here are the release notes.

    Release Notes v1.7.1 rev 08:
    • Fixes:
      • Fixed issue on 'Register Local Var' not allowing to reset name to loaded one
      • Fixed Console Log issues with Personal Skin
      • Fixed issue on overwriting Render Type custom values over a template(API)
      • Fixed issue on local variables generation over the 'Unpack Scale Normal' node
      • Fixed issue with setting special tags over template options (API)
    • Improvements:
      • Added more flexibility to 'Static Switch' node
        • Can have empty property names when Material Toggle is toggled off
        • It no longer modifies keywords ( setting to upper, adding _ON, etc ) if Material Toggle is toggled off
        • Tweaked visible options when on Fetch mode
      • Added hot-fix to 2019.2 Lit template in order to generate shaders without errors when used on HDRP v7.x.x

    Happy shader creations!
     
  19. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,643
    Hello I am trying to figure out if there is a way to enable #pragma enable_d3d11_debug_symbols. only for debug build, maybe through the use of the MULTI_COMPILE feature. Any advice?
     
  20. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    that discord link doesn't work
     
  21. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    I don't think enable_d3d11_debug_symbols is a keyword so you won't be able to use multi-compile on it. Thus this is something that you won't be able to change at run-time.
    For you to set it up just go to the Additional Directives over the master node properties and add an entry. Over the dropdown ( on the left ) select Pragma and paste enable_d3d11_debug_symbols over the textfield ( on the right ).


    Here's an updated link. That one must have had an expiration date.
     
    sebas77 likes this.
  22. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,643
    thanks I was already doing that, I hoped to find a way to be able to not go through all the shaders and add/remove the pragma for each debugging session.
     
  23. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,643
    Another question if you don't mind, I am new to ASE, trying to understand if I am getting it right. I have unticked the LOD cross fade option, but the relative code is still generated. What am I doing wrong?
     
  24. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    No problem at all, we're here to help.
    I'm assuming that you are either using Lightweight or Universal RP.
    You're not doing anything wrong.
    What the LOD CrossFade does code wise is to register the LOD_FADE_CROSSFADE keyword usage through a #pragma multi_compile.
    The code you see on the shader is surrounded by an #ifdef LOD_FADE_CROSSFADE / #endif which means that it will be stripped down if that keyword is not defined.
     
  25. apan-bin

    apan-bin

    Joined:
    May 15, 2015
    Posts:
    29
    OK!
     
  26. VertigoJack

    VertigoJack

    Joined:
    Aug 2, 2019
    Posts:
    8
    I'm having some trouble with having a duplicated texture sample property. It was mentioned in the change log for v1.7.1 rev 02/03 that this was fixed but I'm still encountering this issue. I haven't found a good way to reproduce this issue as it seems to fix itself sometimes.

    I have a single Texture Object node, with the property name _Albedo, that is being used by a Texture Sample node and a Parallax Occlusion Mapping node. For some reason it will still create 2 _Albedo_ST properties: one outside of the UNITY_INSTANCING_BUFFER_START and one inside of it, causing the redefinition error. If I turn off instancing it doesn't seem to have any effect on this.

    Another issue I have noticed is that it won't put the name of the shader into any of the instancing macros (UNITY_INSTANCING_BUFFER_START/END, UNITY_ACCESS_INSTANCED_PROP). Along with this, when it makes the Parallax Occlusion Mapping function call, it won't use the instanced local variable and instead try to reference the non-instanced property.

    Any help would be wonderful as this is really bothering me a lot since I can only fix it by editing the actual file.
     
  27. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,643
    thanks, yes I am using LWRP. I am now trying to figure out if there is a way to disable portion of shaders according the current shader LOD. I want to create several set of shaders according the current quality settings (I don't understand why unity doesn't just support a shader define linked to the quality settings). This is just to avoid to swap shaders at run time according the quality settings. Is it possible?

    Edit (apologize beforehand for the number of following questions) : I want to add some feedback after some hours using the editor:

    The undo is inconvenient, but unluckily also unreliable. Inconvenient because the undo is mixed with the other unity editor actions, so I can't touch the editor if I want to undo the shaders. Unreliable because I get often to weird states like this:

    upload_2019-10-30_11-46-23.png

    this forces me to keep locally various version of the shader to be able to revert when I get to broken states. There are other weirdness with disappearing nodes that undo cannot make them reappear again, but I can't tell more until I understand what actually happens. Can this be solved?

    The Triplanar Sample as a Texture Array option that seems to be undocumented, can you point me out how to use it?
     
    Last edited: Oct 30, 2019
  28. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    Thanks for the info, it was really useful. We did fixed this issue at certain cases, but some may have missed.
    We already were able to replicate the issues following your steps so rest assured that it will be fixed on our next build.

    I wasn't able to replicate this part of the cbuffer declaration, on our tests the shader name was always set as the name of the cbuffer.
    Regarding the usage of the incorrect local variable, we also replicated the issue and will fix it on our next build.


    We are using Unity's own Undo system and yes it's really really finicky. Ctrl+Z is strictly bound (or at least was ) to Unity's own Undo system and since we wanted to use that shortcut ( as it's almost the go to standard undo shortcut ) we were a bit forced to using their system, but it has a lot of issues.
    We have future plans on doing a complete revision on this.

    The usage is the same as you would on a regular texture. You just need to plug-in the additional information of which index of the texture array corresponds to which map.
    P.e you have a texture array which on its first position would have the top, second position would have the middle and third position would have the bottom textures, then on the Top Index you would set 0, Middle Index set 1 and Bottom Index set to 2
     
    Last edited: Oct 30, 2019
  29. VertigoJack

    VertigoJack

    Joined:
    Aug 2, 2019
    Posts:
    8
    I'll see if I still get it after the next release and if I can get a better replication process.

    Glad you were able to replicate the other issues on your end though, will be waiting for the next release.
     
    Amplify_RnD_Rick likes this.
  30. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    I asked about this some time ago but stumbled over it again while upgrading to HDRP 7 and current Amplify:
    You are able to overwrite vertex normal and vertex tangent but this is not reflected in binormal calculation which makes this somewhat useless. I know this can potentially make stuff much more complicated eg when the graph contains Vertex Normal nodes but the current state makes no sense.
    Maybe you can find a simple workaround for now, like an opt in thats pushes binormal creation down a bit?

    FYI: Unity's ShaderGraph handles this correctly.

    Edit: My current solution is to define wbt in ToPS structure and explicitly calculating binormal in template.
     
    Last edited: Oct 31, 2019
  31. arnoob

    arnoob

    Joined:
    May 16, 2014
    Posts:
    155
    Hello everyone!

    So, maybe it will sound dumb, but can someone show me an example of a texture sampling (just like the normal texture sample node) made with a custom expression node? I don't know yet how to write that in the code window, but would love to be able to play with that a bit.

    Thanks!
     
  32. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    We do apologize for not having provided a solution for that problem yet. It's a bit tricky because of how templates are dealt inside ASE.
    Nevertheless we'll do our best to come up with a proper solution.

    It's not dumb at all.

    Here's a screenshot of the most basic sampling operation you can do:



    And here's the link to that node graph, just copy it to your clipboard and paste it directly into an ASE canvas.
    http://paste.amplify.pt/view/raw/9d783f2e

    Over that custom expression you have two inputs, one to receive the texture object and the other to receive the texture coordinates as you need at least those two to perform a sampling operation.

    For more information about the tex2D instruction you can check Nvidia's Cg documentation over here.
    Also be sure to check our documentation on the Custom Expression node
     
  33. Cerberus_team

    Cerberus_team

    Joined:
    Apr 9, 2014
    Posts:
    43
    The standard shader has a "Reflection" checkbox so that the smoothness slider doesn't affect the cubemap.
    Can we do something similar in ASE?

    I' am using dual lighting to create a car shader, a specular workflow for the coating and a metallic one for lights only.
    But i don't want the smoothness slider in the metallic workflow to affect the reflections.

    Is this possible?
     
  34. Polygonmaker

    Polygonmaker

    Joined:
    Nov 18, 2013
    Posts:
    81
    I am having a hard time to find some documentation regards the use of Terrain Wind Animate Vertex. I tested in your demo scene, but it doesnt work in any other shader. Can you help me here please?
    Also any news about the possibility to use world normal maps instead tangent only using the default render pipeline in Unity 2018.3.5?
     
  35. InsaneMonster

    InsaneMonster

    Joined:
    Mar 5, 2017
    Posts:
    4
    Hi, I'm currently getting mad at making ASE working with HDRP. So I'm seeking out for help.

    I made some shaders with ASE, mainly to apply team color to HDRP Lit shaders. I'm been using HD Lit template. I've run into serious troubles and those troubles are related to ASE as far as I know, since they all disappear as soon as I remove any compiled ASE shader from my assets (no need to remove the package itself).

    The first problem I noticed is that, sometimes, all my materials UV are messed up. This happens to HDRP Lit shaders (default ones) only when I compile some ASE shaders, but does not happen to ASE shader themselves!

    In this picture you can clearly see some materials are wrong...
    upload_2019-11-2_12-46-14.png

    This is how it looks like after forcing any ASE shader to recompile (a lot of warning I seem to be unable to fix are also thrown at me). This is also how they look when not using ASE at all (the ramp is still messed up in its front model because it is the ASE shader in the scene and the problem is due to emission, more on this later).
    upload_2019-11-2_12-47-14.png

    It seems ASE is breaking something inside Unity HDRP... At least from my limited knowledge of how ASE works. For what I understood, HDRP requires many shader variants to be compiled. ASE adds its own shader on top following the same paradigm. Something goes wrong here, as far as I can tell...

    Beside that, I also cannot be able to deal with Emission texture map. First of all, I've found no way to have an exposure node to have emission be visible under different illumination settings. This is a major setback and it needs to be fixed asap, in my opinion (Shader Graph has one).
    Also, much more important because it completely breaks emission, emission textures does not seem to be be sampled correctly. The node is the same as every other node texture sample (and indeed they all work fine).

    upload_2019-11-2_12-49-19.png

    When I apply my texture to this node (texture is authored with substance and works with default Unity HDRP Lit shader, so not a texture fault), it is applied in a way I cannot really understand. This happens even with other textures (for example the Base Map) when applied to emission texture. Just a fool-proof that's not texture related. I show you some images for comparison. Tiling is set to (1, 1) and offset is set to (0, 0), just like when applied to default HDRP Lit shader.

    This is how it looks like with Unity HDRP Lit Shader:
    upload_2019-11-2_12-50-49.png

    And this is how it looks like with ASE HD Lit template (with the sampler node shown above):

    upload_2019-11-2_12-51-22.png

    I also had to pump the emission HDR intensity to 15 to make it visible at all. Maybe I'm missing something basic, don't know. Never had this problem with Unity Built-in and ASE, but combining ASE with HDRP is showing up to be a great trouble. This emission bug shows up in every material I've made (with HD Lit template).

    I'm currently using last Amplify Shader Editor version, without examples (I imported everything except examples). I tried to reimport to see if something went corrupted but nothing changed. Unity is 2019.2.7f2 and HDRP is 6.9.2 (I tried to update from 6.9.1 but nothing changed).

    I really need some help here because my workflow is completely broken and porting all my ASE shader to Shader Graph is really something I don't want to be doing...

    Hope to hear from you as soon as possible, thanks in advance!
     
  36. InsaneMonster

    InsaneMonster

    Joined:
    Mar 5, 2017
    Posts:
    4
    Ok, update, but only for the last issue. It seems the problem of the UV map was due to the Texture Sample node. I just created a new Texture Sample node, deleted the first one and connected the new one (texture, graphs are all the same), and the issue disappeared immediately. Interesting!

    Now, the first (UV broken from distance, probably mip maps, of HDRP Lit materials when using ASE) and second (missing exposure control weight inside graph) issues still remains, and I need further input from you. Beside that, I would be really curious to know why a problem like the one mentioned above solved itself by just swapping a node with... another equal node? o_O It just seems counterintuitive to me...
     
  37. boorch

    boorch

    Joined:
    Oct 7, 2015
    Posts:
    40
    Hi!
    I'm trying to rebuild a "pixel art rotation shader" I've found online (sadly I don't remember where, it was months ago, I tried to find it again but I couldn't) in Amplify Shader Editor but so far I'm super confused.

    This is the shader:
    Code (CSharp):
    1. Shader "Unlit/spritePixelated"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.  
    7.         [Header(Scaling)]
    8.         _Res ("Resolution", Float) = 1024
    9.         _PixelSize ("Pixel Size", Float) = .0625
    10.  
    11.         [Header(Sprite MetaData)]
    12.         _SpriteUV ("Sprite Rect", Vector) = (1,1,0,0)
    13.         _SpritePivot ("Sprite Pivot", Vector) = (1,1,0,0)
    14.         _UVCenter ("_UVCenter", Vector) = (0,0,0,0)
    15.  
    16.     }
    17.     SubShader
    18.     {
    19.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"
    20.         "DisableBatching"="True"
    21.         }
    22.         Cull Off
    23.         LOD 100
    24.         Blend SrcAlpha OneMinusSrcAlpha
    25.         Pass
    26.         {
    27.             CGPROGRAM
    28.             #pragma vertex vert
    29.             #pragma fragment frag
    30.  
    31.             #include "UnityCG.cginc"
    32.             uniform half _Res, _PixelSize;
    33.             uniform half4 _SpriteUV, _SpritePivot, _UVCenter;
    34.             struct appdata
    35.             {
    36.                 float4 vertex : POSITION;
    37.                 float2 uv : TEXCOORD0;
    38.             };
    39.             struct v2f
    40.             {
    41.                 float2 uv : TEXCOORD0;
    42.                 float4 vertex : SV_POSITION;
    43.             };
    44.             sampler2D _MainTex;
    45.             float4 _MainTex_ST;
    46.  
    47.             float2 quant(float2 q, float2 v){
    48.                 return floor(q/v)*v;
    49.             }
    50.  
    51.             v2f vert (appdata v)
    52.             {
    53.                 v2f o;
    54.                 o.vertex = UnityObjectToClipPos(v.vertex);
    55.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    56.                 return o;
    57.             }
    58.  
    59.             float2 quantToWorld(float2 value, float q){
    60.                 float2 wp = mul(unity_ObjectToWorld, float4(value,0,0) );
    61.                 wp = quant(wp, q) ;
    62.                 return mul(unity_WorldToObject, float4(wp,0,0));
    63.             }
    64.  
    65.             fixed4 frag (v2f i) : SV_Target
    66.             {
    67.                 float2 uv = i.uv;
    68.                // next line is the pixelation
    69.                 uv = quantToWorld(uv-_UVCenter.xy,  1/_Res)+_UVCenter.xy;
    70.  
    71.                 fixed4 col = tex2D(_MainTex, uv);
    72.                 clip(col.a-.001);
    73.                 return col;
    74.             }
    75.             ENDCG
    76.         }
    77.     }
    78. }

    And this is the component that kind of "forwards" UV data of the current sprite to the shader:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. [ExecuteInEditMode]
    5. [RequireComponent(typeof(SpriteRenderer))]
    6. public class SpriteUVToShader : MonoBehaviour {
    7.     public string UV_property="_SpriteUV";
    8.     public string Pivot_property="_SpritePivot";
    9.     public string uvCenter_property="_UVCenter";
    10.     public string textureSize_property="_Res";
    11.     public string pixelSize_property="_PixelSize";
    12.     SpriteRenderer sr;
    13.     Sprite sprite;
    14.     MaterialPropertyBlock mpb;
    15.  
    16.     void OnValidate()
    17.     {
    18.         update();
    19.     }
    20.  
    21.     void OnWillRenderObject(){
    22.         update();
    23.     }
    24.  
    25.     void Start(){
    26.         update();
    27.     }
    28.  
    29.     void update(){
    30.         if(sr==null)
    31.             sr = GetComponent<SpriteRenderer>();
    32.  
    33.         if(sprite != sr.sprite){
    34.             sprite = sr.sprite;
    35.             applySpriteUV(sr, sprite, ref mpb, UV_property, Pivot_property, uvCenter_property);
    36.             applySpriteTX(sr, sprite, ref mpb, textureSize_property, pixelSize_property);
    37.         }
    38.     }
    39.  
    40.     public static void applySpriteUV(Renderer renderer, Sprite toSprite, ref MaterialPropertyBlock mpb,
    41.         string uvProp=null, string pivotProp=null, string uvCenterProp=null){
    42.  
    43.         if(toSprite==null) return;
    44.  
    45.         var scale = new Vector2(
    46.             toSprite.textureRect.width/ toSprite.texture.width,
    47.             toSprite.textureRect.height/toSprite.texture.height);
    48.  
    49.         var offset = new Vector2(
    50.             toSprite.rect.x/toSprite.texture.width,
    51.             toSprite.rect.y/toSprite.texture.height);
    52.  
    53.         Vector4 uvVector = new Vector4(scale.x,scale.y,offset.x,offset.y);
    54.         Vector4 pivotVector = new Vector4(toSprite.pivot.x/toSprite.rect.width,toSprite.pivot.y/toSprite.rect.height);
    55.  
    56.         if(string.IsNullOrEmpty(uvProp))
    57.             uvProp = "_MainTex_ST";
    58.         if(mpb==null)
    59.             mpb = new MaterialPropertyBlock();
    60.         renderer.GetPropertyBlock(mpb);
    61.  
    62.         mpb.SetVector(uvProp, uvVector);
    63.         if(!string.IsNullOrEmpty(pivotProp))
    64.             mpb.SetVector(pivotProp, pivotVector);
    65.  
    66.         if(!string.IsNullOrEmpty(uvCenterProp))
    67.             mpb.SetVector(uvCenterProp, new Vector2(
    68.                 Mathf.Lerp(uvVector.z, uvVector.z+uvVector.x, pivotVector.x),
    69.                 Mathf.Lerp(uvVector.w, uvVector.w+uvVector.y, pivotVector.y)
    70.             ));
    71.  
    72.         renderer.SetPropertyBlock(mpb);
    73.     }
    74.  
    75.  
    76.     public static void applySpriteTX(Renderer renderer, Sprite toSprite, ref MaterialPropertyBlock mpb,
    77.         string texSizeProp=null, string pixSizeProp=null){
    78.  
    79.         if(toSprite==null || string.IsNullOrEmpty(texSizeProp)) return;
    80.  
    81.         if(mpb==null)
    82.             mpb = new MaterialPropertyBlock();
    83.         renderer.GetPropertyBlock(mpb);
    84.  
    85.         mpb.SetFloat(texSizeProp, toSprite.texture.width);
    86.         if(!string.IsNullOrEmpty(pixSizeProp))
    87.             mpb.SetFloat(pixSizeProp, 1f/toSprite.pixelsPerUnit);
    88.  
    89.         renderer.SetPropertyBlock(mpb);
    90.     }
    91. }
    I'm trying to make sense reading the shader code to a degree but I simply don't know how can I rebuild this is Amplify. For example, I really don't understand where the _SpriteUV and _SpritePivot variables are used in the shader. As far as I can make sense (which is not much) they're just declared and I don't see them being used in vertex or fragment functions. I really don't know where to start. All the shaders I've created before were simply some vfx surface shaders for 3d objects. I've never dealt with any external data for a shader besides random values from particle systems.

    I'd appreciate ANY help!
    And thanks a lot in advance!
     
    Last edited: Nov 3, 2019
  38. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    We do that also that option on ASE. Over the Rendering Options on your Output Node properties, you'll need to toggle on the Fwd Reflections Toggle options.
    After that, just compile your shader and you'll notice the same option will appear over your material inspector.


    ReflectionsToggleASE.png


    This shader function internally uses Unity's own internal AnimateVertex function which is declared over the TerrainEngine.cginc library.

    Unity does not supply any type of documentation over this function but the code itself over the builtin shaders is well commented.

    Regarding the shader function itself, besides vertex position and normal, this function receives a float4 Anim Params which controls/sets up animation parameters.
    Anim Params.x component controls the branch's phase
    Anim Params.y component sets the edge flutter factor
    Anim Params.z is the primary factor which controls the primary bending
    Anim Params.w is the secondary factor which control edge and branch bending.

    This shader function only works when used on Unity Terrain trees because it makes use of its Wind Zones. So if you use it elsewhere it won't work because it won't receive any information regarding wind zones.

    Regarding your second question, we have no plans (at least for now ) on allowing world space normals to be used directly on the Normals port over the Standard Surface Shader Type as the surface shader itself must receive normals in tangent space.
    Unfortunately for now, if you want to use World Normals then you'll need to convert them into tangent space (using the Transform Direction node) before connecting them to the Master Node's Normal input port.

    HDRP in ASE is just a collection of templates. We are not configuring anything on the HDRP pipeline nor adding any special code when creating our shaders.
    The templates themselves are based on Unity own HDRP internal templates.
    Its quite strange that using an ASE shader would influence another one.
    Regarding the Emission Node, rest assured that we will add it on ASE as well. Expect to have it on our next build.
    About that UV issue, it would be immensely helpful if you could pack me a sample project with the issue and send me through the support@amplify.pt so I can see what might be happening.

    This is definitely a but on our end. We'll need to try and replicate it to be able to fix what is happening.

    For that shader I recommend using the Unlit template as it seems to fit your needs.

    You don't need to change anything on the vertex function

    For the fragment function:

    The quantToWorld and quant can be created through nodes, but it would be easier perhaps to create them as two separate custom expressions ( just to keep a similar structure to the original source )

    You should first create the quant custom expression and then add it as a dependency on the quantToWorld one.

    Regarding those unused properties, they really seem unused as there are no reference to them on the code nor the shader is using any Unity internal function that would make use of it.

    That shader ends on a clip instruction so would also need to have to use our Clip node and plug it directly into the Color input port over the Master node.

    Hope that helps.
     
    boorch likes this.
  39. Cerberus_team

    Cerberus_team

    Joined:
    Apr 9, 2014
    Posts:
    43
    It works but that will remove reflections all together, what i need is to remove them on the "Standard Surface Light" node itself.
    Smoothness.png Or else i get double reflections and blurry edges around the cubemap
     
    Last edited: Nov 5, 2019
  40. InsaneMonster

    InsaneMonster

    Joined:
    Mar 5, 2017
    Posts:
    4
    Ok maybe it could be HDRP fault then? I will do further testing in order to to try to make the problem disappear entirely.

    Really looking forward to it then! Any ETA?

    I'll try to reproduce in a sample project in the next days, when I have time. If I succeed, I'll send it to you.
     
  41. GSoch

    GSoch

    Joined:
    Feb 14, 2017
    Posts:
    2
    Dear Amplify Crew,

    we're currently running into 2 problems using Unity 2019.2.9f1 with HDRP 6.9.1 and Amplify v1.7.1 rev 01 for generating Shaders (HD/Lit Template, with Material Type set to Anisotropic):

    1. When having Motion Blur enabled in the HDRP profiles, meshes using our custom shader are correctly blurred when we move the camera. But when the meshes themselves are animated and the camera is still, meshes are not affected by Motion Blur. Assigning Unity's own HD/Lit Shader produces correct MotionBlur when we animate the meshes. "Motion Vectors" has been checked under "Available Passes". What else am I missing?
    Furthermore, some meshes have a Parent that is animated via a script (I guess the rotation is just set to a fixed value each frame, the developer is currently not available), and those meshes have no Motion Blur at all, even when only moving the Camera. How could we fix this?

    2. We are enabling Anistropy as "Material Type", and I managed to match it to the Unity Anisotropy by remapping the values of the Tangent Map from 0 to 1 onto -1 to 1. But even though it's matchin the Anisotropy on the Unity HD/Lit material, the specular lobes and the angle seem really off compared to what I expected. Am I using the Tangent Map wrong, do I need any other Multipliers?
    Anisotropy.jpg
    Furthermore, the Cylinders on which the shader is used are rotating - and in doing so, at 180° rotation the Anisotropic reflection is upside down, it's a bit hard to see in the screenshots, but very obvious in realtime. I guess this is because the Tangent map is rotating with the Mesh, so the reflection vectors are off when the mesh is not at 0° - but it's not supposed to work like this in reality, is it?! Would I have to somehow rotate my UVs in world space ore something fancy like this, so it looks more correct?

    Any help is appreciated, thanks!
     
  42. LarsBreuer

    LarsBreuer

    Joined:
    Jul 19, 2017
    Posts:
    5
    Hi!

    I am new to shader technology so please excuse my lack of vocabulary and the perhaps simple question.

    I want to change the color of the material I created with a noise generator. So far I only managed to change the white areas.

    Before:


    After:


    How can I color the black areas?

    Thanks for your help.
    Lars
     
  43. LarsBreuer

    LarsBreuer

    Joined:
    Jul 19, 2017
    Posts:
    5
    Ok. I answer my own question. I did it this way:



    (I really looked everywhere yesterday. Today I thought I'd have a quick look again after my post and ... found the solution directly.)
     
  44. Amplify_Ricardo

    Amplify_Ricardo

    Joined:
    Jul 19, 2013
    Posts:
    2,389
    Great knowing you found a way to do it! I think you'll find that there are multiple ways of achieving the same effect, it usually depends on what you need to build, or any specific constraints, so I invite you to check our beginners series as a starting point.

    As a side note, the previous node setup did not color the black areas because that's the equivalent of multiplying something by 0; this is covered in our series.

    You might find the Remap Node interesting, you can create quite a few things with it.
     
  45. Amplify_RnD_Rick

    Amplify_RnD_Rick

    Joined:
    Feb 15, 2016
    Posts:
    528
    Hey guys,

    I've just uploaded a new build into our website.
    Here are the release notes.

    Release Notes v1.7.1 rev 09/10:
    • New Node:
      • HD Emission
    • Fixes:
      • Fixed issue when reading shader with missing shader function
      • Fixed issue when duplicating property nodes on Fetch mode would reset property name
      • Fixed issue on 'Parallax Occlusion Mapping' node incorrectly generating instanced _ST vars outside the CBuffer
      • Fixed alpha cutoff issues on HD Lit templates v5.7.2 and v5.16.1
      • Fixed issue on not declaring both BakedGI and BakedBackGI on Lit template
      • Fixed issue on not setting some ports with graph data over templates
    • Improvements:
      • Listing on nodes is now alphabetically ordered
        • Get Local Var
        • Grab Screen Color
        • Static Switch
        • Texture Array
        • Texture Sample
      • Node search bar text now takes property name and inspector name into account

    What you can perhaps do is set the occlusion value to 0. This will remove any GI contribution to the lighting calculation over that node.

    Thank you for that. It will help us a lot.
    Regarding the node, this build I've uploaded already has it.
    It's called HD Emission.

    We'll need to do some tests on both those points to see what might be happening. We'll let you know as soon as we have something.
     
    GSoch likes this.
  46. LarsBreuer

    LarsBreuer

    Joined:
    Jul 19, 2017
    Posts:
    5
    Thanks for your reply.

    I'm working on a board game right now. I only need the shader to show the flow between the fields. But if I want to deepen my knowledge about shaders, I will be happy to use your tips.
     
    Amplify_Ricardo likes this.
  47. Cerberus_team

    Cerberus_team

    Joined:
    Apr 9, 2014
    Posts:
    43
    I need occlusion, can't do this.
    I guess it can't be done for now, it would make a great addition for a future release.
    Thanks for your help.
     
  48. boorch

    boorch

    Joined:
    Oct 7, 2015
    Posts:
    40
    Hi! Can you give me elaborate on how to create quantToWorld and quant a custom expressions? A schematic screenshot maybe? (Sorry I'm quite new to shaders and such and I'm not very good at math)
     
    Last edited: Nov 7, 2019
  49. JTPrime

    JTPrime

    Joined:
    Apr 12, 2019
    Posts:
    12
    Hello! Great asset!

    I'm having a little trouble with blending. I'm trying to create an additive hologram effect like the one pictured in section A (which is using the "Particles/Standard Unlit" Unity shader). In section B, using ASE, you can see that the geometry of the quads and alpha are blocking the arches behind them--what I don't want to happen. My ASE shader settings are listed in section C. Not sure what I need to change. Thanks for any help!

    ase_demo.png
     
  50. ArtByMashhadi

    ArtByMashhadi

    Joined:
    Apr 25, 2019
    Posts:
    2
    Hi,
    Can u guys help me on sth pls.
    Can i use Custom Outline + Toon Shader sample with HDRP??