Search Unity

[RELEASED] All In 1 Sprite Shader

Discussion in 'Assets and Asset Store' started by GeriB, Nov 12, 2019.

  1. alexandergikalo

    alexandergikalo

    Joined:
    Oct 24, 2019
    Posts:
    19
    Hi)
    Did you fix the problem?
    Installed All In 1 Sprite Shader yesterday and ran into the same problem while importing (
     
  2. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    I'm finally wrapping up the update with the new stuff, improvements and fixes.
    I will publish it this following week 100%

    If you need to fix the problem right now the fix was posted by a user some months ago:
    // OLD code
    //half3 lightResult = CombinedShapeLightShared(col, mask, i.lightingUV).rgb;

    // FIX URP 12
    SurfaceData2D surfaceData;
    InputData2D inputData;
    surfaceData.albedo = col.rgb;
    surfaceData.alpha = col.a;
    surfaceData.mask = mask;
    inputData.uv = i.uv;
    inputData.lightingUV = i.lightingUV;
    half3 lightResult = CombinedShapeLightShared(surfaceData, inputData).rgb;
    // END FIX
     
    playchocolate and valneisan like this.
  3. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    110
    First I want to say I love this asset!
    Thank you so much for making it, I use it in everything.

    Shader Effect Request - Glitter:
    I have a general shader-effect request that I haven't seen in any other shader-pack assets, but that I have been looking for/have seen others look for. I have almost never seen a "glitter"-effect in any shader-package. There are also very few tutorails on how to achieve the effect (in both 3D and 2D) (here is one that I have found however:
    ).

    Asset that exist that have glitter-effects:
    There is only one asset that has this glitter-effects that I've been able to find, but it's a narrow asset that seems to only be geared towards 3D and has only glitter/holographic-shaders (nothing else):
    https://assetstore.unity.com/packages/vfx/shaders/glam-glitter-shaders-20921

    It's beautiful. However, many of us who work in 2D and it may not work well in our scenes. The asset linked above also lacks the possibility to combine shaders (from what I can tell) like one can do with yours.

    For this reason I wanted to make a shader-effect-request in AllIn1SpriteShader that a glitter/holographic-shader-effect (white/rainbow or colored sparkles) that you can toggle on/off like the rest of the amazing effects in your pack! :) I think for many developers who are looking to make cute/pretty artstyles or just add sparkles to a scene (like to moving water), it could be very powerful.

    Again, thanks for your amazing work! Just wanted to make this suggesstion.
    Hope your day is awesome :)


    //Hulda
     
    Last edited: Jan 16, 2022
  4. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Hi, thanks for the suggestion and kind words :D

    Unfrotunately this effect, as shown in the tutorial you sent me relies on the view angle and mesh normals. Since the asset is really targeted for sprites and UI the normals are always pointing to the camera in the same way making for very little interesting variation.

    That being said you may be able to do something similar playing around with the Texture Overlay effect (by adding a glitter texture on top). Or even better by using the Sprite Mask method and you can add a fancy glitter effect with as many effects as you want on top. There are a few Demo effects using Sprite Mask. You can know which ones they are by looking at the tag below the effect name.

    Hope this helps!
     
    HuldaGnodima likes this.
  5. Gamingbir

    Gamingbir

    Joined:
    Apr 1, 2014
    Posts:
    195
    Hi was wondering the VFX tool that you have is for making VFX right? So you can sell that VFX you make with that tool or not?
     
  6. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    No, only I can sell effects made with All In 1 Vfx Toolkit since I own the custom shader and custom material inspectors they run on.
    If you distribute in some way an effect made with the asset you are giving away my code without my permission.

    The tool shall be used to create effects and to greatly accelerate the vfx workflow in production projects. In no way the tool should be used to create effects for third parties.
     
  7. Gamingbir

    Gamingbir

    Joined:
    Apr 1, 2014
    Posts:
    195
    Thanks for clearing that part was confused about it. I thought it was a tool inside unity to create your own VFX and all that like Krita for drawing for example.
     
    GeriB likes this.
  8. dikar771

    dikar771

    Joined:
    Oct 30, 2015
    Posts:
    19
    After update to version 2021.2+ all normal maps rendering goes wrong. I figured out that it is because sprites with AllIn1Shader renders by overlay camera. This looks like a bug, cause it worked fine before update
     
    Last edited: Feb 10, 2022
  9. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Hi. Thanks for the heads up.
    I'd like to know the details, as far as I see it works on my 2021.2 version demo. I understand that you are using the 2D Renderer in a Unity version that is newer that 2021.2 right? If you aren't using the URP 2D Renderer in Unity version 2021.2 or newer then you need to stick to the other Unity package.
    Where are you using the normal map and how? Does it never work or just when some effects are enabled.
    If you can send me some screenshots, more info and even the sprites you are using so that I can try reproducing it myself it would be appreciated: seasidegamestudios@gmail.com
     
  10. alexandergikalo

    alexandergikalo

    Joined:
    Oct 24, 2019
    Posts:
    19
    Thanks for a great product!
    Do you know a way to apply a shader to a child child object with text? Now I made a cool shader animation, but it does not affect the text on the sprite ((((
     
  11. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Hi, thanks!
    I don't really know what you mean. The asset shader is meant to be used on sprites and UI images mostly (although it will work on Mesh Renderers, Sprite Shapes, Trails, Lines, Particle Systems...). Text materials are really out of the scope of the asset. It can somewhat work in some cases but it's really not the intended use case.

    Have you seen the Apply Material to Children button in the asset component?

    If this didn't help you much please send more details and a screen capture to the support email: seasidegamestudios@gmail.com
     
  12. alexandergikalo

    alexandergikalo

    Joined:
    Oct 24, 2019
    Posts:
    19
    Yes, that's how it is.
    We'll have to make sprites with text. Thank you)
     
    GeriB likes this.
  13. khrysller

    khrysller

    Joined:
    Mar 14, 2019
    Posts:
    125
    Hello, Thanks for the Asset, pretty amazing. I am on the case using an Image component and I want to animate an effect. O have DOTween and I am using it for really basic stuff. I tried to search for a method to animate an effect, for example Shine from 0 to 1, but I couldn`t find a way to achieve that. Is it possible to share an code example for a case like this? Thanks again and have a great day.
     
    GeriB likes this.
  14. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Thank you for the support :)

    Of course it is possible the first thing to learn how to use DoTween is read the Documentation:
    http://dotween.demigiant.com/documentation.php
    There you'll see the Material tweens

    You can animate the Shine Effect using the DOFloat method.
    So: material.DoFloat(1f, "_ShineLocation", duration); //1f is the target value of _ShineLocation
    You could even make it go back and forth infinitely like this: material.DoFloat(1f, "_ShineLocation", duration).SetLoops(-1, LoopType.Yoyo);

    Keep in mind that you may need a script that duplicates the material on Start if you are planning to use this on UI. See How To Animate Effects section of the asset Documentation for more info.
     
    unity_1eligolan and khrysller like this.
  15. kurismakku

    kurismakku

    Joined:
    Sep 18, 2013
    Posts:
    66
    Hi there, we have one problem, in the editor, everything works fine, but in Windows build, the blur looks very strange.

    We set the material during runtime, with this code: instance.GetComponent<SpriteRenderer>().material = materialBlur;

    Also in case it matters, the texture belongs to a sprite atlas.

    upload_2022-3-5_14-31-0.png
    upload_2022-3-5_14-31-52.png

    Any suggestion on how to fix this? Thanks!
     
  16. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Probably you are using Unity Sprite Atlas system. In the editor, by default, Unity won't use the atlased sprite and will use the original asset reference that isn't atlased. You'll want to force Unity to use the Sprite Atlas also inside the editor and not only in the final build. This will allow you to tune all the Material parameters with the atlased sprite and therefore have the same results than on the final build.

    Hope this helps. And otherwise please reach out to my support email. I hate doing support through the forums. Hate the formatting and I also not get notified when I get a reply. I will always respond faster to emails.
     
  17. khrysller

    khrysller

    Joined:
    Mar 14, 2019
    Posts:
    125
    @GeriB, hello. Are you aware of a glitch on the glitch effect? It's fine in the editor, but when build on Android seems like the glitch only affect part of the image (using Image component).
     
  18. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Chances are there's something going on with the image you are applying this to. Something like using the Unity Sprite Atlas and not setting the use atlas checkbox in the editor or something like that.
    Other option is that the low precision of the shader variables on Android phones (half instead of floats) is causing a weird interaction with the effects you are using.

    If you give me more details. Unity version and pipeline mostly I can take a look. But last build I made on Android I used the Glitch effect and it looked fine to me.
     
  19. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
    I got this error message when I migrated to a new version of unity and also updated allin1spriteshader :

    Assets\AllIn1SpriteShader\Editor\AllIn1SpriteShader.cs(7,14): error CS0101: The namespace '<global namespace>' already contains a definition for 'AllIn1SpriteShader'

    Any idea what this could be? I can't find any other references to that class
     
  20. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
    I found the problem, some filenames were changed and this resulted in there being a class called AllIn1SpriteShader and also a namespace with the same name. This was because in the newer version of the asset some files were removed but after importing the updated asset those files were not removed from disk, so only the new files were added. I removed all script files myself and then re-imported the asset and everything is working now.
     
    christh likes this.
  21. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Please delete the asset and install it again. Doing a clean install before updating is always recommended.
     
    christh likes this.
  22. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    110
    Hi!

    I love your shader-asset. I just discoverd a problem however. The shaders work wonderfully in Unity, but stop working in a proper build. I've added the shaders to a resource-folder and also added them to the "graphics" "always include shaders", but they still don't work!

    How any idea how to fix this?
     
    Nlmbs likes this.
  23. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Please read the How to Enable/Disable Effects section of the documentation. You need to either make sure you include ALL the keyword combinations you'll use or just leave all effects you'll need available and use scripting to change the properties to make effects visible or invisible,
    All effects have a property that will make the effect invisible (width, amount, blend, etc... it will depend on the effect).

    If something breaks when you do a Enable/DisableKeyword it means that the build doesn't have the shader variant you are trying to use after making this change. So you either make sure this shader variant is available or you stop using Enable/DisableKeyword which is what I recommend and what I personally do.
     
    c-Row and HuldaGnodima like this.
  24. HuldaGnodima

    HuldaGnodima

    Joined:
    Oct 10, 2016
    Posts:
    110
    Thank you so much for your detailed response and for pointing towards the section in the documentation! I will try this :) suuuuuuuuch a fantastic tool for game development!

    Hope your day is awesome
     
    GeriB likes this.
  25. hunz

    hunz

    Joined:
    Oct 16, 2012
    Posts:
    29
    Hey, I'm using this shader in VR at the moment and one of eyes renders as Magenta while the other eye is fine. Does anyone know a work around for this?
     
  26. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    This is really strange. I've even personally shipped vr games myself
    Can you please detail your project settings, version, pipeline, vr rendering mode etc?
     
  27. MM-Mat

    MM-Mat

    Joined:
    Dec 11, 2015
    Posts:
    13
    Hi!

    I'm struggling with a problem with AllIn1SpriteShader, probably rather related to the editor / settings, and I wanted to ask if anyone has experienced the same or if there is a quick fix for it.

    When I open Unity and enter play mode, AllIn1SpriteShader effects look "generally wrong" - even a static (ie. the values are not changing) simple Shadow+Shine on a non-atlas sprite (with a single texture) looks like it's completely miscalculated or the keyworded parts would have never ran on it. However it looks just fine in Editor.

    Regardless of how many times I restart play mode, every AllIn1SpriteShader related material are stuck that way until I trigger something (I'm not 100% sure bit it seems the appropriate action is to open a prefab variant with materials using this shader & hit save (I don't even have to change anything). Simply opening a scene or tweaking a material are not enough.

    Then the next time I go into play mode, now every material (using the AllIn1... shader) appear to work correctly, not just the one that is used on the prefab. Like this would be the moment it realizes that the shaders are in use.

    allin1-shader-issue.png

    • I'm on Unity 2021.1.28f1 but I recall the issue was persisting at least since 2019.2.6f1 and for at least a year.
    • The project uses the built-in render pipeline.
    • Cache Server is disabled.
    • I've turned both asynchronous shader compilation & caching preprocessor off, as I thought it might be due to some "placeholder" shader or caching issue, but it seems unrelated.
    • This only happens with AllIn1SpriteShader-based stuff, not with default/built-in or other custom shaders.
    • Materials are saved under the "Material Save Path" (ie. Assets\Gfx\Materials) either in it's root or a subfolder (ie. Assets\Gfx\Materials\Misc)
    I'm pretty sure the solution is rather obvious and I'm missing something, but it's driving me crazy, so I'd really appreciate it if I could get rid of it.
     
    Last edited: Sep 26, 2022
  28. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Hello. First of all happy I caught your message early. Usually it will take some days for me to check the forums. Reaching out via support email is by far the best way of getting a fast and effective reply.

    In any case is the first time I hear what you are reporting. So there's something clearly going with the setup, most likely how the gameobject-material-scripting is happening in your project.

    Let's go over a short sanity checklist you can go through of things that could cause some funkiness (some of them you mentioned, but in any case):
    1. Sprites being inside an atlas. Unity atlases won't be taken into account in scene mode and not in playmode either (when inside the editor) unless you force Unity to do so. In general this is the first thing to look out for when things look different in the Scene view vs Ingame

    2.If you are using this in UI take into account that UI materials are always shared instances (Unity has this limitation). Meaning that unless you duplicate a UI material before changing it ingame, when you change 1 UI component material all other UI components that share the material will change too. If you look at the Scripting section of the Documentation you'll see how to avoid this.

    3.Speaking of scripting, a lot can go wrong here. And I can't obviously see your code. So in case of doubt, create a fresh new empty scene. Drop a sprite of the material you are having issues and press play, you'll see that nothing changes (unless you have some atlas and you are not taking that into account as mentioned in point 1)

    I can't really think of any other cause. So please check all of this. And see how that goes. I insist that a sprite, with no scripts and nothing else in the scene will give you 0 issues.
     
  29. MM-Mat

    MM-Mat

    Joined:
    Dec 11, 2015
    Posts:
    13
    Hi!

    Thank you for your quick reply. I specifically posted this here, assuming that the community may have experienced something similar before, so maybe more people can help.

    In the example screenshot the coat-of-arms sprites do not belong to an atlas, don't have a script to change any shader value or keyword at runtime, and has a common material instance (a .mat file for all three coat-of-arms slots, but it is intended). They cannot fight over any setting since the shader settings (active effects, their values, etc) in the material are static (in terms they are not driven by scripts or changed in any way from the outside).

    To me the same happens regardless if a texture is inside or outside an atlas. Side question: how can I force unity to take atlases into account? I am using unity sprite atlas v2 as it is available in Unity 2021, although it is still in experimental stage in this version, so it might be buggy. If you simply refer to SetAtlasUV as "force Unity", I already use it where needed.

    My best guess is that it might be somehow related to the prefabs (or variants) but I don't see how. If all materials in a scene belong to prefabs (but some of those are already instantiated on the scene in the Editor), should the shader initialize correctly? At least for cases like the coat-of-arms' material where every setting and keyword are static?

    Because in my case, it seems that basically none of the materials (associated with this shader) work correctly until I open any of the prefabs - with such a material present - in the Editor. As soon as I open any one and save it, it starts working everywhere in Play Mode, across completely different materials, with different effects and settings.
     
  30. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    You can force Unity to always use sprite atlases in play mode in Edit > Project Settings > Editor, navigate to Sprite Packer > Mode and select "Sprite Atlas V1 - Always Enabled".
    The SetAtlasUV component is a whole different story, it normalizes UVs in such a way that a sprite inside an atlas can reproduce effects as if it was a standalone sprite.

    Everything you are saying sounds wrong. And there's probably something else or something out of the ordinary in what you are doing. Please prepare a Unity Package I can take a look at and send it to me.
     
  31. Nlmbs

    Nlmbs

    Joined:
    Dec 8, 2019
    Posts:
    1
    I have the same problem
     
  32. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    I have the same reply:
    Please read the How to Enable/Disable Effects section of the documentation. You need to either make sure you include ALL the keyword combinations you'll use or just leave all effects you'll need available and use scripting to change the properties to make effects visible or invisible,
    All effects have a property that will make the effect invisible (width, amount, blend, etc... it will depend on the effect).

    If something breaks when you do a Enable/DisableKeyword it means that the build doesn't have the shader variant you are trying to use after making this change. So you either make sure this shader variant is available or you stop using Enable/DisableKeyword which is what I recommend and what I personally do.

    I'd like to add that you don't need to "Always Include" any shaders. Default graphics settings are best.
     
  33. BeardyElf

    BeardyElf

    Joined:
    Dec 16, 2019
    Posts:
    7
    Hi.I have a weird problem with this shader/material.
    Pic attached and pic1 - normal no shader etc. Pic 2 - object with shader on same sorting layer and lower order with walls, cuts walls and doors(lower sorting layer) beneath object. Pic 3 - object with shader on same sorting layer as walls but higher layer. Pic 4 - this one scene where its working like it should.
    I have no idea why its working on one scene and no others and why it cuts other objects and tiles at same layer and lower layer.
    Scenes use same prefabs, settings etc.
    And its only problem with this shader/material atleast at the moment. I have used this shader with other object before, but had no problems until now.

    pics.png
     
  34. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Hi. I don't quite follow. If you want we can chat and look into it if you send me more details to the support email. Send me a screenshot of each setup so that I can understand what's going on:
    seasidegamestudios@gmail.com

    Why don't you just do what you are doing in pic 4 if that works?

    The setup should be, use the same render queue in the materials, use the same sorting layer and just play around with order in layer
     
  35. BeardyElf

    BeardyElf

    Joined:
    Dec 16, 2019
    Posts:
    7
    Ok. Simply put:
    - I use your allin1shader to get the look I want for the sphere
    - theres only one scene(game level) in the game where it works as it should (pic4)
    - other scenes, it cuts graphics of other gameobjects and tiles if they are in same layer(pic2)
    - if the sphere is in higher layer as in top of everything(pic3), it doesn't interfere other objects but its too hig above walls
    - sphere is prefab and doesnt change in any way between scenes
    - if I use other material like sprite-unlit etc. it works fine in every scene but no effects I want
    - scenes are build same way so theres nothing I can figure whats the problem there
    - maybe its just unity doing something weird?
    - no problems before with other objects and materials with allin1spriteshader
    - EDIT: it works fine in one scene but in other scenes it breaks other objects and tiles rendering/cuts them sort of and I dont know why it happens like that

    But I can send you email later with detailed info and settings,

    LATER EDIT: figured out what helped with my problem. Had to disable Enable Z write in advanced configuration and now it doesnt cut other objects or tiles.
    So no problem any more :)
     
    Last edited: Oct 11, 2022
    GeriB likes this.
  36. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Glad you figured it out :)
     
  37. JuTekPixel

    JuTekPixel

    Joined:
    Sep 17, 2018
    Posts:
    7
    Hello I have a question,
    To change propertie value from code, I know that we can use string name of the property like this _myMaterial.SetFloat("_FishEyeUvAmount", 0), but to avoid strings I would like to use IDnumbers of properties, however it seems like a IDNumber of property does not work here. Or maybe there are no IDnumbers for this shader?
    Please Advise.
     
  38. selamalka

    selamalka

    Joined:
    Jan 25, 2022
    Posts:
    2
    Hello GeriB!

    I am trying to change to change the offset of the Fade Texture through code,

    upload_2022-11-26_16-39-55.png

    though I can't seem to find how to access the property. as you can see here there is none for the offset (that I can see).
    upload_2022-11-26_16-40-38.png

    I found out through the animator where it lies:
    upload_2022-11-26_16-42-21.png

    but again, I can't seem to find how to access it.

    I would really love some help, thank you!
     
  39. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    I already responded to your email. But in case this helps someone else. This is how this can be achieved (it's a generic Unity shader thing so it will work with any other shader too):
    https://docs.unity3d.com/ScriptReference/Material.SetTextureOffset.html
     
  40. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    @GeriB Hello. I want to use Allin1SpriteShader to simply rotate a UI image but there is no "speed" setting for continuous rotation like for the "Rotate" setting, like your Texture Scroll does. What are the chances you could/would add such a setting for Rotate too?
     
  41. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Check out the Scripting section of the Documentation. You can achieve this extremely easily without changing the asset
     
    LilGames likes this.
  42. FlyVC

    FlyVC

    Joined:
    Jan 5, 2020
    Posts:
    30
    @GeriB Thanks for this asset, the flexibility is awesome.
    However I have a performance issue where I don't really know where to start to address it.

    When I use multiple UI Elements with the sprite shader, the update(fps) on the shader itself gets very low, strangely the game fps does not drop significantly, it keeps running on 60fps on my mobile device, but the animation on the shader becomes very choppy, like 2 fps.

    Another wired thing is that I just need to activate the UI Elements once for a performance drop, disabling them does not bring back up the performace.

    Since profiling on a mobile device is very time consuming and I dont really know a lot about shaders, I wanted to ask if you had any ideas on how to tackle this problem.

    Thanks!
     
    Last edited: Mar 16, 2023
  43. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    It's not a performance issue. Otherwise the game wouldn't run at 60fps. If something is slow it will lower the framerate.

    The problem seems to be related to precision. What effects do you have enabled?

    For starters you can open the shader and replace all the "half" appearances with "float". You can do that with Ctrl+F in Visual

    Finally I think this is way easier to go through by email (seasidegamestudios@gmail.com). The format is better + I get notified immediately when a new email comes in. I don't reliably open the forums
     
  44. FlyVC

    FlyVC

    Joined:
    Jan 5, 2020
    Posts:
    30
    Thanks @GeriB

    Your tip already helped, I was using mostly distortion effects, so I was able to single the issue out to one line of code:
    Code (CSharp):
    1. line 701: half distortAmnt = (tex2D(_DistortTex, i.uvDistTex).r - 0.5) * 0.2 * _DistortAmount;
    I changed half to float and the update rate of the animation matches now the fps.
     
    GeriB likes this.
  45. jarbleswestlington_unity

    jarbleswestlington_unity

    Joined:
    Dec 6, 2017
    Posts:
    32
    Hey there, is there any way to completely switch saved materials at runtime?
     
  46. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Of course, all Unity renderers and Ui Graphics have a .material property that can be accessed. I'm sure you'll find a ton of info and examples online. It's a very common use case
     
  47. AustinDrozin

    AustinDrozin

    Joined:
    Jun 8, 2016
    Posts:
    43
    Hello! I searched for 'sliced' in the documentation, but couldn't find anything. Is there a way to use the shader on sliced UI images? The gradient specifically doesn't work default obviously, but I was wondering if there was a workaround.

    upload_2023-8-4_9-57-49.png upload_2023-8-4_9-58-19.png
     
  48. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    There's no straight forward solution for this. Shaders are "dumb". They are data crunchers. They take data and calculate the position and color of what needs to be drawn.
    The shader doesn't know if the image is Sliced or not, if the game is running or not, the platform is running on, if it's UI or Sprite etc. It just receives some texture coordinates, some properties and it calculates the color. So if you stretch it like that by slicing the texture coordinates Unity sends to the GPU are stretched, but other than that, there's no difference from the shader side of things. And there's no way of telling the shader how this stretch is made so it can account for it.

    The only ways you can get the sliced UI Image to act as a single unified texture is to:
    1. Make it a unique texture
    2. Have an extra camera, set to the exact size of the UI element, render this Image into a Render Target and then use a Raw Image to draw this Render Target
    3. Use a fancy setup where you have a camera rendering the whole UI into a Render Target and then using the asset Sprite Atlas Setup + custom logic to pass in the bounds of each UI image to it's corresponding shader.

    Easy option is 1. It will take you some extra time and extra disk space, but not much.
    2 is a bad solution.
    3 can be nice if you really want to do this a lot, but it costs some performance for the extra camera and it's not trivial to implement.

    Good luck! And in case it wasn't clear, this is a not solved problem and no other asset in the store accounts for it either.
     
  49. AustinDrozin

    AustinDrozin

    Joined:
    Jun 8, 2016
    Posts:
    43
    thanks! So by 1 you mean make a texture that is that exact shape as the border?
     
  50. GeriB

    GeriB

    Joined:
    Apr 26, 2017
    Posts:
    192
    Yes. If your texture is the exact shape you'll render you'll have no issues.
    If instead you deform a texture by slicing it, the sliced parts will share the same exact texture coordinates. Resulting in the same pixel color results across a big chunk of what's rendered on screen