#archived-shaders
1 messages · Page 59 of 1
Not at all, that's why I posted it under graphics, and graphics cards are required to run unity last time I checked..
Your decision to buy or not buy a video card is not related to shaders.
I have sort of the same problem, except I need mine to work with Tilemap Renderer, not just Sprite Renderer. I can get it to work for a single sprite, but changing more than one tile at a time changes all other set tiles in the same map, rather than each having their own separate sprite.
sorry just searched this, answer is no damn
can anyobdy help me with cam renderings
A tilemap is basically just one big sprite renderer that repeats sprite textures over space that all share the same material, so applying shader effects to invidiual tiles is tricky
What kind of of effect should it be?
@grizzled bolt thank you for telling me about the tiling and offset node, somehow i forgot about it 😄 I now have my desired effect but i dont quite understand why to be honest. I do feed the shader with 2 textures and get the matching piece of the tile by dividing it by the amount of cards displayed on the texture (my cards are 128x128, my card texture is 384x128 so i divide it by 3, my background card texture is 768x128 px so i divide it by 6) then i offset it depending on which card i want to display. Now my question is, how does it work if i only give the shader my background card texture and fetch the card texture by inserting it as the _MainTex. Since the card texture is only a piece of the whole texture using sprite mode multiple, somehow the scaling is now totally messed up.
Whats the difference between using the whole texture, dividing it and offsetting it, and the other approach of just giving the part of the texture into the shader (Tile mode multiple)?
I hope its not too confusing otherwise i can attach some images 😄
Multiple type sprites in Sprite Renderers already apply an offset in the mesh UVs
That offset is no longer valid if the sprite reference changes
When i do this, the whole object looks white
But with this, the texture appears
I'm seriously confused, doesn't the w component equates to the alpha channel?
(col.xyz, 1) - is just a "comma" operator that returns 1, and then converted into float4. So you are receiving float4(1) which is white. To fix your shader code you need be more explicit: return float4(col.xyz, 1);
I got it to work by setting col.w separatelly, but it was very helpful to know that's the correct way of building new vectors on the fly, Idk where I got the notion that (col.xyz, 1) would work xD
Thank you very much!
Hello, I am having some issues trying to write a for loop in a custom fragment shader. I looked it up and this should be the right syntax but trying to save the shader throws an error.
(Unity version: 2021.3.3f1)
Here is the shader:
Shader "Hidden/NewImageEffectShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target
{
for (int i = 0; i < 5; i++)
{
//Do Something
}
fixed4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
ENDCG
}
}
}
And these are the errors:
Does anyone know what I might be doing wrong?
hi ,
I want to ask a technical question regarding optimization for shader codes.
I wanna add an if statement but i was told many times it's not preferred to use if statements in shaders, I thought of multipling the equation with a float where if float was zero the whole thing will drain.
so which is better an if statement or a float factor?
Option 1: float test = test + sin(30) * factor;
Option 2: if(factor !=0) test = test + sin(30);
Don't know much about the CGPROGRAM syntax, does it work if you just output a direct color? (I think your syntax may be wrong)
the first one
Thanks
The shader is just the default with the for loop added. The errors go away when I remove the for loop
The only idea I have is add some kind of statement to the for loop
even if it's just break/continue
Nope, doesn't work
Do you know if my syntax for the for For Loop is correct?
it looks normal
The Unity verion is 2021.3.3f1 btw
are the errors the same if you paste it after the tex2d call etc
no, the errors go away. I did some more testing and it seems any reference to i.uv after the for loop throws an error.
lol
I know what it is
I'll give you a hint
v2f i
int i
I should've spotted that
I'm going to go jump off a cliff now
pmsl
Thanks for the help Lol
hey guys, is it possible to check the currently active color space (gamma or linear) with shader graph? Basically a node that outputs false if the current color space is gamma and true if it's linear, or vice versa
I'm trying to use various forms of bitmasking, such that tiles calculate which sprite to select from an atlas for their albedo and then select which sprite to use from another atlas for their mask, or to do various blending. So that tiles will dynamically change based on their surrounding neighbors, like custom Rule Tiles (and there's a reason I'm not using the 2D Extensions for this).
If I only have one sprite in each atlas, the masking works. If I have multiple tiles, I can get the albedo to work but not with the masking. At least not in game, even though it works just fine in the Editor. As near as I can tell, this is because Unity expects an actual asset for the renderers rather than a dynamically-created value. However, saving potentially thousands of assets is untenable.
I have tried using Shader graph, and it works fine in the graph, but again not in game and I don't know how to get back out the final sprite on a per-tile basis.
This is what it's going, vs what I want it to do:
Seems quite involved, not sure I totally understand
Is this bitmasking and tile determination supposed to happen with just shaders or with scripts also?
What's the problem with 2D Extensions, or Tilemap Extras I assume you mean
One way to get shader-accessible individual tile data is to write to vertex colors of that tile
Can someone help me figure out if I can use these assets
They are magenta
which must mean the shader is outdated I would think
but I'm very new and not seeing a solution
You could say I'm trying to automate the process and make it more streamlined. I have scripts that aim to take an atlas or array of sprites and apply certain rules to them instead of starting with a bunch of sprites and applying rules to them with arrows and palettes. For instance, I have a modulo tile that allows repetition based on that tile's coordinates. That one works just fine. For anything that needs masking or blending, however, that's where the problem enters.
I don't know that just getting vertex colors will work since I don't want just colors, I want the entire sprite. By which I mean, I want that portion of the texture within the atlas.
Again, the thing that's holding me up is figuring out how to set individual tiles in the tilemap after applying a custom shader without having to save the result as a separate asset and without all tiles in the map displaying the same tile. Right now, I can do one or the other but not both.
i see now how it is. Is there a way to make my background card texture static and not react to the offset? Now everything is fine when using sprite 1/3 but when i use 2/3 both textures get the offset instead of just one
The way to make it static in that sense would be to not use multiple type sprites, rather do all the UV offsetting entirely in shader
if you are using URP/HDRP, make sure your materials use the appropriate shaders; I believe Standard is for BiRP
Vertex colors are just values stored in a vertex, they could be used exactly in the same way as UV coordinates
I expect you need a system to automate assigning the necessary coordinates via colors as required
Maybe there's a way to write custom vertex streams beyond colors but I don't recall exactly
If I were making such a system I think I'd prefer to look into how to generate rule tile sets automatically before making a new rule tiling system
Have started to attempt to get into shaders and to do so I've picked up shader graph isntead of teaching myself HLSL. With that being said, I'm trying to make a shader that effects ONLY the deep (practically black) values of the players camera view and leave everythin else untouch. If you can imagine, I want the darkness of the game to be full of static while the rest is normal. Any documentation, forum posts, or instructions I could get to achieve this affect? Thank you!
Can you photoshop what you want and post it here? What you’re describing could be many things.
You might not even need a shader
The issue isn't so much in creating the rules as it is combining sprites without saving extra assets. Let's just say for sake of argument I have a 16-bit mask that I want to apply to a repeating texture of 4x4 sprites per texture atlas. That's 256 assets I'd have to make per tile type, and presumably I'd have at least 10-20 such tile types that all need to be masked, let alone in combination with each other. So over 2500 assets minimum just for that system, let alone any other part of the game. Again, that's untennable. Yet I know for a fact other games implement something like this, I just don't know how they do it under the hood. If they just use straight meshes instead of built-in tilemaps or something.
Looking through the 2D Extensions, it seems like they are really only equipped to deal with single sprites rather than dynamically masked and blended sprites. That's the crux of my issue.
I'm not sure I'm following this at all, so 2cents, but one thing that came to mind is the unfortunate problems with Dependent Texture Reads and when/why you should avoid them when possible...if other solutions exist at all, that is. Varies by target platform and level too. So food for thought:
https://medium.com/@jasonbooth_86226/stalling-a-gpu-7faac66b11b9
I'd benchmark on various platforms.
Hey guys, anybody have a good turorial or advice on how to create a sniper rifle shot effect
llike widowmaker from overwatch
Ive created a line rendere and want to slowly decay a smoke shader along it
How to use custom shader in DOTS? My water shader should be like screenshot1, but it actually looks like in screenshot2. I followed the description in the exception and added
#pragma target 4.5
#pragma multi_compile _ DOTS_INSTANCING_ON
two lines in my shader
I want to do something but I don't know how to describe it. So the game view is all black, and behind the wall of black is a room that is unveiled whereever the player walks
if anyone knows what I'm talking about, could you send some links?
thats what im trying to do
So essentially, I'm trying to reverse engineer the way ONI does terrain tiles. From my research, I've deduced that it requires two things - modulo tiles to get the repeating texture - and a 2x2 bitmask to divide each tile up into four quadrants for handling border transitions. Each quadrant checks its neighbors for sameness like in a standard 3x3 Full Bitmask to determine which of 16 masks it should pull. Inside the mask, it applies itself. Outside the mask, it applies the neighbor, which could even be an empty tile. Effectively, this requires a compound texture created dynamically at runtime to constantly update as surrounding tiles change.
I can make this work in the Editor, but it's not persistent and thus doesn't transfer to in-game since - as far as I can tell - tilemap renderers and sprite renderers require actual asset references. I can make the modulo stuff work in game or I can make the bitmask work in game as a standalone sprite, but I can't get both to work at the same time because the result isn't saved as an asset.
I know Klei used Unity to create ONI and have actually made this work in practice, so I know it's technically possible. I just don't know what they did on the backend and no one seems to have any documentation online about it. I'm 99.99% sure they didn't save each individual combination as a separate asset, since consider how many unique elements there are in ONI. I could go through all the source code as a last resort to see what they actually did - if they used tilemaps or a custom mesh or custom shaders - but I feel like I know what the problem is, I just don't know how to solve the problem.
Moreover, I feel like this should be solvable in other contexts at a broader level of how to make masks and blending work with tilemaps without having to make a custom mesh. But I just don't know.
You mean like Fog of War effect?
Depends on what type of game your making and what sort of effect you want. Whether you want it around the player, based on tiles, or line of sight.
Unity tutorial about making fog of war. Why is it different than other tutorials? Because everything is compressed to 60 seconds / 1 minute.
Project Files:
https://github.com/Keyiter/One-Minute-Unity/tree/%238-Fog-of-War
Outro music
Micro Fire - Silent Partner
OK, so like what "Oxygen Not Included" did and how. This: https://store.steampowered.com/app/457140/Oxygen_Not_Included/
Maybe if you can show some shots of the types of tiles and changes you're talking about the group can chime in.
In the space-colony simulation game Oxygen Not Included you’ll find that scarcities of oxygen, warmth and sustenance are constant threats to your colony's survival. Guide colonists through the perils of subterranean asteroid living and watch as their population grows until they're not simply surviving, but thriving... Just make sure you don't fo...
$24.99
97637
86
At minimum I'd say they have "layers" logic, since they're carving away rock to get to things "underneath".
Maybe look here, they aren’t doing anything fancy, a few layers with the tried and true tile selection rules http://www.cr31.co.uk/stagecast/wang/blob.html
Stagecast puzzles, games, animation and sims
you could create a texture and make it transparent/white wherever the player goes, and then overlay it onto the game
Trying to recreate a shader from blender to unity but the result is not that good
Here're the shaders inside blender and Unity
Sounds like you want a custom post-processing shader. Basically, you take the image the camera renders and add some effects via custom material. You could just blend to static for each pixel based on its brightness. I'm not familiar with how shader graph works, but I'm sure you could search up some tutorials online.
I've heard parallax shaders are a lot more expensive on mobile than regular old geometry - is this true? Is it because the GPU power is less than the cpu power?
Hello. How can I reduce the dither effect when the camera is far away from the model (Hair)? She looks quite bald like this lol
Hi. I want to be able to take a greyscale map, and using a (for example 0-1 float) return a black and white (no greyscale) map where every pixel less x is black, and everything greater than x is white. What's the node(s) I'm looking for in shader graph? Thanks!
That's what I've been using as part of my research.
I can get the tile bitmasking logic to work and the modulo tiling to work on their own in the tilemap, but this by itself doesn't look like much. The edges are all square, not jagged like in ONI:
I can even get compositing to work in a custom Editor along with custom color blend modes. (Excuse the crappy quality of the test sprites.) The problem is, as you can see in the video, when I update the tilemap with the dynamically created composite, it turns all the tiles the same instead of retaining their individual sprites like in the above images.
Step
Oh, Cyan! Fancy seeing you here. I've seen some of your shader work in your blogs. Very much a fan. ❤️
Anyways, returning to my question, I know in theory how ONI does their edges, I just don't know in practice how they actually executed it.
perfect thank you that was exactly what I was looking for ❤️
are the SpeedTree8 shader's many properties documented anywhere?
e.g. _ST_WindGlobal
I have a script that sets them, but the effect on my terrain trees is oscillating too fast. I'm messing with that script, but I don't really know what any of these vector4's mean
Hey there! I'm really really new to shaders and im having a little trouble finding resources to achieve my objective.
I'm trying to render the screen with a little water like distortion, but i can't find anything to do this (in 3d, in 2d there are lots of tutorials), for now i found how to do it using a sine wave, but i'd like to use noise to make it more natural (but if i can't find a way i'll probably go with the sine wave and leave it alone).
What i have right now is what you can see in the screenshot, i apply it to a plane and put it in front of the camera, the problem is that the object in scene is displaced too much and i can't understand why...
Does anyone have any resource where i could be guided in the proper direction or could just help me? I would be REALLY grateful... :,)
First image is my shader graph, second where it is rendered and third where it should be...
Hi
I made a grid map using shader graph
There is a weird flickering on my grid map
Is this a kind of aliasing?
Please help me to remove this.
LoD? Instead of showing hair material/shader, switch to solid hair when far from camera
https://docs.unity3d.com/2018.4/Documentation/Manual/LevelOfDetail.html
Got it, thanks a lot!
Hm, checking the LOD component, it only accepts renderer as input. Meaning I'd need to create a variant of my hair with an opaque material?
It uses multiple separate renderers, so they should be able to have entirely different properties
When mixing the noise and UVs, I would make two noises (sampled at positions far apart so they're independent) and combine them into a Vector2, multiply by some distortion strength parameter, and add that onto the UVs
Hi everyone ,I read that unity documentation 2023.3 still not fully supported to XR graphic fully and i want to know what nodes are supported "(1) Although Shader Graph shaders can run in XR, Shader Graph doesn’t currently support the XR utility feature to create SPI-compatible shader input textures. Unity will expand support for Shader Graph functionality in future releases"https://docs.unity3d.com/2023.3/Documentation/Manual/xr-render-pipeline-compatibility.html
I'll try that, thank you very much :)
It was the distortion strength what didn't work, thank you very much
Hello, I am using Graphics.Blit in OnRenderImage() to send the rendered image of a camera through a fragment shader to add some custom post-processing. Is there a way to access the LayerMask of a pixel in that shader? If not, is there some other value I can use to give information to the shader without changing anything else? I want some objects to be treated differently in how the post processing effects are applied.
Do unity shaders support double pressision?
Eventtho the datatype double is avaliable in shaders, there are very little things you can do with it without writing your own math functions,
when you pass in a double for example into a
fract();
function you get a waring that you might loose presision meaning that the function internaly will just use single precision,
This is not really a problem for the fract function, but with operations like sin, cos where you would like to have double precision, I don t know how to get it to work
Well I'm not even really looking for a specific "look." I just want to know how to only render on top of close-to-black values and leave all the bright values untouched
make your own cosine function,
Hi devs, I need help with GPU Instancing with URP and Graphics.RenderMeshIndirect.
I followed quite the number of posts and implementations and the process to make it work seems to inject a HLSL file into a shadergraph shader + a custom function for the pragma. Well actually it works, I mean I render correctly meshes BUT the shader throw an error : undeclared identifier 'unity_ObjectToWorld'
Does anyone encountered this problem or have an idea on his origin (or know the resolution) ?
here is my HLSL file (reduced to the minimal code to make it works) :
#define SHADER_GRAPH_SUPPORT_H
#if UNITY_ANY_INSTANCING_ENABLED
struct InstanceData {
float4x4 m;
};
StructuredBuffer<InstanceData> unity_InstanceData;
void SetUnityMatrices(uint instanceID, inout float4x4 objectToWorld, out float4x4 worldToObject) {
InstanceData data = unity_InstanceData[instanceID];
// objectToWorld and worldToObject definition...
}
#endif
void passthrough_float(in float3 In, out float3 Out)
{
Out = In;
}
void setup()
{
#if UNITY_ANY_INSTANCING_ENABLED
SetUnityMatrices(unity_InstanceID, unity_ObjectToWorld, unity_WorldToObject);
#endif
}
#endif```
and my Instancing subgraph for injection :
Not unless you keep track of it yourself. You could check if ALL your desired target platforms support MRT...and create a render texture to hold more information, and return that information on a per-pixel basis, for example. And you'd probably pass that info into the shader too....for example what layer you're on would have to be passed in IIRC.
There are some built-in methods for differentiating pixels...the stencil buffer has several bits available depending on what your needs are. You could look into that too, but be aware that lighting calcs use it too.
Short of all that, after the shader is done, a pixel is just a pixel...color, depth, and optionally things like a normal or motion vector...all stored in screen-sized buffers.
Hello, is it normal for the Dither node to render 0 (black) color ? Shouldn't it only dither when it's above 0? If it's normal, how can I make it so 0 is invisible and it only starts dithering starting 0.01?
I've max my cut out value to 1, if I disable dither, the hair are correctly invisible. But dither do render it. Isn't it confusing?
Hi!
I found a screenspace outline shader online and what it does is that it creates an outline by essentially stretching the object towards the corners of the screen (if the thickness is high enough, you can begin to see 4 copies of the object). While I don't mind the 4 copies, I would like to know if there is a way to kind of blend/blur them, or at least just fill in the spaces between them so that you can't tell that there are 4 copies (as can be seen in my super artistic Paint diagram below).
(I think the part of the shader above is where that blur should go)
hey guys very basic waste of time question but which shader graph node would allow me to scale the image texture/UV by the world size of the polygon its being rendered on? like how probuilder scales textures but instead I want to input my own image
The UVs are tied to the vertices so scaling the mesh stretches the UVs, if that's what you mean
I needed to find the triplanar node
I got it now tho thanks
Hi, I have a compute shader where I've defined a static global struct, I need the values to be kept at different dispatches, but for some weird reason they reset to the default value at every dispatch. This only happens with structs, while normal global variables keep their values through different dispatches. Anyone knows what could be the problem?
hey guys, my intention here is to have a shader that simply takes a texture, scales it to worldspace and scrolls it depending on an input variable, however I'm having trouble because for some reason only two sides/polygon directions of my object are being covered. Can anyone help me?
So from what I can understand, this shader sort of calculates the position of the pixels relative to the object. This means that if I could do a "Less than" check for those pixels, it would probably fill all the space inside the outline of all 4 copies but I am not sure how that can be implemented (if it can be implemented at all). Any idea?
getting this error when i add this to a material that my strand hair uses. the hair simply disapears. im on mac if that has anything to do with it:
Metal: Vertex or Fragment Shader "Shader Graphs/Master" requires a ComputeBuffer at index 4 to be bound, but none provided. Skipping draw calls to avoid crashing.
Yo!
does anyone know how i could make a cool Pixelated Water shader, similar to celestes water, with physics
Quick shader question. I'm writing a shader where I need to sample one of 4 textures depending on some factors. What's the most performant way to do this?
I tried using some if statements to set a sampler2D to the texture I want to sample (shown below), but Unity says that the "Sampler parameter must come from a literal expression."
sampler2D _TextureA;
sampler2D _TextureB;
sampler2D _TextureC;
sampler2D _TextureD;
sampler2D _SampleTexture;
fixed4 frag (v2f i) : SV_Target
{
_SampleTexture = _TextureA;
if(tex2D(_TextureB, i.uv).a > 0.01f) {
_SampleTexture = _TextureB;
}
if(tex2D(_TextureC, i.uv).a > 0.01f) {
_SampleTexture = _TextureC;
}
if(tex2D(_TextureD, i.uv).a > 0.01f) {
_SampleTexture = _TextureD;
}
float4 color = tex2D(_SampleTexture, i.uv);
}
i tried making a shader but it doesnt display on the object but on the material prewiew it shows up
Is this HDRP?
yes
Then the brightness of the scene is orders of magnitude different from the preview render after taking into account the exposure
So, increase the emission intensity by a big enough value that it shows up
now it glows but from the midle out and not from out into the middle
i tried getting this effect
https://youtu.be/Ar9eIn4z6XE?si=RkXSVmi97k5BrRGh
● Check out Bolt: http://ludiq.io/bolt/download
The time has come... Let's explore Unity's new Shader Graph!
♥ Support Brackeys on Patreon: http://patreon.com/brackeys/
····················································································
♥ Subscribe: http://bit.ly/1kMekJV
● Website: http://brackeys.com/
● Facebook: https://f...
As long as you don't have weird negative values in there a One Minus node should fix that
tried it it still does the same except its dark now
if i turn of the directinol light it looks right
can i somhow render the scene without the light on top of it and make everything black invisible so that you just see the outline?
I mean one minus after the fresnel but before the color multiplication
It shouldn't be a necessary step though so there must be something else wrong with your graph
Because it affects the exposure
The Tiling and Offset node takes a Vector2, so only accepts Position.xy. Then when it's output, and the Triplanar node asks for a Vector3, it gets handed a Vector2, and just sticks a zero in the third slot. Instead, multiply the position by some float property, add a Vector3 property, and put that into the Triplanar node's position input
(Tiling and Offset is designed for UVs (hence why its input is called UV), not positions, which is why it works with Vector2s)
https://alexanderameye.github.io/notes/rendering-outlines/
https://bgolus.medium.com/the-quest-for-very-wide-outlines-ba82ed442cd9
Hi there. I am not exactly sure if this is a shader question, or if I am making it too complex by using a shader. I have a shader that flashes between red and white, nothing complex. I have attached that to a material, and I want to use it on my player when they get hit. I have a 3D model from Blender that I am using, and want to apply it to my player mesh. My player mesh has 12 materials on it that came over with the FBX from Blender. I don't think that replacing all those materials during run-time when the player gets hit is the right way to do this. Something feels off about doing it that way.
Can you suggest a direction for me to do this? Or could you direct me to the correct channel to ask this question in?
@burnt crag try a renderer feature: https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@17.0/manual/renderer-features/how-to-custom-effect-render-objects.html
Thank you very much!
Anyone can help me with Shader Update.... i got an Sebastian Lague Shader Shader Graph, and it cant work on new version of unity, any tips to make it work ? or REwrite ?
Hi.
Does anyone have any inspiration / tutorials of how to do water shaders for a top down tile base grid? Most google searches i find are for sidescrolling games.
So far i've been inspired by this https://www.youtube.com/watch?v=nG8OU1GwMtk But i wonder if anyone utilized some other cool effects?
I like to keep things simple - my water shader is just another tile in the tileset... with a little bit of jiggle.
#GodotEngine #GameDev #PixelArt
Join my Discord: https://nathanhoad.net/discord
Thank you! These look great
What the heck, I just found out shader functions can assign values to static variables and this value will persist for further function calls.
Maybe someone can help me with this. I have a few diffrent meshes that are rendered using instances of the same material. Each material instance has it's own instance of the same _BaseMap texture. At runtime these textures are modified, but only using the model UVs as a mask. Now I want to combine the pixel data from all these textures into a single one, using the models UVs as masks. The end result should be that each model looks the same as before if used with the combined texture. How can I achieve this?
You could render each of these meshes to a render texture, with a shader that outputs clipspace coords using uv * 2 - 1 (instead of using vertex positions). Also should use Cull Off
It's a similar idea behind the MeshRenderer mode used in this repo to bake shaders to textures : https://github.com/Cyanilux/BakeShader
Thanks, I'll give it a try.
Why my water surface shader doesn't work in subscene? The frame debugger shows that my shader is used when drawing transparent objects. Also, once I change the render queue in inspector, it appears. But if I enter play mode, or do something that let unity reload, it disappear again. Anyone know why?
Btw, if I put my camera inside the subscene, it seems that the camera just stops rendering.
I get this error what should I do?The Visual Effect Graph is supported in the High Definition Render Pipeline (HDRP) and the Universal Render Pipeline (URP). Please assign your chosen Render Pipeline Asset in the Graphics Settings to use it.
-
Choose a pipeline you want to use (research the difference between URP and HDRP)
-
Set up that pipeline (guides are pinned in #archived-hdrp and #archived-urp )
-
You can now use VFX Graph
thanks 😀
hey. how do I change normal intensity? I know we can use UnpackScaleNormal and pass in the normal intensity directly, but my question is how to do it manually. just wanted to learn is all
any link etc is also very appreciated
you could divide the normal.xy by some factor (leaving normal.z unchanged) and then normalize after that
ah, thanks!
i think if your normals are based on a heightmap, that's mathematically equivalent to stretching or squeezing it
I see. I think these normals are indeed based on hightmap. not sure though. will try the formula
worked like a charm
thanks again ❣️🙏
hey, is it possible to reference properties inside subgraphs? id like to avoid duplicating the same property in multiple shaders that use the same subgraph
woohoo!
was looking at acerola video about water and see that on the top it looks like great water...however on the underside its just "blank"
how would you "show" the water on the bottom-side also?
is it even possible to show on both sides of a mesh?
(pretty new to anything 3d and things like this so sorry if dumb Q)
You can use the Cull command to choose which side of the mesh is visible. Cull Off for both.
https://docs.unity3d.com/Manual/SL-Cull.html
Afaik no, the main graph needs to have the property defined
thought I did it right but still not working
It goes under the Pass, not Properties. The link provides some example code
ah thanks...didn't notice that part 🤦♂️
probably dumb question...putting it under Pass didn't work
but just putting it under "subshader" worked
why would it error when under pass?
(I see both used in the example code)
It should work under either. When under SubShader it sets the culling for all passes. While under Pass it's just for that particular pass.
interesting...thanks!
I changed to hdrp and my skybox gone black how can I get it back?
Anyone here interested in taking a quick one off task to help us convert a simple Unlit Sprite Shader Graph shader, to a UI compatible, maskable, HLSL shader? Compensation available at standard US rates.
no
!collab
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
whats up with the stretching object position node plugged into gradient noise uv and result into base color why that results in this
Shader Graph default noise is 2D; when you plug in a Vector3 (e.g. position), it just takes the x,y components and ignores the z.
can I avoid this?
https://www.reddit.com/r/Unity3D/comments/g2ycp4/i_made_a_bunch_of_3d_noise_nodes_for_shader_graph/ I see dude made 3d noises specifically for this lol
yep
Anyone wanna try to take a crack at this?
How do I include random tree color in a custom shader?
I have a URP shader with _TreeInstanceColor input
Do I need to do more?
Hi,
I have the following shader graph which is generating me a deformation on a sphere.
The issue im seeing is that some of the edges in the sphere are coming up, I think its something to do with normals and nearest neighbours that I can adjust and average out but im currently running blank.
anyone able to point me in the right direction for this.
i made outline shader graph, but my problem is like it. how can i solve it?
There isn't a way to fix this in the shader. Inverted-hull outlines requires the mesh to have smoothed normals rather than flat.
Or at least provide smooth normals in an unused UV channel / vertex color if you still want flat for shading. Might be able to handle that in modelling software, or can calculate from C#, probably using an AssetPostprocessor like this https://gist.github.com/runevision/6fd7cc8d841245a53df5d09ccf6b47ff but swap mesh.normals out for mesh.SetUV 🤷
i tryed this way but it is the same, i was put there script in Assets/Editor folder...
and swap mesh.normals to mesh.SetUVs(0, normals);
If you're not using the UV0 already sure. You'd also need to swap the Normal Vector node for a UV one in the graph
this is result when i was modify shader graph Normal Vector to UV(UV0)
what "LinearEyeDepth" function does in shader?
If your mesh has flat shading or your sphere is made of multiple segments, you will in general get discontinuities in the normals
It takes the depth in the depth buffer (which iirc goes like 1/distance) and converts it to a value linear in distance, where 0 is the camera near plane and 1 is the far plane.
I'm using the built in sphere mesh in unity.
Any advice on a better alternative or something I can do?
It might be that moving the vertex positions is stretching things that shouldn't be stretched and that's causing the discontinuities?
If so, you might need to manually recalculate the vertex normals and tangents
Thank you!
Is the function part of UnityCG.cginc?
I tried searching online, couldn't find any answer.
anyone knows any good tutorials / resources about CommandBuffer and custom shaders to paint on textures ?
trying to extend this method https://www.youtube.com/watch?v=YUWfHX_ZNCw
Painting in video games is a very common practice, more than one might think.
It's often used to paint or interact with the environment,
but also it is used to dirt the player and create consistency between him and the game world.
Today we'll recreate this effect on Unity.
@mixandjam video:
https://youtu.be/FR618z5xEiM
Our sound designer and...
Does anyone know if there is a way to get Unity's UI to render at a specific depth? The Internal-UIRDefault.shader has ZTest GEqual. This causes problems when I disable depth clear on the Panel Settings, I cannot have the depth cleared and need UI to render on top of the world regardless of depth
hey so i made this shader that like, fixes alpha blending (Check image for explanation). I didn't add support for using sprites to alter the "shape" of the object (check other pic) when i made the shader which resulted in the object taking the shape of its collider, but I need to add this now. I tried to implement it by simply multiplying the output by MainTex.a, but that results in some weird transparency glitches that neither I nor chatGPT know how to fix. Please help me.
holy shit that's a wall of code
let me fix that
there
From what I've seen fixing this problem isn't possible without rendering and blending the textures separately to a temporary buffer
Stencils will write based on all fragments/pixels produced by the mesh. If you want to exclude the fully transparent parts of the sprite texture you could use alpha clipping. e.g. clip(col.a - 0.01);
UI usually uses ZTest [unity_GUIZTestMode]. I think that's LEqual or Always(?) depending on the Canvas mode. If you want a specific depth you can set the mode on the Canvas component to Screenspace-Camera, drag camera in and set the plane distance.
For on top of the rest of the scene and after post processing, Screenspace-Overlay is usually used. Or could try an additional camera.
Is there an equivalent to this for UI toolkit? I don't think that one uses Canvas
Hey, I have a question. I'm trying to make a shader, that would make everything behind a plane slowly fade. This is what I've achieved so far, but I have a question, is it somehow possible to make it nicely blend with the skybox, and not a pre-set color? If yes, how would I do that?
You could sample the skybox texture as the color to blend to
I don't know if there's a way to directly reference the current skybox from the shader, but at least you should be able to get it with a script and set it as a global texture for convenience
hm. And how should I sample it? From the cubemap or somehow else?
not gonna lie, shaders are still kinda black magic for me
I'm trying to make a shader to simulate water depth based off of the distance from a ruletile's edge.
My current approach is to use a custom Gaussian Blur subgraph to blur the white edge of the water's sprite and use that as the lerp value between two colors. However the blur subgraph doesn't work well past the first tile in a tilemap. It results in hard edges.
Any thoughts on an alternate approach?
Gaussian Subgraph - https://forum.unity.com/threads/urp-sprite-gaussian-blur-customer-subshadergraph.1327968/
thinking of it, would it be possible to somehow override the alpha value of whatever is rendered beyond the plane? Like, whatever is showing up as black here - make it have alpha = 0, and similarly for the gradient. Not sure if what I'm saying makes sense, but what I'm thinking of, is that this could make things slowly fade until they completely disappear.
Ofc I don't mean a transparent material, I mean making a shader that affects whatever else is visible beyond it.
This would be complicated since skybox usually drawn after opaque
But maybe you can render a skybox using second camera into a texture and draw it as background image then, when drawing the opaques, use a grab pass and blend the grabbed pixel with the road pixel. Complicated and unnecessarily heavy when simply blending opaque and skybox in one pass as mentioned above would do just fine.
I mean making a shader that affects whatever else is visible beyond it.
btw, this basically what transparent means
where would I place that inside of the shader?
would that just go inside of the fragment shader? or
Which render pipeline are you using?
Yeah, that does sound complicated. But then, how should I blend the opaque with the skybox? All I've achieved so far is just making the road fade into some color of choice. And since the skybox isn't quite uniform in terms of color around the map, it doesn't work quite well
URP
If your sky is a procedural shader, you can make it a subgraph in place of sampling the skybox texture
Either way it simply outputs a color for doing whatever you need with it
Using the reflection probe node is simpler but it prefers reflections over the sky which doesn't look right if you have probes, and isn't as high resolution as the real sky
Guys is there a way with ShaderGraph to disregard the UV of a mesh?
I have this model, here and a section of it is using a grid shader I made. Except it's moving in different ways.
What kind of uv's do you want the texture to be sampled with instead?
See the arrows. The top one is moving away from the screen, Z+. The bottom one is moving top-to-bottom, Y-
I want them to move at the same direction, and more so, these are blocks that will make corridors (I'm going to combine them at runtime), so I want them all to match.
Ah, and you cant just fix the direction of the uv's on the mesh itself?
Well I could, but the generator might rotate them.
What I want is basically the shader to take the whole space and do its work, no textures, no UVs
you could use a triplanar node and rotate the uv's 45 degrees in the z axis so you dont get a blend
Let me see if that works. I don't know what that is, but I'm gonna check.
Ensuring the UVs are right in the first place is by far the simplest option
yeah, I agree wuth Spazi, if they need to flow better you need to control how the meshes are oriented when generating, or create variants maybe?
I guess that's what I'm going to have to do, then. Because I can't seem to fit TriPlanar, since I'm using a generated texture
why are you avoiding sampling a low res grid texture, will be cheaper than generating one usually
It's a cubemap skybox, not sure whether that counts as procedural. But thanks for the thing you sent, I'll try it out as soon as I can get on my PC
You can use triplanar projection with procedural textures, and I'm sure you can offset UVs relative to world/object space as well
Buut none of that is as practical as having proper UVs to start with
Yeah. I mean, I'm not that good at UVs, so I wanted to be lazy lmao. It works more or less, some corner of the room is a bit wonky because, well, I don't know how to UV it properly. It's going to have to do. Else I'll never move on. I wanted, like, when the level is generated and combined, to take all the sections and process it as one, so to speak, like it's one whole model instead of blocks.
And have all the generated textures fit nicely and seamlessly
Are the meshes entirely procedural?
I'm using the following in my shader: ```
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
...
uint meshRenderingLayers = GetMeshRenderingLightLayer();
and getting the following: ```
undeclared identifier 'GetMeshRenderingLightLayer'
It worked fine in an older project, but here the function seems to be missing. Was it moved/removed?
It used to be defined in RealtimeLights.hlsl
oh I just found this
I used clip(MainTex.a - col.a); which resulted in the desired behaviour. Thank you!
Draws the renderer mesh with the transform and material of that renderer.
I have another problem with this shader, why is it that when i set the color to black, it becomes transparent?
Even when alpha is 1
NVM this no longer happens
I'm trying to understand what stages actually move the texture data , for example i have the following
maskRenderTexture = new RenderTexture( texIndex.width , texIndex.height , 0);
maskRenderTexture.filterMode = FilterMode.Bilinear;
Graphics.Blit( texture_from_material , maskRenderTexture);
paintMaterial.SetVector(positionID, pos);
paintMaterial.SetFloat(hardnessID, hardness);
paintMaterial.SetFloat(strengthID, strength);
paintMaterial.SetFloat(radiusID, radius);
command.SetRenderTarget( maskRenderTexture );
command.DrawRenderer( rend , paintMaterial , 0 );
command.SetRenderTarget( rendTex1 );
command.Blit( maskRenderTexture, rendTex1 );
can i add another command of rendTex2 directly below ?
command.SetRenderTarget( rendTex2 );
command.Blit( maskRenderTexture, rendTex2 );
You're adding these commands into a queue, and they will be executed in the order you add them. maskRenderTexture will have been drawn to by the DrawRenderer command by the time another command after it is executed. Whether any pixels are actually written to depends on your vertex shader.
I combined this shader with an outline shader, however I want the outline to not render through intersecting objects. How do i achieve this functionality? (Check picture for reference)
Here is the shader:
Playing with deferred rendering and getting these weird artifacts. Any ideas? It seems to be caused by the ShadowCaster pass so I'm guessing the mesh casts these weird shadows on itself
You can probably fix this by tweak the shadow biases on the light
wasn't the issue in this case, I just found out I messed up some stuff in my shader
I made this with shader graph. I want to animate the level value. ANy help?
plop in time node into level, or probably more likelly into a sin wave and then into the rest or something but I don't know how you want the animation to look like so suit yourself
I tried that but it didn't work
I want the green color to increase with animation as the level value rises
I know you just said that and thats how you animate things: over time, so you need the time node and plug it into things to modify your green level
Is there a way to create custom deferred shading models in URP without modifying the StencilDeferred shader in URP's source code?
thanks
Can shader graphs be exported to older versions of unity from before shadergraph?
This would've been so simple if they hadn't made UniversalRenderer and UniversalRendererData sealed 🤦♂️
I think if you use the debug inspector on the URP asset/renderer it has a reference to the stencil material that you can swap out.
No, the shadergraph package is required for the graphs (and it's generated code) to work
thanks! I'll try it out
Seems to be working great, thanks! I guess I'm saved from making my own srp for now
Can someone help me with this? Bumping rq cuz I am bad at waiting
try stencil!
I would, but the shader already has a stencil, and i can't give the outline its own pass because it needs to work in URP
And URP doesn't support multipass shaders for whatever reason, so I can't add another stencil operation
i think you can have two passes, somebody said you can use shadowcaster pass as a hack
only two tho, no more from what i heard
How do i do that?
this is not mine, just searched google
explain a bit about lightmode
This did not work sadly
I've just found another issue which makes everything even worse, because for some reason using stencils in a shader seems to break SpriteMasks
As you can see the sprite masked apple is rendering through the outlined object (Which is not supposed to happen at all)
And the sprite mask also seems to affect the outlined object itself
This is weird
Hi ,
i'm trying to make gradient noise using fragment shader and I kinda did, it's kinda working but I can see the UV squares on the shader, is that normal ?
I'm new to shader in general but is it normal to see those uv squares along the shader ?
the pattern is a bit clear, i dont know if u can see it or not so i've highlighted them
no, not normal that shouldn't be the case
any idea how to fix that ?
nvm I think I fixed it
yo guys. does anyone know a good guide on how to make cel shading
i don't know nothing at all about dealing with shaders.
It's difficult to do much anything with shaders without knowing at least the basics, but you're in luck since there's an official configurable cel shader
https://docs.unity3d.com/Packages/com.unity.toonshader@0.9/manual/GettingStarted.html
thank you dude!
also, can you give me a video or something to teach me something about it?
i'm really looking forward to know unity system as much as i can
and is this compatible with URP?
Yes, check the requirements page for specifics
If you work with URP and like to learn by making stuff, I'd say look for Shader Graph beginner tutorials and get cracking until the system starts making sense
If you want deeper and more theoretical understanding of what's going on and aren't afraid of studying, try these:
https://halisavakis.com/shaderquest-part-1-graphics-concepts/
https://youtu.be/kfM-yu0iQBk
They go through the same stuff but one's in blog format, another as VoD
https://www.youtube.com/watch?v=7qtrJBG-KOs is this same shader technique repeated and blended over and over? If so anyone got a very rough guess of how its made? Especially how all this noise is perfectly mapped onto a sphere
Hi,
is it possible in anyway to save the "add operator(+)","subtract operator(-)" & "multiplier operator(*)" in a variable ?
I wanna make dynamic shader without adding branches.
for example Lets say we have 2 output of 2 different functions A and B , and lets say the add & subtract operator, are the result of function called op(float x ) , where if x was bigger than 0.5 the results is ADD else SUBTRACT , and the results is safed on var C
I wanna be easily right code like float final = A * C * B >> if C was ADD then the result would be A+B , else A-B
is it possible to do something like that ?
Is there any way to preview screenspace shader on scene view? (not using post processing stack)
How are you injecting the shader if not through post processing? If it's on URP a custom pass should still work on the scene camera
Okay guys, I hope someone has tried this before in the core pipeline; I've spent way too many hours in trying to create the perfect exhaust heat effect, which thankfully has been made easier by a distortion shader being introduced in the default unity particle shader options. the effect is near perfect except for one missing detail that would make it complete. does anybody know if it is possibly to add a blur effect to refraction shaders in the Core pipeline of Unity? the distortion looks nice, but usually there's a blur within the hottest of the heat distortion particles. I know it's possible to add that blur in HDRP, however can I apply whatever shader coding enables the blur also in a non-HDRP particle effect? on the right is an example of the blur I used in HDRP that I wish to concert into NON-HDRP to the left. if anyone of you can help me, please ping/reply/DM me! thank you.
this is the current setup of the particle shader
hi ,
i wanna ask about how things work , what is the right approach to do things.
lets say I have a function that creates a white ring at the distance of my choice ( alpha ring )
how do I (add) rbg ring to a float4 color(1,1,1,1);?
is it float4 fin = color.rbga + ring.rbga; ? would that results 1 color overlapping the other since one alpha is just a ring ?
If the function returns float4(1,1,1,ring); you'd likely want to multiply by a colour (i.e. float4(1,0,0,1) for red), to tint the ring.
Assuming the shader is transparent so the alpha output is used
Using OnRenderImage function. It takes screenspace texture and screen buffer as arguments.
Btw I found the solution.
Adding the attribute [ImageEffectAllowedInSceneView] above the class fixed the problem
I'm writing a shader where I need to sample one of 4 textures depending on some calculations. What's the most performant way to do this?
I know I could use if statements, but I'm not sure if this would be very performant as I need to sample the textures many times. Here is a simplified example:
sampler2D _TextureA;
sampler2D _TextureB;
sampler2D _TextureC;
sampler2D _TextureD;
fixed4 frag (v2f i) : SV_Target
{
float4 color;
if(someValue > 0.03f) {
color = tex2D(_TextureA, i.uv); //Do this a lot
} else if(someValue > 0.02f) {
color = tex2D(_TextureB, i.uv); //Do this a lot
} else if(someValue > 0.01f) {
color = tex2D(_TextureC, i.uv); //Do this a lot
} else {
color = tex2D(_TextureD, i.uv); //Do this a lot
}
return color;
}
hi, thanks for responding , but that's not what I meant , the end result is supposed to be something like that , the grey part is suppose to be transparent
how do I just print the ring on the edge and print the rest of the circle with another color (i.e. white) and make the outer most part (grey area) transparent ?
is there an easy way to get rid of those weird backgrounds?
You'd likely use two circle SDF functions to make this. e.g. step(0, distance(uv, float2(0.5,0.5)) - radius) (or possibly with step params swapped or 1-result if it's inverted)
Use a circle with a larger radius as the alpha output to make the outer part transparent.
And use a smaller circle as the t input of a lerp to create a white circle on a red background.
e.g.
float4 color = lerp(red, white, innerCircle.xxxx);
return float4(color.rgb, outerCircle);
You need to connect the A channel of the texture (or Maximum of both texture A channels in this case) to the Alpha port in the Master Stack
creating a seperate blend for the alpha seems to work, ty
hey, that worked perfectly , i might look into making the red color fadeout in the future but other than that , its perfect , thank you so much ❤️
anyone know how to masking using 2 position of gameobject?
In 2D, how do I hide areas of Sprite where the brightness is below a certain level? I mean... Just like Among Us' vision system. I want to solve this using 2D Light & Shader Graph.
hi,
does anyone knows how combine two shapes while keeping both of their color and alpha properties ?
lets say
shape1 : is a ring ( outter circle ) color is yellow
shape2 : is a solid circle ( inner circle ) color is white
how do I tell shader to return both properties without mixing them ?
i tried shape1+shape2 but i ended up with a larger circle instead of a white circle with a yellow edge
You'd use lerp(baseLayer, shapeColor, shapeMask.xxxx)
This example is also basically the same as a question above, so see my answer there : #archived-shaders message
thank you !
The Custom Lit sprite shader gives you access to 2D Light Texture which you can use for alpha with Step node to make stuff in the shadow invisible
Just be sure to use Screen Position UVs when sampling it
Hi there! I need help I want to show two or more textures in one object like upper area has one texture than lower area has another texture in pattern idk how to do it pls help
bassically something like this, do I need two materials for this or two shader for this idk
hmm... i was create node like this but this is result. how can i solve it?
What's the mode of the screen position? It should be default
if you ok, can i get sample graph?
2021.3.
I feel like the UV coordinates for 2D Light Texture may have changed at some point since I vaguely recall not having to use the Screen Position node long ago
But 2021.3. is already old
anyone??
Although it doesn't work on my Unity, I can fix this and make it work! You are my hero!
Well what is your Unity
My crystal ball is being cleaned today
2022.3.8f1
That one is no different from 2021.3. (or the later versions) in this regard
but it dosen't work, The environment of my game, there is one dim global light, and one light that is responsible for the player's vision. At this time, your graph doesn't show shape anywhere
Anyone read my previous post?
Hi! I am passing a texture through a Sample Texture 2D LOD node and then through a Step node. I want to add a bit of noise to the result but I am not sure how to change its UV since it's an RGBA and not a texture. Is there any node for that?
I created this shader and now when i start the game, itfreezes for a bit then plays as normal, is there a way i can bake it like in blender so that it reduces load time?
There's no way to convert RGBA to texture in the shader. But how you add the noise depends on the result you want. Maybe try adding it before the Step, or to the UV before sampling to distort the texture.
anyone else having these issues with cyan's shadergraph custom lighting? when i try to add the _LIGHT_COOKIES keyword and enable it, it doesnt work at all and these errors start showing up
Might just need to Add some value to the Time output to offset the value. When the AngleOffset is 0 the voronoi will look like a grid, perhaps that's what you mean by freezes?
the whole game freezes as if its loading in the shader
i read somewhere that voronoi is expensive so i assumed it was having an effect on my game
oh yeah and the main light cookie subgraph just destroys the shader
Maybe try opening the subgraph and save it
Ive tried that already
it might be directx
d3d11 showing up in the console alot
nope
same error
augh it was working before sorta
i had cookies working on one material
now it doesnt work on any
i got it working !!
there was a duplicate keyword for light cookies that was messing it up
I was actually trying to do it after the Step but it's fine as I got something I'm happy with without the noise.
On another note, is there any way to get more lighting information other than the direction on Shader Graph such as the light's intensity? Or should I make a property for it and update it through code?
is it possible to feather out random intermediate node like this one like where white meets black it would bleed into it
you can do it by one pixel by checking if ddx and ddy are nonzero and if so, using an intermediate value instead
but the easier way is to build it into the function that gives you your pattern
hey is there any way I can do an InterlockedOr in a fragment shader on a RWTexture3D<uint4>?
what is the equivalent to shader graph's (Normal vector) and (Normalize) node in fragment shader unity ?
is there is any shader graph to fragment shader converter ?
SG makes fragment shaders
I think you have some misunderstandings about terminology
i do understand that , but im not sure what is the equivalent to shader graph's (Normal vector) and (Normalize) node in fragment shader unity?
well normalize in sg is Normalize(float2/float3/float4) in fragment
while Normal vector in sg is, .(dot)normal in fragment
You obtain the normal vector using a variable with the NORMAL semantic in the vertex input struct (usually Attributes/appdata).
That'll be in object space. If you need other spaces there's functions to convert it. Depends a bit on the pipeline. e.g. URP/HDRP there is float3 normalWS = TransformObjectToWorldNormal(normalOS);.
To normalize, can use normalize(vector) (though if you use the above function it'll also normalise for you)
Property updated via code sounds good if you need a single value for the entire mesh/object.
Otherwise might need custom functions to access more lighting data. For URP I've got : https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
thank you 🙂
bros, if anyone knows.. I'd appreciate help
I just want to divide the object into areas based on how the light hits it. Currently I am just using a dot product of the normals with the negated light direction but when I increased the lighting intensity a lot, the lit area increased on the object but the part selected by the shader did not because of course it wouldn't, it is not considering intensity at all.
sample both textures and branch between them based on position
how can I hide obvious color banding in my shader gradients? the net says 'Blue Noise' but when I try to implement blue noise it just looks like muddy pixelated garbage
my eyes are picking up very clear banding rings in this, especially at the outer most edge, I want to hide that banding
Enabling camera dithering in URP should fix this
is that done on the camera itself or the URP renderpipeline asset or somewhere else?
camera component should have a checkbox
Oh yeah I see it now. Will that function in scene/game view or only in build? Looking at my gradient in scene it doesnt appear to be changing at all when dither is flagged on/off 🤔
Game view yes, scene view no
Shader generated gradient here
It also uses rapidly animated blue noise from the looks of it
Hm yeah for you I can't see the banding on on the right, but for me in game view, game is playing, dither set to On, the banding is still pretty noticable
aproximately
is it maybe my shader is the problem?
if the noise is roughly the same scale as the bands (so it breaks them up but it doesn't look very noisy) and it changes every frame, then it looks fairly smooth
Hi, I am making a marble texture for my video game map. How would I make a procedural texture in the unity URP shader graph like this texture? I have inverted the Voronoi texture and added a simple noise texture but I have not gotten the look I want.
left is without dithering, right is with dithering; I am just adding 0.01 times a random number between +0.5 and -0.5 to the values. On the left you have pretty bad banding, on the right, the noise breaks up the banding.
Hi all
I have a typical leaf card cutout texture, and model of trees with many of these leaf cards
Is there a way for the entire vertex of a single leaf card mesh to know where the "leaf branch pivot vertex" world position lies?
https://www.shadertoy.com/view/Xs3fR4 Found this on Shadertoy
dank I will try it out
Woah, I’m gonna use that tool in the future. Thanks for the link!
Yeah problem is im only comfortable with shader graph really im animator not a coder I can change the values at the top but doesnt give me enough to work with
Anyone know how I can make this in urp shader graph
playing with outlines on my models. Hoping to figure out a way to get a cool rim lighting effect like vagrant story. Is this possible?
How bad of an idea is it to have a water shader output it's height and normal values into a render texture and then sample single pixels with AsyncGpuReadbackRequests for things that should swim? 😅
Does anyone know how to fix the problem, that only on mobile devices, some shaders/materials appear black?
Not sure about toon shader, but in the game that lightning "rims" were made by duplicating model, making it bigger and putting behind original
Maybe not helpful, but interesting I think 😉
Found their concept
Oh yeah I read that too! I never saw that concept piece though, that's super dope!
I might try that for fun, what's the best way to do that within Unity?
Not sure if this matches your needs but below you can find an implementation of that method built for URP:
https://youtu.be/VpIIFdwTKyQ?si=Tof2owVBJTJedo-2
✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3
Rim lighting is a shading technique that highlights the edges of a model. It's useful to add a moody atmosphere or help an object stand out from a dark background. This effect gets the main light in a custom function node to emphasize the shadowed side of a model.
👋 Subscribe for weekly game development vid...
It's amazing to discover these practical solutions that were used in times with fewer graphical resources 😳
does anyone have an idea how to fix the behaviour I'm struggling with the shader I coded? I'm not using a pipeline/using the default. I was trying to make an outline shader, but for some reason, when I apply it, it overrides everything and sits in front of other sprites. On top of that, it also drags a transparent shadow over the other sprites
You should modify the sprites-default shader (or use Shader Graph), not make one from scratch. You can find the Built-in Shaders in the downloads dropdown for your release https://unity.com/releases/editor/archive
Hello, please tell me, what should I add so that the texture that I apply can be tiled?
The problem is that in the UnitySprites.cginc file in the v2f structure there is no uv field
it's not tilling
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.
You want to use o.texcoord rather than uv. (It's the TEXCOORD0 variable that's used to sample the main texture, can be named whatever, but I imagine the fragment shader here expects texcoord)
Also make sure the Wrap Mode is set to Repeat in the texture import settings, or it'll just stretch the edges of the texture.
Did you even read my message
why do need to use texcoord0 instead of uv coordinates?
texcoord and uv are just variable names, they can be named anything but as you're using the SpriteFrag fragment shader from UnitySprites.cginc, that is written to expect IN.texcoord.
You must use TEXCOORD0 in the vertex input struct (appdata) to obtain the first uv coordinates channel of the mesh. If you use TEXCOORD1, that's the second uv channel (which sprites usually don't have afaik)
I have a shader where I put on a specular,normal and diffuse to have a metal plate with holes. Also an y cutoff alpha. I found some random textures which suited it. I have never created tga files myself. How should you edit these tga files so the cutouts are circles instead of squares?
I tried photoshopping the squares to circles, but it didn't work 🙃
Usually you 3d model surfaces and bake them to normal maps. It's not easy to hand-paint a normal map as the colours need to be very specific to produce the correct vectors.
That explains why it looked so odd
I guess maybe I should just try to find a new material with circles. Hope it works if I overwrite the textures
Please refer to the post that this is a reply to... I found both the HDRP shader file and the core shader file. is it possible to port whatever segments of code that cause the blur to be added to the default unity distortion shader?
From a quick google it looks like Photoshop does have a filter to generate normal maps (Filter > 3D > Generate Normal Map). So maybe if you can just create a bunch of repeating circles and use that it'll work?
I tried that, but only with like 5 circles. Maybe I should edit them all and then try again
That shader file on the right is already compiled. You probably want the source itself. e.g. https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/Particle Standard Unlit.shader (or download the built-in shaders from Unity's site, see #archived-shaders message)
Even with the source it'll probably be difficult as HDRP has a different core ShaderLibrary so most of the functions won't be available. You'd need to find wherever they are and copy them.
I think it would be easier to find a built-in rp example of blurring. It typically requires sampling a texture multiple times with some offsets, then averaging (or using a specific convolution)
Well, here's the issue. I have no idea how to write shader code. I do all my VFX editing in a visual editor like the default Shuriken particle effect editor in core unity which requires no programming, so I have no idea how I'm supposed to manually write whatever code that cause the texture to blur.
Maybe something like this https://gist.github.com/baba-s/386e66cbef08330e14a527d475c541f9
okay, but where am I supposed to plunk it wthin the shader code?
Could you sample a lower-res MIP map of the opaque texture?
Can probably add the passes to the end of the other particle shader, and copy the Factor property to the Properties block.
It's using GrabPasses to grab the screen after rendering to alter the image further. Might be kinda expensive though.
also how do I copypaste a built-in unity shader?
This is in built-in so an opaque texture doesn't really exist (even in URP I don't think it has mipmaps?). Might be an option if GrabPass has mipmaps?
I mentioned how to get built-in shader source files here #archived-shaders message
expensive as in render heavy?
because if so it is only used by the player, meaning it's almost unlikely that anything besides objects that the player uses, also uses that effect
Yea I was referring to performance wise / longer to render frames (mostly gpu side).
The grabpasses have a cost as well as the overdraw from two additional passes (is drawing those pixels again). One of the passes could probably be merged into the main pass of the particle shader but that'll require shader coding knowledge.
welp, I clearly did something not entirely according to plan.
lighting effects start causing this visual artifacting
we're getting somewhere
okay so something is likely set up wrong in how the code is layered.
Ok, nothing I tried worked. I will try to contact the creator of the material 😂
Hi. I've made a wind shader following this: https://www.youtube.com/watch?v=Ctbqax1XRiE I do not use the External Influence part since i'm using the shader on trees. I have a weird issue with some of my sprites. The animation Jumps based on world position.
Now my initial thourght was it had something to do with the offset we use to vary the animation based on its world position. But if i remove that node from my shadergraph it still persists. Does anyone have an idea what the issue might be?
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH
Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - https://www.patreon.com/sasquatchbgames
Wishlist Veil of Maia! - https://store.steampowered.com/app/1948230/Veil_of_Maia/
Wishlist Samurado!
https://store.steampowere...
Interactive Wind Shader for your Foliage...
hi all, can anyone help me pls? why scenecolor node on URP 2022.3 on unlit base color show me grey texture? Depth and opaque texture settings are active
Is this with 2D Renderer? I'm not sure it creates the opaque texture (as sprites tend to be in transparent queue anyway)
Might be able to use a custom renderer feature to blit the screen to your own target & set _CameraOpaqueTexture. But then any shaders that sample it needs to be rendered after that feature executes.
Hello!! is it possible to combine Occlusion shader from VR with dissolve shader? (URP)
im trying to make water but neither transparency nor refractions seem to work the way anyone is showing, despite the graphs looking pretty much identical to others, is there anything blatantly simple im doing wrong and am big dumb dumb? (2022.3.9f1) (URP)
maybe, did you set your shader to be transparent?
well it is seemingly somehwat transparent at least, the colour's alpha is 158 as well so i guess it should be? the sphere in the middle of the water is underwater so unless it's transparent i dont think it should be seen
I don't want any guesses did you set your shader type inside the shader editor to transparent yes or no.
aye found it, yes it's set to transparent
ok good, I guess can I see the shader then?
well im planning on basing it on binarylunar's water shader (wont be able to ask that creator for help since he doesnt seem to reply to questions) so these two are lerped together with the foam (which seems to be the only part that fully works atm)
trying to reverse engineer it but idk, doesnt seem like it is an issue with version either since i loaded another project in unity 2021 instead of 2022 and it didnt work properly either there
yes, is 2D renderer
what are yall using for an ide for hlsl
The use of the Scene Color node requires the "Opaque Texture" option on the URP Asset to be enabled
Hey all,
i want to create some kind of "Hologram" Effect in Unity.
I want to add several geometric Objects and only render there contour.
Does anyone done this? I was thinking about using a Linerenderer for this, or a shader that only renders the contour. But im not sure if this is usefull / possible.
omfg how could i forget that 😭 thank you so much
Hey all
Hello, im trying to create a portal opening like effect. so for this i need 2 things occlusion to hide the front of the portal & 2nd a dissolve effect that fades out from center to outwards. So far i am able to get achieve both but separately for occlusion im using VR's occlusion shader but i dont know how to connect the dissolve effect to occlusion.
what i want is the occlusion dissolves from center & spread outwards
vs code with some shaderlab plugin, or if you want to pay use rider or smth.
Cyan I can't seem to get it to work, however you seem to know how to process shaders, so I'm thinking... would you be willing to help me out in a more custom tailored way if I pay you? I'll offer you 50$ if you can help me fix the render processing on this effect.
Hi!
I made a render pass that takes a render texture of the screen and passes it through a shader. It works mostly fine but the first thing the texture goes through is a couple of Sample Texture LOD nodes and changing their LOD value makes no change on the scene but it does in the shader graph. How is that possible? What might be going wrong?
Do you have mipmaps enabled on your rendertexture? are they generated automatically?
might wanna call GenerateMips manualy when you render the pass
also, this doesn't work on all platforms, you might wanna downscale the texture manually depending on platform
hi , what is the function for Shader graph's "view_direction_node" ?
also what is the equivalent for those in fragment shader ?
Pretty sure those are available in the fragment shader
sure they are but how ? where ? any example ?
The camera node
How do I learn fragment/vertex shaders? Either I'm googling wrong or there's very little information/documentation on it, I went through the basics here https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html but it's still really confusing. I tried making a face flattening shader but that didn't work unfortunately. What should I do?
broo ,, i know , i want the equivalent of that in fragment shader code ....
Turning them on worked. Thanks!!
https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Camera-Node.html gives the code for the node
glad to help! 🙂
Hiyo everyone! Just joined this server, and I'm excited to be here 😄 That being said, I have a question about programmatically adding shaders to a game object - I am checking if the renderer.materials list contains a material of a particular name, and if it doesn't exist, then to add that material. The issue is, once the material is added, it's name changes from DepthOcclusionShader to DepthOcclusionShader - Instance. Does anyone have any suggestions as to how to go about assigning a material to gameobjects that don't already have them at runtime? (also, if I'm asking this question in the wrong place, please point me to the right spot ^_^)
Hey! It is best practice to assign materials to .sharedMaterials, as .material and .materials could create new material instances. If you wish to change material properties in a script you need to use MaterialPropertyBlocks.
Thank youuuu!
Also make sure that you don't change material values in edit mode as that could create instances too 😄 instead use a material variant that you can check against in the script 🙂
🤯 so much to learn - thank you for pointing me in the right direction!
no problem! 🙂
Thanks ❤️
Is there any way to ignore the camera background on Render Textures? Or maybe manipulate the shader to remove the background (solid color)?
hi ,
im getting "undeclared identifier 'TransformWorldToObject'" , not sure what i need to include in the fragment shader to use the function ?
#include "HLSLSupport.cginc"
#include "UnityCG.cginc"
I already have both of them , do i need to pass the function somewhere ??
I don't know much about writing shaders but for some reasons Unity gives tons of errors when writing shaders (in HLSL at least) even when everything is ok so it might be because of that. If the shader works, you can ignore the errors.
unfortunately, it doesn't work , all of it is pinky now
I've also commented out HLSL and the error didnt change at all
something is not right
here , someone test it out please
Shader "test/simple" {
Properties{
_Color("Color", Color) = (1,1,1,1)
}
SubShader{
Tags { "RenderType" = "Opaque" }
LOD 200
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct vertIn {
float4 vertex : POSITION;
};
struct fragOut {
float4 color : SV_Target;
};
float3 normalWorld;
float3 normalObject;
void vert(in vertIn v, out fragOut o) {
o.color = float4(0, 0, 0, 0);
normalWorld = normalize(cross(float3(1,0,0), float3(0,1,0)));
normalObject = TransformWorldToObject(normalWorld); //undeclared identifier 'TransformWorldToObject' at line 29 (on d3d11)
}
void frag(in fragOut i) {
}
ENDCG
}
}
FallBack "Diffuse"
}
||undeclared identifier 'TransformWorldToObject' at line 29 (on d3d11)||
I'm using URP , is it not available for this pipline ?
you need to include this library (it's already in the packages, just easier for me to link it on github): https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl
URP functions are separated over many files now sadly and it's tedious to find where each and every thing is
most things you'll need will be in Packages/com.unity.render-pipelines.core/ShaderLibrary
and in Packages/com.unity.render-pipelines.universal/ShaderLibrary
I think
And you'd probably wanna get rid of UnityCG.cginc include
If I remember correctly that's no longer used
I'd recommend to dig around in the default Lit shader https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader
see what and how it works
it's really hard to customize some parts currently, they are working on block shaders which should make it easier in the future
if you need a simple unlit shader it's way easier
you'd still wanna dig around in includes of includes tho, they do this silly thing where they separate the passes into includes #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitForwardPass.hlsl"
I don't even know how they write these things
Depends, do you want transparent objects to show up in the rendertexture too?
What's your overall end-goal? 😄 There may be a simpler way to achieve
There is a single, opaque object in the scene, on its own layer. There is a Render Feature on the URP Asset which does 3 custom passes. The last pass is the one which I mentioned earlier which goes through an LOD texture and the color of the background is interfering with the shader effect as, after the LOD node I have a step node, and if the background is light enough, it is considered by the step node, causing the whole screen to take the effect that I want to apply just to the object.
is there a way to clamp shader properties between specific values?
Hi, I had a question about a specific tutorial and wanted to see what my options were. I was wanting to find a nice stylized looking cloud flooring for a part of a project and came upon this tutorial: https://www.youtube.com/watch?v=Y7r5n5TsX_E
Sign up via my link will get two FREE months of Skillshare Premium https://skl.sh/romanpapush
—————
#Update: Blender 2.8 is out! https://www.blender.org/
—————
Heyo my dudes!
I really hope you will enjoy this advanced tutorial for complete beginners!
By the end of this video you will master the Air-Bending techniques of the ancients and will le...
But he makes a mesh with 100,000 polygons and that sounds extremely expensive?
I was curious about what a feasible polygon count I should be looking for is or if I should be looking at other options, etc.
Like, what's the best way to optimize this into a feasible option?
Hey everyone im new to shaders in unity! And i was wondering why my material has this weird grey tint
Its just the default material made from Unity
I could just keep the camera's background black and on the last pass' shader, instead of keeping the part out of the effect transparent, I could just render the desired camera color.
Does anyone know if there is a simple way to make sure the top has a layer as well? It is happening because of an y cutoff which is requried for this. Should I just place a plate on top of it?
you can make the property a slider which lets you choose the end points; there's also the clamp function that lets you clamp the values in the code
I think it's because of the way unity models light scattering at low angles; if you had a normal map the material would look a lot less flat
That's what I figured @karmic hatch after messing with alot of the HDRP settings I've come to the conclusion it's something to do with the material unfortunately the textures that were included with the model didn't have a normal map so I'll have to produce one then test it. Thank you!!
hi ,
i was told that shader graph creates a fragment shader file, is this true ? can I see it ?
There's a "View Generated Shader" button at the top of the inspector when you have the shadergraph asset selected
thank you
hi, I'm trying to follow this tutorial , which at this time i should be able to see some results but in my case i got nothing at all , even though I did the same thing https://youtu.be/Uyw5yBFEoXo?t=265
Let's see how we can make an object glow when intersecting geometry around it. Very useful technique for shields, barriers, force fields, among other effects!
00:00 Intro
00:37 URP Setup
01:00 Scene Depth
02:26 Screen Position
03:40 Intersection
04:50 Color
06:42 Render Face
07:11 Intersection Shader - Noise Example
07:34 Intersection Example ...
here is my shader graph
and here is the ones that was used in the tutorial
it worked for him like this
yet mine had noo effect or whatsoever
does anyone know why it didnt work for me ? is it a hardwear issue ?
Check that the "Depth Texture" option is enabled on the URP Asset (will be somewhere in your assets, probably multiple under Settings folder if using the template)
it's already checked
the tutorial mentioned it at the beginning
I'm doing that on an older pc with intel graphic card , could that be the reason ? although it handles lots of graphics.
It's quite a simple effect, I wouldn't expect the graphics card to be the issue
i gree with u , its just i cant think of anything else :/
What material is the cube using? Is it an opaque one
Surface Type : Opaque?
yes
Hmm, did you save the graph? (Save Asset button in top left)
absolutely, i can even send it to u to try it urself
I don't need it, just trying to cover all possibilities. Not sure what else could be the problem
im restarting unity , maybe it's a bug , im also out of options :/
i cant think of anything
nope :/
Have you tried changing the value of IntersectionDepth?
yes , it makes the object over all brighter
I can see the effect on the object when it hit the camera though and only on the camera view
Is it a smooth cut-off or is it sharp?
i have no idea what u mean but all i have right now in shader graph is this and it looks invisable to the camera
if anyone got the time you could just recreate it and test it out and if it worked maybe share the whole project with me to test it on my side and compare it with the one I already have because Im out of options :S
i used the URP 3d template for this project
How bad of an idea is it to have a water
How to get Tilling variable from MainTex?
I should clarify I'm writing the shader in shadergraph so there's no exposed field when I create the property in the blackboard (that I know of)
It's in the inspector for the property
?
The graph inspector; click on the property in the blackboard and open up the graph inspector and you'll be able to edit the default value of the property and make it a slider and so on
oh my god, that makes so much more sense
thank you bro sorry I'm stupid 😭
given that transparency culling and sorting is non-trivial, how would you fake this appearance? 
I could slice the upper triangle off at the edge of at the wall but that wouldn't work as soon as the camera moved
another obvious option would be 'don't make it transparent'
which might be viable
if both meshes were part of the same object I could cull it from self-shadowing by first doing a depth writing pass, but that introduces new issues of having one single mesh be the whole thing
if I removed its back face you'd still see some of the transparency here
oh and on top as well since it doesnt line up 1:1
if the ordering was reliable and one of your meshes would always appear on top of everything else, you could use the opaque texture to generate the color (so set alpha=1 and color=lerp(mesh color, opaque texture, fake alpha))
Thats interesting, good idea I hadn't considered that
Anyone comfortable with geometry shaders or gpu instancing?
(cause I don't know my exact problem :>)
I'm working on geometry grass and I got following "pipeline":
- C# manager script (shader dispatching, compute buffers, settings, grass blade mesh ref, etc.)
- Compute Shader (populates compute buffers with: grass blade positions, rotations, heights & sway(it samples a noise texture))
- <Insert_Problem_Here>
IDK what's next.
As far as I know, I can pass the buffers to surface shaders but they cant create geometry.
How do I use the data in those buffers to gpu instance a mesh?
And im not talking about instancing game objects with a material that supports gpu instancing.
I cant do this with 7 million grass blades...
Might want to look into Graphics.DrawMeshInstanceIndirect (or the newer Graphics.RenderMeshIndirect, same sort of thing).
This is a fairly good example I'm aware of : https://github.com/ColinLeung-NiloCat/UnityURP-MobileDrawMeshInstancedIndirectExample
I personally wouldn't go the geometry shader route as I've heard they are slow and aren't well supported. But afaik you can also generate geometry (vertices, etc) buffers in compute shaders. I think you then draw that with Graphics.DrawProcedural (or newer Graphics.RenderPrimitives?)
Those are the kinds of functions to look into at least, maybe others can help further as they might be more familiar than I am.
NedMakesGames also has a bunch of tutorials with various methods, could be good to watch some of those : https://www.youtube.com/playlist?list=PLAUha41PUKAaCr_ExiPJtpDHmAK6H7Ss9
Thx for the resources gonna take a look at em
Hey There! I am trying to replicate this grass sway shader. I am made the part where the blade move periodically but I want them to move based on the noise for more random look. All I want is a way to move the grass blade based on the gradient noise, like when the value is white there is full displacement and when its black there is no displacement or something like that.
"when the value is white there is full displacement and when its black there is no displacement"
Then what you want is a multiply, likeposition + (displacement * noise)
Though I think a more usual thing is to use some scrolling noise as the displacement itself.
Basically you give the lower vertices of your mesh a displacement value of 0 and the higher a value of 1. (This can be achieved through a gradient)
When you multiply this by the noise value of a noise texture (that you sampled for you XY world pos) you get a new "vertex_displacement" value.
Then you will be able to multiply the vertex positions * a direction vector (of your wind) * the vertex_displacement you just calculated.
To then animate it, just move the noise texture!
Its quite simple once you get the hang of it
Yeah I tried that but the way I am currently doing it isn't supporting it. What I am doing is moving the vertices according to their y value. If a vertex is high, it moves more. This is good with linear movement but I have no clue how to actually replicate the wind here. Here is what I have as of now.
Your noise is currently mapped to the model UV0. As Remilia also mentioned above you likely want to "project" the noise down over the grass using the world position.
In terms of shader graph, use a Position node set to World space -> Swizzle (with "xz" in field) and connect that to the UV port on a Tiling And Offset then to the Gradient Noise.
And connect a Time node to the Offset port to scroll it
Heading off for now, so hope that helps
Thanks, will try it!
Already looks much better, expect for the fact every vertex is random haha.
Is there a way to project a planar map over geometry in shader graph? For example, if I have a sphere, and I want to map an image on it from one particular direction. If I could just use a transform/orientation to project a planar map through the center of the object that would be perfect
Thank you ❤️ I'll give it a try
Hey, so I looked into it and I'm surprised the implementation looks so straight forward.
Still I have my doubts on which one to use.
Do you know what the difference between Graphics.RenderMeshIndirect & Graphics.RenderPrimitivesIndexed is or do you think one will generaly perform better then the other?
(I figured you maybe know a bit more then me)
Graphics.RenderMeshIndirect: Is like how I imagined it to work.
I dont understand what CommandBuffers of Graphics.RenderPrimitivesIndexed though.
They look pretty similar tho?
Looks like a difference in how data is handled. But I cant figure out how Graphics.RenderPrimitivesIndexed works.
Why can't I connect this to the vertex position?
The chain of nodes is already used in fragment stage, or it uses a node that can't be accessed in vertex stage
Hey all, am I setting the value of a shader input via script incorrectly? For some reason, the values of the material instance don't seem to change, neither does the fragment output
Shader"Custom/FadeShader"
{
Properties
{
_Color ("Tint", Color) = (0, 0, 0, 1)
_MainTex ("Texture", 2D) = "white" {}
_PlayerPosWorld ("PlayerPosWorld", Vector) = (.25, .5, .5)
_ObjPosWorld ("ObjPosWorld", Vector) = (.25, .5, .5)
_DistanceModifier ("DistanceModifier", Float) = 10
}
SubShader
{
Tags
{
"RenderType"="Transparent"
"Queue"="Transparent"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite off
Cull off
Pass
{
CGPROGRAM
#include "UnityCG.cginc"
#pragma enable_d3d11_debug_symbols
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
fixed4 _PlayerPosWorld;
fixed4 _ObjPosWorld;
float _DistanceModifier;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
fixed4 color : COLOR;
};
struct v2f
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
fixed4 color : COLOR;
};
v2f vert(appdata v)
{
v2f o;
o.position = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
return o;
}
fixed4 frag(v2f i) : SV_TARGET
{
fixed4 col = tex2D(_MainTex, i.uv);
float dist = distance(_ObjPosWorld, _PlayerPosWorld);
_Color.a = dist * _DistanceModifier;
col *= _Color;
col *= i.color;
return col;
}
ENDCG
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FadeScript : MonoBehaviour
{
[SerializeField] GameObject player;
Material material;
void Awake()
{
material = GetComponent<SpriteRenderer>().material;
}
void Update()
{
material.SetVector("PlayerPosWorld", player.transform.position);
material.SetVector("ObjPosWorld", transform.position);
}
}
I've not used the unity shaders before so figured this would be a simple enough test
I figure this is a unity thing as the shader seems to work when manually changing values ... would rather not have to dig through renderdoc
You need to use _PlayerPosWorld and _ObjPosWorld in your SetVector - those are the names for the properties. The text inside " " is just for display purposes in the inspector.
ahhh ok cheers
EDIT: yup that did it
For planar mapping you use the Position node, Swizzle into a Vector2 and put into UV port on the Sample Texture 2D (or other nodes that use uv coordinates)
https://www.cyanilux.com/faq/#sg-planar-mapping
So this seems to apply uniformly to the entire sprite, is there a way to make it apply pixel-by-pixel instead?
hmm actually that makes no sense
It's because I'm using the obj position rather than the pixel position
Comparing the world position of a player to a pixel screen position is a little more complex I suppose
I'm reading that thanks. And if you want to project it on a vector with a size?
You'll want to calculate the world position for each vertex and pass it to the fragment stage to be interpolated.
Something like, o.worldPos = mul(unity_ObjectToWorld, v.vertex); and add float3 worldPos : TEXCOORD1; to the v2f struct.
Then i.worldPos in the distance function in the frag
Yep
very nice
the last time I was writing shaders it was raw GLSL and I had to do all the projection and space transformation myself so that helps a lot
Not sure what you mean by this
sorry, I don't want it on eg X axis, I want it projected through a rotational transform
vector 3 or whatever (gulp quarternion)
There's Rotate About Axis or can Multiply with a rotation matrix (probably passed in from c#) that you can use to manipulate the position / direction projected in.
Still needs to be truncated down to a Vector2 for the uv coords since the texture is 2D though.
Here I have a transparent material on a tent roof, the lantern glass is also fully transparent with distortion
does anyone know what i need to do to have this roof render behind it? can't seem to figure out what i'm missing.....as you can see you can see inside the tent through the lantern glass
https://gdl.space/iyopesukib.cs How to get rid of this warning? the shader is working well except the warning is bothering
Try adding [NoTilingOffset] before _MainTex in the Properties block
Maybe also change the Tiling on that material to 1 on the Y first too.
this one worked! neat
thanks!
https://gdl.space/kusulaqahu.cs how to make this shader visible from the back?
Flipping them either via spriterenderer flip or transform scale also makes them invisible
You need Cull Off in the SubShader or Pass section, i.e.:
SubShader
{
Cull Off
Tags { "Queue"="Transparent" }
Pass
{
CGPROGRAM
....
lemmesi
ig that worked, thanks. But does the shader cull affect frustum culling? will these sprites keep drawing itself even when the camera no longer looks at it?
No, this refers to face culling. Cull Front will cull the front face, Cull Back will cull the back face, and Cull Off culls neither.
It defaults to Cull Back.
cool stuffs, shaders are a whole new world with new meanings
anyways thanks again, ig i can sleep now 
Not really sure if I should put it here since it's about draw calls and not really about shaders? But I believed that draw calls would allow up to 1023 instances no matter the amount of vertices and shader complexity.
It's not a LOD so why are these 2 different draw calls?
they have 8 and 15 instances respectively
(Built-in render pipeline btw)
https://pastebin.com/kQnEvhvR - main shader code
https://pastebin.com/gGHjVZz6 - Utility
How Can I refactor this shader code? I want to render two textures on my mesh
Hey!
Does anyone know how i can get main light position, or main light direction in shader graph using 2d renderer? main light direction node isnt working, or maybe i'm using it wrong
Hello again! - I have a shader that is reading depth information from a depthTexture and is performing pixel discarding actions in order to simulate occlusion. The issue I'm having is, is that the shader I have is attached to a separate material than what is natively on the game objects. How can I get the shaders that are already on the game objects to respect the pixel discard logic defined in my occlusion shader?
Not sure if this is the place to ask but I am looking for advice on how to create a non-interactive wire grid to show the galactic plane with my local stars similar to the blue polar coordinate grid here:
So just a round grid?
in that case for the circular lines you modolo the distance to the center and for the straight lines you modolo the angle
In a shader? I have yet to learn those and reluctant to invest time in the wrong direction
step(thickness/2, min(radius*min(fract(angle), 1-fract(angle)), min(fract(radius), 1-fract(radius))))
where radius = R*distance(UV, 0.5), and angle = N*arctan((UV-0.5).y/(UV-0.5).x)/(2pi)
(N is an integer and R/2 is the number of rings)
I was thinking about how a glint looks like the area between y = 1/x and y = - 1/x so now I want to make a shadergraph using this but I'm not sure how to do it. anyone got any ideas?
I want this to be based on the math instead of using a texture
this is what I'm talking about btw
I'm working on a game in which i have 2d items in a 3d enviorment that you can pick up. I'm using a basic billboarding (aka the transform.lookat to look at the camera) script
The items are really difficult to see, so i want to make it so that the item grows in size when you move away until a certain point. basically that the item stays the same size compared to the screen.
The reason why the items are difficult to see is because they are beneath water, so you have reduced vision.
I was send here because apparently it's something you do with shaders. i have 0 exprience with shaders and I have no idea where to start.
example of from farther away, i willl reduce the underwater effect, but it is still difficult to see after removing the effect.
Hey y'all, anyone know why this might be happening to me? Trying to add a keyword to my material so my shader can work, but I can't add it!
did anyone have any luck with writing a custom forward+ lit shader that won't crash the Editor in 2022.3? (Trying to write a stylized shader for Entities Graphics)
Heyo! I was curious if I could drive emissions on an object by a point light?
I.E: The same area that the point light affects (with the falloff), can I use that to drive the emission?
yes, you could do it in shaders, but if you don't need it to look crispy you can just make a sprite in an image editor
I'm trying to create a fog effect in my game. I want the borders of my level to have fog, obscuring the edge of my world. I do like the fog effect from Unitys lighting settings, but its based on camera position and not placed in world space. How can I achieve this?
Edit: To clarify, this is a top-down game
anyone got any idea?
Hey 👋 I'm trying to use unity's official toon shader(https://docs.unity3d.com/Packages/com.unity.toonshader@0.9/manual/GettingStarted.html) and the outline seems to not be displayed. I'm using URP and I guess I have to adjust my renderer but I can't see anything in the documentation. Anyone has an idea?
I just realised the shader was under "Failed to compile/Toon", no idea why
Hello wonderful peoples. If I wanted to draw a cone using a position, orientation and degrees, what would be the nodes to look into in shader graph? Thanks!
You can't draw solid shapes "out of the box" with shadergraph.
This would require either raymarching a signed distance field <- achieved with a custom function
Or some mathematicaly accurate ray intersection
Both of them would be done by rendering the shader on a base mesh, like a cube.
So actually, I want to get a world space / 3D cone in order to simulate a flashlight without using actual lights
So use this cone to lerp between a colour texture and black, for example
I figure this cone could be mathematically derived
Ok, that makes way more sense then 🙂
You can look at the sign distance fields functions here : https://iquilezles.org/articles/distfunctions/
They can be reimplemented using nodes
Interesting. This is a good If headache place to start 😌. Would be nice if there was an asset of collections of primitive shapes subgraphs that I could shamelessly steal, because I’m lazy
Thanks!
But for your flashlight simulation, you could go away with more simple maths :
- Transform the world position into your "flashlight space" (you can pass a matrix through script)
- Length of XY + Z * factor will give you a cone shape
Can I rely on your patience and ask you to explain that a little more fully so my childlike brain can understand it?
By pass a matrix by a Script you mean..? I have a script that updates a vector3 position and orientation I was hoping to use within the shader. Do you mean something else?
Long time since I studied matrix math 😅
The shader will be in charge of displaying, but you need to pass the "light" information to it in some way.
A position and orientation could be enough, but my example involves to transform the world pixel coordinates in the "light space" coordinates.
Matrices are very good for this, so you script could update a transformation matrix instead of position & rotation.
It's a simple one liner :
Shader.SetGlobalMatrix( "_LightMatrix", transform.worldToLocalMatrix );
In shadergraph, you create a matrix property with the same name, and multiply the world position by the matrix to transform it.
Ah ok cool, somehow never saw matrix in the graph options. Is a matrix 4 like a vector3 position and quaternion rotation mashed together
I should probably do the reading instead of asking, thanks very much!
No, it's more complicated than that 😅
Figures 🙈
Here 🙂
Yeah I just saw that, funny how my brain can ignore things I don’t understand, I swear matrix was never in shadergraph until now
Do you have the formula for a rounded box SDF that is rounded in both directions? the one from https://iquilezles.org/articles/distfunctions/ the internal values arent inner rounded
crude sketch on left of what I am refering to
cleaner example
Hey everyone. I want to make sort of a progress bar in a unit icon. Like this:
It's sort of a cooldown feature. The shader takes a sprite image, messes around with its color and then draws a line that shows the current progress. The line is slowly crawling up.
What I need is to make sure that the line is always the same pixel size, no matter the texture size. Right now the line is drawn by the rectangle but its width is set up as a fraction of an output picture. I need it to always be the same size in pixels.
Can I set it's size in pixels? Or failing that, is there a way to get pixel size of a texture I'm using?
Would it be possible to use an Unlit Sprite Shader for a UI object with an Image? I have selected "Use Sprite Mesh" and the object shows, but the alpha clipping isn't being observed in the Game view. It looks correct in Scene...
ShaderGraph doesn't support UI currently. Though it does kinda work if you use Screenspace-Camera mode on the Canvas, not Screenspace-Overlay.
https://www.cyanilux.com/faq/#sg-ui
So for doing things like outlines on UI elements, would post-processing be the way to go?
or is there an easier way
oh let me try the outline component
derp
Could have a separate image for the outline to overlay on top. But that means making an outline texture too
i guess that wouldnt be so bad
i guess another option is to use Sprite Renderer and not use UI?
There's a float4 <texturename>_TexelSize property that stores (1/width, 1/height, width, height). Probably _MainTex_TexelSize in this case.
If it's a graph, there's a Texel Size node (renamed to Texture Size in newer versions)
I think you just need to subtract a value from the result. See this section in the 2d sdf page for examples : https://iquilezles.org/articles/distfunctions2d/#:~:text=Making shapes rounded
so I have this really nice skybox pack that looks like this
but the moment I change the shader it completely breaks
any ideas how to fix? I need to use a specific shader to use it in a game but right now I can't use anything but default
The distance functions to a surface are just distances, they "curve" just fine in both directions https://iquilezles.org/articles/distfunctions2d/ See rounded box
Seems a problem with the shader. You will have to post it
you telling me I am wrong and that this is a curvature does not help me remove this non-curvature :|
You are not looking at a rounded box there, why would you expect it to be smooth?
Hey I'm trying to code an unlit shader in HDRP and need the equivalent of a GrabPass in URP for a false transparency without using a render texture outside of the shader. Is there like a camera buffer or something that I can access?
There are textures you can enable and use that are similar to grabpass https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@17.0/manual/universalrp-asset.html#rendering
Does something like _CameraOpaqueTexture work in HDRP?
Sorry, I was confused whether you were talking about URP or HDRP, as URP does not support grabpass either, perhaps you meant to say BiRP (the built-in render pipeline)
I'm not that familiar with HDRP but https://forum.unity.com/threads/_cameraopaquetexture-in-hdrp.685423/#post-4585762 appears to be an option? Either way, it's just a case of researching those two terms until you land on a solution that works
If you're using shadergraph I believe the Scene Color node returns the opaque scene during the transparency pass, you can look at how they implement if if you want to do it custom
I'm trying to modify a raindrop shader to use what would be the equivalent of shadergraph's HDSceneColor node. Here's the shader - it's based on a YT tutorial:
I've tried to build it in shadergraph but I'm not a shader engineer so not getting very far
you can look at the compiled shader from a shader graph and see what HDSceneColor does
how do you look into a compiled shader? Is it in the material?
Yeah nah, that's like a 5000 line shader. And I don't really know what I'm looking for.
generally the names of the nodes are kept and they're called out to as functions, so you may be able to ctrl-f for terms
If I've used Lerp or Saturate for example, they're just there as functions
This is the only reference to an actual HDSceneColor in the compiled shader:
SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
{
SurfaceDescription surface = (SurfaceDescription)0;
float3 _HDSceneColor_7d30baade8ad4f6baa2f179fb49ccb23_Output_2_Vector3 = Unity_HDRP_SampleSceneColor_float(float4(IN.NDCPosition.xy, 0, 0).xy, 0, GetInverseCurrentExposureMultiplier());
surface.BaseColor = _HDSceneColor_7d30baade8ad4f6baa2f179fb49ccb23_Output_2_Vector3;
surface.Emission = float3(0, 0, 0);
surface.Alpha = 1;
return surface;
}
Would it need any special pragmas? How would you insert it into the shader above?
The Scene Color node is probably calling this function - https://github.com/Unity-Technologies/Graphics/blob/5d219cf30bde734b86f6fc5fb956315116c722b7/Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl#L30
Or SampleCameraColor directly - https://github.com/Unity-Technologies/Graphics/blob/5d219cf30bde734b86f6fc5fb956315116c722b7/Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl#L264
The SampleCameraColor in the first one is unrecognised so needs some sort of import (tbh shader coding is beyond me). But I haven't tried getting the Sameple_Tex 2D directly. That might work.
The only other option I can think of is to somehow use custom functions in the shader graph with the returns of the shader and blend the uv's of the scene color. Probably the longest way around 😄
Thanks though, that was really helpful
I've seen this sort of effect work in HDRP before, but it's hard to tell what method people are using to get it. I'm hesitantat to use a render texture as it's really expensive and my draw calls/framerate is already punished enough. Worse case I can do it though. Then there's the custom pass volume that could work but haven't looked into how that works, and I'm not sure if it's any better than the render texture. Shadergraph is an option but the effect on the uv's is all in mathmatica code so yeah. Then of course there is gettin gthe actual shader to work. I'm a mess atm to say the least.
What is "this" and what does it have to do with shaders?
That's just how game-view zoom works. And yes, this has nothing to do with shaders
There are too much channels, what's the category of this type of question?
Ok, thank you
Hi friends , what did the Shader>unlit Graph in unity 2019 has changed to in 2022? i cant find.(URP)
Did you check Shader Graph>URP>Unlit Graph
or something along the lines
It's somewhere in the adjacent menus anyway
Gnight all, anyone can help me with correct way to do something like a atmosphere... i have an game with some planets, and while i go inside any of these planets i need an atmosphere ... and while im inside these can i see planets outside like moon or any other planets in range... but i want to do some sky effect on it
Anyone can help me with some ideias on how to do this ?
Quite a big topic
You could check this video https://youtu.be/DxfEbulyFcY as well as other videos in that planet project series
the result is exactly i want to reach... i will try ... Really thanks Spazi, i did a procedural system generator with Sebastian Lague videos... but i dont know i dint find this videoabout atmosphere heheh
and I couldn't replicate water shader too... Sebastian lague shader is really really beutiful...
I am a newbie to shaders and I am writing my first shader. I want to write a colored dithering shader. I already have the one-bit dithering working, so my grayscale image is dithered into black and white using a noise texture. However, now I want to work on colored dithering, where the final image has a limited color palette (posterization), with dithering to prevent color banding. Right now I don't need code help, I just need help understanding conceptually how this is supposed to work, because I can't find a solid explanation online. The one-bit dithering conceptually makes sense: given the uv of the pixel, sample the noise texture at the same uv, and then use that as a threshold to determine the output value of black or white. And even color posterization makes sense conceptually: given the color of the pixel, find the nearest color in your palette, and then output that. However, I cannot understand how to combine these two effects. Once the color is posterized, how should you sample the noise texture exactly to create the dither effect? Thanks.
Nevermind, this blogpost https://shihn.ca/posts/2020/dithering/ and this wikipedia article https://en.wikipedia.org/wiki/Ordered_dithering#Algorithm are helping me crack it.
Hello, what happens when I connect a Vector3 output to a float input? Does Unity takes the x (being the first) or does it average the 3 components of the vector to get the average float?
It just takes the x component
I'm trying to make Kelvin van Hoorn's black hole shader work in my vr game using single-pass, because now It's only rendering in the left eye. Now, I followed the documentation https://docs.unity3d.com/Manual/SinglePassInstancing.html but I get an error with the UNITY_INITIALIZE_OUTPUT:
*Shader error in 'Unlit/Blackhole': undeclared identifier 'UNITY_INITIALIZE_OUTPUT' at line 60 (on d3d11)
Compiling Subshader: 0, Pass: <Unnamed Pass 0>, Vertex program with <no keywords>
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: SHADER_API_GLES30 UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING
*
Anybody here that knows what is going on?
(I'm on URP btw)
Show your vert. Do you have all the includes?
undeclared identifier means that the macro is not defined.
v2f vert(Attributes IN, appdata v)
{
v2f OUT = (v2f)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f,OUT);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
VertexPositionInputs vertexInput = GetVertexPositionInputs(IN.posOS.xyz);
OUT.posCS = vertexInput.positionCS;
OUT.posWS = vertexInput.positionWS;
// Object information, based upon Unity's shadergraph library functions
OUT.centre = UNITY_MATRIX_M._m03_m13_m23;
OUT.objectScale = float3(length(float3(UNITY_MATRIX_M[0].x, UNITY_MATRIX_M[1].x, UNITY_MATRIX_M[2].x)),
length(float3(UNITY_MATRIX_M[0].y, UNITY_MATRIX_M[1].y, UNITY_MATRIX_M[2].y)),
length(float3(UNITY_MATRIX_M[0].z, UNITY_MATRIX_M[1].z, UNITY_MATRIX_M[2].z)));
return OUT;
}
This is the vert, can I also ask what Includes I can try to add?
I also tried UNITY_INITIALIZE_OUTPUT(v2f,o) like in the documentation
I'm very new to hlsl and shader writing so I don't know half of the stuff I'm doing
Oh and i see i also tried adding appdata v to the v2f vert thing up top
but I don't know if that is correct
The UNITY_INITIALIZE_OUTPUT macro is just basically doing what you already did in your fist line...it's casting a zero to a v2f struct type and filling the struct with zeroes. You could replace it with your code like
OUT = (v2f) 0;
Although since "out" is a reserved keyword, I wouldn't use it for a variable name, btw. Just to avoid problems if you forget to upper case it.
So I should just remove the OUT = (v2f) 0;
Yeah I'm just editing a shader I found online so the whole shader relies on the variable name
Or do I missunderstand you?
lol, the dangers of the internet!
Or just remove the macro line since you've already zeroed it.
Try commenting out the UNITY_INITIALIZE_OUTPUT.
I would think a local variable declaration like that with an initializer would work without needing the extra code line.
Okay so in the scene editor it lookst correct when removing the UNITY_INITIALIZE_OUTPUT line, but when I play in vr I only see a pink sphere in the left eye, nothing in the right.
Should I also mention it's a raymarching shader?
Does that change anything?
The pink error color? Did you get another compile error?
No no compile error
Does it have to do with the URP?
oh yeah now i get an error with the variable "o" in this line: UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
Well, that's progress of sorts.
IDK, doubt it. URP supports it.
The struct is named OUT not o.
Yeah, it's a macro and needs the name of the struct you're operating on.
Aaaand now I'm getting some blue artifacts in the corners and in between the accretion disk and the swartzchild radius when I'm in VR looking at the black hole. When using a non VR rig (a normal camera)
I don't get these blue artifacts, do you know where I'm getting them from?
Nah, I don't do VR (although I've messed with it a bit). Maybe someone else will chime in.
The summary is that (as you know) you generate TWO images in the same pass...one for each eye. So if it works in mono, IDK why it's not working in stereo unless one of your eye-specific calcs is off kilter.
@robust stone
Okay, I’ll see, thanks!
I am debugging some distortion in my dithering shader, so I tried painting a checkerboard onto the texture (if the x and y of the uv are both odd, fill the fragment in with black, otherwise fill it in with white). The code to compute the fragment color looks like this:
float checkerboard = floor(fragment.uv.y * MainTex_TexelSize.zw.y) % 2 == 1 && floor(fragment.uv.x * _MainTex_TexelSize.zw.x) % 2 == 1 ? 0.0f : 1.0f;
return float4(checkerboard, checkerboard, checkerboard, 1.0f);
What I am seeing is the attached image, which clearly shows distortion. Either my code is wrong, and it is painting multiple pixels, or the texture/camera really is distorted. What could be causing distortion like this? Thanks.
Spazi Really thanks ! its works perfectly, really thanks man!
So let's say I want to make foot prints on sand, snow or mud. How? Any leads on this?
Pretty sure a normal / displacement map is usually used for that, depending on the situation.
Does anyone know why my grid shader causes this weird ghosting affect when I hover a gameobject over it?
I have no experience with shaders so this is utterly confusing.
Oddly enough, the ghosting only shows in the play mode window not the editor window...
i think i'm doing something wrong with the alpha in my shader 1st picture is how it currently looks ( you can see the background through the sprite) and the second is when i don't connect the alpha. ( cant see the background and colors are normal )
im currently adding the alpha's together to get the correct shape ( bottom - right node )
another question, can anyone tell me what is causing those white lines around my sprite?
I am drawing meshes using render mesh instanced,
accordingly to frame debugger, the max instances per draw call instance in 511?
Although unity states its 1023, why is that?
it took me 50+ hours to realize this
but the reason why shader wasnt working was because, I was account for a 1023 limit meanwhile the shader had a 511 instance limit
wut ?
fixed some of the earlier problems with my shader, but now im trying to add the normals. its a lit shader but it does not seem to interact with light at all
Sprite renderer has some extra lighting/shadow options when you turn on its debug I believe so might want to make sure that's all enabled
where can i find those additional options?
Ugh, one of the drop downs should say debug on it on there
Your character in the back there does receive light though, no?
yeah that one worked when it was just a normal map as a material. now im trying to include it in the shader that also switches outfits and colors
i found the extra debug options but dont see anything that could help me
I'm not too sure about shader graph, but I've had problems getting shadows/light to work in hlsl with urp, and usually it's because of some named attributes did not work with spriterenderer.
Have you tried just using a lit shader instead of sprite lit? Little rusty on this stuff, but I've a feeling 3D lighting may not affect it since your character is in a 3D Isometric world.
i was just trying out a normal lit shader and then it did reflect lighting but the sprite was messed up. tried changing some settings and now nothing is being rendered anymore. not even when reverting back to sprite unlit
finally got it working after reverting to an earlier save and building it again as a lit shader. but the lighting seems reversed somehow 🤔 @ebon basin
it only seems reversed when gpu instancing is enabled
Interesting. Not too sure about that one. I believe I had to break batching on some my sprite shaders for reasons involving some clipping and lighting issues.
actually I believe the issue was more that I was doing the billboarding logic inside of the shader itself.
anyway, if you're not running into performance issues, you can probably ignore it for now.
is it possible to use a texture atlas (color map) with transparent areas? would unity recognize the transparent areas as transparent?
If your texture uses alpha blending or alpha clipping then the alpha channel (or any other color if custom shader) can be used for transparency
But note that alpha blended geometry has very inaccurate depth sorting
Because of this you'd prefer to use alpha blended materials only with specific meshes that don't need precise depth sorting
weird question, I don't like how the bands briefly double up double thick when they meet at the center
is it even physically possible to prevent that though?
I would want it to.. never? double up? But I can't even picture what that would look like
the intersection point just feels discontinuous and sticks out like a sore thumb but I cannot begin to picture what it would even look like 'corrected'
they have to meet at somepoint, right? So maybe its just not possible to prevent it from briefly doubling up every cycle?
could they somehow meet.. without doubling up?
thank you. i’m trying to wrap my head around this 
hi , i'm trying to understand what this function represents
this is the function of the raw option for screenposition node ( shader graph)
what does IN means ?
is it frag in fixed4 frag(v2f frag) : SV_Target {} ?
I said "texture uses alpha clipping" but I meant material/shader uses alpha clipping
Materials are settings for shaders and shaders give you all the shading functionality
If you're using default shaders of your render pipeline then you only need to enable alpha clipping or transparency in the material
Probably not
Unless they shrink right near the edge
Or fade out instead making contact at all
which unity fragment shader function that return 0 if input is less than a certain value (ex. 0.9)
im trying to count on math instead of if stataments
Hi I have a shadergraph for mixing textures (triplanar) and if I make hole edges are totally broken
Blend I have set to 5, 5+ do nothing
Triplanar mapping relies on mesh normals
If they're messed up, so is the mapping
Its only deformed terrain :/
They look like extremely sharp edges, that can likely cause distortion in smoothly interpolated normals
And how to solve it? I have runtime deforming mesh and this is really bad
I'd try making the edges softer
If you want harsh cliffs it's better to use cliff meshes placed over the terrain than to try to make them with brushes, as the terrain component cannot represent vertical detail
If it has to be editable at runtime you may have to implement some forced geometry smoothing onto the deform operations
I don't like to hear that. I will not affect how the player will deform. When excavating the hole, I count on rounding, but when the hole is made in one place, these sharp edges can occur.
Is there no other solution?
Could try with a blend value of like 1000 just in case that has any positive effect
Nope nothing change
There's some ways to modify and recalculate normals using shaders per-fragment, but I don't know what kind of calcuation could help here
The terrain already attempts to smooth out its normals but they are per vertex so distortion occurs at drastic angles
I understand that, but it would like a solution. I thought of converting it purely to Sample texture, maybe that could help
You can sample textures in many ways, but if you use the mesh UVs, as the Terrain does by default, there will be stretching on any inclines as the texture is basically projected from above
We'll see, I'll try to redo it, I already had it done on the sample texture (I migrated from URP) and minor deformation was visible there, but it wasn't as terrible as with the triplanar.
The edges are better, but the middle texture is more distorted.
is there is an easy way to convert surface shader to fragment shader ??
im trying to write depth function in fragment shader similar to depth node in shader graph with eye mod selected, not sure why its so hard but there sooo much difference between the fragment shader and the generated code of shader graph
When using URP - do I have to stick with URP shaders or is it ok to use other ones?
A friend of mine is using some kind of Blender Addon to map Blender shaders to Unity with a custom shader.
I just wonder if this will block URP from working as intended?
are you building some kind of terraforming?
Not really, just a slight deformation of the terrain
Hey, folk. Still really trying to get this fixed. I am using a package called Stylized Water 2. I am using the mobile water prefab. I have been waiting for a response on their forum for a while but no luck. Some people are saying the shader calculations are dependent on the z depth of the camera. I couldn't find anything in the shader file, but I am also not very familiar with shaders yet. Any help isgreatly appreciated. The only solution we have right now is to have a static camera.
But as you can see, the edge of the water where it meets the land is glitching when moving the camera suddenly.
Just a quick note that i figured this out! Fixed by making the shader a transparent surface type instead of using alpha clipping...
Hey guys, I'm having some issues with 2D shaders, I never created shaders so I decided following some tutorials, but the issue is that even by following tutorials I never get the same result as the video.
I just need a simple shader for an outline, but I don't understand how to create it.
I tried following different tutorials, but I am never able to get the result that I want
is it possible to access the SurfaceDescriptionInputs in a shadergraph Custom Function? I really would prefer not having to have a bunch of spurious inputs for things like screen position etc
how to get the screenPosition raw using fragment shader ....????
does anyone know this ? i have been looking for weeks for this
has everyone left unity already ?
Hello!
I am having the issue mentioned on this post: https://forum.unity.com/threads/solved-texture-clamp-question.413334/ however, my shader is being applied as a render pass to a render texture of the whole screen. Is there any standard way of solving this or shall I try the suggestion mentioned on the last reply of the thread above?
float4 PixelShader(float4 pos: SV_Position)
{
float4 clipPos = pos / pos.w;
float2 screenUV = clipPos.xy * 0.5f + 0.5f;
screenUV.y = 1 - screenUV.y;
float2 screenPosInPixels = screenUV * renderTargetWidthAndHeight.xy;
...
}
Pseudocode
thanks a lot but i dont know how to use that , PixelShader seems to be a known function on its own
i have to mention im new to shader, i some but not everything
This is pixel (fragment) shader entry function
you are specifying it in shader source like:
#pragma fragment PixelShader
im sorry im still confused , i added it under pass but it caused an error and it looks like it has been already defined
syntax error: unexpected token 'PixelShader'
I have showed you the general approach. Algorithm. It will not compile. You need to specify renderTargetWidthAndHeight with correct data for example. Signature of function is not complete.
thanks a lot, but could you provide me with something to study or read or a video to watch ? i really dont understand what am i doing with that, and how would this get ScreenPosition Raw just like the shaderGraph node
This is what screenUV variable will contain in my code snippet.
ok thanks , i will try look into that a bit further
I still dont know what pos is or how to obtain it
Bump
any idea why ANY of the shaders i use created in shader graph have red background where alpha is 0? using same shader in different project - all fine..
why small shader like this tooks up 3.5 mb of memory in runtime? is there a way how to reduce and strip not needed shader variants from it?
Hi how can i fix the problem , is somebody have tutorial or how can i solve the problem?
I had a obj file i was covering fbx and when i wasmaking couple and when i came on unity it happened
Generated noises are expensive. This is why you see people using noise textures instead
Is your custom material assigned to the mesh? Imported meshes use generic embedded materials by default
thank you, will try to do it then.
Why is the material black? I am following a youtube tut but on their video it is very bright. I tried two different scenes but same result in both
Ambient occlusion is 0, which removes all ambient light
Omg lol how could I miss that
Thank you
Is there a good way to "increase" the ambient occlusion beyond 1? Because my skybox is pitch black (space game) and the light source I have isn't strong enough to light up the material enough, but I wanna make the metal look brighter than it physically should
Or rather, increase the reflectance value
Lowering the smoothness to 0.5 does this, but then I lose out on the shininess I want
No, but you should be able to separate the lighting skybox and the rendering skybox
That way the objects will be lit with a brighter ambiant sky, but the camera background sky will still be the almost black space
That'd have to affect all materials, but I expect is the easiest one
Well, indeed. Else you start to dive into the custom lighting route 😅
Could also add an intensified reflection probe or a different cubemap into emission, but it's unwieldy if it needs to be added in a PBR way
I think block shaders in the future should be able to make this kind of thing easier?
In theory, yes
Thanks, I'll check out your suggestions
I figured out a big problem, I hadn't done any uv-unwrapping on my blender model so that's why it was so extremely dark!
I keep forgetting these basic things 😂
the boots isnt mine but the cloth is my creation
Try to confirm that the material and texture work on the mesh by first assigning them as a standard material
It's unclear if the mesh can't show the texture or if something's wrong with the shader
when i couple on blender , the textures arent make problem but when i come to unity it happened on everytime
I don't know much about Unity, so I often have to get it done by others.
Can vertex shaders manipulate vertices only in a specific submesh or do they not have a way to determine the submesh
They don't have a way to distinguish submeshes.
But you can :
- Mask the submesh with a vertex attribute, like color / uv[X] coordinate, or based on position
- Apply a different shader/material to the submesh you want to deform.
Okay I'll look into colours
hi,
if I have the equivalent to (shader graph: spaceposition-default node) in fragment code
what i need to do to get the same results as spaceposition-raw
The raw mode should be what you have before the perspective divide step (screenPos / screenPos.w)
Material 'upheavtt Material' with Shader 'Shader Graphs/TextShader' doesn't have a float or range property '_CullMode'
how can i fix this?
it appears when destroying object
that is what i thought but when i compared the output of that compared to shader graph's its quite different
left is screenPos / screenPos.w , right is shader graph - screenposition(RAW)
how do we put a subgraph into a submenu in the context menu option
of our own choosing
eg SubGraph > Math Nodes >
i want to create the math node submenu
The text under the subgraph name (will say "Sub Graphs") in the Blackboard window is actually editable if you double click it. I think using a / should create a submenu
can we put them in the pre-existing categories or will they always have to be Sub Graphs/... ?
You can create your own categories too
ah nice
that was not easy to find in docs 😄
unless they never even mentioned it
kinda wish we could use hlsl files and make them into subgraphs
rather than use custom code nodes
why is it expecting _half for my function and not _float
It's not expecting it, it's not expecting that, it's undeclared
i have a function DepthToWorldPos_float
so why is it not finding _half which i didnt even want
kinda confusing
You can set the precision under the Node Settings. By default it inherits based on inputs.
so are these inputs all halfs then ?
bit odd if camera position isnt using full float precision
Idk, if you use one of the colour modes it would tell you. Might also just be the precision set by the whole graph (under Graph Settings)
Green means "switchable", so it can be either. The custom function node might be expecting both _float and _half to be defined (when set to inherit)
i see - seems switchable makes it work
never knew about these colour modes
very helpful!
any one know of any scripts out there to support exposing colour gradients in inspector for shadergraph
seems its the only field that unity doesn't expose in the inspector
How to make this water thingy more interesting visually?
what topic can make a shader animate it waterlike
Color gradient can't be exposed because it is not a valid shaderlab property type.
"Shadergraph markdown" GitHub package allows to expose gradients, but under the hood it is a 1d gradient texture.
Hi, I am looking into creating a 2D glow shader for a material. I want it to support GPU Instancing. The reason behind it is that as far as I am aware, GPU Instancing allows you to have the same material on different objects with different parameters. Is this possible and how would I go ahead with it?
GPU instancing is a way to tell the GPU to draw a mesh many times in a single command. This in itself isn't very useful if the mesh is drawn multiple times in the same position, so that's where shaders with instancing support come in. The shader can ask for its instance number, which is unique to each instance, and use that to affect how it's drawn. For example, you could use the ID as an index to an array that's passed to the shader. That's how the built-in properties like transform matrix are handled. Alternatively, you could use the ID as a random seed to generate unique(ish) data for each instance.