#archived-shaders

1 messages · Page 232 of 1

tight phoenix
#

Lets say have I have 32 objects that I want to have the same material and shader, but tint 32 separate colors, is that possible? I know SpriteRenderers can pass in a color like that, but I am unsure with a 3D mesh

hard ravine
#

Hello everyone, I've created a shader that does this effect. However to see the effect it renders it onto a UI panel which is really bad. I want to do this as a render feature but have no idea how.
Simple terms a 2d pixel metaball to make goo.
If anyone could help that would be fantastic, no stress either way.

#

Or even if possible a link to an article

amber saffron
silver sparrow
#

are there any good books out there related to shader programming? if so, any links where i can purchase the book?

lean lotus
#

is there a good way for me to use things like WaveActiveCountBits(true) in compute shaders in unity yet?

tight phoenix
#

Shadergraph Question:
Is there a way to ignore the pixel dimensions of an input texture and make it all the same size?
As in, I have a 256x256 and a 1024x1024, if I put them in as a texture, the 1024 is massive compared to the 256

#

I dont mind that one might get stretched/compressed/lose detail

#

texel size can get me its dimensions, but Im not sure how to then use that info to normalize the final sprite's size

tight phoenix
#

I want to be able to pass in ANY texture, and have it just resize that texture to an exact fixed dimension

#

How do you do this in shadergraph?

lean lotus
#

if I use mul(float3 raydirection, float3x3 tangent_space) to get local_to_world type transformation, can I just do mul(float3x3 tangent_space, float3 raydirection) to get a world_to_local type transformation?

lean lotus
#

also whats a good way to tell a number is a NAN or Inf so I can turn that into a true or false?

simple spade
#

is there a way to convert shaders to the universal render pipeline?

#

my current shader is having trouble

shadow locust
manic abyss
#

I installed urp, set the pipeline to a 2d Renderer Pipeline Asset

#

i get a white material on my sprite

#

and not the orange

#

like a grey color

amber saffron
manic abyss
#

ye I did it

#

works now

silver sparrow
wild thorn
#

I've been looking around for a good introduction on how to write your own deferred shader. I've found some examples in the Unity shaders, but it is difficult for me to understand when / where certain shaders are applied and how I can apply my own. Does anyone know a good guide on how deferred shaders work in Unity, and how I can make my own? I understand the concept of deferred rendering - I just don't understand how Unity approaches it, yet 🙂

amber saffron
amber saffron
wild thorn
#

I'd say so - but it wouldn't be that different from what Unity has to offer. For now at least. I think I should start with writing a deferred shader that uses the render pipeline of Unity. As an example, introduce triplanar projection to a deferred shader. Or have my own setup on how the textures are sampled. But the attributes (albedo, normals, metallic, etc) would be the same

wild thorn
amber saffron
wild thorn
#

So far I've been writing shaders from scratch, my mind says surface shaders become deprecated at some point. Is that my mind playing tricks on me, or is it worth looking into surface shaders?

amber saffron
#

That's .... complicated.
If you're only aiming for the built-in renderer, surface shaders will still work.
Surface shaders are just a way of removing the hassle of handling yourself the forward/deferred and lighting complications.

In most recent versions, shadergraph is also supporting the built-in render pipeline, and at some point will be to go-to method for making shaders

wild thorn
#

Interesting, I see - would you recommend me to work with Shader graph instead?

#

As in: work with shader graph over writing my own shaders?

amber saffron
#

If at any moment you want your shaders to work with URP/HDRP, I'd says yes, as they don't have any support for surface shaders and writing shaders from scratch is ... complicated

wild thorn
#

I understand - I'll take next week to investigate surface shaders and shader graph. I have a background in writing OpenGL code, hence I initially started with writing shaders from scratch.

#

Thank you for you time 🙂

keen sparrow
#

Heyas; shader beginner here.
I've made a ShaderGraph (for a simple triplanar material), which is just a Lit ShaderGraph that sets the Base Color- and Normal (Tangent Space) fields based on a texture. However, when put next to the normal URP Lit shader, it looks completely different and reacts differently to light.

My shader doesn't interact with light in the same way; doesn't interact with environmental light at all; and don't get any relfectiveness from being metallic; etc. ie. They look entirely different.
Any advice on how to fix this? What's the issue? Where to start?

amber saffron
keen sparrow
#

The Material's setup is this. Obviously the lit one has a lot more functionality, but I tried disabling as much of that as possible.

#

This is what the Shadergraph is like.

amber saffron
#

2nd sample texture node : change type to "normal"

#

(and small semantic here, that's planar mapping, not triplanar 🙂 )

#

Also, the metallic value is not the same

#

Ambiant occlusion should be 1 I guess

#

and if you might want to add the normal intensity (using normal strength node)

keen sparrow
#

Right, changed the normal's texture type to normal; and added the normal strength node. Turns out setting the ambient Occlusion to 1 fixed most of the issues. Thank you for that.
However, the two materials differ when changing the Metallic value (custom one goes way darker). And Environmental lighting is super strong on the custom one, and softer on the Lit shader.

#

Also, regarding the triplanar; it's supposed to do all sides eventually. But just the top on is simpler (for the image/testing).

amber saffron
#

Can you do some new screenshots for comparison ?

keen sparrow
#

This is with the custom shader's Metallic value set to 1 (left), and the Lit shader Metallic Map set to 1 (right).

#

This is with metallic on both set to 0, but the environmental lighting's Ambient Color set to bright red.

#

Metallic value doesn't give it it's shine either; just makes it darker at the moment. :p

amber saffron
#

I'm more surprised by the red part, almost looks like the material doesn't receive direct lighting 🤔
Maybe some incorrect normal

keen sparrow
#

Huh, you're right. I disabled the directional light and they look about the same. (metallic/smoothness etc at 0, environmental lighting to red (obviously :p)).

#

Both have a default Unity cube as a mesh (not sure if this matters at all).

amber saffron
#

It has probably something to do with the normals in your shader

#

You mentioned you did change the normal texture type, did you mean in the import settings, or in the sample node ? (or both)

keen sparrow
#

In the Sample Node of the graph, as I'm not sure what Import settings refers to. 😄
Also without the directional light, with metalic value at 1 the custom shader is just straight black.

teal breach
#

I've not been on unity in a while, but fired up 2021.2.7f1 and no matter what I do, shaders seems completely broken - shader graph always pink. it's a completely clean project. is this an unfortunate version issue?

amber saffron
amber saffron
keen sparrow
#

So this then? I haven't changed anything about this, so should be whatever the default is. Both materials use the same texture, so I don't know how that would cause them to behave differently.

amber saffron
#

That's the albedo texture, I was talking about the normal map 🙂

#

"Texture Type" should be "normal"

keen sparrow
#

Yeah, sorry. It's set to Normal map for the Texture Type as well in the import settings.

amber saffron
#

Hum, there's probably something still missing, but I can't get it

keen sparrow
#

Well, that's not good. 😐 That's my shader-learning experience so far, though. Don't know where to start, don't know how to end. :p Found some articles on lighting, hoping that'll help, otherwise... asset store it is (again).

amber saffron
marble palm
#

So I’ve been messing around in shadertoy recently and quickly noticed that people use a technique called ray marching to render elaborate 3D scenes completely in the pixel shader. Other than as a novelty and perhaps some niche uses, is there any real use for this technique in games or other applications? I feel like using the normal CPU -> VS -> PS pipeline is a much more efficient way to do the same thing. Am I missing something?

amber saffron
# marble palm So I’ve been messing around in shadertoy recently and quickly noticed that peopl...

The case of shadertoy is a bit specific, as there is no 3D model system and eveything is done as "render a full screen quad". Regular rasterization is faster.
But raymarching has it's use anyway in realtime rendering, some examples :

  • Parallax occlusion mapping to fake surface details
  • Volumetric fog (well, it's more ray steps, but similair idea)
  • Objects rendering or effects using signed distance fields functions or textures
crimson hamlet
#

Is this an acceptable vertex shader? It can have four (4) colors and TINT. I like some colors but not too many okay.

I would really like to implement DITHERING as well.

split pine
#

how do I make black outlines like these?

crimson hamlet
#

Seems to be built in to unity

#

Or was at some point

split pine
crimson hamlet
#

¯_(ツ)_/¯

split pine
#

oh ok thanks for the help

balmy thicket
#

I'm in the process of creating a spellbook. Right now each page is a new material with a new camera with a new rendertexture. Seems like a performance nightmare - any ideas for how this could be done better?

desert orbit
#

Reuse them, you only need as many as there are in one frame.

balmy thicket
desert orbit
#

profile it

balmy thicket
#

Wise, thanks will do!

grizzled bolt
civic fern
#

hey guys can someone help me with this graph thing i dont understand?

#

whole relevant graph is shown here

#

why is there, with this setup, a random white line when it should be black forever?

#

its always there at some distance with circle radius

#

in that example, circle radius is 0.34

amber saffron
civic fern
#

interesting suggestion, but you can see all the logic there, i think. no negative numbers

#

the Distance vector is just so i could see an edge of the circle easily, essneitlaly scrolling the previw map

amber saffron
#

(after the second one minus node)

civic fern
#

oh, interesting

#

i feel like there's gotta be an easier way to do this tbh

#

ill say my goal so anybody can help

amber saffron
#

You want to do a sphere / disk mask, right ?

civic fern
#

i think so

#

ill draw it out cause im new to all this

#

this is the vague idea

#

however it would also be very cool if i could do like a stretched version soooo

#

more like this..?

#

so its white for longer and the transition from alpha 1 to alpha 0 only happens to in a short distance on the perimeter

amber saffron
#

distance => smoothstep

civic fern
#

😭

#

that BETTER not work that easily

amber saffron
#

and for smoothstep :

  • in: distance value
  • edge1 : outer radius
  • edge2 : inner radius
civic fern
#

oh my god

#

always ask discord upfront huh

#

tysm!

amber saffron
#

🙂

civic fern
#

actually while im here ive got another question

#

does alpha not work for values other than 0 and 1?

#

im using that circle as an alpha channel but nothing seems to be transparent. is that a setting somewhere? is it expensive?

amber saffron
#

In the graph settings, change the material type to "transparent" 🙂

#

And yes, rendering transparent objects is a bit more expensive than opaque

civic fern
#

it's transparent already, is there anything else i have to tick?

#

im using URP

#

it's a lit material

amber saffron
#

Hum, it should then work out of the box 🤔

civic fern
#

what i mean is the smoothstep bit doesnt seem to make it more transparent

#

maybe that region is just very small

#

nah i put inner at 0 no difference

#

oh wait no i got it working!

#

inner radius for smoothstep needed to be negative, for some reason.

amber saffron
#

Oh ?

#

Weird

civic fern
#

extremely

#

well, whatever, dont look a gift shader in the mouth

amber saffron
#

distance is always positive, so if edge1 > edge2 , and both are positive, is should work

civic fern
#

maybe the distance is just unnoticabley small? ill write this for another day's investigation

amber saffron
#

Maybe ? I don't know the size of your object.

civic fern
#

its about 1x1, not insane

#

i have an other question actually since you're being very life-savingly helpful

#

this shader will need to take in the transform.position of a different gameObject than the material its assigned to. whats the easiest wya to go about doing that?

#

once its in the shader as a vector3 i can take it from there

amber saffron
#

You have to use a script to send the object position to your material.
material.setVector("myVectorPropertyName", target.position);
Where the property name is the "Reference name" of the property in shadergraph

civic fern
#

oh, sick, thats way easier than i thought

#

ty!

vague imp
#

why cant i connect this to the normal ?

merry rose
regal stag
#

Technically it's due to the screenspace partial derivatives (ddx/ddy) that are used by the regular texture sample to calculate the mipmap level, and those are only available in the fragment stage.
While you could use the LOD version to specify an exact mipmap for use per-vertex, if it's a normal map it would make more sense to be connected to the "Normal (Tangent space)" port in the Fragment stage.

lime star
#

any good extensions for autocompletion and syntax highlighting for HLSL in microsoft visual studio?

plush bane
#

How can I use unlit Sprite shader graph in my UI. I tried now different ways and it just doesn't work

#

In editor its cool

#

Runtime this 😦

dim yoke
little widget
#

I want to use shader graph and Amplify shader because I have a library in each. How does one go about switching between the two assets of can I only have one shader tool in the project at a time?
I am sure others are in the same pickle.

regal stag
plush bane
#
fixed4 frag(v2f i) : SV_Target
            {
                float xRemap = i.uv.x * 100;

                if (floor(xRemap) % 10.0 == 0.0) {
                    return float4(0.0, 0.0, 0.0, 1.0);
                }

                return float4(1.0, 1.0, 1.0, 0.5);
            }
pseudo urchin
#

Does anyone know why this ui blur effect is making my game so laggy?

plush bane
#

Hi this produces thick lines. How do I get 1-2 pixel thick perfect lines?

#

👆

regal stag
plush bane
#

Ouh i put in the if statement

#

With smaller value 0.01 it still produces uneven lines

regal stag
#

It doesn't really need to be in an if statement as it already returns 0 or 1. Can just do

float x = step(frac(i.uv.x * 10), 0.05);
return float4(x,x,x,1);
plush bane
#

Some are 2 px, some 1px

#

Also with thicker lines it sometimes 1px more or less

dim yoke
#

If the lines are 1.5 lines thick, its kinda expected to be either 1 or 2

#

You have to get those exactly 1 or 2

#

Maybe something to do with partial derivatives

plush bane
#

Yes I need all 1 or 2 or whatever, but all even thickness

#

Trying to figure it out

regal stag
#

Perhaps you need to take into account the width of the quad it's applied to. Or screen (_ScreenParams)?

dim yoke
#

Couldnt partial derivative of the uv.x help?

dim yoke
plush bane
#

I was thinking maybe I could use Object space pixel positions (integers) and not uv floats.. but how to I get thouse?

dim yoke
#

Theres nothing wrong with uv being float

#

But if youre trying to render line with thickness something between 1 and 2, some may be 1 and some 2 pixles width

plush bane
#

I am not aware that I am trying that

dim yoke
#

You could use ddx(uv.x) to get number that tells how much the uv coordinate changes when moving one pixel to right on the screen

dim yoke
fleet rampart
#

how do i fix this normal issue?

#

*Bottom left corner

#

its like split into 4 diffrent normals or something

regal stag
fleet rampart
#

i tried but it still gives me the same

#

just lighter

regal stag
#

Might also just need to Flip / Negate / Multiply by (1, -1, 1) instead of using Invert Colors when using Normal mode

#

Assuming the direction stored in the normal map isn't right

#

The normal map also looks quite light, might be a colorspace thing. Not sure if it's been exported/imported properly.

fleet rampart
#

flip negate multiply doesnt do it either

#

and as loose ones they done either

regal stag
#

I meant use one, not all at once. Those nodes all do similar things.
Maybe it's a problem with the normal map? Have you tried testing it with a lit shader that HDRP provides?

fleet rampart
#

yeah so the thing is

#

this is a lit shader

#

i just removed some properties

plush bane
#

true

#

Not sure how use screen with tho in this shader

#

Shot in the dark

#
float xRemap = i.uv.x * 100 * unity_OrthoParams.x;
                

                if (floor(xRemap) % 20.0 == 0.0) {
                    return float4(0.0, 0.0, 0.0, 1.0); 
                }

                return float4(1.0, 1.0, 1.0, 0.5);
#

But same problems 😄

dim yoke
plush bane
#

Yes, I am hacking it already :))

pseudo urchin
#

Does anyone know why this ui blur effect is making my game so laggy?

dim hinge
#

did you find a solution for this?

flint hornet
#

I don't even remember

#

lol

dim hinge
#

@flint hornetthe thing is that on an old moto e it works fine, but on a "newer" pixel xl, when entering the scene the app dies

#

Im drawing a grid on the screen

flint hornet
#

yah sorry bro, not sure

dim hinge
#

ok

frigid zinc
#

ive got this shader that shows a flat colour mesh through anything its behind but it doesnt work behind transparent textures

#

Not sure what to do because i dont know shader code

exotic goblet
#

@plucky stag

#

Check around in the graphics section

#

@plucky stag

#

Here bru

plucky stag
#

Wassup shawty

exotic goblet
#

In graphics

plush bane
#

How do I get object space pixel position is a coded shader?

plush bane
#

And about ddx. Strange but it always returns 0. If I set ddx(1) then pixel to the right with ddx(0) should return 1, right?

plush bane
#

Is there some setting I must turn on for it to work?

plush bane
#
fixed4 frag(v2f i) : SV_Target
            {
                float dx = abs(ddx(1.0));

                if (dx > 0.0) { // this never happens
                    ddx(8.0);
                    return float4(1.0, 0.0, 0.0, 1.0);
                }

                float xRemap = i.uv.x * 100;

                if (round(xRemap) % 10.0 == 0.0) {
                    ddx(8.0);
                    return float4(0.0, 0.0, 0.0, 1.0); 
                }

                return float4(1.0, 1.0, 1.0, 0.5);
            }
dim yoke
#

Youre probably misunderstanding the concept of partial derivatives

plush bane
#

Maybe it doesn't work if its called twice

dim yoke
plush bane
dim yoke
#

I don't quite get what the point of ddx(8) if you can just type 0 instead...

dim yoke
#

I mean ddx(8) is literally 0

plush bane
dim yoke
#

float dx = abs(ddx(1.0)); is **same **as float dx = 0;

plush bane
#

You are not taking into account the fallowing code lines

dim yoke
plush bane
#

If pixel 0,0 is ddx(8.0) and pixel 1,0 is ddx(1.0), the difference is 7.0

dim yoke
#

no, ddx(someFixedValue) is **always ** 0

plush bane
#

its not fixed.. i set 8 or 1

#

Just some lines lower

#

It will be always 0 if there is no variation

#

Because x-x = 0

dim yoke
#

ddx(8.0); what is that line doing? nothing? ddx(y) returns the change of y when moving one pixel right on the screen. Since 8-8=0, ddx(8.0) returns always 0 and you don't even use that for anything. that line does exactly as much as line with only 1+1; on it

plush bane
#

I was thinking that ddx(x) sets the current value that will be compared in next pixel

dim yoke
#

no, ddx(x) returns the rate of change of x when moving on the horizontal axis on screen.

#

ddx(x) compares the x of the pixel next to it to the x of the current pixel

plush bane
#

But tehnicaly it must memorize x value of pixel 0,0 to compare it with pixel 1,0 ?

dim yoke
plush bane
#

I already read this

#
In this case we can use any value and get the change between the neighboring speenspace pixels.
#

That what I am trying. Set 8 for pixel 0,0 (abstract position) and then compare to 1 in 1,0

#

But as it doesn't work there is thing that I am not getting 😄

dim yoke
#

you're still working on fixed line thickness?

plush bane
#

yes

dim yoke
# plush bane yes

this is what I got with partial derivatives (hope the poor gif quality don't mess up the video):

#

@plush bane This is the shader graph setup I used:

#

with that setup the scale of the object and screen scale/ratio doesn't affect the thickness. only if you change the roll of the camera or rotate the object, ddx will not look good anymore because the lines are not vertical on the screen anymore (but small amount or rotation doesn't mess it up)

plush bane
plush bane
lime star
#

this might not be the right place to ask but im currently writing some compute shaders with microsoft visual studio code and it bugs me that it doesnt have proper syntax highlighting, debugging and auto-suggestions, making me not sure where my errors are and if what im writing is even possible in HLSl at all... any extensions/tools/other editors that would allow this for HLSL (and preferably also c# so i dont always have to switch)? thanks in advance

dim yoke
#

it's free for students

lime star
#

even though im a student, my school isnt part of the accredited schools

plush bane
dim yoke
plush bane
#

At least for UI

#

Maybe thats the parts that isn't moved yet to new shaders

little widget
tacit stream
#

Shaders graphs still don't support gpu instancing?

regal stag
fervent tinsel
tacit stream
#

hm

fervent tinsel
#

built-in support for SG is kinda half baked anyway

#

also only on 2021.2+

tacit stream
#

what about material property blocks?

#

I need to use Graphics.Draw calls manually

#

so I don't see any other way to use instancing but mtb

shell compass
#

does anyone have any basic tutorials to shaders

desert orbit
#

@shell compass Check pinned resources in the relevant channels.

shell compass
#

thanks

marble thunder
#

Wonder how I can access individual texture channel from Sampler2D? Must I use tex2D?

patent lily
#

anyone have idea why it looks different in editor mode and game mode ?

tepid agate
#

Hi, I'm trying to make a shader using shader graph and I wonder if I can obtain a similar result as the distance fields option in Unreal Engine 4. I want to make foam around my water shader but using depth isn't realistic at all. Anyone knows how I can get a texture of where foam should be? This is an example for UE4, but I'm working with Unity -> https://www.youtube.com/watch?v=QABi9T34b_k

Patreon: https://www.patreon.com/StevesTutorials I made this video before making my new water material. Its still relevant because i still use distant fields in my new material :D

Twitch: https://www.twitch.tv/stevestutorials

Twitter: https://twitter.com/StevesTutorials

Discord: https://discord.gg/FDpvyKD

▶ Play video
arctic flame
#

does anyone have a sampler2d reference?

#

i'm googling and can't find just a normal reference page / documentation

tacit stream
#

how property _MainTex is defined in shaders?
Is that simply a texture from material?

hot gate
#

Hi I'm having some trouble with making my first shader. When I try to select a new color from the color panel nothing seems to pops up like it usually should? Kinda frustrating, I've clicked everywhere and feel like I've attempted everything I’m clicking inside the black color box.. nothing comes up. Please help. I'm new to unity 🙂

regal stag
regal stag
# tacit stream how property `_MainTex` is defined in shaders? Is that simply a texture from mat...

Unsure exactly on the question, It's a texture property.
Declared in ShaderLab using _MainTex ("Main Texture", 2D) = "white" {}
And HLSL using sampler2D _MainTex; in older DX9 syntax, or Texture2D _MainTex; SamplerState sampler_MainTex; in DX10/11+ syntax. Might also use macros.

If it's defined in the ShaderLab Properties section (at the top of a shader file), or "Exposed" in Shader Graph, it's set through the material. Otherwise if it's only defined in the HLSL section it's treated as a global property and set through Shader.SetGlobalTexture.

tacit stream
#

Is there any sort of property that is accessed through per material?

#

oh is that one?

regal stag
#

It depends how it's declared. The name "_MainTex" itself isn't that important.

tacit stream
#

I'm guessing in shader graph there's no Material Property Block?

#

Only per material instance property?

regal stag
#

MPBs break the SRP Batcher so yeah should stick to material instances.

tacit stream
#

that sucks

#

goodbye shader graphs for now then xD

#

or maybe not

tacit stream
#

I plan on calling DrawInstanced myself

#

any way I can implement MPBs?

regal stag
#

If you're using DrawInstanced calls the SRP Batcher won't be used anyway so it doesn't really matter that it breaks it

#

The graph should already work with instancing too, as long as you don't set up properties in the blackboard (afaik)

tacit stream
#

I mean, how do I implement them then?

#

so far I don't see any special UI for mtb

#

only for material properties

regal stag
#

Material property blocks aren't really a shader thing. They are set up on the C# side and passed to a renderer. You can technically use them even without instancing - though if you're using DrawInstanced calls you'll probably want the shader to still support that.
In the past I've used a Custom Function to add the instanced properties (also linked this yesterday but I feel my message was missed) : https://twitter.com/Cyanilux/status/1382832863817703426

#

It's been a while since I tested this so it might have broke in newer versions though

tacit stream
#

f, I can't open twitter links

regal stag
tacit stream
#

thanks

#

oooh, didn't know that is a thing

#

hmm, so syntax is just like in C#?

#

you basically define field

#

and then call it through code

#

hmm, I can pass hlsl into ShaderGraph?

regal stag
#

The code on the left is HLSL, it's what shaders are usually written in. Shader Graph just is a node tool that generates it, but you can also use HLSL snippets through the Custom Function node.

The code is similar to what you'd use in the built-in RP when dealing with GPU Instancing & Material Property Blocks. This is a good tutorial on the topic : https://www.ronja-tutorials.com/post/048-material-property-blocks/

tacit stream
#

does unity have built in create option or I need to create file all by myself?

#

I mean how to create my own custom function

regal stag
#

You'll need to create the file. Can use basically any text editor, then save it with the .hlsl extension

regal stag
regal stag
tacit stream
#

any idea if there's any intellisense for shaders out there btw?

digital gust
#

Hey everyone, I am trying to write a shader that performs a gradient from a z world point to a target z world point. How would I go about doing that in the vertex part of a shader?

regal stag
# tepid agate Hi, I'm trying to make a shader using shader graph and I wonder if I can obtain ...

Unity doesn't have any built-in distance field generation. If it helps, Harry Alisavakis recently did something on twitter to generate one : https://twitter.com/HarryAlisavakis/status/1481644176349401089

Based on a few comments (and he explained it on a twitch stream I watched), their method uses an orthographic camera looking down, with near clip plane aligned to water plane. Objects are rendered with a replacement shader (for URP can use RenderObjects feature w/ override material) that renders front faces white and inner faces black. Then a Jump Flood algorithm is used to turn it into a distance field (specifically Harry uses https://unitylist.com/p/111b/Jump-Flooding-Algorithm)

It could probably run realtime, but also more performant if the result is baked/saved as a regular texture that the water shader can then use. If it's baked, the foam won't update with objects that move though.

digital gust
#

So right now I have the local and global world position I want to target. I am just confused as how to convert the vertex position to check for that range. So is vertex like the local position in the gameobject hierarchy "visually" on the mesh or is it another space itself within the mesh? I guess thats what UV is, dependent on the mesh, but vert is som ehow world or local position

tacit stream
#

ok, soooo

#ifndef CUSTOM_INSTANCING
#define CUSTOM_INSTANCING

UNITY_INSTANCING_BUFFER_START(Props)

UNITY_DEFINE_INSTANCED_PROP(float4, _CutData)

UNITY_INSTANCING_BUFFER_END(Props)

void GetAnimationData(out float4 Out){

    Out = UNITY_ACCESS_INSTANCED_PROP(Props, _CutData);
    }

#endif
#

How did you make it work with that custom code?

regal stag
#

Hovering over the red ! symbol should show any errors, if it's still there after those changes

tacit stream
#

ok I got it

#

looks like

regal stag
# digital gust So right now I have the local and global world position I want to target. I am j...

The vertices in the mesh are usually stored in local/object space. I guess it would be equivalent to the position of a GameObject when parented to the mesh object (transform.localPosition).
For comparing against a world position, you'd convert the vertex position to world via the model matrix (unity_ObjectToWorld, or UNITY_MATRIX_M).
e.g. float4 positionWS = mul(unity_ObjectToWorld, float4(positionOS.xyz, 1));

tacit stream
#

I need to define Outputs myself

#

ok, that's actually really pog

#

so that means I can combine several MPB functions into one shader like this?

digital gust
regal stag
tacit stream
#

no I mean

regal stag
#

Or have one function return multiple outputs, not sure what you're using the instanced properties for

tacit stream
#

combine several files

#

into one shader

#

kinda like keep it modular

#

for shaders with different MPB properties

regal stag
#

You can usually have multiple HLSL files. But in this case, I think it'll cause problems as each will be defining it's own instancing buffer and probably cause redefinition errors.

digital gust
#

Maybe you can clarify once again Cyan 😄 If I have this line and my vertex object is rotated, so y-Axis local is equal to z-Axis in global, would this line make the worldPos.z being my vertex.y?
float3 worldPos = mul (unity_ObjectToWorld, i.vertex).xyz;

tacit stream
#

I don't get it, shaders don't like integers or what?

#
void GetAnimationData_float(out int width, out int height, out int tile)
{
    int3 data = UNITY_ACCESS_INSTANCED_PROP(Props, _CutData);
    width = data.x;
    height = data.y;
    tile = data.z;
}
digital gust
tacit stream
#

I'm not sure if you can cast in hlsl

#

kek

regal stag
#

I think you can though it also happens automatically afaik

digital gust
#

you should be able to cast an int from unity docs

#

call, not cast

tacit stream
#

so far I don't have any luck tho

#

even with floats

#
void GetAnimationData_float(out float width, out float height, out float tile)
{
    float3 data = UNITY_ACCESS_INSTANCED_PROP(Props, _CutData);
    width = data.x;
    height = data.y;
    tile = data.z;
}
regal stag
#

HLSL does have an int type, but the instanced arrays probably don't support it if it's not working. I'd use floats instad

tacit stream
#

is there some kind of name convention?

digital gust
#

It is expecting a float, not a float3

regal stag
#

You're using out float tile but specifying the output type on the node as Vector3

tacit stream
#

oh damn

digital gust
#

out float3 output instead

tacit stream
#

I forgot to switch from vector3

#

true

#

I assume order is kept

#

originally like in function itself?

regal stag
#

Yes, order must be the same

tacit stream
#

is there a way to define some default MPB?

#

so my shader graph is not broken

#

in edit mod

regal stag
#

In the function, you can use

#ifdef SHADERGRAPH_PREVIEW
width = 1; // or whatever values you want for previews
height = 1;
tile = 1;
#else
float3 data = UNITY_ACCESS_INSTANCED_PROP(Props, _CutData);
width = data.x;
height = data.y;
tile = data.z;
#endif
tacit stream
#

ooooh

#

that's pog

#

I start to love it

#

sooo, no intellisense btw?

#

auto format is necessary kek

regal stag
#

There might be some but idk

digital gust
#

Not that I have seen, shader scripting is just, good luck 😄

tacit stream
#

I'v seen one

#

but it's paid

#

in VSCode

digital gust
#

Nah, not gonna pay for that tbh. Learning by doing then I guess 😄

regal stag
#

I'm using one for .shader files (ShaderLab Formatter), but it doesn't work with .hlsl

tacit stream
regal stag
#

I think it's only highlighting & formatting, not intellisense though.

tacit stream
#

ok, I think I found smth

#

hlsl tools for VS

#

let's see if it's good

digital gust
#

Oh okay, well highlighting is already working in VS Studio, isnt it? If you fiind it useful, let us know 🙂

tacit stream
#

oh man

#

Intellisense

#

aut format too

#

pog

#

gotta get used to errors tho I guess

#

or spend some time

#

hiding them

#

there's only one node for this kind of splitting?

#

simple vector

#

of 2

regal stag
tacit stream
#

I see

#

so far so good

#

I'm really glad I gave time to learn graph, looks extremely faster than ShaderLab to develop

crisp nest
#

I'm trying to sample a texture in this shader, that's all, but it doesn't work. What I get is a blackscreen.

#

I call Graphics.Blit in my program with this shader, so this is basically supposed to draw the _MainTex to the frame buffer.

#

It's a very simple one, but I have no clue why it doesn't work. Any ideas?

#

The relevant bit is this

#
            sampler2D _MainTex;

            float4 frag(Varyings i) : SV_Target
            {
                return tex2D(_MainTex, i.uv);
            }
crisp nest
#

It seems no matter what I put in as UV, I get black pixels.

#

Does that mean _MainTex is not set properly? I dunno

regal stag
digital gust
#

I wonder, can I have two SV_POSITION / POSITIONS inside, because if I just copy paste it and rename it, I get errors:

            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };  

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float2 overlayUv : TEXCOORD1;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };```
#

I am just editing a premade shader and he is using UnityObjectToClipPos(vertex); in the v2f, which I do not want as I want the real position of the vertex

crisp nest
regal stag
# digital gust I wonder, can I have two SV_POSITION / POSITIONS inside, because if I just copy ...

You want to keep using UnityObjectToClipPos for the vertex / SV_POSITION output as that's important to keep rendering the object correctly.
If you need a worldPosition in the fragment shader, you can pass it through in an unused TEXCOORD channel. e.g. TEXCOORD2.

Unrelated, but you should be aware that UNITY_FOG_COORDS(1) means it'll use the TEXCOORD1 channel for fog coords, but you're also already using it for the overlayUv. You'll want to change on of those otherwise they'll conflict and override the values.

digital gust
#

Thank god, that did the trick, just using the texcoord2 will let me calc my correct worldpos (very weird hierarchy setup from the other guy... :D). Now its working as intended, thanks a lot. the gradient part should now be a simple fiddle around thing

#

Why the hell is this working if(_UseGradient > 0.0 && worldPos.z > _GradientPosition.z - 20)
and this not


                if(_UseGradient > 0.0 && worldPos.z > distanceCap)
``` 😄 Anyone got an idea?
hushed vigil
#

I guess because the other uses a constant number and the other uses a variable

digital gust
#

Not really know why this should be an issue, I am feeding gradientlength through code the same way I do with the position.

regal stag
#

Is _GradientLength a property? Like defined in the Properties section at the top of the shader?

digital gust
#

oh wait, that was the script 😄

#

[PerRendererData] _GradientLength ("Gradient Length", Float) = 20.0

#

and in subshader pass float4 _GradientLength;

#

I am getting this if statement conditional expressions must evaluate to a scalar at line 101 (on metal)

regal stag
#

Should be float _GradientLength in hlsl section, not float4

digital gust
#

Copy paste is never good, not even in your own script 😄 thanks

crisp nest
#

@regal stag Can you tell me how to use your Blit rendering feature? 😅

#

I enabled it in my project, and apparently I can set a source and destination

#

But how do I access them in the shader material that I set?

#

And how do I set up destination to draw to the screen buffer?

digital gust
#

Okay, anyone might wanna help me again... I am really finding a hard time to start and stop the gradient on the specific position on the mesh. Does anyone have an example or so how to remap a gradient to a specific position?

#
float3 worldPos = mul (unity_ObjectToWorld, i.rawVertex).xyz;

                if(_UseGradient > 0.0 && worldPos.z > _GradientPosition.z - _GradientLength)
                {
                    //apply gradient
                    fixed4 gradient = _GradientColor;
                    gradient.a = lerp(0, 1, ???); <-- My issue, don't know how to apply any remap to this. I removed my code that is not working anyway
                }
regal stag
# crisp nest <@!357936113983291393> Can you tell me how to use your Blit rendering feature? �...

Can add the feature to the Renderer Features list on the Foward/Universal Renderer asset.
Using _MainTex in the shader obtains the source texture. The returned value from the fragment is applied to the destination.

I'm not sure if URP gives actual access to the screen buffer which might be why your previous method wasn't working. In the past I've done :

  • Use a second camera to render to a low-res Render Texture target. And also have a Main Camera that basically renders nothing (via culling mask).
  • Have each camera using a different Forward/Universal Renderer asset. Can create another in your assets (I think under Create -> Rendering -> URP).
  • You also need to add that new renderer to the list on the URP Asset so it's then available on the Renderer dropdown on the Camera. Set the renderers on each camera.
  • Can then add the blit feature to the renderer used by the main camera only. Use your Render Texture as the source on the feature. And use Camera colour for the destination.
#

Hopefully that makes sense

crisp nest
#

Ah ok so I need another camera that takes the result from the blitting and draws it to screen basically

tacit stream
#

UNITY_DEFINE_INSTANCED_PROP(int, _CutData)
How to define that kind of data in MTB?

#

mtb.SetVectorArray("_CutData", int[])??

#

is that it?

regal stag
# digital gust Okay, anyone might wanna help me again... I am really finding a hard time to sta...

What you want is to use an Inverse Lerp to remap the values to 0-1 range.

float inverseLerp(float A, float B, float T){
    return (T - A)/(B - A);
}

(Where T is the worldPos.z, and A and B are the values/positions the gradient should begin and end at)
Then saturate() to clamp between 0 and 1.
Then apply your gradient. I guess it's single colour but starting transparent?. Can just use the 0-1 value as is in that case, no need to lerp it. If you wanted like a two colour gradient, then could use a Lerp.

regal stag
tacit stream
#

I think I'll try with vector

#

and then other

#

but gotta try first kek

#

yyyep

#

won't work

regal stag
#

Float makes more sense since it's a scalar int, not like an int3

#

But it's possible that it may need changing to float still

tacit stream
#

SetFloatArray is also angered

#

since it's int array

#

annoying

#

gotta work with float array then

crisp nest
#

And I am still getting blackscreen 😦

#

Just like with Graphics.Blit, if I return a specific color in the frag shader, then that color is displayed. But when I sample _MainTex, I get black color only.

regal stag
#

Perhaps the problem is with the shader then? Are the UVs being passed through correctly?
I tend to use an Unlit Shader Graph instead, could try that, with the _MainTex set up in the blackboard (make sure you set the Reference not just name).

#

Could also check the Frame Debugger window. It should be able to tell you what the source texture is, to make sure it's being set correctly

crisp nest
#

I'm confused. It works now, but only sometimes. Sometimes the screen is black. lol

#

I'll try to debug this later

#

but at least it seems to work better than Graphics.Blit so far, lol

crisp nest
#

I feel so stupid

digital gust
crisp nest
#

For some reason my camera was somewhere at the edge of the world

#

That was why I was only seeing black!!!

#

My camera controller was fucking around

#

._.

near field
#

why is dis happening lol?

amber saffron
lean lotus
#

why doesnt HLSL have a #define kind of thing, so I could change a 1 to a 0 and have the compiler get rid of parts of my code?

regal stag
lean lotus
#

wait wha

#

wtf I thought it threw an error before! omg

long shadow
#

Heya
Quick question
Is there any way to input a Gradient from the inspector, using Shader Graph?

#

Or modify a gradient

regal stag
tacit stream
#

How can I add option in my shader to show Enable GPU Instancing option for materials?

#

so that I don't have to enable instancing in code (that's because I can't since I have no main thread access)

astral yew
#

So currently I use scrolling UV to distort a line like this and the line is a Texture2D (this works fine because I can just put the UV into the UV field on SampleTexture2D). Instead of a static line texture I also want to use a Fresnel Effect, but I am having trouble with it.
Would it be possible to either convert that Fresnel output into a Texture2D or apply the scrolling UV to the output directly?

astral yew
#

Yeah, thanks. Guess I was going at it with a more complicated approach than I needed to

knotty juniper
#

you have to see if it works for your case

unborn anchor
#

hey, can someone tell me how the enum node in shadergraph works? if i switch it out for a float it works perfectly. but i want to make it work with the enum node

tacit stream
#

I bet it's same thing and it's enum only on editor end

frank prairie
#

i imported a water pack but looks like it got a bug, because the texture are set on the material but the material are pink, someone know why?

neat hamlet
#

The assets are in a different pipeline than your project, looks like

tacit stream
#

wait what

#

does it mean I can't create shaders with gpu instancing?

#

if I'm using srp

#

my goal here is to call render method myself, not relying on anything at all

scenic raptor
tacit stream
#

How to access single material property block through custom function in graph?

slate wedge
#

hello, any idea why my shader specifically wont display the color blue?

slate wedge
#

I set the blend to multiply and now I can see blue in the preview and on materials again, but it left a light grey background

regal stag
# slate wedge

By dragging a Vector4 output into the Alpha port (which is Vector1/Float) it takes the first component, in this case red. So any values that don't have red end up as fully transparent.
If the Vector4 has an appropriate alpha channel, use a Split node to obtain the A channel.

slate wedge
#

alright, thanks :)

regal stag
# scenic raptor I would be happy if some could up vote this issues https://issuetracker.unity3d....

Assuming I've recreated the issue properly, I don't think it's really a bug - it's kinda just a quirk of how keywords work.

The problem is mostly that keywords inside SubGraph don't have the option to be exposed, which is important to be able to set the default value. The same issue occurs in the main graph if the keyword is not exposed. (Even regular properties have the similar issue, Non-exposed properties aren't serialised in the material so default to 0 regardless of the value set in SG. The defaults in that case are just for preview purposes)

I guess it could be fixed if keywords could be exposed from subgraphs. But otherwise you can currently create the same keyword in the main graph in order to expose it.

Also regardless of the exposed state & default value, the keyword still works correctly if set from C# (material.EnableKeyword / material.DisableKeyword), or by accessing the debug inspector and manually adding the keyword.

unborn anchor
scenic raptor
# regal stag Assuming I've recreated the issue properly, I don't think it's really a bug - it...

But in shader graph there is the possibility to set the default value and therefore I as a user would assume that setting this value also works somehow 🙂

Otherwise you can leave the check mark off and then the bug is that there is an option there.
But then you would also have to disallow keywords in sub graphs.

The problem with setting the same keyword in the main graph is, when I want to reuse my sub graph (for example for lighting, I have to set a lot of keywords for that).
All my shaders should share the same sub graph with my lighting keywords and nodes. But I don't want to declare all keywords on the main shader again.

That is what I did before 2021.2f8 was released, there was another bug I reported, where adding keywords to a sub graph evoked an error and your sub graph crashed. Now this is fixed, but we still can't use keywords^^

cerulean dune
#

Hello !
I'm using shader graph to assemblate 3 different shapes (from a 2D Texture Array) that can each have a different color
When I have 2 colorized shapes, I lerp them with the "T" node set to the 2nd shape's alpha (the 2nd shape is onto the 1st shape)

I've been trying a lot of different things like :

  • Testing every options of the Blend node with different parameters
  • Changing every options of my 2D Array Texture that contains the shapes (linear, bilinear, clamp, repeat, size, ...)
  • Exporting from photoshop without any pixel containing opacity (so every pixels with opacity would be set to 1)
  • etc...

But I still have this issue when lerping the shapes :
The 2nd shape won't overwrite totally the first one, there'll be a thin line separating these shapes

#

easier to see in preview :

#

I assume that the alpha of the 2nd shape are kept when lerping, so the background (which is grey in my case) will be visible

#

Any idea of how to solve this ? Would help me a lot, I'm not sure to understand why it's doing that

unborn anchor
#

in shadergraph

cerulean dune
unborn anchor
cerulean dune
unborn anchor
#

?

cerulean dune
#

Not sure to understand

#

What do I have to change ?

unborn anchor
distant lintel
#

I have a Problem with my Shader: In the main preview you can see that the alpha value is always one even though I have the branch note for the Alpha channel.

dusky vessel
#

is it best to learn shader graph or go straight into GLSL as a beginner?

shadow locust
distant lintel
unborn anchor
#

also, with shadergraph you can much easier understand how your 'code' transforms your data visually in real time, which is especially good for beginners, but also insanely helpful for intermediates and professionals

vague sinew
#

Hey guys, I'm trying to make my texture shaders not look "glossy"... I only get the desired lighting effect if I set them to metallic but then they look glossy... Any ideas?

frank prairie
#

Guys, i have one doubt, i saw one guy using RGB to do a mask texture, but he didnt saved the file with the Alpha texture where it contain the smoothness, its not right to select the alpha to save togheter with the others RGB channels?

grizzled bolt
frank prairie
lone bone
#

my preview keeps turning blue, and i have to right click and hit sphere again to make it properly preview.

vocal narwhal
lone bone
vague sinew
#

Hey! How could I translate this piece of code to shadergraph?

fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
if (length(IN.uv3_Tintmap)) {
  fixed4 tintmap = tex2D(_Tintmap, IN.uv3_Tintmap);
  c *= fixed4(tintmap.bgr, 1.0);
}
amber saffron
# vague sinew Hey! How could I translate this piece of code to shadergraph? ``` fixed4 c = tex...

fixed4 c = tex2D(_MainTex, IN.uv_MainTex)
sample main tex

if (length(IN.uv3_Tintmap))
length node with "UV3" as input. Plug in comparison node and compar "if > 1)
From that, use to boolean to branch.

If false, do nothing, an use the sample from main tex.

If true :

fixed4 tintmap = tex2D(_Tintmap, IN.uv3_Tintmap);
sample "tintmap"
c *= fixed4(tintmap.bgr, 1.0);
swizzle to brg (split output of sample, and combine in vector4 using the right order), and multiply with main tex sample

vague sinew
#

Thanks!!

#

Like this, I guess?

amber saffron
#

Looks almost correct. I'm not sure for the swizzle order, it's not easy to read 🙂
it should go from RGB > BRG
And no connection to alpha, as it's forced to 1

#

Ah, also

#

the comparison input is wrong

#

It's not the length of the sample that is tested, but the length of the UV3. You'll need to add a UV Coordinates node

vague sinew
amber saffron
#

Looks like you're trying to create a node from an existing connection. The UV node is only outputting, so the search will not find a corresponding input

vague sinew
#

So I match the channel on the texture to the channel on the node and that's all?

amber saffron
#

Yes. That's what the code was doing.
The swizzle still is wrong 😅, alpha to 1

vague sinew
#

I mean, I flipped R and B, do you mean the output?

#

c *= fixed4(tintmap.bgr, 1.0);

amber saffron
#

Yes, the flip seems correct now, but in your screenshot alpha is 0

#

should be 1

vague sinew
#

Oh okay, I think it's correct now

#

Thank you!

amber saffron
#

👍

vague sinew
#

The colors seems a bit washed, is there anything shader-wise I can do about it?

distant sleet
#

Quick question, as the visual studio extension for hlsl doesn't get built in unity functions in shaders is there a way to ignore just this error and not all instances of an unexpected token?

polar vector
#

Hi, does anyone have an idea how to get the blend part of the right result (a texture2d made in an art application) to be applied in a shader when two objects overlap? I've tried all blend modes that I know of and cant quite get the same result which seems like the "correct" result of blending the two colors according to art applications (left is shader, right is the art program texture)

smoky cobalt
#

Hello. I'm new to unity and shaders. I want to improve the look for an app(android) Can someone help me? 😄

vague sinew
#

Is it possible to make a texture unlit shader receive other objects shadows? If so, how? I can only find things regarding toon shaders and such

grizzled bolt
vague sinew
#

I see... Another one then

#

I'm trying to create a node which will get rid of the magenta of my textures, this works but results in some fuzziness, how could I add some "tolerance" to the input color?

regal stag
regal stag
vague sinew
#

The color mask kinda works but its fuzziness and range params don't quite help me get there because the magenta as it gets closer to other colors starts to blend so the mask won't pick it up anymore

#

resulting in something like this (with range and fuzziness at 0)

regal stag
vague sinew
#

It starts to “eat” more of the texture but I think that’s something I’ll have to live with

regal stag
polar vector
#

Unfortunately no, this is Blend SrcAlpha OneMinusSrcAlpha (left) - goal is right

#

and this is One One @regal stag

grizzled bolt
#

The blending on the right is the gamma incorrect average of the colors

polar vector
#

So painting applications give gamma incorrect averages? I'll checkout the video, basically what gives the right color is

float amount = 1 - srcAlpha;
float alphaCombined = backgroundAlpha * amount;
float newAlpha = backgroundAlpha * amount + srcAlpha;

Color c;
// For all rib
c = (backgroundColor * alphaCombined + srcColor * alpha) / newAlpha
c.a = newAlpha

where backgroundColor is the color which srcColor is trying to blend with, in this case
backgroundColor is red and srcColor is green

clear vector
#

Is there any way to find all variables (not properties) in shader? What i need is to get string names of all StructuredBuffer in my shader

polar vector
#

Nvm it seems you're right @grizzled bolt when changing the render mode to gamma instead of linear it fixes it so I'll decide what to do based on that, thanks a lot! Huge help

grizzled bolt
polar vector
#

Yeah ahah I'm going for a painting application inside my game basically to let users draw backgrounds and everything for their own levels, so ill have to think is it better to modify the equation to be gamma corrected or just go with gamma color space

grizzled bolt
#

Though this is a bit of a tangent

polar vector
#

Thanks, I'll take a look at it

amber saffron
vague sinew
#

cant you create a material from that shader and extract it from a material some how?

#

like you would with reflection

low lichen
#

A material is only aware of properties, not the actual shader uniforms

misty yew
#

Hi, I was looking into creating a basic shader in Shader Graph that can be used in a line renderer. The line renderer seems to be taking in a Gradient as the color and I found out that I need to have the Vertex Color node to be able to read the gradient. However I noticed that the vertex color node only accepts the first and last keys in the gradient when coloring the line, and skips the rest. It also seems to not read the alpha values properly. I cant seem to find any information about this when googling. I did however find a youtube tutorial on making a shader that works for the line renderer, however that tutorial only seemed to cover a 2-keyed gradient. I must be missing something no?

wooden blaze
#
Shader "Procedural Toolkit/Standard Vertex Color"
{
    Properties
    {
        _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
        _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
        
        CGPROGRAM

        #pragma surface surf Standard

        struct Input
        {
            float4 color: Color;
        };

        half _Smoothness;
        half _Metallic;

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            o.Metallic = _Metallic;
            o.Smoothness = _Smoothness;
            o.Albedo = IN.color.rgb;
            o.Alpha = IN.color.a;
        }

        ENDCG
    }
    FallBack "Diffuse"
}

I know almost nothing about shaders but I was wondering if there is a way to "adapt" this shader to URP? So that it works in the same way, and is compatible with URP

misty yew
wooden blaze
#

what should I do here?

regal stag
# misty yew Hi, I was looking into creating a basic shader in Shader Graph that can be used ...

I would assume the gradient is applied differently based on what vertices are generated by the LineRenderer. It can't pass colours in where there isn't vertices. It might be that if you set the UV to repeat/tile (rather than stretch), or just include more positions along the line, it'll generate more vertices and so can apply more of the gradient to the vertex colours.
Should be able to use the wireframe mode in the scene view to see where the vertices are.

regal stag
# wooden blaze ```cs Shader "Procedural Toolkit/Standard Vertex Color" { Properties { ...

Create the Vertex Color node and connect it to the Base Color port on the master stack.
Also use a Split node on the Vertex Color, and attach the A output to the Alpha port. (Though since the shader is Opaque I'm not sure why this is required)
For the Metallic and Smoothness ports, create Float properties in the Blackboard window (top left, can be toggled with buttons in top right of graph). Rename them, drag the properties into the graph and connect them to the ports.

wooden blaze
regal stag
#

Oh right. The Alpha port only appears if you change the graph type to Transparent (or use alpha clipping) in Graph Settings. But you don't need that so can just ignore setting it

normal grotto
#

Not sure if this is the right channel but my grass which in the picture below uses 2 batches and 2 setpass calls. I would like to know why its so high and how I can change it.

#

The shader is the one attached to it and the grass only consist of 3 faces

#

GPU instancing is also turned on and the grass is not placed by the terrain tools

steel notch
#

So I have a mesh, and a file that basically contains some type of "tag" for each vertex (words like "Left, Right, Bottom" etc).
I want to have a shader that #1, colors the verts based on the tag the vert has, and #2, be able to have it show it's only showing verts that have the tag "Bottom" (or whatever I tell it).
Any suggestions for how to do that?

blissful marlin
#

Every time I compile an apk, every one of my shadergraphs has to "strip vertex programs", which takes a very long time. Any explanation for why this is necessary? I've got 25ish materials all using 1 of 2 ubershaders

clear vector
#

does shader property's id is stable between editor and build? I guess it is just name hash

low lichen
#

https://docs.unity3d.com/ScriptReference/Shader.PropertyToID.html

Each name of shader property (for example, _MainTex or _Color) is assigned an unique integer number in Unity, that stays the same for the whole game. The numbers will not be the same between different runs of the game or between machines, so do not store them or send them over network.

patent lily
#

hi i have a bunch build in RP shader create by shader forge, and i want to convert it all to urp shader, and i did some research, all document says i need to change a lot of stuff like

CGINCLUDE -> HLSLINCLUDE
UnityObjectToClipPos -> TransformObjectToHClip

etc...

but i found a easy way to do, just

"LightMode"="ForwardBase” -> "LightMode"="UniversalForward”

and all it works, except some "GrabPass" issue.
i wonder know is it a good way? or should i completely convert it to urp version like the first method?

dim yoke
patent lily
foggy chasm
#

Hello, I'm new to shaders. I wanna show wireframes of model in game-view. what is best way to achieve that?

tranquil socket
#

How does one go about making a shader work with stereo rendering in VR? I wrote a shader for URP10, and now I have to make it work with Multiview on Vulkan for Quest2.

low lichen
tranquil socket
#

thanks @low lichen !

#

i went over the docs, and found several different pages with partial explainations that didn't make much sense, didn't find this one at all

civic fern
#

hey guys i have a pretty urgent question

#

i have a shader that generates a grid only to be applied across a plane, for obvious reasons, os that it's 2d.

#

i want to be able to rotate this grid, because it's rotation currenly uses world coords so rotating the plane is no use, i dont think

#

this was my best attempt to rotate it in shader graph but obviously the result is not as expected

#

can anybody help?

#

top one is an example reference of the kind of rotation i expected Rotate to mean

ocean karma
#

@civic fern rotate position coords and then use it to create grid

civic fern
#

ohh, that sounds good

#

ty!

leaden radish
#

btw what is recommend to learn shaders or just use shader graph and compute the graphs?

#

also you can open compiled shaders in shader graph or something?

grizzled bolt
green depot
#

Can anyone tell me how to set different shader graph properties per instance? For example I have two planes sharing the same scrolling texture shader that I set up. I'd like for one to scroll faster than the other by typing in a different number in the exposed scroll speed property that I set up.

#

If I type a number in one is automatically changes the other to match it.

#

I'm trying to get away with a single shader for any number of instances but allow each instance to have different numbers plugged into the property fields.

#

After Googling a bit I found my way to the Override Property Declaration checkbox but and read that I have to switch Shader Declaration over to Hybrid Per Instance but it doesn't seem to be making a difference.

regal stag
green depot
#

So if I have 20 planes that I'd want to scroll in different directions or at different speeds I'd have to make 20 materials? There's no way to just use one and be able to adjust those numbers for each different instance?

fervent flare
regal stag
# green depot So if I have 20 planes that I'd want to scroll in different directions or at dif...

Basically yes. You can generate those materials at runtime though, by using a C# script to access renderer.material (where renderer is obtained through GetComponent<Renderer>()). It'll create a clone/instance of the material and automatically assign it. Then use the SetFloat/SetVector/whatever to set the properties.

There's also renderer.sharedMaterial for accessing the material without creating instances.

Depending on the render pipeline there's other options, like Material Property Blocks too, set on the renderer. But they break the SRP batching that URP/HDRP uses.

regal stag
low lichen
fervent flare
#

@regal stag Is there no elegant real solution? The meshes are using the same material so short of making countless instances of the material in the future, I guess it's not solveable?

regal stag
fervent flare
#

@regal stag Damn that seems like a huge drawback and a questionable design decision by Unity 🤯 But yeah in this case I guess I'll have to have one material use an opaque shader.... shame. Thanks a bunch nonetheless once more!

lean lotus
#

is there a way to see how long each compute shader takes to run?

dim yoke
# fervent flare <@!357936113983291393> Damn that seems like a huge drawback and a questionable d...

No, it has nothing to do with unity specifically but the way rasterization based rendering works. Theres some approximations to get quite good looking results but all the ”perfect” solutions are very heavy computationally and therefore realtime 3d engines do not use them usually. Theres usually some ways to hack the ordering using the queue value, scripting etc. Sometimes real transparency isnt even needed. You could probably use opaque rendering with alpha clipping shader if the alpha needs to be only either 0 or 1. Dithering transparency can also look good enough sometimes

vague sinew
#

What is the property that will increase in my texture color the closer it gets to a light source?

#

Is it the magnitude?

#

I'm trying to affect the maximum "brightness" my texture can get when close to a light spot... I have tried this where Multiply is set to a value below 0

grizzled bolt
#

@fervent flare There's also ZWrite that fixes transparency problems in some situations
Though I haven't always had luck getting it to work

gritty gull
#

how do I use the shaders that came with the free asset ... it says cant convert shader to selected pipeline UniversalRP materials

lean lotus
#

how can I see the time each compute shader takes to run? I cant do much else to optimize a unity shader, so I wanna see how long each kernel takes

modern ridge
#

Is there native support in unity for VR 3d video?

#

I've been given a VR 360 3d video by a friend/client who just wants to view it on a VR headset. I'm sure this should be easy in Unity but I can't for the life of me get it to work.

safe summit
#

I found a cool wind shader for leaves, but unfortunately it uses URP, which is incompatible with all my other shaders

#

Is there a way to convert a shader graph to built in pipeline?

#

or maybe use both pipelines?

#

or maybe upgrade my custom built in shaders to urp?

#

Also, I try looking up built in render pipeline wind shader, and all it gives me are urp shaders, is there a better way of looking for those

#

Hold on, I'm trying something, aparently unity 2021.2 has shader graph support for SRP (built in pipeline)

polar relic
#

HDRP shaders have a "After Post Process" option that's really nice for UI elements.
Is there any way to do the same in URP: having a material that's not affected by the post-process phase?

analog karma
#

how do i use multiple textures to make animation with shader graph?

normal cape
#

how do i declare a float array property in my custom shader?

#

i couldn't find any information online

analog karma
#

i'm trying to make caustics

wary jackal
#

Are you talking about a frame-by-frame animation?

analog karma
#

yea

#

i prepared 10 images

wary jackal
#

Well, the most effecient way is to put all of those in a sheet, and then offset the UV every frame or something like that

#

Why would you want to do a frame by frame animation though? It's much more effecient to have two caustic textures and take the min

#

and then just have them scroll at different speeds

#

@analog karma unless you're going for a hand animated look, that tutorial I sent is the way to go.

#

If you know enough about shader graph, you should be able to translate that code into shader graph

analog karma
#

i need a frame by frame solution

#

tried flipbook and doesn't work

wary jackal
#

Why do you need a frame by frame solution?

#

@analog karma

analog karma
#

i'm not really that good with shader graphs

#

and flipbook doesn't work

wary jackal
#

Yeah, but that doesn't answer my question. Why does it have to be frame by frame?

analog karma
#

well because i wanted to make it frame by frame

wary jackal
#

For any particular reason?

analog karma
#

moving it doesn't really make a realistic caustic effect

wary jackal
#

Okay

#

So like I said, put all your images in a spritesheet, and offset the UV every time interval

#

but you'll have to clamp the values so it only plays once per frame or something like that

analog karma
#

this just happens if i use the spritesheet texture

wary jackal
#

I can't really tell what's happening there

#

Do you see in the material where it says UV offset or something like that?

analog karma
#

yea

#

used that and doesn't work

wary jackal
#

wdym doesn't work

analog karma
#

wait i think its working

wary jackal
#

Can you send a quick video? it's very hard to tell what's happening

#

It appears that that screenshot is in a pool. Were you just getting the tiling to be correct?

analog karma
#

yea

#

sorry

wary jackal
#

Okay. And that's with the entire sprite sheet, correct?

analog karma
#

yes

wary jackal
#

Wait so what's wrong with flipbook?

analog karma
#

its probably because it uses the decal projector

#

i used that so it sticks with the surface

wary jackal
#

So are you good? You know what you're doing?

analog karma
#

yea

wary jackal
#

Cool! Glad you got it working

patent lily
#

hi is there any way to convert build in custom surface shader to urp?

dim yoke
patent lily
weary jetty
#

I m using shadergraph in built-in RP.
The problem is SceneColor node is not working as intended even after setting surface to transparent. What other setting(s) I'm missing?

dim yoke
amber saffron
weary jetty
keen patio
#

hi, How to update a part of data to a texture

#

such as there's a big texture2D, I want to upload only 1/2 x 1/2

#

I can come out with one way : upload to a small texture, then copy to a big one in compute shader

gusty grove
#

hi all, i have a lil issu on shader graph.
Why the "tiling node" dont tile the "rectangle" node ?

#

Well, sorry. But why?

grand jolt
#

I have a question about that v2f parameter I called input

I understand that I have declared a fragment function with a fixed4 return type and assigned a v2f parameter called input

I don't see anywhere in my shader code neither the vert nor the frag functions being called and by extension no paramaters being passed into them

Do I assume this is done behind the scenes and the CGProgram knows what parameters to pass into my vert and frag functions?

With all of this said, my actual question is: Does CGProgram know it should pass the output of my vert function into the v2f input parameter?

untold shoal
#

I have a shader question but it isnt for unity, but im honestly out of ideas so I figure I should ask here anyway!
Basically the way my game is set up every sprite in the scene is drawn to a quad and tilted at a 45° angle for depth sorting.
Now the player is an actual 3D model, not a sprite.
I need the player to be drawn and then ideally flattened and tilted to a 45° angle too. Im trying to figure this out via a shader but every single one of my attempts has failed thus far. Any ideas on the math for this ?

amber saffron
# gusty grove Well, sorry. But why?

"Tiling" in that context takes the assumption that you will use the tiled UVs with a sample texture node and a texture that has a tiling mode set to "tile". It won't work as well for "clamp" texture.
This name directly comes from the "tiling / offset" parameters of the standard shader I guess.

And the rectangle mask is a shader node that draws a rectangle based on coordinates.

After the tiling&offset node, the UV values go far over 1, beeing outside of the "grid" for the rectangle to be drawn.
But by using the fraction node, you keep only the fractional part of the UV coordinates, so it transforms this 0>0.5>1>1.5>2>2.5>3>3.5>4... to a repetition of [0;1) ranges
And as such, the rectangle mask is itself done in all those smaller grids.

amber saffron
grand jolt
amber saffron
# untold shoal I have a shader question but it isnt for unity, but im honestly out of ideas so ...

You should be able to "squish" the vertex coordinate of your player mesh along the world forward axis, maybe not full flat but "very flat" (else you might end up with z fighting). This needs the object to world matrix to work.
Then rotate around the pivot, still in world coordinates, and finally transform the coordinates in view space for rendering (or ... clip space ? I'm always confused with the namings)

You might want to keep some track of the original coordinates in the interpolator if you're doing dynamic lighting in the fragment shader though.

gusty grove
untold shoal
#

but ill try another approach

spring sparrow
#

Anyone know of a smart way to handle led color changes/patterns in Shader Graph?

fossil ermine
#

What could lead to there being such a major difference between what's shown in the editor vs how the shader looks on mobile?

  • The shader was made using shadergraph + a render texture.
  • The mobile build is running on Vulkan

Thanks in advance!

steel notch
#

So I have a 3D Texture here

#

When I turn the alpha down it creates this nice transparent look.

#

However when I toss it into the scene with the shader provided by Unity, turning down the alpha makes the cube look like this.

#

How do I get it looking like what's in the inspector?

fleet rampart
#

does purple mean something is not working correctly?

regal stag
fleet rampart
#

but 1 still gives me purple

regal stag
steel notch
#

can URP not do this?

regal stag
# steel notch can URP not do this?

Should be able to. There's a VolumeShader example at the end of the docs page you linked, is that what you're using? Does it not work in URP? (though ideally even if it does work, should convert it to a URP shader so it supports the SRP batcher)

steel notch
fleet rampart
#

is there a shader where i can combine the metallness and specular option at the same time

#

in hdrp

arctic flame
#

hi everyone

#

i've made a shader in unity 's standard that does a cubic projection of a texture in world space

#

could i please get a hand in turning it into a cylindrical projection? i'm not sure what i need to do

misty plover
#

How to access properties of TextMesh Pro Shaders at runtime via script? eg turn off Glow, change an Underlay's parameters or any of the other values shown in the Inspector of these shaders.

vocal narwhal
misty plover
vocal narwhal
misty plover
vocal narwhal
misty plover
vocal narwhal
#

switch your inspector to Debug Mode and look at the properties. Turning things on and off might require looking at the shader keywords

#

Seeing as TMP is a package you can easily look at the shader source for the associated feature

#

Use EnableKeyword/DisableKeyword with those

misty plover
#

Really ignorant. Having enabled a keyword, do I then set to true/false to turn Glow/Underlay etc on/off?

vocal narwhal
#

The keyword being enabled/disabled is its functionality being on or off

misty plover
#

Has this been done before? I can't find examples of this with TMP.

misty plover
#

Cheers! Feels like there are about 10 things to do to make even small changes. Not as straight forward as imagined.

misty plover
vocal narwhal
#

Nope

#

I like text as plain as possible 😛

misty plover
royal night
#

I tried to remove the wave/grass tint from the grass when wind is applied via https://answers.unity.com/questions/541456/why-does-the-grass-change-color-by-default.html and copying the terrainEngine.cginc over to my local project, is there some better way to replace / force it to use my new copy?

Other than just editing it in the actual unity editor folder which, I would like to avoid since I work on multiple projects

#

Barring that, I'm willing to copy over the whole terrain shader itself, and make a new MAT via that to force it but I can't seem to figure out where the actual shader code is for that 😐

gusty grove
#

Hello everyone,

I am currently working on a version of shader graph that does not allow me to add a boolean keyword directly in the shader graph editor.
Is there any way I can add one by another method than directly the editor?

royal night
#

Welp, nvm found the actual code, and ended up replacing refs/includes in all the places that mattered to my replacement TerrainEngine.cginc, and it seems to be working,

lean lotus
#

what do i need to do to get WaveActiveCountBits to not error in a compute shader?

lean lotus
#

also isnt groupshared memory in compute shaders supposed to be faster to write to and read from then say just declaring an array in a compute shader?

wise willow
#

How can I write to the _ShadowMapTexture buffer?

halcyon warren
#

How could i make my shader not effect certain faces?? Edit: It would be a cylinder, and i don't want to apply the shader to the two end faces

dim yoke
lavish oasis
#

Any way to figure out whats the bad part of the shader?

lean lotus
#

is there a way to get intrinsics from shader model 6 into my compute shader? on unity 2020.3.20f1, but willing to upgrade if i means I can get WaveActiveCountBits to work

#

and why are my compute shaders both D3D11 and D3D12, but I dont get anything from shader model 6.0

#

or when I try to use WaveActiveCountBits, it errors out

#

i basically need an HLSL equivilant of CUDA's activemask

knotty yarrow
#

do anyone knows why is all the custom shader graph material are not working on android build

#

it works perfectly fine on editor

#

but when i build it

#

all of the material that made using shader graph are not working

#

its just pink

cosmic prairie
knotty yarrow
#

yeah its android 10

meager pelican
# lean lotus also isnt groupshared memory in compute shaders supposed to be faster to write t...
GPUOpen

Sebastian Aaltonen, co-founder of Second Order Ltd, talks about how to optimize GPU occupancy and resource usage of compute shaders that use large thread groups.

rare swan
#

I need some help, i'm using shader graph to create a shader that makes a material's emission change over time randomly to create a pulsating effect. In order to complete the effect I need to sample the value from the emissive levels and apply it to the brightness of a point light

#

I intend on doing this via script, I got to this point

#

test and test 4 are an attempt to read the color and emissive values (only output on both is (1,1,1,1) ), test 3 is currently unused, test 2 points to the object I want to get the material from

#

I am able to point the script to the material but I have no luck in getting the emission value

#

unless there's some way to read the variable directly from shadergraph

zealous oriole
#

Ok. I'm having trouble with a set of materials not updating on shader change during runtime. I change a color property but there's something not re-rendering. It's a set of materials on a single meshrenderer. Is there a way to force the mesh renderer to re-draw or even just update its instanced materials?
I think this should change the color being rendered but it doesn't:
MeshRenderer myMeshRenderer = prismMeshRenderer; Material rendPrismTop = myMeshRenderer.materials.First(mat => mat.name.Contains(matPrismTop.name)); rendPrismTop.SetColor("ColorTop", letterNoMatchLightColor); Debug.Log("Top Renderer Color:" + rendPrismTop.GetColor("ColorTop"));
Is there a way to force a re-render of a single mesh?

zealous oriole
#

Your 'multiply' and 'color mask' coming out of the top only has one output and you're pushing it into a Vector3. That MIGHT cause a problem. Not sure. My guess is what's happening is happening because you're applying a single scalar to Vectors. Is the 'axis' the motion is moving across the X, Y, or Z axis, or is it some weird combination of the three?

#

Right, but your final multiply output stages are both scalars (one dimensional) and therefore will probably multiply whatever you're multiplying by a single factor, ergo a single direction of noise. But that's just my rough guess.

brittle wyvern
#

Hi everybody, I'm trying to do some post processing effects for VR. I've followed this article in order to blit properly in VR:

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@13.1/manual/renderer-features/how-to-fullscreen-blit-in-xr-spi.html

But the article explains only how to blit the _cameraOpaqueTexture. How can we blit including transparents?

I tried using the renderer.cameraColorTarget but this doesn't seem to break the stereo and the image appears only in one eye and with wrong perspective. Any ideas?

#

Thank you in advance for any help, quite lost here

terse crescent
#

How to do background mountains?

dull lintel
#

Silly question maybe, but is there a way to automatically align/straighten nodes to their inputs like in UE4?

languid zodiac
#

Is there in the urp any global variable that describes shadow distance that was set in the quality settings?

regal stag
regal stag
# languid zodiac Is there in the urp any global variable that describes shadow distance that was ...

Not too sure. One of the components of _MainLightShadowParams (maybe z?) might help calculate it since it's used to fade shadows at that distance. Would have to look through Shadows.hlsl. https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl

Alternatively if the value is needed probably just set a global variable yourself (via Shader.SetGlobalFloat/Vector)

regal stag
# brittle wyvern Hi everybody, I'm trying to do some post processing effects for VR. I've followe...

Before calling DrawMesh, you'd pass the render texture you want to draw into the shader via setting a global texture id. e.g. cmd.SetGlobalTexture("_MainTex", source) (then use _MainTex in the shader, rather than _CameraOpaqueTexture).

I haven't been able to test this properly for VR, but I have a version of a renderer feature (somewhat based on that article) here. (The repo is still named "blit" but this branch uses DrawMesh) : https://github.com/Cyanilux/URP_BlitRenderFeature/tree/cmd-drawMesh
(If you try using that and it works, please let me know~)

languid zodiac
regal stag
# rare swan I intend on doing this via script, I got to this point

You can't set/read shader variables on the C# side, that's not how shaders work. GetColor will only obtain the values set on the material (via the inspector or previous SetColor calls).
If you need the value on the C# side it would be best to calculate it in the script, then pass the colour to the shader (e.g. renderer.sharedMaterial.SetColor(...))

regal stag
# zealous oriole Ok. I'm having trouble with a set of materials not updating on shader change dur...

I believe .materials returns a copy of the materials, so you need to store the array in a variable, alter it, then pass it back. Try :

MeshRenderer myMeshRenderer = prismMeshRenderer;
Material[] mats = myMeshRenderer.materials;

Material rendPrismTop = mats.First(mat => mat.name.Contains(matPrismTop.name));
rendPrismTop.SetColor("ColorTop", letterNoMatchLightColor);

myMeshRenderer.materials = mats;
#

Make sure that the shader you are using is also using the property name "ColorTop". It might expect something like _ColorTop instead? Hard to tell without seeing the shader.

#

If you are trying to post code, use code blocks like "``` code ```"

zealous oriole
#

It's a custom shader I made. Should I be naming my variables to _ColorTop?

#

Note that this is in the URP.

regal stag
#

Is it shader code or shader graph?

zealous oriole
#

I've been messing around with property blocks, E.G.

            MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
            myMeshRenderer.GetPropertyBlock(propertyBlock, i);
            propertyBlock.SetColor(2, letterNoMatchLightColor);
            MaterialPropertyBlock propertyBlockTwo = new MaterialPropertyBlock();
            myMeshRenderer.GetPropertyBlock(propertyBlockTwo, i);
            propertyBlockTwo.SetColor(3, letterNoMatchLightColor);
            myMeshRenderer.SetPropertyBlock(propertyBlock, i);
            myMeshRenderer.SetPropertyBlock(propertyBlockTwo, i);
#

Shader graph

regal stag
#

You shouldn't really be using Material Property Blocks in URP as it breaks the SRP Batcher. Keep using the .materials approach instead.

zealous oriole
#

Ok then.

regal stag
#

The string used in the SetColor call should be the "Reference" of the property in Shader Graph, which isn't always the same as the display name you give it. It should be a field under the property settings. e.g. can see here it's Vector1_481c... but that can also be changed to something more readable.

#

In 2021.2 it automatically tries to match the reference to the name now, but adds a _ to the start.

zealous oriole
#

Should I be able to see the shader properties if I look them up with :
mats[7].shader.FindPropertyIndex("TopColor");

#

Because I don't. They never have values when I try that way. I can't see the values with the index either. It's weird.

regal stag
#

It might not be able to find the property as you aren't using the correct reference? As I've tried to explain above, it's the Reference field that is important here, not the property name.

zealous oriole
#

Yeah, it looks like that was what I was doing wrong.

#

Thank you. I have been messing around with this for almost a full day.

#

Yeah, that's EXACTLY what I've been doing wrong. Can't thank you enough.

regal stag
#

I would assume the offset is only occurring on one axis because you use the Normal vector in tangent space - which I'm pretty sure is just always (0,0,1) as that's how tangent space is defined. The various multiplies will scale that but won't change the 0s which keeps it only on the z axis.

hot blaze
#

hi everyone i am working on urp shader graph and got this trouble. the outline only appear in scene view.

#

thanks

lean lotus
zealous oriole
vague orchid
#

Hello , how to get a Object to appear partly Wet, i want an "Effector " Sphere to make it wet where the sphere hit the object . Hope somebody could guide me in the right direction ... or tell me where i should do some more reserch to figure it out

halcyon warren
#

What would be the best way to create a fire beam that follows a path. At first i thought of procedurally generating a mesh and applying a shader but I feel like there has to be a better way no??

zealous oriole
#

I might try a particle system, personally.

wraith inlet
# halcyon warren What would be the best way to create a fire beam that follows a path. At first i...

This time we are going to see how to make particles follow a path in Unity. With the Particle System and with Visual Effect Graph. Bezier curves are a most when it comes to this, so let's see how to use them here!

Realistic Smoke Flipbook Texture: https://www.patreon.com/posts/61632332
Sebastian Lague Path Creator: https://assetstore.unity.com/...

▶ Play video
halcyon warren
civic panther
#

how do i make a PBR?

devout dirge
#

in the shader graph

#

anyone else who has tried to make a gouraud shader that works with multiple lights?

I currently figured out how a phong shader works but those seem to be better documented for 'multiple light' use cases

manic abyss
#

guys im starting out with shaders, i wanted to know how I could make a shader that converts all colors to black, but outlines everything the player sees with blue color

#

would this be possible in unity shaders? I come from unreal and there it was just a slider

#

and i dont mean like, having to make new materials for everything and then make changes to those materials

#

i want to make it affect whatever the player sees

lone bone
#

is there a way to make a cube "Filled"? When the camera is inside this cube it looks hollow, but id rather the whole inside be black

#

im trying to make a 3d spherical mask effect, kind of like the one in Outer wilds DLC where you drop the lantern and it makes a bubble of vision. Basically, you can see stuff within the sphere, but everything outside the sphere looks black

tacit parcel
civic panther
regal stag
civic panther
#

Thx

regal stag
# lone bone is there a way to make a cube "Filled"? When the camera is inside this cube it ...

Either flip the faces in your modelling program (in Blender this is done by flipping normals) or use a shader set to Cull Front, rather than Cull Back. Or Cull Off / Two-Sided.

As for the second part of the question you'd want to send the position and radius of your sphere into the shader and compare it against the fragment position (probably all in world space). e.g. https://www.patreon.com/posts/26438849

brittle wyvern
#

@regal stag Thank you very much for the sample code. This is exactly what I was doing, but I have problems when using a render texture as target, I thought the problem was how I was blitting, but it might be how I'm configurering the render texture.

So I do exactly the same approach to blit the cameraColorTarget to a render texture that I create. In the frame debugger I can see that the cameraColorTarget is a texture2dArray that includes left and right eye. After blitting, the temp texture array only has the left eye, and the right eye is gone.

#
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
            {
                var cmd = CommandBufferPool.Get();
                var camera = renderingData.cameraData.camera;
                if (camera.cameraType != CameraType.Game)
                    return;

                // Create temp Render Texture
                if (tempRT == null) 
                {
                    var descriptor = renderingData.cameraData.cameraTargetDescriptor;
                    tempRT = new RenderTexture(descriptor);
                }

                int taaSourceTex = Shader.PropertyToID("_SourceTex");

                using (new ProfilingScope(cmd, m_ProfilingSampler))
                {
                    var cameraColorTarget = renderer.cameraColorTarget;

                    // Stereo color blit to temp RT
                    cmd.SetGlobalTexture(taaSourceTex, cameraColorTarget);
                    cmd.SetRenderTarget(tempRT);
                    cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, material, 0, 2);

                    // Blit result back to camareColorTarget
                    cmd.SetGlobalTexture(taaSourceTex, tempRT);
                    cmd.SetRenderTarget(cameraColorTarget);
                    cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, material, 0, 2);
                }

                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();
                CommandBufferPool.Release(cmd);
            }

#

The color blit shader looks like this:

         struct AttributesTest
         {
            float4 positionOS : POSITION;
            float2 uv         : TEXCOORD0;
            UNITY_VERTEX_INPUT_INSTANCE_ID
         };

         struct VaryingsTest
         {
            float4 positionCS : SV_POSITION;
            float2 uv         : TEXCOORD0;
            UNITY_VERTEX_INPUT_INSTANCE_ID 
            UNITY_VERTEX_OUTPUT_STEREO
         };

        VaryingsTest VertTest(AttributesTest v)
        {
            VaryingsTest o;
            UNITY_SETUP_INSTANCE_ID(v);
            UNITY_INITIALIZE_OUTPUT(VaryingsTest, o); // Do I need this?
            UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
            o.positionCS = float4(v.positionOS.xyz, 1);
            o.uv = v.uv;
            #if UNITY_UV_STARTS_AT_TOP
            o.positionCS.y *= -1;
            #endif
            return o;
        }

        TEXTURE2D_X(_SourceTex);
        SAMPLER(sampler_SourceTex);

        half4 FragTest(VaryingsTest i) : SV_Target
        {
            UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
            float2 uv = UnityStereoTransformScreenSpaceTex(i.uv); // Do I need this?

            float4 _LeftEyeColor = float4(0,1,0,1); 
            float4 _RightEyeColor = float4(1,0,0,1);
            float4 _color = lerp(_LeftEyeColor, _RightEyeColor, unity_StereoEyeIndex);

            float4 _sample = SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, uv);

            return _sample * _color;
        }

#

But this is what happens

#

the RT seems to only have the right eye, and it breaks XR, in the end I get just a black screen

#

I've recently found out that RenderTextures have this vrUsage option, might this be related to the problem?

#

I thought the RT would be fine as I'm using the cameraColorTarget descriptor to create it...

regal stag
regal stag
# manic abyss guys im starting out with shaders, i wanted to know how I could make a shader th...

For those kinds of outlines you probably want to look into edge detection in an image effect. If you're in the Universal RP : (https://alexanderameye.github.io/notes/edge-detection-outlines/)
Or for Built-in RP (& Post Proccessing package) : (https://roystan.net/articles/outline-shader.html)

manic abyss
#

my current problem is making the fill colors of objects to black

#

still working on it

brittle wyvern
#

@regal stag Wao! you are right, this makes me so happy, I spent the last 3 days trying everything, this is really cool! thank you 🙂

#

@regal stag how is that fixing it exactly? I'm trying to look at the constructor but probably you can give me a hint

regal stag
brittle wyvern
#

Also, I see in your example that you don't use this:

UNITY_INITIALIZE_OUTPUT(VaryingsTest, o); // Do I need this?
float2 uv = UnityStereoTransformScreenSpaceTex(i.uv); // Do I need this?

Are those required ? I didn't get very well from the article what those are doing

#

I believe the last value of -1 corresponds to "all slices"
ahhh, amazing, thnx

#

actually, I was trying to do this before:

//cmd.SetRenderTarget(tempRT, 0, CubemapFace.Unknown, 0);
Blit once
//cmd.SetRenderTarget(tempRT, 0, CubemapFace.Unknown, 1);
Blit again

didn't notice there was a -1 option

#

great 🙂

manic abyss
#

guys whats the difference between coded shaders and shaders made in shader graphs?

regal stag
regal stag
manic abyss
#

ok

#

thx

brittle wyvern
#

Is there a way to detect if a shader is in vr (single pass instanced stereo) ?

#

#if UNITY_SINGLE_PASS_STEREO
return float4(0,0,1,1);
#endif
this does not seem to work

#

oh, this seems to work:

        #if defined(UNITY_SINGLE_PASS_STEREO) || defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
civic panther
#

i made a lit shader graph and the tutorial i followed wants me to connect the vertex color to the albedo but there isn't an albedo connection point

regal stag
civic panther
#

thx

#

still very purple

regal stag
civic panther
regal stag
#

Above that. Button with "Save Asset"

civic panther
#

ah

#

does this look right?

regal stag
# civic panther does this look right?

The graph looks fine. The project probably isn't configured to use the same pipeline that the graph is using for it's target (under Graph Settings in Graph Inspector window). If it's URP, make sure you've created a pipeline asset and assigned it under Project Settings -> Graphics. See what I linked above.

civic panther
#

ah

sharp delta
#

Hi, how do I expose the channel mixer parameters?

amber saffron
sharp delta
#

sad..

#

Also is the custom function node broken?
As soon as I add any output to it, it gets an error.
This seems to happen in all the later than 2019(?) versions Unity..
https://tinyurl.com/y9skn6xx

amber saffron
amber saffron
# sharp delta sad..

You could however re-create it's behaviour and expose all the settings you need.

sharp delta
#

Do these things relate to having the Sample Buffer node in place? 🤔

sharp delta
#

so we do have a node, but if I want to expose it's parameters I should write my own hm

sharp delta
#

this is from the Channel Mixer node ^

amber saffron
sharp delta
#

true 😅

amber saffron
#

And the 9 floats OutXinX are the weights

dim yoke
sharp delta
#

My thought about this, is that maybe, I could edit the channel mixer nodes code, to expose the parameters

#

should be just a few lines

low lichen
dim yoke
#

even if compiler is mart, i kinda doubt it's that smart

amber saffron
#

I've pinged the devs, it could be an old code shenanigan

sharp delta
#

ignore the smoothstep node

amber saffron
sharp delta
#

the second option seems easier xD

#

so what's the thing with the custom function node?

amber saffron
#

IDK, I mean, it should just work 🙂

#

It's not immediately working when you create the node because it needs setup

sharp delta
#

🧠-> 🚮

brittle wyvern
#

Does anybody know anything about GetStereoProjectionMatrix and GetStereoViewMatrix in VR? I'm always getting the identity matrix, does that make sense?

                    var proj = camera.projectionMatrix;
                    var view = camera.worldToCameraMatrix;
                    var viewProj = proj * view; // Not identity matrix!

                    Matrix4x4 viewProjLeft = Matrix4x4.zero;
                    Matrix4x4 viewProjRight = Matrix4x4.zero;
                    if (renderingData.cameraData.xrRendering) {
                        Debug.Log("Camera stereo");
                        var projLeft = camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
                        var viewLeft = camera.GetStereoViewMatrix(Camera.StereoscopicEye.Left);
                        viewProjLeft = projLeft * viewLeft;
                        Debug.Log($"viewProjLeft: {viewProjLeft}"); // identity matrix!

                        var projRight = camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
                        var viewRight = camera.GetStereoViewMatrix(Camera.StereoscopicEye.Right);
                        viewProjRight = projRight * viewRight;
                        Debug.Log($"viewProjRight: {viewProjRight}"); // identity matrix!
                    }
brittle wyvern
#

camera.stereoEnabled is also always false... so desperate hehehe

regal stag
#

For distortion/wind on foliage I usually just use a sine based on the worldspace position, e.g. https://www.cyanilux.com/tutorials/soft-foliage-shader-breakdown/#wind
But noise also works as long as you can map it to the geometry without seams. If two connected quads are mapped to completely different parts of a texture for example, that creates a seam in the UV coordinates so the noise generated also has seams.
Currently you're using the Position node as the uvs for the noise so it shouldn't be producing seams though. It's hard to tell just from the graph where the problem lies. While debugging it's usually useful to output values to the fragment color/emission so you can see how it applies to the model and you should be able to see the seams (where values change abruptly)

half tide
#

Hey can anyone guide me through how to make a normal map scroll in unity? I have been searchig for the last 2 hours

half tide
brittle wyvern
#

Unity seems to do the same for the HDCamera:
from https://github.com/Unity-Technologies/FPSSample/blob/master/Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs

           if (camera.stereoEnabled)
            {
                textureWidthScaling = new Vector4(2.0f, 0.5f, 0.0f, 0.0f);
                for (uint eyeIndex = 0; eyeIndex < 2; eyeIndex++)
                {
                    // For VR, TAA proj matrices don't need to be jittered
                    var currProjStereo = camera.GetStereoProjectionMatrix((Camera.StereoscopicEye)eyeIndex);
                    var gpuCurrProjStereo = GL.GetGPUProjectionMatrix(currProjStereo, true);
                    var gpuCurrViewStereo = camera.GetStereoViewMatrix((Camera.StereoscopicEye)eyeIndex);
GitHub

A first person multiplayer shooter example project in Unity - FPSSample/HDCamera.cs at master · Unity-Technologies/FPSSample

#

but I get always false and identity matrices 🙂

regal stag
half tide
#

It just treats it as a texture after this and doesn't let me input it into normal slot

regal stag
#

Unless you really do want per-vertex normals, in which case use a Sample Texture 2D LOD node.

half tide
#

Really appreciated, thank you

south temple
#

I'm trying to convert glsl code to hlsl but i'm not getting the same result, and I think i maybe know the code where the problem comes from.
Can you guys confirm if this in glsl:

mat4 calcRotateMat4X(float radian) {
    return mat4(
        1.0, 0.0, 0.0, 0.0,
        0.0, cos(radian), -sin(radian), 0.0,
        0.0, sin(radian), cos(radian), 0.0,
        0.0, 0.0, 0.0, 1.0
    );
}

mat4 calcRotateMat4Y(float radian) {
    return mat4(
        cos(radian), 0.0, sin(radian), 0.0,
        0.0, 1.0, 0.0, 0.0,
        -sin(radian), 0.0, cos(radian), 0.0,
        0.0, 0.0, 0.0, 1.0
    );
}

mat4 calcRotateMat4Z(float radian) {
    return mat4(
        cos(radian), -sin(radian), 0.0, 0.0,
        sin(radian), cos(radian), 0.0, 0.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0
    );
}

mat4 calcRotateMat4(vec3 radian) {
    return calcRotateMat4X(radian.x) * calcRotateMat4Y(radian.y) * calcRotateMat4Z(radian.z);
}

is the same as this in hlsl:

float4x4 calcRotateMat4X(float radian) {
    return float4x4(
        1.0, 0.0, 0.0, 0.0,
        0.0, cos(radian), -sin(radian), 0.0,
        0.0, sin(radian), cos(radian), 0.0,
        0.0, 0.0, 0.0, 1.0
    );
}

float4x4 calcRotateMat4Y(float radian) {
    return float4x4(
        cos(radian), 0.0, sin(radian), 0.0,
        0.0, 1.0, 0.0, 0.0,
        -sin(radian), 0.0, cos(radian), 0.0,
        0.0, 0.0, 0.0, 1.0
    );
}

float4x4 calcRotateMat4Z(float radian) {
    return float4x4(
        cos(radian), -sin(radian), 0.0, 0.0,
        sin(radian), cos(radian), 0.0, 0.0,
        0.0, 0.0, 1.0, 0.0,
        0.0, 0.0, 0.0, 1.0
    );
}

float4x4 calcRotateMat4(float3 radian) {
    return mul(mul(calcRotateMat4Y(radian.y), calcRotateMat4Z(radian.z)), calcRotateMat4X(radian.x));
}
regal stag
south temple
#

I think i actually tried all 9 combination and none was right

#

wait a second because i have another part of my code that i'm not sure about

#

glsl

    float yaw1 = atan(dir1.z, dir1.x);
    float pitch1 = atan(sqrt(dir1.z * dir1.z + dir1.x * dir1.x), dir1.y) + PI;

    float yaw2 = atan(dir2.z, dir2.x);
    float pitch2 = atan(sqrt(dir2.z * dir2.z + dir2.x * dir2.x), dir2.y) + PI;

    mat4 rot_node = calcRotateMat4(vec3(0.0, yaw1, pitch1));
    mat4 rot_parent = calcRotateMat4(vec3(0.0, yaw2, pitch2));
    ...

hlsl

  float yaw1 = atan2(dir1.x, dir1.z);
  float pitch1 = atan2(dir1.y, sqrt(dir1.z*dir1.z + dir1.x*dir1.x)) + PI;

  float yaw2 = atan2(dir2.x, dir2.z);
  float pitch2 = atan2(dir2.y, sqrt(dir2.z*dir2.z + dir2.x*dir2.x)) + PI;

  float4x4 rot_node = calcRotateMat4(float3(0.0, yaw1, pitch1));
  float4x4 rot_parent = calcRotateMat4(float3(0.0, yaw2, pitch2));
  ...

I know the atan2 arguments in hlsl are reversed
And i think i got it right but it's really the only thing where there could be a bug looking at the result

sharp delta
#

how can I use this in a custom function node?

#

it doesn't even tell you what code does the node accept

regal stag
sharp delta
#

thanks!

#

brain not work today.. heh..

hearty obsidian
#

hey all, I have a plane and I have objects moving on top of it. I'd like to make it glow around the units. I

I achieved that by creating a 6x6 texture(I have a max of 36 units), packing the position data and radius inside of each pixel and then my shadergraph has a custom function node that iterates through the pixels and determines the glow strength based on the distance.

It gets the desired results but performs very poorly. Is there a less expensive technique I could use?

supple thistle
#

I just have one quick question about shaders, I think this looks pretty good, but I want anything outside of the lines to be transparent, how can I do that?

#

please @ me if you know

simple violet
#

what lines

#

the white lines? if so then make subtract red channel

supple thistle
#

the white ones, but I figured it out

steel cave
#

if i made a decently complex shader in Amplify shader engine, with rim light, 2 types of emission, bunch of panning and fx, orientation, etc... and i put this on a plane, and then made a plane prefab and used that plane for tiles in a game, would that have a significant impact. what about just one time for a main character etc? I see alot of talk about draws and shaders and etc and didn't know if prefabs change things or not or what are things to avoid, like... the tile floor question i asked

tame topaz
#

!ban 285373952757465088 scam

echo moatBOT
#

dynoSuccess Coco.#3656 was banned

supple thistle
#

how can I make this more red?

#

kinda like the pic above

dim yoke
supple thistle
dim yoke
#

What part?

supple thistle
#

multiply

dim yoke
#

Multiply node 😄

#

Multiply the color you put to base color (or whatever its called nowadays) slot by (1.3, 1.3, 1.3) (or something similiar) and then put that result in base color slot

long token
#

Hey peoples, tag me in the reply please. I have a custom shader im trying to add a hue shift toggle to the shader to influence rim color on a material. Is anyone versed enough in shader coding that can help add just that functionality ? Any help is greatly appreciated! I can send you the shader file if needed. I got the check boxes and hue shift slider into the unity editor where I can see it but the buttons and slider do not work. This shit is hard yo. Can someone help me please!

#

Everything after rim color does not currently work

supple thistle
#

so my weapon appears like this in-game

#

any idea why?

#

@dim yoke

regal stag
# supple thistle

Would assume there's currently some negative values since white - red = cyan. It looks like you need to use a Saturate node (clamps between 0 and 1) on the colour (and/or alpha perhaps)

supple thistle