#archived-shaders

1 messages ยท Page 158 of 1

tropic galleon
#

How do I write vectors to a texture?

#

Is each pixel essentially a vector? And how can I get it on the back?

foggy falcon
#

reading on the texture requires sampling it

tropic galleon
#

How its work?

foggy falcon
#

not familiar with that

prime estuary
#

how to make particles glow?

thick fulcrum
#

@tropic galleon checkout the "boat attack" demo by unity, there is a git for it. included is an example of how to leave wake behind boats or there is a good ocean on store which does it very well too.

tropic galleon
#

why my shader not full size?

smoky sigil
#

How do I even get shadergraph

low lichen
#

Window > Package Manager

#

But it only supports URP and HDRP

smoky sigil
#

What is URP and HDRP?

low lichen
#

That's something Google can answer

#

Google has a lot of answers

smoky sigil
#

So

#

no LWRP?

regal stag
#

LWRP was renamed to URP

smoky sigil
#

o_o

#

In my package manager it was LWRP

#

URP is for the Alpha/Beta likely

regal stag
#

I believe that LWRP is still listed in the package manager so it can still be used to update the package, but a lot of the versions are probably just URP ones

fervent tinsel
#

If you dont see universal rp on package manager it means you are on older unity

willow basin
#

What is URP and HDRP?
@smoky sigil URP Its Universal Render Pipeline , to use for graphics like mobile, HDRP its High Definition Render Pipeline to create games in PC, Mac etc the two pipelines can to use shader graph

smoky sigil
#

Thanks ^^

devout quarry
#

uhm

main cypress
#

URP is for the Alpha/Beta likely
@smoky sigil Actually I think the name has changed as of 2019.3

devout quarry
#

Universal render pipeline will become the default pipeline so definitely also for desktop and console

#

Universal is just 'universal', mobile + desktop + console

smoky sigil
#

Funny because I have 19.3

#

and I have both in the store :D

#

I mena

#

mean

devout quarry
#

HDRP is for higher end platforms like desktop + consoles

smoky sigil
#

packet manager

regal stag
#

Yeah, both are included in the package manager. Likely so that users still using lightweight can easily update to the newer versions without having to uninstall and reinstall URP.

smoky sigil
#

I am so done for the day :D

#

But how do I use a shader I made in graph editor?

#

Because... That's what I can't do yet :D

devout quarry
#

If you install URP in 2019.3, shader graph will be included

smoky sigil
#

It

devout quarry
#

Create > shader > graph to create a new graph

smoky sigil
#

was and I made a shader

regal stag
#

Same as using shaders written using code. Apply it to a Material.

smoky sigil
#

but how do I put it ... yeah how do I Apply it to a material?

main cypress
#

But how do I use a shader I made in graph editor?
@smoky sigil apply shader to material, apply material to object

#

just drag the shader onto the material ๐Ÿ™‚

devout quarry
#

You can right click on the shadergraph and click on 'create material' to automatically create a material that uses the shader

regal stag
#

Create a material and select the shader from the dropdown, or drag it onto it

main cypress
#

I could use some advice too if you guys don't mind

smoky sigil
#

That... doesn't seem to work

#

I mean dragging the shader onto the material

devout quarry
#

Right click the .shadergraph file in your project window and click 'create material'

#

@main cypress ask away

smoky sigil
#

I'm going to cry xD

#

Why... what?

devout quarry
#

@smoky sigil read this whole guide through

#

you probably need to assign an active render pipeline asset, but the guide explains it all, I recommend giving it a read

smoky sigil
#

But

#

I got that? don't I?

regal stag
#

It looks like you've created one, but you also need to set it under the project settings

smoky sigil
#

Yes

#

and on the left my shader works???

low lichen
#

Try clicking Save Asset in Shader Graph

main cypress
#

On the top left corner of the shader graph window

#

@main cypress ask away
@devout quarry I'm wondering how to do something similar to decals in URP, any idea how that could be accomplished?

#

I'm trying to figure out how I can recreate the sticker functionality from LittleBigPlanet

devout quarry
#

this system works well

#

but this

#

is basically a single shader, and also works very nicely

main cypress
#

But I have no idea how it works

#

I also have no idea whether this is the best solution for what I'm trying to do

#

I actually don't know much about shaders which is why I'm so lost

#

Also not even sure shaders are the best way to do it. Is there a way of painting on a texture in-game?

devout quarry
#

I think the NiloCat shader should help you out

#

hold on

#

check this video

#

he uses the decal shader to project the texture onto the geometry

#

so you can use it to put a texture nicely on the surroundings

#

like a sticker

main cypress
#

actually yeah the way that he does it is pretty useful actually

devout quarry
#

there's also this

#

but I recommend taking a look at the nilocat shader first, because you see it in action in the video, and it's really just 1 shader

#

and you can download the project from in the video if you need to see how it was set up

main cypress
#

Yeah I've come across all these I've even used the nilocat one

#

but I'm not sure if it's the actual best way to do what I want to do

#

but thanks that was helpful

devout quarry
#

the driven decals system is more feature rich

#

but works the same as you can see, this would be like a sticker right?

main cypress
#

yeah it would work, but I'm wondering what would happen if there were a lot of those in a scene, would it affect performance?

#

and I'm also just wondering how that shader works

#

because I have no idea

devout quarry
#

the driven decal system is really just a quad

#

I'm not sure either, never looked at it

#

the driven decals system uses a shadergraph shader btw

#

so maybe cool to look at

main cypress
#

oh right

#

I'll have a look, thanks

#

I'll experiment a little bit and show you what I come up with ๐Ÿ™‚ thanks for the help

quick wigeon
#

trying to make a Toon Shader for a fighting game using Shader Graph. I can make the lighting effect, but I am having trouble with the actual outline part

#

and I can't figure out how to make it in shader graph

knotty juniper
#

@quick wigeon problem is that the shadergraph does not allow for multipass shaders taht are normaly used to make a inverted coppy of the mesh and make that extured out.

quick wigeon
#

oh

near imp
#

here's a tutorial i came across that doesnt use shader graph i think

#

perhaps the ideas u can use tho?

trim jolt
#

Anyone know how to make a cube half way invisible? Like at the top of the cube its a solid color but as it goes down it becomes invisible?

cursive jewel
#

hi guys i want make a cube glow something like this. Is there any simple method to achieve this if I am not using LWRP/HDRP?

devout quarry
#

@quick wigeon

#

Tutorial for outlines + shadergraph

quick wigeon
#

thanks

pale nest
#

Hi, I'm fairly new to unity, can someone help/tell me what I'm doing wrong? I'm just trying to change the hue of my texture but I can't for the life of me figure out why the output is just black+white

vocal narwhal
pale nest
#

oh yeah I was messing around, default doesn't work either

vocal narwhal
#

but also, if you offset grey you still get grey, if something has no hue in the first place then how do you offset it

pale nest
pale nest
#

Ohhhh ok

#

it works now, thank you so much

smoky sigil
#

Okay guys

#

The next step is Fresnel effect, but I need to be able to adjust it's strength with Code and even turn it off.

#

If anyone can help me with that I'll be berry happy

devout quarry
#

In shadergraph you can add a property in the blackboard that controls the power of the fresnel effect

#

you can give that property a 'reference' that you can then use in your C# script

#

using Material.SetFloat

#

so for example material.SetFloat("_FresnelPower", 5);

smoky sigil
#

Thanks, but how do I

you can give that property a 'reference' that you can then use in your C# script

devout quarry
#

look at the blackboard

#

there is a reference field there

#

"Reference name"

#

just use like "_FresnelPower"

smoky sigil
#

Hmm, I've read a tutorial on how complicated it would be because in earlier versions they had no proper reference names...
And I am still confused but thank you I'll try to figure it out ^^

devout quarry
#

You're using shadergraph right?

#

Really, in the blackboard for the property you want to change by script, add a reference name

#

Then, you can use that reference name in your C# script

smoky sigil
#

in the blackboard
Where.
Sorry, I am just confused ^^

smoky sigil
#

The blackboard is my problem, what should I create there?

#

I'd need a float

regal stag
#

Vector1 is a float

smoky sigil
#

so... IDK as I said, I am confused ^^

fervent tinsel
#

vector1 = float

smoky sigil
#

Oh

#

k

#

:D

#

Thanks :D

smoky sigil
#

So

#

My first bigger issue, I don't know how to solve. If my game gets started with a white skybox instead of a black one I get this bug

#

This is how it should be btw

devout quarry
#

Are you using a lit or unlit master node?

smoky sigil
#

Lit

#

I think

#

I'm so new to this sorry ^^

#

Where can I check? :)

devout quarry
#

In shader graph, the 'final' node

#

Says either 'unlit' or 'pbr' I think

#

Try using an unlit node

#

Create new master node that's unlit, then right click on it and click 'set active', then you can remove the old master node

smoky sigil
#

Alright, but I use emission for the fern effect. Hmm, brb I have to try it out

#

Yeah, I don't get the effect I had befor

#

I use emission for the Fernsel

#

You can take a look at the Video I posted before.

#

Ugh, first function and I already have a huge problem ๐Ÿ˜…

#

But...

#

I am confused

#

even so, I don't get this bug every time I run my code

devout quarry
#

Uh yeah not sure, but then for your pbr node you'll need to make sure it's not affected by the skybox lighting

smoky sigil
#

My problem is if it "Generates lighting" with a white skybox

regal stag
#

Rather than a skybox it might be better to have the camera set to a solid colour background type

smoky sigil
#

Can I just generate lighting with a line of code?

#

Because then in the start function I set the Sky Black, re-generate it, and then it's all good

#

Like with the "generate lighting" button in the settings

#

Hmm

#

Alright this gets me to many more questions

#

If I generate lighting at the start of the game, will characters spawned afterwards generate their lighting in the current skybox?

regal stag
#

I'm not too sure how the environmental/ambient lighting works, but you might be able to set it to colour, rather than using the skybox.

#

(Lighting window/tab btw)

#

Or, as I suggested a bit above. Rather than using a skybox, leave it at black and change the camera to render a background colour rather than a skybox. That background colour shouldn't affect lighting.

#

Also, you can still use the fresnel output for an Unlit master node, which may be preferred if you aren't actually using lighting. The emission output on the PBR is basically like an "unlit" overlay over the lit result. For the unlit node, it's already unlit so you can combine the texture and fresnel results (e.g. using an add or maximum node), and put that into the colour input on the unlit master.

smoky sigil
#

I am

#

So confused

#

Like... I can not recreate this bug anymore???

#

But whatever I guess...

#

Now, How do I add just a colored filter on top of everything. Like in shooters, when you get hurt, the way the screen turns red.

#

Is there any method to put shaders on top of everything? Maybe even Post processing?

#

Aye

#

I fixed it by setting "Enviroment reflections" to custom and not adding any cubemap

#

But Is there any method to put shaders on top of everything? Maybe even Post processing?

regal stag
#

There are probably ways to tint the screen using URP's post processing, although it doesn't support apply custom shaders (yet?).

smoky sigil
#

I can just put a Shader on the camera

#

Can I?

regal stag
smoky sigil
#

I'm confused.

#

But I'll eat something and come back

smoky sigil
#

Now my next steps are:

  1. Make a shader for bossfights. The bosses should light up their environment.
  2. Make a shader for the Blood rain event.
  3. Make the shaders universal, Applying to all NPC/Enviromental Objects.
  4. Done.
    But how I'll do that? Good question.
marsh turret
#

hmmm

#

would adding a custom renderer feature allow me to re-shade all objects in my scene that go "underwater"

#

to mean that the albedo takes into account their distance from the light and falloffs faster (cos underwater it shoul go blue then black a lot more than in air)

smoky sigil
#

What if I want to add a 2D scene on top of the 3D?

#

Like... what would be great for shaders, and the UI

#

But how do I do that...

#

._.

devout quarry
#

@marsh turret you could work with a post processing volume?

#

position it under the water surface and tint the scene blue

#

it's an approximation for sure, but could look convincing enough

smoky sigil
#

Why...

#

Does this not work? or am I stupid? or is it old?

devout quarry
#

Urp uses post processing v3

#

Gameobject>create>volume

#

Then you can add post processing

marsh turret
#

position it under the water surface and tint the scene blue
@devout quarry issue there is players IN the water looking down

#

water needs to get darker as you look down...sunlight needs to drop off....ideally all lights but sunlight esp.

smoky sigil
#

Urp uses post processing v3
Gameobject>create>volume
Then you can add post processing
Okay

marsh turret
#

i'm already doing PP for color tint, and I've coded in for fog to get stronger and darker as you descend

smoky sigil
#

How do I activate it/add it to the game?

devout quarry
#

@marsh turret but if players stand in the water, so they have their eyes above the water line right? and they look down?

#

They see the water surfaces right? So the objects will have whatever tint your water shader has

#

I'm not sure I understand

regal stag
#

I think they want a gradient so objects deeper are darker than objects nearer the surface. You could do something like that by using the world space Y position.

#

On the objects shader. This assumes the water is at a constant height throughout the map though too.

devout quarry
#

Yeah

smoky sigil
#

Why does it not work

devout quarry
#

Or multiple post process volumes stacked on eachother and blend between them?

smoky sigil
#

and why do I keep trying to get my simplistic but hard to make visual style ._.

devout quarry
#

@smoky sigil have you enabled post processing on your camera?

smoky sigil
#

No, how do I do that...

marsh turret
#

aaah, i understand what you meant @devout quarry

#

sorry, I should have been more specific

smoky sigil
#

Sorry that I'm annoying, but I am really trying...

marsh turret
#

my game is not water like a pool, but water like the ocean

#

so if a player is swimming underwater (or more often, in their submarine, and the camera is following them)

#

then when they look down, the water should be getting darker and darker as it's deeper

devout quarry
#

Ah right yeah I think cyan's solution would be good

#

In the shader of the underwater objects, take world position into account and color based on that

smoky sigil
#

How do I enable post processing on my camera

#

:(

regal stag
#

Look at the camera component. There should be a "Post Processing" checkbox. Just make sure that's checked

smoky sigil
#

I swear to god I was googling like crazy and went trough the list 3 times

#

Didn't see it

#

._.

marsh turret
#

hmmm my issue ther is what about objects that move from in water to out of water?

#

do I just need to add the shader code to every single object in my scene that might go underwater?

#

that would be...unfortunate

#

i was hoping there would be some way to "override" the lighting on any surface based on if it's underwater or not

#

(I can find out if any particular point is underwater or not ,that's not an issue)

#

also it needs to take into account whether the light source is above water or not...if it's above water (ie. the main Directional) then falloff needs to be measured based on that point's distance to the water surface...

#

otherwise, it needs to calculate falloff from the light (say, an underwater spotlight) and attenuate it properly

smoky sigil
#

Ugh

marsh turret
#

if that's gonna be too much work, I'd settle for just the main directional light

smoky sigil
#

How do I reference the RGB Tint in a script?

marsh turret
#

but that still means adding a shader node and override to every single object...

#

just wish there was a way to simply change teh lighting model so "if surface is below (waterlevel), attenuate light using this formula"

regal stag
marsh turret
#

gotchya ta

thick fulcrum
#

@marsh turret have you looked at the Crest project, it covers a lot of what you are asking. Git version for standard renderer is free, so you can check it out and if you need URP/HDRP can buy on asset store.

marsh turret
#

yeah I've seen Crest - sadly this is a commercial project and previous..experience has led me and other members to be very disinclined to touch assets

#

(which is to say "oh look, they updated something. And our game is broke and unlikely to ever be able to be updated ever again. Yay")

#

on top of that it's a bit overkill - graphical fidelity would be very costly at that level, this is a physics game so lots going on already

thick fulcrum
#

some asset devs do abandon work so it can becomre outdated, but the crest guys are keeping it updated and actively deceloping it. They are very helpful, I know it's easy to get stung by assets. But it's also easy to design you game to be modular and flexible to swap in assets or out.

marsh turret
#

but thank you for the suggestion - I might reach out to then if they have any tips

thick fulcrum
#

crest is Very performant and can be adjusted / customised to any graphic style, you should pop onto their discord and see who's using it and what problems are (if any)

#

there is also a good list of water papers on their site for reference material

smoky sigil
#

How the hell do I access PostProcessing-Variables in 2019.3 URP

marsh turret
#

hmmmm

#

could I write a custom renderer in URP

#

that goes over what the opaque and transparent passes have already done

#

and say "hey if underwater, darken the albedo based on "this""?

#

how do custom renderers work in terms of overlaying?

lone stream
#

@marsh turret might want to disect this repo, this is on built in renderer though

#

oh forgot the link my bad

marsh turret
#

ta

marsh turret
#

hey Cyan, are you around?

regal stag
#

Yea

marsh turret
#

sorry to bother you

#

you wrote this right?

regal stag
#

Yep

marsh turret
#

it's a bit of a smelly hack

#

but do you think if I create a plane in my water

#

(like say -20)

#

and move it based on the position of the camera

#

i could "fake" the underwater falloff/darkness effect I'm looking for

#

(i basically need a volumetric fog but URP hasn't got one, and certainly not one that's very performant)

#

it's that or I'm gonna have to add a node to every single shader in my game that checks if it's underwater then adjusts it's albedo based on distance to water surface/directional light...

regal stag
#

Hmm, that definitely seems a bit hackish and Idk if it'll give the result you want

marsh turret
#

i am struggling to find an approach that will tbh

regal stag
#

It might be possible to apply a similar effect as post processing instead, that way you wouldn't have to worry about moving the plane

marsh turret
#

in URP?

#

i thouht about a custom renderer

#

but it would be layer-based and I can't very well change an object's layers based on if it's out of water or in

regal stag
#

Would the built in fog work for something like this?

#

I guess it's not flat though

marsh turret
#

i am using built-in fog and making it darker etc as player descends

#

but...

#

it's a 2d effect

#

(i'm a 3d artist, not a very good graphicsprogrammer so I might be using art teminology not programmer language, sorry)

#

so it's rendered over the camera view...

#

not a true 3d effect..

#

so if the player looks down, it isn't "visible" as a flat effect looking down into the water

regal stag
#

I'm thinking that a post processing effect that reconstructs the world position from the depth texture might work. Then tint darker based on the Y axis.

marsh turret
#

can URP have custom PP effects?

regal stag
marsh turret
#

hmmm, a PP could work nicely if achievable

regal stag
marsh turret
#

does that mean subsituting the shader into everything being rendereed?

#

or am I mixing stuff up?

regal stag
#

Nah, the RenderObjects feature uses an overrideMaterial to replace the shader being rendered

marsh turret
#

ah so I don't lose colors, textures etc

regal stag
#

A Blit feature just takes what the camera renders into a _MainTex property, which you can then edit and pass out

marsh turret
#

that's what I need ๐Ÿ™‚

#

thank you Cyan

#

i proabbly won't get it working, cos this is my first real foray into serious programming...ten years of 3D in the industry etc but first time really doing actual code stuff

#

but I at least know where to look. Thank you.

regal stag
#

Good luck ๐Ÿ‘

marsh turret
#

that depth-inverse projection should be the key..I can use that code to get the y position, then modulate the albedo darkness from that

#

be nice if I could just do that in the shader graph mind you lol. I like node-editing - we've used that in 3D for years now!

#

actually...i..can?

#

if Blit just allows you to take the _MainTex...

regal stag
#

Might be able to rewrite it in node form, or use a custom function node

marsh turret
#

i can make a shader in shader-graph that uses the _MainTex value, does the light-position stuff in the shader graph...

#

i think

regal stag
#

Hmm, noticing that the DepthInverseProjection is using BlitFullscreenTriangle rather than a regular blit. I think it's written for the PPv2 stack so Idk it'll probably need tweaking.

#

The InverseProjection shader also uses the SV_VertexID, which I don't think is accessible in shadergraph

#

It's only using it for the clip space position though, maybe there's another way to get that

orchid briar
#

Hmm

#

Im fiddling around with pixel accurate picking

#

using a replacement shader, packing data into Color32, etc.

#

im having problems with linear color space, which is what i assume i should use

#

i create the render texture like this: new RenderTexture(w, h, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);

#

so when i 'inject' the data from unity/C# side, this is what i get: id: 64190, as 32bit color: RGBA(190, 250, 0, 0)

#

but when i pull it out of the texture, this is what i get: id: 62595, as 32bit color: RGBA(131, 244, 0, 0)

#

it's... off

#

this is what RenderTextureReadWrite.Linear says in intellisense

#

so i would assume that this DOESNT convert the colors, right

#

the integer ID is converted to a Color32 like this

#
    unsafe static Color32 IdEncode(int id)
    {
        return *(Color32*)&id;
    }
#

and then assigned on a MaterialPropertyBlock like this: block.SetColor(PROPERTY, idEncoded);

#

now i noticed that SetColor converts Color32 to a Color

#

but that conversion seems harmless (it's just channel/(float)byte.Maxvalue which is fine)

#

here is the weird thing tho

#

if i create the texture with RenderTextureReadWrite.sRGB instead, it... WORKS.

#

It produces the right id when the color data in the render texture is converted to a an int again...

#

but of course... sRGB mode says this

#

which seems like it's the OPPOSITE of what i want...

#

so where the hell is the color getting fucked up?

#

I am at a damn loss

marsh turret
#

hmmm, i am not sure i know enough about shadergraph/prgroamming to achieve this

#

i'm fairly sure I can do a shader in shadre-graph that would take the world-position of a vertex and get the light level effect working on it based on it's -y coord

orchid briar
#

To make it EVEN more confusing, if i switch to using a float, and using RFloat as color format

#

and convert the ints to floats, and then back also

marsh turret
#

but i'm not sure if I can do the same to a shader which is being rendered in a blit pass

orchid briar
#

it works... NO MATTER what the color format is being used

#

fkn hell that was way more work than i thought it'd be because of the damn color format

marsh turret
#

oh ho! Cyan:

#

they added a new "example", making a gradient-based distance fog

regal stag
#

Oh cool, didn't see that branch. It'll probably be similar effect to the fog though, where it won't vary with the depth of the water.

marsh turret
#

it's a bit "hidden"

#

no, but I an change that

#

it's a depth-based fog effect - so all I need to do is tie the "depth" in question to a world position insted of the camera

#

and that's all being done in the shder graph

regal stag
#

Hmm, but it's still an image effect / blit. It's a similar problem that the depth inverse projection thing was trying to solve

marsh turret
#

arggghhhh you've got to be shitting me

#

it's not there

#

the wiki for it has the effect listed, but the GIT code is missing entirely ๐Ÿ˜ฆ

regal stag
marsh turret
#

aaah yeah

#

thank you

#

i mean, if I'm reading this properly tho

#

it should do everything I'm looking for; I can change the albedo of the objects I want to change, based on their position relative to the water surface

#

becasue it's not dependent on the camera position inherently - it's getting a depth texture for the positions...

#

instead I can use a worldposition

#

yeah, OK, I've just seen why I was wrong.

#

because it's an image effect, it's only gonna work for overlaying the image effectively..

#

that said..

regal stag
#

Lol.. why is there even a UNITY_MATRIX_I_P, if it's not even defined in URP. ๐Ÿ™ƒ
#define UNITY_MATRIX_I_P ERROR_UNITY_MATRIX_I_P_IS_NOT_DEFINED

marsh turret
#

if I have a render pass for the Directional light....which does something like this...then a second render pass that explicitly does NOT render the directional light but does render other lights...or something like that

#

or maybe...since I know what the directional light is always doing, calculate what the effect of the directional light on each vertex position is, then discount the correct amount based on what it should be since we're underwater..

grand jolt
#

Anyone know a good tutorial on a shader that pulses emission as well as changing the color?

orchid briar
#

@grand jolt pulsing can be done using sin + _Time.y variable

#

changing color can be done the same way with lerp + _Time.y

#
float strength = lerp(StrengthMin, StrengthMax, sin(_Time.y * 10) * 0.5 + 0.5);
float4 color = lerp(ColorMin, ColorMax, sin(_Time.y * 10) * 0.5 + 0.5);
grand jolt
#

@orchid briar aha, thanks, at least I know what nodes to use (I'm using Shader Graph, should have clarified that sorry), do you know of any videos where someone does it in graph? I like to see it visually as i'm new to Shader Graph and tend to mess things up if I do it solo ๐Ÿ˜›

orchid briar
#

sorry no clue dont use shader graph

grand jolt
#

yeah theres literally a sin and lerp node in it so i'll give them a look

#

thanks anyways

orchid briar
#

np

devout quarry
#

@grand jolt the time node should also have a sin output

grand jolt
#

@devout quarry yeah found it, just going to fiddle with things until it works, would rather use a shader than coding, waaaay more performant ๐Ÿ˜›

devout quarry
#

what do you mean?

#

you'd rather use shader graph than hand written?

grand jolt
#

@devout quarry yeah, plus SG tends to do things is a more compact way, it streamlines the code if possible, I believe

devout quarry
#

I think the opposite is true

#

It would make sense that shader graph introduces overhead and hand-written shaders are more performant

grand jolt
#

probably, I may be confusing it when compared to VFX actually

devout quarry
#

Ah right, VFX graph is very powerful

#

never used it, but I've seen some results and it's crazy

grand jolt
#

I have a bunch of mesh effects, but boy if they spawn more than 4 or 5 effects at once my PC goes "BUH..."

#

I saw the brackeys one where he made like a million particles, that was craaazy

regal stag
#

@marsh turret Have been playing around with the world position reconstruction from depth for the blit feature, finally got it working correctly in shadergraph.

#

I still don't understand exactly how it works, but it does.

lavish sierra
#

Unity hackweek is coming up and I was thinking it might be nice to have a website where one could browse shaders & graphs

#

what do y'all think?

devout quarry
#

@lavish sierra

#

this is already pretty nice

#

not sure if you had something similar in mind

marsh turret
#

ooooh, this is nice @regal stag

#

thank you for sharing

lavish sierra
marsh turret
#

you should publish this up

devout quarry
#

so with a visual preview

lavish sierra
#

yes, or rather, the visual preview is the main point

devout quarry
#

so you could load in a .shadergraph file and preview it there?

#

that would be neat

lavish sierra
#

hmm, you could, but you're still missing the point

grand jolt
#

yeah, would be nice to see the effect in action

lavish sierra
#

the "gallery" effect is the main point - it's definitely helpful to download/upload things though

#

I would link the TIGSource image crawler to demonstrate but looks like that died

marsh turret
#

what does it render now Cyan

#

i assume just a position.node

devout quarry
#

is it like this?

#

never heard of TIG source image crawler, but this is a gallery style thing

lavish sierra
#

yeah, it's like that but it's an automated crawler so a bit less organized

devout quarry
#

where would the site get the shaders from?

#

uploads?

regal stag
#

@marsh turret Yeah, it's basically what the Position node (world space) would do for objects in the scene, but as an image effect.

marsh turret
#

whre exactly did you put your c#

#

in the Create()?

#

(i'm trying to duplicate to see if I can do something similar...

regal stag
#

I put it in the Blit pass Execute function

#

It would probably also work in a separate component in the scene or something too.

#

It's just something that needs to be updated each frame

marsh turret
#

I haven't done custom renderer before so I was looking at the Blit.cs example code

regal stag
#

Yeah, there's a Blit.cs and a BlitPass.cs, you can basically copy them into your project and they should just work.

marsh turret
#

i figured your code was in the AddRenderPasses() method

#

then realised i was looking at the wrong class

regal stag
#

It would probably work there too, as I think that runs per frame each time the feature is used

marsh turret
#

you should definitely write this up tho

lavish sierra
#

@devout quarry yes, thanks to the time limitations of hackweek you'd probably have to upload from the editor

marsh turret
#

this is a whole new way to use the SRP for render stuff

lavish sierra
#

so the webgl compilation can happen therein

regal stag
#

@marsh turret Yeah I might write it up. It's likely more expensive than just using the Position.y in every shader in the scene, but it is certainly easier if you have a lot of shaders that you'd need to edit.

marsh turret
#

in my example (which I get is quite niche)

#

i only call the PP stack for "underwater", cos I can fake depth in the water shader if I'm above teh water

#

but this (should if I can work out how to make ti work nicely) allow for things like the ground fog effect you have up

#

to be ran as a post-process

regal stag
#

Yea

grand jolt
#

if you achieve that you should let Unity know, they could add it into the engine as an option

#

on the fog volume

#

perhaps

marsh turret
#

so "fake" volumetrics

#

not as computationally cheap perhaps

#

but still usable on mobile etc

#

still be issues around view angle and stuff I think

#

but getting the world position in a PP shader is huge

#

cos you can pass in other stuff like camera position, position of objects etc (e.g my water surface level)

tropic galleon
#

can a shader change an objectโ€™s collider? for the ship to react to the waves

marsh turret
#

i don't think so

#

but way I have gotten it is I have wave generator code that is lodged into my bouyancy script

#

(i say mine, I adapted it from a tutorial on water physics!)

#

that generates the waves and spits out vertexes for the surface etc

#

i then feed that data into the shader to have the shader render the surface in the right place

#

but equally the boyouncy script can also use it to determine physics of boats etc

#

so a big wave can "hit" and make a boat go up...making the wave capsize the boat etc would be for your physics scipts

tropic galleon
#

How you take hit from shader?

marsh turret
#

cyan: sorry to bother you again (cos I hate people that do that)

#

but any idea what I've done wron ghere?

#

I can see the effect working but it's also rendering a big black square covering most of my view

regal stag
#

Mmm

#

I think that's because of the depthonly/shadow caster pass messing with it. I think on the Blit feature there's a pass index that I had set to 0

marsh turret
#

aaaaah thank you

#

I was struggling with shader gaph wondering if I'd messed up

#

yaaay it works

#

i can go eat now hahah

#

wife was screaming at me to get dinner

orchid briar
#

im having a fun problem

#

...

#

AsyncGPUReadback.RequestIntoNativeArray()

#

segfaults the editor

#

... sigh

tropic galleon
#

can i get the result of the shader?

#

To work in logic

#

For example, I want to make walls like in rainbow six

grand jolt
#

@tropic galleon If your referring to blasting walls apart, thats usually achieved by having a duplicate of the wall but with a mesh thats cut into pieces, when someone does enough damage it disables the original wall, enables the breakable one and adds force in the opposite direction to fling the pieces accordingly.

But i'm not sure if they do it that way specifically in R6, or if they use some other method, also not aware of any way to make a shader effect logic like that, but i'm not an expert in shaders so someone else may be able to clarify.

grand jolt
#

Anyone know why this grid isnt animating? i'm trying to have individual control over which axis animates, i've tested both the outputs of the Vector2's straight into the offset on the tiling node and they both work, so it's something between the Vector2's and the offset input thats not working...

I take it multiply is the correct node for merging them?

https://i.ibb.co/sWnzHDk/Image5.png

lavish sierra
#

@grand jolt multiplying by zero will get you a zero

#

since one or the other input in your multiply is always a zero, the output will always be zero too

#

assuming you toggle between animating X or Y and aren't doing a diagonal (though even in that case only 1/4 scenarios work as intended)

tropic galleon
#

I think there is some kind of mechanism for generating new walls.

orchid briar
#

Does OSX not support RFloat texture format?

#

RenderTextureFormat.RFloat

#

Trying to render an object id to a texture with this shader:

#
Shader "Hidden/ObjectId" {
  SubShader {
    Tags { 
      "PixelPerfectPicking" = "ObjectId" 
    }
    Pass {
      CGPROGRAM
      
      #pragma target 3.0
      #pragma vertex vert
      #pragma fragment frag
      #include "UnityCG.cginc"
      
      UNITY_INSTANCING_BUFFER_START(Props)
        UNITY_DEFINE_INSTANCED_PROP(float, _ObjectId)
      UNITY_INSTANCING_BUFFER_END(Props)
    
      float4 vert (float4 vertex : POSITION) : SV_POSITION {
        return UnityObjectToClipPos(vertex);
      }
    
      float frag () : SV_Target {
        return UNITY_ACCESS_INSTANCED_PROP(Props, _ObjectId);
      }
      
      ENDCG
    }
  }
}
#

But it just comes out as 0

#

yes _ObjectId is set ofc, it all works on windows

#

I tried without instancing also, no dice.

meager pelican
#

return 0.5 and see what it does.

#

you could always try some kind of encode/decode float thing too. With a different texture format, depending on what precision you need.

worldly drift
#

Could anybody explain the positionNDC from the URP shaders to me? As far as I understand NDC space is just Clipspace devided by w but the calculation in Core.hlsl looks different

#
float4 ndc = input.positionCS * 0.5f;
input.positionNDC.xy = float2(ndc.x, ndc.y * _ProjectionParams.x) + ndc.w;
input.positionNDC.zw = input.positionCS.zw;
regal stag
#

@worldly drift I don't fully understand the function but it's the same as what ComputeScreenPos does. I think it's just remapping the clip space ranges. I believe it's intended to be used in the vertex shader and passed into the fragment, where you would then do the division. float screenPos = IN.positionNDC.xy / IN.positionNDC.w; before actually using it.

worldly drift
#

yeah seems like this is the intended usage. Its just confusing that its called positionNDC and I am really confused by that calculation. Why would anyone want to add w to xy?

regal stag
#

Ah, I think I get it

worldly drift
#

_ProjectionParams.x seems to be responsible for flipped projection matrices but I would think they would multiply z by this value then.

regal stag
#

I think clip space is in the range from -w to w, so:
-0.5w to 0.5w after the first line
0w to 1w after the second
0 to 1 after dividing by w

#

For both x and y axises

worldly drift
#

yeah that absolutely makes sense

#

I thought NDC was -1 to 1 though

#

so clipspace is -w to w and NDC is 0 to 1?

regal stag
#

This is something I've been confused about from reading things online, but that's what makes sense to me.
I've seen things like clip space being in a -1 to 1 range instead, which I think is true for an orthographic projection, but not perspective based. I haven't been able to find much on NDC space, one forums answer I read mentioned -1 to 1, but I've also seen an article mention 0 to 1 before, and that certainly makes more sense to me here.

meager pelican
#

Vertex shaders output clip space in the rage of -1 to +1. But the w component is the perspective divide, and happens in hardware, due to SV_POSITION and/or other semantic such that it's prospectively correct. So the farther away it is, the more it's "divided" and the smaller it gets in the -1 to +1 xy range. That shrinks everything towards the center at 0,0 when you think about it. Which gives you a frustum "cone" type of thing. ...wider/higher and covers more area at distance.

Then, as mentioned, there's that damnable Direct-X flipped matrix thing in the mix inconveniencing millions of programmers for what will probably be generations.

worldly drift
#

so it seems like positionCS is the space that Unity actually uses for clipping and vertex transformation because it is usually put in SV_POSITION and positionNDC is kind of an additional space to be used for some custom screen space magic?

meager pelican
#

Well the hardware uses it. As well as the z value for early depth testing.

Good find, and yeah.

#

It's the hardware rasterizer, as I understand it, that needs all this stuff and does the clipping in most cases. but you can turn things like hardware depth testing off.

worldly drift
#

it just seems that the "real" NDC would be the positionCS after it got devided by w by the rasterizer

regal stag
#

Yeah it is, but I think that can't be done in the vertex shader so isn't in the function

worldly drift
#

positionNDC just seems to be some additional space that you could also get by positionCS *0.5 + 1 in the fragment shader

#

Yeah it is, but I think that can't be done in the vertex shader so isn't in the function
@regal stag yeah makes sense

#

but still confusing var naming

regal stag
#

Yeah it confused me when I first saw it too, meant to look into it again so glad you brought it up

meager pelican
#

Yeah, I agree that the naming is iffy. But in that case it's "just a structure member" in the v2f. Name it asdf9df9asfd if you want. The hardware plays games according to the semantic attached. Fun stuff.

And all IIRC.
And bless bgolus.

worldly drift
#

I was just really glad about the new naming convention with putting the space as a postfix. At least till it tricked me ๐Ÿ˜‰

meager pelican
#

it just seems that the "real" NDC would be the positionCS after it got devided by w by the rasterizer
@worldly drift

I think that's the "real clip space". But it's done in hardware. So AFTER the divide, it's clipped if outside the range.

#

Per pixel basically. But the frag isn't called for a logical pixel unless it's in range.

worldly drift
#

Thanks to both of you @regal stag and @meager pelican. I was really getting mad about this as I just didnt get it ๐Ÿ˜…

meager pelican
#

Speaking of clip space. Don't get me started on all these "huge single-draw-call meshes" where if one single itty-bitty pixel is on the screen the GPU has to process the entire mesh, and it's the entire terrain or something due to some misguided developer's intent at reducing draw calls.

#

๐Ÿ˜‰

grand jolt
#

@lavish sierra not sure what you mean, both the Vector2's work, the only thing that seems to be wrong is the way they are combined.

in runtime if I want either axis to animate I just toggle the appropriate bool, or both if I want both axis to animate.

since one or the other input in your multiply is always a zero
dont understand this, of course it's zero until I toggle the appropriate bool in the inspector?

regal stag
#

@grand jolt You are multiplying the results of the branch. If the top branch is true (x=time, y=0). The bottom branch is false (x=0,y=0). Multiply them together and the output will be (0,0), so no movement.

grand jolt
#

wow, so basically, when you do shaders you have to think completely backwards to conventional logic.....niiiiice Unity

#

i'll give it a try, cheers

regal stag
#

Instead of bools & branches you could also just use floats to control the speed of the offset, and set it at 0 when not animating

grand jolt
#

yeah was planning to look into the speed, it's just a basic grid shader, I had one done ages ago but accidentally deleted it.....now I gotta learn it all again lol

sonic plinth
#

So a while back I asked how I could create a drop shadow behind a part of a texture. Though I would like to make the shadow longer, not sure how to go about doing that though.

sonic plinth
#

Can't really figure it out..

rapid acorn
#

Is it possible to make a toothpaste behaviour (a semisolid cream behavior)? Like how it gets out of a tube

worldly drift
#

@sonic plinth Maybe you could scale the uv coordinates you use to sample the texture

sonic plinth
#

@worldly drift Not sure how to. Still relatively new to the Shader graph

worldly drift
#

your sample texture 2d node have a uv input

#

If I remember correctly there should be a UV node which you can put in there. That by itself wont change anything. But you can then manipulate it (e.g. multiply it by a scale factor) before putting it into the uv input

sonic plinth
#

Multiplying it just makes it go into the corner for some reason.

worldly drift
#

yeah thats because 0,0 is in one corner

#

you would have to offset it than scale and offset it back

#

as uv space goes from 0 to 1 it should work if you substract 0.5 than scale and then add 0.5 again

#

this would scale around the center

sonic plinth
#

No doesn't seem to work

#

Simply just made it smaller

sonic plinth
#

I don't think that method is gonna work. Even if the shadow is bigger, it would be completely black on some places since it would only make it bigger. not longer.

grand jolt
#

excuse me, but how does one learn shader programming? I've been trying to find out how to make a grass geometry shader and it hasn't been going well at all. It seems there are little to no sources which document the process step by step (sturdy explanations).

devout quarry
#

@grand jolt this is a good tutorial

grand jolt
#

Tysm, I came across that one, but then wondered if possible how I could spawn quads through the geometry shaders and place a custom grass texture on them

#

You don't have to look for it, it's ok. Was just wondering, ranting over the low availability of comprehensive resources. But ty for your kindness.

grand jolt
#

oh! I'll look into it

#

tysm @devout quarry

atomic echo
#

Is there a way to set a global shader variable (ex: Shader.SetGlobalFloat) in editor? My current workaround is starting playmode, moving to the value I want, then closing playmode... but that's super-hack of course.

low lichen
#

@atomic echo Does calling Shader.SetGlobalX outside playmode not work?

atomic echo
#

Haven't tried. Didn't want to make an editor script if there's already a UI for it.

low lichen
#

@atomic echo There definitely isn't

atomic echo
#

Cool

molten halo
vocal narwhal
#

I wonder if it's the add ๐Ÿ˜ด

molten halo
#

๐Ÿค”

#

I mean I'm just combining the color values that are clearly not making it pure white at the start.

vocal narwhal
#

you're adding values together, and getting an additive result, I don't really know what you expect

molten halo
#

then what do?

#

how do make work? ๐Ÿฅด

vocal narwhal
#

what do you want to happen? I don't understand your description

molten halo
#

I'm passing in the texture's color to be blended with another texture

#

and I can't(shouldn't) include the alpha value, so I tried just combining the other 3 together.

vocal narwhal
#

if you don't want the alpha just use a split and a combine

molten halo
#

WIIIIIITCH!

#

Now I'm having an issue with the second texture. I know I'm doing it the wrong way, but I don't know what the right way is.

#

see how the texture is whiter than the first one (first one being the one from the previous issue), but when I pass this one into the Blend node, they are both the same brightness.

#

I need the chunks to stay brighter.

#

don't worry about the alpha stuff on the bottom

molten halo
#

I wish the nodes had tooltips. xD

molten halo
#

Using the x2 Add node approach here seems to have worked.

heady jewel
#

I was able to save it a few minutes ago

#

Also I can't add anything, can't disconnect anything and can't copy past anything

#

Same thing if I create a new shader

#

I can't even move any nodes

devout quarry
#

@heady jewel that's a bug

#

You need to update your SRP version

amber minnow
#

Hello, does anyone know if it's possible to blend terrain chunks together? I am getting seams in places. They are set to the same grouping ID. Cheers

sonic plinth
#

Anyone able to help with what I talked about earlier? Scroll up a little to find it. Don't really wanna post the same thing again

amber saffron
#

@sonic plinth basically, a drop shadow is similar as the outline here : https://www.youtube.com/watch?v=MqpyXhBIRSw
But you offset the UVs in the direction where you want the shadow to be

Thanks to NVIDIA for sponsoring!
Learn more about NVIDIA Studioโ–บ https://nvda.ws/38AaA8K
Razer Blade Studio laptopsโ–บ https://www.razer.com/studio

In this video we create outline effect using 2D Shader Graph!

โ— Learn more about 2D Shader Graph: https://youtu.be/5dzGj9k8Qy8
...

โ–ถ Play video
#

IF you want to make the shadows bigger than the object. Else, if you want it to have the same size, just sample the texture with a UV offset and pick the alpha to have your "shadow mask"

#

(Sorry, I put the wrong link, corrected)

sonic plinth
#

If I just make the shadow bigger you can see where its fully black. I just want to make the shadow reach further out.

#

having it be bigger won't do that

amber saffron
#

I'm not sure to understand what you mean here.

#

But the shadow can not go further than the sprite's mesh itself

sonic plinth
#

That's not what I meant, I'll show a picture of what I mean. Give me a moment so I can get it back to when it was bigger.

#

The shadow length is the same as before.. Just now you can see the inner part of it

amber saffron
#

That's not what I was saying. Have you watched the tutorial ?

sonic plinth
#

Alright I'll watch it, I thought it was using the same method as I tried before.

thick fulcrum
#

I believe @sonic plinth wants to fade the effect the further out it gets, perhaps a blur might do this better than an outline.
Simplest is probably method currently in use but apply it two or three times at different sizes with different opacities.

#

but would be better in one go if possible

sonic plinth
#

Yeah I just want to fade the effect. I can try that but it might look hard at some positions?

thick fulcrum
#

possibly because it's getting scaled up... the alternative is to do an offset in multiple directions. but that may be slower I don't know

#

some sort of blur would be better as it might not even need scaling up

sonic plinth
#

Not sure how to go about bluring it though

thick fulcrum
#

it's not perfect, but might do

amber saffron
#

This blur is also doing the multiple samples trick.

#

If you want to save perfs, the ways to go would be using signed distance fields, but this requires a bit more pre-processing of the sprites

sonic plinth
#

Doesn't seem like there's an actual optimal way to do this

marsh turret
#

use a texture @sonic plinth

sonic plinth
#

What do you mean

heady jewel
#

@devout quarry after restarting unity at least 10 times it fixed by itself

devout quarry
#

Yeah but still

#

What you said is a known bug with shadergraph that was fixed in an update

heady jewel
#

I have the latest version of URP and Shadergraph

lavish sierra
#

@heady jewel try turning on the main preview in the shadergraph

near basalt
#

I have exactly the same bug as well

#

trying to find a fix for it

devout quarry
#

updating SRP fixed it for me

near basalt
#

how do I do that ?

devout quarry
#

in package manager

#

select URP or HDRP package whichever one you're using

#

and update

#

and if you don't see an update, make sure you enable 'view preview packages' so you see the latest ones as well

near basalt
#

not sure it shows me anything, I have latest 8.1 right now for URP and 2020.1.0b11 for editor

#

managed to fix it by deleting a node, after that it started to work

devout quarry
#

weird, updating to 8.1 fixed it for me

near basalt
#

oh, I had that disabled

devout quarry
#

and you have 8.1 installed?

near basalt
#

yes, just updated

devout quarry
#

And that fixed the issue?

near basalt
#

nope, what fixed, was deleting a node after that it started to work

devout quarry
#

@heady jewel you on 8.1 as well?

near basalt
#

at least it works for now

golden crest
#

So I figured out the reason this was crashing was because of some particle effects in my scene. If i keep them turned off or on a different layer it doesn't crash. I think that's weird, but it should be fine. I still can't figure out why this isn't rendering the objects on the layer though.

green abyss
#

Hullo! I'm trying to create a health bar shader kinda similar to the league of legends healthbar. This is what I have so far and it all works good.https://hatebin.com/zpnocnepff

#

Here's what it looks like

#

So on to my question, I've been tinkering with this for hours and I just can't seem to get it to work. In league of legends when you get a shield, it sort of shifts this whole thing to the left, and tacks the shield on the end of the healthbar

#

I can't seem to get that to work

#

See my terrible picture for reference

#

Anyone have any suggestions? Thanks in advance!!

golden crest
#

can you add the shield amount to the maximum health? that would shift the current hp left and let the shield part show behind it if you make the fill amount for the shield (current hp + shield) / maximum hp

#

ive only made hp bars using UI canvas tool but i think it should work

green abyss
#

Totally!! I think that would work

golden crest
#

u might need 2 max hp values one with shield and one without so u dont heal for your shield amount

#

if that makes sense

grand jolt
#

is it possible to place flowers on unity terrain with the petals facing up and the stem facing down, but using the terrain system for optimization?

fervent tinsel
#

trying stochastic texturing on sg/master-stack ๐Ÿ˜„ Warning in Graph at Assets/New Shader Graph.shadergraph at node Sample Procedural Texture 2D: Validation: Sample Procedural Texture 2D Node is not allowed by HDRP implementation

fast drift
#

I feel like this is the best category to ask this - is there a good way to combine multiple textures via script at runtime so they can be assigned to a material as a single texture? I have a model that uses only one texture, but since I'd like to let the player choose colors for different parts individually, I'd like to be able to split it into multiple textures and then stack them on top of one another before applying them to the material. Thanks in advance!

fervent tinsel
#

could use custom render texture for it

#

or substance plugin (need substance designer to authoring)

#

doing the coloring realtime on a shader basically only requires one extra texture lookup tho, it shouldn't be that expensive

fast drift
#

Custom render texture?

#

I'm just looking to do it with as few additional requirements as I can, and I didn't really want to edit the shader unless I have to because I know basically nothing about shaders. I'll probably have the texture split into 5 or 6 pieces from what I recall (not at my PC right now).

green abyss
#

Would it not just be easiest to split it into multiple textures?

fast drift
#

I'm not sure how difficult that would be. I have like zero experience with texture mapping and I didn't make the model myself

#

I feel like sticking with one texture is convenient because I could have the textures merge on the editing screen, save the merged texture, and just load that when it actually needs used instead of having to retrieve each texture individually?

#

That's just my thought process though, I'm still pretty new to Unity so I'm not well-versed in what the best options are for these kinds of things.

fervent tinsel
#

for coloring part x of the texture, you'd just have a mask texture with specific color and then tint that masked area from original texture with the preferred color

#

if you need only 4 custom colors, it's simple, just one mask per texture channel, for more colors, you need to make bit more complicated shader

green abyss
#

Is this like a Minecraft custom skin type deal?

fast drift
#

No, it's for a fighting game where I want to let you choose your character's shirt, pants, hair, etc colors individually instead of using preset color combinations.

#

So you're still choosing from a preset collection of textures for each section but you can use any combination of those.

#

But obviously I don't want you selecting those on the character select, so there's going to be a separate customization screen a la Tekken 7. In my head it makes the most sense to merge everything into a single texture and save it from the customization screen so I can just load that single texture from the character select.

#

This may not be the best way to do it so I'm open to other suggestions but that's my first instinct.

pliant bridge
#

https://www.youtube.com/watch?v=_Q3YGZFRv6s
Oculus Quest Liquids!
Download here: https://github.com/aniruddhahar/URP-LiquidShadergraph
Also, you don't need VR to run it, it can be used in any URP project.

Procedural Shader graph for interactive liquids in Unity URP
This is a shadergraph to 'fake' interactive liquid simulation in Unity's Universal Render Pipeline, made with the goal to bring really cheap, and adjustable interactive liquid behaviour to lightweight rendering appli...

โ–ถ Play video
scenic furnace
#

that is very cool! I think I'll have to dive into that to see how you made it

lavish sierra
coarse path
#

Shader noob. I've got a basic triplanar shader. is it possible to render different textures at different heights?

#

while keeping triplanar texturing?

slow bear
#

I want to try my hand on raymarching/SDF shaders for volumetric effects but _what happens when the camera intersects the geometry that hosts the SDF shader?

#

I mean, if I have like a cube with a volumetric cloud effect, does it get cut off as soon as the camera enters one face of the cube?

#

Shader noob. I've got a basic triplanar shader. is it possible to render different textures at different heights?
@coarse path yes, if you use the heightmap info to sample the right texture

violet kelp
#

@regal stag do you think its worth investing learning shaders ? i am normally a C# coder, i am doing a solo project so i think i need to learn other aspects of game development such as shaders, i saw your recent post about shaders, but was wondering if its worth invest in learning shaders or shader graph, i really like shader graph (because its node based and requires 0 shader coding knowledge), so what would you suggest to someone that is new to game development and will go solo iindie for a while ?

grand jolt
#

I'm trying to render a render texture to a plane, but the plane is just white? What am I doing wrong? ๐Ÿค”

grand jolt
#

Fixed: Even though I set my Render Texture in the Blackboard, it somehow didn't get set inside the material itself. APplies it there and does show the render texture

plush bane
#

Hello! I have question about "Position" node. When I select space "Object" will the output values be from -1 to 1 ?

regal stag
#

@plush bane Not necessarily, no. The positions will depend on how the model was made & imported, they can be outside the -1 to 1 range.

#

@violet kelp I'd say learning shaders is worth it, and shadergraph certainly makes it easier to get started.

plush bane
#

@regal stag I can't create a very simple thing in shader graph. A gradient thing. Object is black at bottom (Y axis) and get greener and greener on top.

#

The idea was to use Position node. The bigger the Y, the greener the thing

regal stag
#

You can still assume the positions are in a -1 to 1 range in order to do the gradient, but they don't have to be

plush bane
#

But I would have to know min and max in order todo this

regal stag
#

If you want the gradient to work for all meshes (and be exactly black at the bottom of the mesh, and green at the top), then yes, you'd probably need to know the mix/max and send them in using properties.

#

Or model them so they always range from -1 to 1.

#

Alternatively, you could UV map the model by projecting uvs from the side, and use the UV.y as the gradient instead.

plush bane
#

Hmm thanks will try

grand jolt
#

I want to combine 2 camera's but not as layers. but by Mask. How would I do this in HDRP ?

#

Example (good golly what amazing art work)

plush bane
#

@regal stag wich node gives UV cordinates?

#

Ah UV

#

Just have to split

plush bane
#

Interesting. I have an FBX object imported. It's not rotated, scale 1, etc. But when it comes to shaders it's Y is swapped with Z. How is that possible?

regal stag
#

Is this from Blender? Because I know blender is z-up, while unity is y-up. There's probably settings to fix it during export. (You might have to look at some tutorials as I've never really exported things properly lol)

fervent tinsel
#

@violet kelp you dont really need to understand text based shaders with shader graph, only if you need some custom functions not provided by sg. Writing text based shaders yourself from scratch with current srps is not even feasible at all

#

That being said, main thing to understand about shaders is that they are just math

low lichen
#

@fervent tinsel

Writing text based shaders yourself from scratch with current srps is not even feasible at all
For lit shaders, I understand what you mean. For unlit shaders, it's no different except some macros if you want to support SRP Batcher.

fervent tinsel
#

@low lichen only for lwrp/urp afaik

low lichen
#

Yeah, I should have added that. I've only used URP

fervent tinsel
#

Hdrp complicates even simplest things

#

Some of the old style passes still work tho

low lichen
#

Surely there are some includes you can add that do most of the work for you?

fervent tinsel
#

The issue with working on hdrp shaders manually is that their api evolves a lot between versions. Keeping your custom shaders up to date between hdrp versions is a monumental task

#

I've done it in past and wouldnt recommend to anyone

#

Just use SG if you can and your port to newer version is one button press (resave for graph)

amber saffron
#

I would recommand putting all you code in a custom SG function node, and let the rest live by its own

fervent tinsel
#

Exactly

grand jolt
#

Can someone help me with my issue that I described above?

#

(the nice art work)

amber saffron
#

Render in two RT, and mix them in a dedicated shader ?

grand jolt
#

And then how do I apply this dedicated shader to the full screen?

amber saffron
#

Apply it to a UI quad ๐Ÿ™‚

grand jolt
#

Oh - interesting

amber saffron
#

Or, you can just render one, and apply it with the mask transparency as a full screen UI image

low lichen
#

Do you need the mask to be able to blend between the two? If you need it either or, then you should be able to use the stencil buffer, assuming HDRP supports that.

amber saffron
#

HDRP doesn't support that.

grand jolt
#

it doesn't

low lichen
#

You could do a trick with the depth buffer though

grand jolt
#

I eventually need the masking of the 2 camera's to be based on the distance to a certain game object in the world

low lichen
#

Just draw a quad in front of the camera with depth only to block a portion of the screen

grand jolt
#

But I can mix the mask in that case

low lichen
#

Then draw the second camera after drawing the first

grand jolt
#

I think the applying to a UI Quad is def more of a solution I like

low lichen
#

If you need to blend, then yeah you need to do it in a custom pass

grand jolt
#

I don't think @amber saffron meant a custom pass.

Just render both camera's to a Render Texture and mix them in another shader based on the Mask

low lichen
#

That other shader would be the custom full screen pass

grand jolt
#

Now all that's left is how to create a mask in realtime ๐Ÿ˜…

low lichen
#

What's the effect you're going for?

grand jolt
#

In this image I'd like the mask to be this

#

squegly line = solid color ofc

low lichen
#

So you want the shield sphere to sort of act like a portal to see something else?

grand jolt
#

yea basically

#

but only once you're close enough

#

so hence the combination of camera's based on the mask

#

which in turn is based on distance from shield sphere

low lichen
#

So the portal image would appear as a growing circle as you get closer to the edge of the sphere?

#

With faded edges?

grand jolt
#

yup

#

exactly

amber saffron
#

If you know that the mask is based on a sphere, you could also do all this with one camera

#

and make a custom shader applied to all the objects, that "cuts" them based on a distance test

grand jolt
#

Ye I was thinking of that first as well - but I don't like that approach for a multitude of reasons

#

So I'd like to continue with my current "thought train"

amber saffron
#

Might lead to some shadowing glitches tough

grand jolt
#

Yeah, that's what I anticipated, which is fine

#

How would you go about creating a mask in real time based on the sphere?

#

in this case - from a different angle the mask would obv look a bit different cause It's colliding with geometry

low lichen
#

But also the white part might include some of the sphere in the distance?

#

How close is close enough to see this portal image?

grand jolt
#

Should be based on a distance number eventually

#

first things first though is creating a mask based on how and where the sphere collides with other geometry

#

But also the white part might include some of the sphere in the distance?
@low lichen how so?

low lichen
#

Because the parts of the sphere that are far enough away from the camera would not be included in the mask?

#

To form this portal circle with faded edges

#

In the last screenshot, the camera is closer to the left edge of the sphere, so maybe only that part would not be in the white mask

grand jolt
#

in this angle the mask would look like this

#

it'll be a mask based on view basically

low lichen
#

but only once you're close enough

#

So in that screenshot, is the camera close enough?

grand jolt
#

oh yeah, forget about that statement

#

I'll need the mask nonetheless

#

for some other stuff

#

I just need to be able to create a mask based on the Main Camera view

low lichen
#

I can describe how I would do it in URP, but I don't know what translates to HDRP

grand jolt
#

Give it a try - I'll take anything over nothing ๐Ÿ˜„

low lichen
#

If you have a depth buffer of the scene geometry, then you can use that buffer to draw the sphere to a separate mask render texture with a custom unlit shader with ZTest Greater and just return full white in the frag shader

#

Then, assuming the mask render texture was cleared to black, you'll have a texture that is white wherever the sphere won't be visible

#

When you set the render target, you can use a depth buffer from another render texture, like the depth buffer of the scene you render before all this.

grand jolt
#

lol, seriously though - I understand the thought process here

#

but no idea how to do this in HDRP >.<

low lichen
#

Not sure how scriptable it is. Don't think it has renderer features like URP.

#

Apparently is has Custom Passes instead which use the post processing volume system, I think

amber saffron
#

There is no "pp" volume system, just "the" volume system

#

But yes, you could use a custom pass to render only the masking sphere with the scene zbuffer, to a separate buffer (custom pass color buffer), and use it a the mask.

grand jolt
#

But yes, you could use a custom pass to render only the masking sphere with the scene zbuffer, to a separate buffer (custom pass color buffer), and use it a the mask.
@amber saffron sounds difficult - got a tutorial or reading material somewhere for me?

amber saffron
grand jolt
#

any other way except for this custom pass to generate the mask I desire?

amber saffron
#

Hum :/
Add a camera with clear depth only, a black BG, and render a inward facing opaque white sphere only there, in a RT

#

That way you will keep the depth of the object, and parts where the mask is not behind it will be white.

grim abyss
#

Does anyone know why my shader won't give a proper outline with color on a image with white borders?

low lichen
#

@amber saffron Won't that clear the depth of the scene though? Or does Clear Depth Only mean it only clears color and not depth?

grim abyss
#

Maybe something to do with the colors being added?

amber saffron
#

Sorry, I indeed inverted the idea : clear color only, not depth ๐Ÿ˜„

grand jolt
#

@amber saffron I can't seem to see the "Clear color only option?

low lichen
#

Is there an event hook for right before the camera renders in HDRP? You could then turn off clearing on the camera and clear just the color manually using GL.Clear

amber saffron
#

Hum, sorry, that was a wrong memory I had of the setting.
It's not possible to not clear the depth in HDRP

#

So the custom pass option is probably you best choice here.

grand jolt
#

I tried with the Culling Mask of the camera, but that leaves me witht he full mask instead of the mask that also incorporates the surrounding geometry

#

It'll do for now for testing, But I'll eventually have to look into custom Passรฉs - thanks!

amber saffron
#

@grand jolt For the sake of seeing if it's possible, I made something that looks like your effect by using a custom pass.

grand jolt
#

Care to share? ๐Ÿ˜„

amber saffron
#

Yep, cleaning up a bit and will send a zip

grand jolt
#

You're a god send - I tried 2 different camera's for testing purposes and using RT with a hand made 50/50 mask - but my 2nd RT seems to lag compared to the first so idk what I am doing wrong

#

(imma try and share a video in a couple min)

#

check Game Window - there is a mask - and I got to use 2 Camera's but as you can see it seems to lag behind a little and isn't smooth at all

amber saffron
grand jolt
#

U went insta with that just released LTS version :p

amber saffron
#

Oh, yeah, sorry. You should be able to open it in 2019.3 still

grand jolt
#

Np, downloading LTS now ๐Ÿ˜„ hehe

#

Thank you for the help

#

btw,have you looked at the video? I tried to do it. but the cameras seem to lag in relation to one another. any idea why?

amber saffron
#

I need to be up to date

#

Maybe depends on the rendering order of the cameras ? If the one that write to the RT is rendered after the main one, then the display in the UI is kind of delayed to the next frame.

waxen gorge
#

Is there any reason for a scrollview to not be properly masked when rendered through a RenderTexture + Camera?

grand jolt
#

Maximum number (256) of shader global keywords exceeded
How can I fix this?

low lichen
fair sleet
honest hull
#

Alpha geometry is queued separately from normal geometry (so it is more efficient) ||@fair sleet||

fair sleet
#

ok but what's the difference between normal geometry and alpha tested geometry?

regal stag
#

AlphaTest refers to shaders that use the hlsl clip function to discards pixels if their alpha is below a certain alpha cutoff/threshold

fair sleet
#

that sounds like exactly the thing I need
how do I use it?

regal stag
#

clip(alpha - threshold); in a fragment shader

#

The alpha is commonly obtained from a texture, and a threshold could be set as a property

fair sleet
#

that's pretty convenient
I need to set the RenderType in the shader tags to "Transparent" right?
thanks

regal stag
#

I think there's a "TransparentCutout" that's typically used with this kind of thing

fair sleet
#

ok I will use that

#
float angle(float2 a, float2 b)
            {
                return (acos(dot(a, b)) + 1)/2;
            }

Is this function correct? It should return the angle between two vectors as a range from 0 to 1

devout quarry
#

I might be wrong but dot will return a -1..1 range right?

#

and acos is cos^-1? so it will return an angle in degrees?

#

and then you add 1 to that angle?

fair sleet
#

wait
I read the docs wrong
I thought acos returned a value from -1 to 1

devout quarry
#

I think if you lose the acos, it should work?

#

dot returns [-1,1] range, so you add 1 to get [0,2] then divide by 2 to get [0,1]

fair sleet
regal stag
#

Dot product returns 1 if the vectors are aligned and 0 if they are perpendicular (90 deg apart), (and -1 for opposite directions), so isn't the same as angle alone. I think the acos is to convert it to an angle in radians - might be between 0 and pi then? So if you want 0-1 range, divide the acos result by pi? Bit of a guess

devout quarry
#

that makes sense to me

fair sleet
#

it seems like converting the value returned by acos worked

#

man the documentation is so bad
it doesn't say if acos is in radians or degrees or (-1,1)

devout quarry
#

so just like this? return acos(dot(a, b))/pi;

regal stag
#

I think most times it's radians when dealing with calculations

fair sleet
#

you're right
for some reason I thought it would return a range between -1 and 1

devout quarry
#

cos takes in an angle and returns -1 to 1 range

#

acos is inverse, so other way around

fair sleet
#

I got confused again (doing return degrees(acos(dot(a, b))) looked like it worked ) but it seems like return acos(dot(a, b))/pi; works perfectly.

#

actually nevermind
it gives me the right angle but it's clamped between (0 and 1) so I can't figure if the angle is clockwise or anti-clockwise (i need something like Vector2.SignedAngle)

fair sleet
#

Managed to some research and settled on this.
I only need the angle between the vector and the y axis so this works.

float SignedAngleOy(float2 a)
            {
                return (atan2(a.x,-a.y) / pi+1) /2;
            }
grand jolt
#

I don't get why it works.

#

In fact, I don't get why the whole shader works. The sampling itself fills the mesh but then a hole in an outline is rendered somehow.

near pond
#

shader made with shader graph are all supose to work with webgl or not?

#

im trying hard to have my water shader work on a tilemap and it work fine in editor but not loading in webgl

#

not sure what im doing wrong

grand jolt
#

Holy heck, I finally got it. This shader extends the object's silhouette beyond its original edges in the color buffer and then subtracts the original silhouette to get the outline. Holy shit was I slow to figure that one out.

lavish sierra
gloomy oasis
#

Hello, I would like to know how I could do to have the bottom of the water while keeping my wave effect above.
Anyone have a little help or tip ?

cosmic prairie
#

@gloomy oasis I guess it's placed on a cube, so try multiplying the wave texture with max(0,worldNormal.y), or lerp with this normal value between the top effect and bottom effect, whichever works best

gloomy oasis
#

yes it's placed on a cube and i will try ty

civic mortar
amber saffron
#

You will need at least a 3D noise for that. 2dimensions for uv, and 1 for time

#

If you don't have this, it will be a 1 dimension animated noise.

civic mortar
#

I just want the noise to move horizontally

amber saffron
#

OR you can juste scroll the uvs

#

ok

#

add the tilling/offset node

#

and input the time in the offset vector, to make the uvs pan

civic mortar
#

And how can I turn time into a 2d vector?

tidal rover
#

doesnt the time node output a float? should just combine those 2 together with a node

civic mortar
#

What kind of node?

#

I'm just starting

amber saffron
#

vector2D node

tidal rover
#

dunno? append vector, does that exist?

#

Remy prolly nows more specifics about it

civic mortar
#

Ah, should've just searched that

amber saffron
#

Yes, the append node exists, but in that case the simple vector2D is the same

civic mortar
#

When I insert that into the alpha of the main node, literally nothing happens. Why?

amber saffron
#

Did you set the master node to be transparent ?

civic mortar
#

I don't know what that means, so probably not

amber saffron
#

click on the cogwhell in the top right of the master node, you will probably understand what I'm saying then ๐Ÿ™‚

civic mortar
#

Ah! Thanks

fickle jay
#

Hello. I tried to use "Transparent shader with depth writes" from there: https://docs.unity3d.com/Manual/SL-CullAndDepth.html and it doesn't work as intended. The result corresponds to the picture to the left. I also tried this one and got the same result: http://wiki.unity3d.com/index.php?title=AlphaVertexLitZ

Here is a test project I made to showcase the problem: https://github.com/QuasiStellar/test
Shader itself: https://github.com/QuasiStellar/test/blob/master/Assets/Materials/transparent.shader
Script that applies shader to all materials: https://github.com/QuasiStellar/test/blob/master/Assets/Scripts/NewBehaviourScript.cs

regal niche
#

Hi everyone ! How do i use a shader for a terrain in unity 2019 2.6 f1 ? thanks a lot !

amber saffron
#

Same as before : create your shader, create a material that uses this shader, assign the material to the terrain in the terrain settings.

regal niche
#

ah ok cool thanks ! that's what i tried but it says "can't assign materials with shaders which need tangents geometry on terrain, use shaders in terrain/nature instead" but i cant find the terrain/nature tab ๐Ÿ™‚

amber saffron
#

nature/terrain

fervent tinsel
#

like, how does the new SG system validate this?

#

I have similar structure already as on current SG nodes with same interfaces but it still keeps telling it's not compatible

fervent tinsel
#

so it's not the node structure but there's apparently something else that defines what this is compatible with

#

some list somewhere?

#

ah, found it, it needs to be listed at com.unity.shadergraph/Editor/Generation/TargetResources/NodeTypes.cs

fickle jay
#

Why was my message deleted?

fervent tinsel
fickle jay
#

No, after that. I just asked why it was ignored.

low lichen
#

@fickle jay I tested your shader and it works fine for me. You're not using URP, are you?

fickle jay
#

Probably not. Can you explain?

low lichen
#

And have you tested this shader without your script?

#

Just creating a new material using this shader and use it on an object in the scene

fickle jay
#

That works as intended.

low lichen
#

So it's an issue with your script, not the shader

#

I noticed you use renderer.materials in your script. Are you expecting the renderers to have multiple material/submeshes?

fickle jay
#

Just creating a new material using this shader and use it on an object in the scene
In this case I just make brand new material.
And script changes shader of the existing ones.

#

Yes, it has multiple materials.

low lichen
#

You'll probably need a different approach for that. What you're probably seeing is the submeshes overlapping.

#

Because to the GPU, they might as well be completely separate objects

#

What's happening now is this:

Draw Renderer:
  Mesh 1
    Depth Only Pass
    Transparent Pass
  Mesh 2
    Depth Only Pass
    Transparent Pass
#

What you want is:

Draw Renderer:
  Mesh 1
    Depth Only Pass
  Mesh 2
    Depth Only Pass
  Mesh 1
    Transparent Pass
  Mesh 2
    Transparent Pass
fickle jay
#

The only difference between these materials is color, in fact they are just pure color without any texture or anything. Does it make it easier?

low lichen
#

That doesn't affect the problem

fickle jay
#

(

low lichen
#

If you create a new material with this shader and apply it manually to one of your models with multiple meshes, does it look the same as if you ran the script?

#

Minus the difference in color

#

And you'll have to add it multiple times for each submesh

fickle jay
#

Yes, the same.

#

What you want is:

Draw Renderer:
  Mesh 1
    Depth Only Pass
  Mesh 2
    Depth Only Pass
  Mesh 1
    Transparent Pass
  Mesh 2
    Transparent Pass

Can I set this order manually in the shader?

lament pagoda
#

why does some of my shadows change, depending on where i look and am in the game?

low lichen
#

You won't be able to do it in a single shader. You'll have to split the passes into separate shaders, then have your renderer materials setup like this:

Materials:
  Depth Only // < That's for mesh 1
  Depth Only // < That's for mesh 2
  Regular Transparent // < That's for mesh 1
  Regular Transparent // < That's for mesh 2
#

@fickle jay Here's a depth only shader:

Shader "Custom/Depth Only" {
    SubShader {
        Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    
        Pass {
            ZWrite On
            ColorMask 0
        }
    }
}
#

It's just your original shader with all the transparent stuff stripped out.

#

@lament pagoda Change how?

fickle jay
#

He probably means that shadows are more detailed when you're close to them.

lament pagoda
#

no

#

or well

#

wait a sec

#

sorry for the bad quality. its only bad because max upload is 8mb on discord

fickle jay
#
> Materials:
>   Depth Only // < That's for mesh 1
>   Depth Only // < That's for mesh 2
>   Regular Transparent // < That's for mesh 1
>   Regular Transparent // < That's for mesh 2
> ```
But how do I set two materials to one submesh?
low lichen
#

The way multiple materials work in Unity is if there are more materials than submeshes, it will wrap back around. So for example if you have 1 mesh, each extra material will just draw the mesh again with that material.:

1
1
1
#

With 2 meshes

1
2
1
2
1
2
#

There each mesh gets drawn 3 times with whatever materials you put in each slot

#

So if you have 2 meshes and set the materials to this:

Depth Only
Depth Only
Regular Transparent
Regular Transparent

It draw the first mesh with Depth Only, then it will draw the second mesh with Depth Only, then it will draw the first mesh with Regular Transparent, then it will draw the second mesh with Regular Transparent.

fickle jay
#

Can I add materials from script?

low lichen
#

Sure, but it's a bit painful because it's an array instead of a list

#

So you have to create a new array

#

So you just set the materials array directly

fickle jay
#

How should regular transparent shader look like?

low lichen
#

Not a special shader, just whatever transparent shader you prefer

fickle jay
low lichen
#

It's the other way around

#

Depth only first

#

Then transparent

#

Are you trying to post code?

fickle jay
#
void Start()
    {
        var obj = Instantiate(Resources.Load<GameObject>("capital"), new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0));
        var materialsCount = obj.GetComponent<Renderer>().materials.Length;
        var newMaterials = Enumerable.Repeat(obj.GetComponent<Renderer>().materials[0], materialsCount * 2).ToList();
        for (var i = 0; i < materialsCount; i++)
        {
            var material = obj.GetComponent<Renderer>().materials[i];
            var color = material.color;
            material.shader = depthOnlyShader;
            newMaterials[i] = material;
            
            material = new Material(transparentShader);
            material.color = new Color(color.r, color.g, color.b, 0.5f);
            newMaterials[materialsCount + i] = material;
        }

        obj.GetComponent<Renderer>().materials = newMaterials.ToArray();
    }```
low lichen
#

How many submeshes does this model have?

fickle jay
#

9

low lichen
#

Is there a reason you need so many submeshes?

#

Preferably, it would be just one mesh

fickle jay
#

Is there another way to make 9 colors?