#archived-shaders

1 messages Β· Page 70 of 1

dreamy narwhal
#

I just assumed

#

But yeah get rid of all those blits they're unecessary

#

What I'd do is make a light buffer, render all the lights to that then perform a single blit with some blending shader to the main color buffer

humble robin
#

yeah i think i need to do that

#

i have no idea why are there 3 blits

#

its kinda old code

dreamy narwhal
#

I mean you're already there pretty much

humble robin
#

by the way, i just checked if there is culling

#

i made a bunch of lights in an empty scene

#

and triangle count doesnt decrease when they are not in cameras range

#

i guess there is no culling

dreamy narwhal
#

I mean its not such a bad issue

#

Any fragments outside the render texture are automatically discarded anyway

humble robin
#

thanks for the help

dreamy narwhal
#

Just to clarify, why are you using the preious lighting render texture?

#

At the start you blit the render texture to prevLightRenderTexture

humble robin
#

i have no idea why i have 3 render textures named lightrendertexture, prevrendertexture and temprendertexture

#

as far as i can remember

dreamy narwhal
#

lmao

humble robin
#

i was trying to make additive blending

#

but didn't knew how to

#

so i made a shader to add 2 textures together

#

holy hell

dreamy narwhal
#

Yeah that sounds right

humble robin
#

i just need

#

additive blending then

#

ooohhh

dreamy narwhal
#

Yep

#

Render the lights to a seperate texture, then blit it to the color buffer with an additive shader

#

Simple as color + light color

humble robin
#

yup

#

my past self

#

definitely made the dumbest thing here

dreamy narwhal
#

lol its fine everyone makes mistakes

#

I'll write up what I think your implementation should look like just give me a moment

humble robin
#

sure

#

thanks

dreamy narwhal
#

Ahh i didn't get the code block formatting right lol

humble robin
#

` you can use three of those

#

to get code formatting

dreamy narwhal
#

Oh

#

i used the wrong symbol

#
cmd.SetRenderTarget(lightRenderTexture);
cmd.ClearRenderTarget(true, true, Color.clear);

//Loop through each light
for (int i = 0; i < lights.Length; i++)
{
    //Get next light
    CustomPointLight currentPointLight = (CustomPointLight)lights[i];

    //Set properties
    cmd.SetGlobalFloat("_LightTempRadius", currentPointLight.radius);
    cmd.SetGlobalColor("_LightTempColor", currentPointLight.color);
    cmd.SetGlobalFloat("_LightTempIntensity", currentPointLight.intensity);
    cmd.SetGlobalVector("_LightTempWorldPos", new Vector3(currentPointLight.worldPos.x, currentPointLight.worldPos.y, currentPointLight.distance));

    //Draw light to light render texture
    cmd.DrawMesh(currentPointLight.mesh, Matrix4x4.identity, pointLightMaterial);
}

//Blit light render texture to cameras color buffer (or whatever youre drawing the lights too)
cmd.Blit(lightRenderTexture, colorBuffer, additiveMaterial);```
#

Oh cool

#

I think this is what you're looking for

#

Only one blit is needed, since all lights are drawn to the buffer first

humble robin
#

thanks a lot

#

implementing rn

dreamy narwhal
#

Cool hope everything works out!

humble robin
dreamy narwhal
#

Np nice to hear it worked out

full tapir
#

guys, i am creating a decal shader in built in RP by reconstructing the position using the depth texture. It works with normal objects since the unity_WorldToObject matrix has correct values. Now, while trying to make the same effect with particle systems, i see that matrix is always identity matrix so it doesn't have effect. I'm currently stuck trying to create the same matrix using particles vertex streams. Does anyone have any tips for sending me to the right direction? Thanks a lot for any help and have a great day

dreamy narwhal
#

Back again. I got my deffered shader to work but theres a problem that it doesn't seem to receive any specular lighting, despite writing the correct smoothness values to the gbuffer. I suspect it may have something to do with the material flags channel in the buffer, but annoyingly I can't view it from the frame debugger so I'm effectively debugging blind. If anyone could help that'd be great. Left side is my deffered shader, right is built in. 2nd image is the smoothness channel

nova coyote
#

is there any solution of rendering decal over transparent object?

#

I want to have decal over the transparent object, is there a way to make this work?

wild marlin
#

is there no way to recreate the procedural musgrave from blender using shader graph in unity with simple noise etc?

grizzled bolt
tacit parcel
#

is this urp decal? maybe you can try to make the transparent object to write to depth buffer

grizzled bolt
# wild marlin Fair yeah

With custom function node you can get basically any type of noise function even if there's no shader graph node for it

onyx island
#

Hi, recently I’ve been trying to make a room shader. I found a tutorial and followed it perfectly twice, but I still get the same results. The material I used is just gray.

deep moth
#

The way those work is you're basically raycasting in a shader into a box right?

onyx island
deep moth
#

Oh nice!! 😊

restive crypt
#

hey fellas, I have a black hole distortion shader here and I want to make it so that it ignores a certain layer number when distorting the objects but i'm not quite sure how to do it πŸ€”
https://hastebin.skyra.pw/acepiqoxig.cc

deep moth
#

The grab texture is the thing to change. I can think of a couple ways to handle it - one would be to render the grab texture before you render the layer you want hidden. The other would be to render a separate texture without that layer and use that

#

W/ a separate camera.

restive crypt
deep moth
#

the easiest way would be to make a new camera, create a new render texture

#

set the camera to mask that layer

#

and then set it as a texture2D in the shader

#

(easiest not most performant)

#

from there you kinda add layers of complexity

#

to speed it up

#

slowest, most foolproof -> using a rendertexture with an extra camera that has layers

#

fastest, most headache -> using custom passes in URP or changing render order to make sure the grab texture is filled with all of the things you want in the image right before the thing you dont want in the grab pass is rendered

wind torrent
#

HI there. I just started messing up with shader graph and trying to use some full screen shaders. I've implemented by now, following a tutorial, a full screen shader to make a glitch effect and a scanline effect, and used a branch node to be able to activate each one just by changing the value of a boolean.
My question is about if this is the right way to do it, by building up different effects on the same shader and playing around with booleans to let them affect the final result of the shader.
Cuz I do not know about a way to build them in separate shaders and apply more than one material on the Full Screen Pass Render Feature at the same time, but i feel like im making a lot of processing that ends up killed by a branch node at the end

wind torrent
#

Well, i've found out i can add several full screen pass renderers so i guess thats the way to go πŸ™‚

deep moth
#

Those are both totally valid approaches to the problem! The branch node actually doesn't save any performance in shadergraph since its basically shorthand for a lerp(see edit) if you look at the compiled code.

edit: A ternary expression that doesn't cause real branching to occur, instead calculating both sides of the branch node and returning the one that lines up with the bool. See thread for more detail.

#

(which is an old way of writing things w/o conditionals bc those used to be slower in shaders)

#

The way that a lot of really complex shaders are written is with this #MULTI_COMPILE keyword that tells the compiler to compile variations of the shader and use them when those keywords are set to true.

#

I'm pretty sure you can use keywords in shadergraph too

#

That approach is nice because the shader only knows about the code that's relevant to it -- it doesn't even know how to use the other effects if it could once it compiles it apart

#

It becomes frustrating when you spend a ton of time waiting to compile shader variants

#

especially w/ URP / HDRP

#

Anyway -- the proper way of handling stuff like that is usually just to use #MULTI_COMPILE ~YourKeyword~

#

(assuming that the logic should all be in the same place to begin with)

#

Sounds like u made the right decisions

jovial raptor
#

hi there, anyone here using shader graph on built-in??
Is it possible to get the depth buffer? on URP I need to activate the depth texture on render pipeline settings, and as far as I know there isn't any setting for depth on built-in

vital token
#

This MIGHT be a shader problem?
So I've got a shader for a water texture, that adds a voronoi noise to the water that moves, and acts as a "ripple" effect. And ontop of that I have a depthfade shader that with some noise acts as foam for the water. And with the scene camera, I can see the foam around objects in the water correctly. But in the game camera, I only see the floating spec foam and not the foam around objects in the water and I don't understand why.

I took both the shader graphs from two youtube videos, so that's why I'm asking for help here because I low key dont understand what any of it does πŸ™‚

autumn carbon
#

so, i want to make a softbody slime shader

#

and i want it to be fully procedural, no sprites

#

it has to collide with rigidbodies

#

and change shape base on the velocity etc

#

how would i aproadh this?

#

the collision for the object that uses this shader is rigidoby, i just want the shader to look like its softbody

#

wait

#

no il just use sprite shape renderer

#

🫀

deep moth
#

The other thing I'd check is that the near and far plane don't make a difference - you could try making the scene near far the same as the game near far (probably not the issue but worth checking to be consistent)

deep moth
# autumn carbon the collision for the object that uses this shader is rigidoby, i just want the ...

Just for fun if you're comfortable with spoilers for INSIDE there's a really cool softbody technique they use: https://m.youtube.com/watch?v=gFkYjAKuUCE

GDC

In this 2017 GDC talk, Playdead's Andreas, Normand Grntved, Sren Trautner Madsen, Lasse Jon Fuglsang Pedersen and Mikkel Bogeskov Svendsen peel apart the layers woven together to make INSIDE's horrific [SPOILER], showing how its dynamic arms are imposed on a sack of physics bodies, moved by physics and animation as one unit, and glued together b...

β–Ά Play video
vital token
deep moth
#

Sweet glad to hear!! 😊

tiny wedge
#

Hello, as I'm very unfamiliar with unity I'm curious if it's possible to change the emission value with a shape key? It will be used as a toggle in a vrm file.

tawny shard
#

I have this simple shader with noise
(the background image)
and I would like to scroll it like it is fog
any idea on how I could do that

this is the whole shader graph
its messy (it is the first one I made)

tulip carbon
#

Hi. Does anyone know how to flip (mirror the y axis basically) an output please? Like this is all the shader has, but for some reason it displays it upside down. Thanks

regal stag
gloomy gust
#

How can I create a shader that's just a single colour and isn't affected by light? Like a cartoon sorta shader thing

tulip carbon
gloomy gust
#

If it's unlit won't it get affected by bloom?

regal stag
gloomy gust
#

I know I said I didn't want it affected by light πŸ˜…

tawny shard
#

could you tell me what uv is

#

it works great now

#

thank you soooo much

#

been on this for a while

regal stag
tawny shard
#

that makes more sense, I got a bit confused when change UV0 to UV1 cuz it seemed to be the same just like a different noise?

#

thought it was types of noise at first

regal stag
regal stag
tawny shard
#

ohhhhhh

#

that makes a lot of sense

cunning cradle
#

I downloaded a player model from sketch fab and imported that into unity. There are six textures but I don’t know how to add that to the player

summer pagoda
#

Does anyone know why and how a shader causes CPU usage to spike, considering it is only a single draw call and is supposed to run a GPU? Am I missing something? (Unity 2022.3.6f1, Built-In RP hence Shaderlab)

gloomy gust
#

i dont think toon shaders work too well on a low poly model

restive crypt
terse epoch
#

Anyone know any good websites hosting Unity 3.5 shader scripts that still work?

deep moth
#

It's another sampler2d

#

You just need to add a param for it at the top if you want it in the material ui

burnt crown
#

looking for a mentor for shaders. ive learned a decent amount myself, but I don't see a point in learning anything if i dont go overkill on it. i want to master it to make stunning skyboxes. anyone up for it? thanks

restive crypt
deep moth
restive crypt
#

ohh thanks

#

damn I just realised that I wasn't even changing the right material as well

deep moth
#

Did that work?

finite stirrup
#

how do I use the stencil property when making a shader graph that's supposed to be used on UI elements?

#

I'm noticing it's messing up my masks and also the console keeps yelling at me about it

#

it's also rendering everything on the same canvas with the custom material on top of everything without a material

#

I'm making an outline shader and it turns out making shaders for UI stuff is weird

regal stag
finite stirrup
#

yeah I was just doing some research and came across that

#

I've been working on my project for quite a while though and am unsure if upgrading project versions is very smart

#

also isn't 2023+ when you have to do the install fee?

finite stirrup
#

thanks that worked

#

still iffy about the installation fee tho

finite stirrup
#

I'm currently working on an Inverse Mask component for my game, so I opened up the Mask component's code and I assume I can just change some enums and stuff to make it work inversely, but what would I change? I'm not exactly a shader programmer, but I understand that the stencil buffer is what makes the mask work and that what I do has to involve that. Any help would be appreicated!

mental bone
#

Making a gore system in HDRP

broken sinew
#

what space and what coordinate range is output from ComputeScreenPos? Am I using it correctly?:

// in vertex shader
  o.vertex = UnityObjectToClipPos(v.vertex); // clip space?, from (-w,-w,0) to (w, w, w)?
  o.screenPos = ComputeScreenPos(o.vertex); // ???
// in fragment:
  frag_out.color = float4(frag_in.screenPos.xyz, 1.0);
#

I can see that only after dividing by w in fragment shader it looks "properly"

regal stag
#

Yes, you are supposed to divide by w in the fragment to map it from (-w,w) to the (0,1) range. Not too sure about z off the top of my head - I think that varies between platforms.

broken sinew
#

So UnityObjectToClipPos returns in homogenous coordinates (from (-w,-w,0) to (+w, +w, +w)? is this range correct or is it platform dependent?).

fleet jungle
broken sinew
#

Is computing screenPos in vertex even a good practice*? What would the difference be if I calculate it in vertex shader or in fragment shader then?

regal stag
remote mauve
#

I have an image which I do not control (it's user generated content), it's likely to be very small (~200x200 pixels), and I need to stretch it to full screen and use it as backdrop of the UI. Because it's scaled up by so much, it gets very pixelated and ugly with jagged pixel edges, and I'm trying to improve that in some way.
One idea I'm having is to have it Gaussian blurred with a large radius to create an effect similar to Window's aero glass, however I'm concerned about performance because the game is aimed to run well even on low end mobile. Gaussian blur shader is normally implemented by sampling surrounding pixels, which I think maybe can be optimized because of my situation of the source image being scaled up?
Other ideas of making it not look ugly are also welcomed.

night steppe
remote mauve
#

Sure that's one way.

grim needle
#

think i've fixed it? Do you guys say the robot is like "Cell Shaded" or not? Edit: Ignore

low lichen
broken sinew
# remote mauve I have an image which I do not control (it's user generated content), it's likel...
  1. Did you review the requirements? Is stretching the image even sensible and would it look good? Would changing requirements to something like "images must be at least WxH in size" solve your problem? This is one possible route
  2. If you want to use Aero like blurred effect, can you preprocess the image for the first time, render to texture, and later use cached, blurred image? Depending on the amount of elements it could be the best solution Β­β€” process once when UI element is mounted, dispose when it is unmounted.
  3. Instead of scaling up, could you consider scaling down/cropping an image that is too big instead? That could simplify a few things.
  4. Are you sure that user-uploaded image for a backdrop is a good idea here? Won't that introduce a bunch of readability issues?
remote mauve
#

Texture2D.Apply is a huge bottleneck and it has to happen on main thread, so that's quite problematic even if I moved pixel manipulation to a different thread. Even a tiny image still costs milliseconds.

#

One approach I tried is to downscale the image to 64x64, Gaussian blur it, then simply use that with normal bilinear filtering. It doesn't look as good as Gaussian blurring the full size image but somewhat acceptable, but even this size Texture2D.Apply by itself is still eating milliseconds and causing a frame time spike.

broken sinew
#

it would be miliseconds of the first content paint, later it would be free, no?

remote mauve
#

Yeah it's only on the first frame.

steel notch
#

Is there a way to have a texture act like it's 9 sliced across a model?

prime shale
#

sampling at a lower mip level to get effectively a blurrier version of the same texture

#

just an idea but if you want low cost, that is one way to go

wind torrent
#

Hi there, i'm using a full screen shader to emulate crt scanlines.It looks like this

#

But when i move the camera Up and Down the effect seems to dissapear until the vertical movement stops.
Im not using motion blur or anything, i've read that it might be the monitor causing ghosting, but im not so sure about that, and maybe here some knows if thats true or not :/

#

I've also read that it m ight be my own brain processing the moving image the one which is deleting the scanlines out of the ecuation xd. May be i can try to make my scanlines thicker.

In any case, if anyone thinks that what im saying is dumb and there is a simple solution let me know plz ❀️

wind torrent
#

ITs actually my eyes, i can see them if i stick my face to the screen, srry for bothering u guys D:

amber saffron
sudden rose
#

how can i make a mat which is transparent and also shows outline per edge

#

https://youtu.be/VpIIFdwTKyQ?si=PSDvpF9P53GVIFFu
i have tried this but this doesnt work in transparent mat

We'll take a look at a Screen Space Outline solution for Unity URP. A great asset from Github, shared for FREE from a fantastic developer. This has outlines for colour, thickness and uses layers to occlude other objects. We'll look at setup and a couple of use cases to make some awesome outlines!

➑️Robins Outline Devlog: https://www.youtube.com...

β–Ά Play video
quasi forge
#

So I'm very new to shader editing and coding in general and I'm trying to do something that sounds simple but cant seem to do it. I just want a line of pixels, while the left most pixel represents the current value of a property, while the rightmost property has the biggest delay before changing to said value, and it be linear between the two. (That sounded more complicated lol)

amber saffron
amber saffron
deep moth
# sudden rose how can i make a mat which is transparent and also shows outline per edge

Ben golus has an awesome technique for this using stencils. Its worth slowing down a little to build an intuition for it instead of copying and pasting. Multipass shaders also aren't supported in urp. But it's a cool technique https://twitter.com/bgolus/status/1482863883626823683?lang=en

I've written "a bit" about doing outlines, like using inverted shells, render texture blurs, or JFA. But there's one more technique I've alluded to in a few places I wanted to share. Offset multi-pass stencil outlines.

https://t.co/My6AHoc1vw

sudden rose
amber saffron
junior copper
#

how can I do a gradient between 0 and 1

  • 0 is bottom of the mesh
  • 1 is top of the mesh
  • 0.5 is the center of the mesh

i suppose you have to use the object position

amber saffron
junior copper
#

okay ty

dusky stirrup
#

I'm trying to make a depth outline shader.
How can I make my lines stronger / more pronounced?

hearty obsidian
#

I'm trying to get the normals after the skinned mesh renderer deformations. How can I accomplish this?

leaden shuttle
#

hey ive been having an issue where in unity 2023.2, shader graph doesnt work. i updated an existing project and it broke all my shaders, and i thought it was a one time thing, but in a new project, it still doesn't seem to work. I did a sanity check by just plugging the sample texture node into the output and it still didn't work. the sprite just doesnt show at all if i have a shadergraph material on it. It seems like the sprite's texture isn't being assigned to maintex for whatever reason

grizzled bolt
#

And as the next sanity check I'd try getting just a color to show

leaden shuttle
#

i got it to work. for some reason switching the UV setting for the sample texture off of 2 and then back to 2 fixed it somehow

#

ok its not working. heres the shader graph:

frigid jay
leaden shuttle
#

ok i didnt even do anything and it started working all of the sudden. idk whats wrong with unity

grizzled bolt
#

What's the point of using Replace Color there

leaden shuttle
#

I have no idea what it means i thought it was the dimension of the uv and it was 2 by default

#

Im using it for an outline so i can highlight interactable objects by replacing the outline color

#

I prefer it to making an outline shader

grizzled bolt
broken sinew
#

blurred buffer with clipping is another option

#
wary scaffold
#

Does anyone have a tutorial or anything on passing vector arrays to shadergraph Or a custom node out there? I'm building an alpha cutout shader that tracks up to 32 objects and cuts a hole in ceiling mesh. It works and I have a script that pools the objects and passes its data to the shader. But this requires me to have 32 vector3 variables (and 32 bools for circle/square, and 32 more for radius/size) and do a massive graph with a bunch of blends to get them all to show. Surely there is a better way? All googling I have done either leads to "no, shadergraphs dont handle that" or writing custom hlsl - but I have yet to find a good tutorial for hlsl arrays. Any guidance is appreciated!

regal stag
# wary scaffold Does anyone have a tutorial or anything on passing vector arrays to shadergraph ...

Not a full tutorial but I do have an example here - https://www.cyanilux.com/faq/#sg-arrays
Using Shader.SetGlobalXArray functions to pass the data in. Note if you want a different array per-material, while there is are material.SetXArray versions it ends up being quite buggy in URP/HDRP due to how the SRP batcher works. (But there are ways to break the srp batcher compatibility for those objects if necessary)

austere cradle
#

how do i turn on antialiasing

#

on my project

regal stag
quasi forge
#

Thanks discord for the random blank space under the video poi_hehe

broken sinew
echo badger
#

I am trying to write a compute shader that adds/overlays a texture decal to another texture. The decal has a TRS. So my thinking was to create a backgroundToDecal matrix (float4x4?) and use that to sample the decal. But not really sure how to handle when the the sample point is not in the decal. Or how to go about making the matrix.

Any pointers or ideas?

low lichen
echo badger
broken sinew
#

can I somehow create a depth prepass, so that I can first write backface depth, then do proper rendering of front face and use the previously calculated depth?

broken sinew
#

for context: I try to raymarch on a mesh, and I would like to limit ray to the backface of a mesh, so it doesn't march "past" the mesh. Ofc this is a generalisation that should only work for convex meshes, but it's good enough (and if someone knows how to do it for concave meshes I'm very eager to know!)

unborn wren
#

Hey I just started learning Shader Graph coming from programming. I'm curious about Shader Graph as a tool and visual scripting in general, how do you keep everything organized? Even with a very simple shader I feel like the whole thing becomes messy and unintelligible extremely quickly, I can't imagine how a big complicated production shader looks like and how people can actually work with it. Do you have some advice on how to organize things inside Shader Graph? Do you have some screenshots of more complicated shaders to show how it's organized?
Thanks!

#

Also, is using Shader Graph required (or heavily recommended?) or could I create the same shader by just writing code? Shader Graph doesn't seem to be doing anything special, it is just an algorithm at the end of the day.

broken sinew
unborn wren
#

is writing them by hand practical in any real world scenario? or would I be silly to do this? I have no experience to be able to tell.

broken sinew
#

a lot of shaders are hand written because the expressiveness and fidelity of such code is far greater than what shadergraph can produce, but there are also a lot of shaders made purely in shadergraph. I think the main point is that you should use appropriate tool for a job. If you can do something in a shadergraph and be happy with it, go for it, but if you need more fidelity/control/performance/pizzaz, you might consider writing your shaders by hand. Reimplementing a shadergraph shader by writing it by hand "just because" should rise some red flags. Hacking around with nodes in shadergraph to achieve something you could implement in one function should as well.

#

And a quick example of things you can do manually that is hard (or impossible without custom nodes) in shadergraph (for now): for example raymarching shader.

unborn wren
#

I see, thank you for the explanation. So in a game project it could happen that some shaders are written by hand and some are made in shader graph for a single game.

wary scaffold
broken sinew
#

Yup. I've once been in a project, where shaders generated by AmplifyShaders had to be hand-tuned, because they had some problems with z-sorting etc. So as you can see there are even hybrid cases wth correcting by hand generated shaders xd

#

As for organizing, idk, that's a question to someone else. The only thing I can point to are SubGraphs

wary scaffold
#

Trying to figure out the last part of this shader.
Its an alpha cutout shader that applies up to 32 holes in an object based on other objects positions. I thought I was transforming the positions of objects correctly onto the plane(ceiling).
Oddly enough if I have a plane scaled to .3048 x.3048 it works 1:1 with the objects position. If I scale the plane back to 1 or move it, the holes no longer follow the objects position. I assume its how I'm transforming world space coords to object/UV space. Anyone have a good example of how to apply effects to a material in worldspace?

warm moss
#

(Every Amplify template is a text file in Amplify folder)

broken sinew
#

iirc it was a one-off change, that was made for a feature that lasted for, like, a month until it was scrapped or reworked. The funny part was β€” the artist had Amplify Shaders package and I didn't, so I was basically working with what I could use at the time :D
(good to know though that the templates can be swapped!)

warm moss
broken sinew
#

is there a good image or post describing each element of the UNITY_MATRIX_P?

#

And is near plane the same as focal length in regular (non-physical) camera?

acoustic flame
#

i figured out that it only does this with the blood shader that I have on the material, so i'm guessing it's something I need to change there

snow depot
#

Does anyone know how to make like half life 1 flashlight style fake lighting? Like there isn't any actual nonbaked lighting but there's a circle of area in front of you that is lit up

eternal storm
#

Hi, I want to make a pixelart 3D shader with shadergraph. Currently I use an asset called propixelizer, but have a small issue with it. Right now, the pixel's amount change based on how close the camera is to the object, and how I want my shader to work is to have a consistent amount of pixels, and the pixel count should only be changed by an input field. Would this feature be possible to implement, or should I just ditch the idea?

dark flare
#

Those are both totally valid approaches

ember grove
#

Might anyone know how I can disable the player's reflection from a shader?
(apart from putting it onto a new layer?)

I'm planning to do the player reflection separately, so just wondering, thanks!

tribal badger
#

I've asked this before, but I can't wrap my head around this. Imagine I have a shader for folliage with a little sway, and another for props, and a third triplanar one for texturing terrain or terrain features. Now if I want to add "wetness" based on some parameter for everything in my game I would need to add it to all of my shaders? Is there some way to "composite" effects other than re-using subgraphs in shader graph for example? Or making an "uber shader" that you use on everything with different parameters?

What's your approach / convention for adding "features" to all your materials?

warm moss
# tribal badger I've asked this before, but I can't wrap my head around this. Imagine I have a s...

You could make a modular HLSL header with wetness calculations that take structs with input data and modify the passed in PBR surface parameters. This would let you reuse the same wetness calculations across a bunch of unrelated shaders by including the header and invoking the wetness function. The only duplicate work across shaders would be copypasting the pragmas and properties for wetness across all of them.

#

(I don't like ubershaders)

tired skiff
#

DISTORTION SHADER
does anyone know how to make a shader graph distortion shader in hdrp?
i tried to search (ctrl + f) here but no one give a real solution. they all say that in URP is different, ok. But what's the soolution in HDRP?

dawn depot
#

Can't find Vector1 in Unity Shader Graph. Should I use Float instead of it?

neat gazelle
#

Hi folks, I've opened up 3D game kit and all the surfaces are blue, how do I turn this off?

amber saffron
neat gazelle
#

ah okay, how do I turn this off?

#

driving me nuts

neat gazelle
#

omg I've done it

winter pier
#

guys how do i make so that the only light thats in my scene is only from the light souces i make? currently everyone isnt black when i turn off all lights, instead its a a very ugly brown colour bg, and it colours all objects to that ugly colour

#

how do i disable it

low lichen
low lichen
#

In the Lighting window

winter pier
#

ok

#

i found it

sly steeple
#

Surface shader to urp

Hello ShaderNerds ;
I have Project where I am using a custom surface shader for my terrain written in HLSL it is the only shader I ever made myself so my knowledge about shaders is very poor. The shader was working fine and I am amazed that it does...

WHAT ITS DOING:
blending textures based on terrain height and steepness + plus adding colors and applying triplanar mapping (terrain is a custom mesh)

WHATS THE ISSUE:
I am now converting my project to urp and sadly urp does not support surface shaders. So I guess I have to convert it into another type of shader. So I am wondering what type of shader should I use? (Preferably one which would make it easy to include normal maps at some point later on). Where can I find help/instructions on how to do it ?

Much thanks in advance

warm moss
#

@sly steeple you should be able to recreate it in Shader Graph. I even managed to make a shader usable with the builtin terrain system.

wary scaffold
#

Can someone help me out? I've created this subgraph with a custom node that takes in a world space position and radius - It is working all as intended except the circles and squares that are being cut out of the ceiling don't follow the position of the objects its linked to perfectly. The farther from the center of the object being cut the tracked object gets the more off center it becomes. Any ideas on what I'm doing wrong?

#

I should mention this is HDRP so absolute world is necessary

#

the above graph then gets blended 32 times with identical other subgraphs in the main shader

winter pier
#

who here wants to teach a person how to shader in vc? i know mostly the concept of shaders from youtube vids but i have never seen any of them walk through on how to actually setup stuff and the "boring stuff" of the process, cuz technical content doesnt get views they crop out most of it

mental spade
#

hey there friends! Quick question: How can I Google this effect? So basically, "a shader that makes the borders of the mesh visible regardless of position" - just like in the editor

regal stag
# mental spade hey there friends! Quick question: How can I Google this effect? So basically, "...

For the border, there's a bunch of techniques for "outlines". They're pretty common, but not necessarily an easy topic. This lists most of them : https://ameye.dev/notes/rendering-outlines/
If you want it visible through objects look into using ZTest Always and compare with depth texture to reduce the opacity, or render as two passes (one solid with ZTest LEqual and one slightly transparent with ZTest Greater)

mental spade
#

@regal stag thanks that looks like a great place to start

amber saffron
wary scaffold
amber saffron
wary scaffold
#

UVPos is just the world position of the object (poorly named I know)

#

The whole thing gets build up to 32 objects like this (I know this is ugly, cant figure out how to pass all 32 in one loop)

amber saffron
#

So, the graph should be correct, πŸ€”
With the exception that the rectangle and ellipse expect to draw in the 0to1 uv range, so you should probably also add (0.5, 0.5) to the calculated position.

amber saffron
wary scaffold
#

right but then how to I pass all 32 into that code?

amber saffron
wary scaffold
#
{
    float3 _UVPos = 0;
    float _radius = 0;
    float _isSquare = 0;

    _UVPos = float3(_Worldpositions[index].x, _Worldpositions[index].y, _Worldpositions[index].z);
    _radius = float(_Worldpositions[index].w);
    _isSquare = float(_isSquared[index]);

    UVPos = _UVPos;
    radius = _radius;
    isSquare = _isSquare;


    //[unroll]
    //for (int i = 0; i < 32; i++) 
    //{

    //}
}```
sly steeple
# warm moss <@664542728750891049> you should be able to recreate it in Shader Graph. I even ...

Ok i started to look into shader graph a little, so when creating a new graph i have the option between unlit and pbr. From my understanding unlit would be just fine for what my shader is doing currently(?).. but if I want to add normal textures later I might have problems correct? So I m wondering, can I basicly treat the pbr like the unlit for now and just use the pbr graph so I keep the otption availibe to add more complex shading stuff later or is there something I am missing ? Like drawbacks in performance or sth?

EDIT I am not using Unity Terrain

wary scaffold
amber saffron
wary scaffold
warm moss
amber saffron
#

Here's a very quick modification of the code you've shared higher to do what you wanted :

void ExampleOutput_float(float3 worldPos, out float mask) 
{
    float3 _UVPos = 0;
    float _radius = 0;
    bool _isSquare = 0;
    float2 uv = float2(0, 0);
    
    mask = 0;


    [unroll]
    for (int i = 0; i < 32; i++) 
    {
        _UVPos = _Worldpositions[i].xyz;
        _radius = _Worldpositions[i].w;
        _isSquare = _isSquared[i] > 0.5;

        uv = (_UVPos - worldPos).xz;
        
        if (_isSquare)
        {
            float2 d = abs(uv) - float2(_radius , _radius );
            d = 1 - d / fwidth(d);
            mask = max(saturate(min(d.x, d.y)), mask);
        }
        else
        {
            float d = length( uv / float2(_radius , _radius ));
            mask = max(saturate((1 - d) / fwidth(d)), mask);
        }
    }
}
#

@wary scaffold

sly steeple
wary scaffold
amber saffron
wary scaffold
#

It still throws Width and Height as undeclared identifiers

amber saffron
wary scaffold
amber saffron
#

@wary scaffold updated

#

And would the mask not need to be mask += since its otherwise overwriting it and only returning the last result?
Not really, since at each loop cycle it is taking the max value between the previous mask and the new shape, so they "stack"

wary scaffold
amber saffron
wary scaffold
# amber saffron Thank you, but I have none of those πŸ˜…

Well if I can ever repay you lmk! I've learned more in the past 30 minutes from working through that then days and days of doing my own research and trying to hack things together. Heck I'm amazed I almost had a working subshader. And thats only thanks to Cyan's excellent tutorials on their site.

sly steeple
#

I am in the process of converting my surface shader to shader graph (absoluty first time using shader graph). Regarding the shader graph Inputs :
I can input tex2Darrays niceβœ…
I cant input a simple float array ❌
I cant input a color array ❌
I feel like there "should" be way to do it?!?

amber saffron
sly steeple
#

ok i will have look at includes than. So I simply have to declare the arrays I need in a separate hlsl file which I than can somehow need to include in my graph, so I can use material.SetFloatArray and material.SetColorArray? Thanks

sly steeple
#

I am just lost now so this are my properties in the surface shader:

const static int maxLayers = 8;
        
int layerCount;
float3 baseColors[maxLayers];
float baseStartHeights[maxLayers];    
float baseBlends[maxLayers];
float baseColorStrength[maxLayers];
float textureScales[maxLayers];
float steeptextureScales[maxLayers];
float steepMulti;
float steepThreshold;
float minHeight;
float maxHeight;
UNITY_DECLARE_TEX2DARRAY(baseTextures);
UNITY_DECLARE_TEX2DARRAY(steepTextures);```
amber saffron
sly steeple
amber saffron
sly steeple
#

i think base color but give me second i will try to reproduce it

#

ok I cant reproduce it (tried to many things to remember); I just used your code snippet now and I get unexpected token "(" at line 164 I made screenshot of how I set up the Node; thanks a lot for helping my frustration level is peeking at the moment πŸ˜„
That error does not make sense to me at all

amber saffron
#

The error you have is because when the node it set to string type, it wraps the written code in a function already.

#

And when using the include type :

  • The function name will have to be "GetBaseColor"
  • Force the precision to "float" : the precision is appened to the end of the function name, resuling in the one declared in the hlsl
sly steeple
#

Ok that does make sense; thank you I will take a break now and try this later. I was using string simply to try stuff out quickly. I was really lost and could not find anything. By the way, when i include multiple of these functions in one file can I than control which one is called by changing the name inside the inspector accordingly? It seem a bit messy to have one file for each array and also as final question, does it even make sense to do what i am trying with shader graph?

amber saffron
#

when i include multiple of these functions in one file can I than control which one is called by changing the name inside the inspector accordingly
Yes πŸ™‚

#

does it even make sense to do what i am trying with shader graph?
Yes πŸ™‚

sly steeple
amber saffron
copper grove
#

i want to make an image like this that is fully transparent at the top but not transparent(or a little) at the bottom

#

how do i do it?

#

im talking about the one behind the dialogue

#

idk if its with a shader, i just didnt know where to ask this

copper grove
#

what should i type in google

#

idk how to describe that image

fossil cloak
#

create it yourself

copper grove
#

how

fossil cloak
copper grove
#

i have a pixel art software

#

ill try

fossil cloak
#

or google for something like alpha gradient png

copper grove
fossil cloak
sly steeple
atomic glade
#

Is there anywhere I can find a shader graph version of the Unity standard shaders? Specifically the standard URP lit shader for my usages, but I want to extend it with some new options without breaking any of what makes the shader do what it does

mental bone
#

A brand new lit graph already does everything the lit shader does

faint socket
#

anyone knows why my image half dissappears from certain angles?

atomic glade
#

Just would be convenient if there were premade graph versions of the existing shaders to base it off of

mental bone
#

That would be convenient indeed

#

We have a nice little library of subgraphs that we have made and reuse in most projects

#

Including a pbr one where it just hides all the sample texture nodes and sliders

atomic glade
#

Hm, the PBR Node seems to be missing an obvious hookup for the height map.

mental bone
#

I think it shows up if you enable it in the graph settings

atomic glade
#

Okay so it's got to be more involved than just plugging in the maps into the slots because these two things look very different

#

Even removed the heightmap from the right-cube since I don't know how to replicate it

regal stag
#

Or Parallax Occlusion Mapping, more accurate but more expensive too.

atomic glade
#

Okay, that does seem to have applied the heightmap. Do you know what else is missing to replicate the standard URP lit shader?

#

Same set of textures, what I can assume is a pretty straightforward shader

regal stag
#

Is the normal map applied? Not sure they look correct.
Make sure you set the Type on the Sample Texture 2D node to "Normal" for that one

atomic glade
#

Yeah, it's applied and it's the same asset

#

Oh, in the node, I had changed the texture, but not the node. That did it

#

thank you

atomic elm
#

Hi, how can I create a billboarding shader that can also be rotated (similar to creating a Particle System with a billboarding texture with rotation)? I have this series of nodes that can get me rotation, and another series of nodes that can billboard, but I'm not sure how to combine them. Thanks

deep moth
#

Would it work for you to do a that rotation before you billboard it?

#

Right after that multiply in the billboard group.

ember grove
# ember grove Might anyone know how I can disable the player's reflection from a shader? (apar...

ah nvm got it to work with a bit of a hacky thing! πŸ™‚

Pasting the steps below --

I was following this tutorial here: https://www.youtube.com/watch?v=ym1K3of3pys

I followed the chapters till / including the "reflection" section, the only differences I made were --

  1. Place the player on a separate layer, called P as an example.

  2. Make a new camera, C, the size of the player roughly. Set the culling mask layers to be only P.

  3. Create a new sprite, and make sure it equal to the size of C, and place it right under the player.

  4. There is a white background texture. that will be there by default. I'm not sure if there is a way to get rid of it (see screenshot attached), so what I did was instead set the alpha value of the reflection sprite to be very low, so that the white box appears to be invisible πŸ™‚

This is the shader graph, in case it may help anyone facing a similar thing out ! πŸ™‚

Attaching the final result as well!

Learn how to create a water refelction effect in Unity

Download the project starting files at https://drive.google.com/open?id=1OUOcx75_fm-1yZb6rSt8siWEYWJrdUe-

Inspired by Binary Lunar: https://www.youtube.com/watch?v=O1lRGKfCi9o

Get my latest Udemy course 'Learn To Code By Making a 2D Platformer in Unity & C#' at https://www.udemy.com/cours...

β–Ά Play video
steel notch
#

Is there a way to apply a screenspace effect BEFORE lighting?

#

I want to apply an outline to some objects but make that outine susceptible to lighting/post processing.

mental bone
#

It would be better to use the inverted hull method for this since then you have a mesh to actually apply lighting to

steel notch
#

Other outlines, like on the sprites and the floor, are just from a texture.

mental bone
#

Honestly these outlines look like they are authored in the texture

steel notch
mental bone
#

So they are in essence authored in the texture 🀣

steel notch
#

but ya, working to try to replicate this style

#

and the outlines on the 3D models are giving me trouble

eager ocean
#

I'm generating some procedural meshes using ComputeShader, and then I use this VertexShader to map the faces on a texture. Does anyone know if I can change the texture at runtime by setting it through a script, and how can I do it? So far I've tried material.SetTexture("_MainTex", Texture) but it doesn't work

mental bone
# steel notch but ya, working to try to replicate this style

I have to say that you will not get close to replicating clean and thoroughly placed outlines like this with an algorithm. Well maybe some AI driven post processing can come close but still. Sometimes the work has to be put in and done by hand.

mental bone
steel notch
#

like the lines you see here, for example

mental bone
#

Ah you can get decent one like that using the goodnold depth normals technique

#

But again… you want then to react to lightning that is tricky

steel notch
#

ya I'd want them to basically act as if they're textured πŸ˜›

mental bone
#

I dont think its possible without extra geometry to be honest

steel notch
#

Like some custom render feature.

mental bone
#

In a deferred renderer it could be possible to take the same approach that deferred decals do. You would render out all opaques, get depth and normal, calculate the outlines and somehow apply that data back to the g buffer

#

For a forward renderer Im not sure

tacit parcel
#

I mean, a black color with white light would still look black

mental bone
#

So turns out Im a bit rusty on my computer shader knowledge. This particular shader essentially needs to read from one array and write to another, both are 1d and the same length. Now I know it’s a good idea to keep thread count to 64 or a multiple of that due to wavefront occupancy and what not. Since we are talking 1d arrays here I don’t need the extra dimensions and can just go for [128,1,1] in the shader. However I cant seem to figure out how to properly calculate the thread group size for the dispatch since for every dispatch the arrays can be of different sizes

#

Im not sure what happens if I dispatch more than I need so array.lenght/128 rounded up doesnt seem to be a good idea

low lichen
vapid carbon
#

Hi got a question

I basically need an Unlit shader for BIRP... Is there any available online?

low lichen
mental bone
#

Ah reading and writing out of bounds is no problem ?

#

How would I do a bounds check, if id.x > arrLenght?

mental bone
#

And just what return ?

low lichen
#

Sure

low lichen
# mental bone Ah reading and writing out of bounds is no problem ?

Unity can't guarantee it will be safe, it will depend on the graphics library and the GPU. Some libraries guarantee the behavior of out of bounds access, like DirectX 11 will always return zero. DX12 seems to have different behavior depending on the type of resource accessed. Vulkan is undefined behavior, so it should be avoided there.

mental bone
#

Ah I also sample a texture in there so better be safe

regal stag
tawny shard
#

why the zombie weird with my shader

#

thjis is the whole shader

fossil cloak
tawny shard
tawny shard
#

this without and with the material

#

see whats wrong?

regal stag
#

What are you applying the shader to? A sprite renderer?

tawny shard
#

nothing more

fossil cloak
#

i guess changing the wrap mode to "clamp" in the import settings of your zombie could work there

tawny shard
#

it is?

regal stag
tawny shard
#

do u know why it gets this effect

regal stag
#

It can look weird, but normal to look like that. The previews within shader graph show the RGB data, not any transparency/alpha. I think most programs don't save colour data in fully transparent pixels, and Unity also can stretch colours out during import to avoid artifacts (particularly when using bilinear filtering rather than point, but still applies)

tawny shard
#

How would I go about making a shader to make the texture shake

#

been trying for a while

deep moth
#

What kind of shake are you thinking? You could just offset the uv with a noise and time value

tawny shard
#

I'll try to use a noise

#

maybe with a smooth step?

deep moth
#

Try plugging time into the uv slot on the noise

#

And adding another noise

#

Then combining them into a float2

#

And subtracting .5 from the value to make it go from negative to positive.

tawny shard
#

Ill let u know

deep moth
#

Sweet!

tawny shard
#

I just have a few questions if its not bothering

deep moth
#

Ya go for it!

tawny shard
#

why the texture has long feet

#

and

tawny shard
#

what could I do?

#

didnt understand very well what to do with branches

deep moth
#

You could add a float parameter multiplying the intensity

#

Or use a branch

#

Or a lerp

tawny shard
#

like Im used to the big brain but the big feet is kinda new and the big brain doesnt appear on the sprite

deep moth
#

Another way to do this if it's not very often would be to make the shake happen in c#

#

Instead of in the shader

#

Hm. I don't think I know enough about your project to say about long feet. Does anyone else know?

tawny shard
#

but if I put it 0 its very intense

#

so I would need to like set it to 10000

#

to make it not visible

#

this is how I made the shaking

#

the rest

deep moth
#

If you make shakiness a multiply instead of divide it might be more predictable.

tawny shard
#

and they shake

#

when stuned

#

thats it

tawny shard
#

I shouldnt be dividing by 0

deep moth
tawny shard
deep moth
#

Woo!

tawny shard
#

cuz I can just make the shakeyness 0

#

thank you so much, Im just now starting to mess with shader graphs

#

is coding shaders that much harder?

#

I enjoy coding

#

but I aint sure

deep moth
#

There's a bit of boilerplate with unity but it's how I learned!

#

And easy to bring back to unity too.

#

Just slightly different syntax

tawny shard
#

hmm sounds a good place to start thank you!

ocean agate
#

Using Forward+ on my project makes all my shaders glitch blinking/flashing in black and white, anyone else has this issue?

atomic glade
#

Anyone know why a material is much darker in a project loading it from an asset bundle than the original? I have two projects, one of them is for exporting material bundles, and the one that uses them. I have the same shader in both. The first image shows it as it's exported from the bundle generation project, the other is the result in the actual project. Both are lit by a directional light and you can see how much brighter the ground near the applied bundle is. What could be making this material so much darker?

#

I just recreated the material, same textures and shader, and it's still dark so it's obviously something to do with my lighting or project settings. I just don't know what that could be

idle viper
#

I'm having trouble drawing my object in the center of the camera.
I try to set the vertex position to the center of the camera, but this doesn't work.
o.vertex = UnityObjectToClipPos(_WorldSpaceCameraPos);
What is wrong?

deep moth
#

Right now your code is setting the output position of every vertex in your model to the same point: _WorldSpaceCameraPos after being transformed by the Model View Projection matrix (UnityObjectToClipPos()). If you want your model to keep it's shape you should have v.vertex somewhere in your equation.

If you wanna center the vertices in the camera using _WorldSpaceCameraPos you'll want to first transform your model from object space to world space like this float4 worldPos = mul(v.vertex, unity_WorldToObject); then you can subtract the camera position from it worldPos -= _WorldSpaceCameraPos; and then transform it back into local space float4 localPos = mul(worldPos, unity_ObjectToWorld); then run your o.vertex = UnityObjectToClipPos(localPos).

This will probably give you a result where the camera is inside of the object so your next steps would be to figure out the camera forward vector and add it to your world space position.

This approach adds a lot of complexity for centering an object on the screen but might be good for just figuring out how matrices for rendering work. Usually for stuff like this I prefer to transform things in C# since it won't break frustum culling.

If you wanna learn more about matrices for rendering I recommend: https://catlikecoding.com/unity/tutorials/rendering/part-1/

It's also worth it just to mess around and try setting o.vertex = v.vertex; -- this will give you the model space position on screen. It'll squash and strech with the screen since it's not scaled by the aspect ratio of the camera (that happens in the projection matrix).

You could theoretically do all of this centering logic with just the Model, View and Projection matrices.

A Unity Rendering tutorial about matrices and transformations. Part 1 of 20.

dreamy narwhal
#

Hi all, does anyone know if it's possible to write to a uav 3d texture in a fragment shader? I'm having issues doing so.

#

Here's the binding: RWTexture3D<uint> _voxelScene : register(u1);

#

And I simply want to write to pixels where my fragment lands in clip space: uint3 pix = IN.positionHCS.xyz * 16; _voxelScene[pix] = 0xffffffff;

#

However, the texture appears to be empty when rendering 😦

#

The texture descriptor in case i've made some mistake here: RenderTextureDescriptor voxelSceneDesc = new RenderTextureDescriptor() { width = voxelSceneRes, height = voxelSceneRes, dimension = TextureDimension.Tex3D, volumeDepth = voxelSceneRes, enableRandomWrite = true, graphicsFormat = GraphicsFormat.R8G8B8A8_UInt, depthBufferBits = 0, msaaSamples = 1 };

#

And binding on unity side (dummy target is a normal 2d render target): cmd.SetRenderTarget(dummyTarget.depthBuffer); cmd.ClearRenderTarget(true, false, Color.clear); cmd.SetRandomWriteTarget(1, voxelScene); context.ExecuteCommandBuffer(cmd); context.DrawRenderers(cullResults, ref drawSettings, ref filterSettings); cmd.Clear();

#

I've set the shader model target to 5.0 in the shader too, from what ive read this should support writing to uav textures

dreamy narwhal
#

UPDATE: I've solved the issue. Turns out theres a funny behaviour where you have to call ClearRandomWriteTargets() both before and after rendering, idk why this is so but my shader works now πŸ™‚

deep moth
#

this is such a cool idea!! I didn't realize you could write to textures from within a frag shader like that. is this mostly for organization?

dreamy narwhal
# deep moth this is such a cool idea!! I didn't realize you could write to textures from wit...

Thanks! I'm planning on implementing realtime voxel cone-traced GI system for indirect illumination for a project of mine. For that I need to represent the scene as a voxel grid, so i'm using a custom shader which writes to an 3d texture (seen above) to do this. I was super worried I wouldn't be able to do this in unity so this is a massive releif. If youre interested this is the paper im basing this off (my implementation will be alot more simple tho): https://research.nvidia.com/sites/default/files/publications/GIVoxels-pg2011-authors.pdf

mental bone
#

I'm reading a RawBuffer in a custom function node like this ```ByteAddressBuffer _woundBuffer;

void ReadBuffer_float(float i, out float clip, out float blood)
{
uint packedValue = _woundBuffer.Load(i * 4);

clip = (packedValue >> 16) / 65535.0f;
blood = (packedValue & 0xFFFF) / 65535.0f;

#ifdef SHADERGRAPH_PREVIEW
clip = 1;
blood =0;
#endif
}```

#

problem is that the preview works in the graph, but in the scene view the mesh totaly disapears because the clip value that goes into the alpha is 0

#

Can I somehow define the buffer without doing custom code in lets say a Initialize on load or what ever

#

hmm initing the buffer and filling it with data in Reset does work, but the workflow is scuffed

#

lol ofc I release the buffer in OnDisable, so exiting play mode means you have to reset the component again....

dusty creek
#

I started a project in 2022.3.4f1 and decided to open it with 2022.3.19f1 to make sure I'm up to date. but this happened to my skybox shadergraph... does anyone know what happened?

exotic willow
#

whats the best premade shader outline package to use?
I tried to follow a brackeys tutorial on shader outlines for 2d sprites,
but i'm guessing its old because the GUI he went through was completely different and I cant figure out where to create the same shader type.

https://www.youtube.com/watch?v=MqpyXhBIRSw

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
● 2D Glow Tutorial: https://youtu.be/WiDVoj5VQ4c

● Get Gothicvania Ch...

β–Ά Play video
viral holly
exotic willow
#

URP asset (With 2D renderer)
then the video tells you to delete the smaller one and create URP 2D renderer

then edit , project settings, new universal render pipeline asset ( universal render pipeline asset)

regal stag
exotic willow
#

in the video he goes through this path
but i cant find this

regal stag
exotic willow
#

i did try creating an unlit shader graph there but i assumed it was different because our things look different and have different components

regal stag
viral holly
exotic willow
#

where am i supposed to drag it?
brackeys one on the left he drags it into color
but thats not an option for mine, and my one doesnt do anything if i drag it into the closest thing

versed dew
#

I'm doing a blinking shader and wondering how i can just make a shader without the material? Let's say I want a gun with a texture. I just want that texture to blink so the player knows it's an interactable.

exotic willow
#

his one already shows the sprite if he goes back to main, while mine does this
(bottom left one has the shader on it)

regal stag
exotic willow
#

oh :3 i didnt save it

regal stag
exotic willow
#

i guess ctrl S doesnt work and u have to manually press save asset

regal stag
#

Yea

versed dew
regal stag
versed dew
#

I did but it won't change it. I'll send a screen shot RQ

#

Please don't slaughter me. :p

regal stag
#

Looks fine to me, what exactly is the problem?

versed dew
#

using this as an example. This has it's own material and is using the URP Lit shader

#

If i change it to my blinking one. it changes the material too

regal stag
#

Right okay, you need to provide the same texture inputs and sample them in the shader

#

At the very least, _BaseMap is the albedo/colour texture

versed dew
#

So I cant have 1 blink shader for all?

#

This works, Was just thinking I can use 1 shader for every interactable

regal stag
#

If you use a Texture2D property in the blackboard you can expose the texture on the material so it can be swapped out, same as the URP/Lit

versed dew
#

I have 0 clue what that means. Could you point me in the right direction so I can look into it please

ocean agate
versed dew
#

TYTY

exotic willow
amber saffron
exotic willow
#

in the brackeys video he said the clamp after the add was specifically to stop values going over 1

amber saffron
#

But from my understanding of what you have and what you probably want :
after that clamp (that could be replaced with the "Saturate" node) :

  • output color is : lerp from mask color to sprite color using sprite alpha
  • output alpha is : the current outline mask (the output of the clamp/saturate)
amber saffron
exotic willow
#

oh oops its meant to be 0 and 1

amber saffron
exotic willow
#

alright ill swap it out

this is it currently now
i probably did something wrong on the left, ill just go through the tutorial again i guess

amber saffron
#

Show you current nodes setup close to the output, with the corrections I proposed

amber saffron
#

Why a video, a simple screenshot would have been enough ...

exotic willow
amber saffron
#

Try this :

exotic willow
#

tried to follow the image but its difficult lol
I guess thats on me for bad layout

exotic willow
#

heyyy! awesome, thanks!

heavy plover
#

This a shader for a simple square image that is acting as the fill part of a slider but.... the patterns are scaling to the size of the actual thing, which I want it to reamain constant, does anyone know how to do that?

#

This is the shaderGraph that is generating this

#

If it is worth something

warm pulsar
#

There's no way to created instanced properties with the shader graph, is there?

#

I just noticed that I have tons of tiny draw calls because instancing is being broken by different values in my material property blocks

regal stag
warm pulsar
#

this is an HDRP project

#

but I'm deliberately trying to do GPU instancing here

#

i'm drawing lots of copies of the same mesh

#

this is for drawing debris

#

Although, in non-pathological cases (i.e. when I don't spawn tons of copies of the same debriso bject), it's more heterogeneous

regal stag
#

Then yeah try a custom function. I've only tested it in URP but might work in HDRP too

warm pulsar
#

in which case the SRP batcher makes more sense, probably

#

I didn't know you could declare properties in a custom function like that

regal stag
heavy plover
regal stag
heavy plover
#

The Stripes I think I literally downloaded it from the basic unity addons, and does this

#

So.... I am guessing the tiling I need to input based on the scale should go... into the frecuency???

regal stag
heavy plover
regal stag
#

Could copy the subgraph asset if you need the original

#

Or copy the nodes into your main graph

heavy plover
#

Mmmmm.... I think I got it, but I don't think it can work with an interface since its scale is kinda weird realte to the world position

mild dirge
#

Hey, I am a bit confused.
I am just working on a basic scrolling shader based on the tiling and offset.
But already my input is messed up.

On the left is the texture that I am using, and on the right is what the node gives me

Using the 2D template

regal stag
mild dirge
#

It also showed as green when applied to a material in the scene. But additionally connecting alpha to the output alpha fixed it. Thank you a lot ❀️

#

Now to get it to not deform when the plane it's applied to isn't square πŸ˜…

heavy plover
#

So I made this just to compare, the top one is an UI component that is on a screen overlay canvas, is a slider; the botton ones are 3 cubes scaled exactly the same with the same material, so the autotiling for scale works there, but not in the UI component

karmic hatch
#

probably object space if it's aligned there but not necessarily aligned in world space

heavy plover
#

Is there a way to fix that for a UI component?

#

Cause I have been trying to find a way for a while now

mild dirge
#

Damn, I am really starting to notice that I am out of my depth here. I got some theoretical knowledge, but no clue how to implement it

#

What I want to achieve in the end is that I'll have have circles spawned semi randomly (within bounds obvsl) that I want to act as a negative mask.

Basically have a plane with this scrolling texture in the background, and only where the circle is, it can peek through

karmic hatch
#

you can try using Voronoi noise, and saying if the value of the noise is less than a constant (if you want constant-sized circles) or some function of cell value (if you want variable-sized circles), then you use the texture, otherwise you use something else (using a branch node)

mild dirge
#

Not exactly what I mean.

Basically, if an enemies dies, it's gonna leave a puddle for a bit.
But if two enemies die close together, the overlaying textures look bad.
So I want to basically union the two areas and use them as the mask, so they don't individually have the texture, but use the same one, seemlessly

#

You see how the square pattern continues through the circles? If each circle had their own (thus slightly offset) version of the texture, I'd get a mess like in the second picture, and that's only 3 copies

mild dirge
#

Maybe my brain will work better tomorrow

junior copper
#

when building all transparent shaders are not transpaent anymore

#

i tried adding all shaders in Project Settings > Graphics > Always Include Shaders
but this didnt work

exotic willow
#

is there a better way to do the outline with a shader where it doesnt look all blocky like this?
looks pretty ugly

steel notch
#

So I'm making a Fullscreen Shader Graph, and for some reason if all I input is scene color, the entire image ends up being extremely blurry?

#

Any reason this happens?

lyric anchor
#

or use the world position as UV so that when the circles do overlap you won't see it

#

as the overlapping pixels will share the exact same world position

#

(might be easier this way)

lyric anchor
tacit parcel
regal stag
# steel notch So I'm making a Fullscreen Shader Graph, and for some reason if all I input is s...

Scene Color uses the camera's Opaque Texture. There is a tickbox on the URP Asset to enable it, and a setting below that to adjust its down-sampling.

Also note : The opaque texture will not contain transparent objects. If your fullscreen pass occurs in the Before Rendering Transparents event, this is an okay setup. (It avoids rendering an extra fullscreen triangle/quad)

For other events, if you need the camera texture before the fullscreen pass occurred, you should be using the "BlitSource" texture from the URP Sample Buffer instead.

full tapir
#

Hello guys, it appears unity_WorldToObject matrix has inconsistent values using the camera in-game. Using the editor camera has correct values every time. Does anyone know why that's the case? Thanks in advance!

deep moth
heavy plover
honest trench
#

i imported my model as fbx but the textures didnt come with it. i tried importing the texture folder and using the materials tab, but it can't find my textures.
i noticed the textures and layers it had are now sphere shaped shaders? do i need to convert my textures to that to find and load them

grizzled bolt
honest trench
#

i'm trying but suddenly blender decided my models is pink even after telling it where each individual texture is

#

i don't know hot to import them separately, i know which folder has all the models textures and imported that into unity but i cant seem to get unity to find them in the search bar so i can apply them

gleaming robin
#

Have some trouble with a decal shader graph in hdrp, i can't make the alpha in my decal shader graph work. I know there is a fade factor on the decal component but with a value of 1 on it I should be able to manage the drawn texture alpha in the decal master node (cf screen). All I see is my texture draw without opacity (fadefactor= 1 i guess ..) but my material don't affect the alpha in any way .. Any idea welcome ! Thx

grizzled bolt
honest trench
#

i'll go move there, but this is relevant to shaders, in that i don't really want the ones that came with my model

full tapir
# deep moth Whoa. I can't imagine why that would be the case. WorldToObject should be always...

Yes basically i'm reconstructing the global position from depth texture and re creating the uvs for a decal using unity_WorldToObject. It works everytime with editor camera. With in-game camera it gives strange result. I debugged extensively, it appears the problem in in the translation part of the matrix. Also, just returning the matrix[2].xyz is almost always right, but sometimes the color flickers. I really don't know how to fix this, maybe i'll just give up and support only translation and pass the position myself

radiant inlet
#

Hi all, I want to make a lamp post, and have the light be bright white but my character paints on it and I want the light to be the color I painted

#

it's a 2d game, and I have a "paintbrush" script that applies a circle of color on a blank sprite on top of the lamp light

#

at the moment I paint over the light and the light stays white and shines white through the colored paint

deep moth
#

To de-project from clip space into world space

full tapir
#

This is nice i have checked it, but i am in built in render pipeline. So i have to rely on CG not HLSL. I'll try with inverse view projection, it should be available in the macros

junior copper
#

When building my shaders arent transparent anymore, any ideas ?

#

using HDRP & shader graphs

mental bone
#

Are your transpersnt shaders present in a scene? If they are not unity is probably stripping the transperant variants from the build. Look into shader variant collections

junior copper
#
  • in Project Settings > Graphics > Shader Stripping i did :
    • Instacing variants : Keep All
    • Batch Render Group Variuants : Keep All
grizzled bolt
junior copper
junior copper
grizzled bolt
junior copper
#

yes I can see it, isnt it what the editor also uses ?

grizzled bolt
junior copper
grizzled bolt
junior copper
#

i tried adding the materials using the shaders in the Resources folder but its not helping

meager pelican
# full tapir This is nice i have checked it, but i am in built in render pipeline. So i have ...

Well, just FYI...in BiRP you're using HLSL, not CG. You may already have this working by now, but just in case:
The diff between CGPROGRAM vs HLSLPROGRAM is the include files that get included. This implies that included function names could be different too, as you say. But unity is using HLSL syntax (it used to do CG a long time ago).

The inverse projection matrix stuff is a bit different, and you'll find a lot of mis-information about having to pass the equivalent of UNITY_MATRIX_I_VP from C#. Ben Golus to the rescue (again!):
https://gist.github.com/bgolus/a07ed65602c009d5e2f753826e8078a0 which includes world-space reconstruction as part of world normal calcs.
Also it's worth reading the ENTIRE discussion here: https://forum.unity.com/threads/reconstructing-world-space-position-from-depth-texture.1139599/ and noting the diff between post processing and game-object processing since I think you're doing the former.

Gist

Different methods for getting World Normal from Depth Texture, without any external script dependencies. - WorldNormalFromDepthTexture.shader

exotic willow
#

whats the best way to get a smoother outline
I'm just using an offset here for up down left right for the colored outline, which makes it look super blocky and ugly because the base image is pixel art

is there a better way to do this thinker

sinful sparrow
#

Hello is there possibility that someobody could help me why my shader don't use grayscale as transparency?

junior copper
sinful sparrow
hollow juniper
#

is there a way to add the skybox from the current scene onto a shader to be used as a reflection? I see there are cubemap nodes in the shader graph but i do not know how to use it. I am trying this because the volumetric clouds do not reflect onto the shader. But the clouds appear on the skybox

regal stag
# exotic willow whats the best way to get a smoother outline I'm just using an offset here for u...

If you offset by the same size as a pixel/texel the outline should match the pixel resolution of the sprite which might look better.
Would be (1/Width, 1/Height) with values from Texel Size node
Or (Texel Width, Texel Height) from Texture Size node if in newer versions

The are also alternatives, like drawing out the outlines manually and overlaying them on top by sampling two textures in the shader. Or store that outline in alpha channel (i.e. 0 is fully transparent, 0.5 for outline and 1 for regular sprite) - in the shader can mask out each portion with Comparison nodes. Bit longer to setup but a single sample is cheaper.
I've also done something similar here - https://www.cyanilux.com/tutorials/sprite-outline-shader-breakdown/

regal stag
# sinful sparrow

There's definitely some transparency here or the whole mesh would be visible.
Perhaps you want the voronoi effect for the Alpha port only, and connect only the Color property to the Base Color? The multiply is currently darkening the colour.

sinful sparrow
sinful sparrow
regal stag
#

I would also maybe recommend keeping the calculations for the RGB/Base Color and Transparency/Alpha ports as fairly separate chains of nodes in the graph (of Vector4 and Float types), rather than doing a bunch of multiplies and using Split at the end.
Mostly as the previews in Vector4 nodes don't show alpha values, only the RGB, so it can be difficult to visualise.

sinful sparrow
regal stag
sinful sparrow
regal stag
#

And it isn't transparent?

sinful sparrow
#

not at all

regal stag
#

Can you show the Graph Settings (tab in Graph Inspector window)

sinful sparrow
regal stag
#

Hmm it should be transparent then πŸ€”

sinful sparrow
#

when i used "final resault" as an alpha in saturate if works half the way

regal stag
#

You have to be careful about putting a Vector4 into a Float port like that. It truncates the vector down so will take the first component (X/R). If the color property doesn't have a red component the whole thing would be invisible.
That's why a Split is usually used to extract the A channel. But what that contains depends on the textures/calculations you've used. The previews on nodes don't show it, hence why I suggested keeping the RGB and Alpha as separate chains of nodes before

sinful sparrow
#

also im am pretty new to shaders, but i appriceate your help

mild ice
#

how would i go about making a comic shader effect

regal stag
# sinful sparrow either I am not understanding or it dont works, but i suspect first one haha

I don't know the exact setup to get the result you want, but if it helps explain transparency : with an Alpha value of 0, the pixels should be fully transparent, 1 is fully visible. Other values would be partial transparency.

In a node with a float output (ports labelled "(1)" and light blue connections), black in previews will be 0 or negative, and 1 is white or above. Shades of grey are the values between 0 and 1.

The Saturate node clamps inbetween 0 and 1 so you don't have to worry about values outside that range then. I'd recommend always using it before connecting to the Alpha port - as that expects values within that range, and can produce odd results if you pass others in.

regal stag
# mild ice how would i go about making a comic shader effect

Probably a mix between a "toon/cel shader" and "halftone effects". Googling those terms should provide some tutorials.
Maybe also outlines, probably "inverted-hull" outlines or edge detection in post processing, depending if it needs to affect single objects or the whole scene.

sinful sparrow
regal stag
# hollow juniper is there a way to add the skybox from the current scene onto a shader to be used...

If it's a Lit graph type, the skybox should already be included in it's specular/metallic reflections. Might depend on settings in Unity's Lighting window and I'd hit the Bake button to make sure the ambient reflection cubemap is baked.

But if these clouds are a separate object (not part of the skybox material) then that ambient cubemap is not going to include them afaik. If you already have a cubemap containing them, I think you can assign a custom reflection cubemap in the Lighting window too. Otherwise you'd likely need to place and bake Reflection Probes in the scene.

compact reef
#

Im using "legacy vertex lit rendering path"

#

now I have two same grass shaders that support lightmap

#

but i want one of those shaders , not support light map , so what i did is just changed "LightMode" = "VertexLM" to "LightMode" = "vertex"

#

so, the other shader doesnt hold lightmap anymore

#

as im developing this for mobile, was it a good way to manage these shaaders in such waay?

#

or completely removing the lightmap codes and so from the shader would be better?

#

will my implementation affect performance or memory?

opaque crown
#

New to Shader Graph and need a kick in the right direction. Given a grey scale image of some terrain (height map), and an input from 0 to 1, how would I change everything > say .5 to 1 and everything < .5 to 0 ... and perhaps have a fall off range to control the ramped change from 0 to 1?

Just looking for the types of nodes I could use to use here, think I can figure th erest out πŸ˜‰

regal stag
# opaque crown New to Shader Graph and need a kick in the right direction. Given a grey scale ...

It's a little unclear what you're asking. But for > and < there is Comparison node, which would go into Branch. Or can use Step (shorthand for In >= edge ? 1 : 0 iirc) into a Lerp

If you need a falloff, you'd likely want to remap the heightmap value with Inverse Lerp (unclamped, so may want to Saturate to clamp between 0 and 1) or Smoothstep (similar but not linear, already clamped).
Can then Lerp with that.

opaque crown
regal stag
#

Right okay, Inverse Lerp is what you want

opaque crown
#

Thanks ... will look at that πŸ˜‰

regal stag
#

I think you'll want A and B to be something like slider - falloff and slider + falloff

#

I'd probably clamp falloff to .001 as if it's exactly 0 the inverse lerp will be dividing by 0

tall notch
#

I've made this voxel shader for better lighting in my minecraft clone. But the problem is that fogs don't renderer on gameobjects with this shader, and can't do projection. Can someone help me ?

opaque crown
#

Not sure why I'm getting that purple artifact in the lower left corner, prob just bad data in the base texture.

#

Guess it will do for a basic terrain avoidance radar overlay.

broken sinew
#

Is there somewhere a TEX/graphic of a unity projection matrix?

#

because I know that there are some differences between different libraries, for example opengl and others

#

this is the one I found, and I am not sure if that's what unity projection matrix looks like:

#

but I found a bunch of code that seems to work for my usecase, and for example this is how it calculates fov:

float CameraFocalLength() { return abs(UNITY_MATRIX_P[1][1]); }
#

and I don't quite understand it

#

because when looking at the picture above, it seems to me like the UNITY_MATRIX_P[1][1] is ctg(vertical_fov/2)

#

hmmm, I seem to have isunderstood what a focal length is, in that case

#

I thought it is expressed as a distance

unborn wren
#

Hello, in a context of a 2D game, I have several materials made with different shaders, each responsible for a certain special effect. I want to be able to use those effects on a sprite and control it through code. I noticed that the SpriteRenderer is able to only have one material.
Should I swap the material in runtime whenever I need to run a different effect? Is it impossible to have more than one material at a time?

#

another way of solving this would be to cram every effect into a single giant shader but that doesn't seem to be a good solution... ??

pastel oracle
#

Hello,
I have hundreds of particles in my game with predefined colors. I want to apply a metaball effect to them and blend their colors like in the image below. Is this realistic to create via shader? Thank you! πŸ™‚

I succeeded in creating a shader that created a metaball effect (via texture modification) , but then it was possible to apply one color to the resulting texture and thus not create blending.

broken sinew
#

the obvious choice is deferred rendering path for that

pastel oracle
broken sinew
pastel oracle
#

I based it on this shader, but as you can see, final result is colored via one color and particles colors are forgotten

broken sinew
#

what if you tried with the input texture with differently colored particles?

#

step over alpha instead of red channel

#

(assuming the black was alpha)

#

there are many metaball examples on shadertoy

#

they most commonly use SDFs

pastel oracle
pastel oracle
broken sinew
#

I've seen some good examples in pure CSS with filters, so if you search you should be able to find how it would probably exactly look like if done in shaders

fallow zephyr
#

hey can someone help me add reflection and divide into the emission node without combining them?

main lily
#

So I am watching a tutorial on how to stylize bloom shader into comic style circles, and it gives me an error in the custom shader pass script that 'source' is null value, any way to fix it?

#

error btw

full tapir
# meager pelican Well, just FYI...in BiRP you're using HLSL, not CG. You may already have this...

thank you very much for clarifying the difference between CGPROGRAM and HLSLPROGRAM. And also thank you for the examples you provided, the second one i already looked at, the first one i didn't.
In any case, the problem is not the reconstruction of world position from the depth texture, rather the transformation of the world position to local position, for recreating the UVs for the decal.
What i resorted to is this one, and it works:
```CS
MeshRenderer mr;
void Update()
{
Matrix4x4 worldToObject = mr.worldToLocalMatrix;
mr.materials[0].SetMatrix("WORLD_TO_OBJECT", worldToObject);

}```

Basically this matrix should be the same as unity_WorldToObject. In practice tho, unity_WorldToObject flickers (for some reason, only when the MeshRenderer is rendered with the in-game camera, and not the editor camera), and the translation part of the matrix is not consistent.

#

Now, passing the matrix this way causes a new material instance per decal, and it's something i would like to avoid if possible

noble tree
#

hi all πŸ‘‹ im using Graphics.RenderMeshInstanced to render a bunch of cubes and i'd like for each of them have different properties, like translation, scale, color, etc.

i currently have it working by sending multiple arrays to the shader with material.Set???Array and reading them in the shader with UNITY_ACCESS_INSTANCED_PROP. but i feel like this could be improved if i sent a single array of structs containing per-instance data.

on the shader side i have:
- a struct with per-instance parameters
- a shader that supports instancing, but does not support my custom struct. im not sure that the standard way of accessing instance uniforms will work.

UNITY_INSTANCING_BUFFER_START(InstanceProperties)
  UNITY_DEFINE_INSTANCED_PROP(CubeInstanceUniform, _InstanceUniforms)
UNITY_INSTANCING_BUFFER_END(InstanceProperties)

on the C# side i have:
- a struct that matches the one in the shader
- a NativeArray containing data for each instance

i'm pretty sure i need to pass in a GraphicsBuffer to the SetBuffer method on Material/MaterialPropertyBlock to get my data from C# to the shader, but i can't quite nail down how to create a GraphicsBuffer and update it with the contents of the NativeArray.

would appreciate any insight πŸ™

meager pelican
# full tapir Now, passing the matrix this way causes a new material instance per decal, and i...

Does the flickering look like z-fighting? IDK what you mean by "not consistent" on the translation part.
Anyway, if you must pass a custom matrix for each instance, you'll have to used Material Property Blocks and instancing code in your shader for each instance. It won't work (as you found out) to just set a shader-level variable via mesh renderer.
https://docs.unity3d.com/Manual/gpu-instancing-shader.html

meager pelican
# noble tree hi all πŸ‘‹ im using `Graphics.RenderMeshInstanced` to render a bunch of cubes and...

The docs have a pretty good example of using a custom struct to set up an instanced call via Graphics.RenderMeshInstanced. They use a custom "weight" struct member.
https://docs.unity3d.com/ScriptReference/Graphics.RenderMeshInstanced.html
The Graphics.RenderMeshInstanced call passes your array of custom structs as the 4th item in the function call. IDK why you'd need to set up some kind of graphics buffer.
AFAIK, the standard instancing syntax should work in the shader, but of course the shader must support instancing.

#

In this case, you're not using MPB's, and you don't even need game object reference. The required struct member includes the object to world transformation matrix.

noble tree
#

but the example in the docs indicates that the example weight is not used for rendering, and that "The instanced rendering ignores any other members you include in the struct for your own use."

noble tree
full tapir
#

will try what you suggested with MaterialPropertyBlock

vivid ferry
#

doing by tutorial https://youtu.be/gRq-IdShxpU
but cannot connect normal node to normal field in master node

In this video, we'll take a look at how we can use the Shader Graph feature in Universal Render Pipeline, or URP for short, with Unity to create a water shader! The water shader can be simple or complex, and include the features you desire. Let your imagination get wild in this tutorial, or simply follow step-by-step to get about the same result...

β–Ά Play video
#

going reverse from master to normal maps shows that this field do not support sample texture 2d, only sample texture 2d LOD

#

nvm wrong field. Needed the one at very bottom, not at the top

full tapir
#

ok, thanks to the boss @meager pelican now it works. It's not possible to define a float4x4 as a material property in the shader, but setting it with MaterialPropertyBlock still works. Now the matrix is right and doesn't flicker, and it's still maintained only as one material instance. i really don't know what will happen on different platforms but for now it works on pc. the most mysterious thing is the flickering in unity_WorldToObject. I will submit a bug report soon hoping to shed some light because it drove me mad

#

also, the instancing magic uses something called CBUFFER, which is a constant buffer, from what i have read it's used to define renderer specific data. Can somebody point me to a resource that goes in depth on the intricacies of CBUFFERs? haven't been able to find much. Even books or code comments

meager pelican
# full tapir ok, thanks to the boss <@573586703202254878> now it works. It's not possible to...

From what you say here, I realize what happened.....not a bug.
The "flickering" is due to the fact that EACH INSTANCE has a different WorldToObject matrix. If you were setting it in a single shader variable with shared instances of the same material ref....you only got the "last one". That's why you need MPB's, because it stuffs the unique value of that matrix into that CBUFFER you're talking about for each instance index.
IDK why they didn't call MPB's "Instance Data Blocks" but they didn't.

As to Constant Buffers, they're an attribute of (A) how GPUs work and (B) how the API implements those workings, but every API is going to have a way for the engine to submit a buffer-of-data concept, in a big batch, to the GPU. Since we're working in HLSL, here's some of the background of it from Microsoft: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-constants

Now, Unity's ShaderLab syntax is a bit different than what you'd see if you were writing directly to the DX API in C++, for example, but that's the whole benefit of using an engine! Unity will be able to translate its syntax to different APIs if you conform to their lexicon. Their shader compiler and engine take care of all that API-specific stuff for you.

All you need to know about them is they are an array of structs, that are constants in that draw call, and the engine submits the whole array at once into a buffer.

So Unity's instancing methodology passes you an "instance index" and an array of structs that you define with MPB specifics and it has its own internal transform matrix and such passed by default so each instance of an object gets a unique transform matrix. But it can't know ahead of time that you also want a unique color, or maybe a unique scale, or unique something-else. Hence the need for MPBs.

In Shader Model 4, shader constants are stored in one or more buffer resources in memory.

meager pelican
# noble tree but the example in the docs indicates that the example `weight` is *not* used fo...

Glad you got it working.
That example is a bit...vague. It COULD use weight in the shader, it's just that it's not a necessary thing that ALL objects would need....like they ALL need the ObjectToWorld matrix, and they could all need that motion vector data. But "weight" isn't something they'd anticipate as "standard". Basically, if the shader didn't use weight at all, there's no reason to pass it to begin with. They'd do better rewriting that with something that is used in the example, like instance-specific color. What they're saying is that they require certain things in that struct, named certain ways, but you can add more things, they'll pass it on to YOUR shader for YOU to use, but they will ignore it in Their logic.

pastel oracle
#

@meager pelican Hello, I see you are trying to give advice, can I also ask your opinion on my problem? Thank you πŸ™‚

meager pelican
warped barn
#

Is it normal for a shaders to have 5GB+ memory usage? πŸ˜₯

warped barn
pastel oracle
# pastel oracle Hello, I have hundreds of particles in my game with predefined colors. I want to...

@meager pelican Don't apologize at all πŸ™‚ I already asked yesterday, so I'll do a quick recap:

  • want to create metaball effect on particles (particle is gameobject with colored circle sprite)
  • in scene is variable number of particles (player is spawning them), the total number is in the hundreds up to two thousands
  • the colour of the particles is not the same, so the created metaball should create some color blend
  • particles are not overlaping, they are trying be at a certain distance from each other (using SPH for physics)
  • according to yesterday's advice I tried blur+step+clip method, but results were not overwhelming, I got almost no blending in my case

In previous tests I converted the particles to texture using the camera and then applied shaders to them to create metaballs, but the problem was in the following application of color blending. Do you have some idea, how would you try to create it? Thank you πŸ™‚

unborn wren
#

is there a way to have more than one material on a SpriteRenderer or do I need to pack every special effect into a single shader and a single material?

grizzled bolt
unborn wren
#

swap the shader or swap the material, or it's the same thing?

grizzled bolt
grizzled bolt
unborn wren
#

I see, so most games would just have one effect for one sprite at any given time. If I need a different effect, I swap the material for the time of the effect and swap back.

grizzled bolt
unborn wren
#

so using these, I can have one big shader and just use what I need by setting thoes keywords dynamically in code?

grizzled bolt
#

In the case of URP and HDRP it can get a bit technical when making sure you can swap them at runtime smoothly

unborn wren
#

I use URP

unborn wren
#

thanks!

#

so there's two ways to do it - either have one big shader and disable/enable what I need, or have multiple shaders and swap in runtime

#

if I understand correctly

sharp garden
#

anyone run into any issues with directional lightmaps in your shaders on Unity 2023.3 when running on Android? the shader now just renders a muddled texture with random lines, and I have to pass the nodirlightmap pragma in the shader for the textures to work again, but that of course disables the lightmap and makes the model dark.

broken sinew
#

Have you tried more advanced compositing, perhaps multiple layered blurs and some color enhancements like color dodge or something?

grizzled bolt
sharp garden
#

Yeah I think it's just broken in 2023 at this point. it was fine in previous versions. we are on built-in so can't use APVs AFAIK but I haven't looked into them much

#

of course they didn't back port some of the features we upgraded to 2023 for to a more stable LTS or something, and they've broken features that have been working fine prior.

grizzled bolt
sharp garden
fleet olive
#

ive got this really strange issue with shaders

#

some of my pixels are turning strange colors

#

using a 256x256 texture

#

i get this

#

really weird colored artifacts

#

with a 2k texture, this

#

blue,pink and green/pink

#

its much more visible in the step function where im relating the texture to the foam intersection data

#

before the step function it looks like this

#

this is what is put into the edge part of the function

#

looking like this with some other bits all in all

pseudo narwhal
fleet olive
#

the color channels represent opacity

#

black being transparent and white being opaque

#

alpha isnt used

pseudo narwhal
#

doesn’t change what I said

#

you don’t need 3 channels to make a grey map

fleet olive
#

i guess

#

if theyre ranging from white to black all the values will be the same

pseudo narwhal
#

Just move the pin from rgb out to r out

fleet olive
#

yeah i did that

#

works fine now except for the foam is like

#

partially transparent?

#

when combined with the surface foam it becomes whiter

#

the intersection foam isnt particularly contrasting anyway, it blends a lot more than I want it to

#

even when my blend factor is absolute

#

all im doing is adding the intersection foam on top

#

intersection foam blend is 0 so the value is unaffected

grand jolt
#

I needs help. On the avatar , I put a material on the eyebrows but whenever I go In play mode and go in vrchat its pink

frozen sky
#

can someone help... I want to try to make a shader kind of like this, without the outline, but I cant find any resources anywhere

I've tried using outlines for selection but I haven't found any solution that isn't just buggy in general

#

basically just a color overlay shader

strange basalt
#

what is buggy, the hardest part of what you see there is the outline

#

otherwise its just multplying or adding color on top

#

though in that example its pretty obvious this is happening in screen space due to it also effecting the shadow

frozen sky
#

the outline has been buggy and thats why im opting to just not use it

#

im incredibly new to shader graph... i figured all i needed to do is multiply the color but which node do i use to get the color of the object itself on the screen?

strange basalt
#

well the outline really only would be easy to do if this was done as a render feature and done in screen space

#

more or less render pass that draws the "selected" objects into a buffer, then later on you use that buffer to blend in color on the screen

cursive jewel
#

Why is it like this? Combine node's alpha should be same as subtract node right ??

mental bone
#

Preview in nodes does not show alpha values

#

If i am not mistaken

cursive jewel
#

Even in editor the alpha is not showing

#

It's opaque

grizzled bolt
mental bone
#

Is your material set to opaque? Recently I noticed that even enabling alpha clip for example in the shadergraph the actual material settings don’t change to reflect that

#

Btw guys my gore system still has the problem that the buffer containing clip weights is uninitialized during editor time. Problem is that I need to clear it in OnDisable to avoid leaks so even if I do something in Reset or what ever it gets cleared when we exit play mode. Anyone know of a solution ?

#

Im thinking of actually having two completely different buffers and something hooked into the editor events to switch them. But seems hacky

copper shoal
#

why is my preview that but in my scene it appears as this

grizzled bolt
green zephyr
#

hi all! I'm building a baked shadowmap system. I preprocess the shadowmap to get nice soft shadows with only one sample. Thing is, when dealing with large levels I'd like to split the shadowmap into tiles because the memory cost can be quite high if everything is loaded at max res (8k R16 texture for each 1km^2 light frustum tile). Now, I'm trying to use TextureArray2D to store tiles, and try to set the desired mipmap level according to camera position using Mipmap Streaming. But it seems Mipmap Streaming does not work with TextureArray2D. Does anybody know about this? Also, virtual texturing which could be another solution seems to have been abandoned 😦

#

That's the resolution i'm going for, in a 4x4 km scene. When blurred it looks nicer ha

#

In the case of sun directly overhead, 16 baked shadowmap tiles. But without TextureArrays, the sampling gets a lot uglier. I may have to go deep into loading/unloading unmanaged textures...

odd warren
#

I'm extremely new to Unity sorry, but is there a way for my texture not to get stretched on thinner walls? I don't really know what's going on but it sure doesn't look good

grizzled bolt
odd warren
#

ohh, that makes sense!

#

Where does one find those strechy UV maps?

grizzled bolt
odd warren
#

ohhh I see I'll look this up thank you :))

snow forge
#

Evenin' all. Soooooo, using Shader Graph (URP), is it at all possible to 'find' the darkest pixel in an image and the brightest pixel? (need to 'normalise' a grey scale image between black and white), example attached......

#

I know to use the remap node, but the problem is that there are a bunch of images and they all have differing 'lowest/highest' values. πŸ˜•

regal stag
snow forge
#

Thanks though πŸ™‚

regal stag
snow forge
strange prairie
#

Does anyone know if it's possible to clear the Metal shader cache on MacOS?

#

I saw a massive PSO stutter - once. I wrote some code to precache this material but I don't know how to test it

edgy crane
#

Hey there,

Is there a way to pass a list of float (of varying size) into a shader graph ?

mental bone
#

You can pass in a buffer thats fixed size

#

You could pre-allocate a big enough buffer and pass in a extra variable indicating up to where in the buffer to read

edgy crane
mental bone
#

Oh shadergraph does not have a buffer property for the black board

#

You need to define it in a custom function node

broken sinew
#

I am writing a custom shader with vertex + fragment code (important here is that I don't use surface shaders for now) in BRP. How do I call some "standard shading" in the fragment color?

#

for example my current fragment part:

    SurfaceOutput s;
    s.Albedo = YELLOW;
    s.Alpha = 1.0;
    s.Emission = 0;
    s.Gloss = 1.0;
    s.Specular = 0.5;
    s.Normal = sdf.normal;

    UnityLight l;
    l.color = _LightColor0;
    l.dir = normalize(_WorldSpaceLightPos0 - sdf.p);
    l.ndotl = 1; // unused

    fixed4 color = UnityLambertLight(s, l);
    color.rgb += ShadeSH9(half4(sdf.normal, 1));

    fixed4 gridColor = sdf::debug::worldgrid(sdf.p);
    frag_out.color.rgb = lerp(color, gridColor.rgb, gridColor.a);

    return frag_out;
#

but it looks a bit... off ?

#

like why is albedo only visible where it's lighted

#

UnityLambertLight is from Lighting.cginc
There is also LightingLambert but idk where do I get UnityGI gi from

edgy crane
mental bone
#

A buffer is just a gpu array

#

And inside a custom function node you can write hlsl that reads the buffer like a normal array

#

Then you can do with the values as you please

edgy crane
#

I see. I think I get the general idea but it's a bit out of my reach for now, I will need to look into it πŸ™‚ Thank you !

mental bone
#

Your texture idea is also something that is done and is very viable. It is done to this day on devices that dont support buffers

amber bison
#

anyone got any good water shaders with ripples for vr that arent laggy at all for stuff like quest 2 and 3 standalone

#

also mainly urp shadergraph

odd quarry
#

Has anyone gotten intellisense to work for Built-in shader include files in VS Code? I have the Shader languages support for VS Code extension and my *.cginc associated with "hlsl" in my settings.json. Intellisense works for HLSL but not for the helper functions.

exotic willow
#

https://www.youtube.com/watch?v=mRDG5sQYjdo&t=993s
in this video he creates a texel size node
but thats not a thing in mine thinker any idea why

Heya Pals!

This week's tutorial is a bit of a deeper look into shaders using Unity's Shader Graph, where we build a custom outline shader from scratch while discussing the ins and outs of the tool.

Enjoy!

Music:
Helynt - Our New Horizons [Gamechops.com]

Chapters:
0:00 - Introduction
0:47 - Why use shaders?
1:48 - Getting started with Shader ...

β–Ά Play video
edgy crane
#

Hi there !

That may be an obvious question : I'm trying to construct a Custom Node that takes in a float and an Array of Vector2 (of fixed size at runtime) and return a float (an int technically but who cares). As I understand I need to use the "File" Type Custom node with a code inside a file. So my question is simply what type of files ? ^^" txt or something in particular ?

edgy crane
#

Here is a representation of what I'mtrying to accomplish with an array of 4 Vector2:
But obviously, depending on the object, the size of the array could be anything from 16 to 1600. And while the size of the array will not change at runtime, the content will ^^

exotic willow
#

hmmm... anyone know why my outline shader (left) is making the object seem more faded than just the image (right)

edgy crane
edgy crane
#

Custom Node

exotic willow
edgy crane
exotic willow
#

would be the first

edgy crane
#

Then go in your Graph inspector

#

You will have the setting for the type of material , switch to lit

exotic willow
#

ah awesome
thanks, found it

north shadow
#

I am a beginner I cant seem to figure out why material is graying out in a 2d game

granite lion
#

how do i fix my cel shader acting up

#

idk if its because its a cylinder or what

#

i fixed it nvn

#

nvm

onyx ferry
#

Hi everyone. I know a lot of people have probably mentioned this before, but I'd like to create something similar to tesslr8s pixel art shader. How would I go about initially getting the pixelated look? I understand that a lot of its visual style comes down to a lot of additional tweaks such as toon lighting and outlines. I will figure that out eventually, just need the starting point.
https://www.youtube.com/watch?v=NutO1jzuVXU

Date of Recording: 2020-10-10

Following the example of many 2D pixel art games, we render our scene at a low pixel art resolution (640x360) and upscale the result to the screen resolution for presentation. At render-time, the camera is snapped to the nearest "pixel", and when blitting to screen, the snap offset is corrected so that the camera i...

β–Ά Play video
round shoal
#

Hi guys, i have a little problem
im following this tutorial and his shadergraph looks like this

#

i replicated all the steps just like it shows and i have the very same version of unity and everything on point

#

but my second multiply does not work

#

does anyone have some idea? it is blank

regal stag
regal stag
woven prism
#

Hey y'all, does Z test have VR issues? I have a series of Z test disabling shaders and some stuff modifying the queue values in order to produce a world-space blackout screen that renders over everything, while also allowing certain objects to render over the blackout. It looks like the attached image.

However, shader seems to struggle with VR, and the blackout screen and the other objects using the custom shader are only rendering on the left eye. Does anyone see anything potentially problematic with this shader? Oh it's too long lemme attach it in a separate message.

#
Shader "UI/Default_OverlayNoZTest"
{
    Properties
    {
        [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1,1,1,1)
        
        _StencilComp ("Stencil Comparison", Float) = 8
        _Stencil ("Stencil ID", Float) = 0
        _StencilOp ("Stencil Operation", Float) = 0
        _StencilWriteMask ("Stencil Write Mask", Float) = 255
        _StencilReadMask ("Stencil Read Mask", Float) = 255

        _ColorMask ("Color Mask", Float) = 15
    }```
#
    SubShader
    {
        Tags
        { 
            "Queue"="Overlay" 
            "IgnoreProjector"="True" 
            "RenderType"="Transparent" 
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }
        
        Stencil
        {
            Ref [_Stencil]
            Comp [_StencilComp]
            Pass [_StencilOp] 
            ReadMask [_StencilReadMask]
            WriteMask [_StencilWriteMask]
        }

        Cull Off
        Lighting Off
        ZWrite Off
        ZTest Off
        Blend SrcAlpha OneMinusSrcAlpha
        ColorMask [_ColorMask]

        Pass
        {
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            
            struct appdata_t
            {
                float4 vertex   : POSITION;
                float4 color    : COLOR;
                float2 texcoord : TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex   : SV_POSITION;
                fixed4 color    : COLOR;
                half2 texcoord  : TEXCOORD0;
            };
            
            fixed4 _Color;

            v2f vert(appdata_t IN)
            {
                v2f OUT;
                OUT.vertex = UnityObjectToClipPos(IN.vertex);
                OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET
                OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
#endif
                OUT.color = IN.color * _Color;
                return OUT;
            }

            sampler2D _MainTex;

            fixed4 frag(v2f IN) : SV_Target
            {
                half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
                clip (color.a - 0.01);
                return color;
            }
        ENDCG
        }
    }
}```
#

unfortunately I'm a relatively new Unity developer and I don't have a good grasp of shaders (I'm currently taking linear algebra, if you want a benchmark for my technical knowledge), so I don't actually know what this shader is doing other than disabling the ztest and what it's doing with the queue

round shoal
woven prism
round shoal
#

DUDE YOU'RE AMAZING

#

how can i thank you

echo briar
#

Hey! Currently trying to implement sepia tone effect on my UI images, everything works fine as soon as I use UI Masks on parent gameobjects, the whole UI image disappears! Not even using stencil make things work.

woven prism
#

at least until something else in VR breaks clueless

honest bison
#

Does Unity work with BlendAdd type shading? I ask because the results from my compiled shader are not as expected. I would expect areas in the alpha channel with a value of zero to be added, while areas with one to be blended. Why is this not the case? Can anyone elaborate?

#

Another way to say this is that One OneMinusSrcAlpha and SrcAlpha OneMinusSrcAlpha look exactly the same.

fleet olive
#

how do i prevent mynormals from like

#

making the sun look goofy af

#

they also just look kinda weird in general

#

they dont really look like how light would bounce off the water

#

and theyre strangely distinguisted

steel notch
#

Ok I think I'm confused at something here. I have this texture, which linearly interpolates from 0 to 1 in all channels in the horizontal of the image.

#

I have a Shader Graph that compares the value from the R channel against some defined value. If it's above the value, it makes it black, otherwise it's white.

#

I would expect that if the comparison value is 0.5, I should expect the division from white to black to occur halfway across the image.

#

It does not.

#

Why is this?

#

Just to confirm, this is the code used to generate the texture.

        Vector2Int dimensions = new Vector2Int(512, 512);
        var texture = new Texture2D(dimensions.x, dimensions.y);
        for (int x = 0; x < dimensions.x; x++)
        {
            for (int y = 0; y < dimensions.y; y++)
            {
                float distance = (x / (float)dimensions.x);
                texture.SetPixel(x, y, new Color(distance, distance ,distance, 1));
            }
        }

        var data = texture.EncodeToPNG();
mental bone
#

Anyone got any ideas on generating random blood splats from noise ?

amber saffron
amber saffron
steel notch
#

Is there some nonsense where it was stored as a logarithmic scale?

mental bone
#

I'm adding on another layer that paints blood based on a hit. Essentially I have a shader that executes on a RT in uv space. So i was thinking of using some worldspace based noise to "create" the splat. Soooo fully random on surface I guess.

amber saffron
#

Typically, you want to enable sRGB for everything that represents colors, and disable it for all the rest (normal, surface data maps like specular and metallic, masks ...)

steel notch
#

You mentioned a specific format when I created the texture, what should I be looking for?

amber saffron
steel notch
#

Is this something specific for the GPU?

amber saffron
amber saffron
steel notch
#

Disgusting

#

Actually Remy, would it be alright if I DM'd you a more involved question?

amber saffron
#

Basically, figure this : if on a screen you were to display a gradient by varying the "voltage" of the pixels linearly, you would percieve it with more white than black. This is because the eyes response to intensity is not linear. sRGB "flags" the texture/color to apply a curve on those intensities so the percieved gradient is nice like we would expect it πŸ˜…

steel notch
#

Thanks I appreciate it.

steel notch
#

Mind accepting?

grim bear
#

Hi, i'm new to shader programming,
There are 2 objects

  • The big square (let's call it background)
  • The smaller sprite (let's call it small_object)

i'm trying to project small_object's UV to big square's UV.
so based on the picture, the small_object's UV should be almost all green

any idea how to do this? thank you

amber saffron
low lichen
grim bear
amber saffron
grim bear
amber saffron
#

Well, you have to get their sizes and positions based on the sprites object, and pass them to the material with c# code.

#

You can do most of the math in c#, and just pass the tiling and offset value to the material.
tiling is smallSize/BigSize
offset is (smallPos - bigPos) / BigSize
(relative position of the small object over the big one)

grim bear
pastel oracle
#

@amber saffron Hello, I apologize for mentioning you like that. Could I ask you about my problem, too? Thank you! πŸ™‚

amber saffron
pastel oracle
amber saffron
junior copper
#

when using a material on a image, the outline comp doesnt work

#

any workarounds ?

granite lion
broken sinew
#

where can I read more about the exact math behind "perspective correction"?

exotic willow
amber saffron
low lichen
exotic willow
#

is sine sintime

#

theres nothing i can find with that name

amber saffron
exotic willow
#

oh kekw_dog
thanks

wild marlin
#

is it possible to use vertex shader on UI element? to create a distortion?

viscid knoll
wild marlin
amber saffron
wild marlin
amber saffron
#

So you have to rely on pixel distortion

wild marlin
#

With the base colour, right and not vertex