#archived-shaders

1 messages Β· Page 161 of 1

thick glen
#

Thank you all for your earlier help. Is there a way to read the component values of an object after a hit is detected with that object via the collider?

So something like

if(hit.collider.CompareTag("ObjectTag"))
               {
                        //code that returns Component Value;
            //code that returns variable value from script on the object                        
        }
grand jolt
#

Hi guys, is there any way to add an IF check in here via nodes that basically wont feed in the emission map if it's null?

meager pelican
#

@grand jolt I'm not sure I tracked the whole conversation, so grain of salt.

But normally, you'd do

  1. Whatever stuff to calc "normal" color.
  2. Whatever stuff to calc emission color.
  3. add them, with a saturate operation after.

Now, #2 could be multiplying by your emission map's intensity value. So if you have black in the map, that's a 0, so you'd be adding 0. But if it's a 1, then you'd get full emission color x 1, and if .5, 1/2 emission intensity.

So finalcolor = saturate(baseColor + emissionColor * emissionIntensity);

grand jolt
#

you mean multiply it all after adding in the graph?

#

@meager pelican

#

i'm very new to this shader graph stuff, sorry lol

#

and yeah emission maps are black / white

#

have to also admit the emission is definately duller than expected, had to up the intensity by 4

meager pelican
#

No multiply has precedence over addition.

float4 emissionColor = [whatever you do] * emissionMapIntensityValue.
return saturate(baseColor + emissionColor);```

Assuming you're not doing HDR.  If you are, lose the saturate operation.
#

So in SG, make boxes that do that. :p

grand jolt
#

yeah i'm using HDR, so I have to find a node that will combine the RGBA of _MainTex and the intensity value of the _Emission?

If so, any idea how to get the intensity of _Emission seeing as it's an RGBA texture input?
@meager pelican

#

theres the entire map btw, in case i did something stupid somewhere

meager pelican
#

You said the emission maps are black/white. Right?

grand jolt
#

yeah

meager pelican
#

So just pick off the red value or something. It will range from 0 to 1, right?

grand jolt
#

ohh I see, theres only 2 values gotcha, so I can use pretty much any channel

meager pelican
#

And you have a color variable for emission color.

#

So if your RGB emission color is (.34, .23, .86) and you multiply by your black emission map color (what you called null in your question above) you'd be adding 0 to your other main color. So no change.

But if you have a 1 in your map, you're adding (.34, .23, .86) to the color.

Then there's alpha.....you'll have to deal with that separately, that's almost always a pain.

grand jolt
#

ah.....these sprites do have some alpha around them

meager pelican
#

Just use the alpha from the main texture, or alpha clip with a threshold.

grand jolt
#

this all started with a damn Brackeys tutorial, I just wanted emission maps on 2D sprites XD

#

oh ok, already done

#

ok, so:

RGBA of _MainTex
multiply with
R of _Emission

? assuming i'm not still being a total noob at understanding this

meager pelican
#

I love Brackeys, watch him every week just for fun, even if I know the topic.
I wish he'd learn more shaders. He's doing more SG though, so that's cool.

#

RGBA of main text.
Add (emission color * R of _EmissionIntensityMap)

grand jolt
#

the issue I have with brackeys is a lot of their stuff goes out of date fast, considering his following surely he could hire someone to go through and edit old videos with corrective subtitles or something

#

ok, trying now

meager pelican
#

You're still going to have to do your vertex color thing too. That's all your "main color"

#

You did. πŸ™‚

#

Did it work? Don't forget to save changes.

grand jolt
#

testing now, wanted to make sure it looked ok, before Unity fries my hard drive somehow πŸ˜›

#

it......works UnityChanShocked ........according to what i'm seeing...

Does this solve the issue of _Emission being null? you mentioned it before but not sure if we addressed it with this

spiral agate
#
    col += tex2D(Tex, UV - float2(d,0));
    col += tex2D(Tex, UV + float2(d,0));
    col += tex2D(Tex, UV - float2(0,d));
    col += tex2D(Tex, UV + float2(0,d));
    col += tex2D(Tex, UV - float2(d,d));
    col += tex2D(Tex, UV + float2(d,d));
    col += tex2D(Tex, UV - float2(d,-d));
    col += tex2D(Tex, UV + float2(d,-d));

how do i put these into for loops?
first replacing 0->0, 1->d;
second replacing 0->(-d),1->(+d)

how would that look like in code
is radix4 possible in hlsl?

meager pelican
#

Black isn't null, it's zero. πŸ˜‰

grand jolt
#

well yeah, sorry, forgive my noobishness πŸ˜›

spiral agate
#

Does this solve the issue of _Emission being null?
@grand jolt just clamp / saturate your output

meager pelican
#

He's using HDR

grand jolt
#

it works it's fine, HDR

spiral agate
#

alright then, max(youremission,0), at least fixes negatives

meager pelican
#

It will never be negative. πŸ˜‰

#

Why do you want for loops for that?

spiral agate
#

not sure, less code is nice to handle is all

meager pelican
#

Yeah, it might be. But really, a shader compiler is likely to unroll the loop if it can and it's reasonable size. Unless you tell it not to. They'd rather chew up code space than branch. IIRC.

spiral agate
#

alright, i'll keep it as is then

grand jolt
#

one last thing actually, to avoid coding blunders, some of my code will likely try to modify the "_Color" variable, would I just make a new color property as _Color, then feed that into where the Vertex Color is going in?

#

then i'll set it to white default

meager pelican
#

I thought you were using vertex color to maintain compatibility with the sprite rendering.

#

But you can do it with your own value if you want. _Color or _Foo or whatever.

grand jolt
#

possibly, and it all works fine, i'm currently using:

mySpriteRenderer.color = Color.Lerp(mySpriteRenderer.color, discoColors[discoColorsIndex], t);

But i just wanted to see if I can make sure if I ever forget that and try using the:

mySpriteRenderer.material.color = Color.Lerp("_Color", mySpriteRenderer.color, discoColors[discoColorsIndex], t);

way it wont freak out in the console

meager pelican
#

Do you have a lot of these that need custom [Disco!] colors?

grand jolt
#

yeah virtually everything, the script is per-object at the moment

#

the arrays are set in start

meager pelican
#

OK, here's the deal. It's a unity thing with materials.

If you set material.whatever it CLONES THE MATERIAL, makes an internal copy, and assigns i to renderer.material. So if you have 300 objects, you'll end up with 300 damn copies of the material, and that chews up memory, and screws up GPU instancing in the standard pipeline.

In the new pipelines, it's different, sorts by shader as I understand it, so it might work out, but normally you don't want 300 stupid copies of the same thing save one value.

So what you do is use Material Property Blocks. And you set the color on that.

Normally.

For frigg'n sprites, IDK for sure though.

But whenever I see .materail, I freek out.

#

Mostly you want to use MPB's and renderer.sharedMaterial. But in the new SRP's that can break one of the batching routines for the experimental renderer.

grand jolt
#

well i've got a bunch of test objects in the scene and it doesn't seem to freak out the batching at all

#

it all instances fine

#

also, I have a BUNCH of performance coding in it

meager pelican
#

Yeah, it might not, but it WILL chew up memory.

grand jolt
#

basically:

If you cant see it
If the component doesnt exist
If it's a certain distance away from the player
If the relevant bools arent selected on the script

It wont even act πŸ˜›

meager pelican
#

Like I say, IDK about sprites in SPR yet. It all depends on how many is many.

grand jolt
#

aye, even I dont really know yet, but i'm also planning to multithread and entity system eventually so hopefully that will mitigate any problems

#

DOTS is a beast..

#

also object pooling

#

this thing is going to be performance-optimized, no friggin way im ending up on someones dirty devs list

meager pelican
#

Indeed. I'm exuding optimism.
Yeah, pooling virtually always good.

#

Goodnight all. πŸ™‚

grand jolt
#

thanks for all the help!

spiral agate
#

oh, found it, this may be actually what i wanted

spiral agate
#

now we are talking, awesome :3

#

got 3 different blurs down now

wary horizon
exotic estuary
#

I have a property exposed in my scene, and I can change the value in the shadergraph, but when I try to do it in the material inspector nothing changes. Anyone know where I might be going wrong?

#

(The property is an opacity variable and I'm pretty new to this fyi)

slow bear
#

What's cheaper for noise: a texture lookup or a function?

#

(in a situation where the shape of the noise is not important)

meager pelican
#

@slow bear Usually math is cheaper, but with low end mobile and if you're processing something pretty logically texture reads might be faster in some special instances, as low end mobile math can suck too, particularly when throttled due to things like heat or batter. IIRC. In general, favor math over memory reads. This is off the top of my head, and I'm not really up to speed so YMMV.

exotic estuary
#

Ok new question cause I sorted the old thing. How should I go about changing shader properties in runtime, and can I change them individually for each object?

#

I want objects to get transparent if they're close to the camera

#

Seems like quite a pain

meager pelican
#

You can have individual instance properties with Material Property Blocks, or by duplicating the material.

But for a nearness transparency, if all the objects share a material, then all you need to do is compute the distance to the camera position. The "shader" knows the camera pos, so you just use the worldPos of the frag and compute the distance. If it's < [some value] then go transparent.

exotic estuary
#

Right that would be ok except I want to use dither transparency

#

So theres no sorting hassle

#

So I'm trying to have one value for one object

#

By duplicating do you mean one material for every single object?

civic pike
#

hi there dear devs! has anybody an idea how I could create a mask for the scene fog in URP? I mean I would like to have a shader which is transparent and removes the fog on whatever will be rendered behind a mask f.e. thanks for any hints & tricks!

low lichen
#

@civic pike Can you explain what this is for? I'm having a hard time understanding exactly how this mask would work and what it would be useful for.

civic pike
#

imagine you are in a submarine for example. and you see the interior from outside. the interior should not be affected by the heavy fog which is surrounded outside the submarine

#

by seeing the interior from outside I mean that there is kind of a puppet house cut of the submarine, we are not looking through a window into it

low lichen
#

I see. Are you using the fog setting in the Lighting Settings window or a post processing fog?

civic pike
#

from the Lighting settings window

low lichen
#

Then the way the fog works is each object's shader is responsible for drawing fog in it. So if you make a custom shader that just doesn't do that, objects using that shader won't have fog on them

civic pike
#

I see, seems to be quite a task. Maybe I'm better off with a post processing fog.

#

What are the big disadvantages of a post processed fog, besides the performance costs?

low lichen
#

Well, post processing fog is applied globally and unless you customize the shader effect, you can't have some objects without fog

#

Unless you draw the outside environment first, then do the fog post processing on it, then draw the submarine interior on top of that.

civic pike
#

Yap, I think I get it πŸ™‚ Thanks a lot for the quick response! ❀️

low lichen
#

That shader would also add a custom fog effect, not reliant on the fog setting in the Lighting Settings window

civic pike
#

that's true, the point is that objects can be out or inside the submarine plus is the inner mesh the same mesh as the outer cover at the moment.

meager pelican
#

And if you're doing custom water and custom fog, you could use a stencil mask.

hollow grove
#

making custom volume from shader?

copper comet
#

I don't know if it's more of a shader or rendering question but I'm trying to use drawproceduralindirect, and it seems that the "start instance location" part of the bufferwithargs is not passed correctly to the shader ?

meager pelican
#

Huh. Standard pipeline?
What's happening?
Which function are you using (There's two signatures).

copper comet
#

yeah the standard pipeline

#

im using the first one (without the index buffer). I use the instanceid in the shader to get some drawing infos (textures, color etc) and everything is drawn using the infos at offset 0

#

maybe Im not understanding it corretly and start vertex position doesnt mean offset ?

#

(although it seems to work with the start vertex position but not the start instance position now that im doing some more troubleshooting)

meager pelican
#

God, it's been a while since I messed with this. They use the word "location"...but offset or index? πŸ˜‰

copper comet
#

i would've hoped that the SV_VertexID and SV_InstanceID were modified accordingly πŸ˜›

meager pelican
#

I know I've had it working. Did you fix it?

copper comet
#

no, not the instanceid

#

im wondering if I need to use the unity macros

#

but its not really unity instance ?

meager pelican
#

There's macros to handle it all.

copper comet
#

no ?

meager pelican
#

Here's MS's HLSL explanation. And it's set by the API for you. But there's sometimes issues with how you declare it, so use the macros.

But yes ( πŸ˜‰ ) it is the mesh instance.

#

And the vertexID will be the vert within the instance.

#

So you're going to have to do the math I guess. I'm trying to find you an example, but I'm juggling IRL stuff.

copper comet
#

yeah

#

not problem !

#

im still digging

meager pelican
#

But the instanceID won't give you the whole offset that you need. I think you're going to have to multiply by # verts and the zero-based mesh index. Or whatever.

copper comet
#

yeah it must be something like that

meager pelican
#

So for a 3 vert mesh, you'll get 0, 1, 2 in the verts for instanceID 0, and 0, 1, 2 again for instanceID 1, etc. All zero based.
So your offset index into your buffer is instanceID * 3 + vertexID to get the vert data in your vert();

copper comet
#

but im using several call to drawprocedural indirection with different values in the argumentbuffer, using it like this (number of vertices,number of instance, vertices offset, instance offset)

#

instance offset doesn't seem to be taken into account ?

meager pelican
#

What is happening? How do you know "it's not taken into account"?
I mean, you may need some debugging here to see, like render doc to see what values are coming in, or even a gpu-specific debugger (AMD, NVIDIA gpu tools).

I don't know, I don't remember it not working last time I messed with this.

Location would be byte offset IIRC, as I'm sure you know. Per docs:
has to have four integer numbers at given argsOffset offset: vertex count per instance, instance count, start vertex location, and start instance location.
And that sounds like what you're doing!

#

Is vertex offset the "span" for each instance, or an offset within the instance? I don't remember.

copper comet
#

im just debugging as colors but yeah you're right its time to fire render doc

#

i thing the vertex offset is the same for all instances

#

think*

meager pelican
#

Yeah, but I'm assuming you have different meshes in one buffer, so you're making multiple calls, right? And location starts are call-specific.

But I just don't remember the diff...because I probably started ver0, instance 0 at 0 offset, so start vert location and start instance location was the same? My head hurts, and I have someone trying to talk to me IRL. lol

copper comet
#

ahah

#

yeah thats what i do.

#

hopefully things will get clearer with renderdoc ! thanks for the help

meager pelican
#

I didn't help much. Maybe when I get a chance I can find my old code where I messed with this and see what I did. But it was probably the same mesh all the way through. :/

#

Keep me posted if you figure it out, because now it's bugging me. πŸ˜‰

copper comet
#

allright !

meager pelican
#

I guess the documentation could be a tad clearer on "start vertex location" and "start instance location" too. When would the instance 0 start at a different location than the vertex 0 of the first instance?

copper comet
#

hum apparently the two start location are not automatically set

slow bear
#

@meager pelican thanks for the reply; also, does favouring math over textures still holds true for Particle Systems?

copper comet
#

i dont know where i can access them

meager pelican
#

@slow bear Yes.
@copper comet Wut?

#

You set the start offsets

copper comet
#

yeah ! but the value i put in is not used anywhere

#

not matter what I set the result is the same

#

and renderdoc gives me the same values too et if i change the two offsets

meager pelican
#

Show me the C# that sets them

#

They're in that args buffer

#

Right?

copper comet
#

yeah

#

the 8 first int are 1920,1,0,0, 2880,1,1920,1

#

the code is a bit all over the place so there not a clear source i can show you

#

i draw two different mesh (they both have only one instance) one of 1920 vert at index 0, the other of 2880 vert at index 1920

meager pelican
#

You mean offset 1920?
That won't work unless you account for those 1st 8 ints. πŸ˜‰

copper comet
#

yeah offset 1920

#

the countbuffer is a different buffer than the buffer i read the vertex from

meager pelican
#

Oh, oops.

#

OK, if it's an offset, you have to multiply by sizeof item. You want a byte address.

#

Right?

copper comet
#

yeah

#

4*4, sizeof int is 4

meager pelican
#

So if your verts are float4's, that's 16 bytes each, yes? Because 32 bit float = 4 bytes each, x 4 floats.

#

Right.

copper comet
#

no i thinj the offset in the function is the offset in the count buffer

meager pelican
#

Dammit. I need to find some code.
Please stand by. One moment please.

copper comet
#

yup

#

no problem

meager pelican
#

We interrupt this program...

#

πŸ˜‰

copper comet
#

hum digging deeper i think either it's not at all how you should use that, or just it just doesnt work in this use case.

meager pelican
#

Yeah, OK.
And Unity docs say this Buffer with arguments, bufferWithArgs, has to have four integer numbers at given argsOffset offset: vertex count per instance, instance count, start vertex location, and start instance location.
So "start vertex Location" and "start Instance location" would be 0 offset from the start of the item in your 1st case? Because you don't have any misc data at the start of the mesh.
And then you'd have for your 2nd one
A big offset for startInstanceLocation and 0 for start vertex location?

copper comet
#

i think id have start instancelocation at 1 and a big offset for start vertex no ?

meager pelican
#

Did you get the 1st instance to draw?

copper comet
#

tbh my brain is melting :p

#

yeah it draws

#

both call draw the same thing except the second one draw a big more vertex

meager pelican
#

The whole thing is float4's right? No extra stuff?

#

So maybe your 1920 or whatever.

copper comet
#

in countbuffer its int

meager pelican
#

I mean the vert buffer

copper comet
#

my "vertex buffer" its actually a structured buffer generated in a compute shader and there's a bit more stuff

meager pelican
#

Oy

copper comet
#
            {
                float4 pos : POSITION;
                float3 normal : NORMAL;
                float2 uv : TEXCOORD0;
                float3 tangent : TANGENT;
                
            };```
meager pelican
#

OK OK OK πŸ™‚

#

So the size of the item is 12 floats x 4 = 48 bytes (thinking out loud)

#

And you have 1920 in the first instance

#

Starting at pos 0 in the buffer

#

Then you have another >1920 in the next instance

copper comet
#

the next instance is actually a new call (just one instance per call just to test)

meager pelican
#

So for your first draw call you're doing what? (that one works, right)

#

Yeah.

copper comet
#

im drawing the 1920 vert in one instance

#

im reading some data in my structured buffer, and some per instance data in an instance data Constant buffer

#

(with SV_instanceID)

meager pelican
#

Buffer with arguments, bufferWithArgs, has to have four integer numbers at given argsOffset offset: vertex count per instance, instance count, start vertex location, and start instance location.
You're setting up the arg buffer as
(1920, 1, 0, 0)

#

for the first call

copper comet
#

i would have hope the second call would have started the SV_vertexID at 1921 and the SV_instanceID at 1

#

yes

meager pelican
#

I would think so too

copper comet
#

right !!!

meager pelican
#

So for the 2nd call, what do you do that isn't working?

#

But since it's a 2nd call, it doesn't matter I suppose.

#

Come to think of it, I was expecting it to reset

copper comet
#

the second call draw the same vertices and per instance data than the first call

meager pelican
#

???

copper comet
#

even if the count buffer has the offset

meager pelican
#

how many verts in the 2nd call?

copper comet
#

but it draws 2880 vert

#

so it overlaps the second "mesh"

meager pelican
#

So you'd set argbuff with (2880, 1, ?, 0)

#

Wait!

#

Are you reusing the first set of verts, and just drawing MORE?

#

Or is it a completely different set?

copper comet
#

the arbuffer is like you said (with 1 in ?)

#

no

#

with 1920 sorry

#

im using the same structuredbuffer yeah

meager pelican
#

But not reusing the first set of verts. you have 1920 verts, and then 2880 verts. (your overlap comment confused me)

copper comet
#

yeah they are all in the same structuredbuffer

#

with the second mesh starting at index 1921

#

since i have an arbitrary number of meshes

meager pelican
#

So your second buff is (2880, 1, ?1920?, 0)? Maybe I have those last two backwards. sec

#

Because index 0 to index 1919 is your first set

#

1920 starts your 2nd set.

copper comet
#

yup

meager pelican
#

So your start Index Location (the last param) should be 1920?

#

If I read it properly (and IDK now)....

copper comet
#

i think its the one bfore last

meager pelican
#

So you'd set the buffer as
(2880, 1, 0, 1920)
Try that, but maybe I have it backwards. Spitballing.

#

The MS site says:

The index of the first vertex.

StartInstanceLocation
A value added to each index before reading per-instance data from a vertex buffer.```
copper comet
#

yeah i did that, to no avail 😦

meager pelican
#

And you tried the other way around. And that didn't work.
Hence your whole question here.

copper comet
#

yeah

#

im gonna try to see if i can ask someone at unity through my company contacts

#

this is mind boggling

meager pelican
#

I'm just extra stupid today, and I'm not trying it, I'm just trying to talk it through on a discord. ;)
I'll bet the forums would be more productive, if you post a question.

#

OH, maybe you have to add 32!

#

Because of your extra-structure data??????? And 0 offset for the vert, because it's the first structure member? Something like that

#

IDK Unity putting a pic in the docs, or more descriptive docs would help.

grand jolt
#

Hi Guys, got a problem with 2D sprite emission from yesterday, was hoping someone could help, The sprite is covered by emission is there if the sprite changes to a texture with no _Emission map

It would be great if I could add some sort of IF check in to make sure the _Emission is only passed if it exists....

(quite new, be gentle πŸ˜› )

copper comet
#

@meager pelican yeah i agree. Il let you know when my contact answer

regal stag
#

@grand jolt If you change the _Emission map mode in the blackboard to "black" rather than white, it will be (0,0,0,0) when not set so won't show anything.

grand jolt
#

@regal stag Firm handshake to you sir, many thanks!

Would you know any tutorials on modifying this so it reacts to realtime light? as sprites are lit, would like to make them as dark as their environment

#

"I keep seeing "make it a diffuse" in places but not sure if thats relevant to me in the graph method..

regal stag
#

I think you are in HDRP, right? If so, I'm not sure. I only know how to light sprites using URP's 2D renderer & Sprite Lit master.

grand jolt
#

damn, curse HDRP and it's graphical quality πŸ˜›

#

think I found one, let me try modifying

#

fail...gah

grand jolt
knotty juniper
#

why not try it?

copper comet
#

@meager pelican It seems that the vertex offset only work if you provide an indexbuffer (and its an offset into this indexbuffer) I guess per msdn doc that the instance offset only work when you provide a vertexbuffer but unity doesn't allow that ? Ill wait for my contact info, but I think i'm just going to pass 2 int in a materialpropertyblock which are going to be my offsets, and it'll work fine.

fast rose
#

has anyone found a GOOD water that works in URP and cheap for mobile?

finite sequoia
#

Just a quicky, is there any way to pass a Texture2DArray into a shadergraph?

meager pelican
#

@copper comet indexBuffer......
The first version has no index buffer, the 2nd one does. They map to two different calls in DX11. One isn't indexed, the other is. You're using the first non-indexed one IIRC. But it still has the params in question.

It might just be easier for you to have two buffers, since you're doing two calls anyway, and then just pass zeroes for the last two params.

#

Your first mesh drew fine.

#

I assume the index buffer is vert index list for shared verts. So there's the verts list, and the index (unity calls it triangles) list.

#

But you're not using that version.

bitter forge
#

quick optimization question, i'm looking to add a bevel to my models, is there an optimization or performance concern if i do this with shaders? whats faster / more optimized?

meager pelican
#

@finite sequoia Did you figure it out?
Check versions on the site, but there's a sample Texture2DArray node, so there's a datatype for it. I think I looked at the 9.0 SG, but that's probably not production ready yet. So check versions.

#

@bitter forge I know how to do that in an SDF, but with a regular mesh, it's harder, as you have to add geometry to pull it off, since you're dealing with flat-triangles and interpolation. If you want to do "lighting tricks" that don't actually change the mesh, but just the coloring (so you'll still have sharp "points" on the mesh like box corners) that's a manipulation of the surface normal for lighting calcs. Still hard.

Maybe someone knows of a decent way to "add bevel", but wow.

#

The fastest way is probably to add the bevel to the geometry, or use all SDF's, but you have to know what you're getting into. If you want it adjustable, maybe you can reverse it...add bevel, but figure out how to REMOVE BEVEL in a shader. IDK.

#

Shaders deal with polygons.

finite sequoia
#

@finite sequoia Did you figure it out?
Check versions on the site, but there's a sample Texture2DArray node, so there's a datatype for it. I think I looked at the 9.0 SG, but that's probably not production ready yet. So check versions.
@meager pelican I'm using the TextureArrayNode and I have it as an accessible property, I just don't know how to pass data into it πŸ˜‚ Material.SetTexture2DArray() doesn't seem to be in the documentation anywhere, and nor does the lambda expression I had before to pass a Texture2D in via Material.SetTexture(). I'm using the latest versions of Unity and Shadergraph

meager pelican
#

Not the Texture2D

#

So I guess the short answer is mat.SetTexture works for both. πŸ™‚

#

@finite sequoia

finite sequoia
#

Thank you for all of this! I'll give it a tackle and let you know if I have any issues 😊😊

#

You're the best @meager pelican

bitter forge
#

@meager pelican Thanks for that. For what i read its a pain to do in a shader since the "when to calculate" needs to be stored somewhere so I'm doing it in blender using the bevel modifier in the meantime, this will add topology but thats fine. might get away with baking.

umbral cargo
#

can I write custom code to use as a node in ShaderGraph that performs custom vertex displacement?

#

I think I can and then pass the results into exposed properties like this on the master node, correct?

meager pelican
#

can I write custom code to use as a node in ShaderGraph that performs custom vertex displacement?
@umbral cargo Yes

I think I can and then pass the results into exposed properties like this on the master node, correct?
Yes

#

(You should just try it!) πŸ˜‰

#

But the normal and tangents may need to be recalced if you're not extruding/reducing along the existing normal. If so, buckle up.

umbral cargo
#

ok, I think I am

#

just doing basic displacement map of the y-axis on a flat plane sort of thing

meager pelican
#

Well then no, you're not using the same normals/tangents. You need to calc new ones.

#

Because the normal of the plane isn't the same as the normal of a "hill".

#

The normal of the plane is Vector3.up basically. But that's not true on the side of a "hill". πŸ˜‰

#

What you'll end up doing in calculating 3 points near your vertex and trying to decide on what the normal is. Which sucks when the vert is a peak, and it will be. You should do some digging/googling.

#

The normal calc, once you mange to figure out what 3 points to use, isn't too bad. It's trying to figure out what 3 points to use that sucks. Since your shader only knows its one point that it's working on. But there's derrivitives, and there's other ways I guess. Like sampling your height map and making some kind of decisions.

There's got to be tuts and videos somewhere.
Then once you have the normal, you'll be able to calc the tangent.

umbral cargo
#

oh I see

#

originally I had everything unlit, but I do want it to be lit now, so I will need to do that

#

sounds fun 😰

meager pelican
#

It's been done, there's info, and past posts in this discord.

But I was thinking that as long as you're thinking about custom nodes (you don't need one just to use a height map, you can do that in regular SG notes) you might want to just output all 3 things....vert, normal, tan.

umbral cargo
#

Interesting. Wasn't aware there would be regular nodes that would do that.

finite sequoia
#

@meager pelican Sorry to bother you again, I've read through the articles you've sent me and from what I can tell everything I have done is correct. I am trying to blend textures together based on their heights from a float[,] heightmap. I'm in the process of switching everything over to URP and shadergraphs. The Texture2DArray does seem to be passed over from the TextureData.cs script; I had a couple of Debug.Log() thrown in to verify. I will throw you screenshots of the shadergraph as well as the original HLSL and .cginc file that I used for the custom function

#
const static int maxLayerCount = 8;
const static float epsilon = 1E-4;

int layerCount;
float3 baseColours[maxLayerCount];
float baseStartHeights[maxLayerCount];
float baseBlends[maxLayerCount];
float baseColourStrength[maxLayerCount];
float baseTextureScales[maxLayerCount];

float invLerp(float a, float b, float t)
{
    return a + t * (b - a);
}


float3 triplanar(float3 worldPos, float scale, float3 blendAxes, Texture2DArray textures, SamplerState ss, int textureIndex) {
    float3 scaledWorldPos = worldPos / scale;
    float3 xProjection = SAMPLE_TEXTURE2D_ARRAY(textures, ss, float2(scaledWorldPos.y, scaledWorldPos.z), textureIndex) * blendAxes.x;
    float3 yProjection = SAMPLE_TEXTURE2D_ARRAY(textures, ss, float2(scaledWorldPos.x, scaledWorldPos.z), textureIndex) * blendAxes.y;
    float3 zProjection = SAMPLE_TEXTURE2D_ARRAY(textures, ss, float2(scaledWorldPos.x, scaledWorldPos.y), textureIndex) * blendAxes.z;
    return xProjection + yProjection + zProjection;
}

void layer_terrain_float(float3 worldPos, float heightPercent, float3 worldNormal, Texture2DArray textures, SamplerState ss, int layerCount, out float3 albedo) {
    float3 blendAxes = abs(worldNormal);
    blendAxes /= blendAxes.x + blendAxes.y + blendAxes.z;

    albedo = 0;

    for (int i = 0; i < layerCount; i ++) {
        float drawStrength = invLerp(-baseBlends[i]/2 - epsilon, baseBlends[i]/2, heightPercent - baseStartHeights[i]);

        float3 baseColour = baseColours[i] * baseColourStrength[i];
        float3 textureColour = triplanar(worldPos, baseTextureScales[i], blendAxes, textures, ss, i) * (1-baseColourStrength[i]);

        albedo = albedo * (1-drawStrength) + (baseColour + textureColour) * drawStrength;
    }
}
#

^The .cginc function

#

Sorry, I know this is a lot to ask, but I am super stuck

meager pelican
#

That's asking me to digest a lot of code before breakfast!

Let's try some debugging first.
Somehow you're calcing "height" to decide what index to use?

#

Or you have a mask?

finite sequoia
#

Yeah, the height value is calculated and is the minimum and maximum values generated by the perlin noise

meager pelican
#

And you're passing that into the triplaner thing as the last param. With a 1-val?????

#

I think you want that to end up being the index to read from in the array, right? Tex[0], tex[1], tex[2]...basically.

finite sequoia
#

Yeah

meager pelican
#

So you should be able to output some values for debugging

#

So take whatever that calc is, ignore the rest, and output that into the RGB color value. If you want it greyscale, output it into all 3 RGB channels. You may have to scale it so it ends up being 0-1, so divide it by the max. What do you get for the scene result?

#

The most common/easiest way to debug a shader is to dump a scaled value into the color.

#

After that it gets more complex....frame debugger, render doc, or dedicated shader debuggers.

finite sequoia
#

So take whatever that calc is, ignore the rest, and output that into the RGB color value. If you want it greyscale, output it into all 3 RGB channels. You may have to scale it so it ends up being 0-1, so divide it by the max. What do you get for the scene result?
@meager pelican So how do I go about that, sorry?

meager pelican
#

I don't have my head around your code yet. Not awake!
But you end up with something that decides what to read. It looks like you're looping and blending though, and I'm not sure what all it's doing deciding on the blend.
My head hurts now. πŸ˜‰

#

Somehow you want to look at individual variables, like ss, or or a scaled color or whateer you're trying to examine

finite sequoia
#

It's okay, mine would too!

#

I wish I could just Debug.Log()

meager pelican
#

You kind of are! Just output the numeric value in a color. and throw that into albedo.

#

So if you want to check what ss is doing, output ss at some point into the color. And output that from the node into albedo.

#

You're hacking your own code, and bypassing most of it (well, ignoring).

In a "real shader" you'd just "return ss.xxx/50." or something. For debugging.

finite sequoia
meager pelican
#

In the code. within the custom function. It outputs albedo as a vector 3.

#

So set Albedo = ss.xxx/50 or whatever the calc is that makes sense.

finite sequoia
#

Ah lol

#

SamplerState doesn't have a .xxx , and I can't output directly into the albedo as you can't cast a SamplerState to a float3

meager pelican
#

Oh, sorry, wrong one. Not ss.

#

Some other variable that you want to examine.

#

I was thinking "i" index.

#

Or something.

#

Yeah, not the sampler state, bad example :p

#

Try just figuring out the height first.

finite sequoia
#

This code worked using just 'real shaders' though. This is the code I'm trying to replicate

void surf (Input IN, inout SurfaceOutputStandard o) {
  float heightPercent = inverseLerp(minHeight,maxHeight, IN.worldPos.y);
  float3 blendAxes = abs(IN.worldNormal);
  blendAxes /= blendAxes.x + blendAxes.y + blendAxes.z;
  for (int i = 0; i < layerCount; i++) {
    float drawStrength = inverseLerp(-baseBlends[i]/2 - epsilon, baseBlends[i]/2, heightPercent - baseStartHeights[i]);
    float3 baseColour = baseColours[i] * baseColourStrength[i];
    float3 textureColour = triplanar(IN.worldPos, baseTextureScales[i], blendAxes, i) * (1-baseColourStrength[i]);
    o.Albedo = o.Albedo * (1-drawStrength) + (baseColour+textureColour) * drawStrength;
  }
}
meager pelican
#

Alright! So in THAT code, heightPercent is the 0-1 value of the 0 to 50 (or whatev) for the y pos. That's good.
IDK what you're doing with:
float drawStrength = invLerp(-baseBlends[i]/2 - epsilon, baseBlends[i]/2, heightPercent - baseStartHeights[i]); yet. But maybe that works.

Let's find out.
output that into albedo, and return.
so Albedo = drawStrength; return;

finite sequoia
#

(also I have no idea why the water is white in game but previews fine in the scene view but that's a problem for another day lmao)

meager pelican
#

You can use unity's color picker and set some color somewhere (make a mat if you want) to the "pick" on any of those. You'll probably get 0's. Black. But you might get 0.00001 or something.

#

Just FYI.

#

OK, so your drawStrength calc seems to suck. At first glance. No offense.

finite sequoia
#

Hahahahah

meager pelican
#

So we have to figure that out.

finite sequoia
#

That's fine

#
Assertion failed on expression: '0 == m_CurrentBufferBindMask[kUnityPerDraw]'
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
``` is a new error
meager pelican
#

I think you had some issues in your video too, and that could also be a problem. But we're debugging here, we expect problems.

finite sequoia
#

Haha

meager pelican
#

But IDK what that unity error is right now without googling for it.

#

Let's make sure everything is set in the 2dArray.

finite sequoia
#

It's a pretty common Unity bug apparently lmao, it just crops up from time to time

#

Let's make sure everything is set in the 2dArray.
@meager pelican Okey dokey. The array length gets set correctly, and there is data there. The files get accessed properly and the Tex2DArray has contents

#

Debug.Log(texturesArray.depth); gives the correct depth of 6

meager pelican
#

yeah, in c#. But there's a long journey from there to the shader settings and outputting results.
Just output
albedo = SAMPLE_TEXTURE2D_ARRAY(textures, ss, float2(scaledWorldPos.y, scaledWorldPos.z), 3); It won't look right but I just picked "3". Or some damn thing. This triplaner thing is throwing it all off a bit, but we have to deal with that.

#

BTW, that float2 UV setting looks "funny".

finite sequoia
#

By all means correct me lmao

meager pelican
#

THat's not what I mean.
I mean in what I typed. It needs to be scaled...the scaled worldpos.

#

So if it is, it's fine.

#

But include that calc first to scale it.

#

ANd then put a "return;" after it.

#

This takes a lot of time to describe in a discord! :p

finite sequoia
#

Including that line you sent applies the Grassy Rocks texture stretched along an axis

meager pelican
#

OK, and that's the 3rd index (4th texture). So it's all in there.

#

Good. So we're sampling, and we're UVing something.

finite sequoia
#

Woooo 🍾🍾

#

We're living on a prayer

#

(because it seems like we're half way there.... It's okay, I'll walk myself out)

meager pelican
#

Yeah, I often crack myself up too. Not many others, but me, sure. πŸ˜‰

#

OK, so let's check this out:

        float3 baseColour = baseColours[i] * baseColourStrength[i];
        float3 textureColour = triplanar(worldPos, baseTextureScales[i], blendAxes, textures, ss, i) * (1-baseColourStrength[i]);

        albedo = albedo * (1-drawStrength) + (baseColour + textureColour) * drawStrength;```
#

The problem is the darn thing is inside a loop.

#

What's your basecolorstrength[] ?

finite sequoia
#

It's actually not needed. Before I used textures, I used block colours to show the different heights. It's part of the Layer class and can be adjusted to tint the textures, but it's not essential

meager pelican
#

You're adding extra stuff and making my head hurt again! πŸ˜‰

finite sequoia
#

lmao

#

I sincerely apologise

meager pelican
#

np

#

lol

#

OK, so drawStrength is still 0, but you invert that later in this loop. (1-drawStrength). Which makes no sense to me. But....maybe to you and I just don't understand what you're doing.

#

And I'm assuming you have baseColorStrength[] set to some non-zero values, right?

finite sequoia
#

the drawstrength is 0 if it is below the baseStartHeight for the index and 1 if it is above. This means that it is drawn at full opacity when it is between this layer and the next one and fades in from below

#

Yeah

meager pelican
#

OK, thanks. So baseColorStrength is which one?

#

The tint?

finite sequoia
#

Hold on, it would probably help if I named everything the same lmao

meager pelican
#

lol

finite sequoia
#

Consistency πŸ‘‰πŸ˜ŽπŸ‘‰

meager pelican
#

P.S.
Normally you'd paste code with something like hastebin.

#

If it's more than a few lines

finite sequoia
#

It's all on github if that helps

unique cedar
#

Hello just wondering I use Unreal engine and Redshit and they are using the same metal/rough shading workflow

finite sequoia
unique cedar
#

Now for Unity wondering if it's the same workflow too? it been a very long time since I opened Unity

meager pelican
#

OK, got the github terrain shader open, reading.

finite sequoia
#

I created a new branch called Convert to Shadergraph that has the current stuff we are working on in

meager pelican
#

OK, found the cginc custom node for terrain. Not much to it, looks worse in discord. :p

finite sequoia
#

hahahah

meager pelican
#

Shouldn't you have some += inside your loop or something? Aren't you accumulating the color?

finite sequoia
#

Ummm probably?

meager pelican
#

You're multiplying in that last line. Maybe that's OK. Maybe not.

#

You're basically doing a *=

#

albedo = albedo * ____

finite sequoia
meager pelican
#

In the end, divide it by # textures accumulated (average it).

#

Just to see

finite sequoia
meager pelican
#

You can do a blend too. Blending it a bit more complex. It's adding, with the other value, but using alpha to weight it.

#

OK, better.

#

Let's blend.

#

Check this for fun. (sec).

finite sequoia
#

Sounds interesting

meager pelican
#

so what you do is you blend in with alpha as an intensity (because that's what you're doing, an intensity). To blend, you can use several equations. But we'll try a few, and keep it simple. Additive blending maybe.

#

But weighted by strength.

finite sequoia
#

Okey dokey. What's the formula

meager pelican
#

Well, it looks like yours
albedo = albedo * (1-drawStrength) + textureColour * drawStrength;
if you imagine that the "draw strength" is the alpha.

#

I'm going to call drawStrength the apha.
so that's the very common alpha, one-minus-alpha blend. The more alpha you have, the less background you have. And vice versa.

finite sequoia
#

Yeah the drawStrenth is the alpha then

#

because it is how much opacity the texture has

meager pelican
#

Hmmmmmm

#

IDK why you got all white. Yet.

#

Can you maybe clone the material and make a test one, and then let's cut it down to two textures in the array (or 3 due to water).

finite sequoia
#

ofc

meager pelican
#

And remove the debugging out of the code.

#

So it's back to normal

finite sequoia
#

Yup

meager pelican
#

And what do you get with the first 2 levels only?

finite sequoia
#

Thee changes have been committed to the branch

#

Black

#

Not solid black though, the normals are applied

meager pelican
#

You should really only need to change the mat.

finite sequoia
#

i know

meager pelican
#

OK

finite sequoia
#

But we can talk about my bad coding standards later

meager pelican
#

Sorry

#

OK, so how about 1 texture, still black, right?

finite sequoia
#

Yup

meager pelican
#

Oy

#

OK, something is zero.

#

Let's find out what.

finite sequoia
#

Sounds good to me

meager pelican
#

We're only looping through...how many times? 1 or 2 now? (There's the water level pink color thing going on)

finite sequoia
#

Looping thorugh twice now, I have turned off the water shader

meager pelican
#

OK, so 0 is water, and 1 is the mountains.

finite sequoia
#

0 up to 0.3 is the water texture and anything above is grass, yeah

meager pelican
#

OK.

#

And that's y height...like up to 50, right?

#

or something? or is it %

finite sequoia
#

From the heightmap it's 1. There is then a multiplier that applies to the mesh generated

meager pelican
#

So scaled height

finite sequoia
#

yeah. Uniform scaling

meager pelican
#

Let's output the results on each variable

#

so inside this:

    for (int i = 0; i < layerCount; i ++) {
        float drawStrength = invLerp(-baseBlends[i]/2 - epsilon, baseBlends[i]/2, heightPercent - baseStartHeights[i]);
        float3 baseColour = baseColours[i] * baseColourStrength[i];
        float3 textureColour = triplanar(worldPos, baseTextureScales[i], blendAxes, textures, ss, i) * (1-baseColourStrength[i]);
        albedo = albedo * (1-drawStrength) + textureColour * drawStrength;
    }

Is what we're going to check out, when index == 1

finite sequoia
#

Okay

#

What do I have to do?

meager pelican
#

So make a float3 debugResult outside the loop.
And assign it with
if (i == 1) debugResult = baseColour;
and then after the for loop, before the end of the function, just assign
albedo = debugResult;

finite sequoia
meager pelican
#

Did you put the if after basecolor was calced (Sorry for asking that, no offense)

#

I assume you did.

#

So why is your base color black?

#

Is it supposed to be?

finite sequoia
meager pelican
#

Or is colorStrength[1] == 0

#

Well, it ain't. πŸ˜‰

#

lol

finite sequoia
#

the if statement is after the colour is assigned, eys

meager pelican
#

But actually, it should be the grass (1)

finite sequoia
#

And yeah I realised after I sent πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚

meager pelican
#

lol

#

So it's the color or the strength.

finite sequoia
#

It's black even if i == 0

meager pelican
#

So let's check each

finite sequoia
#

Okay

meager pelican
#

So set debugResult = to each part of the expression, and figure out what's zero and what isn't.
I'll BBIAB...

finite sequoia
#

bbiab?

meager pelican
#

be back in a bit

finite sequoia
#

Ah okay

#

Thank you for this btw!

#

I've taken up a lot of your time

meager pelican
#

np. But everyone else is going to kill us for 2000 posts. πŸ˜‰

finite sequoia
#

Pffft

#

What are they gonna do? Kick us for trying to fix some code/

meager pelican
#

IDK what they're doing in our discord anyway! πŸ˜‰

finite sequoia
#

Hahahhaa

meager pelican
#

So did you figure out if the color or if the strength is 0?

finite sequoia
meager pelican
#

OK, well that's a start eh?
So maybe plug in a constant of .5 instead for strength, and use two textures.

#

And then we can look at the C# code that set the strength array later.

#

Do they blend?

finite sequoia
#

Back to black with 0.5

meager pelican
#

It's the strength.
@finite sequoia
Prove that then. Because it's not. ;)
Let's see, output the strength in debugResult.

finite sequoia
meager pelican
#

Well then why didn't .5 work?
Confused.

finite sequoia
#

I have no idea, that's why I'm here....

meager pelican
#

lol Fair enough.

#

Let's try .5 again.
So debugResult = baseColours[i] * .5 should work.

#

with the if still there of course

#

And the assignment of it to albedo at the end

finite sequoia
meager pelican
#

OK THAT is what I was expecting.

#

Better now. πŸ™‚

finite sequoia
#

πŸŽ‰πŸŽ‰πŸΎ

meager pelican
#

lol

finite sequoia
#

NOW we're living on a prayer

meager pelican
#

Yeah. And a wing.

#

So... It's that strength array not being set. And all colors are 0? Maybe?

finite sequoia
#

seems plausible

meager pelican
#

lemme go find your C#

finite sequoia
#

Carpe

#

You're gonna hate me

#

Idk if this is gonna fix it

#

but

#

tehere's a typo

#

Still broken

#

Phew

meager pelican
#

You gonna make me search all your code for "setfloat" or you gonna tell me where it is?

#

πŸ˜‰

finite sequoia
#

TextureData.cs line 31 was material.SetFloatArray("baseColourstrength") when it should have been material.SetFloatArray("baseColourstrengths")

meager pelican
#

Ah. That WILL do it. (cause it not to work)

finite sequoia
meager pelican
#

Debug log it and make sure you have the values there in the array.
Sec...

#

In your orginal shader, it was singular (baseColourStrength)

finite sequoia
#

Yeah

meager pelican
#

Anyway, that has to match your setFloatArray call.

#

As you know

finite sequoia
#

It does now

meager pelican
#

You see those 3 errors you're getting?

finite sequoia
#

they're not errors... They are what I am outputting with Debug.Log()

meager pelican
#

Uh, it's saying the sampler macro isn't declared. For some reason, although I guess it worked before.

finite sequoia
#

Ohhhh yeah that's a visudal studio thing I think

meager pelican
#

Up to you, if you think it's just VS and spurious.

#

But if not, you'll get black results if it nulls it out or something.

#

Or worse, nans (that's usually something else)

finite sequoia
#

No change, mesh is still black

meager pelican
#

OK, so if you output the results of the strengtharray, it was black. I mean REALLY black = 0?

#

OK, and no more errors and you know it all compiled.

finite sequoia
#

Outputting the strengtharray gives it the colour of the index

#

No more erros and everythign has compiled

meager pelican
#

It should be a grey value between 0 and 1, right?

finite sequoia
#

What should, sorry?

meager pelican
#

The values in the strength array.

So
if (i==1) debugResult = baseColourStrength[i];
Or plural version of that. But whatever.
And return debugResult in the albedo.

finite sequoia
#

Ignore that

#

I'm an idiot

meager pelican
#

OK, good. And if you're updating that per frame, or starting and playing again, it should change based on texture 1's slider value in the inspector.

#

So that's not it

#

Now anyway, maybe was before with the typo, I'm losing track.

finite sequoia
#

Haha sorry I know this is a lot

meager pelican
#

@finite sequoia Uhmmm....
Where do you use the value you calculate for baseColour?

finite sequoia
#

To add a tint; albedo *= (1-drawStrength) + (baseColour+textureColour) * drawStrength

meager pelican
#

OK, what I'm seeing on my (maybe out of date github) is
albedo = albedo * (1-drawStrength) + textureColour * drawStrength;

#

That makes sense

#

that you added it in

finite sequoia
#

The line above is as it is in the old shader o.Albedo = o.Albedo * (1-drawStrength) + (baseColour+textureColour) * drawStrength;

meager pelican
#

Yeah, that's how it should be I'd think. So whatever I'm looking at is a tad not-whats-going-on

#

fine

finite sequoia
#

I just pushed everythign I have atm

meager pelican
#

And you know you have the result commented out at the end, right?

finite sequoia
#

OOF

meager pelican
#

It should be.

finite sequoia
#

Good then

meager pelican
#

Last I saw you had it at some value, like .3 or something, eh?

#

So that's the grey you're getting

#

So that's coming through.

finite sequoia
#

Yeha

meager pelican
#

Now just change your if to check the textureing results from the triplaner call.

finite sequoia
#

Wow I wish I could type

meager pelican
#

debugResult = textureColour;

finite sequoia
#

Oh I know, I was just talking about my typos

#

So that works perfectly

meager pelican
#

And if you removed the debugging (comment out) it's black?

finite sequoia
#

Correct

meager pelican
#

All lines commented out, including the last one (Reeeally sorry for asking that, just can't see your screen)

finite sequoia
meager pelican
#

Wait!

#

You changed the albedo calc!

#

???

#

Maybe I messed you up discussing it.

finite sequoia
#

I added basecolour back in yeah

meager pelican
#

You had = not *=
you had albedo = albedo * (1- __) + (stuff) * ___

finite sequoia
#

Eek okay I'll change the format

meager pelican
#

Yeah.

#

πŸ™‚

finite sequoia
#

Still black

meager pelican
#

WTHeck?

#

OK.

finite sequoia
meager pelican
#

You now owe me a beer, regardless of if I ever help figure it out.

finite sequoia
#

Oh I know

#

This is over 3 hours now haha

meager pelican
#

Dang it! still black.
S'OK, slow day.

finite sequoia
#

I didn't think it would be THIS hard to transfer something I already had in HLSL to shadergraph

meager pelican
#

It shouldn't be, but maybe ...it could be me too. It's hard to pick up other people's code, I should fire up unity and load your github, but that's like cheating.

#

lol

finite sequoia
#

You haven't already?!?

meager pelican
#

Just on a wild hunch, change your metallic in SG to like .3 for fun.

#

No.

#

My goal was to help you do shader debugging, not for me to do it. Technically.

finite sequoia
meager pelican
#

Still black when you run it?

finite sequoia
#
UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow.IsDirty () (at Library/PackageCache/com.unity.shadergraph@8.0.1/Editor/Drawing/MaterialGraphEditWindow.cs:255)
UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow.CheckForChanges () (at Library/PackageCache/com.unity.shadergraph@8.0.1/Editor/Drawing/MaterialGraphEditWindow.cs:265)
UnityEditor.ShaderGraph.ShaderGraphAssetPostProcessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Library/PackageCache/com.unity.shadergraph@8.0.1/Editor/Importers/ShaderGraphAssetPostProcessor.cs:66)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <fb001e01371b4adca20013e0ac763896>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <fb001e01371b4adca20013e0ac763896>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <fb001e01371b4adca20013e0ac763896>:0)
UnityEditor.AssetPostprocessingInternal.InvokeMethod (System.Reflection.MethodInfo method, System.Object[] args) (at <b85fd61302f04ebc817d5c985c202647>:0)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at <b85fd61302f04ebc817d5c985c202647>:0)
#

Yup and still black

meager pelican
#

OK wait a sec.
(searches dim recesses of memory)
you have a custom skybox, yes?

finite sequoia
#

Yeah I do

meager pelican
#

NO, that's not it.

finite sequoia
#

I can turn it off for now

meager pelican
#

I was thinking about something where skybox being messed up and not set in lighting tab turned everything black. but for you that's not it, because we can return a value in the shader, and it works.

#

What the hell is with all those errors?

finite sequoia
#

Meh, I'll use the default skybox just in case

#

Fuck knows

#

I've never seen them before

#

Shadergraph window stuff

meager pelican
#

If you keep getting errors save your work, including the SG, and exit and restart the damn thing.

finite sequoia
#

I'll do that now

#

Just restarted my PC, waiting for unity to boot back up

meager pelican
#

That's the spirit! no half measures! πŸ˜‰

finite sequoia
#

It's taking forever

meager pelican
#

lol

finite sequoia
#

Guess what? Still black

meager pelican
#

Errors?

finite sequoia
#

none

meager pelican
#

πŸ™‚

#

Let's give GOL a sec to chime in.

#

He's typing something

ancient kayak
#

Hello everyone! Do you know how i'd make a shader that takes the on screen position of an object and uses tht ro reference a texture? I want these asteroids to match the background

finite sequoia
#

@meager pelican dm?

meager pelican
#

Nah.

#

@ancient kayak what pipeline

#

And I don't understand your question, really. You can get screen position and map that to uv's to sample another texture.

ancient kayak
#

uh, universal i think lol

#

the question basically is - how do i make the asteroids take on the color of the background

meager pelican
#

Like if they're transparent?

#

Or reflection?

#

Or what?

ancient kayak
#

not quite either. essentially i want to recreate a foggy atmosphere, but using fog (to my knowledge) only makes everything one color

#

vs my backgrounds are gradients

meager pelican
#

That's different.
you want a texture-color based fog.

There's different ways to do fog.
You can apply it to each object...every object would have to be fog-aware. But you could always get that fog color from sampling a bg texture in screenspace. Then, as you set the color, you'd blend it with some fog color, maybe by distance.

If you do that, check unity's standard olde fog methodology.

But you can also do it as a post-process. That involves recoloring the screen, and applying distance based fog, possibly optionally maybe by checking the depth buffer so it's not at a far plane, or maybe by having a stencil mask for all objects drawn. or just all pixels.

That's done with a post processing pass and a full screen quad or triangle.

ancient kayak
#

😡

ancient kayak
#

Give me a sec to process haha

meager pelican
#

But you'll have to do the asteroids in a later pass. Or maybe scrap that scene color node, and just use screenspace to sample your bg texture to get the color

ancient kayak
#

That's different.
you want a texture-color based fog.

There's different ways to do fog.
You can apply it to each object...every object would have to be fog-aware. But you could always get that fog color from sampling a bg texture in screenspace. Then, as you set the color, you'd blend it with some fog color, maybe by distance.

If you do that, check unity's standard olde fog methodology.

I think I've seen "by distance" before, but that makes things change color the further away they get from the camera, right? I need things to change color based on the xy.

meager pelican
#

The distance isn't about the color, it's about the intensity of the color (more/deeper as it is farther away, less up close)

ancient kayak
#

Hmm. I'm not sure I follow/if we're on the same page. If all the bg asteroids are the same distance, how would we make them different colors?

meager pelican
#

You said you want to tint them toward the bg color. So pixel by pixel, you'd sample the background color at that point in the screen, and use that color. But how intense the fog is ...that's up to you to decide how to do. Often done by distance, maybe with a scalar so you can set intensity.

ancient kayak
#

Ah I see

meager pelican
#

If they're all the same distance (that's doubtful for a 3d object) then maybe just scale it.

ancient kayak
#

I guess now I have to figure out how to sample a screenspace texture

#

In case it wasn't clear, I'm a total noob with shaders lol

meager pelican
#

There's a node where you can get screenspace location. ANd then you can sample your bg texture if you can convert it to UV's (0-1 values for x and y)

#

google around and play with it, now that you have the general concept in your head. You'll get it. πŸ™‚

ancient kayak
#

Haha will do!

#

Thanks for the help!

meager pelican
#

np!

ancient kayak
#

If I end up struggling I'll be riiiiight back here

#

πŸ˜‚πŸ˜†

finite sequoia
#

It's okay @ancient kayak I know your pain

meager pelican
#

@finite sequoia Tell me you were debugging and you fix it while we were talking. πŸ˜‰

finite sequoia
#

Haha nope, I went and had some dinner lmao

meager pelican
#

They let you eat with code like that? πŸ˜„

#

OK, so I'm going nuts. Let's check the albedo outputs for index == 0

#

So in the if() check if i==0 and then save off albedo into debugResult, and output debugResult;

finite sequoia
#

I don't think I am doing inverselerp correctly

#

I think I'm only lerping

meager pelican
#

Could be, I think we got zeros. That's where we're going next

#

In that albedo calc.

finite sequoia
#

Hold on

#

This is what I had before...

float invLerp(a, b, t){
  return a + t * (b - a);
}

And I have now googled what the formula actually is

float invLerp(float xx, float yy, float t)
{
    return (t - a) / (b - a);
}
#

Changing the function gives a funky result...

meager pelican
#

I was going to bypass it next anyway

finite sequoia
meager pelican
#

Better I guess. But hang on

#

You know where you declare float3 albedo, and then set it to 0? Set it to .5

finite sequoia
#

Okay

meager pelican
#

OK now before your albedo calc, add a debug line and set drawStrength = .5;

finite sequoia
#

Like this?

if (i == 1) {
  drawStrength = 0.5;
}        
albedo = albedo * (1 - drawStrength) + (baseColour + textureColour) * drawStrength;
meager pelican
#

Nah.
Just maybe right after the inverserLerp line. Say "drawStrength = .5;"

#

Bypass the whole inverselerp thing

finite sequoia
meager pelican
#

I can't tell...did you remove the debug lines except for the new one?

finite sequoia
#

YEah

meager pelican
#

So it should now be blending each texture 50/50

finite sequoia
#

i think it is, yeah

meager pelican
#

What was happening before was that you started off with black, got 0 for your inverseLerp so you blended 0 with 0's original color

#

A lot

finite sequoia
#

Ah okay, that makes sense

#

Blending black with black

meager pelican
#

yep

#

So now you know A) how to debug this, even if the long way around, and also where to fix it.
Sec...I'm working on lunch for someone

finite sequoia
#

Okay!

meager pelican
#

OK, so way back you said this was the original source:

void surf (Input IN, inout SurfaceOutputStandard o) {
  float heightPercent = inverseLerp(minHeight,maxHeight, IN.worldPos.y);
  float3 blendAxes = abs(IN.worldNormal);
  blendAxes /= blendAxes.x + blendAxes.y + blendAxes.z;
  for (int i = 0; i < layerCount; i++) {
    float drawStrength = inverseLerp(-baseBlends[i]/2 - epsilon, baseBlends[i]/2, heightPercent - baseStartHeights[i]);
    float3 baseColour = baseColours[i] * baseColourStrength[i];
    float3 textureColour = triplanar(IN.worldPos, baseTextureScales[i], blendAxes, i) * (1-baseColourStrength[i]);
    o.Albedo = o.Albedo * (1-drawStrength) + (baseColour+textureColour) * drawStrength;
  }
}```
finite sequoia
#

Yup it is

meager pelican
#

So what that's doing is giving you back "t" for whatever value you have in worldpos.y

finite sequoia
#

Soudns right

meager pelican
#

What you're doing is
float drawStrength = invLerp(-baseBlends[i]/2 - epsilon, baseBlends[i]/2, heightPercent - baseStartHeights[i]);

finite sequoia
#

yup

meager pelican
#

and I'm not wrapping my head around that.

finite sequoia
#

Carpe I fixed it

#

We needed to saturate the result of the inverseLerp

#
float invLerp(float xx, float yy, float value)
{
    return saturate((value - xx) / (yy - xx));
}
#

Thank you for all your help! Now let me buy you a virtual beer

meager pelican
#

Oh, and also, shaders have an inverse lerp function.

#

InvLerp( a, b, value ) = t

finite sequoia
#

It's not a recognised symbol

meager pelican
#

huh.

finite sequoia
#

Which is why i wrote mine

#

Idk either

meager pelican
#

maybe I'm thinking smoothstep or C# or something.

#

But OK, if you can fix yours, you're gold.

finite sequoia
#

We got texture blending!

#

Just need to fix the water now lmao

meager pelican
#

Well, between the typo on the strengths, and also the invLerp thing, it was a combo problem, and hard to figure out.

#

Glad to help.

finite sequoia
#

Any ideas right off the bat as to why the water doesn't appear in Game view?

meager pelican
#

Is it SG?

finite sequoia
#

Yup

meager pelican
#

Seems like others have discussed such. I'm not sure the context. But off the top of my head, no. Maybe show the graph so people can comment.

finite sequoia
#

It's a big boi. I'm gonna do some googling first and see if I can fix it on my own

#

Just wondering if you had come across anythign similar in your time

meager pelican
#

Yeah, divide it up into parts. Use the color output trick to check values.

finite sequoia
#

:))))))0

meager pelican
#

It's probably got reflections, but I see you replaced the skybox, so that's not it. Sometimes you can get NaN's from invalid skybox or something.

#

I'd bypass any reflection calcs first, and just see if it's blue. Etc.

#

Also make sure you bake any lighting that you need to.

grand jolt
#

how do i make it look even better?

finite sequoia
#

@grand jolt personally, I'm not a fan of the blooming, I'd also give it a more shallow depth of field. Other than that this looks amazing! What's it for?

willow summit
#

anybody know how i tell a object not to cast shadows while having a costume pbr graph shader?

clever plaza
#

Hi guys, do you know why my wave shader is different on scene and game view?

I want to achieve the scene view look

grand jolt
#

@finite sequoia that is a picture from my survival game , my job in this is i make the graphics/map/main menu/character and controls

finite sequoia
#

Awesome! If you need anyone to test, hmu! @grand jolt

meager pelican
#

@clever plaza Possibly due to

  1. doing calcs in clip space vs worldspace units, which will impact:
  2. ?Camera pos differences showing different results?
clever plaza
#

@meager pelican

I see, so i should calculate the vertex in worldSpace?

Yes different camera pos / changing ortho size causing different result as well

meager pelican
#

I would think that you want the results to be world-scale specific, regardless of where the camera is viewing it from. Thus the scale of the sin wave should use world-units, and THEN go through the perspective/matrix changes. So in the distance, the waves would be very small on the screen but the same # of waves across the object. Same way the object scales.

The vert() shader needs to output clip-space, so that's good. You need to keep that much of it. But somehow, you need worldspace in there too. You'd probably have a separate worldspace calc variable. There's a unity_ObjectToWorld matrix you can use.

Or if you're not scaling it and don't need to transform the object accordingly, you can modify it directly in object space, changing it BEFORE the conversion to clip space.

clever plaza
#

Ahh okay,
Thank you for the detailed explanation.

After modifying the vertex wave (in object space) and then convert it to clip space, now the scene and game view has the same result.

Thanks again 😁

meager pelican
#

Just be careful how the scale and rotation of the transform works, or doesn't. πŸ˜‰ Depending on what you want. πŸ™‚

#

Cool that you got it working.

frozen mason
#

Hey guys. I need help. Im looking for a way to sample texture in order to change the vertices of my procedural cube grid so it would give me forward motion for specific cubes based on that texture. I want to build something like this. https://www.youtube.com/watch?v=6wWD3kxV1og&feature=emb_title
What I have is the procedural grid and some shader that can move the z axis of the vertices so it gives me that effect but cant understand how do I sample the texture so only cubes that match black or whit color would move instead of whole mesh z axis

Mechatronics in art. Hyper-Matrix from media group Jonpasang. More info: http://www.mechatronic.me/26 Hyper-matrix was shown at the exhibition EXPO 2012 in Hyundai Motor Group pavilion in Korea. In show were used small cubes that moved on specially prescribed program.

β–Ά Play video
meager pelican
#

@frozen mason
But if you're adjusting verts (or position) in the vertex shader you'll need to use tex2Dlod to sample in a vertex shader stage. Then you can adjust either the position, or extrude verts along their local object z axis probably BEFORE you transform it to clip space.

frozen mason
#

@meager pelican URP. So with the above shader I can extrude verticec on z axis but I tottaly dont know how to incorporate texture sampling into that. So black will be 0 extrude and white will be full extrude
Im total noob with shaders.

#

so forexample in this gif it would be the dark grey would not move where the white grey only move

meager pelican
#

We have a Cyan for that. Wonder where he is? πŸ˜‰

regal stag
#

Vertex offsetting involves adding or subtracting a value from the existing position. If you were to multiply that offset with the result of a texture sample before the add/subtract, it would give the result you want.

#

Assuming the texture is black (0) for no offset, and white (1) for full offset

#

And as Carpe mentioned, since it's in the vertex stage you need to use the tex2Dlod / Sample Texture LOD node, as the normal texture sample can only be connected during the fragment stages.

frozen mason
#

Yeah I know about LOD node from multiple articles. What I dont understand is how to properly connect the nodes to get this

If you were to multiply that offset with the result of a texture sample before the add/subtract, it would give the result you want.

regal stag
#

Yeah, I'd probably do the multiply after the Branch so it affects both the Left and Right extrudes at the same time, assuming you want it to.

frozen mason
#

tried that. Don't seem to give me the effect. Still extrudes all of the vertices of front ond back face

regal stag
#

You could also swap the "Comparison -> Branch with 0 and 1" from the texture sample for a Step node. I think they would be identical but makes it a bit more readable imo.

#

If I'm not mistaken, both the grey colours in the texture are over 0.5

#

Think they are around 0.62 and 0.78 from using the eye-dropper tool in paint

#

If possible I'd just switch it out for a custom black + white texture.

frozen mason
#

You could also swap the "Comparison -> Branch with 0 and 1" from the texture sample for a Step node. I think they would be identical but makes it a bit more readable imo.
@regal stag hehe not feeling what you mean. The comparision and branch is clear for me at least for now so I know whats happening somewhat

regal stag
#

Might be that the UVs are too close to the transition on the texture. Maybe messed up by the linear filtering. Don't know if using point mode would fix it or not though.

#

Would be a setting on the texture in the inspector, or you could connect a Sample State node to the Sample Texture to override it

#

I think I'd probably use the position of the center of the cube to sample the texture (using the Object node), that way all four vertices will always be the same

#

Also is each of these black/white blocks a separate cube?

frozen mason
#

Yeah might be the UV i had a problem with setting them on my procedural cube grid. I thoguh I did them properly as compared to the unity default cube and they looked
the same.

#

Yeah it is

#

I;ve added Sampler state and set it to point filter and wrap repat and increased comparision threshold for the texture and this is the effect Xd

#

I think I'd probably use the position of the center of the cube to sample the texture (using the Object node), that way all four vertices will always be the same
@regal stag whoa that's something new. Truly don't know what ure talking about. Im really soryy being so hard to work with. I have 0 experience with shaders 😦 Apologise

regal stag
#

If you are generating the cubes procedurally you could set the UVs for all points in each cube to a single point in the texture. That way it would always be inside the black/white parts, rather than on the edge. Unless you actually need these UVs for applying a texture to each face too - in which case you could use two separate UV channels to pass this information into the shader.
I think you'd basically want each cube's UVs to point to a different pixel on the texture.

frozen mason
#

so the UV mapping gave me a lot of headache. THis is what I do for the texture

private void SetUvs() {
        float tilePercentX = 1 / texturePixelSize.x;
        float tilePercentY = 1 / texturePixelSize.y;

        float uMin = tilePercentX * tileX;
        float uMax = tilePercentX * (tileX + 1);
        float vMin = tilePercentY * tileY;
        float vMax = tilePercentY * (tileY + 1);

        _uvs.AddRange(new[] {
            new Vector2(uMin, vMin),
            new Vector2(uMax, vMin),
            new Vector2(uMax, vMax),
            new Vector2(uMin, vMax),
        });
    }
#

So giving it tileX = 0 and tileY = 0 it would give me the bottom left square at least that what I think it should πŸ˜„

regal stag
#

Right, so I think if you did

float v = tilePercentY * (tileY + 0.5f);```
for all four vertices / _uvs, it would be a point in the center of the pixel for each cube/tile.
frozen mason
#

Oh I get where you going. Yeah, make sense

regal stag
#

That way it's unlikely to bleed into other pixels and cause issues, and I see no point of the min-max unless it's bigger than a pixel and is used to apply an actual texture/pattern.

frozen mason
#

Fik ME!! IT WORKED

#

OMG @regal stag you are the god!!! Holy I was fighting with this for 2,5 weeks. Im so happy YEAAAAA

#

Holy moly... Fianlly. Thank you so much man! I love you and your blog. It's very helpful!

regal stag
#

No problem, and thanks! πŸ’™

humble mantle
#

How do you use shuriken particle system with hdrp? My particles dont fade nor do they show the colors, the particles on show the colors from the sprites (which are just white)

#

I cant find anything helpful online either, so kinda stuck here

regal stag
#

I believe shuriken particles use vertex colours

humble mantle
#

is that not compatible with HDRP?

regal stag
#

Should be, the shader just needs to take it into account. If you are using shadergraph there's a Vertex Color node.

humble mantle
#

I am just using the default hdrp lit shader with shuriken, I assumed it would work like all previous default shaders Unity offered

regal stag
#

I don't think the default lit shaders tend to use vertex colours. Usually you'd use a Particles shader. I assume HDRP has a particle material somewhere

#

If not, could probably create one via shadergraph instead.

humble mantle
#

I am an absolute rookie with shadergraph, is CG still a thing with HDRP?

regal stag
#

Uh not really. I'm more familiar with URP but while you can write written vert/frag shaders there's a bunch of differences. It's a lot easier to use shadergraph.

humble mantle
#

Alright, cheers for the info, I will be spending some time on tutorials then ❀️

pure flume
#

Hey, does anyone know a good starting point in shadergraph for isolating certain parts of the frame to be rendered? Say I have a sphere and want everything thats inside that sphere to have a changed color or be blurred.

#

I'm trying to figure something out with camera position or view direction and calculating from there but I can't even begin to get my head around this.

fervent tinsel
#

@pure flume urp or hdrp?

pure flume
#

@fervent tinsel hdrp

fervent tinsel
#

you can use HDRP's custom passes for something like that

#

you could also use stencil mask but you also need custom pass atm to set the stencil bits and it's 100% undocumented

#

@pure flume check especially the glitch effect from that

#

it's using shader graph along with custom pass config for the effect

#

(no coding required for that)

pure flume
#

I had seen bits of that custom pass stuff, but didn't understand it well enough to determine if it was what I needed

#

I suppose getting the effect I want from a normal shader applied to a single object doesn't really make sense

#

I will read through it again and try to apply it. Thanks πŸ™‚

fervent tinsel
#

if you just want to change the color of single object, you could just do that on one custom shader

#

no need for custom passes and stuff

pure flume
#

well I'm not sure if I'm explaining it correctly

#

what I want is more complicated than that though

fervent tinsel
#

well, can you explain what you really are after?

pure flume
#

I basically want special effects (not entirely decided yet, possibly greyscale or blurring etc.) applied to a specific volume, more or less

#

if I applied the shader to a box lets say, I would expect everythign inside that box to be rendered in this special way any anything out of it normally

#

or vice versa

#

*and

#

thinking about it, it does sound like a fullscreen pass

#

with some depth buffer magic

#

rather than a standard surface shader or anything like that

knotty juniper
#

The volume does refer to if the camera is inside that volume it uses the effect
not if the object rendert is

pure flume
#

sorry, I don't quite understand. are you asking a question or telling me?

knotty juniper
#

Telling
if you are refering the the post effect volumes

pure flume
#

I'm not really referring to anything specific tbh

#

Since I'm not entirely sure what it is I need

#

current theory seems to be Custom Passes

#

not post processing effects exactly

knotty juniper
#

Custom Passes sounds good

pure flume
#

Well, I guess this is a little above my paygrade for now πŸ˜„

obtuse dirge
#

Getting Openssl error trying to upgrade to HDRP 7.4.1 from 3.1 , Unity 2019.3.13f1, but all the requirements went fine

#

ON top of that , after trying to send in crash , 10 min later or so, said unable to write ,,,?

warped field
#

is there any shaders for a sketchy cartoon look

#

?

#

not just a outlike but like a scribbly shader

hexed portal
#

for anyone doing procedural terrain and wanting to avoid this kind of thing

#

just found a blending algorithm that seems useful

#

they pretty much store both textures' "depth maps" as grayscale versions in their alpha channels

fervent tinsel
#

@hexed portal looks like pretty stock standard height blend

#

HDRP's terrain shader supports that out of the box

#

I dunno about URP as I don't use it

hexed portal
#

yeah, I don't really need the features from HDRP/URP at the moment but this specific functionality was nice to find

fervent tinsel
#

I bet many 3rd party terrain shaders implement that as well

#

it's pretty common technique

hexed portal
#

I didn't actually know how it worked until reading that tbh

#

didn't know it was that simple

ancient kayak
#

@meager pelican i'm baaaack. idk if you're online though lol

#

does anyone know how to make fog affect individual elements differently? vs just having one global fog?

soft harness
#

So i'm trying to have this heart beat thing, but it's not exactly working. Any way to have this be a more heart beat like pattern? float beat = lerp(v.r, 1, sin(_Time * 50));

royal night
#

Any idea why would be getting the error

maximum ps_5_0 sampler register index
``` when I'm trying to modify a third party shader that is in a my assets?

The original is imported/compiles fine, but when I make a copy and move it into a different folder, it starts throwing that error.
burnt wigeon
#

@soft harness check LeanTween or DotTween

soft harness
#

What?

royal night
#

nevermind, I think I see what's happening, the folder I copied it into had some overrides for UnityPBSLighting.cginc and etc, and I think one of the parent includes has more samplers defined.

burnt wigeon
#

@soft harness Or animation curves. Tweening engines let you the stuff you wanna do with one line

#

you could pass an animation curve to your lerp too and tune it the way you want

meager pelican
#

@ancient kayak Well, you didn't define "differently", but we talked about two ways to do fog...on the objects themselves as you draw them, or with a post-process of the screen.

If you want each object to have different fog based on not just the background color, but some attribute of the object, I suppose the "do fog as you color the object" method would be most attractive. Then you can do whatever you want as you assign the color.

But I'm guessing here, as I'd can't really tell what you're after.

#

The "do it as you go' method has the advantage of not needing a 2nd pass of the screen in post.

#

But it's limited in some ways too. Like harder to do volumetrics and shadows in the fog...because it only knows about itself since the scene isn't constructed yet, and shadow passes happen later.

#

I suppose you can have a hybrid approach where the object writes to some buffer (maybe stencil) and then the post-process knows about that, and can use the customized info to do whatever you want.

soft harness
#

Also ignore the weird aspect ratio thing

signal rapids
#

Hey! Sounds like a simple thing, but I can't figure out how to create a warp effect like the warp node in Substance Designer. I want to push/push areas of my texture with a normal map or a noise. Can someone point me in the right direction? I'm using Shader Graph in HDRP

grand jolt
#

is there a way to transfer vertex paint data to other LODs? i realize it wont be exact because different meshes, i just need it more or less similar

meager pelican
#

@signal rapids So your UV sampling would be modified by some warp-calc, like noise. Done all the time, usually just adding some offsets to it. Remember that UV's range from 0 to 1 for x and y.

#

@grand jolt it has to be built into the model's vertex colors and/or UV's. If you're using procedural geometry, you'd calc that anyway.

grand jolt
#

@meager pelican so theres like no way to make every single object unique without having unique prefabs? i just wanna mix it with shaders later, LODs are for extra performance. should i use one LOD then?

fervent tinsel
#

use decals / shader with randomization that doesn't rely on vertex color

#

or simply use mesh without lods

grand jolt
#

no lods method is kinda dirty πŸ€”

#

isnt ther option in polybrush to paint on all lods?

meager pelican
#

LOD's are kind of debatable, they're good for far-off objects, otherwise it's mostly about on-screen pixel count, not triangles per se. Popping is a problem close up. One of the experts here had a post/article about it...I think it was Jason Booth.

Anyway, so if you want LOD's, and you only need one or two max, you'd have to paint them too. That's if you want painting that way with a tool. The other way is to just "paint" the texture that you've uv unwrapped into.

grand jolt
#

Hello I use DrawMesHInstanced instancing to draw thousand of objects on screen which used to work fine on all platforms.
some months ago after a chrome update the instancing on chrome is meshed up while on firefox/windows build everything is ok
any ideas?

fervent tinsel
#

ah yes, you can use "splatmap"

#

I think tools like substance painter has some built-in support for like 4 layer materials

#

but chances are that you'll pay more from texture lookup overhead than what you'd pay for simply having one lod

#

your mesh doesn't exactly shout highpoly to me

#

like with all perf related things, don't assume, measure

#

make some prototypes with estimated polycounts and see if it matters at all

meager pelican
#

Yep, measure.
But there's some givens. Like those hi-poly mountains you're walking on up close...if you use them for distant backgrounds...well, you don't want one triangle per pixel or worse multi-per-pixel, since you overload the vertex shader stage for no reason. So a lower-poly version is great...until you travel there.

brisk bison
#

I downloaded a transparent terrain shader, but it's having strange bugs on my terrain

#

I got it from here

#

If I make a new terrain and apply a transparent texture, it seems to work fine

#

So, why would it only have a problem with my current terrain?

#

Interesting, turning off GPU instancing seemed to stop the bug

fervent tinsel
#

@brisk bison I'm curious, why would anyone need transparent terrain?

brisk bison
#

Mainly because I need to cut out part of the terrain, and I can't find any way to do that

fervent tinsel
#

there's terrain holes

#

exactly for that

brisk bison
#

I'm using Unity 2018.4.20 sadly

fervent tinsel
#

ah well

#

why? πŸ˜„

brisk bison
#

Enforced requirements

#

I'd use the latest if I could

fervent tinsel
#

I actually totally understand that

#

2018.4 is still more stable than 2019.4 IMO

#

and if you use built-in renderer, there's not all that much new on 2019

#

(better terrain though, and newer physics engine)

brisk bison
#

The terrain tools has me drooling, it's sad I can't use it :/

fervent tinsel
#

yeah, it's a nice improvement to the previous setup that was unchanged for a decade

#

just for holes though, you might get better perf with opaque shader that does alpha-cut

#

don't ask me how to do it for this though πŸ˜„

brisk bison
#

I'm trying to basically cut a plane (water) through the base of the land. For my use case, I need it completely see through to the underside of the world (absolutely nothing, just the skybox)

fervent tinsel
#

for that you could also just have multiple terrains that align so that there's a hole in the middle

brisk bison
#

So I figured , if I can't cut the terrain, made I can use a shader to render it transparent

fervent tinsel
#

but even that would be easier to do with newer terrain where you can adjust terrain across the seams

brisk bison
#

Yeah, the 2018 tools are a little limited with that kind of flexibility

fervent tinsel
#

for the terrain shader and gpu instancing... did you just copy paste some shader from internet or did you modify a 2018.4 terrain shader?

brisk bison
#

Copy and paste basically lol

#

I'm not well versed in shaders

fervent tinsel
#

there are probably some changes on the terrain shader which are required for the gpu instancing to work

#

when you hit the Downloads (Win) etc dropdown there, there's an option for Built in shaders for the version you select

#

shaders that ship with the editor are compiled so you can't realistically edit them as is, you need the source code which is on that mentioned link

brisk bison
#

Ahh. I bet that if I could write shaders, I could make it render transparent below a certain height

fervent tinsel
#

sure

#

that's actually not that difficult

#

I don't deal much with built-in renderer anymore but when I do, I usually start with Amplify Shader Editor (you could also use free Shader Forge) to see what code it generates so I don't have search around for right shader functions and macros

#

simplest way to do this type of thing is to take the vertex position and check if it's below your float value you set in some property, if so, make it fully transparent

#

doing it in object space would make it work regardless of the terrain's own location

brisk bison
#

I have Amplify actually, never used it though

#

Looks like my best bet here it to attempt to write one. Gotta learn something sometime I guess :p

open leaf
#

Hi, Unity 2020 beta exposes Conservative Rasterization flag - how can I enable it when doing custom shader rendering using command buffers?

willow pike
#

Hey ya'll! I've got a simple fire shader I made for some torches in my game. It's working great, but I'm wondering the simplest way I can tweak the shader so there is some randomization on a per object basis. Say I have two torches side by side, I don't want their animations to be identical at any one frame.

meager pelican
#

@open leaf Did you try using the SV_InnerCoverage semantic?

burnt wigeon
#

@willow pike you can instanciate a copy of the material and tune it

meager pelican
#

IDK if it's active or not, just reading the docs

burnt wigeon
#

copies dont share the same parameters

meager pelican
#

@willow pike I use one or more scrolling distortion textures to manipulate the UV's per particle/quad.

open leaf
#

@meager pelican no, i found in Unity docs that enabling CR is done through RasterState, but the only way to actually set this that i've found is through ScriptableRenderingContext.DrawRenderers

meager pelican
#

Yeah, but once it's set you should be able to use that semantic to get more info on the pixel (theoretically, I have no idea, haven't tried it).

#

That's the shader side I though you were asking about.

#

As to the C# side, IDK. Sorry.

open leaf
#

I need to overestimate rasterization when rendering mesh triangles onto their "uv-map texture"

meager pelican
#

I'm exuding optimism here, but sorry I can't help you more. πŸ˜‰

open leaf
#

Sure - thanks anyway!

meager pelican
#

I'd be surprised that it's not enabled per renderer or material. But IDK. Maybe I'll dig. It would be nice if you had a doc reference to save time.

ocean bison
#

I'm trying to get the light direction of a point light in my shader using the following snippet, but it doesn't seem to be working properly. (I thought this what was my research on this subject suggested, but clearly, I messed it up somehow) float4 LightDir = _WorldSpaceLightPos0; if (LightDir.w == 1) { LightDir.xyz = normalize( i.worldvertpos - LightDir.xyz); LightDir.w = 0; } LightDir.w = 1;//opaque for test return LightDir;//for test

#

(oh, forgot to metion, works as expected for directional lights, just not point & spot)

meager pelican
#

Well, output fixed4(LightDir.www, 1) what do you get?

ocean bison
#

I get the correct color if I'm using a directional light.. and unexpecetedly - NOTHING is displayed when using a point light.

#

actualy. I didn't do fixed.. hold on

meager pelican
#

If you're in an opaque queue, the W is probably going to get trashed. That's why I output it into the RGB with a swizzle.

ocean bison
#

same.. very odd.. I expected somthing to show.. I'm using Tags {"LightMode" = "ForwardBase" "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }

meager pelican
#

Did you use the expression I gave you? It should be opaque, white or black.

#

Not "nothing"

ocean bison
#

lol.. no- ooops.. I used .xyz, not www- I'll try that.

meager pelican
#

And you'll want to remove that line before the return that forces it to 1

low lichen
#

The ForwardBase pass will only pass in information about the directional light, baked lighting, vertex lights and ambient

#

You need a ForwardAdd pass if you want to draw additional pixel lights

meager pelican
#

Yeah, there's a forward add pass.

#

Jinx

ocean bison
#

I used.. return fixed4(_WorldSpaceLightPos0.www,1);.. oh!

meager pelican
#

That's what I thought he was saying.

#

I was trying to see what happened with your if()

#

But never mind, MS is correct.

#

You need proper passes

ocean bison
#

So do I still need a ForwardBase pass at all?

meager pelican
#

Yeeah...

low lichen
#

ForwardAdd adds onto the ForwardBase

ocean bison
#

hmm.. so If I return (0,0,0,0) from ForwardBase.... then whatever I have in ForwardAdd will be what gets displayed?

low lichen
#

Why would you want to only use ForwardAdd?

ocean bison
#

I'm drawing atmpsphere effects- without a light- there is nothing really to draw

#

works fine for my directional light, but not point light.. all I'm trying to do it make it work with point light also

#

(I need to replace the directional light in my scene with a point light)

#

should I do directional light in ForwardBase. THEN the point light in ForwardAdd?

low lichen
#

That's what Unity's built-in forward rendering expects you to do

#

But of course, that additive blending for additional lights isn't always what you want

willow pike
#

@meager pelican thanks! Sorry for the delayed reply. Doesn’t instantiating materials get expensive on performance? I don’t really want to adjust the material manually on each object. Just want the timing of the fire to vary so they don’t look the same. Even if it was randomized that would be fine.

low lichen
#

@ocean bison Then there isn't really any other option than to pass the additional light information to the shader yourself

willow pike
#

Could you animate the material based on it position so they vary without creating duplicate materials?

meager pelican
#

should I do directional light in ForwardBase. THEN the point light in ForwardAdd?
@ocean bison I'd try that.

#

@willow pike I'd try that.

#

πŸ˜‰

ocean bison
#

Just switching to ForwardAdd allows the point light to work as expected- but breaks the directional. So if i need BOTH, I'll need BOTH passes... least thats what it's looking like.

meager pelican
#

dart, yes. So you don't need per-instance data. You can use Material Property Blocks and not dup materials, but that can have some issues in the new pipeline if you're using certain batchers for some damn reason. But position might just work too. It's all fake anyway. πŸ˜‰

#

Agree, Glurth

ocean bison
low lichen
#

@ocean bison Just be aware that the ForwardAdd pass will be drawn for each light that affects the object, leading to a lot of draw calls with many lights.

#

This is something that URP does better, it combines the base and add pass into one pass

ocean bison
#

@low lichen I did see this guy in the docs.. unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 float4 (ForwardBase pass only) world space positions of first four non-important point lights. perhaps I should use that in ForwardBase instead?

low lichen
#

That's for vertex lights

#

Though, I guess there's nothing stopping you from computing them as pixel lights

#

But you'd have to set them all to non-important/vertex lights

#

Though I think now unity_LightPosition[4] array is used

ocean bison
#

is that (non-important) a setting on the light in the scene? (not seeing it)

low lichen
#

Render Mode

ocean bison
#

ah, ty!

grand jolt
#

I need to render a transparent object AFTER (because both the rectangle and circle are buttons, so I need to render the circle "last"). But, I want the circle's transparency to work (so it will effectively replace the pixels on the rectangle (aka delete them). Is there a way to do this?

spiral agate
#

i cannot figure out whats wrong with it :((