#archived-shaders

1 messages ยท Page 3 of 1

tight phoenix
#

time to start from scratch and spend 1000 hours trying to figure that out

karmic hatch
#

Transform sun direction to object space, then use rotational symmetry to your advantage (you only need an angle between the Sun and your point on the sphere)

#

So just acos(dot(object space sun direction, object space position))

#

For the angle

#

Though I've heard acos is slow in shaders and to avoid it where possible

#

But the cosine of the angle is very useful anyway

tight phoenix
meager pelican
tight phoenix
meager pelican
#

Reflection is like what a mirror does, refraction is what happens when light goes through a substance and changes its direction a bit due to the different densities (refraction index). Think how a stick looks bent if you put it in the water.

So you used a semi-transparent sphere as an example. Crystal ball, whatever. So there's refraction going on, and some reflection too.

You may also wish to use a cube map, and check out the cube map routines for dealing with surrounding reflections/refractions.

thorn tapir
#

Hey so Im trying to make a shader now to just slap on a material to modify the contrast of a tilemap... but what do I use the tilemap as the input in the shader???

if I just connect a contrast node to the master color it blackboxes all my tiles

#

cause I have to modify the contrast inside of the shader, but within the shader, how do I specify the tilemap as the target???

thorn tapir
#

had to use the tilemaps base texture as the input

thorn tapir
thorn tapir
#

hmm so I'm trying to add saturation to this, but I'm not sure how to incorporate it all back together

#

add and multiply both result in some unwanted effects

karmic hatch
#

can you not just put the contrast and saturation nodes successively, so either contrast > saturation or the other way around?

merry oak
#

Is it possible to do multiple passes with shader graph in urp?

thorn tapir
#

saturation first then contrast, instead of doing them in series

#

I could even implement hue, but I'll save that for another time

#

Saturation and constrast is all I care about in this case

glad egret
#

For some reason, i cannot set global/local keywords/properties in shaders on any before event, such as RenderPipelineManager.beginCameraRendering, Camera.onPreRender, MonoBehaviour.OnPreRender

I am trying to make a material set a keyword flag for when a particular camera is rendering it, so it has a different look without need to duplicate geometry.

glad egret
#

do i need to listen to a special event or something before i can change the material properties? How will i go about making a material have different properties for one camera vs every other camera

meager pelican
#

Set the value for the material in script.
The RenderPipelineManger.beginCameraRendering event is for c# scripts. So use a script.

Set the property on the material to true if it is your special camera, and false otherwise. Done.
You'll probably want to use renderer.sharedMaterial if you have that same material on several objects, rather than having to make material instance for each object, but that's up to you.

And IDK why your shader global isn't working.

regal stag
# glad egret For some reason, i cannot set global/local keywords/properties in shaders on any...

Just tested (with edited script, but basically the same), in URP 2021 lts. Seems to work.

private Camera enableForCamera;

void Start() {
    enableForCamera = GetComponent<Camera>();
    RenderPipelineManager.beginCameraRendering += OnBeginCameraRenderering;
}

void OnDestroy() {
    RenderPipelineManager.beginCameraRendering -= OnBeginCameraRenderering;
}

private void OnBeginCameraRenderering(ScriptableRenderContext context, Camera camera) {
    if (camera == enableForCamera){
        Shader.SetGlobalFloat("_TestFloat", 1);
        Shader.EnableKeyword("_TESTKEYWORD");
    }else{
        Shader.SetGlobalFloat("_TestFloat", 0);
        Shader.DisableKeyword("_TESTKEYWORD");
    }
}

If yours isn't working, add a Debug.Log, make sure the code is running somewhere. Also make sure the keywords/properties are global.

  • In Shader Graph that's in the Node Settings tab of Graph Inspector, "Global" on the keyword scope and untick "Exposed" for properties
  • In code, make sure you are using multi_compile (not multi_compile_local) and don't put properties in the ShaderLab section at the top, only define them in the HLSL
regal stag
# merry oak Is it possible to do multiple passes with shader graph in urp?

No, shader graph doesn't do multi-pass. URP also uses single-pass forward rendering so you can't really use multi-pass in code-written shaders either. You can technically use two passes with different LightMode tags ("UniversalForward" and "SRPDefaultUnlit"), but it would break the compatibility with the SRP Batcher. It's better to use separate materials instead.

Can assign multiple materials per renderer, or if you have lots of objects can put them on a Layer and use the RenderObjects feature to re-render that layer with an Override Material.
(Or you can use a custom LightMode tag, and specify that in the RenderObjects feature)

patent plinth
#

@regal stag do you know if unity terrain editor already has support for shaderGraph or not? I remember they've this planned like two years ago on their git repo

glad egret
#

i do have like... 4 cameras, 3 10k render textures, and a couple additively loaded scenes so something going funky

regal stag
patent plinth
#

ah ok.. we'll try to play around with it then.. thanks! ๐Ÿ‘

lucid current
#

does changing color of a material in code creates a new instance of such material?

#

I ask so bcs I want to animate color through DOTween

grizzled bolt
#

By accessing shader.material yes

lucid current
#

renderer.material.color

#

ok it is all the same

#

or not

grizzled bolt
#

Yes

lucid current
#

damnnnnnnn

#

sad

grizzled bolt
#

MaterialPropetyBlocks are one way to do the same thing without creating material instances, though it's not compatible with SRP batching

lucid current
#

I could make a shader graph that would change color though. I think it best what I can do

grizzled bolt
#

On URP/HDRP I don't think it's bad to create material instances as long as you keep track of them and destroy them along with the object

lucid current
#

I am a simple man

#

you see I wanted to make my material sort of blink so that is why I asked

#

changing alpha channel of a color on it would create instances each frame

#

it is dangerous

#

so I would make shader instead

grizzled bolt
lucid current
#

oh yeah?

grizzled bolt
#

It becomes a problem if you have a huge number of objects, each with their own instance, or if you're spawning and destroying such objects rapidly and filling memory with loose material instances

hexed surge
#

hello guys
I'm trying to track down the issue with a grass geometry shader
It generates root points for grass blades in the tessellation stage by subdividing the source mesh
then for each vertex it generates simple grass blades in the geometry stage

everything's fine, except the areas right on top of the edges of the source mesh
I can see that tessellation produces new vertices there just fine, but it looks like they are not passed down to the geometry stage (I'm not sure this is the case), and it causes visible empty areas to appear

maybe someone had experience working on a similar shader and recognizes the issue ?

#

source mesh

#

blades with a visible empty area

#

tessellation that generates the points

ripe grove
#

i am getting this error while building to android

#

could not find anything on google
i made 2 shaders and there are literally just 5 objects that have those shaders on, and it took me around 40 mins to build my project.
i turned off mesh optimization, i preloaded the shaders but nothing worked, and after waiting for the build to complete for this long, i got these errors

kind juniper
#

Are you using a scriptable render pipeline?

#

Or built-in?

ripe grove
#

Built in pipeline

ripe grove
kind juniper
#

Yeah, so shader graph is not very compatible with birp.

#

might want to switch to urp

#

Or not use shader graph

ripe grove
#

I came from urp

#

But it says it's compatible since the 2021.2 versions

kind juniper
#
Shader Graph support for the Built-In Render Pipeline is for compatibility purposes only. Shader Graph doesn't receive updates for Built-In Render Pipeline support, aside from bug fixes for existing features. It's recommended to use Shader Graph with the Scriptable Render Pipelines.
#

So yeah, you shouldn't use it for birp in production

ripe grove
#

Here, it says shader graph added for built in render pipeline

ripe grove
#

Shadergraph: Added: Added a new target for the Built-In Render Pipeline which includes Lit and Unlit sub-targets.

#

This is what it says

#

You can search "Built-In" on the page

#

And you will find it, it's a little deep

kind juniper
#

Well, it doesn't mean that you should be using it. Or that it is as compatible as in URP/HDRP.

#

They explicitly say that you should avoid using it on BIRP. And that's in the latest version.

ripe grove
#

Which is the latest version of shader graph?

kind juniper
#

you can see in the link that I shared - 15

regal stag
#

The built-in target should still work even if a SRP is recommended. If you're encountering errors when building it's probably a bug. Could try upgrading unity version or submitting a bug report.

ripe grove
kind juniper
#

But yeah, I guess it would be considered a bug.

#

There are probably platforms that have issues with it.

ripe grove
#

I have posted on forum to see if anyone replies, i will try different unity version now to see if it works there or not

ripe grove
ripe grove
# ripe grove

Btw these are the errors I'm getting, for a reference

grand jolt
#

hi i am not that familliar with shaders. i have this Height Depended tint shader with following function that is responsible for the color:

void surf (Input IN, inout SurfaceOutput o) 
{
  half4 c = tex2D (_MainTex, IN.uv_MainTex);
  float h = (_HeightMax-IN.worldPos.y) / (_HeightMax-_HeightMin);
  fixed4 tintColor = lerp(_ColorMax.rgba, _ColorMin.rgba, h);
  o.Albedo = c.rgb * tintColor.rgb;
  o.Alpha = c.a * tintColor.a;
}

is it possible to make _ColorMin more dominant like in picture

#

so the color begins to change a bit higher than normal

#

ohh nvm

shadow locust
#

you could use any easing function you want

#

right now you're using a linear interpolation

thin bear
#

How do I send a per-object value to a shader?

I'm trying to make a "palette swap shader" so my sprites may use the same artwork, but each can specify a different palette index for the shader to look up on a reference texture.

#

I have done this in Kha (that's like OpenGL) embedding the index in all 4 verts of the quad, maybe I can do the same thing in Unity

tardy oar
#

i am also using a Lit URP shadergraph

#

this is the .shader file that was compiled from the shadergraph:

regal stag
# tardy oar

A magenta/pink result means the shader has an error (unlikely with shader graph), or is not compatible with the current render pipeline.
Make sure the target matches your pipeline. (set under Graph Settings tab of Graph Inspector window, toggled with button in top right of graph).
Also make sure URP is configured correctly. See pinned messages in #archived-urp channel

tardy oar
#

thank you i had not set up URP properly!

tight phoenix
#

I know there is a parallax offset node, but can anyone tell why my graph and the real code are not equivalent? I'm not getting the expected results

#

Where have I made a mistake?

#

is it a pedmas/pemdas problem?

regal stag
#

The View Direction node should be in Tangent space for parallax

tight phoenix
#

Ahh I'll try that ๐Ÿค”

tight phoenix
#

I could just use the parallax node but I'm doing this as a learning project to get a better understanding of shader math

regal stag
#

You should also be using the result as an offset, not to replace the UV entirely. Can use a Tiling And Offset node for that

#

Or UV node and Add

tight phoenix
#

is maybe my p- I was about to say that

tight phoenix
ripe grove
#

What a coincidence @regal stag

#

Then i suddenly remembered I saw that profile pic somewhere

tight phoenix
# regal stag Or UV node and Add

That + Tangent space fixed it, thanks for pointing out my mistake ๐Ÿ‘ Glad to know I didnt goof up the graph too badly, it was just how I was using it

ripe grove
#

I read all of it and it was really helpful. So for my previous problem, i changed the platform from Android to windows and it did not give me error

#

I upgraded to 2022.1.11

#

And when I changed the platform to mobile, it gave me same error while building it.

ripe grove
regal stag
ripe grove
regal stag
ripe grove
regal stag
#

Yes that is only for URP/HDRP

ripe grove
#

Aah i get it now, thanks

#

Mate, just one last thing, if you got like couple of mins?

#

Only if you don't mind, it would take you like max 2-3 minutes to reproduce this error that i am having. And then maybe you can better understand this? I mean i am coming to built in pipeline from urp because I had to drop urp for lower performance on mobile. Now birp works flawlessly and have great performance but i cant really see any other option if the shader graph doesn't work in built in pipeline. So if you don't mind. It won't take longer than 5 minutes.

#

If you want to try it

Steps:
Just create a new project with built in render pipeline
Install shader graph from package manager
Create a new shader graph(lit)
Just hook up color property to base color
Create a new material out of the newly created shader graph
assign a color to material it in inspector (maybe red, or anything other than white)
Build the project for Android
That's it.

regal stag
#

I haven't got unity properly set up on this pc to test. But if those are the steps you need to take to reproduce it, it's definitely a bug. Should do a bug report, so hopefully it can be fixed.
In the meantime, you may want to avoid using shader graph for Android, or switch to URP (if possible)

ripe grove
#

its exactly that easy, like this is what you get when you do the steps above

#

do you by any chance have any idea what it could be tho? i am sorry if i am asking alot, but you know its a little disappointing to see it not work.
also where do i make a bug report tho? never made any so i have no idea

regal stag
ripe grove
sullen jungle
#

Hey epic devs
I want to know something about draw calls not sure I can ask here but do tell where I can if I shouldn't here
When does every draw call happen?
Every frame? every x seconds within 1 frame?

dim yoke
sullen jungle
sullen jungle
# dim yoke What?

What would happen if you have 100 objects to be draw on screen and your pc cannot run over 60fps
What would happen? Would you have frame drops?

dim yoke
#

So 60fps

sullen jungle
#

No so I have 60 frames to work with and I need to draw 100 and since every 1 frame can draw 1 object
So it will be able to draw to 60 objects and still have 40 that weren't drawn yet

worn gorge
#

Anyone know if we can setup instanced properties in shader graph now (without editing the final shader manually), such that we can use DrawMeshInstanced with them by passing in the MaterialPropertyBlock.

regal stag
regal stag
# sullen jungle No so I have 60 frames to work with and I need to draw 100 and since every 1 fra...

As AleksiH mentioned above, every frame all objects (at least the ones in the viewing frustum) are drawn, not just one object per frame.
But it's hard to say how long it takes to render a frame, as it'll vary - depending on how many draw calls (objects / batches), what shaders are being used and the target platform/gpu. You'd likely need to try and profile it. Then optimise later if necessary.

The statistics window might help a bit. https://docs.unity3d.com/Manual/RenderingStatistics.html
(Though in URP I don't think it displays the SRP-batches, not sure how helpful it is)

tight phoenix
#

Question, I was learning from a tutorial and I noticed the result looks suspiciously like a fresnel

#

is that just what fresnel is under the hood?

waxen slate
#

Hey, I'm writing a custom shader for TextMeshPro (Specialized anti-aliasing for a pixelated raster font) and I want to use Unity's UI effects components. Does anyone know what I'd have to do to support those in the shader?

grand jolt
regal stag
#

Can see the generated code for each node btw on the Shader Graph docs page. Right-click nodes and select "Open Documentation". Though recreating things in the graph may help understand it better if you aren't used to hlsl.

grand jolt
#

Does anybody know of a fix?

neat hamlet
#

looks like URP 's point light limit

grand jolt
neat hamlet
#

might still be a pixel light count issue ? minion19Thinking

#

oh right, doesnt happen with standard shader

grand jolt
#

yea, it's pretty confusing lol

kind juniper
#

It is most likely. It's not rp specific, but rendering path thing.

#

forward rendering has a limit of point/pixel lights. Deferred doesn't, but it's a bit heavier by default.

tall flicker
#

how to fade an UI component from middle to edge
like the alpha is 1.0 in center, but 0 on outside

#

there are no exact tutorial about that, all i know is it can only done by making a custom shader

#

to be simple, alpha gradient

grand jolt
#

Hey ive been looking at a few videos on game toon shaders and have a little question

#

Are shaders normally used on the entire games models like the player model and world around the player

#

Or are they used on only a few models like player models to help performance

tight phoenix
#

is there a way to get 'Normal From Height' less aliased and pixelated?

#

im using voronoi there, I've seen that normal from texture is better, but I'm not using a texture in this case

twilit geyser
#

Why is shader graph fucking up the colors here?

tight phoenix
#

What is that shader trick where you combine two things and it ends up being a bunch of colored bands

#

I forget how its done or how to describe it so I cant google it reliably

#

Im trying to make random rainbow noise

#

this is what I meant by bands, maybe finding it now

regal stag
tight phoenix
#

It didnt do what I hoped for but looks good at least

#

I've been struggling to make "sparkles" similar to this, ive tried a bunch of different sparkle/glittery tutorials but none have looked the way I hoped for
either they left out too much 'assumed' info that I couldn't finish the tutorial without, or the effect simply wasn't what I was going for

#

a lot of tutorials are like 'just add parallax' and it doesn't do anything remotely like what they have there to attach it to a parallax node

#

this is allegedly the method to do that above affect

#

I feel like about 50 more critical things are being left out

#

mine kinda looks like dogshit :/

#

doesnt do a single thing I set out to make it do, just shittier copies of other far better effects

dim yoke
twilit geyser
wide thicket
#

Why does my subgraph create an entirely different effect than what it outputs in my shader?

#

subgraph:

#

shader:

#

even when i remove the inputs, so that it only relies on it's own values, it does it's own thing

karmic hatch
# tight phoenix

Refraction and everything looks pretty good imo, just multiply the color for each sparkle by pow(dot(view direction, sparkle normal)*0.5+0.5, 50) or similar and then they'll sparkle depending on the angle (you can make it dependent on the direction to the light source but it probably won't matter too much since you won't be identifying the individual ones anyway)

tight phoenix
#

Ill throw all of this out and try again from scratch with that formula

karmic hatch
#

Try increasing the power a lot

tight phoenix
#

either you could see nothing, or see all of them, nothing would do 'some of them'

#

rebuilding atm

tight phoenix
karmic hatch
#

Multiply then add

#

It's roughly the same as saturate -> pow

#

Shouldn't be functionally different

tight phoenix
#

What is that 50 at the end?

karmic hatch
#

The power

tight phoenix
#

is the dot product between all that stuff and 50?

#

oh right the first thing is pow not dot

karmic hatch
#

Dot is between view direction and normalize(sparkle normal)

tight phoenix
#

I didnt see the pow at the start

karmic hatch
#

Just make the power >> 1

#

If it's close to one, you just have diffusely lit things, not like specular highlights which you want

tight phoenix
#

or they do really weird stuff like only sparkles on the -x -y faces of the surface

#

all four of them, its not changing at all when I rotate the mesh

karmic hatch
#

I think view space won't work, but anything else will (you just want the view direction to be able to change). Object space or tangent space would probably be best since they'd make it change as the mesh rotates

tight phoenix
#

Im doing something wrong here but i'm too inexperienced to understand what or fix it

karmic hatch
#

Also you need to make sure the normals for the sparkles are distributed on all sides of the origin, you don't want all of the components to be positive or something (but in tangent space I think the B component should be positive always?)

tight phoenix
#

increasing/decreasing power only makes it look worse, broken texture pink

tight phoenix
karmic hatch
#

Make sure everything is normalized

tight phoenix
karmic hatch
tight phoenix
#

I'm doing something completely wrong because it just wont sparkle no matter what values I put in

#

it fades in and out completely as a single unit, and the faces are all @#$%^ up some showing, some not, some in reverse

#

I've been fighting with this all day long and I just feel fucking stupid and worthless, I can't do a single thing on my own

#

literally 100% of my "successes" are my successfully getting help from someone else to fix my stupid piece of shit mess :/

#

im getting really discouraged

#

I wish I wasn't such a stupid failure

meager pelican
# tight phoenix pow(dot(view direction, sparkle normal)*0.5+0.5, 50) is the order of this dot of...

(Sorry for butting in guys)
Nope
The random color texture is sampled.
In the example image, they ONLY subtracted .5 from the color RGB result. They didn't mulitply by .5 (although I'm not following the conversation well, so I hope you'll both excuse me if I F*** this up).
That result is a directional vector where the RGB components range from -0.5 to +0.5
They then applied the dot product of the view direction and that random vector, with a Pow or whatever.

tight phoenix
#

are you saying I should multiply before at some stage?

meager pelican
#

There was no multiply.

#

Just a subtract

tight phoenix
#

all my efforts are just complete dogshit it wont do a single fucking thing and im beyond emotionally compromised im not able to contine working on this without going into crisis

meager pelican
#

In that example.

tight phoenix
#

im going to close discord now

meager pelican
#

OK, chin up!

karmic hatch
meager pelican
#

Sure, but IDK that they normalized either. Interestingly. Although I'd guess that you would normalize both vectors.

#

And then there's the question of how to apply the random color texture to the cube in 3D space. I'm not sure I can tell from that one image how they did that. Maybe they had a texture3D?

#

bunp is right in that the explanation falls a bit...short...IMO.

karmic hatch
wide thicket
#

why would my subgraph eb giving me a different outcome from my shader?

karmic hatch
#

@tight phoenix here i just took voronoi noise (i used 3d voronoi but you could try some triplanar thing or some other method to optimise it as 3d voronoi is slow), used the cell values to create 'flakes' with random normals, then used fairly standard specular (pow(dot(reflection(normalize(view direction), normalize(random normal)), sun direction), 200)) to make them sparkly

#

there are some strange correlations which is probably because of the way the random normals are distributed (not uniformly enough) but whatever

#

Btw I put the output color into emission

#

Might want to also multiply by saturate(dot(surface normal, sun direction)) so they don't sparkle in the dark bits unless you want that

wet ermine
#

Does anybody know a good technique to achieve an inline effect on 2D sprites? I tried using the Step node on ShaderGraph and it worked, but the inline is very thin and I couldn't make it any thicker...

runic zodiac
#

I'm using the shader graph and my material is always purple even tho I am changing tue colour

kind juniper
runic zodiac
kind juniper
#

Yeah, you're probably using built-in render pipeline. And the shader graph is only compatible with it from unity version 2021.2 or something.

runic zodiac
kind juniper
runic zodiac
kind juniper
runic zodiac
sly breach
#

quick question , does this mean unity compiles 1000 million shaders or is it 1000 megabyes ?

kind juniper
#

Anyone have a clue how to implement sprite sorting with a custom mesh + shader graph?

kind juniper
kind juniper
twilit geyser
#

Hey y'all ๐Ÿ™‚ Can anybody tell me why this shader is not able to stencil? Is there anything I can do about that inside shader graph?

neat hamlet
#

afaik shader graph doesnt support stencil buffer stuff

hidden oak
#

so, I made a shader to simulate the refraction of light from water above for a game that is supposed to play out underwater. But when I apply it to an object in unity it only works on one side of an object, anyone know why?

#

I'm very very new to unity shaders so I have no idea how this works

white marsh
#

Is it like that in world space or object space?

hidden oak
#

what do you mean?

white marsh
#

If you rotate the cube is it sticking to the same side or us it always facing the same direction?

hidden oak
#

facing the same direction

white marsh
#

Sounds like you have accidentally mapped the texture in world space in one axis

hidden oak
#

oh! did not know that. do you know how I can fix that?

#

this is the last part of my shader

white marsh
#

Is this using a texture?

hidden oak
#

yeah

white marsh
#

Then the problem is probably where you sample the texture

hidden oak
#

i tried changing it to object space as well but it didn't seem to change

#

should it instead be sample texture 3d?

white marsh
#

What is the uv input?

#

Im kot exactly sure but i think texture 3d is. For itger types of textures not for 3d geometry

hidden oak
#

just checked ,it's not a 3d texture. that's apparently something else

white marsh
#

There we go, wold position as UV. If you want it ti scroll you should be using the x or y value of the UV not world position

#

I don't use the shader graph much so i don't know the name of the node you need but it should just be the mesh uv

hidden oak
#

and changing the type of position? would that help?

white marsh
#

Yeah, the UV input of the sample tex is essentially used to map the texture around it. If you aren't using the values that defines where and what should be where, ie, the UV coordinates it will map differently. In this case in world space

hidden oak
#

is it just a UV node?

white marsh
#

If you try to output the world position as the color vs the uv as the color you will se what i mean

#

Yeah should be

hidden oak
#

So, I tried a UV node. It worked somewhat, but I did realize that now not all the planes have the same size

#

as you can see here

white marsh
#

Wait hold on are you making caustics?

#

Or i guess simulating caustics

regal stag
#

Could continue using the world position, but Swizzle it with "xz" so it projects from above. It will still stretch on sides of objects though

white marsh
#

^ yes, i didn't realize thats what he wanted

#

But i assume you also want this texture to not effect the sides and bottom if this is an overlay for another texture

wet ermine
#

Does anybody know a good technique to achieve an inline effect on 2D sprites? I tried using the Step node on ShaderGraph and it worked, but the inline is very thin and I couldn't make it any thicker...

elfin mesa
#

hey all, does anyone know if there's a way to get all these options from the URP Lit material into a shader graph? if it has to all be done manually, has Unity put out any resources on how to do this?

tight phoenix
#

im still trying and failing to do glitter, im critically missing something, im not understanding something to make it work and I keep grinding my gears against it and failing to get any traction

#

I have a texture for testing random colors as vector directions to mask which parts of the glitter will be visible or not

#

but I cant figure out what im actually supposed to DO with it

#

what space it should be in, should it be added, multiplied, dot producted, literally anything I have no idea

#

everything I try looks completely wrong like complete shit

#

I really need help on this I cant do it on my own

#

and my mental health is in the pits, admitting that openly that im so worthless I cant do something this simple on my own is tipping me over the edge into criss, time for me to close the internet

karmic hatch
#

Optimally you'd distribute them across a sphere surface evenly rather than across a cube but that is slower

#

Maybe you could create a random matrix and rotate but that's more effort too

tight phoenix
#

oh the reflection is between the view normal and random normal
and the dot is between the that and the sun direction?

tight phoenix
#

im pretty sure im doing the reflection step wrong

#

and clearly doing the power step wrong

#

the raw voronoi isnt the answer

#

i wish i just understood, i wish i just knew the answer, i wish i had the ability to solve anything or even begin to know what step is wrong

tight phoenix
#

WHAT AM I DOING WRONG, WHY WONT IT EVER @#$#$^#$^ WORK

#

i get so fucking furiously angry at how fucking worthless and useless I am and i get so fucking angry at how knowledgeably everyone else is, things for you are so easy that you can literally just immediately type out the answer bracket flow like its nothing, and im too fucking stupid to read between the lines

#

i am in crisis now leaving again

#

why. wont. it. just. fucking. work
Why am i so fucking stupid
why cant i do literally anything without my hand being held

#

why can i be handed the answers on a golden plate but im too fucking stupid to know how to pick up a fucking fork and eat the answers

karmic hatch
karmic hatch
tight phoenix
#

i desperately wish I could not feel emotions, my feelings hold me back from achieving success

#

if I could just act rationally, think clearly, not get down by repeated failures

tight phoenix
#

which wont be today

#

thank you for your kind words and patience

karmic hatch
meager pelican
#

I'll drop this here for fun.
This is NOT sparkles.
But it is a nice clear video tutorial, with shader graph, on how to make translucent crystal like things, with screen space refraction. Sparkles could be added to it. And this time I won't butt into the ongoing discussion about those.
https://www.youtube.com/watch?v=tIW2zM6ed8o

Refraction shader using ShaderGraph, works both on URP and HDRP. Uses the opaque texture to achieve screen space refraction.

(ใฅ๏ฟฃ ยณ๏ฟฃ)ใฅ ~(ห˜โ–พห˜~)

TWITCH ( อกยฐ อœส– อกยฐ)
https://www.twitch.tv/PabloMakes

TWITTER (เฒฅ๏นเฒฅ)
https://twitter.com/PabloMakes

โ‚ช โ‚ช Time Stamps โ‚ช โ‚ช
00:00 - Intro
01:57 - Opaque Texture
05:09 - Refraction
13:14 - Normals

...

โ–ถ Play video
boreal gust
#

Hello everyone, I have a procedurally generated map and some textures are applied to the mesh according to the height of the regions. I also got a curved world surface shader I found from the internet (for a planet-like look). I am a complete beginner in shaders but I managed to merge the 2 shader together but it seems like the vertex modification is done first and then the textures are applied, so the far sides of the map is just water. Is there a way to fix this?

regal stag
boreal gust
#

No it's a surface shader. I see that's the thing I need to do but because I'm a beginner in shaders and because there isn't much about this on the internet I don't know how to do it.

regal stag
# boreal gust No it's a surface shader. I see that's the thing I need to do but because I'm a ...

Ah okay. My knowledge on surface shaders is a bit lacking, but I imagine you'd need to add your own variable to the Input struct (e.g. float3 customWorldPos;) rather than using the built-in one.

Then in the vertex modification function (probably named "vert"), should be able to specify out Input o as an additional parameter, and use o.customWorldPos = mul(unity_ObjectToWorld, v.vertex).xyz;, before the v.vertex is modified that is.

Also edit the surf function to use IN.customWorldPos instead of IN.worldPos.

meager pelican
leaden zinc
#

Hey guys, im looking through pins and comments tho im gonna ask.
What are some good and hopefully up to date resources for shading programming with Unity?
Im interested in learning shading coding as well as using tools like shader graph.

wet ermine
#

Hello, everyone!
Does anybody know a good technique to achieve an inline effect on 2D sprites? I tried using the Step node on ShaderGraph and it worked, but the inline is very thin and I couldn't make it any thicker...

meager pelican
# leaden zinc Hey guys, im looking through pins and comments tho im gonna ask. What are some g...

Well, the thing is this stuff has "history". It has history in the languages (API's really) used, as well as history within Unity, like the different rendering pipelines.

You'll find a lot of resources/tuts for Unity's older Built-in Render Pipeline (BiRP), these are almost all pure hand-written code but Shader Graph now works for a subset of functions for it. It's not intended to fully support BiRP though, IIUC. That's not at all to say that it isn't worth learning, particularly if you want to hand-write code.

But the newer pipelines are a bit different, both in syntax and functionality. So the question you have to ask yourself first is "Where do I want to start?" Open GL (GLSL) or DirectX (HLSL)? I'd go with HLSL, but you'll find tons of resources for GLSL (Grrrr). Unity will translate the HLSL to GLSL as required for the target platform.

Those pinned resources you mentioned have many links that can get you started, but you should form a plan. And there's not really any right or wrong answer, as long as you know what you're getting into has "history" to it. IMHO.

So it will be easier to learn BiRP coding-by-hand, but there are resources that can help you with the new pipelines (URP, HDRP) too.

leaden zinc
meager pelican
#

Maybe start with Cyan's stuff in the pinned links...

meager pelican
leaden zinc
#

okay thank you!

wet ermine
#

Then subtracted the output with the alpha again, to get the inline effect

meager pelican
#

Well, you could "cheat".
The sprite system supports a secondary texture that you could use to "read" the inline or not-inline from.
https://docs.unity3d.com/Manual/SpriteEditor-SecondaryTextures.html
That's just one idea. That lets you do it at sprite edit time, rather than have an overly-nasty set of shader code.

I think. ๐Ÿ˜‰
@wet ermine

wet ermine
#

I already considered an inflate technique, but I have no idea of how to inflate plane 3D meshes, since it's normals are always pointing up

wet ermine
#

(in my case the camera is rendering a plane geometry, so I considered doing the inline on the mesh itself using inverse hull or something similar since I couldn't do it in the texture on the UI)

heavy stirrup
#

Anyone know why motion vector texture isn't being binded by Unity? I changed the depth mode on the camera

#

it's being rendered before post processing in a URP render pass

heavy stirrup
#

nvm

#

i dont think motion vectors are supported in URP 10.9

fading fable
#

Hi guys, I downloaded this TintedUIBlur shader: https://gist.github.com/jhocking/9de4197daf84698a60e51c67695d2be3
And it was working great with pre-URP, but now I switched to URP and I'm a bit noobie to update it.
In scene view it works just as before, but in game view it's no longer transparent but all grey.
Could you help me please? ๐Ÿ™‚
Console has lots of errors like this:
Shader properties can't be added to this global property sheet. Trying to add _HBlur (type 4 count 1)
Thanks in advance!

cinder path
#

it is struggling to use the grab pass of "_HBlur" that it uses to redraw over it

#

there are lots of errors because it tries every time the shader is called

#

i'd look into the horizontal blur pass to see if it isn't that one that has compatibility issues

#

do you have that problem with the _VBlur as well?

fading fable
#

No, only _HBlur, _HBlur_ST, _HBlur_TexelSize

cinder path
#

right all properties

#

mh i'm not familiar with URP shaders but it seems an entirely different beast

#

are you a bit fluent in shaderlab writing? or you just brought the code in your project?

fading fable
#

Not really familiar :\ Not especially bought, downloaded it from the github link above.

cinder path
#

right

#

this is the reason it isn't working

#

if you are using a custom shader i'm unsure it will automatically update it with the tool, it's possible that it needs manual rewriting but as I never did it I cannot tell you for sure

#

but the article above gives you a good overview of what's different

fading fable
#

The automatic update only works with built-in shaders. That's why I'm asking for manual help with this custom one sadly :\

cinder path
#

yeesh i was afraid it wouldn't

#

here is another article for the custom shaders

#

it gives you a table of the differences

#

you'll need to update all the shaders in your pipeline to get it working

#

i hope it helps!

fading fable
#

Thanks!

native otter
#

I've created a shader in shadergraph for simulate some wind effect through leaves using time and on the vertex position.
Now all the prefab trees using this shader are acting the same, I would like to have some randomness and difference between the same prefab tree.
It's probably easy using a trick with a transform on world node probably? In which direction should I think?

#

I use this setup.

cinder path
cinder path
#

like a sort of random seed

regal stag
# native otter I use this setup.

Since atm you use Cosine Time, it's not possible to offset the phase of that. You'd need to switch to using the Time output -> Add/Subtract some random value (see below) -> Sine/Cosine node.

For the random value : I imagine your trees won't move around, so could use the Position output from the Object node - this gives you the worldspace origin of each tree. I'd then Swizzle with "xz" and use it as the Seed to a Random Range node.
(If the objects did need to move, then would need an offset or seed property, as exitshadow suggested)

regal stag
native otter
#

Thanks, will try that.

boreal gust
grand jolt
#

However I want to add a outline to this

#

Something like this but filled ( not just a weird line )

#

Something nice would be another circle under this one

#

However idk how to do that

regal stag
grand jolt
#

However idk how to add them togheter

#

Here I have a thicker circle

regal stag
#

Connect it to the Alpha port on the master node/stack

grand jolt
#

nvm

#

being dumb comes with its problems

grand jolt
#

on the same note

#

how could I add an outline to the red part like this

#

I could add another red stuff but smaller, but idk how to add them

regal stag
grand jolt
#

and be ,,animated"

#

I just use a noise to change the black parts in red and it looks super nice

grand jolt
tulip carbon
#

Hi, I'm pretty new in everything related to shaders, but could anyone tell me how can I modify a shader to show like a white part in the highest part of the mesh please?

tulip carbon
#

hmmm more like the top part of a wave

cinder path
tulip carbon
#

and how do I do that exactly please?๐Ÿ˜…

#

Like, I have no idea about shaders

cinder path
#

i'd follow a tutorial about shader graph then

#

or find a snow shader, it is likely it will achieve the same effect

tulip carbon
#

like, I have this big wave, and I want it to get like a gradient from the top part to about the middle with a white tint

tulip carbon
cinder path
tulip carbon
cinder path
tulip carbon
#

and the snow shaders (at least the one I'm watching), won't work because it only applies snow to the parts facing up

cinder path
#

it's basically really getting the data of the vertex.y and deciding from there

cinder path
#

and then extrudes in that direction (very grossly this is a teaching shader)

#

alternatively you can also make a color range with a white tip and map it to your wave

#

it might be less expensive

meager pelican
tulip carbon
#

like, I've tried with something called gradient but doesn't seem to change anything

meager pelican
#

Maybe position node, set to object space, and a conditional/branch or perhaps lerp.

karmic hatch
#

But sample gradient is a good idea

meager pelican
#

Right. Assuming the model is a mesh and it is set up that way. IDK your setup.

tulip carbon
#

like this?

tulip carbon
karmic hatch
#

Also whatever you're adding it to is already white I think

#

So doesn't look like much

tulip carbon
#

hmm then no idea what I have to do tbh๐Ÿ˜…

#

like, the wave still looks the same

karmic hatch
#

Try multiplying the position by a float and make that float big

#

Also see where the origin for your wave mesh is. Is it at the top, bottom, or middle?

tulip carbon
#

top

karmic hatch
#

Ok then put the object space y into a negate node first and flip the direction of the gradient

#

Might actually make things easier tbh

karmic hatch
tulip carbon
#

like this...?

karmic hatch
#

So position > split (y) > negate > multiply [by float property] > sample gradient

karmic hatch
#

(anywhere between position and sample gradient)

tulip carbon
#

like this?

karmic hatch
#

Yes

tulip carbon
#

now I see a white line there, but is in the middle not the top

karmic hatch
#

then the origin of the object must be in the middle I think

#

You can just add a float to the y component before the negate node

tulip carbon
#

probably, then I migth have looked it in an incorrect way, my bad

karmic hatch
#

And tune it to land at the top

tulip carbon
#

how?

karmic hatch
#

Just make it a property and move it around until the foam is in the right place

#

Also to make the fade wider, decrease the multiply float

#

(create node, right click, select 'convert to property')

#

(then when you click on the material, you can edit the properties in the inspector)

tulip carbon
#

where do I right click sorry?

karmic hatch
#

just search 'float'

#

Create a float node and give it some value

#

Then plug it in

#

Then right click on the float node

tulip carbon
#

oh like this?

karmic hatch
#

Yes

tulip carbon
#

and to move it up?

karmic hatch
#

Before the multiply, put in an add node and create a new property for that

#

And then you can change it to put the foam wherever you want

tulip carbon
#

idk what I did but now everything is white ๐Ÿ˜ฆ

#

okay nvm found it

#

but the add thing before the multiply doesnt move it up

karmic hatch
#

if you change the float it should move it up or down?

karmic hatch
#

Are there perhaps two meshes, with one upside down?

grand jolt
#

How to multiply something to make it more transparent?

tulip carbon
karmic hatch
grand jolt
#

I have this

#

and I want it semi transperent

karmic hatch
#

There's an alpha option in the fragment node for transparent shaders

#

It should be there by default if you've set your shader to be transparent

grand jolt
#

I did

karmic hatch
#

So then create whatever shape you want your transparency map to be, then plug that into the alpha

grand jolt
#

well

#

what about semi transperent part?

karmic hatch
karmic hatch
grand jolt
karmic hatch
grand jolt
#

if I multiply the clamp by 0.5 would that work?

karmic hatch
tulip carbon
#

nope, don't think so

karmic hatch
#

Make VALUE quite large

tulip carbon
#

oh wait now when I set it to the X value yes

#

but I tried it before and didn't do that

#

well thank you so much ๐Ÿ˜„

karmic hatch
#

Np :)

tulip carbon
#

and sorry for being such a noob๐Ÿ˜…

karmic hatch
#

We all have to start somewhere :)

tulip carbon
#

okay and do you know if it's possible to like set the tiling of a procedural noise please?

karmic hatch
#

Or voronoi noise if you like the look of it but I find it has more limited use

tulip carbon
karmic hatch
#

The scaling gives you the scale of the noise, if you want it to tile you'd be better off using a texture

tulip carbon
#

and is there a way to create a texture with that procedural noise...?

karmic hatch
#

Idk, you can download noise textures online though

tulip carbon
#

oh okay

karmic hatch
#

You probably could create a texture but you'd need to modify the code creating the noise so it lines up

tawdry thistle
#

Hello!
I'm trying to read my own global texture in my Shader Graphs with Shader.SetGlobalTexture("_LOS_TEXTURE", renderedTexture); in my script.

#

Unfortunately I'm getting a 'tex2D': cannot implicitly convert from 'Texture2D<float4>' to 'struct UnityTexture2D'

#

Anyone can help with that? ๐Ÿ˜„

steel notch
#

How do you convert a color to greyscale in shader graph?

olive hinge
#

if I have gpu instancing enabled on a material, grass in this case, should I notice it in the stats for batching/saved by batching? it seems to have no impact on performance when its enabled.

slender sonnet
#

heya, was wondering how i could perhaps reverse the spherize on my shader graph as to go from:

#

to something like this, dont mind the poor photoshop

meager pelican
# steel notch How do you convert a color to greyscale in shader graph?

Well you can check out the color conversion node for SG. Use the HSV value component (.z) of the result, and input your either linear or RGB value.

Or you can take the dot product of the color.RGB and float3(0.2126729, 0.7151522, 0.0721750) which if the internet didn't lie to me, gives you a float result for the grayscale that you'd just make into a color for all 3 channels.

steel notch
#

I added the RGB together and just divided by 3 >_>

meager pelican
# steel notch I added the RGB together and just divided by 3 >_>

That works. It is appropriately lazy (wink), but unfortunately it is a bit less accurate since the green value of the color has more influence because the human eye is more sensitive to it.
If you're not picky about it, that value is very efficient if not completely accurate.

meager pelican
olive hinge
meager pelican
#

I thought SG supported it by default, but maybe there's things that screw it up.

URP, if that's what you're using, batches differently too, but I'm not sure that matters really...it still groups by shader in that case, and should support instances. So IDK what the deal is.

olive hinge
#

im using HDRP

#

and it doesnt seem like instancing is doing anything with the default lit shader, no reduction in batches

meager pelican
#

Oh, IDK about HDRP....anyone using that is on the "advanced, figure it all out" side of the pipelines, IMO. Sorry I can't help more.

olive hinge
#

i very much regret using it

regal stag
tawdry thistle
#

Thanks, will try! โค๏ธ

merry bone
#

Any time I use a simple noise node in Shader Graph I get these artefacts. Is this just an inevitable part of the value noise Unity throws out, is this a bug, or is this pilot error?

regal stag
karmic hatch
merry bone
#

Thanks Cyan, this example just used the default plane with default UVs and the noise scaled to 100, but it's also visible down to scaling of less than 20, and stays until very high values. The material is just an HDRP lit shader with a noise node dumped straight into albedo. Any ideas how I could go about trying to debug this one or sending anything of value to Unity? Good to know you don't normally have this issue at least!

regal stag
merry bone
#

Ohhhh, this might all explain it then. I was under the impression that simple noise defaulted to being deterministic (my use case requires it), but it turns out I'm using a version that's just a notch behind when they added that so I am indeed using the sine hash. I'm going to try updating and see if that unlocks the parameter the documentation talks about. Thanks again for the help!

regal stag
lusty wadi
#

i'm trying to make a swirl animation for a scene fade, but i cannot seem to get it right, im looking for a spiral that kinda closes in and out with a simple variable change

vital smelt
#

Anyone have any possibly solutions for the issue I posted in #archived-urp ?

lusty wadi
#

how do i make this more toony

regal stag
lusty wadi
#

thank you, ill look up what tstep is..

#

yup, thank you, this was exactly what i needed

regal stag
#

Posterize might also work if you want to convert it to multiple bands/steps

lusty wadi
#

these are some very weird naming schemes, i must say.

karmic hatch
echo flare
#

Created a procedurally generated fuel gauge and it looks great, in the preview. When I created the material and attached it to a quad, it looks very strange and I see NullReferenceException's in the console

echo flare
#

My solution involved copying chunks of the graph over to a new graph. Still not sure what happened, but here is the final result, any feedback is appreciated

karmic hatch
vital smelt
#

So, I have a Subgraph that modifies the H and S values of a colour, but how do I apply the V?

young lantern
#

I could use some help with shaders if anyone knows those. At the moment the texture of an object is set based on its world position. As such, moving that object around will change the texture. I only want the texture to be set based on the position ONCE and then not change from there.

meager pelican
young lantern
#

I'll give that a try tomrrow, thank you ๐Ÿ™‚ @meager pelican

#

Would that cause any issues with the texture getting stretched when the object gets enlarged? As that was the point of world position

regal stag
young lantern
regal stag
# young lantern I feel like that would stretch too?

It wont stretch if you keep using world space. To clarify a bit, the Position output from the Object node gives you the worldspace origin of the object. Subtracting that origin from the world space fragment Position means the coordinates are then always centered around (0, 0, 0), so now the texture moves with the object.

Alternatively, I think you could also use a Transformation Matrix node with "Model", and Multiply with a Vector4 containing your Position (xyz) and a value of 0 in the w component. (That means it won't apply the translation part of the matrix). Same thing as above but there the translation is already applied and we are removing it by subtracting.

Though with both of these, it still won't make the coordinates rotate with the object if you need that too.

#

Important to note that only really works with MeshRenderers/SkinnedMeshRenderers too.

regal stag
# vital smelt So, I have a Subgraph that modifies the H and S values of a colour, but how do I...

Instead of using Hue/Saturation nodes, you should use a Colorspace Conversion node if you need to alter all 3 HSV components.

You can then use math on each component. e.g. R -> Add (with R from your other Vector3) to replicate the hue offset. Though if it goes above/below 1 you'd probably need to wrap that back around manually. I think the Fraction node should work.

Then on G and B could Multiply (with the G/B of your other Vector3) to control how saturated/bright it is.
Then recombine them using a Combine or Vector3 node, and put through another Colorspace Conversion back to RGB (or Linear?)

young lantern
fading fable
#

Hi guys, I tried modifying a hex tile shader to support transparency.
Which I kind of achieved, but now with Surface Type == Transparent, the UI won't be rendered above them.
On the example below the UI is only visible if there are other objects, like trees between the tiles and the UI.
Why? ๐Ÿ˜„ Thanks in advance!

cinder path
#

I don't really know where to post this, but as it's GPU-related this is my bet.

What would be a good and reasonable upgrade from a GeForce GTX 1060? I am not convinced by the RTX 2060 and most above are still too expensive for what they can bring that is better than my old thing. Is there anything reasonably priced around 500โ‚ฌ / 600$ that brings significant increase in performance?

mental bone
#

can someone explain to me the frag function in the DepthOnlyPass in URP ```half4 DepthOnlyFragment(Varyings input) : SV_TARGET
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
return 0;

}``` What is this Alpha method ? what does it do and why does it return 0 instead of the fragment depth ?

regal stag
mental bone
#

oh right...

#

thats why we have ZWrite On
ColorMask 0 at the top of the pass

regal stag
#

Yep

karmic hatch
fading fable
#

Got it under Advanced options. Thanks! ๐Ÿ™‚

karmic hatch
#

In the material i think there's a place for it

#

default is 3000 or something and if you increase it it goes later

summer trellis
#

is there a way to create a gradient in the shader graph?

#

not with the gradient node

#

like a way to input stuff and make a gradient

#

something like this setup, but with more than two colours

shadow locust
summer trellis
#

i get that but i'm not entirely sure how i'd do it

shadow locust
#

well each color needs to be associated with a "t" value - then you just find the two colors closest to the "t" and interpolate between them

summer trellis
#

right

echo flare
#

There's a gradient sampler node, use the uv coords as the sample position

#

oh, missed the part where you don't want that

shadow locust
#

I mean id definitely suggest using the built in gradient

shadow locust
summer trellis
#

yeah

#

another thing, is there a way to click on a node and have that output automatically be the overall output of the shader, like you can in blender?

#

rather than dragging it all the way over

tulip carbon
#

Why does my shader looks completely white in the VR headset please?

karmic hatch
#

Why can't you use sample gradient?

summer trellis
#

the gradient will be different at every point

karmic hatch
karmic hatch
summer trellis
#

1-10

#

it's a biome type thing

#

every biome has a gradient so the colour is dependent on the height

#

but i also want to seamlessly transition between the biomes

#

no ugly sudden colour changes

shadow locust
#

Why can't you use the built in gradient node?

summer trellis
#

it's randomly generated

shadow locust
#

That's not an issue

#

you can create the Gradient procedurally too

#

from your randomly generated colors

summer trellis
#

oh?

shadow locust
#

there's an example on that page

summer trellis
#

yeah i can make the gradients for each biome in c#

#

but then when i get to the edge of two biomes i'd need to make a gradient between them for every vertex

shadow locust
#

Another thing you could explore is the free gradient you get from using vertex colors and uv mapping

#

it's a bit limited based on your vertex locations in the mesh though

summer trellis
#

yeah i think i've got a solution going rn

#

thanks for the help though

summer trellis
#

yeah

#

got it working now. thanks ๐Ÿ‘

tulip carbon
abstract yacht
#

Hello everyone ! I'm a complete noob with shaders ... I found some shaders to hide 3D objects in a UI scrollview but the shader on the object only renders it completely white and I'd like to be able to take a material and only add the "mask" effect via a script. Do you think it's possible? Portal is the "inverted-"masking cube and Backobjects is the one on the "white" 3D object. Any tips? Can't find my way through that one

unique pumice
#

nvm im stupid I forgot about the mask ๐Ÿคฆโ€โ™‚๏ธ

royal vale
#

So I have a Render Texture I'm constantly updating and I'm trying to use it as a sort of heightmap to apply a nice specular shader on. I can't really figure out the right path to start implementing this-- any pointers?

royal vale
#

Well I'm not super familiar with writing lighting shaders but there's enough info online to do that part-- the main thing I'm trying to figure out is to get the data from my render texture in a usable format to treat it as a heightmap (afaik a heightmap is the best way to do what I want)

#

something akin to this lighting effect, it's basically the classic physarum model which I have done and working great. Just trying to get the lighting portion now

dim yoke
#

I dont really know what you mean by โ€treat render texture as a heightmapโ€. Heightmaps are just textures representing height

royal vale
#

right, I'm new to using unity so bear with my fuzziness haha. I guess I'm just asking how you would go about adding specular lighting to a texture then

tight phoenix
#

how would one remap voronoi's roundness into squareness?

dim yoke
royal vale
# dim yoke What kind of texture? So you have the main color texture already and you want to...

So this is an example of what the texture would be while running. the main color would be black and the heightmap would be based on the amount of whiteness at each pixel (in motion it's changing constantly). The whiter parts would be "higher" so would show lighting highlights from whatever direction the source is at. in practice I would have color variants so the highlights don't blend in

#

color example

regal stag
tight phoenix
dim yoke
royal vale
#

Okay cool that's useful

#

A normal is basically the instantaneous 3D slope of a point on a texture right?

dim yoke
#

The Normal From Height node uses the heights on the adjacent pixels (using partial dericatives) to figure out the normal vector

royal vale
#

Okay gotcha that makes sense

#

Shader Graph looks nice haha thanks for mentioning

dim yoke
#

I think the amount of resources about custom lighting with shader graph is quite limited tho. Most of those uses handwritten shaders as they have been out there so much longer and shader graph is bit more limited with its features

karmic hatch
#

(hence it's zero at the edges, and increases to the middles of the cells

#

)

river wharf
#

So, weird question maybe. Say I wanted to apply uv scrolling to just a specific quad of a texture and not the rest of the texture. Is there any way to do that?
I'm basically using a texture atlas for low poly solid colors and want one part of the model to scroll, but the rest to stay solid.

#

Base texture looks like this and let's say that's a swords "blade" uv is mapped in red, and the "handle" is mapped in blue quad.

regal stag
river wharf
karmic hatch
karmic hatch
regal stag
# karmic hatch This is more for the square shown there, right?

Yeah, I guess my answer is more for that example in particular. Though I'm sure it can be extended to a larger atlas too.
I'd typically avoid using another texture as a mask / comparing colours as then you have a texture read dependant on another which is less performant afaik.

karmic hatch
#

you're best off doing that with a script by calculating distances to a few points in the branches. You probably could use a divide-and-conquer technique by writing the tree positions to a texture, then running through 2ร—2 squares and downsampling until you find the overall minimum distance, then use a script to plug that in, but that's going to be a pain and unnecessary

heavy stirrup
#

is SampleSceneDepth linear depth?

regal stag
# heavy stirrup is SampleSceneDepth linear depth?

If you're referring to the URP function in DeclareDepthTexture.hlsl, then it's the "raw" value sampled straight from the depth texture.
In an orthographic projection it would be linear. But in perspective you'll need to put it through Linear01Depth(rawDepth, _ZBufferParams) (or LinearEyeDepth for units)

meager pelican
# young lantern Would that cause any issues with the texture getting stretched when the object g...

It can, that's why I mentioned the tiling and offset node may be needed to counteract that. If you stretch it 2x, you'd tile the result 2x, but I'm unsure of the exact computations you'd want off the top of my head because I assume you're using triplanar mapping of some sort (details of what you're up to are a bit light).

Tiling and offset for UV's are easy....tiling is just a float2 multiply and offset is a float2 addition.

So you seem to be saying that for, say, a brick wall, regardless of how long you make it, or how high you make it, or where you place it, the bricks stay the same size across the object (more bricks get added as it grows in a direction). Rotation on the other hand would be ignored in model/UV space and get applied later with the full scale/rotate/translate.

But see Cyan's post too. Note as he mentioned, those techniques won't work for rotations though.

tight phoenix
#

How does shader forge multiply differ from shadergraph? it has three inputs somehow?

tight phoenix
#

What's the easiest/best way to get random vectors pointing in any 3d direction?

#

a lot of them, each different, probably in object space ๐Ÿค”

tight phoenix
tight phoenix
#

better ๐Ÿค”

#

feels like im doing a lot of steps for something that should be much easier to obtain though

#

that and its not noisy enough

icy merlin
#

Is there any way to convert depth buffer into raw scene depth?
Second camera uses depth from main camera sadly.

exotic kraken
#

How can I do an image effect on everything except for the UI without a second camera?

exotic kraken
icy merlin
exotic kraken
#

The second camera doesn't have its own depth buffer?

icy merlin
exotic kraken
#

A shader should run once for each camera each frame. Are you saying the depth data is taken from the first camera's depth buffer even when the shader is running for the second camera?

#

What effect are you using the scene depth for?

icy merlin
icy merlin
#

item on second camera with the same shader

exotic kraken
#

What does the first camera render look like when taken from the same angle with the same objects in the scene?

icy merlin
#

if I change culling mask it would looks like that

#

but I need an item to be in orthographic projection so I use the second camera

exotic kraken
#

Does this error still exist when the second camera uses perspective projection?

icy merlin
#

I was trying almost everything. It doesn't depends on projection or any camera settings. All I found was a depth problem with second camera

lethal grotto
#

hi guys, im a huge noob when it comes to lighting and shaders, so does anyone know where a good starting point would be if i was trying to get my game (3d) lighting/shading to be cartoony, like not flat colors, but like pixar-ish, fall guys, or something like that yk

royal vale
#

Hey all, so I have a particle system that I'm trying to add a shader to. I have a texture that has all the particles with their trails, then another texture where it's mainly the density of the particles on the screen with whiter being more dense. My goal is to add reflective ish highlights onto the denser parts, then put that ontop of the nice colored texture.

How I'm trying to do it is I have a material that uses the density texture, then I call Blit(niceTexture, screen, material) so the (hopefully shiny) material is added ontop of the nice colored one

#

This has largely been unsuccessful lol, I'm using the standard material shaders provided and they usually just give me a black screen or will just change the color if I change the Albedo or Emission color

thorny falcon
#

im new to shader and was wonder if there was a why to add like noise to break up dirt to "sand" (surface shader)

shadow locust
#

sure you basically described it yourself - use a noise function

thorny falcon
#

yea idk how to apply it tho

karmic hatch
#

If you multiply a vector3 of 3 independent such random floats by a 'random' matrix you should get random rotations and so no cube symmetry

#

(probably also worth doing ((2x)-1), aka remap((0,1),(-1,1)) to the fracted numbers to let them be negative too)

#

The 'proper' way to create a unit vector on a sphere is to create two angles in the right distributions and then use some trigonometry

#

But that's slow

#

Iirc one of the fastest ways is to just generate random numbers in a cube and loop until one vector3 lands inside a unit sphere, then normalize.

#

But can't do loops in shader graph

#

Roughly half of the time you should get a vector inside the sphere so ig you could just repeat the procedure 3 times and accept that ~12% of your cells won't be spherically distributed

honest bison
#

Does anyone feel like explaining tangent space to me?

regal stag
# honest bison Does anyone feel like explaining tangent space to me?

Tangent space uses vectors from the model to stay relative to the mesh's surface. It can be different per-fragment/pixel.

The "normal" vector you might be familiar with, points out from each vertex/face - It's the Z axis of tangent space. The X and Y axis use the tangent vector and a bitangent (or binormal) vector (usually calculated from the tangent and normal, using a cross product).

The tangent & bitangent are also aligned to the axis of the UVs. The space is most commonly used for applying tangent space normal maps. You also see the tangent space view direction used in parallax mapping.

honest bison
#

What you really want for triplanar mapping is to calculate the unique tangents and bitangents for each โ€œfaceโ€ of the triplanar texture UVs. But, if you remember near the start I said donโ€™t do this. Why? Because we can make surprisingly decent approximations with very little data. We can use the world axis as the tangents. Even more simply and cheaply we can swap some of the normal map components around (aka swizzle), and get the same result!

#

I am trying to understand this method.

honest bison
native otter
#

At this stage I have setup my vertex 'wind' shader perfectly.
Now I wanted to only the ends of the tree leaves to be effected, so I painted them with vertex color.
I want to give the wind effect only at the outward parts (green vertex color), but it won't work.
If I hook up the red and green channel, then all the leaves are effected.
Am I missing something here?

#

lerp A is a position Node Object space

native otter
native otter
#

Yeah it works now, perfectly!

regal stag
#

But as I think Ben Golus is getting at, can use swizzling (reordering the components) rather than constructing transformation matrices to convert between the spaces. Which I think makes sense... as when you sample the normal maps they are already aligned to the world axis.

honest bison
regal stag
# honest bison Does that mean they are in world space then? We wouldn't need to transform them ...

Not quite. Take the planar projection from the top/bottom (Y axis) for example. We use the X and Z of world space position to sample that.

Lets assume a blank normal map for now, which stores values of (0.5, 0.5, 1), and becomes (0,0,1) after the NormalUnpack. That vector has 1 on the Z axis. But World-Up is 1 on Y. Hence it needs to be swizzled in order to "transform" it into world space.
(Hopefully that makes sense. It's quite hard to explain)

native otter
#

If I understand it correctly, I cannot simulated wind on non flat meshes like my branches with my vertex position shader, correct?
I get distorted geometry. I thought maybe I had doubles, but I think I need to rig the branches, or is it possible with my vertex position shader?

wary horizon
#

is cyan about (I dont want to ping) I'm using the blit render feature. But i have some floating damage text (3d Text, that the blit is occluding) I need it to render after transparents for the effect im making. But i also dont want it to occlude this 3D text i have. Is there a way to make this work?

regal stag
magic ravine
#

how can i make the sin wavelength shorter on the time node?

#

at the moment it stays at the end of the gradient for a couple of seconds

wary horizon
magic ravine
#

how do i make it 'bounce back' immediately

regal stag
# magic ravine how can i make the sin wavelength shorter on the time node?

You can't change the wavelength of the "Sine Time" but you could do Time output -> Multiply by some float -> Sine

The problem here isn't necessarily the wavelength though. Sine outputs a value between -1 and 1, while the sample gradient expects 0-1. You'd need to use an Inverse Lerp node (or Remap) first.

magic ravine
#

thanks!

exotic kraken
#

How can I do an image effect on everything except for the UI without a second camera?

desert orbit
#

You have to be more specific of what you are talking about. If it's about #๐Ÿ’ฅโ”ƒpost-processing , if UI is in screen space, it's not affected by post processing.

magic ravine
#

Im trying to make a rainbow gradient texture but i can't get it to swap between the colors smoothly

#

the sin wave seems to stop at 1 and -1

#

how can i make it flow nicely

regal stag
magic ravine
#

Awesome thanks mate

broken sinew
#

can I use the depth buffer from first pass in the next pass?

#

I want to render the backfaces to the depthbuffer in the Pass #1 and later read that depth in the Pass#2 in fragment shader

#

in some cheap way

#

I heard about command buffers and grab pass

#

but is there something cheaper (and shader-only)

#

i'm in built in render pipeline

elder ingot
#

im trying to create a simple lit shader shadows using an unlit shader

#

basically adding artifical shadows based on the direction of the face

#

it looks fine in the material preview (the right side is darker)

#

but looks fully black in the scene

#

does anyone have any idea why?

elder ingot
#

solved

#

turns out shader graph is buggy when you dont make the variables exposed

pearl frigate
#

Never worked with shader graphs before, but i have made a texture/material which is working.

Now i want to apply it to part of my procedural island, but it doesnt really apply, and i don't know how to do this.

As seen on this image, the texture works completely fine on the ball. The green that you see on the ground of the island is the exact same texture, but doesnt show the same...

shadow locust
#

what is the ground? Is it a MeshRenderer? A Terrain?

pearl frigate
pearl frigate
#

I am also not sure how to properly apply normal maps, rough and metallic maps... at all, but i guess ill figure out

#

But i still need to know how to get it onto a mesh

shadow locust
pearl frigate
shadow locust
#

depends how you made the terrain

#

if it's procedurally generated, you need to procedurally generate the UVs too

pearl frigate
#

I am also new to procedural generation if you cant tell :P

shadow locust
#

If you have no uvs it'll just use the 0,0 pixel of the texture everywhere

#

hence why it's all green

pearl frigate
pearl frigate
# shadow locust If you have no uvs it'll just use the 0,0 pixel of the texture everywhere

Would you be able to help out here? :-)

Getting this odd behavior now. As you can see here i got the uvs (somewhat) working. Right now they are just set to be equal to the vertices, to have it projected at the size of the triangles.

But for some reason it seems to be morphed by the shape of the terrain, but looking at the wireframe, the triangles are how they should be. Why does this happen?

shadow locust
#

I mean I can't really say. procedural uv mapping is tricky

#

it all comes down to which UV values you give each vertex

pearl frigate
olive hinge
#

When you have a Sample Texture 2D node in shadergraph, are the output color values, R G and B, 0 to 1?

#

it seems like for a pure green color, when mapped to alpha, is less than 1

broken sinew
#

how do I properly write to Z buffer :(

#

I have position in world space, but idk what value I should write

#

I don't know what kind of value should I write to SV_DEPTH

regal stag
# broken sinew I don't know what kind of value should I write to SV_DEPTH

Assuming a perspective projection,
Should be able to transform your worldspace position into view space.
-viewPos.z then gives you what is commonly referred to as "eye" depth.

Can then do the opposite of the LinearEyeDepth function, which should be :

float rawDepth = (1.0 - (eyeDepth * _ZBufferParams.w)) / (eyeDepth * _ZBufferParams.z);

That rawDepth should be the value you need to write to SV_Depth iirc.

#

(And in case of orthographic projection, -viewPos.z * _ProjectionParams.w should work)

broken sinew
#

Ok, thanks

#

I am amazed though, that there is no helper macro/function to Invert LinearEyeDepth

#

Does z buffer have values in range [0, 1]?

broken sinew
#

Or is it platform dependent

#

I heard that opengl has something else than gles for example,and in one or the other the buffer is inverted, or in a different range (-.5 +.5?)

regal stag
broken sinew
#

Ok, thanks, I'll try that

tight phoenix
tight phoenix
#

What should the output value look like? I can't get it to be anything but a single solid color, I am not sure how to then use it as random values

karmic hatch
#

idk if you can do that in shader graph though

#

well you can do equivalent

#

make 3 more random vectors (A, B, C), dot them with your random vector (R) and then combine them into a new vector3 (dot(A, R), dot(B, R), dot(C, R))

karmic hatch
tight phoenix
karmic hatch
#

ye

tight phoenix
#

that already works a lot better

karmic hatch
#

nice

tight phoenix
#

Is putting in just whatever in the matrix3x3 what I should be doing? I will google into the matrix node because I am not familiar with matrix math

karmic hatch
#

you would want the matrix3x3 to have random elements, otherwise you're taking vectors distributed in a cube and then just deforming that cube

#

if it has random elements then you deform each vector randomly so it shouldn't be far off a spherical distribution (if it's not a true spherical distribution)

#

though tbh vectors distributed across a cube are probably fine to get the rest of the effect working, then you can come back to making the distribution as good as possible later on

tight phoenix
#

Does "you would want the matrix3x3 to have random elements" mean having a random value in each of the 9 boxes?

karmic hatch
#

yeah

tight phoenix
#

I cant plug in anything to that node so I just put random numbers in from my head, okay

karmic hatch
#

you want it to change with each different cell value too

tight phoenix
#

Is that something I am not doing currently?

karmic hatch
#

but tbh just an identity (1,0,0; 0,1,0; 0,0,1) would be good enough to look OK, you'd just have more sparkles in some directions than others

karmic hatch
tight phoenix
#

How do I make the matrix not constant ๐Ÿค”

#

Matrix Construction?

karmic hatch
#

you'd have to put in a random number to each cell; it's equivalent to what i said earlier with the dot products with random vectors but also it's probably more important to get the rest of the stuff working so it actually sparkles then come back to it

tight phoenix
#

Oh

#

This looks pretty random now

#

Even more random than it did before

#

I will leave it at this and get the rest of the stuff working now like you said

karmic hatch
#

hmm combining like that seems dodgy since the vector3 is already made of those floats - i think that's just equivalent to squaring the vector3?

#

(hence also why it's darker ig)

#

probably doesn't change things much though

tight phoenix
#

Oh ๐Ÿค”

#

Ill plug them in a different order, so its not RGB both times

karmic hatch
#

just normalize and then use that to build the rest of the sparkle shader

karmic hatch
#

what you can do is abs the b component, then convert from tangent space to object/world space

#

means you never have sparkle normals pointing inwards (more sparkles)

#

you could also just overlay multiple sparkle effects on one another

karmic hatch
#

btw for my sparkle attempt, here is the bit that calculates the normal from the random vector3

#

and here's the specular part (taking in the normal vector and returning the brightness of specular reflection)

#

could be worth adding in a fresnel or something but that's the gist of it

#

the two outputs are multiplied further to the right

tight phoenix
tight phoenix
#

I keep following tutorial after tutorial after tutorial, am I just stupid? NOTHING I try works. I have examples that look exactly what I want, but when I try to follow them step by step, the result looks nothing like their output

#

I cannot make this glitter shader at all, im too fucking stupid

#
#

everyone else seems to be able to just make it work

#

and every fucking tutorial is just like 'take the dot of view and normal'

#

it never works, I dont know wtf im supposed to do because it never works, it doesnt do a single #$%#^&@ing thing

#

I keep looking and looking and doing tutorial after tutorial, going into crisis daily because im too fucking stupid to solve anything myself

#

and it never fucking works

humble robin
#

i actually came here to ask help

#

but you just made me realize

#

my error isn't that bad

#

thanks

tight phoenix
#

My problem isnt that im fucking stupid, its that I ALSO have crippling mental health problems

#

that make every aspect of my life 1000x harder

#

if I just couldnt feel feelings, I would be better than any other shader coder out there, because I could just mechanically produce content, practice 24/7, until I die

#

inject soma into my eyeballs please

#

back to the grind of being a worthless failure unable to achieve even the smallest shader effect

#

it hurts so badly to want to just fucking make nice things, to just have a single drop of worth or value, to not be a worthless insignificant piece of shit incapable of supporting themselves or making a single nice thing ever

#

I hate how incredibly bitter and angry and envious and hateful and jealous I am of every other talented artist that I cannot be no matter how hard I grind my blood and bone into the dirt spinning my wheels trying to acomplish a single thing that im too fucking stupid to do

#

im off the deep end now in mental health crisis, time to close discord until I calm down

#

and then try and fail to achieve anything all over again, and end right back in the exact same place, because nothing will change once I calm down, ill still be just as fucking stupid and clueless as before my fucking worthless stupidity pushed me into crisis in the first place

tardy oar
#

i got it to work but i would like to make it toggle-able and i cant seem to figure it out.

#

any help is appreciated!

long bramble
#

@tight phoenix Thats achually a really really complicated shader

rich silo
#

Can someone help me figure out why the color preview and the actual color on the line are so different here?

vocal narwhal
mental bone
#

I want to use a global texture array as a atlas for our environment in a Oculus 2 app. What would be the best way to encode the slice index into a mesh directly. Vertex color ?

mental bone
#

Also if anyone knows how to export extra data from Blender, that would be great. I would hate to have to write custom scripts in Unity just to get one extra float into the vertex pos or UV's

meager pelican
# mental bone I want to use a global texture array as a atlas for our environment in a Oculus...

That's always irritated me too. That there's no "user defined uint" (or whatever) value PER MESH. So you end up plugging the same value into, say, 100K verts on the one mesh. But when you think about it more, what you realize is that you probably want per-mesh-instance. Then we get into GPU instancing.

The thing is that instancing is a bit weird in the new pipelines. If you're in the BiRP, "just" use instancing to give each instance of the mesh a unique value per instance. In URP/HDRP, unfortunately, you end up having to create a unique instance of the material for each unique value. So you could have 500 green tree materials, each one having a unique uint or something so you can index into your global texture array. Argggh!

I much prefer the BiRP method of functional material property blocks. The URP/HDRP method just seems very wasteful and short-sighted, but I admit I could be wrong in my assessment. IDK if there's a way around it, because the engine is what assigns the mesh-instance-index as it draws each frame. So you can't go off and create your own CBUFFER for each instance.

mental bone
#

Well what I'm doing right now is to read the UV's of the mesh, remap them to a vector3 and set them back

#

that way we encode a extra byte into UV0 per mesh and use that in the shader as the slice index

#

we are not doing instancing, because we dont have a huge number of repeating meshes anyways

#

we are trying to optimize gpu bandwidht for the Quest2, basicly push as little data as possible per draw call

mental bone
#
 private void OnPostprocessModel(GameObject gameObject)
    {
        if(gameObject.name.Contains("chunk"))
        {
            Mesh mesh = gameObject.GetComponent<MeshFilter>().sharedMesh;
            Vector3[] newUV = new Vector3[mesh.uv.Length];
            for (int i = 0; i < mesh.uv.Length; i++)
            {
               newUV[i] = new Vector3(mesh.uv[i].x, mesh.uv[i].y, Int32.Parse(gameObject.name.Split('_')[1]));
            }
            mesh.SetUVs(0, newUV);
            gameObject.GetComponent<MeshFilter>().sharedMesh = mesh;
        }
    }``` pretty ugly code, but in the end this is how I got that extra byte into the uv
#

after that the sample is just half4 texColor = SAMPLE_TEXTURE2D_ARRAY(_EnvironmentAtlas,sampler_EnvironmentAtlas, input.uv.xy,input.uv.z);

#

works

ripe jackal
#

hi all, I'm trying to make a fire shader. The shader uses a 8x8 texture to determine what part of the tile that should be burning (and reveal another texture beneath). It works fine, but now I want to sample neighboring pixels as well, to make the edges better looking and more natural between tiles. To do this, I sample a 10x10 texture instead where all the edge-pixels are from neighboring tiles.

But here's the issue: I want to use the 10x10 texture when performing all Steps in the shader graph, but in the end I want to "crop" the shader (scale it) so that it doesnt include the edge pixels from the neighboring tiles. Does anyone know how to achieve this? Would greatly appreciate any help!!

grand jolt
#

I was looking for something like this but for URP: https://www.youtube.com/watch?v=b4utgRuIekk
Is there an asset or shader script that exist and can show object with light?

Let's make a revealing shader that is normally blank and full transparent, but when you shine a light on it becomes revealed. A useful effect for blacklight effects (think the Condemned blacklight as an example).

To accomplish this effect we're going to use a simple dot product calculation using the direction of our flashlight and the differenc...

โ–ถ Play video
mental bone
#

Use a spheremask node, raycast to determine sphere center, pass that data to the shader

hexed surge
#

it works, but it's so incredibly hairy in both the shader and the c# part, want to make something more robust and straightforward

native otter
#

Is the _TreeInstanceColor part of shadergraph GUI for control in the terrain paint trees (custom made trees)?

mental bone
open sable
#

Hey every one,
I have a shadergraph question:
How can I pass modified texcoord0 UV's from the vertex stage, to the fragment stage?

The vertex block has only Position, Normal, Tangent; but I'd like to plug in UV's that I'm modifying via a custom function, so that the UV nodes in the fragment stage (and the mesh it self for other shaders), use the updated UV's.

I can use a custom interpolator, but that seems a bit of a roundabout and not efficient way to do it.

I've fiddled with some semantincs, creating a vertex struct in the custom function I'm using

{
    float4 vertex : POSITION;
    float3 normal : NORMAL;
    float4 texcoord : TEXCOORD0;
};```

but so far, I can't get it to work. Halp?
regal stag
amber saffron
open sable
#

bummer

amber saffron
#

Ah, Cyan, always rapid firing here

regal stag
#

I'm not sure why you think it's roundabout / non efficient, it's not really any different from what you are trying to do in a custom function

amber saffron
#

I think that what he is trying to say is that it adds a non necessary interpolator if he doesn't care about keeping the original UV values.

#

I don't think it's a perf killer, but hey

regal stag
#

I see

open sable
#

Hmm, I always thought, that the way the vertex stage passes the v.info into to the fragment stage, it's streamlined and optimized.

And this way, it's doing 2 things: interpolating UV (which are bad for my use case) and does a custom interpolation, that will not work with UV nodes for example

#

Thank you. On the same topic. This is part of a bigger problem I'm facing, maybe you guys could point me in the right direction?
I'm creating a custom unlit terrain shader for use with instanced drawing. I got my terrain draw working, but for one of the effects, I'm using the Internal-DepthNormals texture (outlines)

#

the issue is...(I don;t really know what the issue is), the depthnormals texture is not beeing drawn on the instaced mesh (even though, the shaders seems capable of doing so)

regal stag
#

I think there may be some confusion as to what custom interpolators are doing. It allows you to do the calculation in the vertex shader and pass to the fragment. In the generated shader it's implemented in the similar way to using a TEXCOORDn semantic in the VertexInput.
(Though in this case, shader graph packs data into a "PackedVaryings" to make full float4 use of each interpolator. And uses INTERPn, but that should be the same thing as TEXCOORD afaik)

open sable
#

I have a suspicion, that in my case, the DepthNormals texture, is using the wrong UV's...

#

now the noobquestion: how could I supply the "good", uv's I get from the shadergraph, to the other shader

regal stag
#

The DepthNormals texture would be in screen space so should use the screen position to sample it, (rather than model UVs)

open sable
#

hmm..makes sense. So it could be vert positions that it's getting wrong...or something complety different?

regal stag
#

Can you clarify on how these outlines are being drawn? Is it a post-process effect?
Also what render pipeline are you in?

open sable
#

as a side note: Big fan of your work Cyan ๐Ÿ™‚

URP, the outlines draw is base on work done by NedGamesGames, using Sobel filters on the depth normals texture (after unpacking it and doing some filtering on it).

It works fine on normaly drawn geometry and terrain

#

It's the instanced bit, that screws it up

#

This is the code I'm using to make it work:

#define CUSTOM_TERRAIN_INSTANCING
#ifdef UNITY_INSTANCING_ENABLED
    sampler2D _TerrainHeightmapTexture;
    sampler2D _TerrainNormalmapTexture;
    float4 _TerrainHeightmapRecipSize;   // float4(1.0f/width, 1.0f/height, 1.0f/(width-1), 1.0f/(height-1))
    float4 _TerrainHeightmapScale;       // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f)
    UNITY_INSTANCING_BUFFER_START(Terrain)
        UNITY_DEFINE_INSTANCED_PROP(float4, _TerrainPatchInstanceData)  // float4(xBase, yBase, skipScale, ~)
    UNITY_INSTANCING_BUFFER_END(Terrain)
#endif
void setupScale()
{
}
 
void ApplyMeshModification_float( float2 vertXY, out float3 vertex, out float2 Newtexcoord, out float3 normal )
{
#ifdef SHADERGRAPH_PREVIEW
    Newtexcoord=float2(0,0);
    normal=float3(0,0,0);
    vertex=float3(0,0,0);
#else
#ifdef UNITY_INSTANCING_ENABLED
    float2 patchVertex = vertXY;
    float4 instanceData = UNITY_ACCESS_INSTANCED_PROP(Terrain, _TerrainPatchInstanceData);
    float4 uvscale = instanceData.z * _TerrainHeightmapRecipSize;
    float4 uvoffset = instanceData.xyxy * uvscale;
    uvoffset.xy += 0.5f * _TerrainHeightmapRecipSize.xy;
    float2 sampleCoords = (patchVertex.xy * uvscale.xy + uvoffset.xy);
    float hm = UnpackHeightmap(tex2Dlod(_TerrainHeightmapTexture, float4(sampleCoords, 0, 0)));
    vertex.xz = (patchVertex.xy + instanceData.xy) * _TerrainHeightmapScale.xz * instanceData.z;  //(x + xBase) * hmScale.x * skipScale;
    vertex.y = hm * _TerrainHeightmapScale.y;
    Newtexcoord.xy = (patchVertex.xy * uvscale.zw + uvoffset.zw);
    normal = tex2Dlod(_TerrainNormalmapTexture, float4(sampleCoords, 0, 0)).xyz * 2 - 1;
#else
    Newtexcoord = float2(0, 0);
    normal = float3(0, 0, 0);
    vertex = float3(0, 0, 0);
#endif
#endif
}
#endif // CUSTOM_TERRAIN_INSTANCING```
#

and also this pragma: #pragma instancing_options renderinglayer assumeuniformscaling nomatrices nolightprobe nolightmap
Edit: It's not a postproces, it's integrated in the shader itself

harsh marsh
#

Optimizing my LIDAR thingy. Rendering millions of points using instancing, want to use a better mesh for the points (currently using a low poly sphere).

Ideally, I want to use a quad but then I'd need to figure out a way to make sure that the quads are billboards and always facing the camera.

I've seen people do this from within the vertex shader but I've been having trouble applying it to my current code to the point where I'm just doing random stuff in hopes that something works so I've reverted back to the original code

v2f vert (appdata_full v, uint instanceID : SV_InstanceID)
{
    float3 instancePos=PositionBuffer[instanceID];
    float3 worldPos=v.vertex+instancePos;

    v2f o;
    o.pos = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0f));
    o.uv=v.texcoord;
    return o;
}   

Anyone know what I should do to worldPos in order to make sure it's always facing towards the view direction?

open sable
# harsh marsh Optimizing my LIDAR thingy. Rendering millions of points using instancing, want ...

Hey...dunno if this will help. I'm using this to rotate my tree billboards, maybe something will stick nudge you in the right direction?

{
    OutputData output;        
    float4 CENTER = In.vertex;
    float3 CORNER = In.inputNormals * In.uv2.x;    
    float3 worldspaceCenter = mul(unity_ObjectToWorld, CENTER).xyz;    
    float3 clipVect;    
    clipVect = (In.vertexWP + float3(0, In.uv3.y, 0)) - In.CameraPos; 
    float3 camVector = mul(unity_ObjectToWorld, CENTER).xyz - In.CameraPos;       
    if (length(clipVect) < In.CullDistance - 3 || length(clipVect) > In.FarCullDistance)
    {
        output.normal=0;
        output.tangent=0;
        output.vertex = 0;
        return output;
    }
    else
    {
    float3 zaxis = normalize(In.camVect);    
    float3 xaxis = normalize(cross(float3(0, 1, 0), zaxis));
    float3 yaxis = cross(zaxis, xaxis);
    float4x4 lookatMatrix =
    {
        xaxis.x, yaxis.x, zaxis.x, 0,
                    xaxis.y, yaxis.y, zaxis.y, 0,
                    xaxis.z, yaxis.z, zaxis.z, 0,
                    0, 0, 0, 1
    };    
    output.vertex = mul(lookatMatrix, float4(CORNER.x, CORNER.y, (yaxis.y - 1.0) * In.uv2.y, 1));
    output.vertex.xyz += CENTER.xyz;
        
    output.normal = -zaxis;
       
    output.tangent.xyz = xaxis;
    output.tangent.w = -1;
    return output;
    }
    
}```
(ignore the Cull parts)
regal stag
# open sable as a side note: Big fan of your work Cyan ๐Ÿ™‚ URP, the outlines draw is base on...

I see. If the feature is using an override material with the Internal-DepthNormals shader to generate the CameraDepthNormals texture then yeah that wouldn't include these mesh modifications so be drawing in the incorrect place.

And/or it could be that the instanced call doesn't even get included in the DrawRenderers call to begin with. I'm not too sure. Could likely confirm this by editing the outline shader temporarily to output the depthnormals to the screen. Or view the texture via the Frame Debugger window.

open sable
#

not beeing included in the DrawRenderers seems plausible, buuuut...I've had issues with the texture when using Indirect Instanced foliage.
Trees render with this method, were showing up in the texture

#

They were messed up as hell, I had to filterthem out, but they were showing up

regal stag
open sable
#

indeed it does

regal stag
#

Then yeah, that would be replacing the material/shader completely and might not be able to render the terrain correctly if it was intended to be instanced instead. I'm not too sure

open sable
#

hmm, woud there be a brute force way to supply the modified mesh info to the depthnormals shader/material?

regal stag
# open sable hmm, woud there be a brute force way to supply the modified mesh info to the dep...

Hmmm yeah, you might be able to put the terrain on a separate layer... that would allow you to filter it for another DrawRenderers call (assuming it shows up in that). Where you could then use a specific terrain shader that supports the instancing for the overrideMaterial.
Basically the same setup that is currently there, just duplicated with different FilterSettings / DrawingSettings

open sable
regal stag
#

For the record as well,
Technically, URP can generate it's own CameraDepthNormals texture now without relying on overrideMaterial. But it requires the shader to have a specific pass (using LightMode = "DepthNormals"). It's nice because that pass can include the same mesh modifications and it would then work...

... the annoying thing is that Unlit Graphs don't generate that DepthNormals pass. ๐Ÿ™ƒ

#

I think because it's mostly intended for the SSAO feature. And I guess it does kinda make sense for unlit objects to not have ambient occlusion.

open sable
#

huh, interesting

#

Yeah, most of my shaders atm are unlit. Switching them to Lit, might be an unnecessary hassle (even though I'm lighting the objcets up...just using custom lighting)

regal stag
#

Yeah, I still stick to generating my own depth normals texture when dealing with outlines since I tend to use unlit + custom lighting too.

harsh marsh
#

well I made a billboard shader that worked on a plane by itself but doesn't work on my instanced geometry :/

#

seems its rotating all of the geometry at once

#

I feel like at this point my only option is a geometry shader? not sure.

tight phoenix
open sable
open sable
rain niche
#

I converted my GLSL code to CG and I'm getting very different results from a lot of calculations. Are there any altered behaviours I should look out for when converting my code to CG?

rain niche
#

GLSL just doesn't work on Mac at all so CG is critical.

tight phoenix
#

everything I attempt ends up with either all sparkles showing, or none, never 'some but not at all based on angle'

#

I will punch myself in the face if someone tells me 'take the dot product of the viewing angle and normal vector' because I know that is step one, but then what do you do with that, because when I do that I get this:

open sable
regal stag
tight phoenix
open sable
rain niche
tight phoenix
rain niche
#

it also may be that vector components disappear when using simplified syntax

tight phoenix
#

random vectors โœ…
dot product of view and normal โœ…
any idea what im supposed to do next ๐Ÿšซ

#

I know the clown vomit random vectors in some way has to combine with the dot product, but what that way is is beyond me

regal stag
open sable
tight phoenix
#

they arent -all- showing there but like 90% of them are

tight phoenix
open sable
#

first thing is...test your shader on a material in the scene, not the oupput of shader graph

regal stag
tight phoenix
#

so its completely nonfunctional in scene

#

this has been my experience with every attempt, I do what im told, never works

#

also the back is double dark for some reason

open sable
regal stag
#

Then it should glitter in scene view too

tight phoenix
#

Ah yes scrolling up you are right, you said normal vector and I replaced view

regal stag
#

I'm not too sure why the back is darker though. That might be down to how the random vectors are generated. Hopefully with view direction it won't be noticeable? ๐Ÿ˜…

tight phoenix
#

Well now it doesn't glitter in preview but does in scene

#

which is extremely frustrating because there was no way for me to know the preview wouldnt preview how it actually looks

open sable
#

part of learning ;]

tight phoenix
#

it is however still super dark on the back

#

probably my random vectors like Cyan said

regal stag
#

The Main Preview is basically a fixed camera and you rotate the model, that's why it doesn't glitter there when using view direction. It's kinda annoying. I tend to always use scene view for previewing

tight phoenix
#

Oh

#

that's a problem then

#

yeah rotating the model in scene it doesnt glitter

#

Its gotta do both ๐Ÿค”

regal stag
#

Using Object space in the View Direction should fix that

tight phoenix
#

this is how I am generating random vectors atm

tight phoenix
#

my brain is wired backwards

regal stag
#

Maybe delete the Normal Vector node for now. Can always add it back in if you need it later

tight phoenix
#

yeah

#

behaviour in scene and preview is the same now, namely that it gets dark from certain angles

#

skipping all this didnt fix it

#

I've gotten this far on other attempts I think, but im stuck again that now its randomly dark on the back, and I have no ability to diagnose why

tight phoenix
open sable
#

what do you mean by randomly?

#

is it not because of the light direction?

tight phoenix
#

afaik light direction is not being factored into this at all atm

#

its an unlit shader