#archived-shaders
1 messages Β· Page 79 of 1
(I'm using the debugger outside of play mode)
oh wow
as I mouse over different parts of the inspector, the object is flashing
And this is with an SRP Batch draw call selected?
Yep
Also, with the game running, it's fine
even if I do not write to the matrices
uninitialized memory is part of a complete breakfast
(unity 2023.2.20f1, HDRP version 16.0.6, ARM macbook)
Yeah, I would only trust an external tool like RenderDoc to show the real values.
(it's using row 0 of the transform matrix for the fragment color)
so here, it's actually correct most of the time
it should be red
I've managed to do render debugging through XCode
although...unity doesn't come back to life after a frame capture
so it's a bit awkward
(i used this to discover I was doing billions and billions of flops in the fragment stage)
too much simplex noise, oops
and yeah, it sounds like unity thinks it's sending the correct values π
It only happens when inspecting the object itself. If I inspect something else, it's fine
something funny is going on over here
...is it getting batched alongside the preview in the inspector?
if I put the inspector in Debug mode, it stops flashing. The preview at the bottom is still wrong, but it's not changing as I mouse around the inspector
sometimes it get stuck all-white after I deselect, though
very weird behavior
time to make an example project
oh yeah, it's exhibiting similar behavior in unity 6
so that's something i've been looking into a bit..
I think that's where you use a structured buffer?
but I am also interested in learning about this (:
Your options are either arrays, which are fixed size and can't be larger than 1023, or graphics buffers. If you're using Shader Graph, I don't think you can define arrays, except maybe in a custom HLSL node?
not using the shader graph
Both act like arrays rather than lists. That is you can't resize them after they are created.
Arrays are as simple as:
float4 _MyArray[12];
and then Material.SetVectorArray. They can't be defined as properties or be serialized.
Buffers have to be created and disposed of by you, either using ComputeBuffer or GraphicsBuffer. The latter is more recent and the recommended option. In most cases, both are accepted in various shader APIs, except in some cases where only GraphicsBuffer is accepted, like in VFX Graph.
Buffers work very similarly to textures, in that they are separate objects which can be read from by multiple shaders.
So if I want to use a GraphicsBuffer in a shader graph, I'd need to add a Custom Function node and write some HLSL?
Looks like that is still the case, yes.
i'd love to be able to just run a blob of shader graph once for every item in a buffer
but I suspect I'll need to translate this into HLSL...
Using shader graph, how do I get the object's position in screen position? The screen position node is not what I'm looking for, since I want to keep the object's origin in place.
desired effect:
Try this
If your on older versions that don't have Screen in transform node, see https://www.cyanilux.com/faq/#sg-stabilised-screenpos
@regal stag I think that worked, thanks! Didn't know about the swizzle node either
Is setting a keyword (that I've already looked up by name and stored in a variable) every frame a problem?
it's easy enough to add some extra code to check if I've already set the keyword to the desired state
but it'd be nice to not have that extra clutter
I was trying to figure out how to setup my shader to include normals
I found something that is called normal from texture and was wondering if that is it
this is what I have so far
If you're referring to ShaderGraph's Normal From Texture node, that takes a heightmap as an input
If you have a normal map, sample with the regular Sample Texture 2D but set mode dropdown on it to Normal
ah ok
Then in this case, use Transform to convert from Tangent to World space too. Replace any Normal Vector nodes with that result.
I have custom passes that create an outline for objects, however it does so for all objects on this layer. My issue, is that I want only specific objects to "enable" this custom pass once x happens, I have a way of detecting when it should do the custom pass however I am very new to rendering as a whole and don't really know a workaround for making the pass enabled only after this "detection". Any ideas?
HDRP ^
Hey I had a question on how to add this into the main piece of the shader. I am pretty new to shaders sorry
atm I am trying to connect my models texture and normal into the actual shader
My other message above answers that #archived-shaders message
I wannna learn about shaders
ah ok so I used the transform to convert the tangent to world as type normal but how do I add that to the texture?
when I do it, it changes the colors to green and blue as if it's reading the normal as a texture
I used a mutliply to join the texture with the normal map
for my texture I used a Multiple that had a remap and a sampletexture 2d connected to the multiple
do I attatch to the vertex? it has a object space that leads to a normal
You don't want to multiply. Replace the Normal Vector node you have at the start of the chain with the output of the Transform node
Hey I am looking for some pointers on how to accomplish an effect for this skybox shader I am making.
I want to have a blur/haze around visible geometry. I can think of a way to accomplish this effect, but I don't think it's performance friendly at all. It involves using a render texture with a secondary camera, rendering only visible geometry in the depth buffer, masking it all as white, and then applying a gaussian blur. Is there a better way to accomplish this effect? Thanks
To give a simple example of what I am trying to do:
Imagine the red circle and cube are geometry, and the black is just a blank skybox
I want the skybox shader to recognize the geometry and draw a haze around it, kind of like this:
Any help is appreciated β€οΈ
So I'm using a billboard shader. The bottom is a unity cube, the top is a cube I made in blender. Any idea why the blender one is tilting down instead of toward the viewer?
does anyone know how I can make all the non black areas white?
Step node, input the texture as "in", and set edge to something like 0.00001
is it possible to look into shader graph of urp/lit?
No because the URP/Lit shader is written in code, not graphs
https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader
If you're trying to replicate it, the Lit graph does the same kind of shading you mostly just need to provide it the textures & sample them
sure let me try it
My shader sometimes works sometimes doesn't. How can I fix this.
The blue color mostly makes me think the shader is still compiling
whats the best way of debugging a render texture in the unity frame debugger?
i only seem to be able to debug things rendered directly to the screen
hey can anyone help me add a hue shift to my avatar that i have for vrchat im still pretty new to unity and editing stuff so id appreciate it alot
I can help if it's a node based shader (shader graph, amplify) or pure c# code. But can't help with HLSL.
the problem is that hte bottom bit is not getting rendered with an outline and the outline is flipped for just that
it's only affecting the last material
how can I make it that it affects all materials
It loops through the submeshes again. Add a fourth material to re-render the second submesh
nope doesn't seem to
Btw I'm Using HDRP
what do I do in blender?
It's in one mesh
Maybe it works differently in HDRP. Could always duplicate the object instead
wouldnt it still just do the first one again
thats normal for the shader
how owuld I use multiple shader passes though
how would I implement it to the material
I didn't download and drag'n'drop them
I made sure to understand. It's just that I never added them to a material before I just made materials out of them
So what do I need to do to attach it to the default shader
also it's the hdrp unlit which I'm using
not default
here's my shader graph
also the error you saw is from adding the outline material
cause the shader isn't being acted on the specific material it's just a general shader as it's own material
someone know why?
@rustic cove What pipeline are you using?
URP
Extra material slots don't "act on" the other materials, they just render the mesh again with a different shader
So how would I be able to render all the matetials
Would I need to get reference to another material and put the outline on it
I was doing some research and someone gets over this probelm by doing a command buffer draw renderer. Any idea what that means?
What I need is to get the material values and add the shader into it. Else I'll have to separate everything my material and use the version I currently am doing
Not really
You should first study how outline effects work and how they are implemented rather than trying to fix problems on vague assumptions
The technique you've used so far works by rendering the mesh again with a black color, bigger and with inverted normals
It doesn't require any data from the other shader before it
There are many reasons why it might not work, the most common reasons are a missing a step in the guide, and having a mesh with an odd scale or normals so the effect can't appear correctly
I'd like to use a shader to display a black rectangle that always covers two empty gameobjects, but I'm not sure where to start
any ideas?
I currently have a plane that's rigged to follow those two game objects, and I'm trying to apply a billboard shader to it, but it's not working out.
I made a shader in hdrp before and i switched my project to hdrp, the shader was made with the dissolve shader. It doesnt work in urp, any fixes?
I did some testing and research and it is that the this type of shader only renders on one material. So I'm either going to have to make a shader that embeds itself into the material or separate the models by material
So apparently the reverse Hull method I used has a problem cause there should be another one which can render multiple materials ill do some more research but I also would like some guidance into how I can get the material values. I know I can get base model and texture but to make every variable matter from the hdrp settings it would take long
Hey guyssss
I am making a grass shader and I wanted to get the color based on the color map of the whole thing.
But I have no idea how :P
got any ideas?
This is the map btw
You could use world position x and z input as the uv input for that texture. Could be tricky though to allign it correctly in scene. This will basically pre map your texture in world space and the grass color would depend on where it is. You probably also need to know how large the map is in units to get accurate scaling in the shader.
https://www.stevestreeting.com/2019/02/22/enemy-health-bars-in-1-draw-call-in-unity/
I had a question about this blog post about batching HP enemy bars. It's a little dated, but I've been putting it in my projects without a problem. My question is about these function calls:
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float, _Fill)
UNITY_INSTANCING_BUFFER_END(Props)```
They're used for instancing the HP bars, but are these calls redundant now that you can just select GPU instancing on the material from the editor?
Recently I needed to do something pretty common in many top-down games: render a whole bunch of health bars for enemies on the screen. Something like this:
Obviously, I want to do this as efficiently as possible, preferably all in a single draw call. As I always do before I start something, I did a quick search online of what other people are do...
GPU instancing in general seems hard to gauge as the batching still seems to show larger numbers than if they were static batched.
No, those macros are what make the shader compatible with GPU instancing.
Note that if you're using the SRP Batcher, it will never use GPU instancing to batch draw calls. So, only manual instanced draw calls from scripts will work.
By SRP Batcher you mean the static batching, right? I know that if you enable static batching, it disables GPU instancing from that gameobject renderer.
So you're telling me I can do both if I do it like this?
And, if I weren't using static batching, is there any difference between enabling GPU instancing from the material vs using these shader macros?
Yeah, it's interesting but with GPU instancing you still get a large batch count on the statistics, but there is a noticable difference with it on and off.
maybe it's time to ditch SpriteRender's dynamic batching and make it all GPU instanced.
Hey all, so i'm working with unlit shader graph in URP and making a toon shader, is there a way for me to make these objects receive shadows? For example, I'd like the plane here to receive object shadows:
trying to achieve a style like this with the shadows, but i'm not sure how to approach it as a shader graph/ coding newb
https://www.youtube.com/watch?v=GQyCPaThQnA
This may be helpful, but there's some he does outside of the ShaderGraph too
βοΈ Tested in 2020.3 & 2021.1
Do you have a material that doesn't look quite right in Unity's URP lit shader graph? Or would you like to experiment with stylized art styles with the convenience of the shader graph? In this tutorial, I show how to implement custom lighting, allowing you to solve both those problems. Afterwards, you could extend t...
Ned in general has a lot of good info on getting that light and shadow data for your shaders
Thank you! Yes, it looks like i'll have to resort to a bit of code, I'll try and get that set up. Thanks for the link! Seems really useful.
No, I mean SRP Batcher, i.e. Scriptable Render Pipeline Batcher. SRP Batcher is recommended for URP and HDRP and mostly replaces GPU instancing. If you have it on, Unity will never use GPU instancing automatically.
Right, but if the object moves throughout the scene, you would use GPU instancing over the SRP static batching, or is there something I'm not aware of here.
SRP Batcher has nothing to do with static batching.
So I guess the idea here is if you're rendering a lot of a similar object with the same material, GPU instancing may still be suggested, but otherwise leave GPU instancing off? And, Static batching is something that's done additionally after to further reduce drawcallls?
There's a lot more to this than I thought.
You may not be using SRP Batcher. If you're using the built-in render pipeline, SRP Batcher is not an option. And on URP and HDRP, it's optional. I can't remember if it's enabled by default.
I mostly code URP, and I do notice that option on the render's profile.
HDRP I don't think it's on by default though
If you choose to use SRP Batcher, then that changes drastically how you manage batching. In the built-in batcher, you have to minimize unique materials, and a good way to do that is by using GPU instancing.
With SRP Batcher, you need to minimize unique shader variants, but you're encouraged to have many material instances. That's why Unity implement the material variant system, to encourage that workflow further.
MaterialPropertyBlocks are very useful in the built-in batcher, but actually break batching with SRP Batcher, so they should never be used.
"If you choose to use SRP Batcher, then that changes drastically how you manage batching. In the built-in batcher, you have to minimize unique materials, and a good way to do that is by using GPU instancing."
I was reading about that earlier from the devs on the forums. Didn't really explain much and basically said don't worry too much about it and it's just an artifact from built-in on the topic of SRP
I guess at this point I should just start profiling a bunch of settings with different combinations cause there's a lot more going on than I previously thought.
GPU instancing is still a powerful feature, but SRP Batcher is much more convenient and I think faster in scene with more diverse meshes. If you have a specific feature where the same exact mesh needs to be rendered many times, then you can see benefits by using GPU instancing. There's a section in the documentation which describes how to do that with SRP Batcher.
https://docs.unity3d.com/Manual/SRPBatcher.html#:~:text=Intentionally removing SRP Batcher compatibility for GameObjects
oh yeah, I found an article that explains why this is necessary
and you're right! you can transpose and switch the operands
you wind up with transpose(vec) * tranpose(transpose(inverse(matrix)), which is just transpose(vec) * inverse(matrix)
the transform matrix is inverted and transposed to flip its scaling without touching its rotation
i can feel the matrix math flowing back into my brain meat
(i had a great handle on this...back in 2016)
I have tried so many ways to fix this but I couldn't
(The objects are not casting any shadows)
this could be a problem with your renderers, your shaders, your lights...
check that you have a directional light and that it's set to cast shadows
#archived-lighting if you're not using custom shaders for these and if in that case your shadows do work with default shaders
I'm trying to change my shader so that it takes in a grey scale texture to use for shading, but instead of just multiplying the grey by the color it uses the values of the grey to shade by color intensity instead. However, I'm having issues with a mask oriented approach as it is too hard to get an accurate enough result with the blurry shading. Does anyone have any ideas?
I don't understand how that's different from just multiplying the colors
will try
Yo I just bought the 20$ version of the unity bundle and trying to use the shaders from the bundle. While using the outline shader I want to be able to change the values on the shader for per object. I want to kinda "turn it on and off" when hovered. I can't seem to find a way to do it online
color intensity is like raising a color to an exponent
hello ppl
so, I am making a grass shader where I am trying to make the color of my grass based on the basemap of the terrain
Since not everyone uses unity's terrain tool, I decided to allow an map and I have a simple texture.
From what I have learned up until now is that I should somehow get the position of the grass object and map it onto the basemap.
This is my shader up until now:
help wud be greatly appreciated
I am having a very, very bizarre issue
using a custom shadergraph in Built In, I only get shadows to cast and be visible from one direction of the camera
for some reason the other direction doesnt get shadows
I switch from my custom shadegraph to the basic specular setup and you can see how the shadows cast properly there
another example
I have absolutely no idea why this might be happening
my custom shader is a very basic PBR Setup shader
which uses this very basic node
I dont think there is anything blatantly wrong with this last one
Its just splitting some textures for a classic PBR setup, ported for built in
if anyone has a clue of why this is happening it would be incredible helpful, I have been trying to fix this for a while and have no idea whats going on
Alright found some oddity. I've got some TextMeshPro mesh rendering some text within a collection of sprites using a Sorting Group.
I would like to do some masking on the Text.
With the Sprites I use a Sprite Mask, but the TextMeshPro mesh doesn't seem to have a masking option.
I did however find this 3 year old tweet saying you can.
https://x.com/OndraPaska/status/1407348952446476304
And it works.
So my question is.
- Fucking why does this work?
- Is there a better way to do masking with text meshes?
- This solution changes the material itself, it would be nice if I could change this property on an object by object basis. Any suggestions?
so, here https://youtu.be/Ic_3p90NdxM?si=fexdS3q79Kxtqs4Y&t=673 it shows custom waterline shader, but i cant find any examples anywhere
Letβs dive into the High Definition Render Pipeline (HDRP) water system! See the steps/workflows for creating realistic bodies of water in your Unity scenes.
The water system allows you to add high-quality oceans, rivers, pools, and lakes to your HDRP environments.
In this video, weβll cover the basics of setting up a water surface from scra...
i guess its just using getcameraheightfromwater to blur the line here?
how to make this shader get affected by shadow
( it's applied on the capsule )
Unlit shader, iirc, cant receive shadow.
I think it would be easier to modify the lighting function of a simple lit shader so it can have flat shading, than making shadow works with unlit shader
yes, theres a sample somewhere
yup, found it
You need custom functions to receive shadows. But I've got a package with some subgraphs that can handle it for you here (in particular the Main Light Shadows one)
https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
- It works because sprite masks use stencils. The masks are written to the stencil buffer with a value of 1. And here Stencil Comp of 3 is "Equal", so it renders when the mask and text overlaps.
- idk
- Easiest way is probably just to create two materials, a regular one and a masked one.
Hey Lazy, can ya tell me where you are at with your Sprite shader? I'm doing a Jam where I'm looking into 2.5D again, but my variation of Bgolus' billboard shader still breaks batching. I'm still not too sure about my options besides finding an alternative to Sprite Renderer.
Can I remove this layer of pitch black shadows from a lit shader graph to appear like the unlit one ?
Hi! I have a custom material that i'm applying some texture arrays in the editor. However everytime something happens it loses reference and i need to update it again. I started checking and subscribing to events that trigger that loss, like before assembly reload, after assembly reload, scene saved, undoredo performed, etcc, but every so often I encounter a new case where it loses and i need to find the new event and subscribe to it
Is there a better approach to do that? a global event, or global check to do that
set the normals to face towards the main light?
(will need to make a custom node or set through a script)
or use emission! that works too
So I have another question relating to batching a specific shader if you mind answering. I have this 2.5D shader such that I can render sprites in a way where they will not clip into geometry using some billboarding techniques. The problem I am having is that if I were to use this shader with the SpriteRender component, I have to explicitly break batching in the shader else SpriteRender will not render them correctly. I believe this is due to the nature of how SpriteRenders do their own dynamic batching.
So my idea is that I should probably forgo SpriteRenders and render it myself using quads, meaning I'll have to probably animate them in code myself by iterating over the sprite atlas. My question is, if I were to do it this way, each individual player/enemy unit will need their own material for me to iterate through. In this case, SRP batching should really help minimize the drawcalls in this case, or is there more I should be aware of?
I'm expecting to render maybe hundreds of units at a time to give an idea.
Dynamic batching is ideal for sprites, so if you can find a way to keep that, I would try that. The problem you're facing is likely because the vertices of the mesh are combined with others and get transformed into world space, so you can't rely on the object position to be localized to the sprite.
SpriteRenderers have actually not really been compatible with SRP Batcher until very recently, when SRP Batcher added support in 2023.1, so the version of Unity you're using is very relevant here.
In older version, SpriteRenderer uses MaterialPropertyBlocks to set the sprite texture. This breaks SRP Batcher support, but that's usually fine because dynamic batching can be used instead.
I don't know how 2023.1+ works, other than that SpriteRenderers can be batched with SRP Batcher. A Unity developer says here that SRP Batcher should be faster than dynamic batching for dense sprite meshes (when you have the sprite's Mesh Type set to Tight) and otherwise dynamic batching is preferred.
Ah, neat about time. I just think in general that any billboarding done in the shader has in the past not worked with any sprites I worked with. Usually I would billboard via cpu side to avoid it, but this shader I am using is a bit more complicated.
Maybe I could make a bit more sense to put it CPU side, but I've also got a bunch of shadow/lighting that would not make sense be easy to implement.
I'm assuming you're using an older version than 2023.1. One thing you can do to get around the world space transformation that happens with dynamic batching is to pass in the sprite's position or transformation matrix as a material property. SpriteRenderer is already using a MaterialPropertyBlock, you can just add one more property to that.
That way, you can calculate the true local vertex positions, which I'm assuming you need to calculate your billboarded position.
Alright let me check about that, but otherwise on the discussion of having multiple materials (100+), that shouldn't be too much of a problem for the batcher?
if I need to fallback onto it because I will animate everything in code lol
If you're using a version older than 2023.1, which you still haven't confirmed yet, then SpriteRenderers are not using SRP Batcher. So then you have to treat it the way you would treat batching in the built-in render pipeline, which is to reduce the number of materials.
Oh, I wasn't going to use SpriteRenders, just a texture array for each Unit that I iterate through
and instead use quads which I'll iterate over on update
I'll have an exposed field for the material for the texture atlas so each enemy will update using that.
The SRP Batcher will handle that many materials. But it will still take some time to create them initially and you have to ensure you destroy them afterwards, because otherwise they will stay in memory until you load into a new scene.
Object pooling the materials is probably fine, and I'll take your word for it if it comes to that. TY for your time ^^
void InitalizeSurfaceData(Varyings IN, out SurfaceData surfaceData)
{
surfaceData = (SurfaceData)0; // avoids "not completely initalized" errors
half4 baseMap = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, IN.uv);
#ifdef _ALPHATEST_ON
// Alpha Clipping
clip(baseMap.a - _Cutoff);
#endif
half4 diffuse = baseMap * _BaseColor * IN.color;
...
}```
clip doesn't seem to be working for me in 2023.2.20f1, and this shader was working in most 2021 version and 2022 versions
Not too sure if that's the exact issue as I am quite a little rusty with this stuff. I just know that sprite shaders in SRP using HLSL is a pain in the butt.
Ended up going with opaque alpha clipped.
Yeah but whatcha doing with billboarding
In my case I knew my camera would always look down at 45 degrees. So I just scaled my units by 1.42 along the Y to "undo" the visual shrinking cause by the angle. They're actually still upright. This made it so I didn't have any issue with the sprites clipping into walls behind them.
I had found some other 2.5D games that did this as well. It seems to be a solid solution if you know your camera angle will be mostly static.
Ah, ahah. Yeah, sometimes the simplest solutions are just what you need
I could probably do that but the only issue I have (beyond clipping not working right now for some reason) is batching
When I tried out my custom lighting I broke batching on transparent, but before I figured out how to fix it I decided to swap over to alpha clipped opaques, and that just instantly fixed it.
How many dudes do you even have? Even though the rendering was really inefficient with transparent, I was still getting solid FPS with 100 units.
It was only with 200+ that stuff started to go bad.
if you make your dudes transparent, that's less fun particles and shaders you can have on the geometry
in 2D it doesnt matter too much because sorting order fixes a lot of those issues
Yep. The worry I had was that my dudes were composed of multiple sprites, and with so many of them moving everywhere, layering would break without a sorting group.
But I sort of underestimated how close you could shove planes together.
You can have them separated by like 0.001 units and they're fine.
To REALLY make sure I didn't get any sorting issues I have a script on my dudes that, when they're created, randomly rotates them along the Y axis between -5 and 5 degrees.
It's barely perceivable, adds a bit of visual variation to them which is nice, and makes it pretty much impossible for odd layering.
the precision on the z-fighting isn't absolute I've noticed and I would budge it a bit more if you expect to render these planes from afar
Ya I'm aware it's related to the range between the clipping planes.
I think the individual layers for the dudes are sitting at a separation of 0.01 at the moment.
Should be fine π
Pulled in the far clipping plane from the default 1000 to 250 to be extra sure.
How did you come to the number 1.42?
I always hear a bunch of people experimenting arbitrarily until they find a number similar to 1.4 etc when working with stuff like this
Like top down movement multiplying by 1.4
1.4 is close to the square root of 2.
Well it's trig off of 45 degrees.
Think I just quickly did the math, saw it was 1.41 and a bit of a remainder and just upped it to 1.42.
oh, huh. The #ifdef doesnt seem to work
https://i.imgur.com/4Yz6kPK.png
Shadows kinda broke now too ;(
half4 ShadowPassFragment(Varyings IN) : SV_TARGET
{
Alpha(SampleAlbedoAlpha(IN.uv, TEXTURE2D_ARGS(_MainTex, sampler_MainTex)).a, _BaseColor, _Cutoff);
return 0;
}```
I mean that seems right, right?
Anyone know of a shader I can quickly use to key things like a green screen?
you can get a very basic effect by adjusting alpha based on the color of a texture
something like this
it computes how far you are from [0,1,0], which is pure green
anything within 0.01 of that color value will wind up getting its alpha reduced
I suspect this not going to work that well, though
Don't green-screen effects usually look at larger chunks of an image to figure out what's "inside" and what's "outside"?
https://hatebin.com/howdeyzjce
Can anyone spot any error or perhaps something deprecated in this code? My console is getting spammed with 'State comes from an incompatible keyword space' and seems to get fixed if I remove the shadow entirely, but there's no actual stacktrace.
works in multiple different 2022 and 2021 versions, and now only giving me trouble with 2023.2.20f1
#ifdef just seems to be not working at all
Tried a basic shadowcaster script from unity's repo and spams me with those same errors
guess it's time for blob shadows
I'm rather new to shader graph, but does anyone know why adding a power node adds random holes sometimes in the terrain? (Its all for the fragment shader)
Hey, @steel notch. Whatcha use for your shadows to prevent the shadows from overlapping? Stencil stuff?
Try a Saturate after the gradient noise. It can sometimes return slight negative values, which power doesn't support
Oh yeah I forgot about that. Thanks a lot!
Not sure if it matters but I've seen unity use shader_feature_local instead of shader_feature_local_fragment for the _ALPHATEST_ON one.
I actually got it to work but im facing a very strange bug
No cigar. I'll probably try out some later* version in a while because everything I'm doing here (besides the billboarding logic) is pulled right from unity's own repo or libraries.
I have a quad with a video player placed on it and im keying, and it works fine EXCEPT for the first time it runs after reloading the scene:
first time reloading scene
every other time it looks like this
which is the desired look
textures load properly
but when I reload the scene this happens
anyone has any clues?
Sounds like a problem with the video player
Ah, well that did fix the batching problems. One thing I noticed is that I cannot flip x/y on the vertex anymore (or vertex color for that matter) so i guess that means I do need to introduce those frames with the atlas. Also shadows seem broken in this version, but I think I'll just stick with blobs for now.
And then finally if I can ever figure out how to completely eliminate self-shadowing
which can honestly be resolved with some tricks like rendering a silhouette I guess
https://hatebin.com/flfzhrrkfd
Shader for those interested. It's based of Bgolus' z-depth billboard shader from the forums and a month of me doing cocaine. Far from perfect but fixes clipping problems and (somewhat) helps at directional shadow intake. Also #archived-shaders message for the shadow caster which does work (not this version apparently) but does have that peter-panning / self-shadowing issue which is pretty hard to solve considering it's a quad we're rendering
Without SRP batching though you have to explicitly break the shader batching else Sprite Render's dynamic batching will just not render anything.
the image on the left has a lit shader
the image on the right has the same exact shader but unlit
so can I get the same effect of the image on the right while getting the shadow from the lit shader ? ( I want the gradient one not the pitch black )
confused as to what you are going for, you mean that you want a smoother transition from the shadow to light for the shader on the right?
I want the shadow but I want the unlit shader ( the image on the left )
Finally got a good result from shader graph:
(Note colors and pattern will be procedualy generated)
Reposting from #π»βunity-talk - How Unity handles compute shaders under the hood? I am wondering after reading this comment:
https://github.com/bevyengine/bevy/issues/5024#issuecomment-1556284646
The current implementation of wgpu only has one interal queue for submit() calls. Therefore, we still have to know where and when to put our compute submit() calls, as they will run sequentially with the render queue. I know that vulkan has a separate compute queue, and I'm hoping that one day, wgpu will too. I just don't know how feasible / mature this multi-queue system is for other backends wgpu implements.
I don't know what Unity does. I'd guess it is some combination of:
- You are scheduling lots of jobs, but the total time is only a handful of milliseconds so it finishes within a single frame (but may take a few frames to send the results back to the CPU).
- The compute work takes a few tens to hundreds of milliseconds, causing a minor frame stutter but it isn't that noticeable.
- Unity itself has some mechanism to throttle the rate of async compute jobs being sent to the GPU. I haven't used Unity, so I don't have more insight here, but it seems kind of hard because you'd presumably have to estimate how long tasks will take.
afaik unity is still mainly a dx11 engine, so it does not have multiple queues... anyone here knows better?
If you want to queue a compute shader dispatch into the async pipeline (on platforms where that is supported) you need to use a CommandBuffer and execute it with this:
https://docs.unity3d.com/ScriptReference/Graphics.ExecuteCommandBufferAsync.html
Otherwise, compute will run in the same queue as graphics calls.
As for the comments in the GitHub issue, there's some misunderstanding about how compute shaders are run. Async or not, a compute shader dispatch will always finish before the GPU finishes the current frame. You can't have a compute shader run asynchronously in the background for as long as it takes to finish, it will stall the frame if it's taking a long time.
Getting results back asynchronously is done with AsyncGPUReadback. This is not specific to compute shaders, just any time you want to read data from GPU memory back to CPU memory. Since the CPU is always one frame ahead (e.g. the CPU is working on frame 2 while the GPU is still processing the commands for frame 1), you can't read data back immediately, so you have to get it asynchronously. I don't know the exact process Unity uses to achieve this, it's different for each graphics API, but whatever it is, it usually returns the data 1-2 frames later.
I may be wrong about async compute pipeline being tied to the framebuffer swap. But the async compute pipeline can still only do one dispatch at a time, so your async compute would be hogging the pipeline over multiple frames if that is the goal.
Anyone know how to fix that shadow problem?
Shader "Custom/Leaves"
{
Properties
{
_Color1 ("Color 1", Color) = (1, 0, 0, 1)
_Color2 ("Color 2", Color) = (0, 1, 0, 1)
_RampThreshold ("Ramp Threshold", Range(0, 1)) = 0.5
_WindStrength ("Wind Strength", Range(0, 1)) = 0.1
_WindSpeed ("Wind Speed", Range(0, 10)) = 1.0
_WindFrequency ("Wind Frequency", Range(0, 10)) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert addshadow vertex:vert
struct Input
{
float3 worldNormal;
};
float4 _Color1;
float4 _Color2;
float _RampThreshold;
float _WindStrength;
float _WindSpeed;
float _WindFrequency;
void vert (inout appdata_full v)
{
// Convertir la posiciΓ³n del vΓ©rtice al espacio mundial
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
// Calcular el desplazamiento del viento usando una funciΓ³n seno
float wind = sin(worldPos.x * _WindFrequency + _Time.y * _WindSpeed) * _WindStrength;
// Limitar el desplazamiento del viento para que sea mΓ‘s sutil
wind = clamp(wind, -_WindStrength, _WindStrength);
// Aplicar el desplazamiento al vΓ©rtice
v.vertex.x += wind;
}
void surf (Input IN, inout SurfaceOutput o)
{
// Calcular la iluminaciΓ³n basada en la normal
float ndotl = dot(IN.worldNormal, _WorldSpaceLightPos0);
// Determinar el color base en funciΓ³n de la intensidad de la iluminaciΓ³n y el umbral
fixed4 color;
if (ndotl > _RampThreshold)
{
color = _Color2;
}
else
{
color = _Color1;
}
o.Albedo = color.rgb;
o.Alpha = color.a;
}
ENDCG
}
FallBack "Diffuse"
}
Okay that makes sense
But the async compute pipeline can still only do one dispatch at a time, so your async compute would be hogging the pipeline over multiple frames if that is the goal.
However, if I understand correctly this would not be the case anymore when you have multiple queues - like in vulkan's latest apis. (not in unity)
In that case, it would be possible to achieve hardware parallelization across different workloads - right?
Vulkan can't guarantee hardware capability. I don't know the state of GPUs today in this regard, but I think it's pretty common for GPUs to only have one graphics queue and one compute queue, if that. The GPU will just handle scheduling for you if you're using more queues than that in Vulkan, like how a CPU scheduler handles running virtual threads on physical cores. So in that case, you won't get parallelization and maybe even worse performance since the GPU would be constantly switching tasks and context.
gotcha π
Any task you throw to the compute pipeline or to the graphics pipeline is going to try to use 100% of the available hardware to finish that task. There's not really much compute available to run in the background.
But you can definitely have one compute task and one graphics task running side by side, as those are usually pretty separate.
π Thanks!
can I change hdr color intensity via shadergraph?
why adding another layer of texture makes the shadows all black , havent even painted the new texture yet
see i remove the new layer and my shadows work fine
Unity has this and it doesn't matter where the shader is, it always finds that cginc
How can I do something similar for my asset? So that it can always be found
I have this cginc in my package, but from a custom shader they cant be found
If it's in a package but the shader isn't, you'd want the full path to the file starting with Packages/
Mmmm this is problematic
I'm following a layout where the package is not in the packaged folder at all
It's defined in the manifest.json with the file path
(this is so I can work on the same asset from multiple projects)
Is there no way to make shaders cginc global?
Not that I'm aware of
How does unity manage to have the gcing accessibles from anywhere
The includes path is probably passed into the shader compiler as an argument
alright, note to future anyone. The name after Packages/ doesn't have to be the name of the folder or asset, but the exact name that it's on the packages manifest. Then it can be anywhere
I could use some help with some shader UV manipulation. I have a shader that is currently tiled and scaled with the object's size. I'd like to extend this to also offset this by the world position:
I thought this would be as simple as using an Add node at the end of this and adding the world position, but this just causes the UV to stretch. What am I doing wrong?
Can be a bit tricky looking this up as most searches for World Space Position UVs show triplanar solutions. That's not what I want.
Adding Position output from Object node?
Ah I was using Geometry node. Let me try object
That gives you per-vertex positions
which will indeed stretch the UVs
(or per-fragment positions)
i presume this is in the fragment stage
the further you get from the origin, the more the UV gets offset (and thus it's non-uniform)
yeah
Can Shadergraph interactwith the stencil buffer at all?
The canvas and sprite graph probably does stencils behind the scenes to support masking.
iirc URP's Fullscreen graph also has stencil values in graph settings, but the fullscreen feature doesn't actually bind a depth/stencil buffer (might be fixed in Unity 6 tho)
But for other graph types, shader graph doesn't expose any stencil values/ops. Can only use overrides on RenderObjects.
I made a shader for water but it's just white color sphere, there's no transparency or any water type view
Hmm. That's probably good enough then.
Thanks
@vagrant dagger
do not ping me, I just pointed you to the correct channel
Ohh ok, I texted there to find someone that could help me.
Nvm
iirc the Built-in RP doesn't generate an opaque texture for the Scene Color node to work. But attaching this script to the camera should handle that - https://gist.github.com/Cyanilux/181893cd061e97eb12d5bfdec9fecaab
How do you access the depth buffer of a render texture? Really struggling here π
I'm using Amplify (although I imagine shader graph will have a similar approach)
it's adding a semantic to the return value from the function
SV_Target indicates that it's going to a render target, according to the docs
I'm not sure if removing that means the shader program will completely ignore the result from the frag function
ah, yes, you'll get an error when compiling it -- complaining about a missing semantic on the return value
I can't find any other semantics that are valid for a float4 return value
well, the return type is separate
fixed4 in your case
but the shader program needs to know what to do with that value
sure, you just need to pass it in from the vertex stage
it'll get interpolated based on the vertices that make up the triangle the fragment is part of
Here's a cool skybox shader I have been working on β€οΈ
Same shader with a test cube and a different palette.
I am trying to create the outline around the player I am using spine2d but the outline of the left produces the shader around every body part, and the right is own shader which shades the whole character, I want to create the shader around the outerpart.
I have attached the shader https://pastebin.com/4YnawYgd
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Has anyone around has luck animating material parameters with radial coordinates?
I am trying to make a simple pool of blood system, I was successful animating a radial mask that grows from center outwards
but trying to animate the UV offset of a radial UV completely breaks them
which is insanely
is there something I am missing?
it seems everytime I change the offset the sampler "resets"
and samples from a compeltely different place
which causes that weird artifact where the value is being decreased but it actually looks like its speeding up
this happens with both sampled noise and sample textures
I am insanely confused by this
I can see 3 distinct layers
when viewed from the side
you might try using parallax mapping
yeah it really seems like 3 separate layers with their own normals + parallax mapping, give it a shot to that
Fixed my issue!
Hiya, I'm working on a rock shader with triplanar detail normals. But why is it when I rotate the object, the shading gets so much darker. I'm doing something wrong with the detail normal, but I'm not sure.
Ah I see. It's because I'm using a reconstruct Z node
Is it possible to reconstruct the Z value of normal and still use it as triplanar mapping?
Either parallax mapping or shell texturing https://www.youtube.com/watch?v=9dr-tRQzij4. I don't really know which one would be faster, likely depends on the required precision level and the target device
The second example is parallax occlusion mapping, or just parallax mapping
The first example is shell texturing since you can see under the "layers"
The answer to this btw was transform world space normal to tangent space normal.
Heya, is it possible to get the size (width, height) of a picture passed into a compute shader (from inside the shader)? Or is the only option to pass the values with a buffer/cparam?
If the input is Texture2D<x> or RWTexture2D<x> (as opposed to sampler2D), then you can call GetDimensions on the texture to get its dimensions.
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-texture2d-getdimensions
Thanks, seems to be working!
Always include the solution so if someone else runs into a similar issue they don't just read "fixed it".
If I wanted to write a compute shader that would calculate the amount of transparent pixels in a texture, how would I go about keeping track of the int?
Is it just a RWStructuredBuffer?
You can use atomic operations for this
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/interlockedadd
But if you want to read this value back to a script, you'll need to write it to a buffer. Perform the atomic operation directly on the buffer element.
RWStructuredBuffer<int> _TransparentPixelCount;
[numthreads(8, 8, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
...
if (pixel.a < 1)
{
InterlockedAdd(_TransparentPixelCount[0], 1);
}
}
Oh, that's exactly what I was looking for! I remember using this ages ago, but could not remember how it's called. Would this also work if I had a RWSTructuredBuffer with a struct that contains two ints?
struct CalculationResult {
uint totalPixels;
uint correctPixels;
};
RWStructuredBuffer<CalculationResult> Result;
I think it should work, yes.
InterlockedAdd(Result[0].correctPixels, 1);
It's just important that you don't try to add to a temporary local variable.
Wonderful, thank you so much π
Why is this doing this instead of just the white ares getting brighter?
Here it works (my other project)
Likely negative values in your black/white result. Try a Saturate node to clamp before adding
That seems to have done it! I feel like my overall solution is pretty bad though; I am trying to generate an emissionmap from the _MainTex. All areas that are very bright on the maintex should be even brighter with some bloom in the end: For that I did this;
it seems to somewhat work now but I am sure this is not the best solution
But thanks for your help! At least its functional now!
Are those Minimum nodes on the left with values of 1? If so, I don't think they're doing anything as the texture is likely a 0-1 value, unless it's some HDR/float format.
I think there's also a Saturation node that you could use to convert the texture to greyscale instead of the adds. But if what you've got works, that's fine. It doesn't look that bad to me.
Yeah it somewhat works: But I have a problem with the color:
here it looks fine, I basically just add the green "emission" map
But in the game its white again for some reason?
Is the colour green on the Material asset?
Oh shit im just stupid xD
I thought it would take the default i set in the shader graph
my bad
Thanks alot!
i have a shader that does vertex displacement in all axis, but im having trouble on getting the normals, would anyone happen to know the solution?
I have some methods I'm aware of listed here - https://www.cyanilux.com/tutorials/vertex-displacement/#recalculating-normals
ill give them a try, thanks
ive actually already tried one of those methods
but for some reason the normals came out like this
i cant tell where its wrong
I have a general question on exposing fields of a shader. When we are to edit these fields at runtime, they will affect all other shared instance, correct? So ideally, if I want to make some distorting shader that I lower/increase over some (controlled) time, I would want to make a unique material for each unit that I'd apply this material to. Is this correct and if so, would anyone suggest another way to go about it instead?
I would expect this to be different between SRP and built-in as well, but it seems that making a bunch of materials via SRP would be fine?
The way I've been doing dependency injection usually has a single shared material for my object pools, but this kinda makes it tricky.
Check your subtract B inputs - you should be using the displaced position, not just the displacement.
Also make sure the spaces match. Perhaps do the displacement in all in World. Then use Transform node to convert to Object before connecting to master stack.
also, a gotcha to watch out for: if you work in Absolute World, make sure to still use World when transforming directions
You don't have to create and apply materials manually, using Renderer.material to access (instead of .sharedMaterial) will generate an instance for you at runtime. But yeah, assuming the shader supports the SRP Batcher it's not too bad.
For built-in RP you'd probably use GPU Instancing & MaterialPropertyBlocks instead if it's the same mesh.
transforming a direction with Absolute World mode causes...weirdness
i guess it winds up translating the vector
Wouldn't it be fine if mode is set to Direction?
https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Transform-Node.html
If you use the Transform Node to convert coordinate spaces that aren't for position values, Unity recommends that you use the World space option. Using Absolute World on values that don't represent position might result in unexpected behavior.
I never really work with Absolute World as I don't use HDRP so aren't familiar with how SG acts with it
Yeah, that would be what I'd need to change on the object pooling, but it's unfortunate cause now I would need to divide down my objects by material types instead of having a single prefab type to inject onto.
I think it just adds/subtracts the camera position
but this winds up being bogus for non-position vectors
Hmm yeah I guess
I think Unity wants you to just use Renderer.material to automatically create instances. But what most people miss is that its your responsibility to destroy the instance afterwards, because they will pile up in memory until Resources.UnloadUnusedAssets() is called, which Unity does when you load a scene in Single mode.
(even when you're correctly in Direction/Normal mode)
Really odd it doesn't just... automatically switch to World if the mode is set
Oh, that sounds useful then. So I guess ideally I can just stick to the single prefab idea, but with some SO data that creates a new material which I would dispose when returning to the pool then, eh? Ideally when would I want to call that flushing method?
Ideally you wouldn't call it at runtime, only during loading screens, because it lags.
Ideally you would Destroy the instances instead.
Ah, ok. I getcha. Basically stick with DI and when returning to the pool just destroy the material instance.
A side note but you can't make "emission" with the base color input, since it'll just be multiplying the effect of light and still black in darkness
To get true sprite emission you'd have to use the sprite custom lit graph and lerp between the glow texture and the main texture multiplied by the light texture
Or use secondary textures to mask in certain parts of sprites with a global light that only targets that mask channel, which can be done without any shaders
Yeah right now Im only using this to somehow influence the bloom to get some sort of fake emission
Do you maybe have a resource on how to do this? Because what im doing right now with bloom feels very hacky and if I want something much brighter I need tio increase bloom intensity which makes everything bright. I dont really have much control with how I do it now
I have a shader that displaces vertices using a direction I've baked into UV1. This works great for non-skinned meshes, but it falls part for skinned meshes.
I need to figure out the direction after deformation. Any thoughts on how to do that? A few things have come to mind:
- Store the displacement in tangent space.
- Bake the original object-space normal into UV2 so that I know how the skinning rotated the vertex, and use that to rotate the displacement vector.
I was trying the latter because I thought of it first, but I am firmly bungling the math
and it's kind of icky
i'm thinking tangent space is the way to go here
If I could get the SkinnedMeshRenderer to deform my vector, that'd be nice!
ah, but computing that direction in tangent space might be difficult. i might not even have a UV map
No chance of this, the compute shader that does skinning is reading very specific attributes, position, normal and tangent
(actually, i'm not even sure where the tangent vector comes from in the first place!)
maybe i will give that second idea another crack
You can do skinning directly in the shader, if you pass in the bone matrices
Here's Unity's skinning compute shader for reference.
https://github.com/chsxf/unity-built-in-shaders/blob/2021.3/Shaders/DefaultResources/Internal-Skinning.compute
I think this knowledge might not currently exist online outside of a few offhanded mentions in the docs so I'll make an example
The goal is to be able to make a mesh with this sort of profile swell and shrink. If I push vertices out along their normals, all of the crevices wind up overlapping each other
I'm currently just projecting their original object-space positions (baked into UV1) onto a plane and then moving the vertex based on that
Works great until things start rotating!
that's not so bad...
For the matrices, you have to multiply the localToWorldMatrixes from SkinnedMeshRenderer.bones with SkinnedMeshRenderer.sharedMesh.bindPoses.
So I could write my own compute shader that does the exact same transformations as the built-in skinning shader
or I could reimplement it in my graphics shader
No need to do it in a compute shader, you can do it in the vertex shader.
do I want to do it in the shader graph, though? π
That would be really amazing! Thank you!
Shape keys?
this second idea wouldn't handle scaled bones properly
Am I blind? Where did you say shape keys?
Oh wait
Brain fart. I had originally mentioned shape keys in my OP, but removed it partway through. So I got that mixed up.
I want to be able to adjust the strength of the displacement along the entire mesh.
Shape keys can approximate this
or just scaling the bones, really!
Because that is relevant here. Unity will skin blendshapes, and blend shapes are just vertex position offsets + optional normal offsets.
that's actually what I've done previously: make a chain of bones and scale them in the XZ directinos
Since what you want is an offset that gets skinned, you can just use a blendshape for that.
This is the sort of behavior i'm looking for
I can approximate it with blendshapes, but it's chunky
using the original object-space position is working fantastically for parts of the mesh that aren't being rotated relative to the root bone (which is why I didn't notice the problem until now)
does anyone have a good explainer on the .raytracing shaders?
just a link or a sample project
(compatible with HDRP preferrably)
How can I make a shader write to an int texture?
I don't know how to transfer shaders into a texture, normally i baked them by using an ortographic camera and taking a picture, but there must be a better way
Does anyone have a clue how you would make a shader/shadergraph so that I can have my cave entrance fade to black the further back it goes? I've been trying things for 2 days now with no success (in URP).
Even the most successful version I had (which still sucked) completely broke when you entered the cube with the material on it.
Hey all! I'm trying to make a cloud shader for my 2D game, and I don't know if this is the right place to post this, but My shader graph is being weird, and I don't know how to fix it. Can anyone help ( URP )
Hello one question. I liked this simulation of water. It works on this mesh. I want to use it for a waterfall, it has a curve in which the water moves faster. I tried to edit the mesh in blender, but it causes the texture to stretch, and if I add new vertices, it doesn't render so it needs something called UV.
shader is from the garden scene by URP Sample
The issue was that I was a dumbass, the shader was working properly LOL
I misunderstood what I was doing with the offset
Animating the offset linearly would indeed result in the blood flowing with a constant speed
And stopping abruptly
Solution was to just a different animation curve
Can you use the Decal Render feature with an orthographic camera somehow?
Here we go
Probably requires at least URP 12
Oh wow thank you so much! I will check it out tomorrow! I really appreciate it!
How can i make it so the Text Underlay (aka shadow) is based on the text color (like example on the right) rather than a fixed color for every piece of text (like on the left example)?
it seems impossible
(not sure if this is the right channel, pls lmk)
@urban anchor maybe create another text that is the child of the current one that would be simplest solution
How does the Crest HDRP water system compare to Unity 6's HDRP water system? What are the tradeoffs between the two?
Hey can someone explain this layering to me?
We have that red streak coming through her torso but blocked by her leg and somehow behind the card border?
hard to tell from image alone. Could you share a video highlighting the effect?
seems like the card is setting a stencil mask, while the ghost spider is the one get masked, the red beam is unmasked
the ghost spider might be spine or layered image
Let me know how it works ^^
And if anything's unclear in the example
problem is, I have hundreds of pieces of text
I have this fairly big shader controlling leaves for bushes, I'm trying to get a gradient like pictured but for some reason this gradient I set up only shows going to black, even though I tried changing the colors (currently a light blue). Any ideas?
you're adding the position onto the gradient value; if the position is negative enough along all three axes it will be black
hm but if I dont have obj position the gradient won't go over the whole object correctly
Ya sure, here's the video for both of you. @tacit parcel
https://youtube.com/clip/UgkxKxF5YFFE1vRz9IpHYJMGjUXXaI1lT4uu?si=r4rJcancX6OchPdW
5 seconds Β· Clipped by SBroproductions Β· Original video "Blinking M'BAKU!!! | Marvel Snap Deck" by MegaMogwai
The cards are definitely fully 3D models. They even have a little thickness to them.
It looks like the trail goes straight through the card/torso of the character but not the legs. To me it looks like the depth value written to the buffer might be just offset by some height map texture to get other objects to clip with it as if the legs were higher than the rest. This could work for the legs but some other cards seem to have real depth to them as if they were composed of multiple separate layers on top of each other (some closer to the camera)
I wouldn't be too sure about that. Well some sort of 3D model for sure but the image itself might be just a flat quad with normal map or parallax mapping applied to it to make it look 3D
Ya the question is really about the actual image of the card. There's definitely a 3D model THERE that the card front rests on. It's just a question of whether that front is baked into the model texture itself or is some sprites resting on top.
The depth offset is a cool idea but I'm not sure. Maybe for the legs, but there are parts of the body that just outright leave the boundaries of the card such as her arms and webbing.
could also be a shader that combines bunch of components together though intuitively it would make more sense to use few separate sprites to have less and more simple shaders to potentially get better performance and allow more variance in the cards more easily
And they don't look alpha clipped.
There are some cardswhere this trail effect doesn't even clip through the body of the sprite.
In case of depth buffer approach the whole character could have a depth offset map but the vertices might also be physically offset to create depth for the image (in clip space to not distort the image). There's also likely dozen other methods that I just can't wrap my head around atm. Would love to hear from other possible ways to achieve the same effect
It's simple, I just contact one of their tech artists and ask π
Hi Everyone, Noob here, Lets say i have 100 RawImage components (uGui Canvas) with their own different textures.
now i want to set same instance of Material (which is a shader graph based shader that turns image to grayscale) .
My assumptions are that all the images will turn greyscale and there wont be performance impact?
is that right?
Or is there an another way to reuse same instance of material among multiple canvas components?
Thanks
Im trying to do a simple sine wave deformation in a shader like you'd use on a flag in wind but I cannot find a tutorial on it nor can I figure it out myself. CAn anyone see what I am doing wrong here to fix it?
found this which looks like it will push me in the direction I was hoping for. Though I'm a little confused by their use of UV nodes, I thought you couldnt do texture sampling in vertex position deformation
You can sample textures in vertex stage, but you'd need to use the Sample Texture 2D LOD node rather than the regular one
Oh right sorry I misspoke, what I meant was that I thought UV's themselves were used for texture sampling and couldnt be involved in vertex displacement at all, that I would have to use object space coordinate position nodes instead of UV
I havent done a vertex deformation in a few months so I've forgotten all of what I used to know π«
UVs can be used too, they're just values per vertex. They don't need to be used to sample textures.
For displacement make sure you'd adding the offset to the original vertex position
Also while the Position->Split->Vector3 setup works, I much prefer adding Position & Vector3 as it keeps the graph cleaner
Very simplified, but this graph hopefully shows what I mean
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-Shadow.html have you checked this out
i feel so stupid bro, lmao, thanks
wait no
doesn't seem to work on text mesh pro ui
Text mesh pro already has an option for creating an under-shadow, or you do not want to use that one?
@urban anchor underlay in textmeshpro
yes, that's what I mention in my first message. The shadow color doesn't inherit from the text color.
but you can change the color of the underlay. or does that change the color of all underlays?
The above will not work as well, i think you can try texture-based shadows instead of creating separate GameObjects for shadows, you can render the text as a texture and apply a shadow effect using image processing techniques basically shaders ( you can ask chatgpt to write the shader for you) . This approach can be more efficient, especially for static text, as it reduces the number of draw calls and meshes.
for dynamic text you can explore SDF rendering
Lets say I have this quarter rounded rectangle. What is the best way to render a full rectangle using this sprite only?
Any better ways/tools than having 4 different gameobjects rotated & positioned to form a full rectangle?
quarter rounded rectangle sprite an efficient approach is to utilize texture mapping and UV coordinates to create the full rectangle.
makes sense. does unity have a sprite tool for this? or should I implement it manually?
https://www.youtube.com/watch?v=37q-0oS65LY unless you're not looking to build UI elements with this?
How to use Unity's built-in 9-slice utility via the Sprite Editor, and what this help you accomplish.
9-slicing sprites is used primarily for UIs and 2D games. It allows you to stretch a sprite without deforming the corners, and also allows you to tile the center of a sprite while keeping the outer edges untiled.
For more documentation on 9-...
I'm working on a decal shadergraph and any time I change (just the connections not the properties) any node anywhere it causes a shader recompile immediately and it's massively slowing down my ability to work on it, is there a way to disable that? I didn't seem to have this problem in other shader graph types...
Correct me if I'm wrong, but having my shaders in shader graph should make it easier to transition between render pipelines right?
If your shaders need lighting, yes.
anyone familiar with the URP PSX Shader?
Specifically URP PSX PBR
And has anyone experienced issues with baking lighting with it?
What are the fastest mobile blurs for UI? I need to make sure that the photo blurs, some testing, it lags and the FPS drops to almost 0
hello shader experts 
idk how to make shader graph like this myself
but here is some information about it
https://media.discordapp.net/attachments/1116193509393825915/1245388136867958876/Screenshot_3.png?ex=66589196&is=66574016&hm=56cf3823bf493a188fd6bfc5339f99c8d2be42b436f33d91ed179e6ae9e5d90a&=&format=webp&quality=lossless
https://cdn.discordapp.com/attachments/1116193509393825915/1244939840714444850/image.png?ex=665798d3&is=66564753&hm=23310f21e0ee40232d95e19358f1ed24c2b87045dbd2836bbe7c0b5c56a7c14e&
if anyone know how to make it / tutorial video or shader file i will be happyyyyy β€οΈ
probably downscaling it
I'm a little confused about downscaling?
I am guessing you wanna blur everything if so, you could blit your render to a smaller texture than your screen size and then present that to the screen.
just sample this heart texture, and then do some vertex displacement based on some noise
So, how can I use methods defined by other nodes inside a custom function for a node? I'm trying to use the UnpackScaleNormal from built in in URP but it says it doesn't exist. So I guess I need to use this that is more global https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Normal-Unpack-Node.html
Unless this is an extremly high vertex count mesh (which I doubt since it's a carpet) this wouldn't work. I would say to do a geometry shader, but no clue on how to do that in shader graph
For URP there's a bunch of functions in Packing.hlsl
UnpackNormalScale is probably what you want
Two more questions.
1- Is there an implicity speed loss when using shader graph? I feel like code attached, is faster than the graph attached (feel means looking at it, not testing of course)
2- The branch node acts as a literal branch? I used to do this, which was actually a speed boost. Does branch also produce that or should I make a custom node for it?
( i use this in very specific cases where it actually makes sense )
blendAxes /= blendAxes.x+blendAxes.y+blendAxes.z; is not the same as Normalize, fyi.
No, the graph will generate similar code (other than the normalise part ^). idk if other parts the graph generates will cause any performance differences though, unlikely
Afaik the branch node uses a ternary which in hlsl always executes both sides. So if you want a true branch you'd need a custom function
parallax mapping for the 3D
Ah true, normalize normalizes the magnitude not the vector
Alright
Perfect! Thanks!
Is there an equivalent node?
How can I make a dynamic input? So like, if I input a vector3 the subgraph treats it as an input3 but If I put a Vector4 it treats as a vector4
I don't think we can π¦
Not that I'm aware of, there's no option exposed for it
Every time I try to do a Convert To Subgraph, I get a null ref error in the console π€
but im not using any kind of custom nodes so I am not sure what is proccing it, is there any way to trace it somewhere?
how do i make custom shaders?
That's a lot like asking "how do I make custom code"
following a vertex deformation -> recalculate normals shader tutorial I made this, but I have a problem with it
The normal recalculation relies on Vec3 object space positions, and I wanted to use this effect on a skinned mesh that deforms to bones on top of also doing this look
as soon as the bones move, the whole thing kinda breaks
is it physically possible to recalculate normals from just the UV coordinates?
I need to use the vec2 uvs for the deformations to make the effect work with the bones but I dont know how to to recalculate the normals from that
alternatively is there any way to achieve the above effect without shaders some other way?
I would say yes, but you would need to know the true distance between points
But thinking about it, if it's fully 3d maybe you cant
Why cant you use vector3 positions in object space?
The vertices are being displaced right?
Because I want to also deform the plane via bones and when I do that the whole thing breaks visually, Ill take a screenshot 1 sec
the only way I can describe what I think I am seeing here is that somehow the bone rotation is causing the mesh itself to rotate it's object space, or something
gets really messy real fast
Oh I see, that does indeed look weird. Are you calculating the normals in the shader right?
But i mean, the animation itself also looks weird
I think unity already has it
yo guys whats that in the background
dark red background
i changing the alpha but it doesnt effect it
More questions!
1- Is there a way to set a category to custom sub graphs? So that they have their own tab?
2- Can I use subgraphs inside compute shaders?. I have some code translated into subgraphs but the same nodes (and previously lines) need to be used inside compute shaders for some precomputinh
3- There's no support for multi pass???
A wait, with the new RenderGraph it might be π΅βπ«
Hello, im'm trying to make a shader to make nice patterns for my game but i keep running into issues:
hold on i might be onto something...
nope...
Why does it stretch?
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float offsetX = _Time.y * _Speed;
float screenX = i.uv.x * _ScreenParams.x + offsetX;
float screenY = i.uv.y * _ScreenParams.y;
float new_x = fmod(screenX, _Distance);
float new_y = fmod(screenY, _Distance);
if (pow(new_x - (_Distance / 2), 2) + pow(new_y - (_Distance / 2), 2) <= pow(_Radius, 2))
{
return fixed4(1.0, 0.1, 0.1, 1.0);
}
else
{
return fixed4(0.0, 0.0, 0.0, 0.0);
}
}
the UVs stretch when you stretch the object
so when you're multiplying by uv.x, uv.y in the frag shader you're telling it about how the object is scaled
I'm more confused about why is it than fine at scale [15; 5.5; 1]...
What do i do than?
Edit the material? Shader? Object?
"Um, yeah, this is whats wrong, this is how it works, i won't tell you how to fix it tho".
Thanks a lot.... π
chill out; you could multiply the screen position by the screen resolution and then rather than multiplying by the uvs, dot those with the tangent vectors (gradients of the UVs) and that gives you coordinates aligned with the UVs but scaled to the screen
The thing is that uv is local, and i wanna keep it local...
The UV is just weird and idk why. You can clearly see that it's not square.
The only reason i need to solve this is becouse the stretching is not the same between Game and Scene
I think that's because you're multiplying by the screen size which isn't necessarily the same
This might be down to a choice of _Distance
- There's grey text under the graph name in the Blackboard window. It doesn't look editable - but if you double click it is...
- compute shaders are code only, no graphs
- no, sg generates multiple passes behind the scenes based on graph type (i.e. forward, deferred, shadowcaster, depthonly, depthnormalsonly, meta) but you can't specify passes with custom lightmodes or add extra unlit/forward passes. That breaks the SRP Batcher anyways.
(Also RenderGraph is a scripting API, not another visual editor just in case that's unclear based on the naming. It's not a replacement for shadergraphs. But renderer features are meant to use it. But yes, you may be able to use a custom feature or RenderObjects to re-render objects with another material/shader)
If using 2023.2+, use the Canvas Graph type for UI. Other graph types generate additional passes which may be rendered incorrectly.
For older versions, SG didn't support UI but using a Screenspace-Camera canvas somewhat works. More info - https://www.cyanilux.com/faq/#sg-ui
Hello π I'm using Unity 2022.3.24f1 and URP
I have a really critical problem with building time. On I9-14900k and 4090rtx it takes 6hours. There were around 1.000.000 shader variants compile.
I read this topic: https://forum.unity.com/threads/extremely-slow-shader-compiling-for-builds.1342220/
but there are so much words, so little actions and clear instructions.
Is this variant prefiltering something I need to turn on? Put some codes, if yes then where? I'm confused about this one
The second time I tried to build without ANY changes in project also took 6 hours.
1- thanks will check that
2- can't i use a compiled version of a shader graph?
3- bff alright thanks
Probably not the compiled, but the generated code maybe. It tends to be pretty unreadable though, I think it would be better to just rewrite it in hlsl manually
I see yeah, but wanted to use a subgraph and make use of the input/output part, but otherwise i will just make the hlsl and use it in shader graph as custom nodes
Not great (because i prefer everything being easily readable by the user) but at least a workaround
Anyone has some tips for this?
I just stumbled across this
that might be relevant (:
hey, so sorry for the late reply and you mightve already forgotten about this, but im having trouble trying to understand this
i have my spaces and maths on world and for some reason my normals still look odd
it seems like my normals are completely fine when the object is in +x and -z
but its flipped on hte opposite side
im so confused as to why this is happening
General question - Why are shaders in Unity predominantly written with visual scripting as far as I can tell?
Because it's easier. Many game engines provide visual scripting solution for shaders/materials nowadays. Unity is not an exception.
most gpu only support float, especially the older ones, so adding 'real integer' support to the shader language might make things more complicated on compiling process
You can also use the generated code and deleted 2 passes and set the z position in the canvas to 1000+ and it also works great
Hello! This is my first time here, and I'm very new to unity as a whole. I'm working in Unity 2019.4.26f1 for modding, and I'm trying to make a shader graph for a particle effect. It works so long as the object is at world origin. I'll share videos of it working as intended and then what it's doing off of world position. And I'll share my node graph (it's messy, apologies). I've been looking through some forums and tried multiple variations but no luck yet. Thanks for the help! edit the graph shows only the parts that are in question, there is a little bit more to the shader that I left out. **Edit 2, didn't realize clips had irrelevant sound, got rid of them
Aaaand the videos are a bit scuffed, first starts 3 seconds in, the second starts 16 seconds in. Sorry about that
Hi, I'd like to ask, when It comes to apply multiple effects on a single mesh, should I use multiple passes in a shader, or should I seperate it to multiple shaders/materials?
Mmm, that sounds weird, integers are way simpler to represent than floats, but i guess that the ones that support structured buffers are the ones that support integers? Im don't know how i would otherwise access an array
So im looking at making a custom function But I notice that If I do a custom node that has the function as input on off and then output regarding a branch, i would already be calculating the whole branch before going into it
Like, my only option would be a node that has all the code of that branch inside, but I cant make a node where the subsquenet nodes are inside a branch right?
I can't insert that piece of code
or can I
Compilers are clever and should strip the code if an input variable is unused in one of the branches afaik, but you may want to double check
That said not sure how useful branches are for just an on/off state. I think usually the cost of both sides of the branch needs to be roughly the same?
Yeah, but in this case the code would basically look like this, and therefore the input would already be calculated
void MsBranch(in float val, in float input, out float resutl){
UNITY_BRANCH
if (val > 0)
input = result;
}
In this case extremely. On means triplanar stochastic sampling per four textures with the extras (occlusion, heightmap, normal map), aka around 144 samples, if off i just sample one prebaked texture
So avoiding one branch definetly saves a lot of time
Yeah but since that input isn't used elsewhere the compiler might try to optimise it. You'd have to read the compiled code to check
Would you be able to help me out were on the compiled code the branch might be happening? I have no clue on how to understand/find if there's an actual branch or not
The unlit shader is arond 1701 lines
ah wait, i can find it with ctrl+f, i forgot to save it
Yeah no, it looks like it's sampling any way before going into the node
That's the SG generated code, not the compiled one
but there's no [branch] tag, I doubt it will create a branch
(plus, im not sure how to check if there's an actual branch in the compiled code)
oh
It creates branches, okay that's good. Now i need to know tho if the actual branches are correct
OH
it does the branch? since the sample is inside, im guessing it's actually doing it
Hi. I have a shader that has red green and blue channels being driven by stuff.
I put this through a saturation node with the expectation that when desaturated the red green and blue would become monochrome and of the same intensity. However, what I wind up with is this , where you can see clearly that the G comes out strongest with blue the weakest. Any idea what's going on here?
This is because the Saturation node is tuned for human eyes and how it perceives luminance. I perceive the green to be brighter than the red, and the red brighter than the blue, despite the fact they are the same brightness values.
Right, I was wondering if it was something like that, thanks
what would be the alternative method here? essentially I want to mathematically 'desaturate' it... so that I can use them each as an opacity and when I add them together get 1, ie RGB 0.33,33,33 adds up to A 1, but that each 0.33 looks the same.. I'm probably explaining that terribly
You can take an average of the three. (r+g+b) / 3
hmm yeah, I was trying that somewhere else in this
Or the max value.
ok, I'll keep poking at it, thanks
Do you want (0, 1, 0) (fully green) to be as bright as (1, 1, 1) (white)? If so, then you need to use max.
no, I want it only to be white when the 3 channels combine
so 3 equal greys that total to white
then (r+g+b)/3 would probably be best
funny that I was using that maths elsewhere in the shader already
thanks π
stupid human eye functions
π
These two colors have the same average brightness. (0.33, 0.33, 0.33) vs (0, 1, 0).
Generally.
Can I input/output a custom struct in shader graph?
Shader graphs compile back to shader code so the performance is comparable to each other as mentioned. If I had to guess, shader graph could be bit slower but the difference doesn't generally matter anyway
Is learning shader graph good for long-term learning, or is there a case for learning the code?
Hey all,
Soooooo, I'm trying to make a 'scrolling' noise shader, but seem to have forgotten how to do it properly.
Image attached of what I have so far but the noise is scrolling sideways no matter what I do. Lil bit confused. lol.
Can anyone see where I'm going wrong please?
Multiply time by a vec2, add to your position/UVs, and use that to sample the noise
(if you just add the time directly it'll get swizzled to vec2(time,time) so if you're happy with it scrolling diagonally then just go for that)
Ah got it, thanks π
how do i fix this?
I have a render texture with a fake light with a fake image glow so I used the additive shader on it. For some reason it looks like this in the render texture and it is not transparent.
The camera is rendering it and it has a solid color black background, I made it transparent and it works fine, but not with something with an additive material
May become and issue with regular shader code as well. The compiler will optimize the code as much as it can so the performance isnβt in our hands for most parts (you canβt even do proper branches and loops with shader graph anyway which can become heavy). You can even insert shader code in your graphs with the Custom Function node as well but often times that is not done to improve performance either but rather do things that canβt be acccessed with the available nodes (like loops)
Any idea why this works in the editor, but not in a WebGL build? (Using URP)
half SamplePCSS(TEXTURE2D(ShadowMap), SAMPLER(sampler_ShadowMap), float4 shadowCoord, float3 radius, half4 shadowParams, bool isPerspectiveProjection = true) {
if (isPerspectiveProjection)
shadowCoord.xyz /= shadowCoord.w;
if (shadowCoord.z <= 0.0 || shadowCoord.z >= 1.0) return 1.0;
real attenuation = 0;
return SAMPLE_TEXTURE2D(ShadowMap, sampler_ShadowMap, shadowCoord.xy).x <= shadowCoord.z ? 1.0 : 0.25;
}
called by SamplePCSS(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_LinearClamp), shadowCoord, radius3d, shadowParams, false)
Hey folks, I am creating a series of full screen shaders using shader graph but for whatever reason they do not show up in my Quest builds. I added them to the render settings. Not sure what I need to do
My shader varients are HUGE and it takes forever to build my game. It seems to be one shader, which is the gradient shader, can someone help me with this? Everything above the red line in the picture builds super fast and normally, but the one below the red line is EXTREMELY SLOW, someone please help me with my hours long build times! Here is also the shader graph, it's very simple.
What do you see if you expand the "compile and show code" drop down?
A long list of keywords thats over 3600 lines
Each line completely full
A shader graph with 6 NODES, followed from a popular tutorial.
how do i rotate the red part that i circled its in a shader graph
Hi everyone, I'm still a beginner at shaders and I've found the guassian post processing shader online, but how do I make it so that I can use a mask texture to affect the strength of the blur through transparency?
Anyone knows if the these 2 values are supposed to match? When I click the "compile and show code", it starts compiling way more variants than it shows in the first screenshot. Or are these not variants?
It's also weirds that some keywords like Fog ones are included despite me turning them off in the Graphics settings
Rotating things is quite easy but separating the red part can be bit tricky. You could use distance from the center to approximately figure out the size but that would leave hard edge where the rotation starts, that may not be an issue for this specific image (because the grey thing around the red thing seems radially symmetric if that's even a word) but if you need this to work for any image, it may look quite harsh. In that sense it would be easier if the thing to be rotated was an separate texture
Is there any way to create internal variables in shader graph, so that I reduce the amount of lines crossing the diferent nodes?
I've got an editor script (+ a couple subgraphs) that adds that - https://github.com/Cyanilux/ShaderGraphVariables
Yeah, because this is hard to read
Ty
Reroute, can double-click a wire to create one
Oof yeah. Though I should mention my package only works with vectors/floats, not other connection types
Aww man, this is goood
Thanks tho! I will give it a try (and maybe even implement other types)
Now another problem, can I copy a blackboard entirely?
So I can copy all of these variables from the subgraph
Can you highlight them in blackboard and Ctrl+C, Ctrl+V in other? I'm really not sure
how do i take away the white background?
Maybe get the magnitude of the rgb, step with .99 and lerp with 1 returning transparent and 0 the color.
Or just use an if node
ive never used shadergraph, but surely theres a way to encapsulate a bunch of nodes as a single function?
(to reduce spaghetti)
idk what any of that is lol
Yes, you can make a subgraph (or select, right-click, convert to subgraph)
(Though I guess that might be more for re-use of those nodes, not necessarily spaghetti reduction)
Time to learn then
Could be easier to add an alpha channel to the texture (or one of the colour channels as a mask if unused)
anyone know how to fix this error ?
It's just a warning, not an error. If the material works, you can ignore it / or add the tag to the shader code as mentioned
yeah looks like there is some option to make it work on vrchat since it's only support standard shader pipeline
this is how looks like in unity
https://cdn.discordapp.com/attachments/1237692392694349845/1246438863132561439/image.png?ex=665c6426&is=665b12a6&hm=0637c3ff889cc76e63b01230b205bab943be0dcc37192cd1e269642a6f7b990d&
this how looks like in game
https://cdn.discordapp.com/attachments/1237692392694349845/1246438802009100449/image.png?ex=665c6418&is=665b1298&hm=ee0cf13de33ad37b209494d7384927311bf365dd9265af3285d13ac5429a3334&
awww i see
Nope :((
I just ended up manually copyinh them
https://gyazo.com/2e5bb624a1526582c4de2d41fb0dfc87
Can anyone help me understand why this happens?
one is probably negative so when you add something positive to it, it's still black; put a Saturate() node between each Multiply and the Add
Yeah it fixed it. thanks
in game
in editor
Hi
I have this piece of code
public RenderTexture Bake(Mesh mesh, Material targetMaterial, LocalObjectPool pool)
{
RenderTexture rt = pool.GetGroundRenderTexture();
Mesh M = mesh;
Graphics.SetRenderTarget(rt);
GL.Clear(true, true, Color.black);
GL.PushMatrix();
GL.LoadOrtho();
targetMaterial.SetPass(0);
targetMaterial.EnableKeyword("_BAKE");
Graphics.DrawMeshNow(M, Matrix4x4.identity);
Graphics.SetRenderTarget(null);
GL.PopMatrix();
targetMaterial.DisableKeyword("_BAKE");
return rt;
}
That helps me bake a shader into a texture
Previously I just did that and it worked, because my shader had two passes, the first one being the required to bake
However now with shader graph i have no clue on how to get the correct pass. I made it all into one shader pass (because afaik you cant do multiple passes) but its saying that there are 8 passes (probably related to lighting) so I dont know which one to target
Is anyone able to help me with this? It's been over 1 year since I'm trying to find a solution.. I started developing my game on Unity 2019.something.something when LightweightRenderPipeline was still around and was working. Now I updated it to 2022.3.19f1 and if I try to make a new shader graph for a sprite sheet, it makes it a square, stretching the texture.. so it looks like this for example
when it should've looked something like this
Your shader is not set to use the sample texture alpha for alpha transparency
thank you!!
Is there any way to run a lit shader without any lighting effects?
Trying to bake it into a texture but light effects are in my way
A lit shader without any lighting is an unlit shader
I donβt believe you
Does anyone here know if Shadergraph Fullscreen shaders work on mobile/VR? Can't seem to get the one I made to show up in build
What setup do you have? From quick Google full screen shader graph is only available in hdrp..?
Hmm. There appears to be something similar in urp as well
URP. I was just reading the docs and was hoping that someone had any luck getting a fullscreen shadergraph to work in a build. Trying to create a grid vignette effect.
Does it work in a standalone(windows) build?
It does.
Just not on Quest 3
I tried adding it to the includes just in case it got stripped out but that was a no go as well
Are you using the same urp settings/quality levels for both of the builds?
Yea same URP asset. No changes outside of the obvious platform relevant ones
Open project settings - quality and take a screenshot
All my other shadergraphs work on Q3 just not fullscreen
How are you applying that shader though? Post processing?
The shader is visible once you add it to the Render Features without even applying it to anything
Ok, so it's a full screen render feature.
correct
Is that the scene that you're building?
I don't think it would work correctly without a camera
oh no this is just a empty I just started to work on some other shaders
Does any other full screen render feature work?
I don't see anything about it not working on mobile.
Can you take a screenshot that I asked earlier?
Do you see that android and standalone builds have different quality level set as default level?
Try using the same quality level for Android and test again.
Switched Android to Balanced for performance reasons
Hey, I'm still new to shader graph and can't really figure this out. My issue is that I'm trying to blend between two textures but I'm not sure how to supply the right value to the inverselerp. Any ideas?
you can ignore the comparison - just for test
building now
Then try building windows build on balanced as well.
These 2 quality levels probably use a different urp asset
I don't know what settings exactly affects it(possibly the post processing), but it's possibly disabled in the urp setting used in the balanced quality level.
connecting the clamp into the lerp, "works". The blending seems fine, issue is that the secondary texture that it's supposed to blend into is seemingly absent, instead it blends into a very red version of the first texture
Doing another build target for High Quality
no idea what I did but it fixed itself, seems like
I can see it in High Fidelity but the performance is pretty bad. Adding the shader to the Balanced Asset
Yea its disabled in Balanced. Need to figure out what affects it
Why my outline shader is like this, the black outline is coming out from the gameobject. I want it to be something like the red one.
So, disabling HDR and Anti Aliasing shows it but now my UI Quality it aliased and jagged
You probably want to extrude the vertices along their normals. Now you're just extruding them relative to the object pivot point, which is not gonna move them uniformly.
Sorry, i'm unfamilar with Shadergraph, what node do i need to add?
Tweaked a bunch of settings and its passable for now but it draws in a vignette in each eye instead of one vignette drawing across both eyes.
I followed your instructions. There are some improvements as the outline origin does not move but now i don't really know how to explain it but like every face is extruding an outline like the cube.
Yeah, that's a limitation of such approach. faces that don't have common vertices would not be connected.
outlines is actually a pretty complicated topic. Might want to research it a bit
Dame, thanks for your help.
I feel like the last thing I cant figure out is why the full screen shaders draw a single instance in each eye vs a shared render across both eyes
Wat?
the top is how it is showing up[ now and the bottom is the desired
Hello, where am i supposed to assign the roughness textures on the material?
This might require adjusting your shader specifically for vr.
Depends on the shader
depends how?
Because what properies/texture the material takes depends on the shader
it's URP. Does that help?
URP is a render pipeline, not a shader
In a URP-lit shader metallic/specular maps perform the same function as the roughness map, although they require the values inversed afaik.
So i assign it to metallic? But there's also a metallic texture which came with the model. Does that mean that i have to choose between metallic and rougness textures?
It depends on what purpose these textures served in whatever software the model was made in
In unity a metallic map uses 2 channels for different information:
With a texture assigned to the Metallic Property, both the Metallic and Smoothness sliders disappear. Instead, the Metallic levels for the material are controlled by the values in the Red channel of the texture, and the Smoothness levels for the material are controlled by the Alpha channel of the texture.
https://docs.unity3d.com/Manual/StandardShaderMaterialParameterMetallic.html
It's possible that your riughness and metallic textures just represent these 2 channels.
it doesn't say anything about roughness
roughness determines how rough a surface is
In other words, it's the opposite of smoothness
So they are basically the same property, just inversed in value
Roughness field appears on material settings when i swtich the shader to Autodesk interactive but that shader is not compatible with URP. There's no field for roughness map when i choose URP - lit
Did you even read what I said?
I read all of it. Do you mean your previous comment?
Yes
roughness is the same as smoothness, just opposite in value (1 - x). You can inverse the texture and use it as smoothness.
Or create a custom shader that inverts the value
Smoothness should be packed into the alpha channel of the metallic map, like dlich quoted earlier.
Yeah, buf it would be part of an asset where people will provide a lit shader and I want to bake it
I cannot transform it to unlit on runtime
I don't think that's something easily implementable, especially in a close sourced engine.
I got it. Select URP-Autodesk interactive in the shader settings. There's a slot for both metallic and roughness map, you can assign them both. That's it. This is the answer i was looking for
I can do it on built in, not the transforming it, but it's easier for the user to implement a pass than to make another shader. I liked that i had to only assign one material in the inspector, instead of two
But i cannot make vertex shaders with the shader graph, without modifying the generated code
(and I'm not sure if even modifying it)
The shader graph does generate a vertex shader though. There are some nodes that get put in the vertex shader. It depends on the node and what it is plugged into.
Indeed but I would need also a different fragment shader, basically a different pass
If you just need a similar functionality to render passes, then there's the render objects feature in URP.
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@17.0/manual/renderer-features/renderer-feature-render-objects.html
Hi, someone can help me with the Alpha Clipping option in shader graph ? Cause idk how that works.. :c
I've the same result all the time xd
As you have "Allow Material Override" ticked, I would check the settings on the material too. You may have Alpha Clipping disabled there
On the material.. hmm, i've no material for this mesh
So just need to disable it ?
Oh y that work.. lol
Ty xd
You must have a material, that's how you assign shaders to objects.
That "Allow Material Override" exposes the settings to the material. Newly created materials will use the values under the Graph Settings, but existing materials won't be changed.
But sure, if you don't need to toggle the settings per material you can disable it.
Okay,
So where's my material options ? I must add it on my graph ?
i'm lost xd
Idk how control it :x
Since you appear to be rendering the mesh from the vfx graph, the material properties would be controlled by the vfx graph
heya, im just getting started with shaders, and im just trying to make a simple sahder where a pixel is rendered by its WS position, but its just throwing a bunch of errors about missing semantics, and i looked at the docs and its still not mkaing quite sense, so any explanation would be appreciated!`
this is the code rn:
{
float3 positionOS : POSITION; // Position in object space
float2 uv : TEXCOORD0;
};
struct Interpolators
{
float3 positionWS;
};
Interpolators Vertex(Attributes input)
{
Interpolators output;
VertexPositionInputs posnInputs = GetVertexPositionInputs(input.positionOS);
output.positionWS = posnInputs.positionWS;
return output;
}
float4 Fragment(Interpolators input) : SV_TARGET
{
return float4(input.positionWS, 1);
}```
The interpolators need semantics attached (like : TEXCOORD0, etc - though afaik the exact naming isn't important, except for system value SV_ ones)
The vertex shader also must output a clipspace position to SV_POSITION to actually produce fragments (+ draw something to the screen/render target)
yeah, most of them are just informational
but from what i understood TEXCOORD0 is for uvs and TEXCOORD1 for lightmap data?
like they get automaticaaly assigned by the shader
That's only for Attributes
oh cool
In interpolators, TEXCOORD can be anything you want it to be. But really you can just use INTERP0 etc if you want. I think that's what shader graph generates.
and say i wanted to have a bunch of different data passed, how would i do that?
becuase i tried marking both the CS and WS positions with VS_POSITION and it yelled iat me
Between the vert & frag? You add more interpolators, e.g. with : TEXCOORD1, : TEXCOORD2 etc.
You only want the CS output marked as SV_POSITION
There is, it depends on the target platform
okie tysm!
Hey, guys.
I know everyone here asks about the little things, and unfortunately I will be no exception. I need some advice, I need to use the PSX Shader and I have a problem with the night where I need the trees to not "glow" so much and just reflect the light from my flashlight.
If there is anyone here who can help me, I will be grateful for the rest of my life. 
Screenshot would be better i guess
I am still trying to figure out why my full screen render feature effect renders per eye and not per frame. I can't seem to set it to single instance
I don't do VR, but can probably use the Eye Index to scale/offset the fullscreen effect
If you're looking to work with texture arrays there is a Texture2DArray property type and Sample Texture 2D Array node
Can maybe try set index port based on height of fragment. And another two samples for neighbouring height values (-1 and +1 to index) and blend between those
Si I made a shader in builtin using shader graph and it works perfectly in built-in (obs) and URP
Howeveer Im getting an error in HDRP
void SG_SampleTextureAssetFull_02270f3fc2b8e1a4180f553e9571cfbb_float(float _Index, float2 _UV, bool _UV_0ab1ea7c094346929806292a904bf9d3_IsConnected, float _Weight, UnityTexture2DArray _AlbedoArray, UnitySamplerState AlbedoSampler, UnityTexture2DArray _OcclusionArray, UnitySamplerState OcclusionSampler, UnityTexture2DArray _NormalArray, UnitySamplerState NormalSampler, Bindings_SampleTextureAssetFull_02270f3fc2b8e1a4180f553e9571cfbb_float IN, out float4 Albedo_1, out float4 Occlusion_2, out float3 Normal_3)
{
float _Property_52579ffba1bc4d86b11f13f3b8f20138_Out_0_Float = _Weight;
float _Comparison_80c3934b99594784bd37bc66f02e073d_Out_2_Boolean;
Unity_Comparison_GreaterOrEqual_float(_Property_52579ffba1bc4d86b11f13f3b8f20138_Out_0_Float, 0, _Comparison_80c3934b99594784bd37bc66f02e073d_Out_2_Boolean);
UnityTexture2DArray _Property_545f9984588b4a889dbd00f6c03dae13_Out_0_Texture2DArray = _AlbedoArray;
these are the lines affected by that, the first one is the 16059 and the last one 16064
I don't understand what could be the issue?
That was true in the past but nowadays you can import a combined texture and have unity split it up based on rows/columns (select Texture Shape as Array)
https://docs.unity3d.com/Manual/class-TextureImporter.html
Why does the time node appear to speed up when I move the camera?
Hi, I'd like to ask what's so special about the MainTexture attribute? When I set the the property to MainTexture, the object will be affected by Special Texture properties and can't be selected in Editor until pointing its current shape. Is that feature a pros or a cons?
π€ Are you using world position in your shader perhaps?
yes, that was the issue. Thanks
i had the same issue disable material overide
i can dm u the shader if you want
put the UVs through a Tiling And Offset node first
Y that i do too, that work so.. idc about material xd
Hello, why does the albedo transperency texture look like this ? It looks like they're painted on a paper and glued to the model's head
It looks like you don't have any transparency in the shader there
i selected autodesk interactive transparent shader
ok, i got it. It is fixed when i check the UseOpacityMap box
Hello, In HDRP, a custom node with a texture2darray sample doesn't work, anyone knows what's going on?
The custom Node
The final HDRP shader
The error
Im in HDRP 14.0.10, unity 2022.3.20f1
(im not sure if i can send files like that)
It seems that there's the BareTexture2darray and the Texture2DArray variables? How are they diferent? And why two? if I change to a bare textuyre2d array the shader gets compiled, but the subgraph appears as error
Texture 2D Array is UnityTexture2DArray which acts as a wrapper around the texture and sampler.
But these types were only added in SG v10.3+ so there had to be "Bare" versions for the actual texture types (which would be Texture2DArray here), so it didn't break older graphs that were upgrading.
https://www.cyanilux.com/tutorials/intro-to-shader-graph/#better-texture-data-types
So how should I handle this. Because HDRP doesnt support UnityTexture2DArray, but it doesn't even support its own node of texture2d array
Sounds like it could be a bug? I'm not sure, I don't use HDRP
Could you show the custom function code?
Or is it just the built-in one in a subgraph?
it just the built-in one
I had previously a custom funciton, and moved into the built one because i supposed that maybe what you mentioned was the case, and assumed that the built-in would take that into consideration
I'd maybe try a custom function instead of sg's node. I think this should work,
void SampleArray_float(UnityTexture2DArray Texture, float2 UV, float Index, out float4 Out){
Out = SAMPLE_TEXTURE2D_ARRAY(Texture, Texture.samplerstate, UV, Index);
}
That's what I thought too, but for HDRP it should be using the Texture2DArray<float4> instead of the Unity ONe
I think
But im gonna make a bug report and see, because HDRP is not a must rn
Can i make node variations between target pipelines in a single asset?
So i dont hve two shaders for URP and HDRP that are completely the same but with one node difference
Made the bug report https://unity3d.atlassian.net/servicedesk/customer/portal/2/IN-77697
probably stupid question, but do semantics need to be all caps?
it doesnt seem to be throwing any errors yet but ive always seen people using all caps so i was wondering
I think it works regardless, but probably better to stick to coding practices of HLSL, which uses all caps for some older semantics. But there's also a lot of SV_ ones which aren't all caps.
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics
okie cool thx!
I have this shader that does the white outline. Each body part (head, body, hands, legs) is an individual spriterenderer.
Ideally I would want the outline to be only around on the sides and not over where it covers other body parts. Is there a way to do this in the shadergraph or would I use a different approach alltogether?
Maybe this shows it better; I wnat these parts in red to not show the outline but the actual bodyparts behind it. The outline should only appear on the outer edge
Seems difficult because each Bodypart is its own SpriteRenderer.
Here is my current shader
Not sure if what I want is possible at all but it would look much better, I appreciate any help!
This is what I am trying to achieve. I was following https://www.youtube.com/watch?v=SlTkBe4YNbo but the outlines show on top of other if the objects overlap. I tried looking through various outline
could you set the render order so all the outlines render before all the sprites (so the sprites always end up behind)
Hello there ! Is there a way to get the same result as this amplify node (https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/World_Space_Light_Dir) but in shadergraph ? Thanks in advance !
(I can't use main light direction as I'll have multiple lights)
It's because the Base color is a float3 meaning it does not have an alpha component in it. That's why you should add Alpha block for the Fragment segment and drag the alpha from the texture there
why does it look like this when i apply the metallic-roughness texture on it?
It is supposed to look like this
"apply" how exactly
i drag the metallic-rougness texture to metallic slot. It's URP-Lit shader
Invert the roughness channel ? URP/Lit uses smoothness
how do i do that?
i change smoothness value, nothing happens
it looks bettter when there is a light source around it, but there are still those black parts which are annoying
In the texture import settings, repack the roughness texture channel to be 1-itself
Scene lighting also affects the appearance of lit materials
You might have black ambient lighting but sky in the reflection probe, or vice versa
yes it's about the light
It looks like your flesh tone there is partially metallic
Materials in real world are either metal or not, mixing it up haphazardly will give you weird results in many situations
hi, can somebody tell me why is that when i move closer to a tree, it turns magenta like this?
It swaps the tree to a LOD level that uses a material with an unsupported shader (or a shader with errors)
and how can i change the shader?
Shaders can be changed from the material asset, which are the magenta orbs visible in your project window there
Terrain trees expect a shader made for tree rendering specifically
i want it to look glossy, not metallic. If i turn off metallic map, it becomes a dull color. Btw it's a third part model, not mine
If it's not metal, keep metallic at 0
Glossiness comes from low roughness / high smoothness
To get a more vibrant color, use a more vibrant color on the color texture
Many graphical software implement a bright HDRi along with filmic tonemapping so that can give the impression that colors are "washed out", but that will change when you bring into an engine where you control the tonemapping and environmental lighting
Bear simulator? π Noticed the Medve Movement
yep, university project haha
#π»βunity-talk message i need some help
i posted it already i dont wanna repost but i rlly wan help
Share the !code properly, so we don't need to download it.
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
i rlly wanna know wha is wrong
cuz idk anything abt shader
Which of the shaders throws the error?
That being said. There's some very weird bullshit in the code.
Where did you get these shaders from?
Like wtf is this supposed to be?
both
idk it works on 5.0.0f4
dont rember
It looks like a precompiled shader, not the initial source code. Perhaps that's why it doesn't work outside of the specific version where it was precompiled. You'll need to find the original shader source code.