#archived-shaders
1 messages · Page 41 of 1
Can't. I'm using Built-In.
why did you choose built in?
(genuine question again, i'm curious)
It's what I'm most accustomed to. I've been using Unity since about until the new Unity UI system came around in Unity 4
i see
And I'd have to refactor a whole ton of other things if I wanted to move to URP
i see i see, yeah that's a reason
Shader Graph supports built-in
Mind if I DM you about what I’m trying to make?
Yes, if you have questions just ask them here
Ok. It’s currently dinner time so I can’t show my shader code right now
Thank you! Sorta like ghetto metaballs, per this picture I am rendering that falloff to a render texture of the terrain, and then using that texture to calculate effects that will be on the terrain's surface. The way the overlaps overlap on the render texture makes it do the metaball thing on its own.
The render mode is 'Alpha' but many adjacent ones were adding up way too fast to 100%, is why the gradient ended up being very faint in the end
ohhh that's a cool way to do that
once you draw to a render texture, you use edge to get the shore?
Yeah, smoothstep specifically. I couldnt get the effect to work without having some way for the different pieces to 'know' about eachother is why I settled for the render texture.
Its made from an ortho camera looking down that renders only the mask bits to a black background
I have no idea how to do that, but i sort of understand, that's cool
neither did I til I found a tutorial for it. Ill see if I still have the link
https://blog.theknightsofunity.com/practical-use-of-render-textures/
I think it was this one, it should have enough to make use of them
camera pointing straight down set to orthographic is key
oh wow that's going in my bookmarks
or you mean facing antinormal
what if ur plane of drawing is
tilted
then negative on the y axis won't work
it'll be skewed
anyways i would still like to know if this is okay on performance, as in will unity sample only one at a time or both?
this isn't a per pixel operation so i feel the branch shouldn't cause performance issues but
i might make a better blur shader later on
https://hastebin.com/share/fitavaquno.csharp Here's my shader so far.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
The new pass I have just overrides the whole previous pass instead of adding to it.
UsePass "Custom/CharacterMix/FORWARD"
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 p = tex2D (_Pupil, IN.uv_Pupil);
fixed4 pm = tex2D (_PupilMix, IN.uv_Pupil);
fixed4 pn = tex2D (_PupilNrm, IN.uv_Pupil);
fixed3 finalColor = saturate(p.rgb + o.Albedo.rgb);
o.Albedo = finalColor.rgb;
}
Even if I do nothing in the surf function, it still overrides it.
Can someone help me with this? A surf function that doesn't override the previous pass
Anyone?
patience exists lol
Sorry... I've just been struggling with this all day.
yeah thats fair, usually i will just leave my question in a channel and explain in great detail what i want and what im getting, then i go to sleep and come back to see if any answers are there, eventually if i dont get an answer i just go turbo research mode to see if there is anything hidden or anything thats tangent from what i want that i can use to solve my problem, and also after a few hours is when i bump my message
its alright unless you are trying to make a game in 1 week
you didn't specify any alpha input
Setting o.Alpha doesn't work. When I comment out everything else, the whole thing just goes black
I think you also need to add alpha or alphacutoff into the pragma
It worked. Thanks!
Created my first shader (a wavy/ripple effect to be applied to objects' reflections in water), and for the most part it works fine. The exception is when a sprite is animating, there is a weird stutter / disjoint issue on the reflection every animation cycle. It looks like this, anyone seen something like this before and know what the issue is? https://media3.giphy.com/media/v1.Y2lkPTc5MGI3NjExYzNmNDFkNGVhNjhmNzJmNDdhNjczNmVjMTgwYTM2ZjcxZTJiNzRkOCZjdD1n/anf49CwXmA8m2Qe5Fb/giphy.gif
Hi there. I am doing a course on Udemy for creating Shaders with code, and I can't seem to get this to work. I thought I typed it exactly as she has it, but when I switch to a texture, the color of the object changes, but doesn't apply the texture. Can someone help me see something I am not seeing?
{
Properties
{
_myColor ("Example Color", Color) = (1, 1, 1, 1)
_myRange ("Example Range", Range(0, 5)) = 1
_myTex ("Example Texture", 2D) = "white" {}
_myCube ("Example Cube", CUBE) = "" {}
_myFloat ("Example Float", Float) = 0.5
_myVector ("Example Vector", Vector) = (0.5, 1, 1, 1)
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert
fixed4 _myColor;
half _myRange;
sampler2D _myTex;
samplerCUBE _myCube;
float _myFloat;
float4 _myVector;
struct Input
{
float2 UV_myTex;
float3 worldRefl;
};
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = tex2D(_myTex, IN.UV_myTex).rgb;
}
ENDCG
}
FallBack "Diffuse"
}
What we havent seen before and know how to fix is your actual shader, please post it, we cant read minds and/or your drive
What is sharedMaterial
Hey everyone!
I'm a shader noob and I'm using this shader to produce a shine effect for my UI elements, it's working perfectly fine except that when game is played and atlases are generated, the calculated position for the shine effect uses the whole atlas the texture is part of
How can I get the position in the texture only and not the whole atlas?
My guess is something gotta change here but no idea what to do about it
Why don't you do it in the original pass rather than an extra pass?
NM, I see you got it working.
Also related to your performance question, the branch on a uniform isn't that bad. But you may not need it at all.
That's what shader variants do. Conditional compilation of, say, two variants: one with your uniform predicate, one without it (the true side one and the false-side one). Then, you set the shader to multi-compile both options, and the engine will pick the right one to use. One set of source code, two binary shader options, one for true and one for false.
Does someone know how to make this shader work in URP?
tried to even make ChatGPT to convert it, didn't go well
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
I don't get how that should change anything
Or can anyone tell me how to make this? https://www.youtube.com/watch?v=ZPlCN-6WleM
A prototype of a flashlight that reveal objects otherwise invisible. The idea is that the objects are in other dimension and only visible through this especial flashlight.
Well, you could be setting the values on the wrong material reference. I don't know if you are or not. I'm just looking a code fragments you gave and wondering if that's why you're not seeing what you set in the buffer.
lol, good try though.
There's probably a few ways, depending on the EXACT result you want.
What pipeline are you in?
One way is to do a per-pixel ray-cast from the flashlight to your object and compute if it is in the cone-of-light or not. If it is, you'd have to decide on if that's good enough or if you want to also vary light intensity like they did in that video. But start with the basics and just get it to show up or not.
Another way is to have some kind of intersection test between a cone and the various objects...but don't actually draw the cone, just do the test. It looks volumetric of sorts, so I'm not sure a stencil will do. Drawing the light effect could be another pass.
All of the above needs to take the depth buffer into account, but if your invisible objects honor the depth test, the occluded pixels won't be drawn anyway.
custom lighting shader, you can use this as a starting point: https://blog.unity.com/engine-platform/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019
and to make the object change color when it's fully visible you'll have to do some checks on the CPU and change a shader variable to change the color
Yeah, was trying to at least only make the object appear depending on the spotlight edge possition (smoothly), but kinda hard to recreate and test it with the lack of time 😅
URP, found a working shader for built in, but cannot find for URP sadly
You might want to investigate light layers too.
I haven't done this effect so I'm just spit-balling here.
I made a shader for a pretty similar effect but I unfortunately can't give that to you because I signed the rights away haha
ahaha, sure I understand that. I guess you can make your own variant for a tutorial, there's lack for URP 😄
Well, the second pass is intended for a masked pupil on a secondary shader that utilizes the original shader's pass
I've written an HLSL shader but I'm not sure if the output values are right. Is there a way of debugging the value of the HLSL method for a certain input?
i did that twice in 2 days lmao
but i ended up solving my own question
on my own
hiya!
I'm having a bit of a issue with a compute shader and 3d textures and i was wondering if i could get some help
I'm creating a 3D RenderTexture in c#, using SetTexture to send it to a compute shader and then running it, but for some reason the texture stays white! even if i specifically set it to be black!
here's the CS:
tex = new RenderTexture(volumeSize, volumeSize, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear);
tex.dimension = UnityEngine.Rendering.TextureDimension.Tex3D;
tex.volumeDepth = volumeSize;
tex.enableRandomWrite = true;
tex.Create();
shader.SetTexture(shader.FindKernel("CSMain"), "tex", tex);
shader.SetInt("volumeSize", volumeSize);
shader.Dispatch(shader.FindKernel("CSMain"), tex.width / 8, tex.height / 8, tex.depth / 8);
and the shader:
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture3D<float3> tex;
int volumeSize;
[numthreads(8,8,8)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
// TODO: insert actual code here!
tex[id.xyz] = float3(id.x / 100, id.y / 100, 1);
}
im not really sure what to do, id really appreciate some help
So, i assume that this is indeed bad
and i should just use different shader variants
well that's a bit annoying
i wish i had a better way to do that because i have this subgraph (with the 4 inputs) that allows me to use the shader wherever i want
It's not too awful if the branching conditions are based on uniform values. You alluded to this before.
If ALL pixels take the same logical branch, it's usually not that bad.
As that quote says, branching on uniforms when there's similar workloads isn't necessarily that bad. I mean, you gotta do what you gotta do.
But 4 inputs results in 2^4 variants. = 16 variants for all combinations of input booleans.
Your render texture format is Rhalf. So it only has one half-float.
Also it's always a good idea to bounds-check the subscript on the left of the =, so you never write out of bounds, although you may ensure that all dimensions are in fact divisible by 8, you don't want to assume that in code.
that's fine, it only needs one float
also yeah good idea but i wanna figure out why its not doing anything at all atm
You're setting it to a float3. Use float expression.
Also, how are you checking the result?
inspector
hm, alright
this is the compute shader now
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture3D<float> tex;
int volumeSize;
[numthreads(8,8,8)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
// TODO: insert actual code here!
tex[id.xyz] = 0;
}
it's still showing fully as white, even though it's being set to zero
but its the same texture
i thought you could use the gpu to write to the texture
like since this is read write this should be visible in the inspector right?
UPDATING UNITY FIXED IT
It's like this:
The GPU is a separate computer inside your main computer.
You create a texture on the CPU side, initialize it, and then "send it off" in the "mail" to the GPU shop.
The GPU shop works on it LOCALLY. But if you want the results back "at your house" (cpu side) it has to be shipped back to you.
You can read data back from the texture when the GPU is done working on it.
BUT readbacks are slow.
And IDK why changing versions fixed it, unless they updated the inspector logic to go get the texture from the GPU. If you're not doing a read-back in C#, IDK how you'd see the data on the CPU side.
can i turn a Vec4 back into a Texture2D?
Not unless you're talking about generating/baking texture assets with shader code in some way
hmm
Hi there. Can someone help me with this. I am doing a course on Udemy, and I thought that I had typed this code exactly as she has presented it, but for some reason, my result is different than hers. When I apply a texture to the shader, it only changes the color of the object, and doesn't apply the texture. I am sure I have some type of typo in this, but I just can't see it. Can someone help me see what I am missing?
{
Properties
{
_myColor ("Example Color", Color) = (1, 1, 1, 1)
_myRange ("Example Range", Range(0, 5)) = 1
_myTex ("Example Texture", 2D) = "white" {}
_myCube ("Example Cube", CUBE) = "" {}
_myFloat ("Example Float", Float) = 0.5
_myVector ("Example Vector", Vector) = (0.5, 1, 1, 1)
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert
fixed4 _myColor;
half _myRange;
sampler2D _myTex;
samplerCUBE _myCube;
float _myFloat;
float4 _myVector;
struct Input
{
float2 UV_myTex;
float3 worldRefl;
};
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = tex2D(_myTex, IN.UV_myTex).rgb;
}
ENDCG
}
FallBack "Diffuse"
}```
The texture might not have any mipmaps
mipmaps?
oh yeah btw i figured out the 2D alternative to Transparent Layer Mask, it's Camera Sorting Layers
same thing but different implementation, and a bit less flexible
i want to change the LOD so it's blurred
as i want to find an alternative to this method which looks bad and i feel is inefficient (sampling 5 times)
I've been trying to figure out what this does for a little, but i just do not understand what this is
Smaller versions of textures created for better performance when viewing from a distance
make sure your texture asset has “generate mipmaps” enabled
yeah i googled that and i tried to also make them at runtime
it's a uhh
texture made by the renderer
i don't have access to that

how do you get vec2 unpacking
i don't see a node for it
(split a vec2 into 2 float outputs)
this?
it seems to work
why is this like this
why can't i get voronoi cells which are distributed somewhat evenly within -.5 and .5?
Is there a way to get the previous frame texture? (In my c# code i'm using Graphics.Blit inside of OnRenderImage)
you could just save the frame to a texture and read it next frame, no?
btw why is my voronoi so uniform
the settings are default
i figured it out, it's manual tiling and offset
for some odd reason they were using that method instead of
ignoring the moving vector, that's irrelevant
can you provide an example for that?
i'm working inside of OnRenderImage, that gives me the source texture and the destination texture
what is the source texture type?
just make a private member
on the top
and save it to that
RenderTexture
private RenderTexture m_oldTexture;
and write to that at the end of your OnRenderImage method
void OnRenderImage(source, dest) {
// do stuff with source, dest and m_oldTexture
// at the end set the old texture to the current one for the next frame
m_oldTexture = source;
}```
so should i blit the source to the oldTexture?
i guess to copy i do
oh you probabbly do
use Graphics.CopyTexture()
no?
this is done GPU side so it's a pretty efficient function
so at the end of the method i should add
material.SetTexture("_OldTex", previousFrameTexture); Graphics.CopyTexture(src, previousFrameTexture);
so that the shader first reads the texture before it gets updated
Why does my fish look so weird in Unity? I did the UV editing in Blender, exported the fbx. In Unity, I created a new URP unlit texture material and used the same texture I used in blender. What's making this happen?
The optical illusion is not intended
I think it's the normals that are maybe flipped or something with backface culling
Hm, the normals don't seem to be flipped in Blender. Not sure what backface culling is, gotta google
in the material if you use urp you have an option here for renderning the faces
maybe that will work for you if you change it to both
That only seems to be for the regular lit shader, not the texture unlit one
oh then i don't know what could be wrong
you can maybe try and make a custom shader with shader graph if it's not too complex to recreate
You're using a Sprite shader, that would only really work on 2d sprites, not 3D objects.
You can see through because sprites are transparent and don't write to the depth buffer, so faces can't easily be sorted
I wanted to ask myself what would be the way to convert RGB values to a single value? like rgb to b/w
There should be a URP -> Unlit shader that would work better if you need it to be unlit. Or create your own via shader graph
Oh, you're right, plugged the texture into the base map in the regular unlit (that evaded me for some reason) and now it looks fine
this is my current setup, i don't think it's actually correct yet
i mostly just want to make it easier for the smoothness and metallic map because the default shader requires it to be in alpha or something and i don't have a good tool for that
this rim should be more smooth but currently doesn't seem right
Vector4 into a Vector1/Float port would just use the X/R channel. Could use the R output instead, but if the textures are greyscale, it doesn't really matter.
yeah maybe i should look for such a tool to combine the metallic and smoothness map
it doesn't seem to change it
hello guys, is there a node in shader graph thats literally output = input
Should be able to find some "channel packing" tools that can do it. Or use image manipulation like photoshop/gimp/etc.
yeah, i want one that could just be inside unity with 2 image inputs or something
Preview would do that. In 2021.2+ you can also double-click a connection to create a small reroute node, if that's what you want
the double click is exactly what i needed, thanks!
(in urp) Does anyone know a good solution for making semi-transparent objects cast shadows? Alpha clipping and dithering shadows don't give me the results I'm looking for. I need the opacity of the shadow to match the opacity of the object that casted it.
did this work?
that did not, i can try again to be sure
hmm
you do not need the variable at the top
for the old frame
you can read from _OldTex
next frame
i'm pretty sure it doesn't get flushed
what variable on top?
private RenderTexture material
any way to change a shader graph node fast without making a new one and reconnecting all the paths?
like if i wanted to convert a simple noise to gradient noise or something
wait no here:
private RenderTexture m_lastFrame
void OnRenderTexture(src, dest) {
// do stuff with m_lastframe
m_lastFrame = new RenderTexture(src)
}
try this
and this
private RenderTexture m_lastFrame;
void OnRenderTexture(src, dest) {
// do stuff with m_lastframe
m_lastFrame = Graphics.CopyTexture(src);
}```
the second one is more efficient if it works
also, why aren't you using URP
i'm using the built in one just to test stuff around
and because i didn't want to use shader graph
i see
how come?
i wanted to get a little more confidence with HLSL since i never used it before, when doing shaders i always used GLSL
i see
i mean can't you also use HLSL in urp?
i think not with Graphics.blit etc
Hey guys I have a question:
I am working on a edge detection outline shader graph. Essentially I want to draw lines where I want to define them. I had the idea of using a color id map to define where the edges are (the edges are between where the colors change) as seen in the image. This way I can use color based edge detection to find where to draw the lines. Then of course the regular opaque map as seen in the image. I want to use the color id map to draw the edges from the camera's point of view, but render the color map and overlay the calculated lines. How would I do this because It doesnt seem that I can do this with a fullscreen shader graph. And there isn't a way that I know of to do this from an object shader.
There's many ways to do outlines
This is always a good starting point
https://alexanderameye.github.io/notes/rendering-outlines/
Yeah I’ve read through a lot of them
None of the methods really fit my needs though
The closest one that got there was the one that was used for mars first logistics
I decided to use a color map instead since I couldn’t really unpack how he got surface ids to work
So I had this idea for an improvement to the way I render lines in Mars First Logistics. I've had a lot of people ask about how that works, so here's a (somewhat technical) thread about it and the improvement I recently made.
1930
295
Here is the thread for that
If you're in URP you'd probably want to look into writing a custom renderer feature to re-render your model into a separate target with an overrideMaterial/Shader to render the colorIDs. Then pass that into a global texture property to sample in the fullscreen pass.
(If you use overrideMaterial you'd need to pass the ids into vertex colours. overrideShader keeps properties but I think it's 2022.2+ only?)
Ah I see
So essentially override it so you render it once with colorid then pass it to full screen to draw the lines then after you render the regular opaque map?
Basically yes, though you may want to render opaques first, then render the colorIDs so you can use the camera depth target still. Otherwise you'll see lines through objects that don't appear in that colorID pass.
Oh that makes sense
Thanks this helps a lot!
Before I go surrender myself to the hells of rendering stuff I wanted to ask, do you happen to know anything about Face ID stuff? I read somewhere that you are able to give each face of a mesh an ID I was curious about that.
If it helps I've also got this feature which is fairly similar (renders objects into separate buffer for a glitching overlay effect)
https://gist.github.com/Cyanilux/d16dbfec869dbfb690426c837745679c
But it uses RenderTargetHandle which is deprecated in favour of RTHandle in Unity 2022. You may need to research into that.
Could keep the blit but removing that and using the Fullscreen graph + feature is probably better. Would also want to add that depth target as a second param to ConfigureTarget.
Not sure really. I'd look into passing the IDs into vertex colours though if you aren't using those for anything else. That seems the easiest way to me
Yeah the thing about that is I don’t want to use the full screen shader if I had the choice or if it were possible I would instead have it a per object shader
I don’t want every object to have edge detection
Oh yeah, the problem with vertex colors is it seems that it has a gradient which won’t play well…
If there is a way to assign something like that to faces that would be helpful I’ll still have to look further into it
If you only do the edge detection on the buffer created by the colorID pass you can still control which objects have the edge detection (you'd specify a LayerMask in that feature).
But yeah, it's still a fullscreen effect and may be cheaper to do it in an object shader. In that case you would do the colorID feature first, then render those objects again in the opaque pass while doing the edge detection.
True
Yeah, can duplicate some vertices to get around that.
Could alternatively use an additional UV channel, that would basically do that automatically. Unwrap each part, scale down to a single point, place somewhere on UV.
Oh that’s actually genius
Though it might be a pain in the butt literally just rig edges so you have a bunch of islands that would help it
But it could also be problematic for stuff like weight painting
Hey all, so I have this shader, it basically lets me bake Animations into a texture, then run it back through a MeshRenderer and show animated vertices, without actual Skinned Meshes, and it's great. This was the original github repo I built it upon, and ive changed a ton of the code but the shader itself it pretty much unchanged:
https://github.com/piti6/UnityGpuInstancedAnimation
I've been trying to add things like a simple shadow pass, or depth pass, or get it working with Enviro Fog, or even transparency, but I don't really have any knowledge on how writing shaders works, and was just wondering where a good place to start might be?
Here's what it looks like when applying Post FX like Fog, or even just enabling shadows- note the ghostly cutout of the mesh in the render pass, this is what I'm hoping to add to the shader along with the Albedo color, which seems to be the only thing thats currently working:
and here's the shader itself:
Has anyone managed to get a "depth mask" shader working in URP such as discussed here: https://forum.unity.com/threads/depth-mask-shader-in-urp.855136/ So far most of my experiments have failed, and i'm not sure what I'm missing.
im trying to add voronoi cells to hue
but why is the result only red from the color node and not how the Main Preview looks
Are you using the default Unity Quad mesh or something else
the default unity quad
if i just connect the cells to fragment color, its fine
and with scene color its fine too
so probably something wrong with my color conversion
yeah I'm not really following what you're trying to do with that
From 1, 0, 0, to HSV you'll get I think... 0, 1, 1
the output is red like here
but im adding voronoi cells to the hue
and the shader graph preview is what i want
but scene/game render is still just red
if you output the value from the Add you have there, is it just white?
and what does it look like when you feed it into a preview node in the graph
perhaps it would work if you fed it into a frac before combining it
I am also a little weirded out by how the gradient in the voronoi just completely disappears when you get to the colorspace conversion
gradient disappears because im using the cells
Ah that makes sense. Still, my other questions should lead us somewhere
so i connected the add output to preview and to that conversion as well
Can you just put a frac inbetween the add and combine?
I have an issue where when adding a detail normal map, my normals completely mess up! I had to do some extra math to figure out how to use the green normal maps instead of converting them, which works for the base normal map but not for the detail one. Does anyone know why thats happening? Its really been bugging me.
and still just red in scene/game
it's also red in the preview now?
yes
I think that confirms my suspicions but now I just need to think about the workaround
so what do you think is the culprit
I suspect that the Hue you're getting out of your color is 0 in the graph, but it's 1 in the material.
So when you're in the graph, you're essentially just getting the voronoi, but when you're in the material you're adding the voronoi to 1, and the hsv conversion does not wrap
But I don't totally have the maths in my head and thought the frac would have just fixed it, wrapping the result to 0->1, but maybe I'm missing something
im just using the automatic material when you open that arrow from a shader
I know, it doesn't mean the preview isn't different to the material
I feel like I have no idea what is going on with the voronoi cells, you output it to color and it looks fine, you feed it through a frac node and get black? I don't get it
the more i try the more im confused 😅
okay i have some colors
still probably doing it in a weird way tho
I don't understand how any output from the voronoi node through a frac is black, I feel insane
it's like it just outputs 0 when used with certain things
I uh... am going to give up understanding this and chalk it up to 'shit's fucked'
same 

Like, I am used to the shadergraph preview being generally broken and unreliable, but I can copy the code it generates, add a frac of my own and I get black. Replace the frac with a basic while loop that should do functionally the same thing, and get what I expect. I just don't get it. Either I have a fundamental misunderstanding of something, or the voronoi node compiles reaaaal weird
is there like, normalised object coords like the top of object would alway be y = 1.0 and the bottom y = 0.0
not that I know of
You'd have to use mesh renderer bounds and pass them to the shader with a script
Hey I'm using Unity 2019 for the purpose of developing maps for VRChat and I was wondering if anyone knows about, or has a shader that does the following: (apologies if I get some terminology wrong) I wanted to blend two textures preferably with heightmaps to break up the repetitiveness of certain textures. I see this in Overwatch a lot and I've attached an example. Is there some shader that would allow me to paint this transition onto my models, like on walls, floors, etc? I've also seen this type of thing with many terrain shaders such as microsplat, but I know it's probably different for things that aren't terrain.
Hey, I'm writing a little custom HLSL function for Shader Graph. I need one of Unity's built-in matrices _Object2World, but I have no idea how to properly include it in my .hlsl file. Any hints?
Think I solved it, I forgot they renamed it to "unity_ObjectToWorld"
you can use Lerp(texture1, texture2, heightmap) or similar; it is functionally the same as for terrain (blending between two textures based on some deciding parameter)
you could paint vertex colors into your model (I think polybrush can do it?) and inside the shader just lerp between two textures using the vertex color
(it would be a very begginer friendly shader graph 😉 )
can noise() be used in a surface shader?
I didn't know that would be possible atleast. why don't you just try yourself?
i have been trying actually
instead of something saying its undefined, i'm getting cannot map expression to ps_5_0 instruction set at line 26
said line 26 is where noise() is
So I don't think it's possible. https://forum.unity.com/threads/cg-noise-function.25970/
how did google not show me that
hm
ok, might have to do random a bit differently
ty
maybe have it read from a property that is randomly set on the c# side
If you only need one value that is constant within the same frame, that would be good idea. if you really need to use noise functions in your shader code, you can use noise functions made by others
want to randomly clip() things and reading the ms site on hlsl showed noise, was hoping a built in function would work for it. have seen a few examples of external noise functions but i don't think i fully understand it
i'll log fps with setting on the c# side and then using a external noise function in the shader, see which one is faster
probs the shader one
shader by far
c# one could be good for easily controlling the time it does choose a random number (and in my case, changing what things get clipped) but if you want to do it every frame, shader
Hey, I have a little problem:
-I have a shader that can make objects only render at a certain radius of the player (like cutting the part that isn't visible)
-I have a script that makes an edge collider have a modificable circumference arc shape
How could I combine this two both (make objects only render inside of that shape)
If you have any question or something you didn't understand, let me know
Anyone know why my ".shader" is pink? I'm not very good with shaders, sorry. It's just from the asset store.
I'm also using URP and I converted the materials and textures and such but it didn't change anything
unless an asset from the store says it's URP compatible, it's unlikely to be. You could try to look at the code and recreate it in Shader Graph.
Alright thanks
I'm not sure what your end result actually looks like.
but if you're using a sphere radius and you have a collider that same radius, it sounds like you've "combined" them.
I mean, you've limited rendering on the shader side, and you've got a collider on the CPU side.
What can't you do?
I suppose you could put a sphere of radius ? on the player and have it render only to a stencil buffer, and then have all the other objects render only inside that sphere. Of the objects you care about, that is.
not like that
if you can elaborate more on what your trying to do it would be easier to help
well there is alot of things to keep in mind
I know you have that function running on the vertex shader
so the operations your doing are run for every vertex on the model
so with v.vertex you are grabbing the current vertex position
and with v.normal
you are grabbing the current vertex normal position
now
it is important to note
that the vertex normal is in object space I believe (someone can correct me if I'm wrong)
and the vertex position is in object space
basically you have two things in object space
now
the problem with this
is that you are sampling a texture
which normally has alot of detail or info on it
but remember
you are doing all of this in the vertex shader
meaning that you are only sampling basically like a low quality/blurry version of that texture per vertex
you following @grand jolt ?
there is a way but there are some things to keep in mind
because you might be getting what you want or you won't
but to finish the thought exercise, it's safe to assume that the normal map you are trying to sample is a tangent space normal map
not an object space normal map
tex2d is for surface shader
use tex2dlod for vertex shader
note that the original v.vertex is in object space as @prime shale said while normal texture is usually in tangent space
thanks for summary thats perfect
lol
but what you need to do is to transform that tangent space normal map into an object space one
you can do it right in the shader with some math if you know it
or if you can you could just bake an object space normal map
or maybe bake it to vertex color if he doesnt use it 🤔
true, something else you could do
would eliminate the need to sample a texture
after sampling the texture it needs to be transformed
- 2.0f - 1.0f
or just use UnpackNormal(normalTextureColor)
Anyone know what i might be missing from this shader to correctly pass shadows and depth, and integrate other Post FX?
This screenshot is using EnviroFog, and EnviroVolumeClouds, but if i remove those and use Unity Fog it seems to render properly. It's a GPU animation shader that does some bone vertex magic to change whats being displayed in the meshRenderer itself, but I'd like to pass along everything besides the Albedo, Metalic, etc
try adding "addshadow" to the pragma line
DUDE thank you, thats INSANE that it was that simple lol
I've spent weeks thinking maybe i need to pass some Fixed4 or float4 or something i dont understand yet, but nope that was enough. Thanks a ton!
fixed4 is just like float4 but it s fixed has 32 bitstotal whereas float4 has 32*4 I think
Is there no way at allto set your own struct as a uniform in a shader?
Well, not bytes but bits, otherwise true
and do you know if there is a way to set your custom struct as a uniform in unity, without having to pass it as a buffer?
This is only supported by the OpenGL ES 2.0 Graphics API. On other APIs it becomes the lowest supported precision (half or float).
This is the lowest precision fixed point value and is generally 11 bits. fixed values range from –2.0 to +2.0 and have a precision of 1/256.
Fixed precision is useful for regular colors (as typically stored in regular textures) and performing simple operations on them.```
https://docs.unity3d.com/Manual/SL-DataTypesAndPrecision.html
"fixed" doesn't really exist in HLSL DirectX. It gets promoted to half. But wait! Half gets promoted to float on DX10 or later. lol.
So if you're counting bits, and you're worried about data size, you have to take platform differences into account, at least at the register level. Storage in memory might vary, like in a struct...not sure...but the engine will take care of setting the right values on the elements when you do the set operations.
The 4 (or 3 or 2) on the end of the scalar types promote them to vector types. So half4 is 4 component vector of size "half" on the platform. Half is equivalent to half1.
fixed is seldom used anymore. OpenGL 3.x doesn't even use it, IIUC. It's there for backward compatibility with OpenGL 2.x.
hi guys, im trying to display character B all over my 3d gameobject i made a custom shader but doesnt seem to work, like i want it to display character b with golden color ona white 3d gameobject and the b's will be moving from right to left
How are you planning to display "B"? I see no texture there with the letter B
Actually I tried for the shader to write character b in golden or yellow color but it didnt work
Its supposed yo take a ehite or light colored texture
Nope, the collider is an arc of circumference, so the thing I want to archieve is to get things rendered only inside of that arc of circumference
what's your B map?
also, what's the shader?
send pics 🙂
Can I get bqck to you after iftar?
Its almost iftar time
sure
Im fasting
Thankyou would be great if I can resolve this
❣
AND TODAY IS MY BIRTHDAY TOO AHHA
no problem, feel free to drop me a message later
happy bday!
Thankyou 🥰
how can i sample more than once in shadergraph?
wait
i mean like multi-pass
not sample
Shader "Custom/Alphabet" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Speed ("Speed", Range(0, 1)) = 0.5
_Size ("Size", Range(0, 1)) = 0.2
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float _Speed;
float _Size;
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target {
float2 uv = i.uv;
uv.x += _Time.y * _Speed;
uv.x = fmod(uv.x, 1.0);
float2 offset = frac(uv * float2(1.0/_Size, 1.0)) * _Size;
uv -= offset;
return tex2D(_MainTex, uv);
}
ENDCG
}
}
FallBack "Diffuse"
}
any idea? @cosmic prairie
I'm trying to optimize this HLSL code:
if (a >= b)
output = x;
else
output = y;
I've tried to do it like this:
output = step(a, b) * x + step(b, a) * y;
but the second solution seems to glitch when a and b are equal (sometimes it returns y, sometimes it returns x+y).
Also for some reason changing >= to > in the first solution glitches between x and y values.
Are there any suggested optimizations to get rid of if statement or should I just stick with it?
The compiler might already not be "branching" here so it may not make a difference, or if it's based on uniforms/properties it's probably fine. But otherwise you could do output = (a >= b) ? x : y;
Inlining definitely makes it look nicer. It also seems to not glitch, so I guess I will stay with your solution. Thanks.
A question about Compute shaders, I'm trying to set a float in a compute shader using heightComputation.SetFloat("rimWidth", RimWidth); in a cs script (where RimWidth is a float), but the shader takes the value to be 1.050254e+09 when it should be 0.3
What could be causing this
I suggest checking if all the values are properly set up. I would probably debug each value individually. Keep in mind that variable references are often different from their display names (often starting with _), it's worth checking if the property name is right.
Just realised that after days of confusion, rimWidth was defined as a float in the shader
I mean int
Thank you
regarding the 16 sampler and 128 texture limit in Unity, does it mean 16 sampler state limit?
can i make 2 shaders work on a single gameobject at the same time/?
No
There are ways to render an object a second time on top of itself with a different shader but that's often not very practical
i have two shaders one fro dispalying a character texture on top of the 3d gameobject
and the second one i need for setting opacity of the 3d gameobject
and need both on same
Technically one Renderer can have multiple materials, but it's for other cases. If you really want to process Renderer with multiple shaders, technically you could do some postprocessing, but it also seems to be a tool for other scenarios.
If I understand you correctly, you want to have select texture and transparency for the same object. Most shaders can do both things. When it comes to custom shaders, it should be quite easy to add a transparency setting if needed. I would recommend sticking to a single shader.
so adding both functionalities to a single shader?
Yep. If those are the only needed functionalities, then built-in shaders should be enough.
hmm not sure why you need that size thingy in fragment
let me show you the refrence of what i need
but should work if you have plugged in a texture that has a B in it
This is "HugoBoss_3_propositions.mp4" by Burhan Ahmad on Vimeo, the home for high quality videos and the people who love them.
when the character appears on corresponding screen he has those b b b b b b b b b b all over it i want that and then a opacity thing to differenciate between different gameobjects
I can't really watch it, it wants me to log in
can you get it on streamable?
just a drag n drop
so you want to exactly replicate this?
yes/
how do you want to flatten the character?
so you need no 3D view?
no
is the camera stationary? does it not rotate?
because then u can use the world position as UV
no camera will stay at the same positiono
or even the clip position
basically ill be getting real time data from a signalServer
and im gonna use that to instantiate gameobject that will replicaterealtime movemnet of humans
and these gameobjects shown will be represented like that
try looking into this, I need to got to sleep, it's past 1 AM haha, will check on the chat tomorrow
why is my second pass not being executed?
Shader "Custom/Shader"
{
// properties ...
SubShader {
// First pass
Pass {
// Tags ...
ZWrite off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag_firstpass
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata {
float4 vertex : SV_POSITION;
float2 texcoord: TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata v) {
// ...
}
sampler2D _CameraSortingLayerTexture;
float4 _CameraSortingLayerTexture_TexelSize;
float _Size;
half4 frag_firstpass( v2f i ) : COLOR {
// ...
}
ENDCG
}
// Second pass
Pass {
// Tags ...
ZWrite off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag_secondpass
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct appdata {
float4 vertex : SV_POSITION;
float2 texcoord: TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata v) {
// ...
}
sampler2D _CameraSortingLayerTexture;
float4 _CameraSortingLayerTexture_TexelSize;
float _Size;
half4 frag_secondpass( v2f i ) : COLOR {
// ...
}
ENDCG
}
}
}```
this is my first shaderlab shader
i've done a fair bit of research for the past few days in shaders
btw, if i change the order of the first pass and the second pass
still, it is only the top pass that gets executed
which makes me think that the top one is being ran last and overwriting the texture somehow???
or the bottom one is just not being ran at all
Does anyone know how to add Dithercrossfade into a vertex lit blended shader?
i.e the procedure
if using URP, use the Dither Node.
https://docs.unity.cn/Packages/com.unity.shadergraph@12.1/manual/Dither-Node.html
hey i have this shader applied to a gameobject but if i apply the same shader to another gameobject alll the changes of one gameobject are copied in the other one
how to fix this
it's built in RP
this is my code
Shader "Custom/Alphabet" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_TileX ("Tile X", Range(1, 10)) = 3
_TileY ("Tile Y", Range(1, 10)) = 3
_Speed ("Speed", Range(0, 1)) = 0.5
_Opacity ("Opacity", Range(0, 1)) = 1
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
CGPROGRAM
#pragma surface surf Standard alpha
sampler2D _MainTex;
float _TileX;
float _TileY;
float _Speed;
float _Opacity;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandard o) {
float2 uv = IN.uv_MainTex * float2(_TileX, _TileY);
uv.x += _Time.y * _Speed;
uv.x = fmod(uv.x, 1.0);
uv = frac(uv);
o.Albedo = tex2D(_MainTex, uv).rgb;
o.Alpha = tex2D(_MainTex, uv).a * _Opacity; // Use alpha channel to define opacity of the object
o.Emission = o.Albedo * 0.5; // Add some emissive effect to make the texture appear "golden"
}
ENDCG
}
FallBack "Diffuse"
}
i cant see the character in game view even if i set th eopacity to 1
when did it turn into a surface shader 💀
this makes no sense man xd what are you sayiiin
😄
it was always like this
like when i apply it to a material
and if that material is applied on another gameobject both go through same changes
Try this one, looks simple enough to implement
https://github.com/gkjohnson/unity-dithered-transparency-shader
if they are using the same material then sure, the changes will be applied to all of them
make them use different material (either manually duplicating the materials, or by code)
okay, and what if I instantiate multiple gameobjects
@cosmic prairie
so I tried alot but that opacity thing was always messing up, I think I will use a 2d sprite instead as its gonna be a side view anyways
and I can just change the alpha of image color from code
does anybody happen to have any 2d sprite of such sort, that is a maybe male humanoid?
use material property blocks
create a materialpropertyblock property in your code, in your start / inti method create a new instance of it
when u want to change a material value do the following:
yourmeshrenderer.getpeopertyblock(yourpropertyblock)
propertyblock.settexture/setwhatever()
yourmeshrenderer.setpropertyblock(yourpropertyblock)
or if you only need a finite number of materials just keep track of them and assign them in the sharedmaterial property of your mesh renderer
don't u need to animate it?
opaque shaders wont get any transparency
Yea thats the problem, i cant use 2d
What do you suggest
change rendertype to transparent add renderqueue transparent
iirc rendertype doesnt affect transparencies, it's purpose is more for shader replacement 'tags'
might aswell do it properly
or u can just do clip() or discard()
thats like a cutout
instead of a partial transparency
btw if u need hlsl commands check ms docs, for shaderlab and unitycg check unity docs
try disabling ztest in the second pass
okay thankyou
ill have a look into it
is that for builtin or urp?
from the code, seems like built in
yeah seems, wasnt sure tho
Hello !
Is there any way in a Lit Shader (URP) to cancel the Ambient Light's color ? I tried a lot of things but it's always ending up by having a small color difference...
I also heard about setting my renderer's LightProbeUsage = CustomProvided but I have no idea of how to setup the entire lightning after that
urp shaders are... complex
check out block shaders from their forums, maybe with those its easier to change
how do i get rid of the seam line without a custom noise tex? (using on a quad)
use a seamless noise algorithm
this has periodic noises
try those
thanks!
it doesnt have uvs
which wouldnt even be a problem if the world space thing or the clip space thing was implemented
that I mentioned
there is also triplanar mapping if you don't like uv's :3
I'm really new to the whole shader graph thing, and I'm honestly really lost
I know I may have overcomplicated things with this method, but I'm trying to learn to make things that I could reuse across multiple projects
I have sprites for houses and stuff, and I want them to me colored according to the team's color
I have 2 sprites for each house, one which is the sprite itself, and another which is sort of like a map that shows which areas should be multiplied by the team's color and which shouldn't
Anything painted black in the map should be ignored, and everything painted red in the map should be multiplied in the sprite itself
I tried working for hours on making my own shader to do that kind of thing, but I'm too new to this (literally learnt the basics yesterday) to actually implement it.
This is pretty much all I have
I've been trying to apply this shader to Text (TMP and standard Text components) without success. With TextMeshPro, i can't even do anything but with Text, it just outputs black. Any idea how i could do that? I'm not that knowledgeable with shaders
Here's how I would do it
I haven't used it yet but thank you, you're awesome for giving such a detailed example haha
Oh nevermind. I just changed the threshold and it works now
It's working, I love you
thank you so much!
how I can make motion trail shaders for character any idea
can post processing shaders access the stencil buffer?
to just test if it was working i just put in this in:
Stencil {
Ref 255
Comp NotEqual
Pass Keep
}
ofc i have something that should be writing to 255
ok i think ive gotta find a different solution stencils wouldnt work the way i was hoping it would
just set the alpha to 0?
you can se that the alpha is set to 1. if you want to make the white transparent you can use out of the comparison node as the alpha and plug it in stead of using 1
you might need to invert it first though
I have a sinewave I am using as a shoreline that I am not sure how to adjust to function the way I want.
Currently the peaks and valleys are the same size across the whole effect, giving it a uniform band size as it emits.
What I want to see is the peak to narrow the further out it gets, for the inner edge to move faster than the outer edge so that it narrows 
But so far nothing i've tried has achieved that
visual diagram of what I mean
an attempt that I thought would work but doesnt
the bands remain uniform width, I want them to get narrower the further away from (0,0) they are
Oh getting close, I think I figured it out; just a matter of adjusting the values
you want something like this?
Yeah that looks right, is there a more efficient way to get that than what I am doing above?
I did it like this:
oh yeah don't forget to add the time node I forgot that
Looks good 👍 Will adapt that in
Can someone please help me? Im struggling alot with URP and 2D shadows, and now my sprite is black and the shadows are still not working
that alpha is for both colors, i wanna control the alpha of the white color only
yeah, you make a mask for only the white color and plug it in there
and how do i do that ? lol
you are already using a mask to blend white and red right? you can use that same mask for the alpha. though you might need to invert it
Where do you add time in your example? I added it to the first Add and the output is very strange
Into the add node which does not have a second input, if you do that you should get expected results..
Hey everyone. I bought a shader which includes a position transform to simulate tree sway in the wind, however, using it makes it not able to bake any lighting (baking loop). I checked the shader and I found a deprecated transform. I tried to replace it with the new transform node, but its still giving the baking loop. Removing this function fixes all problems. Any one has a clue what I can look for to fix the baking loop while still having the tree sway function?
ztest is disabled in both passes
oh wait
ztest
what's that
it did not seem to work
Hey, I am having some problems in making my shader up to work, could someone help me via dm? I would appreciate it so much
I've been reading a book about shader programming and they do this to calculate binormals:
o.binormal = normalize(cross(o.normal, o.tangent) * v.tangent.w);
Why do they multiply the cross product by the w value of tangent?
Isn't the w value just 0?
ztest always
that way it will ignore ztest and always drawn, I think
nope
still only the first pass being ran
this is the shader
I'm on the 2D renderer and _CameraSortingLayerTexture is the screen
(that i wish to use as the background)
I don't know if it varies in 2D, but URP doesn't really do multi-pass shaders - when applied to materials on objects at least. It depends how you're applying the shader.
Even if the second pass does run, I think it would also just draw over the first. For a 2-step blur you'd need to input the result of the first pass into the second.
Usually you'd apply the blur using blits to handle both of these (e.g. first pass with _CameraSortingLayerTexture as source, to a temp render texture destination, then second pass with that temp as source, camera as destination)
ah
yeah i figured that but i just do not know how to execute
i am very inxeprienced
My understanding is that the tangent is aligned to the X axis of the UVs and binormal/bitangent is aligned to the Y axis. So the w value stores -1 or 1 to make sure it follows that axis, as the UVs could be flipped depending on how the model was setup.
can you make a temporary texture using a shader?
or do i have to use c#
thank you for your insight though!
btw, only the first pass executes as the second is the vertical blur but it's only blurred horizontally
Ideally you'd use C#
(well, technically you can create Render Texture assets in the project window and assign them to a second camera... but that's kinda messy)
i see
(not just vertically, which would imply the second pass is overwriting the first)
I think you might be able to use my blit renderer feature to handle it too, as that includes a "Texture ID" destination/source. If you still have that
I'm sure there's also blur renderer feature examples out there that handle both blits in one feature
i heard that it's more efficient to do it in multi-pass
but i just could be very wrong
It's still multi-pass, just combining the two blit calls into a single feature
oh i see
Might be slightly easier to setup that way
i see i see, okay thank you i will look into that 👍 :D
why does my shader i made not work on my UI element? it works fine on a sprite renderer
these two are both using the same material but dont do the same thing
how do I make a texture for just the green one? I have a similar rectangle object, I just need to know how to make the texture, which is like a horizontal striped pattern thing, that wraps around the rectangle
Is it possible that youre not supposed to use the time node for generating patterns and stuff? It breaks the light baker
Or are you supposed to lightbake first, and then apply the timenodes
I dont think that matters whats the issue anyway
And if its lighting go in #archived-lighting
Ok thanks 🙏
in blender, ive got something like this, which allows me to set the color of the iris
ive modified the eye to now look like this
and am looking to make a shader so that i can color the green and blue independently
i havent really used the shader system before though, so im not really sure where to start
I guess, start by learning shader graf or hlsl, whatever you more prefer
i figured it out
hey im having these errors, altought my shaders work just fine and nothing crashes, they also appear in build in the dev console but yet, they dont affect anything
how can i get rid of them? please ping in reply, thanks!
i am not modyfing and refering to _MainTex anywhere in the code
i dont have any references to that shader in the code
it's just a material that i dragged&dropped to an Image
this is the shader graph
material.mainTexture counts as _MainTex too
im not refering to the material at all
You've assigned this material to a canvas image ?
This component will try to assign the sprite to the _MainTexture property of the material, and this is where the error comes from
yes, to a canvas image
changing the texture property name to _MainTexture in the shader graph will fix it?
It will :
- fix the error as the canvas image will be properly able to assign the sprite (even if null)
- allow you to use the sprite of the image in your shader without having to assign the image to the material yourself
it is already as _MainTex
should it be _MainTexture?
Sorry, yes, _MainTex , but the important one is the Reference name
it is a problem then, when changing the Reference name to _MainTex the shader doesnt work properly on my UI
this is the UI shader, a horizontally scrolling race flag
this happens after changing the name
Did you assign what I think is the flag checkerboard texture to the image component (in the sprite property)
oh, so it might reset back to None when changing the Reference name?
Indeed, changing the reference name will loose track of the previous value, but on to of it, if the sprite in the image component is none, it will assign "none"
Sorry for idiotic screenshot i on phone now. I have a problem. In my 2d game, i do a shadows based on transform matrix model in shader graph. It duplicates texture and do offset based on rotation. But i noticed that transform matrix model dont work when objects batched it always return the same value. I need Up transforms vector to calculate. In Example Material change color based on rotation. Triangle works but 2 squares are batched so they always the same.I can change material in script to broke batching but is bad for performance. So how can i get up transforms vector to do with batching? Help me please.
can i have some help recreating this shader from blender in unitys shader graph, its a sphere with a radial gradient
You can't, at least not directly.
Those two squares, when batched, are one model with one transform
I suppose you could stuff the "up transform" into some uv(s) data on the verts.
But a better way is to try to use GPU instancing rather than batching, if your use-case allows it.
Quick Question: ... is it possible to spawn meshes on a surface using shader graph URP. Basically what I'm looking to do is create your typical moss shader that only appears on surfaces facing up, but I'd also want it to spawn in alpha planes for the fuzziness... is this possible? If not, anyone got any suggestions as to what would be the best way to achieve this. cheers
my shader in blender looks like this
I im beginner in shaders. I dont have this shader now . But i have shader in example.
alpha planes? You mean transparent queues?
can someone help with my thing chatgpt is hallucinating
You may wish to investigate snow-shaders. They "spawn" snow on top of objects. In your case it's green and textured for moss.
You don't normally want to generate meshes in the shader, but you can modify them to generate thickness.
You CAN spawn triangles in a shader, they're called geometry shaders, but you have to have something to start with and they're SLOW so they're generally avoided if possible. What's normally done is to modify the underlying mesh.
poly fins with an alpha texture to create the fuzziness of the moss.
just ask right away
You could generate planes and blend in an alpha queue, I'd suppose. Like how terrain blends with a splat map, but blend with the background.
thanks
scroll up please my question is about 5 messages earlier
i need help my fellow game devs
Unity Shader Graph - Rock Blending with Moss or Snow Shader Tutorial
In this Shader Graph tutorial we are going to see how to create a shader that gives the illusion of Moss, Snow or Dust accumulating on top of a rock, road or even a roof.
It can have other purposes like making an object look wet from water or you can blend between materials....
I've GTG for work. Have fun gang.
What you're asking isn't possible with any built-in features @sick sparrow. But it might be possible to create a script that you can run manually to process the scene and instantiate meshes in the relevant areas. You would have to build the script yourself though
cya 
am i shadowbanned
why are yall talking about modifiying gpu shaders mid render cycle but you cant tell me how to put a gradient on a sphere
No, but I don't have time right now, someone else will though. 🙂
Gradient + Sample gradient is what you want @haughty tendon
thank you ole
Thanks for the link. this is how I would usually do it. but I'm looking to create somethign a bit more high-end with my current scene and was looking for a solution that would look good close up. Basically imagine I'm just trying to spawn tiny blades of grass on any particular surface.
but it needs to be mapped to a pshere
the gradient requires something to plug into time
i mean sample gradient
thanks for the reply. 🙂
so probably y
if you want the gradient to change from up to down, you could use the y component i think
this is what i want it to look like
gradient + sample gradient doesnt work you need some other magic
yes, you need to use the y component as time
most likely you want it in object space
so you split the position, get your y (aka r g), and plug it in time
Oh, well then you DO want to generate meshs, like a grass shader (good example). Maybe you want both things, for LOD type of implementation, because generating meshes for far-away things would be expensive.
But yeah, grass shaders are a good example of that.
So have you tried that type of implementation, why didn't it work?
(Gone now, later)
@finite tree thank you you are very kind
one final thing how would i change the scale?
scale of what?
the gradient i think , maybe i just need to create an open value and assign a gradient that i make via script
im sorry, can you please illustrate what you mean by scale gradient?
i think its a porblem i need to research on my own first before wasting others time with something i can probably solve on my own im sorry for asking that latter question 😦
Hey, I am a complete newbie to materials, shaders, etc.
Making a mobile game in Unity and I am currently using no scriptable render pipeline (or at least it says "None" in my project settings) if it's relevant.
Is it possible for me to place shader / material on Image (Canvas) component (Not SpriteRenderer)?
If yes, can I have one shader / material that I can just place on multiple images that would make them black and white?
I also saw the possibility of using Graphs to create shaders instead of writing them. Is this viable with these? (When I click on my shaders file it opens up code always)
Then you can create a _MainTex texture parameter, which will read the image from the UI image
I tested it in shadergraph here
But if you're on the built-in render pipeline, then you need to be on the newest version of unity to have access to the shader graph
2021.3.16f1 is the version I am on
Oh just had to reinstall the package
Thanks a lot ❤️
why does my shader work in unity but not on the sphere i imported from blender
can you show the difference?
you are using r, im sorry for my mistake earlier
y = g
xyz/rgb, you wanted to use the y so g
i switched it for the x axis
it still not fixing it 😦
and it only covers half the sphere
in the shader graph
you can see in your screenshot the bottom half of your sphere is all red
looks like different orientation, unity's sphere has y up orientation while blender has z up orientation
na it just paints the whole sphere one colour
for that, you can use the remap node since time in gradient sampler expects 0 - 1
thank you
There is no solution for this? That is very strange.
If you are talking of static bathing, then it is expected, as basically static batching is merging meshes together, nuking their individual transformation matrices on the way
Is there any other way to get the rotation vector. To make it work when batching? For sprites.
sorry to interupt but @finite tree's solution works in the shader graph but when i apply it to a high poly sphere imported from blender its just one colour and i dont know why
and does it work on unity's sphere?
you could google how to export blender objects so that unity is happy about it, that could be the problem as rakyat said here
yes it works on unitys sphere, and updating!!! i found it works extra good on probuilders sphere
so i think ill just use that if you cant come up with a better solution!
Hey, so I have created Unlit Shader Graph GrayScale (I want to place it on my Image (Canvas) as a Material).
I created GrayScale Material and placed the material on my Image. How do I assign the texture or the float value parameter? :/
It should be in the material
if it works with unity sphere and not the tesselated sphere, then maybe export settings are wrong on your importet sphere
yeah that's why I am confused :/ all dropdowns are expanded in that picture
Can you show the properties panel of your variables?
This is how it looks for me by default, and then you can hide the maintex property in the material as well since it's assigned automatically
why are my exposed nodes greyed out in the inspector?
Do you guys have any resources for learning how to make URP shaders as a beginner in that space? All the ones i find are for the standard rendering pipeline, which makes them useless
Do you mean this one? Or this one
This
Have you pressed save asset in the top left?
Oh well, I have been pressing Ctrl+S in hopes it would save but it didnt :'))
BTW, Can I edit these values for example your "Saturation" dynamically through code?
maybe try enabling the override thingy button in the graf settings in shader graf?
Yeah for sure, you would use the SetFloat function and use the reference as parameter
Alright, thanks a lot. Helped me tremendously 🙂
i have a custom shader that is supported by SRP but i wanna convert it to URP, is there is an easy way to convert it ? i tried to let unity convert it but that didnt work + i have 0 knowledge in custom shaders
if its an hlsl shader its not easy if its shader graf its kinda the same and straightforward
Certainly not something you would call easy. Without experience it's not really feasible
i tried Override Property Declaration in Node Settings, and Allow Material Override in Graph Settings, but still greyed out
not sure did you make this, or was it downloaded?
idk, maybe create your own material?
works, thanks
@shadow kraken Would it be possible in my case Image (Canvas) shader somehow take into account the Color input (highlighted in image) on Image as well? Currently it has no effect and it is important to have effect when it comes to buttons :/
Yes, create a parameter with the reference _Color
And then multiply that over your existing colour
So it essentially takes it automatically for each Unity Script serialized field on Image and Sprite Renderer?
Not sure I understand
So for Unity Components - Image and SpriteRenderer I can reference _MainTex and _Color and it will automatically be taken as input in the material
Yes indeed
_Color ("Tint", Color) = (1,1,1,1) would be equivalent to Vector4 then?
As I can't have "Tint" in Shader Graph inputs
The reference is _Color, the displayed name is Tint
well if you write vector4 instead of color you will get 4 numbers you can work with, color will give you a color picker
The displayed name can be whatever you want
There is a dedicated parameter type for colour
Oh alright, I understand now
Thanks, I actually managed to learn a lot of Shader Graph today thanks to you 🙂
can i use fwidth for aliasing on a mask?
or i guess another question could be. should i implement the aliasing into the shader or let post processing do it?
Welp the _Color doesn't work (I saved this time :D).
I tried with both Vector4 and Color as type of input.
I also googled that Sprites (which I am not sure if it's my case as I am using Image(Canvas) component) use the vertex colors of the mesh for the colour. Any ideas?
This is how I validated it would work - I would have much darker images with the red color as input
https://answers.unity.com/questions/1441060/access-ui-image-color-in-shader.html
this further proves that it's in vertex info
Aha
This is because you're adding the colour before you're doing the colour correction
You should be multiplying the colour at the very end
Try that first @grand jolt, your setup works on my end with colour
I mean the Multiply works - it's the problem of Unity not taking the Color from Inspector and assigning it to the shader
The red is not applied
Even if you set the saturation to 1?
Yup, sadly it just keeps the default value and it never changes based on the set value on Image Component
If you change the value on Image Component does your image change as well?
Oh I am on a Built-in render pipeline so I don't even have that option I suppose?
What are your options?
Lit or Unlit
Then it might not be an option I suppose
The shader graph for BiRP is still pretty new
Are there any breaking changes when I switch to different render pipeline?
I didn't look into render pipelines before so I might be able to just switch easily?
Depends a lot on your project and how far along you are
I mean project is purely done in Canvas and via Images
Then it might be ok
But it wouldn't be too complex to do this shader in HLSL instead, as long as you just need the base features + saturation
I mean that's option as well I suppose, I'll check the URP first and see if that's the correct approach
Be sure to make a backup of your project
There's a Vertex Color node, that should let you get the colour afaik
Shader graphs really don't work that well on UI though, it doesn't have proper support for it.
It's kinda okay if you use canvas set to Screenspace-Camera, but Overlay doesn't work well - I think because it tries to draw all passes (including shadowcaster, depthonly, etc).
Also won't work with masking components though (like scroll rect)
Yes I am working with Scroll Rect and I am receinving "doesn't have _Stencil property" warnings already
Yes, that's also something that's handled in the written shader
But I believe I should be able to get _Stencil property and perhaps mask it in shader?
The colors btw work with the URP
(Although I have several errors now lol)
You could define them in the blackboard to stop the error, but you won't be able to mask with them. It's not used in the HLSL code of the shader, but the ShaderLab portion for Stencil operations.
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Shader graph doesn't allow you to add these for some reason. You could generate code from the graph, copy and edit that, but not a great workflow (it's then separate from the graph and you'd have to generate & edit every time you need to make changes)
I don't think I will be editing this changing this Shader afterwards - so how would I approach the generating code and masking with stencil? Is there some resource you are basing this of?
i can't seem to figure out what's causing this issue:
#define GRABPIXEL(weight,kernelx) tex2Dproj(_CameraSortingLayerTexture, UNITY_PROJ_COORD(float4(i.uv.x + _CameraSortingLayerTexture_TexelSize.x * kernelx*_Strength, i.uv.y, i.uv.z, i.uv.w))) * weight
it is a float4
When you select the graph asset in the project window there's buttons at the top of the inspector, one should be like "View Generated Code". It'll then open as shader code in a temp folder. Can copy that .shader file to your own project and edit it.
Can use the default UI shader like Ole linked earlier as reference : https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/UI/UI-Default.shader
so just doing
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
would mask it already?
Should do yeah (assuming you also add lines 10-14 of that UI-Default shader)
Alright, thanks a lot 🙂
What type is _CameraSortingLayerTexture?
um
i fixed it JUST now
it was Texture2D
it is meant to be a sampler2D
i don't know why but i assumed it was an issue with the second param
how would i change this to camerasortinglayertexture
ohh i did it
nvm i did not
If you're using _CameraSortingLayerTexture in the shader (for first pass), I'm not sure you really need to
it does not draw
well i want to draw to that texture
because that is the texture behind the UI
if i draw to _CameraSortingLayerTexture
then this happens
wait
what
nevermind i need to do this?
This is drawing _CameraSortingLayerTexture to the camera, not the other way around. Right?
i just know that one way the ui is drawn over
and i don't want to apply the blur to the UI
(if i apply the material to the background gameobject, it works just fine)
(but second pass does not execute)
yeah i'm not sure if what i said is right
If the feature is set to the before/after post process event I think the blur should still occur before UI.
In the blur feature I'd try :
Blit using cameraColorTarget to a tempTarget, using first pass (0). In that pass, sample _CameraSortingLayerTexture
Blit using tempTarget to cameraColorTarget, using second pass (1), sampling _MainTex (or _BlitTexture if using newer Blitter API / RTHandles)
Maybe you could also render the UI with an overlay camera to avoid that?
i have post-processing on the UI
Ah right
When using a blit, unity passes the "source" texture into that property
every source is passed to _MainTex?
So you need the second pass of the blur to use the horizontally-blurred texture, hence the tempTarget
oh so _MainTex would have the blurred texture?
Assuming you set the blits up with the targets like I mentioned, yeah
_MainTex in the first pass would just be the camera target. Could try keep using that, or _CameraSortingLayerTexture. I'm not sure if it matters
i see what you mean
ohhh
that makes sense
the blur works
ayy
the ui is still being overwritten though
no matter how far up i go in the render process
is it possible that i could make a material with 2 pass instead?
or like pass a global texture
to a material to sample and display
instead of blitting back to the camera target you could blit to another temporary texture, then cmd.SetGlobalTexture
why does my shader i made not work on my UI element? it works fine on a sprite renderer
these two are both using the same material but dont do the same thing
i made a rendertexture
and made that into a material
which i put onto the sprite
but it's just white
i did this
it works
but i did write a shader to draw that custom texture
which i'm not sure is ideal
whic his also quite buggy lmao
is there a better way to do this?
(to draw the texture to the material)
i love that i can 10x downsample the image with the high blur and still have it unnoticeable
can anyone tell me why it wont appear to be selected and wont let me drag it in
(bottom left)
Nvm i got it
In shadergraph URP I want to do an effect that doesn't show / masked out if its in shadow of another mesh.
What is the method to access the scene shadow data?
https://youtu.be/RC91uxRTId8
I tried following this tutorial but the results I got were buggy and inconsistent, and didn't work to receive shadow data
By buggy an inconsistent I mean
- the shadows cast have holes in them
- the meshes don't receive shadows
- the mesh lighting is a bizarre stepped thing that I can't explain, gif shows it
the only part I need/am looking for is detecting where shadow is/isnt, I dont need any of the rest
Googling just found this hub, looking to see if it solves my problem
https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
My guess would be the render feature is on the renderer marked as "default" on the URP asset, which is also used by editor previews - like the one in the bottom right. It's using the same render texture, so overrides the scene/game view as well.
Should be able to fix it by preventing the feature from being enqueued or executing by checking the camera type and return early.
if(renderingData.cameraData.cameraType == CameraType.Preview) return;
Can use the Main Light Shadows subgraph from my custom lighting package : https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
That won't really fix the holes in the shadow, that's probably just the mesh or shadow bias settings affecting that. Could also change Renderer to Cast Shadows : Double Sided, might help.
Yeah realized that after the mesh itself is just has janky holes
I am getting an undeclared identifier from your node
I am using the v8 branch because I am on 2020.3
oddly I only get the error in my shadergraph, I dont get any error when inspecting the subgraph itself
ill try to read through the notes if its answered somewhere
Maybe try opening the subgraphs and re-save them?
Oh that worked, interesting
sweet, access to shadows 👍
Do you reccomed a better method to reduce shadow acne than what I've done here?
https://youtu.be/1bm0McKAh9E?t=1357
this person has tutorials on it but they're writing HLSL that accesses unity functions so I am struggling to re-impliment what they did in graph
"inset geometry a little bit along its normals." reccomends the doccumentation, Ill have to google how to do that
Usually the way to fix shadow acne is edit the shadow/depth bias settings on the URP asset rather than anything in the shader itself. And possibly play around with the cascades
Ahh okay, in here then
Ah yes Depth Bias right away makes it look a lot better 👍
Would also recommend a Saturate in your graph here btw, probably after the Dot Product. It contains negative values currently
Ah yes, the dot's dark values continue into the negative in the dark, which saturate will fix 👍 Will do , now that I have shadows + less acne starting on that bit now
Hard to tell what the actual problem is here, we don't know what the shader meant to be doing.
But also if it's a shader graph, that doesn't really support UI (when using a Canvas with Overlay mode at least, Camera or World space UI tends to work okay). But usually better to write code based on the UI-Default one instead (https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/UI/UI-Default.shader)
i feel like that should be obvious but i cant wrap my head around it.
i want my triangles to use the vertex color of the first vertex of the triangle => no smooth color interpolation.
im looking at the URP shadergraph but i cant think of how to implement that.
its for a minecraft like fragment shader
You need to have the same colour in each vertex of the triangle. Can have duplicate vertices in the mesh for each face if you need them to be different along that edge.
You can technically specify nointerpolation on interpolators in hlsl, but shader graph doesn't have access to that.
is there a way to use some other object's property in a shader graph?
yeah just found that. shame, was hoping for an easy solution wihtout having to write a custom frag shader
What do you mean by "some other object's property" exactly?
example: a shader that would have plugged in the y of water, and apply rust to objects with this shader, based on how much they are submerged
that did not change anything
there are still flickers
Okay, you can create properties in the blackboard and set them from a C# script (e.g. material.SetFloat("_WaterYLevel", waterTransform.position.y);)
might just be my system
any1 know how to make just that green part? like the double colored stripes and have it wrap around a rectangle
so with code, thanks! i guess the way to go is Custom Function node
why with shaders
I mean that should stop it "copying" the preview sphere when viewing materials in the inspector. I'm not sure why it's flickering specifically
not sure, terrain?
aight ill try there
oh i see
thanks man
You'd set the properties in a C# script, not shader side, so shouldn't need a Custom Function node here. To obtain them in the shader you set up properties in the Blackboard window
the flicker is basically just a plain white output when it happens, and it only happens for one frame + only if i move my mouse
it does not happen in play mode
but yes, i see that helped, thank you
Could apply a texture and set the "tiling" field to make it repeat
ill try that, thanks
How can I disable vertex lighting on a sufrace shader? (VERTEXLIGHT_ON)
Should be able to add novertexlights to the surface pragma line, according to https://docs.unity3d.com/Manual/SL-SurfaceShaders.html
writing a general purpose shader for this project but got one problem. It seems its not correctly handling transparency as you can see the edges of the texture being used
should probs post code, one moment
hm, discord isn't liking me putting in a codeblock, pastebin it is
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.
tried playing around with blendmode, zwrite and the renderqueue but no luck
i clicked the delete key when i had custom function node selected, it disappeared but left a ghost there, lagged my whole shader graph, previews stopped moving, and apparently "nothing loaded" after i clicked Save Asset, moving nodes is kinda weird now, and well, restarting unity is my only option now, i hope my shader will heal in that time
did this happen to anyone before???
- i get this error logged any time i try to do anything in the shader graph, cant create a new node, cant properly move the bugged ones

So why is. Why Transformation matrix model is need if it throw the same value when batched there is no logic looks like trash parameter. I can do property for this and rewrite in update. Why i cant really get rotation when batched?
just closed that bugged graph window and opened the shader again, its fine now, custom function ghost is gone, as well as some of my progress
(glad i screnshoted it just in case
)
Need a solution for this. Please
I have a shader, when i am in edit mode i can change the strength slider, and the game view represents this change, but when i am in play mode, the slider does not change anything
I have added the shader in the always included shaders, now the slider works in play mode but changed via script are not reflected
m_backgroundBlur.SetFloat("_Strength", Mathf.Lerp(m_backgroundBlur.GetFloat("_Strength"), m_enabled ? blurIntensity : 0, lerpValue));
Debug.Log(m_backgroundBlur.GetFloat("_Strength"));```
this is my code, and i can confirm that the value is being changed by the debug.log
what can i do to make this look less creepy
i dont have any of the other facial features made but its in progress
right now i dont want the eyes to pop as much
the first Get_Float("_Strength") returns the correct value, which the slider is set to
those eyes were made specifically with a custom shader
and i think that might be why
right now its really simple
i feel like tweaking something in here could make it less horrifying
more info:
i have substituted for this, instead of the "_Strength" string, although that yielded no results either
Make the irises bigger so the whites above and below don't show as much.
alr
how do you get m_backgroundBlur?
try to log m_backgroundBlur and see if the shader has additional (Instance) string
it might be instantiated
i have done with both (instance) and without instance
here is my code
i usually do not have line 30
but it does not make a diference
with line 30, it says (Instance), without it says no instance
in line 25, try using sharedmaterial instead
i am just restarting my project 1 sec
oh wow, that worked
do you mind explaining why you thought that would work?
getting material using .material and modifying it might get the material instanced
Note:
This function automatically instantiates the materials and makes them unique to this renderer. It is your responsibility to destroy the materials when the game object is being destroyed
https://docs.unity3d.com/ScriptReference/Renderer-material.html
you're welcome 🙂
I found this "Enable" Node in a video I was watching, but I cant seem to find it, what was this node replaced with?
never heard of it. What is it supposed to do?
Is there a way to change the Unity grass texture shader for Terrain so that it has point filtering alphas? Trying to work around this rounding I'm getting with the pixels in my alpha textures.
well if you select a texture you can set it to point no filter
Link to the video would help.
Enable/disable out of context doesn't mean anything.