#archived-shaders
1 messages · Page 36 of 1
The simplest way is probably to compare to a "ground truth" mesh
What is a 'ground truth' in this circumstance? Is that like the mesh by itself without deforming it but with still recalculating the normals?
Trying to google it but only finding confusing unclear results
If you have a mesh that matches a height texture exactly (one created from the other) then deform your mesh with the texture, you can compare them side by side
Oh deform a mesh to a height texture and then compare the procedural result, I see
I tried recalculating the normals without deforming the mesh and when its completely flat it looks correct but the version that thinks its deformed without being deformed, the secularity takes on a very polygonal look
Blender for example lets you do the same kind of deformation and normal recalculation on the mesh, using their math which I'd trust
Ill boot up blender and see how hard it is to create that comparison
I have a plane and a texture, trying to figure out how to apply that deformation now. I have no experience with blender, googling a lot
I am seeing the deformation modifiers, Ill google that, ah okay Displace modifier

I am struggling to apply the displace, and the net is not yeilding any answers
I cant move forward and debug my shader until I have this but I cant figure out how to have this
for some reason it wont show me any parameters for the displacement
You'll have to be in Object mode and then apply the modified in this tab
that does contain the params but the params dont appear to change anything no matter what value I input
I only know how to use 3dsmax but max wont deform on a texture as far as Im aware
I will keep googling
You are in Edit mode here, switch to Object mode by pressing tab with your cursor over the 3D viewport
Oh I see, interesting
After it's been applied you'd right click the mesh and "shade smooth" to automatically calculate the normals
I expect you'll want to use UV coordinates instead of local for the displacement, makes it easier to line up the texture in case the transform scales or spaces get wonky upon export
Got it to work, brought it into unity after smoothing it like you said
That is a good point, I will switch it to UV and do it again

Hm, nothing changes when I set it to local
I dont know if that means its already exactly the size of local
That's probably the case
the deformation also doesnt appear to match the texture at all
Hey, helpppppp
Ill just move forward for now and hope it works in unity
I hit a huge snag - its not possible to deform the vertexes by a texture because you cannot sample textures in the vertex step
so there's no possible way I can use this to act as a baseline comparison
XY back to square one, how do I get a baseline to compare it to 🤔
Getting frustrated that I just wasted all that time in blender only to ultimately get nothing from it, that method cannot produce a base line to compare against
looking at this again, is this what specular should look like on recalculated normals?
it seems wrong to me
if this was a normal map it would be 100% wrong
You can sample Texture2D LOD
how/why is it making hexagons where there are none
I didnt know that, Ill try to find out what that is
that worked, now to recalculate the normals for comparison
Yay! 
when I replace the procedural noise with a texture sample, the recalculation no longer works
all I did was delete the procedural noise and replace it with the texture identical in every way
but clearly not identical in any way because it no longer works
this was the old method
I ripped out everything and replaced it with the texture sample
anyone know what the object vertex position node is in URP lit shader graph?
the expected result
now its turned purple for no reason after I moved the code into a subgraph
why does debugging shaders have to be so extremely frustrating and painful
why/how does anyone rely purely on interpreting color values to debug
this is masochism
is there really no better way?
hey not entirely sure where this question belong, but how hard would it be to selectivley apply a pixelation shader to things in my scene?
Is it as simple as two cameras, one capturing only the things I want pixelated, another capturing everything but that... apply shader, and somehow mix the results back together for the output?
there are no differences so why is it magenta
I do not understand
its not magenta inside the graph
Do I need to pass in the texture ??? that makes no sense but I can see nothing eles to try
nope doesnt work
I don't fully understand how your node setup works but one thing that comes to mind is that your procedural noise used object coordinates, but the texture uses UV coordinates so maybe something gets lost in that translation
hm I see, after replacing UV with object position its still magenta though
its not magenta inside the graph
but it is outside of the graph
this is that magenta node
identical in every way
except that cannot be possible
my understanding is wrong
I am wrong
but I cannot understand how or where I am wrong to fix it
im too frustrated for this
I just want to deform a mesh and then recalculate normals of the deformed mesh
but this is proving to be impossible
I am using these nodes from this person to recalculate the normals
he says this is the only way, it is correct, it is flawless, it must work
the problem must be with my work, his work is not flawed
I copied his identically in every way so if it worked for him it should work for me but it doesnt work for me
so I am wrong
but knowing that doesnt help me become right
im starting to have an ocd melt down so im just going to close everything and give up, thats all something someone like me can do
someone please show me where I am going wrong because I am not capable of progressing until I know where is going wrong and I am not capable of fixing it myself, I need help
I have not made that kind of system or much anything of that complexity so I can't be of more help
figured this out it's just above in vertex master node
im struggling to get the two to line up now
when in blender if I set it to UV instead of local, it didnt change, so I assumed uv and local were identical
but that is not the case
You can always write HLSL... 😆
I would rather eat glass
to put it lightly
okay I think I got them to line up
now to try to recalculate the normals again
its definitely not the same
this guy's recalculate normals after mesh deformation is complete nonsense, its not even remotely recalculated
so now my XY is going even further back because literally all my work is built upon a useless incorrect lie :/
all of this is wrong nonsense bluffing to be correct it seems
I dont understand why someone would go to all that effort just to make something that isnt even remotely aproximal
his is stupidly based around animating over time so maybe the mistake is that I just adapted it wrong somewhere
he is doing all this worthless extra shit that completely occludes any possible understanding of what is important and ciritcal and what is worthless wasted computations
so frustrating when people release tutorials and assets that are bunded with all this bloat
when you google recalculating normals in shader this is the only result
it makes me feel better to blame him but I know in my heart that ultimately I am the one too unskilled to make sense of his work
Probably not identical after export, like I assumed
so I have this shader for my leaves, but instead of looking like they are blowing in the wind I am getting a weird psychedelic effect. Any ideas?
the effect:
If you distort the texture with noise rather than just the vertices, the leaves can get very swirly
If you distort it too much, the texture will slide away from the mesh UV space, and adjacent leaves will be revealed on those faces where they shouldn't
I assume that's what you mean by psychedelic effect
I think wind animations usually are done only on vertices
Probably no need to do it on both verts and texture
Is there a way to reference the ambience colour in the shadergraph?
Even if I get rid of the noise on the texture, it still doesnt look right. Sure, the weird effect is gone, but it still doesnt look like it is blowing in the wind so much as "jittering"
the bottom bar is "bugged" because Render Mode is set to Overlay and not Camera. The material is used in a Image component. Is there another way to tackle this besides changing Render Mode of the Canvas component? I want to avoid having to go back and change a few scripts.
Hey guys I require some assistance
I am trying to get a dissolve shader to come out of this object
But it makes it look like this
Supposed to look like that
Ive got this going on in the graph view
It still says its missing _MainTex
I am probably missing something super obvious so any help is appreciated
Thanks
How do I fix this issue? I feel like it can be fixed through the shader graph, but I'm not too sure how
bashing the article writer wont do you any good, just saying...
try this, it's written in shader code but I think it can be converted to shadergraph
https://www.ronja-tutorials.com/post/015-wobble-displacement/
what you might need is this vert shader code from the article, again, I think shadergraph has all the nodes needed to remake it in shadergraph
float4 modifiedPos = data.vertex;
modifiedPos.y += sin(data.vertex.x * _Frequency) * _Amplitude;
float3 posPlusTangent = data.vertex + data.tangent * 0.01;
posPlusTangent.y += sin(posPlusTangent.x * _Frequency) * _Amplitude;
float3 bitangent = cross(data.normal, data.tangent);
float3 posPlusBitangent = data.vertex + bitangent * 0.01;
posPlusBitangent.y += sin(posPlusBitangent.x * _Frequency) * _Amplitude;
float3 modifiedTangent = posPlusTangent - modifiedPos;
float3 modifiedBitangent = posPlusBitangent - modifiedPos;
float3 modifiedNormal = cross(modifiedTangent, modifiedBitangent);
data.normal = normalize(modifiedNormal);
data.vertex = modifiedPos;
}```
the basic seems similar with the article you've posted (predicting the neighboring texel to calculate normal), but I think it's easier to understand (at least for me)
Summary So far we only used the vertex shader to move vertices from their object coordinates to their clip space coordinates (or to the world space coordinates which we then used for other things). But there are more things we can do with vertex shaders. As a introduction I’m going to show you how to apply a simple sine wave to a model, making i...
You are right. I called myself out shortly after - it made me feel better in the short term but ultimately the root of the problem was my own lack of ability, not their tutorial.
I will try out your code. I was trying to get access to the full data like vertexes in shadergraph but wasn't having much success in figuring out the syntax; I kept getting undeclared identifiers
Ill take a look at this tomorrow morning first this, its midnight atm for me
i have a simple stencil shader with a stencil int parameter, but when i change it via script at runtime it doesn't work
mat.SetInt("Stencil", 1) doesn't throw any errors or anything but when i look at the object in the scene/inspector its still showing 0 for Stencil
how does the stencil block look?
Is it using transparent mode? try switching to opaque with alpha test.
Or maybe using render features and override the write to z buffer (or something)
you have to do something like
Stencil{ Ref [_Refvalue]
and then set _Refvalue with SetInt
why does this happen?
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
RenderTextureDescriptor descriptor = new RenderTextureDescriptor(source.width, source.height, source.format);
RenderTexture normalDepthRT = RenderTexture.GetTemporary(descriptor);
outlineCam.targetTexture = normalDepthRT;
outlineCam.Render();
Graphics.Blit(normalDepthRT, destination);
RenderTexture.ReleaseTemporary(normalDepthRT);
}
heres the code
Ah! Thanks for the reply! I fixed it by changing depth write to force enabled!
I've made a toon shader using NedMakesGames' tutorial as a base (unlit shader), but discovered that objects, rather than casting a shadow on the object with the shader, acts as a light source and brightens up the object rather than casts a shadow. Is there a way to make objects using the same shader cast shadows onto each other?
yeah thats what im doing, it just has no effect when i change it at runtime
_StencilMask("Stencil", Int) = 0
Stencil {
Ref [_StencilMask]
}
oh wait
just to be sure, youre called SetInt on _StencilMask right
i might be a dipshit
not "stencil"
😛
any idea how to create triangle checker on shader graph?, thank you
In Shadergraph how can I access data.vertex like in a normal HLSL written shader?
Im tyrying to adapt hlsl code into a custom function node but I don't know how to send in all the things it needs, and google is not yielding answers
All you can do is get the vertex data from the geometry inputs nodes (position / view direction / normal / color ....)
Ah so Position in object space is equivalent to data.vertex?
Yes
sorry what I meant is something like this
already try using checker but the problem is I can't adjust the "gradient" for normal
so i'm using a stencil mask and stenciled shaders to make some impossible overlapping room
how can i make it so the blue cube 2 is occluded by the mask itself?
but i should still be able to see blue cube 1
bc its "in front" of the mask
Ive re-implimented that code block, but I am not sure how to actually use it now that I have it - I dont know what frequency or amplitude are supposed to be doing, or how to take this and use it in my use case, which is to deform the mesh on the Y axis and then recalculate the normals after having done so
based on this it looks like frequency and amplitude is for their sine wave stuff
but I am not trying to do sine wave stuff
Luckily the tangent are already saved in the model data, so we can just use them. The bitangent isn’t, but we can calculate it easily by taking the cross product of the normal and the tangent (taking the cross product of two vectors returns a vector that’s orthogonal to both).
After we obtain the bitangent we create two new points that are almost at the vertex position, but slightly changed, and give them the same treatment we gave the original position.
With those positions we can now calculate the new normal of the surface. For that we calculate a new tangent and bitangent from the positions by subtracting the modified base surface position from the modified surface positions where we added the tangent/bitangent previously. And after obtaining the new tangent and bitangent, we can take their cross product to get the new normal which we then use.```
there description is saying how it works but my comprehension is not strong enough to make sense of it
way simpler. If you want the black triangles on top, just switch the subtraction node inputs up and down
doing this the mesh just vanishes entirely 🤔
no values ive tried in freq or amp do anything visible
noise in either slot does nothing
the answer is right here in my hands but I'm not skilled enough to grasp it
I dont know what i am doing wrong or how to learn how to learn
Easyest would be tp shift the uvs
hm reading the code they're doing SIN and I dont need sines so maybe I can edit that line
float4 modifiedPos = position;
//modifiedPos.y += sin(position.x * _Frequency) * _Amplitude;
modifiedPos.y += noise;
float3 posPlusTangent = position + tangent * 0.01;
//posPlusTangent.y += sin(posPlusTangent.x * _Frequency) * _Amplitude;
posPlusTangent.y += noise;
float3 bitangent = cross(normal, tangent);
float3 posPlusBitangent = position + bitangent * 0.01;
//posPlusBitangent.y += sin(posPlusBitangent.x * _Frequency) * _Amplitude;
posPlusBitangent.y += noise;
float3 modifiedTangent = posPlusTangent - modifiedPos;
float3 modifiedBitangent = posPlusBitangent - modifiedPos;
float3 modifiedNormal = cross(modifiedTangent, modifiedBitangent);
outNormal = normalize(modifiedNormal);
outPosition = modifiedPos;```
in this code block, why might the meshes vanish?
I assume they vanished because they have been offset someplace very far away or shrunk extremely small or something
but I can't see why the code would be doing that
if I dont edit the vertex positions the mesh does not vanish but the normals look very wrong
Note that you are adding the same noise value to the 3 positions, while you should calculate 3 noise values for each of the 3 reference positions
Oh how would I do that? I have to pump in the noise externally so there's no way to resample it from different positions
Then you have to re-think how you approach this.
The key point of the normal calculation method is to apply the same deformation to position, pos+tan, pos+bitan, and calculate the deformed normal from those.
I am also starting to feel like at the end of this I am going to have the exact same nonfunctional version I had before, its starting to look more and more exactly like that set up and I've already seen that that set up doesnt work, which is concerning
this did not work and its looking exactly like this
Should work 🤷♂️
I've used it in the past and can confirm it works
is the answer that its just not possible to deform vertex and recalculate the normals? because thats the dead end I keep being lead into
if you say it can be done that is reassuring but so far I have had zero success in doing it
the results I get are unusuable and unpredictable and do not match any of the examples
Ill try again from scratch but I am not optimistic
I will try to pass out the 3 modified values, and then use them on noises, and then pass that back into a new custom function to finish the output
this looks promising, I might be getting somewhere
I split the code before and after the triangulated three positions to do the noise inbetween the making and the using
Why are you using normal vector in tangent and object space ?
You should use Tangent + tangent cross normal (bitangent)
I have no idea, I was trying to interpret their code and no one told me I was wrong.
void vert(inout appdata_full data){
float4 modifiedPos = data.vertex;
modifiedPos.y += sin(data.vertex.x * _Frequency) * _Amplitude;
float3 posPlusTangent = data.vertex + data.tangent * 0.01;
posPlusTangent.y += sin(posPlusTangent.x * _Frequency) * _Amplitude;
float3 bitangent = cross(data.normal, data.tangent);
float3 posPlusBitangent = data.vertex + bitangent * 0.01;
posPlusBitangent.y += sin(posPlusBitangent.x * _Frequency) * _Amplitude;
float3 modifiedTangent = posPlusTangent - modifiedPos;
float3 modifiedBitangent = posPlusBitangent - modifiedPos;
float3 modifiedNormal = cross(modifiedTangent, modifiedBitangent);
data.normal = normalize(modifiedNormal);
data.vertex = modifiedPos;
}```
they appear to be using tangent and bitangent, is this not correct?
What should I be using if I should not be using tangent and bitangent?
You should use tangent and bitangent
arent I? I am confused now
But this, is not a tangent
I am trying to aproximate this and I dont know what data.vertex or data.normal is in shadergraph
There is a dedicated tangent vector node
what is data.normal if not the normal vector in tangent space???
someone told me that data.vertex was object space position in shadergraph, what then is data.normal?
normal vector node, in object space
making that change completely broke the normals, it looked correct before, are you sure?
I'm talking of the equivalent of data.tangent is **tangent **vector node
It is still wrong
so its just conicidence that it looks right?
yes
another reason why debugging shaders is so painful, the only way to debug is to look at its appearance and its appearance can lie
yes 🙂
awesome, thank you 👍 I would have not figured that out on my own
This looks correct, is there a way I can determine if it is correct, beyond just looking at it with my eyes?
this being deformation of the vertexes and recalculation of the normals from the deformed positions
Erm.... nothing that I can think of
Thats fair
debugging shaders is tough
Actually I just came up with one relatively easy way that could work. You can do normalize(cross(ddx(vertexPos), ddy(vertexY))) to find the normals calculated from the adjacent pixel position. By comparing those and the normals calculated by you, you can see whether you got it right. Because that way of using partial derivatives makes the normals flat shaded, you would be better to switch to a lot more subdivided mesh so it doesnt mess up the test
whoa, thank you so much.
does the concept is: since the "object space" can't be "tiled", so it's need to be divided first using fraction?
Hello, I have an issue where after the scene reloads, the shader/lighting is all screwed up. The only code I have for this is
{ UnityEngine.SceneManagement.SceneManager.LoadScene("Level 1"); }``` on the trigger object that the ball hits when it falls off the platform.
I'm an absolute beginner and am following a book on how to code this, and it doesn't say anything about this issue appearing/how to fix it.
https://gyazo.com/6f73f10709ed2b745c6c31788bc7052a
here you can see how the tiling affects the UV output. Tiling basically multiplies the uv coordinate by 5.
with fraction node, it keeps it always between 0 and 1 (each coordinate)
If I haven't tiled the fraction UV output, the preview results on the right would be all black
in other words, it's like without fraction tiling like "scaling" the object, but with fraction, it's tile the UV right?
If you have difficulties with this, you can always watch BLENDER tutorials about Node Shaders. It's the same principle, different program and quite a few different nodes
they are very popular
yeah both can be transfer to each other
what I meant is without fraction it's like enlarging a sticker on same surface but with fraction, we add (tile) multiple sticker to fill the surface
Iam looking for some kind of shader to turn white graphics into blured edges and preferably in rectangle shape
I have this but i cant seem to find what iam looking for, tried googling but dont really know how to call it
i want to achieve glow behind this portrait, where green sprite is
something like this
🌍 Bundle MASSIVE Discount 98% OFF! https://cmonkey.co/humblebundle
✅ Get FREE Assets https://assetstore.unity.com/?on_sale=true&aid=1101l96nj&pubref=unityglow
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundl...
Thanks, but trying to avoid postprocessing and trying to do like blur glow in background, dont need actual glow
aight
It's better if you test the pictures with all the different UVs with a Plane object and a Texture image. The results will surprise you.
is that planar or tridimensional? Sprite 2D or a 3D Object?
Anyone know how i can create a Unlit Graph?
It is not in the create option, i'm new to shaders so i don't really know where to look, but the tutorial showed it in the create menu
Why does my fresnel cover the entirety of the object even though it covers only the edges in the preview?
increasing or reducing power doesn't seem to do anything in that regard
Are you using normals correctly?
Anyone got anything for this one?
multiply the alpha of the sample 2d texture with noise texture first. It will ensures that the noise is only applied to the non-transparent parts of the sprite
The reason it looks cloudy is because you are setting the transparent area not transparent anymore.
Also, MAYBE (I haven't tested it) you should also change the scale of the simple noise so it fits the pixel resolution or your sprite's resolution is too big for the texture.
Is it possible to affect point lights from inside of a shader graph? I'm trying to add a clamp to avoid oversaturation when players/enemies with point light effects stand near each other.
That appeared to work perfectly! Thanks! I scaled the noise and it didnt seem to do much honestly. Now there is just this weird flickering effect but I can workshop it.
Sprite
I'm messing with stencil shaders per ronja's old tutorial here: https://www.ronja-tutorials.com/post/022-stencil-buffers/
selected is a portal mask with the stencil write shader with the mask set to 1... the red cube uses the stencil read shader with the mask set to 1, blue objects use the stencil read shader with the mask set to 0
how can i make the stencil mask portal show only stuff with the mask set to 1, but still show the floating blue cube where it overlaps, because it is in front of it?
all my shaders seem to have been destroyed for some reason after switching to 2021.3.19f from 2021.3.18f
a shadergraph i had working in the last version didnt seem to work
how can I fix this isssue?
fixed it , turns out it disabled my render pipeline asset so i added it again
is it possible to add 2 materials to one object?
like how to stack 2-3 effects on asset
If it has a mesh renderer I believe
I got like 2-3 shader graphs that create different effects
how about 2D sprites?
like if i want to make it glow and pixelate at same time
glow is one shader graph another is another graph
oh well i don't like drawing pixel so i just add a pixel shader to it lol and say to those pixel lovers here is ur pixel art
Using Sub Graph
@late terrace If you are following their tutorial, make sure you have the same Unity version and pipeline installed to see the same features.
!ban 718852952684625959 Scam
REDHOOD#1627 was banned
Even if my project is already a Work in progress? I can't really go back to previous version
But does that mean they removed the Unlit Graph?
I'm sorry for all the question, i'm very new to shaders
And shadergraph support for built-in pipeline is only on latest versions.
Thank you very much, its working all good and i can create it now, : )
why does sprite default not get affected by shadows, but my one does?
If you want it to be unaffected by shadows and light use unlit shader
Is there an equivalent to mathf.pinpong in the shadergraph? Trying to make something like the flashing of a gmod error
turning it unlit does this stuff though
In unlit shader you correct brightness yourself. So apply darker tint to match
where do i do that? sorry im new to shaders and just downloaded this. im using a shadergraph
If it's a completely custom shader you have to introduce another color and mix it in. Lookup how to tint colors in shadergraph.
or use default unlit and use its tint
Time and Sin nodes for example. There are examples online.
I did try Sin but its not exactly what I'm looking for
You'll have to be more specific then
im trying to make an outline shader though
You still need a tint color for the non-outline part
You just multiply color property and it will be a tint color
i do need the door to be affected by shadows, but i want the outline to be unaffeeced
Should have started with that then
sorry 😅
Don't think it's possible. You might push very bright or dark color on your outline to overwhelm any shadow or light. Apart from that use separate unlit material on top as an outline
can i use multiple materials?
well yes, draw outline material on top. Depending on how you have things setup. position in the world of make it priority layer or render order.
sooooooooo I have a shadergraph a buddy made for me (I have no idea how shaders do the thing) anyway, How can i use it in the project, I importet it, tried creating different shaders but i didnt see that i can put it in somewhere or how
consider other objects interaction if they also have own outline materials so they won't conflics
i can only have one here it seems tho
You drop shader on a material and use that material
You need shadergraph and appropriate pipeline installed
Consider going through this course to familiarise yourself with Unity https://learn.unity.com/pathway/unity-essentials
Hi all,
I'm having a bit of a brain issue.
I have this graph and everything is working great (dissolve shader), what I'm trying to do now is 'overlay' a colour 'on top' of the base rock texture (to make it look like the rock has ore). Using a colour at the moment but will eventually use a texture.
I'm a bit stuck on what node(s) to use to mix the two, I've tried multiplying/adding/blending but none seem to work (the base rock texture gets covered up by the black)
I made it grow up, graph is still empty
Use a Lerp, with the output of the step in the T input. A as texture colour, B as OreColour property.
You would need to install the Shader Graph package (or render pipeline the graph was made for) to be able to use a shadergraph asset as a shader.
installed all of them
from what i saw in packages
lightweight made it big, that was it
@regal stag Ah thanks. I always seem to have a weird blind spot with the lerp node. lol.
is there a way to make a stencil mask doesn't always render "in front"?
What do I need to change to make the black background transparent? The png for this sprite has a transparent background, not sure why it's black in this Shader Graph. This is a Shader Graph -> URP -> Sprite Unlit Shader Graph
You need to plug in your sprite's transparency or alpha channel to alpha input
So I have two custom functions, which both work independently
it basically does the same thing but with different math
when I try and attach both to any node
it spits out an error
I just want to use an enum to switch between them, the add node is just there for demonstration
I can't seem to figure out why
I doubt anyone can give me an answer since there isn't a lot of information, but can anyone give me some hints on where to start looking?
I'm new to GPU syntax. This should be a simple question;
For a line such as
o.uv = v.uv;
How do I mess with just the u component and leave the v component untouched. Eg.
o.uv = (0.5, v.v);
That's what I assumed would work, but it doesn't like "v.v".
Finally figured it out.
o.uv[0] = 0.5
does making shader graph shaders cause long build times?
whenever i make a build i see a compiling shader variants and it can take hours
my project isn't even very big
i only have 6 shader graph shaders
o.uv.x
o.uv.y
to mess with a specific component you just use xyz
o.uv.x = 0; //modifying the u component
@thin bear
Ah thanks man! That looks way better, I'll update my code.
I see how it's supposed to go now
In "o.uv.x", UV is the whole uv structure, and .x is one component of it
.v isn't a thing, you can do [0123], .xyzw, or .rgba
(which you choose is up to you, it's a matter of preference)
Ahh thank you. That's even more info
https://cdn.discordapp.com/attachments/497873729578336276/1080715222576275506/brokenspot.gif Anyone know why my unlit shader's spot light shadows only occur in one direction?
So very nearly done with this shader and getting it to do exactly what I need it to do but I was wondering if anyone had any suggestions on how to make it look better. ie, a better way to blend/integrate the 'ore' texture onto the base asteroid rock texture without it looking like it's just painted differently. Having a bit of a brain block on ideas.
I think that allready looks sick af. When gold is on top of a rock its often, that between these big gold pieces and the rock is a relatively thin layer of gold sorounding it
@lunar valley Aaw shucks. lol. Thanks. 🙂 I am quite happy with it, but the harsh edges on the ore bother me. lol.
You said you were using two materials, yes? What pipeline?
@meager pelican Single Material. HDRP.
1 sec......going to record a vid of it 'working'
OK, maybe check into DDXY. Track the change in color and MAYBE you can figure something.
Two textures? (I'm not up to speed here, and have to bail out soon, but somehow you need to track the changes).
Because that's what you want to change. You don't want an abrupt change of color.
GTG, have fun (looks good!)
There ya go, test vid of what I'm trying to do. 🙂
There is a weird transparency thing going on when it's supposed to be fully opaque which I need to fix, but I think I know what that is.
is this done with one shader or?
Yeah one shader.
one sec, let me stitch a few screen grabs together.
It's a little messy tbh, but top half deals with the actual texturing side of things, and the bottom half is the dissolve stuff.
The quality is really bad so I am guessing what all of the nodes are but If you wouldn't be pluging the noise into the step function you would a have a lot smoother fallof
Quality's bad? How so? Looks fine here full size.
not really sure where this would go, but in unity this is happening to my sprites
they appear to have blue on some of the pixels
of the screenshot, can't read the names of the nodes but whatever
@lunar valley Open in Browser and zoom in?
im on phone, and when I zoom its very pixelated so I can't read it but as I said its whatever
aah okay.
But yeah with the step node, if I don't do that it kinda covers the whole asteroid with the ore colour 😕
sokay, I'll live with it for now. It works, that's all that matters. lol. Plenty more to do on other things 🙂
you can "sharpen" it differently while still having smooth fallof
Disable texture compression
#🔀┃art-asset-workflow and #🖼️┃2d-tools are more fitting for this
You need to download the image to see the uncompressed version
Thank you Ill update you after
ah, ^^
I thought this worked like in whatsapp where the pictures are automatically decompressed and downloaded
Hello people. So, I have 3 images I want to use as a background / skybox. A pretty nebula, without stars, an image with a transparent background and lots of small stars and an image with a transparent background and a few large stars.
I want to have the nebula at the back, with the small and big stars layered on top, and offset the star images by different values to simulate parallax. Now, my game is like a 2D game with 3D rendering. Top down view, movement constrained to a plane, etc.
The camera is not orthographic because there will still be movement on the Z axis, mostly rotations, and some environment objects might still move "front and back" as a sort of puzzle mechanic.
I'm using HDRP.
My images are square, they tile, but they aren't skewed for a regular cubemap.
I can imagine two ways to do it.
Either making a custom shader (maybe as a graph ?) to render the nebula and stars and have the stars offset depending on a parameter, OR
simply have a large plane that's far away enough that it doesn't clip with anything else (or give it a shader with an order of -1 to render it before anything else ?) and parent it to the camera.
Which approach would be the best ? If there's a 3rd option that's better, please mention it.
Depending on the choosen approach, could you help me set it up ? (All of that is highly theoretical and I'm not sure how to implement things like custom shaders)
if your camera is orthographic you won't have 3D paralax automatically, you can also do paralax without shaders but if you want to use them you can use tilling and offset node in shadergraf to move it with the player.
Yeah, that was my plan, to use a script to move the stars. I'm not sure if I should try and setup a shader graph and a cubemap for the skybox or just create 3 basic planes and move the transform.position of the stars...
You could use a Smoothstep instead of a Step to make there more of a transition/gradient between the two textures.
@regal stag aaah, interesting. Will give that a go, thank you 🙂 ((Still learning all the nodes. lol.))
damn I thought you would have figured that when I said different smoothing methods
@lunar valley lol. Sometimes my brain turns to mush and I turn into a turnip. Especially today (dealing with Fluid Dynamics for work) lol.
Shader "Custom/Shader_Skybox" {
#include "UnityCG.cginc"
Properties{
_InvProjMatrix("Inverse Projection Matrix", Matrix4x4) = "unity_CameraInvProjection"
_WorldSpaceCameraPos("Camera Position", Vector) = "unity_CameraWorldPos"
_Cube("Skybox Cube Texture", Cube) = "" {}
}
// Eingabevariablen
float4 screenPos;
// Berechnet den View Ray für ein gegebenes Pixel im Bildschirmkoordinatensystem
float3 ComputeViewRay(float4 screenPos)
{
float4 ndcPos = float4(screenPos.xy * 2.0 - 1.0, 1.0, 1.0);
float4 worldPos = mul(_InvProjMatrix, ndcPos);
worldPos /= worldPos.w;
float3 viewDir = normalize(worldPos.xyz - _WorldSpaceCameraPos);
return viewDir;
}
// Ausgabevariablen
fixed4 frag(v2f i) : SV_Target
{
// View Ray berechnen
float3 viewDir = ComputeViewRay(screenPos);
// Farbwert des Pixels aus der Skybox-Textur auslesen
fixed4 color = texCUBE(_Cube, viewDir);
return color;
}
}
can someone tell me what my problem her is? because i just include a header there. its standard lib for unity right?
You're mixing up the shader file ShaderLab syntax (Shader, Properties, Pass block) with the actual CG/HLSL code which should be put inside a CGPROGRAM and ENDCG tags for Built-in RP. Can see some examples here : https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
thank you
How can I allow backface culling? I heard I need to create a new shader (best to copy from Standard) and apply it via code. However I have no real idea how to do that quickly
I have nodes that make a hex grid and nodes that return a random color based on the object's position, but I would like to combine them so that every hex cell has a random color
I know that what I need is for every cell to be exactly one value across the entire cell, but I am not sure how to get that from what I have
if there is any variance in value then the randomize will randomize the color for every individual pixel which is not what I want
this is the end result I am trying to get - this person however every single hexagon is an individual game object, in my use case its one single flat plane
its easy to do if it were individual game objects like that, but since I have a flat plane I need to adapt it for that but am not sure how 🤔
I do have the SDF of one single hexagon but I am not sure if that approach solves what my current grid can't do 🤔
@tight phoenix How are you generating the colours currently? Can we see the far left nodes fully (the ones that feed into the Hex Lines Group)
Sure! https://www.youtube.com/watch?v=hc6msdFcnA4 It's followed from this tutorial and is somewhat extensive. I imagine it can be simplified or made more efficient with the use of the SDF.
short version: UV coordinates are spun and fractioned and other maths to shape them into hexes
Okay, well bare in mind that I'm still learning this stuff myself, so I may be way off. But I think in the 'BGR Repeating Grid' is where the colours are getting defined, I'm not entire sure how to go about it, but I would think that you need some sort of randomisation of colours maybe after the last Power node in that Group would be needed before feeding into the Initial Grid group?
Looking at it, I'm not really sure how to get rid of the repeating pattern though. 😕
Yeah its tricky. I have not had much luck since, I started to look into Custom Function node sollutions to do some of the heavy lifting math but it mostly just made janked out static or broken pink black checkerboard
If it were game objects I would pump the game object's position into a randomizing function and return that to adjust its color
but since its a texture not objects, I would need every hex cell to be filled with a single value to do the same
but I can't figure out the math to procedurally build a hexagonal tiling pattern filled with all a single value
in the circled step here it will have made a tiling pattern of rhombuses that are filled with a solid value of 0, 1, 2, etc as it moves off into the UV distance
but I am not sure how to then turn that into hexagons while retaining its behaviour 🤔
thinking visually, I need to map the U and V gradients into hexagons somehow and then combine them as the input into the random color node I have
but like, do it right and with math, thats just an example sketch drawn badly
Isnt the result just texture coordinates rounded to the nearest hexagonal grid origin? This could be helpful https://observablehq.com/@jrus/hexround
👀 Mh yes this does seem to be what I am looking for. Will read through this and try to adapt it, thanks 👍
guys can anyone explain me something, i wanted to make this leaves of the tree fade out the transparency when the tree comes close to the camera, what is a good way of achieving this effect?
Is there a way to completely turn the environment black and just turn one mesh white
Much like this
I kinda wanna add this effect when i slash some enemy
yes there is, many infact
some way I can think of
A. using camera replacement shader to override the person shader (to white) and the rest to black (easier in built-in pipeline, gives headache in urp)
B. using camera culling layer to exclude the background from the player, then shade the character white
C. using stencil, again, it will be more elaborate if you are using urp
the easiest way to shade the character white is using emission channel
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_MyFloatArray ("My Float Array", Float[]) = 1 2 3 4 5
}
//
uniform float _MyFloatArray[];
Can somoene help me find the correct syntax for this, I'm inside a unlit shader, so I can't use computebuffers.
You cannot declare arrays in the property block afaik. You should be able to declare a const array like:
static const float _MyFloatArray[] = { 1, 2, 3, 4, 5 };
I don't want to predeclare it, I want an array that I can set trough the material
You don't need to put it in the Properties section
the properties block is for the inspector
oh
and you won't be able to use the inspector, you will have to use code
so just this will work?
uniform float _MyFloatArray[];
I'm pretty sure you have to declare the length:
float _MyFloatArray[5]
can the length be a variable?
The length is fixed
but you could choose to make it a max amount and only use part of it based on a variable
Property (VectorGraphicMaterial) exceeds previous array size (206 vs 4). Cap to previous size. Restart Unity to recreate the arrays.
UnityEngine.Material:SetFloatArray (string,System.Collections.Generic.List`1<single>)
This means that I have to predefine the size?
Yes. As @vocal narwhal already said, you have to define it as a max-size. The size has to be known a compile time, for shaders. That's for an array.
But you can use a compute buffer, and declare a max_size int variable of some name, and then create the compute buffer in C# and set the max_size variable there too, and then pass both the compute buffer and max_size variable to the shader.
oh you can use a compute buffer on unlit shader?
Yes. It's just a buffer, nothing to do with lighting.
You can declare buffers in any shader, it's a tool like anything else
Unless you code it to impact lighting, that is.
The only thing is whether or not you have a compute compatible platform, which excludes low-end mobile
The workaround for that is generally to just use a texture
yes I did that before, but it's kind of a pain in the ass using a texture for storing data
You might investigate CBUFFER storage for static data that doesn't get modified by the shader (is read-only). But again, check platform compatibility and limitations.
seems as not even my onboard graphics card supports it
so using a texture as a stroage is gonna be my best choice?
I have a very basic shader in BIRP that is used as a sort of always on top shader. When applied by default it just renders unlit white. When I transfer it to URP, it doesn't give any errors, but objects render fully transparent. Would anyone have an idea if some of this isn't supported in URP?
SubShader
{
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
ZTest Always
Cull Off
Fog { Mode Off }
BindChannels
{
Bind "vertex", vertex
Bind "color", color
}
}
}
The Bind syntax I'm not familiar with so that might be it
Alternatively help me decode this. Is the shader just using some shortcuts to set up a vert shader pulling the vertex color and applying it directly?
Actually it does render but only when there's another object overlapping with it 🤔
If I remove ZWrite Off then it behaves like in BIRP... So I guess this behaviour is different in URP
Not sure why it acts differently in built-in but to clarify, what's probably happening here is the skybox is rendered after the opaque queue, and because the sphere doesn't write to the depth buffer the skybox renders over it.
So would need ZWrite to be On, or specify Tags{"Queue"="Transparent"} so it's rendered after the skybox. (I imagine it would also need to be in the transparent queue to make Blend work correctly)
That makes a lot of sense. Setting it to transparent queue fixed it. Thank you so much for explaining
Are there any differences between Vulkan and DX11 when it comes to either structured compute buffer access or SampleLevel in compute shaders?? I have an issue where my shader will either have something written to it incorrectly or it reads something incorrectly and I can't quite figure out what. It works perfectly in Vulkan but it's broken in DX11.
The only thing that I could even think of was whether there's some difference between how either handles clamped samplers. I typically have to do -0.01 on the texture size division as I sample a texture or it will return an incorrect value.
second half is DX11
or maybe the async write is causing data loss?? but would that matter for a compute shader? maybe i should switch to another buffer write mode
also has BeginBufferWrite been removed? It's listed as an option for dynamic buffers but it doesn't seem to exist
It works in DX12 it seems but not DX11.
how do i create a skybox in unity trough rastarization do i have to program something in shader?
Can you describe in more detail what kind of result you want exactly
hmm so my task is to create a skybox end then create a plane in front of the camera so that i can apply shader in every pixel so i get the same image as on my skybox so that i can compare the values on my plane with the values in the skybox. I want to check if my rays are correct or not.
i hope thats clear what i mean
Rays?
like light rays
Shader "Custom/Skybox6" {
Properties{
_FrontTex("Front Texture", Cube) = "white" {}
_BackTex("Back Texture", Cube) = "white" {}
_LeftTex("Left Texture", Cube) = "white" {}
_RightTex("Right Texture", Cube) = "white" {}
_UpTex("Up Texture", Cube) = "white" {}
_DownTex("Down Texture", Cube) = "white" {}
}
SubShader{
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
samplerCUBE _FrontTex;
samplerCUBE _BackTex;
samplerCUBE _LeftTex;
samplerCUBE _RightTex;
samplerCUBE _UpTex;
samplerCUBE _DownTex;
struct Input {
float3 worldPos;
};
void surf(Input IN, inout SurfaceOutput o) {
float4 frontColor = texCUBE(_FrontTex, IN.worldPos);
float4 backColor = texCUBE(_BackTex, IN.worldPos);
float4 leftColor = texCUBE(_LeftTex, IN.worldPos);
float4 rightColor = texCUBE(_RightTex, IN.worldPos);
float4 upColor = texCUBE(_UpTex, IN.worldPos);
float4 downColor = texCUBE(_DownTex, IN.worldPos);
float4 finalColor = (frontColor + backColor + leftColor + rightColor + upColor + downColor) / 6.0;
o.Albedo = finalColor.rgb;
o.Alpha = finalColor.a;
}
ENDCG
}
FallBack "Skybox/Cubemap"
}
do someone know what i have done wrong? because i dont get any errors and i cant put any pictures in the inspector window
You've declared the texture properties as "Cube", for cubemaps, is this intended ? (so the inspector expects cubemap textures, not 2D textures)
yeah because i want to use it on a cube
If it is intended, then it expects you to assign cubemap textures, and not regular 2D ones
ok i changed it to 2D thx
Howdy folks. I've been learning the ShaderGraph to make fun effects for my 2D game, but haven't discovered if there is a way to modify the impact of how URP point lights interact with the materials. Specifically I'd like to put a clamp on how much they combine, to prevent oversaturation during events when multiple lights overlap in the scene. Just wondering if anyone has a moment to help me understand if what I want to do is feasible?
since updating to 2022 unity render target handle is now switched to rtHandle but my friend getting errors in
Blit(commandBuffer, source, tempRenderTargetHandle.Identifier(), material);
the "tempRenderTargetHandle" no longer have an .Identifier() to it
what is the switch to make it work
It should work if both source and tempRenderTargetHandle params are RTHandles. .Indentifer() is not needed.
Why can't I manage to write data to a dynamic compute buffer with .SetData when BeginWrite works just fine with a SubUpdate buffer? Is SetData more finnicky about "blittable types"? I have a struct with 3 uints in it which works fine with BeginWrite.
I tried both a normal type array and a native array but neither works.
in the shader "source" is a RenderTargetIdentifier
Even changed to a uint buffer and nothing
You need both params to be the same type. Either stick to RenderTargetIdentifiers and ignore the deprecated warning, or swap both to a RTHandle. This might provide an example : https://github.com/Cyanilux/URP_BlitRenderFeature/tree/2022.1
Is it possible to add a shader to a light 2D?
Hello!
I am trying to make some portal stuff using URP, Render Features and Stencil buffer, and I have a question:
On image 1, the portal is functioning correctly, displaying the blue cylinder correctly, since it is after the portal.
On image 2, the cylinder is between the camera and the portal, and yet, with the cylinder being rendered after the stencil, it still shown within the portal.
Do you have any Idea what I could try? Thanks!
(Image 2 but without the stencil effect for more clarity)
I got it working doing
computeTileDataBuffer = new ComputeBuffer(mapSize.x * mapSize.y * mapSize.z, ComputeTileData.SizeOf());
instead of
computeTileDataBuffer = new ComputeBuffer(mapSize.x * mapSize.y * mapSize.z, ComputeTileData.SizeOf(), ComputeBufferType.Structured, ComputeBufferMode.Dynamic);
??? Why is this significant? I thought it was supposed to be dynamic
So it has to be Immutable I guess??
why doesn't dynamic work??
i made portals a while ago and instead of using stencil buffers i use this shader applied to object displaying render texture from camera
^ to somewhat add to the above. If I understand the problem correctly using a render texture would have the same problem.
But one advantage of that method is that you can edit the projection matrix of that second camera to be oblique, meaning it's near clip plane can be at the portal plane and any objects infront of the portal are clipped. If you don't want to use a second camera, might still be able to edit the projection matrix in a custom renderer feature (and reset it after rendering the portal objects).
An alternative could be writing a shader that adds a clipping plane. e.g. https://www.ronja-tutorials.com/post/021-plane-clipping/ (will need to translate to URP / shader graph). But means every object needs to use that.
Thank you @amber hollow @regal stag ! This is to be used in VR, so I think a renderTexture might not give the best result (with both eye, etc), but a clipping plane might help, I will look into it, thank you!
What? I think you might have a misconception of shaders
I'm thinking there may be a way to optimise my shader code: I'm rendering a tornado funnel (essentially a curved cone) and using a 3D noise texture to vary the density and shape of the cone. I'm thinking a 3D texture may be overkill, and there may be a way to combine multiple 2D textures?
float3 samplePos1 = float3(samplePos.x, samplePos.y, 0);
float3 samplePos2 = float3(samplePos.z, samplePos.y, 0.5);
float3 samplePos3 = float3(samplePos.x, samplePos.z, 0.9);
float4 rawSample1 = _shapeTex.Sample(sampler_shapeTex, samplePos1);
float4 rawSample2 = _shapeTex.Sample(sampler_shapeTex, samplePos2);
float4 rawSample3 = _shapeTex.Sample(sampler_shapeTex, samplePos3);
float4 rawSample = rawSample1 * 0.333 + rawSample2 * 0.333 + rawSample3 * 0.333;
float shapeOffset = dot(float3(rawSample.x, rawSample.y, rawSample.z), float3(shapeCoefs.x, shapeCoefs.y, shapeCoefs.z));
This sort of works but at certain angles you can see the repetition in the pattern
Hello dear ShaderMakers, i'm a total noob in this matter !
I have a flying enemy with wings that render fine with the standard double sided shader.
For rendering and optimizing purpose, I have a custom shader that is based on the standard shader and the cutout effect works fine. Except i needed it to be like the standart double sided, because only one side of the wings is rendered. Can you help me ?
You could flip the normal in fragment stage if it's a backface
Or it might be more performant to skip that calculation and just duplicate the wing geometry with flipped normals in a model editor
Is it possible to apply a shader to the texture of a SpriteLight2D?
noob question: how do i stop background sprites from being rendered in front of foreground sprites
i'm not using sprite renderer. i'm using mesh renderer
I'm dying
nvm i figured it out. hell yeah
i enabled material overrides in the shader and set the surface type to opaque in the surface options. then i disabled alpha clipping
So I'm trying to make a tree and followed a tutorial
Multiplying the alpha input with a float doesn't make it transparent and completely ruins the whole thing, how would I fix this?
You're not "multiplying the alpha input with a float", you're outputting alpha directly to the alpha value at the fragment stage. And it looks like you're using alpha clipping with a threshold of 0.5, a good thing. If your alpha values in your texture are correct, the black areas will be clipped.
And from the image you've shown, it looks like they ARE clipped.
So I don't understand. That's a nice looking tree so far, BTW.
There's some slight black around the edges. Might be due to how you're sampling the texture, or some blurring/anti-aliasing going on somewhere.
I mean, I tried multiplying the alpha input with a float and it didn't work, and it's not shown in the picture above because I deleted it for that reason.
What I need is for the entire leaf section to appear more transparent than it already is, while keeping everything else intact including the clipping, color shade, and whatnot.
ENTIRE leaf transparent? Like cellophane leaves?
OK, well, that's different. Alpha clipped shaders are generally done in the opaque queue, and I suspect that's what's going on here.
Try moving to the transparent queue.
But if you do that, you may have to do a discard/clip operation in your shader if there's nodes for it. Testing the value of the alpha against some threshold. Or do a conditional that sets alpha to zero for the pixels you're excluding.
You know, so you can see through the leaves when the player walks beneath them
Well, you might be talking about an entirely different effect...distance-to-player screen space dithering.
you want to know what is between the camera and the player, and dither it/fade-it out somehow, depending on how you want it to look.
something like this?
https://www.youtube.com/watch?v=rVeS7oh3oug
A follow up to the previous tutorial, I show you how to use dithering in Shader Graph to fade out meshes when they are close to the camera.
Previous Tutorial
https://youtu.be/iTlSwQ4b-uM
(づ ̄ ³ ̄)づ ~(˘▾˘~)
TWITCH ( ͡° ͜ʖ ͡°)
https://www.twitch.tv/PabloMakes
TWITTER (ಥ﹏ಥ)
https://twitter.com/PabloMakes
₪ ₪ Time Stamps ₪ ₪
00:00 - Int...
I created this texture.
Texture2D myDataTexture = new Texture2D(count,1,TextureFormat.RGFloat,false);
When I upload it to a shader, it seems to have negative values when being read in following manner
//Inside the shader
float2 pointA = tex2D(Points_t, index2).xy*32768;
Does someone have a clue, why this is happening?
I have used a shader to make this card design. Initially I put it on a Sprite Renderer and it worked fine but now I switched to an Image because I want to keep the cards as canvas elements. However, instead of being transparent on the sides, it is showing as black. What can I do to make it transparent?
What type of material do canvas elements use? Currently the shader for the card is set to Sprite Custom Lit
Or does this not have to do with the shader but with the canvas settings?
Hi! After a lot of time I created a toon shader based on many tutorials and articles online. The shader perform as expected on everything, but it doesn't work correctly mixing the main light and additional lights. Here's what happens:
When I turn on the light (as in this campfire) the light changes the color of the objects too much, and it also sets them black if the intensity is low.
As you can see from a very low intensity light, the color almost turns black.
I figured out that there had to me some multiplication between the lights in the shader, and I found it:
But turning that multiplication into an "Add" function doesn't fix the black light. It fixes the color (the orange light only adds a bit of orange to the objects) but when light intensity is low, the light is still black.
Any clue on how to fix it? The shader is also pretty big and I don't know if sharing it all can be helpful.
With the "Add" function it seems like every value less than "Intensity 1" decreases the light in the nearby objects, while intensity 1 does abnsolutely nothing
Pass
{
StructuredBuffer<float2> Points_b : register(t0);
}
C#
{
ComputeBuffer buffer = new ComputeBuffer(count,sizeof(float)*2);
buffer.SetData(data);
VectorGraphicMaterial.SetBuffer(name+"_b",buffer);
}
//Does someone see why all the values in the shader are then equal to (0,0)
Okay that's perfect, I'll have to wait a few hours until I can go back and implement it but thanks a ton
No, but use a debugger and do the obvious things first, like verify that variable "name" = "Points" and that variable data is of the right type and contents.
Also, did you set the buffer on the right material instance? Verify the instance against the instance on the object's renderer.
Zero values coming in are suspiciously like uninitialized/default data.
Hello I'm trying to use this https://github.com/fuqunaga/MirrorReflection to create a plane acting as a mirror. But it is not compatible with URP so I'm trying to use the same script that builds a reflexion texture, and create my own shader graph that renders this texture to my plane.
It doesn't work, nothing is rendered. I supposed that the built texture is available from the shader graph from a _ReflectionTex variable but maybe it is wrong. Could you please tell me what is the problem ? Here is my shader graph:
Are shader debuggers a thing?
I meant C# debugger.
But yes, shader debuggers exist. Research PIX (DX12) and Visual Studio (DX11) and also see the options for vendor-specific debugging tools for your particular make/model of GPU. The vendor tools are the most painful to get set up and use, but also the most powerful for analysis/debugging.
See also: https://docs.unity3d.com/Manual/SL-DebuggingD3D11ShadersWithVS.html
Hey, I have problem when building the game. It throws error about Nature Renderer Shader?
How can I solve this? what can be the problem.
It worked perfectly fine, but now I cannot build the game
When I click on the error message on console:
Hey, I have some code that uses graphics.drawneshnow and a lot of GL.Vertex etc. I’m using the unlit color shader and setting the color property and calling setpass to change the color. I think setpass is causing a little extra overhead but I can’t figure out how to use gl.color instead. What does the shader need to look like for gl.color to work?
Hmm, I’ve used BindChannels in my shader and it works when drawing lines directly, but not with Graohics.DrawMeshNow
Hi! I'm trying to make a shader to pixelize my 3D player, but not the environment, because that's already pixel art. How would I do this with shader graph? Everything I've seen keeps applying to the whole screen or it just isn't viable.. I'm relatively new to shaders so please enlighten me! :D thank you!
I dont think there is any way to do that in fragment shader alone, given a fragment, theres no way to know how the pixels near it will be colored so getting the color at the pixelated pixels origin is impossible. Easiest way that I can think of is to render the character into separate render texture and render that using a sprite that has shader in it that pixelates the texture
how would i do that, keep the alpha of the background, and then place it exactly where the player is supposed to be on screen?
I tried something like that but it kept the background instead of having transparency, and I also couldn't figure out how to make the pixelized version appear where the player is normally on screen.
The positioning should be relatively easy to solve using some math, aspect ratios and field of view of the cameras should be pretty much all you need to place the sprite correctly
Alright.. But how would I get the camera to output the render texture with a transparent BG?
Currently it is just black
aha! apparently post processing makes it keep the background for some reason!
Thank you!
Hey everyone! I was wondering if anyone knew how I could make an outline for sprites with bones in 2D, I searched online but can only find something that would work with a sprite changing shape
Bonus point if you know how I could make it pixel perfect
Theres some good shaders on the asset store @hazy sage
Ive seen some good free ones before
I searched for "2D outline" and only found 3 free ones that have nothing to do with outlines xd
What do I have to search for exactly?
pixel outline is what i would try
None are free, only one is an actual outline, and it only works with "fixed" sprites
The All-In-One sprite shader on the store has outline support, among a ton of other useful sprite effects.
If I wanted to create this type of effect where the wall disappears between the player and the character. Is a shader the right way to do this?
Is there a Texture Format which has 3 channels which can store floats?
I'm looking through this list, https://docs.unity3d.com/ScriptReference/TextureFormat.html
and there's 'RFloat' , 'RGFloat' , 'RGBAFloat' but no RGBFloat
There is a RGB9e5Float, but I am not sure it's what I want (I'm new to shaders)
Is there such a format available?
Probably not, because hardware likes to have things aligned in certain ways. Just use RGBA if you really need it
Looks like there's some RGB Float types in GraphicsFormat (e.g. R32G32B32_SFloat). Maybe can use that instead?
https://docs.unity3d.com/ScriptReference/Experimental.Rendering.GraphicsFormat.html
In this specific case, as the walls are very jagged I'd say probably not. They're likely modelled in two parts, with the top section disabled (perhaps with a fade/dither animation)
But you could use shaders if what you need is a bit simpler, like cutting the wall at a certain Y level (perhaps + noise, might give a similar result to this)
Thanks. I'll see what I can do with that. In my head I thought it would be easy to make that effect were I could have a wall and then have a shape that would "cut out" the wall almost like a boolean effect in blender as I rotated the camera around the room. But its turned into a few days of trial and error with not much progress. I looked at stencil buffers and a couple "transparent shader" tutorials but nothing has really giving me this effect. I should just make the whole scene with a static camera and just have a cut out like in the game.
Hey artists,
Is there a way to make a shader that apply a overlay texture on top of everything it collide with, I want to make some kind of growing moisture for my game but I searched for hours and don't seems to find something
Thank you !
Guys
i need help , im porting a bunch of shaders to unity from shadertoy
there's this one, that when i do this
it acts like this
i want to make it show , regardless of what distance is
or increase the distance
um... so what's going on here? where is the shader from shadertoy? is it fullscreen quad or something?
this is the shader
i want to navigate thru with VR
but to do that, i have to fix this render issue that it hides when you go high
i found where the flaw is, render , but removing it bugs everything lol
@dim yoke
i can send my conversion so far in dms so you can check it out
Mesh bounds do not automatically update to match GPU deformation, which can cause it to be culled prematurely by frustum culling
yeah, im a newbie with this stuff
sorry
i also got a few shaders that i want to be able to walk around, and not get a static animated shader
Anyone got news about this?
can somebody teach me how to fix these shaders?
I haven't seen any sprite outline shaders that don't rely on the geometry not deforming, but assuming there aren't any you'll have to apply non-sprite outline techniques to your characters
https://alexanderameye.github.io/notes/rendering-outlines/
Even sprites are 3D meshes so the process might not be all that different, just make sure to account for transparency
hey, could anyone help me with changing the color of the texture? im trying to combine the color property with the sample texture 2d but it doesnt work because it reverts to white in the add node. How do I change the color of the sample texture 2d or fix this in general? Please have patience with me as Im very new to shaders
looks correct to me
Im assuming perhaps mabye you want to modify the texture by "multiplying" it by a color instead of adding a color like you currently are doing?
and in that case, just swap that add node for a multiply one
thanks, will try that
works! thank you very much
Would anyone have a reference to a shader that can replicate a Sims 1 style z-buffer fake depth sort? In essence I would like to discard pixels of my character sprite, based on a custom depth map in the shader. Seen in this image. These are 2D sprites, but they appear to interpenetrate like 3D geometry and this is due to the use of a custom depth texture.
And in a more modern game, here is Project Zomboid doing the exact same thing for their game. 2D sprites that sort fake depth based on a texture map gradient.
It's a low poly model, so i just added a " Cull Off" and now it's working 🙂 thanks for your advice about modeling, i keep that in mind for performance purpose
That's a quick way to do it
Just note that if the material is also receiving light, only the front face will be considered and mirrored onto the backface
Quick way is my way 😉 solo dev' and nothing released right now :p
I would assume it falls under the Append type, based on the description https://docs.unity3d.com/ScriptReference/ComputeBufferType.Append.html
I am doing vertex deformation and then normal recalculation and I am experiencing an issue that I am not 100% sure what the cause or sollution is
as pictured, object surface vector is black on that side edge, but green on the deformed height bit
as far as I am aware that back part should be the same color yeah?
visualizing it from other angles, it feels like too much of the original flat surface color is being used maybe?
but I am not sure 100% where the problem occurs or how to fix it because this normal recalculation is a massive ammount of code and nodes to achieve, all of which I was given rather than coded myself
I am noob, but did you consider light impact here ?
I don't think its a trick of the light but Ill set it to unlit to be sure
yeah its not just the lighting
HM when the noise is a smaller scale, its only happening at the edges
the inner parts are dark as should be expected
so I must be doing something wrong with how I tried to naievely not use this effect at the edges
the mask I am using to only deform the verts I want (lightened to show verts)
I am just lerping between the calculated bit and what it normally was, but that clearly isnt doing what I think it should do or what I want it to do
Seeing this i see no bug, colors repartition match the normals i see. I have a problem (because of english maybe) to understand what do you want to achieve here : you want the edges t be what color ?
The problem I am trying to fix is that the specular highlights look wrong, the color is just me trying to debug it
the inner part looks right but compare the inner part to the outer edge, the specular is all janked up
thats what im trying to fix, and to fix that I must fix the normals, and the normals are what I was visualizing in color
How do you calculate this mask? Perhaps for the normal you could use a mask with a harsher edge rather than having the gradient
its a hexagon SDF, the reason I chose soft edge was I need the value close to the edge to be zero, but not create a harsh cliff edge
I need the outer area to smoothly transition to flat so that it doesnt create a ram-rod straight edge vert wall
the more we discuss it the more I think I am using my mask wrong in some way
I'm not sure if it's "wrong" using the lerp, but you could try multiplying the mask with the amount of displacement instead (I guess noise1, noise2 and noise3 in this case)
no mask showcases the problem I am trying to solve
besides that it also affects the outer polygons, but it also creates openings, and I don't want vertical walls anyways so its not just a matter of fillling the gap
I thought of that as well actually but that didnt work either
what is pictured above is doing that, that was the first sollution I tried, getting rid of the Lerp and multiplying the noise by the mask
That's odd, because it looks like it's still being displaced there
What is 'it' in this circumstance?
The vertex positions I mean. Displacement is usually something along the lines of vertexPos + float3(0, height, 0)
If the mask contains values of 0 on the outer edges, then height * mask would produce 0 for those edges and there shouldn't be any displacement
https://cdn.discordapp.com/attachments/497874081329184799/1082059604223074417/image.png Yes thats what is occuring here
if you are refering to this image, this was the image with no mask
I don't think I am communicating what I mean or understanding what you mean well
here is the mask applied Step not Smoothstep
the back part should be black but its not black because its recalculating the noise at that spot as if the noise is continuing and not clamped off like I am doing 🤔
and me lerping with the 'actual' normal is the flat upper face green normal 🤔
and not the black normal that it should be recalculated into
I think im starting to see why its wrong but I am not seeing how to fix it
the mask must come much earlier, but where
doing the mask immediatlely after the noise pattern should be the answer???? but that didnt work, it made no difference
The mask currently is going into these Hex Terrain Noise Calculation subgraphs. Is it being used there?
not currently because I took it out to debug why it wasnt working, I will re-add it to where it was, which was multiplying the noise
here is before I moved the code into a subgraph because it was just 3 copies of the same thing
the mask was multiplied after the last step before going into the calculator
Mask being multiplied into immediately after the noise
I fear I am just too stupid to play telephone like this, you are so skilled that if I just link you the graph you could find what I am doing wrong in 10 seconds flat 🔥
but that doesnt help me grow and learn and not make the mistake in the future
I'm not so sure, I'm a bit stumped too 😅
the answer is going to be that im a stupid idiot who assumed something somewhere, assumed wrong, and ruined it
Sorry getting frustrated, will keep my language neutral
the shader as is is currently hacked to piece because im desperately trying to debug it
this is not the X or the Y or the Z this is like 15 steps removed from what im ACTUALLY trying to fix and do
but I cannot get to any of the things I ACTUALLY want to be doing because every single fundamental thing is completely #$@#^@ broken because I don't know what I am doing
yeah im not able to remain unemotional, closing discord
mark my words the problem is that I made a stupid mistake because I'm #$@#^ stupid, its NEVEr unity thats wrong, its always me who is wrong
Old video using shader forge, but using partial derivation might work for you.
You might get away with using ddx ddy functions (ddxy) to track WSposition changes, and do:
float3 posddy = ddy(IN.worldPos.xyz);
float3 normalWS = normalize(cross(posddx, posddy));
partial derivative solution may not be what you want to use for the final result but as I said earlier, they could be good way to debug your normals to see whether they are correct or not
@dim yokeSorry if I duplicated, I probably missed something in the posts above. I skimmed.
Also one thing to check is if you're needing and getting worlds-space normals vs tangent-space normals.
Guys, I'm a total noob at shaders. What can I do to make the sphere around the ammo more interesting? Or should I leave it as is?
well it was about week ago, just saying that partial derivatives may not be what you want as they only produce hard shaded normals (but they could be good way to get "correct" normals to compare against)
I mean should I just remove the circle and leave the outline
that is what I am doing already, the problem is coming from the mask and not the calculation as far as I can tell
@tight phoenix Okay... I think I've figured it out. I compared it to other methods and they were also quite green actually. It's really not far off so was difficult to debug. But I'll try to explain what I think the problem is :
The way this normal reconstruct technique works is simulating the displacement from three points, the vertex position and two nearby points, offset in the tangent and bitangent directions. To get the correct result, it's important that any displacement calculation is replicated for each point separately and must use that point as the input. (That's why you use a subgraph, generating the noise multiple times with each point as the input)
But currently when you calculate the mask, you're using the Position node. That's only correct for that first point. You would need to duplicate the mask calculation with "outTangent" and "outBiTangent" as inputs. The output of those would go into the corresponding Mask input on the Hex Terrain Noise Calc subgraph.
(Or like, move the mask calculation into that subgraph and use the Position Vector property as it's input. Probably easier)
Also inside that subgraph, move the mask multiply to the end (after multiplying by height)
Looks fine and really all I would suggest outside of what you got is adding continuous rotation so it looks more interactable. As far as shader improvements, maybe some outlines for the pickups to further increase the visibility.
look fine with or without the circle? Also, I added rotation (of the individual meshes) but it literally cannot be seen. I also tried rotating the entire groups but I think it kinda looked stupid
readin this now 👀 took time to de-stress, clear head now
I see, that makes sense. I will replicate the mask three times
I have a camera and have set its mode to DepthTextureMode.Depth
How do i get this texture in my shader for this specific camera ? its not the main camera
i dont follow how that lets me get a depth texture from a specific camera in my material
OK, let's clarify your question. If you have two cameras, CameraB and the MainCamera, you've set the depth texture mode on CameraB to be DepthTextureMode.Depth.
Now you want to "get this texture in my shader"...
Where is "your shader" running? Under CameraB or under MainCamera?
its shader graph
i assigned the RT to material.mainTexture in Awake in C#
and also to camera B target texture in Awake
now i try to render this texture in SG to my mesh and its all black
IDK what objects are rendered with what camera.
I'm thinking that you want access to that CameraB-RT from your MainCamera's rendering pass.
the two cameras dont know about each other
That's why I posted the SetRenderTarget info.
this is what i basically tried:
private void Awake()
{
transform.localScale = new(_range * 2, 0.01f, _range * 2);
_camera.depthTextureMode = DepthTextureMode.Depth;
_camera.cullingMask = gameObject.layer;
_rt = new RenderTexture(_camera.pixelWidth, _camera.pixelHeight, 24, RenderTextureFormat.Depth);
_rt.filterMode = FilterMode.Point;
_rt.wrapMode = TextureWrapMode.Clamp;
_camera.targetTexture = _rt;
_material = GetComponent<MeshRenderer>().material;
_material.mainTexture = _rt;
Render();
}
private void Render()
{
_camera.Set(_angle, _range, transform.position);
if (_rt.width != _camera.pixelWidth || _rt.height != _camera.pixelHeight)
ResizeRenderTexture();
_camera.Render();
}
What pipeline?
Usually to access a depth texture on a camera for a shader running under that camera you would declare a texture in the shader:
Depth textures are available for sampling in shaders as global shader properties. By declaring a sampler called _CameraDepthTexture you will be able to sample the main depth texture for the camera.
_CameraDepthTexture always refers to the camera’s primary depth texture. By contrast, you can use _LastCameraDepthTexture to refer to the last depth texture rendered by any camera. This could be useful for example if you render a half-resolution depth texture in script using a secondary camera and want to make it available to a post-process shader.```
https://docs.unity3d.com/Manual/SL-CameraDepthTexture.html
The engine will "hook it up" to your material.
But if you're trying to access the depth texture from CameraB while having MainCamera also use that texture, that can be more complicated.
Shader Graph will declare that _CameraDepthTexture automatically if you use Scene Depth node, AFAIK. But if you want to use that texture from the other camera, make sure that the camera you're running under is in overlay mode so it "inherits" the texture, or that you've assigned the right texture to it.
URP - what do you mean by hook it up
how does the camera know which material and vice versa
The object and its material are rendering under a camera at any specific moment. It's a render context bascially.
CameraB does not use the same texture as MainCamera as they are not related at all basically CameraB is just to generate a depth texture from the perspective of an NPC's vision
then i want to use that result in his shader for a field of view effect
which is a per npc situation since they have different fovs
OK, so you don't need it assigned as a depth texture for main camera?
indeed _camera in my script above is my second camera
not my main camera
i linked it in the inspector
OK, and is this script on the main camera or on the other camera?
IDK that you can nest camera.Render() calls inside each other...
no its not on the main camera object
im not nesting
_camera.Render() is from type Camera thats unity the script above is my custom script
this is how it is setup atm
IDK, then. You should be able to assign the texture as input.
However, you may have to decode the depth info.
yeah you mean the linear01 stuff
Hi! Is there a way to get the ambientIntensity in a shader graph?
yeah
I created a day/night manager which uses both ambientColor and ambientIntensity to change colors for the twilight, morning and night. The color was then applied in every shader simply multiplying the ambientColor with the rest of the graph output. The problem is that the color turns black during the night, and if I multiply everything with black color everything becomes black, no matter if there are other light sources or not. So what I think I should do, is multiplying the ambientColor with ambientIntensity and then adding this to the shaderGraph. But I can't find ambientIntensity anywhere in the shader graph 😦
Here's the point where I multiply all the previous graphs with the ambeintColor (turning everything black if the ambient is black)
Afaik, URP does not use depthTextureMode - to enable the Depth Texture there's an option on the URP Asset. I also think you can't just set _camera.targetTexture as that's for the colour target, not depth texture.
If you're trying to get the depth texture from a specific camera to the main camera, you'd probably need to blit it. Can try Graphics.Blit, but if you're in URP you can use a Renderer Feature, e.g. https://github.com/Cyanilux/URP_BlitRenderFeature
(You'd have two Universal Renderer assets, one with the blit (source as texture ID _CameraDepthTexture, destination ID as whatever global texture property you want to use to obtain it later), assign both to the URP Asset then on the second camera, change the Renderer to the one with the blit, and make sure the main camera has the one without)
🤔 ill take a read of this this is stress
unity shader devs must surely live shorter lives with the stress of trying to figure out how to master unity's graphical api 😄
If the graph has custom lighting calculations, you'd want to multiply by the ambient colour before adding those on.
guess ill need to learn about custom render features
Frack, I mean...the docs need to say what pipeline a command is applicable to...
You mean calculating mainLight and additional lights custom functions? If so, yes, but how would multiplying the color there change anything?
If the color is black, no matter where I multiply it the result should always be black... no?
Here's where I calculate the lights, with custom function and subgraphs
I'm not too sure what these functions are doing, but I think the way you usually handle ambient lighting is something like (ambient * albedo) + mainLight + additionalLight
So perhaps you just need to add rather than multiply
I don't use ambient in the custom functions, I just multiply it in the end, as shown in the first screenshot
I copied and understood only a little the code from a youtube video to create a toon effect
✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3 🩹 Fixes for 2020.2 and .3:
► When you create a shader graph, set the material setting to "Unlit"
► The gear menu on Custom Function nodes is now in the graph inspector
► Editing properties must be done in the graph inspector instead of the blackboard
► In Lighting.hlsl, change the line "if SHADERGRAPH_PREVIEW...
That's the video
https://youtu.be/whmPkDp3dqo. GitHub Gist: instantly share code, notes, and snippets.
And that's the code
as I see there, ambient is not being used
(that's why I added it in the end, in my shader graph)
Shader "Skybox_Cube" {
Properties{
_Cube("Environment Map", Cube) = "white" {}
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified uniforms
samplerCUBE _Cube;
struct vertexInput {
float4 vertex : POSITION;
float3 texcoord : TEXCOORD0;
};
struct vertexOutput {
float4 vertex : SV_POSITION;
float3 texcoord : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.vertex = UnityObjectToClipPos(input.vertex);
output.texcoord = input.texcoord;
return output;
}
fixed4 frag(vertexOutput input) : COLOR
{
return texCUBE(_Cube, input.texcoord);
}
ENDCG
}
i get an Shader error in '': Parse error: syntax error, unexpected TOK_GPUPROGRAMID at line 6
do someone know what the causes the problem?
Probably because you're missing SubShader and Pass sections, see https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
it worked thx
Anyone know how to make Star/Diamond shape in shader graph from UV?
Something like this
Can do something like this
Oh thanks, I just rediscovered it too at the same time!
my implementation of what you suggested sorta worked but it introduced distinct hexagonal edges to the effect for some reason 🤔
better example
The mask itself is responsible for the edges but I am not sure how to blur that out 🤔
hm maybe there is a hexagon SDF with rounded corners
no wait all SDFs are rounded, I just have to change the coordinates/falloff/maths, I should be able to solve this on my own
yeah getting real close, should be everything I need 
Hello, I turned a bunch of nodes in a shader graph into a subshader, and I now got this error:
The subshader seems to work correctly inside another shader. The code used there is used in many other shaders, and it does not create any error
That's a shader graph... it's giving weird errors
Might be a mistake in the custom function code? Also try resaving the graph, that sometimes refreshes/recompiles it
The custom function node is working good on other shaders, and the subshader graph itself is working correctly in another shader 😦 I also recompiled it manually... gave more errors
I found that those two shaders are different. That's the shader where the subgraph works
That's the one where it doesn't
they're both unlit
Hi everyone, I again have a problem, where I seem to need a shader. I simply want to make only the edges of a cube visible. I searched a while, but I dont really find something about that. Can anyone tell me what to search, or maybe a tutorial anywhere? I appreciate every help.
There's many techniques for outline rendering and all of them have their own complexities
https://alexanderameye.github.io/notes/rendering-outlines/
Thank you, but I dont think I need an outline shader this time. I really want to see every edge of the cube.
What does that mean precisely?
Something like that
I found something which is giving me that result, but it is judders with movement
If you just need it for a cube, I suppose you could just make it out of geometry or in texturing
No shaders necessary
By every edges do you mean the wireframe?
Okay, how do I start with that/ where do I look that up? I really have no clue about textures etc.
Yes
Spazi is saying you could model a cube that is itself a wireframe rather than shader/texture. Give me a sec to launch 3dsmax but it has a modifier to turn a mesh into a hull (if hull is the word you use for this)
Hi All,
For years I have used GLSL for work and home use.
I have pushed my son towards writing shaders in Unity as well
Given that both GLSL and HLSL are two sides of the same coin I kept postponing my learning of HLSL.
Although I occasionally would find examples in HLSL I could get the general idea and rewrite it in GLSL.
Now my son switched his game to HDRP, and now HLSL is a must.
I can't deal with Shader graph where a simple line like a = b * c takes up as much screen real estate as a whole function.
Plus searching for something in the code is easier than in a Shader Graph.
I tried to follow the template code, but it makes use of a lot of Unity macros and helper functions and finding documentation or examples for those functions is a major pain.
;;;;;;;;TLDR;;;;;;;
Can someone please recommend a book on HLSL for Unity that also covers Unity's helper functions and works with HDRP?
Please
Or if one is not available a book on HLSL for Unity for people that know GLSL
Ah okay I see. Perfect thank you
3dsmax calls this a 'lattice'
Okay, makes sense. That is indeed what I am searching for
it looks like Blender also calls it Lattice in its modifiers
I see, do you know how I can achieve that in unity?
Unity is not really a 3d modeling program, blender is free
As far as I know, there aren't even any examples, beyond random lone ones, for how to write HDRP shaders which can't be relied to be up to date, and writing them by hand is not an officially supported workflow
Use the Shader Graph
Learn shader writing with the Built-in RP, not URP or HDRP
If you don't know what textures are, I'd say that's where you need to start studying
Okay, do you know if I would be able to see through the cube excluding the drawn lattice, when I would create that lattice of the cube in blender e.g., and then import it in unity?
Of course I know what a texture is and how to create one from an image for example, but I not how to create the one I am searching for..
Here's an example
If the box's UV map has the same texture on each side, and the texture has white edges like this, they'll appear right at the corners of geometry
If you go to this menu in the Unity editor
Asset -> Create -> Shader ->
There are 3 templates for the HDRP.
When you open the newly made file there is familiar code. But I'm unfamiliar with the functions included.
For example from CustomPassCommon.hlsl
Coming from a world where you write shaders to a world where you construct shaders with blocks feels like going from C# to Scratch
I see, I will give it a try. I would need to have the black plane as transparent, but I will try
The functions are the difficult part about it
Maybe the nodes feel clumsy but the other option you have is very unlikely to make your or anyone's life easier
At least until there's more documentation about the functions
The fact that they dropped the support for GLSL does not help either.
😦
I guess I'll focus on HLSL in the default RP then see if the functions from Unity's HLSL files will start to make sense
"""""Maybe the nodes feel clumsy but the other option you have is very unlikely to make your or anyone's life easier""""""
It would make my life easier 😄
Perhaps your son will find Shader Graph useful, even if it seems unintuitive to you
I started with zero shader knowledge and quickly got the hang of shaders with SG, even without instructions
If you want to do anything with lighting, it really won't be easy writing it by hand. It's alright in URP but no idea what HDRP would be like.
You could try a graph and generate code from it, but that'll likely be pretty unreadable.
The code it generates is the assembly code.
Not very helpful
No, for shader graphs you can see the generated shader/hlsl code. There's a button in the inspector at the top (not the compiled code one)
He's been talking about SG.
SG irritates me to no end...
It's literally going from C# to Scratch...
With all those tools that help you edit the code. Search for variables, search for functions, go to definition
You could try using a mix of ShaderGraph + Custom Function nodes with hlsl include files
SG is very convenient so a lot of those operations aren't necessary for navigation, but it really doesn't teach shader coding either
If the point of the excercise is to learn shader code, then URP or HDRP are not a great choice for starting with
I think my problem is understanding GLSL code well, and cursory understanding the HLSL.
I bet those Unity's hlsl files had been around since the default and URP.
I think my problem will be solve with diving into HLSL with Unity
Thanks everyone for helping me decide which way to steer my learning
""""""SG is very convenient so a lot of those operations aren't necessary for navigation"""""""
For simple stuff, sure.
But as a rule of thumb.
"The complexity of software will only grow"
HDRP is only the next step in the evolution of shaders that combines frequently solved problems, however the complexity will continue to grow
This should hopefully improve with block shaders.
Here's hoping!
I'll probably still use SG, but yeah 😄
Why's that? I thought block shaders were intended as an expansion/replacement
I just find it quicker to use a node editor, but maybe that'll change with block shaders idk. Also probably depends what type of shader it is (especially since SG doesn't support some stuff)
Node based workflow still has its place. In a way, Shader Graph has served as a temporary substitute for surface shaders, but block shaders are the true replacement.
Ah, I assumed block shaders were to have a graph-like editor for themselves due to what I knew of node blocks, but looks like they're all code?
Yes, block shaders are pure code, and shadergraph will generate block shaders code
https://gfycat.com/windymassivebluejay
final results, everything working as intended thanks to your help 👍
Oh that's cool. Will there also be some compatibility the other way, as in using block shaders in shader graphs? I haven't looked deeply into what the architecture for block shaders will be, but the way I understand it is that you will be able to combine block shaders to layer different effects.
I don't think there is other plans to do it the other way around 🤔
I hit a snag with my shader that I hope is easy to fix.
I have noise calculated in world space positions, and an SDF mask that I need to calculate in object space positions
but just subbing in object space to the mask and world to the noise didnt work
it totally broke the calculations
hm okay recalculating it 3 times fixed it, but now its positions are not matching its position
and now its weirdly super shiny
translating it to work in world space instead of object space is non-trivial
its not as simple as just changing it from object to world in the position node
hmm the problem is because I need the mask to be centered on the object, but the noise to be in world space coordinates
but passing in the object space position didnt work
oh I fixed it, I just had to calc the world and object twice
I feel like I must be doing something wrong that can be better, more efficient, when looking at how much of a hot soup this has become
no something is definitely not right
that huge bright spot is completely wrong
gdi why is nothing ever easy or simple, why cant I just go object space -> world space, and boom it just works
I @#$@#% shaders, how nothing is ever logical, nothing ever easy, nothing ever makes any sense, no debug tools, no explanation, no sense
time to take a break because Im emotionally compromised now by this stupid POS
for some reason its rotated in world space and not in object space 🔥
take a break like you said you would
no where in the shader, no where at all, takes in the objecty's Y position. its never used anywhere ever. and yet this is happening despite it being physically impossible
i hate shaders so @#$@^%ing much
why does it work perfectly in object space and why is it a complete @#$@%#234 POS in world space
Hi, I‘m working on a foliage rendering system. I chop my terrain up in tiles and run a compute shader per tile to collect instance data (position, instance count, etc). I then pass that instance data to the material (every tile uses the same material) and the material to a Graphics.DrawMeshInstancedIndirect call. Now the issue is that when I have 2 or more tiles the same material instance is overridden. So essentially, my compute shaders spit out multiple instance data buffers but since they’re using the same material instance they are just overriding the material instance data buffer.
What’s the best approach to take from here? Just copy the material such that each tile has a separate material instance?
I’ve read about MaterialPropertyBlocks, are those an alternative to coping the Material?
@next solstice I believe you want to combine the frensel effect with the alpha channel
if you want to make it transparent where the black is rn
Thank you
basically split your color into the 4 channels, then take your frensel effect and alpha channel, and multiply them. next, combine everything back into your color data that you want
i think thats it
yeah
Doesn't look like the fresnel is doing anything now
i need to see the whole shader graph
but
basically
your red color is stuck in the multiply node
and you only pass the value of the multiply to one channel
like for example
why is the B input of your shader a Vector4
i need to know that
sorry B input of the multiply node
actually yknow what
i think your original shader does affect the alpha
I've compacted it a bit but its still a bit low res
I also fixed the error in my previous screenshot where the texture rgba was going into r of combine lol
yeah
your red isnt being applied to the combine because you arent passing the values
i think it would make sense to do what you were doing before
but just alpha isnt rendering for some reason on prview
do you have the shader rendering mode set to opaque or transparent
This, surface type in the graph inspector?
im not putting anything in alpha in fragment right
you want to pass the alpha seperately to the fragment section oft the shader
yeah
but i think you do want to keep transparent mode
like this?
um i think so but try setting the A of combine to 1
Doesn't look like anything changed.
weird
what if
you connect the alpha output of the fragment to the fernel effect output
Um, fragment doesn't have an output?
the alpha one
that you used before
i consider it an output because you are outputting it to the object
Sorry I don't understand. Alpha from what node?
and what do you mean connect? Do you mean combine?
yea
that looks correct now
afaik
though i notice you apply a modifer to your fernel, might want to take the output of the modified fernel but before you add color too it? im not sure whatyou want, but that looks like what you wanted to me
It shouldn't be transparent in the center. I want the other texture to show through. So since the other texture is black and white checkerboard it should show black and white checkerboard in the center. However it was showing black in the center.
I wonder if this is the problem. It's showing black in the center, so the fresnel effect isn't giving fade from white to transparent, it's giving fade from white to black. Is there a grayscale to transparency node or something?
It would have to be inverted because usually grayscale to transparent makes black opaque and white transparent, which is the opposite of what I want.
So there would be something here in the gap between invert and the multiply with color that converts the black to alpha
thats what i was trying to do when passing fernel into fragment alplha
also, its not white to black
its 1 to 0
but it renders the preview as if r, g, and b are all following the value of the effect
oh ok you were trying to make it transparent between the red and the checkers?
i thought you meant transparent in world view
lol
yeah
Is there a way for Shader Graph to get properties from another script? I Know I can get a texture from the Sprite Renderer, but I want every instance to check an attribute script to get it's random color.
how do I get a scene object's rotation in a shader?
is it one of these things that need a script to inject the data in the shader?
You have the transform matrix. It's possible to extract the rotation from it, but it's an expensive operation. In what format do you need the rotation? A rotation matrix? Quaternion? Euler angles?
I just need to dot the forward of an object, just don't know if adding a reference to a transform is possible in a shader
my guess is nope, just inject the materialpropertyblock on each frame
Oh, well that's easy:
float3 worldForward = mul(unity_ObjectToWorld, float4(0, 0, 1, 0));
There are also functions for this, different depending on if you're using built-in or SRP:
float3 worldForward = UnityObjectToWorldDir(float3(0, 0, 1)); // built-in
float3 worldForward = TransformObjectToWorldDir(float3(0, 0, 1)); // URP/HDRP
I forgot to mention that the object is not the surface being shaded, it's a directional light
but thanks for the refresher, you're quite courageous for hand coding SRP shaders 🙂
I see. Yeah it's something you would need to pass in each frame. Unity already passes in the directional light direction through _WorldSpaceLightPos0 in built-in for you. URP probably has something similar.
i am confused with shader graph in the vertex section i created a custom interpolator to get the distance of the vertex to the game object's position, then in the frag i use a lerp to do alpha transparency based on distance but it isn't doing a radial fade. why might this be?
how do i get this to be radially transparent by distance - i presumed it would interpolate the vertex distances so each frag has an interpolated distance?
ok it works if i do all of the math in frag
but was hoping to do the distance in vertex to reduce the amount of calculations
😦
I think you need the position node https://docs.unity3d.com/Packages/com.unity.shadergraph@14.0/manual/Position-Node.html
i am using the position node
The position returned by the object node is not per vertex
it works in frag shader but not setting distances in vertex shader first
Oh wait Im sleepy
my screen shot shows the position node in use lol
Whats the vertex density of the mesh?
its the regular unity cube
Think about it the other way around.
Scripts send data to shaders (via material settings). Shaders don't go get data from scripts.
The script(s) are the senders, the shaders are the receivers.
So you need a script that sets something (buffer or texture or just properties) that your shaders can use. Maybe a shader global thing that is set.
If you want per-instance values, that can be more complicated, but check into "Material property blocks" and see how you can make that work with _BaseColor in Shader Graph. It might work, since _BaseColor was one of the properties that works with instancing IIRC. But in general there's an "issue" with MPBs and Shader Graph, as I understand it.
do someone know how to get Pixelvalues from the skybox?
Too vague.
Skybox is drawn AFTER opaque objects are drawn.
What pipeline are you in?
So WHEN do you want to get theses values? During opaque passes? During skybox generation? During transparent pass?
If the latter and you're in URP, you can get the entire background opaque objects + skybox using the scene-color node in shader graph. But that won't give you the "sky" that is behind a scene object.
If you must have the sky, regardless of opaque objects, you're probably best off using a sky or sky+terrain camera as the first camera in a camera stack. Then drawing all your stuff on top of that.
It's hard to answer your question without more details for what and when you need all this data. I mean, since the skybox is drawn after opaques, some of it is never even generated if there's an object occluding the view of the sky.
i have a custom shader for my cube object to generate a skybox in the cube. I want to compare if my skybox is the same as if i generate a skybox in the scene with "skybox/cubemap" shader.
Sounds like you're trying to compare cube maps to each other.
IDK.
The skybox that's actually output to the screen is a subset of the cubemap and is going to be interpolated across the pixels of the screen.
IDK how you compare the results other than just writing your own skybox shader and using the scene color node or a grab-pass to "grab the sky" and then compare the two, and then maybe output a difference map as an overlay.
Kinda sounds like this "test" is more complex than what you were making originally
it will get even more complicated XD. But for the time being i want to know if my shader works correctly or not 😄
Has anyone had any luck with proper auto-complete for writing shaders in Unity?
There's an HLSL addon for vs which does a lot, but it can't recognize some shaderlab things and also, it can't find include files at all, which is a big problem with any URP shader
I hope you are not only wanting the comparison for debugging, thats a lotta extra work
Is there no way to compare it in paint by applying both materials to the sky separately and taking a screenshot
is there a way to hide objects when being behind an invisible object?
my plan for now is, to create two separate 3D cubes and apply two separate shader. After that i will write a script which will compare every pixel.
JetBrains Rider has the best ShaderLab/HLSL support that I've seen.
https://www.jetbrains.com/help/rider/Features_Unity.html#support-for-shader-files
Not listed on that page is Go To Definition, which will also open include files so you can easily see the definitions of built-in functions and macros.
Oh, looks promising, I'm trying this out today, thank you! 😄
Does Unity also use this in-house? They had to use something similar to write all those libraries
every rendered pixel? with ortographic camera?
ehm i dont realy know what you mean, my thoughts were to use this example
How are you planning to render your shader into a texture?
i would just apply the shader on the material and then give the material to my object
okay, you have a material, and object and a shader
where is the part that yields you the texture with the data
i thought the shader is basicly the Texture, is it not? I would have taken the object as my Texture3D source
It's not
The texture is pixel data, imagine a grid of values
The shader is a program the GPU executes to render to screen pixels
Your screen is rendered to a RenderTexture
which you can read from
but I'm not sure how you would compare two objects that way
(if you copy to an actual texture which will be located in the RAM instead of GPU memory)
can i compare the values of one object with the other in the fragmentshader? its basicly my pixel values right?
Iam doing a vr project for school and iam trying to make objects be highlighted when touch them hoping someone knows how to do this and can help me
What RP
Also how you want the effect to look
I was hoping to create an effect like this just a simple like that shows when hand is touching the object and disappears when holding it https://youtu.be/veBOFcKC2qg
Second part of this project I’m doing to learn how to use the new XR system in Unity. In this video you will be able to see movement system, outline effect, Pick objects, interaction with physical buttons and system to prevent the player from not crossing the walls, making it always within the limits.
All done in the URP(Universal Render Pipeli...
Not sure what you mean with RP first time doing any of this
if you have both shader logic running in the same shader
but you only get color info