#archived-shaders

1 messages ยท Page 145 of 1

tardy spire
#

Happy to try something to troubleshoot/verify if you have any ideas tho ๐Ÿ‘

simple frost
#

it shouldnt change scale or rotation with what you are doing I think...so I am guessing that matrix is not getting passed in correctly.

low lichen
#

@tardy spire Isn't matrix multiplication usually mul(matrix, vertex)? You're putting the matrix as the second parameter here.

simple frost
#

instead of using a materialpropertyblock, can you try setting directly on the material the matrix

#

@low lichen I think that should be auto corrected

tardy spire
#

@low lichen yea I thought that may be it, but amplify doesn't seem to care and outputs the same result either way

simple frost
#

since you cant really do righthand matrix mult

#

the other thing you can do @tardy spire is grab the 4th column of the matrix and set that as your color. Changing scale should then change the corresponding rgb of the color and you can verify that way

tardy spire
simple frost
#

neat

#

theres also a transform node instead of a multiply if you wanted to use it

#

I believe theres one that takes in a matrix I mean

tardy spire
#

I can't seem to find it. Also I figured out why it wasn't working in amplify. I needed to convert the vertex position to a float4 ๐Ÿ‘Œ

simple frost
#

Ahhhhhh thatll do it! Nice catch

devout quarry
#

Can I round a float to 1 decimal in a shader?

#

just with nodes

#

maybe multiply by 10, then floor, then divide again?

low lichen
#

That's how Math.Round does it

devout quarry
#

Alright neat, it seems to work

tardy spire
#

@devout quarry was just about to tweet at you that you should round the vertex positions (in reference to your last tweet)!

#

pretty sure they need to be rounded in screenspace and then converted back to local to properly mimic retro graphics imprecision

devout quarry
#

Right now I'm doing screen width/height multiplied by a float 0-1 rounded to 1 decimal

#

and let's say that float2 is called 'amount'

#

I do floor((screenspace uvs) * amount) / amount

#

as my new Uvs

tardy spire
#

Any matrix savvy peeps around?
I'm trying to interpolate vertex positions/normals to be relative to another transformation. Vertex positions are easy, but when it came to getting the normal I wasn't sure how to transform a vector as direction with an arbitrary 4x4 matrix. I see there's nodes for transforming between local, world, view etc but those are predefined and I need to transform a direction with a local to world matrix sent via a material property block.

Anyways, I think I stumbled into a solution, but would love to know if this is an ok way to do it!

low lichen
#

@tardy spire I'm definitely not a matrix savvy peep, but I think directions are supposed to have w as 0 when doing matrix multiplication. Maybe that alone is enough.

tardy spire
#

Hmm I always thought w was supposed to be 1 ๐Ÿค”

low lichen
tardy spire
#

(side note) The issue with just multiplying a direction by the local to world matrix is that it will also get translated and scaled (treated as a position)
To transform a direction it should just be rotated. That's why I'm also multiplying a point at (0,0,0) and then subtracting it from the transformed normal. If my understanding is correct, the point at (0,0,0) will get translated by the transformation matrix. By subtracting the result from the normal I'm undoing any translation effect it received by being multiplied by the matrix. Initially this didn't work and I was getting weird lighting so I tried using transposing the matrix first and that seemed to work ๐Ÿคทโ€โ™‚๏ธ

low lichen
#

The w being 0 is what prevents it from being translated and just rotated and scaled

#

But it looks like you have to do more than just that for transforming normals

tardy spire
#

๐Ÿ‘€ i think you're right that appears to just work! I had no idea putting a 0 prevented translation and scaling! There's some weird stuff going on when interpolating the normals, but that's a different problem. When it's fully at the start or end it looks fine to me

#

interestingly when I revert to my old way of transforming the normals it looks exactly the same. I guess I just found a weird roundabout way to get the same result

#

settings w to 0 is far better tho haha

brave tinsel
#

i am playing with shader graph and i want a transparent material to blend together? like when a river meets the ocean
tell me the deep secrets of how to make that happen? ๐Ÿค”

stone sandal
#

this might be close to what you're looking for

fervent tinsel
#

oh wow, that's pinned?

#

I mean there's been way more important topics here but I'm not complaining

stone sandal
#

haha it's been pinned for a while! back when hippocoder reposted it we were getting like 5 questions a week about water depth fading

plain lantern
#

Hey. Quick question I'm doing vertex displacement + Fresnel in shader graph. URP setup. The output isn't matching the shadergraph editor in that the fresnel effect doesn't seem to respect the normal input I give it. Anyone who can help me in diagnosing what gives?

Am i missing a setting or something? Am i supposed to do it in a different order?

#

Here's a super exaggerated version of the wanted result

low lichen
#

What happens if you scale the sphere down so it's just (1, 1, 1)? I assume that's the scale of the sphere in the preview.

brave tinsel
#

no i was asking about making two transparent materials blend together

plain lantern
#

Oh god it works

#

I just tried it as you were typing that

#

Thanks!

lone python
#

could y'all help a newbie out?
been following one of brackeys's tutorial on how to make a force field. the only difference is i've been making it in HDRP and he was doing it in the LDRP. what i suspect is the problem is the scene depth node not knowing what to do, as i don't see any kind of option for it in the settings

#

here's how mine turned out compared to his, along with the shader graph in case i missed something

simple frost
#

@lone python if you're in HD I believe there is an HD scene depth node that you need to use instead of the scene depth node itself (we are working on making these node usages more clear)

lone python
#

i don't see a node like that when searching for it

#

there is a HD scene color, but not a HD scene depth

simple frost
#

which version are you on?

lone python
#

2019.2.6f1

simple frost
#

whats your alpha clip at?

lone python
#

where's that? ๐Ÿ˜…

simple frost
#

on the pbr node

#

if you expand it you should see a variable called alpha clip

#

make sure its set to 0

#

and that the material is set to transparent

lone python
#

the material is set to transparent, as for the alpha clipping, it's set to one

simple frost
#

set it to 0

lone python
stone sandal
#

any chance you can upgrade to 19.3? ๐Ÿ˜… it should have a lot of those UI bugs solved

simple frost
#

and alphaclipthreshold will need to be 0

lone python
#

done, and it works now!

simple frost
#

woo!

lone python
simple frost
#

nice work!

#

so alphaclip tells the shader "if alpha gets below this threshold, dont draw"

low lichen
#

@simple frost Alpha clip is 0 by default, isn't it? It's the AlphaClipThreshold(1) that is confusing, because it's not saying it's set to 1, but that it takes a Vector1, right?

#

I've had this confusion before

stone sandal
#

clip threshold is actually 0.5 by default at that version

simple frost
#

^

stone sandal
#

it's been changed in recent versions

low lichen
#

Does that mean alpha clip is enabled by default unless you assign 0?

stone sandal
#

on the PBR master node for HDRP yes, which is why we changed it to 0 in recent packages

#

so that it isn't enabled by default

low lichen
#

Oh, good

lone python
#

okay so in project, the hexagon scrolling texture is still not showing

#

could it be because of the post processing in the scene?

simple frost
#

the scene view needs to have animated materials checked

lone python
#

ah okay, annnnnnnnddddddd where do i find that ^^'
i'm still finding my way around unity

simple frost
lone python
#

alright. Thank you!

#

ah okay. it was right in front of me. and it is checked

simple frost
#

still not animating?

lone python
#

oh wait, i think i got it

#

yep. the texture was in the graph, but not in the material

simple frost
#

thatll do it

#

well done tho!

lone python
#

thanks! been at it for 3 hours trying to figure out what the problem was ๐Ÿ˜†

tardy spire
#

whenever i try to use a View Direction node, or any node that uses the view direction internally, i get an error and the shader fails to compile (shader graph)

undeclared identifier 'GetWorldSpaceNormalizeViewDir' at line 1285 (on d3d11)

I see an issue posted last year in october and the tracker says it's fixed in an unreleased version of shader graph. seems kinda crazy to think view direction has been unusable for 6 months so I figured there may be an alternative solution

stone sandal
#

can you link that issue please?

low lichen
#

Maybe it's only when used in the vertex stage, which is why it hasn't been noticed by too many?

stone sandal
#

hmm i also was the person who fixed that.

tardy spire
#

I'm also getting it in a visual effect shader graph which im assuming is in the fragment stage?

#

excuse the unecessary view direction node, i was troubleshooting

low lichen
#

The color is probably run through the vertex shader and passed to the fragment

#

But don't listen to me, listen to the devs ๐Ÿ˜…

stone sandal
#

what version are you on? 7.2 is absolutely a released package by now (in fact it should be up to 7.3 by now)

#

actually it might have been just a misversion report -- the bug looks like it landed after 7.2 cut off. it should be in 7.3

tardy spire
low lichen
#

It's the verified version, but you should see more if you expand the package

stone sandal
#

are you using hd or universal?

tardy spire
#

universal

stone sandal
#

find universal in PM, use the arrow on the left to expand the version view

#

you should be able to update to 7.3 that way, but you need make sure you update universal and everything else will go with it

#

will keep you from getting in a weird mismatch version state

tardy spire
#

gotcha, thanks! Are the newer versions generally stable? I see they aren't preview packages, but maybe "preview package" is reserved for packages that have never been given a verified release?

low lichen
#

It's kinda misleading to show "Up to date" when there is a newer version available and only visible when you click a little arrow that's easy to miss.

tardy spire
#

yea i wasn't aware until ya'll mentioned it ๐Ÿ˜†

tardy spire
#

@stone sandal so after upgrading it works great in a normal fragment or vertex shader, but I still get the error in a vfx graph shader

#

I can create a bug report if you like

stone sandal
#

that's probably best, so we can track it

low lichen
#

@tardy spire For now, you can calculate it yourself by subtracting the world position of the camera and the world position of the vertex and normalizing that.

tardy spire
#

does the camera node reflect values of the main camera or current camera? i tried that very briefly but it wasn't working in the scene view so i figured it was pulling values from the main camera. maybe i was doing something else weird tho, because that seems odd to me

low lichen
#

Documentation says:

Provides access to various parameters of the Camera currently being used for rendering.

tardy spire
#

hmm ok, i must have been doing soemthing funky then, thanks ๐Ÿ‘

tardy spire
simple frost
#

@tardy spire thank you!

sly trout
#

where can we report bugs for shadergraph?

#

position node set to object in sprites flickers a lot, causing incorrect calculations and jitter

#

it can be easily replicated doing the following

stone sandal
#

Please report bugs using the in editor bug report system

#

Help > Report a bug

sly trout
#

okay!

whole salmon
#

I created a simple Dissolve shader. When I apply it to two different Raw Images as the material, however, playing with the settings on one affects the settings on another. What am I doing wrong?

low lichen
#

@whole salmon That's just how materials work. You have to create two materials using the same shader if you want them to have different properties.

whole salmon
#

Ok. Can I instance them from a prefab programmatically?

#

What's best practice for handling a shader that you've built that you want to apply to dozens/hundreds of objects in your game?

#

I'm assuming you instantiate a shader, attach it to your material, do your thing, then remove it later?

low lichen
#

You don't instantiate the shader. The shader is just code. The material has the properties that are passed to the shader, so you instantiate the material and edit its properties.

#

Unity has a built-in way to easily instance materials by accessing the Renderer.material property.

#

By accessing that property, Unity will first check if the renderer is currently using an instanced material. If not, it will create a new instance, assign it to the renderer and return it to you.

whole salmon
#

Wow. Genius.

low lichen
#

Renderer.sharedMaterial just returns the material assigned

whole salmon
#

so if I have my library of materials (just plain materials but each with a custom shader), and attach them using Renderer.material.. i should be good to go?

#

Is there a way to do that in the editor?

#

I'm assuming drag and drop onto the Material field gives a shared instance?

low lichen
#

Presumably you'd be setting these material properties through script, right?

whole salmon
#

Yeah

low lichen
#

Then just put the original material on the prefab and when you want to modify it through script, get it through the material property and Unity will handle the instancing.

whole salmon
#

But just to play around with it, it's nice to see it in the editor.. I suppose it's not really a gameplay issue.. just a workflow issue, something to be aware of.. I think I"m going to be combining shaders for various things

#

OK, awesome. Thanks. Like I said... genius.

#

You're a mentally stable genius

ancient silo
#

I have a scene with a bunch of mushrooms as the only source of light, its a cave area. Whats the best way of doing this? I've tried attaching point light to each one but they keep flickering and go through walls and using post-processing doesn't help them light up other surfaces.

low lichen
#

@ancient silo How many mushrooms/lights?

#

And are you using URP or HDRP or just built-in?

ancient silo
#

URP, probably around 20 mushrooms altogether in the scene.

#

Its a 3D Platformer

low lichen
#

URP has a maximum of 8 realtime lights affecting one renderer.

#

I think the default setting is 4, but can be increased to 8

#

The bigger the range of the light, the more objects it might affect

ancient silo
#

Would going over that result in flickering point lights?

#

This is how they were set up with point lights

low lichen
#

If you're going over this limit, it will have to start picking which to prioritize and which to fallback as vertex lights. That could be the flickering, but I'd have to see it.

#

Is it flickering even when the camera is stationary?

ancient silo
#

Nope, only when moving. But Point lights also go through surfaces/ walls so I'm trying to find another way of lighting them.

low lichen
#

If it's only when moving, then I can believe it's because different lights are getting prioritized which could cause flickering as its switching between lights.

#

I think it's based on distance from the camera

#

Maybe you can bake this?

#

Then you can just use the emission of the material to create light, which will also appear a lot more realistic

ancient silo
#

Would baking make it so the light doesn't reflect on the character?

low lichen
#

It wouldn't without light probes, but if you sprinkle some light probes around the mushrooms, they can light dynamic objects pretty convincingly and fast.

ancient silo
#

Thanks, I'll try it out

whole salmon
#

Is there a way to get a shader graph asset to save when I press CTRL+S? the only way I can see to do it is to click "save asset" in the top left of the window, or try to close the shader graph and get prompted by Unity.. neither of which is ideal

carmine pond
#

does anyone have an issue why in shader code _Variable * value != constant * value?

#

seems like if I use a uniform constant it looks slightly different form a constant. This is using full float on everything.

#

this happens when building to a pixel 3 adreno

halcyon lichen
#

Hello! I'm basically teaching myself how to program shaders and it's been tough. I have a question, is it possible to permanently write color data to a vertices via a shader?

gleaming moss
#

yes, but probably not via the methods you're thinking of

#

you're really asking 'can I write to a buffer holding vertex data on the GPU' and while the answer totally is yes, there are specific and generally well thought-out reasons why doing this on the fly is a bad idea

#

best advice I can give-- the GPU and CPU are fundamentally not the same things and trying to write CPU-ish code for a GPU is a recipe for a bad time

halcyon lichen
#

@gleaming moss I can understand that and I want to avoid it if at all possible.

#

I've been working on trying to do some kind of fog of war that isn't taxing on the system and so far most methods are insane.

#

I got something going with a shader and I'd like to feed that data back to the CPU to do something so that I don't have to check all verts every frame. If I know what's under the shader, then I'd like to put that data somewhere to be adjusted.

somber quest
#

Hey guys, I am new with shaders and am currently developing a way to make a nice outline on intersecting objects. I have made a post about it here: https://answers.unity.com/questions/1710794/problem-with-outling-intersection-using-shader-pro.html As a quick summary what I want to do is find a way to make an outline visible from all axes on a mesh that was clipped. Specifically care about the top view to be rendered properly. Thanks!

rotund laurel
#

Hi I'm having an issue where I made a shader for UI and that after putting it in the game it looks different

#

If I make a new unity scene and add a canvas/image with the shader on it it works like intended

#

but as soon as this get placed in my game it becomes really laggy and blurry

#

does anyone have an idea if this is related to the shader or if my game is affecting the shader in some way

sharp flint
#

is there any good unity shader tutorial ? ๐Ÿ˜ฎ

warm marsh
#

having this issue using URP and the URP/Lit shader set to specular, both of these brown colours are the same hex value, what could be going wrong?

devout quarry
#

is there any good unity shader tutorial ? ๐Ÿ˜ฎ
@sharp flint Just shaders in general?

#

@warm marsh they have a different albedo texture right?

warm marsh
#

yeah different textures both set to the same hex color vlaue

#

value*

devout quarry
#

yeah but if the texture is different, they will output a different color

#

or maybe I'm not understanding what you mean

warm marsh
#

there are 2 textures one is all "brown" its a light brown orange but yeah and the other one is a blend from that color at the base of the rocks to a grey

#

so at the connecting point in the pic that is the same color value

devout quarry
#

what about tiling/offset? Can you make them to line up?

warm marsh
#

they are 2 seperate game objects, the point at which they touch is lined up in the UVs in term of the color being the same

sharp flint
#

@devout quarry yeah shader in general ๐Ÿ˜ฎ

devout quarry
#

@sharp flint this might help

#

pretty long but I think it's useful

shadow kraken
#

@warm marsh If you put each material on a plane and line them up next to each other, how do they look?

meager pelican
#

The tiling is different on the left one also, but IDK that it will make a diff with that texture. @warm marsh

#

And the normals are different, so that will impact the lighting calcs

warm marsh
#

sorry 1 sec ill set up a few screenshots

shadow kraken
#

It also looks like the colours are different on the textures themselves (based on the super tiny thumbs) so it would be good to see the textures next to each other as well

warm marsh
#

same texture/material on both

shadow kraken
#

Are they both lit the same way? i.e both dynamic or both static

warm marsh
shadow kraken
warm marsh
#

im stumped haha

shadow kraken
#

I....... yeah

warm marsh
#

i was thinking its the directional light but even then you would expect some form of transition from light to dark/ color change based on the angle of the light source

shadow kraken
#

Not with directional lights

#

What if you place a point light there

warm marsh
#

teh fudge

shadow kraken
#

Might be worth looking through your quality settings

warm marsh
#

any particular settings in mind?

shadow kraken
#

oh!!

#

Actually.... maybe not. But yeah the pixel light count

warm marsh
#

no luck with any settings its all mainly in my urp profile

#

thats with the ground as a cube

#

and the rock is at the edge of the cube there

low lichen
#

@warm marsh Isn't is just the normal of the surface? If you rotate the floor, I'm sure it will cycle through some of the other colors on the rock.

#

The flat portion on the rock is a similar color to the flat ground

warm marsh
#

yeah if you look above when i put the samematerial on both objects they had no normal maps and they were still different

low lichen
#

Not normal maps

#

The normal of the surface of the mesh

#

Which way the surface is pointing

#

The floor is pointing directly up, the rock is mostly not pointing directly up

#

The part of the rock I drew a circle around has a similar normal to the floor, directly up, and so it has a similar color.

#

The lightest parts of the rock are the ones facing the sun

warm marsh
#

is there no way to get this so they aren't so different?

#

instead of a normal map on the floor maybe actual mesh deformation?

low lichen
#

If you want shading to have less of a color impact, add ambient light

#

If the sun is the only source of light, then the parts facing away from the sun will be completely pitch black

#

So the gradient goes from your desired color to pitch black

warm marsh
#

see how the side portion has a dark patch as well? why would that be?

low lichen
#

It's also facing away from the sun, about the same amount as the top part

warm marsh
#

ah okay got ya

low lichen
#

Almost 90ยฐ to the right, while the top part is almost 90ยฐ up

warm marsh
#

i didnt know it would be so different, guess ive just never had it so obviously lit and unlit before

low lichen
#

The sun is at a very shallow angle, so the floor is going to end up a bit darker

mortal sage
#

Hi there, I made a HDRP graph for terrains with over 60 exposed properties I wonder if there is a way to convert that thing into a PBR graph, other than copy/paste the nodes into an empty graph. A way that allows me to keep also the exposed property and not recreate them manually (which would take a lot of time). I need to use that shader in a URP project

devout quarry
#

You just need to change the master node?

#

What happens when you just drop the file in URP, and open it? Can you open it and change the master node?

mortal sage
#

Yes ideally it would just be about replacing the master node, but it doesn't seem to be possible

devout quarry
#

Create new master node, right click it, press 'set active'

#

then remove old master node

mortal sage
#

thank you!! I didn't know I could to that

#

perfect ๐Ÿฅณ problem solved thanks a lot Alexander

prime pasture
#

My shader starting to act up a bit strange, I have a simple shader that just display a texture, I used Frame Debugger to see what happens and it seems Unity set my _MainTex to the camera render when I click between the Game View and the Scene View any idea what is happening? my texture is set and I never changed it in code

#

Note again, nothing has changed between the screenshots except clicking between the viewports

low lichen
#

That is strange. It's showing a view from a different perspective. Do you recognize it as some camera? Is it the perspective of the scene camera?

prime pasture
#

And for the record, here is the fragment function
:

float2 uv = i.screenUV.xy / i.screenUV.w;
float attenuation = LIGHT_ATTENUATION(i);
float shad = (1 - attenuation) * _ShadowColor.a;

fixed4 col = tex2D(_MainTex, uv);
col.rgb = lerp(col.rgb, _ShadowColor, shad);

return col;
#

@low lichen Its even stranger than that! The Scene View show it from a different angle!

#

its like its based on the unity editor view angle from that specific viewport (game view and scene view)

low lichen
#

Are you sure there isn't a second camera somewhere in the scene?

#

Is this shader writing to depth?

prime pasture
#

@low lichen 100% no other cameras

#

Yes, there is depth writing

low lichen
#

Just as a test, what happens if you rename the _MainTex property to something else?

prime pasture
#

Wow, indeed it fixed it

#

Its really weird I don't have any code that touch that shader, to be exact, I dont edit any shader from script

#

@low lichen Thanks!

somber sentinel
#

_MainTex is used by Unity and is usually set to different values depending on where it is in the renderloop

blissful wraith
#

Hi, I'm starting some tutorials on shaders and I'm having trouble understand "semantics". Are they shader-language specific? Do they affect the shader or are they just for the programmer?

low lichen
blissful wraith
#

@low lichen ah, thanks. That should clear things up as I learn.

vague yacht
#

any ideas how the trail / layer reveal is done here?

#

I've noticed that the 4 different layers are set up beforehand, and the players are just "revealing" their layer

#

because the greeen guy has flowers in the same spot when he walks over it few times after someone else

#

which is great because painting with a mesh for 4 players in runtime could be bad for performance

#

but the still have to reveal the area like a rubber and it has to persist, which I don't know how is done

#

or is it actually some kind of painting with material?

simple frost
#

@vague yacht I would bet you are correct that there is just a reveal going on with the corresponding player layer, but I imagine they are painting to a texture . Could probably paint to a fairly low-rez texture and upsample it for perf.

vague yacht
#

like, paint to a texture with a transparent brush?

#

also, the green guys layer looks like a mesh or can you do a 3d shader like this?

simple frost
#

I was thinking more paint to a single channel texture and give each player an id mask, like .2, .4, .6, and .8 and have them all draw to that texture with their id and read from that

#

yeah, as long as those objects use the same or similar shader then it would be fine

#

read in the texture using worldspaceposition as uv and if my layer isnt there clip

vague yacht
#

yeah that sounds good, I'll try and test this

#

thank you!

gleaming moss
#

that's not a texture, either

#

look at the grass meshes

#

guessing they do alpha clip based on influence

simple frost
#

? why could that not be a texture?

gleaming moss
#

you have four meshes in the same space

#

It's three-dimensional

simple frost
#

sure, so you map 3d worldspace point to 2d plane by clamp and sample uv

gleaming moss
#

rather, I am clarifying that I think there are actually individual meshes being revealed and it's not just painting something into a single shared texture

#

if that makes sense

#

since I do agree the actual influence looks like something done with RTT/persistence

simple frost
#

Oh yeah no there are definitely meshes being revealed , thats not something a texture could do haha

low lichen
#

There's probably one mask texture where RGBA is mapped to each of the players

#

You know, you can probably hook RenderDoc to it and see how they do it.

#

Most games work through RenderDoc

vague yacht
#

I'll check the render doc as well

#

never used it, looks promising, ty

low lichen
#

If you've used the Frame Debugger before in Unity, it's similar to that but with a lot more information

simple frost
#

+1 for renderdoc, love it

gleaming moss
#

honestly prefer the nSight UI

#

but if it's not available then RenderDoc's not a bad substitute

simple frost
#

renderdoc just has great integration with unity

#

so I prefer it usually

gleaming moss
#

nor is it a knock on the Unity integration-- just don't really care for how many clicks are required for resource inspection

simple frost
#

hah, fair enough!

gleaming moss
#

the Vulkan command buffer situation could do with some improvement if we're talking about Unity usage patterns ๐Ÿ˜‰

#

that's a lot of nesting

simple frost
#

fair jab, well played ๐Ÿคฃ

sharp verge
#

Just wondering, in the shader graph what would the performance impact be of having to use another texture sample 2D node for the same texture? I've got a RGB mask texture but I've made one of the channels use a different scale (tiled 4 times) to give more variation when the base textures are tiled, but to make it work it seams like I'll have to sample the texture again so that I can scale the UVs properly. Is this a bad idea?

low lichen
#

It's not a worse idea than sampling a normal + albedo. How many texture samples you can get away with depends on your target hardware.

gleaming moss
#

cost of texture access is all in loading things from GPU memory and that being on the slow end when compared to simple math operations

#

would likely be the same GPU cost as just reading from a different texture with the same resolution

heady pewter
#

is there anywhere specific where i can learn unity's shaderlab language?
i'm using 2017 unity (because i'm currently too scared to upgrade at the moment) so that visual shadergraph ui isn't available for me.
long story short, i was trying to apply some simple normal maps to my 2d sprites.

#

what i have attempted so far was trying to take the old legacy cutout/bumped diffuse shader as an idea. but i've ran into a few issues. so i guess so far i'm trying to learn at the moment is:

since i want to use normal maps, that means i can't use a vert/frag to get the bumped maps to work right? if so, then it's best i use a surface shader?

devout spoke
#

I am successfully changing the RenderSettings.skybox.SetInt("_SunDisk", 1) between 1 and 2 during runtime. And I can confirm this in the skybox material itself. However, the sun does NOT update accordingly. It stays at whatever mode it was in when runtime started. I am even calling DynamicGI.UpdateEnviroment() after the switch. What else do I need to trigger?

sonic plinth
#

Heyo, pretty new to shaders and I'm guessing everyone here knows what dissolve shaders are, I want to make one that works with just small pixels, for example I have a 8x8 texture that I would like to have a dissolve shader that just changes those pixels instead of smooth dissolving. I'm not sure if anyone here gets what I mean but well, tried my best explaining.

#

Or some sort of pixelated dissolve shader, maybe 16x16 instead of 8x8 because that may be too pixelated

devout quarry
#

In shadergraph whenever I use a custom function node, when I move the nodes around in my project, the reference gets lost and the shader doesn't compile :/

#

is that something that will be fixed?

sharp verge
#

Is there a way of selecting a single channel for the height input of the Parallax Occlusion Mapping node? It asks for a texture 2D rather then a sample texture 2D so I have to plug in the whole texture, but I'd rather use a packed texture instead

amber saffron
#

Hum, no

#

but you can pack by just keeping in mind that it's the red channel that is used

#

it needs a texture 2D asset input because the parallax node is going to sample it multiple times.

sharp verge
#

@amber saffron So the POM node just uses the red channel?

amber saffron
#

double checked in the code : yes

sharp verge
#

Ah that's great, was already using red for height anyway

keen scaffold
#

Hello peoples ๐Ÿ˜„ I've started using ShaderGraph recently because it's effing amazing! I've followed a bunch of tutorials and made a bunch of weird things. However, I wondered if there was some really really nitty gritty low-level explanations of how all the nodes work

#

Every tutorial I've found only scratches the surface. I feel like I don't have the knowledge to write new shaders, but rather copy or modify existing ones from tutorials. I'd really like a solid understanding of how UVs, tangents, world space, the various nodes, etc, all work. Anyone aware of any really good documentation or lengthy tutorials out there? I'm willing to put the time in

devout quarry
#

these pages often have some info about the implementation of the nodes

#

This website also covers some nodes pretty in-depth

#

Like UV, voronoi, fresnel, scene depth, scene color

keen scaffold
#

Does it talk about how they interact with one another? I've actually read up on this before

#

I'm having more trouble understanding how ports interact - like how a colour becomes a normal, or a direction becomes a colour, etc - sometimes you can pass a V4 into a V1 input, etc

devout quarry
#

color is vector4

#

normal is a direction, is a vector3

keen scaffold
#

These look great btw

devout quarry
#

if you plug vector4 into a vector3

#

the w component will just be ignored

#

same with v4 into v1

#

it'll just take the first component

keen scaffold
#

Ahhh, so it goes in order of preference? A V1 into a V4 will just send the red channel?

devout quarry
#

if you want exact control over which values are used, you should use split/combine nodes

#

I think if your V1 is for example 0.8

#

the v4 will become (0.8, 0.8, 0.8, 0.8)

#

but honestly I'm not super sure haha

amber saffron
#

That's how it works yes ๐Ÿ™‚

devout quarry
#

what about v2 in v4 then?

keen scaffold
#

Dude, shaders are a total head fuck. Everything's semi-dynamic and doesn't need clearly defining

#

Would that be (value, value, null, null)?

#

or (value, value, 0, 0)

devout quarry
#

I think 0 is the default

#

not 'null'

keen scaffold
#

I think split and combine are literally the two nodes which solve all my issues haha

devout quarry
#

definitely

#

instead of 'combine' node, I prefer to use the vector2/vector3/vector4 nodes

#

but that's preference

keen scaffold
#

I'll check that out too

#

Are you familiar with the UV node? I'd like to do something extremely simple, such as scrolling a texture across the Y axis

#

So I'd like to just plug in a time node to the Y value

#

But the UV node has no inputs, so what exactly is its purpose?

devout quarry
#

tiling and offset

amber saffron
#

check the tile/offset node for that

devout quarry
#

put that into the uv

#

multiply time with speed variable, and put it in the y slot of a vector2 node, then that goes into the offset slot of the tiling and offset node

amber saffron
#

+1

keen scaffold
#

Thank you ๐Ÿ˜„ I'll have a look at that too

#

I feel like half the time I make a cool shader, it's totally accidental

keen scaffold
#

Been messing with lit 2D sprites at the moment to create this disgusting looking fellow

somber quest
#

Hey guys, I had written a post above but will try again. Maybe the issue is very difficult to fix but could anyone please guide me in a correct way for a nice solution? https://answers.unity.com/questions/1710794/problem-with-outling-intersection-using-shader-pro.html As a quick summary what I want to do is find a way to make an outline visible from all axes on a mesh that was clipped. Specifically care about the top view to be rendered properly. Thanks

amber saffron
#

I think that what you're asking for might not be possible to do without more complex methods, IE : rendering in a separate buffer the objects you "cut" to do a per pixel outline, and compose with the main rendering afterwards

somber quest
#

@amber saffron Sounds very interesting, do you perhaps know a tutorial I could watch about this? I have never used a seperate buffer to render stuff

#

@amber saffron My colluegue reccomended to read about "Compute shaders" do you think that might help come closer to the solution?

amber saffron
#

I'm not sure compute shaders will be any help here...

somber quest
#

I think that what you're asking for might not be possible to do without more complex methods, IE : rendering in a separate buffer the objects you "cut" to do a per pixel outline, and compose with the main rendering afterwards
@amber saffron Might this be about Command Buffers?

amber saffron
#

Well, it can be done without command buffers, but yes, it's a bit more optimal ๐Ÿ™‚

somber quest
#

@amber saffron I wanted to ask, do you perhaps know WHY the intersection shader vertex positions cannot be changed. Like what happens is, when the bounding box is inside an object, it colours all intersecting faces. Why cannot I just move the point I would like to colour? I was thinking to modify the intersection points and change their normals such that the outline is actually seen from above.

lavish ermine
#

Hi there ! I'm looking for help about ShaderGraph. I need to make a porting of a surface shader that relies on a compute buffer, but compute buffers seem not to be supported in ShaderGraph

amber saffron
#

I'm not sure to understand what you're saying here @somber quest

lavish ermine
#

is there anyway to write a compute buffer on a material in HDRP and read it in ShaderGraph

somber quest
#

@amber saffron to shortly explain, the intersection shader has 2 passes. In the second vertex function we just o.vertex = UnityObjectToClipPos(v.vertex); and in the frag just return _Color;

What I wanted to do is edit either o or v in the vertex shader. Like offset it or change the normals. I could not visually see a difference though. I am not sure why

amber saffron
#

Editing o.vertex should deform the shape

#

@lavish ermine not at the moment iirc

#

Maybe through a HLSL include file used in a custom function node :/

lavish ermine
#

@amber saffron this is something I need to try, but it seems that setting a buffer on a meterial is not allowed in HDRP

#

do you know if this is a planned feature?

amber saffron
#

Don't remember on top of my head, sorry.

#

I think it is something that is quite often asked tough

lavish ermine
#

Thank you. I will try and dig more on the subject

gleaming moss
#

I don't think that's a 100% trivial question

#

pixel shaders can write to unordered access views since the beginning of D3D11 but there are some constraints-- other stages did get the ability in later revisions/11.1-ish but that might change based on 3D API

#

figuring out where that buffer export gets run sounds like a complex question too ๐Ÿ˜

#

sounds like another great application for custom master nodes

lavish ermine
#

@gleaming moss Again, a custom master node would require an access to a GPU buffer in a way or another. In my case (HairStudio, a hair simulation), the vast majority of the data used to shape the geometry is located in the buffer, not in the mesh. This data is produced by a compute shader, and if I need to read it back in CPU memory to update the mesh, I encounter a big performance hit

gleaming moss
#

ah, so you just need to read that buffer in the graph

lavish ermine
#

@gleaming moss no, I don't know that function and I don't quie understand it. How do you use it inside ShaderGraph?

gleaming moss
#

it's an app/C#-side function, just related to binding the resource(s) you're working with

#

at least for write

#

looks like the global buffer set functions can deal with read-only binding too-- was afraid it only handled constant buffers, but it looks like you can supply read-only views

lavish ermine
#

I understand the how it can help in binding GPU data in some situation, but I can't figure out how to access a buffer via the ShaderGraph. I still need to try and set a buffer (and other data) in a material in HDRP and see if I can access it via a custom node HSLS function

gleaming moss
#

and as Remy mentioned, you need an HLSL file that declares a buffer resource and reads from it given an element index

lavish ermine
#

I know how to delcare a HLSL function in a custom node, but I can't declare a buffer in a function. I would need that buffer to be declared in a custom input.

gleaming moss
#

you can't, they're always in the top-level scope. You can include a file that declares the buffer and the function

lavish ermine
#

how that?

gleaming moss
#

and then just reference the function in the custom node

#

Create your include file and select it in the custom node

lavish ermine
#

so if I declare a custom node that is using a HLSL file, I can declare new shader variable in the HLSL code?

gleaming moss
#

exactly

lavish ermine
#

something like that is possible?

gleaming moss
#

already got it ๐Ÿ™‚

#

so you would want an output for each member of the struct

#

and probably a uint or something with the index of the buffer

lavish ermine
#

remember that I only need to read the buffer, not write it

gleaming moss
#

yes, you need a completely different resource type for writing

#

RWBuffer<>

lavish ermine
#

so I just need to give an index in the method parameter, and the result are two float3 in my case

#

I need to try that ^^

gleaming moss
#

and that might be more complicated

lavish ermine
#

why would it be more complicated?

gleaming moss
#

writing from the regular shader pipeline-- talking about two different things

#

sorry, fast topic change

lavish ermine
#

ok

#

well, I will write inside this shader from a compute shader. maybe I will issue some difficulties in predicting the order of execution

#

compute shader will write sometime, and the shader will read each time it renders.

#

I'll give it a try and see

#

well, thanks you, it have been very informative ^^

silver bronze
#

In a compute shader, is it better to send less bytes of data but remap the values into a different float size in the shader itself, or to just send more bytes of data but not have to remap the values in the compute shader?
Example:

  1. Vector3 position which is 12 bytes is sent to the compute shader, but the z is always 0
  2. compute shader takes it in as a float3, then does math, ending up with a value for z (so it NEEDS to be a float3 in the compute shader)
    vs
  3. Vector2 position, 8 bytes, is sent into the compute shader
  4. compute shader maps it into a float3 (float3(position.x, position.y, 0)) then does math
lavish ermine
#

first version is correct

#

in the second solution, you would have a map with x,y as input + a map with x,y,z as output. even if the map is full of 0, it is allocated in memory and sent

silver bronze
#

@lavish ermine sorry position was a bad wording, offset would be better. It would be sent in as a vector2, taken in as a float2, then lets say adding to a position:
position += float3(offset.x, offset.y);

#

position would be a seperate vector3/float3, these are seperate sets of data

lavish ermine
#

If you need the data to be separated in gpu side then yes, you need two array. But if the first version of the data can be lost after the function, one array of xyz should be better. Note that you will certainly notice little to no difference if it's only memory transfer CPU->GPU

silver bronze
#

Ah okay

#

Thanks!

sonic plinth
#

Hello, so ive been told that sending data to a shader is faster than using SetPixels() on a Texture2D. is this true?

#

I don't really know anything about shaders so

gleaming moss
#

copying data from the CPU to the GPU is going to be about the same speed in both cases. Updating a few pixels in a texture is probably going to cause the whole image to be uploaded again, though

#

this isn't a complete question

#

is it all the same data? How often are you doing it?

#

what are you really trying to do

lavish ermine
#

@sonic plinth same anwser. updating the data of a buffer or a texture will lead to the same time if they haze the same size, I think

#

and it will be hard to test the difference between the two

#

@gleaming moss I have tested placing a uniform variale in my custom node HLSL file, but it doesn't seem to work. The data does not seem to be written when I call the material.setFloat(myFloatID, value). I also get an exception "Material doesn't have a float or range property 'MyFloat'" when I try a material.getFloat(myFloatID)

gleaming moss
#

@lavish ermine I suspect you need to use the global Shader.SetFloat()-- Unity properties have a whole infrastructure outside of shader code itself

sonic plinth
#

Has anyone tried making a dissolve shader that works on 8x8 sprites and only changes the pixels on that. or 16x16 because 8x8 might be too small for dissolving. Hope someone here understood what I said

gleaming moss
#

there wouldn't really be anything special about it, it already works on one pixel at a time

#

maybe disable texture filtering if you don't want that

lavish ermine
#

@gleaming moss Thanks you for your time, it's very kind. I've found a static method called Shader.SetGlobalFloat(...). Are you talking about that? It seems to set the value for all shaders, and seems dangerous. Plus in my case, there are many instances that requires their own data set.

sonic plinth
#

@gleaming moss I'm confused on what you mean

gleaming moss
#

@sonic plinth regular dissolve shader should do what you want if it's a 8x8, 16x16 or 4096x4096 texture/render target

#

shouldn't need to modify anything

#

if you're doing pixel art stuff then you might want to turn off some of the blending the card does to textures

sonic plinth
#

Huh, when I try to make one the dissolving is high resolution compared to the sprite size

gleaming moss
#

how are you determining what area(s) to make invisible

sonic plinth
#

well, dont really have any anymore, deleted my dissolving script so I will have to make a new one

#

plus, dont really know a good way to make a dissolve shader in the first place. Quite new to working with shaders

gleaming moss
#

are you using shader graph or writing it by hand

sonic plinth
#

shader graph. writing by hand seems harder

gleaming moss
#

ok, and is this for a lit object or are you still working with tiles

sonic plinth
#

its a gameobject, not apart of my project's texture world map if thats what youre talking about.

gleaming moss
#

that's fine, just figuring out what master node you need to work with

#

the big change is making sure you have the 'alpha clip' turned on in the master node options

sonic plinth
#

Yeah, using LWRP if that is necessary information :p

gleaming moss
#

dissolve stuff is really just alpha testing like you might see in a static, painted texture

#

if you have a noisy input and gradually increase/decrease the opacity values, you end up with this grainy effect that looks like the surface is crumbling into ash

sonic plinth
#

I'm a little confused on how to actually make the dissolve shader, as ive never really used shader graph before

gleaming moss
#

instead of writing code, you drop nodes in and connect them together

#

it can help a bit to see visual representation of a few steps as you're making things

sonic plinth
#

Yeah I get that but unsure how to make a dissolve shader with it, since I don't know all of the nodes and how they work yknow?

gleaming moss
#

the big change is making sure you have the 'alpha clip' turned on in the master node options

#

dissolve stuff is really just alpha testing like you might see in a static, painted texture

#

if you have a noisy input and gradually increase/decrease the opacity values, you end up with this grainy effect that looks like the surface is crumbling into ash

#

there are also a few video examples of how to put them together on YouTube-- some of this will change depending on how you want to control what dissolves when

sonic plinth
#

a bit of a dumb question but how do you remove a connection

#

actually nevermind

gleaming moss
#

ok, was that made with your graph?

#

if so, post a picture and let's talk about how it works

sonic plinth
#

here. (the border of my sprite is like the same color as the background color so you cant really see it)

gleaming moss
#

one of the first things you can try is adjusting the scale of the noise node on the left

sonic plinth
#

well, no matter what scale it is the noise is always gonna be high resolution

gleaming moss
#

are you interested in working at the scale of pixels in the source image?

#

as in whole pixels going away at once

sonic plinth
#

Pretty much, but probably at maybe 16x16 instead of 8x8

gleaming moss
#

you have a few options then

#

you can chunk up the input UV that you feed in to the noise node

#

that would be done by reading the sprite texture coordinates (there's a node for this) and then feeding it into a 'posterize' node

#

alternately you can create a noise texture that's 16x16 in your favorite image program and make sure it uses point/no filtering

#

which is an option when you're importing the texture

#

you could then replace the noise node with another texture read

sonic plinth
#

well, what is the "sprite texture coordinates node" called?

gleaming moss
#

should just be called UV I think

sonic plinth
#

figured that out, multiply the value after step with the RGBA from sprite

gleaming moss
#

one thing to keep in mind is that the "resolution" won't be affected by object scale (and if you don't use/need this, then no sweat)

#

it might make sense to have the 'steps' parameter come from a property too

sonic plinth
#

Yeah I know

gleaming moss
#

so you can increase or decrease the virtual resolution according to scale

sonic plinth
#

I just disconnected the dissolve amount so I can test in the editor faster

#

also; it seems the sprite becomes semi transparent in the end for some reason

#

and some pink somehow got into the sprite, probably from the multiplying

gleaming moss
#

try flipping the 'edge' and 'in' inputs in the 'step' node

#

those look backwards

#

'edge' should be the dissolve amount

#

second, try multiplying the alpha and noise and putting that in the 'in' input

#

then combine the regular sprite color with the alpha

lavish ermine
#

@gleaming moss You were right, myMaterial.setBuffer(myPropertyID, myBuffer) works like a charm. So it is indeed totally possible (and pretty strait forward) to set a buffer on a material using shaderGraph.

gleaming moss
#

still collecting reasons to yell at Unity Engineering for custom master nodes tho ๐Ÿ™‚

cloud turret
#

Anyone know of examples of custom unlit 2d shaders which hook into the lighting system?

#

(in shader graph)

gleaming moss
#

3D ones would probably work just off the top of my head

#

I don't think the 2D nodes need different shader constants

cloud turret
#

That was my initial thought, and I adapted some 3d custom functions, but my sprites aren't lit

gleaming moss
#

have not investigated

#

ok, RIP

cloud turret
#

Just wanted to see if there was anything I could reference more specifically as I continue investigating

gleaming moss
#

nope, join me in yelling at Unity for custom master node then

#

non-photoreal rendering is kind of a bad joke with Shader Graph rn

sonic plinth
#

@gleaming moss not sure what you meant with "combine the regular sprite color with the alpha". currently looks like this

gleaming moss
#

@sonic plinth yeah, that didn't work out as well as I want-- you do need to multiply after the step

#

since the basic sprite alpha should work independent of the dissolve threshold

#

that's my b

sonic plinth
#

so what, just remove the multiple between noise and step?

gleaming moss
#

just try the noise directly into the step

#

exactly

sonic plinth
#

you can see just a little row of colors at some areas

gleaming moss
#

yeah I see that little line

#

wonder if that's a precision problem with the Posterize node

#

can I ask-- did you check the import settings for your texture?

#

if possible, try turning off mipmaps and setting it to point/no filtering

cloud turret
#

afaik the only difference between 2d and 3d shaders is that you need to get your colors/normals from _MainTex and _NormalMap. Anything I'm missing there?

(also, new to Discord - does it have threading? I feel like I'm interrupting)

sonic plinth
#

it has no mip maps and is point/no filtering

gleaming moss
#

@cloud turret no, Discord is glorified Slack is glorified IRC

cloud turret
#

Slack has threading :/

gleaming moss
#

ah wait yeah

#

I forgot, Slack did have threads

sonic plinth
#

also; I would like if the pixels didnt just disappear completely and instead fade like usual dissolve effects, not sure if this is possible with how it currently works but yeah

gleaming moss
#

@sonic plinth you can make that happen, but you need to change/remove the Step node

sonic plinth
#

Huh, though well, not sure if I can do it myself :p

gleaming moss
#

(just make it 'subtract')

sonic plinth
#

oh that was easy enough

#

some weird things are happening with that though

#

I mean, it doesnt really work with a 0-1 input

gleaming moss
#

how so

sonic plinth
#

it becomes completely invisible at like 0.6 and visible at like -1

gleaming moss
#

the time node is to visualize animation

#

yeah, that does take some more work to get controllable

sonic plinth
#

what do you mean operands?

gleaming moss
#

inputs to the node

#

you can also scale and bias the dissolve factor to compensate

#

probably the easiest solution

#

use the Tiling and Offset node with values of 0.5 on the shader

sonic plinth
#

it seems having the noise go to B instead of A makes it so 0 is invisible and 2 is completely visible

gleaming moss
#

yeah would suggest setting it like I have in the picture

#

just didn't see how you arranged the subtract

sonic plinth
cloud turret
#

Anyone know for sure if methods like GetMainLight work in 2d?

#

Haven't been able to track down any 2d render pipeline specific shader code in github

sonic plinth
#

hey so is it possible to have a 'transition' between these 'tiles' with a shader? the whole map is a big Texture2D so it should be able to be done

sonic plinth
#

Anyone?

proven sundial
#

Trying to translate a graph from amplify to unity format. Need help with a few missing nodes. What would be the equivalent of Register local variable ?https://inresin.wordpress.com/2020/04/03/terrain-and-mesh-blending-in-unity/

regal stag
#

@proven sundial I don't think there is an equivalent. It's stores the value in a variable which can be obtained via the Get Local Var node later on. The purpose is just to make the graph less messy. In shadergraph, you'd just have to drag the output directly into the other slot.

proven sundial
#

Ah, ok!

#

Messy graphs is my speciality, so that shouldn't be a problem! ๐Ÿ˜›

#

And for Append, I'll use Add, right @regal stag

regal stag
#

No, I think the append is putting the two Vector1 values into a Vector2. The equivalent would be the Vector2 or Combine node

proven sundial
#

Thanks, last question for now:
R=X
G=Y
B=Z
?

regal stag
#

Yeah, and A=W for the fourth component.

proven sundial
#

I suspect you've gone over the tut/breakdown yourself already?

regal stag
#

I read through it briefly but haven't tried it out

proven sundial
#

I find it a bit odd that I have to render a heightmap, shaders that give similar results, that I've come across in the past (looking at @desert pumice ) didn't seem to need that.

desert pumice
#

re-rendering the terrain ever frame seems an expensive way to do mesh blending.. terrain is static. That said, it does handle some dynamic cases nicely..

devout quarry
#

I got a question

#

So a directional light has a vector3 rotation right

#

the values in the inspector

#

How can I convert those values to a direction vector?

#

I don't want to read the rotation in the shader or anything, I can input the rotation values manually

#

but I want it converted to a direction

#

I mean I can convert it in my head, for example a rotation of (45,0,0)

#

would become a direction of (0,-0.5,0.5)

grand jolt
#

Hi! There is any recommended shader to try to make a decal?

low lichen
#

@devout quarry Why do you want to do this conversion in the shader if you're inputting it from script?

#

@grand jolt It depends on what rendering path you are using, forward or deferred

devout quarry
#

I'm not inputting from a script

#

I want the direction hardcoded in there for now

#

but the direction needs to match a certain rotation in eulerangles

grand jolt
#

@low lichen How can I know it? Im using the URP

low lichen
#

@devout quarry So you just want some method of converting euler angles into a normalized direction that you can do in your head?

#

@grand jolt URP is forward rendering

devout quarry
#

or calculator

#

but yeah basically I want to know how I can convert euler angles to normalized direction

#

but maybe that's not really shader related

low lichen
#

@devout quarry I'd recommend installing the Immediate Window package in Unity so you can just input:

Quaternion.Euler(whateverX, whateverY, whateverZ) * Vector3.forward
#

And it will print out the direction you want

#

Or do it in a script

grand jolt
#

@low lichen And that supports decals? Or do I need to fake it

low lichen
#

@grand jolt Decals are easier to do in deferred, because it has all the information you need about the scene ready to use. That is the depth buffer and the normal buffer.

#

@grand jolt You can still do decals similarly to how they are done in deferred, but you either have to render the normals texture yourself or calculate the normal by sampling the depth texture multiple times and calculating a normal.

grand jolt
#

@low lichen Ill try to look about it then, thx

devout quarry
#

Thank you for the tip mentally

#

will try

devout quarry
#

works like a charm

#

didn't know about that window, thanks!

grand jolt
#

hi guys, so i'm making a shader in shader graph

#

i am using rotate on a sample texture 2d to rotate the texture 90 degrees, and i want to add a tiling and offset node to make it scroll, and i tried things like multiplying/adding rotation to the tiling and offset, and also trying to put the sample texture into another one somehow but that didnt work either, how can i do this?

gleaming moss
#

have you tried connecting the output of the tiling and offset note into the rotation or vice versa

grand jolt
#

no, but i fixed it anyways, it was a super simple texture so i manually rotated it and made a new texture with the rotation

#

but

#

i do have one more question

#

its simple

#

so

#

is there any way

#

that I can do something like the hdr effect

#

where it is kind of a low intensity to a high intensity

#

but with a gradient

#

e.g the high intensity is a different color

livid island
#

Can anyone guide with normals recalculation? I'm displacing vertices with my vert shader, how could I recalculate the vertex normals based on that displacement?

sonic plinth
#

@gleaming moss Hey hope I'm not being annoying by asking but how would I turn the 0-2 range to a 0-255 range?

gleaming moss
#

@sonic plinth mostly adjusting the parameters to the tiling and offset node in the graph

sonic plinth
#

I dont have a tiling and offset node, where would I put one

gleaming moss
#

are you tweaking the dissolve amount parameter before putting it in the subtract node

sonic plinth
#

I'm not no

gleaming moss
#

which range are we talking about then

#

not sure I follow

sonic plinth
#

well I want the dissolve amount to be 0-255, instead of 0-2

gleaming moss
#

are you talking in general or is there something I don't remember

#

what does the graph look like right now

sonic plinth
#

the dissolve amount range currently works like 0-2 but I want it to work like 0-255

gleaming moss
#

should be able to scale the dissolve amount by (2/255)

#

regular algebra

sonic plinth
#

you did mean like dissolveamount/255?

#

and the dissolveamount range being 0 - 255

gleaming moss
#

right, so the final formula would be like (2 * dissolveamount / 255)

#

which can be simplified to (dissolveamount / 1) * (2/255)

#

cancel the division by 1, get (dissolveamount * 2/255)

#

quick sanity check, if dissolveamount is 255 then it becomes (255 * 2 / 255) or just 2

#

or 2 * 255/255

sonic plinth
#

I just did dissolveamount * 2 and divide that by 255

sonic plinth
#

@gleaming moss how would I add a random offset to the noise so it doesnt look repetitive every time a item dissolves?

twin swallow
#

anyone know why this stretching happens in the image on the left? it doesnt happen in any videos ive seen

lime viper
#

is that maybe what the image looks like without any alpha value?

vocal narwhal
#

That's how it looks without alpha visible

twin swallow
#

So it's an issue with the way the png was saved?

lime viper
#

no you often want to repeat pixels like that so that if the alpha samples a little wider the colors maintain the same

#

if you say filled that area with black pixels the final image when mip-mapped down might end up writing a bunch of black pixels

#

so it would have the sprite have a weird outline

twin swallow
#

im adding an outline, and those stretched pixels are affecting the output, tinting the outline

lime viper
#

I'm not familiar enough with the sprite shader graph to understand specifics I'm afraid, what does your outline effect look like?

#

as in how is it implemented

twin swallow
#

ah, the reason i wasnt seeing it in videos is that they have a solid color outline on their sprites

#

im shifting the alpha in 4 directions, then adding them together and subtracting the original alpha to get a border. then coloring it and adding it to the original

#

the white center of that ship is lightening the border

lime viper
#

so there are a couple of ways you can fix it, you can first multiply the RGB of the base texture by the alpha then apply the outline, that is probably the cheapest

#

otherwise you are gonna want blends, lerps or branches

twin swallow
#

multiplying the alpha worked perfectly ๐Ÿ™‚

lime viper
#

don't know how well SG optimizes but if it collapses down correctly it should just be a single MAD so same cost as what you had before

twin swallow
#

now im left with a black background on it ๐Ÿ˜‚

#

i should be able to manage this

#

got it. thanks for the assist!

lime viper
#

no problem, glad to help

twin swallow
#

it doesnt seem to work properly on a sliced sprite. it seems the other spites in my sprite sheet are getting borders that extend onto nearby sprites

lime viper
#

hmm I don't know how the sprite sheets work, but you might try setting it so that the sampler state is set to clamp

twin swallow
#

i may just need to split the sprites so the shader samples individual textures

#

seems like there must be a way to do this, though

lime viper
#

like I said I'm not too familiar with sprites, how are you selecting the different sprites?

twin swallow
#

its set on the SpriteRenderer component in Inspector

lime viper
#

so you aren't doing it in your shader at all?

twin swallow
lime viper
#

can you show me what a UV node looks like ?

twin swallow
lime viper
#

ok, so you might be able to use the UV's to mask things

#

so you might be able to just throw a saturate in between the UV node and the sample texture node

twin swallow
#

doesnt seem to have changed the final output

#

The blue at the top to the left and right are from the ship sprite above

lime viper
#

how are you expanding your alpha?

twin swallow
#

I'm offsetting the alpha in 4 directions, then adding those together

cursive jewel
#

Hi guys, I am working on a2D project in which water shader is rising and if it touches character, the character dies.. I have very limited knowledge about shaders and have no idea how to implement collision detection. Please help..

lime viper
#

@cursive jewel Shaders are usually not a great means of driving gameplay things, you likely want to have some sort of game object separate from the shader for that and then have the shader match that object

twin swallow
#

a box collider would probably suffice

lime viper
#

@twin swallow so the problem is you need to mask out any pixels outside of the base 0-1 UV space

cursive jewel
#

@lime viper @twin swallow Thanks

twin swallow
#

Not sure if im doing something wrong. This is a bit over my head ๐Ÿ˜…

#

ive managed to make it output nothing

lime viper
#

heh, to be fair my technique might be flawed for sprite based stuff

twin swallow
#

I think the added complexity is making the sprite atlas not worth it

lime viper
#

I mean it maybe that Unity just hasn't implemented the feature you need for it, 2D shader graph is pretty new

unborn void
#

do anyone know how to compile shader at runtime

dreamy kernel
#

Anyone knows how could I get distance from the forward-facing side of mesh to the back-facing one through graph editor?
I need that to know "thickness" of specific point.

#

I have glowing polygonal trail, that shrinks over time. If it becomes too thin, aliasing gets horrible. I want to prevent that by making it more transparent, depending on it's width, so to say.

#

Please help.

fickle crypt
#

Is there a way to debug compute shaders via RenderDoc with debugging info? Currently it displays disassembler code...

#

I read about #pragma enable_d3d11_debug_symbols but it is used in standard shaders, not Compute Shaders...

meager pelican
#

Hmmm.

#

Vendors have their own tools, and PIX captures frames and lets you edit/debug shaders in simulation. BUT...IDK how/if it works for compute shaders.

#

PIX last I knew needed DX12

fickle crypt
#

My game is DX11 and PIX does not support it, at least 2 latest versions

meager pelican
#

But you're debugging!
Can your dev pc support DX12?
switch to DX12 for debugging. Switch back when done.

???? Maybe ????

fickle crypt
#

i'll try

meager pelican
#

Good luck, but I'd check for compute shader debug support first. like I said, IDK about that.

fervent tinsel
#

@fickle crypt latest PIX has DX11 emulation for DX12

fickle crypt
#

I tried, it exits with Exception

fervent tinsel
#

hmmm I wonder if it's published yet

#

did they state it supported that already?

#

they did mention it on DirectX stream few weeks ago I think

naive mural
#

hello, i'm using a compute shader for some calculations and retrieving the data back to the CPU. I require to reset the buffer each time i dispatch the shader, however, setting a new buffer via shader.SetBuffer() is not working to refresh the data back to 0 if i Dispose()/Release(). If i don't Dispose()/Release() of the previous buffer, it works, the data gets nicely gotten rid of and then when i set the new buffer, all of it's values are 0. However, then i'm spammed with warnings that the GC has disposed of the compute buffer and that i should use Dispose()/Release() to get rid of the data properly. Is there a way to reset the buffer that i'm missing?

low lichen
#

I usually have a dedicated kernel for clearing the buffer

naive mural
#

i see, so you dispatch before the main dispatch to clear the data?

low lichen
#

Yeah

naive mural
#

@low lichen thanks

heady sierra
#

Guys I would like to ask, would it be possible to have something like box layer which can make the graphics at the back affected by the boxed-shader

#

Let me draw first

grand jolt
#

hi guys, just had a quick question. Im new to shader graph, and essentially I have a bunch of scrolling textures which I used add nodes to combine them all. Is there any way to input that final add node into a another tiling and offset node to offset the texture and then add the final add node and tiling and offset to create a duplicate

digital gust
#

@heady sierra you mean like rippled glass?

#

@grand jolt did you try it?

grand jolt
#

yes

#

essentially i have a network of adds to combine the textures

digital gust
#

And now you want what exactly? Or what is not working?

grand jolt
#

its a bunch of textures, and what i wanted was essentially those textures (scrolling), but offset. Essentially taking the final add node with the combined texture and duplicating it with an offset.

I thought maybe I could take the final texture and put it in another add node, and also have the final texture input into tiling and offset, and the tiling and offset into the add node

digital gust
#

Yes that sounds possible, thats what I meant, did you try it and if yes, what is not working?

leaden gyro
#

Im trying to create a simple reflection glass shader graph. Right now it is reliant on a reflection probe, but this has some issues:

#

As you can see, because the glass is part of one material, they share the probe, which is problematic. I'd prefer to not make all of the windows different materials.

#

So, in URP, is there a better way to get reflections?

gleaming moss
#

use HDRP, only partially ironically

#

reflection probe volumes solve this for you

#

you might be able to wrangle the deferred shading mode in URP into what you need, but that's not actually out

grand jolt
#

is there a shader that can make clothes look dirty when on? like smeared colors over the textures

gilded portal
#

You can craft that with a material blend shader

#

or really even just a grunge overlayed could do what youre looking for

#

or duplicate your geometry and apply a tileable of that grunge over it as a decal but then thats +1 geo so might want to pass by a material

thick fulcrum
#

@leaden gyro reflections with probe in URP are not for things like mirrors / water. They give a general projection. Which is great for rough surfaces, but where you want a mirror like reflection you will need Planar reflections. I suggest looking at the "boat attack" demo from Unity. It has a planar reflections script which you can attach to a camera and then use the provided texture as input in shadergraph.

leaden gyro
#

Ill have a look at how accessable that is @thick fulcrum , thanks

warm marsh
#

is it possible to create a frosted glass material in URP?

thick fulcrum
#

@warm marsh yes it is possible, you will need to enable the opaque texture option in the URP settings. Then you can access it in shadergraph, also need to make sure your in transparent mode for your shader. Then you can affect the texture to give you desired results. If you google there is an example in the forums done by a Unity guy some time back.

warm marsh
#

@thick fulcrum thanks bud, I just cracked it, appreciate the help though

mystic kiln
#

how can i access unity_OrthoParams in the shader graph? (it's a global variable (vector 4) that is already defined)

regal stag
#

@mystic kiln The Camera node has outputs of unity_OrthoParams values.

float _Camera_Width = unity_OrthoParams.x;
float _Camera_Height = unity_OrthoParams.y;```
mystic kiln
#

oh, thanks

desert orbit
#

@slow turret Don't cross-post. pick one channel.

slow turret
#

If i'd knew which one it belongs to

naive mural
#

hello, i have a problem with using textures on Materials. I'm using a RenderTexture as a heightmap in one of my shaders and i am updating this texture each FixedUpdate with Graphics.CopyTexture(). When i do so, materials which use this texture do not get updated and i need to update them manually by assigning the same texture that they're supposed to be using again. Is this expected behaviour?

warm marsh
#

does anybody know where the URP equivalent directory is located Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl

devout quarry
#

probably something like

#

com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl

#

I don't think there is a one-to-one equivalent? Which functions do you need?

wary socket
#

Hi guys, i wanted to ask if its possible to add a galaxy parallax effect onto a 2dsprite and when it moves u get the galaxy effect? like d3 cosmic wings or fortnite skins samsung, or poe shaper realm

meager pelican
#

hello, i have a problem with using textures on Materials. I'm using a RenderTexture as a heightmap in one of my shaders and i am updating this texture each FixedUpdate with Graphics.CopyTexture(). When i do so, materials which use this texture do not get updated and i need to update them manually by assigning the same texture that they're supposed to be using again. Is this expected behaviour?
@naive mural

What do you mean by "materials do not get updated"? Graphics.CopyTexture() happens on the GPU not the CPU. Do you mean to say that the copy didn't work on the GPU?

naive mural
#

@meager pelican I fixed my problem. The texture was getting updated, however, the materials which i presumed to be using the texture were not to the effect that the texture has changed. I forgot that i was creating the texture at the start, however, was not assigning it to the material with the new texture. It was still using the old one, which is why i thought while updating the texture the material was for some reason keeping a copy of the previous texture before the copy and holding that as the reference. I was just using using 2 textures in total and forgot about it.

median lava
#

can someone help me add alpha cutout to the standard asset toon shader

#

ive been trying and im lost

#

this is what i have so far

#
    Properties {
        _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} 
        _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5
        _Mask ("Mask", 2D) = "white" {}
        
    }

    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
        
CGPROGRAM
#pragma surface surf ToonRamp

sampler2D _Ramp;


// custom lighting function that uses a texture ramp based
// on angle between light direction and normal
#pragma lighting ToonRamp exclude_path:prepass alphatest:_Cutoff
inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
{
    #ifndef USING_DIRECTIONAL_LIGHT
    lightDir = normalize(lightDir);
    #endif
    
    half d = dot (s.Normal, lightDir)*0.5 + 0.5;
    half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
    
    half4 c;

    c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
    c.a = 0;
    return c;
}


sampler2D _MainTex;
float4 _Color;
sampler2D _Mask;

struct Input {
    float2 uv_MainTex : TEXCOORD0;
};

void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Alpha = tex2D (_Mask, IN.uv_MainTex).a;
    o.Albedo = c.rgb;
//    o.Alpha = c.a;
}
ENDCG

    } 

    Fallback "Diffuse"
}
#

i still dont have a cutout effect

low lichen
#

@median lava Have you looked at other alpha cutoff shaders to see how they do it?

median lava
#

ive have thats what i did to get what i have @low lichen

#

but still not working

low lichen
#

There's usually a clip() or discard; involved

median lava
#

ive seen the discard before but i dont know where to put it

low lichen
#

It's a way of discarding pixels. So you'd do it in the surf function, which is run for each pixel

#

And you'd probably want to only do discard; if the alpha is lower than some cutoff

median lava
#

tried if(color.a < _CutOff) discard; return color;

#

with no luck

low lichen
#

You don't have any variable named color in your shader

median lava
#

_color

low lichen
#

And the surf function is void, it doesn't return anything.

median lava
#

return color;

low lichen
#

The method doesn't return anything, why are you trying to return something?

#

You'll just get a compile error

#

And I assume you mean _Color, but that property is always the same, regardless of the pixel. It's just the color property in your material

#

So if you do the alpha clip based on that, the whole object will disappear if you reduce the alpha of that color property below the threshold

#

You probably want to take the texture alpha into account somehow

median lava
#

ok ima try that

devout quarry
#

I have this pattern

#

But when I zoom out these patterns emerge

#

Does anybody know why that his?

#

I see these patterns sometimes in other things to, when things are small, packed together

low lichen
#

You solve it with mip mapping

gleaming moss
#

nope

devout quarry
#

I'm not using any texture here

gleaming moss
#

you hide it with mipmapping

devout quarry
#

That's an interesting link, thanks

low lichen
#

It's a problem, mip mapping is a solution

gleaming moss
#

it's innate to any sampling, you can just attenuate high frequencies with mipmaps first as a prefilter

#

it's somewhat possible to counteract mathematically if you know extra information about any high-frequency signals in your shader

#

basically anything likely to change a lot over the span of a few pixels onscreen

#

triangles are actually one of the mostest classicest examples

#

infinite-resolution source signal (basically limits of floating-point resolution) mapped to considerably lower-resolution screen

meager pelican
#

Wait until you use some anti-aliasing (or even not) and you get the creepy crawlies. That's fun too.

gleaming moss
#

kill post processing AA

#

no remorse or hesitation

#

it's Wrongโ„ข

tardy spire
#

I'm setting some shader properties via a material property block and it's working great, but the property I'm setting is **not **marked with the [PerRendererData] attribute in the shader. What is the point of the attribute if it works without it? Does it improve performance?

gleaming moss
#

@tardy spire I believe you end up writing more constant data for every draw call

low lichen
#

@tardy spire Nope. As I understand it, it used to be necessary, but now it just hides the property

tardy spire
#

Interesting, maybe I should test it ๐Ÿค”
On a similar note, do you know if there's a performance benefit to create on material property block and send it to multiple renderers, or create a new material property block for each renderer. Ignoring the increased memory and time spent setting the same value on multiple MPBs, I'm curious if there's a rendering cost. I guess this is another thing I can test, but if someone already knows it'll save me 10 minutes ๐Ÿ˜†

low lichen
#

When you call SetPropertyBlock, it appears it just copies the data from it, because if you modify it, you still have to set it again.

gleaming moss
#

there's always going to be some decoupling with constant data since there's an actual write to GPU memory involved

tardy spire
#

Ah right. Makes sense! Thanks @gleaming moss @low lichen

gleaming moss
#

yeah tl;dr I don't think there's a 1:1 relationship with cbuffers to MaterialPropertyBlocks

meager pelican
#

Ignoring the increased memory and time spent setting the same value on multiple MPBs, I'm curious if there's a rendering cost. @tardy spire

#

Well, if you ignore all the extra cost stuff, then no. ๐Ÿ˜‰

#

Don't forget to ignore the extra cost of uploading the extra redundant data to the GPU too.

#

Seriously, though, the various "batchers" handle all that, that's all part of the batching restrictions for those cbuffers, as I understand it.

But if a different renderer used a different buffer somehow, then I suppose it doesn't result in duplicate reads from the buffer. So it would be handling overhead, as I understand it. ?Or there's only ever one buffer?

#

So IDK if it's possible to force different CBUFFERS for the same shader/material using MPB's. at all.

median lava
#

i got an error message variable 'c' used without having been completely initialized at line 32 (on d3d11)

#

i dont know where to add the UNITY_INITIALIZE_OUTPUT thingy

#

here's what i got so far

#
    Properties {
        _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
    }
 
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
       
CGPROGRAM
#pragma surface surf ToonRamp
 
sampler2D _Ramp;
 
// custom lighting function that uses a texture ramp based
// on angle between light direction and normal
#pragma lighting ToonRamp exclude_path:prepass
inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
{
    #ifndef USING_DIRECTIONAL_LIGHT
    lightDir = normalize(lightDir);
    #endif
   
   
    half d = dot (s.Normal, lightDir)*0.5 + 0.5;
    half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
   
    half4 c;
    c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);   
    return c;
}
 
 
sampler2D _MainTex;
float4 _Color;
 
struct Input {
    float2 uv_MainTex : TEXCOORD0;
};
 
void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a;
   
}
ENDCG
 
    }
 
    Fallback "Diffuse"
}```
dry grotto
#

your variable c is not initialized, try half4 c = new half4(1.0, 1.0, 1.0, 1.0);

median lava
#

@dry grotto the error message is gone but my shader isnt acting like it should ๐Ÿ˜ฆ

meager pelican
#

Use half4(expression, whateverAlpha)

median lava
#

where exactly? @meager pelican

#

i have no clue how to code shaders

meager pelican
#

You have lines that say:

    c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);  ```

Try this:
``` half4 c = half4(s.Albedo * _LightColor0.rgb * ramp * (atten * 2), <whatever alpha you want>);```
#

or maybe (I'd have to check the input struct) you can return the s.alpha.

dry grotto
median lava
#

ive changed it to half4 c = half4(s.Albedo * _LightColor0.rgb * ramp * (atten * 2));

#

now i get redefinition of 'c' at line 33 error

#

that means i have two right?

dry grotto
#

Yes, you should only define c once, like you would in C#

inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
{
    #ifndef USING_DIRECTIONAL_LIGHT
    lightDir = normalize(lightDir);
    #endif
   
   
    half d = dot (s.Normal, lightDir)*0.5 + 0.5;
    half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
   
    half4 c = half4(s.Albedo * _LightColor0.rgb * ramp * (atten * 2.0), s.Alpha); 
    return c;
}
median lava
#

@dry grotto thanks the error is gone but i still have no alpha on the material ๐Ÿ˜ซ

dry grotto
#

Ah okay, so the problem is alpha? Try:
#pragma surface surf ToonRamp keepalpha

median lava
#

@dry grotto no luck

dry grotto
#

Wait, there are a few things wrong here. One Sec

median lava
#

as you can see the texture has alpha but the material is not transparent

#
    Properties {
        _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
    }
 
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
       
CGPROGRAM
#pragma surface surf ToonRamp keepalpha
 
sampler2D _Ramp;
 
// custom lighting function that uses a texture ramp based
// on angle between light direction and normal
#pragma lighting ToonRamp exclude_path:prepass
inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
{
    #ifndef USING_DIRECTIONAL_LIGHT
    lightDir = normalize(lightDir);
    #endif
   
   
    half d = dot (s.Normal, lightDir)*0.5 + 0.5;
    half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
   
    half4 c = half4(s.Albedo * _LightColor0.rgb * ramp * (atten * 2), s.Alpha); 
    return c;
}
 
 
sampler2D _MainTex;
float4 _Color;
 
struct Input {
    float2 uv_MainTex : TEXCOORD0;
};
 
void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a;
   
}
ENDCG
 
    }
 
    Fallback "Diffuse"
}```
#

what i got so far

stone sandal
#

please use something like codebin to share large chunks of code like that to keep the chat organized c:

dry grotto
#
Shader "Toon/Lit" {
    Properties {
        _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
    }
 
    SubShader {
        Tags { "RenderType"="Transparent" "Queue" = "Transparent" }
        Blend SrcAlpha OneMinusSrcAlpha
        LOD 200
       
CGPROGRAM
#pragma surface surf ToonRamp keepalpha
 
sampler2D _Ramp;
 
// custom lighting function that uses a texture ramp based
// on angle between light direction and normal
#pragma lighting ToonRamp exclude_path:prepass
inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
{
    #ifndef USING_DIRECTIONAL_LIGHT
    lightDir = normalize(lightDir);
    #endif
   
   
    half d = dot (s.Normal, lightDir)*0.5 + 0.5;
    half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
   
    half4 c = half4(1.0, 1.0, 1.0, 1.0);
    c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2.0);   
    c.a = s.Alpha;
    return c;
}
 
 
sampler2D _MainTex;
float4 _Color;
 
struct Input {
    float2 uv_MainTex : TEXCOORD0;
};
 
void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a;
   
}
ENDCG
 
    }
 
    Fallback "Legacy Shaders/Transparent/VertexLit"
}
#

Try that one.
@stone sandal whoops, sorry :S

stone sandal
median lava
#

@stone sandal sorry

#

@dry grotto thanks but unfortunately now i get Unexpected token usertype. Expected one of: ',' ';' at line 31 error

dry grotto
#

Oh, yep remove the new from line 31

#

So the trick here was to define the blend mode (line 10)

median lava
#

@dry grotto hey awesome it works !!! ๐Ÿ™‚

#

@dry grotto thank you so much

dry grotto
#

To make sure everything renders correctly transparent objects also need to be rendered after opaque one's, that's what's defined in line 9. Line 55 is also interesting, since there will be methods that are not defined in your shader, so setting the correct fallback can be important (even though that was not the problem with this shader). ๐Ÿ™‚

heady jewel
#

Hi, I'm trying to make realistic clouds for my game but I don't know how to make them volumetric, how could I do this ?

median lava
#

i really dont know mush about surface shader code

#

i been trying for 3 days

dry grotto
heady jewel
#

Currently they are just a noise texture with alpha clipping

median lava
#

@dry grotto thanks i will check that out

heady jewel
#

I'm trying to make something like this

#

Only the big clouds

whole glacier
#

how would one achieve a looping custom gradient?

amber saffron
#

Easiest : sample a looping gradient texture

whole glacier
#

im doing it in shaderlab and the end goal is its a random looping color gradient

amber saffron
#

What will be random there ? Size of the loop ? Gradient colors ? ...

whole glacier
#

Gradient colors

amber saffron
#

Using an array of color value and looping on it to lerp the final color.

whole glacier
#

ah okay thank you, ill check it out!

mental stirrup
#

I am trying to create a buoyant object on a water shader. How do I retrieve the surface height of the waves?

#

it's not a mesh, it's a shader

#

Does Unity have a built in shader graph?

low lichen
#

I don't understand what you mean

mental stirrup
#

what programming language are Unity shaders?

#

and is there a graph within Unity?

low lichen
#

Did you make this shader graph?

#

It sounds like you don't understand what Shader Graph is

grand jolt
#

HSLS @mental stirrup you can make custom graph shaders on shadergraph

mental stirrup
#

I have worked with a shadergraph in Blender. I dont know where to find the window in Unity.

The asset I purchased was made with ShardForge I guess...

plucky bone
#

looks at the thing that's literally called shader graph

regal stag
#

Unity has a Shader Graph tool for the Universal or High Definition render pipelines

plucky bone
#

Shaderforge?

#

It's an asset

#

You'll have to download it

mental stirrup
#

So... I purchased an asset off the Asset Store.
The water shader it uses is here:

I am trying to either
a) Get the height of the surface under a 3d game object in order to change the transform.position.y (height) to the shader's surface height
b) Use the same algorithm from the shader and transfer it to a C# that I can attach to a game object.

Essentially, I want and object to float with the waves.

#

๐Ÿ™‚

plucky bone
#

Neither of that is really easily done

#

And I doubt the creator appreciates someone posting the shader publicly

#

(You probably agreed with a license that doesn't allow you to publish it publicly as well)

mental stirrup
#

Oops?

#

Can you report it and get it deleted?

And can you guide me on figuring out how to make an object float?

plucky bone
#

You can just delete it yourself

mental stirrup
#

I cant delete it from pastebin, but I deleted it from Discord

#

nvm

devout quarry
#

lol which asset was it

plucky bone
#

Anyways, just converting a shader to C# is a terrible idea

#

Your performance will most likely be terrible

mental stirrup
#

Alright... and is there a float I can retrieve from the shader?

plucky bone
#

So you probably want to some simpler or threaded algorithm for collision

mental stirrup
#

of the surface height or vertex height?

low lichen
#

Not for modifying the mesh, just to calculate what the height should be for an object on the surface

plucky bone
#

CPU > GPU tends to be mostly one way

mental stirrup
#

Some water assets modify the mesh, if that were the case then I could maybe figure it out.

This water asset uses only shader code

#

actually... it has a reflection script for water reflection

nocturne escarp
#

Hey fellow coders !
I need a bit help here as i am working for first ttime on shaders... can anyone help me setting up lightweight pipeline

plucky bone
#

LWRP is no longer a thing iirc

#

It's now URP

mental stirrup
devout quarry
#

Have you tried contacting the creator?

mental stirrup
#

I will, I just thought someone here might have some insight.

plucky bone
#

It really isn't that simple to make an object float

devout quarry
#

I see 2 options. 1. Convert wave logic to C# script so you can read values there as well. 2. Do waves purely in C#, not in shader

#

I have no idea if those are good ideas but that's what I would try

regal stag
mental stirrup
#

I'm not trying to make Assassins Creed Black Flag or anything...
I was hoping to find some simple way to jerry-rig an object to go up and down on the Y-axis based on the height of the shader vertex below it.

devout quarry
#

Take a look at the code he uses for wave height

#

convert it to C#, and then use that C# script to move objects up/down

#

the asset uses amplify shader editor from the looks of it

#

this might help as well

regal stag
#

From the code they posted earlier, it was a shader forge shader. It still contains a vertex shader (vert function) though which is what you'd need to use to calculate the height.

mental stirrup
#

Holy cow... this stuff is way over my head.

devout quarry
#

yeah well buoyancy is not basic

mental stirrup
#

Would be cool if I could drop a dynamic NavMesh on the water... lmao

low lichen
#

The method he describes is strange. It sounds like he's doing the mesh modification on the CPU because he has access to the mesh vertices from script, so presumably he has some script that simulates the waves for each vertex. But instead of just doing the same simulation for each corner of the object, he uses the vertices he already computed and tries to find the closest vertex to each corner by comparing the distance of every vertex to each corner.

#

I can't imagine that being faster than just simulating the wave heights for those corner points too, unless your wave simulation is super heavy

mental stirrup
#

(Is thinking about abandoning floating objects)

low lichen
#

I guess he maybe did it so that his buoyancy asset would be compatible with any water wave asset that modifies the mesh on the CPU

mental stirrup
#

I was hoping I could figure out a simple way to get the Vertex Y position or distance from each sphere collider, then just the height of each sphere collider in FixedUpdate()

#

from collider to shader surface

low lichen
#

The mesh is calculated on the GPU and isn't saved anywhere. You can't access it.

#

All you can do is simulate what the shader is doing yourself

#

In script

mental stirrup
#

๐Ÿฅบ

nocturne escarp
#

@regal stag how to use it ?

#

in the same way as Lightweight RP ??

devout quarry
#

It's just a name change

#

it's a continuation

#

you can get URP in the package manager in Unity 2019.3+

nocturne escarp
#

@devout quarry thanks

mental stirrup
devout quarry
#

@mental stirrup that asset uses a sinusoidal wave

#

so if your water shader uses another kind of wave, it might not match up

#

hard to tell since the asset page doesn't have a lot of information

#

I would follow that tutorial ๐Ÿ™‚

mental stirrup
#

Thanks.
I guess then... after I follow the tutorial, what do I research in order to create foam and masks and such?

mental stirrup
#

How does one practice programming shaders?

devout quarry
#

just look for tutorials online

#

you practice by doing it

#

first, choose if you want to do hand written shaders or node-based

#

then look for tutorials

mental stirrup
#

Yep. Only way to learn is to do it. Your google search phrase will help though.

#

Thanks for pointing me in the right direction

#

-or- I might purchase an asset that includes object buoyancy. LOL

#

Either way, thanks for your help.

#

Im gonna follow the tutorial and learn about shaders. Dangit...

#

There's always something else. ๐Ÿ™‚

prime pasture
#

Any idea how to easily get screen uv from custom standard shader? (I took the standard shader and just edited the fragBase)

#

This is basically the shader:

            #pragma vertex vertBase
            #pragma fragment fragBase
            #include "UnityStandardCore.cginc"
            VertexOutputForwardBase vertBase(VertexInput v) { return vertForwardBase(v); }
            VertexOutputForwardAdd vertAdd(VertexInput v) { return vertForwardAdd(v); }

            #define COLORS 32.0
            uniform sampler2D _LUT;
            float4 _LUT_TexelSize;
            float _Contribution;
            int _ShouldDiscard;

            half4 fragBase(VertexOutputForwardBase i) : SV_Target
            {
                clip(_ShouldDiscard);

                float maxColor = COLORS - 1.0;
                half4 col = saturate(fragForwardBaseInternal(i));
                float halfColX = 0.5 / _LUT_TexelSize.z;
                float halfColY = 0.5 / _LUT_TexelSize.w;
                float threshold = maxColor / COLORS;

                float xOffset = halfColX + col.r * threshold / COLORS;
                float yOffset = halfColY + col.g * threshold;
                float cell = floor(col.b * maxColor);

                float2 lutPos = float2(cell / COLORS + xOffset, yOffset);
                half4 gradedCol = tex2D(_LUT, lutPos);

                col.rgb = lerp(col.rgb, gradedCol.rgb, _Contribution);
                //half4 col = fragForwardBaseInternal(i);
                //col = tex2D(_LUT, i.tex);
                return col;
            }
            half4 fragAdd(VertexOutputForwardAdd i) : SV_Target { return  fragForwardAddInternal(i); }
hoary umbra
#

does anybody hase an idea why shader graph and gradient color as proprty is not working?

stone sandal
#

do you mean on the material inspector?

hoary umbra
#

it doesn't apear on the material inspector and if you fill the property gradient color with multiple colors, unity will display this:

#

I didn't even connected this gradient property with anything. but using a gradient that isn't listed as property and everything is fine according to unity.

stone sandal
devout quarry
#

Do VFX graph/shader graph teams work together closely? Some of the visual designs are really different

#

although maybe that's on purpose

stone sandal
#

we try, but we are based out of different countries on opposite timezones c:

devout quarry
#

but like a 'subtract' node or something, I would expect those to look exactly the same