#archived-shaders
1 messages Β· Page 169 of 1
It samples _CameraDepthTexture
I think _CameraDepthAttachment is related to the actual depth buffer / render target, but it's copied (or possibly recreated) into _CameraDepthTexture so it can be sampled
yeah I found I had to make changes to _CameraDepthAttachment to get post processing working for SRP
@tardy spire You still need help with your problem?
Weirdly, if I blit the _CameraDepthAttachment into the _CameraDepthTexture the scene view goes to pot (and the effect is still broken and cant be sampled in the game view)
argh
It's like just reading the depth buffer can be enough to screw it up
@teal breach Is the cube using a custom shader? And if so, does that shader have a shadow caster pass? (because I think it might use that when creating the depth texture, while in the scene it only needs a depthonly pass).
yeah it has the shadowcaster pass
the actual depth buffer itself looks fine in frame debug
Can't really think of why it wouldn't show in the depth texture then.
and so does the _CameraDepthTexture
(after the blit)
I don't entirely trust the Frame Debug though
in the same frame, if I go forward a few steps in the debugger, then back to the original step, it now looks different
I suppose something must be left in an undefined state
@low lichen that'd be great! I found out how to get shadowcoords and sample the shadowmap but haven't figured out how to add a fade yet. (Slight tangent:) Oddly if I pass 0,0,0,0 as the shadow coord the attenuation still works. Not sure why that is π€
I'm trying to understand your description of the custom lighting model. If surface angle doesn't affect it, what determines which surfaces are in shade?
Or do you mean surface angle matters, but it's binary rather than smooth?
The shader is unlit and lerps between a light and shadow tint by the attenuation. There's no ndotl or anything. (Not at computer now but when I get back I can send images to better explain)
So you have a directional light with shadows, but objects are fully lit unless another object casts a shadow on them?
Yup!
There's self shadowing so it doesn't look too weird, but I'd like to add a fade where the shadow starts so that it looks softer and you can't see as much artifacting
Not sure how the shadow rendering works, but if it's rendering a depth value I could check the fragments distance from the light source against the depth of whatever is casting the shadow to create a gradient which I can use to fade in the shadow over some distance
I know it's not even remotely physically correct, but I'm trying to mimic another stylized lighting look and this is something they're doing with custom light/shadow rendering. I want to see how much of it I can do without ditching Unitys lighting system
@low lichen here's custom shadows with a fade
here's unity shadows without a fade
neither does NdotL, both tint base color with lerp(shadow color, light color, attenuation)
Well, that's cool looking.
So you have some self-shadow that I don't understand, but it has to change anyway. And then you have cast shadows, but you can do a "soft" version of those. Like that greenish line on the upright in the right foreground on a "flat" surface...that's cast and could be soft shadows.
But for self-shadows, you'll probably have to do (you're going to hate this answer) an NdotL-ish calc anyway, maybe with a smoothstep or step function, I'd think. Because you need to know when you get near the threshold of your shadow. But you can do it differently to have less gradient I suppose.
Off the top of my head and best guess.
But IDK how that would fix your "cube" to be soft. Hmm. you can always check out the code for shadowcaster pass, if you're using their lighting (lit) shaders. But you'll have to manually edit. For the BRDF calc on your cube IDK how you know unless you can use normals and some post process. Dang.
Rambling. Oy.
Hello can anyone tell me how to apply a gradient affect, my two scenes are two drastic colors and i want to soften the transition π, its for a 2d game π
@meager pelican yea so the first image of the pipe is a completely custom lighting/shadow system. I didn't write it, but my understanding is an orthographic camera is used for the "directional light." it uses a separate urp renderer to render the depth of the scene from the light's transform and then fragments can check if they are in shadow by checking if the world position is further away from the light than the depth the camera rendered at their position in shadowspace. having this depth lets the fragment check how close to the surface that is causing the shadow the fragment position is in. using that distance the shader makes the shadow fade in over some distance.
i'm assuming unity's lighting is doing something similar? if i could get the fragments distance from the surface that is casting a shadow i could implement my own fade. I guess the question is: does Unity's lighting system store enough info for me to calculate this:
I'm using ASE and have made my own attenuation function with this as the core code
float4 shadowCoord = TransformWorldToShadowCoord(position);
Light light = GetMainLight(shadowCoord);
return light.distanceAttenuation * light.shadowAttenuation;
this is "default" attenuation you normally get. so i'm trying to see if i can modify it to fade in over some distance
I've thought about using ndotl and offsetting/remapping it, but i fear unity's shadows start too "high" up on the model to do this without it feeling like normal lighting. The light has to bleed around the backside of the model a bit for it to feel soft and fluffy.
I guess I could increase the depth bias on the light and use tweaked ndotl like you mention, but i worry that would result in weird shadows since shadows cast on other objects would have a large bias but selfshadowing would look a lil more normal do to tweaked ndotl
I'm in forward mode and drawing large decals on the ground. How can I bake shadows onto my decal, but avoid dropping a shadow onto the mesh underneath?
@regal stag would that blit feature be usable by shaders on, say, a sprite as well, or is it only for full screen stuff?
@eager folio It's fullscreen but I think you can blit to a render texture rather than back to the camera, though I've never really tried that. Then get that texture in a regular shader. I imagine you'd probably need to make sure you handle the blit before those objects are rendered though.
If you are looking to only apply a fullscreen effect to certain objects, you can render only those objects to an off screen render target and then use that as a mask for the post process effect
would anyone be able to explain to me how I can tell if an objects depth is within a fixed range in shader graph?
I've been experimenting with the scene depth node and reading online in linear space it should return a value between 0-1 using near plane and far plane. But just simply plugging this into color shows this not to be the case - the color is the same regardless of its position in my cameras clip range ( which is 0-10)
What would be a good result for me is at near plane the object was black and at far plane the object was white I think
oh that's why I subtract the screenpos.w
because I have the max of the far plane
I kept seeing examples of multiplying scene depth by far range which confused me
did you check this https://twitter.com/cyanilux/status/1169932943869059073
I've never used the Orthographic projection, but depth effects work slightly differently. I was asked about it on the official Unity discord, and after some research got it working, so might as well share a small thread here too. π #unity3D #shaders https://t.co/ng67JlVsyk
382
I did read that yeah
not the twitter thread
it's been difficult for me to convert information into my use case
I'm basically trying to enable / disable an effect by comparing the objects depth value
it should only be enabled if the object is closer to the camera than my player is
Hi, I'm back with my foam problem :)
Like you said @amber saffron, I've used the DDX and DDY nodes like this
Here the rest of the graph which is going to the emission
Unfortunately, it's giving me a weird foam around my object
There are some weirds triangles
I don't know where I'm wrong with the graph :/
Yes, that's what I'm trying to do !
Has anyone dealt with shadergraph? I have a issue when I enabled double sided. I'm able to see it in scene view but when I press play I lose the double sided.
Hello! Anyone know if you can expose the blend modes like additive and alpha outside of shadergraph?
@honest bison that looks amazing! any insight how to achieve that outward pulsing?
iirc, they are only exposed in HDRP with HDRP/* master nodes.
For the pulsing effect, it's probably done using some maths (ex: sin(x+time)) after the scene depth VS current depth comparison.
@amber saffron ahh ok awesome ty on both points!
I think they are using signed distance fields (SDF) by passing the sphere positions + radius in through an array, as the scene is called "SDF_Array". Might be able to get a similar result with depth too though
Good catch Cyan on the scene name π
Sorry guys, that is exactly right. Alan Zuchoni has a great tutorial on how to send arrays to a shader.
is there a way to make garaud shading with the shadergraph?
i'm assuming unity's lighting is doing something similar? if i could get the fragments distance from the surface that is casting a shadow i could implement my own fade. I guess the question is: does Unity's lighting system store enough info for me to calculate this:
I don't think so @tardy spire
Others may know more, but with the shadow map (which is where that shadow comes from as you're saying) you don't know WHAT caused the shadow to be there.
But like I said, shadow casting process knows, and it supports "fuzzy" soft-shadows. So why not just use that? They blur the shadow map before casting it onto the scene. So the cast shadows get the blur that way.
The nasty question was the OTHER one, how do you SELF SHADOW that cube of yours to get what you want? With roundish objects you can use the NdotL stuff and get an idea how close you are to a boundary because it's a numeric result. But with that cube, the sharp edge has an abrupt change.
Gotcha, I guess it's not lookin too promising :/
In regards to the cube - if I could calculate a fade, the sharp edges shouldn't be a problem, but I agree they would be an issue with NdotL
@tardy spire Is that the effect you want? Do you have an asset that does what you want, but you want to recreate it?
I think you're basically talking about having to completely write your own shadow system from scratch, including self-shadows. Then maybe you can pull it off.
Roger that @meager pelican
@low lichen yea I'm just trying to see how close I can get to the custom look while still using unity's lighting/shadows
the shadows is really the only thing i can't control enough it seems π
Is it an existing asset? I don't know that you answered that.????
I thought you were faking all that up.
haha nah it's a lighting thing https://twitter.com/CynicatPro is working on
it doesn't appear to be released anywhere tho
Did you try the shadow blur (soft shadows) in lighting for cast shadows?
That shadow on the bottom right doesn't look very "soft" right now. Hmm. And it looks like you have some hella bias settings. Guessing.
Yea I've got some weird bias settings, but it's definitely soft shadows
Is it possible to have a properties block inside a custom fullscreen pass?
@crystal light You mean MaterialPropertyBlock?
@low lichen Thank you for your response. I would like to sample a 2D texture inside a custom fullscreen pass, so how exactly could I pass it to the shader?
@crystal light How are you performing the full screen pass now? A material is always required, as far as I know.
If that material has properties, those properties will be used in the pass.
I have another problem with my leaves. Close up, they look as intended, but as i walk away from them, they start to disapear
why is this happening
Might be due to texture mip maps. I think there's an option on the texture to allow mip maps to "Preserve Coverage" which should help fix that.
Yea I've got some weird bias settings, but it's definitely soft shadows
@tardy spire try setting the light distance setting higher. Usually that gives a bit more blur
@regal stag that does not fix it.
@nimble perch Does this happen gradually or does it pop out of existence at a certain distance.
gradually
but only with alphaClipThreshold. when i set it to 0 it does not disapear but than my transparency does not work
this is my shader, maybe it helps
I still think it's related to mipmaps. Is there a reason why the AlphaClipThreshold needs to be as high as 0.9? If the texture alpha is just black & white a value around 0.5 would probably work just as well.
setting the threhold to .5 does fix it mostly but im still getting some wiered outline bugs, but i guess thes due to my texture not heaving perfect alpha.
Is the shader transparent? I'd probably keep it opaque, that way the alpha is just used for the clipping.
What do your texture import settings look like @nimble perch ?
Well, I think the outlines are gone at least π
Might be something to do with shadows, hard to tell
here, on the left sight it looks right on the other sight not
Does changing the shadow bias settings help at all?
where do i change thatπ
Eh, either on the light or URP asset
@nimble perch I'd also experiment with making that just a black and white image, and importing it as greyscale, with the alpha as "From Grey Scale"
Not only will that be lower memory, it'll be cleaner
I think the shader is probably two sided right, and it looks like it's casting shadows onto itself. The faces are too close to really handle that properly, so increasing the depth bias will likely let the shadows through.
im sorry but i still cant find any shadow bias option
Are you using URP or HDRP?
HDRP
Okay, should be on the Light under shadows, according to this : https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@8.2/manual/Shadows-in-HDRP.html
Apparently if some property fields are missing, you need to click the more options cog to expose them.
OOoohhhhhhh
well im sad do tell you guys... but its not fixing it...
by the way this is kind of what im trying to achieve
im wondering: in a shadowcaster pass, is it possible to make only select triangles cast a shadow, but make everything receive shadows?
i added grass particles on top of a surface shader (with geometry shaders etc), and i wanted the grass to not cast a shadow
The shadowcaster pass is only responsible for casting shadows, not receiving them
You can manually write custom shadowcaster passes in all the pipelines AFAIK.
As far as receiving, that's an attribute of the model/object.
shadowcasters also seem to validate how a shader receives shadows
otherwise it appears like something is transparent
in terms of how shadows are placed
also, this is for per object @meager pelican :p i need specific polygons in a shader to cast and others not to
in a single object
I'd assume you can use a custom shadowcaster pass which discards for certain triangles, probably based on some texture mask or vertex colors or something.
i do have a method to know which ones would cast already, i just need to know how to make em not cast :'D
float4 frag(g2f i) : SV_Target
{
if (i.uv.x < 2)
{
// this should not cast
float4 col = tex2D(_FolTexture, i.uv);
if (col.a < _FolClipping && i.uv.y < 2) discard;
}
else
{
// this should
if (i.uv3.y <= 1)
{
float borderAlpha = tex2D(_BorderTex, i.uv3 * float2(1, 0.5) + float2(0, 0.5)).a;
if (borderAlpha < _BorderClipping) discard;
}
}
SHADOW_CASTER_FRAGMENT(i)
}
this is what it looks like right now
this is what happens when only the else statements does the shadowcaster fragment
and this when only the grass particles get the shadowcaster fragments
granted, the grass already looks good to me, but if its possible to not make them cast a shadow, then i'd gladly do so :p
Hey, I'm trying to apply a render texture to a material but struggle to do so, I tried doing this RenderTexture rend = enemyCam[i].targetTexture; enemySprite[i].GetComponent<AIScript>().quad.GetComponent<Renderer>().material.SetTexture("_BaseMap", rend);
but it didn't change BaseMap
Hi all. Today i tried to create little flipbook shader through shader graph for my 2D character. I have sprite sheet with 8 frames of character animation in a row. I decided that using shader graph flipbook node will be nice and clean solution to pass different sprite sheets that supposed to be animated in a same way instead of having tones of animation and animator or complex custom logic for sequencing those frames. I thought it would be simple and inside shader graph result looks just great. But when i created material and sprite renderer with this shader my character was looking wierd.
The first thing was that result sprite renderer looks like it was shredded. That was fixed by changing mesh type from Tight to Full Rect in import settings.
The 2nd thing was that result renderer was was expanded by X. I thought that this is because sprite sheet have 8 frame in a 1 row. So i set X scale to 0.125 (which is 1/8) and now renderer looks perfectly.
So my question is: why 1st wierd thing appearing? And what can i do to not scale sprite renderer for every sprite sheet?
@low lichen seems like they are NOT. I can't even declare a property block within a fullscreen pass shader...
All I really want to do is render a texture in a fullscreen pass, really.
is it posible to create a shader, that does not cast shadows on itsel, but on anything else in shadergraph ?
Hey, I'm trying to apply a render texture to a material but struggle to do so, I tried doing this
enemySprite[i].GetComponent<AIScript>().quad.GetComponent<Renderer>().material.SetTexture("_BaseMap", rend);```
but it didn't change BaseMap
I'm trying to figure out how to make one of those stylized grass shaders using Amplify Shader Editor.
I have gotten close. The problem I am having is that when rotated, my grass is shaded differently and I am not sure how to fix it.
In blender I have rotated the normals of the vertices of the mesh to face up. And that makes it this close.
@sage moss good call. looks like anything that lowers the pixel density (like lower res, less cascades, higher shadow distance) gives it more blur
I have a system im devising where I feed my shaders a list of primative shapes, and operations , plus other data, found out I couldnt feed it a struct only floats, ints, vector4. i imagine if i switch to a computeShader I can feed it the custom class/struct
but i havent really grasped the concept of computeShaders so if anyone has some links or tips would appreciate it. for the most part what Im building works its just a ugly hack where I used a vector4 to pass it data I wanted as string etc
is there an easy way to keep textures tiled instead of manually changing the tiling every time an object's size changes?
can i have help with transparency
Im not sure if this is a shader issue but my objects appear transparent on a side
I imported my models from blender
are your normals oriented in the correct way ? i dont now which shader you are using but i think its cullinng your backfaces
shader says standard
also the normals should be facing the right way
It was a cube and I removed three sides and flipped normals to get a corner of my room
well i would atleast check it
ok
sometimes blender does wiered stuff to your normals
yeah, i think there is a toggle in blender to check which way the face, well, faces
Im flipping the normals of all of the problem areas so it should work after its done
ok I think i fixed it
My normals were indeed weird
I asked this question yesterday. I am in forward render mode. I want my decals to receive baked shadows. I don't want them to drop baked shadows. How to achieve?
I tried flipping the normals to both sides but I still get this problem with this one wall
and that one part of the desk
anyone have any ideas on how to improve this?
like effect wise
anything else to add to the effect
Some UV distortion or glitching effects maybe. I have a hologram breakdown that does those, might give some ideas : https://cyangamedev.wordpress.com/2019/05/20/hologram-shader-breakdown/
@clear vector You seem to have figured out the basic issues; For the first, you should always use full rect if you are doing UV based animation because animating only the UV won't update the outline. For the second, it is probably easiest to just expose the scale in the inspector.
@eager folio thank you for answer. I think it will be easy to do through script. Anyway i will pass different sprite sheets to shader and i need to know frame count, so while i know frame count and count of rows and columns i can calculate proper scale.
also, this is for per object @meager pelican :p i need specific polygons in a shader to cast and others not to
@digital vector
Assuming that code fragment was for a shadowcaster pass, did you try to discard() the pixel if you don't want it to be shadowed? As long as you can tell on a per-pixel basis.....
I sent in Screenshots of what it looks like with discards in each if statement
Neither works
Everything should receive, but not everything should cast
You'd only discard where you don't want a shadow cast.
The grass doesn't receive shadows anymore too
Maybe I did something wrong with how shadow data is passed along, idk
Receiving shadows is a different thing. This is for the pass called SHADOWCASTER. You didn't show the whole pass so I can't tell.
Shadow casting is a PASS
More than the fragment function?
It has a frag function in it.
But it's it's own pass
Yeah it is
I have a pass just for it
I can send more details tomorrow, kinda 1 am here lol
Fine. And if you can tell which polygons cast and which don't, do a discard for those that do not.
but thats what I did in the Screenshots I sent
IDK why you have discards on both 'sides'
That's not what your code did.
I sent the code for the original
But I'm not sure....
The second Screenshot had an added discard
Frack matrix projection π±
Jokes on you I actually had a dream about writing this exact shader lol
lol
Trying to make a shader that applies a glow when the player is close by but I think I'm doing something wrong
PlayerPosition is a global variable set by a script on the player
so the above works but I'm not sure how to completely remove the fresnel if they are over a certain distance
how can I render a custom pass from another point of view (camera)?
@ripe wigeon The fresnel power is not the intensity, but the curve of the effect on the edges.
To controll the intensity, multiply the output of the fresnel by the output of the divide node
Hi. Does anyone know of an example or a tutorial of Chunked LOD, CDLOD, Geo Mipmapping or Geo Clipmapping? I figured that I need to use 1 of these as my LOD system, but have no idea how to even begin making such a system.(Yes, I have googled, but can't find anything unity specific)
ok i have some heavy shader graphs and i want to be able to control when it runs
i plan to have 100s of objects with this shader
Beautiful
but i will only have 5 running at one time
how do i "disable" the shader from running
Thanks @amber saffron, that looks to be where I was going wrong!
heres the shader in action if you want to see it
but to get back to the question
can i just disable the gameobject the shader is attached to or disable a parent object?
Hmm, it's still not increasing as I get closer
Nevermind, switching to absolute world position fixed it
how do i "disable" the shader from running
@steel river There's an old saying in CG....the fastest polygons are the one's you DON'T draw.
You "stop it from running" by not drawing the object.
Is that what you mean?
If you mean "don't animate the distortion"....then pass in some fixed time index (say 0) and don't update it. Or set some scalar variable that you multiply by, and scale to 0 for "off".
@ripe wigeon If you want you can just "not add it in"...
the graph equivalent of
col += (dist > threshold) ? float4(0,0,0,0) : fresnelCol;
If dist is not at the pixel level, like if it's per object origin, see if you can get it to calc in the vertex stage but IDK that you can force that in SG.
@meager pelican like i mean i dont want to have the shader running when it doesnt need to. like i disable the renderer but the shader still runs in the background
i assume that isnt the case though
if i disable it it wont run period
Yeah, it only runs when the object is drawn.
Is it possible to have some original vertex position in the Shader Graph before Wind?
You are referring to getting it in the fragment stage right? I don't think it's possible in shader graph yet.
@regal stag yup. I'm thinking of a way to "bake" some original vertex position into UV2 for example, and get it in a fragment stage. Maybe some custom function code would do?
You could probably bake the data in via C# (as in, copying the vertex positions and put them into the mesh.uv2 channel), but I don't think it's possible within shadergraph, even through a custom hlsl function. You don't have access to the struct in order to allow it to interpolate between the vert and frag. It's something that's on the roadmap but no idea when it's going to be implemented.
Unless you can somehow cheat it through the vertex tangent or vertex normals, but I'm pretty sure they get normalised during the fragment so wouldn't really work. (and would likely mess with shading if it's a pbr/lit shader)
@regal stag I've found a workaround for my case. Use a conversion of Vector 0, 0, 0 from object space to an absolute world space. That should do fine to look up some color variation.
That would give you the object position in world space, but IDK about vertex pos.
@meager pelican well, I've needed some kind of anchor point for color variation that would not account for Wind
some kind of stable basis point
How can I write a custom shader material editor for my Graph?
Are you referring to the material inspector? I know some newer versions of shadergraph allow you to override that - (unsure if the package manager versions include that or not). For the actual editor script, I assume it would be like the example here : https://docs.unity3d.com/Manual/SL-CustomShaderGUI.html
@regal stag yes, I mean the material inspector. I've already saw the doc. Just want to know how to infuse that CustomShaderEditor directive into the shadergraph
@crystal light Some versions have an override on the master node, URP v8.2.0 does at least, not sure about previous ones.
oh @regal stag , the other day I think you mentioned a SHADERPASS_SHADOWCASTER define
I tried it out but it doesn't get defined for 8.2 - not sure about later versions
Hmm, I'm using 8.2.0 and the generated code has it defined
@teal breach Are you trying to find out which pass it is for a built-in pipeline shader? I think built-in uses UNITY_PASS_SHADOWCASTER instead
nah, I have to change the alpha based on whether the object is in a shadowcaster pass or not. I tried using the above define, but it doesn't get set during the draw call (as verified from frame debugger)
I already have a separate material I need to apply to get around the lack of custom passes in ShaderGraph, so I just moved the Shadowcaster pass there
I'm basically just saying 'be wary of that define' - it didn't work for me on 8.2.0, 2020.1.0f
I'm not too sure what you mean by "it doesn't get set during the draw call (as verified from the frame debugger)", but doing something like this in shadergraph would output an alpha value of 1 for the shadow caster and 0 for anything else. I haven't come across any issues with this, it seems to work fine.
Is it just me or is that image file not showing as an image. Is discord okay?
@regal stag I take it back, it looks like it is defined in the generated code. I thought it was defined as per a shader keyword (so I was expecting to see that keyword defined in the frame debugger when making the draw calls on those objects for shadows). I guess my shader wasn't working for some other reason!
Ah right
ahm anyone know whats causing this wiered lighting bug ? where do these lines come from ?
@nimble perch Might be shadow cascade settings?
Hello everyone! I want to repeat a tiled grid.
Take this image for example. I want each of the symbols to randomly change between each other as well as colors
I did something cute with ShaderGraph that does more or less what I want, but it's limited to one symbol only
Can I repeat this result to create a bigger grid?
@spiral bay You would need to change the integer feeding into 'tile' for every tile the uv tiles.
yes
That little part is OK
when I change the integer, the symbol moves and all
that little part works.
I want to take that whole thing and make it one tile, and have like 64 of them
You'd want to make some noise and then convert that into an integer you can feed into the flipbook tile
That would make it move automatically, right?
Not sure what you mean by move automatically
I have a 8x8 grid. Each tile in that grid has a symbol in it. I managed to make a flipbook that takes those symbols and move them. This works. Now, I want to fill my 8x8 grid with all those moving symbols
The solution I have right now is to make a new plane with a new script and tile it manually
but I want to eventually fill a whole wall with these
that means thousands of tiles
So I was wondering if I could have a way to "fill" a plane with these single tiles randomly
as it's a flipbook I imagine not, simplest way is to create c# code to spawn a quad / prefab dynamically and repeat the spawning on x,y axis for however many you want per row etc.
@spiral bay You scale it down to use only a portion of the UV and use the noise texture to 'choose' a tile for each one
@thick fulcrum yeah, that's what I feared. I really didn't want to do this because it would kill my framerate
@eager folio Aye, but how do I get it do make out a huge square with 32, 64, 128, etc of these at the same time?
You tile it.
Hrm, no
lessee...
I am not very good with shadergraph. might be easier to just write it as shader code>.>
Though this is pretty neat π
I did something with tiling random runes a while ago : https://twitter.com/Cyanilux/status/1119599987170709504
Playing around with #shadergraph more! This strange cube (alien computer core?) was made by generating random numbers to manipulate the UVs used to sample the texture containing the runes. See thread for graph! πΎ#unity3D #madewithunity #shaders #gamedev https://t.co/WxRu5Kjyt...
The graph is in the tweet comments, used UV * tiling into Floor node for a seed to generate a random numbers to offset the UV * tiling -> Fraction coord.
Didn't use the Flipbook node but that might have made it a little easier
I figured out what was wrong
I, er, set the input on the noise to an integer.
derp
@regal stag nice, thank you! not in 7.1 though .. π¦
I figured out that using shader from shader graph in URP 2D breaks batching at RenderLoop.Draw. When using just regular sprite renderer all renderers with the same sprite drowned by the 1 RenderLoop.Draw. Am i doing something wrong?
@clear vector are they different materials?
By default all sprites use the same material so they batch together
@clear vector are they different materials?
@eager folio No, i use just one material for my shader
Also tryed create a simple shadergraph shader without any nodes, just empty. And it breaks batching))
Also shader info doesn't say that it will break batching
Welp, guess shadergraph sucks π
@clear vector No reaction gifs, please
Ok, didn't know this rule, sorry
@novel summit This is English only speaking server, sorry.
hey shader masters
I am sure one of you want to contribute to an open source project! https://github.com/Siccity/GLTFUtility/issues/75
your soul will rise to the heavens if you contribute and you will have my eternal gratitude!
@cobalt bolt why don't you just apply new materials when you load the model? If the material property names are the same, it should transfer over
@cobalt bolt why don't you just apply new materials when you load the model? If the material property names are the same, it should transfer over
@sage moss The asset uses 3 custom shaders. They need to be converted.
Then, how does GLTF know the mapping when you serialize and deserialize anyways?
huh...what? I have no idea what you're saying. But the asset works like when you import an FBX into Unity. You can click to expand and see what's inside.
It doesn't convert the gltf into a prefab or anything like that
Anyways, converting the shaders is probably easy for people who knows how shaders work? Hopefully?
Is there a way to make CustomDrawRendererPass to affect VFXGraph particles?
@meager pelican I have a whole world full of meshes with a regular shader. I need to render them a 2nd time into a temporary texture with a random color like the pic attached. Is there a way to do that without remaking the whole camera frustum culling system to get a list of Renderers to draw using CommandBuffer.DrawRenderer?
Why not let Unity figure it out, it already knows!
Have you seen https://docs.unity3d.com/Manual/SL-ShaderReplacement.html ?
IDK how you're assigning colors, but if it's "just" geometry flat shaded like that, however you do it you can have a flat-shading shader that grabs the color and renders it to a render texture (set that destination texture on the camera).
@grand jolt
So you can call Cmera.RenderWithShader
I'm on URP.
I have my own custom Render Objects To Target render feature already, but the issue is I need to pass a custom random color to each mesh somehow while they're all going to share a material.
And the only solution I see is drawing each individually and presetting the material prop for color before each cmd.DrawRenderer.
Yeah, you'll have to stick the color into the mesh data, like a UV set.
Or maybe assign an index into a color array so you can change it without having to update all the meshes.
Really? So no replacement shaders in URP, eh? :/
Render Objects feature allows you to replace the material, it's the same thing.
Seen and seen.
They replace the material
The RenderObjects override material won't copy over shader properties like replacement shaders do though
If he's got the color [index] stuffed into mesh data, might not be too bad.
Yeah if it's stored in the mesh it'll be fine
The color should differ on a per object basis, not a mesh basis.
Crap
Yeah
OK, let's solve it on the C# side.
when you get a "will render object" event, add the object to a list of renderers.
clear that list at the start of a frame
So now you know who is going to render.
Then iterate throug that list and render
Maybe to a render texture.
?
Draw calls will suck
It might make sense to use material property blocks & instancing stuff. I'm not really an expert on that, but what Alexander Ameye asked in #archived-hdrp seems somewhat related to this problem too.
SRP Batcher isn't compatible with property blocks.
I know, but you can still use instancing if you can write the shader to support that
Would it even make sense considering I won't have a million of the same object.
Does your target platform support multiple render targets? As long as we're spitballing....
What if I generate the random color inside the shader?
You might be able to do both at once.
Is the random colour important? If not then sure, might be able to generate it in the shader
The platform is PC.
IDK how you want to assign the color, but I'd seriously consider making it an index
I just need distinct colors for edge detection.
Uh.....
Hmmm.....
Do you have control over the models?
Like blender or other software, and can you assign vert colors?
I can.
Are these quads with a masked/transparent image, or is it a mesh?
Meshes.
I'll come clean, it's basically this https://twitter.com/georgebatch/status/1040996814202318848
Here's a thread about how the leafy biz works in my bird game if you wanna know #screenshotsaturday https://t.co/Nc7hMxVEXp
172
Yeah, outlineing!
You could probably generate a random colour based on the world position of the object.
I guess I could hash the world position, use it as input to noise and make that a color.
Yeah, he says right in that post he uses an assigned vertex color + random color
Then a post-processing pass
And we're discussing the + random color part π
So Vert colors baby!
But ya all great rubber ducks, I forgot about hashing the position.
But Maybe pick random color based on some instancing index
Looking at the comments, they are actually using manual vertex colours
Yeah, but random color added
Yeah, but your other question was "How do i get it to render without duplicating frustum culling" then the replacement shaders....material....
But NOW I'm thinking you can do the whole damn thing in one pass with multiple render textures if you want. Same shader. But it might take custom editing I don't think SG supports MRT's.
I'm not using Shader Graph for my custom effects, I like the control.
So you'd output the "normal" color to one RT and the flat randomized one to the other. Then run your post processing after that.
I haven't tried MRT on URP
No worries, I got the rest of the pipeline down.
This is like the 3rd custom effect I'm writing where I use objects from some layer as a mask and ignoring all the boilerplate it's as simple as that in URP: cs context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings, ref renderStateBlock);
I actually have never needed to use a RenderTexture, I just create a temporary in the command buffer and then release it.
And so does URP itself, at least most of the passes I've checked out.
Yeah, I'm not saying you can't use temp RT's at all....
I'm not making a point, just being a boring nerd π
π
@grand jolt , I take it you want some way to distinguish different objects so you can outline them?
the way I did this was to make a separate outline material, and apply it to the objects (so they have two materials and one submesh)
The outline material defines only a pass with LightMode=Outline
I then add a render feature which renders only objects with LightMode=Outline, so only those objects get drawn to the screen (in this case, a render texture I use for post processing)
is randomness really necessary if world position would be unique for each object?
"Randomness" could = hash-to-some-color
@teal breach oh, the pipeline won't render the mesh in regular mode with this custom LightMode?
That tweet mentioned depth buffer too.
Probably using derivatives on both color and depth to detect changes in PP
if you define it as a separate pass you can basically have it so the normal rendering is unaffected, then when you have your render feature it will only use your custom pass
But yeah, since hashing inside the shader doesn't break batching, I think I'll try it.
(the reason I did it that way rather than world position is because sometimes I want an outline to go around certain entities - eg a character and their items)
Oh yeah, I do have filtering by the lightmode tag in my custom render objects feature.
So the separate outline material is basically a hand-drawn outline? So double materials.
Or is it computing an outline?
It's for coloring pixels on the screen with a unique ID - you then have to make a separate pass to do the outline (look for dissimilar pixels)
Unity gives you a warning about over-drawing, but if your custom material defines no other passes (eg, forward lighting or shadow casting) then there isn't any additional overhead beyond what you already need for the outlining
Yeah, that's basically what beat is talking about. So give it a custom renderer with a different LightMode. Hmm.
It feels really hacky to have another material, but its the only way I could get it to work in my case because I want to support ShaderGraph (and you cant define other passes for shadergraph materials)
If you are using ShaderLab, no need for a separate material, you can just add the pass as normal
He's in URP, but custom editing shaders.
I still think he can do it with MRT's too. Either way sounds like it will work. If MRT's then only one pass needed.
yeah MRTs would be nice
Why do you guys keep talking about multiple render targets like having over 1 texture is something fancy π€
if you can't get MRTs to work, you might be able to hack it by using the alpha channel, if you are only ever rendering opaque objects, and inject a pass before rendering transparents
I think they aren't supported on all targets either?
That outline method works for me though, I also pack other metadata into the outline texture (like color of the outline, object ID, etc) for per-object outline control
Beat?
You'd be outputting the "normal" color to the color buffer, but AT THE SAME TIME be outputting your "flat" color to your temp RT. So two birds (Ha!) with one stone.
One pass.
READING textures is easy in shaders, right? You can have 20 of em.
But outputting results gets more complicated outside of what is "stock".
Damn. They don't write about that in the manual.
I don't worry too much about a separate outline render pass though, the material is literally just writing the color property to the output with no other calculation beyond visibility so it's pretty fast
At least it should be possible, even if not future proof.
https://forum.unity.com/threads/urp-shadergraph-with-multiple-rendertargets.878299/
But it's up to you. @teal breach has a method that works "stock".
See what they do in the "standard" pipleline, it will be similar for URP (prolly the same syntax).
Can't hurt to try it. Just output "white" to start and test it.
If you still want to experiment with MRT's, you end up setting an RT array either on the camera or using the Graphics class.
https://docs.unity3d.com/ScriptReference/Graphics.SetRenderTarget.html
see Camera. too.
(I use world pos + forward to hash so rotations also influence the color)
Pretty sure in URP you're supposed to use ConfigureTarget in custom pass's Configure.
But yeah, maybe later.
Donezo
Anyone with a good, kind soul here?
You spelled Transferwise incorrectly
Benjamin! Are you the chosen one? I saw you typing!
@sage moss I am sure your shader skills are unparalleled.
Use them for the good of humanity
https://github.com/Siccity/GLTFUtility/issues/75
whats up marks?
How can i get the camera view direction?
Not the direction of the camera position to the vertex, but the actual direction that the camera is pointin
i tried it like this float3 viewViewDir = mul(UNITY_MATRIX_V, _WorldSpaceCameraPos.xyz + float3(0, 0, -1)); but idk if its correct
doesnt look like it lol
im pretty sure i can somehow get it using the view matrix, but im not sure how
Shadergraph's camera node uses this as it's generated code apparently : float3 _Camera_Direction = -1 * mul(UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz);
yesss thanks! I'll try it out!
Oh that might be in world space though
yes thats why i need
dont worry
definitely looks more correct than what i had going lol
whats up marks?
@teal breach There is an open source project with 3 custom shaders that need to be converted to URP shaders https://github.com/Siccity/GLTFUtility/issues/75
It's probably not difficult to do for shader people, but the author doesn't know.
Why does an importer even ship with custom shaders, that makes no sense at all.
I don't knooooow T_T. All I know is that it's the best gltf importer for Unity!
Here are the shaders: https://github.com/Siccity/GLTFUtility/tree/master/Materials . I am sure if you look at them, you'll be like "oh converting them to URP is so easy! I can do this with my hands tied behind my back in 2 minutes!"
I would assume the shaders are there because one uses _Roughness while unity uses Smoothness (1-roughness), (or _Glossiness?), but I doubt it would be that difficult to just apply the values correctly to the standard shader. Maybe there's some other differences there too.
Converting them to URP isn't exactly easy if you want to keep them in code form, as URP doesn't support surface shaders. You could use shadergraph though, with the PBR Master node. It's basically the same inputs, just set up the textures and other properties with the appropriate references, sample them, maybe a few multiplies with colours like in the code, then connect them up to the master.
Is it possible to create such effect in URP with shader graph?? Surface shaders dont work on URP right ? https://twitter.com/minionsart/status/976179207599546368
Making an cool Aura effect using outline, normals, and noise :) #gamedev #unitytips #tutorial Shader code in first reply!
More Tips> https://t.co/5O0VnWgd0S https://t.co/OBxUevQstP
669
2560
@frozen mason Correct, for the aura outline you'd probably want an unlit shader anyway though. In URP you wouldn't want to use a multi-pass shader, but separate the toon effect and aura into separate shaders/materials.There's already tutorials on toon shaders using shader graph.
The inverted-hull outline technique is a bit awkward to do in shadergraph because you don't have access to "Cull Front". You can however have a Two Sided shader and use the Is Front Face node to set the alpha below the alpha clip threshold for front faces to have them be clipped, personally I don't really like that method. The alternative is writing it via code. Unity actually has an example for URP that does inverted-hull outlines here : https://github.com/Unity-Technologies/UniversalRenderingExamples/blob/master/Assets/_CompletedDemos/ToonOutlinePostprocessCompleted/Shaders/ToonBasicOutline.shader, Shouldn't be too difficult to add a noise texture to that.
Once you have the separate materials, you can apply both of them to the MeshRenderer. It'll warn you about using shader passes instead but using this method works with the SRP batcher.
Whoa as always a lot of info @regal stag thanks for tips! Will check them out !
Oh, Joyce's shader isn't actually using inverted-hull outlines, it's modifying the clip space position. That's also a bit awkward in shadergraph though as the vertex position input expects object space. The inverted-hull technique might still work though.
Im lookig at some of the docs and the code for shaders is nightmare to me... I can play with graph but code is different to handle ;/ damn why its so hard π
Doesn't help that the code for URP is a bit different. The Shaderlab stuff is the same, but the hlsl code uses different function names compared to built-in.
How do I even create shader out of the code from that github u pasted?
Create an "Unlit Shader", then replace the contents
Okay looks nice. And now I need to create second outline with noise ??
Or do I need to modify this one to accommodate the noise in it ?
bgolus also had a really nice article on outlines, but its a slightly more complicated method
that is the deep end though!
To advanced for sure π at least for me π
Yea you'll want to modify and add the noise. Can't go over it much now but might tomorrow if you can't figure it out. For the hlsl part urp tends to use TEXTURE2D(_TexName); SAMPLER(sampler_TexName); outside function for declaring, then SAMPLE_TEXTURE2D(_TexName, sampler_TexName, uv); instead of tex2D, though that might still work too idk
Cool will try and play with that. Thank you so much !
For the rim bit later I think you'll also need viewDir and world normal passed from vert to frag. I think those would be calculated using float3 viewDir = vertexInput.positionWS - _WorldSpaceCameraPos; float3 worldNormal = TransformObjectToWorldNormal(normalOS);
That might help cover some of the annoying URP specific function stuff
I need some help figuring out what's wrong with my water shader. I wrote it following a Catlike Coding tutorial on water shaders (this one: https://catlikecoding.com/unity/tutorials/flow/looking-through-water/), and it seems to work fine on my machine both in the editor and in builds, but when I gave a build to my friends, the water was messed up on each of their machines.
In the picture (all post-process effects have been turned off to rule them out), the right side is what it's supposed to look like (transparent with displaced vertices for objects behind it), but it appears as the left side for other people, a solid surface.
Additionally, the surface of the water seems to "flicker" based on what the player is looking at on other people's machines, as can be seen in this gif that my friend kindly provided for me:
https://gfycat.com/exaltedthickfirecrest
The source code for the water shader can be found here:
https://raw.githubusercontent.com/JoshSauter/Epitaph/master/Assets/EpitaphWater/Water.shader
Would love for some help figuring out what's going on here, thanks!!
Is it possible, given a 100x1 input texture, to make a shader that outputs a square 'filled' up to the points in that texture?
(example input and output there)
Hi Guys ! π I hope you're doing well ! I'm working on a shader using the shader graph. I would like to know if it's possible to recreate this kind of effect (screenshot from S.Designer) ? My input doesn't have any "anti aliased" border (only black and white) and I would like to simulate a smooth transition.
Depends on what your input here is, but there is no easy or optimised way to "blur" like this else than by sampling multiple times with offsets and average the value.
@ornate blade Yes.
Sample the texture, and then use the output value in a step node. Value as threshold, and uv.y as input.
I would assume that's using signed distance functions rather than texture sampling
Well, ideally that is what you'd like to do, but he specifically said that the input is only B&W
Ah i see, ideally you'd change it so the texture already has that distance information baked in if it needs to be applied to any shape
Thanks for the feedback @amber saffron , ill give that a go π
Thank you, that's what I thought, it's not the best approach. I'm going to take the problem in a different way.
Why are the UVs inside struct AttributesMesh only float2 when they're float4 in ShaderGraph?
@deep hemlock You might be able to use a derivative function on the color value maybe combined with step. It will "shift" it slightly though, as the lower/left directions will "smear" extra grey values unless you're careful. And you'd have to put in logic to decide what the values can be, but you can detect a drastic change from the previous pixel. Tends to be "splotchy"/aliased on irregular curves.
And that works at the per-pixel level, so it will vary depending on distance and also on the monitor/resolution.
Are you a shader programmer who wants to contribute to an awesome open source project? Look no further, and convert 3 shaders to URP: https://github.com/Siccity/GLTFUtility/issues/75
Why doesn't the alpha show correctly? The bottom part of my image is a transparent shadow.
In the texture preview ? That's just because of the preview, you should look at an object in the scene that uses this material.
@cobalt bolt Don't want to sound rude but. The OP in that issue spells out the solution, no new shader needed. This is not a shader problem, c# code is required to fix the issue.
The project uses 3 custom shaders "if URP then: change shader references from standard shaders/materials to URP shaders". The author himself is not familiar with URP
@cobalt bolt Well, you haven't actually mentioned what these custom shaders do that standard URP shaders won't.
Sorry, I am not familiar with shaders at all. I have no idea. I am just a user of the asset, but I need to use it on a URP project, and I can't because of the shaders. The shaders are just a blackbox to me, they are needed for the asset to work. The shaders are here https://github.com/Siccity/GLTFUtility/tree/master/Materials . I was hoping an experienced shader programmer could take a look and convert them, if it isn't too much trouble.
You don't have to write a shader to make it work. Use URP/Lit shader, and bind the textures to the proper properties, and it's good to go
SHADERed v1.4: explore & create HLSL, GLSL (ES) and Godot shaders in your browser.
https://t.co/lIcJzzucu9
#gamedev #indiedev
SHADERed is the most powerful shader IDE. It is open-source, cross-platform & has features such as the shader debugger, compute shaders, plugin API, etc...
Hey there, new to the server, wondering if I could get some help with HDRP orthographic depth buffers. I'm using a setup similar to @regal stag's URP shadergraph for intersection (attached image), but I can't seem to read anything from the depth buffer in HDRP from an orthographic view. I'm reliant on a number of HDRP only features, but being able to do orthographic depth intersection would be insanely useful. Thanks!
@acoustic canyon Just tested the graph in HDRP, it needs to be transparent (same as in URP), but it seems to work fine? I'm using the HDRP template project, didn't really change any settings. Also targetting windows, not sure if it would be different for mac/linux, not sure how I'd test it.
@regal stag you're totally right, I just forgot to enable transparent in both the shader and material on HDRP. Thanks a ton!
Any ideas why I get artifacts?
Just making a simple Transition shader plugged into Sprite Unlit Master, seems my step node is not precise enough to filter the gradient values in my texture?
Could be that your gradient texture has some noise in it (often added to prevent visible banding) which would case the jagged edge you're seeing when the step is applied?
Sorry to intrude, but does anyone know what sub shader I have to write to get LWRP shaders to work in the Standard Render Pipeline?
Please ping/dm if you know
@regal stag I miserably fail trying to compose something π
@frozen mason π
Need some help?
I've got this pattern
And I want to make the cutoff hard, so I apply a step function
step(edge, color) and this works
but the color is cyan in the end
@regal stag If possible. Yes please π What I got is bunch of errors nothing more
this is with an edge value of 0.04
I kinda get why it's happening when I try to use a step function on a color but I'm not sure how to make it so the color is green all the way?
even for small values for 'edge'
Would be better to step on a greyscale / single value, then apply the colour after.
Yeah that's true but the issue is I don't have access to the color at that point of the process
but maybe I should reconsider my design then :/
I was trying to look at this but yeah no clue what Im doing https://gist.github.com/phi-lira/10159a824e4e522060c47e21762941bb
Can someone give me some good shader graph tutorials?
@frozen mason This should work. It's basically the same as the code Joyce (minionsart) shared, but converted to URP. Also using inverted-hull outlines but I've left in the version they used as well : https://pastebin.com/ze7XZu0q
The noise kinda changes size based on distance away though which is a bit weird, probably will want to look into a way of fixing that.
@grand jolt I've got a few here that might be useful. They are more on specific effects rather than how to use shader graph though : https://cyangamedev.wordpress.com/contents/
ok
@regal stag Whoa, didn't expect that. Thank you! And yeah definitely wouldn't be able to even come up with such thing xD You rock!
@frozen mason oh I forgot to normalize the view direction, might want to add that in. π
@acoustic canyon thanks for the suggestion, but that cant be it - i have tried with various textures, some from tutorials where others made it work. Starting to wonder if it could be a setting i missed.
I am thinking it could be a project setting issue, or a bug due to the Sprite unlit being experimental
Does anyone have a example of overlay shader for URP using Blit maybe?
@devout quarry I don't know how much controll you have over the color input, but the best way is to do how Cyan mentioned.
If you can't, as I see it the gradient is going from a single color to black. So this could be interpreted in HSV color space as a linear change in the value.
You could convert the color to HSV, step the V value, and then reconvert to RGB, keeping the hue and saturation ?
Guess ill just write a sprite unlit shader with code, also just found this note about experimental 2D renderer Note: If you have the experimental 2D Renderer enabled (menu: Graphics Settings > add the 2D Renderer Asset under Scriptable Render Pipeline Settings), some of the options related to 3D rendering in the URP Asset don't have any impact on your final app or game.
@amber saffron that seems like a nice workaround that would work!
But indeed I'm going to try a different approach first
Hi all, I'm having a slight issue with depth of field and transparency sorting. I have a semi-transparent object with a shader that pushes its position in the render queue to 2450, which stops it from blurring with depth of field. However when this transparent object sits in front of the skybox (which is on 1000 in the renderer queue), blue is rendered through the transparent object. I just want the skybox to be rendered behind the transparent object. Is this possible? Sorry, real shader noob here...
@cursive girder can you send an image of how it currently looks?
@regal stag This would be it ?
output.viewDirWS = normalize((vertexInput.positionWS - GetCameraPositionWS()));
Given that It actually gives almost the exact result at least its looking good to me π β€οΈ one thing is that camera distance but I think its not that bad but the other one after doing normalize I can see green artifacts if close to the target
@frozen mason Yeah, not sure what's causing that really. It's probably some negative values in the calcualtions somewhere. saturate usually fixes that (clamps between 0 and 1). Though if you are using HDR colours & bloom you probably don't want to clamp values above 1. Maybe return max(0, result); on the final line would fix it? Although maybe the alpha also shouldn't go above 1... Might need to separate them and do something like return float4(max(0,result.rgb),saturate(result.a));? π€·
Does anyone know how i can edit this and have a texture that is "hologrammed" ? for example: an earth texture
You'd want to swap the Albedo input on the master node out for a Sample Texture 2D rather than a solid colour property. Unless I'm misunderstanding what you want to achieve.
So i have these scan lines that move down, i want this overlayed a texture so it looks like a hologram globe
If that makes sense?
@regal stag putting a texture as the albedo isnt doing anything unfortunately
ah well, only have of it is working (sort of) and its not visable in scene
Oh, if you want the texture to glow with the hologram then you might want to sample and multiply it with the hologram result, before putting it into emission, rather than using albedo.
that er... works but the scan lines are now black and theres no edge
Shaders are hard lol
this is the full thing @regal stag
@cursive girder You didn't mention what pipeline you're using, but you can try something like camera sacking or layer masks to draw that object on top, later, after the PP effects.
That would make it more of a procedural/C# side issue, rather than a shader issue. But I'm unclear from your post for exactly what you want.
@wary horizon Maybe add them instead of multiplying then?
I understand that you want to apply the texture to the hologram effect but there is a few ways you could do that depending on the result you want. Multiplying would replace the "white" of the hologram with the colour from the texture. If that's not what you want, then Adding might be more what you expect.
@https://streamable.com/ieu8du @regal stag pretty much perfect, thank you. I just need to figure out how to wrap a texture around a sphere with no seams now π
Cyan I saw you tweeted about a retro challenge?
@wary horizon that looks killer! If it's the scan line seam that you're trying to avoid, you could try doing the scan lines procedurally based off object local/world position like so:
@acoustic canyon i think its the texture wrapping around the sphere, since its a vertical line
and thank you π
I want to make a mesh gradually visible from top to bottom. What am I looking for ? Something like reverse dissolve shader ? I'm not accustomed with the terminology so I will appreciate any directions
Vertical dissolve?
Essentially, this is it
and this is the result. you can have less / more noise and not use HDR, if its not what you're looking for
@glad warren ^
@acoustic canyon but yea, its this line which is the problem, which i believe is the seam of the texture
@random silo, yeah the opposite of it
thank you
can you pass the shader to me ?
is it somewhere available ?
i gave you a full screenshot of how to set it up
woop woop , I have just fnished writing some shaders for the legacy renderer which are fully compatible with HDRP's packed texture masks. I even have variants now which support colormapping.
now I can use the same packed textures in both HDRP and legacy 
ok so, back at my shadowcaster problem:
I mentioned how my shader, when discarding pixels in the shadowcaster, treats fragments that are being discarded like there is no geometry at all, and renders the shadows behind that geometry
and maybe it has something to do with the way i do the shadows?
geometry to fragment struct -> unityShadowCoord4 _ShadowCoord : TEXCOORD4 (only for forwardpass)
in forward pass: vertex._ShadowCoord = ComputeScreenPos(vertex.pos);
in shadowcaster pass: UnityApplyLinearShadowBias(vertex.pos);
forward fragment function: SHADOW_ATTENUATION(i)
caster fragment function: SHADOW_CASTER_FRAGMENT(i)
this is basically how i get the shadows
is anything not happening like expected that causes the behavior? π€
For refernce:
basically the fragment code
are you trying to write one shadowcaster to handle transparent and opaque things as a single material?
but by discarding inside that "if" block everything inside SHADOW_CASTER_FRAGMENT will no longer execute.
so that will prevent your foilage from casting shadows.
which is what I expect from reading that.
@digital vector
my goal is to have the entire rendered geometry (the grass generated through a geometry shader and the original geometry) receive shadows, but only have the original geometry cast one
and everyone said "just discard the pixel on the shadow caster", but as seen in these screenshots, that obviously wont work
at least not with the current way i do it
is this inside a standard shader?
because this code might also be executed inside meta and any pass which writes to depth.
its a shader pass on top of a surface shader (but it overwrites the original shadows)
the orig. geometry uses a surface shader, but the grass particles have two passes have special functions
it looks like the shadow caster fragment writes to some depth buffer, so i'd only need to figure out how to do that manually
@digital vector Been looking into this more and I can kinda understand why this is happening. As you mentioned, the shadowcaster pass is also used for a camera's depth texture. It's compared with the directional light's shadowmap in order to determine whether a shadow should be cast or not. And that's put into a screen space shadow texture before anything is even rendered. By discarding it's like that pixel isn't there so you see the shadows through it.
I'm unsure if there's a way to manually handle it, but I am aware that the mesh renderer has a Cast Shadows option - which has the ability to remove the object from the shadowmap, but keep it in the camera depth texture. That should mean it doesn't cast shadows but still receives/draws them correctly? My suggestion would be to separate the geometry grass bits into a separate shader without the rest of the ground and see if using that cast shadows option would work (with a regular shadowcaster pass).
I see what you want now.
Some have implemented their own shadow maps.
However, you're in a catch-22 situation. I think.
One suggestion if Cyan's method doesn't produce what you want, you may wish to research transparent objects receiving shadows. As that would not cast them, but would receive them and shade the object. Not exactly the same, but it would give you some ideas. You could consider actually putting your grass in a transparent pass so the shadowmap casting isn't done for it, even if it returns opaque alpha.
Just spitballing.
There are forum posts and sample shaders on the topic.
Basic shader help question:
To start, I tried doing this with the default standard material and it works fine. It only stops working when I make my own shader. What I am doing is using "SetTexture" in a script and updating the material in real time.
I made a new shader, which for now is just an exposed Texture2D > Sample2D > Master. The name of the exposed texture is "BaseTexture". In the code, I am running gameObject.GetComponent<Renderer>().material.SetTexture("BaseTexture", _tex); When I do this, however, the texture in the game is not updating. Anyone know what I'm doing wrong?
quick question:
My unity scene view no longer shows the shaders as they look in game view? not sure if I ticked a setting or not but I can't find anything different.
What it looks like now
what it should look like
(note the shader in scene view is also no longer animated)
@spark wind Maybe you turned off the depth pass, or the water surface is included in the depth now?
Why would it appear different in game view then scene view if depth was interpreted differently?
example, then next to eachother in both views
AH ********* @sage moss thanks for the answer, but it turns out I had view in ISO and tilted it at some point and didn't notice.
Iso seems to disable depth pass
Isometric doesn't disable the depth but it works differently so produces a different result. Mainly, it's already linear so the raw to linear01 conversion isn't needed.
@hasty vessel Are you sure it shouldn't be "_BaseTexture" instead?
I'm not sure, does the C# scripting require _ be added to the property name you generate?
You can change the reference, thats the one you need to use in c#
I think it doesn't need to start with _ but that tends to be what most shaders do
i'll see if i can find something about that. thanks for the help guys!
on another note, what editor do you guys use to program shaders? im using visual studio, and while it has syntax highlighting, it does not have auto complete or error highlighting
Skinned mesh renderers don't get instanced?
Is there a way to make them support instancing?
@digital vector I just use Visual Studio as well, there's a number of extensions you can get to help with syntax highlighting and auto complete, etc
Hello there fellow devs. I've got a problem with Shader Graph (URP) and I couldn't find any help on the web. I've created a shader for fading materials into transparency. It's only used for map edge tiles, as you can see in below attached screenshot. It works just as intended in Shader Graph preview, the scene view AND in the game view as well (the screenshot itself is rendered from the game view). Although when I hit play and enter play mode, meshes that are using this shader are not rendered at all. What might be the trouble?
The graph is pretty complex for screenshoting, as I've put all the variations in, so if needed, I can provide the shader graph file right quick
The selected part is what creates the fading effect, it's just being repeated with different split values to variate the fading orientation
So what's up with URP outputting the wrong color despite me simply outputting it in the shader?
float4 Fragment(Varyings input) : SV_Target
{
return _OutlineColor;
}```
Linear colorspace, tonemapping and color correction turned off.
@devout quarry yep that's the asset demo scene, my scene was a bit of a mess at the time so I felt it best to show my issue using the demo π
I have what I imagine is a pretty simple problem
My model has a diffuse with an alpha channel
We are using a custom shader that takes all of the mask inputs as individual textures
When I try change my surface type to transparent, the whole model goes invisible
Any idea why?
Your master node alpha (Vector1) input is coming out of a Vector4, which means it takes the first component only, aka red, not actually the alpha channel. Is that intended? If not, use the A output from the sample texture instead
Ah, I had actually changed that a minute ago - it does it even with the alpha output from the sample
This does the same thing
@regal stag
Hmm okay, is the AlphaClipThreshold culling it maybe?
No - changing that to any value has no effect
If you use a Preview node on the sample texture A output what does it look like?
What does the preview of the A channel look like?
Hm okay. Not really sure why it would be going invisible then. Might be something specific to HDRP.
If parts of the model doesn't need to be transparent then using separate materials would be better yeah. Still not sure why it would go invisible though.
@spiral kite check your UV's
[ShaderGraph] What is the reason for Position node set to object space to produce different look in edit mode than in play mode? Why is there a difference at all?
@toxic fable It's possible that there is some batching going on, (like combining multiple meshes into a single one). Therefore the object space positions are no longer relative to the game object's origin, but a combined origin?
Oh yeah, that might be it. The batching is happening, intentionally in fact. I completely overlooked that
You could potentially do the fading using UVs, or even just vertex colors instead of relying on the position
Actually I thought I need to rely on the position because I needed the fade to always go from the center of the mesh, regardless of its UVs, shape or anything. And this method worked, just not in the play mode. I need to revert Lerp min max values to get it working properly in play mode (but then it's not working properly in edit mode). But realizing the batching is behind this is a huge step forward. Thank you for that sir
Switched off the batching for the fade tiles (really just a couple of them, so the draw call number increase is minimal, barely noticeable) and it works perfectly. Thank you again @regal stag
@toxic fable No problem. Also something of note, if the SRP Batcher is enabled those draw calls should also be batched using that (or I guess technically the "setup" for those draw calls is the part that's batched) - and as far as I'm aware that doesn't affect the object space positions.
I assume the other batching is either some custom thing, or due to marking objects as static - I tend to do a lot of procedural stuff so hardly use it.
It would be. You can think of world space uvs as "projecting" the texture through the axis that isn't being used in the uvs. If you are using the X and Z position for example, the texture would stretch through the Y axis since it's not being taken into account.
so how do i fix
It's better for flat meshes. Triplanar mapping is a way to apply the same concept to 3D, but if you just want to apply a texture to a 3D object you usually want to use the UVs from the model. (leaving the UV input blank or using the UV node).
You would want to control the Tiling of the UVs using the object's scale (which could be obtained via the Object node, or perhaps passed in as a property and controlled from script instead). Probably only need one axis of that scale, so you'd want to Split it. I'm not sure which axis corresponds to the diameter though.
So, this is my first time working with shaders and I'm using a pbr shader graph...
I have a circular alpha connected to a slider.
It works well on the front but I need 2 things that I can't figure out.
I want to feather the alpha edges and I also want only the front and back faces of the wall object to use the shader alpha.
Currently, my sides are fully transparent on the sides, top, and bottom (when I tick two-sided, which I want).
Anyone know shaders that can help? π
I got a tip from someone to look up triplanar techniques!
However, most tutorials i'm finding work with multiplying for emissions. Anyone know how to do triplanar shader graphs for alpha?
I just need 1 side to have the alpha. the other 2 would be solid.
But i wanted the alpha in both directions on the 1 axis
@rich ice something like this should work. Triplanar involves mapping textures around all 3 axes, you're really only looking for mapping on a single axis if I'm correct. This is just using the default soft particle texture with a step to control the size of the hole
@acoustic canyon
I appreciate the response!
Unfortunately, it seems your set up doesn't do anything except remove the hole, keep the sides invisible, and make the object disappear when clip is below 1?
I'm pretty sure i have the same setup?
though, my circle in step seems bigger..
Here's what I had for the initial picture
So, actually, the sides seem to disappear due to two sided being checked... but i want that effect to see the inside of the object.. is there a way around this?
The normals seem flipped
Ah, yes. They are on the back to.
Hello,
I have a problem. I am making a game with URP Forward render. I have a Spriteshape object with a custom Sprite-Lit-Default shader.
The Shader is thisone.
i can't change the SpriteShape Renderer color via inspector. I would have to create a different material for every color. How can i fix this?
(I can't use the 2D renderer because if i do my device do not support the app)
@obsidian shore I'm not really familiar with the SpriteShape, but if it's like the regular sprite it might be using vertex colours. There's a Vertex Color node to get that input.
edit : Hmm actually, this seems to suggest it uses a "_RendererColor" property : https://forum.unity.com/threads/tell-us-about-your-experience-with-sprite-shape.686305/#post-5637007
I have some "torches" in the game, and I would like to apply "Bloom" on it.
What's the cleanest way to do so? Separate camera? I don't want it on other sprites. Or a material? Or is there a better way?
2D Game.
@regal stag yes that one, but it does not work, it only work if I use the URP with 2D renderer
but i can't do so because if i do i get an "hardware not supported for this application" on my device
It was a problem some months ago but then they fixed it on 2D renderer, but not on Forward renderer
@obsidian shore Have you tried changing your color property to _RendererColor instead of _Color? Maybe also with and without it being exposed, not sure if that would change anything.
The fix in that post seems to just suggest adding that to the shader includes that I assume the 2D renderer's sprite master nodes end up using. I imagine the colour is being passed in still on the C# side, it just needs to use the right property reference.
i'll try it
@regal stag it works! thank you
but i get an error in shader graph
Hmmm okay, that's annoying. If it's already defined somewhere you might be able to output it from a Custom Function node rather than using the color property then
i am new to shadergrpah can you explain?
Hmm it doesn't appear to be working
I'm unsure if there's a way to stop that error then. It doesn't seem to be accessible in shadergraph, but defining it causes redefinition. I think it only happens with the sprite master nodes though, would the Unlit one still work with the SpriteShape?
i try
i have to create a new shadergraph with sprite unlit and copy all the nodes from the sprite lit?
Should be able to create an Unlit master node in the graph, you can then right-click and set it as the active one
i get the same error "redefinition of _RendererColor"
how can i use the custon function node?
What about after closing and reopening the graph?
nope still error
Also which URP version are you on?
8.2.0
I have some "torches" in the game, and I would like to apply "Bloom" on it.
What's the cleanest way to do so? Separate camera? I don't want it on other sprites. Or a material? Or is there a better way?
2D Game.
@rugged verge nvm just found out ShaderGraph's intensity is quite helpful for this
@obsidian shore Okay, so I've installed the SpriteShape to check what's going on. It looks like the "Sprite Unlit Master" actually works with the color as is. It doesn't need the property. The "Sprite Lit Master" does not, but if you aren't in the 2D renderer I don't think you are using that lighting system anyway.
well i am using 2D lights in my scene
I don't think the 2D lights work without the 2D renderer though? I can't even create them without switching
oh right. Well it's becasue i had 2D renderer but then i get hardware error on my device, so i deleted the 2D renderer and added a forward renderer
and the 2D lights created with 2D renderer are still in the scene
Right, those lights would have stopped working then
but the lights works, i dont' see the scene black
I think they basically become unlit in the forward renderer
With Unlit it does not works for me
i have empty Main Preview in shadergraph and in the scene my spriteshape is magenta
oh nvm i forgot to click on save asset......
You'll need to remove the _RendererColor too if you haven't already
@regal stag hey, sorry if i bother you but i have another problem. I don't know if it related to the sahders or something else
nvm i think i understood how to fix it, sorry again
No worries
@regal stag nvm i could't fix it. I have a moving line shader. In my tablet after some time ti starts to look like this
Ah okay, might be some precision issues with the _Time input getting too large. Might be able to use a Vector1 property instead, (either passed into the shader using material.SetFloat, or probably easier setting it globally using Shader.SetGlobalFloat). Control that value from script but rather than keeping it growing, have it repeat instead.
The downside to repeating is there will be a jump where the UVs suddenly change, but if the pattern repeats perfectly too it shouldn't be noticeable.
okay i'll try, thanks
one more thing, i can't see the preview in my shadergraph window
is that bad?
Mmm not sure. If it works in-game that's all that really matters. I hardly ever use the main preview in shadergraph.
It might be something like the default property values in the graph aren't the same as what it uses in-game. Not sure which mesh the main preview has been set to either, but if it's a quad it might just need rotating.
Unless you are referring to the main preview isn't visible in the graph at all? There's usually a button at the top to show/hide it
Might be something specific to the Sprite master node too
I'd check the Tiling property default values
If it's set to (0,0) it should probably be changed to (1,1) instead
it's 1,1
ye as you said that's the important thing
is there a way to make shaders for hdrp not using shader graphs (i.e. code) but still using the lit base (like, surface shaders)? they get a bit unsolvably tangled up and unreadable at times like here
ShaderGraph seems so good, but it's really hard to convert my existing 2D project with lots of assets used to be compatible with it.
@quick holly I don't think there's anything like surface shaders yet, but you can write code and use it in a graph with the Custom Function node. https://docs.unity3d.com/Packages/com.unity.shadergraph@8.2/manual/Custom-Function-Node.html
That might help at least with some parts that get super tangled or for long maths calculations that take up several nodes but would really only be a few lines in code.
Technically you could probably also handle everything in the custom function and just pass each output out and connect it to the master node.
i have a heat distort shader on that purple orb, it distorts the air around itself, but why it is not distorting the "moon" thing i have right next to it? O.o
any way i can stop shader graph from freezing the editor for 15 seconds every time i change something in the shader? it really isn't helping when trying to figure out what nodes i should delete
Does this happen to anyone else? I just installed URP and sometimes this started happening
Fixed it by adding/removing a random component.
Is there a way to soften the shadow? I found out about "Shadow Caster 2D" that Unity just added, seems to work really nice.
oh it's apparently not possible https://answers.unity.com/questions/1757684/is-it-possible-to-use-soft-shadows-in-2d-using-urp.html
It's a great start though, since it means I might not need to rely on assets for the lighting
Another thing I wanted was how to "refract" the shadows and light, when it hits a wall. Just like how it does in the real world.
and a feature to make the "shadow shape" the physical shape of the sprite
Shader Graph + URP is so good, wish some older asset authors could make their assets compatible with URP (some asset authors seemed to have trouble with it due to some constraints, e.g. custom rendering injection) and the shadow to have soft shadows. Hope to see Shader Graph + URP come more popular and ingrained into assets and the future.
To summarise, these two ideas would be nice for the Unity URP team to implement.
1. For 2D Shadows: soft shadows vs distance (lots of demand for soft shadows, just search on Google to see this), option to choose what defines the shadow shape (e.g. collider, or the Physics Outline/Shape of a sprite) - this is important for tilemaps instead of toil of manually adjusting the shadow shape in tilemaps.
2. Work with existing popular Unity asset authors to help migrate their asset to become compatible with URP. A lot of popular assets like SC Post Processing is not able to become compatible with Unity URP 2D due to not being able to inject custom rendering.
Keep up the great work Unity, really love the updates and hope to see more.
@quick holly While there's no surface shaders for URP, shader graph is a CODE GENERATOR just like surface shaders are.
Sooo....... start with a simple lit graph, put a couple token nodes in to do what you want where convenient, and then skip all the spaghetti and just right click on the master node and "view code" (whatever they call it). Edit from there and tweak it. But once you edit it, you can't go back to SG. It's a one-way operation.
How can I determine which parts of the texture are responsoble for given parts on the mesh? I have a blade with texture where I would like to add some HDR color for bloom to the blade but cant say which part on texture is the blade
UV mapping (the XY texture coordinate mapping for each triangle vertex) is done in the modeling software. Unity's shader gets passed the UV's from the model. Unless you're procedurally generating the mesh, then you calc the UVs.
@wary horizon One object doesn't know about the others. The way that is done is either
- draw it later and get a hold of the back-buffer somehow (grabpass, or URP's screen grab thing) and blend
- Do a post-processing effect over top of the finished screen.
I think unity has a tutorial for distortion, they used option #1 for some force field thing. IIRC
Never been to URP but is Speculative surface achievable in URP by default?
I know a shader graph can, but I'm wondering if there's anything by default. Just a curiosity
Does the HDRP layered lit texture work with polybrush vertex painting? It's telling me it's an unsupported material
@coarse path Yes it does.
It says none of the materials on the object support vertex colors.
I've tried changing vertex color mode into multiplicative and additive
Ah okay, might be some precision issues with the _Time input getting too large. Might be able to use a Vector1 property instead, (either passed into the shader using material.SetFloat, or probably easier setting it globally using Shader.SetGlobalFloat). Control that value from script but rather than keeping it growing, have it repeat instead.
@regal stag hey sorry to bother you again but despite my efforts i am not able to make it work properly. Could you show me how to do it? (Just the few lines of code for the repeating cycle) I would like not to use code on Update function. Can i do it directly in the shadergrpah?
Shaders can't really update properties, so it would have to be in C# using Update. Would probably be something like
float speed = 1;
float t = 0;
int property = Shader.PropertyToID("_CustomTime"); // might need to be set in Start idk
void Update(){
t += Time.deltaTime * speed;
if (t < 0) t++;
if (t > 1) t--;
Shader.SetGlobalFloat(property, t);
}```
If you want different speeds for different shaders, could also provide it as a Vector4 instead, with each component increasing at a different rate. Unity's _Time variable actually already does this too, but they still don't repeat so will probably reach a point where precision issues become a problem.
You might be able to produce repeating using the Fraction node instead. (Removes the integer part of a number. Basically a repeating 0-1 value. So if _Time was a value of 5.5 it would return 0.5. As time increases to 6.0 it would return 0). But I'm not sure if that would fix the precision issues though.
It's possible that the fraction node will still help as the precision of a float in C#/cpu vs the shader/gpu might be different for mobile/tablet?
okay thanks a lot again
@regal stag the Fraction node solution seems to fix the issue
hi how can i create a terrain with shader ? thanks a lot
i've looked on the internet but i still don't understand that message..
i just used a plane it works now
How can I achieve this kind of effect where Items has some glowing colour and also that blink of white glare effect which comes from side to side (not that constant slow one the one which blinks fast)
This is what I got so far. Dont know how the blink effect can be achieved. And I feel the colors are to much vibrant??
This is my graph. Do I need the Normal and occlusion? Can I do something fancy with those?? How I could improve the look of those to be more similar like on the videos with the characters
@wary horizon does your shader use a GrabPass?
if so , everything else must render before your orb.
Can I get a uniform half with GetFloat? I appear to be having an issue with it.
hello guys, I tried to make material for my character's hair, but I had this problem with the normal map in my shader. it is as if the material did not have a good resolution when rendering the normal map. Has anyone had this problem?
this is the same hair in blender.
just for the record, I tried to use larger textures and it didn't work.
I was wondering what node do you need to add to a shader to remove a color from the sprite?
@spice tinsel Like keying for a green screen?
I don't know of a node that does that, but I'm sure you can combine some other nodes to get the same effect
You need to create a "mask" from the color you want of the sprite.
This doesn't need a lot of nodes : subtract, absolute, step.
Hey, I gave you some hints, please try to think by yourself how you could isolate the color π
ok
I'll be here to help if you can't figure it out
If it's "easier", you could also make it in two nodes : distance and step
ok
I tried this but it didnt work
Cause I think that for Diastance A is your Sprite and B is the color you want to remove
Yep, you're on the good path
You can increase the tolerence using the "in" input of step.
This is maybe cause by texture compression
I tried that too but the sprite is now like distance
idk what you used a value, but remember that the distance is a small fraction, as color value goes from 0 to 1
I think I just solved the problem with a diffrent method
I'll send a pic
(the sprite there, I just used it for a test)
The main preview is Subtract without the black
thanks still
for the help
Oh, I forgot about this node π
But the calculation there is probably pretty similar
Also another question how do I remove or shrink the main preview tab?
It can be resized on the bottom right corner
But it should have been the top left corner, or just all corners.
Remy pls fix
The minus on the bottom left corner I had seen it before and tried to shrink it but finally now it worked
This is already in the work for future updates iirc
Oh I think I got why the distance method didn't work ... do you have alpha in you sprite ? You were doing the calculations on RGB+A, while the color mask node only works on RGB
oh yeah it alpha
Is it possibly to write a Tessellated Terrain shader in HDRP?
Technically, yes. But hard
any idea how i activate "back then front face rendering" on URP Standard Lit Shaders? the render order is totally messed up
at least that is what i think to be the problem
There is no option for that, but you could do it using custom render features.
Back then front rendering is basically two passes.
that seems pretty dumb to be honest. :/ i know that hdrp contains such a thing and i wonder how it has worked before that. the problem is not unique and always occures when working with transparent objects
Cheap work around is making the model two-sided.
Transparent sorting has always been something tricky, and the double side option doesn't exist in built-in unity, so it was a non issue
Making the model two sided will not help when using transparency.
that doesn't change which faces are drawn infront of each other @meager pelican
no problem
In HDRP when you enable this option, it automatically handles it in two passes
In URP, you have to do it by yourself.
huh
There is the concept of order-independent-transparency, but it's going to be even harder to implement than your other options, and not practical for SG at all. It's an accumulation buffer.
do you know a tutorial how to achieve that Remy? i never had anything to do with the custom render features. and i am an idiot
Here is a small tutorial about the feature : https://learn.unity.com/tutorial/custom-render-passes-with-urp
But it seems that it relies on the settings of an override material ... and I don't remember if its possible to do front face culling right now.
Can you change the model? What about opaque for it all except the glass?
@twilit elbow Transparent should still clip to the depth buffer, but it won't update it, but if it's just the glass........
That model looks like it's mixed use...opaque parts and glass parts in one model, which is what I think is creating your problem, right?
@meager pelican that is what i try right now but it will take some time since today is definitly a bad day for me
so yeah making the railing there own objects and splitting it from the glass worked so far. it's kind of a shame to have more unneccessary objects in the scene but at least the railing no longer looks glitchy ^.^
hey friends, i have finished the roguelike tutorial and i am personalising. I want to add rain but no matter what I do it always initiates behind the Board like this:
does anyone know how I might fix this?
How are you doing it now?
i havent changed anything
i tried sorting layers for the tile pieces and game objects but it made no difference
each level is generated by script and prefabs
the rain is a permanent game object i the scene
I'm still not 100% on how you did it, but it sounds like you're experiencing clipping against the depth buffer. What pipeline are you in? Is there some quad on the camera for the rain to "fall" on?
URP and Im guessing no quad because it does not sound familiar
Well, you could try VFX graph if your target can support it.
With Shader Graph, you could put a transparent quad up in front of the camera and scroll a rain texture vertically.
Or use a native particle system.
Thoughts.
@meager pelican thanks for this feedback! i hope it'll help π
@twilit elbow you can assign different materials to the same object without splitting the mesh in Blender.
@grand jolt true haven't thought of that. but i still have the extra drawcall for the 2nd material now. but hey my game will never be published anyways so who cares about performance xD
bit of a specialist thing
but is there any way to deduce the distance between a vertex we're shading and an object vertically beneath it?
I'm doing water shading and currently I'm using the scene depth multiplied by the camera's far-plane to get a depth effect on the water
but obviosly when the player moves, the depth of the water "changes" based on the view point etc
what i need is the distance between the surface of the water we're shading and the sea-bed directly underneath it
If you can compute the world-space depth of both points, then subtract them, you get a consistent value regardless of view location. So world-space.
yeah but how do i get the world-space depth of the seabed?
that's the bit i'm stuck on
Are you using shader graph, or built-in?
cos it's not where the camera might be pointing
You can bake a heightmap or an SDF.
shadergraph, URP
You could potentially use a separate camera, rendering from above the water to a render texture
SG can give you worldspace of a vertex, and then interpolate it for the water surface, for example. As far as computing it yourself, you can just project a vector from the camera to the point, and add that to the camera WS value.
For a two camera approach, add a second orthographic camera directly above your water facing down, andhave it render to a render texture with the depth texture, then use that depth texture in your water shader to do what you want
Actually, true, you could render depth of the seabed from top down view and then reproject it to worldspace in the shader.
SG can give you worldspace of a vertex, and then interpolate it for the water surface, for example. As far as computing it yourself, you can just project a vector from the camera to the point, and add that to the camera WS value.
@meager pelican I understood about half of that
You'd also want to set it's render layers to ignore the character and anything else that's not water or seabed, but it should be a relatively straightforward setup
i like the idea of what carpe said cos then it will account for waves, other objects etc
There's a formula for reconstructing the WS pos of a depth-valued pixel. I don't have it off the top of my head, but google is your friend. No additional rendering required (and faster).
but i'm still lost...I need a vector from the worldspace of the surface of the water
to the point with the same x, z coords but the y coord of the seabed
That's in your water shader. But it would grab the scene depth texture to get the bottom point (which you want to calc the ws from too). For the water, you already have a WS point for all the pixels.
Just a sec, I'll google it for you.
i have the ws for all the points of the water;
what i'm not "getting" is how I pass in the depth of teh terrain at that instance
like, we're shading water at 102, 0.3, 203
Although @meager pelican if you have a camera angle where the bottom of the seabed isn't visible, there's no screenspace method of getting the position of the bottom of the seabed, as it's not rendered, correct? (Shallow camera angle in deep water)
how do I get the y position of the seabed underneath it, so 102, -34, 203?
Agree....
But in case you want to try....
https://forum.unity.com/threads/correct-way-to-recover-world-space-position-from-depth-value.426678/
I think that would technically only happen if the view was partly submerged, or you were "out to sea".
and using the out to lerp between a shallow and a deep water color
There's a bunch of water shaders too. Even a good demo in the boat attack project.
that's what that was "lifted" from π
but it seems to shade some of the water a different colours based on view direction
so you'll be walking around a nice turquiose beach then look up and it suddenly gets darker
@meager pelican The case I'm thinking of is something like this:
The blue point at the water's surface is visible, but the point directly beneath it on the bottom of the seabed isn't visible, so there's no way to find it's depth from just the camera
@marsh turret I'm only reading parts of the convo but most ways of getting depth are camera dependent
so if you do coloration based on that, it might shift when changing your view
most shaders subtract alpha component of raw screen position from the scene depth in eye space right?
but then you're working in eye space, so camera relative. If you want more 'robust' way of getting depth, you'll need to do something else
convert scene depth to world position then check the difference between that world position and the world position of the water pixel
ah I see @meager pelican already mentioned that
oke yeah I'm exactly saying what he said oops
@marsh turret you can take a look here at the 'scene depth to world position'
but it's an old document and might be full of errors so don't look at it too much ahha (it was basically just me dumping my thoughts in a document while writing a shader)
You can steal world space depth reconstruction from basically any SSAO URP project on Github.
thanks everyone
The trick is that you want the pixel under the water, so it depends on your needs. If you're at a rather oblique angle, you get mostly reflection anyway. And the more "downward" you look, the closer the pixel is to the proper pixel from a y-axis perspective. That's why the top-down camera depth works if you can afford the 2nd render pass, because you can use the worldspace xz postion and get the y depth at that water pixel, not counting refraction. Or you just fake it with calcing WS from the depth buffer and see if it's "close enough".
One trick is to render to a lower resolution (like 1/2 each way so 1/4 the pixels) texture for the seafloor depth. Fewer pixels = faster.
Yep, you might be able to get the render resolution even lower than that and just let bilinear filtering do the job. You could potentially use a single pass simple blur on the camera, although that could start to add more overhead instead, you'd have to try it and see
@meager pelican can you help me with picking a graphics format for a fullscreen temporary for custom effects?
Am I supposed to use GraphicsFormatUtility.GetGraphicsFormat(RenderTextureFormat.ARGB32, isRgb: true) for a format with alpha channel?
Usually I use the camera texture descriptor URP provides me but I need an alpha channel now.
@amber saffron thank you for your response. I have managed to hack-port the tessellation shader inside a custom terrain shader, and the whole sub-division is fine.
the only problem I'm getting is due to shading artifacts.
what could cause those?
Is it projected shadow issue ? If yes, have you also applied your tesselation/displacement code to the shadow caster pass ?
@grand jolt Mobile or desktop? How much do you care about precision?
With mobile, you want to be aware of Half4 type stuffis.
@meager pelican desktop. I guess float is the highest precision, I'll be fine with that.
Since halfs are macrod to floats anyway.
Yeah, on desktops it is.
Did you see this list of formats? The next question is "what's generally fastest" or maybe "smallest" if you care about memory.
I peeked at URP post processing and it seems R8G8B8A8_SRGB is the default for linear color space.
They try to use B10G11R11_UFloatPack32 if it's supported but this looks like aliens made it.
I just don't want the game to run only on my PC π
I usually pass that type of enum to whatever render texture api call. I think it often ends up being the 8-bit format in the end, but intermediate work textures you might want floats and 32 bit.
So basically you work in high precision and then end up dumping it back down to 8 bits for outputting the results. If I understand correctly.
Again, precision. 32 bits
if you want full precision floats.
So 8 bits per channel, got it.
Uh...
Oh, you mean 32 per channel.
π
Alright, dumb q: why do all formats have r, g and b in random order.
Does it impact the rgb value order in shaders?
It's not a random order. Some monitors expect pixel values in different orders.
Mine for example in BGRA
I"m just saying you might not want to limit to 8 bits...loosing precision
Some are 16 bits for example.
IIRC Unity has some defaults and figures that out for you somehow.
You want a script created RGBA temporary rendter texture, or just texture?
Are you computing the noise in a shader?
I pass a RenderTextureDescriptor to CommandBuffer.GetTemporary.
Is it writable by shaders?
This is what I do.
In my custom scriptable render pass I allocate a temporary, blit my noise shader into it and then all world shaders sample it using screen positions to blend it on top of them.