#archived-shaders
1 messages Β· Page 200 of 1
wym use comments from the struct?
Comment out stuff in the struct. Sorry. Don't delete lines, use comments.
https://pastebin.com/HDnxLwY7 this is all I got right now
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
gotcha
Lines 51, and 53-56 comment out.
51 is the worldNormal one right?
I got an error when there was nothing defining a normal
Sorry, 50 not 51
okay
it gave me an error on line 99 for the v.color but I think that's just because of commenting out the color variable
I'll just take out the * v.color
OK, keep color (Sprites use vertex colors I guess)
got it
just gotta wait for unity to recompile this
it's just froze up right now
not entirely sure if I want to kill the process or not
huh
it's just taking an eternity to compile
I appreciate your help, but I'm gonna have to call it here, gonna go eat dinner and take care of some other things but I cannot thank you enough for your time and effort in helping me
We're actually getting closer. Fun to help. But I have to cut grass. lol. So we'll both call it.
It's hard to do remotely.
Maybe I can run across you tomorrow or something. Or just mess with it. I think you're close.
I can feel it haha π
That example posted from the youtube video was just a standard surface shader for sprites.
Anyway mess with it, reboot unity.
We made progress anyway, but now....
laterz
What renderpipline do you use?
URP
im seeing that i need to use HLSL instead of CGPROGRAM
which i assume changes a bunch of other stuff..
:D
this seem to be a shader for the "old" build in pipline
yeah, the tutorial i followed seems to be for that haha
so the shader does not throw a error but just not work for your pipline
Got it, thank you. will start over with URP in mind
should be doable π
Is there anyway to read the position in world space instead of object space in shadergraph?
or is there a way to convert world space to object space I'm missing?
the tranform node should be able to do that.
https://docs.unity3d.com/Packages/com.unity.shadergraph@7.1/manual/Transform-Node.html
That's perfect thanks
On the position node I guess you have the option with a dropdown menu, to change between World and Object position
yo does anyone know how to make a low poly shader for unity 2020.3?
all the tutorials im seeing are outdated and im only beginning in shader graph
Hi, this one is old but the nodes it uses are common ones which haven't been changed.
https://www.youtube.com/watch?v=e3oYQL0oDEs
This is how to make a low poly looking shader for Unity3D. The following shader should work with most versions of the Lightweight render pipeline / Universal render pipeline. Sorry if voice is a bit monotone, I made this after just waking up.
Finished Shader: https://drive.google.com/open?id=1-U2xfpvrG_lXh98Whg87qHquD0PEz_tc
Extra video for ad...
Shader Graph is kind new btw.
yea i saw that and followed it, i just realized im not properly setting up the shader tho so i think im going to try that first lol
had an issue with the texture appearing as pink, likely to be caused by that
Did you created the project with the Universal Render Pipeline Template?
Or did you installed the Universal RP package on an existing project?
I didn't use the template I just have a normal project and installed the package
So the latter
You might need to assign a Universal Render Pipeline Render Asset on the Graphics Settings to really use URP
I remember having to create a shader config or something and put that in an inspector
ohh yes thats what it was i think
ill try
Yes, it is nothing too complex but to be honest I would like that it could be done automatically when installing the package. Huaha
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@11.0/manual/InstallURPIntoAProject.html
cant believe ive been scratching my head for like an hour for that to be the solution lol
well ill definitely remember that now thanks
Is this the right section for fog/lighting?
any suggestions on masking the outter edges of my tiles, preferably fog?
any good tutorials for shader coding in urp (or just in general)
im quite good at making shaders in shader graph but i'd like to get started with real code based shaders because im looking into some more complex effects
curved world if possible, but fog will also work
Hello π€ Does someone have an idea how to attempt something like anti-aliasing for shadows within a toon shader (or outside the shader, but I don't think there is a way outside the sader):
I'm kinda new to shader programming so i don't know where to start... Maybe with a softstep? π
I think anti-aliasing is the wrong word. I just want so soften the edges a tiny bit
isnt there already an option for soft shadow inside light inspector?
yeah, but the thing is a draw that shadow inside the toon shader, so the soft shadow doesn't do anything. Or at least thats what I think, since soft shadows are on in the picture above and they don't look so smooth to me. It's not the end of the world but it would be nice to have smoother shadows π
but afaik, unity's builtin toon shader already done that
it can use toon texture lookup (for real time directional light) or cubemap (works without light iirc)
Hi everyone, I would like to do a water puddle shader but I don't know how to do it, can anyone help me to create one ?
hi there, I try to optimize my VFX and when I run into the Frame Debugger I found that (cf picture).
This shader is made with shader graph, on 2019.4 (HDRP 7.x).
I don't find how to enable batching, could you help me?
does anyone one know how to layer 3 different rectangles on top of each other without any transparency?
theyre blending together which i want just on top of each othere
@delicate badger It might be for instancing instead.
@vestal aspen Sure, use an opaque queue, not transparent. But you're probably going to get z-fighting issues if they're "on top of each other".
Ok but I don't find how to do that with a shader made with the shadergraph
If I put a pretty large structured buffer as a large texture instead of a large structured buffer, would that be faster to access for a compute shader?(It would have to access this many, many times for every thread)
Startin to grasp at straws for performance optimizations for my compute shader raytracer, got textures working, but it renders scenes like the sponza scene at 0.2 fps with 2 bounces... and idk what to try next to optimize it
@delicate badger Try enabling instancing on the materials that the shader is assigned to.
I know in code-based shaders I needed to use tex2Dlod to sample a texture in the vertex part of the shader.. I assume thats why it wont let me make this green connection in shadergraph? anyway around it, in shadergraph?
dunno why I couldn't find that node original but it DOES exist in shader graph too
Has anyone here worked on a water shader with foams? I'm trying to get water intersections working using a guide by Gabriel Aguiar Prod:https://youtu.be/jBmBb-je4Lg
But at the second part where he starts working on the foams, in my project, the foam doesn't appear WITH the water
Unity Shader Graph - Cartoon Stylized Water with Foam Shader Tutorial
In this Shader Graph tutorial we are going to see how to create a cool stylized water with foam! Foam is the hardest part but it gives a really nice touch to the water.
DOWNLOAD HERE: https://www.patre...
what it should look like every 10 tiles
So i had this working with plain quads.
I set the UVs through script and everything was fine. I tried to make this work with a shader so I can have edge tiles that would just be a mask.
I look at the offset properties of each mat and it looks as expected, between 0-1 incrementing by 0.1. The tiling is set to 0.1.
theres no rotations on the interior tiles.
when i set up a few tiles and test (manually) if the offset works as intended it does. So there must be somethign wrong with my shader graph
@delicate badger Sorry, I think I gave you a bad answer, as there's probably no material.
Did you do this type of thing?
https://learn.unity.com/tutorial/integrate-shader-graph-into-visual-effect-graph#5f570b06edbc2a1ca2b48788
I guess that's still experimental, and I'd try the unity forums if you don't get an answer here.
With Unityβs Visual Effect Graph, you can integrate Shaders from Shader Graph into your effects. Although currently an experimental feature, it provides new opportunities for enhancing the look and feel of your effects without doing any Shader coding. In this tutorial, you will learn how to create Shaders in Shader Graph that are compatible with...
I was just trying to help, but I didn't realize the VFX side wanted the shader, not the material.
@wheat quail I'm not exactly sure what you're passing and calcing, but I can tell you that each tile won't know about the others. So it would have to know its own cell location in the 10x10 "grid" that you're using, and then start there instead of at its own UV of 0,0 to 1,1. So each tile would have to know its offset from somewhere. Maybe that's the UV set you're passing in, but the math looks suspicious.
I'd start off by making blackboard variables and playing with them dynamically.
But somehow, on one of the UV sets, you'll have to tell each tile that it is (3, 7) or whatever of (10,10). Right? And then do offsets by multiplying by 0.1
Or you could do some kind of worldspace mapping to calc UV's maybe.
@atomic elm Hi mate, I have a channel where I explain this kind of content π it's in Spanish but has English subtitles https://www.youtube.com/watch?v=kbrNP4akMmg&ab_channel=Jettelly
Que tal JetGuys ! Somos Jettelly Team y en este capΓtulo crearemos un shader estilo toon para cascadas utilizando Unity URP y Shader Graph.
πDescarga los archivos del proyecto: https://www.patreon.com/posts/42155988
Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
βAyΓΊdanos a conseguir 50K Suscriptores y liberaremos nuestro curso de Shaders completamente gr...
Thanks! I'll check it out!
interesting. So it seems to work in the negatives. I think I have to offset my numbers differently in the positives
Remember that a modulus operator "wraps" things...0123456789012345.... if you do a mod 10 on some calc'ed offsets.
he, i made vertex displ. shader, but its only working for spheres. i read i should deactivate smooth edges, but its completely reshapes the mesh. what can i do?
Hello guys do you know how to generate texture 2d array for my shader in unity?
Is it possible to achieve an outline shader for probuilder objects?
I should make myself more clear, I'm looking for a way to highlight the intersection of faces in an object
For example, a cube with flipped normals
The option is not available :/ that my big problem ^^
We are on the old particle system, not the Visual Effect Graph, so there is a material, not only the shader :/
Why my scene is so over-exposed?
Example material settings
Color Space is set to Linear
to many lightsources
can I make an opaque shader in URP that only render to the depth texture? I want it to be invisible in game, but I need the depth written for post process stuff
@bitter needle You can write a shader that only has a depth pass, but you might also be able to just set the renderer's shadow casting mode to ShadowsOnly. That will make it only be drawn during the depth pre-pass.
depth pass only should be cheaper though, shouldn't it?
I'll check out both solutions, thanks
It should end up being the same thing
aight
Anything that ends up in the depth pre-pass will cast shadows
@knotty juniper there is any direct code to creating texture array
Like this
Texture2D Array example, see https://docs.unity3d.com/ScriptReference/Texture2DArray.html - TextureArray.cs
But it show some error
I recently made a EditorWindow for creating Texture2DArrays, https://gist.github.com/Cyanilux/e672f328c4cafb361b490a5943c1c211
Thk @regal stag and texture 2d array help in performance improvement?
And can I use texture 2d array in shader?
do i just need more vertices?
a sphere and a cilynder
Hey guys, I try to rewrite this shader graph part as hlsl, but it seams that I am missing something. For some reason it looks like the Depth Value is returning wrong values, because of the graph is refracting only things behind. My written one is refracting everything? Have someone an idea what is happening there?
Found out I was missing the variable, but still no effect... :/
Ohhhhhhh!
You said VFX and I thought you meant VFX GRAPH.
OK.
What pipleline are you in? URP?
URP batches by shader grouping, and it is weird what batches and what doesn't. As to why the shader doesn't allow batching, and doesn't have an option for instancing on the material, I'll have to help research.
Here's a good discussion, again by the immortal bgolus, talking about some details in shuriken and batching/instancing, with input from Unity engineers too.
https://forum.unity.com/threads/clarifying-how-particle-systems-use-instancing-and-dynamic-batching.678445/
And see post # 17 and post 21 in that article too, instancing may not be working for particles in URP for your version, depending on what ver you're using.
Also make sure you enable instancing in the particle system itself. On the Suriken side.
https://docs.unity3d.com/Manual/PartSysInstancing.html
Ok, i got it. simply had to use _ZBufferParams in the LinearEyeDepth fuction.
no, we are in HDRP 7.4, Unity 2019.4
@delicate badger See posts 19 and 21 in that first link above. Apparently instancing isn't available in your version. As far as the shader disabling batching, IDK.
IDK how/if it applies to HDRP
It might be true for SRP's in general.
how do I make a material tile
What pipeline, what shader?
There's tiling and offset on the material properties.
For standard shaders that you don't have to write (they support that out of the box)
is there somewhere by chance that lists reasons why a compute shader is slow?
I am absolutely struggling with my compute shader, its seems to run much MUCH slower than I might think, and idk why, and I dont know where to go/what to do next to try to optimize it
Wow
You'll probably want to check into dedicated GPU debugging software for that.
What GPU?
Nvidia has their tool chain, and AMD has theirs.
And you can get detailed stats on waves and timing and waits and stuff.
Otherwise, you'll have to do it the manual-way....like commenting various parts out and benchmarking in chunks.
The debugging software is a bit to set up, but it's interesting.
not workinh
What shader?
Should work unless your C# code modifies the material somehow. I've not seen where the standard shader didn't tile/offset. That's a new one.
yes new
Check C# code. What unity version are you using?
Make sure you have the right material assigned to the object you're looking at. Maybe it got messed up.
here only 1 area has it
here
The white square? Or the bed?
white square
And when you select that object, it's got a material on it called "Floor 1"?
yes
im on a macbook air
Its a ray tracing compute shader im making, but it seems to run so much slower than it should be and idk why... im wondering if im doing something in it really wrong thats resulting in huge slowdowns
Since when isn't ray-tracing slow? Particularly on lower end or mobile GPU's (no offense intended to macbook airs)
It's usually done off-line, not real-time.
That's what those new RTX cards are all about, and they're pricey and also high-end stuff. And mostly for things like reflections, maybe shadows and stuff, not sure. But if you're raytracing entire scenes, it's not going to be real-time.
@odd wraith Make sure the textue is set to wrap mode on the import settings, or play with settings. But other than that, IDK. I'd be surprised if there was a bug like that in standard shader. But not out of the realm of possibility.
how do I set it to wrap mode
mhm im aware, but the kind of FPS im getting I dont think I should be
for like 3k triangles(with a BVH) and 2 bounces, im getting 10ish fps
@odd wraith Highlight the texture in the inspector's list of stuff/assets and check the import settings.
@lean lotus IDK man. But 10 doesn't sound that surprising to me, to be honest. You can try the detailed debugging tools. You can even trace through shaders with them. There's a learning curve....
It's possible you're doing something that is memory-access bound, or too many loops, but it sounds like you have sane limits.
You might look into loop optimization for shaders. And watch out for conditionals, as "both sides" can often execute depending on the condition.
what type of wrap mode
Use Repeat
ok
That should be the default, but maybe it got changed. Otherwise, I'm out of ideas.
damn
@grand jolt OK, you're displacing verts.
But what's the deal? Not tessellated enough? you have gaps showing up? What?
how can I make a material to be like spots on a ball I have the spots but the material is covering it all
Is tiling working now?
yes
Yay!
working on a ball
OK, so you want a checkerboard pattern with your squares or what?
I thought you were doing a floor
no I have a sprite for some spots and I want them the cover the ball but still show the white bit
Oy. Well, if you're using standard shaders, that's tougher. You may have to author your own texture, with white bits and colored spot bits.
And tiling a texture on a ball is harder due to the problems of mapping 2D rectangles to 3D spherical objects. Sometimes it takes a special 3D model to do that.
will change the material asking to what
This really isn't a shader question, unless you want to write a custom shader. Otherwise, there's sections for 3d in general and a few others on the channel panel.
ok
how can I make a custom shader
thats what im asking. my shader is breaking the mesh into parts. i dont know how i can prevent the mesh from breaking. i dont know what you mean by "tesselated" since im not using tesselation. i guess you mean "unified normals" are missing. like in this thread: https://forum.unity.com/threads/vertex-shader-breaking-the-mesh-apart.505057/
or do you mean beveled egdes(blender)?
"If the model has discontinuous normals over the surface, then breaks can appear anywhere that the normal stops being continuous. That is, the edges where there is a normal discontinuity may become disconnected."
that would mean that i cannot use vert shaders for cubes
but from the info i cannot calculate the right ammount of edges.
there must be a number from which i can calculate required number of unsmooth edges in order to prevent the mesh from breaking when applying a vert shader.
ok fixed mine
@grand jolt OK. There's a million ways to modify verts, but let's say you're extruding them along the surface normals. So you want to "blow up" or "shrink" a ball or cylinder or whatever. You're actually better off doing that with the transform scaling, but maybe you're doing it in a lopsided way. Bounding a ball and deforming it. Making it have spikes, or whatever.
So say...take Unity's default cube. It's got 8 corners, right? But there's 24 verts. That's because it's duplicating the verts to get the normals on each triangle correct. Probably what that link tells you...didn't read it.
SO...to "blow it up" and extrude it, you have to SHARE verts rather than duplicate them. BUT if you do that, the lighting will be off. Since the verts at the corner will actually be pointing at like a 45 rather than 90 degree angle from a surface. And you get a rounded-lit cube.
SO maybe you should be scaling instead of vertex displacing. OR...you'll need to think more about how verts and normals work. Because surface normals (and the associated lighting for them) are stored on each vert of each triangle in the mesh data.
Unless you use a normal map
first of all thnks for your message. i dont really need lights. the depth buffer would be enough for me, if the depth buffer is even working without a light source
Depth buffer isn't a function of having a light at all, really. So you're OK there.
but why are there even vert shaders if you can only use them for normal maps
Depth is for "Is the pixel I'm drawing occluded by one nearer already?"
No.
Um.
Damned, thx, i will have a look
Vertex shaders set the 3 points on the triangle into worldspace. And then the vert shader outputs something called clip-space, which is similar to a "flat 2D" thing, but without being adjusted for depth yet (a 'perspective divide' happens between the vert() and the frag() stage).
So the vert() is about translating a model into the camera's view properly and smashing it all down into 2D. Perspective divide and Rasterization happens, where pixels are assigned to any triangles that are in-bounds, and then the pixel shader is run for each and every one of those pixels.
@grand jolt
So vert shaders (particularly with interpolating things) are really really handy.
But there's just this logical thing about modeling and sharing or not-sharing verts.
What is it you want to do to that capsule?
yes i understand that now, the verts a re needed for phong shading and stuff, thats why you cannot just displace them
Well, you CAN, depending on how the mesh is modeled.
i wanted to have a little turbulance on a mesh
and then converting it back to the source position
Like it "quivers" or is "jello" or something?
yes
exactly
so i can either change the way of aproaching this, o r i have to change the mesh? right?
but really: thank you, i totaly forgot about: the normals are needed to convert the mesh into world space
OK, what you probably want is to make a model, or find one to download, that has enough triangles to do what you want to do. There is a thing with tessellation of meshes by the GPU to bust it up into small triangles, but let's not worry about that right now.
But the normals will have to be recalculated or the lighting won't look right. And that's a bit harder to do.
What pipeline and shader types are you using?
i have used a lit shader in hdrp (unity v.2020).
yes i will make my model more detailed. thank you very much for your time and to help me understand this!
np.
But I'm looking for a jelly shader.
I can find them for the standard pipeline with tutorials. But although you can do it with graphs, I haven't hit a full tutorial for hdrp.
Cyan has one for a jellyfish. Probably URP.
wow this guy is great! thnks again π
This might give you some ideas and things to play with though.
https://www.cyanilux.com/tutorials/jellyfish-shader-breakdown/
Also, to see/read what was done in the old-shader language (Shaderlab) see:
https://heliosinteractive.com/jelly-shader/
thnks man!
Iβm using a vertex displacement shadergraph (URP) to draw the water and ground for a terrain. When rendering them as opaque, everything looks fine. However, when I change the shader to be transparent, the color of the water is all messed up. It looks almost like it is showing the SKY behind the water, rather than the ground behind the water. Iβm starting to suspect that even though it moved the vertex, itβs NOT updating the depth map properly so it doesnβt realize there is βgroundβ behind the water- but Iβm not really sure about this. Looking for suggestions on what else the problem might be, and how to resolve it. In this image, the top is using opaque- the bottom transparent (the water has an alpha of about 0.7).
also: no idea why the pools look smaller when using transparent
OK, what are you outputting for a color? How do you calc it? What about alpha?
Are you using the scene color node, or are you blending?
The terrain looks OK from what I can tell now.
Transparents don't update the depth, and you don't want it to.,
Probably.
I'm using just static materials colors for the color. I only offset the vertex and compute the appropriate normal.
the alpha comes from that static color- looksing at the A chanel only
What did you set the alpha channel of the water to? Should be some fraction, because color 0 is black, and alpha looks like it's a 1.
But I can't be sure.
Huh. If you set it to .1 does it look "more red"?
Did you set it to transparent too? (you can't do transparency in opaque queue).
Show graph properties
thats what I wanted. would like to beable to see some of the ground through the water...
oh
but then I'd see that shadow when set to opaque also.. would I?
Yeah. IDK Maybe show graph.
I compute the normal by looking at my height map input- perhaps incorrectly? ok 1 sec
For the water, you want world-up vector (usually)
Unless you have waves. π
For the terrain, you can set it by sampling heights to compute the normal to get your new surface normal for a pixel. But for the water, it's "flat", so it's a normal vector that points up. However that's stored.
That's not bad. But they're always ugly, because they're graphs. π
I wrote a thing to grab it into a png.. but couldn't find it now when I need it! lol
so for normal- i get the heghts of the neighbors from the hieghtmap and use the difference to define the normal in that direction
as a test- I could just omit that. leave em all as 0,1,0...?
lol.
Beautiful. For terain. And that looks like it is working.
But, for water I think you just want "up" but as a normal vector.
Because water is flat.
I'd have to figure out if that's the right value for the normal, but otherwise yeah.
not this water π it "flows" down hils and stuff
has waves too
but lemme try a straight up normal as atest
Oy. OK, well IDK then. Try simplifying and just set the color to blue, and the transparency to .1 or .5 or .7 and see what happens. Then add pieces a bit at ta time. Water to me is a plane, not the hills. But you can certainly offset the plane to get waves and stuff. But I'd assume that's different offset than what you do for the terrain.
I want to know, right now, why it isn't transparent.
same- issue.. just no shading.
Normals are stored weird.
Are you using the same shader for both? What happened to the terrain?
"I want to know, right now, why it isn't transparent." this is what made me suspect the depth map not detecting the ground might be the problem..perhaps that's the SKY we see through the water?
yes, same shader for both- different mats with different color
Separate out the shaders. I'd make the terrain opaque too.
ahh.. thats a good idea- will try that
oh.. when I turn off the ground- the black DOES go away. I see NOTHING but sky (with water alpha at 0)
GTG for now. Touch base with all of us, but mess around and see what you can find an google.
Alpha 0 won't tell you much.
But the ground should be opaque so it updates the depth buffer.
Water transparent.
you were right on the money about the shadows.. when I turned the shadow off on water (not sure why it was on- oversight) the black wentaway! testing higher alpha for water now!
ok, thanks for the help Carpe - good thoughts!
That means the normal calc is probably wrong for the (flat) water, like we've been saying.
Good luck, others will be along.
There's tons of water shaders and an infinite # of ways to do them.
It's almost as bad as all the outlining questions. π :p
Sorry if this is a dumb question - say I wanted to modify a float in a shader graph - how would I go about doing that in script?
is the float a property of the material?
Yes. You set the value onto the material for the object.
There's different ways depending, and with SG, IDK where they are with things like material property blocks.
See Material.SetFloat() and cousins.
@meager pelican FYI: shadows OFF on water.. and seperate shaders (ground opaque, water trasp) did the trick!
im probably missing something but... why cant i add any more nodes? not even dragging from an existing thing pops the menu. nothing in console
I was experimenting with trying to get transparent objects that are indoors to receive shadows from my roof so they would not pick up my directional sun light, and in the process of doing that, I tried enabling alpha-test in Amplify, which set the shader order to 2450. When I did this, the transparent objects began to look normal indoors, being dark as they should be, and not picking up the directional light from outside. However, when I went outside the same objects were now showing dithered transparency wherever a shadow was behind them, and on the dark shadowy backside of the object where the light wasn't hitting it. Anyone know why this is happening?
never seen that afore.. I'd try: close & reopen shader, close &reopen unity, reboot, delete libraray folder
looks like I've run out of compilation errors with :
rend.material.SetFloat("fadeAmount", newFade);```
so now its just a matter of setting up a lerp, putting it on my objects, and triggering it properly
@uncut valve you might want to use sharedMaterial rather than material if updating it every cycle.. the former does some odd stuff.... https://docs.unity3d.com/ScriptReference/Renderer-material.html
reopening shader does nothing, making a new shader graph object entirely doesnt do anything either. tried restarting unity (2021.1.6f1), nothing. tried with another unity version (2021.1.5f1, only other version i have installed), still nothing. though, on 21.1.5, i can drag from the output node connector and it does pop up a create node menu - in the top left corner (of my monitor)....
just tried a brand new project, still nothing
that is so strange.. hmm I don't know what else to suggest. perhaps time for some OS checks? like chkdsk?
hmm, ill try restarting & updating π€·
I've tried both now, in the hopes that as you suggest, getting the material through the renderer might act strange, but alas, the float won't set π¦
still nothing, currently installing 2020 lts version, π€·
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class dissolveController : MonoBehaviour {
Material mat;
public float fadeTimer = 0;
public bool isDissolving = false;
void Start () {
mat = GetComponent<MeshRenderer> ().material;
}
void startDissolve () {
fadeTimer = 0;
isDissolving = true;
}
void Update () {
fadeTimer += Time.deltaTime;
if (fadeTimer >= 1) {
fadeTimer = 1;
isDissolving = false;
}
if (isDissolving) {
mat.SetFloat ("fadeAmount", fadeTimer);
}
}
void OnTriggerEnter (Collider col) {
if (col.tag == "playermanipulator") {
startDissolve ();
}
}
}```
I'm not sure if setfloat is working properly - that seems to be the stop gap here
this isnt the final implementation, just a test script on a test object to see if I can get it working π
@uncut valve well either should work, but one could might uneccessary materials.. just gtta be careful about that.. re it not changing the value from script.. first make sure the property is EXPOSED in your shader, AND that the REFRENCE name (not the "regular" name) of the property matches the string you use in code
ahaaaa I will try the reference name
ty
Yep that works, you da man, man.
π
mat.SetFloat ("Vector1_f6718bbfab304664aed84889e25e9d67", fadeTimer);```
ugly but it works π
hehe.. you CAN change that in the shader ya know.
thats a better idea in fact.
I'm still pretty new with shader graph, papa brackeys leaves a lot of his shader graph tutorials like "Okay now you're free to experiment!"
but like.. i need to know more lol
now that you have that working check out https://docs.unity3d.com/ScriptReference/Shader.FindPropertyIndex.html for faster proprety access by ID number.
neat
lts version kind of works.. the create node popup apears in random places on my monitor, though it does consistently show up. except my project wont automatically convert to it. nice
@restive charm since it doesn't happen on a newly installed version, and it only happens with the new version on your computer (not ours).. this points toward a corrupted installation.
yeah. ill try reinstalling 21.1.6
Hi guys.
Do you know an efficient way for blur in mobile? I want my ui background become blur and the hard thing for me is that there is other ui element behind my background.
yuk! but not sure what else to suggest π’
argh I think I'm going to have to use a list to use the effect on my prefabs, since there's.. five models with materials
Orrrrr I make a simplified model to swap out while animating.. then I don't have to swap materials around
I'm using URP, would anyone know why this shader ```
Shader "Universal Render Pileline/Custom/EdgeGlow" {
Properties {
}
SubShader {
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
Pass {
HLSLPROGRAM
#pragma vertex EdgeGlowPassVertex
#pragma fragment EdgeGlowPassFragment
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct VertexInput {
float4 objectPos : POSITION;
};
struct VertexOutput {
float4 hcsPos : SV_POSITION;
};
VertexOutput EdgeGlowPassVertex(VertexInput input) {
VertexOutput output;
output.hcsPos = TransformObjectToHClip(input.objectPos.xyz);
return output;
}
float4 EdgeGlowPassFragment(VertexOutput input) {
return 1;
}
ENDHLSL
}
}
}``` Would give this error?
I don't think you can just return a float4 - you need a struct type with semantics
but isnt that what this bit is? struct VertexOutput { float4 hcsPos : SV_POSITION; };
yes but the return type on your fragment shader is just float4
im pretty much just going from this
which uses half4
i replaced float with half and still same error
its got something to do with the vertex shader but idk what im doing wrong
theres no docs for urp from what I can tell
try restarting the editor
You are meant to use Shader Graph
as the shader APIs are still in flux for URP and HDRP
you should probably be using shader graph
shadergraph is really hacky in my experience
getting lighting info and stuff
just feels hacky
It's the best bet right now Β―_(γ)_/Β―
have done, restarted editor,pc. tried new project. tried different versions. tried reinstalling the same version
there are assets for image and other effects in canvas
not to mention depth/stencil stuff
If you want a stable and documented shader api for hand-writing shaders you should stick with built-in for now
yeah I guess
a video of it working π
which i hate, shadergraph is great for simpler stuff
but I want to hand write other stuff
well thanks ig
tell me about it - I'm waiting eagerly for StructuredBuffer support
I tried handwriting URP shaders too because ShaderGraph doesn't have it
I failed
im looking at 2 seemingly identical shaders
like line for line identical
and one works the other doesnt
is this the kind of edge glow you're talking about @lethal fern ? https://www.youtube.com/watch?v=UkqVNjw2IR8
Use the Shadergraph tool to create a custom shader that applies a glow to the edge of our object.
Asset Pack used in scene: https://assetstore.unity.com/packages/3d/environments/landscapes/lowpoly-environment-pack-99479
Created by Korveen
or like an exterior outline
vfx graph is also really nice
the actual shader was just a test, im just trying to learn how to write urp shaders by hand
the shader is irrelevant, i just picked something that sounded interesting
but thank you ill look at that
@shadow locust : SV_Target
i missed that
on my fragment shader
that was all
im so dumb
What i want to do is rotate my masked image. right now im rotating it then masking it. What do i do? add, multiply, is there like an image node?
What could be causing this sort of visual?
@atomic elm transparent shaders don't write to the depth buffer so they don't sort very well.
You can try changing the queue manually
How would I do that?
Nevermind, I found it. Thanks.
The issue now is that it's having that depth issue with itself
Unfortunately when I try to make this shader opaque, it just becomes white
Transparent things draw back-to-front.
And that waterfall is drawn first, and the "pool" is drawn 2nd. Overwriting the waterfall.
Yup
I'm not sure why it needs to be transparent, if you can't see through it. Is there anything special about it?
You can draw opaque if you want opaque water... in normal shaders. IDK if you can set this to write to the depth buffer from the opaque queue.
I don't SG a ton, frankly. Drives me nuts.
But that's not a slam, it's me.
Yeah, I'm not too familiar with shaders at all really lol
Honestly, it could be opaque, but when I set the surface to Opaque, it just becomes white. I'm going to mess around with some of the blend mode settings to see what happens
Is it some big complicated water shader with reflections and refraction that ends up looking like spaghetti? Or can you post a pic of it?
Here's a view of the graph
This was the guide I was following https://youtu.be/kbrNP4akMmg
Que tal JetGuys ! Somos Jettelly Team y en este capΓtulo crearemos un shader estilo toon para cascadas utilizando Unity URP y Shader Graph.
πDescarga los archivos del proyecto: https://www.patreon.com/posts/42155988
Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
βAyΓΊdanos a conseguir 50K Suscriptores y liberaremos nuestro curso de Shaders completamente gr...
Yeah, that's what I thought. I can't read it. lol. This is a pet-peeve.
OTOH, SG has some nice features too, and is more future-proof than any shader you write by hand, theoretically.
That graph is way too tiny to read but I can see you don't use rhe alpha channel. So I'm guessing it is transparent to use the scene depth texture
And thats why itvturns white when you make it opaque
The video says he's doing depth of elements under the water. Probably adding white. So yeah, he wants that depth texture.
You could just do maybe some offset to the queue like opaque+10 or something. IDK if SG lets you do that like regular shaders. I should fire up unity but I'm being lazy. Will google.
@atomic elmand like @eager foliois saying, the opaque depth map is produced in opaque and it is drawn the other way...from front to back. So the water got drawn first.
And was missing the depth info.
More that if you set it to opaque, it writes to the depth map so it reads its own depth. You could probably have it on a higher queue, yeah. I think Cyan did a post on that.
Thanks guys, I'll try out these tips
It doesn't write to the depth until it's done with the pixel. π
Of course if the waterfall doesn't nead edge foam(it doesn't seem to be used in your screenshot) you can take that part out for the waterfall and have that be a separate opaque material from the flat water planes
It's a pretty cool looking toon water shader. I added that site to my "look at their videos" list. I get to practice listening to Spanish while reading the CC too.
i found out that i did not convert the position to worldspace in the end. so it actually works now. thnks for your support. so if I write a vert shader, its always required to convert the normals right? because overriding the properties that are required to make the object even visible also means that you have to recalculate them (in to worldspace) in the end
Yeah, vertex outputs clipspace to the next stage.
So you're going to have to do that vert math in the vert shader to transform the local vertex from the model into clip space. Sometimes you can just do it all at once, or at other times you do it in stages. Magic 4x4 vector math. Unity supplies a float4x4 matrix (several really) and they have a macro you use.
But somehow you have to go from local through the objects Transform and end up basically rotating the world around the camera, and then spatting it into clip space by knowing the camera's view, thus getting ready to shove it flat onto the 2d screen. Conceptually. IIRC. There's a "perspective divide" and stuff that happens between the two stages. And interpolation happens with that structure you pass between them, so you can lerp stuff, like colors, UV's or coordinates. Then each pixel gets its own unique set of interpolated values.
And it all works together in hardware and programmable stages, and ends up massively paralleling all these pixels at once.
Pretty cool and fun black art.
ending up calculating matrices is the worst possible thing that could happen to me hahahah. i read this book about camera clipping once.........π
@half remnant use noise map or any other mask map in lerp T
U can do with the help of nested lerp with different mask map for blending the different texture @half remnant
In this tutorial about Unity 5 and Amplify Shader Editor (ASE) I show how to create a shader with 2 textures (one is overlaying the other one) and a mask that defines, where the overlay texture is visible: https://www.assetstore.unity3d.com/#!/content/68570
See my social profiles here
G+: https://plus.google.com/+JayAnAm
Twitter: https://twitte...
@half remnant This video give the basic understanding of lerp
Wait a for 5 minute I give you some screen shot
Or more minutes lol
No problem u understand one by one when day pass+ keep on doing on your work
First mask map is the blue print which texture should place in which position of mesh @half remnant
Mask map whether be in black, white, gray or LIKE SPLAT MAP
mask map example
splat map example
@half remnant i will see u later
Hi everyone, I made this shader using Cg language https://twitter.com/jettelly/status/1390878257503932418
You know what guys? we love what we do ! we're working on some techniques to achieve volumetric transparent surfaces in Unity. Do you want a Candy? π
More videos --> https://t.co/AG3ETb2klS π
#madewithunity #indiedev #unity3d #gamedev #shaders #indiegaming https://t.co/YeAQsqnqPj
I'm trying to reproduce a "candy" surface
Hey anyone know why my skybox is totally green?
I tried change skybox texture but same :/
Im using URP
Fixed
bad shader type
Anyone know how to check the distance between a vertex and a game object?
I tried passing in an object's position to the shader and did a distance() between the obj and vertex, doesnt seem to work
This is my current thinking
IDK why that wouldn't work, but your description isn't specific enough.
distance() is an built-in function in HLSL.
But distance to what?
You probably need the worldspace positions, and you also need to understand that the object's origin may not be where you think it is.
Are you talking about a vertex on the same object, or a vertex to some-other object?
If on the same object, all you're getting is the object-space distance of the vertex to the object origin. Unscaled. You can get a distance in worldspace by transforming it and transforming (0,0,0) and doing a distance().
(note, you edited/added a code snippit after this)
Thanks for your reply
here is me passing a transforms position to the shader every update
Stored as a vector
OK, but that's going to be a worldspace position. Is v.vertex in worldspace in the 1st code sample above? Did you transform it to worldspace or get worldpos passed in?
nope I did not do any transformations
Therein lies your problem.
It's like mixing metric and imperial measurements, you have to convert to similar things.
I could try transforming the position in the script first like this
I see
Kinda like this?
A quick google search brought this up
although nvm
this was done in C#
I want to convert it in the shader
This is the standard pipleline, right?
Lemme see if I can find you the macro, or if you can just have unity send it to you. I think if you use "worldpos" as a variable, the engine will plug it in for you! Something like that.
But yeah, you can do that conversion you're showing too.
This this a Surface shader or vert/frag?
float3 worldPos = mul (_Object2World, v.vertex).xyz;
vert
Yes, that works, but I'm trying to have a way to avoid it in the first place. Sec
ok, cheers bud
ok @meager pelican I got that part working, distance checking is working nicely now
But I have one more question if possible
OK, shoot.
As you can see
the gameobject further away
when it gets closer the mesh is deformed in that direction
however its fairly sharp
I would like to smooth the vertices out if possible. I can attach more screenshoits one sec
It looks like you need to scale the deformation according to distance. That looks like some kind of hard-step you're doing.
yea exactly
yea at the moment I am just checking if the distance is less than a certain threshold before multiplying that vertex by some scalar value
Like because you have displacement value. You need to scale that as a % of the distance, and maybe have a slider for "strength" that is a multiplier.
I need to maybe lerp somehow
yes yes yes, exactly
this is what I am wanting
hit the nail on the head
would I lerp between the distance and some strength value maybe?
Lerps are good. You may need to clamp the results.
Well, you know that dist is > influenceDistance so you can just use that as a % and multiply by your displacement. Maybe inverted. I don't have enough caffeine yet. But yeah, lerp or some maths. I'd add a slider to scale the whole operation, kind of like scalable gravity. So some black-balls may be more massive than others.
how do you mean use it as a %?
Um, the T value of the lerp, or just some scalar.
oh ok, I understand now what you mean
ok thanks for your help, ill give it a shot myself now and come back to you
π
Just try (1-(dist/influenceDist)) but if that's right then your if is backwards in the code, because dist should be <= influence dist. But think about it.
So take that and multiply it by the offset amount that you multiply the normal vector by.
I mean I tried adding some scalar values to control it
which helped but this is also weird
ill try this
You want to offset the verts in the direction of the black ball, right?
yea exactly
So you'd take the positions of each, subtract them, and normalize the vector to get a unit-vector that you can multiply by.
subtract them from what?
This was my current thinking
each other. Black ball - red ball. Or whatever. In worldspace. So that gives you a directional vector. You normalize it to get a unit vector, that gives you the right direction with a magnitude of 1. And thus, you can multiply that by the amount of "pull" you want and get the offest to add to the point.
I mean, I still want the verticies to move along their own normals
wait let me draw something
Kinda like this
imagine both are perfect spheres
Yeah but you don't really want them to change according to their normals, I don't think. Otherwise points on the "bottom left" of that big circle would move left and down AWAY from the small circle.
hmm, I sort of see what you mean
You can research metaballs too. That's interesting. They even merge with each other.
But they're all signed-distance fields.
ok
so sorry, one more time, what would you reccoment
getting the normal vector
with reference to the black ball
I don't recommend the normal vector for displacement. And least I don't think I do with insufficient caffeine.
:p
So I'd offset according to "pull direction"
thats currently what I am doing I believe
Calculating distance between the pull position vector and the vector
and then offsetting a vertex based on this distance
I dont necesseraly need the vertex to pull directly to the black ball
just create sort of a wave underneath the ball on the surface
newVert = oldVert + PullVector * distanceScale * StrengthSlider;```
OK
Then you can split the diff with a slider.
NormalVectVert = oldVert + NormalVector * distanceScale * StrengthSlider;
And then lerp between the two with a slider or something.
This is handled in the normalize?
You need the distance calc, and releative to the influenceDistance to know "how close" our "too far away" you are
so I should keep the distance check if statement in
So if you're right up next to it, it's stronger than if you're near max distance, right?
and then put your code within?
yea exactly
So you're scaling the offset by dist/influenceDist which is near 1 at the far-away point and near 0 up close, so you need to 1 minus that. So (1.0-value) and "invert" it, so closer is 100% and farther is approaching 0% Then just scale of amount of offset by that.
As to what direction, you're going to have to find a solution you like. You can use the surface normal, but that won't look right IMO, or you can use the direction-to-object.
yea I can handle this part, cheers.
unsure of the properties of newVert and oldVert
Yeah, you just need to do that distanceScale with teh 1-dist.
Yes, or maybe the worldspace version of that.
yes
and for dist/influenceDist
what should I put here
just the distance for dist?
from the earlier calculation
Yep
The "gravity direction" that you normalized * some strength.
do this?
OK, so "PullVector" is what I just called gravity direction.
yup
I have assigned variables for both the center of the red ball and the black ball
for _CenterPos and _PullPosition
hmm, ill try both
forgive me but I dont remember the 1-% stuff
Which you called out, but you need to do that earlier
?
Change "Out" to DistanceScale.
Move it up 3 lines.
oh, gotcha
and then I lerp between the newVert and the NormalVectVert?
Moved it up
Sure, if you want. Or do something else. That's you coding. π
I'd make that another slider with some named value.
what, just another strenght property?
Or try distance scale, or the inverted version (without doing 1-)
There's no "rule" really, it's all "if it looks good, it is good" stuff.
There are more-standard ways, see your googles for metaballs.
Lerp does work in shadres, yes! It's very powerful, but it's not clamped like in C# so be careful.
no i didnt mean lerp
Abs works too.
I meant ab
abs
ok good
fun stuff
I guess newVert shouldnt be a float3
although its utilizing vectors
But DistanceScale should be positive anyway. due to your if.
You're missing a ; on the end of the distanceScale calc.
oh haha, thanks
just getting more of the same
ill try changing some things around
What do you have for strength and whatnot? The sliders?
Inflluence distance is high I know
but its on a large scale
so it makes sense
like the red sphere is 1000 units wide
Use pastebin or hatebin, post your shader please.
sure one sec
idk if this is how you are meant to upload it
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
there is a link
No, but I don't mind since the new format for discord
ignore alot of the variables in there
starting unity. Please die waiting.... π (Skeleton at keyboard)
thanks haha :0
appreciate the help by the way
I am relatively new to shader work
I have sort of been building my way up
It's waiting on a cache server I don't have for some reason.
haha
btw I have a script which updates the position of the second ball in edit mode
do you want me to attach that or are you ok
Gimme your two transforms for the balls, please.
I'm good right now.
its just a simple setvector in update with runineditmode checked
I'll expose the variables and plug manually
they are just simple spheres one has a more dense mesh to make the effect smoother
you can place them anywhere
mine is on a large scale but really you can recreate this with just one sphere above another
I know, but I'm trying to recreate YOUR VALUES so we have same scale. π
I'll use unity spheres
I can provide the mesh also
Nah
ok sure
Just locations, scale
Does the black hold deform, or just the red-planet
Second, almost set up
OK, converting the variables to properties, almost done.
No script needed.
Include file ignored, not used now.
yh of course
OK, I have a red ball, black ball, camera with 20000 far plane, no include needed, no script.
Trying to get shader to work out.
sounds like my setup
Please stand by. One moment please. Your regular programming will resume soon
haha, cheers xD
What are you seeing? Are you getting distortion?
OK, first off, IDK where your red-sphere color is coming from.
I get this (taking screen shot)
what do you mean you dont know where the colour is coming from?
I just gave the mat a colour
The calc is diff. See how mine is "flat red"? Maybe you have that noise function working or something.
I have shaded wireframe turned on
Oh, lol
lmao
OK, and highly tessellated ball.
yup
lol
Do those values look reasonable for what your script is setting?
my script is only setting the position of the moon
Sec
do you want me to send you the script also
You can pastebin it.
Its literally this
just in update
set pullPosition to the black balls position value
and have execute in edit mode on
There you go
OK, but I plugged in the values in the editor (as you see above). And I have the balls at those positions.
make sure always update is on
Hang on π
Yeah I posted them above, basically. Edited some to match yours
sec
Pasting script
these are not the same as mine
these are mine
these values wont produce anything
bump influence distance up to at least 1500
I did, but I'll mess with it again, getting your script to work.
For me
OK, I got it started. Had to go to 1800's for some reason.
sec
Well, I'm just fixing up my script because names didn't match up.
please be patient.
Also IDK where you set the ref to the pullObject but I've made it public.
yea ok no worries
OK, I finally got to the shader code.
I see what is going on.
You are manipulating the vertex in LOCAL space. Then converting that to clip space.
ah I see
But the normal won't match from local space to worldspace, among other things, if it's rotated.
It's not but it could be.
And the worldpos thing will be screwed up.
Sec
If you try rotating the red-ball in unity, you get to have even more fun. Still not matching the way we have it now.
We might need to pass in a diff matrix, or calc one to invert things.
My material is distorted (its on a quad) pls help this,, is how it should be:
Thats howw it is:
@onyx jungleParticularly when we multiply by worldspace sizes in that huge scale, and then apply it to local space! That's why you get those huge distortions, since your scale is x1000
The UnityObjectToClipPos() applies the scale, and we do that LATER. So for a unity sphere, we're applying offsets that are x1000 times too high. lol
oh ok
so what should I do?
It won't work by itself, need other changes.
But I'm brain farting.
Sec
I put lighting on it to see the normals in a sane way.
Your frag can be as simple as:
o.color.rgb = _NoiseColor * Lighting;
But you'll have to set up a vector property for _LightingDir
I've almost got it.
The lerp isn't working between normal-type and directional-type.
@onyx jungle
ok cheers @meager pelican
I am currently just out right now so I cannot respond for 30 or so minutes
REALLY appreciate this help however
OK
@onyx jungleIt was fun, I'm just rusty.
v2f vert(appdata v) {
v2f o;
o.normal = UnityObjectToWorldNormal(v.normal);
float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
float wsDist = distance(_PullPosition, worldPos);
if (wsDist <= _InfluenceDist) {
float3 pullVector = _PullPosition - worldPos;
float wsDistanceScale = (1 - (wsDist / _InfluenceDist)) * _StrengthSlider;
float3 newVert = worldPos + pullVector * wsDistanceScale;
float3 normalVectVert = worldPos + o.normal * length(pullVector) * wsDistanceScale;
worldPos.xyz = lerp(normalVectVert, newVert, _DirectionLerp).xyz;
}
o.vertex = mul(UNITY_MATRIX_VP, worldPos); // WorldPos to clip space THIS IS THE TRICK TO MANIPULATING IN WS
o.noise_uv = v.vertex.xyz;
o.uv = 0; // <<== do something with this if you want, but always initilize all output variables.
return o;
}
void frag(v2f i, out f2g o) {
float Lighting = dot(i.normal, normalize(_LightDir));
o.color.rgb = _NoiseColor * (Lighting +0.1);
}
Test it out. May not scale/rotate properly, but it may. I added a slider for the lerp.
_DirectionLerp("Normal vs Pull Direction Lerp", Range(0, 1.)) = .5
And the define as a float _DirectionLerp;
Changed some stuff around.
I'm out of time too. π
As they say...."Cheers". π
Well ive opened up my ray tracing compute shader in RenderDoc, but idk what im looking at, but almost all of the time taken is in that compute shader... looking for optimizations and debugging of compute shaders is so annoying... I see I have a few structured buffers that are around or greater than 1 million in length, would these be better stored as textures?(They get referenced/read a LOT of times per frame)
Is there anything with the memory or data layout or anything I can do to optimize this as well?
Im so lost for ways to try and optimize this any more...
Does anyone know why it isnt letting me srt a reference
In v10, the settings for each property is found in the Node Settings tab of the Graph Inspector window. Need to have the property highlighted in the blackboard or graph.
ok thank you
wow ok cheers, ill give it a try now
sorry for not replying
I was out
i have this effect on my second camera
this is my second camera
but the bloom is not working
does any one know why this is
@velvet raft The Post Processing package (PPv2) does not work with URP. It has it's own built-in volume system instead. There's a "Volume" script, see documentation here : https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@11.0/manual/integration-with-post-processing.html
is there anyway i can make the bloom only effect objects renderd on 1 of the cameras
Can use the Post Processing tickbox if you want to disable it completely for a camera. Otherwise, there's the Volume Mask (under Environment on the camera) which acts similar to how the Post-process Layer worked in PPv2.
You can "chain" lerps together.
https://forum.unity.com/threads/blend-multiple-textures.958744/
There's no way for us to tell, really. Too much info missing.
Maybe someone will have a good guess.
But we can't tell what you're doing, really.
At least I can't. I shouldn't speak for others.
Does anyone know if there is a way to change albedo in autodesk interactive shader so i can lerp from solid color to texture color?
no shader graph
I'm using URP and recently these specific prefabs started snapping back and forth. Both are URP/Lit Shaders that came with the asset pack, untouched. Why is this happening ? https://screenrec.com/share/0tOISxYhXF
update : It was transparent as default. Making it opaque worked.
how do I access this menu
try looking for shader graph in the package manager or if you are using urp ou something like that just right click into the assets area and go into shaders and create a shader from there
which
which of these^^^^ or not from here cause from the tutorial double click opens script
wait mine is a standard shader does it have to be one of the other (I have 2020 version)
I can't open it and he is using it
@odd wraith check that link
I don't have those choices
How can I get those choices
Those options are for shader code. You are looking for Shader Graph, which is installed separately. It's only available in the Universal RP and High Definition RPs and automatically included alongside installing those packages. They require a bunch of changes to the project though, so be sure you want to upgrade. For URP see https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@11.0/manual/InstallingAndConfiguringURP.html
You can find more info here : https://www.cyanilux.com/tutorials/intro-to-shader-graph/#install
^
Updated versions would be better, but any would let you use Shader Graph. The version in the package manager also depends on the current Unity version being used.
where do I install it from cause I'm stuck in a maze
Hello guys , I have 4k texture Atlas in which I want to pick texture 3 only to fill my plan using shader , how can I do that?
From the Window > Package Manager. Look at the documentation I linked. It goes through how to set it up, either from a new project or installing into an existing one.
you can create three UV offsets as material parameters: the UV coordinates of the top left corner of the textures you want to use.
ok know I'm installing it do I need to do the configuring
@regal stag ^
Read the docs
Whats wrong with my first shader guys
Properties
{
_MainTex("Texture", 2D) = "white" {}
_MainColor("Main Color", Color) = (0, 1, 0)
_CircleColor("Circle Color", Color) = (1, 0, 0)
_Center("Center", Vector) = (0,0,0,0)
_Radius("Radius", Range(0, 100)) = 10
_Thickness("Thickness", Range(0, 100)) = 5
}
SubShader
{
CGPROGRAM
#pragma surface surfaceFunc Lambert
sampler2D _MainTex;
fixed3 _MainColor;
fixed3 _CircleColor;
float3 _Center;
float _Thickness;
float _Radius;
struct Input {
float2 uv_MainTex;
float3 worldPos;
};
void surfaceFunc(Input IN, inout SurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex);
float dist = distance(_Center, IN.worldPos);
if (dist > _Radius && dist < (_Radius + _Thickness))
o.Albedo = _CircleColor;
else
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}```
its so simple and yet its pink
Im trying to draw a circle around the player so the player can see his attack range
so only the circle should have a color the rest should be transparent, and im putting it on a quad below the player, is that an ok way to do it?
probably not gonna keep it that way im gonna need to find a way to put it on teh terrain later but for now i jsut want my very first shader to do something so any help is appreciated
The hot pink is an error color
So it's either that you have the wrong pipleline set up for you surface shader. Or you have an error.
You should see an error message in the console. But if not, select the shader in the inspector and see what that says.
@marsh ventureAnother way to select quadrant 3 is to remap uv's of (0,0) thru (1,1) to (0,0) thru (.5,.5) . In other words divide it by 2 (but that's just for that quadrant) . For the first quadrant, you'd also divide by 2 but you'd have a .5 offset in the Y direction. For the 4th quadrant you'd divide by 2 and offset x by .5. And for quad 2 you'd divide by 2 and offset both by .5.
So the formula for selecting any of them becomes:
inline float2 RemapUVs(float2 uvIN, float quadrant) {
float2 newUV = uvIN * .5;
return float2(newUV.x + .5 * (mod(quadrant, 2) == 0.0), newUV.y + .5 * (quadrant < 3));
}```
But I didn't try that, so it might blow up. Off the top of my head.
That's if you insist on numbering them that way instead of 0 based.
forgot to mention, no errors in console or on the shader itself(in inspector) im using URP though
anyway this is my circle now, not using shaders but it works for my purpose for now
Surface shaders don't work in URP. That's the other thing, the wrong pipleline for the tool. Or wrong tool for the pipeline. That shader is simple enough you can use Shader Graph. π
Pass a player position? But why would the shader care?
hi! any ideas for recreating this in shader graph?
im making a horror game and i need a good goo shader
i was thinking voronoi noise and then use the ridges in between cells? but idk
The fastest is to probably pass the player position to your shader, and then when it's in rage of distance, say, 0.001 or whatever the hell, then set some shared variable to the biome type. Google "atomics" so you don't clobber it. Only set it if the player is visible, and default it each frame at the start of rendering to some value that is "not set". And you'd have to do custom code and maybe edit the shader file directly, bypassing SG.
Then, on the C# side you can read that data back. The problem is that last I knew, and maybe it has been fixed, Shader Graph doesn't allow you to bind structured buffers. If you only need, say, one float, maybe you can do it with a custom node and atomics but IDK how because the resrouces won't be bound to the shader.
So you're going to have to dig in hard. And what you're asking isn't simple AFAIK.
It might be easier to get the right data from the texture and compute the lerps yourself in C#.
I'm really grasping at straws here with SG and doing this at all. Maybe someone smart will know.
@half remnant
If you need the C# side to know the biome, I'd look at generating the planet biomes on the C# side, and passing that data to the shader (e.g. in uvs / vertex colors) instead of using 3d noise in the shader.
I wouldn't say that looks like voronoi, but Voronoi -> One Minus can give a fleshy cells look. That type of noise looks more like the Gradient Noise -> Subtract 0.5 -> Absolute.
Could also just pass a texture in like that.
hi! is there any way to turn off main lighting for a lit shader graph, but still keep normals calculations?
ive found a shader that fakes a decal, by using a cube, but it still has lighting on some of the faces of the cube
i still want to keep normals because it sorta gives that goo effect, which is what i'm going for
Maybe turn off shadow calculation
It should be set to transparent too, so it doesn't write that cube to the depth buffer
yep, its transparent
how do i do that?
On the renderer, change the Shadow Casting Mode
I mean on this renderer, the cube
Hey i need help with shaders. I am making a 2D game and i am trying to make a shader that inverts the colours of objects that are behind this material.
@warm pebble in which renderer?
URP? @eager folio
Cool project! There's a trick I learned for shader graph from a brackeys tutorial, using noise to set up a transition line - of course the exact implementation wouldn't be right for your project, but it might work -https://www.youtube.com/watch?v=L_Bzcw9tqTc
Here's a crappy shader I made based off the ideas - the.. third node down the line, in the top row, that'd generate some nice transitions.
For yourrrrss.. not too sure - maybe duplicating and flipping the noise, and using first as alpha mask for texture a, second as mask for texture b, so they line up nice, and make sure alpha culling is on
going to need a way to identify biomes anyways, if you plan to procedurally put objects in em π
no idea! just spitballin' π
Oh wait, I misunderstood what you said there - yeah you're right, it would, I just used that video as an example, you wouldn't be plugging the noise into vertexes, but into alpha masks, as suggested right after
just using it for the textures
On a mostly unrelated note - would make a mighty interesting planet with animated vertices and working stitching π
When I create shader variants, I can not see some shaders that I have added in the shader list (graphics setting) and then imported. why? For example Hidden/ShaderA but when I click on shaderVarient file, I do not find it
Hello, I am making a compute shader. Is there a way to pass in a struct that contains an array, because it seems to not be a blittable type.
Hey, how do i handle roughness and hdr emission in my shader code, so it works like autodesk interactive, or work at all ? π
Where can I find the World matrix? (I want to remove the rotation from it, so I don't wanna use the transform node)
It's the Model matrix from the Transformation Matrix node. There's also a Position and Scale output from the Object node which might be helpful if you don't want the rotation part.
Is it impossible to use shader materials on a canvas set to Overlay?
Hey, I am trying to set an element in an array in my shader:
uniform float2 array[20]
and I tried doing this:
mat.SetFloat("array0", new Vector2(1,1));
and it doesn't seem to work, is there other way to set an element to an array?
Everything works for an int or float
Afaik you can only set the entire array. mat.SetFloatArray("array", array);, so I guess set the element before that. https://docs.unity3d.com/ScriptReference/Material.SetFloatArray.html
@regal stag I thought so too, but I saw someone did it:
http://www.alanzucconi.com/2016/01/27/arrays-shaders-heatmaps-in-unity3d/
anyway, I guess I'll use SetFloatArray, thanks
The problem I am having with this is that I need to send Vector4 array instead of Vector2
Oh interesting, I didn't know that. Then yeah, you'd need to use mat.SetVector instead. You might still be able to pass the Vector2 into it
I guess Unity just pass the buffer as is so I can do something like this maybe:
new Vector4(new Vector2(..), new Vector2(...); // This will pack 2 elements into one vector
That's the thing, no matter how I try to pass it, it doesn't seem to be working
(with SetVector)
I guess maybe something changed since that post
Google says its impossible, But i don't see why unity would make it impossible
I just want to blur other UI elements behind an Image i enable π¦
Yeah, it's possible that method is only for versions prior to Unity 5.4 since there's an updated post that explains the SetFloatArray and SetVectorArray. https://www.alanzucconi.com/2016/10/24/arrays-shaders-unity-5-4/
Nice find, thanks!
At this point a yes or no would help π
If you are using Unity URP I think you could do that with the Camera Stack and post effects @wary horizon
How can i use autodesk interactive built in shader and modify it so i can blend textures in it ?
hi guys, i need some help with creating my first stencil shader..
i have two objects (coins) and in case of collision i need to erase the overlaping part from the first coin.. i read that stencil should be easiest way to detect and remove given pixels
can anyone help me?
anyone?
@regal stag Should I learn shader coding? And if I should, for which render pipeline ?
What does "erase the overlapping part from the first coin" mean? Depth clipping should allow two coin-type objects to intersect, no stencil needed. So IDK what you mean. Draw pic, or maybe someone else knows what you're talking about.
Does unity have any built-in/included hashing functions? Getting scalar random values from a vector
The Unity.Mathematics package has hashing functions for all of its types. I don't know how random they are though.
Oh, I just realized this is in #archived-shaders
I think I have Mathematics installed. I havenβt looked at it yet. I know it uses shader-like syntax but can it be used with HLSL or is only for the burst compiler
I don't know of any included hashing shader functions in Unity
Unity.Mathematics can't be used in shaders. But if you like its hashing, you can just copy it. Since its syntax is intentionally made similar to HLSL, it can probably be copied directly.
For example, the hash function for float2 is defined as:
public static uint hash(float2 v)
{
return csum(asuint(v) * uint2(0xFA3A3285u, 0xAD55999Du)) + 0xDCDD5341u;
}
asuint exists in HLSL and csum is just defined as uint csum(uint2 n) { return n.x + n.y; }
Nice
I was looking for a built in equivalent of something like this
Iβll have to check out mathematics
Hi, what's happened to the 2D Renderer option in the shader menu? I'm in Unity 2020.3.1, URP 10.3.2
Are if/else statements recommended against in shader code? I initially assumed that if/else statements slow the shader code down a lot but I see many examples online that use if/else statments like its nothing
as I know they should not be used if they can be avoided, but there are some special cases where branches are not avoidable, also if they are just examples, they may be some quick jobs to show the thing and not worry about performance
but yeah, try to find different ways for problems
That makes sense, thank you
(also, there are some cases where the compiler knows what you are trying to do and kinda re-writes your bytecode)
sooouu If you want to use if-s you may try to, maybe profile it and see how much slower it is with the branch
but if you avoid them you don't need to worry about this I guess
and rarely it could be faster with a branch if the branchless is way more complex
BTW for and while loops have similar concerns right? Because every loop involves branching?
Not necessarily. Shaders can unroll loops. See https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-for
Also just because an if is used, doesn't mean it produces a branch. You can even force them to flatten or branch afaik. https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-if
I guess when the loop is not dependent on the loop's content they are unrolled?
Is a vector2 a built in variable with the HLSL?
If not how can I make an array of a struct?
Would be a float2 in hlsl
With .x and .y (or .r and .g)
oh oh question, if I have an array of float2, and I only want to do additions, multiplication and other stuff on them, can I cast the float2 array to float4 array for the time being, and only later use it as float2 array when I need to calculate things like length?
Is there a way I could make a Shader return an array of undetermined length?
@runic pendantIt depends a lot on the nature of the conditional.
All the cores in a group share the same instruction counter. So if even 1 core has to execute the else, and all the others execute the if, then they ALL step through it, and some are masked off if it's not applicable to them. Basically.
Same with that "rare exception" that happens one out of 20 times...well, if ANY core has to execute it, they all get slowed down.
And that's the "bad" thing about them, speed. Because cores often get hit with "both sides" and basically execution time is full for all.
BUT...if the conditional on the if() is a uniform value that's passed into the shader...well...they all execute the same section, and can all SKIP any other section if present.
So it all depends on the if().
And small if's in an otherwise simple shader aren't that bad, if it's just a simple calc like an multiply-add that "both" execute conditionally.
How fast is fast?
π
Thank you, that answered my question perfectly. I probably don't have to worry about speed with the shaders I am writing now, but I just became curious from looking at other people's code
Many people think they avoid it with the ternary operator, but that's ultimately a conditional too. π
You may want to benchmark the [branch] attribute though, and see the caution in the article Cyan posted about resource consumption.
Rule of thumb is when in doubt, use ternary but watch out for side-effects.
I should mention shader compilers are hardware specific, so there's really few guarantees for how anything is precisely implemented with all the different platforms out there.
And they optimize some expressions to remove branching if they can.
I will assist in the research regarding this because I kinda wanna know too π How are the transitions using the noise?
so apparently there is just a ton of things included in the render pipeline by default even without Unity.Mathematics. I was just looking at common.hlsl which includes Random.hlsl a min ago
update: Random.hlsl includes jenkins' one-at-a-time hashing algorithm but not lookup2 or lookup3 (Unity.Mathematics looks like the best solution)
@half remnant are your planets modified terrains, or trigs from code? can't remember if we went over this
if it's a terrain, this might work for you:
but if it's not a terrain that method wont work.
(something similar might though)
I mean, how does it look! I remember seeing the sharp transitions yesterday - I assume using the noise makes it look nicer?
yeah, awesome - that solved that problem heh
ahyes lol
So the shape, is it generated through code, or is it a model?
so there's already references for all the vertices - the method I mentioned above could possibly still work, if you can figure out a way to generate the equivalent of an alpha map π
for, biome identification that is
something I realized while researching solutions for the biome identification, there's parallels with people trying to make dynamic footprints based on the texture
all the methods ive seen so far use terrainData's alpha map though
which your thing does not have
if you aren't using the alpha channel for anything, and transparency is off, you could use that to make a mask
oo a better idea than setting it for the whole map, you can offset noise by a little bit and then mask based off the noise, if you wanted a thin line at the edges of biomes
so it flips it rather than sets it constantly
I mean, that method is no more hacky than the super deprecated terraindata alpha map trick heh
uh yeh, ill get an example, I use something similar in a dissolve shader to get the edges to glow
using that method would entirely eliminate the need for the shader π
but yeah, more controllable
I think astroneer does, but its just colour
oh I guess astroneer is only one planet anyways, derp
all space suited up and nowhere to go!
welp, tbh its been a long time since ive seen that game, I remember it from early, so it's probably quite a bit diff actually
im trying to duplicate astroneer's terrain this week π
I really want to be able to tunnel and dig in my game, so.. it's kind of a matter of, how long will it take, and how bad will it be
ty ty, I'll need it
Why are my Standard Unity Materials not updating when importing URP? Every other Material gets updated to the lit shader except default standard and default particles
I believe in VS it should be as simple as Tools -> Options -> TextEditor -> File Extensions and enter the extension.
I'm guessing it's because there is no exact match for particles so it's just being "safe" which means you need to manually change the shader to a suitable one. Not sure why default standard isn't but the upgrade process is not perfect by any means.
thank you
Thanks, ive already tried that. But i didnt find a way to change the default material's shader. Is it possible?
@thick fulcrum
if it wont let you, just have to create a new material and try it that way. I migrated all my particles over a year or so ago and they work fine except for a bug to do with starting them when nested in prefabs in a certain way π
Sadly I don't remember the specifics of how I changed the shader but it is possible to work around. I'm progressively moving away from the old system to the new vfx graph when I have time to learn / experiment it seems a much better system so long as you only need basic world interaction and I recommend giving that a try when you have time π
Hi everyone. Question: How do you prefer to write HLSL code? I don't like the way it is setup in VS since there is no auto-completion nor can I look at definitions of some functions.
@thick fulcrum Ok thx. I may just use the default pipeline or change the base material. it just sucks for the particles cause i have to make my own standard particles :P
@main coral yes, I hate hlsl too
I'm just a bit confused, where do I find the definition of this function:
LightingSpecular()
I get a warning about an implicitly truncated vector and I would like to fix it, but I just can't find the return type of LightingSpecular() nor the argument list
It's in URP's ShaderLibrary, Lighting.hlsl
https://github.com/Unity-Technologies/Graphics/blob/44036031309915c73d201b2657dd9cdf705373b9/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl#L30
Thank you very much π€
JetBrains Rider has good Unity shader support, auto-complete/intellisense and Go To Definition included.