#archived-shaders
1 messages · Page 20 of 1
Using a Material Property Block on the Renderer would break SRP batcher compatibility without needing to mess with the shader itself.
does this brak compatability for all shaders / materials or only for a specific one?
Just the renderers you set the property block on
From which version is main light direction node available?
As it seems to be missing in the 2020.3 one
Seems to be 2022.1+, but can always use Custom Functions in previous versions to get light data.
For URP can use : https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
Does this work both with deferred and forward lighting?
Unity recommends not using cbuffer to declare constant buffers, but the macro they recommend doesn't work in compute shaders. Anyone would know which platform cbuffer would fail to compile for ?
Can someone explain what shaders really do? I try and read up on Unity docs, like shaderbox and stuff, but I just don’t understand what it’s doing. Is it me calculating lighting and how the light bounces off objects or is that done internally by Unity? If it’s done internally, what are the points of all the pragmas and such? Is there a benefit to HLSL/ShaderLab vs Shader Graph (SRP)
I’ve written compute shaders and that makes a bit of sense, with the parallelism and stuff
Shaders are basically small program that run on your gpu and render stuff to screen(or something else).
But when it comes to the render pipeline I get confused. Does the gpu automatically support things like drawing on the screen
Right, but like when I’m writing a shader, am I writing how light bounces off of objects or am I just defining things like normal maps and unity handles that
Light calculations are usually done in the shaders, yeah. Unity's standard shader.
Shaders are part of unity as well. You can't really separate them.
Depends if you use a vert/frag shader where you'd need to write your own lighting models, or surface shaders which can handle it for you (if in Built-in RP).
Bad wording... Shaders are part of the rendering process.
I’m assuming frag is where you would write your own lighting?
If you write a shader completely yourself without relying on unity Macros and functions and want to have rpoper lighting, then yes, you'll have to write it yourself.
So the pragmas define for me how light bounces off of objects?
Macros
Frag is short for fragment, also called pixel. It runs 1 thread per pixel on screen. Lighting is not a one shot function it includes all sorts of calculations both in the vertex and the fragment stage.
No. They're just a programming construct, kinda like functions but "evaluated" at compile time . You can do whatever you want with them.
There's really no magic about shaders. It's all just math and logic if you break it down.
Well so is programming, but it’s like different to wrap your head around shaders I feel like
Yeah, I felt so too some time ago.
Are there any videos or sources you can recommend?
Learning some C/C++ could be quite helpful. Especially with the macros.
I'll let Cyan add to that as he was trying to type something for some time. 😄
You can probably get the direction in either path. But custom lighting models are usually rendered in forward even in the deferred path. That's due to how deferred works - it uses a shader in screenspace to apply PBR lighting based on the gbuffers. There are ways to override that shader too, but it's separate from the shader applied to the actual mesh renderer and you probably wouldn't use shader graph for that.
I already know C/C++
Like I’m not a professional at it
Oh, okay. Then you're settled there I guess.
Yeah I just can’t tie the lighting part together
Compute shaders I can kinda understand
Where I split up processing power on the gpu between threads that are labeled by their index
Aside from that, it seems like you have some misunderstanding about the rendering pipeline. So maybe learn how modern computer graphics work.
Yeah I never looked too much into that, you could be right
Well, regular shaders are the same. They run some logic in threads.
I know basic stuff like normals, vertices, materials, stuff like that
Maybe watch this first:
https://www.youtube.com/watch?v=cvcAjgMUPUA&t=287s&ab_channel=TheHappieCat
Ok let me watch it, one second
Ok I watched it but it didn’t go too much into shaders really, more about the general render pipeline process
Yes. Well, you need to understand that before getting into shaders, because that's what they do. Don't expect to understand everything from just one video though. I've been learning graphics related things for more than a year and there are still things I'm not sure about.
Right, I’m just waiting for it to click and then im gonna be like
because I overthought it
Maybe try this series:
https://www.youtube.com/watch?v=KVWsAL37NGw&ab_channel=NedMakesGames
Although it's focusing on urp, but it's pretty in-depth.
Ok sounds good, I’ll have to check it out. Thanks man
Hey, I'm trying to assign a texture to a computeshader, and I'm getting a weird error:
Property (targetTexture) at kernel index (1): Attempting to bind texture as UAV but the texture wasn't created with the UAV usage flag set!```
Which is weird, because it seems it's complaining that they're not readwrite, but I'm creating the textures in code, so they should be
_targetTexture = new Texture2D(_targetTextureSize.x, _targetTextureSize.y);
_shader.SetTexture(1, "targetTexture", _targetTexture);
does anyone have a clue what's going on?
in the shader, it's a RWTexture2D
From my understanding it has to be a RenderTexture. At least I didn't find a way to write to a regular Texture2D.
thanks, that works!
now I got another problem - I copied URP's SimpleLit shader, and I'm trying to add a Pass to it, but it doesn't seem to run at all
what I did, is in the first subshader, I added my own pass at the end, filled it with code, and I'm kind of expecting it to just apply after all the previous passes, but it doesn't seem to do that
what am I doing wrong here?
got some progress - it flashes the correct thing for a second, then returns to rendering the main texture
URP doesn't really do multi-pass shaders like that. (Well, technically it can with the LightMode tag not set but that breaks SRP batcher compatibility so isn't recommended)
If you add a Pass with a custom LightMode tag you can tell URP to render it through the RenderObjects feature though. Or use a separate shader & apply a second material.
I tried applying a second material, actually, but after going into playmode, it got removed from my renderer
how can I fix that?
I actually asked on code general about it
That's weird, haven't seen that before. Do you have any C# scripts setting materials or something that might be overriding it?
nope, I don't, that's why it's so weird
it is a model, with a material assigned through the model, maybe that can do something?
oh wait, it's just a prefab actually, I don't know then
You can use SRPBatcher with a non-standard LightMode tag to implement a custom pass - you just have to make sure that the CBUFFER is the same in all passes
it worked that way all the way through 2019, 2020 and 2021 ... _until like a month ago 😦 _
and now I'm trying to figure out what went wrong on the latest 2021, because it seems like something major changed behind the scenes on a minor URP change number, and I haven't figured out what yet but the SRPBatcher is really broken now 🥹
Yeah, but you still need to tell URP to render that pass through a feature
I think so yeah, but when you have passes without LightMode tag in built-in they get rendered automatically
While in URP that would break SRP Batcher compatibility as it doesn't like "multi-pass" shaders like that
I used this extensively for outline passing and it worked fine with the batcher before (as I say, until very recently)
and hopefully I can figure out why it isn't working with the batcher now
about that, after trying to apply a second material in playtime, it gets applied to a random nearby object
it's slightly tedious matching the CBUFFERs with the gibberish produced by shader graph, but it does draw everything in a single SRPBatch even for nonstandard light passes
1 specific object, but unrelated
I got it
I just had to not make it static
but why...
I got some problems with my hdrp outline shader. The first image is when I turn on the fog, the second is when I turn it off, and the third one is my code. Is there anyone who can help me to fix this?
Static batches(combines) several meshes together and renders them as one object. It would usually batch renderers that use the same material, but perhaps it doesn't work as expected with several materials. Especially if a mesh only has one material slot.
I'm making a terrain shader with Shader Graph. How can I access more than the first 4 terrain layers/splat mask channels? I'm currently using _Control as the control texture.
Using HDRP and this is for the Terrain component.
How does one make a shader that encapsulates the entire area of inside a cube?
vs just the edges
IE:
shader looks like this from outside
This on inside
Ignore
changed to zwrite not equal
And it works
Good day I'll just ask why my material is pink
I created a shader graph using steps above
Either the shader is broken or incompatible with your render pipeline.
I followed the procedure in making shader graph using this
Enjoy it!
Full Project:
https://github.com/varpon666/Roof-Cleaner
Code and Textures:
https://github.com/varpon666/Cleaning-Game
My game on Google Play :
https://play.google.com/store/apps/developer?id=V.A.R.P.O.N
Can I create a shader using circle?
Circle?
You mean circle texture?
That doesn't matter the shader itself is broken/incompatible
Are you using URP as your render pipeline?
Yes I am I need a sprite renderer lit graph
Are 100% sure you have urp set up properly? Can you create a material with a urp shader and see if it's pink or not?
I just click the Project Settings > Graphics > URP Global Settings then the button fix
I'll google how to set URP properly
Yep, that's not enough. You need to config the RP asset in your graphics/quality settings.
Oh Thanks one more question if you don't mind
I'm creating a 2D circle but as can you see in the image it looks hexagonal so someone told me to use a sprite renderer shader as a solution
That's why I tried urp sprite renderer shader
How are you creating a 2d circle?
2D object > Sprites > Circles
Is it from sprite shapes?🤔
That's not the pink circle though
I mean,can you select the pink circle and take a screenshot of it's inspector?
I do t know what but there's something really wrong about that circle.
Can you give it a 1 1 1 scale?
The shader is not appropriate for sprites, as you can see by the warning it's completely ignoring the value
Use a Sprite shadergraph template if you have access to it, and make sure there is a _MainTex texture property that you use the RGB and A channels from
How do I make a texture tile nicely across all meshes, while keeping the texture the same size?
I managed to achieve this with boxes, but it screws up with other meshes, how would I manage to do this with shader graph?
Anyone know of a way/shader to pixelate particle systems? Haven't found a pixelate shader that works, so I am currently rendering to a down-scaled render texture and overlaying with my main camera. The issue with this is it's not compatible with sorting layers, so all of my pixelated particles are on top of everything else, plus the second camera is a big hassle. (Example of what I currently have below, this is in URP. Been stuck on this for awhile with no luck /: )
Use a triplanar shader
i will try, thank you
nothing changed, the texture is still horribly stretched
maybe i'm using this in the wrong way?
https://learn.unity.com/tutorial/shader-graph-tiling-and-offset-2019-3#
Ya using one of these?
Oh, why don't you try exposing a variable for the tiling input for the triplanar node there
Probably should give examples of what previous shaders you've tried doing, cause I feel like all my failed shader attempts end up in some pixelated monstrosity lol.
Pixellating is usually done by multiplying the UVs by some integer, rounding (floor/ceiling also work), then dividing by that integer again and using that to sample whatever noise/texture you're sampling
Maybe the streched thing you see is the normal, not the albedo texture ?
You guys certainly know that there is a optional feature of standard shader which is "CrossFade animated transition" ....now the question is ..does this feature have a heavy performance impact if i enable it for a MOBILE project?
because, i dont want my LODs pop up like a weirdo....
Crossfade animated transition? What are you referring to?
If you're referring to lod groups transition mode, then I'm not sure how much it's related to shaders. It just renders both groups with different alpha.(the docs also mention dithering, but don't mention how it's implemented).
I have some interesting bug with render queue on android. Meanwhile it working on my emulator great.
Can somebody help me with it
How to keep Shadow Cascades in HDRP?When I press play they vanish
well in the standard shader script there is a lod crossfade prama ...if u uncomment it ...u will have the crossfade animation on lod transition if u r using the standard shader
Hi I created a sprite shadergraph still the circle looks hexagon
Did you connect the alpha ?
One of those textures you're sampling probably has an alpha mask of the disk, no ?
Connect it to the alpha output of the master stack
Is there any way to get color from sprite renderer when enabled gpu instancing?
It is vertex color and when enabled gpu instancing vertex color sets to white.
Build-in pipeline.
Pls don't suggest to get any srp.
Looking at the built-in shader files/includes, I think it's _RendererColor (which is set from unity_SpriteRendererColorArray). Could use these as a template :
https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/Sprites-Default.shader
https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/CGIncludes/UnitySprites.cginc
Thx, i will look it
That is the master stack yes. You want to connect the A output from the Sample Texture 2D node (that is sampling the _MainTex) to the Alpha port on the stack as Remy mentioned.
Hey, sorry I didnt answer before, but the school got the better of me.. The max and minimum values work, but I still cant figure out a way to calculate the actual fill value from the product amount expressed in grams. Could you help out a bit?
Thank you it works
you need to define what the maximum number of grams the container hollds in grams
in my script that is what is set as MaxNumber
and mind number is in my case 0
lets say 250 grams
i use this forumlar for calulating the fill value
shaderFloat = Mathf.InverseLerp(minNumber, MaxNumber, fluidFill);
in your case this would be
shaderFloat = Mathf.InverseLerp(0, 250, gramsFilled);
oh, okay
shaderFloat is then given to the shader as the fill value
Works like a charm
thanks
And when I want to change the surface from transparent to opaque I need to make a new shader yes? I cant just set a boolean?
correct
you can make your transparent shader non transparent but it still has the shading issues that transparent shader have
only a opaque shader fixes that
and how can I make it non transparent?
the transparency is controlled via the alpha value of the albedo texture in most cases
if you do your own shader just set the alpha value to 1
you can change between the opque and transparent master node when you select the master node
then you should see the options for the shader
(in shadergraph)
yeah but I cant change it via code can I?
how can i get camera normal in a written shader? tried using unity_CameraToWorld but i just get an "undeclared identifier" error
Thx, looks like it works
im using hlsl in a post processing shader for birp
i dont know much about shaders but i have this shader to make a filling effect for this dropper but the problem is, when i rotate the dropper the filling liqued start to disappear, and i dont want that, i need it to stay as it is only be able to change the filling volume
maybe its leaking 🤭
and i dont know much about shaders also, i mostly use nodes, play until i get answer
and my best guess would be that you need to take rotation into consideration also
like you have position
lol
yes i did guess that too but the question is, how do i do that lol
I would try recreating above node and just trial and error. Some YT stuff for inspiration but no, cant help. Didnt use shadergraph much
Are you 100% sure you've properly followed the tutorial for this shader ?
Subtracting the scale from the position doesn't make sense ...
You probably want to subtract the object position, to have a "world position centered on object" ?
If you store the positions of both ends in object space somewhere, you can transform both to world space, and then lerp between the y values as your fill level
So when it's 1, it'll be full, and 0 for empty
Hey guys in the shader graph tool how do i add albedo to the fragments section?
It is the "Base Color"
Ahh ok it just had a name change from the tutorial im watching
Thank you! Also how do i take a 2d texture like this and select just the part that I want?
Typically the UV coordinates stored in the mesh is responsible for that
Ahhh ok thank you!
When i update my graph it goes to this weird blue color until i update another value on the fragments window, is there a way to make it update normally?
any way to get a full depth texture in shader graph? i need to use it in a for loop in a custom node so the uvs gonna be different for each iteration and i cant just use the scene depth node
never mind i got it 😄
Here is what I tried to use. The effect worked okayish for a standalone object (had some weird artifacts on the edges) but didn't work at all for particle systems. I even tried using custom vertex streams from the particle system with no luck. (GIF with individual object mostly working, and particles not working)
(Shader)
Hi, not sure where to ask this, but is there anyway to replace the sun with a texture in your procedural sky (in URP)
Cant really see what's going on in the shader graph there, but the artifacts could be a transparency problem. Perhaps just control the alpha values yourself instead of feeding it in from the texture 2D node, and if that doesn't work, maybe try fooling around with alpha clipping.
The artifacts would be due to jumps in the UV values, related to mipmaps too. Can either use Sample Texture 2D LOD or a custom function with SAMPLE_TEXTURE2D_GRAD(tex, sampler, uv, ddx(uv2), ddy(uv2)), where uv is your current UV, and uv2 is just the UV node without those jumps.
Some more info here : https://www.cyanilux.com/faq/#sg-pixellated-seams
As for why it doesn't work with particles, that's due to the Object node. Would need to get the particle scale from custom vertex streams as you mention which can then be accessed through the UV node.
Should be able to include and use functions in https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl
Hi, is there any shader whizz in here who can answer my question?
I'm looking to get specular highlights on my materials in HDRP. This is obviously fine and easy to do, but I want to achieve specular highlights on my materials with baked lighting.
Could a shader possibly do something like that?
As soon as I bake my lights in Unity, I get no specular from my materials making them look very flat and low-quality.
Thanks
anyone?
I'm no expert but you could have an identical scene rendered with unlit glowing materials, and then overlay that onto everything else where the flashlight is shining
Hi, I'm having some "problem". I wanted to insert that kind of circle on a plane, but my circle is in fact bigger than my plane. How can I fit the circle inside my plane?
I think it's my Fresnel Effect that's makes it weird
Oh well I found out a way without the Fresnel, but I was wondering if it's still possible flatten sphere effect
yeah i did change that i know
Hello guys I'm having a question, how can I get an array of Color Values from a Shadergraph color? I don't need code, maybe just a hint would really help!
I'm thinking of dividing the searching points of color based on the length of my map
Or something like making the resulat of a node into a texture2D
You can't. Each shader thread has access to one color that it samples. There are no arrays.
That's really disappointing 😦 So there's no way I can read each of those thread? or any kind of conversion?
I meant I would make my own array of colors for each thread
What are you trying to do anyway?
You can't output the result of a node into a texture, but you can render into a texture with a shader. Or create it with a compute shader.
I made this with my nodes in Shadergraph. I wished to be able to use it for spawning object in non-black areas made by the node. The white area is my map generated by a perlin. I want to spawn chest and other kinds of object in the white areas
If I understand correctly, I need to render it or compute it..? Well that's already a huge step towards my goal so thanks lol, I guess I have new stuff to learn 
I'll try to know what a compute shader is
If you need to access your perlin noise map data in C#, you need to render it to a texture(or a 2d array) first. Then you can reuse that texture for whatever else you're using it in your shader.
Or if the pattern is kind of simple and doesn't need a visual to go with it, you could produce it entirely in C#
That's my problem. I want it to be shadergraphynamic XD. Like dynamic by shader
How do a render such thing actually? I'm not sure where to start
You'd render to a render texture by setting the current render target. Look upsetting render target in unity.
But I'd generate the noise map in a compute shader. It's way more simple and logical for me.
Ok! thanks for all the help!
Hey there
I need an shader to use on quads with transparent textures (for watch hands) on mobile but I don't want it to be translucent (as in I only want the transparency applied where alpha is 0)
Currently I'm getting some clipping issues with Unity particle shaders and they're translucent too
Can anyone point me in the right direction so I Know what to look for?
Use an opaque shader with alpha-clip
thank you so much for the detailed explanation! it was really helpful. What are the final nodes feeding into? Albedo, emission and alpha?
grettings. I am making a water shader which uses the vertex shader to create waves. I was wondering if there was a way to make other objects float on the waters surface. Aka to move up and down with the surface of the water.
Unless it's a leaf or something like that, it will honestly look better if the object is partially submerged anyway, and at a flat position, maybe bopping up and down at the same interval as the vertices, but not on top of them
If you really need to, use a mesh collider and raycasts, or add a texture on a separate material or in another pass of the shader
Yeah I plan on making it so its a bit under the water. The main issue is that the water will not always move at the same rate. Sometimes it will be calm and sometimes it will move quite a bit.
I think either you have to get that rate, maybe even from the shader, or do the collider and ray way, and just disable collisions of the water with everything in the physics settings
can anyone tell me what is this pattern ? i always see in my broken shader
this is also moire ??
probably
ok thanks, ill try
is this a procedural mesh? I had similiar looking problem until I used RecalculateTangents on the mesh
also, if youre using Shader Graph, make sure that your Sample Texture 2D node for your normal map, has Type set to Normal, not Default
This happens whenever rendering a pattern that's smaller/finer than what can be displayed
hi
how can i make ztest only happen inside a object not behind it?
my shader is simple unlit with two pass one is ZTest Greater as red one and one is ZTest Less which is blue one.
how i can I achieve the right result?
It's not possible with ZTest. There is not enough information in the depth buffer to know how "deep" the sphere is. For all it knows, that sphere might be a very long capsule that extends away from the camera.
The only way to achieve what you want is to pass additional information into the rectangle shader about where the sphere is and what its radius is and use that to calculate which pixels are inside it.
imagine there's a room that if players enter it other player can see them but if somebody is out of the room they don't get seen pass through
is only way to pass extra information about the rooms? there are so many rooms in my game
Do you know of any other game that has a similar effect that you can show me, just to make sure I understand what you're imagining?
apex legends
I don't play it, so I don't know what to look for
Just imagine it like
- You are a sniper and watching over 3 houses in middle of a dessert which contain stuff like gun and health
- There are 5 other players in game which have to survive from getting killed by you
- You can't see them but you have a sensor in those 3 houses which if those 5 players step in, you can see them through walls
- But if they stay behind the room and not stepping in you are not able to see them through walls
Maybe add a trigger collider to the rooms/buildings. And when there's a collision, render the players with additional see-through shader?
Yes that would work but those houses are not box shaped they are spherical domes that makes it hard
there should be a way for this in shader like 3d modeling software when your model intersect another model it highlights the area
What 3D modeling software has that feature (and can I see it?)
But what do they intersect if they're inside the buildings? Are the building meshes "filled" inside?
You could use convex mesh colliders for triggers too. Although not perfect, but I'm sure it's not a big deal if they don't match the mesh perfectly.
What you're imagining with shaders is from the realm of raymarching. While not impossible, it's pretty hard and complicated and you will need to have a "filled"(not hollow) meshes anyway.
Basically, approximating with mesh colliders is gonna be 100 times easier and faster than any solution with shaders.
This result could also be done using stencil buffer and two passes for the sphere to mask what is intersecting it.
Hello, I need a bit of help. I have some tiles with a black border made with a custom shader (im not using a texture because im adding moving stuff within the borders) but on some specific low resolutions the border dissapears. Is there a way to gaurantee that the border is at least 1 pixel wide? Heres images on how it should look vs how it sometimes looks. And each tiles is a seperate gameobject
oh thank god, can you explain more?
Hum, it's the matter of ordering the passes right.
- Render the boxes
- Render the sphere back faces with ztest and write into the stencil buffer : the stencil has now a mask of the sphere but box pixels are missing
- Render the sphere front faces with ztest again, and invert the values of the stencil bit : the mask should now be only where the box is intersecting the sphere
- Render the "inside" pass of the box
Here's the official stencil buffer doc : https://docs.unity3d.com/Manual/SL-Stencil.html
but stencils are off screen no?
No
Ok so
- Render the boxes is the regular blue shades
If you do the borders based on UVs, the further away the tile, the smaller the border, to the point that it gets smaller than a pixel and disapears ...
You can use derivatives (ddx, ddy, fwidth) on the uv values to determine a minimum size for the border to have it always at least 1px wide
Oh remy this is so complex, I need a separate shader for sphere? how can i access sphere stincel from boxes? and how can i Order this passes they are done by gpu as i know
how can i get a world to screen space position in a post processing shader?
- The stencil is a screen space buffer, accessible from any object
- You can change the draw order of your passes using the
queuetag
is there any example of what i want somewhere?
I remember the doc had a very easy sample at some point, trying to find it again :/
thank you i'm struggling on this for a week :[
Not exactly what you want, but two nice examples : https://docs.unity3d.com/2019.3/Documentation/Manual/SL-Stencil.html
Multiply by the view*projection matrix UNITY_MATRIX_VP should do the trick 🤔
Hello why is the following code not working in HLSL
uint ground = asuint(((noise(id.xz) * .5f) + .5f) * cakeSize);
this is my first written shader so im not sure how to do any of this. also im using hlsl in a custom post processing shader for the v2 package in birp, not sure if that matters
HLSL doesn't have a noise function anymore since SM2 😦
mul(position, UNITY_MATRIX_VP );
Thanks Remy.
I have one more question. I currently use the Unity CPU Procedural Mesh where I feed it vertices and triangles. I am wanting to do this on the GPU instead. Do you have any resource where I can see an example of that. I am just confused of the syntax in a Compute Buffer to do this.
do i need to add another include to the shader or something?
Erm, no I don't have this handy
No problem. I can probably find something.
I think UnityCG.cginc but I thought it was kind of included in the whole universe XD
added that and it doesnt seem to be working
only other one i have is #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"
why doesnt it have a definition for UNITY_MATRIX_VP then?
Maybe it's not including UnityCG, but other stuffs
Try to include UnityShaderVariables.cginc It's the one with this variable
similar errors
Thanks! This was very useful and I tried it but im still encountering the issue, though it is more rare now. You can see its missing part of the line near the top. Any ideas why?
This is what the end of my shader looks like:
float color = fwidth(IN.uv_MainTex);
if (min(min(1-x,x),min(1-y,y)) <= color) {
color = 0;
} else {
color = 1;
}
o.Albedo = color;
o.Alpha = 0;
o.Specular = 0;
o.Gloss = 0;
Sorry, I think I'm tired and can't figure it out, but it should be possible to do it
looked at the post processing include and found this note which looks like it could have something to do with the problem
looks like it has its own variable for matrixvp which i assume is the same thing
Yes
Are there volumetric shaders? One that would encapsulate entirety of pixels in a 3d object? IE a cube.
Nothing out of the box in unity, no
ah. dang
How do I get my shadergraph file to go from this blue graph icon to this rainbow s icon?
Any unity shader pros that wouldn't mind talking in private to possibly help me solve a problem. Easier to send pics/possibly teamview to show issue
@amber saffron why did you deleted your post? it was not possible?
I didn't delete any post 🤔
Our posts are gone lol
I'm working on a simulation for an upcoming event, and I need a water shader. I've found one and it looks/works perfectly in scene/game view, but as soon as I run it, it turns pink. I'm trying to use it with VR, and it seemed to work great up until I started incorporating VR elements. I'm not too well versed in shaders at all, so I don't even know where to begin on fixing this. I've been reading up on URP vs HDRP, and it seems vr and HDRP don't mix too well, so I've switched to URP. The shader looks fine when running through URP, just not inplay mode
Normal one is in game view, pink is in play mode
could it be a postprocessing issue?
someone have a good video-tutorial to learn shaders?
doesnt seem to be working
not sure how to debug with shaders but i did try setting the color to mul(_SunPosition, unity_MatrixVP); and it seems to be displaying a random color on the entire screen, not lerping between values or anything as id expect it to do
It’d seem so. How would I check that? I’ve been mostly 2D for years, but trying to rapidly learn 3D (with mostly success surprisingly lmao). Is there some way to debug this?
well first step would be to find and disable any postprocessing volumes in your scene and see if that changes anything
Got ya! I’ll try that. Thanks!
anyone able to help?
https://www.shadertoy.com/view/ddXGD2 just saw this and was reminded of your problem
Need help here, Just finished the following tutorial https://www.youtube.com/watch?v=RC91uxRTId8&list=LL&index=12 but the material keeps only creating shadows but not receiving, I try doing the thing I found on the commentary that said to put the Keycodes on the SubGraphs, but still do not work.
YouTube
Ned Makes Games
Toon Shader in Unity Using a Shader Graph with Custom Lighting!
the version is 2021.3.8f1
also did the debug thing but the keycodes were already in there
✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3 🩹 For 2020.2 and .3:
► When you create a shader graph, set the material setting to "Unlit"
► The gear menu on Custom Function nodes is now in the graph inspector
► Editing properties must be done in the graph inspector instead of the blackboard
► In Lighting.hlsl, change the line "if SHADERGRAPH_PREVIEW" to "...
Anyone knows the problem?
That tutorial is kinda outdated. Need to use _MAIN_LIGHT_SHADOWS for the first keyword, not the calculate one.
Or https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
I'm working on a custom unlit shadergraph function, im getting the following error. Shader error in 'Shader Graphs/fogged-lighting': undeclared identifier 'GetMeshRenderingLayer' at Assets/hlsl/CustomLighting.hlsl(60) (on d3d11)
cyan, does your code use light layers?
Not currently
I will try once I get home, thank you
I have a question. Was following code monkey tutorial for dissolve shader
His version for some reason doesnt work for me
there is no red outline from bottom row
managed to make it work with adding 2 alpha layers before and again after
but makes no sense
so i have to add 2 alpha channels (yellow) and then AGAIN add them together (red) to make it wok
shouldnt red node do the all work?
this is result without yellow node
I think it's because you're using the wrong Step node in what goes into the alpha. The red part is being made transparent. Should use the one at the bottom with more white, multiplied with the A output from tex sample, into A on Combine.
But tbh I wouldn't even bother with the Combine & Split, just keep the RGB and Alpha separate, it's usually easier.
hello hello, is there a way to change a color emissive by script? I'm using shader labs
You'd need to use that Color_b9cc627... as the string in the SetColor call. The "Color Emissive" is just for display purposes. (Ideally the property name wouldn't be named so random, I guess it was generated from a shader graph or something. Could go through all of the code and change it to _EmissiveColor or something)
well so it's fine if i rename it?
it was generated by the Shader Lab (i used to do shader files by hand, so idk if it's ok)
multiply of bottom and tex sample is not solution, tried it
so this works now
and nice tip for separating A and RGB, did that
but shouldnt this last ADD node do the same job? cause below its the same thing as above, well it should be
The alpha of your Color property might be set to 0, rather than 1. That would explain why the first screenshot works but the second doesn't.
is there a way to rename it from the entire file?
it has 5.7k lines
OH YEAH! this is my color input for bottom one
Use a code editor that has a "Find and Replace" function? (Usually Ctrl+H)
just did, it doesn't work anymore
might be because of the dependencies
Didn't work, I even tried changing the place where the keywords would be in every subgraph and graph, didn't work
I will try remaking the shader with a newer version of the tutorial but I still would like to know what in the hell is wrong in there
I will dowload your version in the github and see the diferences, If I find the problem I will be back
Okay, I manage to fix by using the subgraph you used on your toon shader, thanks for the help
Question, I've found out recently how to implement dithered transparency for objects (or screen door transparency) - but I am having trouble figuring out how to apply dithering to shadows, or better put as a question - "how can I dither shadows?"
If someone had a link to some reading materials I could read on it, preferably compatible with URP, that would be awesome
Hii does anyone know how to put a shader to the whole camera? In using urp
I'm *
(I'm currently working for a vr project and I have to add the shader so it affects the whole scene)
Probably ideal to research it yourself, then ask questions when you're having problems implementing it all.
Urp is an srp though.
Are you talking about postprocessing?
Assuming you mean scriptable render pipeline, which srp is the common abbreviation for.
Hey, There!
Is there a HDRP/Lit shader that uses world space texture coordinates instead of local ones?
You're looking for a TriPlanar shader, which should be enough to let you find what you want.
Before I look into it does it work for moving objects?
Setting base uv mapping to Planar or TriPlanar causes this with HDRP/Lit and thats not the desired effect
You dont want world space texture coords for moving objects since well they move in the world
This is exactly what you'd expect for world space UVs, no?
looks like the texutre is sampled in world space uvs. I assume you want the texture to move with the tank and in that case it needs to be sampled in object space uvs.
I have a (hopefully not silly) question. I have a branch that I would like to use as a mask. Is there a way to blur/smooth the hard black and white edges that I get from the branch?
Use smoothstep instead🤔
how to replace alpha blended rendering instead of cutoff in a shader script?
i've a grass sway shader that uses cutoff....but it looks edgy and disappear away over distance
just want to make it look like mobile/particle/alpha blended type of soft-edged
any way?
You'll need to change the blending operation, and the rendering queue : https://docs.unity3d.com/Manual/SL-Blend.html
But I don't recommand that, as it will probably lead to transparent sorting issue.
Object A -
Stencil
{
Ref 220
Comp Always
Pass Keep
}
Object B -
Stencil
{
Ref 220
Comp NotEqual
Pass Keep
}
Shouldn't this draw object A where it is supposed to be, and then when object B renders, it not draw where object A is?
Hello! I may be a bit dumb, but how do I get the texture of an object? i'm trying to make an animated shader, but I can't seem to understand what I need to reference in the texture 2D asset.
The texture file
What do you mean "get" the texture of an object
How does the object "have" textures
Renderer componets reference materials and meshes, materials reference shaders and textures to populate properties exposed by the shader, you are making a shader, you do not have any exposed properties, you are about to hard-code a texture into the shader, on the bottom-left panel click "+" and add a texture property. Switch out "Texture 2D Asset" with the created property.
I don't really now a lot about textures, but don't objects have textures?
What should I put inside that created property?
Object A needs to Replace on Pass, no?
Object A is just a cull. It's not really doing anything
It's just transparent object that is keeping normal background stuff
the object doesn't inherently have any textures associated with it; you have to give the shader a texture and then it applies that texture onto the object (you can either set the property manually for various materials using the same shader with different textures, or you can have a script take the texture from your assets and give it to the shader on start)
Hello 🙂 Anyone would know what a U at the end of an integer literal means in HLSL ? example: '3U'
Unsigned Int I believe
I'm starting to get what you mean! So if I wanted to have a shader that is similar to a dissolve, and have it move around, should I reference the dissolve effect into the texture?
The dissolve is done by the shader (though the texture might store information about which areas to dissolve first). The texture basically stores information that the shader can use.
(Brackeys has a good tutorial on making a dissolve effect)
It does, and I tried it on my own project, but I want to add a twist, and have that effect move around the object. But from what I've seen so far, I need a tiling and offset node, as well as a sample texture to do that.
Indeed; the texture is in your assets somewhere though, it's not attached to any gameobject in particular
Alright I'll look for it, and maybe watch a few more videos to see if i can find anything!
I'm really having issues getting this shader to work in VR. It renders just fine in edit/game view, but goes pink in play mode. Additionally, with the headset, the pink shader is only rendering in one eye (the left) the right eye completely hides the object. I'm using URP. Is there a way to convert a shader to work with VR? I'm not too versed in shaders.
Both eyes as seen in VR and what it looks like when not in play mode.
Did you hand write the shader or is it a shadergraph?
If you hand write it you may need to add some code to support the stereo rendering method: https://docs.unity3d.com/Manual/SinglePassInstancing.html
It's an asset from the store, though it seems to be handwritten.
I'd try adding support for single pass instancing to it first then
if you wanted to test quickly you could try changing the stereo rendering method to multi-pass to see if that works, but you should not really use that for a VR game if possible
im writing a shader that limits the maximum light radiance that certain materials can receive (working of fog of war) but my method for doing so seems to remove details from the normal map, can anyone suggest a better way to limit the radiance or fix the normal issue? You can see the normals look good on the outer edge of the lit area (where radianceMax has not been exceeded) but disappear in the center. Other than radianceMax part, this is a copy of the LightingPhysicallyBased from urp source
half NdotL = saturate(dot(normalWS, lightDirectionWS));
half3 radiance = lightColor * (lightAttenuation * NdotL);
// attempt to set a maximum radiance for light received by fog of war materials
float3 radianceMax = normalize(lightColor * (lightAttenuation * NdotL)) * 0.75;
if (radiance.y > radianceMax.y || radiance.x > radianceMax.x || radiance.z > radianceMax.z)
{
radiance = radianceMax;
}
Seems like you would want to apply the NdotL to you radianceMax outside of the normalize so the normal information is still applied
wow duh, thank you
that looks better
Any idea what is making this happen?
https://www.youtube.com/watch?v=GQyCPaThQnA used this tutorial
✔️ Tested in 2020.3 & 2021.1
Do you have a material that doesn't look quite right in Unity's URP lit shader graph? Or would you like to experiment with stylized art styles with the convenience of the shader graph? In this tutorial, I show how to implement custom lighting, allowing you to solve both those problems. Afterwards, you could extend t...
the problem is definitly on the following code.
float diffuse = saturate(dot(d.normalWS, light.direction));
float specularDot = saturate(dot(d.normalWS, normalize(light.direction + d.viewDirectionWS)));
float specular = pow(specularDot, GetSmoothnessPower(d.smoothness)) * diffuse;
float3 color = d.albedo * radiance * (diffuse + specular);
@civic lantern
Thanks for the help where would the output go?
drag from Out(4) to Base Color(3)
but you also need to declare the texture property
and then drag that texture to the Triplanar's texture input
Thanks, but now the shader looks like this.
There aren't all the options as on HDRP/Lit.
I just tested that shader on a capsule and it works fine
maybe you need to add a Tiling float property and plug it into the Triplanar node's Tile input
and if you want options like in HDRP/Lit (normal map, mask map, remapping...), you need to add them to the shader yourself, or find an existing shader graph
You may also want to correct for object scaling, you can use the object node and the scale value there to multiply the position input before sending it
How did this not create a HDRP/Lit Shader?
It's just a template
It's a bit weird though, how Unity doesn't ship with a Shader Graph that works like HDRP/Lit
so we have to replicate it ourselves
Has anyone replicated it?
Btw this does this which is not correct.
I haven't used this but could work:
https://github.com/RemyUnity/SG-HDRP-Lit
this is what the simple shader looks like on my end:
you should test how it works with primitive shapes too.
maybe your tank mesh is somehow messed up
@latent frigate btw make sure your texture's Wrap Mode is set to Repeat
Could be how is that even possible?
It works for the Unity default Cube
your tank mesh's normals/tangents are probably somehow messed up
I made the model in Blender and uv unwrapped it there.
select all vertices in blender, hit Shift+N, and save
to recalculate normals
maybe that helps.. hard to tell whats wrong here
also UV's shouldnt matter here because we aren't using them
and what is the scale of that tank object and its parts? 🤔
They range from 100-0.000025
I didn't apply transform when exporting
so this is the setup I'd recommend:
oh jesus okay that probably explains it
do what cameron suggested:
#archived-shaders message
oh hes back
Hey, Cameron! Can you send the file?
its 2 nodes from what you have now
all you need is the multiply and the object node, I also threw it together with URP so I'm not sure it will work in HDRP
it's nearly identical in HDRP (no bounds in Object node in HDRP)
I meant WRT to just passing the file
@civic lantern , @lime viper
Hey, Thanks!
It looks like that the new shader you guys made fixes the tiling issue!
Just one more question.
How can I expose the texture and tiling so that I can change them in the editor?
There is an area over on the left of the shader graph called the blackboard you hit the plus there and add in the values you want to expose there, for texture you would add a texture2d and for tiling you would put a float, you can also name those parameters how you would prefer
Thank you all so much!
It works now!
camoflaged objects is a good use case for this type of shader 😁
Is there a performance hit for using double-sided shaders?
Unfortunately the answer is largely "It depends" but I feel pretty safe saying unless you are like looking to squeeze the last drop of performance out of things it is probably fine or a net benefit.
Slightly longer version: Turning it on for a large number of unique materials/shaders will increase your draw calls and the amount of geometry drawn each frame. On the other hand if you are making something that is best served having two sided e.g. you would otherwise duplicate geometry and flip normals, or cause you to have to draw more complex geometry you are probably going to see a benefit.
The geometry will have to be drawn twice, once for each side
does anyone know a potential solution to the white borders around each "cell" here?
the coordinates are generated using frac(uv * resolution) and then used to sample a spritesheet of the characters
i initially thought it might be because the frac function returns a value in [0,1) range rather than [0,1] , but i tried messing with that and it didnt appear to make a difference
I also have my textures wrap mode to clamp, which lessened the issue but didn't solve it
is there a way to slowly move one color in the sample gradient node?
This should explain the issue : https://www.cyanilux.com/faq/#sg-pixellated-seams
That's written with URP/ShaderGraph in mind. If you're in Built-in RP should be able to use tex2Dgrad(sampler, frac(uv * resolution), ddx(uv), ddy(uv)). Or disable mipmaps/use tex2Dlod if you don't need them.
ah you are awesome
thank you so much
https://youtu.be/XZ9-ZqHxg2s or do this without a gradient
Anyone knows a good hlsl syntax highlighter that is compatible with Unity, and how it's file system is set up? I currently use the HLSL tools for Visual Studio plugin, but any shader include is not recognized, as the paths refer to the local path in the assets, and also the local path that refers to unity package cache for like URP shader includes
Or even a way to set up the plugin to work with Unity would be great, I'm just not really experienced with vs plugins. I did check if the plugin has any options to set folders to look inside for includes, but it seems like there is no option
Use a Step node
(What my goal would be, is to be able to use the "go to definition" feature of the plugin, so it would be easier to dig inside URP's lighting)
worked. thanks.
Is there any way to get a noise gradient from a shader into a c# script? I want to make buoyancy for my water but I need my gradient noise for that, and when I use the shader code in the documentation I don't get the same pattern
Cyan, I tryed other tutorials for making the shader work properly the way I wanted and they always carry a problem, the shader on your github was the only one that has worked properly, do you have a tutorial explaining the logic or the process behind making it?
I don't have a tutorial about it no. There might be some comments in the CustomLighting.hlsl file explaining parts of it and important keywords though.
okay, thank you, found your tutorials and I will be using them, you got yourself a new follower
Does it not cull the side facing away from the camera?
Is is possible to do parallax scrolling on a plane using only a shader?
Could anyone help me with this one?
I do not know this, but in most cases a mesh will have about half of its polygons away from the camera anyhow, showing the backface
Oh yeah duh. I was thinking about a plane and missed that.
Yes, you would need to have a texture sample for each layer you want to support. Then if you wanted to run them off of the view use the fragment view direction transformed into tangent space then multiplied by a depth value. Then you can blend each of the layers to make the final result.
What component will let me render in 2d based only off some virtual UVs? I.e. without a texture or mesh required? Just pure shader?
You could just use a MeshRenderer with a quad and a custom shader
I guess, or a sprite renderer with a blank texture -- but is there really no way to just render based off UVs scaled to the object size?
Ultimately GPUs work with meshes (triangles and vertices)
So like you could do https://docs.unity3d.com/ScriptReference/Graphics.DrawProcedural.html
But you're still providing "mesh data"
just in a different way
I don't know that that is true -- thousands of shader examples out there rendering solely in the screen space UVs.
Is Shaderforge and OBS "instantiating a quad" so it can render a shader that only takes in the UVs?
You can call UVs mesh data if you like, but I don't see any reason why you can't just define the UVs without a fake quad in the background. It's just a coordinate system.
The UVs have to correspond to vertex positions in a triangle or they're kinda meaningless
the UV values themselves are just numbers 0-1
the position in the uv array corresponds to a vertex
I'm well aware what UVs are but they're just a coordinate system that is mapped onto vertices in the context of meshes. In a texture or on a screen space or in a box or a window, the UVs are just the relevant coordinate space.
You need some way to define that box or window
There is no really a reason for it to be connected to the concept of 'vertices' even if you need a start and end point for the range.
You can call them that.
it's just vertex data in the GPU memory
"Mesh" is a Unity concept but ultimately you need to put vertex data into the GPU for your UVs to refer to
so yes OBS and Shaderforge are putting vertex data into the gpu
This seems like a semantic argument
I misspoke, meant Shadertoy.
Maybe it's semantic but there is extra overhead to instantiating quads and all the associated data beyond literally just the UVs.
instantiating quads
This is a loaded term
you don't need a GameObject
Is that what you're asking about?
I already pointed you at one example way to do it without a GameObject
This is another way:
https://docs.unity3d.com/ScriptReference/Graphics.DrawMesh.html
And about a dozen more here:
https://docs.unity3d.com/ScriptReference/Graphics.html
Yes you need more data beyond just the UVs, you also need the vertex and triangle data.
No, I'm saying that a quad mesh comes with a lot of associated overheads (like vertex indices, rotation, and other bookkeeping stuff) that are completely irrelevant to defining a UV space (such as in screen space). And I'm just wondering why there doesn't seem to be a way to define that very basically (and trivially) defined UV space without rendering a mesh.
All of that "irrelevant" info is relevant and necessary for the GPU to do it. ShaderToy and OBS are allowed to make assumptions about it being a 2D viewport on the screen. Unity is a 3D game engine so it doesn't get to make that assumption
Those applications are uploading that data to the GPU behind the scenes
You can call the coordinates that define the extent of the space 'the vertices' if you want. But there is a difference between providing coordinate pairs as bare numbers and providing a quad mesh.
Which is exactly the component I'm asking about, a component that makes assumptions about what and where and how you're rendering stuff (specifically in 2D, as well). If it doesn't exist -- fine. But it seems like a really obvious thing to include.
Here you can do this if you want
https://docs.unity3d.com/ScriptReference/Graphics.DrawTexture.html
Under the hood it's doing the same thing, but you get to provide screen space coordinates instead of 3D coordinates
As I said - lots of goodies in the Graphics class.
That does seem useful for screen space stuff. Is there a similar one one for world space too?
But you're saying that under the hood that would be loading in a 'mesh', including all the extra irrelevant data?
That's how GPUs render stuff so yes
or at least how the graphics APIs (Vulkan, DirectX etc) work
If you want world space, you're providing a mesh
That's how you define the world space object shape to render
Well I guess I have no expertise in that but it seems to me pretty ridiculous that anyone would design it that way. Edge and face sets (etc) are completely irrelevant to the kind of thing I want to render. But I guess I'll have to accept that overhead.
edge and face sets aren't a thing here
it's just vertices, triangles, and UVs
Yes, triangles, as in the sets that define the connected vertex graph and the faces (tris, if you want to call them that).
and they are relevant because otherwise it has no idea where and how to draw each pixel
Have you actually tried this and found that there's some level of unacceptable overhead here?
The only numbers I need to render 2d screen or world space UV based effects are the 4 vec2 pairs that shape the box (or even the just 1 coordinate + 2 extent values).
use DrawTexture then. I'm just telling you under the hood any application that does things that way has to convert that to vertices and triangles to get the GPU to draw it.
Oh I accept that you're right, I am just baffled by it.
these are 3D graphics apis
they're optimized towards drawing 3d objects
drawing 2D things is just bolted on
There are 2D drawing APIs like Skia: https://skia.org/
But even those use the 3D apis like OpenGL or Vulkan under the hood
I guess the whole system is rather inflexible. I just see no reason why it ever had to be that way given that the calculations would be identical in every way? I guess it was 'good enough' for this use case so no reason to make it any more optimal. The story of all technological development.
So you can apply a fragment shader to the whole screen and only use the intrinsics related to screen space. This workflow is not super easy to use, so you may want to consider just putting a quad in front of the camera, you can still use screen space based intrinsics it just doesn't require you to dive into the blit system.
If you still want to start looking at the blit system you could start with the Unity Documentation: https://docs.unity3d.com/ScriptReference/Graphics.Blit.html
Or if you like I believe this might be a bit less involved
https://github.com/Cyanilux/URP_BlitRenderFeature
As to why it isn't a well supported workflow, screen ratio and resolution can vary drastically between users and platforms, it is better to instead have a layer of abstraction that lets you have absolute measures that are then pushed through to the screen.
Imagine if you will having a character jump, with the abstraction you can say the jump height will be 1 meter and the general process that presents it to the screen will solve all that for you.
However when working in screen space you need to go backwards to figure out what 1 meter is in the current screen context, is 1 meter .25 of the screen? what if the screen ratio is wider? Is the camera distance fixed?
Thanks for those docs, I'll have a look at them.
That said I do understand why you wouldn't use screen space coordinates to render world space objects.
What I don't quite get (other than "it's the way things are") is why, in 2d, whether screen or world space, you'd need to provide 4 vertices + the adjacency graph and face presence data (i.e. a mesh) to define the UV mapping which is already uniquely and completely specified by 1 float vec2 coordinate + 2x float width and height, (or potentially all ints in pixel space).
But this isn't my expertise, my expertise is optimising scientific code for HPCs. So perhaps there is some good reason for it, beyond lack of willpower to implement it.
So what you are taking about are the screen space intrinsics, not sure if you are looking to do this with HLSL or in shader graph but the screen coordinates are readily available in either, they will present a 0-1 2D space that represents the screen, often they will also provide the depth information of the screen as well in the Z component.
In Shadergraph you can use Screen Position in default mode, I've not worked much with HLSL but it looks like you can pass it via semantics here: https://docs.unity3d.com/Manual/SL-ShaderSemantics.html
Shadergraph also has the Screen node which has the width and height in pixels. That data could also just be passed directly via the material if you want to use HLSL
GPU's are designed to be fast polygon rendering machines, massively multi-parallel rendering of millions of polygons. Polygons are composed of 3 verts each, ultimately. Even "larger" polygons (say quads) are broken down into triangles.
The pipeline is designed to take 3 points (verts) and output them into 2D screen space-ish....it's actually called clip space.
Clip space is a -1 to 1 space with (0,0) at the center, and most of the 3D work done to "splat" the 2D or 3D scene onto that flat LOGICAL plane. The physical plan isn't being dealt with yet...it's all just math.
You don't really need more than 3 verts to map and entire view screen into this process. Research "full screen triangle GPU" for some fun. But regardless of how you do it, with 4 verts or 3 verts, you're mapping a logical mathematical space called clip space over the screen. For a triangle at the center of the screen it's not a full screen quad. For a full screen tri/quad...it just happens to neatly cover the whole screen.
THEN....The magic happens IN HARDWARE. The vertex stage is the stage that set it all up...into clip space. The RASTERIZER then maps the results of the polygon's verts onto pixels of the logical screen (which often maps to physical screen size but I supposed doesn't have to). During rasterization, there's a perspective divide that happens where the depth information is taken into account for 3D screens and the farther things are away the more they're divided such that they move toward that (0,0) point.
THEN (and only then) can you get into screen space. Because all the math before that is in LOGICAL SPACE, not physical device space.
Anyway, all you need to do screen space mapping is 3 verts, submitted somehow to the programmable vert stage. AND THAT's IT. No extra overhead is needed, but the GPU has to do its job of mapping the logical space to the physical pixels so it can call the fragment stage shader for each pixel in the resulting polygon...be it some arbitrary area of the screen, or the entire screen. That rasterization is hardware and not programmable. But the input to it (vert stage) is programmable, and the frag processing is programmable.
I see, so it's solely a contrivance to deal with the hardware side rasterisation? I know and could tell anyone the entire space (whether it be clip or screen) with a coordinate, width and height. But, we need to convert that into a set of vertices solely so the hardware can undo that conversion and get back to the mapping which we already knew (thanks to the peculiar constraints and symmetries in this specific calculation) and theoretically could have provided to the GPU were the hardware able accept it.
I suppose so.
But think of it this way...what API isn't a "contrivance" and abstraction? Isn't that in effect the entire idea behind an API to begin with?
I mean, there is some physical memory on the GPU that maps (probably double buffered) to the physical screen and is output at every frame to the hardware. I suppose we could just write bits to that like in the old days of the most simple "
"graphics cards".
The first graphics cards, beyond just memory-mapped-to-monitor contained some sets of utility functions. Like blits, and fills but the real "GPU"s contained higher level functions that let programmers exploit dedicated hardware. And we moved quickly in the PC realm from 2D to 3D cards, because filling lots of polygons fast is really cool graphics, and all we really could afford with the speeds-feeds of the time. Ray tracing was WAY WAY WAY out of that league and still is mostly....RTX technology is just beginning to appear now.
There are other aspects to consider, like parallelization and math, that are best done on a GPU...so a math-space to device-space construct is needed.
The fragment/pixel shader stage (the meat of screen-space calcs) must be called for each pixel. You can do that in a compute shader too I suppose. Just tell it to run for width x height itterations.
Sure, I suppose. But it just seems like there is a whole step you can skip in these specific cases.
There is the projection of the polygon into the flat space (which seems like the computationally intensive part to me) then there is the actual drawing.
Maybe there isn't as much to gain by skipping that first step as I expect there would be... and I get that we, collectively, as a culture, became kind of obsessed with 3d.
But there are still a lot of 2d games out there, (maybe even ones that would even appreciate being able to render a billion more particles, not to mention other more philosophical concerns) so I guess to me it seems like it would be valuable to haver a higher level function to skip that first step and just tell the GPU "here is the mapping, don't worry about it".
The vert stage and rasterization is minimal.
But you can use compute shaders.
With them you can write directly to RenderTexture[x, y]
But somehow you have to tell the GPU how to allocate all of those processing units and in what "waves"....so there's still an API for that.
Modern GPU's don't see much of a difference between vertices or pixels, processing 3-4 vertices to make a full screen quad is a tiny fraction compared to processing 8.3 million pixels
Another thing I should mention is that each processor core has interpolators associated with them. So you can set 3 verts in logical space and have the interpolators compute screen space coordinates, or other data FOR YOU, during processing/rasterization, device independent...basically FOR FREE, or at least at a performance level in silicon that is above what you'd get if you were doing it manually in the fragment stage.
Also GPU's in theory are stateless, that is to say every frame they are given fresh data with no knowledge of what data made up the previous frame, this is less true nowadays where previous data can be carried over, but it is largely in a different format than what the CPU passes in
This ties into the idea that the GPU is about being extremely focused on processing many tiny chunks of data in parallel their programming structure is designed to maximize that vs. the more general programming you would find for CPU based languages
Sure but not every object in 2d world space (or screen space) is going to cover 8.3 million pixels and you may very well have thousands, or hundreds of thousands (or whatever you can push the system to) of objects whose polys need to be projected into the flat space.
3 verts rather than 1 coordinate and 2 extents is already 50% more memory per space that needs defining and no idea how much CPU time in the transfer to the GPU. And for whatever is 'free' I suspect we mean in calculation time rather than say, energy cost.
I get that what we have already works well enough for this situation. And of course from the viewpoint of productivity there is no point in optimising before you need to.
But there is also the question of basic competency and arbitrarily doing inefficient things (like say, copying a whole array into a function's memory rather than the 1 value you need from it) just doesn't make sense.
I assumed that since you clearly don't need 'verts' or a 'mesh' as a whole data structure to define the space (mathematically) there would be a clear and obvious way to skip that. I guess not. Or there is in Compute Shaders?
Either way an interesting discussion.
The whole screen at 4k is ~8.3 million pixels, they all have to be drawn at least once
per frame
It is interesting. 🙂
But somehow, unless you have dedicated/known hardware, you have to map logical space to physical-device.
That's rasterization. 2D or 3D, mesh or no mesh, it has to be done.
The center of the screen at offset (widht/2, height/2) isn't a constant. It varies by device that it is executed on.
Whereas in clip space, (0,0) is the center, regardless.
And then there's interpolation in silicon....FAST. A big performance boost.
As to your example of data storage, you could create a buffer of x/y location and 2 extents and the vert stage could use that to output logical math-space info to be rasterized. So really it's already possible to do that. It is done, in fact, for situations where geometry is generateed (procedural geometry can come from anything)
Somehow you have to be able to write to abstract-space and end up in concrete-space.
Yeah, but that is always happening and the relative computational time spent on the pixels vs the projection into the flat space will depend on the number of local spaces that need projecting.
0 objects, then 100% of compute time is spent on the pixel loop. A billion objects each with their own local space that needs to be projected into the flat space? Who knows.
In 3d that projection is complex and it makes sense there is highly optimised hardware to do that.
In 2d all subspaces are simple translations.
You can write a software based rasterizer on the CPU, but that's slow. And rasterization in a GPU is per the api.
You need to check out interpolators. "Simple translations" don't even have to be done in certain cases, if you're using the rasterizer. That's probably not exactly what you're saying. Maybe an example will help.
Well what I mean is from local to world to screen, for example.
I get that the logical space differs from the pixel space since there is no way to know a priori how the discretisation grid aligns with the logical space.
So the other problem is that GPU's want to be given a simple program to run, and they want to run it on every pixel, so if you want to put X number of sprites on screen what happens is that it does a logic check on every pixel to see if X sprite should appear there
Yeah, there are many other optimisation issues to be able to put a billion things on screen -- for sure.
Yeah but by implementing them you are essentially re-implementing the vertex/triangle stage
Let's say you want to "smear" a gradient across the screen.
If you do that in a compute shader, where you're in 2D and you pass in the width/height and then calc the value for each pixel at (x, y) and shove the color into the pixel....you can do that.
It's slow.
The faster way is to let the rasterization process smear the colors for you in a device independent way as it is rasterizing anyway. The vertex stage outputs color at each of the 3 verts, let's call it pixelColor.
So in that case, your frag function doesn't even care what its location is, and it can simply return the result from the interpolators. The frag function would just return
return pixelColor;
and pixelColor would be calculated by hardware interpolators in silicon that end up having to dispatch the frag calls anyway.
That's the lowest overhead, and it works on any resolution of device without YOUR program having to know anything because the GPU already knows what to do.
Well the kind of sorting you need to do in 3d is just far far more complex than what you need to do in 2d due to the constraints afforded you by the lack of a 3rd dimension.
In 2d you only need to know the order, but in 3d you need to worry about the extent of the polygon which may intersect other polygons in a way that a single polygon-space requires two orderings (one in front and one behind a separate polygon-space).
Or even more orderings, potentially.
So you can totally do them in order in a painters algorithm, but even more efficient is to write out the color and the depth information, then you can skip drawing things that have a lower depth value
I see, but this would work only if the smear you wanted to do was identical to the interp they used in the silicon right? If you had some weird function you wanted to apply it'd be a compute shader, or more vertices?
As many vertices that would be required to approximate the function with lerp or smoothstep or whatever it uses.
Assuming you have a good 0-1 mapping you can just remap those values as needed
I'm using a simple example.
But anything can be "smeared" by interpolators...colors, screen-space coordinates, whatever.
And of course, if your pixel's result is a function f(x), you can still write and call f(x) to set the color. You don't HAVE to interpolate everything. But it is really handy for device-resolution independence of anything that is convenient.
Right but in 2d all you need is the order. The depth of the 'polygon' or the depth of 'object'. In 3d the depth of the object isn't enough because of intersections, and the potential for an object to extend in front and behind another object so afaik there is a lot of complex stuff going on when it comes to ordering in 3d, something completely superfluous in 2d.
What is the sort order except a 3rd dimension?
In a way it is a third dimension but the constraints on the situation make it far easier to compute what to render. They're all parallel, don't intersect, can't be both in front and behind at the same time, so you can simply take the top item (and then deal with transparencies).
In 3d, as far as I know, rendering engines usually do a lot of other clever things to correctly order objects because of exactly those things? Feel free to tell me I'm wrong though.
So in general that is how 3D works as well, things will be sorted back to front from the camera and each submitted to the GPU, by writing out the depth information into a depth buffer shaders have an early out. but the GPU wants floats. Also you have to remember too a CPU tops out at like 16 cores, GPU's are 1000+ each able to process these things far faster than a CPU
Sure but the difference with 3d is you don't know the sorting a priori. You have to calculate the sorting because the projection isn't orthographic, the camera can move in 3d, and the objects can move in front and behind each other, or have extents that go in front and behind another object simultaneously.
In 2d you know the sorting a priori because you set which layer the sprite was on and that doesn't (usually) change. (and even if it does change it changes because you told it to, so you still know what the sorting is without calculating it).
The camera also can't move in a way that changes the ordering.
So you don't even need to do 'sorting' in 2d. You can just 'index' the objects instead, no calculations needed.
Why wouldn't the projection be orthographic?
Well, just disable depth sorting in your shader.🤷♂️
Then it will render purely on the sorting order that the materials provide.
I'm pretty sure it's a hardware level thing though, so I'm not sure if you're gonna get any boost in performance at all.
Not sure what your point is? I'm just pointing out that the constraints of 2d necessarily open up opportunities for far more efficient calculations (whether measured by memory, time, or energy). I don't know whether or not GPUs actually have the hardware to take advantage of that fact or not.
Okay..? Perhaps you're right, eo what are you gonna do about it?
People usually keep depth sorting on because turning it off often ends up with undesired effects in the rendering because of the problems I mentioned. Those problems don't exist in 2d (or anything parallel to a plane and constrained to move parallel to that plane, and viewed from a camera normal to that plane).
So most GPUs work with Vec4s in either Single, Half, or Fixed* precision, even if you pass it a vec2 it treats it as vec4
*fixed is rarely used now adays
Nothing. It's just an observation.
The depth sorting is done at the engine, not at the GPU.
That's probably why Unity has a different 2d system than the 3D system.
By the time it gets to the GPU, like @lime viper just said, there's not much difference between a 2D vector and a 3D vector for performance.
Makes sense.
Of course there's other factors, but that's programmable BY YOU in your shader.
Okay. Well, the reality is that 3d is way more resource-demanding than 2d, so the industry, hardware and graphics apis evolved to make 3d as performant as possible. As a side effect it made any rendering(wether 2d or 3d) faster. You can do almost anything with 2d now a days without experiencing performance issues. Optimizing for 2d is simply irrelevant in most cases.
I mean writing/reading from the depth buffer. Isn't that on the GPU side?
As a fun kind of aside it is fun to take a look at this as an example of that 2D-3D hybrid: https://twitter.com/UnpackingALife/status/1572704540482469888
yes, Unpacking was built in Unity, or as we like to say, by ~secretly using the third dimension~
5955
717
Trying to imagine the workflow/tools they would have made to work like that. I guess you gotta do what you gotta do though.
It's actually pretty common in 2d games I think.
In the simplest form, just have some utility script that places the sprites at certain z pos based on something(layer?)
it's probably not bad to automate away with a tool, just do the illustrator style move forwared/move backward, and keep it at units of 1 for each move
superliminal was made in unity and that's a large premise to the game
Yeah I can see an advantage in being able to use the perspective view to just grab and reorder things in complex scenes like this.
In 3d, how do I use shaders to render a character's eyes over their hair without then being able to see their eyes through their head when you turn them around? I tried messing with the draw order but realised if I put the eyes on top they'd just show through the head entirely
If you put the eyes on top but have them cull the back face, they should be transparent when they're on the other side of the head
thank you!!!
does anyone know where this background texture comes from in this example?
https://programmer.ink/think/unity-shader-restore-csgo-holographic-sticker-effect.html
there's only two input images, when you look at everything he posted, they are in the green one.. but it doesn't seem to be used in the code, what am i missing?
Materials provided by small partners: hologram sticker effect, referred to as holo: achievements: The implementation of shader graph based on URP and built in pipeline 1. Effect analysis Here you can see the sticker effect of csgo: StatTrak™ AWP | Man-o'-war (Minimal Wear) | 3D Skin Viewer AccoUTF-8...
is there a way to not render vfx particles in certain areas?
I need to use a vfx graph for the snow for performance, but they also can't have collisions, so they show up in interiors
can I somehow have a volume where they don't render?
Hey, not positive if this is the right chanel to ask this, but I'm having an issue with getting a texture to look correct in unity, when I render it in blender my corners look like this
but in unity they look like this and all the tinkering in my mind hasn't gotten it to look right
I haven't done a lot with texture mapping vefore so I could be totally off on something but I figured I'd see if anyone recognized the issue right away, I can get a similar issue in blender by changing my interpolation mode to linear rather than closest but can't find a similar setting in unity
Closest thing I've found is changing the filter mode on the texture from bilinear (default) to point (no filter)
but then it introduces these weird lines
artifact of aa maybe?
is there a clamp wrap mode?
actually what do the UVs look like? Is the texture a cube net which it then folds onto the mesh?
yeah this is the UV I was using
I swapped over to a spritemap that I'm using a script to apply at runtime and this works though
If you just fill all the transparent areas with black, it should work
i stg
sometimes
I'm just not half there
to be clear that was the perfect solution thanks
Hi, could somebody please recommend me a decent directional fade shader video please?
I've tried to ind one my self but wasn't really successful when it comes to 3D.
What I am looking for is an object going from completely visible to transparent top to bottom.
you can make it in shader graph, just plug one minus the y value of the position into alpha
(would be useful to use a remap if the mesh's top and bottom aren't at y=0 and 1)
(also good practice to saturate anything going into alpha)
ok, I'll take a look into that, thanks!
does the shader graph tool have a way to "shave" off a collection of floats, like turning RGBA into RGB? Been using split and combine, but I feel like there has to be a better way
is there a way to make fullscreen shaders using the shader graph
There is a Swizzle node. It has a text field where you could enter "rgb" (or "xyz"). Though if you're in old versions it used a different UI and was very buggy so was avoided.
But note that Shader Graph will also truncate vectors automatically, e.g. if a Vector4 (rgba) is put into a Vector3 port it takes the first 3 components (rgb).
There's going to be a proper Fullscreen graph target in 2022.2+ I believe, but that's an alpha version of Unity at the moment.
As for current solutions, you can use graphs with a Graphics.Blit / cmd.Blit (e.g. for URP : https://github.com/Cyanilux/URP_BlitRenderFeature/, use _MainTex to get source texture).
Or can set view/projection matrices to Identity then use DrawMesh/DrawProcedural/etc to draw a fullscreen quad.
ight
Unity is about to mess up again with their new Block Shader, if you don't want another SRP nightmware, I strongly encourage everyone to go support jbooth https://forum.unity.com/threads/block-shaders-surface-shaders-for-srps-and-more-public-demo-now-available.1350497/page-2#post-8528396
can I assign any float to the uvs of the mesh, outside 0 and 1, then read that data with a custom node in shader graph?
Should be able to, yeah.
thanks
guys can you help me with this one
so i created a shader and assigned the material to it, then I put the material into the object
after finishing the shader (which, in its preview, is clearly moving), the object doesnt seem to change, it still has the material's base colour, the material as well seems to be unaffected even though the assigned shader is clearly moving
am I missing something>?
nevermind, I slapped a bunch of buttons and got it fixed (somehow)
Dose anyone have a mirror shader I can use that works instead of using renders because it’s very tedious
Library\PackageCache\com.unity.shadergraph@13.1.8\Editor\Generation\Targets\BuiltIn\Editor\ShaderGraph\Targets\BuiltInSubTarget.cs(33,28): error CS0246: The type or namespace name 'BuiltInShaderGraphSaveContext' could not be found (are you missing a using directive or an assembly reference?)
I updated to 2022.1.21 today and keep getting this.deeted libraryfolder and rebuilt it,still same error, any tips?
Instead of what "renders"?
can you split a model so every part has its own matirial
Yes, open it in a modeling program and assign materials to the different faces.
hi,
suppose i have a gameobject A that stores a reference to a compute shader.
i have other gameobjects B that access A, in order to assign inputs to the shader then dispatch it
should each gameobject B have its own reference to the compute shader, or does it not matter?
Im using Universal renderpipeline and i want to set a texture/sprite onto my mesh. However its... just... transparent for some damn reason, no matter what properties i set. Why ?
I need to use the "Sprite-Lit-Default" shader... however its just transparent, why ?
are the normals in the right direction?
I assume so, in 2020 with URP it worked... now 2021 and URP and its just transparent for some damn reason
ah, well, i dont think "sprite" materials are gonna work with meshes
strong emphasis on "Think" though
What other shaders might work than ? ^^
It basically downloads an image and should put it onto the 3D plane to display the image... thats the "goal"
try the standard lit ones that come with urp, im not sure if they use texturesamplers or not
standard shader does this, you just need to make sure your Mesh UVs are correct
Yea a render texture
Some people use camera and a render texture I’m looking for an actual mirror texture
Well, that's how mirrors work. They reflect the view from the perspective of the mirror. There's no more "real" way to do mirrors.
Ok
There's no "magic" shader that can reflect the whole scene view without the help of an additional camera.
There are screen reflections and stuff, but they're not perfect.
I know vrchat has it but I’m not finna steal it
has what?
Has mirror shader and I think it’s called render too for it
There's no magic shader that could just make reflections work without additional setup from C#/Cameras/Render textures.
It's simply physically impossible.
Ok
The only way to get "free" reflections is to use raytracing
How could I add simple Metallic/Reflections to this frag shader?
https://hastebin.com/lawisafuxu.csharp
Started a bit, but not sure where to go from there..
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hello! Could anyone help me using the Fresnel effect? I'm trying to make it so that the outline is black, but the inside is colored, but when I multiply it with a black color, and plug it into the emission it doesn't change anything.
What does your shader look like?
Sounds like you're taking the Fresnel node output, multiplying it by zero, and then plugging it into emission - which by default is zero - so it comes out looking the same
assuming your object has some base color, you want to multiply the base color by (1 - fresnel) since fresnel goes between 0 and 1
(note that it'll be grey on the edges, not perfectly black, because a lit material with a black base color will still reflect some light. If you want it to be perfectly black, you need to do an unlit graph and do all the lighting yourself)
Emission cannot make a surface darker than it already is
You can actually have negative emission
(though it probably wouldn't play nice with fog/post processing)
How do I access all of the Terrain layers from Shader Graph?
I only managed to find the first 4. How does unity pack the rest?
So I should substract after the multiply?
If I explained incorrectly, I want the orange to be inside, and the black to be the outer color
You'll probably want to "one minus" before the multiply
I'll give it a try thx!
The easy way? Convert it to a surface shader.
The hard way? Temp use a surface shader, generate output and view generated source. Go through the source, figure out all the calls it is doing, all the passes, and you can duplicate the lighting and BRDF functionality for PBR. There's many variants but you only need one, really, and all passes including shadow receiving code in the main part and shadow caster pass, reflection code, color calcs, etc.
Can any frag shader be converted to surface shaders?
And how would you go about it?
I'm still quite intimiated by shaders in general haha.. especially when I can't use Amplify Shaders
Hey guys, does anyone know how to convert a shader (.shader file) to a lit shader graph (for Universal Render Pipeline)?
This is the actual code:
https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html
Mostly you'll just do the same things, with a custom vert and custom frag. You'll want a custom vert stage because you pass the original object position (called localPosition) in your fraginput struct.
In the frag you'll do the same calcs and assign the result to the .albedo member. You'll want to set the normal vector, and if using PBR lighting...the metallic and smoothness values even if you just hard code some of them.
With a surface shader, lighting/shadows get auto-generated...it will make all the necessary passes for you.
You could try Shader Graph, it has limited support for the BiRP from what I understand. IDK if it will work though, nor do I know what Unity version you are on. I'm not too familiar with BiRP and SG interop.
hey....how to have movement shader based on interaction?
like in case of foliages...if u go through it, it will move on interaction
possible by shader script?
and is it expensive for mobile? just to guess...
Pass in some data into the shader representing your character( a capsule/sphere info?) Then do some light math in the vertex shader to get an offset for each vertex and move the vertex by it.
Hard to say without testing. It's definitely heavier than not doing it.
So how do you go about stacking materials/shaders onto something? Like for example imagine you have a shader that makes the object glow, and you have another shader that makes an object dissolve away. How do you make it so you can have the glowing object dissolve away?
Does this require multiple passes? I'm pretty sure URP has trouble with that.
Do I just slap both materials on, with the dissolve after the glow so its effect takes priority?
Is it that simple?
If you put both into the same shader, i think they will be dealing with different parts (alpha vs emission) so it wouldn't require much work to combine them
I think fundamentally you cannot have two shaders acting together on the same surface
Your realistic options are to have all effects in the shaders that need them (paying mind to complexity)
or swapping effectless shaders to effect shaders on the fly while passing over the properties to reduce unnecessary calculations (might need some extra effort to make sure shaders are compatible)
I'm trying to make a Shader Graph that works as a drop in replacement for URP Lit shader. But I can't figure out what I need to name my Shader Graph parameters. For example URP Lit has a Base Map for the texture. What should I name my texture parameter in Shader graph?
Can see the property names the URP/Lit shader uses by looking at the shader file in the inspector, or opening it in a code editor. Or use https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader
So for the Base Map / Albedo texture it's _BaseMap
But to clarify, It's not really about the name of the property, It's the reference field in the property settings you want to match.
So this line [MainTexture] _BaseMap("Albedo", 2D) = "white" {} means the parameter name is _BaseMap?
I mean parameter Reference?
Yes
Thanks
Is it possible to change the Graph Inspector parameters from input parameters? For example Workflow Mode Render Face etc...or you'd have to make a separate graph with these different optinos?
Hey, anyone know, what happens here or how i can fix it.
After import this Asset Pack i only have these Pink Shaders. Im using URP
When using URP you must use URP compatible shaders/materials
Make new materials for them, or if you have ASE you might be able to compile them again for URP
Ah okay sorry. Thanks
Hello!
I have a question on shader graph, as I now am able to get into it as the technical artist on a project.
I have a custom shader master flow from the blank shader template, which includes both metallic and specular color. This is due to stuff I was experimenting with in Blender.
Although I am seeing no change when using the specular color value even when metallic is at 0.
Is their something I am missing or can both not be in the same shader, causing metallic to override specular color?
..or does it require me to go the color and metallic to dielectric spec route to be able to have both values workable at once?
If it is:
Metallic ( black and white map ) - connect to your metallic output
Specular ( greyscale or color ) - for greyscale that will need some extra stuff, but for color that go into the specular color output.
Roughness / Glossiness - a greyscale map you need to connect to the smoothness output
Emission ( black/white or color ) - a black/white mask or color map , with the mask multiplied by a color, with either connecting to the emission output.
Ah, so unlike Blender's supershader or Unreals color/metallic to specular, Unity can not do either at the same time, got it.
I would ask for you if your reflections are based on math values or a mapped image?
From what I have seen in Amplify before, and presumably the same can be said for Shader Graph, if your doing skybox stuff, the skybox math / texture needs to be connected at the end to emission.
Also real quick, if I am using the built-in renderer as my target, will shader graph support metallic and specular, or just metallic.
..or would I need URP entirely to use either master stack outputs?
Ah okay, it just doesn't let me switch to either on the fly like URP, I would have to add in say metallic or spec manually?
For that, I would still connect it to emission from my knowledge.
I would agree, given the game we are bringing to a new engine, ala Unity, used specular, but we have had problems getting the same look in Specular workflow, as we were given only the compiled assets, meaning we can get textures and models all working, but we have none of the shader code.
Ala none of the master files, so until I can get the shader code, reason I am trying to figure out this out by guesswork.
I mean that is easily gotten around by just pointing a texture's correct channel to the right master stack input.
The part were having an issue with is reflections.
In metallic workflow it looks right, but that makes no sense since they did the same thing in specular workflow.
I have been unable to get that color to black reflectivity in specular mode.
Well color to darkened color reflectivity in specular mode anyway.
is tessellation possible in shader graph?
No.
I am having this exact problem: https://forum.unity.com/threads/writing-to-a-rwbyteaddressbuffer-from-a-pixel-shader-in-a-scriptablerenderpass.995959/
So I started from scratch on all this, and okay, built in render pipeline, added specular color to the stack, it is greyed out, does anyone know why?
I do not have URP installed for reference.
Quick question, if I have a voronoi node in my shader graph, no time or anything to change it
Is it calculated every single frame?
Greyed-out nodes in the master stack means it isn't used by the current Target / Graph Settings.
I don't know how the Built-in target works, but there might be something like "Workflow Mode" in the graph settings where you can switch between Metallic/Specular workflows?
Nope, tried to funky with all the graph settings, did nothing.
It exists outside URP, so that tells me it can use specular color, but I do not know how.
I guess the Built-in Lit graph is Metallic-workflow only then
Then why is specular color there without URP then?
If it wasn't supported or there in code, then it shouldn't even exist in the menu.
It might also be used in HDRP? idk
Looked at the Built-in target source and found references to the workflow mode (as it's likely just copied from URP) but the UI hides it as the shader generation code probably doesn't properly support it yet. https://github.com/Unity-Technologies/Graphics/blob/4ccc5351ef4d264e7cf5d4cdab0024770dbc3740/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Targets/BuiltInLitSubTarget.cs#L138
It does mention "Temporarily"... but given how long it took the Built-in target to even be introduced into shader graph, I wouldn't really expect it soon.
It is strange too because the 2021 version does show the specular color block in the wiki fragment blocks section.
Yes, Voronoi (and other noise nodes) are based on maths calculated per-frame.
But shaders are usually pretty good with that so it may not be an issue. Unless you're targeting mobile maybe, then swapping it out for a texture may be more performant.
Yikes I am trying to use that on shadergraphs and they appear everywhere
So probably ill just bake it?
Also thanks really appreciate it! Couldn't really find that online
https://pastebin.com/SfYGF4YM i'm working on a custom masking shader for my game, but for some reason this is only coming up with the classic error pink. I've double checked with the tutorial i followed, and i can't seem to find any errors. can anyone here help me figure out what's wrong?
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.
So i seem to have narrowed the issue down to compatibility with URP, now i just need to translate it to the URP shader language. Does anyone mind helping me with it?
Is it possible to make a unity surface/texture that can have arbitrary data on it, like if I wanted to make it show my desktop?
So I have an issue, so in shader graph, I have the base color texture going into base color, but it looks nothing like the texture I have to the right.
Yet, metallic is a 0 without any of my math put in, and smoothness is at .5.
Metallic at 0 should be fully showing the base color no problem...yet it doesn't.
Thoughts?
I'm using this image as the 'cubemap' for reference.
It is called a reflection map, but I am unsure how this would be a smoothness map at that point.
If you're using a custom thing, i would say yes put it in emission
I have to convert screen uvs to world positions inside a compute shader, whats the best way to do that?
Should I just lerp between the Frustum Corner?
float4 vertex : POSITION;
float4 color : COLOR;
float4 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR0;
float2 uv : TEXCOORD0;
float4 screenPos : TEXCOORD1;
float4 worldPos : TEXCOORD2;
};```
I want to be able to access the edges of the mesh of an object with this, but I can't seem to do it other than using uv, but that only works on single image objects.
I was thinking I would just use the vertex value but how do I just get that?
{
v2f o;
o.color = v.color;
o.pos = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.pos);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.uv = v.uv.xy;
return o;
}```
Can I add another position/texcoord channel and just do o.vertexPos = v.vertex; or something?
i still don't understand the channels at all tbqh
I assume this channel is also for asking questions with shaders made with shadergraph?
I just solved a problem I had with a vertex color shader, that was missing shadows, by putting addshadow to the end of the #pragma line but I have no idea what I did besides enable shadows.
I'm trying to make a shader that will let me do a texture across multiple planes in world space, if that makes sense? I'm not good at shaders at all, so I have basically no idea what I'm doing half the time. I tried to follow some Unity forum posts on how to achieve what I wanted to do but I can't really get there. The Texture seems fine on the preview, but the result is not at all like that.
This is what I want (I made it in paint quickly)
This is what I get in Unity
This is my graph
you dont need to triplanar map it
you can just use a repeating texture with tiling and offset, with an additional vec2 for adjusting the uv scale
and with the world object position added to the offset
I'd love to know how to do that.
So I remove the triplanar node, I keep the Position node on world (?), I keep the tiling/offset node and then you say add another Vec2 for offset somewhere?
i'll see if i can show you something when i have access to my laptop 🙂
ahh, world pos to the offset of the tiling and offset node
something like that, make sure your texture import settings has wrap mode to repeat, else set the sampler state to repeat
The Position node would need to be Split so you can access the two axis you need for the planar texture projection. Probably XZ/RB in this case.
It would also go into the UV port on the Tiling And Offset as you want to replace the UVs, not offset them.
Something like this
This leaves me with an entirely one-color texture
I assume I'm doing something wrong
The Main Preview quad is probably aligned to a different axis. Try testing it in the scene instead.
It's also completely yellow in the scene
Can't you do like a tile map and just adjust the size?
I have 4 separate meshes that need to line up
Thats alright as long as you adjust the size of the uv
Make sure the plane is pointing up, and make sure the Tiling value on the material isn't set to 0
If you need anything 3d then a triplanar is probably the way
If only vertical or horizontal then tile map should do the trick
With world pos
I tried triplanar at the start but was advised that I didn't need it for what I tried to achieve.
It should also be said that I don't really know what I'm doing in regards to shaders. They are black magic to me.
if you can have the uvs setup correctly, triplanar isn't really needed, else triplanar is also an option
To get this, simple tile map should be fine, given uniformed uv
If not then theres probably a lot of math needed, or a projected uv which i forgot how to do, but its called projected something
i think you mean uv camera mapping
I gave up and instead just tried to eyeball it.
It's not perfect, but it's good enough for the purporse
Thanks for trying to help me @full zephyr @regal stag and @deep otter
Glad it worked out
i almost have it hold on
just a bit more tweaking needed
yeah... honestly just set your uvs correctly and tile them
the other option is triplanar
Right
because this isn't working
I know that, like, in Unreal for example, you can click an option that tries to line up materials using triplanar. I always thought that was magical. Though I don't know how to replicate that in Unity.
let me see if that's possible
I guess this is exactly what we are trying to do here; https://youtu.be/MfJ_1LWe2Q4
In this episode of 5-Minute Materials we look at the World Aligned Texture node! This Material Function allows you to create seamlessly tiling textures across multiple objects by using tri-planar projection to avoid needing proper UV's on your objects! It can save hours of extra work if you know what you're doing, as well allow completely differ...
to attempt rephrasing, how do i get the edges of a 2D objects mesh on an object using a slice from a sprite sheet? on a single sprite object you can just use UV but in a sheet the UV and texelsizes don't represent the size of the mesh.
I can get the SV_Position output which is -0.5 to 0.5, which is semi-usable, but I have no data to translate this into on screen pixels using texture sizes or anything, for example making a 2 pixel wide outline.
Depth cel shading is usually good enough for that, or bake a 2pixel wide outline in your sprite to begin with
oh wow it was really simple @quartz flint
that's... shadergraph, the same as yours
unlit, pbr, etc...what type?
i'm using unlit for experimental purposes
Alright
you just need a seamless texture is all
and wow, this node is useful, i'll tile all my greyboxes with this from now
This is Triplanar Mapping btw, if you ever need to do environments and whatnot.
I used a single texture to try and do what you have achieved now, but normally you'd use three different textures so you can make a landscape and whatnot.
yep, the built in node just samples the same texture thrice
Yea
But at least with the above you have control, I guess
But yeah that kind of texturing is super useful
Especially for procgen UVs
How'd you make the texture @full zephyr ?
Did you make it square where one half is white the other black?
rotated rectangle on background, seamless modifier applied
https://pastebin.com/SfYGF4YM I'm working on a masking shader for a holographic effect in my game, but i believe the tutorial i followed to help make it isn't for URP. Is there a way I can convert this to be compatible with URP, so I can use it for my project? I have the shader script in the linked paste.
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.
URP uses ShaderLab with HLSL, this should help
https://blog.unity.com/technology/migrating-built-in-shaders-to-the-universal-render-pipeline
Alternatively if you need at mosf few shaders you can rewrite it in ShaderGraph
The only thing that would require custom editor node is stencil.
This would be best solution in my opinion since it's quite easy starting point, and it should be editor update-proof.
How could I convert this to URP?```cs
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
_computeShader.SetTexture(0, "Result", _renderTexture);
_computeShader.SetVector("Resolution", new Vector4(_renderTexture.width, _renderTexture.height));
_computeShader.SetVectorArray("Corners", _corners);
_computeShader.Dispatch(0, _renderTexture.width / 8, _renderTexture.height / 8, 1);
Graphics.Blit(_renderTexture, destination);
}```
Or do something similar?
OnRenderImage does not work in urp
do you want to have a custom post effect?
@slim steppe
yep
this is another nice example project with custom effects
https://github.com/togucchi/urp-postprocessing-examples
thanks
This is getting me closer to what I need, but it's giving me an error when I manually changed it from CG to HLSL:
Shader error in 'Custom/redDot01': Unexpected identifier "fixed4". Expected one of: typedef const void inline uniform nointerpolation extern shared static volatile row_major column_major struct sampler or a user-defined type at UnityLightingCommon.cginc(4)
I can't seem to find a solution on my own or online. Do you have any ideas on how I could fix this?
I think HLSL used float4 instead of fixed4
I've used a fixed4 in hlsl before though (iirc)
"unexpected identifier fixed4" makes me think there's a semicolon or similar missing somewhere
Looks like you're maybe still importing a cginc file from your hslsl shader or something? The error is in UnityLightingCommon.cginc(4)
(I don't know enough about shaders to know if that makes sense 😆)
6ri9cty7uo bj0l.
this is my image, UI image (without text)
Made burnt effect shader but problem is its not scaling or respecting aspect ratio
iam not really sure what to google as shader scale and aspect ratio dont give info about it
this is with shader
can i just "apply shader" to not be stretched
ignore alpha difference, resolved that
To preserve the aspect ratios I usually just contain my element and use the full screen stretch anchor presets
You mean UI element? Well that banner is much slimmer, i resized it for visual effect but would like for shader to be independant if thats possible
to be like "overlay"
i guess here shader is applied to image and then image is stretched so shader is too
Yeah, exactly. Not too sure how you can produce that information back to the shader automatically, you're just stretching the UVs this anyway, but can probably adjust them yourself by changing it in the shader and using fields.
otherwise what you'd probably want to do is encapsulate, use the full image stretch pivot/anchor, then reduce the size to where you want it using content resize elements
Width resize anchors I think would distort it
can i make shader certain aspect ratio?
I want to use the Standard shader but just add the noambient pragma to it so it ignores ambient light. is there an easy way to do this?
(I'm using the built-in render pipeline)
https://docs.unity3d.com/Packages/com.unity.shadergraph@7.1/manual/Screen-Node.html
There's that which would match the current ratio
@ebon basin that is input node, just as Texel Size which gives height and width
nothing to make shader "wide"
this actually makes it work, but my shader graph version is 10.x while there is object node and with 14.0 version you get objects renderer size which would make this process automatic and not hardcoded. why is my shadergraph 4 versions behind? package manager has no answers
oh nvm its part of unity version 2022
Texel gives you height and width, but you want the aspect ratio of it
Texel gives you size of texture i think which is 1313x111
image is 500x100 on screen
The idea is you want your shader to adjust as you change the aspect ratio, which if you're using tiling, you'll have to use that information to change those values
I'm not too sure, but I think that's the idea of it all
Probably some basic arithmetic
You can test this by changing the ratios, and seeing the tiling of the shader being warped with different resolutions
yeah, thats what iam saying
this is with texture size
looks bad
because sprite is 1313x111
it would work if image in scene was same aspect
dont think i can make it automatic without unity version 2022.2
with hardcoded aspect ratio, looks nice
Yeah, that's what I do. I'm curious now and will probably look into doing it later
probably already solved somewhere on the forums though
i have found this https://stackoverflow.com/questions/70744159/how-can-i-get-the-actual-size-of-a-gameobject-in-shadergraph
combined with some other google results
hard to find if you dont know what to look for hahahahah
but thanks man, you really helped guide me to solution
iam stupid, i can set aspect ratio as variable and set it from script...
why do the gradient noise has these pink spots?
how do I remove ambient/environment light from the Standard shader?
send all of ur nodes.
its a simple blood pool shader
Anyone know how to make this type of glow around a transparent layer in phototshop?
I believe there's an option called "defringe" in PS which functionally does the same, if the purpose is to remove color fringing
You could also do it manually by duplicating the image layer, doing a blur or a median filter on the layer below, and before merging make a mask from the layer above
Thanks! I will look into the defringe option. I tried the duplicate layer method but I loose the details on the outside of the original layer that way.
Hum defringe doesn’t seem to be what I am looking for. It’s more like I need an increase fringe around the grass / flower 😆
That's what it should be doing in for transparent areas
Basically I want this plant to look the same as the one above so there is no white / black showing on the edge of the grass. Defringe removes from plant edges, I need to increase the plants edges.
I believe that is what defringe is for
If it doesn't work you'll have to do a similar process manually as I described
I don't think you are understanding. Basically I don't need to remove any fringe from the around the plant, I need to increase it, or add like a glow around it, this is because when Unity renders the grass shader transparency there sometimes is a white / black border showing due to the clipping. Especially at a distance. So if there is a expanded glow around it, no clipping is noticeable.
This is what defringe does

In your photo above, defringe removes the outer edges.. I need to increase the outer edges... like expand the edge outward.
Ah, I think I've done this before with some blur tool but I cant recall
basically need to bleed the blur out, but not affect the picture layer
yes, exactly! My first thought was to do some type of blur options, but I haven't been able to figure it out.
could be one of photoshops billion filters
I haven't found one that expands the blur outwards
@digital kelp https://docs.unity3d.com/351/Documentation/Manual/HOWTO-alphamaps.html here seems to be a tutorial for how to do the thing manually
The addon is probably not necessary in the modern age since there's the ability to do dilation per-channel
Yes! Brilliant. Dilation is what I am looking for 🙂
Thank you!
Also found by the name "median filter" as mentioned
what is the difference between eye space depths texture and raw depths texture?
I have this shader which stops rendering, but how can I apply a mask to this shader? Such that it only applies blend zero one based on the alpha value of a mask texture?
Shader "Custom/Mask"
{
Properties
{
}
SubShader
{
Tags { "RenderType" = "Opaque" "Queue" = "Geometry-1" }
Blend Zero One
Pass
{
}
}
}
I've got a bunch of info about depth-related stuff in this tutorial : https://www.cyanilux.com/tutorials/depth/
cool. I will make sure to check this out
How do I make two transparent tiles/sprites overlap without any overlapping areas becoming more opaque like in the red square below?
If you want the alpha returned from the fragment shader to be taken into account you'd probably want to use Blend SrcAlpha OneMinusSrcAlpha instead.
where'd I define the mask in this case?
You'd have a texture property in the Properties section at the top of the shader file, and define, sample and return it in the fragment shader. Should be able to find some examples here : https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
thanks bud
If there's no partial transparency on these tiles, could add a Stencils block to the shader. https://docs.unity3d.com/Manual/SL-Stencil.html
Something like this should work iirc :
Stencil {
Ref 1
Comp NotEqual
Pass Replace
}
hey all, im following this tutorial where ill be able to make speedboard shader
but when i apply shader to material, surface input options where i can insert 2d texture arent showing up
where im doing wrong , can someone point out? Im new to shaders
Make sure that the Texture2D property is marked "exposed"
and that the graph is saved
that worked,thank you
what will be the most performant alpha for mobile?
alpha blend vs alpha fade vs alpha cutoff vs src alpha?
@digital kelp would these be still edgy(zigzag) when inserting in Cutout instead of alpha blend...?
Fully opaque > alpha clipping / cutout > transparency
when i am using lambert alpha blending instead of alpha cutout ...it is giving poor performance by a weird spike called Gfx.wait for present
i am not even turned v sync on
idk...but this thing is utterly killing my whole project when i using alpha
Transparency is expensive due to overdraw
any alternate solution for this since decades?
Not many that I know of
On mobile hardware especially you need to keep a track of how many layers of overdraw are on each given pixel, it's probably doable to have some transparency if you avoid such surfaces overlapping
With modern rendering transparency isn't getting any better, and with many technologies it's getting harder, which is why even desktop games often use dithered alpha clipping to replace it, though it won't really look transparent
what should i do then?
Hard to say
@compact reef Probably the best option at this point for your sanity is to use opaque effects only, like most mobile games
Or study mobile optimization more until you have a grasp of the options and can decide which one is the most appropriate for your project's specific needs
im curious how those games like pubg...renders trees they r supposed to using alpha
i have applied This on my 37 foliages
on First LOD it is Cutout on the second LOD it is Alpha blended(which makes it looks better and smooth)
and Got 29 fps on my mobile
Samsung A10
with bloom and Tonemapping post processing effect
i was thinking to make more performance out of it
am i supposed to hope for more performance?
@grizzled bolt...
That game appears to render only particle effects and the UI with alpha blending
Everything else is opaque cutout or fully opaque
Can't spot any post processing either
How can I check if the stencil value is even?
Should be able to use ReadMask to only check the last bit, which would be 0 if even.
Ref 0
Comp Equal
ReadMask 1
...
Thanks!
Would ref 1 check if its not even?
I keep getting this error with a custom shader I used for a red dot sight I made, and can't seem to find any solution for it online. I've checked, and I'm not referencing cginc in my shader. I had manually converted it from CG to HLSL, and I haven't gotten any errors other than this. Does anyone have an idea as to how i could fix this?
Shader error in 'Custom/RDS01': Unexpected identifier "fixed4". Expected one of: typedef const void inline uniform nointerpolation extern shared static volatile row_major column_major struct sampler or a user-defined type at UnityLightingCommon.cginc(4)
Is there anything specific that needs to be done for debugging shaders with renderdoc? I was following the documentation for Unity and included the line #pragma enable_d3d11_debug_symbols into the CGPROGRAM block of the shader, but when opening RenderDoc I am unable to find any specifics on this shader. I was needing to debug a variable, as it seems its not being set but I am unable to do that currently.
is shader graph good for mobile devices?
We all know that now
built in RP supports shader graph too....so...will that be a good choice using in mobile project?
It has nothing to do with performance, it's just generating shader code for you.