#archived-shaders

1 messages ยท Page 141 of 1

low lichen
#

Is it neccessary for your skinned meshed to use multiple materials?

static apex
#

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?

low lichen
#

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

static apex
#

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

low lichen
#

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

static apex
#

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

low lichen
#

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.

static apex
#

K, I follow. Will have to learn how to approach that, but I get the idea.

flint vapor
#

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?

low lichen
flint vapor
#

it worked! thank you sir

quick wigeon
#

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

nimble swallow
#

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)

halcyon hamlet
#

there might be a node called invert

#

otherwise use Minus One

quick wigeon
#

Flip node @nimble swallow

#

Probably

nimble swallow
#

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

near pond
#

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

near pond
#

welp tryed single sprite still not working

solid geyser
#

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.

uncut schooner
#

@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

solid geyser
#

I see. That might be a bit tricky/intensive doing the prefab clones.

uncut schooner
#

as long as they're pooled it shouldn't be that bad

solid geyser
#

What would be optimal is every object within the character prefab was affected, including accessories and objects that are being swapped out

uncut schooner
#

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

solid geyser
#

Oh interesting, where could I get started with those things? I'm semi-new to unity

uncut schooner
#

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

solid geyser
#

Also this game is multiplayer/network focused so that might not translate well to other clients?

uncut schooner
#

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

solid geyser
#

Oh I see

uncut schooner
#

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

solid geyser
#

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

polar yew
#

@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

wide berry
#

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

river dawn
#

Hello! How can I get the code of the Standard.shader?

regal stag
#

@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).

river dawn
#

@regal stag thanks a lot!

digital venture
#

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

regal stag
#

Since you are using Object space, it would be reliant on the mesh's size when imported into unity.

digital venture
#

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

regal stag
#

Probably yeah. Thanks ๐Ÿ˜Š

digital venture
#

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

regal stag
#

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

digital venture
#

thats as far as ive gotten

#

just knowing i shuld use a remap or lerp

#

oh i think if i remap

regal stag
#

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).

digital venture
#

ok i think ive got an idea

#

thanks

regal stag
#

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.

digital venture
#

that's fuckery, i would like this healthbar to be usable not only with this model

#

thanks cyan

river dawn
#

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?

low lichen
#

@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.

heavy stirrup
#

can we send arrays of instanced data to unity shader?

#

so like type1Pos = positionFloat3[0]
type2Pos = positionFloat3[1]
for instanced data

tall chasm
#

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?

lost tendon
#

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

lavish star
#

has anyone worked with sprite maping before? I got some general questions to know before I do some testing.

devout quarry
#

@regal stag

#

In your graphs you often use a 'branch' node right?

regal stag
#

Yeah

devout quarry
#

I thought branch nodes were bad for performance, and I should use a lerp.

#

Now I see this thread

#

AND this commit

regal stag
#

I think Branch nodes are lerps

devout quarry
#

Where they change the branch node from a lerp to a ternary operator

#

yeah they used to be a lerp

regal stag
#

Ah have they changed it now?

devout quarry
#

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

regal stag
#

Good to know

devout quarry
#

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)

regal stag
#

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 ๐Ÿ˜›

devout quarry
#

Ah neat, saved the link

stone sandal
#

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

meager pelican
#

@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.

stone sandal
#

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

heavy stirrup
#

@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

meager pelican
#

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

heavy stirrup
#

@meager pelican I'll try it, thanks ๐Ÿ™‚

hoary umbra
#

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

gleaming moss
#

that's something of an open problem for stylized shading in general

hoary umbra
#

did I asked in the wrong group for help?

gleaming moss
#

no, you're just asking a pretty tricky question ๐Ÿ™‚

hoary umbra
#

is it very complex?

gleaming moss
#

yes-- 'open problem' means 'there isn't really a perfect solution'

#

(it's an English figure of speech)

hoary umbra
#

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

gleaming moss
#

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

hoary umbra
#

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?

gleaming moss
#

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

hoary umbra
#

main light is a custom function. the custom function is writen in HLSL. I could only send you this file to check it

gleaming moss
#

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

hoary umbra
#

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

gleaming moss
#

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

hoary umbra
#

@gleaming moss can I send you my unity package for this? if yes, do you also need a test model?

gleaming moss
#

don't have a good way to open it at the moment

hoary umbra
#

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.

nimble swallow
#

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

regal stag
#

There should be a "sampling mode" on the Scene Depth node for different outputs, set it to "Eye" if you want the LinearEyeDepth

nimble swallow
#

ooooh ok i got it, thanks! just one more thing, are the default UVs passed into scene depth the normalized screen coordinates?

regal stag
#

The default input is the Screen Position node

nimble swallow
#

got it

regal stag
#

Probably should have asked this before, but I assume this is for a perspective camera projection.. right?

#

@nimble swallow

nimble swallow
regal stag
nimble swallow
#

oh ok cool! I definitely want to take a look later, thanks so much for the help ๐Ÿ™‚

hoary umbra
#

I might made a homer... o.o
failing at something results in success.

tall chasm
#

Is there a way I can replace voronoi dots with a texture?

hoary umbra
#

@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.

lime viper
#

Not really, can you explain exactly what you are looking to do? e.g. you want to place stars randomly on a surface

tall chasm
#

@lime viper yes yes

#

that's what I want to do

#

but the tiling and offset is uniform

#

so I want to randomize it

hoary umbra
#

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.

uncut karma
#

@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

tall chasm
#

there is no grid node

uncut karma
#

U must do it with math nodes

#

Or the fmod modulo could help maybe

tall chasm
#

@uncut karma sorry I'm still learning

#

Or am I doing it wrong

uncut karma
#

@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)

tall chasm
#

you can actually edit the individual square of the fraction?

amber saffron
#

You can, by using some conditionals on the tile and offset output, to "filter" what part you want to edit

tall chasm
#

@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

meager pelican
#

@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.

amber saffron
#

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.

frank ferry
#

Does anyone know of any open source or free assets for purely shader-side generated procedural planets? Doesn't have to be anything fancy.

primal quartz
#

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.

amber saffron
#

@primal quartz You can add a random noise value to your alpha channel, based on the XY position

primal quartz
#

I'll try and see if I can, thanks ๐Ÿ™‚

meager pelican
#

@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 ...

โ–ถ Play video
frank ferry
#

Yeah it generates the mesh first than uses shader, I wanted purely shader-based.
Thanks for the answer anyway :).

tall chasm
#

@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

meager pelican
#

@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.

coral goblet
#

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)

amber saffron
#

@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

halcyon hamlet
#

@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.

gleaming moss
#

HDRP uses real radiometric units

#

candelas, etc.

#

the $10,000 'what is intensity 1.0 IRL' question

tall chasm
#

@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?

coral goblet
#

so i just need to convert my lights? and everything should work?

gleaming moss
#

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

frank ferry
#

@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/

uncut karma
#

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
#

@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.

frank ferry
#

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.

meager pelican
#

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 ยฏ_(ใƒ„)_/ยฏ

frank ferry
#

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

meager pelican
#

That's a shrug, IDK what you're after. Mesh, no mesh, what?

frank ferry
#

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.

meager pelican
#

You seem to be saying mutually exclusive things.

#

OK.

frank ferry
#

what is mutually exclusive in that?

meager pelican
#

You said "no mesh, pure shaders".

then you say you can use a sphere mesh.

frank ferry
#

I didnt say I want rpocedural terrain, etc. I just want psuedo random planets.

#

I said no mesh generation

meager pelican
#

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

frank ferry
#

Yeah Sebastian's requires his mesh to work, no?

meager pelican
#

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.

frank ferry
#

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.

meager pelican
#

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.

uncut karma
#

Throw a gpu noise func on it ๐Ÿ˜„

frank ferry
#

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)

meager pelican
#

Pretty in real-time, or pretty in frame generation (like for a movie or something?)

frank ferry
#

dont mind that word lol, just PCG planets

meager pelican
#

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

frank ferry
#

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.

meager pelican
#

You CAN. And they DO, I'm sure. Just not fast. ;)
Bet there's a shadertoy or something. Sec.

frank ferry
#

ah yeah I've seen those in shader toy

amber saffron
frank ferry
#

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...

amber saffron
#

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 ?

woven plover
#

Hey, does unity not offer its Postprocessing stack anymore? i saw it in some YT tutorials but cant find it on the asset store.

meager pelican
#

@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

frank ferry
#

Okay, thank you!

grand jolt
#

@woven plover you can find it in pacman if you use legacy rendering. SRPs have their own builtin forks.

tall chasm
#

Thanks @amber saffron ! I will try that out

#

[solved]

meager pelican
#

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}.

woeful crypt
#

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?

plucky bone
#

Essentially the same thing

digital mauve
#

Hey, I'm having some shader issues when using Addressables on Android, does anyone have any experience on this ?

royal field
#

How would I modify the Standard shader to use Ambient Occlusion on a different UV Set?

craggy patrol
regal stag
#

@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.

craggy patrol
#

oh thx i did not see that the option even existet XD

#

thx

unreal cove
#

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?

slate patrol
#

Alright what in the world am I doing wrong here?

#

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)

low lichen
#

@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.

dusk agate
#

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

low lichen
#

@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.

regal stag
#

@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.

low lichen
#

@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.

unreal cove
#

@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

dusk agate
#

@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

regal stag
#

@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.

ionic nest
#

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.

regal stag
#

@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).

ionic nest
#

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

regal stag
#

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).

ionic nest
#

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

regal stag
#

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.

ionic nest
#

Weird i already done that but still nothing what version are you in?

regal stag
#

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

ionic nest
#

Hmm ill try update unity then and see im runing 2019.3 0

#

Thanks for the help UnityChanOkay

regal stag
#

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. ๐Ÿคž

ionic nest
#

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

dense star
#

Any color that is not white or black, give that error

near pond
#

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?

orchid peak
#

@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

near pond
#

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

royal field
#

How would I modify the Standard shader to use Ambient Occlusion on a different UV Set than the rest of the textures?

low lichen
#

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

#

But there's no straight forward way of replacing this.

distant lily
#

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

plucky bone
#

What's the function?

distant lily
#

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);

plucky bone
#

Why not use whole numbers instead?

distant lily
#

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?

plucky bone
#

You can always floor them

#

And I think they are "supported"

distant lily
#

already tried, but didn't make a difference

plucky bone
#

Some profiles may treat them as floats though

distant lily
#

also tried the round function

distant lily
#

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...

royal field
#

@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?

merry rose
#

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

royal field
#

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?

distant lily
#

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

royal field
#

Tried editing Unity's standard shader like that, but I couldn't figure out where Occlusion gets sorted to UV0

distant lily
#

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"

royal field
#

half occlusion = Occlusion(i.tex.xy); would it be this line I change?

distant lily
#

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,

royal field
#

yeah I found this as well in UnityStandardInput, but the standard shader doesn't actually seem to #include it at all

distant lily
#

well, that is the method that is calle din the code you just posted, isn't it

royal field
#

believe so

distant lily
#

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

royal field
#

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?

royal field
#

@distant lily thanks for the assistance, in the end I was able to get it going!

distant lily
#

no problem, sorry i didn't see the other questions, haven't enabled notifications, but you managed it in the end

royal field
#

All good lol

flint vapor
#

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

night tiger
#

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!

meager pelican
#

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.

night tiger
#

@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)

regal stag
#

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.

night tiger
#

@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...

meager pelican
#

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.

night tiger
#

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.

meager pelican
#

Yeah, it would be nice if you could do it.

grand jolt
#

How do you past a raw list of vector4 or raw list of floats into a shader?

#

@ me with answer pls thanks

low lichen
#

@grand jolt Material.SetVectorArray and Material.SetFloatArray

grand jolt
#

@low lichen what does the property look like in the shader?

#

thats what i dont get

low lichen
#

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

grand jolt
#

@fallen musk perfect thank you

soft harness
#

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?

low lichen
#

It sounds like you're starting with something way too advanced

soft harness
#

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

low lichen
#

Are you making the assumption that shaders have access to some raycast method like Physics.Raycast?

soft harness
#

i hope there's a similar method

low lichen
#

There's not

#

Again, this is way too advanced

soft harness
#

so how does one calculate shadows?

low lichen
#

Start by getting some red pixels on the screen

#

Go from there

soft harness
#

it's basically just a stand surface shader with extra steps

low lichen
#

So you've written a surface shader before?

soft harness
#

no...

low lichen
#

Then how do you know?

soft harness
#

instead of changing the brightness with the light source it changes the alpha

sly breach
#

hi

low lichen
#

That won't make volumetrics

soft harness
#

if you use a particle system emitting planes then have the planes more visible toward the light source it might look similar

low lichen
#

Well, good luck

soft harness
#

i'm just looking for how to calculate shadows

low lichen
#

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

meager pelican
#

๐Ÿฟ

sly breach
#

๐Ÿฟ

#

hi @low lichen

low lichen
#

@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.

soft harness
#

thanks

low lichen
#

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

sly breach
#

๐Ÿ‘‹

#

can i drop a Graphics.Blit question here ?

low lichen
#

Sure

sly breach
#

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

soft harness
#

well that's not very nice

sly breach
#

1st is rendTex 2nd is tex2D

low lichen
#

@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.

sly breach
#

is there a way around it with co routines ?

low lichen
#

@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.

sly breach
#

to read raw data and feed into a machine learning algo

low lichen
#

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

vital schooner
#

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 ?

sly breach
#

would u know if its faster then get pixels ?

#

for some reason readPixels will always return white

low lichen
#

You're not using ReadPixels in the code snippet you posted

#

Did you try it before?

sly breach
#

sorry i mean tex2D.GetPixels( );

#

and yes

#

read pixels will work

low lichen
#

GetPixels only reads the texture data in CPU memory

sly breach
#

ah ok

#

got it

low lichen
#

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.

sly breach
#

i see

#

๐Ÿคž for ML GPU support in the near future

#

cheers @low lichen

meager pelican
#

@vital schooner Did you get the right material reference?

myObject.GetComponent<Renderer>();.sharedMaterail.SetTexture(ID, tex2d)

IIRC.

low lichen
#

Tensorflow can run on the GPU and I'm sure many other libraries can too

meager pelican
#

Only cache the references

sly breach
#

current mlagents implementation only has inference mod for gpu

#

afaik

vital schooner
#

@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 ?

sly breach
#

@low lichen one more quick question : why sometimes the texture on the GPU will appear flipped / upside down ?

meager pelican
#

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.

vital schooner
#

@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.

low lichen
#

@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.

vital schooner
#

@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 ?

meager pelican
#

Don't feel bad, all unity programmers run into it until they learn about it. ๐Ÿ˜‰ Usually the hard way.

sly breach
#

interesting, so i assume it switches between them during the runtime ( i got 2 gpu's intel and nvidia ) - just a guess

#

anyway thnx

low lichen
#

@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.

meager pelican
#

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.

vital schooner
#

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 !

meager pelican
#

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".

vital schooner
#

That isn't suitable in my case, you are just mentioning it for the whole .material, instancing way right ?

meager pelican
#

Yeah, but why won't it work for you? Does your target not support it?

vital schooner
#

Just wondering !

#

I'm just kinda confused still that's why !

#

It's for mobile probably if that is what my "target" means

royal field
#

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?

soft harness
#

this line is an error. any idea why? float2 uv : TEXCOORD0

#

the error is: syntax error: unexpected token 'float2'

#

nvm forgot to add in ;

sly breach
#

what shaders should i use to target android VR ? I'm thinking something like the original doom ( quads with pixel sprites )

soft harness
#

is there a way to do _MainTexture.a?

soft harness
#

mathf.clamp in shader code?

devout quarry
#

Does anybody know about a good tutorial on FFT waves?

ocean spade
#

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

plucky bone
#

Can't you just put a RT in a texture slot?

ocean spade
#

thats what im doing to get the colors of the rt but not sure how to get depth instead

plucky bone
#

Do the same but with the depth information in the RT?

ocean spade
#

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

regal stag
#

Is this for URP? (since you mentioned the Depth Texture option on the camera)

ocean spade
#

yes, i should have mentioned

low lichen
#

Unity has a preference of doing depth pre-passes into a separate texture rather than using the depth buffer

regal stag
#

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

ocean spade
#

it comes from a secondary camera, _camdepthtex will be the depth of the main camera

#

yea

low lichen
#

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.

ocean spade
#

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

regal stag
#

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).

ocean spade
#

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)

regal stag
#

I mean an entirely custom feature pass not the RenderObjects feature, I have some experience with coding them but not a whole lot.

ocean spade
#

ah ok

#

i think i might be able to do this with just one camera, so _CameraDepthTexture actually works

regal stag
#

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

ocean spade
#

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

regal stag
#

Yeah messing around with stuff like this would hurt my head too ๐Ÿ˜…

blissful atlas
#

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

plucky bone
#

IIRC Aras made the one that is used in the editor, perhaps worth pinging him on Twitter @blissful atlas

blissful atlas
#

possibly yeah

vast saddle
#

Is blitting possible using shader graph shader?

meager pelican
#

_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?

blissful atlas
#

@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~ acegikSparkles acegikMeow

#

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

meager pelican
#

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.
blissful atlas
#

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

meager pelican
#

I see. So "twilight" during the editor passes.

blissful atlas
#

(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

meager pelican
#

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

blissful atlas
#

not sure wheeeere I'd output those to be honest, I'd need like, a frame debugger for the scene view~

meager pelican
#

Why not set the outline color to the _ScreenParams values? You say it still always outlines.

blissful atlas
#

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

meager pelican
#

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. ๐Ÿ™‚

blissful atlas
#

yeah, I think I'd have to use some external debugging thing

#

also glad you like my videos~

azure timber
blissful atlas
#

I'll probably just wait until Unity gets back to me

low lichen
#

RenderDoc is great and you can easily debug the scene view with it.

blissful atlas
#

@azure timber what's broken about it?

azure timber
#

@blissful atlas when I tried to mix them, I only got it showing my model as pink.

blissful atlas
#

did you get an error on a specific line?

azure timber
#

nope no errors

blissful atlas
#

that's weird, it should definitely give you an error if it goes pink

#

unless you made a shader that is just pink acegikMeow

azure timber
#

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.

agile flare
#

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.

blissful atlas
#

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

agile flare
#

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.

blissful atlas
#

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.)

agile flare
#

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?

blissful atlas
#

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

agile flare
#

Yes, I believe it's because I'm using a modified version of the standard unity shader.

blissful atlas
#

ah right wait you're modifying, yes that

agile flare
#

So it also has to compile the variants from the standard unity shader.

blissful atlas
#

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

agile flare
#

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?

blissful atlas
#

oh it's been supported since forever

#

unless we mean different things by dynamic branching

agile flare
#

I might be thinking of loops with dynamic iteration counts.

blissful atlas
#

I'm talking about a literal

if( clippingPlanes > 0 ) { do first clip }
if( clippingPlanes > 1 ) { do second clip }
if( clippingPlanes > 2 ) { do third clip }```
agile flare
#

Alright, I'll take a look at doing that. Thanks.

blissful atlas
#

yeah! no worries~

#

that'll be $80

agile flare
blissful atlas
#

incidentally I've had to do clipping planes too

#

there was 10 of them acegikMeow ๐Ÿ’ฆ

agile flare
#

Sounds like a fun time

blissful atlas
#

@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

low lichen
#

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.

blissful atlas
#

does it have the picking buffer? as in, not just the outline shader itself

low lichen
blissful atlas
#

possibly! how did you find it?

low lichen
#

It's part of the SceneCamera.RenderOutline event

blissful atlas
#

(never used renderdoc before)

#

gotcha, sec

low lichen
blissful atlas
#

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

low lichen
#

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?

blissful atlas
#

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

low lichen
#

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?

blissful atlas
#

yep!

low lichen
#

Unfortunately, it's just forwarded it HandleUtility.Internal_PickClosestGO, which goes to native code

blissful atlas
#

yeah, was about to say

low lichen
#

Is there some documentation about this Tags { "LightMode" = "Picking" }?

blissful atlas
#

n o p e

meager pelican
#

I haven't found crap about it, but my google-fu may not be strong today.

blissful atlas
#

it's incredibly undocumented

#

only managed to do it after getting help from tim cooper

meager pelican
#

MS, she's wondering if the _ScreenParams is set properly during the Picking pass or if it is borked.

blissful atlas
#

(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

meager pelican
#

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.

blissful atlas
#

you'd think yeah

low lichen
#

The picking step is probably done before or after the rendering, since it doesn't really have anything to do with rendering.

blissful atlas
#

yeah

#

well, the picking does use a shader pass

#

so it has to render to some sort of buffer

remote mauve
#

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?

meager pelican
#

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.

blissful atlas
#

@remote mauve pretty much yeah

#

@meager pelican no idea where to even begin doing that in a Unity shader, is it possible even?

remote mauve
#

Thanks, good to have confirmation before committing to a solution.

meager pelican
#

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

blissful atlas
#

ah geez, I never go this low level :c

meager pelican
#

Once you go low-level, you never go back....

blissful atlas
#

haha I'd leave as soon as I could

#

might just wait for aras and tim to respond at this point

meager pelican
#

I've never done it for editor stuff though. Usually you try to avoid the editor mess and use a standalone build.

remote mauve
#

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.

blissful atlas
#

if it's unlit I'd guess it's already performant! but I've barely used URP, so I can't say for sure

meager pelican
#

@remote mauve You should be able to find plenty of vertex-color SG's with a google.

agile flare
#

@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.

blissful atlas
#

@agile flare glad it worked out!

remote mauve
#

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 ๐Ÿ˜„

digital mauve
#

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 ?

dry grotto
#

Precision Problem (maybe you use fixed or half instead of floats) would be my guess.

quartz locust
#

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?

stone sandal
#

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

quartz locust
#

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.

remote mauve
soft harness
#

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

orchid peak
remote mauve
#

Thanks, I'll take a read.

#

I reckon I'll have to write my own shader for this then.

shadow magnet
#

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.

sleek granite
#

return the triangle count from the shader using a uniform/atomic

vast saddle
#

Is there a way of scaling an incoming texture inside the shader graph?

shadow magnet
#

@sleek granite so better make a counter inside the compute shader rather than counting the data inside it ?

#

will try it

regal stag
#

@vast saddle You can scale the UVs used to sample the texture

vast saddle
#

What node would I pass the UVs into to do that?

regal stag
#

Either a Multiply node, or the Tiling And Offset node

vast saddle
#

Awesome! I'll give it a try

#

thank you

warm marsh
#

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); ```
shadow magnet
#

How do you calculate the intensity ?

warm marsh
#

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

shadow magnet
warm marsh
#

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

amber saffron
#

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)

wraith wing
#

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

regal stag
#

(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)

wraith wing
#

(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,

regal stag
#

@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.

valid maple
#

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" ?

regal stag
#

@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

valid maple
#

Oh that's a good idea, thanks !

#

Is there a way I can edit the contents of the "Lighting" panel though ?

regal stag
#

Not sure, it might just be easier to have a MonoBehaviour in the scene to manage it

valid maple
#

Yeah

viral chasm
#

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

blissful atlas
#

@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 acegikSparkles acegikMeow 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

viral chasm
#

This is as basic as I can make it..

#

I checked the texture it does look correct

blissful atlas
#

might want to uncheck preserve specular lighting?

viral chasm
#

I tried same result it just looks black at some angles instead

blissful atlas
#

might want to turn off premultiplied blending too

viral chasm
#

yeah that fixes it

#

weird

serene kiln
#

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?

vocal narwhal
#

I would use a MaterialPropertyBlock to set the value on the renderer. Otherwise you'd have to instance the materials

serene kiln
#
        _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.

vocal narwhal
#

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

serene kiln
#

ah okay, makes sense, big thanks for the help

twilit scaffold
#

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 ๐Ÿ˜‚

quiet osprey
#

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.

grand jolt
#

Can anyone give me any tips on how to make more shiny or realistic looking glass?

uncut karma
#

@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

grand jolt
#

Could anyone care to help give some tips on how to replicate this object's effect in unity?

heavy stirrup
#

does unity support 16 bit per channel texture import format

gilded portal
#

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..

low lichen
#

@gilded portal Sure, you can make URP compatible shaders with Shader Graph.

gilded portal
#

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?

low lichen
#

As I understand it, any shader generated by Shader Graph will be compatible with URP and HDRP no matter what.

gilded portal
#

Yey ! Thanks

weary python
#

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;```
weary python
#

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);
            ```
meager pelican
#

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.

weary python
#

woo! yeah it was a huge facepalm haha

mystic geyser
#

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 :

#

dynamic bathcing is forced disabled in shader

#

primitive model on side for comparison

plucky bone
#

Is the pivot really weird?

mystic geyser
#

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

plucky bone
#

CTRL + ALT + SHIFT + C

#

SHIFT + S is useful as well to set your 3d cursor position

fossil elbow
#

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

digital mauve
#

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 ?

vast saddle
#

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.

regal stag
#

@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.

low lichen
#

@digital mauve Can you show a screenshot of what you want?

#

Or rather, what you have now using DrawMesh

fossil cedar
#

@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

regal stag
#

Yeah, depends if you want to mask all colour channels or just alpha.

vast saddle
#

thanks guys!

digital pond
#

How to pass a float2x2 to a compute shader?

#

I can only find Matrix4x4 in UnityEngine

grand jolt
#

Can anyone here help me with some texture issue of a model?

#

I'm still trying to get it to show properly in-game

dense valley
#

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).

tardy spire
#

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)

low lichen
#

Are you using single pass or single pass instanced?

dense valley
#

@low lichen who is the message for?

low lichen
#

@tardy spire

dense valley
#

ok

tardy spire
#

@low lichen single pass instanced. same issue with single pass and a black screen with multipass

low lichen
#

@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

tardy spire
#

Gave it a download, but it doesn't look like I can use it in play mode ๐Ÿค” is that normal? @low lichen

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.

tardy spire
#

ah i gotcha, thanks

tardy spire
#

@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)

low lichen
#

Could you walk me through the steps of the effect?

lost folio
#

does anyone know how to perform 3d rotations of a 3d procedural texture in shader graph?

#

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

tardy spire
#

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

low lichen
#

There's some specific macros you should be using for sampling screen space textures in a post processing shader.

#

When using Single Pass Instanced

regal stag
lost folio
#

@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?

regal stag
#

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?

lost folio
#

It's set up like this

tardy spire
#

@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

regal stag
#

@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.

low lichen
#

@tardy spire If you remove the stencil bit, does it invert everything properly?

tardy spire
#

interestingly no. well it does in the scene view, but not the game view in play mode

lost folio
#

@regal stag OK I think I understand however how would I use rotate around axis to rotate around 2 axis...?

regal stag
#

@lost folio You would need to use two Rotate About Axis nodes, rotating around one axis and then the other.

lost folio
#

OK thanks I'll give it a go ๐Ÿ‘

low lichen
#

@tardy spire I'm noticing you're not using a Blit in the fullscreen pass. Would a Blit not work in this case?

tardy spire
#

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?

low lichen
#

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

tardy spire
#

@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

low lichen
#

How long did you troubleshoot the Blit depth/stencil issue?

tardy spire
#

a long-ass time - @regal stag can attest to that as he was doing most of the troubleshooting haha

regal stag
#

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.

low lichen
#

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
#

welp, rip me.

#

no answers for me

low lichen
#

@dense valley I would answer it if I knew the answer. Sorry. I'm not sure what you mean by Lightmap texture-type.

dense valley
tardy spire
#

@low lichen are you talking about drawing them again with an override material?

lost folio
#

Sorry I'm very new to shader graph!

regal stag
#

@lost folio You need to specify an axis, e.g. (0,1,0) to rotate around the Y axis.

low lichen
#

@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.

tardy spire
#

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 ๐Ÿ˜ฆ

regal stag
#

@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?

lost folio
#

OK thanks I'll keep on at it

low lichen
#

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.

regal stag
#

Ah actually the default fog colour is mid-grey apparently, so that's probably not it.

low lichen
#

@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?

tardy spire
#

yea i'm writing to the stencil and drawing the occluded part in the same pass

low lichen
#

But still drawing the visual cues twice and then the fullscreen pass, right?

tardy spire
#

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)

low lichen
#

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.

regal stag
#

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.

tardy spire
#

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?

low lichen
#

Did you not have it enabled already?

tardy spire
#

no

#

it had been working without it

low lichen
#

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.

tardy spire
#

@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

low lichen
#

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

tardy spire
#

should i set it back to Instancing directly after drawing the mesh?

low lichen
#

Probably? Unless Unity does it itself regularly.

tardy spire
#

Hmm I tried it and don't see a quad anywhere anymore

low lichen
#

Doing screen space stuff in single pass instanced scares me, which is why I'm recommending a different approach.

tardy spire
#

gotcha. i'm open for whatever, I just couldn't get stencils to work with anything else

#

i can't tell if it's also a fullscreen pass

low lichen
#

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.

tardy spire
#

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

low lichen
#

I'm trying to figure it out myself

#

Seems harder than I expected

tardy spire
#

Yea haha that's been my feeling. Super simple effect but it's been a tough one!

low lichen
#

@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.

tardy spire
#

that's super weird!

low lichen
#

Hmm, post processing seems to be doing that for some reason, it's fine before it kicks in.

tardy spire
#

dithering gone wrong?

low lichen
#

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

tardy spire
#

yea lets do that

low lichen
#

It took some debugging to figure out when exactly the Opaque Texture is ready

#

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.

tardy spire
low lichen
#

Great!

tardy spire
#

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

low lichen
#

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.

tardy spire
#

Gotcha, well thanks a bunch for your help I really appreciate it!

low lichen
#

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.

regal niche
#

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

grand jolt
#

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?

gleaming moss
#

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)

grand jolt
#

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

amber saffron
#

@regal niche you need two materials, one per object

tall chasm
#

Is there a way to get the top face of a cube with shader?

regal stag
#

@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).

tall chasm
#

Which means, using that I can also find all the other sides of the cube?

shadow magnet
#

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*

tall chasm
#

I'm not planning on using any textures

regal stag
#

Is there a particular reason you need to get each face of a cube?

tall chasm
#

@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

regal stag
#

In that case you could just use the Position.y to colour the cube, you don't need to get specific faces

shadow magnet
#

you can even specify the color inside the vertex shader

tall chasm
#

Hang on let me find some examples

shadow magnet
tall chasm
#

I'd like to make those edges style

shadow magnet
#

you want hard transition or gradiant ?

tall chasm
#

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

regal stag
#

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.

tall chasm
#

Hang on let me show mine

regal stag
#

For the example you posted, they probably just use textures.

tall chasm
#

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?

regal stag
#

I mean, you are using UVs and a texture in that graph for the grass texture

tall chasm
regal stag
#

Most likely a texture

tall chasm
#

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?

regal stag
#

It's okay, they aren't that silly

#

It looks flat/unlit to me

tall chasm
#

Hmm ok. Alright I'll play around with texturing

#

Thanks!

gleaming moss
#

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

dense valley
#

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```
grand jolt
#

@dense valley uhh _MainTexPan ?

dense valley
#

Panning

grand jolt
#

Read the line

dense valley
#

Is it because of how I named it?

grand jolt
#

Of course it won't appear if you use Hide

dense valley
#

Its supposed to show underneath the texture offset and tiling options

regal stag
#

[HideInInspector] will do exactly that, hide it from the inspector.

grand jolt
#

... remove [HideInInspector]

#

is this a joke question lol

#

?

dense valley
#

no