#archived-shaders

1 messages · Page 247 of 1

unique oar
#

And all of those are valid statements. It's only when I comment out tris.Append(toAppend); that my shader compiles.

idle pumice
#

Can anyone reccomend a resource for an invisible object that casts a shadow in URP?

pls tag me in respone

unique oar
#

@idle pumice no need for a shader. set the mesh renderer to shadows only

meager pelican
unique oar
#

I've also tried changing it to an AppendStructuredBuffer of floats and appending a float, just to see if it's an issue with my struct. Still got the same issue.

meager pelican
#

Since it may be a compiler bug, maybe break the kernels out into separate files, one for the append logic, another for reads and such.

#

Total SWAG (Silly Wild Azz Guess)
Other than that, I guess you should report the bug...

unique oar
#

nice okay discord crashed before i could send my message

#

anyways I tried a second compute shader that writes to an appendbuffer and it worked. So something's wrong with my code, I guess

#

I don't really want to split the appending into its own kernel because that would be a lot of work, but I might give it a go if nothing else is working.

#

Here's my whole script, if anyone wants to take a look. I want to be clear I'm not looking for code review. I know it sucks and probably doesn't work lol, but that's stuff I like to figure out on my own. Just looking for help with line 370 preventing the compiler from working. (also yes there are like 280-something lines of precomputed values in total, sorry)

meager pelican
#

OK, since it could be a compiler bug...anything goes.
Maybe change something else.

Check that int3 and uint3 are matching up. Looks like tri is a uint3 in the struct and you use an int3 constructor. This is just before the append statement, so maybe the compiler is getting screwed up internally.

Or like that index variable. Starts at 0 in CSMain, and is an inout to the function, but it is always passed in as a zero (at least right now). So get rid of it temporarily, and keep track of index in the function. Just to generate different code, for now.

Since you tried a separate compute shader with append buffer in another test and it worked, doesn't sound like it's your setup that's the problem, so generate different code. Just my 2cents.
Otherwise, you're back to reporting a bug, that's all you can do.

#

I'm totally guessing here, but by eliminating line 370, you also eliminate dependencies. And the optimizer logic may throw away some variables as unnecessary BEFORE it tries to generate any resulting code from the remaining logic. So by throwing stuff out, it bypasses whatever is causing the error. But keeping line 370 intact forces it to generate the code to use all the stuff being calculated. And somewhere along the line, in the dependency chain, it gets messed up and pukes.

unique oar
#

I'm gonna keep fiddling with the code. I really hope it's not the compiler screwing up its optimization. Thanks for your help!

meager pelican
#

Yeah, glad to, it's a curious thing!
I know the code is a work in process, I was just trying to think of things that you could screw with in the dependency chain of calcs.

Anyway, good luck. These things are the worst to track down...if you can track it down at all. Keep us posted!

unique oar
#

Will do!

meager pelican
unique oar
#

@meager pelican tracked down the issue

#

It only happens when I use Append in a loop

#

unfortunately I can't get around this by simply putting it in its own method. compiler's too smart for that

#

damn it, some nested if statements won't work either

#

god i hate this

#

Okay NEW problem now. The compiler is detecting this as an infinite loop????

#

for (uint i = 0; i < 16; i += 3)

#

i'm so goddamn confused what is even happening

kind juniper
#

Are you modifying the i inside the loop maybe?

#

Or what makes you think that it detects it as an infinite loop?

unique oar
#

Nope, not modifying the value of i

unique oar
#
    {
        Triangle toAppend;

        uint edge1ID[2] = EdgeMap[edgesToConnect[i]];
        uint edge2ID[2] = EdgeMap[edgesToConnect[i + 1]];
        uint edge3ID[2] = EdgeMap[edgesToConnect[i + 2]];

        toAppend.v1 = vertexInterp(blfPos, edge1ID[0] + blf, edge1ID[1] + blf);
        toAppend.v2 = vertexInterp(blfPos, edge2ID[0] + blf, edge2ID[1] + blf);
        toAppend.v3 = vertexInterp(blfPos, edge3ID[0] + blf, edge3ID[1] + blf);

        tris.Append(toAppend);
    }```
#

like nothing there should cause the compiler to find an infinite loop, right?

kind juniper
unique oar
#

I've been messing with the code a bit, so line 355 in the file I posted might be different, but here line 355 refers to that for loop

#

It's really strange that I didn't get this error when I was using an earlier version with an if statement that could break the loop

cosmic vector
#

so im setting vertex color via c# to = 0.1 under certain conditions as a test and when running my shader on it i get this result any ideas?

unique oar
cosmic vector
#

Oh sorry it’s hidden just .1

unique oar
#

gotcha

#

try checking if it's equal to or less than, idk, 0.11 or something like that

cosmic vector
#

Alright

unique oar
#

if the interference goes away, you can shorten that range (absolute value of vert color minus 0.1, check if that's less than like 0.01) so it doesn't go over ur black area too

#

lmk if that works

cosmic vector
#

just got to my pc testing now

#

so heres it with = to .1 and then <=

unique oar
#

did you do <= 0.11 or 0.1?

cosmic vector
#

oh mb alright so .11 does work

unique oar
#

cool! so yeah, it's probably an issue of calculating an exact vertex color. there'll be a small amount of error, probably much less than 0.01

cosmic vector
#

I'll keep that in mind tyvm!

unique oar
#

np!

#

the abs thing i mentioned earlier should hopefully work so u dont need two comparisons :p

cosmic vector
#

I'll try it thank you again

unique oar
#

no problem!

grand jolt
#

so I have a custom mesh export it to unity and some faces I cant see from the back/front , i know its because of normal but how can I make it so that the normals face both direction at the same time?

unique oar
#

every triangle normally would render the back and front, but gpus cull the back face to save on performance. so keep in mind that by doing this, you're rendering twice as many polygons

grand jolt
unique oar
#

might depend on the render pipeline

grand jolt
unique oar
#

you can use your own custom shader to render both faces though

grand jolt
unique oar
#

hmm shoot im not sure in SRP

#

but you could cheat and just make another mesh with the normals inverted

#

you using blender?

grand jolt
unique oar
#

cool, so duplicate your mesh, then on the duplicate, go into edit mode, select all faces (you can usually do this by pressing 3 then A) and press Alt+N

#

that should bring up some sorta menu, which should have the word "flip" on it

#

Click "Flip" and that'll flip all the normals. You can join them if you want by selecting both then pressing Ctrl+J. Then you can export the models.

grand jolt
#

so , I have a custom mesh and I only want some sides to be that ( so that my pc wont crah when loading too much ) . I only selet the ones I want the normals to face both ways and your steps right?

unique oar
#

oh, yes. And actually after you've selected them and flipped their normals, you can do Ctrl+i to invert your selection to all the faces but the ones you flipped, then delete them

#

to save a little more on performance :)

#

you'll want to delete faces only, not verts or edges or anything like that

grand jolt
#

so I duped , flipped and joined them

unique oar
#

do you still have the flipped faces selected?

grand jolt
#

no

#

I can unjoin them and select them

grand jolt
unique oar
#

Alright, you just press Ctrl+i to invert your selection to everything else. Then you can delete those faces since they're just useless duplicates

grand jolt
#

wait

#

do they have to be joined?

unique oar
#

oh, no this should be before the joining, sorry

grand jolt
#

ok ok

#

and delete faces only?

unique oar
#

yes

grand jolt
#

weird

unique oar
#

what's wrong?

grand jolt
#

it didnt change at all

unique oar
#

strange. is that a screenshot in blender?

grand jolt
#

yessir

unique oar
#

oh, yeah, blender usually renders things on both faces

#

but unity culls backfaces, unless you're using URP where you can turn that off

grand jolt
#

maybe I missed something , after I delete the faces do I join them?

unique oar
#

yes, or you can avoid joining entirely if that's causing issues. they'll just be separate models and objects in the unity editor

grand jolt
#

nvm I had to be in edit mode

grand jolt
#

now its facing both ways

meager pelican
# unique oar like nothing there should cause the compiler to find an infinite loop, right?

Right. Groan.
Looks like a shader compiler loop unrolling bug (guessing).
The compiler will likely unroll that loop into several version of itself...
one for 0, one for 3, 6, 9, 12 and 15.

You could try a [loop] attribute that stops the compiler from unrolling the loop. It might be ignored though, compilers don't have to honor the request. IIRC.
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-for

weary pebble
#

Anyone knowing how to reference a switch from shader in amplify shader? ( I only know Shader.SetGlobalFloat...)

amber saffron
weary pebble
#

@amber saffron thank you 🙂

unique oar
swift loom
#

ok so I kind of asked this the other day, but let me try a different angle.

I'm sending a texture to the shader to tell it what to render on the screen, and with actions like digging dirt or placing things i want to update this texture, but right now i'm literally just using setpixel and reuploading the entire texture every time which feels horrible.

Is this something I should use Graphics.Blit for and a render texture instead perhaps? I'm not sure what a more performant method would be.

unique oar
#

@meager pelican alright, looks like the [unroll] fixed it!! and for some reason that fixed the other compiling issue too!!! thank you so much!

amber saffron
amber saffron
swift loom
#

Thank you 🙏 I will look into it

scarlet falcon
#

Hey guys, wondering how do I learn what each variable is in Unity's shaders. For example the 'i' variable in the fragment shader, where can I look up what properties it has, functions I can call on it etc. The doesn't seem to be very good documentation I can find?

scarlet falcon
#

Or for example the 'step' function? Where do I find how to learn about this?

regal stag
# scarlet falcon Hey guys, wondering how do I learn what each variable is in Unity's shaders. For...

i is just a name so could be anything, but it's probably just short for input. It will likely have a type like v2f (vertex to fragment), which would be a struct defined earlier in the shader file. (Some examples here : https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html)
You should be able to see what properties/fields it has in that struct declaration. Each field would be set by the vertex shader - which also has it's own input struct (typically named appdata in Built-in pipeline), which obtains data from the mesh via POSITION/TEXCOORD/NORMAL etc "semantics" : https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics

As for functions, HLSL has some intrinsic functions, like sin, cos, saturate, step, dot, mul, etc. They are listed here : https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions (Can click on them to see which shader models/types they support)

Unity also provides some functions (e.g. UnityObjectToClipPos) and macros (e.g. TRANSFORM_TEX), though that depends on the render pipeline. Some documentation here for Built-in RP :
https://docs.unity3d.com/Manual/SL-BuiltinFunctions.html
https://docs.unity3d.com/Manual/SL-BuiltinMacros.html
Can also read the code. e.g. https://github.com/TwoTailsGames/Unity-Built-in-Shaders/tree/master/CGIncludes (UnityCG.cginc typically being the main one).
For other pipelines (URP/HDRP) can see the ShaderLibrary folder in the package, or look under https://github.com/Unity-Technologies/Graphics.

untold basalt
#

Hello just a question 🙂
The situation:

  • I have one shader with one Texture (which I want to change for each GameObject)
  • There are "many" (100-500) gameObjects (which are generated for terrain) with that shader, and each has a different texture

The questions
1.) Is there some kind of limitation for the count of texture I can use in the game from RAM or VRAM size?
2.) Is there some kind of known count - how many of these objects (not movable, just only static objects with texture) can be in the scene without decreasing the FPS
3.) How does even Unity works with these Textures - are they released as the gameObject became not active? Or out of the screen (e.g., by culling)

Thanks for any insights 🙂

amber saffron
#
  1. I'm not a pro when talking about how this is managed, but from my understanding, as much textures as needed are fit into the vram, then it starts to pile up in the ram and swaps (bad), and maybe later it also goes into some disk cache and swaps even more ?

So there is no real hard count for the number of textures, it depends on their memory size.

  1. This not only depends on the number of texture, but also how the objects are batched together. Less batches (draw calls) = more performance. If using GPU instancing you can drawn fast a crazy amount of objects

  2. AFAIK, a texture is kept in vram even if not rendered unless space is needed

#

For you use case, you might want to try to have a single big texture as atlas for all your objects that contains all the smaller textures, and draw all the objects in a single draw call, offseting the UVs to select the texture to display.

You might also want to look into virtual texturing, but I don't know a lot about how it works

untold basalt
#

Oh okay - thanks 🙂 This is enough for me (for now 😄 )

misty lion
#

Hi guys, does any one know how to visualize point cloud with shaders? I have a lidar scan of vertices locations only. The problem I have now is that I have a obj file of vertices only, and unity does not recognize any of the vertices since there is no mesh.

amber saffron
misty lion
meager pelican
desert orbit
#

@woven haven Don't cross-post. Pick a single channel.

woven haven
#

idk which one it's for shader or post processing

idle pumice
# unique oar

no wonder I couldn't find any current info on it! 😂 Thank you!!

fading quail
#

I dont really know where to post this question, but why does my texture looks a bit weird

#

On the bottom it looks okay, but on the walls it is so buggy

weary pebble
#

Can someone explain how to set up a public switch in Amplify Shader, I dont know how to make it public xD

dim yoke
unique oar
#

So, I've got an array of arrays of ints in my compute shader, which I've defined by simply declaring it, with all its values already typed in.

#

like this, yknow?

#

just a bunch of precomputed values

#

for some reason, every time I try to read an integer from these arrays, it always returns zero

#

what am I doing wrong?

regal stag
unique oar
regal stag
#

Then not sure sorry

meager pelican
#

@unique oarI'm with Cyan...I'd say the same thing.
Adding "just set it from C# if it won't initialize when static".
If you need that same table in several shaders, use a shader global.

Another thing to try is a single-dimension array, and compute row/col the index yourself. That might aid you with the SET functions.

#

I'll add IDK why you often have to do this from C#, since the compiler should just allocate an internal CBUFFER for it and load it with the shader. And IDK if it is Unity specific issue or shaders in general, but I've hit it before and end up just doing it from C#.

kind juniper
#

Wouldn't that have to do with an array like that basically being an array of pointers? I guess GPU wouldn't like that.

kind juniper
unique oar
#

im so done with this 💀

#

gonna just scrap my whole shader and script and start fresh. maybe it's just something wrong with my code. i'm staying forever fcken doubtful of the compiler though, with the way it flagged loops that terminated after only 5 iterations as "infinite loops"

#

NO I KNOW WHAT THE ISSUE WAS

#

had some integer variables corresponding to moving right, up, and backward throughout sample positions

#

they were not static

#

thank you guys so much im sorry i wasted your time lmfao

kind juniper
unique oar
# kind juniper Can you explain a bit more what the issue was? I'm curious.

So, it's a marching cubes algorithm, and I'm representing each 3D sample point with a single integer index. The sample points x, y, and z indices can each be from 1 to 8, and thus there are 512 possible single-integer indices. Increasing the index by 1 corresponds to a shift to the right, increasing by 8 corresponds to a shift upwards, and increasing by 64 corresponds to a shift backwards. I had these amounts (1, 8, and 64) stored as their own variables, so I could just do index + back to shift backwards, really just so i wouldn't make any mistakes. However, I hadn't marked these variables as static, so they were all initialized to zero

#

I'm still not sure why it caused such widespread issues, and so I'm probably going to rewrite my whole algorithm again anyways because it's obviously so messy

#

But that seemed to be the crux of the problem

#

I'm really not sure why that only started causing the shader to return no triangles (and thus seem as though all the values in my table had been initialized to -1)

#

But it's hopefully something I won't have to return to after I rewrite my shader.

unique oar
#

Just finished rewriting. It fully works! Thank you all so much! I would have probably just given up partway through if you guys hadn't helped me out there 😅

kind juniper
#

Shaders are a pain to debug, but it feels great when they finally work.😬

meager pelican
lusty wadi
#

unity 2019: i'm trying to make a render pipeline asset, cuz otherwise i cannot do anything, but i don't seem to have the option to create a render pipeline asset?
I thought there is a core pipeline asset without importing from the asset manager

shadow locust
#

Builtin Render Pipeline doesn't use a pipeline asset

lusty wadi
#

right, then i need to get LWRP

#

and now find a way to get custom shaders to be rendered..

cosmic belfry
#

How does one write a shader for text mesh pro text ugui so that it animates the hand writing effect? You should be able to see each stroke being drawn out. Sort of like the first 5 seconds of this video: https://www.youtube.com/watch?v=GbMX20YoNTw&ab_channel=SonduckFilm

Learn how to create the handwriting effect! In this After Effect tutorial, we will take text and animate it on with a “write-on” style. This effect is very easy to do and there is two ways to do it. The fast way where you can add the stroke effect to your masked outline and animate the end parameters. Or the best way where you use the pen tool t...

▶ Play video
amber saffron
lusty wadi
#

weird, i thought you can make shaders work without render pipelines

lusty wadi
#

i made a lwrp pipeline, made somehting in shadergraph with fresnel noise and a texture, compiled it and put it in a normal .shader file, removed the lwrp, made a material using that .shader file, but the fresnel dissapeared
The texture2d did show correctly, but the effect was lost..
i need to work with no rp, and wanna make an edge shader..

grizzled bolt
lusty wadi
#

ffffff

#

got it... damn it

grizzled bolt
#

I feel like you're mixing up terminologies

lusty wadi
#

that was a problem of not having lwrp imported

#

and "anything" meant "do any shadergraph work"

#

i thought making a shader in graph is miles easier

grizzled bolt
lusty wadi
#

ugh

#

thanks for the help

#

what im trying to do is impossible.

#

at least i know now

grizzled bolt
#

Yes basically
Non-srp shaders were all hand-written back in those verisons, or authored with something like Amplify

lusty wadi
#

i did find about Amplify, but idk what it is, i thought it was proto shader graph

grizzled bolt
#

Making the shader with shader graph in 2021.3. for built-in RP and bringing it back to 2019 might work, but it's a long shot

lusty wadi
#

god no

#

imma be real, im using 2019 cuz im working on vrchat stuff, and was wondering how their big shaders are made; thought you can make something easily, and you don't need a shader wizard but.. yea, thanks

grizzled bolt
lusty wadi
#

wait so.. with no render pipeline, can i get any shader from.. say, shadertoy and import it to unity?

cosmic belfry
amber saffron
amber saffron
dusty creek
#

following a tutorial for a cel shader, now I test things out but shadows don't get cast on objects... is this normal or did I do something wrong?

fair crest
#

How do I do I replace the white in my shader with another color, I've tried all the blending stuff without success

white marsh
#

You can also fo it yourself, its not very hsrd either but i don't remember how to do that since using usepass is just so much easier and its the same thing anyway

dusty creek
#

I'm using shadergraph

#

do I just make a seperate hlsl shader then?

white marsh
#

Oh, well idk. I don't really use the shader graph that much. Especially for cel shading

#

You can probably find it on google if you try searching for enable shadowcaster in shadergraph

dusty creek
#

ah ok I'll do that. thanks :D

white marsh
#

Though id think whatever tutorial you are following would add it as well shruggie

dusty creek
#

I may have missed it

fair crest
#

how would one separate a gradient into a few steps kinda like a toon shader

white marsh
#

You would use the step function

fair crest
#

thanks

#

what i was looking for

regal stag
#

@white marsh The shader is already casting shadows, the problem is it isn't receiving them.
@dusty creek You can calculate the shadowAtten via a custom function - the tutorial might already be doing that, hard to say without seeing it / the graph. e.g. Should be using GetMainLight with a shadowCoord parameter :

float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
Light mainLight = GetMainLight(shadowCoord);

If you're using an Unlit Graph, you also need to specify some keywords for it to work (mainly _MAIN_LIGHT_SHADOWS, but ideally also _MAIN_LIGHT_SHADOWS_CASCADE and _SHADOWS_SOFT). Can set them up as Boolean Keywords via the blackboard.

Alternatively I've got a package which includes some SubGraphs, like "Main Light Shadows" which returns the ShadowAtten & handles the keywords for you. https://github.com/Cyanilux/URP_ShaderGraphCustomLighting

dusty creek
#

many words I don't get but I think I can figure it out with this and some googling xD thanks a lot <3

white marsh
#

Btw which tutorial are you following? There is a really in depth and detailed toom shader graph tutorial on YouTube by Ned Makes Games

regal stag
dusty creek
#

I'll see what happens if I do the shadows as well

dusty creek
#

old tutorial, I don't have a field to put those keywords in, and if I type them in into an invalid keyword field they don't go to valid keywords, they just disappear. and if I try to increase the size of valid keywords they go to invalid...

white marsh
#

they are case sensitive and they need to be added as a keyword within the shader graph, note that name and the keyword is not the same

dusty creek
#

yea the keyword is in the reference

#

after that the tutorial says to add the keywords

dusty creek
regal stag
# dusty creek only 1 of them seems to be active. the `MAIN_LIGHT_SHADOWS` but not the `_MAIN_L...

Scope should be Global really. And shouldn't need to manually add them in the debug inspector, that's a bit outdated.
The other keywords may only be "active" if they are required by the settings on the URP Asset. It's still good to support them even if you don't need them though.

_MAIN_LIGHT_SHADOWS is the important one, but you need that leading _! You should then be able to obtain the Shadow Attenuation value from a custom function. I'd temporarily attach it to the Base Color output to check if it's working.

dusty creek
#

I added the _, I have nodes that multiply Shadow Attenuation with Distance Attenuation and then multiply it with my previous color output yet the shadows still don't cast over objects other than the terrain. I think I'm gonna follow a more up to date tutorial

unique oar
#

Is there a good way to speed up my GetData calls from compute buffers? Using the profiler, I found that the biggest source of framerate drops is from reading data from a compute buffer. Here's my code.

#
    void RunComputeShader(float[] samplesArray)
    {
        // Set up triangles buffer
        triangles = new ComputeBuffer(4096, sizeof(float) * 12, ComputeBufferType.Append);
        triangles.SetCounterValue(0);
        marchingCubes.SetBuffer(0, "triangles", triangles);

        // Set up array of sample points. Set samplePoints buffer to array.
        samplePoints.SetData(samplesArray);
        marchingCubes.SetBuffer(0, "samplePoints", samplePoints);

        marchingCubes.Dispatch(0, 2, 2, 2);
        
        // Get length of triangles from compute shader.
        ComputeBuffer.CopyCount(triangles, counter, 0);
        int[] countArray = { 0 };
        counter.GetData(countArray);
        int triangleCount = countArray[0];

        // Read the triangles from the compute shader to the triangle array.
        Triangle[] data = new Triangle[triangleCount];
        triangles.GetData(data);

        GenerateMesh(data);
    }```
#

marchingCubes is the compute shader. A triangle struct contains four vector3's. (three for each point, one for the normal)

#

The getting of data takes about 1ms to execute, which is pretty long when I've got lots and lots of objects. I know there's still more optimizations to be made, but this would be a pretty big one to get out of the way.

rich roost
#

@unique oar I still am new to compute shaders so take my word carefully. As you seem to recognize, transferring data to and fro the the GPU is time consuming. What does the GenerateMesh function do?

#

Depending on what that function does, it could be possible to never retrieve any data from the GPU, and therefore save a lot of time.

rich roost
kind juniper
unique oar
unique oar
unique oar
kind juniper
#

I really doubt that data retrieval itself takes that long. It's probably mostly how long the GPU takes to process your data in the compute shader.

unique oar
kind juniper
#

So it's most likely what I said.

#

But 1 minute is a lost anyway. Either you feed a hell lot of data into the compute shader or the algorithm is slow.

unique oar
#

@rich roost here are the scripts. The C# one is pretty messy, but the RunComputeShader method should be mostly coherent lol :p

unique oar
#

that just doesn't sound right :/ I'm getting the buffer data like, within a couple lines of the dispatch

#

itd have to wait or else i'd be getting an incomplete buffer

kind juniper
#

You can't get "partial" data from the shader.

kind juniper
#

It's either all or nothing.

unique oar
#

Anyways, how could I measure the time it takes for my shader's kernel (hope that's the right terminology) to complete, then?

kind juniper
unique oar
#

ahh

kind juniper
#

Looking at your shader, I'd assume that you feed too much data into it at once making it that long to process.

unique oar
#

i was initially running it with 1x1x1 groups, but when I switched to 2x2x2 and doubled the mesh size in all directions, it didn't seem to affect the performance too much?

#

I'm still very unsure about what the optimal sizes are for everything

kind juniper
#

Ughh... I tend to forget that as well, but I think something like 8 by 8 is a good number. With 1 I'd assume that it just uses one thread for all the computation.🤔

unique oar
#

oh, no i've been using 8x8x8 threads, but i switched from 1x1x1 to 2x2x2 groups of those threads (in the dispatch call)

#

sorry 😅

kind juniper
#

Ah wait, the threads numbers are defined on the shader side..? I'm really not sure about it, might need a refresher.

#

Yeah, but I remember that groups of threads also had an effect on that.

unique oar
#

So in a compute shader there's [numthreads(x,y,z)] which is written before each kernel. It defines how many threads are like, assigned in each "direction"? not sure how to put it

kind juniper
#

What I can suggest is have a look at Sebastian League's implementation and compare it to yours - see how fast it completes compared to yours and differences there are.

unique oar
#

but in your dispatch call, you can invoke the kernel multiple times in each direction. i'm invoking the 8x8x8-threaded kernel twice in the x, y, and z directions when I use dispatch

unique oar
#

I've had a look through his implementation recently to see if there's much we did in the C# script differently, but when it comes to getting the data, it looks to be about the same

kind juniper
#

Try different chunk sizes and see how they affect performance.

unique oar
#

hmm, strangely, I think running 2x2x2 gets me the same performance

#

I'm just sort of eyeballing it by running the shader stuff once per frame, and I don't see a difference in FPS

kind juniper
#

That doesn't change the amount of data that needs to be processed.

unique oar
#

yes it does

kind juniper
#

Not overall

unique oar
#

I'm using 2x2x2 instead of 1x1x1, i'm not increasing or decreasing the chunks

#

i am processing 8 times as many sample points when i switch to 2x2x2

kind juniper
#

That's what I mean. Try decreasing the chunks size.

unique oar
#

well that's what i did...

#

to increase or decrease chunk size i have to change the threadgroups

kind juniper
#

No. It still gets processed in one run.

unique oar
#

what

kind juniper
#

Reduce the size of chunks you try to process per dispatch.

unique oar
#

but i'm running it 8 times as much per dispatch aren't i...?

#

like,

#

the dispatch is Dispatch(0, 2, 2, 2) versus Dispatch(0, 1, 1, 1)

#

sorry im very confused

kind juniper
#

I'm not 100% sure, but dispatch groups are not how many times you run the shader, and even if it was, you'd still get the results only when all of them are done.

#

You need to reduce the amount of data you try to process with each dispatch.

unique oar
#

okay, what do you mean "data you try to process"? As in the data I pass into the shader as a computebuffer to run my calculations on? because I'm decreasing that.

#

the data it puts out is also decreased in size. the amount of data it has to perform calculations on is decreased

kind juniper
kind juniper
#

Okay. And you're checking with the profiler each time?

unique oar
#

Yes. It's only slightly, slightly slower to use 2x2x2. As in, like within ~4 or 5 milliseconds. And that could probably be mostly attributed to the mesh creation on the CPU side.

kind juniper
#

I'm not talking about dispatch groups. Why do you keep on bringing them up?

unique oar
#

because it's related to the amount of data I'm processing. Altogether, the kernel uses 512 threads (because it's declared with numthreads[8,8,8]) If I want to process more than just 512 data points per dispatch, I need to increase the dispatch groups

#

and thus get the shader to process more data, which is what you were asking me about

kind juniper
#

Hmm... Okay. You're right about that one.

#

Can you share the code whith the profiler samples?

meager pelican
#

@kind juniper@unique oar
The GPU hardware itself has a limited number of resources at various levels.

For example, each core is a resource. So if you check the specs on your GPU you'll see that it has N shader cores. This varies by make/model.

It also has N texture samplers, and N whatevers.

So these limited resources are allocated at their own levels (core level, or card level....)

So it is certainly possible to allocate 512 threads to run at once, but if you only have 256 cores on some card, you're screwed....some threads are not going to get cores allocated and be suspended. Similarly, some threads may be limited by access to samplers.

Then there's the infamous "vector register pressure" that I always seem to hit in my code. lol. So I'd like to be able to run, say, 5 threads per core (because they are using latency hiding), and X cores per group but I can only run 4 thread and x-whataever per group due to the # of vector registers I've used. But vector registers are faster! So I want to use them! Arrggghhhh!

So in reality, @unique oar, it is all going to depend on WHAT you're doing per core as much as it depends on the # threads you're running at once. The way to check it out is to use a vendor-specific GPU profiler. I have an AMD card, for various reasons, and I use their GPU Open tools and GPU profiler to capture a frame. It will show me the wave-stats, so I can get a feel for how efficiently I've allocated resources.

Then it's "just" a matter of seeing what takes the time where.

Also, it might give you more detail about readback timing. IDK, I don't usually do that, so can't offer insight into it.

meager pelican
#

The point is you're trying to avoid...under-allocation...of resources, but also trying to use what you have most efficiently. Sometimes you can change a few calcs and get an extra core running per wave. The GPU will use latency hiding to allocate thread-groups and get them started up, while they're waiting for a result from say a texture sample read (texture samples are slow, but latency hiding "hides" that fact from you to a degree). So if you dispatch an [8,8, 1] thread group, you'll end up using chunks of 64 cores, and when they all do texture samples, the GPU will allocate ANOTHER 64 core group, and get it started up as fast as it can, and maybe a few more of em too, and then as each texture read finishes in one group, it can get more texture reads cranking in the next group and finish off the first group of code, and then move on to the next group...

I'm no expert, and it's really hard to envision all these dependencies, but basically think of stacks of thread-groups, processing their stuff, and by the time it gets to your shader you have a thread-id, group-id, instance-id, and can compute things.

But it isn't surprising to me that, given the fact that the GPU automatically creates a ton of groups for latency hiding, the comparison of [1,1,1,] and [8,8,8] may not be what you'd expect. Because in the end it is still limited by some resource.

And one other thing to keep in mind is data structures and layout and memory bandwidth. So even how data is packed and read back is important.

Arrrrgggh...I'm talking out of my butt here, but I think I've got the general idea.

meager pelican
naive shuttle
#

Hey, I want to use a displacement map (As seen in the image) in URP. How would I do this? I'm trying to implement this in a shader graph though I don't understand how to make it work.

#

I've looked up multiple solutions but they don't seem to help me

kind juniper
#

Sample the texture, use one of it's channels value as the displacement value. To displace just get the vertex pos and add the value to it's position(presumably you want to offset it in the direction of the normal), then plug the new value into the vertex pos input of the vertex shader.

naive shuttle
#

So I should either use the r, g, or b value?

kind juniper
#

Did you actually plug it somewhere?

naive shuttle
#

I tried plugging it in the vertex displacement, though it won't let me

#

that's the whole problem

kind juniper
naive shuttle
naive shuttle
kind juniper
#

Actually, thinking about it, I'm not sure you can sample a texture in the vertex shader. Hmmm

naive shuttle
#

I've seen people use noise for displacement in urp, but idk how to do it with a texture

kind juniper
#

Do you want to displace the vertices?

naive shuttle
#

Yeah I guess

#

If I have a cube, I want to add depth to it using the displacement texture

#

Or is that not how it works? 👀

kind juniper
naive shuttle
#

True

kind juniper
#

Unless you have a very high definition mesh with as many vertices as pixels in the texture, there's not much point.

naive shuttle
#

let's take this rock then. It has many vertices and I just want to see how it looks with a displacement texture

kind juniper
#

Here's a quick answer I found online

You're simply using the wrong node. "Sample Texture 2D" is a pixel shader node and can not be used for the vertex output.
Use the "Sample Texture 2D LOD" node that works in vertex shader. You just have to supply the LOD you want to sample (probably 0).
naive shuttle
#

Ohhhh yeah! I read this a long time ago though completely forgot about it 🤦

#

Thanks!

naive shuttle
kind juniper
#

Might want to add some multiplier for it not to be as strong

#

also try multiplying by 1 channel

#

instead of vector*vector

naive shuttle
#

👍

kind juniper
#

But yeah, I don't think it's gonna look great, unless you subdivide the mesh a lot more

#

maybe try using it similar to a normal map. No clue how to do that though

naive shuttle
#

Ill just use the normal map instead, and no displacement map

#

Now Im stuck on a very stupid issue. I have a texture > sample texture > tiling and offset and suddenly my texture is green and ugly

#

why would the tiling and offset node make it green?!

#

oh

#

Im just very stupid

kind juniper
#

if you use it to multiply/offset the color, then that would make sense

naive shuttle
#

Ran into another problem I wasn't able to fix. I imported this rock and tried applying my seamless rock material to it, though these weird edges appeared. I tried going into blender and altering the uv's (using smart uv project) though it didn't change anything. How do I get rid of these weird uv's?

#

I just want my seamless material to work seamlessly on the rock

grizzled bolt
naive shuttle
#

Yeah I figured that out

grizzled bolt
#

You'll probably want to project the texture using Triplanar, or some such

naive shuttle
#

Never heard of it

#

and when I look it up it just shows me robotic arms

#

Ok just looked it up, but isn't that a bit too over complicated for what I need?

karmic hatch
#

There's a triplanar node in Shader Graph iirc

dim yoke
naive shuttle
dim yoke
#

There should be quite much information about that online

naive shuttle
#

I'll just stick to my current material

dim yoke
naive shuttle
#

lit

#

But the current material looks good enough, so I don't want to put more time into that

dim yoke
#

I see but just wanna let you know that triplanar mapping works perfectly fine for rock textures. You have obviously done something wrong yourself. Most likely its set to transparent which will cause problems with ordering the triangles correctly

naive shuttle
dense bane
#

how do you profile compute shader in Unity?

#

profiler>other seems like a fit all bag that includes computes but i'd like more detail, for example what time is spent transfering data from the CPU to the shader

wraith forge
#

Is there a way to flip a texture drawn with Graphics.DrawTexture?

compact estuary
#

I also have a question. If I'm using Color Format R32_Float on a render texture and write to it from a shader. Are my values being normalized? Or are they left regular?

mental thorn
#

Anyway to get renderer.cameraColorTarget but for a specific layer in a custom Renderer Feature?

spark kiln
#

anyone know why my subgraph has no inputs?

dusty creek
#

I've tried 2 cel shading tutorials now, one from NedMakesGames (2020) where I got stuck at keywords not being added. then I restarted using a tutorial from Robin Seibold where I was constantly having errors that weren't in the tutorial.

does anyone have a tutorial for a cel shading shader? preferably using shadergraph

meager pelican
# mental thorn Anyway to get `renderer.cameraColorTarget` but for a specific layer in a custom ...

Render textures (camera targets) don't have layers. Layers are "just" logic sorting of draw order.
The custom render feature is (IIRC) a pass/draw-call(s) that is rendered into the render texture.

So you can either figure out how to use a separate render texture somehow, or you can maybe use some kind of stencil setter material and then try to "read" what pixels have the stencil set in yet another pass.

And what do you mean by "get"? To the CPU? To a compute shader?

meager pelican
# compact estuary I also have a question. If I'm using Color Format R32_Float on a render texture ...

Might depend on when you're checking. I mean, if you have a color grading pass at the end, it will end up normalized.
But in-flight I don't think they are normalized, otherwise HDR wouldn't work as well. You might want to enable HDR mode though.

An easy way to test in your setup is to fill it with a high value like 2.0 and then in another pass, process it and cut the value in half, you should end up with 1.0 unless it got normalized.

compact estuary
#

Gotcha, thanks!

#

Does seem to get normalized for some reason, thanks for the idea of the test.

mental thorn
#

source is renderer.cameraColorTarget and ignore "material", it's something else

uneven silo
#

Hi guys. I'm super noob on Shader programming and I need your help for a very weird problem I'm experiencing.
Can I get your attention to this forum post please?
https://forum.unity.com/threads/need-help-converting-glsl-shadertoy-to-hlsl-i-think-i-break-the-gpu-and-im-super-duper-stuck.1306824/

kind juniper
#

Why does shader code always need to be so cryptic? Come on people, give your variables meaningful names!😅

kind juniper
uneven silo
#

Unfortunately I can't use ShaderGraph for this because the main shader contains displacement and tessellation stuff. 😦

#

There are magic numbers in the original shader, yes but the used formulas are not that complicated. I just need to know why passing "s.x" to float4 constructor instead of passing 1 would break the GPU in such a bad way 😦

uneven silo
#

@kind juniper Ok. How about this?

Even thou the s is const float2 (1, 1.7320508)

this produces a black output so I think somehow s.x is 0 instead of 1.

How is this possible?

#

albedoAlpha.rgb *= float3(s.x, 0, 0);

mental bone
#

Does it freak out if you dont mul the final color ?

#

But just set it ?

#

Or can you at least share the full frag function or better yet the whole shader.

#

Also why cant you just sample a repeating hex texture ? Why do you need to generate the hexes in shader code ?

uneven silo
#

WOW. it worked!

#

Very weird for me as a C# programmer but I'll take it.

#

Thank you.

kind juniper
uneven silo
#

You saved me from a big trouble. Thank you very much friend!

#

Far from done but I have some form of Fog of War now thanks to you... I can have a good night sleep now. 🙂

long hinge
#

Hi all, in shadergraph, does anyone know how you move the rectangle node's whitespace to the bottom? So a small section is white at the bottom, but the top half is black

#

nvm, I got it

haughty heart
#

I've started converting my multithreaded planetary generation code to a compute shader, but I've ran into a weird issue I can't seem to figure out.

Discord doesn't allow me to just paste the code here normally, so the code will be two text files.

If discord orders everything correctly the file will be the C# code and the other file should be the Compute Shader.
Also, there is a lot of commented-out code in the C# snippet, that is just leftovers from the multithreading CPU solution that I'll need to re-implement into this new one later, so just ignore it for now.

As to explain how the code in question works - there is a master array of all vertices ( same goes for triangles, but they cause no problems as of now ) that need to be generated for all chunks. There is another array that pinpoints where the vertices for each chunk begin, that is how I distribute them to all chunk after the fact.
The compute shader has been simplified as to confirm that the problem isn't with the math but something else. So all the vertices are being set to a position of (1,1,1)

The part that doesn't work is related to the very first chunk in the array. Whatever chunk is first in the array (same goes if the array only has one chunk to be generated)
will have all the vertex positions set to (0,0,0) , say for one of them which can either get the 000 output, the correct output or just NaN.
All the vertices in the array that are not related to that first chunk get generated without issues.

I've checked all the inputs multiple times now, there is no issue with the data I'm sending to the compute shader as far as I can tell.
I'll post some pictures and maybe more info if I missed anything

#

Here is the output I am getting as of now. As you can see only one of the vertices from the first chunk I being generated correctly ( The amount of vertices per chunk is 361 and you can see that the amount of incorrect vertices is 360 ). From what I can tell, it's the first one in the array that got generated correctly in this case, but I'm not sure

#

This is the output of the compute shader as of now. It calculates everything correctly other than the first chunk, that being the top one.

#

With the proper math being used instead of the (1,1,1) test output, that one odd vertex has NaN values

sacred hull
#

It seems to be transparent in the sahder graph window

#

But here it is not

#

I don't understand

fervent spire
#

Is there a way in my shader, that I can make my object's textures stay in the same position when my object is being rotated?

sacred hull
sacred hull
#

Also, I'm wondering why the semi-transparent cylinder on the left is pixelated while the box on the right is a smooth curve

#

Probably a blender UV problem as it looks weird with other textures too

regal stag
sacred hull
kind juniper
#

Is it normal that render textures created at editing time reset on play and assembly reload or am I doing something wrong?

#

Should I just use a regular texture for that? Is there any benefit to using a render texture in the first place?

sacred hull
sacred hull
#

Why can't I add these together?

sacred hull
#

Yup that was it

grizzled bolt
#

Partial derivatives can be used to render pixel-size shapes on surfaces, that's what I'd look into first

#

The other option would be to use some kind of outline post process in which case you wouldn't be limited by the surface of the mesh, though in that case the outline pixels could not be partially occluded by other things by depth which may or may not be what you want

slim steppe
#

How can I get scene color in a shader? (legacy)

iron cargo
#

heya, I'm trying to render some 2d sprites as planes in a 3d scene, but I can't figure out how to make them transparent. still figuring out how to work with unity, ty!

granite prawn
iron cargo
#

odd- the source files are pngs with transparency?

grizzled bolt
iron cargo
#

oh- that's odd! i don't know if its showing up this way on your monitor but on mine the image has some white AA artifacts when viewed on discord

#

I just set the material to unlit/transparent cutout- and while it does have transparency it seems like it's not from the image directly or something?

#

but that's progress at least

granite prawn
#

you may have already done this, but make sure the import settings are like this:

grizzled bolt
#

Only if it's used as a sprite, though
It looks like it's used as a texture on 3D geometry, but hard to tell just from the screenshot

iron cargo
#

ah! it's on default, i'll see what that does

granite prawn
#

What's the setup of the cat game objects? are they sprites, or UI Images?
If I can reproduce your setup/use case, I might have more insight.

iron cargo
grizzled bolt
#

The material should be able to use the texture's alpha channel for transparency, considering it has some

iron cargo
#

the only setting i'm seeing on this material is alpha cutoff, and some basic things like tiling and render queue 🤔

#

oh interesting, okay

#

going back to the very default material for unity- it has a lot more settings and there is a cutout option. seems to work best for pixelated assets?

#

though ofc it has lighting, which i think would end up causing issues with making that effect work?

#

anyways, transparency works but i'm getting a lot of issues with cutoff

#

so progress i suppose! but yeah bit funky

granite prawn
#

Nice! Glad you got the transparency part working.

iron cargo
granite prawn
#

I'm not sure what you mean by "cutoff"

#

oh, I see

iron cargo
grizzled bolt
granite prawn
#

I'm not sure if this helps, But I got this picture by using the default sprite import settings and then making a new material using Unlit/Transparent shader:

iron cargo
#

ohh wait a min- transparent works a bit differently on the lit and unlit

#

lit material just becomes a neon cyan box when that's selected, but the unlit does the same thing as transparent cutout minus the option to change cutoff, and with grey artifacts instead of white

grizzled bolt
iron cargo
iron cargo
#

hm

grizzled bolt
#

Neon cyan color signifies that the shader is compiling

iron cargo
#

ah, just tried it again yeah

grizzled bolt
#

If you want to truly be rid of the white fringing, you'll need to save the png with nothing but black in its color channels
Most image editors fill transparent pixels with white, assuming that it won't be seen

iron cargo
#

odd

grizzled bolt
#

Gimp has an option to save color for transparent pixels
But also saving as .tga in any program should work too I think

iron cargo
#

i made it in csp, i'll have to poke around for an option there. If i used an asset that wasn't all black and used that method, would it end up with black fringing instead?

iron cargo
#

alright- i suppose for now i could call this a small victory at least. tbh i know i'm definitely in over my head a bit here, i would love to make a little hobby-game project in this 2.5d style someday so hopefully i can keep throwing myself into this and piece together enough of a prototype to understand how it works and what the limitations are

#

for now i'm gonna take a break, its a bit overwhelming trying to understand how this all works haha

#

tysm for the help!

lament jolt
#

im making a bottle and i have two separate objects in the same prefab that i want to change materials or shader properties to make it look different, how would i do that?

meager pelican
naive shuttle
#

uhhh where is normal Lit?

#

Im using URP and suddenly the Lit shader just dissapeared

#

When I make a material it automatically adds the lit shader, though on the material I have it just doesn't exist and I can't select it

granite prawn
#

I would like to have TextMeshProUGUI Text elements visible from a single side. I achieved this by copying TMP SDF (the included shader) and changing Cull [_CullMode] to Cull Back. This works exactly how I want, but I get a console error that's something like "shader doesn't have a property named _CullMode.

I just need to satisfy the error, since I have the behavior I want. Is there a way to declare a property in the shader or override one such that I can assign it the value of Back and keep the line Cull [_CullMode] the same?

merry oak
#

Is there a built in way to get my object's forward direction in world space without making a property and assigning through a different script?

mental thorn
#

Hello, I am trying to make a stop-motion effect in a Custom Renderer Feature by only displaying / updating (I don't know what the correct term is) once in every X frame. So far I've got this which works for the whole screen.

{
CommandBuffer cmd = CommandBufferPool.Get("ScreenSpaceStopMotion");

using (new ProfilingScope(cmd, new ProfilingSampler("ScreenSpaceStopMotionTextureCreation")))

{
DrawingSettings drawSettings = CreateDrawingSettings(shaderTagIdList, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags);

RenderTextureDescriptor cameraTextureDesc = renderingData.cameraData.cameraTargetDescriptor;

cameraTextureDesc.depthBufferBits = 0;

cmd.GetTemporaryRT(tempTexture.id, cameraTextureDesc, FilterMode.Bilinear);

if (Time.frameCount % frameSkip == 0)
{
//"source" is renderer.cameraColorTarget, which is from the AddRenderPasses method
Blit(cmd, source, tempTexture.Identifier());
}

//"source" is renderer.cameraColorTarget, which is from the AddRenderPasses method
Blit(cmd, tempTexture.Identifier(), source);

context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings);
}

context.ExecuteCommandBuffer(cmd);

CommandBufferPool.Release(cmd);
}```

My goal is to make it work per-layer. How could I do that?
Right now I was thinking that a good way would be to make the effect only apply to a certain Overlay Camera (Which would render only the specific layer I want the effect to work on), but I do not know how to do that. Another way I think this could work is to replace source with the RenderTarget of the specific layer in question, but once again I do not know how to do that.

Any help would be greatly appreciated.
regal stag
regal stag
merry oak
granite prawn
regal stag
granite prawn
#

@regal stag nope:

merry oak
#

I think that I might have been wrong about wanting the rotation of the object, because I guess what I need instead is the forward direction of the object. Any ideas on how to get that?

regal stag
# granite prawn <@357936113983291393> nope:

That's annoying. If the shader supports it I would assume it should still be in the debug inspector list though. If not, might be able to add it manually by increasing the array Size field by 1, then folding out the last element and changing the "First" field to _CullMode and "Second" to 2.

granite prawn
merry oak
#

did you mean to ping me or Monsoonexe?

regal stag
#

Sorry yeah wrong reply

merry oak
#

lol np

regal stag
merry oak
regal stag
compact estuary
merry oak
#

I'm want cull to be turned off, but I want pixels that face backwards to be clipped. I tried doing it with this in the v2f vert thing:

clip(dot(UNITY_MATRIX_M._m02_m12_m22, UnityObjectToWorldNormal(normal)));```
And I put this in its input:
```cs
float3 normal : NORMAL```
#

I'm getting this lovely error

compact estuary
#

Makes sense to do that in the fragment shader. This error, there is something weird about your vertex shader.

#

This is a code block for seeing if a pixel is facing the view

merry oak
#

I put this in the vertex shader

regal stag
#

Yeah, clip is a function that is done in the fragment shader. Though I'm not sure I can see the point of manually using clip on back faces over using Cull Back

compact estuary
#
float4 frag(v2f in, bool isFrontFacing : SV_IsFrontFace)
{
  if (isFrontFacing)
  {
    return _InsideColor;
  }
  return _MainColor;
}
#

What's the syntax for code?

kind juniper
compact estuary
#

For me, I was rendering the insides a different color

#

but you'd just want to clip those pixels.

merry oak
#

ok I'll try that

#

I still need i because my frag shader uses it later on, so I tried this:

float4 frag(v2f i : SV_Target, bool isFrontFacing : SV_IsFrontFace)```
however this is giving an error.
merry oak
compact estuary
#

My headers looks like this

float4 frag(v2f i, bool isFrontFacing : SV_IsFrontFace) : SV_Target
#

But this might mean something different.

merry oak
#

oh thank you. the error is gone now, that worked

compact estuary
#

👍

meager pelican
#

In the end it might be mostly academic....since a render texture with no depth buffer and no stencil/vector/whatever is a writable texture. 😉

kind juniper
kind juniper
winter timber
#

wondering if i can make 1 object that wont render a certain shader, so that way if the 2 objects go together, they then cannot be seen, does this make sense?

winter timber
#

so there is a ground plane, that has a water shader

#

and there is a box, inside the boundaries of this box we dont want the water plane with the shader to render

#

hope that makes more sense!

winter timber
#

hmm im thinking perhaps some sort of mask could be used to set the opacity of the water plane to 0 when in locations with the box around it, although how i would do this i do not know

winter timber
tacit parcel
#

Seems like using stencil could work

winter timber
winter timber
winter timber
#

instead of using a cube, or whatever shape to mark where i would like it to not render

#

i can probably use a list of float2 to say where alpha should be 0, acting like holes

#

if the position of this pixel is within this float2 shape, have 0 alpha

#

how i would do that, i dont know yet lol

#

guessing using the position node with the comparison node somehow?

#

although how i would use comparison using a list of different positions, i dont know

#

and how you split positions into x y and z, i dont know

#

could i do something like this to check if the position is within somwhere?

winter timber
brittle owl
#

is there any way in shader graph to force a semi transparent object to write to depth? im trying to have both transparency and depth of field but transparent objects arent affected by depth of field. i tried dithered transparency but it doesnt look very good lol

winter timber
#

if i use a split node could i use rgb as xyz?

#

yas it works, ish, im accidentally using xy, rather than xz, but it is a simple fix atleast!

#

in the shader graph is it possible to create an array of vector 6?

winter timber
amber saffron
winter timber
#

can i create an array of an array of vector3?

rich roost
#

I sense a conspiracy @amber saffron

amber saffron
#

Not a shadergraph limitation, it just doesn't exists in shader languages 🙂

winter timber
amber saffron
#

If it's just to store data, you could as well use a matrix 3x3

winter timber
amber saffron
rich roost
#

I'll be damned if I die before finding the coveted vector 6

winter timber
amber saffron
#

If we are still on the conversions of "how to hide water inside of a boat" conversation, I still think stencil is one of the best options btw

winter timber
#

or rather for now a vallley, cause i havent finished modelling the cave yet lol

amber saffron
winter timber
#

but i got a solution working ish currently, even if it is not the most elegant, i can set 2 positions, and any water inbetween just does not get rendered

#

every time i need a new area to not have water, i have to go and duplicate all the nodes, and add 2 more vector3 properties in the shader graph though, so it probably isnt the best solution

amber saffron
winter timber
#

ok now onto my next challenge with shaders, i have a plan for some areas of the water to be tinted slightly, to do this i have a circular gradient so it fades into this colour, problem is that eventually i plan for the water to have waves, meaning i somehow either need to apply these wave heights to the other object with the circular gradient, or put the gradient object way up high, and simply make it so the tinting only affects the water game object

amber saffron
#

Hum, sooooo, if I got it correctly, you are using an other object bellow/above the water to tint it ?

winter timber
#

circular gradient, with very little alpha in order to tint it without overpowering the water texture

#

usually i keep it on the same y level as the water, to stop issues with the camera going below the tint, but not below the water and then seeing the untinted water

#

potentially i could also use coloured lights to tint the water from above?

amber saffron
#

A light will not tint but really change the lighting. Might be a solution but it isn't "extactly" the same.
If we are still on the mesh idea, you could use the mesh vertex color 🙂

#

Directly on the water surface

winter timber
#

how though, like multiply the colour by another colour? or do you mean using lerp or something?

amber saffron
#

Well, yes, any way of blending can be done in the shader, this is up to you

winter timber
#

i tried that before, i never managed to get any method working, hence why i even used a seperate game object in the first place, do you have any helpful links that might help me learn?

amber saffron
#

I don't have anything specific in mind, sorry :/
You have access to a huge quantity of blending modes using the "blend color" node, and using the rgb+a value of vertex color you should be able to find what fits best.
It could be as easy as using rgb for the color and alpha for the blending intensity

#

To blend from the water base color to the vertex stored one

winter timber
#

ok thank you, i shall try that thankyou!

#

for the opacity part in the blend, should i connect that to a circle mask to get it in a circle gradient blend thing?

amber saffron
winter timber
amber saffron
winter timber
#

afterall this water plane is quite big so the vertex density wont be too high, only high enough to make the waves look decent

#

im sorry lol, im quite new to shader graph and stuff lol

amber saffron
#

It can look blocky if the color change is abrupt, this is fully up to how you author it

#

Note that vertex color is not only to paint full faces into a single color, you can paint a vertex in one color and the neighbor into an other, and the color will be interpolated along the edge in a smooth manner

winter timber
winter timber
#

ok thankyou so much!

amber saffron
brittle owl
#

any other way to do it in urp?

#

i heard something about the render objects feature but im not sure how to do it

amber saffron
#

Hum, yeah, you can probably use a render objects rendererfeature to do a depth prepass manually

brittle owl
#

ive tried messing around with all the depth options (cause im not sure what to do lol) but nothing seems to work

amber saffron
grizzled bolt
#

Hair shader documentation:

If you use semi-transparent hair cards, you must manually sort them so that they are in back-to-front order from every viewing direction.
Does "manually sort" mean just making each card its own independent mesh object, or are there other ways besides that?

amber saffron
brittle owl
amber saffron
brittle owl
#

oh, an alpha clip/opaque shader by itself writes to depth

#

its jsut that transparent doesnt write to depth

#

damn i wish they exposed these options in urp

#

im not really sure what to do now since depth of field is pretty important

final spruce
#

rn i'm using Valerie Palerie's PSX Shader Kit, but i can't get it to look low res without big drawbacks

#

although clearly they found a way to do it considering their screenshots

#

is it possible just to straight up render at a low resolution and scale it to fullscreen?

brittle owl
#

ive created a dither transparency effect in shader graph, currently i have a problem where if 2 objects of that same shader/material overlap in the view they dont show each other behind them, since their dither lines up in the screen

#

how do i fix this?

#

heres whats happening

#

heres what im looking for instead

#

the second one works because their dither patterns are slightly offset from each other

#

i tried doing a thing where it offsets the screen position (input to the dither node) based on the current y position of the object but at certain y values the incorrect effect shows up and it varies by screen resolution

vague imp
#

Is there a tutorial on how i can achieve the first part(parallax of the light) of this effect that was explained in this video? : https://youtube.com/shorts/uLN69rtiu4Y?feature=share

These small lights hold a little secret; they don't contain anything at all! Another quick answer, a series on quick techniques too simple for a longer video.

Don't worry, longer videos are still coming.

🐦 https://twitter.com/JasperRLZ
💰 https://patreon.com/JasperRLZ
🤼 https://discord.gg/bkJmKKv
🌎 https://noclip.website

🎵 Mike Morasky - Porta...

▶ Play video
gilded ridge
#

I'm not sure if this should be here or not but can anyone help me on how to make a gradient effect on far away objects like in the image below?

rich roost
#

@gilded ridge it's called atmospheric fog

gilded ridge
#

Thanks!!

brittle bolt
#

Hey all, I’m generating a shape in uv space, a rounded rectangle. I’d like to take that mask and essentially turn it into a gradient, very similar to how a “bevel” node works in substance. I was under the impression that smooth step was the function for the but I am not getting the results I expected.

mortal basin
#

hello i set up a haze effect with shader graph and put the material in a quad the shader is working good on terrain and objects but its also affecting the player how can i exclude the player from being affected by the material

queen vortex
#

Can anyone tell me how to use cubemaps in a shader and use this shader as HDRI skybox in Unity HDRP? I don't understand why it doesn't work and I can't find any documentation on how it works ?

vague imp
#

Ah yes, unity : ThIs mAtIrIAl cANt Be usEd as A sKy bOX maTiRIaL

rich roost
#

@pastel coyote @worn leaf @agile parcel @tardy root could we get a channel for shader graphs and one for shader code?

#

Usually the shader code stuff gets buried, since there are more people using shader graphs.

#

And i feel the tools are both different yet popular enough that they deserve their own channel.

Im decent at shader code, but I have no idea how to use shader graphs. There are probably people who are good at shader graphs but have no idea how to use the code.

I hope you consider this

#

If there is a better way for me to bring this up, please let me know. I looked a little and could find nothing obvious to me

mental thorn
#

How can I make it so the Object is seen through the Stencil Mask even if there is something in between blocking it (In this case the plane)
I want to render the Object through the Stencil Mask but over the plane (Currently the plane obstructs it)

sharp night
#

Hey!
Not sure if this is the right channel, but I am trying to make a terrain system using tiles where the player can choose from a selection of materials to be used for each tile.
To make the transitions between the materials look better and have no seams I would need a blend between them which I am not sure how to do. On top of that I'm using the HDRP LitTesselation shader.
Would looking into the LayeredLitTesselation shader and polybrush be a good start or there's an obvious way of doing this that I'm not aware of?

merry oak
#

I'm bad at shaders and I don't get why my fragment shader is now not getting the uv coordinates. Does anyone know what could have caused this?

kind juniper
merry oak
kind juniper
#

Then it's probably the latter

#

Or you're not passing the uvs from the vertex shader

merry oak
#

I think that the uvs aren't being passed from the vertex shader, but I'm not sure how to check or fix that.

meager pelican
#

You should probably A) do what @kind juniper suggested and check the model/mesh for UV values first, then B) post your shader so we don't have to play 20 guesses. Maybe use pastebin or some such.

merry oak
meager pelican
#

OH, yeah it has UVs

merry oak
#

Also there is some stuff in there for a custom perlin noise script which I copy pasted from somewhere else, but I'm pretty sure that it works.

meager pelican
#

Change the frag() to just return the result of the texture lookup.
So comment out the two lines between the tex2D and the return.

merry oak
#

That didn't change anything

meager pelican
#

What do you get? Is it black, or what?

merry oak
#

I'll post a screeshot

meager pelican
#

Is there a texture assigned?

merry oak
#

before and after removing

#

just for testing, I set the albedo to white and assigned the jigsaw_albedo texture

meager pelican
#

OK, look at the uv values (in color).
So make the first line of the frag() function say
return fixed4(i.uv.x, i.uv.y, 0, 1);

merry oak
#

sry I didn't mean to get the arrows in there

#

ok I just applied this shader to a different object and it seems to be working on that, so I'm not sure what's wrong

meager pelican
#

Yeah, the uv part of the code looked good to me. So that means that the model data itself is not working as intended.

And how is that quad you keep posting a default unity cube?

merry oak
#

ok I'm zooming in on it a bit, because the surrounding scene is a bit boring, but I can zoom out

meager pelican
#

do you have weird values in tiling and offset? Like tiling of 0?

#

Otherwise IDK, IIRC the default cube has a UV mapping

merry oak
#

ohhhhhhhh, yes I did

meager pelican
#

tiling is a multiplier! So whatever * zero is zero. And that's why you're seeing black.

merry oak
#

um, that's embaressing. Thank you it's working now.

meager pelican
#

np.

#

We all have those days.... 😉

merry oak
#

lol, thank you

soft harness
#

What's the technique to depth-sort an object based on their center instead of per-vertex

meager pelican
vague imp
#

hi chat!, how can i can achieve the first part(parallax of the light) of this effect that was explained in this video in shader graph? : https://youtube.com/shorts/uLN69rtiu4Y?feature=share

These small lights hold a little secret; they don't contain anything at all! Another quick answer, a series on quick techniques too simple for a longer video.

Don't worry, longer videos are still coming.

🐦 https://twitter.com/JasperRLZ
💰 https://patreon.com/JasperRLZ
🤼 https://discord.gg/bkJmKKv
🌎 https://noclip.website

🎵 Mike Morasky - Porta...

▶ Play video
#

is there a tutorial for such effect?

soft harness
vague imp
#

this is the texture:

meager pelican
# soft harness I mean when the Ztest happens it checks the per vertex depth against the depth b...

Oh, that's not quite per-vertex either.
It's per fragment.

And it's in hardware. It's an early-z test during rasterization.
You could possibly change the depth in the vertex shader, but you'd have to do that for the whole triangle. The thing is that will screw with the perspective divide....I think...and result in a messed-up image.

The other option if the above doesn't work, is to do manual depth testing (slow). So you'd turn off depth testing in the shader, and cull all pixels in the fragment shader using whatever you want, probably some center passed in v2f. But again, that's slow.

soft harness
meager pelican
#

Share if you find it. 🙂

vague imp
#

how do i distort a texture from a normal map in shader graph?

weary pebble
#

Anyone here who knows a good tessellation tutorial? 🙂

regal stag
low lichen
vague imp
#

oh its a node

regal stag
#

It allows you to rearrange the vector components. Though in this case I'm just using it to truncate from Vector4 (xyzw) to Vector2 (xy)

vague imp
#

like this?

regal stag
#

Just "xy" will do

vague imp
#

so like this?

regal stag
#

Technically it would truncate automatically in the Offset port tbh

vague imp
#

the distortion is moving my texture to the upper left corner, how do i fix that?

regal stag
#

I guess that would be due to the values in the normal map

fast sierra
#

there's something i really can't seem to grasp.
I've used a shader in an HDRP project to add shadows to my sprites, but why does the alpha get so messed up?

#

(right one is a sprite with the default material, left one with the one in the shader graph)

fast sierra
#

Nvm just had to switch the material to Transparent

copper iris
# amber saffron Lokk into polybrush for vertex painting : https://unity.com/features/polybrush

While Polybrush is great for vertex color painting, they don't really provide any production-ready shaders.
If you need a fast shader which supports Polybrush, I wrote one here:
https://assetstore.unity.com/packages/vfx/shaders/omnishade-pro-mobile-optimized-shader-213594

Add depth to your next project with OmniShade Pro - Mobile Optimized Shader from OmniShade. Find this & more VFX Shaders on the Unity Asset Store.

thick patrol
#

.

proper ore
#

How would one go about "cutting" a mesh in half using shaders? So if I had a mesh consisting of two spheres and a capsule, could I use shaders to hide, for instance, the capsule and only render the spheres?

#

Would that simply be assigning the vertexes which form the capsule no Color? I don't have much experience with shaders.

fossil bridge
#

How could I replicate this look in Unity? Made this in Blender cycles with toon shader and grease pencil

dim yoke
fossil bridge
mental thorn
#

How can I make it so the Object is seen through the Stencil Mask even if there is something in between blocking it (In this case the plane)
I want to render the Object through the Stencil Mask but over the plane (Currently the plane obstructs it)

dim yoke
low lichen
#

But it must be drawn after the plane

mental thorn
# fossil bridge How could I replicate this look in Unity? Made this in Blender cycles with toon ...

First you'd need a cell shader for the lighting on the mesh https://www.youtube.com/watch?v=lUmRJRrZfGc
Then for the shadow on the floor you can go to the lighting window in Unity and set it to that beige-greenish color (See image)
Finally you need to figure out how to make the outlines. You could either turn the Greace Pencil into a mesh https://www.youtube.com/watch?v=bhhLpOhRMzU and in Unity give it an unlit black material, or you could make the outlines with a shader https://www.youtube.com/watch?v=s_P3dVZvVxY. You could also make the outlines with a post processing effect / renderer feature pass https://www.youtube.com/watch?v=LMqio9NsqmM&t=456s https://github.com/Robinseibold/Unity-URP-Outlines

mental thorn
low lichen
mental thorn
#

ah alright

#

thanks

#

@low lichen It works however the object is also affected by it and you can see itself through it (It's concave). Is there anyway to fix that?

low lichen
mental thorn
#

Alright I will try that

low lichen
#

The first pass can be invisible, it just needs to write to depth. You can use ColorMask 0 to make it not write to any of the color channels, the fragment shader can just return 0;.

gilded ridge
#

So basically I just created a curved world shader graph and applied it to the needed materials but it made them purple/pink, please help me

gilded ridge
#

Nvm I fixed it

jagged lodge
#

How would one store an array of float4s in a shader? Looking to store a bunch of spheres (position + radius) if that helps any.

#

Nevermind, forgot to uncomment something like a loser

fossil bridge
copper iris
#

Thank you very much for the detailed

leaden quest
#

Would anybody know how to take generated shapes like the first image, and then to offset and rotate them around polar coordinates like the sine wave image?

Ideally I'd love to be able to generate one set of shapes and then have the ability to increase the number of them rotating around the central UV space, like a typical magic spell kind of visual, however I could change the number, 3, 4, 5 etc.

I could do this with multiple copies of the shape, offsetting their UVs for up to say 5 or 6 versions and with some maths offset their rotations by an integer, but I feel that'd be costly and not "smart"

spring night
#

How can I apply a specific texture to the black parts and a different one to the white parts?

leaden quest
spring night
#

thanks

mental thorn
#

Hello, is it possible to specify which part of a mesh (In this case a plane) the Stencil Buffer will work on with a texture mask? I'm using a plane as a Stencil mask to reveal a cube and would like to specify which part of the plane should actually act as one.

This is how it currently looks:

#

And this is how I would want it to look if there was a pentagonal mask texture:

#

I know I could technically just model the plane to be whatever shape I need it to be, but a texture would be much more convenient since I could swap it easily

Thank you in advance for any help

meager pelican
# mental thorn I know I could technically just model the plane to be whatever shape I need it t...

The thing with stencil, is that it isn't really a code thing...the hardware is set up to write the stencil into the stencil buffer as it goes. So I think what you have to do is either write the pixel or not write the pixel (discard it). If you discard the pixel, the stencil write won't happen either. At least in most cases, see https://gamedev.net/forums/topic/682690-stencil-write-with-clipdiscard/5313005/.

So you could do a special stencil setting operation if you wanted, and not even mess with the color buffer at all.

#

Of course, the discard or not logic is based on your mask.

mental thorn
#

Ah alright

#

Yeah I'll try that

#

@meager pelican Thank you it works 🙂

#

I used the clip function and that did the trick

grand jolt
#

This error keeps showing Material doesn't have a float or range property '_Color'
Here's how the property looks like:cs _Color("Color Range", Range(0.001, 0.999)) = 0.5

vocal narwhal
#

You need a property in code called _Color

grand jolt
#

When you say code do you mean the Shader or what?

#

I'm just trying to animate the property, no code, nothing fancy...

#

@vocal narwhal

vocal narwhal
#

I mean in the shader, yes

#

You'll have to provide some more context as to what you're doing

grand jolt
#

The error started to show when I included the material property in the animation...

kind juniper
vocal narwhal
#

I can only imagine you're animating another material accidentally. It looks fine as far as I can see

grand jolt
#
/*Material doesn't have a float or range property '_Color'
UnityEditor.AnimationUtility:GetEditorCurveValueType (UnityEngine.GameObject,UnityEditor.EditorCurveBinding)
UnityEditorInternal.AnimationWindowSelectionItem:GetEditorCurveValueType (UnityEditor.EditorCurveBinding)
UnityEditorInternal.AnimationWindowUtility:IsNodeLeftOverCurve (UnityEditorInternal.AnimationWindowHierarchyNode)
UnityEditorInternal.AnimationWindowHierarchyGUI:DoIconAndName (UnityEngine.Rect,UnityEditorInternal.AnimationWindowHierarchyNode,bool,bool,single)
UnityEditorInternal.AnimationWindowHierarchyGUI:DoNodeGUI (UnityEngine.Rect,UnityEditorInternal.AnimationWindowHierarchyNode,bool,bool,int)
UnityEditorInternal.AnimationWindowHierarchyGUI:OnRowGUI (UnityEngine.Rect,UnityEditor.IMGUI.Controls.TreeViewItem,int,bool,bool)
UnityEditor.IMGUI.Controls.TreeViewController:OnGUI (UnityEngine.Rect,int)
UnityEditorInternal.AnimationWindowHierarchy:OnGUI (UnityEngine.Rect)
UnityEngine.GUIUtility:ProcessEvent (int,intptr)*/```
kind juniper
vocal narwhal
#

Just to confirm the obvious, Ophe/SpecialLia/LiaMandlebrot I presume was changed from/to MandleBrot in your code upload

grand jolt
#

That was something I changed when I shared the code, actual code:

#

I'll try to restart Unity, maybe that'd fix it

vocal narwhal
#

The point is to not post reaction gifs, not to go around the bot that enforces the rules.

#

I just tested it on my end and I can animate the _Color property without warning

grand jolt
vocal narwhal
#

Generally comes under the same rule. Regardless, not sure what's causing your issue, I can only imagine something's changed the assigned material somehow

grand jolt
vocal narwhal
#

I would imagine that it would be animating the first material, but I'm not sure as to the specifics, it could be that the path it's animating needs to reference the material at the right index

grand jolt
#

Mhm!

brave quartz
#

question

#

im trying to make a triplaner material

#

but I want the g mask to be separate for the top and bottom

#

not really sure where to go from here

#

I know that I can multiply by -1 to get the top and the bottom

#

but how do I recombine everything together?

amber saffron
copper iris
#

triplanar material

brave quartz
#

I was able to isolate the bottom half by multiplying by -1 on the mask

#

but now I need to get my textures to appear on the bottom mask

#

also sorry im new to the unity graph

amber saffron
brave quartz
#

do I put 0 in all the channels or just the y?

amber saffron
#

Use only the Y of the normal as input, since you don't need the other ones 🙂

brave quartz
#

oh haha nvm I found the mistake

#

I wasn't using the G from the split node

#

is there a way to have both the top and bottom but both of them are separate textures?

amber saffron
brave quartz
#

the lerp is giving me either top or bottom

#

not both

amber saffron
#

Show your graph 🙂

brave quartz
amber saffron
#
  1. Set the edge value to 0 (top half will be white, bottom half will be black)
brave quartz
#

okay

amber saffron
#
  1. use the output of the node to lerp between two textures here :
#

So you'll have two different texture at the top and the bottom

brave quartz
#

do I not combine them?

amber saffron
#

No need

#

@brave quartz So, how is it going ?

brave quartz
#

not good lmao my unity crashed but even then im not getting the results im looking for

amber saffron
#

I mean, it should work, can you show how you've connected this ?

brave quartz
#

okay

#

I got something close

#

I cant figure out how to make the bottom blend like the top

#

it takes up half the material, I know where the issue is happening

#

but not how to fix it

stray shard
#

What node do I use to display a card back texture?

amber saffron
# brave quartz

Almost there, lerp between the textures first, then multiply

amber saffron
brave quartz
#

it worked

#

thank you for being patient with me

undone anvil
#

Is proof math theorem important? For writing shader?

amber saffron
undone anvil
#

How about calculus 1-3?
I have no idea what I learned form
Calc 1-2

#

Got a double Grade D from calculus 💀

weary pebble
#

Anyone knows how to fix the normals of the water, so they are not completely black

weary pebble
#

Amplify Shader Graph

stray shard
#

Back side is darker than it should be when I rotate the object, how do I fix this?

undone anvil
#

Could you give an node here?

regal stag
weary pebble
amber saffron
regal stag
#

Probably differentation and integration stuff. I'd say that isn't too important for shaders

amber saffron
undone anvil
#

I never use amplifier shader graph is it same idea as build in shader graph?

weary pebble
#

Almost the same

#

I have a normals T3D Texture xD

stray shard
amber saffron
undone anvil
#

Did you try same normals node with simple plane or quad yet?

amber saffron
weary pebble
#

I try

stray shard
amber saffron
regal stag
#

Or change Fragment Normal Space to world in graph settings

amber saffron
#

Or, if you're not using normal maps, use (0,0,1) and (0,0,-1) as values for the branch node ^^

stray shard
undone anvil
weary pebble
#

When I downscale the normal power the black spots go away, but then the water does not reflect light anymore, and I couldnt get anything else to work xD

undone anvil
#

Did it get effected by global light ?

weary pebble
#

Yes by one directional light

undone anvil
#

There is fragments destination node?

#

Like this

weary pebble
#

this is the shader

vestal frigate
#

Hey, I'm having this issue with my unity where I can play until I solve this error
Ive been looking for the shader in the pack that I downloaded from the unity asset store but can't find it

kind juniper
#

Do you guys know if this is legal in hlsl?

float weights[16] = {w1, w2, w3, w4};

Where w1,2,3,4 are float4.

regal stag
kind juniper
#

Hmm... The whole point is to be able to index the individual channels from 0 to 16.

#

It seems to compile without problem, but I'm not sure what results it would yield yet.

regal stag
#

My assumption would be it truncates the vectors, so resulting in {w1.x, w2.x, w3.x, w4.x, 0, 0, 0 ...} but not sure. May have to return values in fragment shader to test that.

kind juniper
#

Quite possible indeed. Will test it tomorrow.

ornate pendant
#

I'm following along with Sebastian Lague's Procedural Landmass series, and I've ran into the first problem that I can't fix.

For some reason the texture being set by the shader is all messed up; but since there's no feedback from .shader files I don't know if it's an error on my part, or if there's been some change in Unity (considering the video is almost 6 years old).

Can anyone spot a typo / other reason for this "swirling"?

young fog
#

this is what it looks like in the scene

#

I finished the tutorial and still can't find out why it's like that

ornate pendant
#

Answer for my thing:
float3 xProjection = tex2D(testTexture, scaledWorldPos.yz * blendAxes.x);
to
float3 xProjection = tex2D(testTexture, scaledWorldPos.yz) * blendAxes.x;

Damn brackets.

copper iris
elder ingot
#

how can i add the option to change the color of a texture in shader graph?

shadow locust
wraith jungle
#

I want shadow caster 2d
But because the walls aren't connected, This happens

young fog
#

also don't really know how to use shaders

#

@copper iris I posted what my code is earlier

#

it's like it's not getting culled and the pass beneath just isn't showing up

#

I don't know what's the issue the guy didn't use LightMode

#

What does this mean?

copper iris
#

Outline

young fog
#

I don't know what I'm doing with shaders so I need like a quick crash-course to it

#

I also just want to create some fun shaders for beginners

manic solstice
#

How do you simulate the ghosting effect of your eyes when a bright light turns off or when you close your eyes?

magic stump
#

Hello, anyone knows how to use a mesh renderer as a sprite mask?

shadow locust
magic stump
# shadow locust https://xyproblem.info/

Ok, so I tried this tutorial https://youtu.be/CSeUMTaNFYk?t=1131, but I can't reproduce it in the new URP

✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=CSeUMTaNFYk
Let's make an awesome Line of Sight effect that interacts with walls, enemies outside the Field of View are not visible. Excellent effect for any sort of Stealth or Horror game.

Get Survivor Squad and Survivor Squad: Gauntlets in the Game Bundle
https:/...

▶ Play video
thorn tapir
#

Hey, I've been struggling for hours now with a single issue on a shader I'm trying to make

magic stump
thorn tapir
#

the problem basically, is that my render texture is losing its alpha when I modify the text with a replace color node in shader graph

#

this is on URP using a 2D Sprite Unlit graph

rich roost
#

new channel for shader code

thorn tapir
#

if I use a regular Unlit graph, I can simply out the alpha from the texture to the master node and that works, BUT I run into a new problem... in game, it comes out unlit????? and I'm not sure how to light it

rich roost
#

I'm hoping we can get some support for a new channel. Please leave some messages in the server feedback channel if you agree. Thanks.

thorn tapir
#

this is a different shader from what being used in the video above, but it most directly illustrates what I'm trying to do.... however I have no idea why its turning my output grayscale

#

the mult node at the bottom is jost to show that the alpha is not working when I try to do it via mult

thorn tapir
rich roost
thorn tapir
#

no idea honestly

#

at this point though, I may just give up on using a shader to color it, and color it manually with a simple Sprite.Color

#

jsut means I have to put everything that isn't white on its own tilemap

young fog
#

I'm reading through that long page from cyan that was pinned

young fog
#

I read like 90% of it but I'm just not understanding it

#

I can only really understand the basics

rich roost
young fog
#

I don’t get it

kind juniper
#

Basically the difference is birp was using CG shader language, while SRPs use hlsl. Both are very similar, but CG is deprecated since 2012.

mental bone
regal stag
# thorn tapir https://i.imgur.com/SGtsL63.png

It's turning greyscale here because comnecting a Vector3 output to a Vector1/Float input truncates the size of the vector (only uses x or red value) rather than each colour component.
You need to use a Split node (on the Replace Color output)

young fog
#

Wait a minute

#

this is the person’s blog I was reading

young fog
#

there's a bit I do understand past that but most of it I don't

pale python
#

Hi,

does anyone know a tutorial on how to convert Standard shader to URP?

there is a very cool free asset for vr that is the only one of its kind in the store, that only supports standard shader, but we are using URP

#

I'm doing a simple test run VR project, and I believe this asset is essential yet very simple

clear vector
#

where can i find a list of all possible matrices in HLSL? like float4x2, float4x4, etc

clear vector
#

also i've read just now that some platforms only supports square matrices

regal stag
#

I think that's because glsl might only support square ones. Not sure if it cross-compiles to an appropiate size automatically or not though

clear vector
#

I trying to come up with approach of how implement MainTexST with altalsed sprite. And i think that i can just use 2 MainTexST, one to locate texture part on atlas and second one to really make tilling and offset for located rect

#

so i was thinking about float4x2 to avoid extra compute buffer copying

thorn tapir
#

I actually got a different iteration of the shader working, but I think I'll go implement that solution just to put it in my memory

zealous thicket
#

hi, one of my textures in my shader is showing up sideways - any ideas?

its a shader that replaces the texture on cliffs with a cliff texture (the A Short Hike kind of thing) and the texture is right side up on one side and 90 degrees wrong on the other plane.

grand jolt
#

im making a custom skybox shader
and i cant find a guide on adding the sun and matching its rotation with the directional light
if anybody's got a good tutorial send it over pls :3

regal stag
#

Can alternatively get the main light direction with a custom function, something like Out = GetMainLight().direction;

zealous thicket
hexed surge
#

hello guys
I want to try making a shader that breaks tiling repetition (from the Blender donut guy's video)
to do that, I need to rotate uvs for every tile independently (mesh segments, for now just single square faces)
how can I achieve that using the shader graph ?

I can also rotate the uvs in the mesh generator, would that be a better solution ?

#

nvm, figured that part out
works exactly as I wanted, except some weird black dots appearing

#

they seem to appear only at the corners of the faces, any idea what could cause something like this ?

shadow locust
#

probably a divide by zero or something or a sqrt of a negative number

hexed surge
#

nothing like that in my nodes at a glance, but i'll try to play with the numbers maybe

#

I think I know what might be happening, fraction returns 0 at the edges, that breaks the center calculation and rotates around the wrong point

hexed surge
#

I guessed it right, solved it with putting tile centers into zw of the uv0, couldn't figure a way to distinguish tile edges purely inside the graph

#

didn't expect that uvs with all corners having the same value would also be interpolated
had to trunc and add .5, .5 to get rid of that

#

feels kinda hacky

thorn tapir
tranquil jackal
#

anyone have to share Shader stripping tutorial, as I am stuck at making list of needed shaders orther than creating shadervariants file.

hexed surge
#

continuing with the tiling shader
one other technique he uses is some sort of edge distortion for tiles
can you do something like this without touching the geometry ? it looks like uv distortion, but it only affects the seams

regal stag
hexed surge
#

it looks like it distorts the whole uv map, but I'll play with it and see if I can get it to work only for the seams

regal stag
#

I'd also -0.5 before that to center it

hexed surge
#

I can see that it produces the shapes that do look exactly like those in the video, just need to adjust it somehow, my initial guess would be to scale my uvs differently
thanks for the help, the general idea does seem to replicate that effect ❤️

meager gust
#

Is there a way for me to get the positions of every light source in my scene in the hdrp shader graph?
I am making an atmosphere shader and am using this to make a fake direction but I have multiple light sources that I need show my shader for.

dusty silo
#

hi i wanna add decals but there is no option for that here
there should be a render option here but mine dont have

fast sierra
#

tried to make a swaying grass shader and ended up with this abomination lmao
the heck am i doing wrong? is it a scale thing?

#

the shader is as simple as it gets i think

rich roost
fast sierra
#

the weirdest thing is that it works on the shader preview

#

wtf it works if i see it through the camera but doesnt work in Scene mode

dusty creek
#

I'm following the Toon Shader Tutorial from NedMakesGames I finished the additional lights section but it seems that it is skipping most of the shader itself and I can't find where this is happening, my guess is in the HLSL file but I wouldn't know where... anyone able to help?

the main light works fine with the ramp texture and specular highlight, while the additional light (the lightest gray part on the sphere) doesn't blend in with the main light, gets cut off by the main light and does not render the ramp texture nor the specular highlight.

dim yoke
gilded ridge
#

Anyone knows how can I remove atmospheric fog from specific objects?

queen vortex
#

Sorry for the perhaps silly question, but is there any way to interpolate more than 2 things using the same value?

basically I'm trying to do an interpolation from 0 to 1, but with sections of 5 images.

0 being the first image
0.25 being the 2nd image
0.5 being the 3rd image
0.75 being the 4th image

and 1 being the 5th and last image

is there any way to do this?

shadow locust
#

with matrix4x4s

#

i dunno about... images really but ideally the 5 things are in an array/buffer

#

basically the way I do it is like:

float t = whatever;

// find the nearest two values to the interpolant
// if t is 3.4, then low is 3 and high is 4
uint low = floor(t);
uint high = ceil(t);

// for example if t is 3.4, then t - low gives us 0.4
float portionBetween = t - low;

// interpolate between the two nearest values
result = lerp(data[low], data[high], portionBetween);```
#

this requires t to be 0 - 4 though, not 0 - 1

#

so maybe just a t = t * len(data); at the start to rescale it appropriately

dusty creek
#

if I have 2 different shader graphs that I want on 1 object, do I have to make them into subgraphs and put them both in a new graph? or is there an easier way

desert orbit
#

If you want two different effects you have to merge them in the shader

dusty creek
#

ok thanks

tiny lynx
#

this is probably the simplest thing ever but i have no idea how to look it up like at all bc im not familiar with the terminology, but how would i make a material thats just a solid color without any shading whatsoever

shadow locust
#

I think there's an unlit color shader built into every render pipeline

#

if not, it's a very easy shader to make/write

oblique field
#

I created a basic color changing shader with shader graph, but the material from the graph is pink. I've upgraded the material to URP and set up the URP asset in the settings, but the problem persists. Any idea what could cause this?

tight phoenix
#

How do I generate smooth normals from a pixelated texture? I know the answer has something to do with making the texture blurry and using Distance Fields

#

if this is my input, how do I make it so the normal map I generate from this is not pixelated mess and looks rounded and smooth

#

ideally the end result would look something like this? except without needing a texture map 4x larger

#

I know it can be done because thats how fonts do it

knotty juniper
twin valve
#

Hey do you guys know any good tutorials or exercises for learning how to use shadergraph or shader coding? I'd like to reach a point where I understand the concepts behind shaders rather than understanding niche tricks.

knotty juniper
# twin valve Hey do you guys know any good tutorials or exercises for learning how to use sha...

if you are into learning how shader work under the hood this video has a good overview
https://www.youtube.com/watch?v=kfM-yu0iQBk

this is more shadergraph stuff
https://www.youtube.com/watch?v=nDsTBk6eano

Welcome to my three part lecture on shader coding for game devs 💖 I hope you'll find this useful in your game dev journey!

If you are enjoying this series, please consider supporting me on Patreon!
🧡 https://www.patreon.com/acegikmo

00:00:00 - What are shaders?
00:03:00 - Case study/screenshots from FFXIV, Overwatch & more
00:37:42 - The Struc...

▶ Play video

In this Unity tutorial I go over some of the fundamentals of Shader Graph. How to sample textures, play around with colors, distortion, PBR, etc.

Shader graph is used with URP and HDRP, but the principles I show also apply to Amplify Shader Editor or any other node based shader editor.

Disturbulance Texture Pack
https://gumroad.com/l/mlUGC

Pr...

▶ Play video
tight phoenix
#

my sub surface scatter shader isnt working right at all

#

I followed this tutorial to the letter but my result looks nothing like theirs

#

How do I get it to look like theirs?

white marsh
#

im just taking some notes on how i can remove if statements from my HLSL code and ive come across using lerp(A, B, step(x, y)). But if i wanted to make this into a function for slightly better readability what would be a good name for it? im sceptical to naming it somethingIf, but not too sure what else could be a good name
or maybe i should just avoid making a function all together and just add a comment whenever i use it instead?

next sky
#

But everything is fine in the editor...

vocal narwhal
next sky
#

thx

regal stag
# white marsh im just taking some notes on how i can remove if statements from my HLSL code an...

Honestly the whole "avoid if statements" is an outdated thing. It doesn't necessarily mean the shader will even branch. But if it does, branching is usually fine as long as pixels take the same side, like using a property.
If you really want to avoid branches, think you can add [Flatten] before the if - or use a ternary instead (condition ? a : b). Should be slightly better than using lerp & step.