#archived-shaders

1 messages · Page 41 of 1

grand jolt
#

ah nevermind i got it

#

why not use shadergraph

deft frost
#

Can't. I'm using Built-In.

grand jolt
#

this may be a silly question since i've never used normal shaders

#

oh

grand jolt
#

(genuine question again, i'm curious)

deft frost
#

It's what I'm most accustomed to. I've been using Unity since about until the new Unity UI system came around in Unity 4

grand jolt
#

i see

deft frost
#

And I'd have to refactor a whole ton of other things if I wanted to move to URP

grand jolt
#

i see i see, yeah that's a reason

vocal narwhal
grand jolt
#

someone must be confused right now

#

is this a bad idea?

#

using that branch

deft frost
vocal narwhal
#

Yes, if you have questions just ask them here

deft frost
#

Ok. It’s currently dinner time so I can’t show my shader code right now

tight phoenix
#

Thank you! Sorta like ghetto metaballs, per this picture I am rendering that falloff to a render texture of the terrain, and then using that texture to calculate effects that will be on the terrain's surface. The way the overlaps overlap on the render texture makes it do the metaball thing on its own.
The render mode is 'Alpha' but many adjacent ones were adding up way too fast to 100%, is why the gradient ended up being very faint in the end

grand jolt
#

once you draw to a render texture, you use edge to get the shore?

tight phoenix
# grand jolt ohhh that's a cool way to do that

Yeah, smoothstep specifically. I couldnt get the effect to work without having some way for the different pieces to 'know' about eachother is why I settled for the render texture.
Its made from an ortho camera looking down that renders only the mask bits to a black background

grand jolt
#

I have no idea how to do that, but i sort of understand, that's cool

tight phoenix
tight phoenix
grand jolt
#

oh wow that's going in my bookmarks

grand jolt
#

what if ur plane of drawing is

#

tilted

#

then negative on the y axis won't work

#

it'll be skewed

grand jolt
#

this isn't a per pixel operation so i feel the branch shouldn't cause performance issues but

#

i might make a better blur shader later on

deft frost
#

The new pass I have just overrides the whole previous pass instead of adding to it.

#
UsePass "Custom/CharacterMix/FORWARD"

  void surf (Input IN, inout SurfaceOutputStandard o)
        {
           
            fixed4 p = tex2D (_Pupil, IN.uv_Pupil);
            fixed4 pm = tex2D (_PupilMix, IN.uv_Pupil);
            fixed4 pn = tex2D (_PupilNrm, IN.uv_Pupil);

            fixed3 finalColor = saturate(p.rgb + o.Albedo.rgb);
            o.Albedo = finalColor.rgb;             
      
        }
#

Even if I do nothing in the surf function, it still overrides it.

#

Can someone help me with this? A surf function that doesn't override the previous pass

#

Anyone?

distant dirge
#

patience exists lol

deft frost
#

Sorry... I've just been struggling with this all day.

distant dirge
# deft frost Sorry... I've just been struggling with this all day.

yeah thats fair, usually i will just leave my question in a channel and explain in great detail what i want and what im getting, then i go to sleep and come back to see if any answers are there, eventually if i dont get an answer i just go turbo research mode to see if there is anything hidden or anything thats tangent from what i want that i can use to solve my problem, and also after a few hours is when i bump my message

#

its alright unless you are trying to make a game in 1 week

tacit parcel
deft frost
tacit parcel
#

I think you also need to add alpha or alphacutoff into the pragma

deft frost
#

It worked. Thanks!

maiden leaf
burnt crag
#

Hi there. I am doing a course on Udemy for creating Shaders with code, and I can't seem to get this to work. I thought I typed it exactly as she has it, but when I switch to a texture, the color of the object changes, but doesn't apply the texture. Can someone help me see something I am not seeing?

{
    Properties
    {
        _myColor ("Example Color", Color) = (1, 1, 1, 1)
        _myRange ("Example Range", Range(0, 5)) = 1
        _myTex ("Example Texture", 2D) = "white" {}
        _myCube ("Example Cube", CUBE) = "" {}
        _myFloat ("Example Float", Float) = 0.5
        _myVector ("Example Vector", Vector) = (0.5, 1, 1, 1)

    }
    SubShader
    {
        
        CGPROGRAM
        #pragma surface surf Lambert

        
        fixed4 _myColor;
        half _myRange;
        sampler2D _myTex;
        samplerCUBE _myCube;
        float _myFloat;
        float4 _myVector;


        struct Input
        {
            float2 UV_myTex;
            float3 worldRefl;

        };


        void surf (Input IN, inout SurfaceOutput o)
        {
            o.Albedo = tex2D(_myTex, IN.UV_myTex).rgb;

        }
        ENDCG
    }
    FallBack "Diffuse"
}
distant dirge
cunning glacier
#

What is sharedMaterial

north wren
#

Hey everyone!
I'm a shader noob and I'm using this shader to produce a shine effect for my UI elements, it's working perfectly fine except that when game is played and atlases are generated, the calculated position for the shine effect uses the whole atlas the texture is part of
How can I get the position in the texture only and not the whole atlas?

My guess is something gotta change here but no idea what to do about it

meager pelican
#

Why don't you do it in the original pass rather than an extra pass?
NM, I see you got it working.

#

Also related to your performance question, the branch on a uniform isn't that bad. But you may not need it at all.
That's what shader variants do. Conditional compilation of, say, two variants: one with your uniform predicate, one without it (the true side one and the false-side one). Then, you set the shader to multi-compile both options, and the engine will pick the right one to use. One set of source code, two binary shader options, one for true and one for false.

grim nebula
#

tried to even make ChatGPT to convert it, didn't go well

meager pelican
cunning glacier
#

I don't get how that should change anything

grim nebula
meager pelican
#

Well, you could be setting the values on the wrong material reference. I don't know if you are or not. I'm just looking a code fragments you gave and wondering if that's why you're not seeing what you set in the buffer.

meager pelican
meager pelican
# grim nebula Or can anyone tell me how to make this? https://www.youtube.com/watch?v=ZPlCN-6W...

There's probably a few ways, depending on the EXACT result you want.
What pipeline are you in?
One way is to do a per-pixel ray-cast from the flashlight to your object and compute if it is in the cone-of-light or not. If it is, you'd have to decide on if that's good enough or if you want to also vary light intensity like they did in that video. But start with the basics and just get it to show up or not.

Another way is to have some kind of intersection test between a cone and the various objects...but don't actually draw the cone, just do the test. It looks volumetric of sorts, so I'm not sure a stencil will do. Drawing the light effect could be another pass.

#

All of the above needs to take the depth buffer into account, but if your invisible objects honor the depth test, the occluded pixels won't be drawn anyway.

shell fable
#

and to make the object change color when it's fully visible you'll have to do some checks on the CPU and change a shader variable to change the color

grim nebula
grim nebula
meager pelican
shell fable
#

I made a shader for a pretty similar effect but I unfortunately can't give that to you because I signed the rights away haha

grim nebula
deft frost
cosmic sphinx
#

I've written an HLSL shader but I'm not sure if the output values are right. Is there a way of debugging the value of the HLSL method for a certain input?

grand jolt
#

but i ended up solving my own question

#

on my own

woeful thistle
#

hiya!

#

I'm having a bit of a issue with a compute shader and 3d textures and i was wondering if i could get some help

#

I'm creating a 3D RenderTexture in c#, using SetTexture to send it to a compute shader and then running it, but for some reason the texture stays white! even if i specifically set it to be black!

#

here's the CS:

tex = new RenderTexture(volumeSize, volumeSize, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear);
tex.dimension = UnityEngine.Rendering.TextureDimension.Tex3D;
tex.volumeDepth = volumeSize;
tex.enableRandomWrite = true;
tex.Create();


shader.SetTexture(shader.FindKernel("CSMain"), "tex", tex);
shader.SetInt("volumeSize", volumeSize);
shader.Dispatch(shader.FindKernel("CSMain"), tex.width / 8, tex.height / 8, tex.depth / 8);

and the shader:

// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture3D<float3> tex;

int volumeSize;
[numthreads(8,8,8)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
    // TODO: insert actual code here!
    tex[id.xyz] = float3(id.x / 100, id.y / 100, 1);
}
#

im not really sure what to do, id really appreciate some help

grand jolt
#

and i should just use different shader variants

#

well that's a bit annoying

#

i wish i had a better way to do that because i have this subgraph (with the 4 inputs) that allows me to use the shader wherever i want

meager pelican
#

But 4 inputs results in 2^4 variants. = 16 variants for all combinations of input booleans.

meager pelican
#

Also it's always a good idea to bounds-check the subscript on the left of the =, so you never write out of bounds, although you may ensure that all dimensions are in fact divisible by 8, you don't want to assume that in code.

woeful thistle
#

also yeah good idea but i wanna figure out why its not doing anything at all atm

meager pelican
#

You're setting it to a float3. Use float expression.

#

Also, how are you checking the result?

woeful thistle
woeful thistle
#

this is the compute shader now

#
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture3D<float> tex;

int volumeSize;
[numthreads(8,8,8)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
    // TODO: insert actual code here!
    tex[id.xyz] = 0;
}
#

it's still showing fully as white, even though it's being set to zero

meager pelican
#

The inspector is only showing you the CPU side. NOT the GPU side....

#

😉

woeful thistle
#

i thought you could use the gpu to write to the texture

#

like since this is read write this should be visible in the inspector right?

#

UPDATING UNITY FIXED IT

meager pelican
#

It's like this:
The GPU is a separate computer inside your main computer.
You create a texture on the CPU side, initialize it, and then "send it off" in the "mail" to the GPU shop.
The GPU shop works on it LOCALLY. But if you want the results back "at your house" (cpu side) it has to be shipped back to you.
You can read data back from the texture when the GPU is done working on it.
BUT readbacks are slow.

#

And IDK why changing versions fixed it, unless they updated the inspector logic to go get the texture from the GPU. If you're not doing a read-back in C#, IDK how you'd see the data on the CPU side.

grand jolt
#

can i turn a Vec4 back into a Texture2D?

grizzled bolt
grand jolt
#

hmm

burnt crag
#

Hi there. Can someone help me with this. I am doing a course on Udemy, and I thought that I had typed this code exactly as she has presented it, but for some reason, my result is different than hers. When I apply a texture to the shader, it only changes the color of the object, and doesn't apply the texture. I am sure I have some type of typo in this, but I just can't see it. Can someone help me see what I am missing?

{
    Properties
    {
        _myColor ("Example Color", Color) = (1, 1, 1, 1)
        _myRange ("Example Range", Range(0, 5)) = 1
        _myTex ("Example Texture", 2D) = "white" {}
        _myCube ("Example Cube", CUBE) = "" {}
        _myFloat ("Example Float", Float) = 0.5
        _myVector ("Example Vector", Vector) = (0.5, 1, 1, 1)

    }
    SubShader
    {
        
        CGPROGRAM
        #pragma surface surf Lambert

        
        fixed4 _myColor;
        half _myRange;
        sampler2D _myTex;
        samplerCUBE _myCube;
        float _myFloat;
        float4 _myVector;


        struct Input
        {
            float2 UV_myTex;
            float3 worldRefl;

        };


        void surf (Input IN, inout SurfaceOutput o)
        {
            o.Albedo = tex2D(_myTex, IN.UV_myTex).rgb;

        }
        ENDCG
    }
    FallBack "Diffuse"
}```
grand jolt
#

why can i not do this?

#

(the LOD does not do anything)

regal stag
grand jolt
#

mipmaps?

grand jolt
#

same thing but different implementation, and a bit less flexible

#

i want to change the LOD so it's blurred

#

as i want to find an alternative to this method which looks bad and i feel is inefficient (sampling 5 times)

grand jolt
#

I've been trying to figure out what this does for a little, but i just do not understand what this is

vale fulcrum
# grand jolt mipmaps?

Smaller versions of textures created for better performance when viewing from a distance

#

make sure your texture asset has “generate mipmaps” enabled

grand jolt
grand jolt
#

texture made by the renderer

#

i don't have access to that

vale fulcrum
grand jolt
#

how do you get vec2 unpacking

#

i don't see a node for it

#

(split a vec2 into 2 float outputs)

#

it seems to work

#

why is this like this

#

why can't i get voronoi cells which are distributed somewhat evenly within -.5 and .5?

cunning glacier
#

Is there a way to get the previous frame texture? (In my c# code i'm using Graphics.Blit inside of OnRenderImage)

grand jolt
#

you could just save the frame to a texture and read it next frame, no?

grand jolt
#

the settings are default

grand jolt
#

for some odd reason they were using that method instead of

#

ignoring the moving vector, that's irrelevant

cunning glacier
grand jolt
#

umm

#

can you access the current frame's texture?

cunning glacier
#

i'm working inside of OnRenderImage, that gives me the source texture and the destination texture

grand jolt
#

just make a private member

#

on the top

#

and save it to that

cunning glacier
grand jolt
#

private RenderTexture m_oldTexture;

#

and write to that at the end of your OnRenderImage method

#
void OnRenderImage(source, dest) {
    // do stuff with source, dest and m_oldTexture

    // at the end set the old texture to the current one for the next frame
    m_oldTexture = source;
}```
cunning glacier
#

so should i blit the source to the oldTexture?

grand jolt
#

uhh

#

do you need to?

cunning glacier
#

i guess to copy i do

grand jolt
#

oh you probabbly do

cunning glacier
#

do i need to set some textures as active

#

because i didn't get how that works

grand jolt
#

use Graphics.CopyTexture()

grand jolt
cunning glacier
#

so at the end of the method i should add
material.SetTexture("_OldTex", previousFrameTexture); Graphics.CopyTexture(src, previousFrameTexture);

#

so that the shader first reads the texture before it gets updated

junior basalt
stray orbit
junior basalt
stray orbit
#

in the material if you use urp you have an option here for renderning the faces

#

maybe that will work for you if you change it to both

junior basalt
stray orbit
#

oh then i don't know what could be wrong

#

you can maybe try and make a custom shader with shader graph if it's not too complex to recreate

regal stag
stray orbit
#

I wanted to ask myself what would be the way to convert RGB values to a single value? like rgb to b/w

regal stag
#

There should be a URP -> Unlit shader that would work better if you need it to be unlit. Or create your own via shader graph

junior basalt
stray orbit
#

this is my current setup, i don't think it's actually correct yet

#

i mostly just want to make it easier for the smoothness and metallic map because the default shader requires it to be in alpha or something and i don't have a good tool for that

#

this rim should be more smooth but currently doesn't seem right

regal stag
stray orbit
#

yeah maybe i should look for such a tool to combine the metallic and smoothness map

#

it doesn't seem to change it

finite tree
#

hello guys, is there a node in shader graph thats literally output = input

regal stag
stray orbit
#

yeah, i want one that could just be inside unity with 2 image inputs or something

regal stag
finite tree
ivory cobalt
#

(in urp) Does anyone know a good solution for making semi-transparent objects cast shadows? Alpha clipping and dithering shadows don't give me the results I'm looking for. I need the opacity of the shadow to match the opacity of the object that casted it.

cunning glacier
grand jolt
#

you do not need the variable at the top

#

for the old frame

#

you can read from _OldTex

#

next frame

#

i'm pretty sure it doesn't get flushed

cunning glacier
grand jolt
#

private RenderTexture material

finite tree
#

any way to change a shader graph node fast without making a new one and reconnecting all the paths?
like if i wanted to convert a simple noise to gradient noise or something

grand jolt
#
private RenderTexture m_lastFrame

void OnRenderTexture(src, dest) {
    // do stuff with m_lastframe

    m_lastFrame = new RenderTexture(src)
}    
#

try this

#

and this


private RenderTexture m_lastFrame;

void OnRenderTexture(src, dest) {
    // do stuff with m_lastframe

    m_lastFrame = Graphics.CopyTexture(src);
}```
#

the second one is more efficient if it works

#

also, why aren't you using URP

cunning glacier
#

i'm using the built in one just to test stuff around

#

and because i didn't want to use shader graph

grand jolt
#

i see

grand jolt
cunning glacier
#

i wanted to get a little more confidence with HLSL since i never used it before, when doing shaders i always used GLSL

grand jolt
grand jolt
#

i mean can't you also use HLSL in urp?

cunning glacier
#

i think not with Graphics.blit etc

low needle
#

Hey guys I have a question:

I am working on a edge detection outline shader graph. Essentially I want to draw lines where I want to define them. I had the idea of using a color id map to define where the edges are (the edges are between where the colors change) as seen in the image. This way I can use color based edge detection to find where to draw the lines. Then of course the regular opaque map as seen in the image. I want to use the color id map to draw the edges from the camera's point of view, but render the color map and overlay the calculated lines. How would I do this because It doesnt seem that I can do this with a fullscreen shader graph. And there isn't a way that I know of to do this from an object shader.

grizzled bolt
low needle
#

Yeah I’ve read through a lot of them

#

None of the methods really fit my needs though

#

The closest one that got there was the one that was used for mars first logistics

#

I decided to use a color map instead since I couldn’t really unpack how he got surface ids to work

low needle
#

Here is the thread for that

regal stag
# low needle Hey guys I have a question: I am working on a edge detection outline shader gra...

If you're in URP you'd probably want to look into writing a custom renderer feature to re-render your model into a separate target with an overrideMaterial/Shader to render the colorIDs. Then pass that into a global texture property to sample in the fullscreen pass.
(If you use overrideMaterial you'd need to pass the ids into vertex colours. overrideShader keeps properties but I think it's 2022.2+ only?)

low needle
#

Ah I see

#

So essentially override it so you render it once with colorid then pass it to full screen to draw the lines then after you render the regular opaque map?

regal stag
low needle
#

Oh that makes sense

#

Thanks this helps a lot!

#

Before I go surrender myself to the hells of rendering stuff I wanted to ask, do you happen to know anything about Face ID stuff? I read somewhere that you are able to give each face of a mesh an ID I was curious about that.

regal stag
#

If it helps I've also got this feature which is fairly similar (renders objects into separate buffer for a glitching overlay effect)
https://gist.github.com/Cyanilux/d16dbfec869dbfb690426c837745679c
But it uses RenderTargetHandle which is deprecated in favour of RTHandle in Unity 2022. You may need to research into that.
Could keep the blit but removing that and using the Fullscreen graph + feature is probably better. Would also want to add that depth target as a second param to ConfigureTarget.

regal stag
low needle
#

I don’t want every object to have edge detection

low needle
#

If there is a way to assign something like that to faces that would be helpful I’ll still have to look further into it

regal stag
# low needle I don’t want every object to have edge detection

If you only do the edge detection on the buffer created by the colorID pass you can still control which objects have the edge detection (you'd specify a LayerMask in that feature).
But yeah, it's still a fullscreen effect and may be cheaper to do it in an object shader. In that case you would do the colorID feature first, then render those objects again in the opaque pass while doing the edge detection.

low needle
#

True

regal stag
low needle
#

Oh that’s actually genius

#

Though it might be a pain in the butt literally just rig edges so you have a bunch of islands that would help it

#

But it could also be problematic for stuff like weight painting

sly dawn
#

Hey all, so I have this shader, it basically lets me bake Animations into a texture, then run it back through a MeshRenderer and show animated vertices, without actual Skinned Meshes, and it's great. This was the original github repo I built it upon, and ive changed a ton of the code but the shader itself it pretty much unchanged:

https://github.com/piti6/UnityGpuInstancedAnimation

I've been trying to add things like a simple shadow pass, or depth pass, or get it working with Enviro Fog, or even transparency, but I don't really have any knowledge on how writing shaders works, and was just wondering where a good place to start might be?
Here's what it looks like when applying Post FX like Fog, or even just enabling shadows- note the ghostly cutout of the mesh in the render pass, this is what I'm hoping to add to the shader along with the Albedo color, which seems to be the only thing thats currently working:

GitHub

Unity animation object with gpu instancing. Contribute to piti6/UnityGpuInstancedAnimation development by creating an account on GitHub.

ocean raven
finite tree
#

im trying to add voronoi cells to hue
but why is the result only red from the color node and not how the Main Preview looks

shadow locust
finite tree
#

if i just connect the cells to fragment color, its fine

#

and with scene color its fine too

#

so probably something wrong with my color conversion

shadow locust
#

From 1, 0, 0, to HSV you'll get I think... 0, 1, 1

finite tree
#

yes

#

but

#

it behaving like this

#

like i just passed the 3 components

finite tree
#

but im adding voronoi cells to the hue

#

and the shader graph preview is what i want

#

but scene/game render is still just red

vocal narwhal
#

if you output the value from the Add you have there, is it just white?

#

and what does it look like when you feed it into a preview node in the graph

#

perhaps it would work if you fed it into a frac before combining it

#

I am also a little weirded out by how the gradient in the voronoi just completely disappears when you get to the colorspace conversion

finite tree
vocal narwhal
#

Ah that makes sense. Still, my other questions should lead us somewhere

finite tree
#

so i connected the add output to preview and to that conversion as well

vocal narwhal
#

Can you just put a frac inbetween the add and combine?

pastel trench
#

I have an issue where when adding a detail normal map, my normals completely mess up! I had to do some extra math to figure out how to use the green normal maps instead of converting them, which works for the base normal map but not for the detail one. Does anyone know why thats happening? Its really been bugging me.

finite tree
vocal narwhal
#

it's also red in the preview now?

finite tree
#

yes

vocal narwhal
#

I think that confirms my suspicions but now I just need to think about the workaround

finite tree
#

so what do you think is the culprit

vocal narwhal
#

I suspect that the Hue you're getting out of your color is 0 in the graph, but it's 1 in the material.
So when you're in the graph, you're essentially just getting the voronoi, but when you're in the material you're adding the voronoi to 1, and the hsv conversion does not wrap

#

But I don't totally have the maths in my head and thought the frac would have just fixed it, wrapping the result to 0->1, but maybe I'm missing something

finite tree
vocal narwhal
#

I know, it doesn't mean the preview isn't different to the material

#

I feel like I have no idea what is going on with the voronoi cells, you output it to color and it looks fine, you feed it through a frac node and get black? I don't get it

finite tree
#

the more i try the more im confused 😅

#

okay i have some colors

#

still probably doing it in a weird way tho

vocal narwhal
#

I don't understand how any output from the voronoi node through a frac is black, I feel insane

#

it's like it just outputs 0 when used with certain things

finite tree
#

yea thats weird

#

thought its 0-1

#

if you want me to add to (y)our confusion

vocal narwhal
#

I uh... am going to give up understanding this and chalk it up to 'shit's fucked'

finite tree
#

same Unitysadok

vocal narwhal
#

Like, I am used to the shadergraph preview being generally broken and unreliable, but I can copy the code it generates, add a frac of my own and I get black. Replace the frac with a basic while loop that should do functionally the same thing, and get what I expect. I just don't get it. Either I have a fundamental misunderstanding of something, or the voronoi node compiles reaaaal weird

finite tree
#

is there like, normalised object coords like the top of object would alway be y = 1.0 and the bottom y = 0.0

vocal narwhal
#

not that I know of

grizzled bolt
analog blade
#

Hey I'm using Unity 2019 for the purpose of developing maps for VRChat and I was wondering if anyone knows about, or has a shader that does the following: (apologies if I get some terminology wrong) I wanted to blend two textures preferably with heightmaps to break up the repetitiveness of certain textures. I see this in Overwatch a lot and I've attached an example. Is there some shader that would allow me to paint this transition onto my models, like on walls, floors, etc? I've also seen this type of thing with many terrain shaders such as microsplat, but I know it's probably different for things that aren't terrain.

elfin quartz
#

Hey, I'm writing a little custom HLSL function for Shader Graph. I need one of Unity's built-in matrices _Object2World, but I have no idea how to properly include it in my .hlsl file. Any hints?

#

Think I solved it, I forgot they renamed it to "unity_ObjectToWorld"

karmic hatch
cosmic prairie
#

(it would be a very begginer friendly shader graph 😉 )

split light
#

can noise() be used in a surface shader?

dim yoke
split light
#

i have been trying actually

#

instead of something saying its undefined, i'm getting cannot map expression to ps_5_0 instruction set at line 26

#

said line 26 is where noise() is

dim yoke
split light
#

how did google not show me that

#

hm

#

ok, might have to do random a bit differently

#

ty

#

maybe have it read from a property that is randomly set on the c# side

dim yoke
split light
#

want to randomly clip() things and reading the ms site on hlsl showed noise, was hoping a built in function would work for it. have seen a few examples of external noise functions but i don't think i fully understand it

#

i'll log fps with setting on the c# side and then using a external noise function in the shader, see which one is faster

#

probs the shader one

#

shader by far

#

c# one could be good for easily controlling the time it does choose a random number (and in my case, changing what things get clipped) but if you want to do it every frame, shader

vital basalt
#

Hey, I have a little problem:

-I have a shader that can make objects only render at a certain radius of the player (like cutting the part that isn't visible)
-I have a script that makes an edge collider have a modificable circumference arc shape

How could I combine this two both (make objects only render inside of that shape)

If you have any question or something you didn't understand, let me know

kindred lagoon
#

Anyone know why my ".shader" is pink? I'm not very good with shaders, sorry. It's just from the asset store.

#

I'm also using URP and I converted the materials and textures and such but it didn't change anything

vocal narwhal
kindred lagoon
#

Alright thanks

meager pelican
#

I suppose you could put a sphere of radius ? on the player and have it render only to a stencil buffer, and then have all the other objects render only inside that sphere. Of the objects you care about, that is.

prime shale
#

not like that

#

if you can elaborate more on what your trying to do it would be easier to help

#

well there is alot of things to keep in mind

#

I know you have that function running on the vertex shader

#

so the operations your doing are run for every vertex on the model

#

so with v.vertex you are grabbing the current vertex position

#

and with v.normal

#

you are grabbing the current vertex normal position

#

now

#

it is important to note

#

that the vertex normal is in object space I believe (someone can correct me if I'm wrong)

#

and the vertex position is in object space

#

basically you have two things in object space

#

now

#

the problem with this

#

is that you are sampling a texture

#

which normally has alot of detail or info on it

#

but remember

#

you are doing all of this in the vertex shader

#

meaning that you are only sampling basically like a low quality/blurry version of that texture per vertex

#

you following @grand jolt ?

#

there is a way but there are some things to keep in mind

#

because you might be getting what you want or you won't

#

but to finish the thought exercise, it's safe to assume that the normal map you are trying to sample is a tangent space normal map

#

not an object space normal map

tacit parcel
#

tex2d is for surface shader
use tex2dlod for vertex shader
note that the original v.vertex is in object space as @prime shale said while normal texture is usually in tangent space

prime shale
#

thanks for summary thats perfect

#

lol

#

but what you need to do is to transform that tangent space normal map into an object space one

#

you can do it right in the shader with some math if you know it

#

or if you can you could just bake an object space normal map

tacit parcel
#

or maybe bake it to vertex color if he doesnt use it 🤔

prime shale
#

true, something else you could do

#

would eliminate the need to sample a texture

#

after sampling the texture it needs to be transformed

#
  • 2.0f - 1.0f
#

or just use UnpackNormal(normalTextureColor)

sly dawn
#

Anyone know what i might be missing from this shader to correctly pass shadows and depth, and integrate other Post FX?

#

This screenshot is using EnviroFog, and EnviroVolumeClouds, but if i remove those and use Unity Fog it seems to render properly. It's a GPU animation shader that does some bone vertex magic to change whats being displayed in the meshRenderer itself, but I'd like to pass along everything besides the Albedo, Metalic, etc

tacit parcel
sly dawn
#

DUDE thank you, thats INSANE that it was that simple lol

#

I've spent weeks thinking maybe i need to pass some Fixed4 or float4 or something i dont understand yet, but nope that was enough. Thanks a ton!

sacred stratus
#

fixed4 is just like float4 but it s fixed has 32 bitstotal whereas float4 has 32*4 I think

#
Is there no way at allto set your own struct as a uniform in a shader?

dim yoke
sacred stratus
#

and do you know if there is a way to set your custom struct as a uniform in unity, without having to pass it as a buffer?

meager pelican
# sacred stratus fixed4 is just like float4 but it s fixed has 32 bitstotal whereas float4 has 32...

This is only supported by the OpenGL ES 2.0 Graphics API. On other APIs it becomes the lowest supported precision (half or float).

This is the lowest precision fixed point value and is generally 11 bits. fixed values range from –2.0 to +2.0 and have a precision of 1/256.

Fixed precision is useful for regular colors (as typically stored in regular textures) and performing simple operations on them.```
https://docs.unity3d.com/Manual/SL-DataTypesAndPrecision.html
"fixed" doesn't really exist in HLSL DirectX.  It gets promoted to half.  But wait!  Half gets promoted to float on DX10 or later.  lol.
So if you're counting bits, and you're worried about data size, you have to take platform differences into account, at least at the register level.  Storage in memory might vary, like in a struct...not sure...but the engine will take care of setting the right values on the elements when you do the set operations. 

The 4 (or 3 or 2) on the end of the scalar types promote them to vector types.  So half4 is 4 component vector of size "half" on the platform.   Half is equivalent to half1.
#

fixed is seldom used anymore. OpenGL 3.x doesn't even use it, IIUC. It's there for backward compatibility with OpenGL 2.x.

wicked prawn
#

hi guys, im trying to display character B all over my 3d gameobject i made a custom shader but doesnt seem to work, like i want it to display character b with golden color ona white 3d gameobject and the b's will be moving from right to left

cosmic prairie
wicked prawn
#

Actually I tried for the shader to write character b in golden or yellow color but it didnt work

#

Its supposed yo take a ehite or light colored texture

vital basalt
cosmic prairie
#

also, what's the shader?

#

send pics 🙂

wicked prawn
#

Can I get bqck to you after iftar?
Its almost iftar time

cosmic prairie
#

sure

wicked prawn
#

Im fasting

#

Thankyou would be great if I can resolve this

#

#

AND TODAY IS MY BIRTHDAY TOO AHHA

cosmic prairie
#

no problem, feel free to drop me a message later

cosmic prairie
wicked prawn
#

Thankyou 🥰

grand jolt
#

how can i sample more than once in shadergraph?

#

wait

#

i mean like multi-pass

#

not sample

wicked prawn
#
Shader "Custom/Alphabet" {
    Properties {
        _MainTex ("Texture", 2D) = "white" {}
        _Speed ("Speed", Range(0, 1)) = 0.5
        _Size ("Size", Range(0, 1)) = 0.2
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 100
        
        Pass {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            
            struct appdata {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct v2f {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };
            
            sampler2D _MainTex;
            float _Speed;
            float _Size;
            
            v2f vert (appdata v) {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }
            
            fixed4 frag (v2f i) : SV_Target {
                float2 uv = i.uv;
                uv.x += _Time.y * _Speed;
                uv.x = fmod(uv.x, 1.0);
                float2 offset = frac(uv * float2(1.0/_Size, 1.0)) * _Size;
                uv -= offset;
                return tex2D(_MainTex, uv);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}
wicked prawn
#

any idea? @cosmic prairie

cosmic sphinx
#

I'm trying to optimize this HLSL code:

if (a >= b)
  output = x;
else
  output = y;

I've tried to do it like this:

  output = step(a, b) * x + step(b, a) * y;

but the second solution seems to glitch when a and b are equal (sometimes it returns y, sometimes it returns x+y).
Also for some reason changing >= to > in the first solution glitches between x and y values.
Are there any suggested optimizations to get rid of if statement or should I just stick with it?

regal stag
cosmic sphinx
full ravine
#

A question about Compute shaders, I'm trying to set a float in a compute shader using heightComputation.SetFloat("rimWidth", RimWidth); in a cs script (where RimWidth is a float), but the shader takes the value to be 1.050254e+09 when it should be 0.3

#

What could be causing this

cosmic sphinx
full ravine
#

I mean int

#

Thank you

dense bane
#

regarding the 16 sampler and 128 texture limit in Unity, does it mean 16 sampler state limit?

wicked prawn
#

can i make 2 shaders work on a single gameobject at the same time/?

grizzled bolt
wicked prawn
#

i have two shaders one fro dispalying a character texture on top of the 3d gameobject
and the second one i need for setting opacity of the 3d gameobject

#

and need both on same

cosmic sphinx
# wicked prawn can i make 2 shaders work on a single gameobject at the same time/?

Technically one Renderer can have multiple materials, but it's for other cases. If you really want to process Renderer with multiple shaders, technically you could do some postprocessing, but it also seems to be a tool for other scenarios.

If I understand you correctly, you want to have select texture and transparency for the same object. Most shaders can do both things. When it comes to custom shaders, it should be quite easy to add a transparency setting if needed. I would recommend sticking to a single shader.

wicked prawn
#

so adding both functionalities to a single shader?

cosmic sphinx
wicked prawn
#

okay

#

ill try right now

cosmic prairie
wicked prawn
#

let me show you the refrence of what i need

cosmic prairie
#

but should work if you have plugged in a texture that has a B in it

wicked prawn
#

when the character appears on corresponding screen he has those b b b b b b b b b b all over it i want that and then a opacity thing to differenciate between different gameobjects

cosmic prairie
#

I can't really watch it, it wants me to log in

#

can you get it on streamable?

#

just a drag n drop

wicked prawn
#

umm

#

let me try

#

umm it isnt really asking for login i just tried in incognito'

cosmic prairie
#

on phone it does

#

says its not rated, need to log in

cosmic prairie
#

so you want to exactly replicate this?

wicked prawn
#

yes/

cosmic prairie
#

how do you want to flatten the character?

wicked prawn
#

orthographic view of camera

#

that makes it look like flatten

cosmic prairie
#

so you need no 3D view?

wicked prawn
#

no

cosmic prairie
#

is the camera stationary? does it not rotate?

#

because then u can use the world position as UV

wicked prawn
#

no camera will stay at the same positiono

cosmic prairie
#

or even the clip position

wicked prawn
#

basically ill be getting real time data from a signalServer
and im gonna use that to instantiate gameobject that will replicaterealtime movemnet of humans

#

and these gameobjects shown will be represented like that

cosmic prairie
wicked prawn
#

its 3 17 am here xd

#

😄

#

xd

#

okay sure

#

ill look into it

grand jolt
#

why is my second pass not being executed?

Shader "Custom/Shader"
{
    // properties ...
    SubShader {

        // First pass
        Pass {
            // Tags ...
            ZWrite off
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag_firstpass
            #pragma fragmentoption ARB_precision_hint_fastest
            #include "UnityCG.cginc"

            struct appdata {
                float4 vertex : SV_POSITION;
                float2 texcoord: TEXCOORD0;
            };

            struct v2f {
                float4 vertex : SV_POSITION;
                float4 uv : TEXCOORD0;
            };

            v2f vert (appdata v) {
                // ...
            }

            sampler2D _CameraSortingLayerTexture;
            float4 _CameraSortingLayerTexture_TexelSize;
            float _Size;

            half4 frag_firstpass( v2f i ) : COLOR {
                // ...
            }
            ENDCG
        }

        // Second pass
        Pass {    
            // Tags ...

            ZWrite off

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag_secondpass
            #pragma fragmentoption ARB_precision_hint_fastest
            #include "UnityCG.cginc"
            
            struct appdata {
                float4 vertex : SV_POSITION;
                float2 texcoord: TEXCOORD0;
            };

            struct v2f {
                float4 vertex : SV_POSITION;
                float4 uv : TEXCOORD0;
            };

            v2f vert (appdata v) {
                // ...
            }

            sampler2D _CameraSortingLayerTexture;
            float4 _CameraSortingLayerTexture_TexelSize;
            float _Size;

            half4 frag_secondpass( v2f i ) : COLOR {
                // ...
            }
            ENDCG
        }
        
    }
}```
#

this is my first shaderlab shader

#

i've done a fair bit of research for the past few days in shaders

#

btw, if i change the order of the first pass and the second pass

#

still, it is only the top pass that gets executed

#

which makes me think that the top one is being ran last and overwriting the texture somehow???

#

or the bottom one is just not being ran at all

compact reef
#

Does anyone know how to add Dithercrossfade into a vertex lit blended shader?

#

i.e the procedure

wicked prawn
#

hey i have this shader applied to a gameobject but if i apply the same shader to another gameobject alll the changes of one gameobject are copied in the other one

#

how to fix this

wicked prawn
#

this is my code

Shader "Custom/Alphabet" {
    Properties {
        _MainTex ("Texture", 2D) = "white" {}
        _TileX ("Tile X", Range(1, 10)) = 3
        _TileY ("Tile Y", Range(1, 10)) = 3
        _Speed ("Speed", Range(0, 1)) = 0.5
        _Opacity ("Opacity", Range(0, 1)) = 1
    }
 
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 100
 
        CGPROGRAM
        #pragma surface surf Standard alpha
 
        sampler2D _MainTex;
        float _TileX;
        float _TileY;
        float _Speed;
        float _Opacity;
 
        struct Input {
            float2 uv_MainTex;
        };
 
        void surf (Input IN, inout SurfaceOutputStandard o) {
            float2 uv = IN.uv_MainTex * float2(_TileX, _TileY);
            uv.x += _Time.y * _Speed;
            uv.x = fmod(uv.x, 1.0);
            uv = frac(uv);
            o.Albedo = tex2D(_MainTex, uv).rgb;
            o.Alpha = tex2D(_MainTex, uv).a * _Opacity; // Use alpha channel to define opacity of the object
            o.Emission = o.Albedo * 0.5; // Add some emissive effect to make the texture appear "golden"
        }
        ENDCG
    }
    FallBack "Diffuse"
}
#

i cant see the character in game view even if i set th eopacity to 1

cosmic prairie
cosmic prairie
wicked prawn
#

😄
it was always like this

#

like when i apply it to a material
and if that material is applied on another gameobject both go through same changes

tacit parcel
tacit parcel
wicked prawn
#

okay, and what if I instantiate multiple gameobjects

wicked prawn
#

@cosmic prairie

#

so I tried alot but that opacity thing was always messing up, I think I will use a 2d sprite instead as its gonna be a side view anyways
and I can just change the alpha of image color from code
does anybody happen to have any 2d sprite of such sort, that is a maybe male humanoid?

cosmic prairie
#

create a materialpropertyblock property in your code, in your start / inti method create a new instance of it

#

when u want to change a material value do the following:

#

yourmeshrenderer.getpeopertyblock(yourpropertyblock)

#

propertyblock.settexture/setwhatever()

#

yourmeshrenderer.setpropertyblock(yourpropertyblock)

#

or if you only need a finite number of materials just keep track of them and assign them in the sharedmaterial property of your mesh renderer

cosmic prairie
cosmic prairie
wicked prawn
#

What do you suggest

cosmic prairie
tacit parcel
#

iirc rendertype doesnt affect transparencies, it's purpose is more for shader replacement 'tags'

cosmic prairie
#

add Blend SrcAlpha SrcOneMinusAlpha

#

to your subshader

cosmic prairie
cosmic prairie
#

thats like a cutout

#

instead of a partial transparency

#

btw if u need hlsl commands check ms docs, for shaderlab and unitycg check unity docs

tacit parcel
wicked prawn
#

ill have a look into it

cosmic prairie
tacit parcel
#

from the code, seems like built in

cosmic prairie
#

yeah seems, wasnt sure tho

cerulean dune
#

Hello !
Is there any way in a Lit Shader (URP) to cancel the Ambient Light's color ? I tried a lot of things but it's always ending up by having a small color difference...
I also heard about setting my renderer's LightProbeUsage = CustomProvided but I have no idea of how to setup the entire lightning after that

cosmic prairie
#

urp shaders are... complex

#

check out block shaders from their forums, maybe with those its easier to change

finite tree
#

how do i get rid of the seam line without a custom noise tex? (using on a quad)

cosmic prairie
#

use a seamless noise algorithm

#

this has periodic noises

#

try those

finite tree
#

thanks!

wicked prawn
#

so i cant really use shader on a 2d sprite

wicked prawn
#

i downloaded this model but i cant apply my shader on it for some reason

cosmic prairie
#

it doesnt have uvs

#

which wouldnt even be a problem if the world space thing or the clip space thing was implemented

#

that I mentioned

lunar valley
#

there is also triplanar mapping if you don't like uv's :3

forest haven
#

I'm really new to the whole shader graph thing, and I'm honestly really lost
I know I may have overcomplicated things with this method, but I'm trying to learn to make things that I could reuse across multiple projects

I have sprites for houses and stuff, and I want them to me colored according to the team's color
I have 2 sprites for each house, one which is the sprite itself, and another which is sort of like a map that shows which areas should be multiplied by the team's color and which shouldn't

Anything painted black in the map should be ignored, and everything painted red in the map should be multiplied in the sprite itself

I tried working for hours on making my own shader to do that kind of thing, but I'm too new to this (literally learnt the basics yesterday) to actually implement it.

This is pretty much all I have

bitter lintel
#

I've been trying to apply this shader to Text (TMP and standard Text components) without success. With TextMeshPro, i can't even do anything but with Text, it just outputs black. Any idea how i could do that? I'm not that knowledgeable with shaders

forest haven
#

I haven't used it yet but thank you, you're awesome for giving such a detailed example haha

bitter lintel
#

Oh nevermind. I just changed the threshold and it works now

forest haven
flat orchid
#

how I can make motion trail shaders for character any idea

white marsh
#

can post processing shaders access the stencil buffer?

to just test if it was working i just put in this in:

Stencil {
    Ref 255
    Comp NotEqual
    Pass Keep
}
#

ofc i have something that should be writing to 255

white marsh
#

ok i think ive gotta find a different solution stencils wouldnt work the way i was hoping it would

lunar valley
#

just set the alpha to 0?

white marsh
#

you can se that the alpha is set to 1. if you want to make the white transparent you can use out of the comparison node as the alpha and plug it in stead of using 1

#

you might need to invert it first though

tight phoenix
#

I have a sinewave I am using as a shoreline that I am not sure how to adjust to function the way I want.
Currently the peaks and valleys are the same size across the whole effect, giving it a uniform band size as it emits.
What I want to see is the peak to narrow the further out it gets, for the inner edge to move faster than the outer edge so that it narrows UnityChanThink

But so far nothing i've tried has achieved that

#

visual diagram of what I mean

#

an attempt that I thought would work but doesnt

#

the bands remain uniform width, I want them to get narrower the further away from (0,0) they are

#

Oh getting close, I think I figured it out; just a matter of adjusting the values

tight phoenix
lunar valley
#

oh yeah don't forget to add the time node I forgot that

tight phoenix
jaunty mango
#

Can someone please help me? Im struggling alot with URP and 2D shadows, and now my sprite is black and the shadows are still not working

reef sail
white marsh
reef sail
#

and how do i do that ? lol

white marsh
tight phoenix
lunar valley
polar granite
#

Hey everyone. I bought a shader which includes a position transform to simulate tree sway in the wind, however, using it makes it not able to bake any lighting (baking loop). I checked the shader and I found a deprecated transform. I tried to replace it with the new transform node, but its still giving the baking loop. Removing this function fixes all problems. Any one has a clue what I can look for to fix the baking loop while still having the tree sway function?

grand jolt
#

oh wait

#

ztest

#

what's that

#

it did not seem to work

vital basalt
#

Hey, I am having some problems in making my shader up to work, could someone help me via dm? I would appreciate it so much

somber snow
#

I've been reading a book about shader programming and they do this to calculate binormals:

o.binormal = normalize(cross(o.normal, o.tangent) * v.tangent.w);

Why do they multiply the cross product by the w value of tangent?

#

Isn't the w value just 0?

tacit parcel
grand jolt
#

nope

#

still only the first pass being ran

#

this is the shader

#

I'm on the 2D renderer and _CameraSortingLayerTexture is the screen

#

(that i wish to use as the background)

regal stag
# grand jolt still only the first pass being ran

I don't know if it varies in 2D, but URP doesn't really do multi-pass shaders - when applied to materials on objects at least. It depends how you're applying the shader.

Even if the second pass does run, I think it would also just draw over the first. For a 2-step blur you'd need to input the result of the first pass into the second.

Usually you'd apply the blur using blits to handle both of these (e.g. first pass with _CameraSortingLayerTexture as source, to a temp render texture destination, then second pass with that temp as source, camera as destination)

grand jolt
#

ah

#

yeah i figured that but i just do not know how to execute

#

i am very inxeprienced

regal stag
grand jolt
#

or do i have to use c#

grand jolt
#

btw, only the first pass executes as the second is the vertical blur but it's only blurred horizontally

regal stag
grand jolt
#

i see

grand jolt
regal stag
# grand jolt or do i have to use c#

I think you might be able to use my blit renderer feature to handle it too, as that includes a "Texture ID" destination/source. If you still have that

grand jolt
#

hmm

#

i understand what you're trying to say

regal stag
#

I'm sure there's also blur renderer feature examples out there that handle both blits in one feature

grand jolt
#

i heard that it's more efficient to do it in multi-pass

#

but i just could be very wrong

regal stag
#

It's still multi-pass, just combining the two blit calls into a single feature

grand jolt
#

oh i see

regal stag
#

Might be slightly easier to setup that way

grand jolt
#

i see i see, okay thank you i will look into that 👍 :D

wraith quest
#

Anyone know how I can make object unaffected by fog using shader graph?

gloomy gust
#

why does my shader i made not work on my UI element? it works fine on a sprite renderer

#

these two are both using the same material but dont do the same thing

harsh bear
#

how do I make a texture for just the green one? I have a similar rectangle object, I just need to know how to make the texture, which is like a horizontal striped pattern thing, that wraps around the rectangle

polar granite
#

Is it possible that youre not supposed to use the time node for generating patterns and stuff? It breaks the light baker

#

Or are you supposed to lightbake first, and then apply the timenodes

dense flare
polar granite
#

Ok thanks 🙏

fleet olive
#

in blender, ive got something like this, which allows me to set the color of the iris

#

ive modified the eye to now look like this

#

and am looking to make a shader so that i can color the green and blue independently

#

i havent really used the shader system before though, so im not really sure where to start

lunar valley
fleet olive
#

i figured it out

fallow crystal
#

hey im having these errors, altought my shaders work just fine and nothing crashes, they also appear in build in the dev console but yet, they dont affect anything

#

how can i get rid of them? please ping in reply, thanks!

#

i am not modyfing and refering to _MainTex anywhere in the code

#

i dont have any references to that shader in the code

#

it's just a material that i dragged&dropped to an Image

#

this is the shader graph

tacit parcel
fallow crystal
#

im not refering to the material at all

amber saffron
fallow crystal
#

changing the texture property name to _MainTexture in the shader graph will fix it?

amber saffron
fallow crystal
#

should it be _MainTexture?

amber saffron
# fallow crystal

Sorry, yes, _MainTex , but the important one is the Reference name

fallow crystal
#

it is a problem then, when changing the Reference name to _MainTex the shader doesnt work properly on my UI

#

this is the UI shader, a horizontally scrolling race flag

#

this happens after changing the name

amber saffron
#

Did you assign what I think is the flag checkerboard texture to the image component (in the sprite property)

fallow crystal
#

oh, so it might reset back to None when changing the Reference name?

amber saffron
fallow crystal
#

alright, i can see it did indeed reset to none

#

thank you

frozen jetty
#

Sorry for idiotic screenshot i on phone now. I have a problem. In my 2d game, i do a shadows based on transform matrix model in shader graph. It duplicates texture and do offset based on rotation. But i noticed that transform matrix model dont work when objects batched it always return the same value. I need Up transforms vector to calculate. In Example Material change color based on rotation. Triangle works but 2 squares are batched so they always the same.I can change material in script to broke batching but is bad for performance. So how can i get up transforms vector to do with batching? Help me please.

haughty tendon
#

can i have some help recreating this shader from blender in unitys shader graph, its a sphere with a radial gradient

meager pelican
sick sparrow
#

Quick Question: ... is it possible to spawn meshes on a surface using shader graph URP. Basically what I'm looking to do is create your typical moss shader that only appears on surfaces facing up, but I'd also want it to spawn in alpha planes for the fuzziness... is this possible? If not, anyone got any suggestions as to what would be the best way to achieve this. cheers

haughty tendon
#

my shader in blender looks like this

frozen jetty
#

I im beginner in shaders. I dont have this shader now . But i have shader in example.

meager pelican
haughty tendon
#

can someone help with my thing chatgpt is hallucinating

meager pelican
# sick sparrow Quick Question: ... is it possible to spawn meshes on a surface using shader gra...

You may wish to investigate snow-shaders. They "spawn" snow on top of objects. In your case it's green and textured for moss.
You don't normally want to generate meshes in the shader, but you can modify them to generate thickness.
You CAN spawn triangles in a shader, they're called geometry shaders, but you have to have something to start with and they're SLOW so they're generally avoided if possible. What's normally done is to modify the underlying mesh.

sick sparrow
lunar valley
meager pelican
haughty tendon
#

scroll up please my question is about 5 messages earlier

#

i need help my fellow game devs

meager pelican
# sick sparrow thanks

Unity Shader Graph - Rock Blending with Moss or Snow Shader Tutorial

In this Shader Graph tutorial we are going to see how to create a shader that gives the illusion of Moss, Snow or Dust accumulating on top of a rock, road or even a roof.

It can have other purposes like making an object look wet from water or you can blend between materials....

▶ Play video
#

I've GTG for work. Have fun gang.

shadow kraken
#

What you're asking isn't possible with any built-in features @sick sparrow. But it might be possible to create a script that you can run manually to process the scene and instantiate meshes in the relevant areas. You would have to build the script yourself though

finite tree
haughty tendon
#

am i shadowbanned

#

why are yall talking about modifiying gpu shaders mid render cycle but you cant tell me how to put a gradient on a sphere

meager pelican
haughty tendon
#

fml

#

i have been homeless and this is exactly what it feels like

shadow kraken
#

Gradient + Sample gradient is what you want @haughty tendon

haughty tendon
#

thank you ole

sick sparrow
# meager pelican https://www.youtube.com/watch?v=Q43XBychCEY

Thanks for the link. this is how I would usually do it. but I'm looking to create somethign a bit more high-end with my current scene and was looking for a solution that would look good close up. Basically imagine I'm just trying to spawn tiny blades of grass on any particular surface.

haughty tendon
#

but it needs to be mapped to a pshere

#

the gradient requires something to plug into time

#

i mean sample gradient

finite tree
haughty tendon
#

and im trying to plug uv, position everything in idk what

#

to plug in

#

y what?

finite tree
haughty tendon
#

this is what i want it to look like

#

gradient + sample gradient doesnt work you need some other magic

finite tree
#

most likely you want it in object space

#

so you split the position, get your y (aka r g), and plug it in time

meager pelican
#

(Gone now, later)

haughty tendon
#

@finite tree thank you you are very kind

#

one final thing how would i change the scale?

finite tree
haughty tendon
#

the gradient i think , maybe i just need to create an open value and assign a gradient that i make via script

finite tree
#

im sorry, can you please illustrate what you mean by scale gradient?

haughty tendon
#

i think its a porblem i need to research on my own first before wasting others time with something i can probably solve on my own im sorry for asking that latter question 😦

grand jolt
#

Hey, I am a complete newbie to materials, shaders, etc.
Making a mobile game in Unity and I am currently using no scriptable render pipeline (or at least it says "None" in my project settings) if it's relevant.

Is it possible for me to place shader / material on Image (Canvas) component (Not SpriteRenderer)?
If yes, can I have one shader / material that I can just place on multiple images that would make them black and white?

shadow kraken
#

Yes

grand jolt
#

I also saw the possibility of using Graphs to create shaders instead of writing them. Is this viable with these? (When I click on my shaders file it opens up code always)

shadow kraken
#

Then you can create a _MainTex texture parameter, which will read the image from the UI image

#

I tested it in shadergraph here

#

But if you're on the built-in render pipeline, then you need to be on the newest version of unity to have access to the shader graph

grand jolt
#

2021.3.16f1 is the version I am on

#

Oh just had to reinstall the package

#

Thanks a lot ❤️

haughty tendon
#

why does my shader work in unity but not on the sphere i imported from blender

finite tree
haughty tendon
#

also it only works on half of the sphere in the shader graph aswell

finite tree
#

you are using r, im sorry for my mistake earlier

#

y = g

#

xyz/rgb, you wanted to use the y so g

haughty tendon
#

i switched it for the x axis

#

it still not fixing it 😦

#

and it only covers half the sphere

#

in the shader graph

#

you can see in your screenshot the bottom half of your sphere is all red

tacit parcel
# haughty tendon

looks like different orientation, unity's sphere has y up orientation while blender has z up orientation

haughty tendon
#

na it just paints the whole sphere one colour

finite tree
haughty tendon
#

thank you

frozen jetty
amber saffron
frozen jetty
#

Is there any other way to get the rotation vector. To make it work when batching? For sprites.

haughty tendon
#

sorry to interupt but @finite tree's solution works in the shader graph but when i apply it to a high poly sphere imported from blender its just one colour and i dont know why

finite tree
finite tree
haughty tendon
#

yes it works on unitys sphere, and updating!!! i found it works extra good on probuilders sphere

#

so i think ill just use that if you cant come up with a better solution!

grand jolt
#

Hey, so I have created Unlit Shader Graph GrayScale (I want to place it on my Image (Canvas) as a Material).

I created GrayScale Material and placed the material on my Image. How do I assign the texture or the float value parameter? :/

distant dirge
lunar valley
grand jolt
shadow kraken
#

Can you show the properties panel of your variables?

#

This is how it looks for me by default, and then you can hide the maintex property in the material as well since it's assigned automatically

finite tree
#

why are my exposed nodes greyed out in the inspector?

bitter lintel
#

Do you guys have any resources for learning how to make URP shaders as a beginner in that space? All the ones i find are for the standard rendering pipeline, which makes them useless

grand jolt
#

Do you mean this one? Or this one

shadow kraken
grand jolt
shadow kraken
#

Have you pressed save asset in the top left?

grand jolt
#

Oh well, I have been pressing Ctrl+S in hopes it would save but it didnt :'))

#

BTW, Can I edit these values for example your "Saturation" dynamically through code?

lunar valley
shadow kraken
#

Yeah for sure, you would use the SetFloat function and use the reference as parameter

grand jolt
#

Alright, thanks a lot. Helped me tremendously 🙂

reef sail
#

i have a custom shader that is supported by SRP but i wanna convert it to URP, is there is an easy way to convert it ? i tried to let unity convert it but that didnt work + i have 0 knowledge in custom shaders

lunar valley
shadow kraken
#

Certainly not something you would call easy. Without experience it's not really feasible

finite tree
lunar valley
finite tree
#

i made the shader

#

and im using just the automatic material from the arrow button

lunar valley
finite tree
grand jolt
#

@shadow kraken Would it be possible in my case Image (Canvas) shader somehow take into account the Color input (highlighted in image) on Image as well? Currently it has no effect and it is important to have effect when it comes to buttons :/

shadow kraken
#

And then multiply that over your existing colour

grand jolt
#

So it essentially takes it automatically for each Unity Script serialized field on Image and Sprite Renderer?

shadow kraken
#

You can see here the parameters that the default UI shader uses

grand jolt
#

So for Unity Components - Image and SpriteRenderer I can reference _MainTex and _Color and it will automatically be taken as input in the material

shadow kraken
#

Yes indeed

grand jolt
#

_Color ("Tint", Color) = (1,1,1,1) would be equivalent to Vector4 then?

#

As I can't have "Tint" in Shader Graph inputs

shadow kraken
#

The reference is _Color, the displayed name is Tint

lunar valley
shadow kraken
#

The displayed name can be whatever you want

#

There is a dedicated parameter type for colour

grand jolt
#

Oh alright, I understand now

#

Thanks, I actually managed to learn a lot of Shader Graph today thanks to you 🙂

white marsh
#

can i use fwidth for aliasing on a mask?

#

or i guess another question could be. should i implement the aliasing into the shader or let post processing do it?

grand jolt
#

Welp the _Color doesn't work (I saved this time :D).
I tried with both Vector4 and Color as type of input.

I also googled that Sprites (which I am not sure if it's my case as I am using Image(Canvas) component) use the vertex colors of the mesh for the colour. Any ideas?

#

This is how I validated it would work - I would have much darker images with the red color as input

shadow kraken
#

Aha

#

This is because you're adding the colour before you're doing the colour correction

#

You should be multiplying the colour at the very end

#

Try that first @grand jolt, your setup works on my end with colour

grand jolt
#

I mean the Multiply works - it's the problem of Unity not taking the Color from Inspector and assigning it to the shader

#

The red is not applied

shadow kraken
#

Even if you set the saturation to 1?

grand jolt
#

Yup, sadly it just keeps the default value and it never changes based on the set value on Image Component

#

If you change the value on Image Component does your image change as well?

shadow kraken
grand jolt
#

Oh wow, that's interesting

#

Using Multiply under Match > Basic > Multiply

shadow kraken
#

Oh you're using the wrong base shader

#

That might be it

grand jolt
#

Oh I am on a Built-in render pipeline so I don't even have that option I suppose?

shadow kraken
#

What are your options?

grand jolt
#

Lit or Unlit

shadow kraken
#

Then it might not be an option I suppose

#

The shader graph for BiRP is still pretty new

grand jolt
#

Are there any breaking changes when I switch to different render pipeline?

#

I didn't look into render pipelines before so I might be able to just switch easily?

shadow kraken
#

Depends a lot on your project and how far along you are

grand jolt
#

I mean project is purely done in Canvas and via Images

shadow kraken
#

Then it might be ok

#

But it wouldn't be too complex to do this shader in HLSL instead, as long as you just need the base features + saturation

grand jolt
#

I mean that's option as well I suppose, I'll check the URP first and see if that's the correct approach

shadow kraken
#

Be sure to make a backup of your project

regal stag
#

Shader graphs really don't work that well on UI though, it doesn't have proper support for it.

#

It's kinda okay if you use canvas set to Screenspace-Camera, but Overlay doesn't work well - I think because it tries to draw all passes (including shadowcaster, depthonly, etc).
Also won't work with masking components though (like scroll rect)

grand jolt
#

Yes I am working with Scroll Rect and I am receinving "doesn't have _Stencil property" warnings already

shadow kraken
#

Yes, that's also something that's handled in the written shader

grand jolt
#

But I believe I should be able to get _Stencil property and perhaps mask it in shader?

#

The colors btw work with the URP

#

(Although I have several errors now lol)

regal stag
# grand jolt But I believe I should be able to get _Stencil property and perhaps mask it in s...

You could define them in the blackboard to stop the error, but you won't be able to mask with them. It's not used in the HLSL code of the shader, but the ShaderLab portion for Stencil operations.

Stencil
{
    Ref [_Stencil]
    Comp [_StencilComp]
    Pass [_StencilOp]
    ReadMask [_StencilReadMask]
    WriteMask [_StencilWriteMask]
}

Shader graph doesn't allow you to add these for some reason. You could generate code from the graph, copy and edit that, but not a great workflow (it's then separate from the graph and you'd have to generate & edit every time you need to make changes)

grand jolt
#

I don't think I will be editing this changing this Shader afterwards - so how would I approach the generating code and masking with stencil? Is there some resource you are basing this of?

#

i can't seem to figure out what's causing this issue:

#define GRABPIXEL(weight,kernelx) tex2Dproj(_CameraSortingLayerTexture, UNITY_PROJ_COORD(float4(i.uv.x + _CameraSortingLayerTexture_TexelSize.x * kernelx*_Strength, i.uv.y, i.uv.z, i.uv.w))) * weight
#

it is a float4

regal stag
# grand jolt I don't think I will be editing this changing this Shader afterwards - so how wo...

When you select the graph asset in the project window there's buttons at the top of the inspector, one should be like "View Generated Code". It'll then open as shader code in a temp folder. Can copy that .shader file to your own project and edit it.
Can use the default UI shader like Ole linked earlier as reference : https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/UI/UI-Default.shader

grand jolt
#

so just doing

Stencil
{
    Ref [_Stencil]
    Comp [_StencilComp]
    Pass [_StencilOp]
    ReadMask [_StencilReadMask]
    WriteMask [_StencilWriteMask]
}

would mask it already?

regal stag
#

Should do yeah (assuming you also add lines 10-14 of that UI-Default shader)

grand jolt
#

Alright, thanks a lot 🙂

regal stag
grand jolt
#

um

#

i fixed it JUST now

#

it was Texture2D

#

it is meant to be a sampler2D

#

i don't know why but i assumed it was an issue with the second param

#

how would i change this to camerasortinglayertexture

#

ohh i did it

#

nvm i did not

regal stag
#

If you're using _CameraSortingLayerTexture in the shader (for first pass), I'm not sure you really need to

grand jolt
#

it does not draw

#

well i want to draw to that texture

#

because that is the texture behind the UI

#

if i draw to _CameraSortingLayerTexture

#

then this happens

#

wait

#

what

#

nevermind i need to do this?

regal stag
#

This is drawing _CameraSortingLayerTexture to the camera, not the other way around. Right?

grand jolt
#

i just know that one way the ui is drawn over

#

and i don't want to apply the blur to the UI

#

(if i apply the material to the background gameobject, it works just fine)

#

(but second pass does not execute)

grand jolt
regal stag
#

If the feature is set to the before/after post process event I think the blur should still occur before UI.

grand jolt
#

well

#

it overwrites the UI

regal stag
#

In the blur feature I'd try :
Blit using cameraColorTarget to a tempTarget, using first pass (0). In that pass, sample _CameraSortingLayerTexture
Blit using tempTarget to cameraColorTarget, using second pass (1), sampling _MainTex (or _BlitTexture if using newer Blitter API / RTHandles)

regal stag
grand jolt
#

i have post-processing on the UI

regal stag
#

Ah right

grand jolt
#

the first pass is what i've been doing so far but

#

why sampling _MainTex?

regal stag
grand jolt
#

every source is passed to _MainTex?

regal stag
#

So you need the second pass of the blur to use the horizontally-blurred texture, hence the tempTarget

grand jolt
#

oh so _MainTex would have the blurred texture?

regal stag
#

Assuming you set the blits up with the targets like I mentioned, yeah

#

_MainTex in the first pass would just be the camera target. Could try keep using that, or _CameraSortingLayerTexture. I'm not sure if it matters

grand jolt
#

i see what you mean

#

ohhh

#

that makes sense

#

the blur works

#

ayy

#

the ui is still being overwritten though

#

no matter how far up i go in the render process

#

is it possible that i could make a material with 2 pass instead?

#

or like pass a global texture

#

to a material to sample and display

regal stag
gloomy gust
#

why does my shader i made not work on my UI element? it works fine on a sprite renderer
these two are both using the same material but dont do the same thing

grand jolt
#

i made a rendertexture

#

and made that into a material

#

which i put onto the sprite

#

but it's just white

grand jolt
#

it works

#

but i did write a shader to draw that custom texture

#

which i'm not sure is ideal

#

whic his also quite buggy lmao

grand jolt
#

why is it so buggy

#

lmao

#

it works but it's glitching out every now and then

grand jolt
#

(to draw the texture to the material)

#

i love that i can 10x downsample the image with the high blur and still have it unnoticeable

meager tulip
#

can anyone tell me why it wont appear to be selected and wont let me drag it in

#

(bottom left)

#

Nvm i got it

tight phoenix
#

In shadergraph URP I want to do an effect that doesn't show / masked out if its in shadow of another mesh.
What is the method to access the scene shadow data?

#

https://youtu.be/RC91uxRTId8
I tried following this tutorial but the results I got were buggy and inconsistent, and didn't work to receive shadow data

#

By buggy an inconsistent I mean

  • the shadows cast have holes in them
  • the meshes don't receive shadows
  • the mesh lighting is a bizarre stepped thing that I can't explain, gif shows it
regal stag
# grand jolt whic his also quite buggy lmao

My guess would be the render feature is on the renderer marked as "default" on the URP asset, which is also used by editor previews - like the one in the bottom right. It's using the same render texture, so overrides the scene/game view as well.
Should be able to fix it by preventing the feature from being enqueued or executing by checking the camera type and return early.

if(renderingData.cameraData.cameraType == CameraType.Preview) return;
regal stag
#

That won't really fix the holes in the shadow, that's probably just the mesh or shadow bias settings affecting that. Could also change Renderer to Cast Shadows : Double Sided, might help.

tight phoenix
#

Yeah realized that after the mesh itself is just has janky holes

tight phoenix
#

I am using the v8 branch because I am on 2020.3

#

oddly I only get the error in my shadergraph, I dont get any error when inspecting the subgraph itself

#

ill try to read through the notes if its answered somewhere

regal stag
#

Maybe try opening the subgraphs and re-save them?

tight phoenix
#

sweet, access to shadows 👍

tight phoenix
#

"inset geometry a little bit along its normals." reccomends the doccumentation, Ill have to google how to do that

regal stag
tight phoenix
#

Ah yes Depth Bias right away makes it look a lot better 👍

regal stag
tight phoenix
regal stag
# gloomy gust why does my shader i made not work on my UI element? it works fine on a sprite r...

Hard to tell what the actual problem is here, we don't know what the shader meant to be doing.
But also if it's a shader graph, that doesn't really support UI (when using a Canvas with Overlay mode at least, Camera or World space UI tends to work okay). But usually better to write code based on the UI-Default one instead (https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/UI/UI-Default.shader)

woven plover
#

i feel like that should be obvious but i cant wrap my head around it.
i want my triangles to use the vertex color of the first vertex of the triangle => no smooth color interpolation.
im looking at the URP shadergraph but i cant think of how to implement that.

#

its for a minecraft like fragment shader

regal stag
#

You can technically specify nointerpolation on interpolators in hlsl, but shader graph doesn't have access to that.

finite tree
#

is there a way to use some other object's property in a shader graph?

woven plover
regal stag
finite tree
grand jolt
#

that did not change anything

#

there are still flickers

regal stag
grand jolt
#

might just be my system

harsh bear
#

any1 know how to make just that green part? like the double colored stripes and have it wrap around a rectangle

finite tree
harsh bear
#

oh shoot

#

where would I go?

regal stag
grand jolt
#

not sure, terrain?

harsh bear
#

aight ill try there

harsh bear
#

thanks man

regal stag
grand jolt
#

it does not happen in play mode

grand jolt
regal stag
harsh bear
echo lily
#

How can I disable vertex lighting on a sufrace shader? (VERTEXLIGHT_ON)

regal stag
split light
#

writing a general purpose shader for this project but got one problem. It seems its not correctly handling transparency as you can see the edges of the texture being used

#

should probs post code, one moment

#

hm, discord isn't liking me putting in a codeblock, pastebin it is

#

tried playing around with blendmode, zwrite and the renderqueue but no luck

finite tree
#

i clicked the delete key when i had custom function node selected, it disappeared but left a ghost there, lagged my whole shader graph, previews stopped moving, and apparently "nothing loaded" after i clicked Save Asset, moving nodes is kinda weird now, and well, restarting unity is my only option now, i hope my shader will heal in that time UnityChanPanicWork did this happen to anyone before???

finite tree
frozen jetty
finite tree
frozen jetty
grand jolt
#

I have a shader, when i am in edit mode i can change the strength slider, and the game view represents this change, but when i am in play mode, the slider does not change anything

grand jolt
#
m_backgroundBlur.SetFloat("_Strength", Mathf.Lerp(m_backgroundBlur.GetFloat("_Strength"), m_enabled ? blurIntensity : 0, lerpValue));
Debug.Log(m_backgroundBlur.GetFloat("_Strength"));```
#

this is my code, and i can confirm that the value is being changed by the debug.log

fleet olive
#

what can i do to make this look less creepy

#

i dont have any of the other facial features made but its in progress

#

right now i dont want the eyes to pop as much

grand jolt
fleet olive
#

those eyes were made specifically with a custom shader

#

and i think that might be why

#

right now its really simple

#

i feel like tweaking something in here could make it less horrifying

grand jolt
#

i have substituted for this, instead of the "_Strength" string, although that yielded no results either

low lichen
fleet olive
#

alr

tacit parcel
grand jolt
#

here is my code

#

i usually do not have line 30

#

but it does not make a diference

#

with line 30, it says (Instance), without it says no instance

tacit parcel
#

in line 25, try using sharedmaterial instead

grand jolt
#

i am just restarting my project 1 sec

grand jolt
#

do you mind explaining why you thought that would work?

tacit parcel
#

getting material using .material and modifying it might get the material instanced

Note:
This function automatically instantiates the materials and makes them unique to this renderer. It is your responsibility to destroy the materials when the game object is being destroyed
https://docs.unity3d.com/ScriptReference/Renderer-material.html

grand jolt
#

i see

#

thank you :D

tacit parcel
#

you're welcome 🙂

dire ravine
#

I found this "Enable" Node in a video I was watching, but I cant seem to find it, what was this node replaced with?

shadow locust
tiny edge
#

Is there a way to change the Unity grass texture shader for Terrain so that it has point filtering alphas? Trying to work around this rounding I'm getting with the pixels in my alpha textures.

lunar valley
meager pelican