#archived-shaders
1 messages · Page 92 of 1
hey everyone, Im wondering how can I apply different textures to different faces? its applied on cubes (such like minecraft) and I want to have a top- & bottom texture and one texture around it. Can anyone help me? This is what I've got rightnow: (only side texture shown and not top/bottom)
I have this simple shadergraph to adjust texture tiling by object scale ... it works fine in editor but as soon as I enter play mode the texture loses all tiling / looks like it assumes a scale of 1. Googling this it sounds like the issue might be related to (URP?) batching but have been unable to make any headway with that ... help?!
Many ways but the most obvious is by just properly unwrapping the models and having a texture that works with the UVs. If you want to do it by shader without UVs, you could do something similar to triplanar mapping
Classic - fixed it 5s after posting question ... noticed that I'd made the objects this was on static ... needed to uncheck 'batching static' and it works.
thanks, note: I have a big mesh for a whole chunk with all the cube outsides combined to one single mesh so uv unrwapping isnt possible for this
Not literally unwrapping then but you can construct the UVs so that they point automatically to the right position in the texture atlas
Same blocks would have overlapping UVs but that is totally fine
ive had a problem with marching cubes interpolation in compute files ive been trying to get the marching cubes to look like the first photo but the second photo is the only result id get
https://hastebin.com/share/eqikamojay.cpp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
hey, doing some shield with bubble effect etc around and I have problem, it look good from outside of obj with shader (shader is transparent btw) - ss no. 1. but from inside there is no effect visible - ss2, any idea why?
and if I get render face = both the effect is kinda broken, it works from inside but is not like from above results :#
you need to have the object render twice
put two material slots on the renderer and have one set to backface one set to front
like that?
still same effect
maybe should use isfaced or something
Is the culling mode on the Material set to "Both?"
I think my URP asset is not used when actually rendering frames... I have set the same one across all qualities as well as the default in the graphics tab, and it only has one UR data attached, where i got 2 features attached. But when I look in play mode, or even in the frame debugger, they dont have any effect.
What did I miss? It should say something at any point about stencils as thats literally all i override in the features, but its all empty! Its Unity 6000.0.28f1 LTS
its on a fresh URP 2D core project, so version incompatibility is not the reason.. im really puzzled, any help?
The Queue on the feature is set to Opaque, but 2D/sprites tends to be Transparent as also seen from the frame debugger (DrawTransparentObjects)
OMG that actually worked, thank you, thank you thank you, shaders are still black magic to me lol
not working quite how i want it, but at least theres proof it works!
i got it working how I want, but the vision cone mesh seems to correctly display itself hidden only once i walk away from the 0,0,0 position. When free-roaming with a 3d camera in the scene view, the angle of the camera seems to affect it as well? its a generated mesh with the Sprite-Lit-Default material with ZWrite turned to 0, no other changes.
Why would it depends on the world position?
ok turns out i had to change the render queue to 2999 from 3000, but why that is is still a mystery for me, maybe it dynamically assigns the queues and with elements like the walls it was rendering too late hence the all-white cone...?
I had a question about the Shader Graph. If I've a height map for my texture, where would I input this texture into? The fragment has an input for normals and AO, but I'm not seeing an input for a heightmap. Also, I'm trying to apply this map via the triplanar node, so I was wondering if there's any extra steps to be expected using that over using Sample Texture.
I've noticed applying a normal map to a Triplanar node seems a little off, so I was wondering about that too. Maybe I should use a secondary Triplanar node for the normal itself?
Do you want the height map to behave as a normal map? Or do you want it to displace vertices?
What does the lit shader heightmap usually do? Playing around with them it seems to create bump-map for lighting
Did the standard lit shader had such a property(map slot) in unity?🤔
Not entirely sure how it works, but it does make the textures pop out a lot
but that illusion does seem to become reduced the closer you are
pretty neat considering
Looking at the docs, it seems like it's manipulating the uvs for each pixel.
https://docs.unity3d.com/Manual/StandardShaderMaterialParameterHeightMap.html
Is there no input in the fragment/pixel node for that?
This post seems to provide some more insight:
https://discussions.unity.com/t/how-do-i-use-a-heightmap-in-shader-graph/706426
Some magic if it's just about changing UVs
It's weird that there's no node or input for that by default, considering the standard shader has it.
It wouldn't work as great without normal maps. It's the combo of normal maps and height map that produces the illusion.
https://docs.unity3d.com/Packages/com.unity.shadergraph@10.2/manual/Parallax-Mapping-Node.html
Ah ok I guess it's this then
Oh, there was one. Interesting
now to figure out how to get it working with triplanar ;p
😅
okay, so where we're at
this is a depth frame at one point in the Frame Debugger, which would suggest that the shader works?
but the tools clip into walls regardless in the final result
the render feature set up - depth override pass into regular render over
the shader (a bit of a messy hodge podge, but should be getting the job done):
Shader "Custom/DepthOverwriteShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
ZWrite On
ZTest Always
Lighting Off
ColorMask 0
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float color : COLOR;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = o.vertex.w;
return o;
}
fixed4 frag(v2f i, out float outDepth : SV_Depth) : SV_Target
{
outDepth = 5;
fixed4 col = pow(Linear01Depth(i.vertex.z), .85);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
can't see that option in editor
if I set only 1 material, set both render mode, use isFrontFace where for true=>normal shader, false=> one minus from normal and it works BUT its red.... :# it works fine outside and inside but inside color is red :# not blue that is stored in variable and used . I attach a graph for that, one with texture and checking isface etc, one is basic moving/animated fresnel effect and they are connected
You're using one minus for color, so it makes total sense. Do the math on paper. If you have 1,1,1 - 0,0.5,1(which is close to the color you have), you'll get 1,0.5,0(which is roughly close to the red color you get).
The fact that you're using the red color for alpha is also weird btw.
i mean only that "one minus" makes me see effect from inside of object xd u are right that because of that its red but idk how to fix it or make it in other way to see effect from inside
fixed alpha, but what about seeing it from inside without using isFace front + minus one ?
I keep getting Unity crashes for the most basic custom Bloom shader in BuiltIn RP on a new proj.
If I do Graphics.Blit or CommandBuffer.Blit to any texture thats not the "OnRenderImage" destination texture it crashes.
I've tried Unity versions from 2022.3, 2021.3 and even Unity5 and they all crash
Is it a shader you wrote?
I usually get this when I accidentally have an infinite loop in a shader.
Yes, its a CG shader but there are no loops in the shader
Err I do have a loop sorry
Hmm, I ported this from HLSL which was working perfect there in custom RP. But I'm getting it to work in BuiltIn and everything is the same
Maybe for shader ints don't compile the same in CG as they do in HLSL for Unity
Ok well commenting for loop seems to work. So have to figure out wtf is going on with that
So its not the for loop. Its a tex2D sample in the for loop thats the issue.
Graphics.Blit or cmd.Blit should auto set _MainTex prop/const in the shader correct?
Or rather a combo of both. Ugg I hate how broken the old CG shader compiler is
Yes, if you pass it a texture
Can the contents of the texture affect the loop condition?
So everything is fine. This was working perfect in HLSL.
My classic XY pass Bloom works just not my nicer Radial Bloom I want to use
So the radial Bloom uses nested loop. The loop exits just fine I think BUT I'm confirming more
Ok well got it to start working. For some reason it just can't handle as many iterations with CG shader.
The loop doesn't have to be infinite to get that error, it just needs to take longer than 10-30 seconds, something like that. How many ring counts were you using when it was crashing?
So, 16 * 8 = 128 iterations per pixel. It's a lot, but I wouldn't expect it to take many seconds.
ya and last I tested this in custom SRP on a slower GPU than I have now
CG shaders must be a lot slower in terms of its output
In Unity, only HLSL is supported. When you use CGPROGRAM it defines a HLSL shader with a few include files automatically included for compatibility, such as defines for fixed.
you mean for the output
As old Unity versions didn't support HLSL
Both compilers in Unity are just translating to other shader langs anyway
Honestly I'm confused as to why this is so slow in CG
I'm running this on a RTX 3060 and its not that high rez
No, it's been a very long time since Unity supported CG. It's an old language that was abandonded by Nvidia in 2012.
Cg and HLSL share a history and it's why they are basically identical in syntax, with some minor differences, like a few built-in functions and types present in Cg but not HLSL. Unity used to use Cg and a Cg compiler, but that hasn't been the case for a long time. Instead, they use a HLSL compiler for both cases, but use compatibility include files to make Cg files compile correctly in a HLSL compiler.
I don't know why you feel you need to convert your HLSL shader to CG. Are you trying to port this shader to an older Unity version?
The CG or HLSL compiler in Unity3D compiles out to GL, Metal and other console shader langs. So I'm not sure why you're saying this. Yes the native Nvidia and D3D shader compilers created CG and HLSL langs but other game engines have used these as translation langs
Yes the idea was to be able to use older Unity versions.
As its a single player game, I was going to back port it later for fun
How old? I can't find where Unity stopped using a CG compiler, but I imagine it's at least older than Unity 5
I haven't decided yet. Just GLES2 platforms mostly or non-NEON ARM32 SoCs
https://docs.unity3d.com/6000.0/Documentation/Manual/writing-shader-programs-introduction.html
Note: Unity originally used the Cg language, hence the name of some of Unity’s keywords (CGPROGRAM) and file extensions (.cginc). Unity no longer uses Cg, but these names are still in use.
I meant Unity version, not hardware.
You can support those platforms on the latest Unity version and you don't need to use CG shaders for those platforms.
non-NEON ARM32 target ended after Unity5 maybe. I'd have to look
This included Tegra2 chips for example
Also I don't think you're right about shaders in Unity. Unity maybe have used CG directly on Windows but that was never the case on other platforms
This is very easy to see if you compile and look at your ASM shader gen
This is what is going on. I've used these shader langs to much. The legacy compile is not the Nvidia CG compiler as its way way to buggy
The HLSL one in Unity is much better but its still a translator outside D3D platforms
Unity has hlslcc, which converts DirectX shader bytecode to different shader languages. It doesn't have any Cg compiler or converter, because it doesn't need one, Cg is so similar to HLSL, they can just compile it with an HLSL compiler if they polyfill the missing types like fixed.
fixed is just float10 so ya
fixed was a 12 bit fixed point integer in Cg, but Unity polyfills it as a half.
I don't think thats true for ARM GPUs
fixed in Unity will produce lower bit floats on ARM GPUs for sure. I've writen water effects and can see the difference
Well, it depends on the platform, you can see the polyfills here.
https://github.com/chsxf/unity-built-in-shaders/blob/880d2dae8416b35ea467a3d67a44f454c2234bce/Shaders/CGIncludes/HLSLSupport.cginc
half is lower bit float, 16 bit.
Yes but it for sure wasn't a half quality
This is one of the include files included automatically when you use CGPROGRAM instead of HLSLPROGRAM
Half quality isn't any different from float in most cases or in these effects I tested
16 bit isn't any different from 32 bit?
Not for many applications no. A user will never notice a difference
It depends on your use case of course
It's clear what fixed is here:
It's either a float or half, depending on the target platform.
In Unity, you write shader programs using the HLSL programming language.
Unity originally used the Cg language, hence the name of some of Unity’s shader
keywords (CGPROGRAM) and file extensions (.cginc). Unity no longer uses Cg, but these keywords and file extensions are still supported. Note that all shader program code must be valid HLSL, even if it uses the Cg-related keywords and file extensions.The only difference between using HLSLPROGRAM and CGPROGRAM is in the files that Unity automatically includes when it compiles the shader program. This is for backwards compatibility reasons. For more information, see Built-in shader include files.
That doesn't mean UNITY_FIXED_IS_HALF is enabled on all platforms
It depends on if the GPU reports half = fixed performance caps
That's what I said.
It's either a float or half, depending on the target platform.
You can see precisely which platforms they are if you look at the file I linked.
So older GPUs like Tegra2 probably doesn't report this. Or many low end mobile GPUs
To reiterate:
The only difference between using HLSLPROGRAM and CGPROGRAM is in the files that Unity automatically includes when it compiles the shader program. This is for backwards compatibility reasons.
Yes and that code doesn't show its enabled by default on GLES
@low lichen
Thats a && statement
Why use ChatGPT when there's Unity documentation and actual shader code you can use?
This is what Unity is doing
Why spend my life looking though Unity code?
I already know enough about shaders and 3D software.
anyone have a water shader
What is your source for this information? ChatGPT?
for urp
Because we are talking about Unity and how it compiles shaders.
I'm saying this is what Unity is probably doing as this is what any sane game engine would do. Its the most optimal solution
You test the GPU and then select the shader variant depending on hardware
Even the code snips you have shared of Unity's shader foundation suggest this.
As they all seem to be able to not always have half on even in GLES
I'm guessing ChatGPT is thinking this is right from other conversations captured online.
But regardless it hardly matters
The first check is referring to this setting:
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.BuiltinShaderDefine.UNITY_UNIFIED_SHADER_PRECISION_MODEL.html
This is by default not enabled, as far as I know.
Ok so that looks like it forces half to floats and fixed to half on GLES
But that doesn't mean fixed is half with that off
From the code you shared it only flags fixed as half with that on
Look how useful documentation can be? Let's see what ChatGPT thinks it is.
Notice, it doesn't mention this player setting, which is the only that that determines whether it's defined. Because it doesn't know. It still pretends to though, suggesting it's defined based on the target platform, which is wrong.
Look again
#if !defined(UNITY_UNIFIED_SHADER_PRECISION_MODEL).
So, if the unififed precision model is not enabled, and the target platform is GLES or GLES3, fixed is defined as half.
ChatGPT can be very useful. It helped me figure out an issue I missed just yesterday. But it's very bad at this sort of thing, obscure knowledge about an obscure topic and can easily lead one the wrong path.
Unity does have a shader tier system and will compile different variants based on those tiers. But fixed is not one of the things that changes based on that.
Well the new o1 model is much better. 4o is wrong all the time
And Grok 2 seems better than 4o in many cases now
o1 model understand far more and is so much more accurate as code gen for APIs I don't use often
4o gets D3D9 caps questions I ask it wrong for example while o1 doesn't
Google sucks so bad anymore I just have to use AI to search much of anything if I'm trying to be fast
Having good resources bookmarked is also useful. I have these three bookmarked for my Unity related research:
https://github.com/Unity-Technologies/UnityCsReference
https://github.com/Unity-Technologies/Graphics
https://github.com/chsxf/unity-built-in-shaders
GitHub search is pretty decent these days.
When it comes to specific information like this, I wouldn't trust anyone to know it off the top of their head, not even o1. You have to look at the source to get the answer.
If it matters enough ya. This I must have been confusing with texture formats in my head.
For quick HowTo use some API I don't use much. AI is great.
Some APIs have horrid docs and AI can reduce pages and pages of endless fluff into a couple lines
For example used it to better understand FMOD API DSP stuff quick
To bring it back to the original topic, if you're seeing a difference in how your shader works when using HLSLPROGRAM vs CGPROGRAM, the reason for that difference can be found in the HLSLSupport.cginc file, because as we have established, that is the only difference between the two when it comes to Unity.
Which is good, you don't have to hunt down some obscure difference in shader compilers or anything.
Well before I was using a custom SRP. So it wasn't builtin or URP at all. IDK if that could effect stuff or not.
Did you also swap out .hlsl include files from SRP to their .cginc equivalents?
Yes, my custom RP mostly had its own stuff outside pulling in some CoreRP shader includes for standard const etc
Another custom SRP I started to make support OIT
Also had good DOF
And OIT shadows
This used per-pixel sorting after pixel shaders rendered themselves into ArrayTextures.
It was very fast
The OIT objects also could cast OIT shadows within all their layers
My method was fast enough for games actually. I had better screenshots but idk where they are
Here is the custom RP matching Blender materials
Also cool transparent effects it supported
And motion blur
And SSR etc
Cool animation showing skinned motion vectors
This isn't a portfolio channel.
O well, got into a show and tell mood
@low lichen Was able to adjust stuff to be good performance. Thanks for the tips
Figured this is the best channel to ask.
I have this water shader, pretty simple. But why do the normals only work with the directional light that already comes in with the scene? (I increased the normal scale so you can clearly see the difference between the directional and the spot light).
Is it some config I need to toggle?
Can you show how this shader is done ?
Pretty simple normal animation
Or maybe the spot orientation is not good to allow you to see the direct specular lighting, like you see for the directional.
Nope, still only works with the main directional light
I can see some pattern where the spot is affecting the diffuse lighting, so I think that is does have effect.
There is def. a pattern here :
I guess you're using URP ?
Check that the additional lights are per pixel in the current URP asset
Oh it's definitely the light type
wdym ?
It works with a point light
ops wrong image
idk why the inspector says it's a spot light, but with a point light it works it seems
Guess the problem is the spotlight, which I won't use I guess
Like I mentioned, it's probably that you didn't find the matching angle to see the direct specular reflection, a spotlight is nothing more than a "constrained" point light
I'd love to make it work
The player will have a flashlight
But I guess that's just how light in real life works lol
From the view that you had in the last video, change back the light to spot and orient is so that it illuminates where the specular lighting is visible.
Thanks!
Specular lighting depends on the light angle and the view angle, so if you don't have both with the proper "range", you won't see it.
hello i am a noob with shaders i was using 2 packages one is a toon shader and another was a curve shader that curves the world ... the problem is i can only use one material of the ethier one is there any easier way to use both on the same object
No, you can't just take two shaders and expect them to combine, you need to actually merge their code to have a single shader that does the two effects.
omg
okay thanks
how can i create a color replace shader ?
something that takes in an array of colors and an array of colors to change into
and then changes those colours
Shadergraph has a handy node for that : https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Replace-Color-Node.html
oh awesome! what about multiple colours as an input? how would I deal with that? I don't think there's a colour array
Either expose a lot of colors as properties, and use as many Replace Color nodes or :
Use a custom function node, with and hlsl include where you can declare the Color (float4) array, and use a loop in the code to do the same logic over all the values.
i haven't any hlsl experience, so i think i'll just expose a lot of colors
how easly add deph intersection to shader? Cuz i got kinda complikated one shader and idk how to add at the end deph intersection additionaly :/ tried reproduce just that step from https://storyprogramming.com/2019/09/17/shader-graph-force-shield-with-hits/ and multiply it with my own alpha that worked before and cant get that effect
Is it possible to make a simple fog that is applied onto plane to feed it information about real time lightning and get that effect of volumetric lightning. Basically something similar to what HDRP fog can do with lightning but in URP shader
ah, welcome to hell
That line number is from wherever your custom function got put
(and can also include expansions of macros and #include directives)
anyway, I don't see a function namd colorReplace_float anywhere in that HLSL!
You typed in colorReplace as the function name. _float is appended because it's looking for a regular-precision function
(it can also look for _half when doing half precision)
You should rename that function to ReplaceColors_float and then punch in ReplaceColors as the function name in the Custom Function node
also, can you even use float4 arrays like that in the Shader Graph?
This asset does that
https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/analytical-volumetric-lighting-urp-performant-raytraced-volumetr-266586
I happen to have tackled the same problem very recently
I needed to deform a mesh with a variable number of effectors
I ended up just doing this LOL
I wound up using a structured buffer
Unity does support the concept of "vector arrays" on a material, but I don't think the Shader Graph can use them at all
really annoying and hard to extend but it works so
This requires compute shader support -- but I'm making an HDRP game, so whatever
i see
wrote a little script for easier management of the colors
You could use a little texture for this
i just gave up in the end LOL
im gonna just make new textures for each chroma i have planned instead
out of curiosity how would i do this though? is this a lookup table or something?
pretty much -- you'd store a replacement in each pair of pixels
you'd need to sample it correctly so that you aren't measuring between two pixels or something
That is a affect I am trying to achieve but would need some tutorial or at least some general clue on what to search for or which nodes may be used for that
Why not just set up your UV maps so that you can sample from a palette texture?
e.g. a 4x4 texture could provide 16 colors
instead of doing a normal unwrap, you'd put each face on the appropriate chunk of the palette directly
i have an animated face so idk if i can do that
it would maybe maybe sense for the rest of the model
but the face looks like this so idk if that would work lol
you could also do a second UV map that's used for the palette
UV0 would be for the base texture, and then UV1 would look up a tint value from a palette
This is a source I've used for figuring out the math. It's a bit complicated, but not too expensive. The more difficult thing is to get all the lights that overlap each pixel in an efficient way.
https://ijdykeman.github.io/graphics/simple_fog_shader
I want a simple, fast shader that gives me fog illuminated by point lights. To do this, I created a screen-space effect that achieves the results below. Th...
ooh, that looks neat
oh, I've done something very similar before! I needed to deform a mesh to fit into a cone shape
switching coordinate spaces can make problems a lot simpler
i think im just going to stick with seperate textures for now. it allows me to actually change details on it as well anyway
Assuming the issue is alpha, you can do one minus on alpha for the back faces. Not on the whole color.
I made a scanlines full screen shader, but I want it to also have the lens distortion effect that the post processing volume uses. It looks strange that the scanlines are straight and the game graphics are distorted. Changing the injection point didn't help.
Does anyone know of any techniques to recreate a lens distortion effect in a full screen shader?
You would need to sample the shadow map in steps/iterations to simulate volume of light going through the fog plane. Unity used to do ScreenSpace shadow mask making this hard if I remember correctly. I think URP is the same.
Hi, docs say
Surface shaders automatically set up an instance ID, but custom vertex and fragment shaders don’t.
I am using a surface shader. So how can I access this instance id? I tried using v.unity_InstanceID wrapped in #ifdef INSTANCING_ON but it didnt work
I just need a random number for each instance...
anyone know if there are any hyper performant (and nice) skybox aurora borealis approaches out there?
From quick search it seems like raymarching is often used for aurora borealis effects but that's obviously far from performant. Far more performant would be some sort of skybox shader based on couple prebaked textures and lerping between them but I don't think that would be easy to get looking any good. I think good middle ground would be this type of mesh based approach which could use particles to initialize the meshes and a shader to displace the vertices https://www.youtube.com/watch?v=SNP5QqAQqn4. You could develop more sophisticated vertex displacement for more squickly and natural looking waves though. Also the tutorial relies heavily on the procedural noise functions which are quite bad for performance, instead you could use prebaked seamless noise textures for better performance.
hmm yeah. I was hoping to avoid geometry for the simple reason that my skybox has a horizon / fog gradient I'd like it to mix in with, (and also generally trying to avoid transparent objects) - also many of these geo ones wind up looking very ribbony rather than nice evolutions
Hey all,
Anyone please clarify me what does it mean. Is this single shader generating too much draw call or its as showing me as per the object(shader assigned on more then 500 objects).
Hello, I am big noob in shaders and trying to make a texture warp horizontally with a sin wave. My code:
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
float wave = sin(float(v.uv.y) * _Frequency * 6.2826) * _Amplitude;
o.uv = v.uv + float2(wave, 0);
return o;
}```
But no matter what I set frequency to, the texture only spans one wavelength, changing frequency simply shifts the wave up or down vertically, it does not add more tops and bottoms like expected. Am I doing something wrong?
Thanks for any help
You can step through the draw calls to see why they can't be batched
Could be something like they're lit by different light sources
With SRP Batching you shouldn't be laser focused on draw calls though
Thanks @grizzled bolt I am going to check what causing it. Thanks for the clarification. 😀
Just to clarify, a lot of optimization guides are written without the knowledge of SRP Batching which cuts down the cost of draw calls rather than trying to avoid them like other batching methods, so a lot of the time it's a number you can basically ignore
Always measure the real performance effects first and foremost
yeah! I totally agree.
screenspace shadow mask? Is this a mask that I would have to generate myslef or are you talking about a node, because I can't find such node
You could just distort the lines rather than inject them earlier?
In the BatchRendererGroup docs, Unity says Set the most significant bit 0x80000000 in each [Shader Property Value] which instructs the shader that the data is an array with one value per instance, indexed by the instance index. ... what's the alternative here? Are there other options? How does it read the data if I don't set that bit?
How Would I Go Around Making a Shader To Look Like These Mach Diamonds? (sorry if dumb question im new to shaders)
https://docs.unity3d.com/2022.3/Documentation/Manual/dots-instancing-shaders.html
Returns the same as UNITY_ACCESS_DOTS_INSTANCED_PROP, except if the most significant bit of the metadata value is zero, it returns a default value. The default value is the value of the regular material property with the same name as the DOTS Instanced property,
So the MSB is a flag that says "I have values for these instances"
check the "accessing DOTS instanced properties" section on thatp age
You don't have to do this; it's just how the access macros described on that page work
If you only need to view it from the side, you could create a billboard mesh and paint it with a texture or some simple procedural effect
Thanks, exactly what I was looking for... Was hoping there was a better alternative that would deal with resizes better, but alas 😅
No I'm saying the way URP and BuiltIn generate shadows don't allow for what you want. At least by default or very easy
It's better to make your own SRP if you want to start doing advanced stuff imo. Then you can handle shadows more how you want
Any idea on how fog in built-in RP might be achieved?
Via the lighting settings. It should be on by default
distance fog or volumetric fog?
distance fog is already implemented but volumetric fog might be more tricky (unless you are using hdrp)
Hi everyone, I'm currently working on a project that uses producral generation. To do so we are using Graphics.RenderPrimitives, however right now the current implementation of this code is a basic Unlit shader for rendering textures without lighting.
I was wondering if anyone had any resources on how I would go about moving this over to the shadergraph (URP)?
To elaberate on this, specifcally I am talking about the input side of things. with the vertex ID and instance ID in the vertex function.
There should be nodes for that in shader graph.
Ill have a look, I may have missed them. Will they work then just with a normal shader in the same way as the custom .shader file?
They should, yes.
Hello there ! I'm looking to use the simple noise node combine with the view direction but I get this stretch part on one of my axis. Any idea if theres a way to sample 3D UV into the simple noise or if there's a trick to avoid that OR if it's possible to scale a cubemap ? Thanks in advance ! :)
iirc, the "feature examples" shadergraph sample has 3D procedural noises that you could use here.
Else you cand find some here : https://github.com/JimmyCushnie/Noisy-Nodes
You need 3D noise here, yeah
Hiyan sorrt for the late reply, something came up. But continuing my question, your right in saying that the instance ID is a node in the shader graph, but I am unsure on how I would access the transform data that would have been in the compute buffer.
StructuredBuffer<float4x4> _ObjectToWorldMatrices;
StructuredBuffer<int> _Triangles;
StructuredBuffer<float3> _Positions;
StructuredBuffer<float3> _Normals;
StructuredBuffer<float2> _UVs;
I have these buffers in the text based shader, but the properies accessable in the shadergraph are only indevidual variables rather then buffers.
I assume their is a way of doing this, but I am still unsure as how.
Would this be the "hybrid per instance" option on the single parameters?
Wasn't there a way to add buffer properties? 🤔
If there isn't, you can do it the old way - define and sample them in a custom function node.
Unless I am looking in the wrong place then no, I don't think they are listed.
With custom function nodes, I am setting the buffers inside a materialPropertyBlock, would these just be readable on the GPU using the same names they where called when assigning? (Sorry this is more a question about when and why the data is loaded and how do you read it.)
You can access these through a custom function node
I've done this
struct Foo {
float4 whatever;
}
StructuredBuffer<Foo> Items;
void GetItem_float(float index, out float4 result) {
int i = (int) index;
result = Items[i].whatever;
}
(indexing with a float is very silly, but i don't think the shader graph knows what an int is)
then you just set a buffer on the material (or on the material property block) with a matching name
in this case, "Items"
Oh awesome! Thanks thats exactly what I needed, I thought that might be how it worked but I'm glad it is ^-^
Thank you
Hi all! I'm currently working with parallax occlusion mapping in a URP shader graph. I however stumbled onto a persisting problem that i can't get rid of. When my plane is rotate 180 degrees, the parallax mapping works just fine, but as soon as i rotate the object, the parallax starts changing direction. and i have no idea how to change this.
The shader graph is quite complex as its an adapted version of a vertex painting tool. But perhaps someone knows whats causing my issue?
hey guys, does anyone know why sometimes after saving a script, my shaders keep compiling infinitely? as I'm typing this it's been about 5 minutes. only thing that seems to fix it is forcing Unity to close. I only have 3 different versions of this "parallax sight" shader.
also this appears when I re-launch the editor
My hunch is that you have a bad coordinate space conversion somewhere
When the object and camera line up just right, that can cover up an incorrect conversion
e.g. if you forget to convert from object space to world space, it'll still work if the object is at [0,0,0], unrotated, and unscaled
We were actually trying something along those lines, but we don't actually have enough knowledge to figure it out 😭 Would you perhaps be down to do it over a call?
How do you make these overridable inputs?
how do i make a custom rendering pipeline. i am pretty experienced in shader programming but i have never really used unity. i want to make a renderer for a black hole it needs to be ray marching based since i also want a volumetric for the accretion disc. it would be nice if someone could tell me how to make this possible and pass the necessary information to the shader. (GLSL if possible since i have more experience with that)
Make a subgraph and give it a Dropdown property
ah, but this isn't that simple -- it's defaulting to UV0/1/etc. but also letting you plug in a value
I swear I've done this before. I think it had to do with the "use custom binding" setting on the property...?
Sounds familiar.
That just lets you put a custom label on it.
you can then branch based on whether or not anything was plugged in, but there's no dropdown here
This is how that node is implemented in code. Looks like there's an enum with all of the bindings
https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Port-Bindings.html
I don't think you get to stick these on your subgraphs. Darn.
(I tried the names and nothing special happened)
Hi I'm having a bit of trouble, I want to update a material parameter when I click a certain amount of time
But the material does not seem to update in game, even tho it does in the inspector
I tried changing the parameter, or swapping materials but it both ways did not work
I can see the material swapping and changing states in the inspector but not in game
I’m not sure what you mean. I think you mean distort the lines in the shader which is what I am basically asking how to do. I don’t know how to use a full screen shader to mimic the lens distortion/fish bowl effect though.
When you access renderer.material for the first time, the material is instantiated -- thus giving that renderer is own copy of the material
If you're doing this:
public Material material;
void Update() {
material.color = // ...
}
and you drag in the material from the Project window, then that's going to change the original material asset
This will work as long as the renderers are using that asset.
But if you ever access renderer.material on them (maybe to set another property?), they're going to get their own copies of the material
These copies have "(Instance)" appeneded to their names and have nothing to do with the original asset
Ill check it out when I get back on it, ty
I would avoid doing this, beacuse it winds up changing the assets on disk every time it happens
Causes a lot of noise in your version control system
You could do something like this:
[SerializeField] Material material;
[SerializeField] List<Renderer> renderers;
void Start() {
material = Instantiate(material); // now we have a copy
foreach (var renderer in renderers) {
renderer.sharedMaterial = material; // doesn't try to make a copy at any point
}
}
void Update() {
material.color = // ...
}
If each renderer needs its own material because each one customizes something, then just iterate over the renderers and mess with their .material
can I code a custom node for shader graph and save it as its own asset so that I can use it in the future, or will I have to copy and paste it each time?
Hi Guys! I want to change the surface type from Opaque - Transparent of a instanced material in runtime. The material is created using the Shadergraph - PBR lit material. How should i proceed?
Change the surface type to transparent.🤷♂️
You need to set the proper keyword on the material.
I need to change them in realtime. Because these are Ready Player Me assets which gets downloaded in runtime & gets loaded in cache. I found a way to override some settings which i want. Only thing which was pending from my end is switch from opaque to transparent in realtime at the start of the scene
There are no options to set keyword for the surface type.
You can't really do that. You can prepare 2 versions of the material and switch between them though.
Ready player me doesnt give me slot to override two materials. Thats the blocker i have. They are using similar method in their default shader & applying same methods. When i try to override with mine its not switching to transparent eventhough its a minor change or no change from their shader
I'm not sure what the number of slots have to do with anything.
I also don't know what limitation that asset(? Game? ) is imposing on you, so perhaps it's better to ask in their community.
Does anyone know how to access the camera color target in URP? I have tried _CameraColorTexture and _CameraOpaqueTexture like has been suggested online, but I get "undeclared identifier" errors
If you're using the URP includes, include the DeclareOpaqueTexture.hlsl file
https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl
There's a function in it you can use to sample too
Hi all I was wondering if anyone knew what reason it would be that I can't connect a vetor2 output of a custom node:
void GetInstanceData_float(uint instanceID, uint vertexID, out float3 position, out float3 normal, out float2 uv)
{
const float3 objectPosition = _Positions[_Triangles[vertexID + _StartIndex] + _BaseVertexIndex];
position = mul(_ObjectToWorldMatrices[instanceID], float4(objectPosition, 1.0f));
const float3 objectNormal = _Normals[_Triangles[vertexID + _StartIndex] + _BaseVertexIndex];
normal = mul(_ObjectToWorldMatrices[instanceID], float4(objectNormal, 1.0f));
uv = _UVs[instanceID];
}
If anyone knew what could be causing this I would appriciate the hlep
Since that node is connected to the Vertex stage outputs, it won't like being connected to other nodes which only work in fragment stage
Either pass the UV through a Custom Interpolator or split it into a separate custom function
Hello, I have a problem with trying to change vfx's property via code. I've sent some screenshots showing mentioned code, vfx and some other things that may or may not be connected to the issue. I'd be glad if You could provide help
You need to use the "Reference" field of the property under the Node Settings tab (while property is selected), not the name.
It usually defaults to the name prefixed with _, so _Multyplayer in this case should work.
thanks so much
I'll try that
hi, it's us again. i have no idea what i get wrong but... ,do you know what's up?
these are spelt differently, they need to be the same
Everything works perfectly fine. Thank You really much. We appreciate Your help in solving this problem
I am logging shader variants in a build, and am seeing what I believe is the same shader varaints being uploaded multiple times:
1a) Uploaded shader variant to the GPU driver: Universal Render Pipeline/Lit, pass: ShadowCaster, stage: vertex, keywords <no keywords>
2a) Uploaded shader variant to the GPU driver: Universal Render Pipeline/Lit, pass: ShadowCaster, stage: fragment, keywords <no keywords>
1b) Uploaded shader variant to the GPU driver: Universal Render Pipeline/Lit, pass: ShadowCaster, stage: vertex, keywords <no keywords>
2b) Uploaded shader variant to the GPU driver: Universal Render Pipeline/Lit, pass: ShadowCaster, stage: fragment, keywords <no keywords>
^^these are the same exact variants, right? Or is it possible they just show up with the same text but are actually different variants?
I am using addressables, and I understand a potential issue is the duplication of shaders. However, I think I am doing things correctly to avoid this:
I have created a Shader Variant Collection with what I believe to be most of the shader variants used in my scene. That SVC is added into a separate addressable group along with all of the shader files it references (that can be added; some built in ones cannot be added). This includes the URP Lit shader. I am also warming up this shader variant collection before loading any of the other addressable assets that depend on these shaders. As far as I understand it, that is the correct approach when using shaders with addressables.
This is on Unity 6000.0.24f1
In an iOS build
Also, if this were just happening once it would be no big deal, but the LIT shader (plus some other shaders) appear to be duplicated 100's of times, to the point where it is crashing the app due to too much memory being used.
I'm pretty much done implementing a virtual texturing system, however I've been noticing my calculated mipmap levels seem very wrong:
I'm using this formula that I've found from multiple sources:
float CalcMipLevel(float2 uv_px) {
float2 dx = ddx(uv_px);
float2 dy = ddy(uv_px);
float delta_sqr = max(dot(dx, dx), dot(dy, dy));
return max(0, 0.5 * log2(delta_sqr));
}
// Usage in pixel shader:
uint2 virtual_texture_res = uint2(16384, 16384);
float mip = CalcMipLevel(normalized_uv * virtual_texture_res);
https://community.khronos.org/t/mipmap-level-calculation-using-dfdx-dfdy/67480/2
https://bgolus.medium.com/distinctive-derivative-differences-cce38d36797b
Each of those squares is a 256x256px texture. I was under the impression that the calculated mipmap level should keep the screenspace texel density relatively constant. But it clearly isn't, so no amount of mipmap bias will fix it.
Any help or insight would be greatly appreciated.
how do you convert a shader file into a shader include so that I can use it in shader graph?
the extension should be .cginc
A .shader file is written in ShaderLab, which contains HLSL code
The shader include file should be only HLSL code
If you have a shader that includes a function you want to use, then you should just copy that function out into another file
Could the curvature of the surface be throwing you off here?
As you get towards the pole, ddy(uv_px) is going to get rather large (since the planet is curving away from you)
It goes to infinity as you approach the edge of the sphere
yeah but it still feels like the mips are too aggressively low res in the distance
I tried using min instead of max and its much better North-South, each tile is never larger than 256px which is ideal for me
This might be where anisotropic filtering comes in
I think it is using anisotropic, but I guess given I'm implementing a virtual texture that magic doesn't quite automagically work
East-West feels like lowres mips come in too soon
I'd modify the shader so that each pixel displays the derivative
might help you visualize what's going on
Brilliant! Thank you that explains it, sorry for the late reply I only just got a chance to read this.
If i have a lot of shader, should i manage gpu memory or unity does it automatically
Shaders don't take that much GPU memory. Textures and buffers do.
ah i see, okay. How do i calculate how much memory does texture and shader need ? Is it the file size of the texture ?
It depends. File size usually includes metadata and might be compressed differently compared to when it's uploaded to the GPU.
If you need to investigate memory, use the profiler/memory profiler.
I have a question about making a material with only certain parts transparent. I have a .png that I'm using as a texture atlas. when I apply my texture to a unlit/Transparent material. The parts of the mesh that are supposed to be transparent are, but, I can also see faces of my mesh through other faces that shouldnt be transparent. The Alphas from my png are correct for what I want to do so I dont really know whats going wrong.
Do you have depth map(or whatever the setting is called) setting in the render pipeline asset enabled?
Can you take a screenshot of how it looks like as well as a screenshot of the rp asset settings?
Do I find these setting in Edit>Project Setting> Graphics?
You can find them from there, yes. But it should be somewhere in your assets folder. Assuming you're using urp/hdrp.
If its an asset I should have made or imported I haven't done that
There would be a default one if you created a project via a corresponding template.
there Isn't a selectable one in the menu I was talking about earlier. Can I just make a new one
forgot to tag
Looks like you're using a built-in rp. In this case I'm not sure.
Can you record a video/screenshot of the issue?
I'm trying to use a refractive glass material as a helmet in hdrp, and emissive materials aren't emissive through the glass, any fix?
Hi! Is there any way to use Occlusion Queries in Unity through the GPU?
I have GPU driven pipeline that I'm working on and I would like to perform occlusion culling into the vegetation without going through the CPU and one of the tools i found was the use of Occlusion Queries
Unity doesn't expose them and as far as I know, they aren't often used.
Hi, im quite new to unity but very comfortable in blender, so im very familiar with 3D terms etc. Im trying to learn the shader system in unity. Can anyone recommend some tutorials for HDRP and how to "break" repeating tiles etc? 🙂
Mmmm, okay, sad. Can I use them tho? Or it doesn't make sense/there are better alternatives for GPU Occlusion Culling?
{
float4 positionOS : POSITION; // Object space vertex position
UNITY_VERTEX_INPUT_INSTANCE_ID // Instance ID for GPU instancing
};
struct Varyings
{
float4 positionCS : SV_POSITION; // Clip space position (for depth)
float3 worldPos : TEXCOORD0; // World position for circle checks
};
float4 frag(Varyings i) : SV_Target
{
// Calculate normalized depth centered around _CameraY
float heightDifference = i.worldPos.y - _CameraY;
float normalizedDepth = saturate(0.5 + heightDifference / _NormalizationRange);
// Output the normalized depth in the red channel
return float4(normalizedDepth, i.insideCircleValue, 0, 1); // Red channel = normalized Y
}```
hey so I have this shader that gives a normalised depth texture, which I'm using in a command buffer. However, when objects are on top of each other etc. it doesn't really work, I think because command buffer isn't really doing proper depth sorting etc. Is there a way to render all objects over each other and just take per pixels highest depth to combine them all together somehow?
Hi all, I was wondering if anyone knew if their was an issue with RenderPrimative and shadows casting with the shader graph. I have converted my render primitive shader over to using shadergraph and enabled lighting to it, this can receive shadows cast by other objects (as shown in the screenshot with the cubiod gameobject) and also lighting is being correctly calculated based on light direction (faces facing away from the light source get darker). However, the render primitive mesh doesn't seem to be able to cast any shadows itself, my guess is that the depth of the material isn't being written somewhere so the light doesn't consider it an opaque object in the scene.
Does anyone have any experience with this?
This is the error, the cliff should cast a shadow in the same way as the cuboid
I have a collection of RenderTextures that I want to write to my ComputeShader. Can I just put the textures into an ComputeBuffer like I would any other type, or is there a dedicated thing that is designed to store multiple RenderTextures?
like how Texture2DArray is used with Texture2D
Replying to myself here, I found the issues. RenderParams uses a different bool for casting shadows then the material. The shader was set up to do so but the render params wasn't so it couldn't rendender shadows.
All is good now!
trying to get a specular shader texture and by base colour looks like it had no opacity ( not plugged in the normal and specular map yet) but i dont know why my base colour is so faded
Does it look more correct with a smoothness of 0?
I'm not used to the "specular workflow". I also don't quite understand how it differs from using metallicity, to be honest..
But it looks like the reflection of the skybox is overpowering the albedo
no
Okay, what about just making the base color solid red?
Simplify it until it starts behaving properly, basically
solid red still looks faded
What happens as you adjust the "Specular Color" from gray to black?
i eneabled global volume settings and it seemed to be better
i think it might be a HDRP sky and volume issue
Oh, I see
There was no light source
You only had the ambient light and reflection probe
Hence the skybox showing up so clearly
If you're using the HDRP, you might as well do normal physically based rendering instead using SpecularColor :p
im using HDRP and getting all this volume stuff set up is a pain in the chuff. its really hard to understand and i cant seem to find much videos on it surprisingly, i want to jsut deleate the sky and all the sky lighting since my scene is inside
If you want an indoor scene with zero external light, set up your environment like this
its jsut that this 1 texture i need for my walls has a spectral JPG and if i did it normally it looks weird
If you decide you want a little ambient light, you can switch to "Gradient Sky"
and then add a Gradient Sky component that's set to a solid color
Also, delete the directional light
You should wind up with a gray sky that doesn't actually provide any light.
i think something else is providing some sort of light
Click the camera dropdown in the top right of the scene view. Turn on "Overide Exposure" and adjust the slider until the scene looks lit up
What exposure value do you get?
If the scene only lights up with a very low exposure value, that means you're getting a tiny tiny tiny amount of light from something (maybe the clouds, idk). It will be irrelevant once you light up the scene normally
By default, the scene view camera can adjust to some wild exposure values (way beyond normal human vision)
no all i have is a scene with just a map model i made in blender
you can go to the Lighting window and clear baked data if it exists
that'll do it
you can also kill the volumetric clouds volume component
since you won't need those
ahh
i didnt realise i needed to add volumetri clouds to the global volume and then disable them to get rid of them, i though it it wasnt in the volume it wouldnt be active
not that it matter much but how would i get a pitch blacksky instead of grey?
For the game camera, you can change its clear color
The default is "Environment", meaning that the color comes from the skybox
lol project crashed and i lost it all its not even in my projects anymore that was weird
Actually -- I think that having a sky type of "None" already makes it black?
It just doesn't appear that way in the scene view
ahh i see, ill be able to do it again now i know. thanks for the help really appreciate it
well that's odd
presumably the project is still there, just not known about by the hub
never had that happen before
the file path is still there, any way to recover it? not the rigt channel but still
add the project to the unity hub
the hub will have lost track of the project if you moved or otherwise renamed it
got it back just have to redo the volumes
anyone know why this material isn't instancing? I thought you could change a float in a material property block and still instance
does shadergraph not support property instancing?
I'm pretty sure I've done that...
Afaik it doesn't, but you can use a custom function instead
https://www.cyanilux.com/faq/#sg-gpu-instancing
For URP/HDRP you'd usually just stick to material instances + SRP batching though
Has anyone gotten any idea why my main preview dosnt work? I've tried unity 2022 as well, but the same issue still. Im using HDRP pipeline.
When I connect a texture its just white so dosnt work either PLEASE HELP!
ok, thanks. weird that that could work, thank you very much! I'll try it later. I need to do some testing with SRP batching, I seem to recall hearing that it's slower on quest than gpu instancing
I just did this and it worked! strange that such a workaround works when shadergraph still doesn't do it itself. Thanks a lot!
If I wanted to make half of my model (and the models in it) semi-invisible, like if I'm doing a cross section, would a shader be the appropriate way to do that?
well, a shader is how you do all rendering!
You could definitely write a shader that makes everything on one side of a plane half-opaque
you might get some weird rendering problems (see here) #🔀┃art-asset-workflow message
Doesn't seem like a huge issue with that, but setting a material doesn't seem like a good way around it, because I would need half a model to be rendered normally and the other half transparent
You could make a pretty simple thing in the Shader Graph that cuts the alpha for only part of the model
transparent rendering problems could get really nasty though
I could just make it not visible entirely
A cutout shader that uses dithering would behave better
making it transparent is optional
Oh yeah, in that case, it gets very simple
Imagine a shader that discards any pixels whose world position has a X value less than 0
the one issue is that you'll see holes in the model wherever this process happened to cut through a solid object
well it needs to cut through a solid object
I would need double sided rendering
I'm guessing that's done on a per material basis
Yeah, that's a property of the shader itself
It can skip back-faces (the default), front-faces, or neither
gotcha
A dither effect can work pretty well
This is all in an HDRP project, but there's nothing special going on here
oh yeah, that works nicely too
thanks, I'll look up how to do it later, just wanted to get an idea of how simple it was.
Am I using InverseLerp incorrectly? I think my setup's correct in terms of what logic I want (it seems to work correctly), but I can't debug properly because the inverse lerps just produce the magenta effect that usually appears when you screw something up
or does inverse lerp just not work with non-float values?
maybe because it's outputting a vector3 the lerp nodes afterwards aren't receiving a proper input and that's potentially causing problems
actually since normal maps are directional, maybe instead I need some slerp-based functions instead of just lerping
I'm trying to compare four corner values (the top four) against the centre value (bottom) and figure out which values are the most different
I'm detecting differences in normals for an outline shader, and unlike a roberts cross this is capable of telling me whether the difference is more or less than the pixel currently being rendered
it works better with the depth check, but I don't think I've got it 100% right for the normals check
alright I partially fixed it by manually forcing the lerps to read the inputs as floats
so what are you trying to accomplish?
Help please. Same texture, same shader idea but lips conture look much worse. Why? What i do wrong? Or its because URP?
Its some kind of smoothing or else?
InverseLerp will be done per-component on vector3s
hm, will it also work that way when I input a vector3 as a value for a regular lerp?
I think I need to revert that change I made
to ensure that all the axes are lerped properly and that values aren't being ignored
i mean it doesn't really look like the same texture. You prob need to fix your uvs so the texture maps properly, their lips also look much higher poly or at least better modeled
I have created shader for leaf's for the mobile. But it look dark. How can is resolve it?
Or do I need to create double sided mesh?
Isn't that just the unlit side of the leafs? If it's a lit shader, then obviously that's gonna be darker(shadows, you know).
Yes it's lit, so I need an unlit shader.
Do I need to create an unlit shader with a custom function node to achieve good results?
Depends on what you mean by "good results". In real life leafs have shadows on the backside, so if you're going for a realistic style, you probably want it lit the way it is.🤷♂️
Means, I want to achieve with SSS effect and with shadow same as like real life leafs.
SSS?
Yes
Subsurface scattering you mean?
Subsurface scattering is a complex effect and is usually applied in high fidelity rendering(so it's definitely not an unlit shader).
And it's pretty heavy as well, so if you use it for all your trees you're probably gonna get a slide show.
oh! okay then I will stick with unlit shader. thanks you for all details.🙏
because I am creating this one for mobile.
You can cheat SSS fairly easily, e.g. by just adding some emission to the leaves on the more sun-side of the tree. A common trick is to add some of the leaf position (relative to the tree) onto the normal, so the tree is lit more uniformly
Thanks I will try this one as well. But I have to take care of the performance for mobile.
This works but I get this error cropping up intermittently, any idea where to squash it? i tried this but pinky
variable '_CustomFunction_GlowIntensitty_0_Float' used without having been completely initialized at /
Hmm, could maybe try
#if UNITY_ANY_INSTANCING_ENABLED
Out = UNITY_ACCESS_INSTANCED_PROP(Props, _GlowIntensity);
#else
Out = 1;
#endif
I think this got it thanks 🙂
i cant get this shader working in unity 6.0.27
https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/pixelation-65554
i think this has something to do with unity 6 reworking cameras since this doesnt work in the testing scene either
this is supposed to be pixellated
This asset is quite old (last release 2016), so surrely only for the built-in pipeline. Are you using this, or are you using URP ?
urp afaik
i do not know how to convert this to a urp shader
There are some pages here about how to create a custom post process in URP : https://docs.unity3d.com/6000.0/Documentation/Manual/urp/post-processing/custom-post-processing.html
ok cool
Do you want to the B&W dither effect, or only need the pixelation effect ?
just pixellation
Well, you could do it without post then 😄
oh fr?
In you URP asset, you can reduce the screen percentage of rendering, and set interpolation to "none" for a pixelated upscale.
"Render Scale" and "Upscaling Filter : Nearest-Neighbor" here.
hi, here i have a simple geo shader, although i still don't understand them....is there a way to extrude out the triangles using a color mask, i mean, suppose i have a texture with a green circle, now if i want to extrude only the triangles of the plane which have fallen under the green zone, what should i do?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
You geometry shader for each input triangle (v2g IN[3] ) will output 3 triangles in a pyramid shape.
To mask out the circle, you could :
- add the UV in the vertex appdata
- calculate a UV barycenter
- sample the texture with that UV
- If the sampled value is above 0.5 :
a. do the regular pyramid
b. output a single triangle that is the exact same as the input
will this work if its not circle, actually i have a non uniform texture with green channels to mask out
Yes, like I said, sampling the texture to decided to extrude or not, up to you to draw what you want in that texture.
thank you so much
I'm new to shaders and working through the Creative Core Pathway. I want to add my company's logo to a coffee mug but when I do that it also puts a mirror image on the other side. I tried resizing the image used for the base map, but it doesn't seem to make a difference as both images seem to start from the handle of the cup (as opposed to being a wrapping issue). The weirdest part to me is I even tried editing an image file that already displayed the unity logo as I wanted my logo to appear, I did a simple C&P, and it still caused the mirror image on the back of the mug after. I'm really at a loss, and if anybody could shed some light on the matter I'd appreciate it.
I'm just playing around with Unity and wrapping my head around materials and textures.
I've managed to apply a texture to a material and then apply that to some 3D objects.
I'm unsure why but I can't seem to apply it to the plane, it's just pure white?
That's just how your UV map is set up.
You could test this by using a shader that displays the UV coordinates
Your sun is VERY bright
This is blowing out all of the details
But I haven't changed it?
Is it super bright by default?
notice how the lit areas are pure white on this capsule
You're using the HDRP, so it used physically-accurate lighting. The sun is set to like... 100k lux by default
This is fine if the camera is exposing correctly
Yeah I used HDRP then removed it because it was complicating the texture/material learning.
lol ye
Okay, so your sun is still configured for 100,000 lux illumination. You don't want anything nearly that strong for non-HDRP rendering
What would you recommend for a realistic environment? Outdoors?
Try 1 or something
Other render pipelines do not use physically accurate lighting, so the units are very arbitrary
What's the difference between HDRP and standard? I assumed the HDRP was hyper HD or something
The high-definition render pipeline is an alterantive way to render your game, along with the universal render pipeline
Both of these are replacements for the built-in render pipeline -- which is what Unity has used for a long time
They're both "scriptable" -- you get a lot of control over the rendering process, and it's easy to add new renderer features
HDRP is good for high-fidelity graphics on modern PCs and high-end consoles
URP is used to cover a much wider range of hardware, including mobile devices
I don't know what I'm making yet but assuming I'm a beginner trying to make something you can walk around in like Skyrim
Where do I set this, on the scene?
It's easiest to just create a project with the 3D URP template
You can install the URP package and then plug in a few assets manually
but if you haven't really done anything yet, I'd just use the proper template
I created it using the 3D HDRP and then cleared all the stuff away that I needed
You would grab the graphics assets from a URP project and copy them into your existing project, then assign them in the Graphics and Quality settings windows
I've done that before
I swapped a game jam project from HDRP to URP because we realized we were using literally no features of the HD pipeline
So I'd have to add the folders/files back
To get the URP stuff
It's not a setting or something within the scene or lighting
It's part of the project settings
You can actually use multiple render pipelines in the same game -- you'd just assign different "render pipeline assets" to different quality levels
the asset contains all of the configuration needed to use the pipeline
I've never done that before, but it's...possible!
Nothing here for me?
How do you set a texture size, I can't see a "tiling" option on the plane itself (only the material but I don't want to change this)
So, I imported a UV inspector real quick and this is what it shows me.
Huh. So it shouldn't be mirroring at all
And your UV tiling+offset settings are the default values
Oh -- I bet that's the inside of the mug
Probably, but the image I started with and the image after editing accounts for the inside or whatever that is.
See my confusion?
I've decided to use Default RP because it's much easier to add a material to the camera. Should I be using urp instead and just try to figure out how to get a material on the camera there? I also remember shadergraph materials bugging out on ui with urp so I would have to use shaderlab anyway
Right, but this means that the upper half of the UV map is for the inside of the mug, and the bottom half of the UV map is for the outside of the mug
So both the front and back share the same UVs
How do I use that knowledge to help me get rid of the unwanted mirrored image on the mug?
You would need to redo the model's UV map
Right now, the front and back faces look at the same place on the texture
Why would that change by just replacing the logo? The original Unity logo was only on the one side of the mug.
It wouldn't change! So that's odd.
Like apply a shader to what the camera sees
ah, okay
In the URP, you can do this with a FullScreenPass renderer feature
It works with the Shader Graph
Also, the Shader Graph can now create UI shaders.
I forget exactly when that changed. I remember that I used to be unable to use it properly.
Ok cool I guess I’ll move to that then
Im having an issue where im using a toon shader with custom lighting node in hlsl, but the direction light cookie is barely doing any effect... any way i can make it stronger?
Aaah the darkness is based off of the alpha value
Its good to read the documentation sometimes 🦧
I have these meshes that join in my terrain, and the meshes calculate normals by angle. In order to get rid of seams I extruded the mesh down. you can see that the normals themsleves work against each other, however, I have a steepness effect which is in the vertex stage, and used to lerp different textures on
anyone see what's going on?
(btw, there's a Remap node that might be simpler here)
Perhaps you can display the normal vector directly on the surface? That'll help visualize what's going on
hlo all, relative shadergraph newbie here. experienced swe, contributed to a (never finished) digital conversion of one of my tt titles once, have played with mapmagic2 and another proc terrain generator whose name escapes me. mm2 doesnt work on macos (which i now live on) and so im trying to roll my own shadergraph-based proc terrain generator. any tips on blags or vids that are good starters?
i grabbed the free asset eden shadergraphtoterrain or whatever its called, and i am perplexed that the sample graph does what it does, but the shadergraphs i create for the purpose don't seem to be acheiving the same quality results
eden sample shadergraph:
eden sample shadergraph output:
my shadergraph:
my output:
i was hoping i could slap down a bunch of voroni noises at diff scales and then a cone and get an island shape
Adding a shader is displacing the object? Does anyone know what is happening here
Must be vertex position manipulation in the vertex shader.
Well, how are they using this shader? It doesn't seem like it's displacing any vertices, so they probably use it to generate the height map, that they then plug into the terrain component. This would require some setting up and/or additional C# code. Are you doing the same thing they do?
well i think i figured out my f-up -- my shader wasnt a custom material shader? i built a new one of that type and now everything is working like i expected 🤦♂️
this happens to me more frequently than not -- i ask for help on a discord, and in the process of asking the q, i start thinking of what kinds of things i would ask if i actually knew the subject and was trying to figure out what this idiot (me) was doing wrong 😆
helll yeahhhhhhs
does geometry shader support lightprobes?
does opengl 3.1 on mobile support tesselation?
Hi everyone, I'd like to ask for some help
I have an object that appears everywhere in the scene
I made a fade effect from the lower right corner
But I want the objects everywhere to have a consistent fade-out amplitude
here is my node
I can't use texture cuz it wiil be rotate
I need the same effect from screen
Well, if you want the effect to be in object space, why are you using screen position?🤔
Because I want to align srceen bottom right corner
Not according to that screenshot with X and check.
According to that screenshot the way you want it has nothing to do with screen space.
I try object position too,
but I want to align screen right corner in any rotation
so I'm researching how to combine these two
- align screen right bottom corner
- calculate by every object position
I'm not sure what you mean by "align screen right corner".
Do you want the effect to disregard object rotation or something?
like this
No matter how the object rotates or wherever it goes
the gradient will always align to screen right corner
it's not a shadow. the gradient will cover on it
Maybe get the screen space position relative to the object center
yes! I think this is great
Do you have any ideas for which node I should use?
Maybe check the screen space position node settings. As well as the regular position node settings.
Hello everyone. I am trying to build on a grass terrain for VR and following procedural rendering and compute shader tutorial from Daniel Ilett.
The code from the tutorial is converted to Unity 2019.1;
https://youtu.be/uHDmqfdVkak?si=wwiCxuFgZx85ym2C
I attached the convert script on the plane imported from Blender, the code is running now while there is nothing generated on the game environment.
Is there anything i should be aware of? or is there any alternatives or reference I can look in to for producing grass?
Ever wanted to add grass to your game? There are many ways of implementing grass in Unity, and while one technique could be great at one thing, it might suck at another. In this video, I'll go over six grass rendering methods and explore what makes each one great in certain situations.
Made with Unity 2021.3.0f1 and URP 12.1.6.
👇 Do...
i did get the intuition behind how dot products gives the shading , but i dont get why are we multiplying light color and not adding
Because you want to calculate the intensity of the light based on it's angle. There's nothing to add in here. light color + light intensity wouldn't make any sense.
ohh so color depends also on the intensity of light , and dot product gives us a grey scale color so we need to multiply RGB with different values to give it color proportional to intensity
thanks a lot
Dot product gives you a multiplier.
But yes, you got it.
it's in the vertex and applying the standard interolation in the frag, slipped my mind what that's called. I think it's not steep enough that it should actually be fading to white but it's getting influenced by the 'skirt' in the geometry
hi, I have a game i developed a while ago, and now i re-booted it by finding my old package file. however, everything is purple. i can't figure out why or how to fix it. this project is around 2-3 years old.
If i try to change the shaders, something happens, but not quite really fixes the issue
here's an example of trying to use another shader.
honestly i have no idea if its an issue with shaders or what, i have not used unity for years, and i'd like to fix this if possible, it was a cool little game
any help is really appreciated
looks like they are using legacy shaders. are you using the same render pipeline as it was set up in?
i honesty have no idea about render pipelines, all i did was make a new project and try to import everything from the package
i haven't done unity in years
ok so if you are importing a package there's a good chance that you don't have all the original project settings and this is messing up your shaders
ie you could have started a project in urp and then imported a game that's not urp into it
okay, and if the project exists in unity cloud, can i somehow import it?
i don't see any options to download it/import it, but its there
Is it possible to use shader in the same Sprite like the picture I sent you to make 2 luminescence?
I want the sign to be a little light-emitting and the writing on the sign to be light-emitting.
Can it be bloom?
Baking it into the texture or maybe with a shader would be a lot faster and potentially more costumizabel
Do I have to have 2 Sprites to do it like a picture like that using Shader?
It's probably possible without 2 sprites, but thats a LOT harder and a LOT heavier to run (basically bloom per object)
Aha, then I'll have to do two! Thank you for your answer !!
I have a geometry shader where there is something hull and domain...when I keep it normal, in build(for android) the shader returns pink...but when I comment out those 2 lines(hull and domain), the shader works fine, but the Tessellation is gone by this way...any fix about this?
I can help you with this, but I literally just woke up and will need an hour or two
Gimme a ping later
Can you get a screenshot of the Graphics in the Project Settings window, as well as a screenshot of a broken material’s inspector?
bump
thank you, but i actually solved it
i was lucky enough to have a backup from the project back at home so i just asked somoene to upload it, and it works
had to install an older editor for it to work, that might have been the reason it broke, dunno
Ah, excellent (:
It looks like the project is using very old shaders. Modern versions of Unity might not include those anymore
How can I make an effect like this in game? (big blocky outlines)
i made these effects in photoshop but i think it would be a cool effect in the game
I get these weird lines in my project, seems to be caused by mipmaps. The world map is split into 2x4 pieces, combined into a Texture2DArray which is then used in a shader graph shader. I already tried:
- Changing a lot of import settings
- clamping the UVs
- crying
Which wrap modes have you tried in the texture import settings?
I tried repeat, but currently I am using clamp on all textures
And the problem disappears if you disable generating mipmaps? I don't recommend that, just want to confirm that's the source of the problem.
yes the lines dissapear when turning off generate midmaps
Are there import settings on the texture array asset itself? Can you upload a screenshot of that, with generate mipmaps enabled?
The texture array itself does not generate midmaps it seems to reuse the midmaps already generated by the textures
I believe this answer points to the problem, though it doesn't give a solution that can be done in Shader Graph.
https://stackoverflow.com/questions/14765517/how-to-eliminate-texture-seams-from-mipmapping
Essentially, the problem is that the GPU is trying to estimate which mip level to sample from by comparing the difference in UV values in neigboring pixels. When it compares pixels that are on the border between textures, the calculated UV suddenly jumps massively, so it ends up using the smallest mip, which is probably a light gray color.
You should be able to avoid this if you change the Mip Sampling Mode of the Sample Texture 2D Array node to Gradient:
https://docs.unity3d.com/Packages/com.unity.shadergraph@17.0/manual/Sample-Texture-2D-Array-Node.html#additional-node-settings
which will expose new input ports where you can provide your own DDX and DDY value.
The values you'd want to pass in there should be DDX and DDY of the original, unmodified UV, but first scaled to match the scaling of the tiled UVs.
I'll try thank you
Something like this, but with your Custom Function node instead of UV as the source of the original UV.
I assume the original UV is scaled up to make each tile texture smaller on the sphere. That scale should also be applied to the UV before it gets passed into DDX and DDY.
Otherwise, the GPU will use too high resolution mip level.
wow so 3/4 lines disappeared but one remains
void calculateTextureIndexAndUV_float(float2 uv, out float textureIndex, out float2 newUV, out float2 ddxF, out float2 ddyF)
{
const int columns = 4;
const int rows = 2;
float columnF = uv.x * columns;
float rowF = (1.0 - uv.y) * rows;
int column = (int)floor(columnF);
int row = (int)floor(rowF);
column = clamp(column, 0, columns - 1);
row = clamp(row, 0, rows - 1);
textureIndex = floor(row * columns + column);
newUV = float2(columnF, 1.0 - rowF);
ddxF = ddx(newUV);
ddyF = ddy(newUV);
newUV = frac(newUV);
}
Hmm, that must be where the source UV wraps from 0 to 1. To be honest, I'm not sure how the built-in ddx/ddy mipmap logic handles seams like this.
You already helped me a lot, thank you
Also related:
https://www.reddit.com/r/Unity3D/comments/x2a10o/how_to_get_rid_of_uv_seam_on_generated_mesh/
It seems the most common solution is to hide the seam by having the mesh vertices match where it is.
By having the mesh split where the seam is, it means there won't be any triangles that cross that border, and since the GPU only processes pixels together that belong to the same triangle, it won't end up with two neighboring pixels with vastly different UVs.
But if you want to use this workaround, you have to rely on the UVs of the mesh and not the value you calculate from the Position.
I seem to have fixed it by using this approach, thanks to your ressource. Really thank you so much for helping me, I was stuck on this problems for hours and got really frustrated, but thanks to you I can now sleep peacefully :)
if (uv.x < 0.01 || uv.x > 0.99)
{
ddxF = 0;
ddyF = 0;
}
else
{
ddxF = ddx(newUV);
ddyF = ddy(newUV);
}
This is one way to get rid of the seam. What this means is it will use the full resolution mip level for those pixels that cross the border. It might mean you'll see the seam again if you move the camera far away from the mesh. But probably not as noticeable as the original, so it's definitely an improvement.
Would calculating ddxF/ddyF with abs(newUV - 0.5) also work? Not sure off the top of my head
still getting the seam with abs(newUV - 0.5)
Hmm, this might work, yeah. I was thinking about shifting the seam, taking another ddx/ddy and use the maximum, but this is simpler.
I think you'd want to do this after doing frac as well
oh wow, it does work
I was reading about the same issue just the other day: https://www.reedbeta.com/blog/texture-gathers-and-coordinate-precision/
Pixels and polygons and shaders, oh my!
Though for some reason the fix proposed in the article doesn't really work for my terrain shader.
Hi, I'm trying to overlay a texture in Shadergraph using the Blend node. For the overlay texture, I'm using its R channel as its alpha. Is there a way I can change its alpha clipping value? I know you can set the base texture's alpha clipping using the Alpha Clipping Threshold in the main graph, but is there a way to do that separately as well?
Material 'M_General_Wall_Plaster_DarkBlue (Instance)' with Shader 'Shader Graphs/S_General' doesn't have a texture property '_MainTex'
UnityEngine.Material:get_mainTexture (). How can i fix this error I keep getting, i assumed it was in the shader graph?
You can edit the grayscale value in a variety of ways to manipulate the alpha; can even use ut as a gradient input.
well, give that shader a _MainTex property!
(or don't try to access the mainTexture property on your material)
How can I make a shader that flattens the model based on the camera direction?
I want to make an effect similar to "Mr. Game and Watch" in Smash
bumppp
I think these 2 things are directly related to geometry shader workings. If it's being pink, then the device probably doesn't support geometry shaders.
That is assuming there are no issues with your shader.
then i have to go another way around, I guess. anyway thanks for your reply
In theory, that'd be as simple as:
float3 worldPos = mul(unity_ObjectToWorld, i.vertex);
float3 cameraDir = mul((float3x3) unity_CameraToWorld, float3(0,0,1));
worldPos -= centerPoint;
worldPos -= project(worldPos, cameraDir);
worldPos += centerPoint;
o.pos = UnityObjectToClipPos(mul(unity_WorldToObject, worldPos));
oops, that's not a real variable
there we go
If you're using the shader graph, then it'll look significantly simpler, too :p
You're moving the vertices to the center of the stage, removing the part that lines up with the camera's forward vector, and then moving them back to where they started
I'm practicing technical art and I'm trying to replicate the distortion effects you see here, but is there a better way to articulate what's happening here other than 'distortion'?
If you notice there about about 3 ish different effects; the horizontal flickering you see first, the scanline flickering you see second, and lastly that horizontal line that runs down the screen
I think stacking them with random intervals would make a big change.
maybe some color distortion too, like saturation change.
Stacking with random intervals?
What's a good way to to make conditional changes to a shader in the shader graph at run-time?
I think I can utilize a branch node some sort but I am trying to highlight specific cells for my shader rendered grid during certain game events. Like when a player moves, selects, casts ability, etc.
Then I planned on making a MB script to handle the shader updates based on those specific game actions.
anyone know how an effect like this can be achieved?
@gloomy gust The outline coloring? I think you want "Inverted Hull Outlines". Check out #1 on this shader video.
https://www.youtube.com/watch?v=vje0x1BNpp8&ab_channel=DanielIlett
It's time for not just one shader, but 10! In this video, you'll learn about 10 different shader effects, what they are useful for, and how to make them in Shader Graph!
👇 Download the project on GitHub: https://github.com/daniel-ilett/10-shaders
💖 Huge thanks to my Patreon supporters for March 2022, especially: Jeremy Gooch, Morrie...
Can someone lmk if there's a reason for gpu instancing to not work
the frame debugger shows batch cause as different materials which defo isnt true
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Can you share the frame debugger data of the 2 calls?
Can you expand the keywords section and take a screenshot with comparison?
Hmm... Seems to be the same. Can you take a screenshot of the object inspectors? With the renderer and the material visible.
the outlining yeah, but I more meant like adding onto that effect with a thick spiky outline
Based on that imagine, it almost looks like itss a trail from the foot, similar to the trail from the ball, and its just a bad reference angle perhaps. Otherwise you can probably accomplish some vertex alterations where there are mesh collisions / intersections or something similar.
~~shell (inverted mesh) outline? ~~ (already explained above)
also cyan made postprocess version of thick outline like this iirc
Yeah, gimme a minute
gpu instancing gives up if the shader has multiple passes. That's the reason I created 2 different mats and shaders. The Mask shader draws nothing. Its just for stencil
At runtime please.
Hmm... Seems like the are using the same material indeed.
I'd go through all the info in the frame debugger and make sure that there are no differences whatsoever
I'll dig into it more
I have another unlit billboard shader and instancing seems to work right for it
I tried to check if it does something different with the GPU instancing setup
But everything was more or less the same
Maybe something with the mesh settings🤔
I am also facing the same issue, Even everything is same.
Could be
I'll let you know if I manage to fix it
I'll try with a regular cube
Ive made a destruction shader using a bunch of unity stuff, and while it itself is performant, the way i add more is by applying paint, to a mask texture, but this is done with the CPU which is also the most performance heavy task in the entire thing, so i was wondering if it would be worth offloading the painting process to GPU if the texture res is just about 64x64
Yes, painting the mask on the GPU would be way more performant.
The bottleneck here is the data transfer from CPU to GPU.
If you need also the data on the cpu, for raycast by example, a simple compute to read it back might be an option.
where's can I find this postprocessing version?
It's not the mesh but I discovered something super weird
Data from cpu to gpu would pretty much just be - position, radius, color
And then gpu could just modify the texture directly i believe
Yep
It's probably transparency that's breaking GPU instancing
Try with a primitive cube and simple lit shader. If surface is opaque, instancing works correctly, and if it's transparent, instancing breaks
Fixed it
Thanks @dapper arrow .
So is there any way to do it with transparency?
The render queue
So SRP will not work in that case, right?
In my case I had two transparent materials on the same object with same render queue that is the default 3000 which was messing up instancing
Now one of the two shaders have queue 3001 and it seems to work as expected
Unfortunately yes
Until your shader is handwritten
What if they are both 3001?
Oh, wait, it's different materials
Thanks @dapper arrow for your effort.
My guess is that it has to render one object with mat1 and mat2 before rendering any other object to preserve the correct rendering order, and thus it can't batch/instance objects in this case.
Yes they are
Lemme check
Yeah, now that I look at that frame debugger screenshot it looks like that's what's happening
Same result
Instancing breaks
You see that there are 2 draw calls for one object first.
Yep, one comes from the mask material. The expected behaviour was, the mask material doesn't get instanced but the actual light material does
Well, then you'll need to put the masks earlier in the queue and the other material later.
Yuh, that's exactly what I am doing now
Mystery solved I guess
One question:
If I have 2 boxes and both have the same material and mesh but the light maps are different will SRP Bathing work?
GPU instancing won't
That's what I know
Srp batcher only cares about the shader you're using ig
Okay, thanks @dapper arrow
@kind juniper It's this https://youtu.be/9p66mbDHuXM?si=-bswgrGb2rSPiEjw
Doesn't seem to be too complicated (hopefully)
I have two overlapping cubes in the middle
And they only seem to draw over each other when both shaders have the same render queue
Is that a question? I'm not sure I understand what you're trying to show. Maybe record a proper screen recording instead of using a phone camera.
I am sorry, I don't have a proper screen recorder atm
But I recorded something which is easier to understand
Okay, but what's the purpose of the video? What's the question?
The question is why is this happening
If the mask is on a different render queue, wouldn't it still write 1 everywhere
And wouldn't the other shader still check for stencil equals 1
Just want to know the reason that's happening
On the GPU there's only one queue(well, there's a separate compute queue sometimes, but that's irrelevant). GPU executes draw commands one by one in order. If the mask doesn't work, then it's probably rendered after the actual objects.
You should look at the frame debugger to figure it out.
I can also spot an error popping in your video. Seems to be related to rendering too(d3d11)
Could be relevant
Oh, those are just some old broken shaders
I have to clean the project up
I found the reason
It's just this
I'll read the solutions in there
Hope something works
How do I get the equivalent of Unreal's Scene Texture: Custom Depth node in Unity?
I want to do some depth culling in a transparent shader.
Not sure what that UE node is but do you want this..?
https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Scene-Depth-Node.html
Jesus I can't even find docs for that node on the first page when searching this
What I'm trying to replicate is this effect. The character here is semi-transparent but you can't see any inner geometry (which you will get if you just set it to be transparent).
It's this.
From what I understand, this requires a custom depth buffer.
And the shader only compares against that.
You can have one material that writes to the regular depth buffer, and another that does the effect, but then you won't be able to see other transparents through it. https://cdn.discordapp.com/attachments/1316619121680449558/1316761719355478126/Marvel-Win64-Shipping_DY5C8IZZdg.gif?ex=675c396a&is=675ae7ea&hm=d2cdd5219707ec851a5144e9ce8293f4a41e1e93e6be862424073b28d25fd17e&
And you can here.
Should be able to see other transparents through if you change the render queue of both those passes/materials
(though that might mean the ghost character always appears ontop even if the other transparents objects are infront)
I think I'd like to maintain normal sorting 😛
Is there any way to do this in Unity URP?
Surely shaders can write to custom textures and then read from them at later points, no?
so if I'm using Sprite Custom Lit my preview turns black (I guess preview just doesn't know anything about _ShapeLightTextureX and can't sample light textures)
is there anything I can do about it or now I have to customize previews and provide global lighting?
the problem is that even prefab viewing in context is broken
sometimes i wonder if developers even tries their own features
the whole 2d renderer feels like proof of concept with half-baked features
who decided that global lighting fallback has to be black?
i'm probably being really silly but i have an issue where if i make changes to my camera shader in the inspector, they automatically reset when i go into play mode? no idea why
"camera shader"?
you'll need to show us what you're doing
i fixed it, nw lol
looking to create an RGB mask shader for a large asset im making. I need to add dirt/leaks etc. to the large asset and I need it to be driven by masks. Any resources on how to do this? I know how to do it in Unreal, but not sure how similar it is using the Unity Shader Graph
Ultimately both convert to hlsl, so it should be pretty similar.
How can i make a portal effect here?
should i use a shader on this texture, or use a vfx system
I'd want a shader that makes the texture a little wobbly
and then have particles coming out of the portal
how can i achieve a wobbly texture?
So, you normally do this
fixed4 color = tex2D(_MainTex, i.uv);
you sample a texture using the interpolated UV coordinate at the pixel you're rendering
that was a five-dollar sentence right there
you use the UV map to sample the texture
But what if you distort the UV values?
fixed4 color = tex2D(_MainTex, i.uv + sin(i.uv.x));
This would cause the UV coordinate you use to get...distorted
it gets pushed around
if you included time in that formula, it would get distorted over time
(are you doing shader graphs here?)
i just spent all day writing HLSL and i'm cooked
yeah, preferably 😅
im no good at shader writing
okay, so you'll want to use the Tiling & Offset node
you can start by just plugging UV0 into its input and then doing nothing else
next, consider a constant offset
And then, a variable offset!
It might help to look at the actual effect of the distortion on the UV coordinates. This is showing the difference between:
- The original UV coordinate
- The distorted UV coordinate
for a very distorted image (too distorted, even!)
I made it so that negative differences are green and positive differences are red
The distorted UVs move faster than the originals for a bit, then slower, then faster, etc.
this squishes the image (where the distorted UVs are ahead of where they should be) and stretches the image (where they're behind where they should be)
the distortion is strong enough that it actually goes backwards several times
that middle column sure is weird looking
how can i make this more of a rounded square instead of a circle?
why is it not transparent? it's like a weird red color lol
you're going to need to give a more clear view of how you're calculating that mask
I'm guessing you're finding the distance from the center
I guess the alpha has negative value. Add a "saturate" node between the "one minus" and the output
(if so, rather than doing distance as √(x²+y²), do (x^a + y^a)^(1/a). Take the abs of x and y first just to make things safe, and then set a > 2)
how can i add normal maps to each texture?
- Change the shadergraph target type to a lit shader, this seems to be an "unlit".
- Don't use "normal from texture" with normal maps, but use "SAmple Texture 2D" with "Type" set to "Normal".
- Blend the normals the same way you blend the colors, and plug into the "Normal" output of the fragment stage.
holy smokes it all works thank u so much
What does "Ztest Off" do? Is it even valid?
is there any way to check if a subgraph is being used at all in the project? Want to do some cleaning but im not sure if certain subgraphs are being used and i have too many shaders to go one by one
That's not the proper way to blend normals though, whiteout blending should at least look better.
Trying to write a billboard shader for instanced meshes in URP (using code because it seems all hacks for getting InstanceID working w/ shader graph only works for directX) but it doesn't work on instanced geometry (if I apply the material to a normal object it works fine aslong as there's no instanced geometry in scene)
My vertex shader:
float3 grassWS = mul(positionBuffer[instanceID].TRS, IN.positionOS).xyz;
OUT.positionHCS = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(grassWS, 1.0)) + float4(IN.positionOS.x, IN.positionOS.y, 0.0, 0.0));
positionBuffer[instanceID].TRS is a 4x4 matrix
ZTest is used to specify z testing - how you want the shader to test its depth against the depth buffer to decide whether to render a pixel. So ZTest LEqual would mean "only draw when the depth is less than or equal to the depth value in the depth buffer". Usually to turn off depth testing, ZTest Always is used. Perhaps this option used to be called ZTest Off in the past and you encountered a very old shader.
I can get it to work if I extract the position from the TRS matrix but I no longer have any scaling from the TRS matrix
float3 grassWS = positionBuffer[instanceID].TRS._m03_m13_m23;
OUT.positionHCS = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(grassWS, 1.0)) + float4(IN.positionOS.x, IN.positionOS.y, 0.0, 0.0));
Yes I know, but it was the easy setup solution 😅
Fair enough 😆
yeah, you have to watch out for strange alpha values
an alpha of -1 will cause Blend SrcAlpha OneMinusSrcAlpha to do...very weird stuff!
-1 times your color plus 2 times the exisitng color
It looks like you have quite a few options, haha
Always, False, and Off all produce the same results for me
(no z-testing)
what are the built in variables in Input of a surface shader?
How can i make the transition between the portal and the wall less jarring?
looks pretty out of place lol
Maybe make it transparent and lerp alpha to 0 at the edges?🤔
I have this alpha stuff here, but Its a circle and not a square. how can i make the alpha lerp as a square instead of a circle? I assumed that most of the math is done as a circle lol
Assuming the quad has uvs 0-1 horizontally and vertically, you could remap the values close to 0 and 1 to have 0 transparency.
im using the default unity plane mesh
Then it's probably 0-1. You can test it out. If not, then you could remap the object(pixel) position instead.
is there some tutorial / docs i can read on this? still slightly confused and dont wanna waste ur t ime lol
It's mostly just simple math. You could probably ask chat gpt or something for an example.
not entirely sure if i've done this right lol
Get the math down first. It will be easier to get a correct answer and confirm it on paper. You can worry about nodes later.
i'll try that
i think i've achieved my desired effect here!
This node or one coming before is probably only available in the fragment/pixel shader/stage.
this is my workflow
sorry i know the text is probably illegible 😅
how can i make this useable for the vertex stage?
Yeah. Can't see shit.
Ah, it's mostly math. So it's probably normal from height that is only for pixel shader.
curiously enough i can just do this
but i imagine this doesnt work. the preview has become invisible
no my thing goes invisible lmao
What are you planning to achieve anyway by plugging normals into vertex positions?
well i wanted to make a ripply effect for my portal
but instead of like making the texcture ripple i wanted the actual shape to ripple
What is the geometry of the portal? Is it a flat plane?
- You'll need to modify vertex positions.
- You'll need enough vertices in the mesh for the effect to look decent.
yeah flat plane
If it's the default plane mesh, I think it only has like 10 x 10 (or 11?) vertices, so it's gonna look very blocky.
Oh its not a circle
naur
i found a tutorial. i'll try and follow that
i assumed i was working with a single quad plane
idk why
Get the delta of the position from object center and use it in a sine node or something. Then add the result to the z position.
If you fake it in the pixel shader, it would work with a quad too. It wouldn't be modifying the geometry though.
To be honest, that's probably gonna be more then enough, given the context. You can't really notice that the geometry doesn't change in your scenario.
trying to set up a vertex blend shader for meshes. I have created this shader and I installed Polybrush, yet when I go to "paint vertex colors on meshes" it doesnt do anything. completely lost here. am I missing something?
why is it that when i make this simple white metal material fully rough it's not fully white and when i make it fully smooth its black?
I assume it's a general scene lighting issue but I'm not sure what I'm supposed to be doing here.
oh, if i turn off environment reflections it looks much better hm
I know you already solved this but you need reflection probes (or the skybox environment fallback reflections) because without any then there is nothing to reflect, so when you make a material very reflective and metallic it will just appear black
Am I missing something with this? If I rotate the main light at all it doesn't seem like anything is actually changing (note if I use a custom vec3 param in place of this the lighting does work). This is with URP Unity 6.
note I've also tried it with the built in main light direction and that doesn't work either.
Hey i am attempting to create a raymarching shader and im having trouble with depth comparision when the raymarched sphere approaches the screen borders sth weird happens with depth comparision (img) https://pastebin.com/VJgch66z i dont understand why this is happening tbh would appreciate your help
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Well, do the texture property names match what polybrush is using?
how would I check? I’m just using poly brush to select the red channel to paint with. Yet nothing is painting. Assuming I need to use Probuilder with it?
Was there no built-in node for the main light?🤔
The simplest way would be to look at it's code.
Or documentation
what is the cheapest possible way to have a shader write to depth?
Just a bare bones vertex and pixel shader with zwrite on I guess.
but they require shadow caster pass, without it , is that possible?