#archived-shaders

1 messages Β· Page 173 of 1

meager pelican
#

He's scaling cameravec by the offset amount. Then adding it to the vertex.

#

So you'd want something that's more of a percentage type of thing.

#

Plus or minus. So like -1.1 or 1.1 if I read it correctly.

#

Or maybe .001 or -0.001

sinful shuttle
#

But that wouldn't make sense with a vertex color as input...

#

Well that might.

#

Anyway as a test I commented out "v.vertex.z = desiredpos.z * o.vertex.w / desiredpos.w;" and the road reappeared so it is at least working in some fashion.

#

However Z offset of -1.1, 1.1, and 0 do not make the road reappear.

meager pelican
#

Well zero would eliminate the offset completely

#

You want to, as I understood you, offset a min amount to be toward the camera. He's doing a vector toward the camera pos (or from the camera pos). And then scaling it and adding that to the vertex pos.

sinful shuttle
#

Yes, and if I eliminate the offset completely, that should have the same effect as commenting out that last line to set the vertex Z value.

#

But it doesn't. The road dissapears. Which tells me the z value is being lost or corrupted somehow in all the math.

#

Unless by offset you mean the Z is being set to 0 rather than the offset from the Z is being set to 0.

#

UnityObjectToClipPos(v.vertex + zoffset * float4(cameravec.xyz, 0.0));

#

But that ought to just return the vertex position plus nothing if I set zoffset to 0.

#

Though I could be wrong, since I don't understand this part: "float4(cameravec.xyz, 0.0)"

#

What is the 0.0 on the end? And why is the one above dealing with world space 1.0? Is that some kinda vector length? That might explain the offset not working if so, but not the road disappearing when the offset is 0.

junior crow
#

Hi. I’d like to achieve something like this:

#

But instead of each object just being one shade, I’d still like the object to be lit, but I want its gradient map to be controlled by a custom colour palette. Is this possible through a similar method?

#

ie. no texturing. Each material is just one flat colour that shifts to another colour depending on how much it's lit. And I want to be able to set the colours in a colour palette.

meager pelican
#

That's the w component of the vertex. He's got xyz, and is setting w to 0 of the 4 component vector.

#

That's a bit tricky to explain, it it's setting the perspective divide. To convert from clip space to NDC, it divides by .w component. And that happens in hardware. Basically the farther away it is, the more it is divided.

#

Or something like that.

#

Such that the view frustum gets a perspective and the farther away it is, the more "space" it covers.

#

It moves everthing further away more toward the center, compared to straight lines.

#

Vanishing point type of thing

#

Happens in hardware.

#

@sinful shuttle Also try .1 and -.1 or maybe .01 and -.01 for offset.

sinful shuttle
#

None of those works. The road mesh is simply gone.

meager pelican
#

I'd have to play with it I guess, But I can't now, IRL stuff in the way. I'm back and forth from the keyboard right now as it is.

#

Anyway, you want to add an offset that's toward the camera, to the vertex. But I'd have to play with it. I'm not even sure how much perspective correction is needed if it's a small offset.

#

Right now it looks like he's just modifying the z value of the vert multiplying by the ratio of what the desired pos.z is and the old-pos.z or something.

ripe pagoda
#

can I make my own sampler2D manually? where would I learn about what is in there?

low lichen
#

@ripe pagoda sampler2D just represents a 2D texture object that can be sampled. Are you asking if you can create a 2D texture yourself?

ripe pagoda
#

ah, I was specifically interested in changing the UV I think. Was trying to understand whether I could use TRANSFORM_TEX with my own UV to get it to compute some scaling/offset for me.

regal stag
#

TRANSFORM_TEX is just short for uv * tiling + offset

#

But uses the tiling and offset values from a texture, which unity stores in a float4 textureName_ST (.xy being tiling, .zw being offset)

ripe pagoda
#

ah ok, if it's that simple, then I probably don't need it, thanks! πŸ™‚

radiant fiber
#

How can I get my particles to emit from the emitter but still move in world space?

dreamy kernel
#

Can compute shaders be used for... shading?

#

It's just I'm considering a possibility of approximating some complex shading functions via neural nets

#

Since they are basically lookup tables, that almost don't take up memory and scale up very neatly

low lichen
#

@dreamy kernel Compute shaders can be used for anything, so absolutely

dreamy kernel
#

Great

#

By the way, how could I have a pixel color of a background entity to be an input to my shader?

low lichen
#

@dreamy kernel Not simple. You would need a texture of the background. The trouble is, you can't draw to the same texture you're reading from (on most platforms)

dreamy kernel
#

I heard just now that I should use GrabPass, is that right?

low lichen
#

That's one way to do it. I think what that does it it copies the screen texture before rendering your object

#

But it's not very efficient at it, so it's probably the slowest way to do it

#

But the easiest

dreamy kernel
#

And I've heard the exact opposite

#

It's the hard way, but the most powerful one

low lichen
#

What's difficult about adding GrabPass { } to your shader?

dreamy kernel
#

idk

#

Welp, I hope GrabPass works for URP too

low lichen
#

It doesn't

#

But URP has it's own solution for that

#

I'm sure you can find it if you search "unity grabpass urp"

regal stag
#

URP has the Opaque Texture option to replace the grabpass. It basically outputs the camera texture after rendering opaque objects, so in a transparent shader you can get the texture. I believe it's more performant this way, but the down-side is that it only contains opaque stuff.

dreamy kernel
#

Thanks for the help

#

G'night erryone

timber ember
#

Wow so glad I caught this.

#

Wasn't sure why my transparents weren't looking right when overlapping.

meager pelican
#

transparents require blending, and usually sorting (unity does that part for you).

ornate sky
#

I'm having issues with some shaders in VR where the applied 2D texture acts as a billboard and follows the heads Z rotation (when you lean your head side to side). Now, I don't know much at all when it comes to shaders, but could someone point me in the right direction as to what piece of code determines it. I was thinking "viewDir", but not sure what to use instead there if that's the case.

deft frost
#

Hey, could someone help me out? I'm trying to figure out how to do Pixel perfect UV displacement. These pixels should not distort

cosmic prairie
#

round your UV value to the size of a pixel

deft frost
#

Ok. That works if I'm using a displacement map, right? [Kinda like the ones in Mario Galaxy]

crimson trail
#

i found some code for a shader i want to use, but I dont know how to import it into unity

devout quarry
#

@crimson trail what does the code look like?

crimson trail
#

there's the link

devout quarry
#

why not just copy the shader code into a .shader file?

crimson trail
#

ok i had to tell my computer to open the file with visual studio

#

now idk how to add it to a matriel , as i'm using URP

devout quarry
#

@crimson trail create a material, then select the Outlined/Custom shader from the shader dropdown

calm hollow
#

hey, how can I make a height map, and a roughness map in the unity shader graph?

hearty wasp
#

@calm hollow your question is a bit vague, can you clarify what you're trying to do exactly?

#

you should just be able to plug in anything black and white into roughness/height

calm hollow
#

well, I am in a urp render pipeline @hearty wasp

#

and the regular lit shader doesnt have that

hearty wasp
#

ah I've mostly worked with shadergraph in HDRP, let me check what the possibilities are in URP real quick

calm hollow
#

ok

hearty wasp
calm hollow
#

the pbr one

hearty wasp
#

smoothness = roughness, just the same except it's inversed

#

and for height, well you could use vertex displacement

calm hollow
#

ok

#

would I just put an image into the vertx displacement?

hearty wasp
#

a black and white image yeah, and your 3D model needs to have enough tris to be able to displace

calm hollow
#

ok

hearty wasp
#

there's other ways of displacement like a pixel parallax effect but urp doesn't have that out of the box I believe

#

so it's more complicated to make

calm hollow
#

alright then

meager pelican
#

@sinful shuttle I got some time to play with it.
IDK if this is what you wanted or not, so full disclaimer.

However this will nudge the verts toward the camera position as you requested. I think it can mess up shadows though, so watch for that. Anyway, try this in your Vert() function:
v.vertex += float4(normalize(ObjSpaceViewDir(v.vertex)) * _VertOffset, 0);

No warranties expressed or implied, use at own risk! ;)

That ObjSapceViewDir function is a helper function that gives you a vector to the camera relative to object space. So all it does is normalize it and scale it.

Worth a try to see what it does, I can't recreate your scene so...
Make sure you have the "addshadow" keyword in your #pragma Surface line.

calm hollow
#

@hearty wasp is there any other way of having a heightmap. I don't think i want to use vertex displacement because I want to keep my walls low poly.

hearty wasp
#

there's tessellation which basically adds more polys as your camera comes closer to the shader, and there's pixel parallax which is basically not really height but more of an illusion

#

but I couldn't tell you how to make those from scratch

#

HDRP has both of those out of the box though, in its standard hdrp lit material

calm hollow
#

ok

hearty wasp
#

idk what your project is or how far you're into it but if you really need high quality materials/visuals you may wanna try out hdrp

calm hollow
#

ok

hearty wasp
#

I can recommend just making a new hdrp project on the side and just doing a few art tests with the materials for whatever you're doing @calm hollow

calm hollow
#

yeah my project isnt gonna be looking that good. I just wanted to use a height map. My textures already look good with a normal map, but I just want a bit more detail, to make my models look really good.

hearty wasp
#

then you'll probably have to settle on what you have or go all in on making some sort of heightmap shader yourself, but that can be tricky

jovial onyx
#

I've been following @regal stag Non-Ecluiodean Shader Thread https://twitter.com/Cyanilux/status/1193513267534151680?s=20, first it's amazing πŸ’–, second if anyone can help me, I'm currently not understanding how to replace all pixels and not only the ones without anything besides

Hey! I made some impossible geometry! Not only is the interior different for each face... but there's also 5 of them!?

Stencil shaders are cool. βœ¨πŸ‘€
(see thread for a mini-breakdown)
#unity3D #madewithunity #shaders https://t.co/b0hKsDF5iI

Retweets

127

Likes

794

β–Ά Play video
#

This is the Shader

Shader "Custom/Stencil"
{
    Properties {
    [IntRange] _Stencil ("Stencil Ref", Range(0, 255)) = 0
    }
    SubShader {
        Tags { "RenderType"="Transparent" "Queue"="Geometry-10" }
        Pass {
            Stencil {
                Ref [_Stencil]
                Comp Always
                Pass Replace
            }
            ColorMask 0
            ZWrite Off
        }
    }
}
jovial onyx
#

Update: The problem is on the Forward renderer config, i'm trying to get the right configuration, Sincerely i don't know much about stencils and ZTests, but i'll try to get it right

fathom wharf
#

Hey guys. First, i am sorry if this isn't the place, but i am searching little help (i will pay the price of course) I am trying to implement some basic mechanic from tutorial i've seen. The thing is i've written the code, but the code is linked with some VFX shader graph and shaders that i cannot recreate (they are pretty simple, i just don't have the knowledge to make them, i've tried...) So if anyone is skilled in that i would like to get some paid help. Thanks ! (If my post violates the rules, i will delete it)

hearty wasp
#

@fathom wharf could you describe in more detail what you need?

fathom wharf
#

Yes, let me PM u

deft frost
hearty wasp
#

@deft frost looks great!

grand jolt
#

i need help altering this Kino streak shader.. it adds a horizontal flare to where the mesh shines.. i want to just rotate it slightly so it's diagonal or add two streaks.. tried some things with switching the X's to Y's in the code: https://github.com/keijiro/KinoStreak/blob/master/Assets/Kino/Streak/Shader/Streak.shader
but there might be a way to do it with the widths in the csharp controller: https://github.com/keijiro/KinoStreak/blob/master/Assets/Kino/Streak/Streak.cs
if anyone has input or could point me in the right direction.. would be deeply appreciated

hearty wasp
#

I have a bit of an issue of my own, it's my first time picking up water shaders again

#

and I just can't get the hang of edgefoam

#

what I attempted doesn't really work at all haha

regal stag
#

@hearty wasp The Screen Position node needs to be set to Raw mode in order to be able to access the w/alpha component properly

hearty wasp
#

ah honestly? could that be all I did wrong?

#

I'll try it out, one sec

#

@regal stag well that pretty much worked, thank you! Now I just gotta find the way to blend it

crimson trail
safe gate
#

how would i get fresnel to be around the edges of any shape, it works for a sphere but for a cube it's weird?

#

or is that like illegal or something

low lichen
#

@safe gate Yes, the fresnel police will be knocking on your door soon

safe gate
#

oh no

grand jolt
#

does anyone know like how those screenspace shaders are made? i don't understand the script at all.. with the uvs and stuff if anyone has links/resources to how to learn that please lmk

tranquil fern
#

@grand jolt What's a "screenspace shader"?

#

@safe gate Did you figure it out?

#

I had the same question a while back but I dropped it, so I'm curious πŸ˜„

low lichen
#

Fresnel doesn't allow you to do object outlines. It just happens to look like an outline for spheres.

tranquil fern
#

I can't understand why outlines are still a mystery in 2020

#

The unity editor uses them.

low lichen
#

It's more involved than what a single shader can do

tranquil fern
#

I have so many shader questions, it's insane. Is there some sort of master course I can follow?

low lichen
#

Unity renders outlined objects to a separate texture and blurs that texture before adding it back to the scene.

tranquil fern
#

That doesn't sound great for performance πŸ€”

low lichen
#

Certainly not for mobile

safe gate
#

nah i went to bed

tranquil fern
#

πŸ˜„

#

I thought your pfp was boobs. Well played.

safe gate
#

Fresnel doesn't allow you to do object outlines. It just happens to look like an outline for spheres.
oh

#

oh its just a flushed emoji

deft frost
#

I doubt there's any real well performing way of making object outlines other than either using some kind of image effect, or the Toon Outline shader pass

tranquil fern
#

What's a toon outline shader pass?

deft frost
#

Toon

tranquil fern
#

Yes, I made a typo πŸ˜„

deft frost
#

O

tranquil fern
#

Actually... Never mind. My real question is: where do I find a good course?

low lichen
tranquil fern
#

I don't mind paying

low lichen
#

This does outlines by drawing the object again, but a little bigger

tranquil fern
#

haha that's how I solved it the first time, but it looked weird in complex shapes

cosmic prairie
#

@deft frost doesn't look right to me yet

tranquil fern
#

My end goal is having an effect to dissolve objects as they hit the floor. Like the floor is a portal to nothingness, basically. To get there though, I need to know the path and I have no idea

cosmic prairie
#

did you do the following? add displacement to the UV, multiply the UV with the size of the texture in pixels, round it, then divide it with the size of the texture in pixels?

#

@deft frost

grand jolt
#

i need help altering this Kino streak shader.. it adds a horizontal flare to where the mesh shines.. i want to just rotate it slightly so it's diagonal or add two streaks.. tried some things with switching the X's to Y's in the code: https://github.com/keijiro/KinoStreak/blob/master/Assets/Kino/Streak/Shader/Streak.shader
but there might be a way to do it with the widths in the csharp controller: https://github.com/keijiro/KinoStreak/blob/master/Assets/Kino/Streak/Streak.cs
if anyone has input or could point me in the right direction.. would be deeply appreciated
@grand jolt @tranquil fern stuff like this not sureif i have the right terminology

tranquil fern
#

Can't I use coded shaders with URP at all anymore?

thick fulcrum
#

sure you can, just look at the unity ones or some examples around the net.

tranquil fern
#

But they're all pink πŸ˜„

meager pelican
#

@tranquil fern I've used some Udasity courses when I got a good deal on them. Also used Udemy. There's also kindle books.

Much of this stuff is on the web/youtube though. But sometimes it's fun to have a structured course if it's reasonably priced.

tranquil fern
#

Yeah but, any sources?

#

Anything I can get my hands on already?

sinful shuttle
#

I still need some help with a terrain shader that's supposed to stop a path mesh placed on a terrain from clipping through it in places.

Here's what I've got so far...

One person suggested the following:

   {
        v2f o;

        float zoffset = v.color.r; 
        o.pos = UnityObjectToClipPos(v.vertex);
        float3 cameravec = normalize(mul(unity_WorldToObject, float4 (_WorldSpaceCameraPos, 1.0)).xyz - v.vertex.xyz);
        float4 desiredpos = UnityObjectToClipPos(v.vertex + zoffset * float4(cameravec.xyz, 0.0));
        o.pos.z = desiredpos.z * o.pos.w / desiredpos.w;
                               
        return o;
    }```
#

But that didn't work. v2f wasn't found and o.pos wasn't found.
I then edited the code to try to get it to work, but the path simply disappeared unless I commented out the line actually adjusting the path positon. And this happened regardless of whether I set the z offet to 1, -1, 0, or anything in between:


               appdata_full o;
                        
               float zoffset = 0.1; 
               o.vertex = UnityObjectToClipPos(v.vertex);
               float3 cameravec = normalize(mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0)).xyz - v.vertex.xyz);
               float4 desiredpos = UnityObjectToClipPos(v.vertex + zoffset * float4(cameravec.xyz, 0.0));
               v.vertex.z = desiredpos.z * (o.vertex.w / desiredpos.w);            
               v.vertex.xyz = v.vertex.xyz + normalize(ObjSpaceViewDir(v.vertex)) * zoffset;
       
        }```
#

Then I tried this, which seems like it might be giving a similar result to using the Offset command that wasn't doing as good a job as I'd like because the path still had to be like 0.1 units above the terrain up close for it to work. At least, without normalizing the result. When trying to normalize it, it just broke and the path disappeared no matter the offset:


            appdata_full o;
                        
              float zoffset = .1; 
            
            //v.vertex.xyz = v.vertex.xyz + normalize(ObjSpaceViewDir(v.vertex)) * zoffset;
            v.vertex.xyz = v.vertex.xyz + ObjSpaceViewDir(v.vertex) * zoffset;

        }```
So now I'm wondering if perhaps pushing the vertices towards the camera a bit might not be the best approach? I'm thinking instead what if I were to move the vertices up along the Y axis, in world space, but do so more in the distance than up close? Or maybe I just screwed up all the math from the original suggestion because I could never get that to work unaltered and I'm not sure exactly what I'm doing.
thick fulcrum
#

@sinful shuttle I believe with the first example the mistake is in first line, try v2f vert (appdata_base v) it should then compile. If it yields the results you desire, I cannot say but worth a try.

sinful shuttle
#

@thick fulcrum Nope. That didn't compile. Complained about lack of v2f struct which I tried to add, then lack of inout, then color parameter, then pos...

            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };
            

            v2f vert (inout appdata_base v)
            {
                v2f o;

                float zoffset = 1; //v.color.r; 
                o.pos = UnityObjectToClipPos(v.vertex);
                float3 cameravec = normalize(mul(unity_WorldToObject, float4 (_WorldSpaceCameraPos, 1.0)).xyz - v.vertex.xyz);
                float4 desiredpos = UnityObjectToClipPos(v.vertex + zoffset * float4(cameravec.xyz, 0.0));
                o.pos.z = desiredpos.z * o.pos.w / desiredpos.w;
                               
                return o;
            }```
low lichen
#

void vert (inout appdata_full v) is how vertex shaders for surface shaders are defined

#

Are you making a surface shader?

sinful shuttle
#

Yes.

#

Still get an error on o.pos, which I assume is because it's not in the v2f struct but then again I don't know that that struct isn't adding onto some hidden struct which seems to be a thing in shaders from what I've read the last few days. In any case, I don't know what type pos is supposed to be.

low lichen
#

You don't define the v2f in a surface shader

sinful shuttle
#

Well without that struct I get "unexpected identifier o":

            {
                v2f o;

                float zoffset = 1; //v.color.r; 
                o.pos = UnityObjectToClipPos(v.vertex);
                float3 cameravec = normalize(mul(unity_WorldToObject, float4 (_WorldSpaceCameraPos, 1.0)).xyz - v.vertex.xyz);
                float4 desiredpos = UnityObjectToClipPos(v.vertex + zoffset * float4(cameravec.xyz, 0.0));
                o.pos.z = desiredpos.z * o.pos.w / desiredpos.w;
                               
                return o;
            }```
thick fulcrum
low lichen
#

I understand you don't have much experience in shaders, but do you also have little experience in programming in general?

#

Because you've defined a void function, but you're trying to return something in it

sinful shuttle
#

I have like 20 tabs open with various surface and vertex shader stuff.

#

So, yes. πŸ™‚

low lichen
#

Surface shaders give you limited access to extend the vertex shader

sinful shuttle
#

@low lichen "Because you've defined a void function, but you're trying to return something in it" -- I did that because you said "void vert (inout appdata_full v) is how vertex shaders for surface shaders are defined"

low lichen
#

So that should also tell you that the function shouldn't return anything

#

There's a inout parameter, which means you just modify that parameter

sinful shuttle
#

"So that should also tell you that the function shouldn't return anything"

Considering how many hidden variables seem to be involved in coding shaders, I can't take anything for granted. How do I know something isn't being overridden somehow?

#

"There's a inout parameter, which means you just modify that parameter" -- I didn't have inout before, and I didn't know what that did. I come from a C background where I'd pass pointers or references.

low lichen
#

Have you looked at examples of surface shader vertex functions?

sinful shuttle
#

Anyway to answer your question about my experience level I started coding games 25 years ago, but I'm a bit rusty on the coding part.

low lichen
#

https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

Shader "Example/Normal Extrusion" {
    Properties {
      _MainTex ("Texture", 2D) = "white" {}
      _Amount ("Extrusion Amount", Range(-1,1)) = 0.5
    }
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM
      #pragma surface surf Lambert vertex:vert
      struct Input {
          float2 uv_MainTex;
      };
      float _Amount;
      void vert (inout appdata_full v) {
          v.vertex.xyz += v.normal * _Amount;
      }
      sampler2D _MainTex;
      void surf (Input IN, inout SurfaceOutput o) {
          o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
      }
      ENDCG
    } 
    Fallback "Diffuse"
  }
sinful shuttle
#

"Have you looked at examples of surface shader vertex functions?" -- I already answered that question. Yes. I have 20 tabs open...

low lichen
#

Regular vertex shaders and surface shader vertex functions are separate things and it looks like you've been mixing them together

sinful shuttle
#

I've only just learned that this evening, but I do know surface shaders can modify vertices, I just don't know what limitations they have versus vertex specific shaders.

#

For example this works, though not how I want it to:


              float offset = 0.05; // How much to raise the decal one meter from the camera. 0.01 = 1cm
            
            // Calculate distance betweeen a vertex and the camera:
                // float dist = distance(_WorldSpaceCameraPos, mul(Object2World, v.vertex));
                // OR:
                // length(ObjSpaceViewDir(v.vertex));

            v.vertex.y = v.vertex.y + offset / length(ObjSpaceViewDir(v.vertex)); 

            //1 meter away = 1cm rise
            //10 meters away = 0.1 cm rise

        }```
#

I also tried this earlier: v.vertex.xyz = v.vertex.xyz + ObjSpaceViewDir(v.vertex) * zoffset; // Move vertex towards camera.

#

The code I was trying to get work earlier was something someone else suggested, but they have since said it will only work in a vertex shader. Why that is, I don't know.

low lichen
#

The limitation is that you can't change the vertex position after it has been converted to clip position. The generated surface shader would be doing something like this:

v2f surfVert(appdata v)
{
    v2f o;

    vert(v); // Calling your vertex function.

    o.pos = UnityObjectToClipPos(v.vertex);
    ...
}
#

You mean you wanted to get this working?

v2f o;

float zoffset = 1; //v.color.r; 
o.pos = UnityObjectToClipPos(v.vertex);
float3 cameravec = normalize(mul(unity_WorldToObject, float4 (_WorldSpaceCameraPos, 1.0)).xyz - v.vertex.xyz);
float4 desiredpos = UnityObjectToClipPos(v.vertex + zoffset * float4(cameravec.xyz, 0.0));
o.pos.z = desiredpos.z * o.pos.w / desiredpos.w;
               
return o;
sinful shuttle
#

I don't know what that means. And in my examples above, I can see the vertices are being moved on the screen by the surface shader.

#

Yes.

#

"The limitation is that you can't change the vertex position after it has been converted to clip position."

If that is true, why do I see the vertices moving, and why does the vert() function exist?

low lichen
#

You can change the vertex in its local space

#

That then gets passed to the rest of the surface shader, which then converts that to clip position

#

But that code above requires being able to convert to clip position and then do some more work

sinful shuttle
#

Okay but I'm confused about something...

#

If the surface shader is converting to clip positon, and if the code above requires me to convert to clip position and THEN do some work, then is the surface shader converting to clip space AFTER the code I've written for the shader runs, invisibly in the background?

low lichen
#

Select your shader asset in Unity and click "Show generated code" in the inspector

sinful shuttle
#

Cause that doesn't make a lot of sense to me. But it also doesn't make sense that if the conversion were happening before my code runs... that I could not then do whatever modification that vertex shader is doing since that needs to happen after that conversion anyway.

low lichen
#

That's the actual shader. The whole point of a surface shader vs a regular vert/frag shader is that it does most of the boilerplate work for you.

#

So the vertex and surface functions are just functions that the actual shader runs in between other stuff

#

If you wanted to, you could get the generated shader and duplicate it and modify it

#

But if you modify the original surface shader, you'd have to duplicate it and modify it again to get those changes.

#

Btw, I totally understand how this is confusing. There's definitely a lot of hidden magic around shaders, but more so with surface shaders.

sinful shuttle
#

"If you wanted to, you could get the generated shader and duplicate it and modify it"

I get that. And I see the code.

"But if you modify the original surface shader, you'd have to duplicate it and modify it again to get those changes."

But I I'm not sure I understand what you mean by this.

low lichen
#

Like if you decided to add the nofog keyword into the shader to disable fog, you'd have to do that to the original surface shader, let it generate the shader again with no fog calculations, then duplicate and make the same modifications as before.

sinful shuttle
#

Why couldn't I just edit that into the generated shader code? Does that one keyword generate a ton of new code that would make that infeasible I guess?

low lichen
#

One keyword might add hundreds of lines into the generated code

#

In theory, you could make those same modifications to the generated shader code

sinful shuttle
#

Cause I just noticed there's like a dozen copies of my comments and code in this giant shader it made, so something's going on there with optimization I think.

#

It also makes me wonder if to edit this generated shader I would have to duplicate my code in those dozens of locations to make it work.

low lichen
#

The generated code might have some redundant stuff in it that the compiler cleans up.

#

Is the surf function declared multiple times in the generated shader?

#

I thought that one was only declared once

sinful shuttle
#

Some? It's 38,000 lines... πŸ™‚

low lichen
#

Yeah...

sinful shuttle
#

Yea, multiple times.

low lichen
#

If your surf or vert functions are duplicated, you could probably get around that by writing it in a separate .cginc file and #include it in the original surface shader

#

The generated shader should also do that, so you can edit it in the .cginc file

sinful shuttle
#

Unfortunately, this is going way beyond what's worthwhile for me to make it so these terrain decals which represent paths on my terrain always render above it without seeing them floating quite obviously above the terrain. I'm just trying to make a Halloween map of a meadow for VRChat. I only have a month to do it, and I thought it would be nice to fix the River Auto Material's shaders so they work well in VR, because the floating is super obvious.

It's kind of absurd that it seems like no one has solved this problem. Or if they have, nobody's pointed me to any shaders or assets designed to solve this problem. I mean are having decals on terrain that look good in VR really something nobody in Unity land has tackled yet?

low lichen
#

I can't think of a simple way to fix it except just ensuring that the path mesh never intersects the terrain

#

Which is doable

sinful shuttle
#

I appreciate all your help though I have a much better understanding of surface and vertex shaders now.

low lichen
#

I guess the path mesh is generated by this R.A.M asset you're using?

sinful shuttle
#

"I can't think of a simple way to fix it except just ensuring that the path mesh never intersects the terrain"

Well that's the thing... the author of R.A.M. said that the path has to be offset from the terrain because the terrain changes shape in the distance. So to avoid clipping, its necessary. I could see how if I flew high above the terrain and looked down, that would be true, though being at ground level, clipping in the distance would be less obvious.

Nonetheless, his tool generated paths which float around .1 meter above the terrain in spots, and in other places, moving it down by even .05 units causes it to clip through, so I can't move it down at all... Unless I were to manually edit the terrain in all those locations which I was attempting not to have to do. Or I guess I could edit the path but I don't know if probuilder can edit these meshes and I haven't actually used the R.A.M tool yet to see about editing the splines though that would also be a bunch of work.

I guess I just looked at it and assumed it was a rendering bug, but maybe the heights were just generated poorly by the original tool or something.

#

Yes. RAM is for generating rivers, but it can also be used to create roads, which in this case, are actually two ruts side by side on a dirt road that is painted into the terrain in a meadow, and some paths through the woods.

#

You can see the clipping about 10m away there...

#

But elsewhere...

low lichen
#

Is the original shader for this path a surface shader?

sinful shuttle
#

Yes. It's a weird one.

thick fulcrum
#

maybe I'm missing something as I'm not following convo 100% but, why do you need a mesh path at all. Why not just paint onto terrain?

sinful shuttle
low lichen
#

You lose being able to control the direction of the texture

#

You couldn't have tire marks with a painted texture on the terrain

thick fulcrum
#

that's a fair comment, but I would just use "normal decal" to create illusion for example... but are screen space decals doable in VR?

sinful shuttle
#

The terrain already sort of has paths painted on it but the path material does stuff like make the edges darker...

#

Now is this the best way to do it? I don't know. But I don't really have time to fix it either since this is supposed to be a quick fun halloween thing for VRChat.

#

The rocks being bright white is some kinda issue with the lightmapping, maybe being too low res cause I had to lower it to like 2 texels per meter to render it in a reasonable amount of time. Still took a half hour with Bakery.

#

I'm probably gonna have to run magic light probes on this cause the light probes for this whole meadow aren't placed great. My leaf piles are bright when near the ground in many places:

#

And I tracked that issue down to them picking light probes that are far away instead of the ones up close because they're just outside of the tetrahedron of the ones up close.

#

But the bright white rocks are probably unrelated to that.

thick fulcrum
#

I think you might be too critical of it (we all do it), the people playing will probably not notice half the issues you do. I'm sure they will enjoy themselves regardless πŸ˜‰

#

but those rocks do stand out a bit, so agree they do need some attention.

sinful shuttle
#

It's hard to convey in still images how visible the offset is in VR. While its true nobody testing noticed it initially, once you see it its impossible to unsee. Depth perception makes graphic glitches like this really obvious. Plus I'll know its there!

low lichen
#

@sinful shuttle Do you have any realtime shadows in this scene?

sinful shuttle
#

Not at the moment, I don't think. The original scene used them, but it looked bad with no shadows rendering in the distance, and the performance wasn't great. I switched to fully baked light because I was having a hell of a time getting baked lighting to work at all let alone with shadow masks. Turned out I had lightmap static turned off on the terrain. But at that point I was just trying to get something working, so I had disabled shadow masks. So I think players don't even cast shadows on the terrain at this point. Anyway, the performance still isn't great though it is a lot faster with the baked shadows, so I'm gonna reduce the draw distance for the foliage and see how much that gets me, and then I'll try re-enabling dynamic shadow masks for stuff that's up close and see how that goes, though VRChat does not allow you to use distance based shadow masks, so presumably all that will get me is my players casting shadows on the terrain again, and not detailed shadows from the foliage, which I guess I'm okay with if it means I get 20fps more. Plus my tree shadows will be more detailed in the final version since I intend to render a full 4096 map for the terrain, so 4x as detailed at the shadows in the current screenshots. I hope I can snag a 3080 before I have to render that out!

dense willow
#

How do I switch between scenes in the UI?

#

Thanks for the awnser

low lichen
#

@dense willow What does this have to do with shaders?

tranquil zephyr
#

I have a shader that under some circumstances can filter out pixels of the object that is being rendered and set their transparency to 0 alpha. Is there a way to check via script if the object ended up being completely culled out due to being deemed entirely transparent if the transparency logic is handled by the shader?

#

The concrete case I'm working with: A shadowing system similar to the one in Among Us, where I use URP's 2D shadows to hide objects that are in the shadows created by the vision lights.
I can filter out the objects in the shadows, but want to be able to determine via code if the object is in the player's vision range or not.

low lichen
#

How simple it will be depends how the 2D shadows work in URP

#

If it's a mesh that is calculated on the CPU, then it's a little easier because then the CPU has some idea of what might be in shadow and what not

#

But if the shadow is calculated on the GPU, then the CPU has no idea. And since your scripts are run on the CPU, they can't find out either

tranquil zephyr
#

I'm not sure this is entirely relevant. The question can be simplified to "Can I check if all pixels of an object have an alpha of 0 after shading". I just gave the concrete example to explain what I'm after.

safe gate
#

uh im not sure but can't you just use a sprite mask for this?

low lichen
#

@tranquil zephyr I assume you want to check this in a script?

tranquil zephyr
#

But I get what you're saying. Since the filtering is calculated on the GPU, then I can't really get an answer, huh..

#

@low lichen Yes.

#

@safe gate A sprite mask wouldn't be able to handle the dynamic way the shadows are formed off of shadow casters in the scene. It'll only work for the visibility radius around the player.

safe gate
#

aight

#

oh yeah thats right

low lichen
#

I think it's very likely that URP 2D shadows are calculated on the CPU though

#

And it's generating a mesh

tranquil zephyr
#

@safe gate And even then you wouldn't really be able to tell if the sprite was filtered πŸ˜…

#

@low lichen Does it matter if they are though, given the sprite's pixels' fading and filtering is done on the GPU?
Do you mean the idea is to raycast the shadow mesh?

low lichen
#

No, I mean you could check if the given sprite bounds are entirely inside the shadow mesh

#

It wouldn't be completely accurate, because bounds are rectangles and your sprite is a circle

tranquil zephyr
#

That would probably work for simpler shapes, but the shadow's mesh can take on some pretty difficult shapes to work if we're talking about bounds, since they are rectangular.

low lichen
#

There is the option to do a GPU readback to get back some texture and read the pixels

#

But that's also slow

tranquil zephyr
#

Still curious though, how would you even get the mesh used for the shadows?

low lichen
#

I think checking the mesh is easier

#

There's a ShadowCaster2D component, right?

tranquil zephyr
#

Yea, but the shadows in a scene are constructed from multiple casters, not just one. Each wall is a caster basically.

low lichen
#

With a ShadowCasterGroup?

tranquil zephyr
#

Yea, I was thinking of duplicating the filtering logic into a compute shader, but that would require me to read the entire dataset every frame, so it's not very practical.

low lichen
#

What filtering logic?

tranquil zephyr
#

A ShadowCasterGroup will probably combine them into a single mesh, but even then I'm using multiple groups. One for each room, since the room creation is modular.

low lichen
#

I don't think it's combined. From looking at the code, it looks like it's generating a mesh for each ShadowCaster2D and drawing each of them

tranquil zephyr
#

What filtering logic?
@low lichen My shader compares each pixel's color before and after the light/shadow pass and cuts off any pixels that are being shaded under a certain threshold.

low lichen
#

So there's a shadow texture?

tranquil zephyr
#

No.

low lichen
#

It's combined into some light texture?

tranquil zephyr
#

Hold on

#

I modified the frag function of the Sprite-Lit shader that comes with URP to this:

#

The CombinedShapeLightShared() function call is the line that applies shadows to the pixel. All I'm doing is taking the pixel before calling this function on it, and after it, and comparing them to tell if the pixel is shaded.

#

lightMultiplier is a value that indicates the difference factor between the lit and unlit pixels.
Under a certain cutoff value I just filter it out completely, making it transparent.

#

So as I mentioned before, the lights aren't really directly involved with this, as I could just as well replaced the frag with a function that always returns 0 alpha, making a sprite fully transparent at all times, and my question would still be the same: Is it possible to check if no pixels were actually rendered for this sprite.
Which I'm leaning towards thinking the answer to is no.

low lichen
#

No, it's not possible

#

The CPU doesn't have any idea what picture the GPU has generated

#

It's calculated on the GPU and goes straight to the display

tranquil zephyr
#

Yea. Figures.

#

By the way, I didn't actually check this out before, but by the script reference you linked for the shadow casters, it looks like they're incredibly unperformant, huh?

low lichen
#

How so?

tranquil zephyr
#

Haven't actually read the code, or done any profiling, but I would just imagine that having the entire system be based on scripts that are using Update to handle changes to the shape on each shadow caster, rather than a GPU based solution, would not end up scaling very well for large numbers of shadow casters in a scene.

#

Even moreso when said Update method calls GetComponent every frame for every caster.

low lichen
#

A CPU approach is probably better supported on mobile, which I'm sure they are targetting with this

tranquil zephyr
#

Probably, but mobile is also the most susceptible to these kinds of performance issues.

meager pelican
#

I still need some help with a terrain shader that's supposed to stop a path mesh placed on a terrain from clipping through it in places.

Here's what I've got so far...

One person suggested the following:

   {
        v2f o;

        float zoffset = v.color.r; 
        o.pos = UnityObjectToClipPos(v.vertex);
        float3 cameravec = normalize(mul(unity_WorldToObject, float4 (_WorldSpaceCameraPos, 1.0)).xyz - v.vertex.xyz);
        float4 desiredpos = UnityObjectToClipPos(v.vertex + zoffset * float4(cameravec.xyz, 0.0));
        o.pos.z = desiredpos.z * o.pos.w / desiredpos.w;
                               
        return o;
    }```

@sinful shuttle
I gave you one example above that works (I got a chance to mess with it) and I @'ed you I think yesterday.
Here's a reference to it.
It does what you asked for, but maybe not what you want. πŸ˜‰

#

That one line of code will move verts toward the camera position. It does it in object space.

#

I can't tell you if it works with R.A.M. or whatever custom shaders though, that's you programming/testing. I can't duplicate it.

crimson trail
low lichen
#

@crimson trail You want to make a shader that generates an image like the one above?

crimson trail
#

yeah kinda , and it will change like perlin noise to different colors and shapes

low lichen
#

Where did you get that image?

sacred ether
#

do you want the distinct blobs more or the gradient edges?

crimson trail
#

yeah like this , but with the perlin noise blobs

#

so it all blende in nicely

low lichen
crimson trail
#

no

low lichen
#

Looks like the source of your image

#

With C source code

crimson trail
#

its not really the effect i'm trying to get

low lichen
#

It's literally the reference picture you gave, I don't see how I can get any closer than that πŸ˜…

sacred ether
#

if you wanna just try it for your self to start, you can sample a perlin noise and assign different colors to different ranges, i.e. [0.0, 0.25] is red, (0.25, 0.5] is green, etc.

crimson trail
#

I couldn't find a better refence image
so just used that

#

@sacred ether
I'll try that, and see how it gos

#

go's

hearty wasp
#

sorry to pop in randomly in the middle of this but I have a little issue with my triplanar UV effect, it works fine but it looks like it's slightly slanted when I enable it for some reason?

regal stag
#

Usually when doing triplanar you don't add the UVs together like that. You sample the texture/noise 3 times, each with the separate uvs then blend the results together based on the normal vector.

hearty wasp
#

hm I see, going to have to think about it for a moment then in relation to using the subgraph and the branch to turn it on & off

faint notch
#

As far as i can see my NdotH is correct here, I am trying to add specular reflection

#

Next I multiply by NdotL and then feed it into Pow

crimson trail
#

I have no idea , how to use the pbr graph

anyone know a good tutorial on it

faint notch
#

How are you guys adding specular light to your custom toon shaders in Shadergraph?

hearty wasp
#

@regal stag I think I've figured it out based on your advice, thank you!

regal stag
#

@faint notch That looks correct to me. I don't think you want to multiply that with the NdotL though. I think you just need to put it into the Pow then add it with the NdotL/diffuse.

faint notch
#

@regal stag ah, thanks ill try that - i thought Id add it with ndotl to make sure i would only get specular reflections on actual side where there is light

crimson trail
#

how do i update Gradient noise in PBR graph

amber saffron
#

"update" like, make it animate ?

crimson trail
#

yeah

amber saffron
#

Animate the UVs

sacred ether
#

softball question since i'm coming back to a project i havent touched in a while:

I'm generating 2D images based off heightmaps that subdivides it into 4 height regions, then marks the edges. So, an edge is drawn in black on the right between heights less than 0.25 and greater than 0.25, and so on for 0.5 and 0.75. Basically just drawing a line.

#

i've explored some SDF rendering, but have been unable to derive quality SDF fields from the edge-detected image. Here's an SDF derived from the original heightmap. It has the smooth lines I want, but is pretty inaccurate to the height

#

question being: how should I best smooth out the pixely image at the top?

low lichen
#

@sacred ether I think the answer is derivatives.

amber saffron
#

I would directly sample the heightmap in the shader to draw the lines then.
If you think of it, a heightmap is already a distance field (it represents the vertical distance to the 0 level).
So with some easy maths in the shader, you should be able to get the lines you want

sacred ether
#

yeah, i had an implementation that was basically sampling values from the heightmap and transforming them into some distance away from a "band" height, e.g. 0.25, 0.5, 0.75, but that led to some pretty wonky blobs i believe. I can revisit that.

@low lichen what exactly do you mean?

low lichen
faint notch
#

@regal stag worked fine, i had to use high values though for my pow though.

sacred ether
#

ah ok, i get it now. thanks both! will work on this lol

faint notch
crimson trail
#

ok , everything I find on animated uv's is in script
and I want to use the pbr graph
Here's what i have so far , it just moves

amber saffron
#

Yes, well, that's how you animate the UVs, and indeed it moves the noise. So it animates it.

crimson trail
amber saffron
#

Yes, you can clearly see the shapes all going in the same direction

low lichen
#

The camera isn't moving in that video

amber saffron
#

If you want a noise applied to UV space that animates without moving, you will need a 3D noise (2 dimensions for projection, and one dimension for time)

low lichen
#

You can keep your eye on one sphere and see it's just moving up and down

amber saffron
#

But the noise that positions the sphere is moving in the video

crimson trail
#

ok , so how do I randomly color this noise

amber saffron
#

You can use a gradient ramp (that use the grey value to sample in a gradient)

#

But I guess it's not what you're looking for

#

Or use 3 noises with different coordinates to build the RGB color

#

One noise per color channel

crimson trail
#

I can use a lerp to combine them right?

amber saffron
#

technically, yes, but you just have to input them in a vector3 node

crimson trail
#

ok by default thay are all 255 , now I need to get a color node to change over time

#

damn , it actually worked

#

now I need to get a constantly changing seed

hearty wasp
#

is it possible to control a HDR intensity with a vector instead of the built-in intensity?

low lichen
#

@hearty wasp Do you care if the vector scales it exactly the same way, the same curve?

#

If not, you could just multiply the color with a vector property

#

I think that Intensity slider has some gamma curve on it or something, so it's not completely linear

novel summit
#

What is shader tag queue?

peak pawn
#

Is it normal to have such drastic changes between previews when using shader graph and if not what could be causing this?

hearty wasp
#

@hearty wasp Do you care if the vector scales it exactly the same way, the same curve?
@low lichen I'll try it out, thanks

hearty wasp
#

that works just fine for now, that was simpler than I thought haha

tranquil fern
thick fulcrum
#

they don't emit light per say... but an unlit shader can still receive lighting information and can be used for custom style lighting. You can use a custom function to achieve this

meager pelican
#

@tranquil fern Not weird, it's a way to get the alpha isolated. You don't really need the Vector3 node, as it will just truncate the vector4 to a vector3 if you drag the Color(4) to the Color(3). IIRC.

tranquil fern
#

Thanks!

#

Yeah that seems to work

trail dirge
#

Guys, what do you to apply shader to object? Do you moderate cam?

tranquil fern
#

I do not understand the question

#

You make a material and assign the shader to the material and the material to the object

#

If.. That's what you mean

trail dirge
#

Yeah, this making my objects white(

tranquil fern
#

That sounds like emission set to white at an intensity that's too great. But I'm a beginner so I might be wrong.

twilit elbow
#

Hey guys,
is it difficulty to write a sorting feature for a urp shader so unity stops fuckingup the render order in prefabs with transparency? i either have to do that or learn how the lighting stuff in hdrp works ._.

tranquil fern
#

Is it hdrp or urp? You mentioned both

trail dirge
#

Hmm, can this be happening with default Unity shaders, @tranquil fern ?

twilit elbow
#

urp. hdrp has this by default

tranquil fern
#

@trail dirge I don't think so. When I create a shader and create a material that uses it I don't see just white

#

What kind did you make? (shader I mean)

twilit elbow
#

which is why i would have to stick to hdrp if i can't get it done in urp

trail dirge
#

I do not even create shader

#

Cause I even can`t)

tranquil fern
#

Can you phrase your question properly then πŸ˜…

#

Because I have no idea what you have/expect to be honest

twilit elbow
#

do you mean me @tranquil fern ? i think here are two conversations going on right now^^

tranquil fern
#

No, this was for @trail dirge

twilit elbow
#

ok^^

trail dirge
#

It is too hard to explain my problem((

tranquil fern
#

@twilit elbow I don't think I can help you though, it seems a bit too complex for me. I didn't even know sorting was a thing

#

@trail dirge You're going to have to try, I think the mind reader on this discord is currently on holiday

twilit elbow
tranquil fern
trail dirge
#

I am trying to try some ways to do something looking like good shader) One minute

twilit elbow
#

xD

regal stag
#

@twilit elbow Why does that even need to be transparent? Couldn't it just be opaque?

trail dirge
#

How does shader field call in Materials?

#

Aaa

#

Found_

twilit elbow
#

foliage in opaque looks horrible. i use transparency to make the leaves round

remote mauve
#

I'm trying to use my own material/shader for UI Raw Image, how does it determine render order?

twilit elbow
#

uhm

remote mauve
#

Do I need to specifically set Render Queue or do something else to make it work?

twilit elbow
#

ooookey i switched it to opaque and i am confused.^^ i thought it needs to be transparent to get the alpha but it seems like it doesn't?

regal stag
#

It would need to be transparent to use alpha blending. But you can do alpha clipping/cutout with opaque shaders still

trail dirge
#

@tranquil fern What shader is working? I`ll try to use that

twilit elbow
#

ooooh

#

i had no idea Cyan D:

#

Thank you @regal stag ^^

hearty wasp
#

I'm trying to make the offset go into the same direction

#

I've tried a few things but I'm probably just overlooking what needs to go inbetween to make the offset go the opposite direction

regal stag
#

Negate (or Multiplying by -1) should reverse the direction it moves

hearty wasp
#

huh? I tried multiplying by -1 actually

#

and it just made it completely black

#

I'll try again, maybe I screwed something else up that moment

#

right, the preview does turn black so I just assumed it didn't work but in the scene it does work

#

@regal stag again, thanks!

regal stag
#

The preview in the Tiling And Offset node will turn black, but I'd assume the Voronoi one should be fine still

hearty wasp
#

mhm, yeah, it was just me not paying enough attention

#

@regal stag could I dm you about something? it's not about asking more help with shaders lol

meager pelican
#

I'm trying to make the offset go into the same direction
@hearty wasp
There is no "same direction" from UV offsets on a cube. You'll have to calc those offsets in some form of worldspace "flow" vector. Otherwise, there will always be some corner that "flows wrong" from a UV mapping perspective.

I think.

You want a flow map. :2cents:

hearty wasp
#

I see what you mean, but this shader currently doesn't really need that yet

#

plus I'm not really familiar with flowmaps, figuring those out is for another day lol

#

thanks for the suggestion tho!

celest lance
#

trying to create a basic shader that creates a black outline around entities and ive run into an issue where anything rendered behind doesnt render

#

what it looks like in scene view (as you can see they are up-right rather than being flat on the ground, this is due to how the camera is set to render)

shell ice
#

Im a complete beginner in shaders and im just having a hard time understanding this block of code if someone can explain it to me

#
Shader "Custom/Fade" {
    Properties{
        _Blend("Blend", Range(0, 1)) = 0.0
        _BaseTexture("Base Texture", 2D) = "white" {}
        _OverlayTexture("Texture 2 with alpha", 2D) = "white" {}

    }
        SubShader{
                Pass {
                    SetTexture[_BaseTexture]
                    SetTexture[_OverlayTexture] {
                        ConstantColor(0,0,0,[_Blend])
                        combine texture Lerp(constant) previous
                    }
                }
    }
}```
#

so its just a shader that blends the texture from BaseTexture to OverlayTexture

#

im having a hard time understanding whats going on within Pass {}

#

Also when does the contents within "Pass" get executed?

#

I think I get it?

#

if someone can clarify what im about to say

#

Im assuming the first SetTexture overlays the texture on top of the sprite, then the second SetTexture does as well with set parameters?

#

then combine texture Lerp(constant) previous interpolates between texture and previous according to, using constant which is the alpha?

vocal narwhal
#

I'm pretty sure that's surface shader syntax, which I have absolutely no experience with. It was a version of shader coding that attempted to remove boilerplate

shell ice
#

ah is that the case?

#

might have to do more digging then

vocal narwhal
shell ice
#

ill prolly have to find an updated guide or something

#

thanks btw

amber saffron
#

@celest lance I think this is caused by transparent sorting and depth write.
When set to transparent render queue, objects are sorted from back to front, but usually don't write depth. In your case, the spider is drawn first, the whole quad writes to the depth buffer, and prevents the character pixels to be displayed.
Looking at the visual style, if you don't need alpha blended transparency, I'd suggest to use the "AlphaTest" renderqueue, and clip the fully transparent pixels of the objects. Look at the clip HLSL command.

crimson trail
#

I have this Voroni sahder moving , and was wondering how would I color the cells , and not the outlines

vocal narwhal
#

One minus it before adding color

crimson trail
#

that worked thanks

crimson trail
#

how would I make every cell of a voroni cell different colors ?

void bobcat
#

I want to draw literal uniform tiles on top of a Unity terrain. How would I go about this? I can't seem to find resources on how to do it. It's mostly just how to blend materials together on a terrain

glad siren
#

@void bobcat I think the default terrain has that, look how it's done, it has a checkered pattern

void bobcat
#

It's a checkered pattern yes, but it's not exactly what I'd want to do I guess.

#

I'd like to be able to draw tiles that kind of seem like they float slightly above the tile they are over and are slightly smaller than the tile they'd be over

#

So perhaps it's more about making verticies that represents meshes?

glad siren
void bobcat
#

I'll check it out

#

thanks @glad siren

glad siren
#

@void bobcat np, I put timestamps for the 2 parts which may be usefull, the 2nd link shows the effect in action, where each hexagon is controlled individually

void bobcat
#

cool

glad siren
#

Hey guys, this might seem like a basic thing, but I've had a hard time finding coherent info.

I made a dissolve shader with Shader Graph, it's cool works great; the problem is, how do I apply it to an existing object with an exisiting shader, like URP Lit Shader, but make it dissolve ?

I tried making a Texture2D parameter on my shader and using the object Texture (input by hand), which works, but excluding the dissolve, the shader makes the object look really different vs URP Lit shader.

Is there a way to apply my Dissolve to an Object without modifying it's native Texture/Shader ? Like just Adding it on top

crimson trail
#

@glad siren here , I think increase the size to two , then you'll be able to add both

glad siren
#

@crimson trail Yeah, no, I don't think that it works like that, since 1 shader will say this pixel needs to be rendered like this, and the other one will say, this pixel needs to be Transparent, and they will override each other; maybe there is a way to configure it and use this setup to make it work, but I'm going to need additional guidance, because I was not able to make it work on my own.

kind juniper
#

I see many examples only of people using RenderTexture to pass a texture to a compute shader and some examples of Texture2D instead. Is there any difference? Should I prefer using one over the other?

low lichen
#

@kind juniper If you don't need to render to it, then you can definitely use Texture2D instead

kind juniper
#

no, I want to pass in generated noise map and read from it. Is it a bad idea? Should I use an array of float2 or something instead?

low lichen
#

@kind juniper You just need to make sure you upload the texture to the GPU by calling texture.Apply() if you're making it from script

#

It shouldn't be any slower at using regular textures. If anything, I would think it would be slower to use render textures.

kind juniper
#

I see. Thanks!

#

texture.apply though. Do you mean that I need to call that when I fill the color array of the texture?

low lichen
#

Whenever you're modifying the texture in a script, you're just changing it on the CPU side. Apply() uploads the new data to the GPU.

meager pelican
#

@glad siren Convert a UPR lit shader into a dissolve shader.

#

I'm assuming you started with unlit.

#

And that's why they look so different.

#

You need lighting/shadow passes.

#

You MIGHT just be able to swap out the master node.

thick fulcrum
#

@void bobcat another way would be a projection decal, I use one large cube with tiled texture. Performance wise you don't even notice it, Ideally it would be nice to have it exclude certain layers so it just projects on to terrain assets. That part is on my todo list, but I believe you can purchase some assets with this feature built in.

sly breach
#
what is SV_InstanceID ?
kind juniper
#

Whenever you're modifying the texture in a script, you're just changing it on the CPU side. Apply() uploads the new data to the GPU.
@low lichen wait, is it not uploaded when I assign it to a shader? oO

#

If uploaded once, does it stay there? And calling texture.Apply() applies changes to it?

low lichen
#

@kind juniper Maybe Unity does it for you, but I don't think so

kind juniper
#

I'm specifically talking about compute shader. I'm not sure if that's different for regular shaders...

low lichen
#

There's always two copies of the texture, because the CPU and GPU have separate memories

#

If you're modifying it on the CPU, you need to manually sync it with Apply()

kind juniper
#

Yeah, that's what I thought. Thanks!

low lichen
#

@sly breach If you're doing an instanced draw, then SV_InstanceID is the index of the current object being drawn

sly breach
#

how is it sorted ?

#

if i want to use a buffer as a 3d grid

#

something like:

Buffer [ x + WIDTH * ( y + DEPTH * z ) ] # Buffer [ x, y, z ]
low lichen
#

@sly breach Are you drawing it manually with Graphics.DrawMeshInstanced or similar?

#

Or are you letting Unity batch it for you?

sly breach
#

trying to get grid based simulation going on with compute shaders

low lichen
#

@sly breach So you're trying to use the SV_InstanceID in a compute shader?

sly breach
#

i think so

#

still wrapping my head around this topic

low lichen
#

I don't know if that's going to be set to anything useful there

#

You have the uint3 id : SV_DispatchThreadID

sly breach
#

ye and this one is inside a standard shader

#

to visualize the forces

#

but it's used for debugging only

low lichen
#

To visualize a 3D grid? How are you going to do that with 2D pixels?

#

Do you want to draw a mesh for each cell in the grid?

sly breach
#

one sec

#
particleMaterial.SetPass(0); //send the buffer to the material
particleMaterial.SetBuffer("particleBuffer", particleBuffer);
Graphics.DrawProceduralNow(MeshTopology.Points, 1, particleCount);
low lichen
#

If it's just a point, then you should be able to use SV_VertexID

glad siren
#

@meager pelican You are Right, the default shader is URP Simple Lit, and I go to a From Scratch PBR Graph Dissolve shader I made, and the lighting is missing; I didn't quite understand the steps I need to take though.

glad siren
#

@meager pelican I am using a PBR Master in my dissolve and not a Unlit Master though, so I don't really see what I should be doing

#

Simple Lit (Left) / Dissolve (Right)
There is quite a color difference, how can I maintain the Simple Lit colors but add my dissolving effect ?

meager pelican
#

Wait....

#

You want it simple-lit?
Then don't use the PBR node, that's for full physically-based rendering.
But the problem is there's no "simple lit" master node yet. It's on their to-do list.
So it's hard to create one in SG, you'll need custom lighting information and try to reproduce the lighting calcs. The DO publish shader source somewhere.
I just haven't done it, so I can't just post some graph/code for you.

Maybe @empty oar knows something.
There are assets on the asset store, but Unity will do it eventually. Here's a thread on it:
https://forum.unity.com/threads/shadergraph-lw-how-to-create-a-simple-lit-graph.575578/page-2

#

You might be able to get away with blinn-phong calcs (google it) but you'll need to pass in light directions or get them from the custom node.

glad siren
#

@meager pelican THanks, I don't actually care what it is, I was just experimenting on Unity Kyle which was Simple lit. What I actually want, is to be able to apply my Shaders, without screwing up the original object/render

meager pelican
#

You can't. πŸ˜‰ 😦

glad siren
#

Haha RIP at least it's clear πŸ˜„

meager pelican
#

The shaders you use would have to be aware of each other.

glad siren
#

Why not? Β―_(ツ)_/Β―

meager pelican
#

Otherwise, like you say above, how would one know about the transparent parts of the other?
I think you already surmised this.

glad siren
#

Yeah but I'm still novice on Shaders, so I never know if I'm out of the loop on something

meager pelican
#

The only think you could hope for is that whatever shader you used honored a mask, and then mask off the "holes" as you dissolve things. But usually, they won't.

glad siren
#

so in the case of Unity Kyle, I'd have to be in HDRP which has Lit Master Nodes to get the exact effect, right ?

meager pelican
#

IDK, haven't tried whatever Unity Kyle is.

glad siren
#

It's the robot man

meager pelican
#

You CAN swap materials though. So you'd only need the dissolve mat when dissolving.

#

πŸ˜‰

glad siren
meager pelican
#

No you don't have to be in HDRP, unless you want to. I mean, you have a shader feature problem, regardless of pipleline.

glad siren
#

Or is there a way to have the Dissolve effect without having to specify the base texture ?

meager pelican
#

Sure, but it's not lit the same.

#

Look, we're talking about several things at once.

#
  1. How it's lit (colors normally).
#
  1. A dissolve effect
glad siren
#

Yeah, forget the color now

meager pelican
#

Well, then just swap out the material for the dissolve material and start vanishing him.

#

If you don't care about colors.

glad siren
#

Yeah it already does

#

But I'm passing the Texture2D as parameter to the shader

#

Can I not use the Mesh Renderer's Material as parameter ?

meager pelican
#

Materials are shaders.

#

So you don't use a shader as a parameter to another shader

#

Basically, shader + settings = material.

#

but you can swap them out, or you can "stack" them with multiple-materials.

#

Like you said above, though, stacking won't work in this case.

glad siren
#

Yeah so let me just re-phrase, for my Dissolve Mat, I need to pass as a parameter the texture it will dissolve, so if I have 5 different characters, I'll have 5 differents mats, one for each character, which each refer to their appropriate Texture, I will now have 10 mats, 5 dissolve and 5 normal ones, and if I want to dissolve these units, i'll have to go to each and everyone, and swap their current material for the diffuse material, i'm getting this right ?

meager pelican
#

That's one way IF you insist on using some "stock" shader for the non-dissolve mats.

#

But

#

The other way is to use your dissolve shader for the whole thing, then you'd only need 5.

#

BUT, you'll have to duplicate the style you want in SG.

#

There's no Simple-Lit master node yet.

glad siren
#

Do you mean like, having the shader always active, but at like, 0, and when I want to dissolve I push the alpha to 1 ?

meager pelican
#

Or however it works. Most have some slider for "dissolve amount". YMMV

#

So you basically have made your own custom shader materials that are "dissolve aware".

glad siren
#

hmm, okay, but this feels really repetitive no ? like either I make 1 extremely complex shader with parameters to be capable of doing multiple effect, or I create mountains of materials to swap out ?

#

I can only feel I'm missing something

#

this doesn't feel right

meager pelican
#

OK, well maybe others will have more ideas. ;)
My inclination is to say "Welcome to shaders". πŸ™‚

glad siren
#

Haha you've been really helpful @meager pelican, I just feel like I'm not grasping something correctly

meager pelican
#

Well, I hope there's a simple-lit node soon. That would make your life easier. But I think you'll end up rolling your own shaders for now.

What you COULD do, if you're really adventurous and have programming experience but no shader experience, is copy the simple-lit shader source code and edit it by hand to make a simple-lit-dissolve.

But you can't do that in SG.

remote mauve
#

Where is the source code of URP default UI shader?

meager pelican
remote mauve
#

Oof, I'm trying to modify it to incorporate bilinear interpolation for quads into UI, but it seems a bit more complicated than I thought.

marsh turret
#

has anyone got any expereince of recreating the terrain shaders in the shadergraph?

glad siren
#

Any good ressource on Shaders usage/workflow with unity ? Nothing Shader-code related or such ?

glad siren
#

@meager pelican Hey, I'm going to ask again sorry, but for my dissolve, if I want 10 different edge colors, I need 10 different Mat's in the end right ? I haven't found a way to only store 1 and be able to modify it at runtime, without affecting all the others; would I need to make a copy of the material at runtime, and the change it's parameters ?

#

I really hate the idea of duplicating stuff

amber saffron
#

Either this, or use material property blocks

glad siren
#

@amber saffron didn't know of those, will look into it ! ty

meager pelican
#

Yeah, MPB's are per-instance variables to do what you're asking about...to change a color or something uniquely per instance, while not having to duplicate the material.

It can mess up SRP batcher though, somehow, so watch if your batches get messed up. But otherwise they're great. Needs code on the C# side, and your shader has to support it, so SG may or may not do that, it depends IIRC on the variable. If you use _BaseColor I think it is supported for instancing.

#

Another alternative, if you want to do it "by mesh" is to stash some value into mesh attributes, but that's a bit of overkill since you often have to do that per vertex. Like using vertex colors.

I wish unity had some user-variable, like a INT or float4, that's just per mesh that we could get our hands on somehow. IDK how they'd pass that in, but they manage to pass other stuff in...
Then we could set our own unique ID's and a CBUFFER and be done with it.

dreamy kernel
#

God I hate it

#

Why when I sample depth texture, convert values to linear and then use them to apply fog, rotating camera makes fog thinner/thicker?

#

More specifically, when a fragment is seen in screen corner - my shader thinks that my distance to has decreased compared to when I look straight at it

meager pelican
#

?

dreamy kernel
#

Thanks

#

So.. Depth texture doesn't represent actual distance to stuff, huh

dreamy kernel
#

Okay, I figured it out

#

I had to divide my linear depth by dot(pixelDirection, cameraDirection)

remote mauve
#

Does anyone know why TEXCOORD1 doesn't work?

#

My shader has only one texture, but I need two sets of UVs, when doing mesh.SetUVs(0, ...) and taking values from TEXCOORD0 it works, but not for channel 1.

#

Normal and tangent as well.

remote mauve
#

Context for the question above:

I'm overwriting MaskableGraphic.OnPopulateMesh(VertexHelper vh) which generates my own mesh, while things like position/color/uv0 of vertices work, I can't seem to get uv1/uv2/uv3/normal/tangent to work.

meager pelican
#

What pipeline?

remote mauve
#

Just standard for the test project.

meager pelican
#

OK, so your shaders will have to assign the UV's to the texcoord's. You'll need to show source so we can help. If long, pastebin, but you can maybe get away with a short segment.

#

The names in the struct have to begin with uv...and unity will figure it out. Like uvMaintex or uv2Maintex IIRC.

remote mauve
#

Oh huh

#

I don't name them like that, I'll give it a try.

meager pelican
#

It's a Shader Lab thing.

#

There's an underscore (looked it up in shader examples):

     float2 uv_MainTex;
};```
#

And then in v2f you can call it whatever you want, but you assign it to interpolators:

....
float2 uv0 : TEXCOORD0
...
}
remote mauve
#

Hmm, doesn't seem to work, here's my shader

struct appdata {
    float4 pos      : POSITION;
    float2 uv_Data  : TEXCOORD0;
    float2 uv2_Data : TEXCOORD1;
};

struct v2f {
    float4 pos   : SV_POSITION;
    float3 color : COLOR0;
};

v2f vert (appdata v) {
    v2f o;
    o.pos = UnityObjectToClipPos(v.pos);
    o.color = float3(v.uv2_Data, 0.);
    return o;
}

fixed4 frag (v2f i) : SV_Target {
    return fixed4(i.color, 1.);
}
meager pelican
#

It needs to know what sampler/texture I think.
Is your texture name "Data" in properties?

#

Or in the sampler declaration?

#

Also remember UV sets start at 0

remote mauve
#

sampler2D_float _MainTex;

meager pelican
#

Use uv_MainTex

remote mauve
#

Nope.

#
protected override void OnPopulateMesh(VertexHelper vh) {
    var v = new[] {
        // ...
    };

    vh.Clear();

    vh.AddVert(new UIVertex { position = v[0], uv1 = test });
    vh.AddVert(new UIVertex { position = v[1], uv1 = test });
    vh.AddVert(new UIVertex { position = v[2], uv1 = test });
    vh.AddVert(new UIVertex { position = v[3], uv1 = test });

    vh.AddTriangle(0, 1, 2);
    vh.AddTriangle(2, 3, 0);
}
#

If I use uv0 and change shader to take value from uv_MainTex it works fine

#

But if I use uv1 and uv2_MainTex it outputs black.

meager pelican
#

What's test set to?

remote mauve
#

Inspector, between 0 and 1

#

Is this a problem specific to standard pipeline?

#

I'm only using standard in the test project, but production uses URP.

meager pelican
#

URP is going to be different.

#

OK

#

Give it a hard coded uv0, and a normal and tangent just to ensure you're getting the proper overload and it's working.

I haven't used that function before, so IDK.

#

You say if you use uv0 it works?

remote mauve
#

Yep position/color/uv0 works fine, only uv1/uv2/uv3/tangent/normal don't work.

meager pelican
#

Now there is nothing in those functions for uv2, it only has params for uv0 and uv1

remote mauve
#

Yeah uv2 and uv3 not working is to be expected

meager pelican
#

BRB, AFK for a couple min, RL in the way....

remote mauve
#

But I have no idea why uv1/tangent/normal don't.

meager pelican
#

IDK either, maybe it's a UI system/mesh thing. On NORMAL mesh stuff, you can set multiple uv array sets. And then use uv_MainTex, uv1_MainTex...as input, then assign them in the vert() passing them in interpolated v2f struct.

remote mauve
#

Welp, I tried a regular mesh and it works just fine.

meager pelican
#

Yeah... IDK man, sorry.

remote mauve
#

All good, appreciate the help.

#

UI probably does something to the rendering but wow, this is kind of ridiculous.

meager pelican
remote mauve
#

I did some searches on that and that seems to be what people are talking about

#

But disregarding that for a second, normal and tangent don't work either.

#

I tried using normal on a normal mesh and it works fine, but the same wouldn't work for custom populated UI mesh.

meager pelican
#

Try passing it in "custom data" like that post says in case the shader compiler is stripping it out for some damn reason. OR, maybe check the generated code.

#

I've had situations (not this one) where code I thought would be in was stripped. And had to make sure I used a preprocessor directive to get it included.

remote mauve
#

I think it looks right?

meager pelican
#

See normal, but not uv's.
Anyway, not that damn thing, the other one. πŸ˜‰

#

The generated source, not the compiled source.

remote mauve
#

Oh I'm not doing uv1 anymore, I'm doing normal instead.

#

Is it really due to the shader?

meager pelican
#

OK, and you assigned the proper normals in your mesh gen....

remote mauve
meager pelican
#

IDK. I hate UI shaders. :p

remote mauve
#

Here I have both the UI mesh (black smaller square) and normal mesh (bigger square)

#

Both using the same material, and UI mesh can't read the normals I passed to it (shows black) while the normal mesh works.

meager pelican
#

You can try RenderDoc and see if you spot anything funky in the drawcall...it should show you what is coming in....

#

Maybe it's something in the mesh itself, you should be able to check that in C# side, debug.log or debuggers.

#

And IDK if there's an UpdateMaterial() call of some sort to ship stuff to the GPU, don't remember off top of head.

#

Maybe someone else will know.

remote mauve
#

πŸ˜”

#

I actually feel so defeated.

meager pelican
#

Hang in there. This is that 80/20 thing where 80% of your pain comes from 20% of the features.

#

lol

#

So it's this crap that makes you want to scream. But everything has hurdles.

remote mauve
#

Ain't that truth.

#

I don't have access to the mesh itself though, it's in the parent Graphic class

#

There's a legacy mesh generation which have direct access to the mesh

#

Except that I can't seem to get it to work either.

meager pelican
#

Dumb question, did you remember to call FillMesh()?

remote mauve
#

VertexHelper.FillMesh is called by the parent class automatically after OnPopulateMesh

meager pelican
remote mauve
#

Tried that just now, vertices and normals look right.

meager pelican
#

So see what you're getting passed into the vert() stage in RenderDoc. It will show you the contents of the input struct for the call.

#

IIRC

#

Oh, and just a random thought...lighting uses UV sets somehow but IDK how that applies to the UI stuff. So you want to make sure if you're using lit shaders that it isn't getting trashed. But I'm guessing here.

remote mauve
#

Hmm, I don't know much about it.

#

I'll try more stuffs later on, had enough of it for the day.

#

I'm thinking maybe keep reading the source and see what it does with the mesh, maybe there's some clues.

void bobcat
#

@thick fulcrum I'll check it out thanks

dreamy kernel
#

I need grabpasses in urp so bad...

#

:/

#

I might need to stop using urp if I can't use them

#

Opaque texture doesn't cut it

#

I need to be able to see atmosphere of the other planet from within the atmosphere of the planet I'm standing on

low lichen
#

And the atmosphere rendering relies on having the screen texture?

#

Are you distorting it or doing some complex blending operation that can't be done with hardware blending?

marsh turret
#

morning all

#

still trying to find ways to get a terrain-shader in shadergraph...anyone any clues?

amber saffron
#

Expose the terrain splat maps as inputs for the shadergraph, and you can use them for layering

dreamy kernel
#

@low lichen I grab background color and then I darken it based on absorption&scattering, plus I add atmospheric glow on top.

marsh turret
#

Expose the terrain splat maps as inputs for the shadergraph, and you can use them for layering
@amber saffron where can I find them?

#

what I'm really wanting to do is replace the default lit shader that terrain uses with my own shadergraph alternative which uses a GetMainLight function to alter lighting based on the word position (for underwater shading I've tweaked a shader in shadergraph to make stuff blue the darker it goes, but that won't work with the terrain itself, obviously. Unles I can apply that node to the terrain!)

amber saffron
#

Look at the terrain object hierarchy in the project window

#

And to apply the shader to the terrain, you just need to assign it to a material, and assign the material to the terrain in the terrain settings

marsh turret
#

it wn't let you change teh material on a terrain object

meager pelican
#

@dreamy kernel I think you can do it manually, but not in SG. So make an SG shader, copy the source code produced and then edit it from there on out. As I understand it, the pipeline supports multi-pass.

Or check custom render render passes/features if they'll work for your use-case.
https://learn.unity.com/tutorial/custom-render-passes-with-urp

Unity Learn

In this tutorial, you will learn how to use custom render passes to render a toon outline post processing effect on selected objects

amber saffron
#

@marsh turret ^

marsh turret
#

aaah my apologies!

#

altho it really doesn't like that

#

all kinds of rendering glitches lol

amber saffron
#

Warning about missing tangents.
But you should be able to get something to work

marsh turret
#

i get that on other materials but this sahderraph doesn't use any tanget stuff

trail dirge
#

Does anyone know how to make fog on back side of cam? I want to have father->more alpha.

marsh turret
#

it just won't display...i'll keep trying

#

literally what I want to do is take ths existing terrain and just stick a extra step of shading into it

amber saffron
#

Should work πŸ€”

dreamy kernel
#

SG?

#

What's that

#

Ah, shader graph...

#

Well, I'm not using graphs

meager pelican
#

Well, then you should be able to use multiple passes in URP as I understand it. And you'd have access to the back buffer one way or another. Just do a blit to a render texture if you have to, that's basically a "manual grab pass". Or draw a full screen quad and then run a post processing effect.

#

I'm not exactly sure what you're attempting. But there's ways...

marsh turret
#

hmmm there's a point

#

if I can't use my shadergraph terrain on the terrain itself...

#

can I potentially use a blit-pass on just the terrain?

thick fulcrum
#

πŸ€” you could probably use a screen space projection effect, like is often used for caustics

marsh turret
#

i need to do a caustics layer anyway...

#

i have a shadergraph that has the MainLight & AdditionalLights functions fromt he customlighting.hlsl example code Unity provided..

#

which I then multiply by the depth of the water, so if it's near the surface, it's maybe the same color as normal or a little blue...but if it's really deep might be dark blue or even black...then additional lights are added in, based on their distance to the object, regardless of unerwater depth...this way if the player has a flashlight etc it will still work deep down

#

since i've made that sub-graph, my plan was to make a new version of the terrain shader in shadergraph, and just loop the underwater lighting stuff in..but seems quite hard/undocumented

#

you'd think unity would support their own shadergraph tool being used on the terrain

#

or even just provide a default example etc

thick fulcrum
#

it maybe on the plan, but probably a long way down the road.
Given your situation something which is independent of terrain while giving same results would give more flexibility. Less to maintain is always good in my book and trying to get SG terrain working will be a struggle + maintenance.

thorny pelican
normal shuttle
#

Hi, is there something like 'light function materials' from UE4?

#

At least in HDRP?

#

I want to filter the sun light intensity based on its distance to each lit objects pixel.

weary dust
#

Hi guys, do you have any idea of what is this RenderTexture I found with the memory profiler? I googled around and found it has to do with the subshaders but i barely understand how a shader works so I have no idea whats this or if i can get rid of it.

meager pelican
#

It's likely "requested" by a shader [pass] for its needs. So the way to get rid of it is to not use the material that requested the shader. As for figuring that out, explaining that gets complicated but you could try the frame debugger or RenderDoc if you're adventurous.

It's also remotely possible it was allocated by some script, and just named "GrabPass Temp".

weary dust
#

It's likely "requested" by a shader [pass] for its needs. So the way to get rid of it is to not use the material that requested the shader. As for figuring that out, explaining that gets complicated but you could try the frame debugger or RenderDoc if you're adventurous.

It's also remotely possible it was allocated by some script, and just named "GrabPass Temp".
@meager pelican Found it

#

its a shader we have to render a water effect

meager pelican
#

Yeah, that's one typical use-case. It needs to "see" what is behind the water, and so it captures the screen.

weary dust
#

thanks ! πŸ™

azure geyser
#

Is it possible to have a branch not continue if it's false in shader graph? Or Is it possible to compare three values inside of shader graph?

#

Basically is else if logic possible?

dreamy kernel
#

And, uh, how do I exactly do a custom pass in urp?

#

How do I assign shader pass to my customly made one?

#

I can seem to only have one lightmode tag (or whatever it's called) per shader pass

meager pelican
#

@azure geyser if/else are keywords in shader code. There's some caveats on if it's a good idea or not... For most intents and purposes, you're going to execute both sides of the logic from a performance standpoint, unless you're passing in a uniform value as the conditional.

#

If you're using Shader Graph (SG) you have a conditional and branch nodes, and also there's custom-code nodes.

azure geyser
#

Thanks for the info!

azure geyser
#

Is there a reason this is showing on an empty PBR Graph shader. It doesn't turn on or off emission so I'm confused why it's there.

regal stag
#

@azure geyser It might make the emission be used for baked lighting

#

Yea looks like that's what it does. Not labelled that clearly

azure geyser
#

Jeez yeah not at all, okay thanks! I thought it was a hidden _EMISSION keyword or something

agile citrus
#

So I need to change all of the colors of about 1 million vertices every 3-5 seconds. Right now I just have each color array in memory and I use these to set the colors of each mesh when I want them to change.

#

each of the rectangular prisms is a mesh and each of the spider web looking group of lines is a mesh

#

This example is about 1m verts.

#

Would it be smoother to just create a duplicate of all of these meshes for each set of colors where all but the currently displaying colors are inactive?

meager pelican
#

How many unique colors do you really need?

#

Per frame?

#

Can you use a indexed lookup table for them somehow?

agile citrus
#

I would say at max there would be 10 sets of colors for each mesh

#

I'm switching colors every 5 seconds atm

#

Getting the color data isn't an issue. I have it all in a list of Color arrays.

#

I'm just wondering if having invisible copies of each mesh that I make visible when I want to display them would be faster than updating the colors of every mesh.

meager pelican
#

IDK how many "10 sets" is, but the idea is that you DON'T update all those meshes every frame if you can avoid it. Assign color indices and just update the color array lookup table instead (the 10 sets).

When you update meshes it will send a lot of data.

BUT, if you just want to flip between two color sets or something, then just pass a flag for "use set one" or "use set two" and store them in two sets or whatever. Let index for set 1 is x, and set 2 is y in the vert colors.

I'm still not "seeing" it so I'm rambling.

agile citrus
#

Like for every vertex there are 10 different colors it switches between

#

Oh so I can give the mesh more colors in a lookup table that it flips between? I will look into that

meager pelican
#

Oy, and you need that per-vertex?

#

Each frame random?

#

Or not random, but variable?

agile citrus
#

The different colors are established on start up

meager pelican
#

No global for "use set one this frame"?

#

So mesh 1, vert 500 gets color <blah> and that changes each frame?

agile citrus
#

I'm visualizing a neural network and the user selects a folder that contains the input images. I'm expecting anywhere from 1-10 input images.

#

The state of each layer is different depending on each input image.

meager pelican
#

Ah!

agile citrus
#
        {
            foreach (CubeScreen screen in screens)
            {
                screen.nextColors();
            }
        }```
meager pelican
#

And can it be derived by passing in "this is frame # x"?

#

Or are these all unique state changes that can vary?

#

I guess I'm stupid.

#

I'm trying to find a way that you don't have to update 1,000,000 verts per frame.

agile citrus
#

ok I'm very new to unity so bear with me

#

I followed a "minecraft in unity" tutorial figure out how to render these groups of cubes

#

Each cube is a pixel basically

#

The collection of cubes is what I'm calling a CubeScreen

#

Each CubeScreen displays an image

meager pelican
#

Is this AI or medical imaging? I'm assuming AI by "neural network".

agile citrus
#

Yeah I'm just visualizing what's going on inside of neural networks

#

It isn't doing any learning

#

The user uploads their trained model and I'm calling a python script to get all of these "images"

meager pelican
#

So you're colorizing "states" of some sort, eh?
At worst I would thing a triangle would have 3 verts the same color?

agile citrus
#

I realize I could just make the images into textures, but I prefer this route for now

meager pelican
#

So you could cut that updates to 1/3 of it by using indexes.

agile citrus
#

right

#

It's a bunch of triangles

#

oh I can map it like that?

#

with like color indices?

meager pelican
#

Yeah, I'm thinking so.
So you'd update the color table, not the meshes. The meshes would have their id's set and done.

So triangle #1 in mesh #1 would be index 0, etc. And then whatever color you want that to be could be a float4 in your lookup table.

Then you only update the table, not the meshes.

#

So if you had 1,000,000 verts, you only have to update 333,333 ish colors.

agile citrus
#

That does sound preferable.

#

Let me look in the mesh api for that

meager pelican
#

IDK where the 10-sets comes in.

#

You use the vert colors or maybe a UV set to store the index.

#

Or sets of indices?

#

I'm still confused at what you're doing, exactly.

#

But....trying to generate ideas.

agile citrus
#

You get an error when you try to store an array in mesh.colors that isn't the same size as mesh.vertices

meager pelican
#

Yeah.

agile citrus
#

So it has to be a setting if that option exists

#

Well updating 333,000 ints is a lot faster than updating 1million colors

meager pelican
#

So mesh 1, verts 0-2, is the first triangle, and would have it's value set to index 0.
mesh 1, verts 3-5 would be index 1, ... or whatever. I'm still not sure what you're needs are.

Then you'd have a color table you update per frame. A float4 array of colors.

#

So you're assigning the index by TRIANGLE not by vert. So each polygon as the same index.

#

for that triangle.

meager pelican
#

IDK, settings look OK on first glance. Try just outputting the scene node result, no other calcs.

#

Well updating 333,000 ints is a lot faster than updating 1million colors
@agile citrus 333,333 float4's (or 3's but try for float4)
And you can use UV sets for the index instead of vert colors if you want.

agile citrus
#

Yeah I think I'm going to switch to Color32 after I figure this out.

#

I don't see any options to use anything besides Color arrays of the same length as the vertex count.

#

These are specifically per-vertex colors

final hollow
#

are you guys deep in a question right now or can I jump in and ask something new?

agile citrus
#

go ahead man

shrewd grail
#

IDK, settings look OK on first glance. Try just outputting the scene node result, no other calcs.
there are no other calcs going on though? :O

#

its literally just the scene color output going to emission thing

final hollow
#

I'm looking to make use of these "global" shader properties, like "Shader.SetGlobalFloatArray". How does one reference them from within the shader?

#

I'll be hacking something into shadergraph, ultimately, because I'm like a 5 year old when it comes to writing HLSL

#

but if I can cobble together enough knowledge to create a little custom node that emits values from this supposed global property interface, I'll be very happy

regal stag
#

For global shader properties in shadergraph I think you can just create properties in the blackboard like any other.

#

Usually you'd untick the "exposed" option, but I don't think that's actually required.

final hollow
#

theres no "float array" property available to create though

regal stag
#

Ah right, missed that you were referring to the array specifically

final hollow
#

well, to be fair, I wasn't that explicit

#

but yeah, thats what I'm looking for

regal stag
#

For that you will need a custom function (and will need one if you need to loop through that array)

#

I'll find an example quickly, I'm sure I've got one somewhere

final hollow
#

I just need access at a particular index

#

(relative to worldposition)

regal stag
#

Ah okay. You need to use the File mode in the custom function, create a .hlsl file and pass it in.

float _Array[10]; // must set a size

void ArrayExample_float(float index, out float Out){
   Out = _Array[int(index)];
}
#

Would be something like that. I'm not hugely familiar with ints in hlsl so might need tweaking (shadergraph doesn't have any ints afaik, so I assume you'd need to pass it in as a float. Maybe it'll cast it automatically though?)

final hollow
#

yeah arent they like an alias for floats or something?

meager pelican
#

I don't see any options to use anything besides Color arrays of the same length as the vertex count.
@agile citrus You HAVE to assign the same INDEX to all the verts in a polygon. Same number of verts. But you'd only do that ONCE. You're numbering the polygons.
Then you update the color table for each index (that's a separate thing from the meshes). That's one color per polygon, not repeating it 3 times.

final hollow
#

or does it just work because it's named "_Array" ?

#

and I would target that same name when I make the call?

regal stag
#

You'd change _Array to whatever you use in the C# function. So here it would be SetGlobalFloatArray("_Array", array);

final hollow
#

gotcha. nice, that's pretty rad

meager pelican
#

its literally just the scene color output going to emission thing
@shrewd grail Well something showed up I guess. I was saying to output it to albedo, basically the sphere should vanish and show you what's "behind" it, or it will output grey or something weird.

final hollow
#

and YOU'RE pretty rad. let me see if I can try this out quickly..

shrewd grail
#

Alright ill test it out then

regal stag
#

It kinda looks like there's some colour on the top of the sphere. I'm not sure why though. Unless the UVs being used for the scene color is messed up? It should be the Screen Pos

#

In your screenshots it doesn't have an input though, and I'm sure it's supposed to use the screen pos then.

meager pelican
#

He's saying scene color isn't working, but I was suggesting we prove that, as his settings look like it is enabled and he's using transparent pass.

regal stag
#

Yeah, as far as I can tell it should work fine with those settings. No idea why the sphere would look like that though.

#

It kinda looks like messed up uvs to me. Like it might be sampling with the models uv rather than screen position.

shrewd grail
#

do you guys get an idea of what it looks like though? like its not a static color either
its like transparent but weird

#

idk if that's noticeable in that pic

regal stag
#

It should basically look like the shader has gone "invisible" when drawn correctly, as you'll be rendering what's behind it to the sphere. Might be slightly shaded with the smoothness and stuff applied on top

shrewd grail
#

so no difference

#

like if i delete the scene color node its still that same thing

#

like scene color node wont affect it at all

regal stag
#

Are you saving the graph?

shrewd grail
#

ctrl+s right?

regal stag
#

No, you have to use the Save Asset button in the top left

#

Ctrl+S will only save the scene

shrewd grail
#

aaaaaaaaaaaaaaaa

#

thank you

#

so flipping much

#

really sorry for the hassle lmaoo

regal stag
#

No worries

meager pelican
#

lol Happens a lot

shrewd grail
regal stag
#

There we go

meager pelican
#

Yeah, and the rest is lighting or something.

shrewd grail
#

yeah i can fix that now :D

regal stag
#

If you want it less blurry, you can change the Opaque Downsampling option on the URP asset too

humble grove
#

It's best not to use too much shader because you will destroy your computer.

final hollow
#

oh thats interesting. So my array intended array is about a million elements (its a 1001 by 1001 grid)

#

any ideas? πŸ˜…

#

would a texture be a better move?

regal stag
#

Haven't really done something with that many elements before. A texture might be the better option

#

Wouldn't be too bad since you only need to sample it once anyway right?

final hollow
#

is sampling a texture expensive? once per fragment, yeah. fragments are going to take their y position from this grid

regal stag
#

Sampling once is fine, textures are used all the time like that anyway.

final hollow
#

that makes sense. I just have to figure out how to write to a texture from C#

regal stag
final hollow
#

oh hell yes

#

thats excellent, this is gonna be way easier than I thought. the source array is a NativeArray

#

I thought I was going to have to perform an extra step of converting it into a list

#

although, maybe I'm wrong about what this does

#

because... well, I guess I would have to convert these floats into pixels in order for that to work?

regal stag
#

Mmm probably depends on the format the Texture2D was created with

#

Maybe the RFloat format would work with a NativeArray<float> ?

final hollow
#

RFloat format? iinteresting

#

I am seeing functions online to convert back and forth from a color32 and a float32, which is interesting

regal stag
#

Yeah, if the RFloat format doesn't work then you might need to convert it into colours first

final hollow
#

ah, yeah, RFloat is a scalar texture, thats conceptually exactly what I need

#

so in this case I can use the texture nodes and properties that are already in shadergraph, right?

#

hypothetically

regal stag
#

Yea

#

You mentioned earlier about fragments taking their y position from the texture right? Do you mean displacing the vertices though?

final hollow
#

yes

regal stag
#

Then make sure when you sample it in shadergraph, use the Sample Texture 2D LOD node, as the other one can't be used in the vertex stage.

final hollow
#

oooh, great catch

#

does LOD have to do with how granularly it's interpolating values?

regal stag
#

LOD is to do with the texture's mip maps, which you probably don't have any anyway

final hollow
#

oh, right yeah.

#

set it to 0 then?

regal stag
#

Yea 0

#

There is also point vs billinear sampling that you change, I think either in C# when setting up the texture, or override it in the graph with the SamplerState

final hollow
#

want to see what we're building?

#

thats all physics, no shaders involved

#

its all a big ole runtime array of wave positions

#

so if I can map this sucker into a shader, stuffs gonna get real cool in a hurry

#

doesn't seem like its gonna let me sample RFloats from this thing.

#

considering you have no choice in the output of the Sample Texture 2D LOD Node

#

its a Vector4 and that's that

regal stag
#

Ah cool, like a "pin-table" kinda thing

final hollow
#

yeah haha, thats how it ends up looking without shaders

regal stag
#

It should just be the the R output I think?

final hollow
#

ohhh interesting

grand jolt
vocal narwhal
grand jolt
#

do i have to create my own scriptable render pipeline asset?

vocal narwhal
#

If you didn't start your project as a URP project, yes

grand jolt
#

i did

#

just created a new one

vocal narwhal
#

Then you should check the graphics settings to see if it's assigned properly

grand jolt
#

there is nothing for me to assign

vocal narwhal
#

Then you'll have to create one. I'm guessing your project either wasn't actually a URP one or you deleted the asset when you opened it.
Either way, you can create one manually

grand jolt
#

oh, when i created it there was some template scene and stuff that i deleted. might have accidently deleted the shader

shrewd grail
#

how would i be able to make those bubbles inside?
would using particle system instead of shaders be an easier solution to making them? If so, how could i make the particles look like that?

#

i know i would probably be using fresnel and some refraction to make the bubbles but then how would i generate randomly or something

final hollow
#

@shrewd grail so, Im not an expert, but I believe this is typically done by sampling a scrolling noise texture, not actually generating random numbers. you generate random noise and store it as a texture, and then multiply something's position by time and use that to sample the noise

final hollow
#

waiiiit a minute. Sampling textures is done via a number from 0 to 1 isn't it :/

#

not by 2darray indices.

shrewd grail
#

I do have an explaination by the person who made it but I couldnt comprehend it πŸ˜‚
Hold on lemme link it here in case anyone could lay it out for me in simpler words

meager pelican
#

He's commenting on Blender specific shaders anyway.
In general he's saying use a particle system for the bubbles and a glass shader on that (assume that does refraction of some sort).
They already had the cylinder of colored liquid with a top and bottom "slice" on it and an active area in the middle.

Things to search google for: Unity, refraction, bubble, glass, shader, example.
I don't think they're doing any real liquid simulation (no waves or whatnot, no flow if the container is broken).

Or you can check this out:
https://www.youtube.com/watch?v=dFv8lM-kS4E
But it might be hard to follow if you're new to this stuff.

Lately, our twitter feed was literally full of bottles containing liquid directly from the last chapter of Half-Life (Alyx).
A lot of good talented creators made their version of this cool liquid effect.
Today we'll create our version of it on Unity.

Ronja's Stencil article:...

β–Ά Play video
shrewd grail
#

The guy named:pixelgrip did it in unity tho
Combination of shaders+ particle system i think

#

But ill look at that vid thanks

#

Also i dont really need liquid similation
I want my character to basically be made out of gel
So he'd have moving bubbles inside with some refractive shader on him

#

I have a question though, how would you make the particle system look like bubbles πŸ€” (kinda off topic from this channel i guess)

#

Also particle system sounds better performance wise i think?

meager pelican
#

The vid is mostly about liquid sim, so you can skip it, no bubbles!

#

But as for the particle system, I'm pretty sure his post was talking about blender particle system but maybe not.

#

Anyway, you can do the bubble a few ways. The particle system would refract light from the scene. Do that goggle search and find out how to do a custom bubble shader that refracts light. There's many examples IIRC. Publishing all that here isn't very practical and I don't have one handy.

#

The bubble might be a mesh, or it might just be a quad with a circle on it, and a special shader. I know you'll find them if you go looking for it.

shrewd grail
#

Well i already do have a refractive shader :D

meager pelican
#

You'll probably nee d a reflection probe and reading it in a refractory way.

#

Well, use that, and try a mesh particle system with spheres!

#

Emit from a circle on the bottom.

meager pelican
#

You can fake the whole thing too with an animated (tall) texture that wraps in the Y direction (seamless bubbles), and just burn in some reflections, but that's "cheap" and won't really refract.

shrewd grail
#

This counts as refraction right?

#

I mean if i play with the settings a bit

meager pelican
shrewd grail
#

Ah ok

meager pelican
#

You might cheap that out too by inverting the Y UV properly within the bounds.

shrewd grail
#

Well then its super late here
Thanks for all the help, cant wait to try this out tommorrow :D

#

Byee

simple violet
#

I'm trying to add a shader material to a UI image and use a mask

#

but unity says Material doesn't have a texture property '_MainTex'

thick fulcrum
#

@final hollow it's fairly simple to convert a 2d array to 1d, there's examples on the net. Not looked back on the whole conversation, but from the vid what your doing looks a lot like Matthias MΓΌller-Fischer's work, specifically the 2008 GDC using a heightmap to simulate water (pipes sim). You can easily push this to a compute shader if that's a possibility for your target platform.

remote mauve
#

Repost

I'm overwriting MaskableGraphic.OnPopulateMesh(VertexHelper vh) which generates my own mesh for UI, while things like position/color/uv0 of vertices work, I can't seem to get uv1/uv2/uv3/normal/tangent to work.

sharp verge
#

Just wondering, does shader graph have something equivalent to UE4's Material Parameter Collections (https://docs.unrealengine.com/en-US/Engine/Rendering/Materials/ParameterCollections/index.html) where you can define global parameters which effect multiple material instances at the same time, or is this something that can only be done through code? Basically I'm wondering if it's possible to make it so that some shader properties are global and when you adjust the slider it effects the values for each material that uses the shader, like a slider for snow coverage for example.

tranquil fern
#

Using a pbr graph, which node do I need to move between two colors based on a value between 0 and 1?

regal stag
#

Lerp

tranquil fern
#

Ofc.... Sorry, thanks.

tranquil fern
#

I have a quad that plays video, and I want to make it hologram style. The input is a Texture2D... Which graph would be best for that? I tried the unlit master but I can't pass in a texture anywhere.

regal stag
#

Master node isn't really important for using a texture, you just need to set up a Texture2D property in the blackboard and then use the Sample Texture 2D node to sample it.

tranquil fern
#

I'm an absolute moron.

#

I thought "Sample Texture 2D" would be an example texture

#

I didn't want an example, I had my own. haha oh no

#

So then which of the graphs would perform best? Or do they perform pretty much the same?

#

I'll have about 250 of these running around the scene so I want to make sure it doesn't start a fire

regal stag
#

The PBR one has to perform lighting calculations, so will be more expensive than the unlit one. For a hologram effect you probably don't need that lighting so I'd go unlit.