#archived-shaders
1 messages ยท Page 32 of 1
I've made a simple lit shader to render pixel art on planes with alpha but I'm having some issues with light on back faces even if I specified to render both sides
Both sides are rendered, but light is still calculated based on only the front face
So the backface just repeats the lighting on the front
Do I have a way to fix that?
I think you can flip the vertex or fragment normal based on the Is Front Face node
Is that possible using the shadergraph?
Yes
Spazi basically just described doing it for shader graph. But I've also got this : https://www.cyanilux.com/faq/#sg-two-sided-shading
Thanks everyone for the suggestions, I'm using Cyan's guide w/o normal map since its just albedo but I still got that effect ๐ค
the nodes seems greyed out (?)
Normal (Tangent space) is not being used since you set it to use world space, which you can see appeared at the bottom of the stack
To be clear, there's two examples on that page. Depends if you're using a normal map or not. Here you likely want to connect it to the Normal (World Space) block and delete (or ignore) the Tangent one.
You'd need to change your current "horizontal wave plane" to also be vertical (or at least have a copy of it). Can have the bottom vertices of that match the viewport and not move, while the top ones do move.
That way you have pixels "below" that wave, that you can use to write to the stencil buffer. For that you can read through these :
https://docs.unity3d.com/Manual/SL-Stencil.html
https://www.ronja-tutorials.com/post/022-stencil-buffers/
If you're using Shader Graph, it doesn't support stencils. But you can use the RenderObjects feature in URP to override stencil values. I've got a tutorial here which kinda goes through it. The use-case is a bit different but should still be useful? https://www.cyanilux.com/tutorials/sprite-stencil-overlay-breakdown/
If you are using Shader Graph but in Built-in RP, then you may need to convert the graph to code and edit it (button in inspector on graph asset). Or completely move to shader code.
Hi guys! If I have shader property's ID and this property is StructuredBuffer then how can I retrieve property name from shader? Is it possible?
Thanks, fixed by changing Vector Normal space and Fragment Normal space to Tanget (got bit confused at the start cause in the image the node was set to world)
I think I used stencil operations (also see my answer to ao above). It allows pixels to only appear where the values in the stencil buffer match the comparison.
I was rendering the water surface front faces and back faces with separate materials, so it was something like :
- Write the waterline subdivided plane into stencil buffer (Ref 1, Comp Always, Pass Replace)
- Render water surface (top), Cull Back & Stencil Ref 1, NotEqual
- Render water surface (underwater), Cull Front & Stencil Ref 1, Equal
But rendering that waterline plane into a separate buffer is another option. By buffer I mean a Render Texture. (Can do this with another camera, URP renderer feature, or via ComputeBuffer / Graphics apis in C#. Kinda depends on render pipeline)
You can then sample that render texture in your water shader and alpha clip / discard pixels based on that. Also render an image effect (fullscreen quad) for underwater effects, again masked by that render texture.
Have another issue, this time with the alpha, it seems that sometimes you can see through other objects (with same shader but different material)
This is due to how transparency works. It doesn't write to the depth buffer so it's difficult for unity to sort transparent objects.
In this case it doesn't look like you need partial transparency, so you should swap to using Opaque surface mode but enable Alpha Clipping to discard pixels below a certain threshold.
StructuredBuffer is already a keyword in hlsl, so you really shouldn't use that for a property ID
Thanks!
I use it with MaterialPropertyBlock.SetBuffer(id, computeBuffer) and I getting ID from Shader.PropertyToID(bufferNameInShader) and it works. I mean it is not property in terms of shaders, but I need to retrieve buffer name in shader from it's ID. Is it possible?
I havent thought of using a render texture tbh i was trying to use a depth mask ๐
No, the IDs aren't used in the shader, just the property names. Unity assigns IDs to them for getting/setting values only - those IDs are also different every time you run the game.
Just change what name you are using for bufferNameInShader. Even _StructuredBuffer would likely work. It's common to start property names with _ to avoid these types of conflicts with ShaderLab/hlsl keywords.
And by fullscreen wuad im guessing a quad that fits the view frustum of the camera and its close enough to the near clip plane of the camera?
I guess, though it's easier to use something like Graphics.Blit / CommandBuffer.Blit.
I dont know how thos work if im being honest
I might do more research
Also wait does this also mean i can have a caustic texture thats moving and set the uv to world space from depth or is that not how it works?
Maybe I wasn't clear enough, excuse me for my eng. I have no troubles with passing data to buffers. Also I name buffers with _. No problem with that at all.
I just trying implement EditorWindow where I want to display buffers names which I use in my rendering system. But I have only IDs not names so I searching for a way to retrieve StructuredBuffer name having it's id and shader to display name in the editor window. That is all. And it seems there is no way to do it.
Yeah. It works a bit differently in blit shaders (likely as it replaces the view/projection matrices to ensure the quad stays on the screen), but it's still possible to reconstruct the world position from the depth. Something like : https://www.cyanilux.com/tutorials/depth/#blit-perspective
Otherwise if you manually place a quad on the camera plane, or just use this subdivided quad & stencils, then you can likely use this simpler method :
https://www.cyanilux.com/tutorials/depth/#mesh-perspective
Oh wow thank you i didnt you have a break down for this! Thank you
Okay I kinda get it now... I don't think there's a way to get the name from the ID though. Could you not just pass the names instead of the IDs in?
Yes, but in my system same buffer may be registered multiple times so I have method overload for passing both name or id, and user can store buffer names/id however he wants so I can't predict name. Though it isn't very important thing in performance terms so I can just remove possibility to pass ID and let just pass strings only to be able to save them only in editor and show in window. Still sounds like extra data for view layer which not great for me
Hi, I'm trying to add a 'moving noise' type of effect to my outline. Sort of make the outline more interesting. Doesn't seem to be working at all though. Anyone know what's wrong?
Do you know which IDs correspond to which shaders?
(as it stands, if 'outlineNoiseMovement is above 0 it colors the sprite itself, otherwise it does nothing)
Here you are affecting the outline color by the noise.
If you want to make it woble, maybe look at using the noise as source of the outline width ?
Either way would work. Here I was thinking to just add colored splotches (through noise) to the outline and have those move. Except that isn't what this does for some reason
Try multiplying the noise with the outline color.
Or add safeguards (like saturate) to some of the nodes, as I suspect that you have negative values inside the sprite shape.
yes
you mean multiply rather than add?
Then you can do a brute force search for the right property by using Shader.GetPropertyCount and Shader.GetPropertyName/Shader.GetPropertyNameId.
yes
I've tried this, buffes not included to properties
while the top ones do move.
Thank you, but what in what way do you mean that the top ones would move? If I place the Waves script onto a plane that I then orient vertically, then its motion doesn't match the intended waterline motion
edit: If you mean to change the waves script to affect the top of a plane that is oriented vertically, I currently don't really know how to target the top of a plane's vertices in that way, but also I think my water system requires a horizontal plane to work properly with swimming logic.
So it seems to work except for the fact it's also affecting the inner sprite (not just the outline)
K I got it. Had to subtract the inside area again
Nvm same problem. Omg I hate shaders
Excuse the badly drawn image, but I mean instead of the mesh on the left, you want one orientated vertically like the right.
To make only those "top" vertices move you should be able to mask them using uv / vertex colors.
Also no idea why a horizontal mesh would be required for swimming logic but this could be a separate plane just used for visuals.
Hey guys, i got this part of the shader for displacing vertices. It looks like a ocean, tho the normals seem to just point upwards on the plane. How do i recalculate the normals based on this?
Every bit of help appreciated
Better Image
Tried this and another method from a video with gerstner waves, but cant get it to work:
Fix up normals in your Shader Graphs after manipulating vertices!
In Shader Graph, you can move your vertices around, causing your model to take on a new shape. This will often cause the normal vectors to be incorrect, which will ruin your lighting. In this video I'll cover how to fix your normals all within shader graph.
The math is a bit co...
There's a Normal From Height node which is a quick (and likely cheaper) way to calculate normals. (It uses screenspace derivatives (ddx/ddy) which is possible as fragment shader runs in 2x2 pixel blocks, but this means the resulting normal is a bit pixellated too)
Otherwise you'd need to simulate some neighbouring points, offset those and cross product with the differences. Looks similar to this video though I feel they're overcomplicating things a bit. The method I'm more familiar with is :
float4 modifiedPos = Position;
modifiedPos.y += displacement(modifiedPos);
float3 posPlusTangent = Position + Tangent_Vector * 0.01;
posPlusTangent.y += displacement(posPlusTangent)
float3 posPlusBitangent = Position + Bitangent_Vector * 0.01;
posPlusBitangent.y += displacement(posPlusBitangent);
float3 modifiedTangent = posPlusTangent - modifiedPos;
float3 modifiedBitangent = posPlusBitangent - modifiedPos;
float3 modifiedNormal = normalize(cross(modifiedTangent, modifiedBitangent));
(based on https://www.ronja-tutorials.com/post/015-wobble-displacement/)
Thx for the mega detailed answer, i think ill try the normal from height. Tho i am confused with its inputs, i am probably not able to just plug my height in there since it takes an int?
What do you mean? The port is labelled In, are you confusing that with int?
Oh yeah i see
Whoops
aight now i just need to figure out how to use it
The out definately does not connect to vertex normal
With the Normal From Height you use it in the Fragment stage rather than Vertex, basically to construct a normal map. Either in tangent space or world depends what the Normal output space is set to there (can be changed in graph settings)
Hmm
So to change the vertex normal id need to use the code you provided?
Sorry if i talk nonsense and dont get all of it, im basically using tape and nails to hammer my project together...
You'd need to convert the code to nodes, but yeah that method would be handled in the vertex stage
Rip, code to node is my worst enemy
Thanks for the help tho, ill try all of it to get to the result i am looking for
Would i be able to paste the code you provided into the generated shader?
Ah nah forget about that it has 8000 rows
I converted an example to nodes,
I think one thing I didn't make clear is the displacement needs to be based off the modifiedPos/posPlusTangent/posPlusBitangent (labelled as Vertex Pos, Neighbour T, Neighbour B in graph)
In your case your noise is sampled using the Position for example. You'd need to copy that "displacement sample" section an extra 2 times and swap that Position out for these Neighbours. If Absolute World space is required, can use Transform nodes first to convert between spaces.
May be a good idea to move the displacement calculation to a SubGraph since it needs to be handled 3 times.
so just plug the things i am calculating into what you did at vertex pos?
I am unsure on how to implement that in my use case, could you specify a little? I'd be very thankful
ahh so basically my stuff needs to be inbetween where displacement is?
i want it to be world based so i can make my ocean move with the player easily for performance reasons
Yeah, you'd replace the "Displacement" groups with your own calculation. I think that would be everything before that Add node.
And the displacement would basically be the heightmap scrolling?
Yea
I shouldve stayed in school instead of becoming solo indie dev
Aight ill try my best
Ok i was too lazy to put it in a subgraph because i wanted to see it work, but now my plane just goes invisible and i also think the normal should not just be pink
Your currently adding your displacement and my example sine wave displacement, when you should just be replacing it
Like you still want the Vertex Pos, Neighbour T and Neighbour B in the A ports on those 3 Add nodes on the right. But the B input would be your displacement.
aight its all stretched out, but at least its not invisible anymore
Also seems to deform only on one axis
Before your Split nodes you'd likely want Transform nodes from Object to Absolute World space. Since that's the space you were using before.
Is there any difference between saturate and clamp?
saturate will always be between 0 and 1, clamp will do between your own set values so they cant exeed if i am correct
I don't really understand why putting or removing a saturate node from specific places can have such a dramatic effect
Right now my saturate nodes are preventing the HDR colors from glowing, but if I remove them then the shader gets borked
Maybe use Emission?
emission is something different?
Nvm then, am shader noob anyways
as far as I can tell, you need to use saturate anytime two operations are used back to back, like add + subtract, or multiply + add, or multiply + multiply
https://youtu.be/pCxgtVA2zmw
@regal stag
Ahh probably need a higher resolution displacement map maybe
Nah that wasnt it
Does anyone know why my plane is purple? I've been trying to figure this out for 30 minutes
Here's the shader that's being used, I'm guessing the issue is something else though
Actually, I've just tried offsetting the vertices and that hasn't made any noticeable changes, so it seems like it is my shader code
Magenta typically means there's an error when compiling the shader, or the current render pipeline does not support the shader. (Or the platform doesn't support the shader, though that's more in builds)
Usually the console or inspector when shader asset is selected will show error messages
If there's none it's probably the render pipeline. Is this URP/HDRP? As that doesn't support surface shaders. Only vert/frag, or shader graphs.
It wasn't when I first witnessed this issue, then I tried switching to URP and it didn't help
I've switched it back to none now, but the issue persist
I'm going to try creating a new project where I make sure I select the normal RP and see if that helps
You can convert the material from built-in to URP, if that doesn't work the issue must be in the HLSL script
Side tangent here, but aren't surface shaders written in unity shader code?
Or do I have that wrong
The converter only works with built-in shaders. It won't work for custom ones.
There's two parts, Unity's ShaderLab syntax is the outer parts (Shader,Properties,SubShader,Pass blocks). While the actual shader code is written in HLSL (inside CGPROGRAM or HLSLPROGRAM)
Right, that makes sense
I'm not too sure, I'd assume it's due to the resolution of mesh, since the normals are calculated per-vertex here.
Calculating the normal per-fragment with the Normal From Height node may be smoother.
Ahhhhhh I got it to work
Yeah, something weird was going on with the other projects RP config, I just made a new project ensuring that I selected the normal render pipeline
You could use a Maximum node with a value of 0. That would retain HDR values but remove any negative values.
Thanks for the help Cyan, Alda
For future reference, am I able to write surface shaders in URP or HDRP under any circumstance? If not, are there alternatives?
Needs to be vert/frag ones currently, though I find it easier to use Shader Graph (especially if it needs to be lit/shaded).
In the future there will be Block Shaders that will be similar. https://forum.unity.com/threads/block-shaders-surface-shaders-for-srps-and-more-public-demo-now-available.1350497/
I had the same problem but i dont think i could help since my ocean waves are in hlsl or a custom node and all the other effects are in shader graph
But u could try adding a negate node to one of the noise textures
is it just me or the image is blurry?
maybe because you plugged non-normal texture into normal slot? I think you should use height to normal node before plugging in a height map into normal input
Thank you! This is what I was missing. I thought numbers went the other way and higher number = brighter.
yo im extremely new to unity but I have a question. so recently, I bought a shader pack from the asset store, "Skybox Extended Shader" By BOXOPHOBIC. I've been searching for a few hours on how to apply shaders but can't find out how. Do you have to make it a script and apply it to the camera?
Hello! I'm new to shader graph, i'm trying to make this water shader's foam move in same direction on all tiles (3d), how can i do that?
You'll need to apply it to the skybox material, which you can replace in the lighting settings
Set the direction value the same for all tiles?
im fairly new to rendererfeatures and i need hel! why does this give me an error?
Because the method call is wrong.
oh thank you
Maybe you wanted to use this ? https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.Blit.html
cmd.Blit( source, dest, mat)
idk tbh im using unity 2023
i just want to get the scene color
but only see a layer i set it to
.
Do you need a renderer feature for this ?
Shadergraph has a scene color node
yes because i just want to render the layers i want it to
for context im trying to make a water line shader
i really wish you or anyone could help because ive been at this for 2 weeks ๐ฆ
I don't have the full context of what you are trying to achieve and what technique you want to use, there is probably multiple solutions for doing a waterline effect
Like I said, Cyan is listing multiple techniques here
I think you are trying to render a waterline mask in a dedicated texture, right ?
yep
if you have anygood tutorials for this topic please show it to me thank you
I have nothing on top of my head else than the official doc
But seems like the workflow would be :
- Create a temporary mask RT
- Assign it as active RT
- Render the waterline mesh in the mask
- Set active RT to null (so, screen)
- Render a fullscreen quad with the mask RT as input
oh ok! thanks! also i found this! https://www.youtube.com/watch?v=R9MoyEOdmeA im gonna try your idea with this too! thanks my man
In this video we will create a Pixelart effect in Unity by apply it as a post-processing (custom shader graph) to the camera image using a custom render feature in URP
Learn C# for Unity by making games - My Unity video courses:
https://courses.sunnyvalleystudio.com/
Github Scripts
https://github.com/SunnyValleyStudio/unity-URP-Pixel-Effect-Po...
Well, one of the arguments to the method is null when it should not, or the object calling the method itself is null.
public Material material;
public RenderPassEvent passEvent;
class WaterLineRenderPass : ScriptableRenderPass
{
Material Wmaterial;
RTHandle tempTexture, source;
public WaterLineRenderPass(Material mat) : base()
{
Wmaterial = mat;
}
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
source = renderingData.cameraData.renderer.cameraColorTargetHandle;
tempTexture = RTHandles.Alloc(new RenderTargetIdentifier("_TempTexture"), name: "_TempTexture");
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("WaterLine Buffer");
RenderTextureDescriptor textureDescriptor = renderingData.cameraData.cameraTargetDescriptor;
textureDescriptor.depthBufferBits= 0;
cmd.GetTemporaryRT(Shader.PropertyToID(tempTexture.name), textureDescriptor);
Blit(cmd, source, tempTexture, Wmaterial);
Blit(cmd, tempTexture, source);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
tempTexture.Release();
}
}
WaterLineRenderPass m_ScriptablePass;
public override void Create()
{
m_ScriptablePass = new WaterLineRenderPass(this.material);
m_ScriptablePass.renderPassEvent = passEvent;
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
renderer.EnqueuePass(m_ScriptablePass);
}
I recommand to using VS debuging to debug the error line and identify what is null
But all this is slowly getting out of subject for this channel
iirc : divide view direction by it's Z value (after the normalize node)
^
I always use this,
But if you're in newer versions of SG you'll want to use the View Vector node instead, as View Direction is already normalised now in URP
Thank you @regal stag and @amber saffron
Hi, I have a problem with my enum setup. Basically, when I change enums manually through the inspector the shader changes accordingly but when I try to change it through code and through UI although I see the enum actively changing in the inspector the shader doesn't react as it should. Is that a bug or I am doing something wrong?
How are you changing that Enum ?
How are you setting it in code? I'd assume you're currently adjusting the bool/int/float property, but not the actual keywords behind the scenes
Would need to use material.DisableKeyword & material.EnableKeyword
It's set up like this in the code basically
if (dropdownValue == 0)
{
m.sharedMaterial.SetFloat("_COLORBLINDNESS_MODE2", 0);
}
Do I enable the keyword on value change?
Yeah, you need to disable the other keywords and enable the one you need. I don't know what strings your enum is using but it could be something along the lines of :
Material material = m.sharedMaterial;
// disable all
material.DisableKeyword("MYENUM_OPTION1")
material.DisableKeyword("MYENUM_OPTION2")
material.DisableKeyword("MYENUM_OPTION3")
// enable specific
if (dropdownValue == 0){
material.EnableKeyword("MYENUM_OPTION1")
}else if (dropdownValue == 1){
material.EnableKeyword("MYENUM_OPTION2")
}else if ...
Probably should continue updating the float too, so the inspector changes along with the keywords.
I will try that now, thank you
The keywords will be {REFERENCE}_{REFERENCESUFFIX} so in the case of the example above, the Enum Keyword reference would be MYENUM and suffix of each entry OPTION(n)
It worked, thank you so much my dissertation is saved I was literally trying to figure it out for two days lmao
public void Test()
{
collectBuffers = new List<Vector3d[]>(reps);
for(int i = 0; i < reps; i++)
{
collectBuffers.Add(new Vector3d[bufferSizeSqrt*bufferSizeSqrt]);
}
computeBuffers = new List<ComputeBuffer>(reps);
for(int i = 0; i < reps; i++)
{
int kernel = i;
computeBuffers.Add(new ComputeBuffer(bufferSizeSqrt * bufferSizeSqrt, sizeof(double) * 3));
shader.SetBuffer(kernel, "Result", computeBuffers[kernel]);
}
for(int i=0;i<reps; i++)
{
int kernel = i;
shader.Dispatch(kernel, 64, 1, 1);
}
for(int i = 0; i < reps; i++)
{
int kernel = i;
computeBuffers[kernel].GetData(collectBuffers[kernel]);
computeBuffers[kernel].Release();
Debug.Log(collectBuffers[kernel][5].ToFloat);
}
}
I wrote this code that is supposed to dispatch a computeShader at multiple kernels, but it only works with the first kernel and the other ones crash
I get following errors "Kernel index (1) out of range" and "TestShader.compute: Kernel index (1) out of range"
It would be amazing if someone could help me understand why my code is giving me an error
Well that sounds like you do not have enough kernels, how do you get your kernel size?
I thought there where infinite kernels as long as my Gpu doesn t run out of threads, I thought kernels are like different instances of the compute shader
Am I wrong?
you might wanna use this to skip missing kernels: https://docs.unity3d.com/ScriptReference/ComputeShader.FindKernel.html
Can you explain to me what a kernel is?
A kernel is basically a function/operation that is handling the operations
okay so it s not like an instance of the compute shader?
the compute shader holds the kernels
yes so if I dispatch kernel 0 the function gets dispatched at kernel[0]?
https://docs.unity3d.com/ScriptReference/ComputeShader.Dispatch.html thats all my knowledge too here. I only played arouind with compute shaders once
thanks tho
If I remember anything, I let you know, but for now I rather stick to official docs to not talk nonsense here ๐
I'm having what I think is some beginner problems using 2d urp shadergraph ๐
I've got an area of text that I want to pass noise over in a particular direction, but I really just can't figure out how to make it move in any direction other than top right to bottom left - But I want it to move straight up
Put the noise into a Vector2 node before connecting to Tiling And Offset
That's not quite creating the desired effect, but I wasn't even using tiling and offset ๐
I'm a complete noob so I'm probably just misusing a node
This is my whole graph
It's all pretty small idk if you can see any of that
And ty for responding by the way ๐ ๐
I've been stuck trying to achieve this one effect for days now
AHA I got it!
New graph ๐
Thank you @regal stag !
You lead me to explore the UV nodes
I'm gonna cut down on some of this logic that I see is extraneous and get back to work. I appreciate it :)
Yes, can you help me?
Hi all. I have two squares made with compute shaders. One looks good, the other looks derp. For one, I used a standard rectangle collision formula. For the other one, I tried to do something fancy like "if the distance from the center is shorter than the distance to the edge, color the point blue, else black". I don't really know how to debug the values on the compute shaders, does anyone have any idea from the code why the second one might be derp, all other things equal?
float inSquare( float2 pt, float4 rect )
{
float horz = step(rect.x, pt.x) - step(rect.x + rect.z, pt.x);
float vert = step(rect.y, pt.y) - step(rect.y + rect.w, pt.y);
return horz * vert;
}
[numthreads(8,8,1)]
void GoodSquare (uint3 id : SV_DispatchThreadID)
{
float res = inSquare(id.xy, Rect);
Result[id.xy] = float4(0.0, 0.0, res, 1.0);
}
[numthreads(8,8,1)]
void DerpSquare (uint3 id: SV_DispatchThreadID)
{
const int halfRes = texResolution >> 1;
const int sideLength = halfRes >> 1;
const float x2 = (float)id.x;
const float y2 = (float)id.y;
const float x1 = (float)halfRes;
const float y1 = (float)halfRes;
const float alpha = atan((float)(y2 - y1) / (float)(x2 - x1));
const float possibleX = abs(sideLength / abs(cos(alpha)));
const float possibleY = abs(sideLength / abs(sin(alpha)));
const float rMax = min(possibleX, possibleY);
const float h = length(id.xy-float2(halfRes, halfRes));
Result[id.xy] = float4(0.0, 0.0, step(h, rMax), 1.0);
}
I'm trying to store the previous frame as a texture2d for a post processing effect (birp), is there any way to write to a pixel on a texture? or do I need to set it thru a c# script
@chilly lava just set a vector 3 direction?
Not sure, but maybe it's just float approximations issues ?
Graphics.Blit ?
ok so i just tried it and it does work but it looks like there is a minecraft revien under the camera
still does the same .-,
Erm, yes, was wrong : View Vector in View space (to have Z aligned with the camera), and after the division, transform to world space
oh ok lemme tty it
I'm a bit lost in my maths now, else you can try Cyan method that probably works ๐
it didnt :/
IT WORKS! THANK YOU SO MUCH!
Did you try to find the equivalent in the nodes?
yeah, i was gonna ask for an equivalence resource or something.
I dont find some, this is supposed to be lambertian diffuse
Any special node? I mean there is a gradient node for example. but I am not sure by just your screenshot what you want to achieve
that part is supposed to be a basic toon shade
the rest of it are gradients and stuf
Oh, you should google for toon shader on youtube, thats like full of tutorials about a toon shader and outline shader
there are some yeah, they use custom lightning, i will cross fingers i can get the same that node produces..
no need for custom lighting, basically you want some vertex displacement tog et the outline and some ramp/stepping for the colors/shadows. But yeah, just try to find a quite recent one
i dont want to do a toon shader, its this shader that has a base of toon shading only, nothing fancy
You can't do this in shadergraph with 3 nodes
Basically, the "Diffuse BSDF" is already the result of the shader, and you want to apply modifications to the final shaded color (shader to rgb > color ramp).
To do the same in shadergraph, you have to do your own custom lighting
yeah understood
Does your skybox have a custom material or something?
its the efault skybox
default*
And that is a plane you have there as waterfront?
its a renderer feature i mde yesterday
Ahh okay. Alright, thats out of my scope sadly, sorry. Never touched that ๐
its just a render feature the puts the material in screen space
I guess its trying to get depth, but outside of your 3d mesh, there is only the skybox, so its rendering "infinitely"
i guess
im using world pos from depth
Should be able to use a Comparsion node on the Scene Depth output, with the Far Plane value (minus some small amount). That would then go into a Branch
you might have to clamp it at some point, like cyan says to a value you can get like the far plane
well that was unexpected but ok ill try
IT WORKS! thankyou cyan
also cyan do you know anything about this? it gives me an error but i can still play and the effect still works
Looks like one of the parameters of the Blitter.BlitCameraTexture is null. Double-clicking should take you to the line it's from. Maybe add a Debug.Log and check what the values are
ok thanks lets see if i can understand the error
idk what this means but it directs me to the highlighted line
I'd look at WaterLineBuffer.cs:34 as that's mentioned in the error stack
this is the script
this?
sorry im new to renderer features ๐ฆ
ok what is going on now its not givving me an error
now it gave me an error when i open the graph for the waterline
does anyone know how i can edit a shader to work on both eyes on singlepass (vr)
Compute Shaders - Only two workgroups seem to be activ
Hello I am working with compute shaders for the first time experienting weird behaviors I dont understand:
The Kernel above has 8x8x8 Workgroups so after excecution of the shader I am expecting to find 8x8x8 = 512 distinct values inside the buffer; instead the buffer is filled with 8x8 = 64 distinct values while the other 448 values are 0.
I am in at almost two hours researching why this is behaving as it does and I am totaly clueless at this point. Is there something I simply missed or am I understanding sth fundamently wrong?
can you show how you executed the shader on the C# side?
pointsPower3 is 8ยณ
the results above are the numbers I find in the NoiseValue Array
all those other variables are not having an effect at the moment, as I am not using them since I am trying to track down the problem
*I mean the shader properties
The dispatch should be using threads 1, 1, 1 if you want to run 8x8x8 threads, because it acts like a multiplier on top of numthreads in the shader.
oh yes, the uncomented line above did excatly that, but the issue stays the same... putting 8,8,8 there was just me randomly trying to change numbers when trying to fix it
oh actually than I only get 8 distinct values
so i am assuming only one of the three workgroups is working ?
Is there any difference if you change all the ints in the shader to uint?
putting 64, 1, 1 in dispatch for example gives me 512 distinct values
nope i tried that also
Wow thanks yes I just tried again and now it works
nevermind i just forgot to recompile and still had the 64 in dispatch sry, it doesnt do anything
Just out of curiosity, what GPU are you testing this on?
Nvidia GeForce GTX 960
An asset from the store is running with Rendering Thread Time of 1.3 ms in a URP project and 0.3 ms in a Core project. The shader is clearly not URP (it's using CG). Would converting the shader to using the URP/HLSL likely improve the rendering time? The shader ... runs, but it's not functioning entirely as it's supposed to. (apologies, I'm a shader noob, just trying to understand if I'm on the right track)
I believe there might be an issue with coords3Dto1Dindex. example:
chunkSize = 0
coords3d = (1, 1, 1) -> coords1d = 1 + 0 + (1 + 0 + 1) = 3
coords3d = (1, 0, 2) -> coords1d = 1 + 0 + (0 + 0 + 2) = 3
So it may be running 512 times, but overwriting some of the results
My brain is not awake enough to divide out the permutations to see if 512 would resolve to 64 unique indexes or not
I checked this coords to index works correctly .
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
for (int z = 0; z < 8; z++)
{
Debug.Log(x+8*(y+8*z));
}
}
}
This how you get all permutations
I use unity 2022.2.2f1 and I don't understand where can I create shader graphs? This is the only what I have in create->shader
Do you have the shadegraph package imported ?
I don't have it in package manager
Top left, change to packages in unity registry, locate shadergraph, and install
oh, thanks a lot
Shadergraph is now (somewhat) compatible with the build in pipeline, but you might want to install the universal render pipeline instead (no need to have both SG et URP, only URP is enough as SG is a dependency)
I just thought it's like built in feature to use without installing something
I want to make something like this from Bowser's Fury. The object is invisible until the player gets close. Only the parts of the object that are close to the player are visible. How would I accomplish something like this (preferably with shader graph)?
P. S. There is also backface culling
Why not disabling the whole object until the player gets close?
I misread, I thought they were all +. Not enough coffee
all good that was one of the first things i checked, appreciate it anyway
I spend most of my day on this now and I am getting super frustraded cant find any usefull information anywhere
I want to enable only the part of the object that is close to the player
So the far away parts are invisible
Alpha mask pixels based on the distance to the player, and a gradient texture (center/edge gradient of the hexagons)
Ah ok i get it sry
Thank you for answering. I am very inexperienced. Can you give me some pointers/link to a tutorial?
I don't have any handy, search for some terms and you might find some : distance mask, alpha clip, distance dissolve ...
@sacred hull One other option I could think about is never to render the object and instead render a simple mesh in front of the object whenever the player get close enough. That mesh could have that hex texture and move with the player
I imagine this would be easier to achieve if your not good with shaders
Do you by any chance have another computer you can test this on? I can't see why your code wouldn't work. Might also be useful to try to create a minimal reproducible project.
I just decided to make that minimal project ๐ but havnt had the motivation yet, i only have one computer
Do you think it could be sth which is completly unrelated like I dont now some windows security feature or sth like that?
just throwing out some info here not sure if it helps or not but maybe will spark some ideas. The value of id will be:
(gid[0] * threadNum[0] + threadId[0]) // id.x
(gid[1] * threadNum[1] + threadId[1]) // id.y
(gid[2] * threadNum[2] + threadId[2]) // id.x
Not sure what you mean by that ? i checked the values for id.x,y and z and the once for y and z are always 0
how did you check this??
I've been struggling to debug
doing all the math by hand
you can write the thread indicies directly into the buffer
what is the value of pointsPower3 in your code?
8 to the power of 3
ok well one thing that strikes me is you might have too many indexes
so you are dispatching with 8,8,8 and num threads is 8,8,8
so that means you're going to have 8^6
I think, either that or 2*8^3, let me look it up
yes that should happen but it doesnt
If it's something like that, I would guess it's a graphics driver issue.
it does not matter what i am putting into dispatch except for the first number (that screenshot is a bit misleading)
what happens if you set [numthreads(1,1,1)] and shader.Dispatch(0, 8, 8, 8)?
also maybe dumb question but I'm used to seeing this:
_generateFractalNoiseHandle = shader.FindKernel("GenerateFractalNoise");
you are pretty sure that's 0?
you are i right i should be like that
so
dispatch(0,64,8,8) = 512 indicies
dispatch(0,8,8,8) = 64 indicies
dispatch(0, 1, 1, 1) = 8 indicies
dispatch(0,1,99,2)= also 8 indicies
understand the issue here?
yes and it does get executed j
and what's numthreads for these on GenerateFractalNoise? all 1?
any idea where to find informations about such known issues?
8 but the issue is always the same no matter the amount of threads workgroup y and z simple get ignored for some reason
I've never heard of an issue like this, but it can't hurt to update the graphics driver.
they seem to be up to date but I am updating windows now we will see
@grave meteor @low lichen Thanks for all your help I did a windows Update and now it works, there goes a whole day of my life. Some days I really hate programming grrr
So all you do is Assets > Skybox image > Lighting ?
Window > Rendering > Lighting
really??
Ty :) I'll try in a bit
Well I'm new to the ComputeBuffers but there is definetly something strange about the indexing:
It's like it's going in groups of 10 for some reason and I'm not really sure why
oh wait, I'm an idiot
there's some nuance there
so looks good ?
yeah everything good I was just trying to replicate your code to try and help with the issue, but I'm new to ComputeBuffers and HLSL
Learned a lot today!
Thank you for this. Not really what I was looking for but it gave me another idea
yes me too but I recently made an endless procedually generated world and now i want to redo that project but bigger better faster thats why i am looking into compute shaders. It just so hard to find good information on how to use them properly
I am using world/object positions to wrap textures on meshes and I ultimately want to use this to make this kind of 'stepped' appearance in the normal map
How do I correct the normal texture values so that they are always going the correct direction?
better example
the normal looks right at the start, but when I rotate it, the normal doesnt rotate so it becomes wrong, ideally I want it to rotate with the mesh's surface angle
I know the sollution will involve something to do with the object surface normal and a dot product of the world normal vector probably
but I don't know how to reach that sollution
like if this were to be a circle instead of a line, I can't just rotate the red channel
something like this is what I am trying to achieve, where it has normal mapped edges based on height, that light correctly
i've tried texture based and procedural based and neither has given me the desired output
because I am too inexperienced, not because the techniques dont work or are impossible
getting stepps is easy but I can't generate a normal map from them that doesnt look like un-antialiased dogshit
How do I combine these two outputs into a UV channel that will wrap that normal map around the contour lines?
How can I set a value of the shader from a script? The following didn't work:
floorMaterial.SetVector("Player Pos", new Vector4(transform.position.x, transform.position.y, transform.position.z));```
Player Pos is the nice name, you need the reference name
which is probably something like _Player_Pos
Thank you
I dont know regular shaders but shader graph has the reference as pictured there ^
Yup that seems to work
closer-ish but its still rendering wrongly at weird angles
and for some reason doesnt work at all on a cube
this is totally different math but same result
im orbiting around getting it perfectly right
but I dont know what I am doing wrong to correct it to get it rigght
can you help? I won't be abkle to get this on my own
better but not better
what do I do in order to wrap the normal around the mesh?
giving up for now here, I cannot solve this without help and no one seems to be around
I am making waves, depending on the height of the waves it should change color so i give it a better overall apperence, So what i am trying to do is blend the colors with a lerp. Like this
but the result i get is
The green is the second color and should only be on the top of the wave instead it comes in a pattern of stripes
Is it possible to make loops in shader graph?
Like a for loop
So I have this shader that uses a vector3 position to do a "reverse dissolve" effect. Right now this only works with one object's position. How could I expand it to work with infinite objects? fx. bullets, multiple players, etc.
They need to be implemented using custom functions
Damn. That sounds hard. I assume it is a whole other language for shader code?
Just HLSL
Never used it. Probably not a bad thing to learn tho
It's actually not that bad as long as you kind of realize it's pretty limited
This Udemy course is good: https://www.udemy.com/course/compute-shaders/
Compute Shaders vs Custom Render Textures.
What are the differences between these two approaches? Because I can see only one, CRT works on all mobiles, but ComputeShaders only work on compute-capable mobiles.
If I want to create for example a plexus effects, it is possible with both approaches. So I don't see benefits of using compute shader instead of storing and processing all the data in a texture.
As far as I know you can't use Dictionaries there, so for hashing you need to implement your own system. And they for mobiles looks like the CRT is better.
Am I wrong, or missing something important?
this might be a simple or really complex question but I just dont know, how would I loop through every face on a mesh, and then check the texture ( in this case, a render texture ), and if the triangle contains a specific color, run code that inverts the normal of that face ( which effectively 'hides' the face )
im very new to shaders in general so ive got no idea what im doing
you can try different approach, like instead of calculating each object's position inside shader, you could render/blit a circular gradient texture to a render texture, then fetch the render texture to a dissolve shader.
heres some psuedo code i wrote in the fragment shader
I might be wrong, but I don't think it's achievable on fragment or surface shader since they work in fragment level
It might be easier to do that by script(c#) instead
when i asked how to do that by script i was told to do that by shader
bc its not possible to 'hide' a specific face on a mesh without shaders in an efficient way
'hide' a specific face on a mesh without shaders in an efficient way
Yes, this could be done by shader
but
loop through every face on a mesh, and then check the texture ( in this case, a render texture ), and if the triangle contains a specific color, run code that inverts the normal of that face ( which effectively 'hides' the face )
this could be far easier if done by script
how tho
Im still trying to make this work but Im just circling the drain on my own, making no progress.
Still trying to contour a mesh with stepped normal mapped ridge lines
it works in object space sorta but I need it to work in world space, and it just cant make the transisition without completely fucking up
its a struggle to debug ANY part of it
Are there any tutorials or resources for how to use a shader to dynamically transition from one texture to another? For a 2d grid with blended transitions from grass to dirt (or sand, or water, etc.).
except it doesnt work in object space either really
its just completely nonfunctional and hours of my day have been wasted trying to get it working when I know anyone competent with the free time could solve it in 10minutes :/
I am using URP. I cannot figure out why no matter what I do the preview and view in actual game is pink, even when it is just the default shader graph
why isnt this effect centered?
its clearly centered on the left but when it gets used, its offset by like 50% downwards
how do I orient this texture away from the pole
I want it oriented from the slope angle
working fine in one direction
but as soon as you rotate it, it stops working
expected behaviour: slope remains stable fall down
I need it to not do that
its doing that because im projecting the texture against its side on a single axis
because I dont know how to wrap the texture around it uniformly from all directions
how do I uniformly project a texture around a mesh from all directions in order to get stepped height contour lines?
I NEED this solved but I can't do it myself and I can't seem to find any help
ill try back later i guess, all I can do is repeat the same thing over and over and over until someone helps me
I'm having trouble with a pixel perfect shader, anyone willing to take a look?
the problem is that when I round the UVs to pixels, it works fine
however, if I want to offset the UVs by a sub-pixel amount afterwards it doesnt seem to work
Hello everybody. If I set two world space coordinates to a shader, in the fragment how can I calculate the line of pixels connecting the two coordinates? Thank you.
you might want to look at a tecnique called triplanar mapping
or fix your uv maps
I do not really understand if you want to offset uvs the uvs at the end need to ve between zero and one
this is the shader for a post processing effect
the part where I want to offset the UVs is where the add is
its set to 0 in the image
but the idea is that if i offset the UVs by a small amount, the entire screen should shift a small amount
but its only able to shift in large pixel increments
large pixel being the pixelized resolution, which is 4x smaller than the actual resolution of the screen
so each large pixel is 4x larger
or made of 2x2 actual pixels
to downscale the entire screen for a pixel perfect effect
if you do not round it is the offset then correct?
yeah
so in the second image if i get rid of the floor node
it works fine, and can offset by small amounts
I do not kinda get the floor node usually when you want something in pixels you multiply the uvs with the pixel parameters and thats it
im trying to pixelize the screen
so for example, if my pixelized resolution is 480x270 but the screen resolution is 1920x1080
then this rounds each UV to the nearest "pixel"
you could just multiply the uvs with 1/4 of your pixelRes
doesn't that do the same thing?
The texture i'm sampling is the screen color texture, which is 1920x1080
can someone tell me whats wrong? it shows the the skybox is blue but not he geometry? it will only show it blue if the camera y value is < 0
@tight phoenix
Am I wrong to say that you want a shader that makes "height steps", on any give geometry ?
This will probably be very hard to do with regular UV texturing.
However, you could so some trickery with shadergraph provided nodes to manipulate the object normal.
Take the object Y world position as input, and make it a sawtooth wave to have looping black/white gradients.
Use this to scale the Y value of the world normal.
Apply this back to the object normal, and you should have something that looks like what you want.
ill try this
also is there a way of only rendering certain layers in a renderer feature? is there a way?
??? erm, my message was for an other question, not your water effect ๐
oh
thats fine but is there a way to render certain layers in custom renderer fatures?
features*
iirc, yes
oh thanks! really apreciate it!
maybe using triplanar projection?
[edit]
already mentioned above
@tight phoenix Here's a simple graph I made based on what I said :
Fanx
Hi, whenever I connect Texture Size node to my custom function in order to obtain texel size, console complains about
invalid subscript 'texCoord2' somewhere deep within shader pipeline (not within the custom function)
Can someone tell me whats wrong?
This is a minimal test setup I managed to reproduce it with. Apparently Unity doesn't like when I sample the texture myself within the function. What could be causing this? Is this an intended behaviour?
Not too sure, but usually in shader graph you'd sample using macros like, Out = SAMPLE_TEXTURE2D(tex, tex.samplerstate, uv + offset).rgb;
More info/macros listed here : https://www.cyanilux.com/faq/#sg-custom-function-textures
Otherwise, could try using regular Sample Texture 2D node and pass the calculated uv out (or replicate the code in nodes), to see if that also errors. (If it does, I'd try a newer unity version and/or report it as a bug)
How do I create a sub-graph?
create asset / shadergraph / shader sub graph
Thank you
tried the SAMPLE_TEXTURE2D, same outcome unfortunately
yeah, can't replicate with nodes as I am sampling in loop 
Does it work if you just force a vec2 value in the texelSize input ?
the moment I unplug it it compiles fine
(btw, in the code you could just do offset = texelSize * uv )
Also try using tex.texelSize instead of passing the value in
Is this possible, and if so can someone give me the industry terms/concepts I should look into?
I want a quad to render a grass texture bleeding into a dirt texture. Via code (scripts or shaders).
Can this be done within a single mesh using shaders or something? Or do I need to use multiple meshes and have the one in front fade out to expose the one behind?
The term is "layering".
Done using shaders.
that compiles fine, even though the screen is completely gray (it's a post process), thanks ๐
might get that working eventually
What does the "Preview" node do? Nvm, I'll look it up
Thanks! Looks like you can assign multiple materials to a mesh, I didn't realize that.
Is SplatMap a related concept to what you were referring to? Is the idea to use RGBA as 4 channels to control the weight of a texture at a given point? Would this process be limited to 4 texture layering?
This should be only when the mesh has multiple submeshes (groups of polygons where you can assign different materials)
Indeed, the splatmap is related, as it is a way to control how the layering of textures/materials is done.
You can use multiple splatmaps to have more than 4 layers, or use other source of information, like vertex colors, world coordinates, altitude, orientation ...
Sorry, what are you referring to when you say "this should be only when the mesh has multiple submeshes"
A surface can have only one material/shader
A mesh with multiple materials would have those materials on separate surfaces aka submeshes
I said that because since ... years, nothing prevents you to add as many materials to a mesh renderer as you want, exceeding the number of submeshes.
With the build-in renderer, this resulted in the materials stacking up, making it an easy way to do multi-pass rendering.
But with render pipeline, this is an unsupported behaviour that I greatly recommand to avoid
Okay, so am I understanding correctly that multiple materials/textures on a single mesh is discouraged? Is that where a TextureAtlas comes into play?
Discouraged even if using sub meshes?
(Googling Submesh)
Sub meshes won't allow you to blend, as it's 1 material = 1 group of polygons
If you want to layer textures, you only need a shader that loads those textures and lerps or otherwise blends them
Thank you both, I'll stop here and process this. You helped me grasp a stronger understanding of concepts I was already seeing. I know now that I'm on the right track and should probably take a step back and run through basic shader tutorials.
Note that if you want to do a terrain, Unity already has everything needed for this.
2d?
Ah, erm, no, 3D terrain ๐
Hahaha, yeah ... The 3D crowd gets all the good stuff. I was using 2D Tilemaps but they are two specific. No blending control and no ability to use large textures. The tiling nature of the textures isn't what I want.
I would love a 2D terrain feature built in, but I can't even find something good on the Asset Store.
I'm honestly considering playing with 3d instead just because of the support for it (and also because entities 1.0 simply doesn't work in 2D)
I have a value called "foamScale" that changes the size of the foam. The size changes with the scale of the plane. Is there an easy way to make it uniform no matter the scale of the object?
Don't use the UVs of the object for the foam but the world coordinates.
Smart. These are the object UVs right?
Yes
So how can I use world coordinates?
Great! Thank you
That looks great and just what I was going for! Thanks a bunch, I will implement this on my end now
implemented on my end but I did notice it gets pretty moirรฉ patterned at distance, can you think of some way to antialias that?
I just noticed it has some really strong black ridges on the underside that ill have to adjust as well
Underside ridges actually really easy to fix
fix was to make sure the surface normal is at least 1
Moirรฉ is not only related to aliasing.
But an easy fix would be to lesser the effect based on the distance to camera.
Yeah I was thinking the same thing
better view here, making sure the normal is at least 1 fixes the underside ridges
I think this is a wrong fix.
oh yeah?
if you pass in a zero value, it completely futzs up, and that's what your triangle wave bands are doing right?
I might be wrong, but iirc, normal strength node will force z value to positive.
I overlooked the issue, but a fix would be to take the z value before strength, passe through a "sign" node, and multiply the out z by it
which one is the z value, do you mean the Z from the very start when its still xyz?
because its a float with no z value almost immediately
The one before normal strength node
oh you mean this z value
Yes, the normal value
In your screenshot : the G output of the split node (that gets to Z value of the normal strength)
Thank you! Now my water is going in same direction ๐
I use tilemap
are you sure my sollution is wrong? because these normals look perfectly correct to me
can you tell me what is wrong with these normals if my sollution is wrong?
meshRenderers = GetComponentsInChildren<MeshRenderer>();
materials = new List<Material>();
foreach (var mr in meshRenderers)
{
materials.AddRange(mr.materials);
}
for (int i = 0; i < materials.Count; i++)
{
Debug.Log(materials[i].name);
materials[i].SetColor("_EmissionColor", Color.red * 64);
}
This doesn't affect the emission of my material at all. What am I missing here?
The code is a bit sloppy bc I'm just trying to make it work.
I'm touching the graph right now.
Your solution is not "wrong", as it does make sense.
Depends if you want to flatten vertically the normal between the steps or not
It's just that the normal strength calculation take as granted that z is always positive
But if this solutions fits you, just go for it
"flatten vertically the normal between the steps or not"
What does this mean exactly? ๐ค Like the slope presented is different in some way that I dont understand?
If you are saying its wrong I don't want to go ahead with it being wrong even if I think its right
or at the very least an understanding of the why\
Like I said : depends if you want to flattend between the steps or not.
First time using shader graph, why is the main preview empty?
can you draw what you mean? That makes no sense to me visually. If one is doing the left, what is the other doing??
Do you have a render pieline installed and active ?
How can one "flatten between steps" what does that mean visually, and what is the other doing if its NOT flattening between steps?
Using the default URP preset, I think thats a yes?
it worked for a bit but suddenly stopped showing
Hard to draw, as modifying the normal doesn't mean modifying the surface shape ๐
But your solution is kind of what you have in the "?" part
I am really confused, how can you flatten something but not modify its surface shape??
I know we are not adjusting the vertexes physical polygonal mesh shape
are you trying to say that between each slope here that the surface normal is completely flat while oriented upward?
whereas here the surface normal is whatever the original mesh's normal was?
okay I think I sorta understand the issue
I will try to impliment the fix for the black underside that you commented on before
I wasnt able to solve it myself
I am doing some work with shader stripping. Is there a way at runtime to see exactly what shader keywords a particular draw is using? I am pretty sure I have identified the shader/keyword set and made sure to not strip that variant but the build is still using the wrong variant
Open to any way to debug this problem really.
interesting look but im pretty sure I did something wrong
is this the expected output?
it still looks weird to me even after blending out the hard edge between top and bot
is the bottom supposed to look like that? Or am I misunderstanding how it should appear?
the fact that it looks wrong to me makes me feel/think that it doesnt matter if this is accurate to how it should look, that people wont like it because it doesnt look like how they'd expect
I think I understand it now though, the normals think the surface is either completely flat oriented upward, or completely flat oriented downward, and the slopes are completely flat as well
So whever the light is coming from, the bottom is acting like light hitting that side is coming from directly bellow, which in this case is very dark since there's no light source under it
while the rise of each slope ridge catches the light as if light was coming from the side directly which is why it forms dark bands on top and light bands on the bottom 
Whenever I take the botton right alpha node into the alpha block it retunrs in the whole plane turning inviseble. I cant figure out why it happends
I might be stoopid and wrong but maybe alpha Cliping works, if not your alpha which you are pluging in is probably 0
alpha Cliping works, thank you
@tight phoenix I've modified the graph to make my own normal strength calculation (and take into account the y sign) + add a slider for flattening between steps :
Artistic controls could be way better if you wanted to, but I'm to lazy to do it right now.
I've never used shaders in unity before, just made my first one that moves an arrow through time, does the animation just keep playing forever in the scene view? is this normal? Is there a way to make it play only while running the game?
is this the expected output?
Can someone help me translate a GLSL shader into HLSL or is there a way how i can feed / convert a GLSL into a HLSL in Unity ?
Hi is there way to round a pixel in a shader graph? I would like it to be more or less a circle, so that I could make clean territorial edges.
I meant to reply yesterday but got busy. I'm not 100% sure if I understand what you are trying to do. These things can be hard to explain. Idk if I can be of much help, but I'll take a crack at it.
SphereMask node
I am using texture as a mask, I cannot use UV map to produce the circle, as I wanna smooth it between two pixels aswell
I got pretty close now by using a blur filtering to get it closer
You can use object position to get something similar. Depends on the rest of the graph though.
I cannot, this is what I have, a mask texture which I would like to smooth out. using sphere mask alone does not produce. In the last image its not perfect but the closest I got with blurring the texture in shader and then running through sphere mask.
Oh ok yeah now I get it... Hmmm. This is an interesting use case.
Can anyone tell me how HLSL handles decimals when you cast from float to int? Like if you have a float3 test and you do int3(test), will that variable be floored or truncated?? I'm having trouble hunting down some rounding errors...
Every programming language I know truncates. I can't imagine HLSL is any different...
i see, thanks
hi, i'm trying to follow a whirlpool shader tutorial from 2019 into a unity 2022 version. i'm on a step where you're supposed to connect the Power Out to a Lerp T but it's preventing the connection... is it apparent what i am doing wrong?
so im working on getting unity lighting working in my shader, and i wrote what i thought was a simple chunk of code
but it produces SEVERAL incorrect outcomes
fixed4 pixColor = tex2D(_Albedo, IN.uv);
float4 worldPos = mul(unity_ObjectToWorld,IN.vert);
float4 worldCalc = normalize(worldPos - _WorldSpaceLightPos0);
float lightDir = dot(UnityObjectToWorldNormal(IN.norm), worldCalc);
float3 litColor = pixColor * _Color * _LightColor0 * saturate(lightDir);
return float4(litColor,1);
firstly, ill say what i meant this code to do, i meant it to take the world position of the vertex, then subtract that by the world space position of the pointlight in my scene, then get the dot product of that vector and the object normal in world space, then multiply the albedo by the tint color by the light color by the saturated light dot factor
what it DOES do however, is very different, i want to say before anything that this chunk of code is almost definitely the issue, ive gotten it to work with directional lights and im trying to get it to work with pointlights, and its this chunk of code that im having issues with, not anything else outside of it
what the code gives me is this, firstly youll notice that the light seems to always be coming from one unchanging direction despite the actual position of the pointlight, and secondly youll notice theres a blinding streak of light on the left of the camera regardless of where the camera is
i dont understand what i calculated wrong to get this outcome, ive managed to get everything else outside of this chunk of code working fine, ive made my shader work with the forward rendering pipeline, set up my code in a cginc file so i can use it for the forwardbase and forwardadd pass, made sure the blend mode is ideal, ect ect, i just need help on this code right here
is there a way to create a computeBuffer whose element count depends on the contents of a shader value/buffer? Something like indirect args but for compute buffers.
I'm doing some compute mesh generation and don't want to over-allocate memory for vertices and indices
Anyone please:
Whats this error: InvalidOperationException: Failed to add object of type ShaderGraphMetadata. Check that the definition is in a file of the same name and that it compiles properly.
My Shadergraph will not load. This was just working until I updated to latest Unity ugh! There is always something...
And actually you can open the Shader Graph and see it all, it just wont show up normally so it can't be used, its not even saving...
hi, does anyone know how to achieve this effect via shader graph?
https://www.youtube.com/watch?v=pp9eml6YR5c
it makes a surface conform to any mesh shape, even animated
Surface Deformer Demo. Hosted at Unity Assetstore.
@vestal surge I would imagine (I'm still learning, so not 100% sure), that you could sample the objects height somehow and apply that to the vertex positions of your surface object? Or create a new camera (orthographic I think) put it directly above your surface object and use it to create a depth texture that you could then feed into your graph and use the depth texture to drive the vertex displacement? (just guessing).
There's a section in this that deals with using the camera to generate depth.....
In this video, we'll take a look at how we can use the Shader Graph feature in Universal Render Pipeline, or URP for short, with Unity to create a water shader! The water shader can be simple or complex, and include the features you desire. Let your imagination get wild in this tutorial, or simply follow step-by-step to get about the same result...
I Think you'd probably need to have your surface object and 'deformation' objects on seperate layers and adjust the cameras occlusion layers to suit (would probably need a second plane object to use as a 'background' for the depth map creation)
Awesome, thanks! I'll start checking those avenues out. 
No probs. Neither could work. lol. Like I said I'm still learning the graph stuff myself.
Soooo.......I have something I've been playing around with working, but I'm just wondering if there's a more elegant way of doing this? Basically creating a height based mask 'subgraph' with min/max height values with blending.
This is what I have, just seems a little overly complicated to me. lol.
So I removed URP, removed the URP assets, restarted Unity, reinstalled URP and created new assets from that and now it works! Something must of got corrupted when moving to new Unity version ugh...
@midnight mortar I noticed that on 2022.2 URP is all kindsa messed up. Errors all over the place and refused to create a build, after which URP was completely broken.
ie. after restarting Package Manager says URP is 'missing'
Quick comment, then I'm AFK. But I wouldn't saturate lightDir.
Also, for debugging, just output lightDir, or maybe (lightDir *.5 + .5) as a greyscale as in:
return float4(lightDir.xxx, 1); or the other expression which should put it into a 0-1 range.
Guessing here.
How would I go about implementing the fast fourier transform myself for combining sinusoids, and is it required to use complex numbers like with quaternions to make a efficient and good fft
I read the tessendorfer paper about ocean waves but I need some explanation and help
do you guys have experience with amplify shader editor? is it possible to convert unity built-in shader graph assets to amplify graphs?
You can re-do the same (or similar) nodes layout
my end goal is converting hdrp shaders to urp and the only reason i considered this was if amplify has some sort of graph converter to generate somewhat compatible URP shader from HDRP shader
Shadergraph now supports multiple pipelines
You "just" have to add URP as shader target in the graph settings
since which unity version?
2021.3 iirc
Is there a way to pause an animated shader in the scene view?
You can disable animated materials in the top settings of the scene view
Which icon is it in? i tried looking for it but couldnt see it
"Always Refresh" here
It is turned off by default, but the animation still plays and jitters a lot
i guess its playing on editor Update() cause if i hold rmb it plays smoothly
wondering if there is a way to completely disable the animation in the scene view
If your shader is using time, it will alway refresh during an update
i see
Another general question, shader graph seems like a lot of fun and id love to get into learning it, but from the (very little) testing ive done so far, it seems extremely buggy, random error messages when connecting nodes, main preview window bugging out, etc.
Is this to be expected? Im not on the latest version of unity so that could be it, but im wondering if thats just the state of shadergraph and everyone just deals with it or if my editor is just bugged
IDK what version you are using, but it should be fairly stable
Uhh, the preview still shows but the shader turned white randomly
Texture not applied on the material ?
The last thing i did was rename this, and it stopped working after that i think, the name has no effect on what happens right? Im not using any code
it was working until now, just stopped working, so im guessing it is applied, how do i check if its properly applied?
IF renaming also changed the Reference name, then the value that was set on the material is lost, as the material saves the properties bases on the reference name
Just check that in your material inspector the texture is assigned where you want it
Is setting Always refresh graphically expensive? Im just moving an arrow on the x axis here but would that ever be a concern?
anywhere I go no one can answer, is this topic this unknown?
I have notions of fourier transform, but that all, sorry
No
Hi guys, I want to see front and back faces through the model but this is kinda messy... I want only the "faces" from the back and not a "back renderer"? Any idea?
Hey,
How to make a billboard renderer?
With this it seems like the mesh rotated away from the camera.
Also it's affecting z and x I only want y to be affected.
The code is in the thread
Billboard Renderer
Guys im new with shaders, can someone help me on this issue: I have written some simple animated noise shader code that returns the "fragColor". When applied to an image sprite it displays the black and white cloud noise. However what i wanted to do is to use it as an alpha mask, and i am currently struggeling to do that. I tried to use my final noise variable "fragColor" red channel as an alpha mask for the main_color which is my _MainTex:
float4 main_color = tex2D(_MainTex, i.uv);
main_color.a = fragColor.r;
return(main_color);
But this doesnt work.
does anyone have a shader that hides objects behind shadows in 2d?
ive been researching it for a while but everything ive tried is either outdated or just doesnt work
kinda like among us
Someone know why it is pink?
@grand jolt do you have an ENDCG ?
what is that?
I downloaded the shader from github
You need a CGPROGRAM ENDCG tag around your shader code, just create a new shader in Unity Create-> Asset -> Shader and see in their template
looks like one is missing to me
Shader "Alpha Mask/Bumped Specular" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_SpecCol ("Specular Color", Color) = (1,1,1,1)
_Spec ("Specularity", Range (0,1)) = 0.8
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpMap ("Normal Map", 2D) = "bump" {}
_Mask ("Mask (A)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Spec fullforwardshadows addshadow alpha
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _Mask;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_Mask;
};
half _Spec;
fixed4 _SpecCol;
fixed4 _Color;
half4 LightingSpec (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
s.Normal = normalize (s.Normal);
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, 4096.0 * pow (s.Specular, 2)) * s.Specular * 2;
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec * _SpecCol) * atten;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Specular = _Spec;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
o.Alpha = tex2D (_Mask, IN.uv_Mask).a;
}
ENDCG
}
FallBack "Diffuse"
As you can see here
What are possible causes of this seam in a tri-planar projection shader?
The sphere is a default unity sphere, is it the mesh itself? the texture?
completely basic tri planar set up
I checked the normals, UV seams, everything I could think of, none of them show any kind of seam at that position
yet a seam exists
it looks like the normal map is inverting at some point?
https://bgolus.medium.com/normal-mapping-for-a-triplanar-shader-10bf39dca05a reading this now as it might have the answer
@tight phoenix Dumb question maybe, but : why don't you use the triplanar node ?
How do I pass in more than one texture?
Also, you've mixed the axes when blending.
The easy way to blend triplanar is :
Output =
Sample of position XY * normal blend Z +
Sample of position ZY * normal blend X +
Sample of position XZ * normal blend Y
Ah, you don't
Can I shamelessly recommand my repo (old, but should still work I guess) ๐
? : https://github.com/RemyUnity/sg-node-library
There is some nice nodes for triplanar.
You'll have to unpack the normal yourself though.
I will take a look at these
What does this mean exactly? Will it fix my normal issue?
What are Z, X, and Y in my circumstance? Does this replace the lerp? I don't have a single zxy, I have three afaik
"North South" : XY
"Top Bottom" : XZ
"East West" : YZ (Should be ZY imho)
Like this?
Are you saying my problem is just semantics? Or are you saying I need to change my math?
Sorry, wasn't clear : normal blend in my words was the weigth for the blending of each planar projection
I inverted ZY because it looked completely wrong
and that fixed it from looking completely wrong
the texture was rotated 90 degrees
I have no idea what you're trying to show me here, you just want me to change the order in which I combine the normals?
I don't see why it matters if I add X or Y or Z first or second
why do they all go in B instead of A?
Switching tops to bottoms doesnt appear to make any difference at all at the final output
Just look at the first lerp node : you are lerping from the normal value to 0, bases on the weight.
Only 1/3 of the faces should be affected but you have 2/3 : the lerp is done in the wrong order
in the end all 3 axis get the correct textures in the correct positions, I am not understanding why its wrong, how can it be wrong if the result is correct?
Ok, well, if it's correct, don't change it
I mean it works both ways
you arent wrong either
switching A and B in all of these makes no difference to the end output
hm actually it might, let me check that closer
Well, maybe something else is wrong (or maybe it just looks the same), because switching A & B on a lerp inverts the result
hello, so i'd like to know how can i change the properties inside of a script? so that i can then connect two values, 1 from script, 1 from the shader graph
yeah either way output is identical
let me scroll back up through your posts because you had the answer to somehing but now its lost before I got to it
currently trying to fix this weird normal inverison thing happening
From script you can change the values of materials with the different Material.Set... functions
am i doing something wrong here?
more pronounced on the bottom side
No
well idk the values don't change for some reason
Is the property name correct ?
And it's set properly on the script component ?
i think so, i put the script inside fixedupdate
Everything seems correct to me and should work then, so maybe a bit of information is missing if you're 100% sure that it doesn't
i accidentally seemed to forget to put on the shader onto the material, i did now but it still doesn't work weirdly
btw how do i know if the value has changed?
this?
Inspect the material that is affected by the script
oh i'm stupid, it does change
just looked at the inspector
but for some reason this doesn't change
it just stays the same color and it's supposed to be different
This is connected to an output of the shader, right ?
yes
now it is
but the thing is
wait nevermind i thought i had an idea
i thought that the material changed itself
but it's probably because i changed the value in the inspector
but the thing in the shader graph still no work
but when i change the default value it does something
What do you mean ?
Changing the value on the material will not affect what is visible in the shader graph and will no change the default property
but isn't the propery value and default property the same?
property
i thought so
so what is this
Default property value is what you set in shadergraph, and what value the material will have when created
The default value visible in shadergraph ? You don't
Why would you want to change this ?
so that it actually changes the gradient noise
You change the value on the material
Figure the material as a "variant" of the shadergraph, having the exact same behaviour, bur using it's own input values
No, it will not change anything in the shader / shadergraph
BUT, as the noise scale value is controlled by your exposed property, and you change the property value on the material through script, the noise scale of this material will change
wait so can i just set the default value in the shadergraph?
and it will just be that?
- You can not set the default value in shadergraph through script (or at least not in a trivial way)
- The default value is applied on a material when it is created. If you try to change the default value afterwards, the material will keep it's previous state as it has saved the value for that property
still trying to solve this weirndess, I cannot find the source of the problem to fix it
the normals appear to be inverting their direction
I dont understand how this could hapen
it cant be the mesh or the UVs of the mesh because neither is being used
I dont understand where this little wtf is coming from
its even more pronounced on the cylinder
how can this physically occur, it cant because I'm not using its UV, im projecting onto that surface
where is the wtf coming from?
very clearly wrongness
Does anyone know how to include the Gizmo.hlsl file in a URP shader? I am trying to write one that only is rendered when gizmos are turned on, and have the allowing line currently.
#include "UnityPipeline/ShaderLibrary/Gizmo.hlsl"
but don't see that file in there, and can't find any references to how to do it online.
Shader error in 'Custom/Edge Highlight URP': Couldn't open include file 'UnityPipeline/ShaderLibrary/Gizmo.hlsl'. at line 21
At a guess I'd say from the tangent->world transformation (that shadergraph is doing behind the scenes). That uses the Tangent and Normal Vectors from the mesh. And afaik the tangent vector is aligned to the UV.x. So the UVs could still be the cause for this weirdness.
How would I correct this?
can it even BE fixed?
is the problem the mesh? Will i have this problem in other meshes unexpectedly?
I guess check the uvs, but idk
its the default unity mesh, how would I check its UVs?
I cant exactly export it
the problem appears to be related to the 0 position maybe?
its trying to align the normal direction but is shitting itself in some way?
there is a very clear fuzzy line where the UV direction is getting inverted
on one side to the other side you can clearly see what appears to bump IN is now bumping OUT
and I dont know why or how to fix it
the normals are clearly invertign
and I cant solve it
i cant figure out why
or how to fix
one side is completely backwards to the other
how do I fix this?
I am googlign and googling and Im not getting any results at all
every time I have a problem its like I am the only person to have this problem ever in all of history, which cannot be true, and yet I can find no results
getting burnt out again
I HAVE to solve this because as long as it goes unsolved, I cannot trust any normal map on any mesh anywhere ever to be rendering correctly
there is a very clear line where the normal inverts
This line looks like it could just be the "edge" of the lighting.
Where the normal is perpendicular to the light direction
better example, I don't see how that's the case, its clearly inverting
the 'up' ridges become 'down' ridges
Last time I looked at it, it was an error from mesh tangets, as sampling normal map relies on mesh tangent data. if not provided in the mesh I believe it gets generated in vertex stage or smt, its always hard to do normals on sphere.
it cant be a lighting direction problem because the light is hitting the same side
a non-unity sphere has the same problem
they're all inverting and I cant solve it and I need to solve it and I dont know why its happening so I cant solve it but I cant stop trying to solve it because I cannot do anything else beyond this step until it solved
another example of CLEAR inversion occuring
when exporting your mesh make sure you are exporting tangent data, and when importing in unity make sure to set it to use Import undet Tangets data
its not the mesh, it cant be the mesh because EVERY mesh is doing it
I dont know what that means, these are meshes from the net, not mine originally, I dont think its unreasonable to think that all meshes are wrong
here is that mesh, what should I change?
under Tangents choose Import
that does look better, I am not sure if its correct but it looks better at least
it still very much looks like its inverting
are triplanar normal maps maybe just impossible?
because its really feeling like right now its simply not possible to do normal mapping in a tri planar set up because it never works and no one can tell me how to make it work
and most meshes from the net do not have Tangents data, Blender does not export them in default mode either, Calculating them in Unity is not the same as its approximation. Also just using a normal map like this and expecting it work is never the best idea.
there is a Triplanar node in shader graph which can do normal maps aswell
it only takes in a single texture so its useless to me
I dont want to map one single texture on all directions
useless without multiple texture support
looks even WORSE
Then you can use the Unity Shader Graph documentation and write your own triplanar custom function which takes different textures for each side. https://docs.unity3d.com/Packages/com.unity.shadergraph@13.1/manual/Triplanar-Node.html
also very clearly still inverting
so theirs doesnt fix this either
this guy shows the normals inverting
and solve it in his
but I cant figure out how to use his sollution because its all HLSL CG code
calling functions I dont have access to
How am i the only person in the history of 3D to have this problem
surely someone else somewhere has used normal maps before and encountered this problem
why is the sollution impossible to find
I cannot be the first person, its not physically possible
the normal blend doesnt appear to be the problem
because a single normal map with no blend at all is having these same issues
why isnt this guy's mesh having the same inversion problem that all meshes i try have
UDN and Whiteout methods works fine in ShaderGraph
why do i not see the preview of the shader?
also i get this
pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
Compiling Subshader: 0, Pass: Universal Forward, Fragment program with <no keywords>
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: DEBUG_DISPLAY DIRLIGHTMAP_COMBINED DOTS_INSTANCING_ON DYNAMICLIGHTMAP_ON FOG_EXP FOG_EXP2 FOG_LINEAR INSTANCING_ON LIGHTMAP_ON LIGHTMAP_SHADOW_MIXING SHADER_API_GLES30 SHADOWS_SHADOWMASK UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING _ADDITIONAL_LIGHTS _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHT_SHADOWS _CLUSTERED_RENDERING _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 _LIGHT_COOKIES _LIGHT_LAYERS _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN _REFLECTION_PROBE_BLENDING _REFLECTION_PROBE_BOX_PROJECTION _SCREEN_SPACE_OCCLUSION _SHADOWS_SOFT
hi im working with low-res pixel images (the one in this sample is 64x64), how can i make the preview in Shader Graph not appear blurry?
He is not using any extra data, so its should not be mesh then, I have tried all the cheap methods from that site and all works.
Hm your mesh does not have a weird pole at the top?
Can you post a screenshot of the pole of that mesh? Or better yet the fbx and shader? So that I can compare it to mine to see where they differ
No, it does not, as its not using mesh normal/tangents data.

mine IS using that data because im plugged into the normal node?
Im using the function from the site you sent
oh yours is plugged into the normal node
Did you have to manually convert them to functions? I couldnt make heads or tails of porting them over
nope, unity is now using HLSL so all the functions works as expected, you just have to supply your own inputs, as there is "i" but here you do not the that data so you have to put it there yourself through custom function fields
I know that unity custom nodes require it to be like
thing_float(variables, out results)
{
// code
results = //code
}
are you saying you just copy and pasted the code wholesale? Without re-writing the entire thing?
im using in shader editor not file
yes I only changed the different fields to mine
What is 'Shader Editor' ? You mean as a string instead of as a file?
I've never gotten that to work before, it always errors
Give me a moment to write the variables up
// Triplanar uvs
float2 uvX = i.worldPos.zy; // x facing plane
float2 uvY = i.worldPos.xz; // y facing plane
float2 uvZ = i.worldPos.xy; // z facing plane
// Tangent space normal maps
half3 tnormalX = UnpackNormal(tex2D(_BumpMap, uvX));
half3 tnormalY = UnpackNormal(tex2D(_BumpMap, uvY));
half3 tnormalZ = UnpackNormal(tex2D(_BumpMap, uvZ));
// Swizzle world normals into tangent space and apply Whiteout blend
tnormalX = half3(
tnormalX.xy + i.worldNormal.zy,
abs(tnormalX.z) * i.worldNormal.x
);
tnormalY = half3(
tnormalY.xy + i.worldNormal.xz,
abs(tnormalY.z) * i.worldNormal.y
);
tnormalZ = half3(
tnormalZ.xy + i.worldNormal.xy,
abs(tnormalZ.z) * i.worldNormal.z
);
// Swizzle tangent normals to match world orientation and triblend
half3 worldNormal = normalize(
tnormalX.zyx * blend.x +
tnormalY.xzy * blend.y +
tnormalZ.xyz * blend.z
);
Out = worldNormal;```
I have to identify which variables are his and which you replaced them with
its tricky, mainly with texture2D as when you create a texture field in shader graph with the name "_BumpMap" it will throw error as it uses different variable then tex2D needs so you gotta put it there through custom function input.
I replaced every variable which starts with "i."
Ahh I see, this will be quick to change
yes, also I renamed base worldNormal to worldNorm as it would then be recreated at the bottom again
Yeah I saw that'd cause a conflict
Undeclaried identifer worldNormal
but its declared as a half3
When importing texture set the filtering to Point, you can do the same when sampling in shader and assigning SamplerState to SamplerTexture2D node.
is it b ecause its a half3?
ill try float3
stil says its undeclared
I dont understand how they can normalize it but cant declare it
for computeshaders you have a function called SetMatrixArray but in hlsl code all arrays are implicit? so what type do you need set a matrix array
// Whiteout blend
// Triplanar uvs
float2 uvX = worldPos.zy; // x facing plane
float2 uvY = worldPos.xz; // y facing plane
float2 uvZ = worldPos.xy; // z facing plane
// Tangent space normal maps
half3 tnormalX = UnpackNormal(tex2D(BumpMap, uvX));
half3 tnormalY = UnpackNormal(tex2D(BumpMap, uvY));
half3 tnormalZ = UnpackNormal(tex2D(BumpMap, uvZ));
// Swizzle world normals into tangent space and apply Whiteout blend
tnormalX = half3(
tnormalX.xy + worldNorm.zy,
abs(tnormalX.z) * worldNorm.x
);
tnormalY = half3(
tnormalY.xy + worldNorm.xz,
abs(tnormalY.z) * worldNorm.y
);
tnormalZ = half3(
tnormalZ.xy + worldNorm.xy,
abs(tnormalZ.z) * worldNorm.z
);
// Swizzle tangent normals to match world orientation and triblend
float3 worldNormal = normalize(
tnormalX.zyx * blend.x +
tnormalY.xzy * blend.y +
tnormalZ.xyz * blend.z
);
Out = worldNormal;```
you have to declare it in custom function node
is this not declaring it?
What is that if not its declaration?
yes but rename the ones above to the one you set in custom function
wonderful, thank you
What value should Blend be?
its still doing it, there is still the distortion
if im using the exact same code as you, and the same mesh as you, then its the normal map that is wrong?
I do not understand
you have to pass it into Normal World Space output
I sent you the graph above, or for test you can just use worldNormal and using absolute node on it
ah okay this works
nice
the problem appears to be gone
This is already much further than anywhere I got, thank you Kristiรกn
I will read up on what it means to have the fragment be in world space and how that affects the rest of the shader behaviour and the like
alright
hi, for some weird reason i don't see the skybox and when i look around, the sky that isn't actually a sky, gets very blurry and it gets worse the more i look around, and when i try to replace the skybox it just doesn't work
also the sky getting blurry just happens during play mode
and i didn't know what place to put this in so i put it here
since i'm currently working with shaders and maybe something messed up
in scene view you do not have skybox toggled, also it looks like in game view you do not have initialized background, go into your camera and look for Background Type
i did all the things you told me to, but the same thing happens when the background type is set to skybox on the camera, although when it's set on solid it works, but that's not what i'm trying to do
unless the whole project is broken or something
Okay, then check if you have skybox material assigned in Lighting window. If you do make sure the material uses shader compatible with Unity
hm, when i set the skybox material to none, it works but when i set it to any material it just goes back to being broken
what shader does the material use?
cubemap
skybox/cubemap it says
just some random skybox texture i downloaded
i'm guessing skyboxes work with universal render pipeline?
procedural?
i'm sorry i don't think i understand what procedural is, all i'm familiar with is procedural generation, which is what i'm doing in this project
change the shader to Skybox/Procedural
I might be out of ideas now, never seen this happen elsewhere :/
it's fine, it was just a little project for me and my friends but i can always restart and do something else
I was thinking about this again while I was working on some shaders. It looks like everything is on a normal square grid, right? If that's the case maybe you can have another grid for the borders and populate it using premade border shapes with a marching-squares implementation?
Yeah thought of it aswell, but for now I will stick with it as doing marching squares on this size of the map could be pretty taxing on performance
hey guys how do i make a object always be rendered
i have a problem with the guns clipping through objects using a camera but is not being affected by the lights and shadows
Did it help to show anything?
i havent yet tried it admittedly, but i will say that i saturated lightDir to make sure that faces with normals opposite to light direction wont have a -1 lightdir factor
its for blending multiple lights, because im using forward rendering
Yeah, OK, so you'll be getting 0-1 values. but if your results are wrong, at least you'll be able to see what the values of "lightDir" look like for debugging purposes. As you know it should be the light intensity (not direction) as a float, so you should end up with a greyscale N dot L result, either saturated or not.
If you don't, the calc is messed up somewhere, otherwise if it looks right, the problem is elsewhere.
yeah i tried that
it looks the exact same, just without the albedo or color, so its safe to assume that lightdir is the issue
however, i will try to unsaturate it
for debugging purposes
also the exact same.. hmm..
Looking at this code again, the first two things after the texture read are usually done in the vertex stage of the shader, if I'm understanding it properly. The results of that go into the v2f and are interpolated across the triangle.
But the return statement implies that you're showing code for the frag stage.
Those two lines, I think so.
What you don't want to do is the ObjectToWorld twice either. IDK if you are.
Since I can't see the vert() function.
i didnt do objecttoworld for anything in the vert function
the vert variable is just unityobjectotclippos im pretty sure
OK, tricky stuff.
UnityObjectToClipPos is a "compound" thing.
It converts objectToWorld, then that result to view space, then to clip space. ๐
All in "one" sneaky matrix multiply.
It's actually a function that operates differently based on needs, but yeah....
hm, neat
so i really shouldnt be using objectotclippos, because it is already doing objecttoworld with more things added on, that i could probably do based off of the converted vert pos
Well, ObjectToClipPos is needed to output the result tagged with SV_Vertex/POSITION from the vertex shader.
In fact the vertex stage is required to output a variable in clip position. So something will have to use it.
Between the vert() and the frag() the GPU automatically does a perspective divide, dividing the result by the .w component of the clip pos giving perspective distance to the result (squishing things more toward the center of the screen the farther away they are). That all happens during rasterization.
alright
If you want to track worldPos, interpolated across the polygon, put it in a variable in the v2f and let the interpolator do the work. The frag() can just use that to calc the vector between it and the light, giving you per-pixel values if you want.
You could interpolate that vector too, in fact.
so i really have to have objectToClipPos, because alot of important processes happen there, and id be doing alot more work to replicate it rather than just using it, correct?
actually im not sure if i could replicate it
alright
Yeah, the vert() has to output it.
There are several ways to handle this. This is the easiest way: https://www.youtube.com/watch?v=OMVYyW54QlE
#JIMMYVEGAS In this Mini Unity Tutorial, we show you how to stop your weapon clipping into objects, whether it's a gun or sword or anything.
โฆ Subscribe: https://goo.gl/gidCM5
โฆ Patreon: http://patreon.com/jimmyvegas/
โฆ FREE Assets: http://jvunity.com/
โฆ Facebook: https://www.facebook.com/jimmyvegas3d/
โฆ Twitter: https://twitter.com/jimmyvegas17...
so using what youve said, ive managed to get it working to an extent
lights are sorta working, but i think theres something a little wrong with my calculations, that i can probably figure out
What would be the use case of discard vs writing to a Stencil Buffer in a pass and then comparing in order to not write pixels? (Other than the obvious that discard is easier to implement
well way stencil buffer discards is the same
but discard can be used for anything, you could discard a fragement based on a condition
I guess using the stencil buffer is useful for complex comparisons
with stencil its just based on a comparison with the stencil buffer
yea
i find i rarely use discard on its own
generally just something that is being done based on my stencil comparison
I have two textures on a material, one is the main texture and the other is an alpha mask (for reasons). I don't know if I should be discard ing the base texture pixel based on the alpha mask or just output an alpha value of 0. But If I output the alpha (even at 0) I get garbage
It seems like alpha 0 is correct, but discard is working for me ๐คทโโ๏ธ
what platform?
windows
will be fine then
Oh, is this just an Editor thing?
no, more or less its just more expensive to discard on tiled renderers and mobile
i c