Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UBER - Standard Shader Ultra

Discussion in 'Assets and Asset Store' started by tomaszek, Jun 23, 2015.

  1. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    I'm not sure if there is any official or standarized way to orient textures when doing triplanar mapping. One way can work and so the other - depends on textures and specific case. I remember doing it like this because of mirroring at seams when using my demo textures. I'll take a look at the reported issues and get back here.
     
  2. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    As for local vs. world mapping I can give you code mods guidelines to bring it to the same point with desired orientation.

    As you found it in UBER_StandardCore.cginc:

    Code (csharp):
    1.  
    2. void SetupUBER_VertexData_TriplanarWorld(half3 normalWorld, inout half4 i_tangentToWorldAndParallax0, inout half4 i_tangentToWorldAndParallax1, inout half4 i_tangentToWorldAndParallax2) {
    3.    i_tangentToWorldAndParallax0.xyz = cross(normalWorld,cross(normalWorld, float3(0,0,1))); // tangents in world space
    4.    i_tangentToWorldAndParallax0.xyz *= normalWorld.x<0 ? -1:1;
    5.    i_tangentToWorldAndParallax1.xyz = cross(normalWorld,cross(normalWorld, float3(1,0,0)));
    6.    i_tangentToWorldAndParallax1.xyz *= normalWorld.y<0 ? -1:1;
    7.    i_tangentToWorldAndParallax2.xyz = cross(normalWorld,cross(normalWorld, float3(0,1,0))).yxz;
    8.    i_tangentToWorldAndParallax2.xyz *= normalWorld.z>0 ? -1:1;
    9. }
    10.  
    11. void SetupUBER_VertexData_TriplanarLocal(half3 normalObject, inout half4 i_tangentToWorldAndParallax0, inout half4 i_tangentToWorldAndParallax1, inout half4 i_tangentToWorldAndParallax2, out float scaleX, out float scaleY, out float scaleZ) {
    12.    scaleX = length(float3(unity_ObjectToWorld[0][0], unity_ObjectToWorld[1][0], unity_ObjectToWorld[2][0]));
    13.    scaleY = length(float3(unity_ObjectToWorld[0][1], unity_ObjectToWorld[1][1], unity_ObjectToWorld[2][1]));
    14.    scaleZ = length(float3(unity_ObjectToWorld[0][2], unity_ObjectToWorld[1][2], unity_ObjectToWorld[2][2]));
    15.  
    16.    i_tangentToWorldAndParallax0.xyz = cross(normalObject, cross(normalObject, float3(0,0,1))); // tangents in obj space
    17.    i_tangentToWorldAndParallax0.xyz *= normalObject.x<0 ? -1:1;
    18.    i_tangentToWorldAndParallax1.xyz = cross(normalObject, cross(normalObject, float3(1,0,0)));
    19.    i_tangentToWorldAndParallax1.xyz *= normalObject.y<0 ? -1:1;
    20.    i_tangentToWorldAndParallax2.xyz = cross(normalObject, cross(normalObject, float3(0,1,0))).yxz;
    21.    i_tangentToWorldAndParallax2.xyz *= normalObject.z>0 ? -1:1;
    22. }
    23.  
    then at the place where tangent_flip variable was used - now it does not depend on Local/World (code is exactly the same, but I left it just in case for reference):

    Code (csharp):
    1.  
    2.        #if defined(_TRIPLANAR_WORLD_MAPPING)
    3.            float3 tangent_flip = tri_mask * ((normBlend.xyz>0) ? float3(1,1,-1) : float3(-1,-1,1));
    4.        #else
    5.            float3 tangent_flip = tri_mask * ((normBlend.xyz>0) ? float3(1,1,-1) : float3(-1,-1,1));
    6.        #endif
    7.  
    now we need to treat world TBN the same way in world, as it was not orthonormalized there

    Code (csharp):
    1.  
    2.        #if defined(_TRIPLANAR_WORLD_MAPPING)
    3.        
    4.            // TBN in world space
    5.            worldNormal=normBlend; // world normal
    6.            half3 _tangent=tri_mask.xxx*i_tangentToWorldAndParallax0.xyz + tri_mask.yyy*i_tangentToWorldAndParallax1.xyz + tri_mask.zzz*i_tangentToWorldAndParallax2.xyz;
    7.            half3 _binormal=cross(worldNormal, _tangent);
    8.            _tangent = cross(worldNormal, _binormal); // basis is orthonormalized
    9.            _TBN = half3x3(_tangent, _binormal, worldNormal);
    10.            
    11.            eyeVec = normalize(i_eyeVec);
    12.  
    notice this line being added above in basis calculation:
    Code (csharp):
    1. _tangent = cross(worldNormal, _binormal); // basis is orthonormalized
    All above tweaks brings mapping and TBN calculations to well sorted out point, still - I haven't tested all dependencies though - so use it without too much trust :).

    I'm not sure what are exactly the issues you face with triplanar tessellation, you would need to bring some example/repro scenario here. But I've got silent hope that sorting mapping with TBN might fix the other issues in triplanar world variants as it's now calculated very close to what we have in local variants.

    Tom
     
  3. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,789
    @tomaszek Excellent! That is exactly what I needed.
    Yes I guess I do agree. The mapping does entirely depend on what you are doing with the shader, and in most cases where one would use organic non-aligned textures nobody would ever notice a problem with the chosen orientation. In my case I am projecting stone/wall textures in world-space, and they have varying degrees of regularity... the more regular they are the more I require a 90 degree change in the Z mapping orientation. Because of the regularity of the textures, the edge blending is less important to me then getting projections in the expected orientation... so this is all pretty specific to this type of use-case I suppose.

    After implementing your above edits all the backward uv and height mismatches that I was experiencing before are now fixed. For this orientation I did need to make a small tweak to the tangent_flip, setting it back to the original floats:
    Code (CSharp):
    1. #if defined(_TRIPLANAR_WORLD_MAPPING)
    2.    float3 tangent_flip = tri_mask * ((normBlend.xyz>0) ? float3(1,1,1) : float3(-1,-1,-1));
    3. #else
    4.    float3 tangent_flip = tri_mask * ((normBlend.xyz>0) ? float3(1,1,1) : float3(-1,-1,-1));
    5. #endif
    This in addition to your other edits gives me proper UV/Normal/Height across all functions as seen in the below example:


    Great!

    Now in my particular case I was able to fix the x/y orientation in the Z face by making the following adjustments, first by setting the tangent_flip back to your original edit above...
    Code (CSharp):
    1. #if defined(_TRIPLANAR_WORLD_MAPPING)
    2.    float3 tangent_flip = tri_mask * ((normBlend.xyz>0) ? float3(1,1,-1) : float3(-1,-1,1));
    3. #else
    4.    float3 tangent_flip = tri_mask * ((normBlend.xyz>0) ? float3(1,1,-1) : float3(-1,-1,1));
    5. #endif
    Then manually switch the .Z uvs .xy <-->.yx, both for i_tex and lower down in the code for hVal and hVal2 (and adding a reverse initial float value to fix the uv flip in hVal):
    Code (CSharp):
    1. i_tex.xy = float2(tangent_flip.x, tri_mask.x)*posUVZ.zy + float2(tangent_flip.y, tri_mask.y)*posUVZ.xz + float2(tangent_flip.z, tri_mask.z)*posUVZ.xy;
    2. .
    3. .
    4. .
    5. .
    6. half3 hVal = float3(tex2Dlod(_ParallaxMap, (normBlend.x>0) ? float4(uvz.zy, level.xx) : float4(-uvz.z,uvz.y, level.xx)).PARALLAX_CHANNEL, tex2Dlod(_ParallaxMap, (normBlend.y>0) ? float4(uvz.xz, level.xx) : float4(-uvz.x,uvz.z, level.xx)).PARALLAX_CHANNEL, tex2Dlod(_ParallaxMap, (normBlend.z>0) ? float4(uvz.xy * float2(-1,1), level.xx) : float4(uvz.x,uvz.y, level.xx)).PARALLAX_CHANNEL);
    7. #if defined(_TWO_LAYERS)
    8.     float3 uvz2 = posUVZ.xyz*_DetailAlbedoMap_ST.xxx;
    9.     #if defined(_PARALLAXMAP_2MAPS)
    10.         half3 hVal2 = float3(tex2Dlod(_ParallaxMap2, (normBlend.x>0) ? float4(uvz2.zy, level.xx) : float4(-uvz2.z,uvz2.y, level.xx)).PARALLAX_CHANNEL, tex2Dlod(_ParallaxMap2, (normBlend.y>0) ? float4(uvz2.xz, level.xx) : float4(-uvz2.x,uvz2.z, level.xx)).PARALLAX_CHANNEL, tex2Dlod(_ParallaxMap2, (normBlend.z>0) ? float4(uvz.xy * float2(-1,1), level.xx) : float4(uvz2.x,uvz2.y, level.xx)).PARALLAX_CHANNEL);
    11.     #else
    12.         half3 hVal2 = float3(tex2Dlod(_ParallaxMap2, (normBlend.x>0) ? float4(uvz2.zy, level.xx) : float4(-uvz2.z,uvz2.y, level.xx)).PARALLAX_CHANNEL_2ND_LAYER, tex2Dlod(_ParallaxMap2, (normBlend.y>0) ? float4(uvz2.xz, level.xx) : float4(-uvz2.x,uvz2.z, level.xx)).PARALLAX_CHANNEL_2ND_LAYER, tex2Dlod(_ParallaxMap2, (normBlend.z>0) ? float4(uvz.xy * float2(-1,1), level.xx) : float4(uvz2.x,uvz2.y, level.xx)).PARALLAX_CHANNEL_2ND_LAYER);
    13.     #endif
    14.     hVal = lerp( hVal2, hVal, __VERTEX_COLOR_CHANNEL_LAYER);
    15. #endif
    Which gives me exactly the results I am looking for:


    ...so all is well. A big thank you for your help on this!
     
    tomaszek likes this.
  4. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    I'm happy there are still people using UBER (regardles of how much effort Unity puts into invalidating built-in RPs and making shader coders lifes hard with SRPs).
     
    hopeful, sjm-tech and chingwa like this.
  5. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    after a very long time and since i can not use hdrp i wanted to use uber shader. i imported everything but even in the example scene there are a lot of broken effects all alpha /extrusion materials do not work and i get
    Code (CSharp):
    1. Could not create a custom UI for the shader 'UBER - Specular Setup/ POM Distance Map'. The shader has the following: 'CustomEditor = UBER_StandardShaderGUI'. Does the custom editor specified include its namespace? And does the class either derive from ShaderGUI or MaterialEditor?
    2. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    so all materials are not adjustabel.

    unity 2019.4.5f1
     
  6. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    Can't reproduce. Maybe some other 3rd party scripts makes it unable to compile or downloaded version isn't right (sometimes AssetStore gets something wrong from package cache - you can clear it before reimporting). Make sure _verinfo.txt points newest version which is 1.2h

    UBER_1.2h_2019.5.4f1.jpg
     
  7. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    documentation is not up anymore? how is it that the same shader in one scene has all its propertys for translucence in the shader and in an other just the dropdown with those presets?
     
  8. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    I'm not sure the situation you're describing, but I believe you hit the fact UBER just attempts to be "smart" and hides translucency properties in scene where it finds we render using deferred (looking for main cam props and taking its actual render path). It sometimes could be pure wrong as one can use 2 cameras in the same scene. Anyway - shader will behave like it should, but when in deferred UBER tries to hide properties that are not actually used. In deferred we can't control translucency per material, instead - we can select preset used from list. And preset itself has to be configured using deferred translucency script attached to cam (that renders in deferred). If you know you're gona display material in forward - set camera to forward and then you can tweak all translucency params per material.
     
    hopeful likes this.
  9. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    thanks close ground and crab with uber
     
  10. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,665
    I don't know if this is just the internet hiccuping or not, but I can't access the UBER.pdf at the website.
     
  11. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    Doing some maintenance, I'll bring it back ASAP.
     
    hopeful likes this.
  12. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    May I ask for some references to shipped or under production game projects using UBER? I'd like to include some references on my new website.

    ATB, Tom
     
  13. Hotsun

    Hotsun

    Joined:
    Aug 11, 2010
    Posts:
    122
    Nice.
    We are working on Self Portrait for PC.
    This is our first trailer released in 2016.



    The game now looks so much better but we can't release a new trailer for a few months.
    We used UBER a lot.
    I can send info and screenshots by email if it is needed for the website.
     
    tomaszek likes this.
  14. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    yes, please send tomaszek@stobierski.pl
    What's the state of the project is it on early access at least (so that people can download and play some demo?).
     
    Hotsun likes this.
  15. NOSALIS

    NOSALIS

    Joined:
    Feb 3, 2020
    Posts:
    7
    Do you mind posting the code for this? I'm a C# noob who is facing a similar issue.
     
  16. DeidreReay

    DeidreReay

    Joined:
    Oct 28, 2019
    Posts:
    49
    Am I missing something here?? Is there a fade shader that actually takes shadows? Been banging my head against the wall trying to find something (its basically for some really short hair on character Sides of head Fade looks perfect but need to receive shadows still)
     
  17. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    Lack of shadow on transparent object is related to how built-in render pipeline solves shadows (at least direcitonal). It goes thru fullscreen shadowmask that is applied to objects that write to depth buffer. As transparent objects can't do it effectively - it's missing. There are ways to "hack" it but require ingerention in renderering itself while UBER just a shader that extends standard shader still relying on Unity rendering capabilities.
     
  18. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    946
    The HDRP does transparent shadow casters, though I'm not sure that goes for 'fade' transparency. Or receiving.
     
  19. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    Transparent shadow casters were already there in standard shader since Unity 5 (using dissolve 4x4 mask - so makes sense only for soft shadows). Receiving shadows is separate thing. Technicaly there is nothing "wrong" in sampling shadowmaps in any shader pass. You give Unity macro world position and get shadow state. Directional lights shadow receiving was managed using full screen blits to save performance. Unity handles global texture named shadowmap but it has different meaing after shadow casters pass (it's regular shadowmap) and after screenspace shadow receiver (it's then 2d shadowmask). To overcome the problem you would need to plug command buffer after shadow caster pass for directional light, copy shadowmap to separate texture and then sample it manually in any object (your transparent). It's hacky way to do it though. SRPs makes it easier (no need to unnecessary shadowmap copy). This way or another - it's gives some fuss to overcome. BTW - I'm thinking about exposing custom shadows solution on UAS in some predictible future (like months) that should resolve most shadow problems developers run into.
     
  20. KitChristopher

    KitChristopher

    Joined:
    Mar 4, 2019
    Posts:
    6
    Hi Tom,

    I saw this question asked, but it was several years ago, so I was wondering if your latest iteration of UBER works with web gl more smoothly now?

    Thanks!
     
  21. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    Hard to say what should we expect. UBER is supposed to get compiled into workable GL code. "Smoothly" - you mean performance wise or w/o problems of unexpected behaviour? With past years Unity changed shader compilers backends a lot. So - resultant GL code can be produced quite different now comparing to Unity5, U2017 or U2018. As for performance - it's mostly hardware dependent. You would simply need to check it yourself against requested goals for WebGL target.
     
  22. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Why dont you bring uber to hdrp?
     
  23. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    946
    HDRP default shader has most of these features with better implementations. Their triplanar mapping is awesome.
     
    Endi24 likes this.
  24. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    515
    Well do to updates and keeping it at built in. Im going to have to switch to amplify. This was always the first asset I brought into evey project I started and its sad to leave but this is the only asset that has stopped me from upgrading
     
  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,027
    @tomaszek Is there any way to keep the dynamic snow mapping fixed so that if a dynamic object changes orientation that the snow doesn't remap to the top?
     
  26. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    You mean to stick dynamic snow to the side of an dynamic object and keep "snow cap position" when rotate the object? For dynamic snow it won't work because dynamic snow is meant to cover objects from the top as result of snow fall. If dynamic snow covers part of object it's not tracked "physically". Such dynamic case you would need to do with 2nd layer or detail masking like RDR2 does on clothes of characters.
     
  27. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,027
    OK, thanks for the information.
     
  28. ght1875

    ght1875

    Joined:
    Jul 29, 2016
    Posts:
    32
    Does it work in VR?
     
    slimshader likes this.
  29. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    713
    Hi @tomaszek ! When we moved our project from Unity 2017 to 2020 LTS we lost all UBER custom editors and we are having rendering issues with Specular Two Layers Refraction where our windows are not transparent anymore, just 100% reflective.

    The error I get for the GUI is: Could not create a custom editor UI for shader UBER (...) The Shader has the following "CustomEditor = UBER_StandardShaderGUI". Does the custom editor specified include its namespace?

    This is weird. I tried moving the GUI class to public and to no namespace. Have you ever encountered that issue? Do you know any solution to it?
     
  30. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    Moving from different Unity version "as it is" may require to reinstall UBER using newest version availble. I just imported UBER 1.2h into Unity2021 and it works fine.
     
  31. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    713
    I did that earlier, but after simply deleting Library and reimporting the whole thing from version control it works fine. Thanks for responding after all these years ;) Cheers!
     
    hopeful likes this.
  32. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    187
    Hey, shaders look amazing, 2 questions tho:

    1) is there WebGL demo (web player demo does not work)?
    2) does it support single-ass stere rendering?
     
  33. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    I use this asset in my project :)
     
    hopeful likes this.
  34. mashar80

    mashar80

    Joined:
    Oct 2, 2017
    Posts:
    6
    Hi tomaszek,
    Any possibility of this being used in URP projects, any possibility do let me know.
    Regards