#archived-shaders
1 messages ยท Page 141 of 1
Maybe not? Just working on a sample Mixamo character, happened to come with two materials mapped in.
But I can imagine it's plenty common to have a complex character material setup
Is there no common strategy to apply an effect shader on top of a skinned character?
For a dissolve effect, it wouldn't be enough to add a dissolve shader on top because you would have to discard the pixels of the original shader
Couldn't be done as a post processing effect unless you had a texture of the entire scene without the character
Ok
I was just assuming that applying them in order would work for a variety of effects, so long as the dissolve/transparent/glow/etc came last, or after the skinned shading happened.
Figured I just need to know where to slot in an additional item via some component or field
But once you've drawn something on screen, you can't erase it. So if you draw the skinned mesh on the screen first, you can't remove pixels with a dissolve shader.
You could add glow on top, sure
Fair point, sounds like it would require a more clever approach.
Presumably getting the character textures into the dissolve shader, and replacing the material on the character to do the dissolve
Yeah, or you always have the dissolve shader on there, but just configured so it's not dissolved and increase it when you need it.
K, I follow. Will have to learn how to approach that, but I get the idea.
I am really new to shaders so I hope i can get my point across. I want a sprite to be rendered always on top of everything and with help of the unity forums I found this line
Tags { "Queue"="Overlay+1" }
ZTest Always
The thing is I dont really know where to put that into. I know i cant and shouldnt edit the sprite default shader but I'd like to have the default one as a template to just add this fix to it.
Do you guys have any ideas on how to do it?
@flint vapor You can find all the built-in shaders here
https://github.com/cheeseburgames/unity-builtin_shaders/tree/master/Shaders
it worked! thank you sir
I am trying to make an outline for my toon shader. should be simple. it is not
Using URP, and would like to be pointed in the right direction
hello! so i'm really new to shader graph and shaders in general, and i just have a quick question: how do I switch the blacks and whites of a texture I have sampled in shader graph? for context, I grabbed the alpha channel from a sample of the gradient noise node, but for the effect Im trying to achieve I think i need the blacks / whites flipped (I'm applying a step node on it aftewards)
thanks! all really helpful suggestions, didn't realize some of these nodes existed! I realized the previous error was because i accidentally switched my connections to my step node
is there a limit to the number of object a shader can affect?
im getting some weird behavior where only a few object actually move and other arent, its all the same
its in 2d with lwrp, also when character move on the same Y axis of my grass it start working, its only a foliage shader for 2d and im having a hard time getting this to work
nvm found a thread talking about it
after 2 days... lol
seem like multi sprite in a single file doesnt work well
welp tryed single sprite still not working
I'm having trouble finding a way to do this effect instead of trail renderer but I'm sure its been asked many times.
How would i approach making a "shadow fade" effect on the character where they leave a trail of transparent images of them in 3d? Its being used for a dash ability.
@solid geyser One approach is to spawn a prefab of the same character and match up the poses at different points of the dash
and just fade them out over time
otherwise you could try doing some render target stuff
I see. That might be a bit tricky/intensive doing the prefab clones.
as long as they're pooled it shouldn't be that bad
What would be optimal is every object within the character prefab was affected, including accessories and objects that are being swapped out
a neat approach would be to use a render target
you can render to essentially a sprite-sheet using a camera and a render target
Oh interesting, where could I get started with those things? I'm semi-new to unity
and display it on a quad and do whatever to it in shader
it's a bit more complicated, you'd have to create a new Render Target in your project folder
Also this game is multiplayer/network focused so that might not translate well to other clients?
then create a camera in the scene and set its render target to the one you created
It would translate fine
each client would do their own render
Oh I see
the difficult part is if you want it to match up perfectly with your camera
I don't actually know exactly how I'd implement it
It sounds like camera work involving each player which would have to trigger the script on their screen.
I think for now ill use another temporary effect til a good solution comes up
networking is tricky
@regal stag @low lichen In case you guys are interested about what solved the reflection problem
it wasn't related of the shaders at all
it was due of my cubemap, not having the right settings
The convolution type was set to none
so i had to put it to specular glossy reflection
set it into a sky box
then generate back the lightnings
I try to change a value from the via a script in C#.
But when I do. My shader turns purple
Anybody has a clue what is happening?
HDRP - 2019.3.0f6
The shader works fine untill I try to change the value. at that moment it turns purple
Hello! How can I get the code of the Standard.shader?
@river dawn You can download the built-in shader files from here (select "Built-in Shaders" under the downloads dropdown). https://unity3d.com/get-unity/download/archive
There's also probably a bunch of githubs of them, e.g. from what MentallyStable posted yesterday : https://github.com/cheeseburgames/unity-builtin_shaders/blob/master/Shaders/DefaultResourcesExtra/Standard.shader
(you'll likely also want to check the CGIncludes folder & UnityStandardCoreForward.cginc for the actual vert/frag functions).
@regal stag thanks a lot!
Hi, guys, can anybody help me solve healthbar shadergraph riddle?
I am able to manipulate health
but the values dont reach the sides of my object
if i set health to full, you can see from the preview that its not fully red
i think it just gets meters with x and if my healthbar's x scale is bigger than 1
then it doesnt work
i think i need to somehow have object's edge as a variable
Since you are using Object space, it would be reliant on the mesh's size when imported into unity.
wait Cyan are you that person from twitter who does cool unity shaders?
if so good job man, you are so cool
as i was saying
Probably yeah. Thanks ๐
i think i need to set the edge of my object
and then instead of checking for 0 to 1 range
i would check 0 to 1 with edge added
but i can't figure it out..
how to actually do it
You could likely use the Remap node to remap the range of the input into the 0-1 range for the rest of the graph
thats as far as ive gotten
just knowing i shuld use a remap or lerp
oh i think if i remap
You'd probably want to use Remap or Inverse Lerp. They would do the same thing if the intended output range is 0-1. (A remap is just an inverse lerp into an lerp).
The alternative would be to ensure the mesh scale goes from -0.5 to 0.5 units, in Blender, or whatever modelling program you use.
that's fuckery, i would like this healthbar to be usable not only with this model
i did it
thanks cyan
Hello! I created a cginc file and it didn't recognize the include, it's in the same folders as the shaders who does recognize the includes, any idea?
@river dawn Unity will resolve include paths to built-in include files automatically in ShaderLab shaders, but not in .cginc files.
You could #include "UnityStandardBRDF.cginc" in the Shader Lab shader and then not have to include it in this file. Just make sure you do it in the right order.
#include will just paste all the code in that file into the shader when it gets compiled, so you'd end up with two includes of the same file and get duplicate definition errors.
can we send arrays of instanced data to unity shader?
so like type1Pos = positionFloat3[0]
type2Pos = positionFloat3[1]
for instanced data
Is there a way to do height colouring shader? Like for example I have a cube, the top plane is white but the sides are grey, since the sides are below the top plane
Or is this not possible?
So does anyone find the built in shader for unity terrain to be waaay under par?
has anyone come up with a solution for this?
We need two things that it just does not provide
High blending and a texture driven roughness
was able to build my own just fine
but it only overrides the entire map no way to paint with the unity tools
looking for a way to get world or vertex painted cords I apply to the terrain to talk with a custom shader
there is no way people just put up with the dumpster fire that is unity terrain shader
has anyone worked with sprite maping before? I got some general questions to know before I do some testing.
Yeah
I thought branch nodes were bad for performance, and I should use a lerp.
Now I see this thread
@mertkirimgeri @anorangeduck If you want to make sure it doesn't use a branch no-matter-what, use a ternary operator instead.
y += (x == 0) ? 5.0 : 0.0;
AND this commit
-
branch node to ternary operator
-
Update CHANGELOG.md
-
Update Branch-Node.md
-
Minor edit to CHANGELOG.md
Co-authored-by: Sharlene Tan <43795986+sharlenet@users.noreply.github...
I think Branch nodes are lerps
Where they change the branch node from a lerp to a ternary operator
yeah they used to be a lerp
Ah have they changed it now?
Not sure in which version, maybe it's for 8.0+
but the commit is 23 days old
it's tagged with 'v8.0.1' so yeah
Good to know
In the thread I linked above they mention that most 'ternary operations'
don't get turned into 'branches'
but then honestly I think 'branch' is a bad name for the node
since I thought it would always result in a branch (in GPU terms)
Yeah, I don't know a whole lot about branching. I remember reading this post : https://forum.unity.com/threads/branches-how-expensive-are-they.152411/#post-1044475
which discussed "static" and "dynamic" branching, but it's quite old. I think in general if all the pixels take the same branch, it's probably okay. Better to ask an expert though ๐
Ah neat, saved the link
so weird to see my face pop up in the middle of the conversation ๐
but yeah, branch isn't the best term for what the node is doing but what it does is defined on the node's docs
@heavy stirrup Instanced data is already an array and you can basically make a struct out of it per instance that's what really happens. So just have a Type1Pos and a Type2Pos as your instanced data. But if you don't like that, I think you can use arrays. If not, see StructuredBuffer and do it yourself and pass a float or UINT instance index in the instanced data.
it's dynamic switching not static branching really, you want to use actual shader keywords for full static branching that gets stripped at compile time
@meager pelican Yeah, I believe the instanced data is passed in as a constant buffer. I need to pass in n sets of instanced data and interpolate between them
so i may have 5 sets of instanced data, but only need to render them as one instance
Several ways, since there is a setfloatarray
https://docs.unity3d.com/ScriptReference/Material.SetFloatArray.html
but if it's static data, you may want to try to see if there's a performance diff with using your own structured buffer instead. IDK if there's any type of "dirty flag" for instancing data, as I think it's probably rebuilt each frame according to the current screen contents.
See also SetVectorArray
@meager pelican I'll try it, thanks ๐
hi. I made with tutorials mostly this toonshader, but the shadow isn't working perfectly in the moment. also tried to put it on the end, but the shadow would then be too dark and isn't taking the color ramp in account. also is there a way I can tell the shader: don't cast a shadow on yourself? multiple lights also don't work yet in it. :c
that's something of an open problem for stylized shading in general
did I asked in the wrong group for help?
no, you're just asking a pretty tricky question ๐
is it very complex?
yes-- 'open problem' means 'there isn't really a perfect solution'
(it's an English figure of speech)
I also wished to not use the texture color ramp method, but I am not good enough to do it on my own. but it seems to work with the texture so...its not high on the prio right now.
oh. alright
you can start off by scaling your N dot L term by shadow factor
but be aware that Unity's shadowing is in general kind of mediocre
using textures has some advantages over simple math-based thresholds
the scripters in my team are busy with other stuff and the toonshader is not as importand as the gameplay in the moment. and I am actually the 3D artist, but art is not needed yet. so I thought I could work on the shader. but I can't make it better then what I have right now.
N dot L?
DotProduct node (dot) with the Normal input (N) with MainLight (L)
put them together, dot N L, N dot L
left part of your ToonShader block. I don't think there's a node for getting the main light shadow map
I could be wrong on this since most all of my work has been writing HLSL directly
main light is a custom function. the custom function is writen in HLSL. I could only send you this file to check it
the ShadowAtten output should be what you need
however I would suggest rearranging the Add node and tweaking how your ramp works
scale and bias the dot product directly, then scale it by the distance/shadow factors
you want a Multiply and Add with a value of 0.5 coming off the dot product directly before blending other colors
I also have saved everything as a package, cause I feel a quite clueless.
btw. should the shadow not also take in account specular and rimlight? not that a character is in a shadow but the specular point is still shining
yes, that's because your specular code never sees the shadowing value
notice how it never connects to anything in the SpecularPoint area
you probably also want to have specular be affected by the light color and distance attenuation
since right now it isn't affected by either
@gleaming moss can I send you my unity package for this? if yes, do you also need a test model?
don't have a good way to open it at the moment
oh. okay
it would be easier when I was smart enough to understand more. ^^'
I hope I sorted it at least good.
connection the shadow part with near end makes it work better, but the shadow would then complete ignore the lightramp and creat a pure black shadow.
at least the lamp is now affecting the model normal I think.
quick question about the scene depth node in shader graph: does it already apply linear eye depth? I've seen some tutorials for non shader graph where they sample the depth texture using screen position and then applying LinearEyeDepth() to the result so i'm wondering if node automatically does that or would i need to write a custom node to do linear eye depth
There should be a "sampling mode" on the Scene Depth node for different outputs, set it to "Eye" if you want the LinearEyeDepth
ooooh ok i got it, thanks! just one more thing, are the default UVs passed into scene depth the normalized screen coordinates?
The default input is the Screen Position node
got it
Probably should have asked this before, but I assume this is for a perspective camera projection.. right?
@nimble swallow
yeah i was following along to this roystan tutorial about water: https://roystan.net/articles/toon-water.html and trying to translate it to shader graph so i can learn about how all the nodes work in shader graph ๐
Okay good good, just checking as it works differently in an orthographic camera projection. (If you are interested how, the "raw" result is already linear. I actually published a post today about it, might be a bit advanced though, https://cyangamedev.wordpress.com/2020/03/05/orthographic-depth/)
oh ok cool! I definitely want to take a look later, thanks so much for the help ๐
I might made a homer... o.o
failing at something results in success.
Is there a way I can replace voronoi dots with a texture?
I want to replace this black dots with a star sprite
@gleaming moss now the shadow seems to work much better and even taking the new color ramp in account. it doesn't use textures anymore. but the light color is not affecting much.
Not really, can you explain exactly what you are looking to do? e.g. you want to place stars randomly on a surface
@lime viper yes yes
that's what I want to do
but the tiling and offset is uniform
so I want to randomize it
update. works now better and the shadow is also now working. but I found out, the color should not interact with the color ramp and shadow at that point. I also replaced the texture based color ramp with a gradient version instead. solved it on accident.
stuff to add:
don't cast shadow on itself.
multiple lights.
light colors should have an effect.
beauty adjustment changes.
@tall chasm it's somewhat possible but I can't think of the math, you basically need each location to be 0 to 1 uv coordinates, you will likely get some stretching between regions and the stars will not be allowed to overlap
First get it working on a grid where cells are a star or empty randomly
Then once that works you need to shift each row column randomly on u and v
there is no grid node
@uncut karma sorry I'm still learning
how to replace the white cube with my sprite?
Or am I doing it wrong
@tall chasm thats the right idea, the out of your fraction node can go into the texture sampler for the sprite and you will see 4 of them
the tricky part will be randomly offsetting each smaller UV region (see how it goes from black to yellow, that is from 0,0 to 1,1 AKA 0-1 uv coordinates)
you can actually edit the individual square of the fraction?
You can, by using some conditionals on the tile and offset output, to "filter" what part you want to edit
@amber saffron sorry I can't wrap my head around how to do this. All I keep thinking of is for loops and randomizing it in code. But when it comes to shader graph, I'm really lost
@tall chasm Just make a seamless "star texture" and scroll it. The calcs are probably unnecessary overhead anyway. You're going to end up with a seamless star texture as a result, so just start there.
@tall chasm Here is an example :
Taking the output of the tiling node, I truncate it to keep integer values. Then I combine X and Y to have an individual number by cell.
You can see that the result of the divide by 4 node shows that each of the cell had a number ranging from 0 to 3.
I then use this value as input for a random node, and do a fancy *20 and truncate.
This will give each cell a random value ranging from 0 to 20 (or 19, I don't remember if the random is inclusive), but only integer value.
Finally, I add this to the fractioned uvs, to "offset" on X the value of the individual cells, so the range goes from r to r+1 on x.
I don't know it this is what you wanted to do, but it's an example of how you can modify the cells individually.
Does anyone know of any open source or free assets for purely shader-side generated procedural planets? Doesn't have to be anything fancy.
Hello, I need a little help.
I'm trying to make a liquid on the Tilemap. I created a black and white sprite that represents the Alpha channel of Tile, so I can create an edge on the Top, but now I would like to add a movement to that edge like some waves and these waves have to be based on position (Due to being several Tiles side by side). Does anyone have a suggestion on how to do it?
One of the sprites I'm using is the one below. (The other is just a black sprite that is the liquid itself without any edges)
Thanks in advance for your help.
@primal quartz You can add a random noise value to your alpha channel, based on the XY position
I'll try and see if I can, thanks ๐
@frank ferry You may be able to extend this:
https://www.youtube.com/watch?v=QN39W020LqU
IDK if it's what you want though. It's a series, and is pre-SG I think.
In this series we'll be creating a system for procedurally generating simple, but diverse planets.
Get the project files for this episode:
http://github.com/SebLague/Procedural-Planets
Please note that this series will not be covering level of detail or collisions, the goal ...
Yeah it generates the mesh first than uses shader, I wanted purely shader-based.
Thanks for the answer anyway :).
@amber saffron Thank you ๐ I'll have a look later. I was about to drop the whole idea...
@amber saffron this is the closest thing I can find that I'm trying to achieve. The pattern in circle is randomly distributed on a model. I want my stars to be randomly distributed like that
@frank ferry Well, if you don't want a mesh, then you'll have to use a pure-math based method, like a ray traced planet (maybe with SDF's).
And it will be slow and expensive. Or you can use geometry shaders and generate triangles in your shader, but that's not much different than using a mesh.
Shaders color triangles, from meshes, normally. But you can draw a full screen triangle or quad and ray trace using modern hardware, to a limited extent. Unless you like 1 or 1/100ths frames per second. Then you can get a lot more detail. Depends on use case.
hey i wanted to install shader graph (i use 2019.3) so i insatlled it + high definition render pipeline, added the render pipeline in the graphics settings and upgraded the materials, but everything is so dark that i barely see my trees' colors, please help (i'll send a screenshot)
@tall chasm ok, I see.
Well, what you want to do here is basically applying an other tilling/offset node after the frac, to make the uvs move inside each square.
I can make you an example later on
@coral goblet Lights in HDRP use different units, theres a conversion in unity somewhere to convert your lights. Alternatively you can just crank them up. We're talking multiple thousands of units for your sun light.
HDRP uses real radiometric units
candelas, etc.
the $10,000 'what is intensity 1.0 IRL' question
@amber saffron But if you notice, the 'grass' is lighter in colour inside of the model but darker in colour at the edges. All this can be done using shader?
so i just need to convert my lights? and everything should work?
it will probably take some tweaking, PBR always does
alternately, consider URP
should be much less culture shock and it's way more NPR-friendly
@meager pelican Wouldn't I be able to just displace existing geometry of a sphere? Especially if I want a low poly planet that will only be viewed from very far away/
The sun at noon is approximately 120000 lux AFAIK, it's good that HDRP is using these units
But there is more requirement that your scene exposure and camera settings are good otherwise it can look real bad
@meager pelican Wouldn't I be able to just displace existing geometry of a sphere? Especially if I want a low poly planet that will only be viewed from very far away/
@frank ferry A sphere is a mesh...(and there's several types). Geometry = mesh. GPU's color triangles.
OR
You ray trace it in some fashion.
Yes, did I say anything that implied I have no grasp of meshes? Existing geometry (mesh) of a sphere can be used and displaced by heightmaps. You dont need tesselation or creation of additional geometry. Of course creating mesh from scratch gives you more control over terrain, but for some problems (like mine) it is acceptable and the most efficient.
You rejected the sphere mesh already (that was the first link I gave you). He's displacing a sphere if I remember properly. But it's still a mesh.
You said this:
Yeah it generates the mesh first than uses shader, I wanted purely shader-based.
Thanks for the answer anyway :).
So ยฏ_(ใ)_/ยฏ
He creates a mesh procedurally and than displaces it.
I did not want to change my meshes because it would take too much time, I was just looking for ready shader side solutions that would work on any mesh. Altho I was not expecting a pie to land on my hands from the sky, didnt hurt to ask
That's a shrug, IDK what you're after. Mesh, no mesh, what?
Well thanks again, I just used albedo textures and color tints. Works for now, will figure PCG terrain later.
Okay, just to clear this out - I have a mesh, I want a shader that makes random planets form that mesh.
what is mutually exclusive in that?
You said "no mesh, pure shaders".
then you say you can use a sphere mesh.
I didnt say I want rpocedural terrain, etc. I just want psuedo random planets.
I said no mesh generation
Then don't generate one! Use a canned mesh. But the rest is pretty much the same. It's displacement and coloring.
That's just one example
Yeah Sebastian's requires his mesh to work, no?
You can find others that will shade a sphere too. Probably using variations on albedo, height, ocean, atmosphere and cloud layer textures.
Or you can do most of it mathematically.
Yup, exactly. I could only find the former as a free asset, the latter is what I was after.
Will surely do it sometime on my own. But had to submit it today as a game-jam thing (had 48 hours).
So ended up with combination of textures and tints to get semi-unique planets.
If you want a sphere mesh, here the same guy uses noise (and math on C#) to generate offsets. And there's several episodes. Some of that could translate to shaders if you want, but normally you'd want to pass noise textures into a shader so as to not have to do noice math every pixel.
In this episode we'll create a noise filter to process noise, and layer it for more interesting terrain. Episode 04 is out for early access viewers here: https://www.patreon.com/posts/21079771
Noise script:
https://github.com/SebLague/Procedural-Planets/blob/master/Procedural...
Throw a gpu noise func on it ๐
Thanks.
Can you elaborate on ray tracing? Thats the only thing you mentioned that I am not sure of how is it related to PCG planets.
(shader side or not I don't care anymore, I already submitted my work, now all I care is pretty PCG planets)
Pretty in real-time, or pretty in frame generation (like for a movie or something?)
dont mind that word lol, just PCG planets
Anyway, you'll need to google gpu ray tracing, the usual example is a sphere to start with.
THEN you'll have to add random height offsets or maybe just logical coloring (if real high up) based on logical height at the surface, however you do that (noise or whatever). Texturing.
It's a whole thing in and of itself. And usually slow. That's why NVIDIA just came out with ray-traced special (expensive now) cards, and even then they scatter trace and fill in the blanks. Not an expert. Maybe a combo of techniques. Atmosphere comes to mind. Then there's clouds.
Mostly I think it's usually coloring a sphere, not ray tracing one. YMMV
Okay, so ray tracing would be used only for volumetric part of the planet - like clouds?
I was under the impression you meant ray tracing as in a way to generate the whole PCG planet from scratch.
You CAN. And they DO, I'm sure. Just not fast. ;)
Bet there's a shadertoy or something. Sec.
ah yeah I've seen those in shader toy
@tall chasm Here is how you can randomize a bit the placement :
dont they still use some resources? I was always curious on how do they get trees and such in there, Im quite sure they dont use math for that...
As for color, yes it possible to do it, but you will need to find a way to pass the information that the pixel is "on the edge".
Maybe using vertex colors ?
Hey, does unity not offer its Postprocessing stack anymore? i saw it in some YT tutorials but cant find it on the asset store.
@frank ferry Its probably a mix. Here's a lecture, but I haven't watched it all. The description sounds like it will interest you. He's using an RTX though, I think
Speaker: Prof. Morgan McGuire, University of Waterloo and NVIDIA
Link to slides: http://casual-effects.com/research/McGuire2019ProcGen/McGuire2019ProcGen.pdf
Dynamic procedural worlds are magical. They have limitless detail to explore and can surprise even their creators, ...
Okay, thank you!
@woven plover you can find it in pacman if you use legacy rendering. SRPs have their own builtin forks.
Throw a gpu noise func on it ๐
@uncut karma
Yeah, I mentioned that too, it depends on the hardware and the # of octives in the function and how fast reading the pre-calced noise texture is, and if it's flexible enough. YMMV with all this stuff. That's part of what makes it "fun" but also not always practical. I find that having multiple noise textures and offsets often being time-modulated is pretty flexible particularly when you can generate textures all sorts of ways using graphics editors and play with it. To each their own {within hardware constraints}.
Quick question: Is the depth "buffer" and the depth "texture" the same thing? i.e. does ZTest check the _CameraDepthTexture or some separate depth buffer value?
Essentially the same thing
Hey, I'm having some shader issues when using Addressables on Android, does anyone have any experience on this ?
How would I modify the Standard shader to use Ambient Occlusion on a different UV Set?
why does my material always dissapear when a set the alpha below 0.5
@craggy patrol You likely have the Alpha Clip Threshold setting on the Master node set to 0.5. If the alpha value goes below this, the pixels are discarded. If you don't want this, set the threshold to 0.
Hello, I need a shader to mask everything (except the background) behind it. I found this very simple shader
Shader "Unlit/DepthMask"
{
SubShader
{
Tags { "Queue"="Geometry-1" }
ColorMask 0
ZWrite On
Pass {}
}
}
It works great in scene view, but it's black in play mode. Any idea how to fix this, or do you know if there is already a shader that does this?
Alright what in the world am I doing wrong here?
Core SRP library has this little function. Pretty strightforward I say
And I use it like this
However, it gives incorrect results.
Tried to use different inverse matrices, doesn't work as it should
What am I doing wrong here?
The correctedUV variable represents viewport UVs. Those are correct (going from 0 to 1, just like positionNDC requires, perspective corrected)
@unreal cove The reason it works in the scene view is because apparently the scene view renders the skybox first and then renders everything else, whereas the game view renders opaques first, then skybox.
Not sure why it does this, but that's the reason why. The skybox thinks it doesn't have to draw any pixels where the cube is because the depth buffer says there's something already in front of it.
Is there a tutorial about shaders? i dont know where to start. I dont know if i should use unlit shader on my UI Images or make a sprite and use PBR shader. I tried to use PBR Graph and change the Master node occulsion but when i apply the material with my custom shader, sprite just disappears
@unreal cove An alternative is to draw the cube after opaques and write a custom depth value, essentially punching a hole in the depth buffer so when the skybox is drawn, it thinks there's a hole there and it should draw pixels in it.
@dusk agate If we are talking about shadergraph, For UI I'd use an Unlit Graph (set to Transparent surface mode under the cog on the master node). As for sprites, the Universal RP has extra master nodes : "Sprite Unlit" and "Sprite Lit" (the latter uses the URP 2D Renderer + 2D Lights system to light them). Not sure about HDRP, though I probably wouldn't use HDRP if the game is based on sprites.
@unreal cove Here's a shader that does that. It also has to do a bit of stencil stuff because writing custom depth means also affecting the z test.
https://hatebin.com/qenjqqlhnv
Note, this only works in the game view and not the scene view because of what I mentioned before.
@low lichen thank you! actually my background in the end won't be a skybox but a camera view (vuforia), and that somehow works with the shader I posted
@regal stag for the time being my game is based on UI elements. But unlit master node doesnt have occulsion parameter for example. And i wanted to make my image border glow or sth like this. Thats why i tried sprite and PBR instead of unlit
@dusk agate Right, but PBR (physically based rendering) shaders are intended for 3D geometry, to reproduce how objects are lit in the real world. It's not really what you want. If you want a "glow" around the borders of a UI element or sprite, the easiest method is to just overlay a texture containing that glow. Otherwise, you could look into "sprite outline shaders", which might provide a solution.
I'm playing around with shader graph on URP but i don't understand why the vertex object position changes with rotating the camera, Can someone explain. Keep in mind this only happed when using the PBR node it works fine with the unlit node.
@ionic nest Must be something to do with how that Main Preview is generated. It doesn't move around like that in the scene/game. It also seems to be better if the value is saturated (Saturate node, clamps between 0 and 1, perhaps it doesn't like negative numbers).
It's the same thing on the scene view to, And position should not be clamped right?
And it even changes when rotating the directional light
Eh, that seems odd. I don't think that happens for me, maybe a bug?
(As for clamping, it depends what you are using the position for but I usually clamp colour/alpha inputs to prevent issues. Especially when using bloom post processing).
I'm trying to recalculate normals on the shader.
But the object position is messing everything up.
The thing is vertex object position should not change at any condition just like a texture
I don't think the position is changing in the preview actually. PBR shaders usually have things like metallic/specular which might be affecting the final colour. I just changed the Smoothness to 0 and it fixed it looking weird in the preview. Personally I'd stick to using the unlit master if you're just testing stuff though.
Weird i already done that but still nothing what version are you in?
7.1.6, I can quickly check in 7.1.8 too though
ooh or 7.2.1, didn't know that was there
Yeah, it looks fine to me
My 7.1.6 project was in 2019.3.0f1, and I didn't see any weirdness with the objectspace position. I would recommend updating though just in case, maybe it'll fix it still. ๐ค
Yeah, Or i should create a new project
cuz i messed a bit with the settings
But this effect looks really cool even tho its completely wrong

I'm having an issue with
Shader Graphs and the Gradient Node
Any color that is not white or black, give that error
i made a fire shader, im using that as a torch, wondering if its possible with shader to make it like when character move with the torch the top of the flame get drawed back cause of the movement?
@near pond depends on what kind of mesh you're using to display the fire. If it's just a sort of cylinder kinda thing, you could just rotate it in the direction of motion to give the illusion of a fluid
or setup a couple bones and attach some joints
you could also do this in a vertex shader, but that might get messy
its in 2d using a simple sprite, im using vertex shader for the flame already was trying to figure out a way to make a "trail" when moving, but yeah not sure how i could add more vertex shading to make this happen, maybe i should just make it as particle would be easier
actually i just figured out, just need a bool to enable or disable a wind effect on top vertex , i can only move in a direction anyway (the one im facing) so it gotta go backward all the time
How would I modify the Standard shader to use Ambient Occlusion on a different UV Set than the rest of the textures?
Modifying the Standard shader is a bit of trouble because of how many includes and defines it uses. It's difficult to even figure out where everything is defined because it's all split into so many files. But here are the parts you're interested in. Here it's calling an Occlusion function using i.tex.xy as the uv
https://github.com/cheeseburgames/unity-builtin_shaders/blob/c7bae1930a354f7a33c9911edde2d51a343aa889/Shaders/CGIncludes/UnityStandardCore.cginc#L440
And here's where that Occlusion function is defined
https://github.com/cheeseburgames/unity-builtin_shaders/blob/c7bae1930a354f7a33c9911edde2d51a343aa889/Shaders/CGIncludes/UnityStandardInput.cginc#L119
But there's no straight forward way of replacing this.
hey guys, i've stubled upon some weird behaviour, maybe one of you can help me out or give a bit of info about this. I'm working on a fade in and fade out using a pow function, the issue is, that when passing a magic number into the pow function as the power, everything is fine, but as soon as it's a parameter it has issues, i assume this is due to float inconsistencies and rounding errors, but haven't found a way around it
here is the function when using 4 as a power and on the right when using 4.00001 as power, mimicing the issue i think i shappening
and here is the shader, the top image with the magic number 4 and the bottom one with a parameter, the function is used to fade the alpha out along the uv.y axis
i find it quite curious as using floor, rounding or using datatypes with less bit's didn't have any effect
What's the function?
f(x)=-(x*2-1)^(4)+1
and this is how i use it in the shader col.a = col.a * (-pow((i.uv2.y) * 2 - 1, _PowInput) + 1);
Why not use whole numbers instead?
i'm inputting whole numbers, but it rounds them as the general float inconsistencies do
you canรt have an integer in a shader as far as i know
or can you?
already tried, but didn't make a difference
Some profiles may treat them as floats though
turns out dx11 has integer support, but even with a setup like this it doesn't work even though there definitely should be an integer coming out of that, if i set x to 4 it works...
@low lichen OK.... Is there's any way to create a simple shader that'll imitate the functions of the standard shader, but with the aforementioned AO on a diff uv set?
Hello, Im working on trees as my final school project, at this point I at 4th or 5th tree version which might be my final choice of best looking tree from all distances, only problem here is the lighting which I cant figure out, it look pretty good from front and side but as I move more and more behind it it starts picking this hard light, I have custom normals so I knew there will be some, but this is ridiculous and im wondering if there is a way to tone it down or something as this is far from being usable, thanks
the previous version had pretty similar effect without being custom normals, smoothness turned down, even specular occlusion down for try, I changed almost every value everywhere and still cant figure this one out...
the only way I found to remove this weird effect was to disable light to affect Specular, but this affected every object so its not rly viable option
Is there's any way to create a simple shader that'll imitate the functions of the standard shader, but with the AO on a diff UV set?
you can create a fragment shader, that imitates the unity surface shader, then you can dictate yourself, where which uvset is used, but that would be quite a lot of work, i don't know if anybody has done something like this, try searching on github and the forums. other than that you could use a surface sahder, in which it would be much easier to implement all the features, if that would be an option, you still needed to implement the stuff to pass it onto the outputs though.
also you could just grab the default shader an change what you want to cahnge, you can get it by downloading unity's shader libary
Tried editing Unity's standard shader like that, but I couldn't figure out where Occlusion gets sorted to UV0
that is done in StandardSurface.cginc
not in the shader itself
you need to edit that and save it with your shader and then reference this cginc file from the shader
so you'll save a copy of the StandardSurface.cginc and rename it to then reference it in the shader with #include "ChangedName.cginc" instead of #include "StandardSurface.cginc"
half occlusion = Occlusion(i.tex.xy); would it be this line I change?
i can't say that i know from memory, that this is the only instance of the occlusion beeing assigned the uv but htis is one of the lines you would want changed,
yeah I found this as well in UnityStandardInput, but the standard shader doesn't actually seem to #include it at all
well, that is the method that is calle din the code you just posted, isn't it
believe so
this doesn't work aswell, this seems to be a bug in hlsl, i'll probably report it to untiy, but don't think they can do much, as it's not inside their shader additions, as i belief the pow function is in a native libary of hlsl, or it has to do with float/integer handeling
says it can't find the modifiedstandardcorefile.cginc
It's in the assets folder, does the shader have to be in the same folder as the modified standard core file and input file?
a simpler solution would be to move AO to the Secondary Maps so it uses the UV set specified there, right?
@distant lily thanks for the assistance, in the end I was able to get it going!
no problem, sorry i didn't see the other questions, haven't enabled notifications, but you managed it in the end
All good lol
So I created a new PBR shader and was wondering if its possible to add "Render Face" to it
which is on the LightweightRenderpipeline/Unlit shader
it does exactly what I want
nvm im stupid, just found it inside of Shadergraph
Anyone here with a good solution for creating a custom master node for Shader Graph? The API to do that went private awhile ago, but I need a master node for handling UI.Image shaders... If someone has managed to inject the private assembly or has done anything else, I'd appreciate the info!
but I need a master node for handling UI.Image shaders...
@night tiger I noticed that this didn't get answered, so I'm piping in. Are you sure you need that? Not trying to be a jerk, but mostly you can use unlit nodes for UI.Images, so why doesn't that work as a master node? Just make sure to make a _MainTex Texture2D property.
@meager pelican Hello, constructive criticism is always welcome! There are many shader properties - settings in a basic UI.Image shader, i.e ones that handle masking. Does the unlit node produce a shader with those settings / properties? If it were up to me, I'd make the shader in code, but I also need the designer in my team to be able to make some shaders through the Shader Graph. He did use the unlit, if I recall correctly and I got a warning that the shader is missing properties / settings when the image interacted with the mask.
(Forgot to mention the mask didn't work, just to clarify :P)
The Unlit Master won't create the Stencil based properties for masking UI no, the only way I've found around it is editing the generated code.
@regal stag Not only the properties, which is a bare minimum (since you can add them in Shader Graph). It doesn't add the stencil operations, which are essential for the masking to work. I've also found the same solution, but it's quite tedious to do if the shader is modified throughout development. Cannot really fathom why they made the whole API internal...
OK, so it's the lack of a hardware based stencil in SG. Yeah, I think Cyan is correct, and that you'd have to edit the shader source. HOWEVER, you could manually clip to a mask I suppose, although you might need another draw pass and probably a simple custom material to generate that mask into a render texture. It just isn't hardware level support. Maybe using the alpha-clip property to selectively set the alpha and clip the pixel. There's SG dissolve shaders that basically do that with a texture as a dissolve mask.
Depends on how complex the stencil operation is. I'm kind of seat-of-the-pants here since I haven't tried it. But here IS an alpha-clip on the unlit at least, and that's a making operation. So it's all about how to generate that stencil mask in the first place. Or maybe you have other stencil ops you're doing. IDK.
Thanks for the suggestions. Still, I find it pretty annoying that I have no control over this, especially since I could make my own master nodes before Unity 2019.1 hit... Removing functionality and random changes is the one thing I dislike about Unity, since it's now forcing me to a workaround for no reason at all.
Yeah, it would be nice if you could do it.
How do you past a raw list of vector4 or raw list of floats into a shader?
@ me with answer pls thanks
@grand jolt Material.SetVectorArray and Material.SetFloatArray
float4 vectorArray[10] or whatever size you want
The size has to be defined in the shader, it can't be dynamic
You can pass in a dynamic array length as a separate int property and make the size of the array the max value it can be and have the dynamic length be smaller than that
@fallen musk perfect thank you
you know what's a great idea for a first shader? volumetrics
in other unrelated questions, how do you calculate shadows? the dot product method doesn't give shadows
instead of using the built in shadow method, could i use a kind of raycast system to check if the light is obstructed by an opaque object?
It sounds like you're starting with something way too advanced
i've got it in princaple in my head
if it's not obtructed by an opaque object, color it acording to the distance from the light source
i'm using particles, not a volumetric domain
Are you making the assumption that shaders have access to some raycast method like Physics.Raycast?
i hope there's a similar method
so how does one calculate shadows?
it's basically just a stand surface shader with extra steps
So you've written a surface shader before?
no...
Then how do you know?
instead of changing the brightness with the light source it changes the alpha
hi
That won't make volumetrics
if you use a particle system emitting planes then have the planes more visible toward the light source it might look similar
Well, good luck
i'm just looking for how to calculate shadows
When an object is being drawn on the screen, it has no reference to other objects in the scene, unless there's a depth pre-pass done before, in which case you'll have a basic depth map, but that alone isn't enough to calculate shadows
๐ฟ
@soft harness Realtime shadows are done by rendering a camera from the light's perspective, drawing all the objects with a depth pass, then using that texture in a post processing step and comparing the depth from the light with the depth of the camera to determine what the light can't see and what the camera can see, so it can draw a shadow there.
Here's more information about that
https://catlikecoding.com/unity/tutorials/rendering/part-7/
thanks
I'm giving you this information with the hope that it's overwhelming because you have no knowledge of shaders, so you can start with something simpler
Sure
im trying to get camera to Color[] array
here is what i got so far :
Start() {
...
camRef = GetComponent<Camera>( );
camRef.targetTexture = rendTex;
camRef.enabled = false;
}
private void OnRenderImage( RenderTexture source, RenderTexture destination )
{
Graphics.Blit( source, destination );
Graphics.CopyTexture( destination, tex2D );
}
private void LateUpdate( )
{
camRef.Render( );
}
private void Update( )
{
var data = tex2D.GetPixels( );
for(uint y = 0; y < cameraHeight; ++y)
for(uint x = 0; x < cameraWidth; ++x)
values[ y, x ] = data[ y * cameraWidth + x ];
}
the rendTex and tex2D will have valid images
but the values will be always white
Color[ , ] values *
drawing both the rendTex and tex2D onGUI to see the results
well that's not very nice
@soft harness I only say this because I want to help and I know that doing something this advanced as your first introduction to shaders will not go well.
You have to start with the basics.
Doing stuff on the GPU works completely differently from the CPU.
is there a way around it with co routines ?
@sly breach Why do you need to do this? You'd have to copy the texture from GPU memory to CPU memory, which can take a while, most certainly freezing the game for a moment.
to read raw data and feed into a machine learning algo
You can use Texture2D.ReadPixels for this
So you'd set the render texture as the active texture by setting RenderTexture.active, then call ReadPixels, then Apply
I'm trying to change the texture of the material of an object at runtime and the result just doesn't show. The mesh uses an unlit/texture shader and it works correctly when dragging the new texture directly in the settings of the materials in the inspector but not in runtime via code.
using .SetTexture("_MainTex", newTexture);
What am I missing ?
would u know if its faster then get pixels ?
for some reason readPixels will always return white
GetPixels only reads the texture data in CPU memory
The camera renders on the GPU and stores it on the GPU memory
So you have to copy it over, which Graphics.CopyTexture doesn't do, because it only copies on GPU.
@vital schooner Did you get the right material reference?
myObject.GetComponent<Renderer>();.sharedMaterail.SetTexture(ID, tex2d)
IIRC.
Tensorflow can run on the GPU and I'm sure many other libraries can too
Only cache the references
@vital schooner Did you get the right material reference?
myObject.GetComponent<Renderer>();.sharedMaterail.SetTexture(ID, tex2d)
IIRC.
@meager pelican You are a God...the SharedMaterial fixed it....
But why not just plain object.material.SetTexture ?
@low lichen one more quick question : why sometimes the texture on the GPU will appear flipped / upside down ?
It's a quirk "for historical reasons" and maybe design.
.sharedMaterial is for all instances using that material, whereas .materiel makes a clone of the material and lets you set an instance-specific set of attributes on it. So if you EVER reference .material, you clone it (having many refs in memory)...so don't do that unless you really want to. You should google it for a better explanation.
@meager pelican It saddens me cause I was searching for many hours and couldn't find the problem. Feeling a bit stupid to be honest. Every post I found on the forums didn't mention the sharedMaterials thing.
@sly breach It's a graphics library thing. DirectX uses a different coordinate system to OpenGL. In DirectX, (0,0) is the top left, while in OpenGL (0,0) is the bottom left.
@meager pelican though to be honest, I noticed a strange "textureName" (Instanced) thing when I was doing it the wrong way using just .material
that intrigued but due to not knowing the terminology I couldn't search what I was looking for !
What would be a good case for using just .material though ?
Don't feel bad, all unity programmers run into it until they learn about it. ๐ Usually the hard way.
interesting, so i assume it switches between them during the runtime ( i got 2 gpu's intel and nvidia ) - just a guess
anyway thnx
@vital schooner If multiple objects are using the same material and you only want to change the color of one of them, it's handy to be able to duplicate the material at runtime and only modify that one.
When you want to make some unique changes for one instance on one object and you need a new copy of the material. You could also clone the material, modify it, and then assign it to .sharedMaterial on the object in question. Pretty much what happens in the .materal getters and setters.
i see I see. Damn it took me so much time and it was kinda discouraging cause I had a blast using unity for the first time.
Anyways. Thank you my friends !
The more "modern" way to do it is MaterialPropertyBlocks, but that's a lot to explain right now. Google that too, it's "GPU Instancing".
That isn't suitable in my case, you are just mentioning it for the whole .material, instancing way right ?
Yeah, but why won't it work for you? Does your target not support it?
Just wondering !
I'm just kinda confused still that's why !
It's for mobile probably if that is what my "target" means
Been working on a transparency shader method which utilizes both fade and cutout to hide any Z-writing issues. Any ideas as to how I could potentially improve this?
this line is an error. any idea why? float2 uv : TEXCOORD0
the error is: syntax error: unexpected token 'float2'
nvm forgot to add in ;
what shaders should i use to target android VR ? I'm thinking something like the original doom ( quads with pixel sprites )
is there a way to do _MainTexture.a?
mathf.clamp in shader code?
Does anybody know about a good tutorial on FFT waves?
is it possible to sample depth from a render texture from within a shader? like tex2d(_CameraDepthTexture.. but from an RT
it comes from a secondary camera so i cant just use _CameraDepthTexture
Can't you just put a RT in a texture slot?
thats what im doing to get the colors of the rt but not sure how to get depth instead
Do the same but with the depth information in the RT?
there should already be depth info in the RT, the RTs depth buffer is set to "at least 24 bits depth", and the camera that's outputting to the RT has 'depth texture' enabled
but i don't know how to sample this in the shader
Is this for URP? (since you mentioned the Depth Texture option on the camera)
yes, i should have mentioned
Unity has a preference of doing depth pre-passes into a separate texture rather than using the depth buffer
Well that Depth Texture option writes to the _CameraDepthTexture property, so that should work
Unless you want to sample the RT, while rendering the shader on a different camera that is
it comes from a secondary camera, _camdepthtex will be the depth of the main camera
yea
It's not trivial to sample the depth or stencil buffer. I think the texture has to be some specific type and hardware support for it is spotty.
hmm alright, i thought there might be something simple i was missing.. but if not, i should look for a different way of achieving what im trying to do
it's kinda odd so would be hard to explain
i'll keep looking around, thanks for help anyways
It might not be ideal, but you might be able to use a different (forward) Renderer on the secondary camera and set up a custom renderer feature to render a depth prepass, and write it to a different property (instead of _CameraDepthTexture, which I guess would be overridden when each camera renders). I could be wrong about this though, and it's not exactly the easiest thing to do.
As an alternative, you might just be able to pass in the secondary camera position to your shader and calculate the distances between that and the fragment position or something. (although that's distance, not depth).
by custom renderer feature do you mean just adding a 'render object' and changing it's settings?
and by 'render a depth prepass' do you mean like, it can draw depth like a texture? which i can then ref in the shader and sample?
also curious what the diff between distance and depth is, is it just that depth goes from from 0 to 1 as it approaches max distance, and distance is just units (so would appear white unless something is really close)
I mean an entirely custom feature pass not the RenderObjects feature, I have some experience with coding them but not a whole lot.
ah ok
i think i might be able to do this with just one camera, so _CameraDepthTexture actually works
it's an odd 'fake' 3d thing, limited kinda like wolfenstein but curvilinear
I think depth is similar, but is the "distance between the fragment and a plane perpendicular to the camera" rather the camera's origin/position itself, then probably remapped since the depth texture is 0-1 and not even linear.
That looks pretty cool
oh huh, if depth is to the projection plane then maybe it wont work for this
the walls/floor/ceiling dont have a projection plane
wait no it will work, because the sprites are positioned according to their actual distance, and the camera that sees the sprites is orthographic
my head hurts
also ty
Yeah messing around with stuff like this would hurt my head too ๐
does anyone have any experience with setting up a custom selection shader for editor picking?
I have it working completely to make outlines correct and all
but when I position verts by pixel size, I can't select it anymore, even though the outline is still correct. does anyone know what gives? is like, _ScreenParams broken in the outline picking pass or so?
for instance, the one on the left is sized by world space thickness, works just fine. the other two are based on pixel/screen size, outline works fine, but I can't select them anymore
IIRC Aras made the one that is used in the editor, perhaps worth pinging him on Twitter @blissful atlas
possibly yeah
Is blitting possible using shader graph shader?
_ScreenParams should be read-only data, and IDK why your positioning would mess with picking which, as you say, is editor-side.
P.S. Are you the "actual" Freya Holmรฉr? @blissful atlas of shader forge fame?
@meager pelican I was thinking if screen params in some twilight state between editor renders when rendering the picking buffer. also yes I'm shader forge freya~

basically almost all cases work! here's a uh, table
outline and picking passes are both done when Unity do theirs in the editor, which is why it's weird that it isn't working in the picking pass, unless there is some weird quirk where transforming to screen space/using those matrices/using _ScreenParams is borked somehow
Well, I'm the last guy that should be talking to YOU about shaders, but just to be clear...You're talking about that float4 that UnityEngine is passing into your shader in a cbuffer
x is the width of the cameraโs target texture in pixels
, y is the height of the cameraโs target texture in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height.```
From the docs. Why would that be "borked"?
Did you maybe use DX12 and a shader debugger like PIX or even RenderDoc and/or native debugger and see what values you have?
This, frankly, isn't making much sense to me, Freya.
I'm not sure if I can use Unity's debugging tools to debug when unity's picking buffer is rendered in-editor at the very least
I see. So "twilight" during the editor passes.
(just to be clear, I'm not making a custom outline that overrides or emulates Unity's outlines and picking, I'm making it for in-editor use using Unity's own selection and picking system)
as in, I have a pass that taps into Unity's selection system through
Name "Picking"
Tags { "LightMode" = "Picking" }``` etc.
the reason I suspect it has something to do with screen params or matrices is because, well, I have no idea why it would work in the render and outline pass, but not the picking pass, specifically when using screen-space positioning
lol. Ouch.
OK, but you should STILL be able to ouput those values from that float4 to see/debug what you're getting. Even if you just return those values as a color or sumpt'n
not sure wheeeere I'd output those to be honest, I'd need like, a frame debugger for the scene view~
Why not set the outline color to the _ScreenParams values? You say it still always outlines.
what do you mean by setting outline color to screen params?
I can't really output anything from that pass except write to the picking buffer which I have no idea how to find or see, unless I use some external GPU profiling tool with Unity I suppose
OH, I'll bow out, since I've not used that pass before.
But if I'm in a real bind, I use shader debuggers from the manufacturer, but IDK how well that will work in the editor for a scene-view, as you say.
Maybe your shader could have a buffer that you set the values to and then find a way to read back later on the C# side. Just to debug. IDK.
Never used a picking pass. Good luck, I enjoy your videos. ๐
yeah, I think I'd have to use some external debugging thing
also glad you like my videos~
any1 know how to do this? https://forum.unity.com/threads/3d-scrollrect-mask-for-unlit-texture-shader.842569/ - I tried but I only end up with broken shader.
I'll probably just wait until Unity gets back to me
RenderDoc is great and you can easily debug the scene view with it.
@azure timber what's broken about it?
@blissful atlas when I tried to mix them, I only got it showing my model as pink.
did you get an error on a specific line?
nope no errors
that's weird, it should definitely give you an error if it goes pink
unless you made a shader that is just pink 
well i dont really understand the shader code, so not sure what i did xD. - dunno if it would be easier to edit the lighting in the already working shader but dunno how to do that either.
Hey, I've got a clipping plane shader which I'm using to allow the user to enable and manipulate up to 3 clipping planes on a material. I was using Shader.Find to load the shader and attach it via script to some materials but I found it didn't get exported to the production build with that. I'm trying to export it by adding it to the "Always Included Shaders" list but I have the issue of the build process attempting to compile 65536 shader variants for the shader and then crashing when it hits that number.
I looked at creating a shader variant collection to only build what I need but there are at least 3 million variants of the shader program but as far as I know, I need every variant as it is a modified version of the standard Unity shader.
This is how I'm setting up my multi compile for the different number of clipping planes:
// Compile multiple variants of the shader for different amounts of clipping planes
#pragma multi_compile __ CLIPPING_PLANE_1 CLIPPING_PLANE_2 CLIPPING_PLANE_3
That is on every pass.
if you have that many variants, have you considered using shader_feature instead, and make sure those variants you actually use are included/compiled?
plus, you might actually get away with dynamic branching based on number of clipping planes, the clipping math should be simple enough
so you might not need those static branches
since the number of clipping planes is uniform across a single render
I'm not a shader programmer specifically so I don't know what a shader_feature is. I tried using a shader variant collection but after selecting one of my clipping plane options I think I would have had to have selected 700 thousand or so variants to compile. I'm using 2018.3 btw, just in case there's stuff I don't have access to on my version.
multi_compile will compile all variants
shader_feature will compile all variants that are referenced and used by assets in your project
(mind that it won't detect that you are using variants of materials created in code, such as your case of using Shader.Find and new Material() etc.)
I see, how I'm using the shader is that I am iterating over each material on the game object and replacing the shader being used to my clipping plane shader. There's no reference to the shader in the scene, just in code.
It might be best to split the shader up in to 3 shaders, each one having a different number of clipping planes enabled?
it would have the same effect as now basically, since each of those need to compile their internal variants regardless
that's kinda what multi-compile does anyway (splitting it up into multiple shaders)
but it sounds like you have a lot of other variants other than the 4 you listed?
there should only be 4 variants with that line you posted above, rather than, uh, 65536
Yes, I believe it's because I'm using a modified version of the standard unity shader.
ah right wait you're modifying, yes that
So it also has to compile the variants from the standard unity shader.
right
hm
yeah I'd make number of clipping planes an int property
and do dynamic branching
you're very unlikely to hit perf issues with that
Would dynamic branching be available on 2018.3? I think I recall it requiring a certain engine version so that I can access the specific shader language version?
oh it's been supported since forever
unless we mean different things by dynamic branching
I might be thinking of loops with dynamic iteration counts.
I'm talking about a literal
if( clippingPlanes > 0 ) { do first clip }
if( clippingPlanes > 1 ) { do second clip }
if( clippingPlanes > 2 ) { do third clip }```
Alright, I'll take a look at doing that. Thanks.

Sounds like a fun time
@low lichen even with renderdoc I can't seem to find the picking buffer. captured the scene view for 5 sequential frames, so I got the transition between unselected to selected, as well as tried capturing while scene camera was moving. no picking buffer found :c
I can see it
And I don't have to capture sequential frames, I can just press the RenderDoc button in the scene view after loading RenderDoc in Unity.
does it have the picking buffer? as in, not just the outline shader itself
You mean this slightly blurred TempBuffer?
possibly! how did you find it?
It's part of the SceneCamera.RenderOutline event
heck yea that's it~
okay so here's the mystery
or uh, sec
the two on the left are selectable as they should, the two on the right are not
I feel like this is likely the outline buffer rather than the picking buffer
Oh, sorry I thought that's what you were talking about
Is the picking buffer related to selecting the object based on its pixels on the screen or something?
I'm pretty sure yeah
I have a custom pass that Unity's using to make proper outlines and picking
it works great in most cases
except when I position verts based on screen position
then the outline still works, but picking breaks
so I have no idea why, and what's going on behind the scenes
hm, I guess I'd need to look through the resource list but I don't know how to actually view the resources. the texture viewer seems to only respond to/show events rather than resources
Yeah, I don't think the textures are viewable without an event, since they can be written to at any point during the frame
Are you talking about just clicking to select on object in the scene view?
yep!
Well here's the editor class that handles that
https://github.com/Unity-Technologies/UnityCsReference/blob/f50ab75c509cab05254e0ff2f06eb74f5ecd30da/Editor/Mono/SceneView/SceneViewPicking.cs
Unfortunately, it's just forwarded it HandleUtility.Internal_PickClosestGO, which goes to native code
yeah, was about to say
Is there some documentation about this Tags { "LightMode" = "Picking" }?
n o p e
I haven't found crap about it, but my google-fu may not be strong today.
it's incredibly undocumented
only managed to do it after getting help from tim cooper
MS, she's wondering if the _ScreenParams is set properly during the Picking pass or if it is borked.
(that was my theory at least, among other things)
because the outline and the picking works in literally every single case
until I switch to using pixel/screen based sizing/vertex positioning for the lines
the outline works, but picking breaks
Which bothers me some, because why would the outline work if the values were borked up? You'd think that would mess up the outline.
you'd think yeah
The picking step is probably done before or after the rendering, since it doesn't really have anything to do with rendering.
yeah
well, the picking does use a shader pass
so it has to render to some sort of buffer
Quick question, I have a generated mesh, contains triangles with texture that has alpha, and some of them overlap each other.
There is no way to render them in the correct depth order using a shader, and I have to order them in mesh generation before passing it to the draw call?
With a shader debugger, you can set a breakpoint. And even screw with values of "variables". And of course view/watch them.
It's still a capture, but you can rewind, go forward, edit some, also need to compile your shader for debugging.
@remote mauve pretty much yeah
@meager pelican no idea where to even begin doing that in a Unity shader, is it possible even?
Thanks, good to have confirmation before committing to a solution.
Sure. Not painless, but possible. I do it. I use an AMD card right now on my dev-rig, so I use their tools.
There's also PIX, and NVIDIA tools.
Maybe try PIX and a DX12 Compile.
unity has a doc page for PIX
ah geez, I never go this low level :c
Once you go low-level, you never go back....
haha I'd leave as soon as I could
might just wait for aras and tim to respond at this point
I've never done it for editor stuff though. Usually you try to avoid the editor mess and use a standalone build.
Another question, I need a shader that is unlit, supports texture with alpha, vertex color, and no need for other fancy stuffs like shadows and what not.
I'm using URP Particle Unlit, is there a better shader for my situation, or should I look to make one with shader graph/code?
I'm mostly looking to see if I can improve performance especially for low end mobile* devices, but if URP Particle Unlit/other existing shaders are already performant then I'd rather skip the trouble.
if it's unlit I'd guess it's already performant! but I've barely used URP, so I can't say for sure
@remote mauve You should be able to find plenty of vertex-color SG's with a google.
@blissful atlas Rewrote my shaders to use dynamic branching and building the project no longer crashes. Build times are around 10 minutes or so but that's far better than the alternative. Thanks for the help.
@agile flare glad it worked out!
No doubt, but I was thinking if the performance gain is negligible compare to just using an existing shader, which the answer seems to be yes, then I could put it aside for now.
Thanks for the quick answers guys ๐
Hello ! I'm using a custom shadder that rearranges UV's. It works on Windows but on Android it becomes black. On top of your head, is there any reason why this could happen ?
Precision Problem (maybe you use fixed or half instead of floats) would be my guess.
Hey not sure if this is the best place to post about Shadergraph, please let me know if it's not. I'm using Unity 2019.1 with LWRP and until about a month ago was having no trouble with shadergraph. Now, if I try to edit a shader, about every 5 seconds I get a "compiling preview shaders" popup. It is gone in under a second usually, but if I am in the middle of typing to find a node or dragging an output to a different input it will break what I'm doing. This makes it almost impossible to make new nodes, it's a race against time to try to type in the name of the node in time and a lot of the time I can't. I also can't find any information on this on the internet. How can I make it stop recompiling every 5 seconds?
This is something that weโve fixed in newer versions iirc, but I donโt think itโs available any earlier than package versions compatible with 19.2. Iโm pretty sure youโll need to upgrade your editor version
Okay, thanks. I'm confused about why it started happening after several months of no issues. We didn't upgrade the project during that time.
I'm working on something that when giving 4 points at runtime, it generates a textured quad mesh and renders it on screen.
For now I've been simply creating two triangles but problem like this arises: https://cdn.discordapp.com/attachments/497872424281440267/678393704712765440/unknown.png
I have no idea how to fix it other than increasing triangle count to make it less apparent. Is there a better solution with shaders?
this isn't working. any idea why? _Offset += clamp(_Time[1],0,0.9); IN.uv.x = IN.uv.x + _Offset; if (_Offset >= 0.9) { _Offset = ; }
i've got no error messages, it's just not resetting the offset
@remote mauve this is due to how the interpolation of the texture coordinates work (they work at the triangle level, not the quad). Here's an article on the topic: http://reedbeta.com/blog/quadrilateral-interpolation-part-1/
Pixels and polygons and shaders, oh my!
I have problem with a compute shader, from porting my cpu marching cube to my gpu marching cube :
ComputeBuffer trisBuffer = new ComputeBuffer(5*size*size*size, 72, ComputeBufferType.Append);
int trisCounter = 0;
int ThreadGroupSize = Mathf.CeilToInt(size / 8.0f);
MGS.SetBuffer(0, "density", density);
MGS.SetBuffer(0, "trisBuffer", trisBuffer);
MGS.SetInt("chunkSize", size);
MGS.SetFloat("isoLevel", 0.0f);
MGS.Dispatch(0, ThreadGroupSize, ThreadGroupSize, ThreadGroupSize);
//number of triangle
trisCounter = trisBuffer.count;
//get data from the compute buffer
triangle[] tris = new triangle[trisCounter];
trisBuffer.GetData(tris);
the problem is, the count always return the max value, and sometime it fail to build a mesh collider because of that, how can i resolve this problem ?
Example :
size is 16, so max triangle count is : 20 480 but when creating the mesh most of the time it will have less than 20 480 tris (some time is can be juste 100 tris or even 0) but here the out put fail and create huge error.
return the triangle count from the shader using a uniform/atomic
Is there a way of scaling an incoming texture inside the shader graph?
@sleek granite so better make a counter inside the compute shader rather than counting the data inside it ?
will try it
@vast saddle You can scale the UVs used to sample the texture
What node would I pass the UVs into to do that?
Either a Multiply node, or the Tiling And Offset node
I'm trying to increase the emission intensity of a material during runtime and the materials emissiveIntensity is increasing however it cant be seen, if I slightly move the value using the inspector then all of a sudden its glowing like a pregnant lady, any help guys?
starMeshRends[i].material.SetFloat("_EmissiveIntensity", intensity);
starMeshRends[i].material.SetColor("_EmissiveColor", Color.white); ```
How do you calculate the intensity ?
the intensity is being set fine, im lerping based on the rise and set time of the sun, the value displayed in the materials inspector is as expected
I can see it going up and down as expected throughout the night
Im using HDRP as well if that helps
do you use Luminance or EV100 ? maybe it come from the shader where a function diverge to a high number
Maybe this topic can help you : https://gamedev.stackexchange.com/questions/139590/how-to-set-emission-level-through-c
Im using luminance, it just seems suspicious that if I slightly increase or decrease the value within the inspector field by 0.01 for example all of a sudden the intensity level works as expected, I've tried replicating this in code by turning use emissive intensity on and off etc to no avail
thanks for the link ill check it out
Vector4 with the color piped in and then multiplied by the intensity worked a charm, really wish emission intensity would actually do that but oh well, thanks
HDRP is using a custom material inspector to toggles a keyword on the material when the emission intensity is > 0.
You'll have to toggle this keyword manually from your script, or start from a material that already has it, by using a very low intensity value for example (that should be looking like non emissive if you're using physical light units)
hi guys, so i need use b/w video as the alpha channel, is it possible in unity?, how to add it? since it can't by drag-drop
use PBR anyway
@wraith wing Maybe look into the VideoPlayer component & use Sample Texture 2D with a _MainTex property. https://docs.unity3d.com/Manual/class-VideoPlayer.html
(It also looks like you can select any texture property from the shader on the VideoPlayer component ("Material Property" field), so it doesn't have to be _MainTex)
also if i use PBR as material it can't even want to load that setting
(It also looks like you can select any texture property from the shader on the VideoPlayer component ("Material Property" field), so it doesn't have to be _MainTex)
@regal stag but still, there's no alpha / transparency / opacity channel in there,
@wraith wing If the video/texture is greyscale, you should just be able to use one of the R/G/B outputs of the Sample Texture 2D node as the alpha input on the master node (possibly also needing a One Minus node if it's inverted). Could also use the Color Mask node to produce an alpha mask from the texture colours.
The master node also needs to be set to Transparent surface mode if you want semi-transparent alpha values, otherwise use the alpha clip threshold to specify at which alpha values the pixels should be discarded at.
Hi friends. Unity's default Procedural Sky shader is good enough for me, but I had a problem where I'm doing a game in a [popular sci-fi franchise]-like setting and I needed two suns, I changed the shader but sadly had to detach it from the main directional light. Is there a way I can edit the engine settings so I can set 2 lights and have 2 "_WorldSpaceLightPos" and "_LightColor" ?
@wraith wing Also that "Renderer materials have no texture properties" means the shadergraph hasn't got any Texture2D properties set up in the blackboard to use for the VideoPlayer component. You need to set one up before that dropdown can be assigned to.
@valid maple You could use global shader properties, setting them via Shader.SetGlobalVector/SetGlobalColour
Oh that's a good idea, thanks !
Is there a way I can edit the contents of the "Lighting" panel though ?
Not sure, it might just be easier to have a MonoBehaviour in the scene to manage it
Yeah
I'm writing a shader in shader graph on the HDRP pipeline. I'm running into an issue where glossiness is affecting my transparency. Has anyone seen something similar? It's almost as though the glossiness is ignoring my alpha value of the texture..
If I set things to alpha cutout things render fine..
By glossiness I mean the smoothness factor
@low lichen @meager pelican so I managed to solve the picking issue with some help! turns out, when you pick in the scene view, Unity renders a tiny 4x4 rt at your cursor, with a very cursed projection matrix that basically fucks everything up
I thought the issue was that they wrote to _ScreenParams during that render pass, but turns out it's the other way around - they don't write to screen params, so my pixel-size (which uses clip space) scale goes completely off, because it doesn't match this tiny lil frustum rendered around the cursor. so yeah, the fix in the end is uh, this
I tried same result it just looks black at some angles instead
might want to turn off premultiplied blending too
Hello people,
I have a silly question.
I wrote a simple shader. All it does is checks for the world space of the fragment and compares it with the world space position from the properties.
If check fails it discard the fragment, that's all. This shader has to simulate a liquid inside a glass bottle.
So when you change the input position, which is the "top" of the liquid, it would appear so that there is more or less liquid inside the bottle.
I use Script component with overloaded Update method to set the Properties of the shader. And for some reason all objects with this material use the value from the object that I instantiated the first. Is there somethin I'm missing?
I would use a MaterialPropertyBlock to set the value on the renderer. Otherwise you'd have to instance the materials
_renderer.GetPropertyBlock(_propBlock);
_propBlock.SetColor("_Color", Color.Lerp(Color1, Color2, (Mathf.Sin(Time.time * Speed + Offset) + 1) / 2f));
_renderer.SetPropertyBlock(_propBlock);
Kind of like that?
Also if you don't mind me asking, what's about all this underscore notation? I'm pretty new to the unity and I keep seeing it everywhere.
Yep.
Some people like using underscores before their private variables. The C# convention doesn't have that so you'll find many others not doing that
The shader naming convention seems to have the underscores though
not really sure why that is
perhaps to avoid conflicts with functions, not sure
ah okay, makes sense, big thanks for the help
I'm learning Unity at the moment and i know this topic is kind of advanced, but is there any introduction to shaders which dosen't kill me ๐
Does anyone here know of a tool to "clean" materials from lingering shader properties. It seems that all properties on a shader sticks with the material. So switching between shaders causes two problems, a more and more bloated material file. And also issues when shaders has properties that have the [HideInInspector] attribute and share name with eachother, the values wont reset to the default newly selected shader. This has bitten my team in the behind a couple of times now. So any tool, or workaround (besides re-creating materials) is welcome.
Can anyone give me any tips on how to make more shiny or realistic looking glass?
@quiet osprey we had to write a tool to do that, basically find all assets of type material and scrub properties based on if they don't match the shader
It's really just the texture properties that are bad
Could anyone care to help give some tips on how to replicate this object's effect in unity?
does unity support 16 bit per channel texture import format
Hi everyone ! Is it possible to use the shadergraph with URP shaders ? Thanks. (I'd like to make a simple material blend but the game I am modding only allows URP shaders)
Okay its written litterally on the shadergraph page..
@gilded portal Sure, you can make URP compatible shaders with Shader Graph.
Very cool thanks I was scared having to code shit aha
Do I have to work any differently to make it 'URP compatible' or to be compatible it's just a certain shader I'll have to pick in the list to give me the right inputs?
As I understand it, any shader generated by Shader Graph will be compatible with URP and HDRP no matter what.
Yey ! Thanks
Hey all, hoping someone smarter than me might recognize what is happening here.
I'm creating a post processing outline system using the post processing volume, and it works very well. I'm trying to add depth testing for the objects I'm outlining, so that if objects should pass in front of the outline, it gets sorted properly.
Now the classical way to do this is to render your outline objects into buffer with a shader that takes the screen depth and compares it to the z position of the fragment. I've gotten this to work, but there's a weird artifact when I zoom in on things displayed here in this GIF.
it's worth noting that the artifact is coming when I do a comparison of the depth and the z position of the fragment, and render the difference to black, so this is the raw buffer from the frame debugger.
float fragDepth = i.projPos.z;
float culled = screenDepth > fragDepth;```
here is buffer object shader https://pastebin.com/kQFxuJCD
Figured it out.. instead of ``` float screenDepth = DECODE_EYEDEPTH(tex2D(_CameraDepthTexture, i.projPos.xy / i.projPos.w));
float fragDepth = i.projPos.z;
float culled = screenDepth > fragDepth;``` I did ``` float screenDepth = DECODE_EYEDEPTH(tex2D(_CameraDepthTexture, i.projPos.xy / i.projPos.w));
float fragDepth = i.projPos.z;
float tolerance = 0.01;
float culled = screenDepth > (fragDepth-tolerance);
```
That's called "z-fighting" and you'll find it can turn up in several situations where the z values are really close to equal or are equal. Floats aren't absolutely precise, and it causes problems. You may find comparisons using >= rather than > make a diff too. But the tolerance thing is really better IMO.
woo! yeah it was a huge facepalm haha
i have this pillar model , its UVd. when i am trying to debug the vetex positions using shader , all are returning same value. (builtin pipeline , amplify for shaders ). uv debug :
vertex position :
dynamic bathcing is forced disabled in shader
primitive model on side for comparison
Is the pivot really weird?
yea ok , i see. pivot is way offset
ok so followup question , how do i fix way off pivots. recently switched from maya to blender. blender exports weird as hell pivots
i am making a 3d game where i need to change the color of a mesh from the contact point and expanding gradually from there in circular form like a ripple effect.
for example i have a droplet falling from the sky and i need the mesh that collides with the droplet to change the color gradually from the contact point expanding like a ripple effect until the whole mesh gets colored as the same color of the droplet.
does someone have a solution to this
Hello everyone !!!! I don't know if this is the place to ask but you are, after all, the graphics magicians ! I need to draw lots of Dynamic Meshes, with different materials. I don't need lighting, shadows or anything like that. I'm currently using DrawMesh with success, but performance on mobiles gpu is abysmal. Now, what is the better way to do this ? Command buffers? Jobs ?
with the shader graph, is there a way to mask one texture with another? I have two textures, one is black and white and the other is regular texture. I want to use the black and white texture to mask the other.
@vast saddle Use a Lerp node, Put your black/white texture into the T input and the regular texture in the A or B, depending if you want it to show up where the black or white of the mask is.
@digital mauve Can you show a screenshot of what you want?
Or rather, what you have now using DrawMesh
@vast saddle Yes, use split and combine nodes or swizzle node.
route the Red channel into the Alpha channel of an all white color and then you have an Alpha mask you can multiply with anything else.
or, what @regal stag said that works too
Yeah, depends if you want to mask all colour channels or just alpha.
thanks guys!
How to pass a float2x2 to a compute shader?
I can only find Matrix4x4 in UnityEngine
Can anyone here help me with some texture issue of a model?
I'm still trying to get it to show properly in-game
hi there, i am making a shader and would like to make sure the ambient occlusion is set to Lightmap texture-type, how do I do that? I tried to base-off the normal maps method but it seems like it is a bit different. I am on Unity 2017.2.28f1 (Windowsโข๏ธ 10 x64 bits).
Are there any quirks with stencils in VR (URP)? I've got a simple inversion effect in a fullscreen pass using the stencil buffer. It works fine in the scene and game view in edit mode, but when I enter play mode, and the HMD boots up, the effect stops working in the game view (and when looking through the HMD)
Are you using single pass or single pass instanced?
@low lichen who is the message for?
@tardy spire
ok
@low lichen single pass instanced. same issue with single pass and a black screen with multipass
@tardy spire I would debug it with RenderDoc
You'll be able to see the stencil values your writing and see if anything's wrong
Gave it a download, but it doesn't look like I can use it in play mode ๐ค is that normal? @low lichen
First Load RenderDoc from the menu when not in play mode and it will add a RenderDoc button that persists until you close the editor
Then you can go into playmode and press the button in the toolbar of the Scene or Game view.
ah i gotcha, thanks
@low lichen ok i've got it pulled up in render doc and have been scrubbing through the events. should i be looking for something specific in the fullscreen pass event, or where the objects are rendered with the stencil? The object's shaders don't actually have a stencil pass, I'm using a render objects feature in the urp renderer (in case that's relevant)
Could you walk me through the steps of the effect?
does anyone know how to perform 3d rotations of a 3d procedural texture in shader graph?
the scene here uses a 3d (tri planar) shader
which looks like this
But I cant figure out how to spin the shader in 3d
I can wire it up no problem with code I just cant figure out how to access the rotations in shader graph
Sure @low lichen !
I've got some sprites/text on a specific layer ("Visual Cue")
I made a new renderer and set it as the default renderer for the urp config asset.
It has two renderer features:
The first is a RenderObjects feature which renders all objects on the "Visual Cue" layer. It only draws them where they're occluded by another object, and has a stencil value of 1. This results in the objects getting drawn on top of everything, with a stencil value of 1 where it should have been occluded.
The next feature is a custom fullscreen pass. The shader used in the pass is pretty simple. It inverts _MainTex where the stencil is 1.
The result is the screen color getting inverted where visuals should be occluded.
Here's the code for the fullscreen pass and invert shader if you want it https://gist.github.com/keenanwoodall/b269498e6a70f3486f11687ea873942f
@tardy spire Thanks for taking the time to write that, I understand now. Have you seen this documentation before?
https://docs.unity3d.com/Manual/SinglePassInstancing.html
There's some specific macros you should be using for sampling screen space textures in a post processing shader.
When using Single Pass Instanced
@lost folio You can use the Rotate About Axis node to rotate a Vector3 around a specific axis. Or for full 3D rotations it would probably be better to pass in a rotation Matrix, and Multiply it (Matrix * Vector3). Also see this to set it from script : https://docs.unity3d.com/ScriptReference/Material.SetMatrix.html
@regal stag Thanks! I'll take a look
@regal stag Since I'm wanting to drive the rotations from mouse input I guess I'm looking to rotate around 2 axis. Would that mean I need to use 2 rotate around axis and then somehow merge the results with a matrix node in shader view? Also do you know where I would plug the output of the rotate about axis?
Sorry, I mean use the Rotate About Axis OR the rotation matrix method, not both at the same time. You mentioned a triplanar shader, but how is this set up? Using the Triplanar node?
@low lichen ah that's gotta be it! i copied their pass over mine since it appears to be doing exactly what I want anyways, but the invert effect still doesnt work. does anything look off to you?
https://hastebin.com/ofiyuzeyah.cs
@lost folio I see. You probably want to rotate the Position at the beginning, if I'm understanding what you want to do correctly. (so the Rotate About Axis (or Multiply) would go between the Position and Split node.
@tardy spire If you remove the stencil bit, does it invert everything properly?
interestingly no. well it does in the scene view, but not the game view in play mode
@regal stag OK I think I understand however how would I use rotate around axis to rotate around 2 axis...?
@lost folio You would need to use two Rotate About Axis nodes, rotating around one axis and then the other.
OK thanks I'll give it a go ๐
@tardy spire I'm noticing you're not using a Blit in the fullscreen pass. Would a Blit not work in this case?
there were issues with blit not using the depth/stencil
not sure if this means anything, but I added another render objects that draws a temp layer before post processing. I put a cube on that layer, put the invert material on it, and the screen appears to be its main texture
so it seems to be getting the texture?
I'm starting to think that the full screen quad/triangle just isn't appearing in the right place in VR.
Maybe the way you're doing it only works for non-vr
@low lichen I changed the position of the matrix the fullscreen mesh is drawn with to 0,0,0 instead if 0,0,-1 and i'm getting gray in the hmd view which is progress, but it used to be 0,0,0 which resulted in the effect clipping through geometry because it was too far in front of the camera
any idea why it would be gray of all colors?
moving it around in the scene doesn't change the color so it isn't inverting just the skybox or something
How long did you troubleshoot the Blit depth/stencil issue?
a long-ass time - @regal stag can attest to that as he was doing most of the troubleshooting haha
Haha
It was last thursday & friday in #archived-hdrp if you're interested, it's quite a long conversation though.
It was mostly just trial and error, so I don't know if it would work in VR or not. I don't know anything about VR.
someone on the forums has a few really long posts covering their struggles with the blit function too
https://forum.unity.com/threads/has-anyone-ever-gotten-a-stencil-buffer-to-copy-with-commandbuffer-blit.432503/
https://forum.unity.com/threads/commandbuffer-blit-isnt-stencil-buffer-friendly.432776/
https://forum.unity.com/threads/commandbuffer-blit-with-no-custom-shader-commandbuffer-blit-with-internal_blitcopy-shader.432699/#post-2798713
i couldn't follow most of it tho
Trying to think if you can get the same effect without the fullscreen pass
What about drawing the visual cues again with ZTest Greater and a shader that inverts the colors?
@dense valley I would answer it if I knew the answer. Sorry. I'm not sure what you mean by Lightmap texture-type.
@low lichen are you talking about drawing them again with an override material?
@regal stag Any idea how to wire this up so it doesn't destroy the data (pink)
Sorry I'm very new to shader graph!
@lost folio You need to specify an axis, e.g. (0,1,0) to rotate around the Y axis.
@tardy spire Yeah. That override material could be using some other shader that is similar to the one you use for the visual cues, but inverts colors. But this is assuming you're using the same shader for all visual cues.
yea that was my initial plan, but there's a mix of sprites and text mesh pro shaders
if there wasn't text i wouldnt care stylistically if it was one occlusion effect, but the text needs to be readable ๐ฆ
@tardy spire Btw, the grey in that image looks very bright. I seem to remember the default fog colour is similar to that, it's not the fog is it.. maybe?
OK thanks I'll keep on at it
But what if you use your invert colors post processing shader as the override material? The SRP Batcher should make those extra draw calls less expensive.
So instead of one draw call of a quad filling the entire screen, you do multiple for each visual cue, with ZTest Greater and calculate the screen position in the shader to sample the color texture.
Ah actually the default fog colour is mid-grey apparently, so that's probably not it.
@tardy spire That would also skip the stencil step, so it's not even more draw calls than you're already doing.
Oh, I guess you could be writing the stencil and drawing the object in the same pass
Or can you?
so this is strange, the color isn't constant I jsut needed to look around more (ignore the arrow)
yea i'm writing to the stencil and drawing the occluded part in the same pass
But still drawing the visual cues twice and then the fullscreen pass, right?
ya
seems the issue is the texture sampling still
not sure why setting the position of the matrix to 0,0,0 would make the effect visible (even tho its still broken)
It should work to draw the visual cue once normally, then draw them again with ZTest Greater and using a shader that computes its screen position and samples the color texture and inverts it.
That would be fewer draw calls and less stress on the GPU because there's no fullscreen pass.
Tbh I'm not sure why the position of the matrix needed to be set to 0,0,-1 to prevent the near clipping issue in the first place.
interesting, so draw the layer on top of everything, then draw them again with an override material that grabs the screen color and inverts it
does that require opaque textures to be enabled in the urp config?
Did you not have it enabled already?
I guess you could still do whatever you're doing in the FullscreenPass to get the color texture and assign it globally before doing the RenderObjects pass. Not sure if that's more performant than enabling Opaque Texture.
@low lichen so this is interesting. i exposed the position/rotation/scale of the mesh transform used by the fullscreen pass so i could mess around with it. it doesn't seem to be positioned relative to the camera in vr
Isn't it possible that DrawMesh overrides the view projection when doing Single Pass, so it's proper for each eye?
Maybe if you temporarily disable single pass by doing cmd.SetSinglePassStereo(SinglePassStereoMode.None);, it'll not do anything differently from non-VR.
So do that before doing DrawMesh
should i set it back to Instancing directly after drawing the mesh?
Probably? Unless Unity does it itself regularly.
Hmm I tried it and don't see a quad anywhere anymore
Doing screen space stuff in single pass instanced scares me, which is why I'm recommending a different approach.
gotcha. i'm open for whatever, I just couldn't get stencils to work with anything else
does this answer from a unity dev looking promising to you @low lichen ?
https://forum.unity.com/threads/commandbuffer-blit-isnt-stencil-buffer-friendly.432776/#post-2804560
i can't tell if it's also a fullscreen pass
Blit is always fullscreen
I definitely feel better about using Blit than drawing the fullscreen quad manually, so I'd rather go down that route.
I mean I can't tell if his approach is the same as mine to get the stencil to work. It seems like he's not blitting with the post processing material so I guess he's not doing it "right" either
I tried drawing the layer on top always and then drawing it again with a ztest of greater with an override (shader graph) material that inverts the scene color, but the layer doesn't seem to get written to the color texture so it just inverts whatever is in front of it
Yea haha that's been my feeling. Super simple effect but it's been a tough one!
@tardy spire I nearly have something, but do you see that weird noise in the black color? I don't know what that is. It's only in the game view, not the scene view.
that's super weird!
Hmm, post processing seems to be doing that for some reason, it's fine before it kicks in.
dithering gone wrong?
There shouldn't be any dithering happening that I know of
But I can show you my setup and you can see how it works for you
yea lets do that
Here's the renderer
It took some debugging to figure out when exactly the Opaque Texture is ready
and the invert shader
Mine has a solid rect border since I'm just using the default InputFieldBackground, which isn't set to Tight.
But you had the same issue with stencils I'm assuming.
@low lichen That seems to work great and I can now use msaa!
Great!
are there *any performance differences between this approach and what i was doing before? or is this just one of those things I should profile if i start having performance issues?
idk the implications of enabling the opaque texture i guess
Well, in terms of draw calls, you've reduced it by one by skipping the full screen pass. I'm not sure what the cost of enabling the opaque texture is. As far as I can see, it's basically just a blit in between drawing the skybox and transparents.
Gotcha, well thanks a bunch for your help I really appreciate it!
No problem! I happen to be working with URP and Single Pass Instanced for the first time, so I've learned a bit as well.
Hi everyone ! Kind of noob in this shader business, i was wondering how could i apply two different shaders to different objects... they always change together..
thanks a lot
i wanna "cut" a cube
not really
but it will scale to the new cut size
now i want the texture to be the same as before, so it should not scale and should look like the texture got cut off
how would i do that?
UV coordinate adjustment based on intersection of object with whatever you're using (plane?) for cutting
this is very much a complex problem and not something you can really do just with shaders (at least, not in the capacity I think you want)
oh yeah i think i am on the best track if i use uv and a good texture where i can calculate new uvs from that scale
@regal niche you need two materials, one per object
Is there a way to get the top face of a cube with shader?
@tall chasm You could use a Dot product with the Normal Vector (probably in object space so rotations don't change it) and upwards vector (0,1,0).
Which means, using that I can also find all the other sides of the cube?
or for a texture you can setup specific uv coordiate and telling it's the top face of the cube
each uv coordiate correspond to as face
a*
I'm not planning on using any textures
Is there a particular reason you need to get each face of a cube?
@regal stag So I plan on making a game without using textures. The materials will be unlit. So the top face will be a brighter colour, then everything below will have a gradient from light to dark
In that case you could just use the Position.y to colour the cube, you don't need to get specific faces
you can even specify the color inside the vertex shader
Hang on let me find some examples
or the mesh itself with this : https://docs.unity3d.com/ScriptReference/Mesh-colors.html
you want hard transition or gradiant ?
The one with the red arrows have a gradient at the sides. The others are hard transitions. I somewhat know how to do the gradient already. So I'm lost on how to shade the sides to another colour so it's different from the top
I would either look into using Vertex Colours : assigning a colour per vertex, they'll be interpolated between the vertex and fragment shaders so produce a gradient. (Either using the link @shadow magnet posted above for a procedural mesh, or model a cube and assign vertex colours in Blender)
Or use the fragment Position like this.
Hang on let me show mine
For the example you posted, they probably just use textures.
This is mine. But I have a slider the pushes the top colour up the Y axis. It doesn't auto detect the top face of a model. So I thought there might be a better way that shader might know which face is facing the top
Hmm... textures which mean everything will have to be uv mapped?
I mean, you are using UVs and a texture in that graph for the grass texture
Hmm... ok. Do you think this is texture or shader?
Most likely a texture
Ahh ok. Forgive me if I might be asking silly questions. Trying to wrap my head around this artstyle
This is not toon shading right?
I don't think they're silly, but there is a teachable bit in here about art directability. You can do these things in a shader, but if you instead implement via textures or UV they are very controllable for specific effect
if anything it goes to show 'dot product with world-space vector' is almost never a good solution just because it's steps removed from what you really want, i.e. to make certain portions have flat color and others to have a gradient
you want to just mark an area, and something like a vertex color is a great choice for that
Hello I am on Unity 2017.4.28f1, I would like to know why the panning setting i wrote in the shader doesnt appear when I use [HideInInspector]?
_Color ("Color & Alpha", Color) = (1, 1, 1, 1)
_Saturation ("Saturation", Range(-1, 1)) = 0
_MainVertexColoring ("Vertex color usage", Range(0, 1)) = 0
_MainEmissionStrength ("Basic Emission", Range(0, 20)) = 0
_MainHueShift ("HueShift", Range(0, 1)) = 0
_MainTex ("Diffuse", 2D) = "white" { }
[HideInInspector][Vector2] _MainTexPan ("Panning", Vector) = (0, 0, 0, 0)
[Enum(UV 0, 0, UV 1, 1, UV 2, 2, UV 3, 3, Distorted UV 1, 4, Distorted UV 2, 5, Distorted UV 3, 6)] _MainTextureUV ("UV layer", Int) = 0
[HideInInspector] m_end_mainDiffuseOptions ("Diffuse", Float) = 0```
@dense valley uhh _MainTexPan ?
Panning
Read the line
Is it because of how I named it?
Of course it won't appear if you use Hide
Its supposed to show underneath the texture offset and tiling options
[HideInInspector] will do exactly that, hide it from the inspector.
