#archived-shaders

1 messages ยท Page 157 of 1

swift fiber
#

T-T thanks so much

knotty juniper
#

no problem glad to help

swift fiber
#

i can apply this to a circle "quad" too right?

knotty juniper
#

its based on UV

#

so everything that has a workable uv shoud work

swift fiber
#

ah ok nice

knotty juniper
#

you can change it to use world space or object space if that more fitting for your usecase

swift fiber
#

aight thanks for the help alot ^^

#

need to do more reading into this stuff

#

gl on ur work ^^

knotty juniper
#

The good thing is that you never stop learning about new cool stuff.

lavish sierra
#

"cool"

#

If you like pulling your hair out :)

swift fiber
#

xD

knotty juniper
#

@swift fiber add Time to the distance value , for the speed you can multibly the time value before adding it

#

or you can expose a value that you can animate or change by scirpt if you need maunal controll

swift fiber
#

ay nice it works

#

i put it into a vector 1

honest bison
#

I am having an issue where I want to apply the shadow and AO of the baked lighting, but discard the GI information, is that possible?

coarse sage
devout quarry
#

Does the texture have an alpha value?

#

Try getting the A output and see what that gives

bitter forge
#

Don't know if this is the right place to ask this. I'm looking for a few sims style shaders and just wondering if they exist (open or asset store).

  • boolean mesh cut-out's (for windows in walls)
  • invisible objects (for viewing rooms)
remote osprey
#

Howdy Unity friends! I'm working on this fire shader for my game, and I'm trying to get an outline of the image. Usually I just do this by performing a Step operation to get increase the scale of the art, then subtract A from B, which leaves me with an outline. HOWEVER - in the case of the shader I show here - the Step function in the area I have circled in red - no matter what I make the value, it doesn't change the pixels whatsoever. Only if I set it to 0 (all black) or 1 (all white) does it change at all. Can anyone notice something I'm doing wrong here to prevent me from being able to get the outline?

regal stag
#

@remote osprey You can't really Step a value that's already been put through a step node. The step node relies on multiple values, like a gradient, and returns 0 or 1 based on whether it's smaller or larger than the edge value. After you've got a value of 0 or 1, a step with 0.26 isn't going to change anything, as 0 is smaller and 1 is larger - the only difference being your In and edge inputs are switched, so the black/white output is switched around.

#

You could also use UV->Split->G to achieve a similar gradient to avoid the texture samples.

remote osprey
#

AH... okay. That does make sense.

#

Thanks I'll have to try that! I was having some issues getting a procedural gradient to work right so I said SCREW IT and went texture lmao. I'd rather do it with code though.

silk wharf
#

hello!

remote osprey
#

So based on what I have here, can you think of a way that I could still achieve an outline? Or would I need to kill off the first Step node for that to happen?

#

Howdy hey

silk wharf
#

is there a way to use raymarching in shadergraph?

#

I tried used custom functions and 3d textures

#

I cant get the 3d textures to work

#

Im trying to make volumetric clouds using raymarching, but since I have not achieved that no matter what I try, I used stacked noises in a mesh, however it kills perfomance as long as you increase the stack size

regal stag
#

@remote osprey I think you want to do two steps and subtract them, similar to this :

remote osprey
#

Giving that direction a try, thank you @regal stag !

atomic glade
#

I've got some shaders built in Shader Graph using URP, and I'm getting pink shaders for some of them in the built executable, but they seem to work just fine in the editor. Is this a common thing with a simple workaround I should know about or is there something much bigger here I need to work on?

silk wharf
#

@atomic glade which plattform are you building to?

atomic glade
#

On Windows, building for Windows

silk wharf
#

Hmmm have you enabled the experimental shader preprocessor in the editor?

atomic glade
#

I'm not sure. Where could I check that?

silk wharf
#

in project settings - editor

remote osprey
#

@regal stag Worked perfectly. Thanks mate!!

atomic glade
#

I don't see anything that looks like experimental shader stuff

honest bison
#

I would like to apply unity's lightmap in a different way. Is this done within the lighting function?

remote osprey
meager pelican
#

How can i turn this green leaf completely to white ?
@coarse sage

With grey scale tones or not?
If not, multiply the apha x white color. You'll get a white mask. Or if there's no alpha, you can use the any node on the .RGB assuming the black is all 0 (exactly 0).
If you want the greyscale values, you'll either have to do some math, or just multiply white by the green color component. The math for luminescence is in UnityCG.cginc in their source, but basically they set a vector depending on what colorspace you're in
#define unity_ColorSpaceLuminance half4(0.22, 0.707, 0.071, 0.0) // Legacy: alpha is set to 0.0 to specify gamma mode
or
#define unity_ColorSpaceLuminance half4(0.0396819152, 0.458021790, 0.00609653955, 1.0) // Legacy: alpha is set to 1.0 to specify linear mode
and then they do

// Converts color to luminance (grayscale)
inline half Luminance(half3 rgb)
{
    return dot(rgb, unity_ColorSpaceLuminance.rgb);
}```
#

I thought SG had a luminance node, but I didn't see it...

#

But it's just a dot-product node anyway, feeding in one of those two values and your color.

meager pelican
#

You can then swizzle it .xxx to get a greyscale/grayscale.

Come to think of it, you might be better off just converting it to "black and white" in a graphics program if you want grayscale, and then multiply it by green or whatever color to get a colorized leaf.

amber saffron
#

@silk wharf Using a custom function node, you should totally be able to do raymarching in a 3D texture. What was your issue there ?

safe tide
#

Does anyone know how the values in _CameraDepthTexture are computed? I need to replicate the computation of the depth texture. All resources I can find only talk about how to use the depth texture for custom effects but not how it is actually computed.

sacred yew
#

idk im sorry drummerb

#

doers anybody know how bad for file size or build time it is to have unused shaders in a project?

amber saffron
#

unused shaders are stripped out when building. Might still loose some time to be filtered.

sacred yew
#

ah understood

#

I need to figure out why my builds are like 3gb

amber saffron
#

@safe tide What do you mean ? The depth texture is rendered from the objects.

safe tide
#

@amber saffron I want to render the depth of a mesh into a render texture

amber saffron
#

An easy thing to do then is to write a quick unlit shader that outputs depth, and apply it to your object when rendering to the RT

safe tide
#

@amber saffron

An easy thing to do then is to write a quick unlit shader that outputs depth
that's exactly what I'm trying to do ๐Ÿ˜„ but I'm having trouble figuring out what to output in the frag shader

#

there is an example in the docs, but it seems to be out dated, as the UNITY_OUTPUT_DEPTH macro it uses just resolves to return 0

low lichen
#

@safe tide Is this for URP? HDRP? Built-in?

safe tide
#

@low lichen built-in

low lichen
#

@safe tide This is the shadowcaster pass that most Unity shaders fallback to

Pass
{
    Name "ShadowCaster"
    Tags { "LightMode" = "ShadowCaster" }

    ZWrite On ZTest LEqual Cull Off

    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #pragma target 2.0
    #pragma multi_compile_shadowcaster
    #include "UnityCG.cginc"

    struct v2f {
        V2F_SHADOW_CASTER;
        UNITY_VERTEX_OUTPUT_STEREO
    };

    v2f vert( appdata_base v )
    {
        v2f o;
        UNITY_SETUP_INSTANCE_ID(v);
        UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
        TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
        return o;
    }

    float4 frag( v2f i ) : SV_Target
    {
        SHADOW_CASTER_FRAGMENT(i)
    }
    ENDCG
}
safe tide
#

@low lichen thanks a lot for your example! I tried your version from hatebin (actually I had a very similar version also), but for some reason the output is just constant white

low lichen
#

Well, it will only be completely black at the far plane

#

Which could be thousands of units away, depending on how the camera is setup

safe tide
#

ah is this linear depth then?

low lichen
#

The scene camera has a dynamic far plane unless you override it

#

Yeah, this is linear depth

safe tide
#

doesn't the CameraDepthTexture have non-linear depth?

low lichen
#

Hmm, yeah it does

#

Oh actually, it appears to be legacy and does nothing

safe tide
#

yes, but the macro in the frag shader (UNITY_OUTPUT_DEPTH) seems to resolve to return 0

#

I think the depth is rendered implicitly somehow into a native depth texture

#

I'm not sure

low lichen
#

Maybe just do the opposite of Linear01Depth before returning it in the shader?

safe tide
#

@low lichen hmm, almost:

#

left is my shader, right is CameraDepthTexture,

#

ok, I guess this is an OpenGL vs DirectX difference, since with DX11 it looks identical:

low lichen
safe tide
#

oh wow, that's super helpful, thanks

#

I used a different repo, but that only went back to 2017

#

now it looks identical on OpenGL as well, I think

low lichen
#

Does the left side look a little darker on the closest corner or is that just me?

safe tide
#

hmm

regal stag
#

They look the same to me

safe tide
#

I think they are the same, when I enable the Frame Debugger and toggle back and forth between the depth texture and mine, I can't see a difference

#

I had to remove the 1-depth and added the inverse of the Linear01Depth function as you suggested:

fixed4 frag (v2f i) : SV_Target
{
    float depth = clamp(i.depth, 0.0, 1.0);
    depth = (1 / depth - _ZBufferParams.y) / _ZBufferParams.x;
    return fixed4(depth, 0, 0, 1);
}
#

thanks a lot for your help! @low lichen

low lichen
#

Sure, no problem

young rampart
#

Does anyone know anything about the integration of DXC? There was a pull request in a SRP repo but that repo is gone now

amber saffron
young rampart
#

Ah, cheers

#

Ok, so that's DXC compatibility, is it in some version of unity?

amber saffron
midnight fiber
#

Hi I made this conveyor belt shader but I want to show it only on top. How can I achieve it

amber saffron
#

Simple method : make you own 3D model with 2 materials (top, and the rest). You can even use probuilder for that.
Complex method : filter by normal direction to only show it on the top face.

lavish sierra
#

It's not a complex method for @midnight fiber

#

Already been using shader graph a bunch

midnight fiber
#

haha I was making this shader for 4 hours :/

#

Im new to shaders and I dont even know what that means the complex method

#

id need some eassistance

amber saffron
#

So maybe splitting the mesh into two submeshes with different materials will be better ? ๐Ÿ™‚

midnight fiber
#

I tried the simple method but I have problem. The shader doesnt fit

#

this is the model from blender with two materials like you said

#

why is it so scaled?

regal stag
#

You probably need to check the UVs

midnight fiber
#

what does it mean? everybody keeps talking about UVs. I'm lost

regal stag
#

UVs are coordinates for each vertex that are used to tell what part of the texture to use on the face. The current UVs probably are separated so that each face of the cube uses a different section of the whole texture, when you instead want the top face to use the entire texture.

#

I think if you just select the top face, hit U and "Reset" the uvs it'll do that. (I haven't used blender 2.8 so don't know if the keybinding has changed though)

midnight fiber
#

oh thank you

meager pelican
#

Just map the side's uv's to some black part of the border texture. 1 material, 1 draw call. It looks like it has a black border on the texture.

#

There's a UV editor in blender.

amber saffron
#

I'm a bit shocked now

meager pelican
#

What's "chocked" mean?

amber saffron
#

Sorry, classic french mispell when writing english without paying attention

meager pelican
#

Ah. :)
Why shocked?

amber saffron
#

Writing shaders without knowing about UVs

meager pelican
#

Ah. ๐Ÿ™‚

#

I thought I ticked you off or something. I didn't mean to be contrary to your post, only to help the guy.

amber saffron
#

Sorry if it felt like that. You guys helped him understand and fix his issues, and this is great. But I just couldn't imagin that it was possible to start making shader without knowing what UVs are.

regal stag
#

Shadergraph makes it pretty easy to get into shaders without knowing some of the basics. If you're always working with quads or unity primitive meshes you don't necessarily have to know anything about modelling or uvs.

amber saffron
#

All those graphical tools make it to easy for people ๐Ÿ˜„

regal stag
#

It's kinda similar to people trying to use the Fresnel Effect node to get outlines on flat quads/planes, because the preview of the node looks like a glowing outline around a sphere.

meager pelican
#

Unless it's emissive, and you use blur/bloom.... (if you want glow).

#

:p

midnight fiber
#

I made another part. Its half cylinder and when I apply the shader on it, the shader is sqeezed I tried lots of uv settings I just dont know how it should be

#

could somebody help me understand please

meager pelican
#

Do that same 4 step thing, and the big quad, and then another 4 step thing. On the mesh.
Then assign the UV's accordingly, to make from 0% TO 100% through the texture.

#

So all one mesh.

midnight fiber
#

sorry but what 4 step thing

#

I quite dont understand ๐Ÿ˜ฆ

meager pelican
#

The first "box" might be from 0 to .1 in the Y uv. The next box from .1 to .2, then .2 to .3. then .3 to .6, then .6 to .7, .7 to .8 and then .9 to 1.0

low lichen
#

Imagine the texture is the background of that grey box in blender. You've spread out the 4 strips across the whole texture

midnight fiber
#

so make squares out if it?

low lichen
#

Horizontally, that is what you want

meager pelican
#

Mentally unwrap the WHOLE belt. 4 boxes, big square, 4 more boxes (and also sides).

low lichen
#

But you don't want it to stretch out the whole texture vertically

regal stag
#

If it helps, you could actually assign a texture in blender to see what it'll look like

midnight fiber
meager pelican
#

IDK if he's horizontal or vertical.

midnight fiber
#

the shader goes from top to bottom

regal stag
#

I think it was vertical

meager pelican
#

No, that's just one part. Do the WHOLE belt as one mesh.

#

Duplicate that, and put the other "box" in the middle. And merge them all.

midnight fiber
#

but I dont know how to make one mesh out of the whole belt

meager pelican
#

There's only so much I can do for ya on a discord.

midnight fiber
#

I know

meager pelican
#

Maybe someone else will walk you through blender, but barring that, you'll have to google some tutorials. I can tell you what you want (one way, anyway).

midnight fiber
#

I select the 4 faces then what

#

ok :/ thank you tho

meager pelican
#

I'm trying to help you understand, conceptually.

midnight fiber
#

maybe if you draw xd

meager pelican
#

Sec, I'll make you a graphic.

midnight fiber
#

thank you

#

nothing fancy just a sketch will do

meager pelican
#

So that "box" on the bottom of the mesh might map to 0,0 in the lower left, to (1, .1) in its upper right corner. Etc.

#

As you scroll the texture, it will just "wrap around" the mesh. including the rounded ends.

midnight fiber
#

but what is the big square in the middle

meager pelican
#

What you called "the top". The 3 boxes on the top are the front side, and the three on the bottom are the "back" side. The sides of the mesh are omitted, but you can map those to some black border on the texture. Like (0, 0.001) thru (.001, .002). Who cares? It's all black.

midnight fiber
#

and what do you mean by front side and back side when its only half cylinder + it has only 4 sides not 6

#

I appreciate your help but you cant explain this to me I will work with what I have thank you sorry for your time

#

this is some hard thingie I just dont see it

meager pelican
#

OK 4 curves, I only drew 3.

Doesn't matter. Same concept.
curve, curve, curve, curve, long flat part, curve, curve, curve, curve. All one mesh.

#

So it looks like a scroll ish thing.

midnight fiber
#

is that it? the back?

meager pelican
#

I know. Add it. And another curved part on the other side. ONE MESH.

midnight fiber
#

so make cylinder?

meager pelican
#

Start with 1/2 cylinder like you just showed. Add a face on the top edge. Stretch it to be the "long top". Then add another 1/2 cylinder on the other side.

#

Add sides.

#

Then UV unwrap it, and fix it all up.

#

You might want to go close off the bottom too. For fun. No open mesh.

#

And look up "recalculate normals" too when you get a chance.

midnight fiber
#

"Add a face on the top edge" what top edge ๐Ÿคฆโ€โ™‚๏ธ

#

so its closed from right side?

meager pelican
#

sec

#

Maybe start with a box, then stretch it out to be a flat box, and then subdivide the ends.

#

round them off

midnight fiber
#

lol yes but this edge is another part its not part of the middle piece

meager pelican
#

Make it part of it. ONE MESH.

midnight fiber
meager pelican
#

That's the easiest way, and fastest too. Otherwise you're going to run into problems syncing the meshes's uv mappings as you animate this.

#

Yes.

midnight fiber
meager pelican
#

Yes!

#

No

midnight fiber
#

I did it like this tho

meager pelican
#

The top one.

#

lol

midnight fiber
#

what top one

meager pelican
#

Sure. Is that UV mapping window?

midnight fiber
#

yes

meager pelican
#

Or the mesh?

midnight fiber
#

UV editor its called

#

using it for the first time today

meager pelican
#

You need four more of those "box things" on bottom.

midnight fiber
#

why?

meager pelican
#

for the back side curve.

#

both ends are curved.

midnight fiber
#

ohyeah it doesnt fit

#

from bottom

#

but how do I get them the "box things" I cant just dupe them in uv editor

meager pelican
#

The "boxes" are the MESH. In the MESH EDITOR. The verts and faces and stuff.

midnight fiber
#

ok ill make it one mesh

meager pelican
#

I've heard that somewhere before.

regal stag
#

I don't think they have two curved parts yet

#

But you'll likely want to curve the other end next and will have to do the same thing to get the uvs connecting properly.

midnight fiber
#

how do I merge two vertices

#

nvm got it I recalled

#

why in such weird shapes

#

I have 2 squares and 6 rectangles and on the UV they show up as these "triangles"

lavish sierra
#

I really think that would be easier for you

midnight fiber
#

thanks

lavish sierra
#

And if it isn't easier then you only lost 10 mins

midnight fiber
#

well it doesnt help with the UVs but its useful and easy, I will use this for something else though

polar relic
#

In Shadergraph, why does the UI prevent me from linking some specific output sometimes ?
How do I force it to accept any float3 source into Vertex position ?

devout quarry
#

You can't force some things

#

I think its blocks you when you want to mix vertex/fragment stuff

#

what are you trying to do?

#

like a sample texture node into vertex position?

polar relic
#

Trying to make a basic PSX shader, and one of the step require a Posterize node. Even when re-converting it into object space afterward it refuse to accept the modified coordinates.

regal stag
#

I think in some older versions of shadergraph I've had to take the inputs out of the fragment stages to connect something to the vertex stage, then reconnect them. But there are certain nodes that also just locked to a fragment only and can't be used in vertex inputs (like the Sample Texture node as Alexander mentioned - you have to use a Sample Texture LOD node instead).

polar relic
#

Found the exact culprit, it's the "Scene Depth" a bit above in the calculation chain.
... what do I need to do then ?

regal stag
#

Figure out a way to do the shader without the scene depth?

polar relic
#

_<

regal stag
#

How are you using it currently?

polar relic
carmine iron
#

Hello. I've just begun dipping my toes into Shader Graph. I love it. I created a vertex displacement effect for a character and everything is great, but I would like to use a 2dTexture to mask the vertex displacement off the hands and other areas that are getting too much influence. I've tried this setup and it won't plug into the vertex position slot. Please let me know if there is a better way to approach the problem, thank you!

polar relic
#

Welcome to the club ๐Ÿ˜„

regal stag
#

@polar relic Right but that thread isn't using the scene depth, they have a subgraph which they've also shared.

#

I'd probably use the view space position instead of world - camera though.. and just use .z instead of adding all the xyz components up.

#

@carmine iron You need to use a Sample Texture 2D LOD node instead

carmine iron
#

@regal stag Ok, thank you. I'll look into that!

devout quarry
#

Yeah I tried to use scene depth + vertex manipulation before but didn't work

#

which makes sense

carmine iron
#

Well that definitely allows me to make the connection in shader graph, and it mostly works how I expect, but now the verts in my 'masked' area seem to go to object space 0~, instead of just not being displaced. Close! Thanks though @regal stag

regal stag
#

@carmine iron You are probably multiplying, so everything goes to 0 if the texture result is 0. Instead you'll want to only multiply the offset part, or take one of the R/G/B/A outputs into the T of a Lerp, have the A as the Position node (object space) for the regular position, and B as the offset position.

carmine iron
#

@regal stag Thanks, I'll look into that! It does make sense why the 'error' is occurring now

#

I guess I get it. I need to introduce my meshes regular vertex state into the shader too

#

@regal stag Just got it working. Exactly how I expect, thanks!

remote osprey
#

Further progress on that fire shader from yesterday.

#

In a very 'This Is Fine' setup.

grizzled prairie
#

Been having some trouble with a couple of my URP Shader Graph shaders. If anyone could tell me what I'm doing wrong, I'd appreciate it a lot! So in essence I made a simple rimlight shader which I used for a handful of custom Materials where I change the colors in the inspector. In the end I export the Shader, Materials and import them into a new URP project. When I check out the custom colored Materials, their colors and intensity levels are back to the defaults set in the Shader Graph. What am I doing wrong?

regal stag
#

@grizzled prairie This might be due to the property References in the shadergraph blackboard not being changed from their default values. I think the generated ones can change, so you should set them to something more readable/useful.

#

e.g. Instead of Vector1_D23434D2 or whatever, set it to _FresnelSize.

lavish sierra
#

I think what @grizzled prairie is saying is that they want the inspector-set values to remain

#

these values should be in the materials, but in case they were using instanced materials, they'd need to save it in a scene or a prefab or something to keep the values

regal stag
#

I think they are just copying the materials into a different project and losing that inspector data because the references have changed

grizzled prairie
#

@lavish sierra Yeah, I'm saving multiple color variations which just went back to the light blue and blue color in the shader

silk wharf
#

@amber saffron I tried using raymarching with a custom function, however im not sure what I need to put inside the function, I used a for, for the steps thing, but idk what to do with the 3D texture in the function

lavish sierra
#

@regal stag where is this data stored in the first place?

#

it seems unlikely that the references could change relative to the stored data, but maybe the .meta files got left behind or something

regal stag
#

The inspector data is stored in the .mat file.
e.g. m_Floats:
- Vector1_67EBD77D: 0.2

#

But I don't think the shadergraph saves the Vector1_67EBD77D

grizzled prairie
#

I could try changing those values and exporting again

regal stag
#

Oh or maybe it does, "m_DefaultReferenceName": "Vector1_67EBD77D"

#

I'm sure I've had it change when moving the file between projects too though.

#

Hmm maybe that happened on really old versions, either that or I'm going mad. I'm not sure why else they would reset to default values.

sonic plinth
regal stag
#

You'd usually use a Branch node with a boolean, which outputs a value based on whether the boolean is True or False.

grizzled prairie
sonic plinth
#

That works surprisingly well, Thank you!

regal stag
#

@grizzled prairie Oh wow. I guess there's not much you can do, you'll probably just have to recreate the materials.

grizzled prairie
#

Seems like they're read only in the inspector in that version

regal stag
#

And yeah, I looked over some old shadergraph files and they don't include the m_DefaultReferenceName like newer ones do, so those references change. Good to know they won't change with newer versions though.

grizzled prairie
#

Could change them in debug mode, but I guess things could potentially mess up. I only have one source project to gamble with though, since I can't export them safely

regal stag
#

I'd probably just recreate the materials, at least there's only 3 values per material.

grizzled prairie
#

Yeah, I might have to do that, though I wasn't looking forward to it ๐Ÿ˜„

#

Thanks for the help, I'll try to change the References and see if it sticks

amber saffron
#

@silk wharf The usual thing for doing clouds is to march through the volume, and sample the 3D texture that is a "density texture", to accumulate the cloud color at each step, depending on the density.

silk wharf
#

@amber saffron is there any documentation about acomulating the code from the 3D texture?

amber saffron
#

Clouds are lovely and fluffy and rather difficult to make.
In this video I attempt to create clouds from code in the Unity game engine.

Project source (Unity, HLSL, C#) is now out of early access:
https://github.com/SebLague/Clouds
If you'd like to support the creation of mor...

โ–ถ Play video
devout quarry
#

from the unity god himself

#

Sebastian is truly in another l(e)ague

silk wharf
#

@amber saffron I already saw it, I converted most of his written code to shader graph, the only thing that I dont understand, is how can I accomulate the color from the volume

#

I used his sampleDensity function but didnt show any results in my shadergraph

amber saffron
#

It's all explained in the video. The color is the result of sampling multiple times in the volume, from the view direction and then toward the light. And if the maximum density is not met, you then redo the operation a bit further and add the result, etc etc

sonic plinth
lavish sierra
#

@grizzled prairie personally I'd just save everything in a scene and export using the export package

grizzled prairie
#

I could give that a try too

silk wharf
#

@amber saffron okay, im going to try again

#

@sonic plinth Wut.. I didnt notice lol, thanks you!

sonic plinth
#

He usually has them in the description :P though his patreons get them before others.

silk wharf
#

Ahhh I seee, I discoverd his channel a month ago, and I didnt noticed that his code was open source

sonic plinth
#

Mhm! I think he usually makes them public like one or two weeks after the video is uploaded.

#

Though again his patreons get them immediately

silk wharf
#

Ohh I see

devout quarry
#

@silk wharf would love to see the clouds you get!

silk wharf
#

I will post the results once I got it working!

#

perfomance killer btw

devout quarry
#

I can imagine

silk wharf
#

I saw something about graphics.draw mesh, but HDRP doesnt seem to work with it

devout quarry
#

but isn't clouds something you can 'prebake'?

#

and then just mask with noise

silk wharf
#

wdym?

devout quarry
#

I'm not sure how this technique works but to me a cloud systems seems like something where you could do a lot of calculations beforehand (so not on runtime), if you are ready to give up some 'dynamicness'

#

this is a cool technique

silk wharf
#

Ohhh I see, sounds interesting

#

but isnt signed distance functions the same as raymarching?

devout quarry
#

I have 0% experience with clouds btw haha

silk wharf
#

same, Im pretty new at it, but I really want to improve what I have achieved

devout quarry
#

and yeah but he talks about 'premarching'

silk wharf
#

Oh I see, I will read it

slow bear
#

Another channel, same question: I'm trying to dither objects as they get within a certain range from the main camera; I know this is easily done on a per-material basis, but I wanted to develop a solution that would allow me to dither any object that gets too close to the camera without setting a ditherable material for that specific object

#

I looked on CommandBuffers and PostProcessing, as I used them in the past for highlighting/outlining any object tagged with a specific component, but that's only useful when you have to overlay stuff on the final render

#

Then I looked at SRPs, and thought I could do my custom one that does it automatically as one of the pipeline passes

#

Am I over-engineering this?

devout quarry
#

Don't make your own SRP for this is my guess

#

You can indeed achieve this with what you said

#

So by customizing URP

#

And use renderinglayermask (not layermask) as your layer system

#

I'm not sure on the exact implementation, but fairly sure that making your own SRP is overkill

meager pelican
#

I'm not sure how this technique works but to me a cloud systems seems like something where you could do a lot of calculations beforehand (so not on runtime), if you are ready to give up some 'dynamicness'
@devout quarry
Would depend. If the clouds are moving, or the light source is moving, then it's pretty hard to pre-bake. Would have to be something similar to realtime-GI precomputed from multiple angles or something. I haven't seen that done.

There are some good, and pretty inexpensive, assets for good clouds on the asset store. I played with them, but eventually decided to let someone that put man-years into it maintain it for 40 bucks one time charge. ๐Ÿ˜‰

silk wharf
#

@slow bear use a custom pass with your dither shader

#

@meager pelican the thing is, I dont want to download any kind of assets, im doing everything by myself in my project, and also, my project is in HDRP, so written shaders wont work

slow bear
#

@silk wharf I don't want to do it on a per-material basis, I wanted a general system that applies the same behavior (dithering when too close) on each object, regardless of their material

#

@devout quarry I'll have a look at URP, even though I kinda want to keep it away for now

silk wharf
#

@slow bear custom pass replaces your materials in view with the material you want

#

instead of setting up them manually

meager pelican
#

@slow bear The data won't be there. It will be overwritten in the color buffer. You'll need ALL of your materials to be dither-effect aware. Or check before rendering them, and move them to a different layer or something, that you can screw with later in post.

#

Or like storm said, replace the mat. But if you're doing that, you might as well make all your mats dither aware.

slow bear
#

@silk wharf that's still an issue, consider a situation in which two different materials, with two different lighting models, are too close to the near clip plane: the replacement material will still need info about the texture and the lighting model

#

But if you're doing that, you might as well make all your mats dither aware.
@meager pelican exactly, that's my issue with replacements

silk wharf
#

Ahhh

meager pelican
#

How complicated are your material needs?

Start with a stock-material, maybe similar to a standard-lit material.
Then add dither.
Then build all of them from there.

Note I didn't say "just" start. ๐Ÿ˜‰ But it's doable.

silk wharf
#

maybe use a branch for them? set a bool inside your graph

#

and set it true or false if objects are in view

lavish sierra
#

seems like you could generate a grayscale "color" texture and apply dithering without content awareness and then blend this texture with the standard color texture

#

if you did that you'd need a custom pipeline feature and one material that can do the dithering during blit

#

however, you'd get the exact same dithering effect regardless of what the item is

meager pelican
#

There's no way to dither later, as you've lost the underlying pixel that was overwritten. At least that I know of. Unless you can separate out not-dithered and dithered.

lavish sierra
#

you'll need 2 features too, one to generate the custom texture and one to do the post processing

#

you haven't lost the underlying pixel, what are you talking about?

meager pelican
#

It was either overwritten, or not written (depth test fail). So you can't make it "transparent" later and show what was behind it. Because it's not "there".

lavish sierra
#

what the user (camera) sees and what you render to any texture behind the scenes never has to be the same thing

#

ergo, you do not have to lose information

meager pelican
#

Then you're separating things out.

lavish sierra
#

sorry, I don't understand what you mean by that

meager pelican
#

Let's say the rule is "anything within .5 meters of the camera is dithered" OK?
If you don't do it as you draw it, you have to do it later, right?

If you have a blue cube, 1 meter away, and a red ball .4 meters away, the red ball is dithered, and would have to show some of the blue cube. Right?

#

If you're not separating out "those that are not dithered" from "those that are dithered", how do you apply your effect later? Not as you draw the ball?

#

AKA the blue-cube's pixels were overwritten by the red ball's pixels. So you don't know to "show blue" later.

silk wharf
lavish sierra
#

You can put the objects that match your "close to camera" criteria in the transparent pass

meager pelican
#

That's separating them out "by pass".

#

But it won't work if they overlap. You'd still have to swap the materials, unless it's all a screen-space dither of some sort.

lavish sierra
#

I'm talking about a screen space dither, yes

#

you can also use a replacement shader, no?

meager pelican
#

Yeah, you can use a layer too (I said that). But it's still swapping out the mat to get the diter.

#

Sure replacement shader. Not much diff than swapping the mat.

lavish sierra
#

what's the issue with that?

meager pelican
#

If he's going to start doing that, why not just use a custom material that knows about dithering on everything?

silk wharf
#

I still dont understand whats the issue with it

meager pelican
#

"Issue" is probably the wrong notion here.
More like "let's kick it around a bit".

silk wharf
#

Hmm

slow bear
#

@silk wharf basically, I wanted something like "drop any kind of material in the scene, some kind of daemon dithers items for you in the background"

meager pelican
#

swapping mats is more expensive than something already built-aware.

#

lol daemon!

silk wharf
#

Ahhh

#

makes sense

slow bear
#

"dithers items for you when they get too close to you" fix'd

silk wharf
slow bear
#

the daemon being some kind of mechanism that has to be aware of the camera, of the objects and the materials on each one of them

meager pelican
#

The cool thing with screen space dithers, is they avoid overdraw, and you won't have material contexts expiring either.

#

if you do them in the original material.

#

You benefit from early z testing

#

@slow bear You can do it in C# I guess, but IDK how you make it aware of custom materials unless you code it manually as you add them.

mortal vale
#

Hi, I'm coming in here with a question about particle shaders:

So, what I'm trying to do is instead of using a skybox for stars, using particles instead. I already have the particle generation working well, the issue is now the shaders.

It'd be advantageous in this case to have the sphere of stars be very small, only about 10 units across, and parented to the camera. However, I can't find any information about how to make particles render behind everything in a scene but the skybox, so the stars would be in effect rendered at infinite distance. A friend of mine suggested not writing to the z buffer, or to mess around with render order in the shader, but nothing seems to work.

meager pelican
#

I think Aras has a post with a similar far-plane thing. Sec.

mortal vale
#

Thanks

mortal vale
#

oh, I've seen this

meager pelican
#

Well, that answers part of it "infinite distance".

mortal vale
#

I tried the shader, but it's meant for things like cubes, not shaders. If placed on a particle material, the particle system becomes invisible What about a shader makes it a particle shader?

meager pelican
#

Maybe have to subtract a bit of distance so the skybox is "behind" it.

#

"What about a shader that makes it a particle shader"?
Well, it's compatible with the particle system (smart butt answer, sorry). So that means things like vertex colors.

#

You sure you want particles? Or maybe a custom skybox?

lavish sierra
#

also, you can just put the camera in that sphere, no need to have it be humongous (but it'll have to avoid writing Z)

#

it seems like it'll need one or two more tweaks that way though, such as forcing the sphere to render 2nd only to the skybox

mortal vale
#

no, particles i nthis case. At high FOV , star skyboxes become a blurry mess

meager pelican
#

The skybox renders after opaque, before transparent. You can render "AfterSkybox".

#

Ah. FOV

mortal vale
#

ah ok. Would it be better to set render order in a script, or as part of thee shader

meager pelican
#

So the way the skybox knows not to overwrite your cute particle stars, is that you DO write a depth.

#

what pipeline are you using?

#

Unless you write them after the skybox.

mortal vale
#

well, this is actually for modifiying Kerbal Space Program, so it appears to be the scriptable pipeline

#

but ok, that gives me a few leads

#

thanks

meager pelican
#

You can select a render queue somehow.

#

I remember settings somewhere, IIRC.

#

But doing in the shader is fine, IMO.

mortal vale
#

ok

meager pelican
#

Unity will sort out the render queues. That's what it's there for. ๐Ÿ˜‰

dim sequoia
rich flume
#

Hi, I am making a shadergraph for my terrain and I am unfortunately limited to 16 textures which is not enough. Anyone have a solution ?

regal stag
#

@dim sequoia mul is for matrix multiplication : https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-mul

If the first input is a vector it treats it as a row-vector while in the second input it treats it as a column vector. Usually you'd use it with a matrix as one of the inputs, but if both are vectors, it results in a scalar (single value) output due to how matrix multiplication works - and if I'm not mistaken, it's equal to the Dot Product.

Multiplying with the * operator instead, just multiplies each component individually.

dim sequoia
#

ah, thank you a lot! that would explain it.
actually I missed that, because I first thought I read: vector + vector results into vector too, but checking the documentation again, it really returns a scalar value:

meager pelican
rich flume
#

Good idea, I am gonna to test with that node. Thank you

autumn adder
#

Hi guys! I have returned to Built-in from URP and now I get a weird issue sometimes with pink material and "unity internal shader error" any idea why? I would appreciate any help or suggestions

desert orbit
#

Use default shaders on materials with default pipeline.

autumn adder
#

oddly enough this issue appears on custom shaders

#

๐Ÿ˜ฆ

#

when such objects are spawned in play mode (example It would spawn 2 identical characters, one would look perfect with correct shaders, the pther will have "unity internal shader error" and be pink)

fair sleet
#

I have a set of points and I need to make a 2d unlit shader graph that sets the alpha of all pixels near those points to 0.
How would I do this?
Should I generate a texture using a monobehaviour and send it to the GPU or is there a better way?

meager pelican
#

Do they move, or can it all be "baked in"?

fair sleet
#

they move, no baking sadly

meager pelican
#

Then you need some sort of data structure that can hold your "points" and compute per pixel alpha? The thing is, last I knew, you can't bind a compute buffer to Shader Graph yet, but you can with the manually edited shaders.

But as you observed, you CAN bind textures.

Maybe someone else has more info.

grand jolt
#

anyone know how to make a shader that make it look like there is glue splattert all over an object?

slow bear
#

@fair sleet you can feed an array of Vector3 to a shader as a uniform; your problem sounds like a Voronoi effect / Delaunay triangulation thing

fair sleet
#

can I use a shader graph to do that?

#

and yes it's similar to the Voronoi thingy

lavish sierra
#

I'd just use a custom node that uses an array of vectors (which can be set as a property, or a shader global)

#

And just output a value for alpha from that node

fair sleet
#

interesting idea

#

do you need to code the node in c#?

devout quarry
#

custom function nodes use hlsl, no c#

meager pelican
#

But the setfloatarray thing is in C# (or the texture). Whatever.

#

Arrays in shaders are fixed length though, so watch for that, or pass another float for "how many points"

#

Or zero pad

urban pendant
#

Heyo, does anyone know if there's a way to setup Unity to open .shader files using a specific code editor instead of the default one?

lavish sierra
#

I believe you can select "by extension" in the editor dropdown

#

"The Open by file extension option uses your deviceโ€™s default application for the relevant file type when you open a file. If no default application is available, your device opens a window that prompts you to choose an application to use to open the file."

remote osprey
#

Got another shader question I'm a little stuck on, and maybe you all can help. So in the above graph image, the alpha from the top texture and the bottom texture properly subtract in the Subtract node. However, when applied as the Alpha on the Combine after the Split - it isn't there! But, the exact same Alpha from the Subtract node applied to the Alpha of the result clearly works.

Shouldn't the Combine show the same alpha result?

knotty juniper
#

i dont think that the combine node shows the alpha values suppied to it but will still output them via the connection.
The substract node can show it because it only show the one channel

remote osprey
#

@knotty juniper Does that mean a Preview node placed after the Combine node should show the alpha then...?

knotty juniper
#

no, the 4. chanel does not get displayd if you are trying to previw a vector 4

remote osprey
#

Ahhhh okay

knotty juniper
#

the vector 4 you got there can be use for clour and alpha values , but does not have to so it does not make sense to represent it that way

remote osprey
#

AH. Yes you're right. I just tried doing a Split of the Combine and passing the Alpha of that into the Alpha of the final result, and sure enough - it shows!

#

Thanks @knotty juniper ๐Ÿ™‚

knotty juniper
#

glad to help

lavish sierra
#

@remote osprey I'm no expert but it looks like you don't need so many splits and combines

remote osprey
#

I'm trying to mask out where the two images overlap, color that overlap area, then add the colored part back to the image.

lavish sierra
#

if you look at the output of the sample texture 2D, it already gives you R,G,B as split components

#

but you took the RGBA instead and put it into split to get RGB

#

similarly, you don't need to combine the alpha, since you're passing the alpha directly into the master node anyway

#

if you hooked up the RGBA directly to the master node RGB and got rid of your split and combine nodes, you'd have the same result

#

but maybe you can't hook a vector4 into the vector3, though I'd be surprised

remote osprey
#

This was just an example shader, one sec I can show you more of where I'm really trying...

#

So the idea here is that the bottom image is a render texture of what you cannot place something int he environment. The top image is a render texture of what we are placing.

#

If the top image overlaps on the lower image, I want to render just that overlapped section with a different visual effect.

#

So I am trying to make a shader that fetches that area where the 2 overlaps, then gets just that chunk of the top image, applies a modification to it, then (NOT SHOWN HERE OR DONE YET) merges that back into the top image, and then outputs that.

#

(The red color change is placeholder just to get this working. It will be a proper animated effect)

remote osprey
#

Oh. Actually I think I got it lmao

mortal tree
#

Hi Everyone, I have a spritesheet of trees etc, im trying to apply a shake/wind shader with UV Offset noise etc and had a Mask to only shake the top etc.. But the UV is sampling the whole sheet not just the individual sprite. So sprites at the top of the sheet shake a lot and the ones at the bottom dont :P.. How do i clamp the UVs to just the sprite area on the sheet. It is individual game objects so i could get the sprite rect coords from the renderer and feed into the shader but not sure what to do with it. I was going to look into flipbook but my sprites on the sheet are different sizes, can i use the fed in dimensions to pick the right sprite from the flipbook ?

remote osprey
#

Oh I did this exact thing... I can send you a screenshot of my shader when I'm at my computer @mortal tree

#

Off the top of my head though I THINK you need to pass a Position node into the mask...

mortal tree
#

@remote osprey Thanks il give it a go

remote osprey
#

@mortal tree That's the part of my shader that handles the mask based vertex waving.

#

The output of that group goes to the Vertex Position input of the result node.

quaint coyote
#

I tried to create a Screen Space Ambient Occlusion shader using the techniques crytech did... Here's how it looks:
https://youtu.be/PimjasXIQUw

I tried my hands on learning to create an image effect shader which could calculate Screen Space Ambient Occlusion.
In this video, I am toggling the AO on and off.
Improvements will be still going on. Crits/Comments are most welcome.

โ–ถ Play video
mortal tree
#

@remote osprey Thanks, there is quite a lot there, will take me a bit to break it down and give it a go, you say this is for 2D sprites ?

remote osprey
#

Yup! Sprites in an atlas with a sister l separate mask image

sinful vine
#

when I opened the shader graph, it has a symbol that says "the current pipeline render is not compatible with this master node.

devout quarry
#

are you using urp/hdrp?

#

and have you assigned an active render pipeline asset?

sinful vine
#

RBP something

#

PBR @devout quarry

#

how to assign that

devout quarry
#

?

#

if it says 'the current pipeline is not compatible', that could mean that well, the pipeline you're using is not compatible

#

this is either because you haven't installed the universal render pipeline package through the package manager

#

or

#

you have installed it, but haven't made a pipeline asset and assigned it properly

#

you need to create a pipeline asset, then assign it in the project settings under 'quality' section

#

read this if you're using URP

sinful vine
#

it's installed

#

and I just right clicked, gone to create, shader and PBR

devout quarry
#

yes it's installed, but have you assigned an active pipeline asset?

sinful vine
#

how to do that

devout quarry
#

it's all explained here

#

in the link I shared, read it first, it'll fix your issue probably

sinful vine
#

but I'm using PRB

#

PBR*

devout quarry
#

yes, the PBR (physically based rendering) is your master node

#

but you're either using 'default renderer', 'urp - universal render pipeline' or 'hdrp - high definition render pipeline'

#

the concept of 'PBR' is unrelated to your render pipeline

#

the error you got said 'the current render pipeline is not compatible'

sinful vine
#

man I just thought that this shader thing is useful, I'm new to Unity, so I clicked the official shader guide and this is happening

devout quarry
#

which shader guide?

#

if you want to use shader graph, you need to use either URP or HDRP

#

If you're a beginner and you want to use shader graph, I recommend using URP

#

to get shader graph working with URP, really, read this article

devout quarry
#

really, the guide I linked should help you out

sinful vine
#

Cool, I'll check it out later, today I installed Bolt visual scripting, and made a whole Jump plus W, A, S, D control system and I'm tired.

#

Accept my friend request

devout quarry
#

I'd rather stay in public chat here

sinful vine
#

Cool, I'll mention you ๐Ÿ˜„

devout quarry
#

but really, before asking more questions, give that guide I linked a try

sinful vine
#

Sure

silk sky
#

how can I use a lerp to filter only a certain vertex color?

devout quarry
#

can you be a bit more specific about what you're trying to achieve?

#

do you want a lerp input 0-1 that returns the red vertex channel at value 0, the green vertex channel at value 0.5 and the blue vertex channel at value 1?

silk sky
#

I panted some vertex color (R,G and B) on a 3D model and wanted to use them as 3 different masks

devout quarry
#

ah right

#

in shadergraph I just use the vertex color node

silk sky
#

i know that in some way I should use the lerp node but i'm still having issues to know what put in that node

devout quarry
#

ah right so for example if you take the vertex color node

#

split it so you can access the R/G/B components

silk sky
#

already did

devout quarry
#

then for example you put the R channel into the T slot of the lerp node

silk sky
#

ok and what should I pass in the A and B channel?

devout quarry
#

and then in the 'B' output, you put whatever you want to be shown when the Red channel is painted

#

if T is 0, output is A

silk sky
#

ok

devout quarry
#

if T is 1, out put is B

silk sky
#

so T is like the filter?

devout quarry
#

the node will linearly interpolate between A and B based on T

#

so if T is 0, you have 100% A and 0% B

#

if T is 1, you have 0% A and 100% B

silk sky
#

nad for remerge the 3 channels should I use a combine?

#

or an add?

devout quarry
#

that depends on the effect your are making

#

I mean, the output of the lerp node is either A or B or a mix between A and B

#

I don't know what A and B is in your case

silk sky
#

i just want to give a different solid color

devout quarry
#

right so the output of the lerp node is a vector4

silk sky
#

yes

devout quarry
#

but what do you actually want to do? have 3 colors on your object?

#

that you can paint with the vertex colors?

#

what you could do then is have 3 lerp nodes, use the R/G/B outputs of the vertex color for your T variables

#

then use zero as your A inputs for all 3 lerp nodes

#

and use whatever color you want as your B inputs

#

then add the 3 outputs of the lerp nodes together

silk sky
#

I need to isolate these 3 different color and modify them 1 by 1 individually so I can basically make 3 materilas in 1

devout quarry
#

yes then just use '0' for all your A inputs

#

and add the 3 outputs of the lerp nodes together

silk sky
#

ok

#

0 as empity or just a vector 1 at 0?

devout quarry
#

uhm, I just leave the input at zero

silk sky
#

k

devout quarry
#

zo if your B input is a color (vector4), just leave it at 0 0 0 0

#

leave A at 0 0 0 0 I mean

silk sky
#

its working thanks a lot

devout quarry
#

cool!

lavish sierra
#

Why lerp and not multiply?

open brook
#

I'd like to have a shadergraph that affects what's behind the sprite, so for example my sprite can be a white circle and I'd like it to grayscale the texture behind the circle. I don't want to pass in the texture behind since that can change.

I've tried finding tutorials online but can't find a good one.

Do you know of a good tutorial for this?

atomic glade
#

It feels like there's a million ways to do an outline shader and they're all bad. What's a good way to actually make an outline in Shadergraph?

#

I don't need an entire shader done for me or a link to a tutorial, but even just a general strategy, like, "try using X node with Y node"

open brook
#

@atomic glade if it's 2d there's a nice tutorial

atomic glade
#

Nah, 3D

#

It feels like a common enough effect in games that it should be pretty well documented

#

But it's always got some sort of jank to it

open brook
#

Yeah, it's very complex.. I wish there were more in-depth guides. I feel like even if I completely understand one example tutorial doing something even slightly different is really difficult

devout quarry
#

@atomic glade this might help you?

tidal nova
#

I copied this shader and try to add color support to it, but there is a problem - no matter what I modify in this shader, it still seems to act like the base shader

#

I'm 100% sure that I'm using modified one in mesh renderer

silk sky
#

Guys is possible to make a shader that zoom the camera view? I'm trying to make a scope

tidal nova
#

but even after doing testing like returning fixed4(0, 0, 0, 1) as frag color still behaves like the base shader

#

any idea what might be reason behind that?

#

(changed link to shader above)

devout quarry
#

@silk sky use a secondary camera with an adjusted FOV and make it render to a texture, then use that texture on your scope

tidal nova
#

ok, I already figured out why this happens - bottom section of shader only runs if there are lightmaps, otherwise first simple pass is being executed

keen scaffold
#

Hey peeps! Has anyone found any tutorials on exactly how ShaderGraph translates across to normal shaders? A lot of the time I feel like I'm just experimenting, and I'd like a more solid understanding of what's actually happening with each node. Is it looping through each UV one at a time, or is it per-pixel? The effects seem to just magically happen, which means I don't really understand how to write more specific shaders and lack the knowledge to do so.

#

I've been googling constantly for weeks, but I'm only finding tutorials on specific things, like water shaders, forcefield, glass refraction, etc.

#

I've found the documentation doesn't really explain anything in any detail either. The main thing I'm struggling to understand is world space and UVs. I understand what UVs are and how they work in 3D models, but what do the UV0-4 nodes represent in Shadergraph? It's driving me nuts!

remote mauve
#

Is it possible to render things on top of canvases that are set to "Screen Space - Overlay"?

keen scaffold
#

Cyan, are you THE Cyan? With the really useful SG blogs?

regal stag
#

@keen scaffold Most nodes can be connected to both the vertex and fragment stages of the program. When connected to the "Vertex Position/Tangent/Normal" inputs, they run per-vertex, while other master node inputs like Color/Albedo and Alpha are per-fragment (pixel). Shadergraph actually generates code, so they work exactly the same way as code written shaders - and you can see it if you right-click the master node and click "Show Generated Code". A lot of the nodes also have documentation pages that share snippets of code.

The UV nodes gives access to the meshes uv channels (e.g. Mesh.uv, Mesh.uv2, Mesh.uv3, etc in C#, or saved in the model file). If connected to the vertex stage, it'll be the direct value from that vertex, otherwise it'll be an linear interpolation based on the fragment/pixel position between the three vertices that make up the face.

Similarly the Position node gives access to the vertex position, or interpolated fragment position between the three vertices that makes up the face. When it's set to World space the vertex position from the mesh, which is in object space, get's converted to the world space.

amber saffron
#

@keen scaffold UV0-4 : It's simply that a mesh can hold more than one UV set (up to 8 now)

keen scaffold
#

Thanks for the help peeps ๐Ÿ™‚ I also had no idea that you could view the generated code. That seems invaluable! I'll pour through the actual shaders to get a feel for what's going on

#

So would I be correct in thinking that the shadergraph, once compiled down, would run multiple times per frame for each vertex or fragment (like an update loop)?

regal stag
#

Kinda yeah. The vertex shader stage runs for each vertex in the mesh being rendered, and the fragment for each pixel. (Though some fragments might not become actual pixels due to the alpha clip threshold which can clip/discard them).

keen scaffold
#

Right, that makes sense sorta :p

#

So, I've noticed there's 4 UVs, 0-3

#

Does each represent each corner of the UV square? i.e. Top-left, top-right, bottom-left, bottom-right?

regal stag
#

No, the different UV0-3 are the different UV channels. A mesh can contain up to 8, but shadergraph only allows access to 4 currently, like Remy mentioned.

#

Each UV channel can actually contain up to 4 coordinates/values per channel. For simple texturing only the UV0.xy (or R and G in the split node) are used. Each corner of the UV square would be when UV0.xy is equal to (0,0), (1,0), (0,1) or (1,1).

#

Which you also see in the preview of the node, but as colours. The first number being red, and the second green. Where they overlap it shows as yellow.

vagrant rampart
knotty juniper
#

@vagrant rampart can i question why you would like to blend the aledo texture with a qubmep and then put that into the albedo slot of the shader?

vagrant rampart
#

@knotty juniper I have a real-time generated cubemap (not in unity). I want the "lighting" the 3d model by cubemap.

#

I tried changing the skylight for this, but when the app is running, the lighting on the models doesn't change.

regal stag
#

If I'm not mistaken, this is usually handled by the Environmental Reflections source in the Lighting tab, or reflection probes.

keen scaffold
#

Thanks @regal stag, I kind of understand a tiny bit more.

knotty juniper
#

@vagrant rampart what renderpipline are you using?

vagrant rampart
#

@regal stag Environmental Reflections is only applied to metal materials.

#

@knotty juniper URP

knotty juniper
#

The problem is that via the skybox material the light does not affect the object or you need to update it in realtime?

vagrant rampart
#

@knotty juniper yes,i want affect on model color by realtime cubemap.

thick fulcrum
#

@vagrant rampart is this just a sky cube map or other sources?

knotty juniper
#

The problem is a bit that if you just scree blend the qubemap into your nomal albedo texture , all the PBR mecanism do not work for it and your normal scene light is still applied in the end.
Sadly the URP does not seem to have a way to update the entvirement lighting at runtime

thick fulcrum
#

one would just do a procedural sky instead of a skybox approach, even mobile can handle a few lights.... or am I missing something here (usually I am)

knotty juniper
#

@thick fulcrum the lighting data comes from a extenral source as a updating qubemap
That data should be used to light the objects

thick fulcrum
#

looking at the example screenshot, the cubemap is just a panoramic. which does not have any light data. Surely the question is how you translate that into vectors, color and intensity?
Reflections != light

vagrant rampart
#

@thick fulcrum other source

thick fulcrum
#

well presumably you need to handle it like the reflection probe data, as your data is projected. I did it a while back, some examples should be around net

fair sleet
#

can someone link me the documentation for the urp shader functions?

knotty juniper
atomic glade
#

I have a shader that is behaving differently in editor than it does in a build. It's a metallic transparent shader, and I have a function in game to adjust the multiplier for the transparency so you can make it see-through. Inside the Unity Editor it works fine:

#

Even if I try to turn it back to fully opaque it stays pink

#

I have a float that I am multiplying with the alpha map, by default it is 1, and when you press a key it sets that multiplier to 0.5

#

In URP, using a ShaderGraph

#

Before adjusting that alpha multiplier, it shows up in the build fine, but once it changes, it stays pink forever (even if I put the alpha multiplier back to 1.0)

knotty juniper
#

might be by setting the value unity actualy needs some other variant of the sader.

#

if that variant is not included its not working

#

you can use shader variant collections to make sure that all the variants you used in the editor are incluedin the build

#

Edit -> Project Settings -> Graphics

#

there on the bottum you find a save to asset button

atomic glade
#

It's all the same shader, I just have a different alpha multiplier. Would this still count as a shader variant?

#

Oh, hang on, the base shader itself isn't in the always included

#

That might be it

knotty juniper
#

It's all the same shader, I just have a different alpha multiplier. Would this still count as a shader variant?
@atomic glade unity does a lot of optimiation under the hood so it could generate some more then we would expect

atomic glade
#

I wonder why it even worked at all?

knotty juniper
#

The editor does compile the sahder variants you use on the fly but only what is tracked by assets are included into the build

#

changing stuff via script is not referenced other then the shader variant colletion

atomic glade
#

And it's done! Thank you for that

#

Problem solved by adding the shader to the graphics settings

knotty juniper
#

nice

fair sleet
#

Can someone send me a link to the documentation of urp shader functions?
I can't seem to find anything...

desert orbit
#

It's pinned in this channel ^^

fair sleet
#

is this function not from the urp?

regal stag
#

TransformObjectToHClip is a part of SpaceTransforms.hlsl from the render-pipelines.core/ShaderLibrary

fair sleet
#

thanks

honest bison
#

I would like to apply my lightmap in a custom lighting function. Is there a tutorial or example I can work from? I would like it for the lightmap to not affect GI in any way. I would just like the shadow and AO as a straight multiply. Thank You.

fluid lion
#

how does 'inout' work? i've read forum posts that try to explain it but i still don't quite understand

ancient silo
#

I'm trying to make a vertex displacement ripple for palm tree leaves, how would I make it so I can choose the extremity of the effect as it goes out? So the centre stays still and it becomes more flexible as it goes along.

fervent tinsel
amber saffron
#

@ancient silo This kind of effect is oftently driven by vertex color to weigth the deformation

willow basin
#

Hi, I like shader graph but I dont known how to change the scale texture with a flipbook , I try with tiling and offset but Its doesnt work , Its possible to change scale texture in the shader graph?

amber saffron
#

Well, the tiling/offset node it tipically the one you want to use to change the "scale" of a texture ... maybe you're not using it properly ?

willow basin
#

the problem if I use tiling with flipbook duplicate frames like this

amber saffron
#

Ok, I see

#

For this kind of trick, you will need to mask out the zone where you want your image to be displayed

#

You can easilly get a black and white mask by using the procedural rectangle node

regal stag
grand jolt
#

Can anyone help me? So I add texture to my tree but wan to add snow on top of some leaves , so is there any wayto get snow on leaves but don't lose the texture of the leaves

#

I try shader graph but then my texture map goes away

kind juniper
#

@grand jolt you'd probably want to share your shader graph here.

bitter needle
#

is there any standard way to implement depth fade on opaque objects?

#

can't really do it like on transparent ones

#

I guess I could experiment with signed distance fields, but I'd need to do that from scratch

willow basin
#

I make it, thanks

meager pelican
#

@bitter needle dithering?

#

What does "depth fade" mean to you? Transparency type of fade? Or fading into fog color? Or what?

#

You could blend based on depth, in an opaque queue+1, or separate layer

bitter needle
#

I mean like changing the colour based on depth of the object that's behind

#

Like water depth or so

#

but it's ez on transparent objects, they don't write into depth buffer

#

so you can just read from it and that's it

meager pelican
#

You're not required to write to the depth buffer, even for opaque stuff. BUT, if you don't you could get overwritten by things behind you. That's why you separate stuff out into a separate layer or queue.

As you probably know, the main diffs between transparent and opaque are:

  1. Sort order, so transparent draws back-to-front, and opaque front-to-back.
  2. Depth writes, opaque does them, transparent doesn't.
    the rest is your blending in your shader.

The sorting thing is the one the engine does that you have a hard time overriding. That's where layers come in, or queues.
So if you have a "higher" layer or queue, you have a back-buffer you can read and blend with, even if you do the depth writes.

#

Remember that you can manually test depth in the fragment shader too, by reading from the depth buffer to get the current locations depth not counting your current pixel.

bitter needle
#

I tried altering the queue, but didn't get expected results

#

I guess I probably messed up somewhere

#

thanks for the info though ^^

meager pelican
#

It depends on what else you're doing. It's the whole combination, if you can do what you think you're doing (IDK if that makes sense) But ...you might be getting exactly what you asked for, but not what you wanted, as is usual in computing, for all of us. ๐Ÿ˜‰

#

Maybe describe what you want to do again, and also say why you can't use transparent.

#

You might need two passes

bitter needle
#

yea, I'm doing 2 passes right now

#

can't use transparent because of few effects that don't apply to transparent objects

#

I'll let know if I'll have any problems

gilded portal
#

Hi all ! I'm in shadergraph making a quick outline shader by duplicating and displacing toward the outside my mesh. (multiplying normal) , now I need to render first the actual object that needed the outline, or set the outline to backface rendering.

#

But I dont find any rendering priority order setting or back face neither :/

#

Any clue ๐Ÿ™‚ Thanks ?

devout quarry
#

with shader graph?

#

@gilded portal if it's with shader graph, take a look at this thread

gilded portal
#

thanks

#

cant have color in multiply ๐Ÿ˜ฆ

#

its weird theres no rendering priority option ๐Ÿ˜ฎ

devout quarry
#

you can set the rendering queue?

#

and does the graph from the forum thread not work?

#

the last one

fervent tinsel
#

@stone sandal you guys want more input for the SG stacks ? I just tried the current wip branch. I see that if I rename a property that's already on the graph, it doesn't rename the existing one:

#

these two are both same property (MainTexture and BaseColorMap)

#

as additional note, I really really wished you'd let me rename the property also on the Graph Inspector: now I have to move mouse to other side of the screen to rename the property and then again to other side to change the reference name

gilded portal
#

trying it in opaque or additive right now as multiply will work ok for black color only (?).

#

So you can set it to double face render but doesnt look like you can back face only. Im thinking... Inverting normals should produce this?

stone sandal
#

@fervent tinsel that first comment is a bug which weโ€™ll start taking after the package formally releases for alpha testing, but the second note is helpful!

fervent tinsel
#

IMHO it could just show the property name just like the reference there as textbox

#

but it could just be me

#

it just doesn't feel very intuitive that I have to edit the names on two places

civic oriole
#

Hey, is there a way to pass a variable from HLSL shader to CPU bound ?

grand jolt
#

Help! all my shader files have started to be recognized as miscellaneous files in Visual Studio, and I get no Syntax Highlighting or Error Detection. so far I Tried several solutions suggested from googling but nothing seemed to have worked and my problem seems a bit unencountered even! as It's just the shader files that have turned to this...and my C# files seem just as well as before with intelligence/highlighting etc. This started happening right after I installed a bunch of Modules with VS Installer namely Desktop Development with C++ and Game Development with C++

#

my current workaround is using VS code instead.

patent mountain
knotty juniper
#

@patent mountain thas a realy tricky question

#

aproch would be to write a comptue shader that can caluclate a distance map from a given point on the uv outwards
but i have not the slidtest idear how to do that.

knotty juniper
late notch
#

@regal stag @lavish sierra @red swallow Thank you for the help with sprite UV/vertex displacement last week, just had time to test your guys tips and it's working.
@regal stag your example of offseting the UVs worked perfectly. I even tried to modify with Step node after the mask from the UV to see how that would influence the displacement, really cool learning with that example. Thank you again!

lavish sierra
#

np! Glad you got it working

willow basin
#

Control de colors base of normal vector and dot product

silk sky
#

Guys I'm trying to split a model (painted in RGBA vertex paint) into 4 channel/masks in the shadergraph

#

but I noticed that the Alpha seems not working like the R/G/B

#

can somebody help?

amber saffron
#

What do you mean that A doesn't seem to work like RGB

silk sky
#

I used the same process but doesn't seems right

#

this is the shader, pretty simple

slow bear
#

maybe it's not picking up the alpha channel during the import

#

Maybe there's something wrong during the export/import step of your workflow @silk sky

silk sky
#

I used maya and the model surely had transparent faces

#

let me check again

slow bear
#

Have you tried re-importing the model just to be sure the alpha channel was exported correctly?

#

re-import into Maya, I mean in this case

silk sky
#

I cannot find any options regarding the Vertex export

#

but at least the RGB surely got exported

#

as you can see the vertex paint on the body is transparent

#

the Alpha channel for now influce the whole model

regal stag
#

Your shader is colouring where the alpha is 1, not 0. Just like the other channels, colouring where red was 1 for example.

#

If you want the inverted result, which would be easier for painting probably, you should use a One Minus node on the alpha value before it goes into the T input (or switch the A and B inputs around).

silk sky
#

Still not working ๐Ÿ˜

#

I tried both ways

regal stag
#

Then maybe the alpha isn't being imported or something, as Tibor suggested. You could check by dragging the alpha output directly into colour.

silk sky
regal stag
#

Perhaps there are other colour channels in the transparent part too.

slow bear
#

Texture import settings, check its info

#

maybe it's discarding the Alpha channel because it's set to Transparency

regal stag
#

It's not a texture, it's painted vertex colours

slow bear
#

oh, sorry, got them mixed up for a moment

silk sky
#

the strange thing is that in the main preview it works

#

Ok i solved

#

I had to pass the alpha lerp to every other channel

regal stag
#

If that works it's probably your transparent part has the colour (1,1,1,0), rather than say (0,0,0,0).

slow bear
#

If that works it's probably your transparent part has the colour (1,1,1,0), rather than say (0,0,0,0).
@regal stag this also

silk sky
#

mh..ok

#

let me try to fix that to keep the shader clear

slow bear
#

in the Lerp part, you're maling a lerp between transparent black and the color assigned to the channel

#

lerp between solid black (0,0,0,1) and the channel color

regal stag
#

It may be easier to take the alpha as the T to a Lerp, with A as the combined RGB value and B as the alpha colour * intensity

slow bear
#

making*

regal stag
#

Rather than adding all the RGBA channels

#

That way, it doesn't matter what is in the RGB channels, the alpha will always override it. That depends if you want that blending in some cases though.

silk sky
#

for now i just want solid colors

slow bear
regal stag
#

Nah, the alpha of the colours isn't actually important as the final albedo input is a float3 so it's getting dropped anyway

#

maybe still with alpha -> One Minus -> T, or switch the inputs.

slow bear
#

Just thinking out loud: this should work because the Alpha channel already excludes the other channels, so in case of a Lerp the other channels that have already been processed will be left untouched, while the alpha painted parts will get painted with their palette color, right?

#

Assuming the channels do not overlap with each other

regal stag
#

Yeah, it's masking based on the alpha, so alpha=0 will show as the combined RGB channel results, while alpha=1 will show as the alpha colour, regardless of what's in the RGB channels

slow bear
#

at this point, the whole process can be simplified by putting lerps in cascade

#

I'll cook something quick in Amplify

#

and I'll post the graph, different apps but the idea is the same

#

it's just missing the intensity values

regal stag
#

Yeah, that would also work

slow bear
#

also, with a 4x1 texture it should also be possible to source both the palette and the intensity of each channel, but I wonder if it's more efficient than just sourcing vec4 vars in the inspector

regal stag
#

Yeah, and gives you the ability to easily expand the colour palette further than four colours if needed.

meager pelican
#

Isn't lerp vectorized for "T" too? ๐Ÿ˜‰
maybe I'm not tracking what he's after. But IDK why you guys are splitting all these nice vector operations out.

regal stag
#

That's a good point

vagrant rampart
#

Why cubemap affect on material preview in project folder
and not affect on material in scene?
How achieve same result for material in scene?

slow bear
#

Why cubemap affect on material preview in project folder
and not affect on material in scene?
How achieve same result for material in scene?
@vagrant rampart is everything set correctly in the actual material you have assigned to the sphere?

#

Also, you have disabled the scene effects, try turning them on

#

5th button from the left, in between "snap to grid" and "lighting"

vagrant rampart
safe tide
#
while (i >= 0 && exit.distance < intersections[i].distance)
{
    intersections[i + 2] = intersections[i];
    i--;
}

Any ideas why I would get the following warning for this loop?

#

I verified that the loop condition is not always false. And I'm using the result directly for the output.

meager pelican
#

If i is a constant, it unrolled the loop.

#

How is I defined?

#

@safe tide

safe tide
#

int i = intersectionCount - 1; @meager pelican

#

intersectionCount is initialized as 0, so when the loop is run for the first time, indeed it will be skipped entirely, however the whole thing is inside another loop and intersectionCount is incremented for the next iterations

#

However, even if I init intersectionCount to 10, so that even the first section will certainly be run, I get the same warning

meager pelican
#

OK so is the outer loop a constant?
IDK, but if it thinks it can unroll it, there's something going on. There would still be conditionals for each statement.

But if, say for example, the outer loop is 0 to 2 (so 3 itterations) and it can determine that i gets incremented 3 times in the outer loop, maybe it makes cases for 0 (because it can tell the first one won't happen) and then a set for i = 1 and a set for i = 2. And the "loop doesn't do anything" is for the first case. So it omits case 0. (which is i=-1)

Total SWAG.

#

I bet, just as a test case, if you put an if around all this to skip the first case (so if intersectionCount != 0), the message will change.

safe tide
#

@meager pelican
no, the number of iterations in the outerloop is directly determined by a shader input
for (int index = 0; index < ObjectCount; index++) {
I'm currently trying to build a minimal reproduction case

meager pelican
#

Well, maybe it doesn't have to be constant, if it can determine it's initial value of -1, in the unroll. IDK. Try that if out of curiosity. The beginning of the while loop should be an if, basically. But ...hey...loop unrolling.
Weird

safe tide
#

hmm, what.. you were right

#

what the hell

#

putting an if around it makes the warning go away

meager pelican
#

What I think it's telling you is "hey I unrolled your loops somehow, and one of the cases will never execute as written".

safe tide
#

hmm, looks like it

#

or actually I'm not sure
are you saying that it's a short loop so it tries to unroll and the warning is supposed to mean "one of the unrolled iterations will never be run"?

#

I think this detection would happen before the unroll

meager pelican
#

Yep. Guessing. Since it can determine the initial values, or ending values, or whatever.
I'm guessing all part of the same process, as it has to analyze it to decide to unroll it.

#

Since it knows the index=0 is the start, and it knows that intersectionCount and whatever and i depend on the values.

Again SWAG, I'm not a compiler writer.

#

It might imply you can change your logic or conditions to speed things up.

wraith wing
#

hi guys, just random question so i see in most of game like this from BOTW, the env was single sided, is there's any purpose of that?, i assume double sided avoided because it's much heavier to render.

knotty juniper
#

@wraith wing you are correct with your geuss. Normaly only the front face is viable for the player so the backface will never be seen so its not a good idear to render it if its never seen.

wraith wing
#

thanks for the explanation @knotty juniper

knotty juniper
#

@wraith wing It can be useful in some cases to render both sides of a face, like with non flat cutout object or foliage, there adding additional geometry for the back fades does often make no sense.

golden crest
#

I am trying to do post effects using a second camera and replacement shaders
I am following some guide (potentially outdated)
When I run this code with the culling mask set I see only the backgroundColor (black) even though I have objects set to that layer.
When I run the code without the culling mask I still see only black and when I stop the game my editor crashes.
What am I doing wrong?

meager pelican
#

IDK. Depends on what the ColorOnly shader is doing?

#

You could just supply the PP effect material as a parameter to the blit.

#
void Start() {
    camera.SetReplacementShader (EffectShader, "RenderType");
}```
https://docs.unity3d.com/Manual/SL-ShaderReplacement.html
#

So that's another way on the secondary camera if you want to try that.

golden crest
#

its drawing the object with an unlit color, i changed out the shader for a few others it didn't seem to make a difference

fervent tinsel
#

hmmm, from 2020.2.0a13 release notes: Graphics: Added: New API to allow the implementing Custom Render Textures on C# side, skipping completely the builtin Updates.

raw dock
#

Hey, I seek wisdom about dynamic splatmapping! The feature that I'm hoping to achieve is to paint an area to a terrain splatmap that is within a mesh that is intersecting the terrain and thus changing the texture on the part of the terrain that is surrounded by the mesh.

I was thinking that if I could somehow paint that specific area to a rendertexture I could then Graphics.blit that to the splatmap? I might be way off here and that's why I'm humbly asking for guidance.

heady jewel
#

Hi, is it possible to make 3D noise with the shader graph? In blender when you put a noise node you can decide the dimension(1D,2D,3D or 4D)

meager pelican
#

@golden crest You might want to Debug.Log(renderTexture); before the blit to make sure it's set properly. Also that last condition on the if? Should that be "a not" as in !renderTexture.isCreated()?

golden crest
#

You are right, it should be a not. I will try the the debug.log I didn't know I could use it like that.

plush mango
#

Hello I am trying to make a dissolve shader and I managed to make it work but when I go into the game view the shader is full of patchy black spots that aren't in the scene view. is there a way to find out what's wrong?

wise onyx
#

hello yall, ive recently started to try and get into making shaders, but from what ive found, there arent really any good tutorials on parallax depth. im wanting to create a translucent crystal but i just cant seem to find anything on this topic.

#

if any one knows of any good tutorials on something like this, just @ me

patent mountain
drifting stone
#

Is there a way to make a blur UI panel in HDRP

fervent tinsel
drifting stone
#

Thank you

amber saffron
prime pasture
#

Hey, I have a problem with double sided shader, the image show the problem, the orange & blue colors are a part of a mesh I put under the player (some part blend into the background, the green grass in this case).

My problem is, I try to mask the ball (you can see it inside the blue shadow next to the right foot), by using the orange part of the mesh, which is a cone, and the ball is inside it in this image, however, this view from the camera causes the camera to see the blue shadow, which has alpha on it, through it, it should see the cone, hiding the ball, however the shader just ignore the cone part, and cull it, any ideas?

#

I have both:

Cull Off
Blend SrcAlpha OneMinusSrcAlpha
#

Just for another reference, this is the mesh I am talking about, you can see the cone and the plane on top of it

#

The ball goes inside a hole (which goes inside the cone, and you can see the ball there in the last image)

#

A simplified version of my shader is:


fixed4 frag(v2f i, bool isFrontFacing : SV_IsFrontFace) : COLOR
{
    // This is used to project the background texture ontop
    // of the mesh in screen space
    float2 uv = i.screenUV.xy / i.screenUV.w;
    fixed4 col = tex2D(_BackgroundTexture, uv);
    
    // If it is a front face, add shadow to it.
    if (isFrontFacing)
    {
        float attenuation = LIGHT_ATTENUATION(i);
        float shad = (1 - attenuation);
    
        clip(shad - 0.05);
    
        float softness = lerp(1.0, shad, _Softness);
        col = _ShadowColor * softness;
    }

    // Used to mask stuff with 2D image
    col.a *= 1.0 - tex2D(_ScreenMasking, uv);
    
    return col;
}
heady jewel
#

Thank you @amber saffron !

ancient kelp
#

If I have a normal 3d model, is it possible to transform it into something like this using a shader?

slow bear
#

@ancient kelp extremely hard, but it could be done

valid flax
#

I'm trying to cut out everything that's outside the sphere.
I was thinking of doing it with a custom function where all the other materials would get their alpha based on the sphere's location and then use AlphaClipThreshold to remove it.

Wondering what you guys think of that idea, or if there's an easier way to do it

amber saffron
#

So many ways to do this :p
Using stencil to make a mask ?
Indeed using the distance to sphere surface to do the alpha clip (you might want to complexify a bit if you want that some objects have transparency enabled). I would also recommand to directly disable rendering of objects that are fully out of the sphere from script

#

You should also disable the sphere shadow imho

low lichen
#

Stencil would include things outside, behind the sphere

amber saffron
#

True, forget that then

low lichen
#

Shader Graph doesn't have a discard node? If not, a simple custom node function that just compares the distance with the radius and discards based on that should work with both opaque and transparent shaders.

amber saffron
#

Hey, good idea ! I should add that to my library

low lichen
#

It could just use the clip function actually and just need one float parameter

valid flax
#

I know of the discard thing in HLSL code - I'm not too familiar with writing custom functions in Shader graph though

#

is it the exact same? @low lichen

#

or GLSL - whatever, the shader code thingy

#

discard(x)

low lichen
#

The discard I'm talking about is the HLSL discard

#

Custom functions in Shader Graph lets you write HLSL

valid flax
#

It's not available in Shader Graph

#

Oh, perfect then! ๐Ÿ˜„

regal stag
#

You could also just use the alpha clip threshold

valid flax
#

I tried making sense of it @regal stag but I honestly don't understand it perfectly :p

regal stag
#

If the AlphaClipThreshold is higher than the Alpha value, it discards the pixel

low lichen
#

But I guess the custom function would have to pass the current pixel color through it to actually get included in the generated shader? If it doesn't ultimately connect to the master output, it just gets ignored, right @amber saffron?

amber saffron
#

It would still be a bit "weird" to implement, as clip(x) and discard() are "terminal" functions that don't output anything, and to have them compiled by shadergraph, you will need to output something from the custum function, and connect it to the master node :/

regal stag
#

Yeah, it would probably need to be connected in somewhere

valid flax
#

@regal stag since I'm working with a transparent shader alrdy it would clip the sphere itself, I wanna clip everything inside/outside the sphere

#

(I need both use cases)

regal stag
#

I mean for the materials/shaders for the buildings, not the sphere

low lichen
#

You wouldn't use discard on the transparent sphere

amber saffron
#

You could also do something as "stupid" as setting the alpha clip value to either 0 or an immensely big number, depending if the pixel is in or out of the sphere.

#

Should do the trick

valid flax
#

yeah, that's the theory - but how to do that in practice is what im not succesful at

#

so I 100% can't do this using just a shader on the sphere? @low lichen I'd have to put the discarding/clipping on the shaders/materials of everything BUT the sphere?

low lichen
#

Yes

valid flax
#

How, in shadergraph, would a different object be aware of the sphere?

low lichen
#

You'd have to pass the sphere's position and radius to those shaders

valid flax
#

You can't really add a gameobject to the Blackboard

low lichen
#

Probably through a global shader variable

valid flax
#

How would I do that? :p

amber saffron
#

One vector4 property is enough to hold that info, and you the set it through Shader.SetGlobalVector()

low lichen
#

Shader.SetGlobalVector("_SphereInfo", new Vector4(x,y,z,radius));

valid flax
#

Inside a custom function that is called inside the sphere's shader?

low lichen
#

Then make a property in the blackboard of the type Vector4 with the reference name set to _SphereInfo or whatever you want

regal stag
#

No, in a C# script

valid flax
#

So in a empty gameobject with a monobehaviour script in like a Start Function that would have a reference to the "clipshader" (that's applied to everything except the sphere) ?

low lichen
#

It's a global variable, so you don't need a reference to the shader

#

When we write Shader., it's not a reference to the shader, but the Shader class. It's a static method.

valid flax
#

OOOOOH

#

mybad

low lichen
#

And if the sphere moves or changes size, you'd have to update that every frame, or every time it changes

valid flax
#

Luckily it's static ๐Ÿ˜„

regal stag
#

Here's an example of the shadergraph using alphaclipthreshold.
Could also use a Step node, with In as Distance and Edge as the Multiply output, and just leave the AlphaClipThreshold at something like 0.5.

valid flax
#

And then based on that Vector4 change the Alpha's of the buildings and clip it that way?

amber saffron
#

Why do you divide the radius by 2 ?

valid flax
#

isn't he dividing the X position?

regal stag
#

Might be because of the default unity sphere scale

low lichen
#

It's the A component, as in w

valid flax
#

oh, as in RGBA

amber saffron
#

Also, remark based on your screenshot : this works only for ONE sphere

valid flax
#

gotcha

amber saffron
#

You'll have to chain these nodes with multiple vector inputs if you want to have more

valid flax
#

Basically the idea is to cut the inside out on 1 sphere. cut the outside out of the 2nd sphere and combine them

#

but I can for sure continue with this

#

one edge case I'm getting is that basically anything and everything that I want to be cut/clipped will have to have this shader applied to it

#

but what if it's using a transparent shader to begin with, think of glass or something

low lichen
#

That's where using the alpha clip threshold falls apart

#

Since it forces you to use the Alpha output which is also used for transparency

amber saffron
#

That's why I suggested to use the sphere distance to set the alpha clip to 0 or 1

valid flax
#

So a distance check would then be better , as in a custom function

amber saffron
#

0 beeing : I see the transparency, and 1 beeing fully clipped

#

and no need for custom function to do this

valid flax
#

Oh , instead of hardsetting the alphaclipthreshold to be "If it's alpha is lower than 0.5, discard" You make it dynamic in saying "IF distance to circle and lower than 0.5, then discard"

#

This helped tremendously Guys! thanks! ๐Ÿ˜„

#

(atleast in theory, still have to do it in practive :p

amber saffron
low lichen
#

I'm trying to think of a way this effect could be done without requiring custom shaders on everything.

In the case of wanting to clip everything outside the sphere, what about using a combination of a stencil mask and the depth buffer? The stencil mask would cut out everything outside the circle and to cut out things behind the sphere, render an inverted sphere into the depth buffer before rendering everything. The depth value of the inverted sphere would reject anything behind the sphere even if it passes the stencil check.

amber saffron
#

But he also wants it the other way around

low lichen
#

You could do it the other way around too, but you couldn't combine them I'm pretty sure

amber saffron
#

It might be possible by having a full depth prepass and using two stencil bits (back and front faces of the spheres)

#

But having a global shader is probably easier.

low lichen
#

Yeah, and a custom shader lets you do more interesting combination effects

valid flax
#

Some sample to do it only with the clip output :
@amber saffron What is it exactly I'm seeing here? I don't see a cutout of a sphere?

#

or am I blind af?

amber saffron
#

Well, a sphere cutting a plane makes a round hole, right ?

valid flax
#

And the shadergraph material above that is applied to the plane?

amber saffron
#

It is applied to the plane

valid flax
#

Gotcha! ๐Ÿ˜„

#

Exactly what I'm looking for

amber saffron
#

If you invert the step inputs, you invert the mask

valid flax
#

I'm trying to think of a way this effect could be done without requiring custom shaders on everything.

In the case of wanting to clip everything outside the sphere, what about using a combination of a stencil mask and the depth buffer? The stencil mask would cut out everything outside the circle and to cut out things behind the sphere, render an inverted sphere into the depth buffer before rendering everything. The depth value of the inverted sphere would reject anything behind the sphere even if it passes the stencil check.
@low lichen I'll be honest with ya. You kinda blew my head out with what you said. lol. The other solution I seem to grasp better

#

If you invert the step inputs, you invert the mask
@amber saffron Thank you! ๐Ÿ˜„

tropic galleon
#

hi all

#

what it wants?

vocal narwhal
#

you probably do not have a render pipeline properly configured

#

if you're using the default pipeline you will not be able to use shadergraph

devout quarry
#

There is this brackeys tutorial

#

Let's learn how to render characters behind other objects using Scriptable Render Passes!

This video is sponsored by Unity

โ— Download Project: https://ole.unity.com/occlusiondemo
โ— More on Lightweight: https://ole.unity.com/lightweight

ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท...

โ–ถ Play video
#

and what he does is he uses the 'render objects' renderer feature in URP to change the look of some objects in the scene. He configures the layer, so only objects on a specific layer are affected, and then he specifies the material of the object (the dither effect on the right)

#

he then applies it to a bunch of NPC's in the scene

#

but what if I want some objects to show a red colored dither effect, and other objects to show a blue colored dither effect

#

would I need to do 2 renderer features with 2 materials and 2 layers? Or is there a smarter way?

#

is there some way with material property blocks maybe where I can still use 1 renderer feature and 1 material, but the renderer itself can still set some custom properties for the material

low lichen
#

@devout quarry If the renderer has a material property block on it, it will override properties on the override material

#

So yes, you can have one renderer feature with one override material with a color property and override that property with a material property block on the renderer

#

SRP Batcher won't batch that though

devout quarry
#

But for example in the video, in the 'override' slot for the material, he adds some sort of dither effect material and then he adds all the objects that need to be affected to a certain layer

#

So if that dither material has a color property

#

then as you say, on the renderer I should override that property with a material property block

#

but how exactly? because I didn't put the dither material on the object right? I just assigned it in the renderer feature

low lichen
#

A MaterialPropertyBlock just stores the property name it should set and its value

devout quarry
#

so I would need to add a script to each object that sets the material property block?

#

if I need a custom color on that object

low lichen
#

You would need to add a material property block on each renderer you want with a different color, yeah

#

Whether you do that in a script on the object itself or some other script is up to you

devout quarry
#

right

#

but let's say I'm only working with 2 variants, or 3

#

am I better of just working with renderer features, 2 materials and 2 rendering layer masks?

#

in terms of performance

low lichen
#

That would batch better, yeah

devout quarry
#

And so I would be using the new rendering layer mask system

#

is it slow to switch rendering layers at runtime?

low lichen
#

I doubt it's something Unity is caching. It's probably checking the layers every frame, so I think you're just setting an int value.

devout quarry
#

okay cool, I'll test some things out then

#

thanks

atomic glade
#

I'm not sure if this is a lighting question or a shaders question, but how could I remove that seam between these two meshes? They're loaded in at runtime so I can't manually configure them to line them up. I'm using URP and shadergraph with a PBR node on each of them.

lavish sierra
#

Just combine the meshes @atomic glade

atomic glade
#

I can't. They're loaded at runtime from separate files

lavish sierra
#

You can combine them at runtime

atomic glade
#

Ah, I didn't know there was a function for it

#

I'll look into that, I think that might be what I need. I'll just need to find a way to know which meshes need to be combined

lavish sierra
atomic glade
#

So, it looks like these meshes are already part of a single mesh filter as separate submeshes. Is there a way I can get rid of this seam while maintaining them on separate submeshes?

#

Each of those submeshes has metadata based on the source files it was generated from and if I combined the meshes I wouldn't be able to show an individual submesh's metadata

atomic glade
#

Even without keeping them separate, I just managed to combine all the submeshes together and they still have a seam. So now they're on the same mesh and submesh and I'm still getting lines where the divides used to be

tropic galleon
#

Hello. my question is how to deliver a vector array to a shader? I want that on the water after the ship sailed there were waves. Does anyone have a ready-made solution?

foggy falcon
#

look up compute buffers

#

the other alternative is to treat a texture as a lookup table

tropic galleon
#

Shader graph have compute buffer?

foggy falcon
#

not sure, let me look

#

ah, feature is on the roadmap for now. You should use a texture as an array in the interim.

1D Textures should already be supported, or you can use maths to map a 2D tex to a 1D tex space

#

wait, that's the VFX roadmap

tropic galleon
#

after seeing a lot of guides now I understand how to make waves. just noise and time. but that would leave a trace from the ship or something else. Now I donโ€™t know how to do it. maybe you know?

foggy falcon
#

no, I don't, sorry.

As for the buffer in SG, it looks like it's possible with a Custom Node, but you'll have an easier time with the texture method.

The upside of exposing a buffer read node in SG is more complex types, the texture as array method is simpler