#archived-shaders
1 messages · Page 4 of 1
it does the same in scene
I can gif capture it there but it will be the same
im assuming nothing is showing up because the dot product is returning zero between whatever the RNG colors are and the object space view direction?
seems like your normals or view angle might be in world space, goingt to object space might help that
naw it was in object
if I absolute it so there are no negative values, that 'fixes it' by making the values never negative
but im not sure if that is the correct fix or if that is doing something else that will shoot me in the foot later
im guessing the back side was dark because its the dot of the negative values pointing into the 3d objecf
if it's stupid, but works, it's not stupid.
I mean, I hope its not stupid to take the absolute, I hope its the correct sollution. I don't feel like I am learning if I'm doing stupid hacks
I don't fully understand why it fixed it, but it shouldn't cause problems afaik
my turn to spam a bit ;]
as for things that don't work...my interpolated UVs don't work...because I don't know why?
terrain UV with normal draw
terrain UV's with instanced draw
interpolated UV's
(so far so good)
control texture, with normal draw, terrain UV's
waiiiit...it started to work out of the blue by it self now...?
lmao
Thank you Cyan and Marcin, the shader is working now as I hoped to have it look. I am still frustrated that I couldn't do it on my own but I appreciate the help
Now to start on the next bit and try not to lose my shit when it doesnt work on the first 50 attempts 💦
hey
I think I found a shadergraph bug...yay
plug it like this:
(don't mind the debug spagethi)
looks like this
plug it like this
and looks like this...
time to never use a redirect ever again 😨
seems so. Guess it's bug reporting time...?
Wow yeah.
I've never had troubles with redirects but I guess this might be a problem with using redirects with custom interpolators?
seems like it. Also never had issue with them so far
I wonder if using another node inbetween, like a Preview or an Add with 0 works still
How about Custom Interp -> Preview -> Redirect -> Sample. (just curious)
Too add to good things...they just shut of my power ;p
Construction work nearby...
Either way...I'll test this more tomorrow. But: if i plug a redirection node AFTER the preview node, it worked
But if the redirect is right before the interpolated node, it does not
look ma, sparkles at different depths 🔥
not to derail from the bug talk but am testing moving some shaders from amplify to shader graph - is it correct that properties from subgraphs or custom functions do not propagate to parent graphs?
subgraphs can take in properties like the parent shader, defined the same way. The subgraph wont have access to the parents properties unless you pass them in
or is there a clean way to do this that doesn't involve re-declaring these for every graph that will have have the same inputs?
As far as I know, subgraphs have no concept of who their parent is because you can use the same subgraph in any shadergraph
pictured above is a subgraph not having its parent properties ^
Yeah, if you need exposed properties they must be defined in the main graph and connected to the SubGraph node when used in that graph
dang, thanks
really would like to move us over but little things like this keep turning me off
You can select all the properties from a subgraph, and paste them in the parent for faster rewriting. But you will have to wire them up
cheers - perhaps i'll make a tool that does this
Is it possible to change the ZTest value of a shader in code/at runtime?
If the shader uses a property to set it, yes. e.g.
// in Properties
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest", Float) = 4
// in Pass
ZTest [_ZTest]
Should then be able to set from C# with material.SetFloat using the CompareFunction enum (under UnityEngine.Rendering namespace), might need a cast.
Ah, that's awesome, I'll give it a try now. I was just getting lost looking into whatever SubShaders are/if they could possibly help
@regal stag That worked perfectly, thanks
Hello, How can I convert this shader from shadergraph to an unlit shader? It is moving vertices down using the texture. Thats what i need.
@hazy meteor If you click the master node (Fragment), you should be able to select unlit from a dropdown
I am facing a weird issue on some mobile device. I have a very simple shader (code) that scrolls texture over time. Thing is it scrolls at very different speed on some mobile devices, it get really slow on some, and regular speed on other (same as editor). It is not related to lag, some very high end device with 30fps still get a very crappy and blocky texture scrolling. Speed is not the right word, it is the frame rate of the scrolling that is affected. Anyone has an idea^
It is a UI shader I must say
My bad I meant to convert the shadergraph to hlsl unlit shader
I noticed that my custom made shader for the leaves don't render it when viewed from a distance. (leaves slowly disappears)
It only happens with this shader, not with the URP lit shader or with the tree itself.
I'm stuck how to fix this. Any idea?
is it a shader you've writen or a shadergraph shader?
i don't think there is an easy way to auto convert. If you want to view the code generated, you can do that in the graph, but it's hard to read. Easiest way, would be to write in from scrach, using your SG as a template for the functions you are using
^
i don't know a lot about writing shaders myself but this is exactly what i'm looking for: https://www.reddit.com/r/Unity3D/comments/8h8ex2/shader_help_request_affine_texture_mapping_in_a/ i tried out the code in the reply and unfortunately it renders nothing for me. anyone can point me in the right direction? thanks!
Im trying to finish this effect that I didnt finish before
I have the inside-out UVs, and the direction of the main light
how do I use those two inputs with the Refract method to get this appearance on the left side
I was told:
So just acos(dot(object space sun direction, object space position))```
but neither of those things worked for me at all
I couldnt transform the space, and if I could, it was still wrong because it was stuck in object space and would fuck up if the object rotated at all
here is ( acos(dot(object space sun direction, object space position))
but its just white, then what? I have no idea how im supposed to use that
as color
If I use it as color, its completely wrong, its supposed to be on the inner backside, not the outer surface
but I have no idea how im supposed to combine the inside out UVs
with the other part
definitely not this, this just blows up the entire shader and screen
this is -almost- right
but something wacky is going on with the angles
also its in object space so as soon as you rotate it, it fucks up
none of this works because I have no idea what im doing
im just plugging things into things, doing math on things to see if it will do what I want
and none of this will do what I want
im a stupid ape who is literally trying everything on everything bnecause I have zero comprehension of how to actually work towards what I want
the literal only thing I can hope to do is accidentally luck into it by trying every possible combination
frustrating, getting agitated again
this seems almost right except for it being completely wrong
and I cant figure out how to unfuck it
I feel like im very close to figuring it out, if only I could figure out what is causing the big black circle to form
uhhhh if I add nothing, it fixes it
I'm not enough of a mathematician to understand why adding zero actually does something
mfw
New to shadergraphs here. Made a shader that takes the vertices height into account and lerps between materials. I want to add normals to this, and setup the normals with the same lerp function. The normals are setup pretty basic (sub-tree image attached), but this doesnt work.
The error doesnt help me much with any debugging.
Here is the error:
scratch that about adding 0 fixing it, its still like this in scene even if its fixed in preview
making it a PROPERTY of 0... fixes it in scene
subtracting a property value of zero makes it work in scene and in preview https://cdn.discordapp.com/emojis/950813527260663878.webp?size=96&quality=lossless
Alright, so i came to the conclusion that the issue occurs when i add my second lerp (i have 3 in total). It is the exact same Lerp setup as done with textures. Hopefully someone can tell me what i am doing wrong :-) <3
how could I bring a float[ , ] to a shader in script
Is it a Vector2 you are looking for? :-)
Arent you looking to hold 2 floats in one? That is called a Vector2
Yes, that is a Vector2
a Vector3 holds 3 floats
and Vector 4 holds 4 floats.
I might be misunderstanding what you are looking for though. I am fairly new to shading myself.
so a float 2 i think
What are you looking for with a float 2?
(And just so you know, a float is referred to as a Vector1 as well)
to the best of my knowledge, shadergraph doesnt support arrays
https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Data-Types.html
what about surface shaders?
oh I have zero experience there, couldnt say
Heyo, I've looked everywhere for a solution to this and either there's nothing there or no one responds when I ask for help, does anyone know what causes this? I'm trying to make a map for VRChat and the water shader bugs out bad and I don't even know what to call this bug. It's the "RED_SIM Perfect Water Shaders" if that helps at all
I'm also not sure if this is the right channel to be asking lol
If not I'll move it
Im guessing that it may have something to do with a culling issue?
But I'm extremely new to Unity and don't even know where to start trying to fix it
I've been trying to figure out this single issue for months
Seems like your shader is using to many samplers? (As noted by the error, the limit is 16)
If your are sampling a lot of textures, reuse your sampler
Create one on the blackboard, and plug it to all the sampletexture2d nodes, that you use with the same sampler settings
A texture is an 2d float array. Exactly what you are asking for. Create a noise texture in Photoshop, or download one from the web, and you will haver your float2 array (even float4 actually, but you can filter that out in the graph). Or save your c# [,] into the red and green chanel's of a texture, and use that. (U can ignore the other chanel's.)
Hi, would anybody know why doesn't the HDRP lit layered display the layer with the proper transparency? Here is the texture.
And here is the result when applying this texture on any layer above 1
The half dot should be semi transparent, shouldn't it?
I tried the example from the amplify package to reveal an object when it's hit with a certain light
But in the example you need to select also a object behind it (the brick wall)
I don't want that, because I want to place those markers on walls/ceiling/floor...
But I have no clue how to do this :/
this is the graph
URP
You should use decals if you want to place them all over randomly
I'm not sure if amplify supports URP decals, check docs
seems like amplify has a urp decal output nvm this is a custom solution?
(random image I stole from twitter)
Ah thank you! How do I reuse my sampler on the blackboard?
you can create one on the blackboard, or just on the graph (on the graphwill be easeier)
this way, you will not hit the 16 sampler limit.
Keep in mind though, that sampling 16 textures in your shader, is quite a hassle...are you doing a terrain shader by chance?
Yes, i am :P
welcome to the club ;] had the same issue
It's a shadergraph shader.
hmm
Ahh, well thank you for taking your time to help me out! :)
This might be a stupid question (newbie here) but how do i split the sampler output to multiple like you've done in your picture?
double click on a line that is allready there
nice, thank you!
try change the alpha threshold value to a more extreme value
and see if that changes the effect
if yes, than it seems it might ma mipmap alpha issue
This now works! You da man :P
also, change the import settings on your foilage texture, and see if this helps:
it looks like like a mipmapping issue, but might be wrong
That solves the distance problem indeed. Unfortunately it make the leaves more edgy, so maybe I can solve that with a camera distance node?
nah, mipmaps are your problem, and they are generated a bit out of the shadergraph box
Oh I see your second reply, sorry I'll check that
play alpha threshold value in combination with the texture import settings
there also other option there, like different filtering, and border MipMaps
You mean just one unchanged value for the threshold correct?
you should find a combination that works well enought
play with this, in combinathin with the alpha treshold on the shader
I'll check this out, thx
best: put the alpha threshold as a material paramtere
and then set it in the material in scene. You'll find a combination that works.
If you'll be interested on why this happens, there are some cool materials online 😉
✔️ Works in 2020.3 ➕ 2021.1
Mipmaps are scaled down versions of textures Unity generates and draws when a texture takes up a small area on the screen. This saves memory and looks better to boot! In this video, I go over Unity's mipmap generation settings and show how to create custom mipmaps. I also quickly demonstrate a cool trick Nintendo use...
Thank you!
Tried the example but didn't worked. I am also no expert in Shaders :/
No one...? q-q
If it's definitely the water shader causing this you should probably contact the asset owner about it and see if they know anything about the issue. Maybe it's something in the depth/fog related parts, not sure.
oof, it's not about no one. It's more about the problem definition.
You are new to unity, but are asking a pretty advanced question. And yes, sometimes you might get a hit, that someone has the exact same problem, but otherwise, more specific info is needed: what unity version, what pipeline, and as Cyan said: in cases of asset specific problems, their creators should be your first go to, as they know the shader. We don't 🙂
Yeah fair enough, I did try to contact the creator but they never responded to me. I guess I can just try using a different shader which is annoying but might be my only hope
Again I don't even know what to call this issue so idk how to even search for a solution
How do I declare a texture2d array in a hlsl file being used as a custom function node in shadergraph. I've tried using UNITY_DECLARETEX2DARRAY(baseTextures) as stated in the docs, but I just get an "unrecognized identifier"... Btw, I'm setting the texture array from script using Material.SetTexture
Probably depends a bit on the render pipeline. Is this for URP?
Yeah forgot to mention that, yes it's urp
Then the macro should be TEXTURE2D_ARRAY(name)
I see, thx a lot
this is probably not the right place for this but do you guys know how to make objects that cast shadows but are invisble to the camera?
You'd also likely need SAMPLER(name) btw
Or alternatively define the Texture2D Array in the graph blackboard. Can then use UnityTexture2DArray name as an input param (if in URP v10.3+). That should allow you to obtain the sampler via name.samplerstate too.
For sampling, can use SAMPLE_TEXTURE2D_ARRAY(name, sampler, uv, index)
There should be a "Cast Shadows" setting on the MeshRenderer that you can change to "Shadows Only" iirc. (At least there is in URP, not sure about other pipelines)
I'll try checking that out ty
Otherwise could probably use a shader that uses ColorMask 0 and ZWrite Off in it's main forward pass.
Wait how do I hide objects though? I literally started unity yesterday
I checked the docs so that Shadows Only setting should be available in all pipelines
yeah it worked ty
I have a bit of pink in my shader I am working on 
adding, subtracting, multiplying, negating all doesn't get rid of it
Is there an easy way to fix this?
trying to force those values to be something instead of nothing doesnt seem to be working
I know what the cause of the pink is, sorta, but the problem is that I need it to be the value that it is (which is causing the pink)
so I need it to be that value, without causing pink 🤔
I believe the pink (undefined value) is caused by the Dot Product producing values outside of a -1 to 1 range. Making sure both vectors are normalised before putting them into the dot product should fix that.
Or may be able to Clamp the Dot Product output.
👀 Ill try that now, I have been trying to plug in normalize and saturate at random places in hopes that it would fix itself but I didn't really have the understanding to know which place was right to do it
hmm, clamp completely changes how it looks
it does fix the pink, but it also completely destroys all the step before that
sphere radius is responsible for causing the pink to happen
but I need the look it has there, just without the pink
in the output you can see the pink gets interpreted as just black
all the relevent nodes
Hmmm what happens if you Normalise after the Subtract node
From the Screen Position node in unity's docs :
This mode divides Screen Position by the clip space position W component.
Could someone explain to me what this means?
In reference to default mode of the node
that also gets rid of the pink, though it does change how the effect looks a bit
though it still sorta looks like the effect just not to the degree it did before, maybe I can bring it back closer after the arcosine with mult/power/other maths?
Looks real interesting though 👀
ill try doing maths to it now after the arcosign step, this seems like the right direction
In order to calculate the screen position, Unity goes through numerous spaces. From Object space coordinates stored in the mesh, to World space, then View (relative to camera) and Clip space (using camera projection matrix). It then does a bit of remapping and a "perspective divide", which as the docs mention is dividing by the w component. clipPos / clipPos.w.
This results in (0,0) in the bottom left of the screen and (1,1) in the top right. I think Z is just cleared to 0 from what I've experienced with the Default mode. And W is then 1 - since anything divided by itself is 1.
In some cases, obtaining the W axis (and maybe Z) of the clip space before that divide can be useful, hence why the node has a "Raw" mode too. Specifically because of the way the projection matrix works, the W component is the View/Eye space depth to the current fragment. That's commonly used for "edge foam" on water shaders.
I've got more related info here : https://www.cyanilux.com/tutorials/depth/
I really like how that looks!
Yeah this looks pretty cool ✨
Thank you both, after messing with numbers its getting very close
https://cdn.discordapp.com/attachments/497874081329184799/1004483765189476482/unknown.png
the target look I am going for
now that I have the inside working, I will add the reflection/refaction cubemaps
@regal stag Thank you so much! I learned tons from your website in the past, again, thanks for making this knowledge accessible to newcomers
I downloaded Shader Graph and made a simple shader, but I get this error when trying to apply it. What's up with that?
Shader error in 'Shader Graphs/shad': Couldn't open include file 'Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/Shims.hlsl'. at line 559
Maybe try restarting Unity?
after adding reflection/refraction of cubemaps, it looks kinda goofy to me, especially on things other than the sphere
Ill leave it this for now and tweak the values more later
it might be because the cubemap is not the same as the scene background
Might be able to use unity_SpecCube0 to get the auto-generated cubemap for environmental reflections
I think it might by default - in this scene the object's smoothness is set to 1 - perfect reflections, and you can kinda see the cubemap bg on it
or do you mean something more than that?
Ah okay yeah, didn't realise you were using the Lit graph
Or does the Reflection Probe node just use the default? Idk I haven't used it much. Ah yeah it would.
https://cdn.discordapp.com/emojis/556735450622984202.webp?size=96&quality=lossless you definitely know more than I do
hmmm...I'm still having a hard time getting the depthnormal shader to fire up on my instanced geometry...some more insight coming:
This is the depthnormals shader doing it's job on a normaly drawn terrain:
Would anybody know how to handle semi transparency when using the HDRP lit layered on the additional layers? At the moment, even a pixel with 50% opacity is displayed with 100% opacity in the lit layered, is this normal? If nobody knows, is there more documentation on the lit layered somewhere ? The official doc doesn't seem to cover this point.
when instanced, there are no passes. It's just collapsed to this single entry
Properties{
_MainTex("", 2D) = "white" {}
_Cutoff("", Float) = 0.5
_Color("", Color) = (1,1,1,1)
}
SubShader{
Tags { "RenderType" = "Opaque" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float4 nz : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata_base v) {
v2f o;
/*ApplyMeshModification(v);*/
o.pos = UnityObjectToClipPos(v.vertex);
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
/*o.pos = v.vertex;*/
return o;
}
fixed4 frag(v2f i) : SV_Target {
return EncodeDepthNormal(i.nz.w, i.nz.xyz);
}
ENDCG
}
}```
this is the substitute shader that renders the depthnormals texture
{
class Pass : ScriptableRenderPass
{
//int GrassLayerIndex = 17;
//int TreeLayerIndex = 18;
//int OtherLayerIndex = 19;
//int BillboardLayer = 20;
//int VP_NoOutlines = 21;
int layerMask = ~((1 << 17) | (1 << 18) | (1 << 19) | (1 << 20) | (1 << 21));
private Material material;
private List<ShaderTagId> shaderTags;
private FilteringSettings filteringSettings;
private RenderTargetHandle destinationHandle;
public Pass(Material material)
{
this.material = material;
//This contains a list of shader tags, The rendere will only render objects
//with materials containing a shader with at leat one tag in this list
this.shaderTags = new List<ShaderTagId>()
{
//new ShaderTagId("MyShader"),
new ShaderTagId("DepthOnly"),
//new ShaderTagId("Opaque"),
//new ShaderTagId("SRPDefaultUnlit"),
//new ShaderTagId("UniversalForward"),
//new ShaderTagId("LightweightForward"),
};
this.filteringSettings = new FilteringSettings(RenderQueueRange.opaque, layerMask);
destinationHandle.Init("_DepthNormalsTexture");
}
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
cmd.GetTemporaryRT(destinationHandle.id, cameraTextureDescriptor, FilterMode.Point);
ConfigureTarget(destinationHandle.Identifier());
ConfigureClear(ClearFlag.All, Color.black);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
//Create the draw settings, which configures a new draw call to the GPU
var drawSettings = CreateDrawingSettings(shaderTags, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags);
//Overide material to render all objects with our material
drawSettings.overrideMaterial = material;
context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings);
}
public override void FrameCleanup(CommandBuffer cmd)
{
cmd.ReleaseTemporaryRT(destinationHandle.id);
}
}
private Pass pass;
public override void Create()
{
//Using inbuild renderers depth normals texture shader
Material material = CoreUtils.CreateEngineMaterial("Hidden/MyStupidShader");
this.pass = new Pass(material);
//Configures where the render pass should be injected
pass.renderPassEvent = RenderPassEvent.AfterRenderingPrePasses;
//pass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
renderer.EnqueuePass(pass);
}
}``` and here is the render feature that uses this shader
is it, that I'm using not the corrent drawSettings / filteringsettings? is the mesh simply invisible to the shader due to it beeing instanced? wrong renderpass event with combination with something else?
Hmm, shaderTags is only including the DepthOnly one. But your shader doesn't use that, it has no LightMode tag so would use SRPDefaultUnlit.
hmm...is that not indicating it actualy does?
enabling SPRDefoultUnlit -> no change
Enabling all the tags, same thing
Ah right, I guess the shaderTag is like a filter. But in this case you would likely want whatever the main pass in the Terrain is. "UniversalForward" perhaps?
When you don't use Instancing, does this pass work / appear in the Frame Debugger?
I'm guessing that using instancing is removing it from the DrawRenderers call then :\
I'll try to revert to the original internal shader
@open sable Hmm what about adding drawSettings.enableInstancing = true;
Oh, though the docs say it's enabled by default
Same, I saw it in the docs and thought that might be it
this is the original shader
(at least, I hope it is...im using 2021.2, but I thing the main body will be the same...)
might there be a problem with the instance ID setting up?
for example, if I could pass the instance ID, instead of settring it up?
UNITY_VERTEX_INPUT_INSTANCE_ID //Insert
Maybe comment out the drawSettings.overrideMaterial = material line for now. The important thing is if we can get the Draw Mesh (Instanced) Terrain to appear in the Frame Debugger for our pass
for example, the instancing code part has this at the head:
#ifdef UNITY_INSTANCING_ENABLED
sampler2D _TerrainHeightmapTexture;
sampler2D _TerrainNormalmapTexture;
float4 _TerrainHeightmapRecipSize; // float4(1.0f/width, 1.0f/height, 1.0f/(width-1), 1.0f/(height-1))
float4 _TerrainHeightmapScale; // float4(hmScale.x, hmScale.y / (float)(kMaxHeight), hmScale.z, 0.0f)
UNITY_INSTANCING_BUFFER_START(Terrain)
UNITY_DEFINE_INSTANCED_PROP(float4, _TerrainPatchInstanceData) // float4(xBase, yBase, skipScale, ~)
UNITY_INSTANCING_BUFFER_END(Terrain)
#endif
then in the function body it gets the instace data using this
float2 patchVertex = vertXYZW.xy;
float4 instanceData = UNITY_ACCESS_INSTANCED_PROP(Terrain, _TerrainPatchInstanceData);
hmm, but that data is not the most importang thing I see. just some scaling and hight information
This is quite interesting as the URP's DepthPrepass would use this : https://github.com/Unity-Technologies/Graphics/blob/2021.2.16f1.4502/com.unity.render-pipelines.universal/Runtime/Passes/DepthOnlyPass.cs
And that's just a context.DrawRenderers call still, so even with the terrain instanced it should work. The evidence is right in that screenshot of the Frame Debugger. I don't understand why it's not working when we try it though 😦
damn, got to go...to be continued. Thank you Cyan for the efforts, I'll give an update if I move forward with the puzzle 🙂
Hello I am making a shader based on this tutorial: https://danielilett.com/2021-03-19-tut5-15-wall-cutout/
I have it working but I want to make it toggle-able. I have tried putting the code part that actually culls the pixels in an if statement and that works for "toggling" it on, but I cant figure out how to reverse that.
Any help is appreciated!
Hi! Could anyone give me some clue about how I could convert this BRP surface shader into a URP fragment shader? I need to have lighting and all those things surface shaders just do.
How can I add lighting to my shader/model? I havent found any tutorial
do you use shadergraph?
nope
Start with a lit shader in SG. Try to duplicate the logic of the terrain bits, using "nodes".
That's what happens when you access a texture array by index, isn't it
in a surface shader
Why do you need it as a texture2d?
If it's a sampler2D, it's not a texture array
If you use Texture2DArray, you can sample it directly. You don't need to convert to Texture2D/sampler2D
ok
Some macros / example here for Built-in RP : https://docs.unity3d.com/Manual/class-Texture2DArray.html
I've been plugging away at this shader making it look real nice but ive come to realize something that's missing
The interior highlight bit is perfectly on the opposite face of the sphere as if it was perfectly hollow, but on a real gem it can look more/less 'deep' based on... something (the index of refraction maybe?) 🤔
Tryin to figure out what I would need to change to make the glow spot seem less 'deep' inside of it
I think it has something to do with the view vector angle?
from another tutorial this sorta does it I think? I will try to weld the way this one works onto my gem
I think I figured out the issue, there was a plane intersecting with the cube, so there were two objects with the shader at the same time which likely caused some issues. I can't really test it due to VRChat having a bunch of issues with the build and test function rn
Will update if I confirm that's the issue
I sorta got it working but it gets smaller the closer it is to the middle, but also that it gets bigger on the backside equally to how small its become 🤔
which is interesting but not what I am going for 
hm not getting any closer
for once I cant even describe in words what im trying to do
this is really neat, its kind of the exact opposite of what im trying to do but its neat 🤔
Maybe it is the opposite, I can try inverting that
Yeah im stuck, I tried all kinds of dumb things that don't do what I want
I dont have a clue how to obtain what I want, and blindly attaching everything to everything in random orders with random values isnt achieving it
a few interesting looks came of that but none of them were 'it' that im seeking
im 80% sure the thing that has to change is the view direction
or maybe the normal vector?
or just -something- in here
yeah I just don't get it
no matter what I plug in where, the result is the same, which is to say the result is not what I want every time
https://www.youtube.com/watch?v=Y5dylh2aOiw&t=117s
I think what im trying to simulate is something to do with this maybe? or the opposite??
index of refraction seems to be an important word
Still nobody here to let me know how to have the HDRP lit layered shader handle 50% opacity on the extra layers? At the moment, it displays all pixel with opacity > 0% as if it was 100% opacity. Is it a wrong set up on my side or can't the HDRP lit layered shader handle semi opacity on the additional textures?
ok
Hi, thanks for answering. I don't know if you've looked into the shader, but the reason I was asking how to convert it and didn't just use ShaderGraph straight away is that there are float and Color arrays I'm setting thru C#. And as far as I know ShaderGraph doesn't support these.
textures are float4 arrays, and SG does support them
But the arrays I'm passing are quite small and composing textures to encode the values, to then decode them again in the shader seems to be very ineffecient. Also , ShaderGraph doesn't support for loops, meaning I'd have to repeat a lot of nodes and end up with an unreadable graph. What I really want is to write a shader, I just don't know how to incorporate lighting - that was my question
u can use this template: https://gist.github.com/phi-lira/225cd7c5e8545be602dca4eb5ed111ba
with that, you can refract the view direction with the sphere normal and then calculate the point on the vortex that it hits, and what color that point should be
You can use arrays in ShaderGraph via a Custom Function node. (File mode, as you need to define the array outside the function scope)
https://docs.unity3d.com/Packages/com.unity.shadergraph@12.0/manual/Custom-Function-Node.html
e.g.
float _ExampleArray[10];
void ExampleFunction_float(out float Sum){
for (int i=0;i<10;i++){
Sum += _ExampleArray[i];
}
}
is there a way to abstract groups of nodes to repeat operations instead of copying and pasting in Shader Graph?
a bit like how the node groups would work in the Blender Shading Nodes
Select nodes -> right click -> Conver to -> SubGraph
hey Cyan ;] would you like to take part in the continuation of my struggles? ;p
cause, there have been some developments, but I'm missing the last piece of the puzzle.
The main point forward, was enabling instancing, not on the drawSettings, but on the material that does the override. So it was a good idea on your part 🙂
this.pass = new Pass(material);```
This made the terrain appear in the frame debugger, but still rendering null. I've added the instancing pragmas to the DepthNormalsTexture shader,
``` #pragma multi_compile_instancing
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap```
and the meshmodification function, that I use in the main shader.
And it gets the _TerrainHeightmapRecipSize and _TerrainHightmapScale correctly, but is does not get the _TerrainHightmapTexture.
the terrainhight map, is beeing correctly assigne in the main shader, on all the stages
I've tried, brute forcing it, and force feeding the shader the texture
Ahh it had to be enabled on the material! That's good to know
to see if anything happens
Texture2D hightTexture = LoadPNG("C:/vp4/VP/Assets/Heightmaps/Untitled-2.png");
//Debug.Log(hightTexture == null);
material.SetTexture("_Texture", hightTexture);
material.enableInstancing = true;
this.pass = new Pass(material);```
and in deed it does, but highttexture I exported from photoshop, is a bit different than the original (different encoding?)
and it does render something...just not accuratly
Wait this works? But it would be _TerrainHeightmapTexture not _Texture for the property name/reference. Or did you edit the shader too?
it was edited in the shader too
Properties{
_Texture("_Texture", 2D) = "white" {}
}```
Okay gotcha
I was sort of proding and checking, and mixing different definitions of the texture
atm ``` TEXTURE2D(_TerrainHeightmapTexture);
TEXTURE2D(_TerrainNormalmapTexture);
SAMPLER(sampler__TerrainNormalmapTexture);
SAMPLER(vertex_linear_clamp_sampler);
//sampler2D _TerrainHeightmapTexture;
//sampler2D _TerrainNormalmapTexture;```
this is how the texture is declared in the main shader
and both ways work (the commented out one, and the not commented out one)
samping as:
float hm = UnpackHeightmap(_TerrainHeightmapTexture.SampleLevel(vertex_linear_clamp_sampler, sampleCoords, 0));```
depeding on the definition
I'm doing the same thing in the depthnormals shader...but for the life of me, I cant get it, to 'aquire' the TerrainHeightmapTexture
it's always the defoult 16x16 gray box
Maybe you could use material.GetTexture("_TerrainHeightmapTexture") on the normal terrain material rather than a local copy?
Oh or, use terrain.terrainData.heightmapTexture
hm, but i have scenes with multiple terrains. multiple terrain textures
Ah yeah :\
It's annoying that it doesn't seem to be sent through correctly
I guess because it's set on the regular material and not the override
Maybe not ideal, but it would probably work if rather than using an overrideMaterial, you convert the ShaderGraph to shader code. Can then add a custom pass into it (e.g. with tag `"LightMode"="DepthNormals") and have only that pass in the "shaderTags" list in the renderer feature.
for exapple., this is the effect, if I "force feed' the texture
so...I'm close...
Doesn't force feeding the texture also only work with one terrain? Or does the heightmap cover all of them
jup, it dose. This scene has only one terrain (a debug scene)
but the scene this will be used in have 4 or sometimes 16 terrains
Then yeah, I think you'll need to convert the graph to code as I mentioned above
I don't know how else to copy the texture over when using overrideMaterial, as it replaces all property values
Unless the terrain system can work with material property blocks? (But then if it did use that, it should already work)
damn...the shadergraph shader is massive atm 😭 rewriting it for code would be heartbreaking (and yes...I know that should be the way to go...it's just, I wasn't and still am not profficient evnought with hlsl to do it reliably time wise)
You wouldn't necessarily need to rewrite it, you can generate code from the graph
It's a button in the inspector on the graph file
You can view the generated shader, and copy that into a .shader file
interesting. a bit of a hack, and changing anything in the graph, would mean a new generation and reimplementing the depthpass right?
Yeah
hmm, still don't get, why
float4 _TerrainHeightmapScale;
these values are imported correcly, but not the texture
the code is the same
i've tried adding #include "TerrainEngine.cginc" and "TerrainSplatmapCommon.cginc" and it took me nowhere
Oh wait, _TerrainHeightmapTexture should also be global!
When you defined it in the shader did you also put it in the Properties section, or just the hlsl?
now, it is defined only in the hlsl section. I think, i tried defning it in the properties yesterday, but maybe I messed it up somehow
as i understand it, it should not be defined there, right?
nope. I also wonder, it might have to do, something with the particular instace ID...
I think this is just a limitation of overrideMaterial then :\
No idea why some of the float4s still work. Maybe they are "left-overs" still stored in the global property references somewhere. (If there was actually multiple terrains with different sizes in the scene they might be the wrong values)
huh, damn...well, thank you for your time 🙂 I'll see where the code generation and pass implementation takes me :] Haven't done that before, but shoooould be easy enough 🙂
I think I found a bug in the shaderlab or something
I added a property in the properties section for ZTest:
[KeywordEnum(Less, LEqual, Equal, GEqual, Greater, NotEqual, Always)] _ZTest("ZTest", Int) = 1
and later in the shader I use it as:
ZTest [_ZTest]
it doesn't work for LEqual, GEqual - and I have no idea why
written from hand, like ZTest LEqual everything works as expected
This is in a context of writing custom Depth, so if anyone has some problems with using SV_Depth -- try specifying properties by hand, not from insepctor
Those aren't the correct ints/order for the corresponding enum values. They are listed here : https://docs.unity3d.com/ScriptReference/Rendering.CompareFunction.html
You can also just use [Enum(UnityEngine.Rendering.CompareFunction)] instead.
I'm having an issue where I can't use the shader graph in the standard render pipeline.
The shader graph want's me to assign a pipeline target here, but there is no "standard pipeline" asset
oh god, you are a godsent
I would have never guessed that
I've been taking values from https://docs.unity3d.com/Manual/SL-ZTest.html
I can't use URP or HDRP because my project is heavily dependent on the deferred lighting option (which is only available in SRP)
Oof yeah, would be great if that page used the correct order, and mentioned the CompareFunction enum attribute usage 😅
Dang. Unfortunately Unity 2021 and later has a weird bug that makes it unusable on my OS (Debian 11) and I don't think any of the latest versions have fixed it yet.
URP does also support a deferred path in 2021.2+ btw. Can't help with your OS problem though, may just need to provide bug reports and wait for a fix 😦
Okay, that sucks but thank you for your help
sorry to impose, but I had some mixed results (with docs being ambiguous etc) -- what is the relationship between ZTest and early Z prepass?
I have no clue how to even get started doing this, but I want to set up a custom shader graph for a UI Image Panel, and I'm pretty much stumped on how to actually do so.
I have a basic dialogue panel in this pic, where I've got a bright magenta color set up for the inside of the dialogue panel. What I want to do is add a shader to the panel which replaces the magenta with an image texture.
The issue is, no matter what I do, adding ANY material to the Material entry of the panel makes it no longer display, and Unity's shader graph doesn't let me input a Sprite Image as a texture input, only the entire spritemap itself.
Am I going about this in the wrong way?
I'm trying to emulate the effect in RPGs where the background of dialogue boxes has something like a gradient in the middle of it, or even a subtle image texture, with the border surrounding it being unaffected. I thought the way to do this would be to simply make the middle of the dialogue box a specific unused color, then use a shader to replace that color with a texture of my choosing.
ZTest is the same thing as Early-Z, kinda. It's a stage in the rendering that occurs after the vertex shader. The depth of the fragment (basically a pixel) is tested against the depth buffer, base on the ZTest compare function.
If it passes, the value would also be written to the depth buffer (assuming ZWrite On)
If it doesn't pass, that fragment/pixel isn't drawn.
Except, if you use clip(), discard; or alter SV_Depth in the fragment shader, that early-Z can't occur as the depth of the fragment isn't really known. So the depth test then occurs after the fragment stage instead.
"Depth or Z Prepass" is also something different, where you render opaque geometry first to the depth buffer only. Then render again normally. I'm not too familiar with it. I guess it saves time rendering pixels from overlapping objects. In URP there's a "Depth Priming" mode on the Universal Renderer asset which does this.
If the magenta color is intentional, you should change it to a different colour as magenta typically means the shader has an error (or is for a different render pipeline), so it's hard to tell if that's what is happening here.
The other problem is that ShaderGraph doesn't really have proper UI support. In URP, I think the Sprite Unlit graph has worked in the past, but that may have changed. You'd also set up a Texture2D property with the reference changed to "_MainTex" to obtain the sprite image from the Image component, rather than using an exposed texture.
The Magenta Color is intentional, yeah. When I plug any shader into it, though, it goes invisible.
Likewise, it won't let me use a sprite as a texture.
So there isn't really a way to have a dialogue panel with an altered background in HDRP, like in FF7, or PM:TTYD?
If it goes invisible, it's probably just because shader graph doesn't support UI shaders yet. Switching the Canvas type from Overlay to Camera space (and applying camera in field that appears) might help? 🤷
Otherwise you may need to consider using shader code instead. Can use this as a template : https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/UI/UI-Default.shader
Damn. Guess I'll try to figure out shader code, then.
Yeah, I'm not going to be able to do that. Just looking at it, I can tell I'm not cut out to actually code a shader in script.
Why is the stocking not showing in the game view? Here is the scene view, the stockings show
And here is the game view, they become invisible???
Using HDRP lit
If I zoom reaaaally close, it starts to show but only some parts? I don't get it
ohhh, thank you, that clarifies a lot!
I'm trying to understand vertex color node in shadergraph.
To control vertex position on some parts of my mesh I painted that part with green vertex color.
The rest is white, or no vertex color. When I put in a vertex node and want to split this, my first thought
was to use the green channel but that doesn't show any vertex color, only the red and blue channel do. (grey/black)
Is there something I need to understand here? The manual seems very short on this topic.
You'd need to paint the rest of the model black. Both white (1,1,1) and green (0,1,0) when split will give an output of 1 in the G channel.
Ok thank you. I can work with that.
To continue on this question. I have some blue and green and red parts on my mesh. Only green and blue I need to change vertex position.
Without the combine node, the green channel and blue channel works great, but with the combine node, it stops working.
Maybe I don't need the combine, but another node that add those channels up?
The combine would leave the R component of the resulting Vector3 at 0, so the Lerp would then only apply the G/Y and B/Z parts of the displacement.
Instead you could use a Maximum node with the G and B channels.
Or Add together then Saturate.
Or use Red output and One Minus.
Or, instead of painting blue/green you could paint cyan (0,1,1) and green (0,1,0). Both of those would have 1 in the G output so you'd then only need to connect that to the Lerp.
Ok, I need to think this through, thank you
Is there a way to make normal from height less pixelated when using noise-generated non-textures?
googling it there doesnt seem to be much answers, there was one but it only worked with a very specific geometric shape
You dont need a shader for this. Make the image in photoshop or even paint.net and put it as background on the ui panel
the UI Panel has no entry for background, only one for Source Image
Am I just missing something?
Yeah that would be the background
You then add more ui elements as children to that panel
They will render on top
But why it has a canvas component idk
Anyways check out a ui tutorial
this graph from the net does it after all (once I looked at it closer) but there is a problem, the shape it creates is hardcoded into the graph, I can't figure out a way to have you pass in the noise to use in those four places 🤔
if you pass in the noise as a vector 3, how would I connect a UV input to a vector3?
maybe a custom node that takes in a UV and a vec3? But I am not certain how the math works
Yes, but if I render a rounded border over the top of the background panel, it will have corners poking out, won't it? Do children of a background panel clip out the edges of their parent object when using nineslice sprites?
https://docs.unity3d.com/Packages/com.unity.shadergraph@7.1/manual/Simple-Noise-Node.html
looks nontrivial, I am not sure which parts pretain to the use of the UV
There is a mask component for that kind of thing
Wdym connect a UV input into a vector3 ?
I need to pass a noise texture generated procedurally (not actually a texture) into a sub graph, and edit its UV within the sub graph
this noise has to be a vec 3, not a noise node
but vec3s dont have a UV input, so I need to somehow make a way to do whatever/however the sampler works to make it do this
maybe X/Y problem - I need to pass in an arbitrary code-generated texture and then edit its uv's somehow
an input here that replaces these four
So how are you generating the texture ?
noise, any old combination of noises
I am not generating it in any one single fixed way
maybe its not possible? 🤔
Im still confused
Why cant you plug in your desired uv in the simple and gradient noise that generates your final noise
okay, root question:
How do I make Normal From Height not pixelated low res
problem with this: you cant pass in the center bits
so problem is now: how do I pass in the center bits if I cant?
because I have to do a bunch if steps before and after, and the entire UV effect has to be repeated four times
and remaking the same thing four times is a terribly inefficient thing to do
Well yes this is essentially supersampling
So the answer is... you can't make normal from height not be a low res pixelated mess? 🤔
This is where you'd likely start passing in a pre-defined noise normal map rather than generating one
I can just make a texture I guess but its easier to edit the look on the fly fast from within unity itself than doing it in photoshop
Not without paying the extra cost. Your problem is that the noise is low res
Have a high res normal map and add micro details procedurally with some noise
okay I guess Ill have to do it in photoshop 😿 was hoping there was a way around this
Ive recently been playing around with this package https://docs.unity3d.com/Packages/com.unity.surface-gradient-bump-mapping@0.1/manual/index.html and made some pretty cool normal compositing things
When working with individual channels from textures or vectors, is split -> combine/ vector# the method I should be using or is there a more efficient way?
There is a Swizzle node. Using "rg" (or "xy") with it's field would be shorthand for what you are doing here. (For the left side at least. The right part might still need a Split/Combine)
I did see something like that in tutorials but mine doesn't seem to have it - I am only in unity 2020.3 so maybe its a later thing?
Ah yeah, the old version isn't as good :
I'd keep using Split & Vector2 then.
Could make a SubGraph to be a bit cleaner
I was thinking the same thing 🤔 my own swizzle that does it
A question regarding the remap node. This screenshot is taken from a tutorial which
I'm trying to understand the remap node, and what does exactly in this case? Is it limiting the gradient reach perhaps?
The manual saids: "Returns a value between the x and y".
Without it it works great with randomizing the colors on the object.
Remap is taking your input values between 1 and 6 and making them into values between 0 and 1
so anything that was a 6 before is now a 1, and anything that was a 1 before is now a 0
with a linear lerp between for all values between
so for example passing in floats between 0 and 10 and remapping them to be between 0 and 1, values that were a 5 before are now 0.5
I am getting a weirdness I don't fully understand - using parallax node, the paralaxx gets more pronounced the further you zoom away from the object
is it supposed to do that or am I using it wrong? and is there some way I can counter-act that?
Thanks for making it more clear!
oh interesting, it doesnt happen with parallax mapping, only with parallax occlusion mapping 🤔
hm but the non-occlusion versions results are way worse
huh in scene it looks WAY different 🤔
it doesnt get deeper the way it does in preview
but it 'tears' the texture the same way it does with parrallax mapping (non occluded)
I dont want to make 'spikes' in the mesh, I want individual dots at different 'depths'
Is there some way to make it look like it does in the preview?
hhrm this is kind of frustrating, I want it to look like how it looks in the main preview, not how it does in scene, but I am not sure how they differ to correct it
hm, adding more steps stretches it into spears, adding more amplitude tears the texture apart
how do I make it have depth without tearing the texture apart? without making the dots into spears?
question is there a way to return a uint from a custom function node in shader graph? or sample a uint texture?
algebra question - if I want to make the multiplication go equally on both sides instead of just one side eating the other, I have to also subtract by a certain value relative to the multiply value
how do I determine that value with math instead of just manually adjusting it afterwards?
I assume I can derive the value from the multiply value in some way
Not sure what you mean by this - multiplication is commutative.
sample the texture as float and then convert to uint in whatever way you wanted to map it?
as the multiplication value changes, one side eats the other, no matter what value the multi is, the black side will never have white in it
I want to move the mid point so the value change is always at the 50% of the two sides
I do that by subtracting right now, but I need to make subtract automagic from the mult value
ah yeah because 0 * anything is 0. Multiplication is effectively a "darkening" effect, it cannot lighten anything
Yes I know, my question is what is the formula to also subtract so that the mid point range remains 50/50 between the two?
Maybe look into the Blend node?
https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Blend-Node.html
there is nothing to blend, its a single vector, I dont have two inputs
Wait so sorry you want to make sure what part is 50% of the way?
Maybe I am not explaining clearly, let me try again
when multiplied by absurdly high value, its 50/50 white black
when multiplied by a very small number, white side becomes gradually more black
when multiplying by a number AND subtracting by a number relative to the multiplication number, the difference band between white and black can be kept centered between the two sides
how do I determine the subtraction value from the multiplication value to keep the band gradient centered?
without just manually adjusting it till it looks right
for example - if multiplying by 5, then subtracting by 0.3 seems to roughly keep the band centered
if multiplying by 2, then subtracting by about 0.4 seems to keep it centered
how do I find the subtraction value from the multiplication value to keep the band centered?
Does this make sense?
I dont know how to explain it to be any more clear
subtraction = multiplication (???), solve for ??? where ??? is always 50% of the way between the two sides
the answer is going to be an extremely simple math formula
I just don't know how to find it
ill DRAW what I mean since words arent working
If I'm understanding correctly, I think you want (x - 0.5) * someValue + 0.5
Ill try that, here is my drawing I didnt get to finish
sorry I -- just didn't get a chance to read that
All good, trying Cyan's formula now
Hmm it kinda worked but it seems to be happening at the wrong place
if I adjust the initial subtract value it seems to get more centered, but then I don't know if thats throwing off the later math
Could the answer be something else or did I do your formula wrong?
Are you sure I should be using 0.5? its not centered at the right spot
it kinda looks like its centered without the intial subtraction, is the problem maybe my input value?
I don't want 'kinda sorta' though, I want to be mathematically sure its at exactly 50%
hm maybe the problem is because the black values might actually be going "darker" but aren't because it cant display values darker than 0?
yeah that is kinda the problem, it IS going in both directions equally, but i cant use that as a mask
Ah okay, guess you don't need that intial offset. Adding 0.5 should mean it's now centered between the black/white though.
Hmm yeah trying just the add 0.5 it does seem to be centered now
I don't really understand the underlying math why that is the case 🤔
Also yes, values here aren't clamped between 0 and 1, so there are values beyond that - the preview just can't show them.
Since multiplying anything by 0 is 0, you can consider it to already be centred around 0 (where it starts to be black). Adding 0.5 just shifts/offsets that. And since 0.5 is halfway between 0 and 1, it's now centred there.
That makes sense
I'm trying to tweak a shader that draws a ui image with rounded corners and a border
so I can use it as a selection outline on worldspace images.
The camera is orthographic so the image will always be viewed front-on
I've got it working I think, but is there a better way to scale the line width to a constant screenspace size than using the derivative of the world position?
half widthScale = ddx(IN.worldPosition) / 2; // 👈 this is my very good code 😅
float l = (IN.lineWeight * widthScale + 1/IN.pixelWorldScale)/2;
Hey Guys. The Shadergraph i did is telling me "Material doesn't have meta pass" when baking the light.
Didnt find anything how to deal with this. Does someone have an idea?
Hya, anyone has experience using shaders with a tilemap? I'm getting some weird results
Anyone knows why this is happening and how to fix it?
Any idea why this shader is not working properly in WebGL? I swear it's as simple as it could possibly be, just outputting a hardcoded yellow. There's no errors on building. I'm pretty sure the warnings on the web browser are irrelevant.
Shader "Test WebGL"
{
Properties
{
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Cull Back
Pass
{
CGPROGRAM
#include "UnityCG.cginc"
#pragma target 4.5
#pragma vertex vert
#pragma fragment frag
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 position : SV_POSITION;
float4 worldPos : TEXCOORD0;
};
v2f vert(const appdata v)
{
v2f o;
// calculate the position in clip space to render the object
o.position = UnityObjectToClipPos(v.vertex);
// calculate world position of vertex
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_TARGET
{
fixed4 col = fixed4(1, 1, 0, 1);
return col;
}
ENDCG
}
}
}
what shader do i use to make a texture transparent but not the object? I used the Standard shader's Fade and Transparent, but I could see through the object that didn't have transparent Alpha channels
how do I change/edit the shader becuase it is grayed out for me
damn
I feel like coding in c++ from scratch is easier than writing using unity shaders.
anyways; is there anyone who could very simply explain to my 3 braincells how to set a specific pixel on a texture to a certain colour?
and also how to read a specific pixel on a texture.
notes: the shader is an image effect and i'm using it as a "post processing" effect by bliping it.
more context: I want to make a canny edge detection shader that would look through the camera and compare the depth and normals.
I'm first trying to make a guassian blur becuase it feels alot easier than the canny edge detection algorithm.
I have the depth and normals set up, but I have no idea how to loop through every pixel to compare the neighbours and then smooth out the center pixel depending on the neighbour weights.
to put it simply:
is there something that allows me to get the pixel at the position (0,0) (0,1) (0,2) ... (1920, 1080) and then read/write to it?
Pretty cool effect
Create a new material and assign it to the renderer instead.
In pixel shaders you would sample the texture to get it's pixel at specific point. The uvs that you input into the sample function are what determine the position to sample. They range from 0 to 1 on x and y axis. If you know the resolution of the texture, you can get a pixel at specific point with uv = actualPixelPosition / textureResolution.
You can't write to any arbitrary pixel though. Only to the one that the pixel shader is running for.
i gave up cuz i don't have the timeframe to implement it
i did figure that out, but the next problem was scanning the neighbours
You'd just add an offset to the pixel position.🤷♂️
but what about the borders
You check if it's outside of borders if that's important🤷♂️
that sounds like unnecessary performance down the drain tho
it is 🙂
maybe sample an extra texture that looks like a baked border and use it as a mask? 🧐
or use a 2d square signed distance field? but that still requires using min and max functions
try if it's noticably slower when u decide to continue
That's really not that huge of an impact. You just compare a few floats/ints.
When Graphics.Blit is called, will the fragment pass of the used material only evaluate for existing pixels in the destination texture, or are there any implications based on the size of the input texture too? Couldn't really find anything in the docs
or will each pixel of the source texture be evaluated and then interpolated for the output if the resolutions don't match?
the first assumption would make sense to me, to only run for target texture pixels, but I'm just not sure
Graphics.Blit draws a "full-screen" quad. It'll always cover the entirety of the destination texture. The quad is set up with UVs, (0,0) in bottom left and (1,1) in top right (well, the Y might be reversed depending on platform I think). Those UVs are used to sample the source texture, so regardless of it's resolution that also matches the size of the quad/destination.
It would be interpolated/filtered depending on the source texture's filter mode (Point - no interpolation, Linear/Bilinear, Trilinear - also blends between mipmaps, that one probably wont be used in a screenspace effect like this)
Thanks, that helps! I have noticed that on my pc i have to invert y in some cases.
so to clarify, do you mean the target texture is used as this full screen here and the frag pass will only run for all pixels in the target texture?
Yes
thanks!
Materials imported directly from a model can't be edited. You could create a new Material in the Project window somewhere under your Assets. Then assign that under the Materials tab on the model to remap the materials, or manually drag the material onto the model.
This is a limitation of how transparency works. You can fix it somewhat by using a pass prior to the main one which renders the model to the depth buffer only. (ZWrite On, ColorMask 0).
There's a full example here (assuming Built-in render pipeline, since you mentioned Standard shader) : https://forum.unity.com/threads/transparent-depth-shader-good-for-ghosts.149511/
WebGL probably doesn't support #pragma target 4.5. If you don't need any fancy shader features you could just leave that line out, or use 2.5 instead which is the default. See docs for more info : https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html
You may also be able to switch between OpenGL 2.0 and 3.0 in the build settings which could support a higher target. (But I still doubt as high as 4.5)
Each tile in the tilemap has different UV values which allows it to select the correct tile from the texture. Using those same UVs for sampling other textures (or generating noise) will lead to strange results like this.
Instead of relying on UVs, you could use the fragment position. (aka Position node, put into the UV port on the Gradient Noise / Sample Texture 2D / etc)
I thought all graphs generated a Meta pass (but maybe the Sprite ones don't? Assuming URP). Could check the generated shader code (there's a button in the inspector to view it, when the shadergraph asset is selected). But there's not really a way to fix this if it's not there, without manually writing one.
If you are using a sprite graph, maybe you can switch to Lit/Unlit and copy the Meta pass from there? 🤷
Turns out I could use two different materials instead of 1 in Unity since normally I needed to use 1. Made the body opaque and the extremities transparent. Thanks though
That also works, wasn't sure which parts you needed to be transparent
formula adjustment question 🤔
This is the graph to make object space interior cubemapping work, but I have an adjustment I'd like to make that im not sure at which step how to achieve.
You can see in the preview that each cell has is a small snippet of the cubic UVs tiling in every cell, I want to adjust it so that each plane has the full texture stretched over the entire thing 🤔
im pretty sure all I have to do is plug in the object space positon node instead of whichever part of this graph is the part that makes the texture tile in the cube
like this but still with those extra bits 🤔
Hmm, is that maybe what the result of the Multiply at the end is (before the Add)?
Or maybe the add part is needed but the Fraction node would need to be removed (as that's what makes it repeat)
Hmm removing fraction removes the cell-like appearance, so I think the fraction is neccessary
Ill see about trying to plug in my object space to the upper part before the mult
Im pretty sure some length of this's primary job is tiling the texture in each cell, if I could isolate which part I could chop out the whole thing
removing nodes one at a time just turns it into a broken mess so I won't be able to brute force it
Oh right, the fraction node would still used in the calculations at the top. But maybe not the bottom part (like in that final Add node)
Ooh you're suggesting splitting it at the fraction part, top still gets it bottom doesnt? Ill try that
This is really close to working 👀
if you look at it dead-on a single side, it works, but at any angle, each cell is getting filled with pink
I'm thinking it must have something to do with these
something in there is still trying to repeat the texture over the cell
hmm maybe it IS working and im just misreading what im seeing?
whoops discord didnt like that
okay its not working correctly
if I replace it with a texture instead of the colors its def not working
more clear version of whats happening
looks wild though
so its something to do with the viewing angle I think 🤔
this is totally an x/y problem as well
what im actually trying to do is fake raymarching in shadergraph
and I think that this will be able to do it
if I can just map each plane to object position space instead of whatever its doing, and then plug in 3d noise
This is for the sparkles right? You had problems with parallax mapping because it stretches them out iirc
Yeah
I reached out to a guy on twitter who did them really well but he said he did it with raymarching, which I know is both not easy and not supported by shadergraph
this is the next best thing I can think of 🤔
I mean, you can do it in a custom function node
That would require an enormous amount of skill and knowledge of HLSL code which I have neither 😿
ive tried googling other people's pre-made raymarch node but no such thing exists
its almost kinda working, im positive this will be close enough if I can just figure out how to correct the distortion its doing there 🤔
its interesting what removing random parts of the graph does to it, not what I am trying to achieve but interseting to look at
HMM If I multiply the object space position, it does this
does that help deduce why it looks the way it does look wrong?
it feels like its closer at least, its not distorting now
ill try arbitrarily multiplying after each step to see what it does to it
kinda better but still way wrong
maybe i shouldnt be adding at the end, maybe multiply there? nope definitely not
Oh I think I've got it, adding the Position without the Fraction does work, but you still need the Position * CubeScale → * 0.999 → + 0.5 → *2 → -1 part
(same thing just without the fraction node)
my technique of 'try things on things until it just works all on its own' would have never figured that out, setting it up now to test
Think we can then divide by the CubeScale after adding to scale it back down
Eh no, sorry maybe I didn't explain it that well.
I'm referring to duplicating this part again, but without the Fraction node
I must be plugging this in the wrong place
its doing some wild stuff
I don't know where im to use this new segment
replacing the added position with it wasnt the correct answer
oh wait 👀
I think we're in business
that looks like what I was expected
Ah yeah that's right, the divide should be after the add, if you need to adjust the scaling back to more of a 0-1 range
But not too important. Can also just adjust the scaling on the noise node
when you say after the add
you dont mean this add but the add when I combine the two lines of graph?
Yeah I mean the final add when they combine, sorry
Quite like how this looks. It almost looks like it has some ambient occlusion applied.
Yeah that's exactly what I was expecting!
same result when I remove my noise texture
now to see if I can even make them not opaque 👀 the y has been solved but does it solve the x.
Ill post results / when I get stuck
Good luck! 🙏
If that doesn't work out, maybe the next thing to look into for getting sparkles at different depths, would be to sample the texture* multiple times with different amounts of parallax. Not using the parallax mapping node, but offsetting with the View Direction in tangent space. It's the same idea used here for cracked ice : https://www.youtube.com/watch?v=rlGNbq5p5CQ (but you wouldn't need that many layers so close together)
*But this assumes you have a texture to sample to produce the sparkles. Since duplicating generated noise/voronoi/etc would likely be quite expensive - but could still work for testing.
If you can't make a texture manually you could use a shader outputting the noise/voronoi and use that to bake a texture (e.g. using Graphics.Blit). This might help with that : https://www.ronja-tutorials.com/post/030-baking-shaders/
(I guess that texture would probably need to store the sparkle vectors in rgb & maybe noise in the alpha channel for masking)
Yeah its looking like the result we got is not going to be able to do it 🤔 looks cool though
I am sure there is some use for object space compartments like that for something, just maybe not to fake raymarching
*But this assumes you have a texture to sample to produce the sparkles. Since duplicating generated noise/voronoi/etc would likely be quite expensive -
I replaced my 2d voronoi with a 3d voronoi, is that less expensive than multiple 2d voronois?
scaling the mesh to illustrate the 3d object space voronoise
Hi, I'm trying to use the HDRP hair shader but I've got this bug when moving the camera around, it seems like random parts of the hair become see-through or are distorted. I can't figure out the problem. Any help welcomed 😢
3D voronoi would likely be less expensive than a triplanar 2D voronoi yeah
just want to say I've been following your shader adventures the last few days and really like some of the effects you've achieved.
OK nevermind my problem, it was due to the skin shader behind which had a problem compiling, causing both my problems. Changing to another shader on the skin fixed the hair issue
Why did my water turn into this?
It was an asset i got from asset store
Worked fine
Thank you!
My end goal is to learn how to be better at shaders, and to make a fancy dice shader, which is why I'm mostly focusing on cubes
I was going to say haha I have a dice project I've been working on on and off for a few years and I wanted to eventually make collecting really cool dice part of the game. Was going to explore cool dice shaders like you're making myself at some point
so it piqued my interest
👍 to that. I've only been posting the stuff I need help fixing (since this is not the WIP channel), not the stuff I got working all on my own so you haven't seen stuff like this yet:
https://gfycat.com/heavenlyfrailindianpalmsquirrel
nice
When I finally start to roll all these different shaders into a single entity I can share the graph for study, but I imagine thatll be a while yet
Hey, how can I update a mesh collider when Im modifying the vertices in shader?
you cant, vertex shader only affects the visual look/rendering
ok thanks
you would be better to deform the mesh using c# script instead
How can I output a value from shader?
that's the wrong approach
do like AlksiH said
No thats something different
https://gfycat.com/esteemedverifiablecrocodile
I made this as a test before I go fully into raymarched steps from the cracked ice tutorial, its using multiple parallax mapping nodes, and in doing this ive identified a bunch of performance issues I'd like to rectify by moving to the custom node version 🤔
to do the above I had to use three separate parallax nodes, into four separate texture samplers (of the exact same texture) which I then split up by channel and then blended all together
oh and each depth set is just pushed equally further in, the layers are spaced linearly
its kinda warbly looking which the parallax node does the deeper you set the amplitude, and I don't like having to have three separate textures and samplers like this
it proves it works, but is there ways to optimize this? As it stands I don't have much control over how the insides looks programatically, I have to rely on the texture being good 🤔
Im stopping work on it here though today because its the weekend, ill be back on the ball tomorrow or monday to do the cracked ice tutorials in hopes they have the key to making the above less jank
major-ish flaws, the interior is not consistent across each face (not actually volumetric) but I can live with that since getting that would be really hard without real raytracing?
It turned into a cellphone photo ;p btw. doing a photo of your screen, instead of a screenshot, and sharing on a technical discussion, should be somehow punished ;p how does that work...how can you come to a conclusion, that makeing a photo of your screen, and uploading it from your phone, is the right way to do it? It's...mesmerizing
What
I literally asked what the shader turned in
it was a joke. we have no information, on what did the shader did wrong. or any information, that might anwser your original question
Man can you just say what happened wrong
- Nukeythewise posted a cellphone picture of his screen, with the msg: "Why did my water turn into this?"
- You asked, "Turned into what?". A valid question.
- I wanted to be a smartass, as taking picture of your monitor with a cellphone and posting it on discrod, asking for technical help...is sort of offensive
- You misunderstood my msg.
- We don;t know what happend to the shader
By using 3 parallax mapping nodes it's sampling the heightmap 3 times using the same uvs. It's very possible that the compiler would optimise this, but personally I'd still prefer handling it using a Sample Texture 2D node, then input G channel into 3 x Custom Function nodes using (or SubGraphs replicating) the ParallaxOffset1Step function. It's the same thing that the Parallax Mapping node uses but doing it this way, we know it'll sample the heightmap only once.
The other separate texture samples is unavoidable though. But it should be okay. In proper volumetric raymarching, you'd typically be sampling a 3D texture even more times along the view ray - so this should still be an improvement over that (in terms of performance, not quality of course)
e.g.
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ParallaxMapping.hlsl"
// (G channel of Heightmap goes into Height input)
void ParallaxUV_float(float2 UV, float Height, float Scale, float3 TangentSpaceViewDirection, out float2 Out){
Out = UV + ParallaxOffset1Step(Height, Scale, TangentSpaceViewDirection);
}
Or could recreate these in nodes & use subgraph instead. (using ParallaxOffset1Step function here as reference : https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.core/ShaderLibrary/ParallaxMapping.hlsl)
Can also be less warbly looking if you want, should just need to use a constant Height value (maybe 1?). But it looks quite good with the noise texture imo.
Those sound like perfect optimizations
You just made me realize that I might have put a height map image into those paralax nodes causing the warble
Yeah, the heightmap would be responsible for that
I was about to be like "I set the height to a single value" but I set the AMPLITUDE to a single value, and almost definitely forgot a height texture in there
🤦♂️
On the upside I won't need the parallax nodes after I switch over to a custom node feat. this
Also personal preference, but this may look better without the layer of noise that has no parallax. (or maybe with a slight bit). Just looks a little strange with that layer not moving at all.
Ooh yeah the outermost layer? Yeah I was not feeling it there either. I was trying to replicate this kind of appearance that some dice have, having bits translucent and bits opaque at the surface
But using a cloudy noise texture for it instead of something more deliberate didnt work great in the above
Idk, I think the cloudy texture does work still (I like it a lot!)
Just without that outer layer and maybe some colour tweaks.
Oh yeah sorry I meant the same thing - that the outer layer didnt work, the rest worked
the clouds worked on the insides, just not on that outer surface flat part
I closed out of unity for today since its the weekend but looking at my own screenshot I totally put a height map texture in there, rip
this looks very cool
thank you thank you, its definitely progress
Hey there!
I'm feeling kinda stupid right now, but I can't figure out how to transform a world space position to screen space position. I transform WS to clip space, then run ComputeScreenPos, but it outputs wrong result for some reason.
Typically you'd do that transformation (WS -> Clip then ComputeScreenPos) in the vertex shader. You'd then do screenPos.xy / screenPos.w in the fragment to obtain the final screen space position.
Hey, after moving a car from core project to HDRP project my car is all pink and I see something is wrong with shaders on materials (I'm a total newbie). Someone might know how to fix that? 
That's what I'm doing, and it doesn't seem to work.
The shader should practically nothing: extract positionWS from screen position, then transform it back, instead, I get... this.
half4 frag (Varyings input) : SV_Target {
half3 positionWS = (float3)ComputeWorldSpacePosition((float2)input.uv, GetDepth(input.uv), UNITY_MATRIX_I_VP);
float4 positionHCS = TransformWorldToHClip(positionWS);
float4 positionSS = ComputeScreenPos(positionHCS);
return float4(positionSS.xy / positionSS.w, 0, 0);
}
It's a fullscreen blit, though, but I don't think it should have any impact.
You need to convert built-in materials to HDRP ones. See "Upgrading Materials" here : https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@12.1/manual/Upgrading-To-HDRP.html
What is the purpose of reconstructing the world position just to convert back to screen?
It's possible the result is incorrect because the positionWS isn't what you expect
Great thanks! That worked, thank you so much! 
What I'm actually doing is, khm, compressing world space position into irregular pieces using voronoi, so multiple points in the world correspond to the same coordinates on the camera color map.
I see
hm, you're right, there's something funky with positionWS, it doesn't seem to be right
I believe UNITY_MATRIX_I_VP doesn't work in blits, as I've had troubles with using that matrix in the past.
Instead, I use unity_CameraInvProjection and an _InverseView matrix - sent into the shader via Shader.SetGlobalMatrix("_InverseView", cam.cameraToWorldMatrix);.
(Specifically using this, though it's shader graph : https://www.cyanilux.com/tutorials/depth/#blit-perspective)
Since you're already using the ComputeWorldSpacePosition function it might be okay to multiply those matrices together and use that in place of UNITY_MATRIX_I_VP
(Heading off, so hope that helps!)
Thanks, checking it out now
nevermind it got fixed, said URP was not updated
the water shader become weird and adjusting the material made it even more weird
it didnt look like water but a sort of 2d drawing with caustics on the surface and the animation wasnt working
I thought you’re the guy asking lmfao
That was awkward
What is going on here? The shader offsets the vertices in y direction, and as the translation is applied in object space, it should offset the vertices in the direction of the arrow. However, as soon as there are two or more copies of the object, the vertices are being offset upwards, regardless of rotation. Enabling GPU instancing on the material solves this problem, although I don't understand why.
This is the shadergraph
Looks like theyre getting batched together?
There is some automatic batching when dealing with sprites, combining the meshes. Object space isn't really a thing then.
And with gpu instancing enabled, this doesn't happen?
So... Shader Graph doesn't fully support GPU Instancing automatically. Because you have exposed properties, what I think is happening here is that it is just breaking the regular batching that sprites do and rendering them separately. (The Frame Debugger window can probably confirm this)
It's not ideal, as you're dealing with separate draw calls which will be more expensive to render, but you do retain the object space.
One way that could fix this without the GPU Instancing ticked, might be to offset along the Tangent Vector stored in the mesh 🤔 (assuming sprites generate those)
could be dynamic batching
How would I make a texture position itself relative to where the mesh is located in the world?
so that if I were to move the mesh, the texture wouldn't move along with it
Can sample the texture using worldspace position rather than the model UVs.
(Might be able to provide more info if needed, but would need to know which pipeline this is for and whether it's shader code (vert/frag or surf) or for shader graph / other node editor)
Did I make a pedmas mistake in re-creating this implimentation? 🤔
Or maybe I am misunderstanding how to use the output? Changing either Height and Amplitude seems to just tile the texture, neither adds/removes depth
I am assuming viewDirTS is view direction in tangent space, I don't think that part is wrong
The "Amplitude / 2" part should be in the B port on the Subtract, and just Amplitude property on B port of Multiply.
To use the output, should Add it to the UV node before putting into the UV port on Sample Texture 2D.
(Or can put it into Offset of Tiling And Offset node, since that is equivalent to Add)
oh yeah you are right, I looked at this like 10 times and my brain said every time "yep you got the order right"
That fixed it 👍 I must be getting better, I knew it was a pedmas problem at least even if I couldnt find it
got that to work but realized a texture won't suffice for what I want to accomplish
I use noise to generate biomes, so I need my shader to know what the noise value is at a certain location
(although how I generate the biomes has no relevance here, I just simply need to tell my shader what the generated values are somehow)
a texture won't do it since the world is virtually infinite
I got the world pos stuff covered but I have no idea how I can tell my shader what the value is
I guess a solution could be generating the biomes from scratch inside the shader, but I'd prefer to get the values from outside of the shader if possible
hmm I think I'm going to handle my generation like before, turn the values into a texture, and handle that much like a noise map for the shader
HI! It seems I'm lacking some basics. In a shader graph, when inputting a vector (1.0,0,0) to the base color, the displayed color is pure red. However, when using a vector (0.5, 0, 0) and afterwards multiplying it by 2, it is not pure red. I would expect the multiplied vector to be also (1.0, 0, 0) but guess I'm wrong. Could someone explain me what is going on or give me some source to read about it? 🙂
That's very odd. It should definitely produce (1, 0, 0) - and it does on my end (using URP, Unity 2021.3.7f1). Might be a bug with the Combine node? Could try Vector3 instead.
i restarted unity and now it works. oddly, the multiply node now shows pure red and not black as before. guess it was a bug or so 😄 thanks!
Optimized shader and its two sub-nodes. Do you see any inefficiencies I could eliminate?
I noticed the view direction calculation is always the same so I made a subgraph for that.
I was also wondering why in the View Direction step that 0.42 is added to Z value. It seems like an arbitrary magic number? Its like that in the source code you linked, but why 0.43, that's not something obviously like 0.5 is a half
Looks good to me! Yeah 0.42 is completely arbitrary afaik.
Hmm im having some dificulty hooking it into 3d voronoi
I want to sample the voronoi at a certain object space depth 🤔
but like the repeatedly copy pasted textures, its kinda looking like I would need 3 identical 3d voronois
which is not something I want to do, plus no matter what I plug in as its coordinates, when I change the height/amplitude value, the 3d voronoi doesnt change the way it does if say an object was moving through worldspace 3d voronoi
im pretty sure I need the object space node and then math it with the depth offset, but that still wont eliminate the need for 3 3D voronois
Thoughts: I could open up the script that makes the voronoi and try to separate the construction of the voronoi from the sampling of the voronoi, but I'd have to learn a lot about HLSL I think
Yeah, you're always going to need multiple voronois. Which is why it would likely be better if that was baked into a texture
Yeah that was my other alternative, just using a texture and doing math to hide any obvious repeating patterns
Well, shouldn't have any repeating patterns as long as the voronoi texture isn't scaled. Though if you bake the voronoi to a Texture2D it will be the same for each face - but could use a Texture3D instead.
Though I guess if you only have 3 or so layers, there's probably quite a lot in the texture that goes unused, so kinda wasting some memory there.
Oh yeah I have seen/heard of 3D Textures but havent used them yet, I have tried to google a pre-made 3d texture of random noise but no results yet
Part of me realizes I might also be wasting my time looking for optimizations instead of seeing how it performs and optimizing after
Im struggling to find ANYTHING on 3d textures online, its just tons of 2D textures with normal maps, or 3d models, adjacent things
'textures for 3d models' are not 3d textures 😬
Searching for "Texture3D" with the quotes might give some things, but yeah there might not be a lot on it. I've only known them to be used in volumetric raymarching.
But they're basically the same thing as 2D textures, storing colours for each "pixel" (in this case, those are cubes, so "voxel" is probably more accurate). Rather than sampling with a 2D coordinate, you sample with a 3D one.
There's an example here of how to bake a shader to a Texture3D, as well as another example then sampling it (though it's Built-in pipeline shader code)
https://www.ronja-tutorials.com/post/030-baking-shaders/#3d-texture-baking
Ooh okay, I didnt realize Texture3D was a specific unity thing
But yeah, it might be a good idea to try it out with the generated 3D voronoi first
Ronja has good tutorials Ill read through that 👀
oh I DO have just one 3d texture asset, I just found it in my project, it was imported from someone's shader github example I must have downloaded and imported at some point
I know Sebastian Lague used one for marching cubes
https://github.com/SebLague/Marching-Cubes It might be in here? 👀
hmm looking through the repo, there are some compute shaders but I didnt see a 3dtexture asset
In his terraform video
https://github.com/SebLague/Terraforming Oh maybe in here somewhere then?
while I wait for his package to import, trying to sample this 3d texture I do have with the parallax thingy but not getting much results
at least I can use the same asset and sample it repeatedly
unlike the voronoi
👀 I just had a thought I might not need 3d textures at all
the default unity cube has every face the entire UV map, but my cube is an unwrapped cube with 6 unique faces, but that also means there is unused area in the texture file. I might be able to store info there? hmmm maybe not, as soon as I 🦆 its starting to look murky
I was thinking I wouldnt need to sample three times if somehow I could encode parts of a texture to be like 'this bit is at X depth'
but that is making me realize that I would need to have sampled the texture before I can sample the texture 🤔
actually I might be onto something here, going to work this through
Hmm nope I goof'd it. I was thinking I could map segments of a texture to be at higher/deeper depth, and then overlay parts of the same texture together
but in practice going to other parts of the texture, the texture itself changes but the depth its at does not
🤔 also I would still need to use more sample texture 2ds for each overlaid but so now im not even sure what I thought I was going to achieve here
texture changes but height does not, because the height data isnt in the texture space, its in the UV sampling
okay im going to stop messing around with weird optimizations and go back to trying to get glitter to work with the paralax depthses
I ALMOST have Depth Glitter working but there's one bug I can't seem to figure out how to fix 🤔
if I turn the power way down, you can see that im masking out some of the glitter from the surface, but thats not what I WANT to do, I want to mask it based on how deep it is
but I cant seem to figure out where that 'deepness' value is coming from
im using two 2D voronois with only one paralax pass to do all the different glitter depths atm
Somewhere in here im pretty sure the 'Depth' value comes into existence
but I cant seem to isolate it
the view thing and tiling and offset are all X/Y, there's no Z to sample depth
Like if I try to take the minimum of X and Y, the result gets plastered on the surface
I havent been able to find a point where the result goes where it should be, instead of on the surface of the mesh
Where can I get the 'depth' to multiply the end product with???
So that deeper bits are darker
hmm maybe everything I think its doing is wrong and its not at all doing what I think its doing
yeah im stuck, im struggling and its starting to agitate me
time to give this a break
trying to visualize it, the darker the cell is, the more powerful/pronounced the parallax offset is to the UVs as viewed through that cell
which means... there is no depth? 🤔 depth is an illusion? or does depth exist?
anything viewed through one of the black cells there is the most offset the glitter can be, thus I should tint those cells darker... except that darkness is less like a distance and more like a window on the surface that lets you view deeper than the other windows
I think this looks good enough, I just dont like that if you look at it too long the black spaces on the surface start to pop out at you, maybe all I need is to randomize which cells on the surface tint light/dark the same way I am with the glitter itself?
unrelated but I just found a human face from profile view in my noise texture 😱
It's all being drawn to the cube surface, there's no actual interior geometry, so yes there's not really any depth here, it's just an illusion. The texture is being offset in different amounts along the view direction based on your "Height" input (and I guess also scaled by the Amplitude)
If you want to be able to tint sparkles darker when deeper without the "windowing" effect, you'll probably need to use constant Height/Amplitudes per layer and sample the voronoi multiple times similar to before. Can then turn into sparkles, multiply to tint each layer and combine with lerps/blend nodes.
Yeah you're right, I didn't want to use multiple layers for the glitter because the other bits were already also going to be volumetric using multiple layers and those layers add up fast 🤔
I think this is maybe good enough?
the illusion falls apart slightly when you look dead at it straight on
HMM actually 👀 🤔 new idea
Parallax depth mapping is trying to make something look deeper into the surface
but for glitter I don't need to keep the same thing deeper
maybe I can dramatically tile/offset the innards to other parts of the glitter?
so the parallax doesnt just show the same thing but deeper, but shows the texture offset bit?
I think I can pull that off, giving it a try now
how do I put a texture with transparency above another texture
nvm I think I did it - multiplied the first texture with the reverse transparency of the second texture
Hey, how does Unity decide the sort order of the material array in a Skinned Mesh Renderer?
I need the materials in the arraay to be in a specific order
but it brings them in opposite
it was super easy to pull off, all I had to do was add the cell voronoi to the UV being parallaxed
LOOKS like tons of depth, when its actually a single pass no depth at all
now to test it in scene and find out it look way different and p a n i c 👀 (it worked fine) ill post it when its cleaned up tomorrow
Can someone help me? I'm trying to implement refraction in my water shadergraph, but I keep having this issue where the effect is being applied to objects that are in front of the water. Does anyone know how to solve it?
Are you using the scene color for refraction?
To the best of my knowledge, thats one of the downsides/flaws of scene color refraction is things in front will do that even when it makes no sense visually to refract like that
Yes
I don't know how to fix it but maybe something to do with the depth buffer might help, I know that its non-trivial to correct
I've looked everywhere for a solution but never found it.
Ok, thanks
that looks sck
well any idea how to get object node scale work with element in UI Canvas ? currently i work with constant ring line size in any zoom
its work in world space
but in canvas not working
It's kinda old but I have a water shader graph tutorial here : https://www.cyanilux.com/tutorials/water-shader-breakdown/
About half way down it goes over a common method to fix this issue. It uses the depth texture to ignore distortions for pixels above the water plane, and instead just use the undistorted pixel colour.
(Based on https://catlikecoding.com/unity/tutorials/flow/looking-through-water/ - which also goes through removing some of the slight artifacts you get)
It can look a little strange but I imagine it would be cheaper than alternatives like rendering the scene twice (that's kinda similar to planar reflections, but not reflected)
Whyyyyy is this moss so dark? It doesn't even look like moss anymore. I've been trying to fix this for over 2 hours ugh
please help
Turning off cast/receive shadows doesn't do anything, so the fact that it's so damn dark doesn't have to do with shadows
Thanks, i will try this later 😁 👍
Try making the smoothness 0?
I tried a lot of things with smoothness, but it doesn't make it look any better
Also the 'cheap' way would just be to multiply the base color by some float >1
Btw I don't mean the property you've called smoothness, I mean the value on the fragment node
Ill have a look
but that basically ruins the usage of the glossiness map
I mainly used a shader graph so that I can use the other maps as well
Just test it, see if it looks ok
You can multiply the glossiness map by some float instead of adding something
Multiplying doesn't make it look better
I tried that too
anyways, Ill do what you said
1 sec
Multiplying by something >0, <1?
Say, 0.1?
I tried multiplaying it by many things. As I said, I did a lot of things with the smoothness
Smoothness makes it look like this
thats with the smoothness node only
same thing happens when I use the multiply node and the map, though it's less sensitive
Same thing happens when I do it with the add node @karmic hatch
it just turns greyish smooth
not smooth smooth
Try inverting your gloss map
inverssed gloss map + smoothness at 0. The smoothness value goes between -0.5 and 0.5, so it went in the middle at 0
inverted gloss map * smoothnes at 0.5. Smoothness value seems to clamp between 0 and 1
Also, grey
I inverted it with a One Minus node btw
As you're rendering both sides of the quads, you may want to use the Is Front Face node and flip the normal on the False input.
That should get both sides looking consistent at least. Not sure about the "grey"-ness, maybe that's coming from the ambient lighting values.
?
The previews don't show transparency, just the raw RGB data stored in the texture. It's typically stretched out like this in completely transparent areas to reduce artifacts at the edge
I already have a flipped normal map if that's what I need @regal stag
Idk what you mean 😕
Gotcha, thanks.
I believe something like this, except in this case using your normal map output rather than the Normal Vector.
Hmm I see, what does the negate do tho?
Flips the normal vector, so it points in the opposite direction.
The normals stored in the mesh are only correct for the "front" faces. When using both sides, the lighting on the back face is incorrect unless you manually flip it like this
Ah alright, so negate also flips the normal map?
If you use it on the normal map output, sure
Off the top of my head, I am not too sure if it should flip the map entirely or just the Z axis in this case though (which would be Multiply by (1, 1,-1))
That's a different problem due to different programs storing vectors differently in normal maps. You may also need to do that
Can still see that some sides here are pretty dark. If that's okay can leave it, but I believe the correct result would be
Normal Strength -> Flip (Green)
-> into True on Is Front Face
-> and Multiply by (1, 1, -1) for False input.
ohh so I should also flip the normal strength?
If your normal map Y axis is flipped yeah, which I think it is looking at the preview
It should look like the green is "lit from above", if that makes sense
uhh not that doesnt make sense
Do you mean the normal strength variable or node? It only lets me flip the red with the variable
oh wait
ignore me
Referring to the node
So... like this?
Multiply after the Flip (so that has two connections coming out)
Looking from this angle it looks like this, but....
looking at it from the other side it looks like this
I'm guessing that's opposite to the light direction, so it would be darker
The worst one is this...It's sooo dark on the other side
Ill try rotating the light see if that's the cause
I guess you'd fake some light going through by adding to the base color or using the Emission a bit.
yup that's the case
As long as it doesn't glow in the dark, I'm fine with it lol
brb in ~7 min
Is it safe to edit lighting.hlsl ?
I should probably make a backup before editing it, right?
ye
Need help with a shader issue.
I'm trying to add water shader to my game and everything seems very well in editor mode. But, once I make a build the shader disappears and the water is no longer visible.
People have suggested me to add the shader to Preferences -> Graphic Settings -> Always Include, but this method doesn't work for me.
I'm using URP.
Is there a way to read a global vector array from shader graph?
Can use a Custom Function node (File mode, as you need to define the array outside the function scope)
https://docs.unity3d.com/Packages/com.unity.shadergraph@12.0/manual/Custom-Function-Node.html
@regal stag Great, thank you!
(look on hand)
Hi, does anyone know is it standart shader ?
or what kind of shader is it?
which part?
oh the arm?
arm skin
Definitely not the standard unity shader atleast
I’m not sure if anyone can answer but are there any performance differences between generating grass using compute shaders, and modeling grass in blender or any modeling software to paint all over the terrain?
in terms of performance, is it worthwhile to strip out texture samples which are generally empty?
I got a shader that takes an emission sample, does like 2 multiplications against it - but i'm only using the emissive in like 2-3 places. Is it worthwhile to consider splitting the shader into two versions (one with emission, one without) or is just defaulting fine?
i really have no sense for where costs are in shaders
or if this kind of thinking is even worthwhile in the grand scheme of things
It likely depends on which platform you are targeting. If mobile, then I'd say it's definitely worth it. Otherwise, could try both and profile.
You also don't need to make two separate shaders manually. You can use shader keywords (probably shader_feature in this case). (Would use Boolean Keyword in Shader Graph to achieve this)
https://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html
There is probably a bit of a balance, as objects with different keywords won't batch.
Is there a way for me to have an arbitrary number of textures fed into a shader through the inspector? Like be able to add to the list. I want an arbitrary number of layers I can composite, and a color to go with each
Is there a simple/cheap method to blur these cubes that doesnt involve sampling and offseting and recombining in a bunch of passes?
ideally something more like this (photoshop) 🤔 I could just use this as a texture but then I'd lose the ability to scale it up/down
my brain: "Try Posterize, that might help."
turns out that IS posterize
Ill just try the blurred texture because this is just an x/y problem that I think blurring this will fix and most likely it wont 🤔
Yeah it didnt work, moving on from this, even if I did blur it it doesnt do what I hoped
Trig functions are not that ”cheap” but not bad either so maybe you could try this type of approximations for the floor function https://math.stackexchange.com/questions/2746958/smooth-floor-function. If thats too heavy, you could use some precalculated values (look up texture) for it
Ah nvm then
Yeah even though it didnt fix what I was trying to do, that is still a good formula to know, thanks 👍
I'm having a problem with this shader 🤔 It looks great on a sphere, but on a cube you can see how there is sorta of a center point from which the light all spills away from
I'm trying to adjust whatever portion operates from that single point into a sphere into like, four points, to make a cube
uploading a gif that illustrates what im trying to correct out of it more visually
depending on viewing angle you can see that hard point forms
Ill post the graph in a sec, its getting very bloated and messy gotta clean it up
You can see the point forming in the dot product and arccosine, its already there when it gets normalized
I do have a value that I know directly adjusts it, but it only softens it into a spherical shape 🤔
hmm the problem might be because distance math is inherently spherical
certain combinations of values makes it les apparent but it still totally shows up 🤔
maybe the problem is that its coming to a single 'point' like that, maybe I can find the last place it is a point and use like a minimum maximum to widen it arbitrarily 🤔
maximum does kind of fix it but then it creates an obvious spot optical illusion