#archived-shaders
1 messages ยท Page 143 of 1
it's pretty much what I did on the custom pass
it also gives linear blur control on pixel shaders, so no stepping between lod levels
@delicate badger
just make sure to set the master node to transparent and make sure the material is set as well
oh nice !
thanks ๐
was so simple ...
๐ข
I m really bad with shader ^^
How can I convert object space to tangent space in a shader?
@fervent tinsel how did you get the blur only on a square in the middle? When I put it on a GUI Image in the middle of the screen, it blur the whole screen :/ In addition, I have a error in the console
If you create a Texture2D property with the _MainTex reference that error will go away. You could also sample that texture and take the alpha property into account if you don't want the blur to be square.
As for it blurring the whole screen, are you sure the UI image you are applying it to isn't the size of the full screen?
yes :/
@harsh marsh there should be a transform node to do this, let me double check
If I remove the material and put a source Image
It works
As soon as I put a material on it, it blur the whole screen :/
@delicate badger Shadergraphs on Canvases are not supported at the moment, but its on our roadmap
Product roadmap and feature requests. Welcome to our product portal.
no worries! if its important vote for the issue ๐
If the shader is always applied to the entire screen, might be able to mask it using the UVs (/Rectangle Node?), probably not an ideal solution though.
I mean a single quad in front of the camera is not horrid in terms of overhead, but I would recommend it be an unlit material
there is also single-pass-post effects on the roadmap too
@simple frost I'm not using shadergraph
ah, then youll need to multiply by the transform yourself. Which SRP?
default.
float3 objGravity = mul((float3x3)unity_WorldToObject, _Gravity);
float3 objTangentGravity = mul(objGravity, tangent);
like this?
youll need the object to tangent space matrix
@devout quarry , thanks. I probably should've said that I'm not using shader graph for this. I have shaders that I'm porting over from previous versions that I don't want to convert to SG.
which I'm not sure if thats provided by unity default, so you may have to construct it yourself
idk how to get the object to tangent space matrix
o.pos = mul(UNITY_MATRIX_MVP, vertex);
o.worldPos = mul(_Object2World, vertex).xyz;
half3 wNormal = UnityObjectToWorldNormal(normal);
half3 wTangent = UnityObjectToWorldDir(tangent.xyz);
// compute bitangent from cross product of normal and tangent
half tangentSign = tangent.w * unity_WorldTransformParams.w;
half3 wBitangent = cross(wNormal, wTangent) * tangentSign;
// output the tangent space matrix
o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x);
o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y);
o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z);
o.uv = uv;
return o;```
thats how you get the basis vectors
@calm carbon To do alpha clipping in code you'd do something like clip(alpha - clipThreshold);, Or if (alpha < clipThreshold){ discard; }
Thanks. I'm also relying on their shadow pass that relies on that alpha clip property, and it doesn't seem like I can control that specifically.
UsePass "Universal Render Pipeline/Lit/ShadowCaster"
I believe _AlphaClip is used in here. I probably could just rewrite this pass ๐คท
@harsh marsh if youre not as familiar with matrix math you can also calculate it in C# and pass it to the shader
CG has matrix multiplication functions
@calm carbon It looks like they might use a "_Cutoff" property? Looking at the code
@rapid acorn I dont recall a provided conversion matrix to tangent space though, so best I can guess is constructing it from the space basis
seems like that ( _AlphaClip) controls whether alpha clipping is done or not in that pass, and the _Cutoff is the threshold used.
Ah, I see
exposing that property in my shader doesn't seem to make a difference though
@simple frost Ah! Didn't read messages above. CG has multiplications like cross and dot.
@calm carbon The shadow pass fragment seems to be using Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff); are you also using _BaseMap for the texture?
Correct
@delicate badger oh I didn't have it on UI canvas, just put it on a quad mesh in front of camera
What about #pragma shader_feature _ALPHATEST_ON? The shadow pass seems to already be using that though, but I'm running out of ideas. ๐
I also tried leaving it in/commenting that out ๐
Since I saw _AlphaClip turns that on/off
@rapid acorn all good, thanks for the help though!
@calm carbon I'm struggling to find what the _AlphaClip property actually does in the Lit shader, I can't seem to find a mention of it, (except it being declared as a property in the actual Lit.shader file)
Thanks for taking a look. I'll look at it more in detail later today ๐
@regal stag I believe _AlphaClip is used for at what point the clip function call gets made call gets made with the alpha
I can take a look though
That's what I assumed, but the Alpha function in SurfaceInput doesn't seem to actually use it, it uses #if defined(_ALPHATEST_ON) instead
Oh it looks like it's used in the Editor/Shadergraph/Includes files : https://github.com/Unity-Technologies/ScriptableRenderPipeline/search?q=_AlphaClip&unscoped_q=_AlphaClip
looks like its used in universal but not HDRP
as far as I can tell
wait no
its just used as
#if _AlphaClip
clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold);
#endif
so its just a flag
I wanted to control _AlphaClip from my custom shader
doesn't seem like I can when I make it a property
or just call set float on the material
@calm carbon From what I can see the _AlphaClip property isn't used at runtime, possibly only by the editor/shadergraph. Even in the custom ShaderGUI, it uses this : bool alphaClip = material.GetFloat("_AlphaClip") == 1; if (alphaClip){ material.EnableKeyword("_ALPHATEST_ON"); }else{ material.DisableKeyword("_ALPHATEST_ON"); } The runtime/shaderlibrary seems to use those keywords instead, so try using them like MentallyStable said.
gotcha.
#pragma shader_feature _ALPHATEST_ON
Commenting this out from the shader though also doesn't seem to make a difference though.
If you comment it out I assume it then doesn't have it defined, so ignores all alpha clipping code?
That's what I thought. But still performs alpha clipping
Or maybe it always runs? No idea ๐
xD
Wait but are you using UsePass?
Because I think that pragma is already defined in the shadow pass too, so removing it from the normal shader won't affect it
#$%^
But you don't need to remove it, just use material.DisableKeyword?
What is it you're trying to do?
I am porting shaders over from previous Unity versions and using their lit shader as a template so I can use their shadow pass that we used before. I want to be able to control the Alpha clipping flag from the inspector, but I don't have access to it--it was exposed only through their customeditor gui.
I think you can also do this to change the keywords per material, without using a script/custom gui
I assume removing the keyword from that box will disable it?
Interesting! though I'd feel wrong doing it this way ๐
that works though
I'll reconsider and just make a custom gui script. It'll be good practice anyway. Thanks all for your help. ๐
Hi! Im trying to write a Unlit shader that receives shadows by some examples I found online
The object turns out pink :/
The link works, they just posted it twice
Look at the url
I mean, they posted the link twice, use this https://pastebin.com/HgthcXT4
Yeah yeah noticed it's back to back๐๐๐
SOrry
๐
Im progressing a bit with mo code
The problem is I cant get the normal
v.normal gives error :/
Or add it to the appdata struct, is it float3 normal : NORMAL; (not sure off the top of my head)?
Yes that's correct too.
Ah! Didn't notice @plush bane has made an vertex struct too
Better go with @regal stag method
It ain't rendering at all.
@rapid acorn works for me. I think it works only with univeral rendering pipe
Oh yes there's a tag in the shader for that.
Although I can't see the mesh, I can see the shadow ๐
The code is from Unity manual
Whata heck
I guess different code needs to be for Universal piplen ๐คฆ
Hi guys! I am new in Shaders and created a new topic on Unity Forum about SpeedTree and custom property block. Can someone help me to figure out how to solve it (if there is)? Here is the link to the topic: https://forum.unity.com/threads/speedtree-wind-stops-to-work-when-materialpropertyblock-is-applied.849136/#post-5603047
It looks like Vegetation Studio had to inject their own function to work with speedtree
@plush bane For the Universal RP the code would have to be different. But if you are using URP, you also have access to use shader graph instead of writing code.
@regal stag but shader graph is for composing shaders (looks and stuff). I can't make in it my object to receive shadow
If you use the PBR Master it should receive and cast shadows. You can also use the Unlit Master node and do lighting calculations yourself with the help of custom nodes though. https://blogs.unity3d.com/2019/07/31/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019/
@regal stag my goal is a Unlit shader that casts and receives shadows
@plush bane I haven't really done much custom lighting stuff. Last time I tried I struggled to get shadows working properly (through shadergraph custom nodes like the above link).
As for writing code, there's a bunch of differences between shader code for the built-in vs URP pipelines though, and hardly any (if not any at all) tutorials for it. You might need to look at the source for the URP Unlit & Lit shaders as an example : https://github.com/Unity-Technologies/ScriptableRenderPipeline/tree/master/com.unity.render-pipelines.universal/Shaders
@regal stag Ok, thank you for input ๐
hey gang, simple question
were using URP and for our UI, we want to 'grey out' various buttons
is anyone aware of a URP compatible shader to do this anywhere?
So I have a more correct code: https://pastebin.com/3GRTD2p1
Problem now is that mainLight.shadowAttenuation is not changing. It's always 1,1,1
I tested it similar with build in Lit shaders, and mainLight.shadowAttenuation is varying
Any ideas?
@plush bane Looking at the Lit shader, and the ShaderLibrary/Shadows, (https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/ee1d82542baf38281b794769572e4ef0e6a18378/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl)
It looks like you might need to add
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE```
So it does shadow calculations. If it's not defined, most of those shadow functions return 1.
Also unrelated but you might want to switch the UsePass "Legacy Shaders/VertexLit/SHADOWCASTER" out to use the shadowcaster from the URP Lit shader, rather than a legacy one. Universal Render Pipeline/Lit/ShadowCaster maybe?
@regal stag ๐
i remember seeing a tutotrial before that detailed with a shadergraph shader getting info from a component so it could use it's data in a shader
Works but its self shadowing, what I dont want.. have to find a way around
now that was a while back and before it was URP, and was for the global light, which is easy to sort now, have a neat custom node for that
now i just wanna know if there's a way to deal with general data from components/gameobjects, so shaders can interact with stuff better
i have a script that finds the closest light to the player, and i want my shader to take the data from that light so it can use it for it's shadeing, since the node only really deals with the directional light
@hot olive You can create shader properties and set them from a C# script from the material reference to send data into a shader. e.g. material.SetFloat, material.SetVector. If the property isn't exposed it counts as a global property, which can be set using Shader.SetGlobalFloat/Vector/etc
If you want to deal with lights though, this post goes through custom functions. See the "Working with Multiple Lights" part to support more lights than just the main light. https://blogs.unity3d.com/2019/07/31/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019/
ooooo thank you, didn't realise that this article existed!! also thanks for the shout on global variables, thanks!
No problem. That article is a little old now, but I think the functions still work.
yeah trying to like, interpret the shader_preview and LWRP terms and hoping none of the names have been changed besides them
this is probably a common question re: this but how do i fix this, lol
It means that the SpotDirection hasn't been assigned in the function (in all paths)
ooooh just realised my mistake i thiinkkkk
If you are using an #ifdef thing make sure both sides have SpotDirection = float3(0,0,0) or whatever.
No, but you don't want the half4 there if it's a out parameter
Right, so everything in that #ifdef is initialising the out parameters, but if that isn't defined, there's nothing to say what to output. You'll need to add something like :
SpotDirection = float3(0,0,0);
Color = float3(0,0,0);
ShadowAttenuation = 1;```
before the `#endif`
That's assuming you actually need the UNIVERSAL_LIGHTING_INCLUDED ifdef at all
ahhh thanks a million
i didn't realise that was necessary
so it basically needs a backup on what to output if the UNIVERSAL_LIGHTING isn't there?
makes sense
Yeah, if that isn't defined the function would be blank, and it wouldn't know what to output
any idea on how to create a shader like cuphead ?
Is there a specific reason why shadergraph boolean keywords must end with _ON to be exposed? ๐ค
It also seems like the Default for the keyword only works when it is exposed
Hi there! I'm trying to make a material double sided via script, however it won't update until I edit the material in the editor.
bspMaterial.SetFloat("_Smoothness", 0);
bspMaterial.SetTexture("_BaseColorMap", newTex);
bspMaterial.EnableKeyword("_DOUBLESIDED_ON");
bspMaterial.SetFloat("_DoubleSidedEnable", 1f);```
This seems outdated tutorial > https://blogs.unity3d.com/2019/07/31/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019/
Heh maybe not
How I create new file for shader include GRaph?
You gotta test n try yourself @plush bane
Yeah I did
AS clearly ShadowAtten is empty without #define _MAIN_LIGHT_SHADOWS, I did that
But then I got an error: Shader error in 'Unlit Master': invalid subscript 'shadowCoord' at /Projects/Unity/ShiftBall/Library/PackageCache/com.unity.render-pipelines.universal@7.1.8/Editor/ShaderGraph/Includes/Varyings.hlsl(118) (on d3d11)
Can't figure oout how to get around this currtenly
Are you making a toon shader?
But you're trying to get shadows to work right?
okay
On here there is a .unitypackage
with custom node code
if you give me 2 seconds to start up Unity I can share here as well
Oc I give u 2 sec
@devout quarry where do you define _MAIN_LIGHT_SHADOWS ?
nowhere else
that's just the code
Unity defines it for me is my guess
I think it's just whether or not your main light has shadow casting enabled
Problem is that Im casting shadows, but not rceiving
does the code not work?
And it becouse _MAIN_LIGHT_SHADOWS is not defined
But when I define, it gives error ๐ฆ
no
Shader error in 'Unlit Master': invalid subscript 'shadowCoord' at /Projects/Unity/ShiftBall/Library/PackageCache/com.unity.render-pipelines.universal@7.1.8/Editor/ShaderGraph/Includes/Varyings.hlsl(118) (on d3d11)
and if your object is set to not receive shadows but you still want shadows from the shader, just remove the || defined(_RECEIVE_SHADOWS_OFF) check
hmm
if you want you can get the unitypackage from the link I sent, check if that works
ok
Light GetMainLight(float4 shadowCoord)
{
Light light = GetMainLight();
light.shadowAttenuation = MainLightRealtimeShadow(shadowCoord);
return light;
}
half MainLightRealtimeShadow(float4 shadowCoord)
{
#if !defined(_MAIN_LIGHT_SHADOWS) || defined(_RECEIVE_SHADOWS_OFF)
return 1.0h;
#endif
#if SHADOWS_SCREEN
return SampleScreenSpaceShadowmap(shadowCoord);
#else
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
half4 shadowParams = GetMainLightShadowParams();
return SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), shadowCoord, shadowSamplingData, shadowParams, false);
#endif
}
if _MAIN_LIGHT_SHADOWS is not defined, bye bye receiving shadows
@devout quarry how do I use that simpletoon.unitypackage ?
Oh Yhink i got it
Yeah your things is receiving shadows
I found my error thanks to you
I was looking into this yesterday and had the same issue when defining _MAIN_LIGHT_SHADOWS, but there was another one that didn't error.
It was like "MAIN_LIGHT_CALCULATE_SHADOWS" or something.
You also need the shadow cascade one or the shadows look weird at a distance
@regal stag can u look into MAIN_LIGHT_CALCULATE_SHADOWS ? How you define thouse
So.. I'm defining them as keywords in a subgraph, in the shadergraph blackboard.
The Lit.shader uses Multi Compile, so that's what I've set it to.
(I'm using the custom function from the 'custom lighting 2019' article btw).
@regal stag I can't find a place where MAIN_LIGHT_CALCULATE_SHADOWS is used
Annoyingly though, the default values aren't taken into account at all. So when you create a material you need to set the keywords in the debug mode of the inspector
GetMainLight uses MainLightRealtimeShadow, which uses MAIN_LIGHT_CALCULATE_SHADOWS
When _MAIN_LIGHT_SHADOWS is defined, it looks like it automatically defines it
But it errors because the Varyings struct doesn't include "shadowCoord"
@regal stag main code is different. So I have some newer or older version?
Mine
half MainLightRealtimeShadow(float4 shadowCoord)
{
#if !defined(_MAIN_LIGHT_SHADOWS) || defined(_RECEIVE_SHADOWS_OFF)
return 1.0h;
#endif
#if SHADOWS_SCREEN
return SampleScreenSpaceShadowmap(shadowCoord);
#else
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
half4 shadowParams = GetMainLightShadowParams();
return SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), shadowCoord, shadowSamplingData, shadowParams, false);
#endif
}
Un ur URL
half MainLightRealtimeShadow(float4 shadowCoord)
{
#if !defined(MAIN_LIGHT_CALCULATE_SHADOWS)
return 1.0h;
#endif
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
half4 shadowParams = GetMainLightShadowParams();
return SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), shadowCoord, shadowSamplingData, shadowParams, false);
}
Maybe you need to update then to do this, unless you can just bypass it by copying the function but removing the !defined(_MAIN_LIGHT_SHADOWS) || defined(_RECEIVE_SHADOWS_OFF) part. Seems a bit hackish though (probably no more hackish than what I'm doing though ๐
)
Heh, still shadowAttenuation is emoty
Did you do everything I mentioned? Add keywords + set them on the material using the inspector's debug mode?
They work well when defined in hlsl
#define MAIN_LIGHT_CALCULATE_SHADOWS
#define _MAIN_LIGHT_SHADOWS_CASCADE
#define _SHADOWS_SOFT
Oh really? When I defined them in hlsl it wasn't working ๐ฆ
Unless you mean editing the generated code?
No function code
And it makes shadows work too?
Shadow receiving not working
Right yeah, that's what I had too. While I could define it in the custom function, it didn't make receiving shadows work. I assumed it was maybe to do with the order of things being included. (or perhaps the defines don't go outside the scope of that file or something?)
My code
#define MAIN_LIGHT_CALCULATE_SHADOWS
#define _MAIN_LIGHT_SHADOWS_CASCADE
#define _SHADOWS_SOFT
void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
{
#if SHADERGRAPH_PREVIEW
Direction = half3(0.5, 0.5, 0);
Color = 1;
DistanceAtten = 1;
ShadowAtten = 1;
#else
#if SHADOWS_SCREEN
half4 clipPos = TransformWorldToHClip(WorldPos);
half4 shadowCoord = ComputeScreenPos(clipPos);
#else
half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
#endif
Light mainLight = GetMainLight(shadowCoord);
Direction = mainLight.direction;
Color = mainLight.color;
DistanceAtten = mainLight.distanceAttenuation;
#if !defined(MAIN_LIGHT_CALCULATE_SHADOWS) || defined(_RECEIVE_SHADOWS_OFF)
ShadowAtten = 1.0h;
#else
#if SHADOWS_SCREEN
ShadowAtten = SampleScreenSpaceShadowmap(shadowCoord);
#else
/*ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
half shadowStrength = GetMainLightShadowStrength();
ShadowAtten = SampleShadowmap(shadowCoord, TEXTURE2D_ARGS(_MainLightShadowmapTexture,
sampler_MainLightShadowmapTexture),
shadowSamplingData, shadowStrength, false);*/
ShadowAtten = mainLight.shadowAttenuation;
#endif
#endif
#endif
}
I'm just using ShadowAtten = mainLight.shadowAttenuation;
Like the one in the custom lighting article
Oh right, I didn't notice sorry
Yeah I couldn't get it working when defining it in the custom function. Defining them as keywords inside the subgraph worked though, but the default values aren't taken into account, hence the need to set them manually on the debug inspector. (I suppose you could likely also set them from C# using material.EnableKeyword though)
see the two images I posted in messages earlier
Ok I try that
(You can right click the inspector tab to switch it into debug mode btw, since I may not have made that clear. I'm setting those keywords on the Material in that second image above).
Will be afk, so hopefully it works.
see above message ๐
@regal stag yeah, but I can NOT find that
@regal stag found it ๐
@regal stag wonder if there a way to prevent self shadowing
@regal stag MAYBE i should report a bug about that _MAIN_LIGHT_SHADOWS usage
Because it think there are some more check on _MAIN_LIGHT_SHADOWS on the way
Altought _MAIN_LIGHT_SHADOWS should really come from URP definitions
Has anyone used Substance B2M with HDRP so far? It doesn't seem to generate all the textures and material always defaults to Standard instead of HDRP/Lit.
either repack the textures yourself or make a shader graph that accepts the textures in way you need them to
hey! Anyone know their way around the LWRP and post-processing shaders?
I'm using Graphics.Blit but having some issues with my shader in LWRP.
@lunar depot Where/when are you doing the Blit? What event are you hooking into?
lemme check
doing it in OnRenderImage
void OnRenderImage(RenderTexture src, RenderTexture dst) {
if (enabled && fadeMaterial != null)
Graphics.Blit(src, dst, fadeMaterial);
}```
And this is the relevant part in the shader
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST));
col *= (1 - _Fade);
col += _Color * _Fade;
return col;
}```
That method is never called in LWRP
Are you sure? I fiddle with the shader some and got it to do the fade, but with fucked up coordinates.
which led me to believe it was a shader issue - but I might be misremembering. It's been a week
It isn't supported in URP at least, maybe some older versions of LWRP still have some support.
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@7.1/manual/universalrp-builtin-feature-comparison.html
fair enough. That seems definite.
Any idea how to do something similar with the URP/LWRP then?
RenderPipeline.EndFrameRendering?
I think the recommended way is to create your own "renderer feature"
The URP/LWRP scriptable object asset should have a reference to a "forward renderer" asset (slightly different setup in URP and LWRP). This asset has a list of "renderer features" it can optionally have. A built-in one you can choose is the "Render Objects" feature, but that isn't usable for this.
Do you have any documentation on that handy somewhere? Doing custom renderer stuff like that is totally new stuff for me.
also , urp/lwrp are the same thing at this point, right? the lwrp got changed to the urp?
Yeah, but older Unity versions will only be able to use LWRP and not URP.
Ah, okay. That's pre 2019 basically?
Somewhere around there, yeah
Here's a premium Unity tutorial which you can get for free because of COVID-19
https://learn.unity.com/tutorial/custom-render-passes-with-urp
ah. Convenient ๐
There's also a blit pass example here, from the same tutorial I think. https://github.com/Unity-Technologies/UniversalRenderingExamples/tree/cf22099e49c5578230505630c1c91e7c8ea2c884/Assets/Scripts/Runtime/RenderPasses
Might need some tweaking if you want to use it in LWRP instead of URP though
I'm seeing that this tutorial doesn't go into creating your own feature, just using the Render Objects feature, which you won't be able to use for a post processing effect.
The Unity course, I mean
Still, might be a good introduction on how the renderer feature setup works before you make one yourself
well, I think URP only would be fine at this point.
and yeah, probably helpful to learn more about the thing before I try and plug anything into it
Thanks both of you! That should be enough to get me started!
Everything about Shader Graph is frustrating and turns out like crap on medium quality - fallowing Unity own tutorials ๐ฆ
That's just low shadow settings
You can up the shadow resolution / adjust cascades on the pipeline asset
Maybe you've confused it with HDRP?
No I haven't confused
It's designed for mobile, where realtime shadows are rare.
Haven't realtime shadows always looked like this anyway? (like in the built-in pipeline too)
Shadow acne is always an issue with realtime shadows and good resolution at larges scales is only solved by using cascades which can easily multiply the cost of rendering the shadow map.
We weren't saying it was a texture. You can probably adjust the shadow depth bias & normal bias in the pipeline settings asset to reduce it.
On left they own simple lit shader. Looks as should
So its not settings issue
Its My graph issue, or overall shader graph issue, or tutorial issue ๐
Yeah but that cube might not have the issue because it's not in the same place/rotation
Maybe precision ?
@amber saffron if you create a URP Shader Graph that casts and receives shadows & donesn't look like crap on default Medium quality, you are my hero!
You can also force the precision (half vs float) by node. It might be enough
Well unlit graphs right now have a known limitation on receiving shadows. You have to copy the attenuation functions out of the shadows file in URP because of keyword guarding and vertex requirements that the graph doesnโt yet account for
I've been trying to dodge those limitations by setting up appropriate keywords in shadergraph. ๐
@amber saffron your advice is to abstract
There's a cog on nodes to switch between float and half precision. I'm not sure if it will help or not though. You'd also probably need to change the custom function code to use float instead of half.
So like, MainLight_float, out float ShadowAtten. But even then, the shadow attenuation calculated from ShaderLibrary/Shadows.hlsl looks like it uses half precision.
Changed everything to float, same
There is even banding in the screenshot of your graph.
I guess it's coming from the dot product node.
@amber saffron Banding?
This appears related
https://forum.unity.com/threads/why-is-shadow-acne-much-worse-on-default-lwrp-shaders-and-amplify-shaders.686122/
Yes, "bands" are visible here :
Hmm, and why?
I'm not sure that's related to this issue though. And it doesn't look as bad as that in my graph, it might be that discord has compressed the image or something.
trsh's screenshot doesn't look like banding to me. It's not a gradient, it's a repeating pattern.
Also for the cube the normals would be flat, so wouldn't produce any banding like that.
The preview looks smooth an clean
Those bands are produced by Discord
Non on my screen
The preview is Perfect
I assumed that was the case
Buuuuuuuuuuuuuut
๐
I guess it's the normal's foult
Because it built in Shaders they are calculated more complex
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
output.normal = NormalizeNormalPerVertex(normalInput.normalWS);
I deleted Libraries folder
Restarted Unity and now it looks good
Oh no, its not receiving shadows
Thats why
Cool suddenly that is gone again ๐
@plush bane look at the include file for custom lighting from this demo project: https://github.com/natalieburke/ShaderGraphDemo_ComicShader/blob/master/Assets/Include/CustomLighting.hlsl
it has examples of the code needed for unlit shaders to receive cast shadows
i also recommend just giving that demo project a look through anyway, there's good examples of custom lighting in shader graph that we made
@stone sandal this kind of works
tnx
Btw _SHADOWS_SOFT produced the Ugly bands
@stone sandal wonder if there is any trick to prevent self shadowing
you would have to modify the nDotL calculation, I'm pretty sure that's where the self shadowing is coming from
Not really
I'm looking to put a shader on an invisible sphere, and have that sphere overlap my players head. The shader should cull anything inside of it, meaning it will cull the players head. I know there are other methods to do this without a shader, but they don't work for my use case. Is this possible with a shader and if so can anyone point me in the right direction?
filterable shadow representations (ESMs, VSMs, etc.) don't generally have issues with shadow acne
unfortunately, we can't really implement any of that for built-in shaders
@hard wasp in the general case, hard no via the method you describe. The sphere has no control over whether or not other draw calls will write to the render target. You can implement a sphere distance test in the respective other shader(s) to do about the same thing
but that is a very different approach and also has some tradeoffs
issue is that the head is one mesh a part of the body, otherwise I would just hide the head directly
I was hoping I could hide part of the mesh
To hide a Part of mesh, you need to use another 3D object to mask it
Or somehow make the alpha to those vertices go 0
@hard wasp could just set it to an unlit transparent material ๐คทโโ๏ธ
I can't unfortunately, the head is not a separate mesh. If I do that it will hide the whole body (I use full body awareness not a separate set of animations)
Then you gotta mask it with another object.
Easiest way
Or normal based clipping (too much conditionals maybe)
SDF clip on the player mesh will do what you want
specify a local-space position and get the distance in the vertex shader if you have an interpolator to spare
I found this article, which works. But only when the camera is outside of the object the shader is on, is there any way to do this but with it masking even if the camera is inside the sphere?
I was also talking about this type of mask. You will have to use another object with mesh to hide the target object.
And the behaviour you are seeing is due to back face culling.
Is there any thread way to get "Vertex ID" in ShaderGraph?
what are you going to hide with the depth mask? I'm pretty sure this is intended to make the head disappear in a first-person context, that's the edgiest edge case for that technique
past a certain point, just consider doing it correctly if you have to spend more time on hacks anyway
Is there any thread way to get "Vertex ID" in ShaderGraph?
@dapper plover Well, I wanted to that too once, and someone said I could use uv channels to sort of do that, but I never tried it
what are these lines?
this is a wall made of separate cubes, with no texture and a solid color
same thing happens on the player
might be your geometry or texture then
i mean, it could be a million things unfortunately
if you create a new scene and a cube in it, i assume you will not see this artifact
It's from the realtime shadows
@umbral tulip
You can adjust the shadow bias on the light to affect this, but it's not possible to completely remove it
hello, why is my materials turning white when i change them colors via script?
Is there a version of ShaderGraph available for 2018.3 and if so where do I find it?
hello, why is my materials turning white when i change them colors via script?
@cunning geyser the colour that you are trying to use might be white, I think colours such as (5.0f,10.0f,23.0f) are white because it's not from 0-255 but 0.0-1.0, but I haven't used this feature in a while, I may not be right (amรบgy szia :D)
szia ๐
hey um i dont know if im doing something wrong, but i set my directional light to intensity 2, and if i start the game it resets to zero. also in the editor. Any help?
well, deleting it and readding fixed it. very wierd
Hi all!
I am working on a Scope shader, that allows me to zoom, add a crosshair, and a vignette.
But I'm locked down on the Magnification part. The shader zoom well, but pixelates everything behind him, any way to increase the resolution behind the shader?
Well, I assume you're using GrabPass or the Scene Color node if you're using Shader Graph, which gets the texture of the scene. The resolution of that texture is the size of your game window. You can't increase that.
So you'll have to render a separate camera for the scope, which has a lower field of view, making it more zoomed in.
! @proper raptor I've been working on exactly that
i'm using Std surface shaders.
So you're using GrabPass then?
I tried using the opaque texture or grabpass, but it's indeed blurry when zooming
Now I use secondary camera rendering to a texture
and it adjusts the FOV
Yes GrabPass!
Yeah I've think about using a second camera, but I can't get the effect that I want (Parallax correction) as IRL.
this is with secondary camera
is parallax correction when you don't look right at he scope?
Yep! "sight" stay on target!
Why can't you do that with secondary camera?
You can change the render texture however you want in shader
for example in the video I change the UVs to get the 'lens' effect, as well as some chromatic aberration
you should be able to do parallax stuff as well
Let me make a quick draw.
The camera will render what's in front of it. But IRL it's showing what's in front of your eyes.
Okay
maybe you can offset the camera's transform then based on viewing angle?
you think that would work?
Hmm, that can work yeah! So no more shader needed? Just coding?
Uh yeah that could work I think, but honestly I'm not 100% sure, never tried this ๐
But I do think it would, shifting the position of that secondary camera based on the viewing angle
Let me try! ๐
And cool that you have a scope lying around! Nice reference
Haha, some old Aimpoint one!
ah really cool!!
@proper raptor so this is by offsetting the camera?
No I've just cheat a bit with a second vignette haha plus a little correction to the Sight shader!
Yep secondary cam, but I'm working to have that parallax correction on the second camera too!
Is there a way to have 3d models using unlit shader materials to have ambient occlusion on lwrp?
I'm experimenting with shader graphs, and now I arrived into situation when shader works as I want it to work in Scene screen, but renders black in Game screen. It's a kind of a lowpoly shader, so I have this Position -> ddx/ddy -> cross -> normalize subgraph. The rest of pipeline needs WorldNormal, and if I just use Normal Vector (world) everything is good in Scene and Game views. But if I replace Normal Vector with that low poly subgraph it doesn't. I tried everything I could find, transforming object->world (direction) and what not. Any ideas where to look?
The rest of pipeline is a bit customized basic shaders from https://blogs.unity3d.com/2019/07/31/custom-lighting-in-shader-graph-expanding-your-graphs-in-2019/
Okay, if I swap the order of cross product, then it shows correctly in Game view, but show as black in Scene view. ๐ค What could it be?
If I enable Opaque Texture, or HDR, or MSAA, or tick the post processing checkbox in camera properties โย it starts to work as expectedโฆ I probably don't understand some important part of how shaders work. Does these properties enable something that in turn enable ddx/ddy to work?
is there a way to read the amount of light an object gets?
@woven plover You mean how much of it is in shadow?
more like the intensity it gets at a point
You mean you have more than one light?
The lighting is computed on the GPU. It's separate from the CPU, where your scripts run, so you don't have access to it directly.
i have a point light and a sphere that rotates around the camera. i want to notice in my script if the sphere is blocking the light to the camera
Could you just raycast from the camera to the point light's position?
hm yeah i guess raycast will do for now
the sphere has a 2nd, slightly bigger transparent sphere (its a planet with an atmosphere) so i guess ill try to measure how far the raycast passes throught the transparent sphere and reduce the light intensity according to that
I'm trying to make a wall semi transparent when my player is behind it, but I get that ugly result. Any idea why ? I'm using the Standard shader.
the normal wall is on the left, while the transparent one is on the right
@regal stag so i saw this on your twitter. was wondering, what do you have to do to the rest of the scene for it to work?
like, i guess in this example, what do i do with the water
oh wait, i should set the "water" to transparent - 1
im using it for digging holes in sand
only problem now is, shadows of the hole mesh get rendered above the ground
@lavish stream I don't think I had to do anything special to the scene.. can't really remember though. While I used the URP forward renderer a shader like the following would also work. Shader "Unlit/DepthMaskShader" { SubShader { Tags {"Queue" = "Transparent-1" } Pass { ZWrite On ColorMask 0 } } } (sorry about formatting)
I guess if you want to mask sand it might need to be on Geometry-1, assuming this technique will still work on opaque geometry, maybe not? (That way shadows shouldn't be visible through the ground too). Might also be able to look at stencil shaders to produce holes, I think theres some examples on the docs page.
In case that's not clear, I mean the mask would be on Geometry-1 as it needs to be rendered before the sand.. but maybe the hole mesh would also need to be rendered before the mask? (Think you can override the queue on the material). If it doesn't work you might want to look at stencils instead though.
hi, i dont know if thats the right channel to ask, i have a window blinds texture, which has transparent parts in it. i wanna make it so, that light can passes through it. how can i achieve that?
i use baked lighting
do i need to do something with the light maps or is it a shader thing?
@swift totem I think you're looking for alpha cutoff. Not sure how to do to it in coded shaders, but in shader graph it's on the big node.
@solid ravine you can't really use normal transparency for that sort of effect. What you've got to do is use Alpha Clip and dithering for the transparency
transparent things don't write to the depth buffer and so sorting is busted. ^That is the common solution
you can set custom lightmap parameter, where you can say "is transparent"
that worked for my case
@vocal narwhal thank you, I'll dig into that solution !
Howdy! I am using shader graph with Universal Renderer. I am trying to fetch the main light shadow information from an unlit shader graph, so that I can implement my own lighting, but having some issues as discussed here..:
https://forum.unity.com/threads/shadow-and-distance-attenuation-do-not-work-in-urp-unlit-graph.803025/#post-5615980
Hoping for any assistance!
I use this in my project
using 7.2.1
shadow is being cast by the object in top left corner
Alternatively, this tweet thread goes through a method I used (using URP 7.2.1, I don't think it works in 7.1.7 so you may have to update if possible) https://twitter.com/Cyanilux/status/1240636241252679681
Apparently you can also just use the PBR Master node, but set the Albedo to Black, Smoothness & Occlusion to 0 and use the Emission input for your graph color/lighting output. To me that sounds like it needs to do the lighting calculations twice though, although I've heard someone mention the complier strips the PBR one out, can't confirm that though.
@devout quarry Do your shadows look good at a distance using that? I think I've used something similar and I had some glitchy looking shadows past a certain distance (something to do with shadow distance & shadow cascades I think. Might be because of something in the ShaderLibrary/Shadows.hlsl that needs _MAIN_LIGHT_SHADOW_CASCADE?)
yeah after a certain distance the shadow is removed
while for other shadows on 'normal' objects, they go to a lower resolution at that distance
For me it wasn't just removing the shadows though, I had other shadows appearing like it was sampling the shadowmap incorrectly.
has to do with shadow cascaeds indeed
ah, I don't have that I think
this is with 'no cascades'
I'll try your approach also! Haven't tried it
It's a little annoying as the default value in the blackboard isn't used for non-exposed keywords, so you have to set the keywords manually on the material with the debug inspector (or C# material.SetKeyword). I think I prefer using the keywords and Shadows.hlsl functions over having the custom function to sample the shadowmap though.
thanks @regal stag i am trying it out now, it seems annoyingly janky, the way we need to enable keywords manually ๐ฆ
I am getting thispipeline ready for our artists, who is fully capable of working with shader graphs, but needs to be given the tools to do more advanced stuff like this
Ill just implement the custom function to give him access to light data and he can do the rest. But this additional step is an annoying step in his workflow, since normally he doesnt have to deal with keywords directly like this
They should just provide us a 'main light' node ๐
Yes agreed
I couldn't get it to work
I added the keywords manually, in debug material view
but the frame debugger still says my things are being rendered without the keywords, bleh
Need to also have the keywords added to the main light subgraph, and I'm using the custom function from the link in that first tweet.
ah yes thanks my dude, it works now
I mistakenly 'corrected' MAIN_LIGHT_CALCULATE_SHADOWS to _MAIN_LIGHT_CALCULATE_SHADOWS
hello, how do i get my red stained glass ball to look red when the ball is between camera and light?
right now its only showing red when light and camera look from the same direction
i figured i will likely have to flip the normal of the glass, so it will be lit when light falls through it instead of on it
hm nope that is not the effect i wanted.
i need to have a texture that is rendered when its illuminated from the back.
Use dot product between surface normal and light direction
Hey a noob question; I'm using HDRP and shadergraph and..... there really isn't global variables? To change a value in all objects do I have to keep track and update each separately? or is there an easier way?
There is @lost prairie
in shader graph you need to add variables.
It's all via shader graph window
@rapid acorn really? how? I couldn't find it ๐ฆ
That's it
you have made a variable of type Vector2
That Exposed check makes it visible outside in the inspector
@rapid acorn I'm asking about global variables, shared by all materials using same shader
changed by Shader.SetFloat instead of Material.SetFloat
thanks anyway ๐
I mean
Does it not work? Setting a variable by script
SetGlobalFloat
and then sampling it like you are doing shader graph _VerticalScanRange
I'm not sure if it's HDRP or shadergraph (or I'm doing something wrong) but I'm not getting SetGlobalFloat in my project. I think it's hdrp?
you need to disable 'exposed' as well btw
And does disabling the 'exposed' toggle do anything?
oh wait what it's working now >< I have no idea what I was doing wrong but it's there now
I was so sure I checked this dozen of times
I don't think it's about the exposed, I haven't changed that. but I guess I was doing something else wrong all the time somehow
hmm maybe it's overwriting global? I'll test that as well, thanks a lot @devout quarry and again @rapid acorn ๐โโ๏ธ
@devout quarry yep, just checked it. exposed overwrites so had to disable that. but my main problem was I wasn't even getting the method in intellisense probably because I was doing some silly syntactic mistake.
I often have my IDE acting up and not showing me certain methods
Hey! I need help making a stylized hair shader in the universal render pipeline. I want to use the tangents of an object's uv map to determine the direction of an anisotropic shader. If anyone knows how to do this and would be willing to tell me or point me to a tutorial I'd be extremely grateful (I'm still trying to figure out how to get anisotropy to work in unity so any information is helpful).
@mossy kestrel In general transparent shader do not recive or cast shadows, the shadow casting reqires wrinting to the depth buffer what transparent shaders do not do.
for a leef shader you can use a Opouqe shader with coutout to cut away any parts of the mesh you do not like to have drawn.
I'm trying to do something that is probably relatively common, but I'm puzzled on how to do it or what to search for. Basically I want to assign a texture to an object. The texture should ** not be visible in game view**. I want to use the texture to store 'information' that can be sampled by a shader for visual effects.
If you have an answer, feel free to tag me
@devout quarry Well, if you add a texture property to your shader, then you can sample the texture and use that color for anything in the shader.
It sounds like a pretty simple question. Isn't this just what normal maps are? Textures that store directional data and used in lighting calculation.
That sounds very logical indeed haha
Although the exact thing I wanted to do was a bit different
You know how there is a camera opaque texture right
I have a post processing effect that samples that texture for some visual effect (outline). What I want to do now is instead of using the camera opaque texture, I want to use that secondary texture that I assigned to the object
So like an extra 'pass' where the shader looks at the scene, but only sees these secondary textures on all of the objects that have them, and samples it and uses it for some effect
If it's a post processing step, then you need to have a separate render texture which you draw this secondary pass into. How you do this pass is up to you. You could add a second pass into the shader (which rules out Shader Graph) that has a certain LightMode tag and make a custom render pass that draws just that light mode, which is how the depth pre-pass is done.
That's making the assumption you're using URP
@devout quarry I'm guessing you are using URP, then?
Yes! So for example the camera color texture or camera opaque texture (forgot the name), in the frame debugger you can see it. Basically what I think I want is that a custom texture shows up there in that list, and it shows all of the objects in the scene as black, except the ones that have a special secondary map applied to them with a specific name. And then I can sample this texture in my shader just as I sample the camera opaque texture
So instead of using the camera color texture as 'data' for my post process effect, I can choose per object what the 'data' is by assigning an additional texture
So, there's always a target render texture which objects are currently being drawn to. Sometimes it's null, which means it gets drawn directly to screen, sometimes it's a render texture you've created in Unity and assigned in the camera, sometimes it's a temporary render texture you create and assign in code during rendering. The way URP does the color texture is it draws everything into this _CameraColorTexture you see in the frame debugger, then after rendering the opaques and skybox, it copies this texture to _CameraOpaqueTexture, which is what you end up accessing in the shader.
So you need to create your own temporary render texture, set it as the target at some point before the post processing step, then draw the objects that have this secondary map.
Then you can set _CameraColorTexture back as the target and you can read your temporary render texture after that.
If this secondary map doesn't require full color, you could make use of the alpha channel, which is of course unused in the opaque part.
Then you don't have to worry about any secondary render texture or passes, just draw the object as normal while also setting the alpha as whatever you want. It doesn't matter what it's set to for opaque objects.
In fact, Beat Saber uses the alpha channel to determine glow, so an alpha of 1 means full glow and 0 means no glow.
Hi
I don't know much about shaders , but Can we just convert the new principled ultimate shader from blender to unity if it's written in hlsl
?
oh its a node
Its compatible with unreal engine why not unity ?
unity new hdrp lit shader isnot designed for every materials ain't it?
Unty lit shader doesn't support IOR index of refraction
no idea, but blender's shader setup is really nice
im wanting to increase the black levels/decrease contrast of a night sky image to simulate light pollution. Is that possible with shaders, or would it have to be done programmatically?
Trying to make a blood shader like in overgrowth but I'm confused on how to start. If you've never played overgrowth or don't know what I'm talking about, here's a diagram.
Lets say this guy got shot. The red dot appeared and from that red dot came smaller red dots that slowly made it's way down a random distance while making a trail behind them.
I'm not entirely sure how to tackle this. How would I map this blood onto the object? I can't really use the models uv coordinates so I need something else.
This might seem like a very stupid question, are all values in the input struct received by fragment shader always interpolated from the 3 vertices' outputs?
where can i find a list of shader keywords? it really hard writing a shader if you dont know what you can include/use
keywords may be the wrong name. im talking things like uv_MainTex, uv_BumpMap and worldRefl
i found this: https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html, but it doenst seem to have all of them
Hi, I'm trying to find and create Lightweight RP here, but there's none in the list.
They said Create > Rendering > Lightweight pipeline asset
But I cant find the rendering in the project area
already installed but cannot create ๐ฆ
there's an error in your console that looks important
What is it ya?
Ok solved, took me an hour. So basically I searched through the net, it was Lightweight RP. I searched through discord, it was renamed > Universal RP.
I installed, and it was conflicted. Then had to delete both and reinstall, then it fixed
@harsh marsh try using decals or a projector for projecting the effect on the mesh. for the effect's texture you need to make a compute shader I think that updates the blood every frame until its done flowing
@low lichen thank you for the explanation! I'll try to get to work
Is appdata.vertex.w used for anything?
Position data only contains xyz right, so is it fine to use w for something else like vertex alpha?
Is it possible to do a layered rendering with URP? like have 2 camera, one that renders the X objects with Y processing effects, and another camera that only render the background?
Hey, Shader Graph question. I'm trying to use a voronoi, generated in the graph, as texture for a triplanar node. But triplanar only takes a texture input. How can I use something generated in the graph as texture?
@signal rapids You can't. You either have to use a (preferably seamless/tileable) Voronoi texture, or rebuild the Triplanar node functionality - I have a blog post which does this, see 'Multi-texture Triplanar' heading (It's only for the albedo/color triplanar, not normals though) : https://cyangamedev.wordpress.com/2020/01/28/worldspace-uvs-triplanar-mapping/
You will want to replace the Sample Texture 2D nodes with the Voronoi node. (You'll have to test both to see which is more performant, I'd probably go for textures unless the Voronoi angle needs to rotate).
Alright thanks, I'll check this out! @regal stag
For the texture option, you can also make a shader that outputs the desired texture and bake it into a texture using something like this : https://www.ronja-tutorials.com/2018/10/13/baking_shaders.html
But the output likely won't tile perfectly
It has to animate, so I think I'll try your triplanar rebuild with voronoi as texture!
hello, does anyone know if there's overhead of creating a subgraph versus creating a custom node in shader graph?
Thanks for all the help, got it done now.
Is
appdata.vertex.wused for anything?
@remote mauve Yes, it is used for the perceptive divide. I think.
This might seem like a very stupid question, are all values in the input struct received by fragment shader always interpolated from the 3 vertices' outputs?
@remote mauve
Not a stupid question at all. "Always" is a strong word. Usually, yes. There are keywords that can tell the shader compiler not to interpolate certain values though (google "flat" keyword). However it might be platform dependent so use caution.
Thanks, that answers both.
I need some values in fragment shader that belong to the quad, I ended up having those same values in all vertices so interpolation won't change.
Not uncommon. However if you can use "flat" it will save interpolators. I think there's data-size issues too with efficiency, so YMMV. I read/heard somewhere to try to keep your total amount of vert->frag data to size of 4 x float4 for efficiency. But that might be mostly a mobile issue.
packing the data into float4's is pretty common to keep it all "tight".
Hmm, I'm targeting mobile platform ๐
My current v2f struct:
struct v2f {
float4 pos : SV_POSITION;
float4 color : COLOR0;
float4 data0 : TEXCOORD0; // u v
float4 data1 : TEXCOORD1; // q b1
float4 data2 : TEXCOORD2; // b2 b3
};
IDK....that SV_Position is it's own thing. So maybe not too bad! IDK about color0, but meh. Some hardware guru will have to comment further.
How's it performing?
If you can pack uv into an xy of data0 and q and b1 into zw of data0 and eliminate data1, I suppose that's more efficient.
All of those are float2 being packed into float4 so yeah, those are tight already.
cool. That's the best you can do.
Yeah
I actually only use the alpha of color, hence why I asked about position.w earlier.
I thought if it wasn't used I can pack alpha into there instead of having another float4.
Your comments are confusing me, but your posts make sense.
e.g. UV is a float2 so that would go into data0.xy, so what's data0.zw?
u and v have a minimum and a maximum
ok, cool. ๐
Since I'm using only the alpha of color, should I change color from float4 to just a float?
I'm under the impression that internally it still uses a float4.
I think it's more efficient to float4 align the memory...so yeah it might pad it to be a float4. Memory access might just be that wide.
Again, probably hardware dependent to some degree.
Okay, I guess not much else I can do.
Initially I wanted to just cheap out and divide quads more to solve this, instead of learning shader stuffs
It was a pretty fun ride now that it's done, no regrets.
@remote mauve you do not need to have all 4 elements of a texcoord used and there are some perf advantages to doing that. In your case, you can get away with just alpha in a float
interpolation doesn't really follow the same rules as traditional loads since they're very often all done with the whole wave and with scalar math anyway
you can also pack attributes together but most reasonable (i.e. not mobile GPU) shader compilers can transform your code for you if you just use the appropriate-width vectors
meaning that if you need 2 floats, use a float2, etc.
using Vulkan backends is a good idea since you can use Khronos shader tools
Hmm okay, I guess I'll change it to just a float then.
really the only advice I can give is if you don't need a value, don't put it in the struct and your friendly neighborhood shader compiler can handle the rest
Gotcha ๐
I can provide more technical explanation if you'd like-- there's a little bit of background knowledge required about how GPUs spend most of their time doing math but it can make some of this less arbitrary
not essential tho
how can i access the alpha channel of texture in shader?
.a or .w component ^
thanks
I think it can only define one value for each unique tag
Okay! thanks
@remote mauve it used to be that graphics cards had specific hardware for doing this kind of thing that worked in width-4 vectors natively. Since the number of interpolants was also guaranteed by the API there was generally no reason to care about interpolator layout so it didn't really get thought about
And Shader Graph can't do multi-pass shaders right?
Does anybody know if Amplify can do that?
in URP
Well, not user defined ones. It makes the shadow/depth pass and some more built in ones.
I think you can with Amplify.
Okay! thanks for the help
@remote mauve so over the years GPU designers moved over from thinking 'one vector per pixel' to 'one scalar per pixel' and abusing something like SSE/NEON to do a lot of math in not a lot of time. If you've ever heard of waves/warps/wavefronts, that's referencing how these things are grouped together in hardware
there are a few conventions to how that works out for drawing, etc. but loosely you can think of it like the hardware processing the first pixel in the first lane /x component of a really wide vector-- like 32 units, the second pixel in the second lane/y component, etc.
also genesis of why branching (like doing completely different sets of instructions) is not great for shaders
you will do both paths all the time since the card may very well need to have both results in one lane or the other
VS -> PS is usually done by splatting one value across all lanes with dedicated instruction and then using funny mask generation with regular add/multiply instructions to get a unique value per lane/output pixel
the one value being one float/uint/whatever in the VS output
so anyways, that's my TED talk.
and im here like how do i get a vertex lit alpha shader
I've been at this for a while ๐
Vector stuff was actually valid advice, just not for current GPUs. The last one I know of in desktop space was AMD Evergreen
that was like 2010? 2009
looks like Northern Islands was too
since we're also on a lore spree, you can also have a few extra inputs to your fragment shader like MSAA coverage (SV_COVERAGE) that aren't vertex shader stuff per se
neat, but advanced usage
MSAA-aware hashed alpha test, etc.
๐ค
I think I'll leave fancy stuffs to last, for now it's just drawing quads for a simple 2D game on mobile, that isn't focused on visual.
unfortunately I don't think there's too much cool hardware stuffโข for 2D in recent memory
granted I am mostly a 3D dude so I haven't followed as closely
@low lichen Sorry for tagging you so much but I think I'm getting there!
This selected cube has just 1 pass at the moment, but it is a special pass
And I have this rendering in frame debugger
This is outputted to a render texture which I can sample!
And now I can do outlines based on that map! Thank you x1000, your explanation help me a lot
are you trying to generate outlines based on the texture content?
You don't need a separate pass for that
(FWIW)
I want to be able to give objects secondary maps that define where the outlines should be rendered
These maps should not be drawn in game view
So I don't want the outline based on depth/normals/color of the game view
but you can absolutely just pop that in the shader for the object
or at least, the special object
the cube, in this instance
you have less control in screen space honestly
well not anymore
In my head the nice thing is that now I can combine the 'ease' of using a screen space effect together with the artistic freedom of choosing exactly where outlines should be using the secondary map
short version-- make a translucent/alpha shader for the cube, do a ddx/ddy on texcoord and use for your sampling offsets in Sobel/whatever
run same sobel shader like normal
no need for the extra write
how would you get object outlines
could do depth mask, but that's what I was asking about re: texture content
N dot V stuff can work tho
Just a second I'll show exactly what my goal is
the outline would always be on the 'inside' of the object which can get a little interesting with edge-on stuff
you're also most of the way there to stuff like suggestive contours and more industrial-strength NPR techniques
To start with, I have this 'DNC' outline effect with outlines being generated based on a DepthNormalsTexture and a ColorTexture
This is just the debug view, but you get the idea
yep, standard postprocess outline shader stuff
well define 'artistic control' here
if you have regions that you know will always need a line, consider just putting that in the texture
or mesh
I want to be able to draw an outline wherever I want. I thought about drawing outlines in the albedo texture or something, but then the line is 'fixed'
Once I draw the line, it's drawn
IRL line artists will do this, FWIW
sure I can go back in the texture editor and change it, but I want to be able to change things like the width in Unity
thin/thicken lines according to perspective
So the idea was to generate a secondary map for objects where I want user-defined outlines
Forexample a texture like this
you are going to have some issues with texture filtering here, I think
And then pass that texture to the outline effect, which is looking for colour discontinuities
hm. Texture-only stuff is very very doable in-shader with the method I describe and is likely slightly faster since you don't need to read/write a separate RT first
most of the Sobel stuff should be pretty well-cached since your offsets in texture space are still pretty small
outlines can be done with the inflated hull method, but that can also be done as a separate pass in the same shader
will mention that Arc System Works of Guilty Gear/DBF fame were happy with this + hand-painted lines
no perspective funny business required
Basically what I want, workflow-wise, is to be able to exactly define where outlines will go AND change the visual of the outline inside of Unity
So hand-painting outlines is not a fit method for me
SDF texture?
Yeah sure, how the texture is generated does not matter
Using SDFs was actually a plan of mine
you can get constant screen-space width with the ddx/ddy tricks and knowing the output render target dimensions
no separate pass required (but theoretically sound)
meaning it will do what you want, but is a bit clunkier imo
you're basically asking 'am I less than <user parameter line width> pixels from the nearest edge'
in screen space
if yes, emit the line color, if no, do the "normal shader"
how can i inspect the legacy shaders code? im really struggling to get my around shaders.
its not the concept, but where do i get all the needed information for lighting and stuff
in the sense that you want some explanations for why lighting code looks the way it does?
i can apply a texture, that seems easy enough. but how do i get the lights in my scene to light it
yes
rather, are you looking for information about "what sort of constant data do I have" or "what is a BRDF and what's the deal with all these dot products"
i have light textures on my models with custom shader, i need to add emissive textures, didnt know how, so i added regular texture and multiplied its color 2.5 times.
Its bright, looks alright, unless you enter dark area.
So.. how do i add unlit texture?
or emissive
@swift totem https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html if it's the first one
cuz the 2.5 color intensity on shaded texture was dark, in darkness, i increased the multiplier to 5x, but now the texture looks bad and not like the original texture
@gleaming moss thank you very much for your help! i dont even know what brdf is, soooo... im a total beginner; i know how to code, thats it.
@swift totem BRDF is Bidirectional Reflectance Distribution Function, or "given the light is coming from this direction and the surface is pointing mostly in this direction, how much light is bounced in this third direction I am interested in?" It's the physics/math behind rendering
how did you get started, if i may ask so bluntly?
smashing my face into graduate level research with no background (please don't do what I did)
this series at GDC is decent but assumes some physics background
http://www.pbr-book.org/ is also a very long read but decent
own a physical copy of 2e
you are doing gods work! thank you
http://www.pbr-book.org/3ed-2018/Reflection_Models.html might be of interest
the book is built around path tracers so a lot of it won't be super relevant to getting things in Unity quickly
you should see a lot of familiar words from Unity or other graphics stuff ๐
in shading
https://hatebin.com/wdvlhiqhvi anyone knows how to turn Emission to emission texture or atleast unlit?
you want to write the emission texture to the Emission field of the output, not Albedo
o.Albedo = lightTex.xyz+(emissionTex.xyz*emissionTex.w); should be something like
o.Emission = emissionTex.xyz*emissionTex.w;```
oke, ima try, thanks
albedo is a reflection value so anything you put there is subject to light angles, etc. which is not what you want if the surface itself is supposed to be emitting light
Tutorial to set up the shader for Red Dot.
Sights & Scopes Shader available on the Unity Asset Store! https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/sight-scope-shader-163386
Unity Asset Store: https://www.assetstore.unity3d.com/en/#!/search/page...
Tutorial to set up the shader for Scopes.
Sights & Scopes Shader available on the Unity Asset Store! https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/sight-scope-shader-163386
Unity Asset Store: https://www.assetstore.unity3d.com/en/#!/search/page=...
wouldnt the scope picture be fixed in the center and not move around with your camera perspective, so its more parallex(if thats the right word)? otherwise it looks really nice
because im comparing it to escape from tarkov (also made in unity) and there it looks a bit different
I'm not trying to hit the BSG level haha.
๐ ๐
i would like to know whats the difference between theirs and your implemntation? do you know?
and on that topic, does anybody know if there is a source to the shadow technique used in s.t.a.l.k.e.r? if one of you played it, u know what i mean. these shadows are still one of the best shadows ive seen in a videogame. thunderstorms generate sharp shadows while other lights still project their shadows with relative brightness/darkness and its all dynamic.
Does anyone know how to make a hair highlight shader in the URP?
Or any anisotropic shader for that matter?
are you using shader graph, working in a particular style, etc.
hello, does anyone know if there's an option on the shader graph to automatically rename the gpu references of properties to property names? I often forget to rename them and then when i try to set a value to a property on a shader via code it doesn't set it and i end up debugging for quite some time.
Don't think so
You mean like if the property name was 'Top Color'
the reference should be like '_TopColor'?
no, just "Top Color"
Yeah no that does not exist afaik
welp
Because then what would they rename it to?
using 'Top Color' as a reference name is not something I would want
and I imagine a lot of users have a lot of preferences so difficult to make a 'default'
But I like the idea, maybe you could set a formatting expression that lets you define how it should be named based on the property name
@gleaming moss I'm using shader graph and I'm making a non photorealistic game.
Best bets are custom nodes or engineer handwriting your shader, then. Custom lighting models are impossible by design in Shader Graph.
Is that a matcap or are you tweaking one of the BSDF nodes
would you like to see the nodes?
I suspect it's going to confirm my earlier advice, unfortunately, but I can advise further once I know how your Blender stuff works
Yes but there's nothing on it cuz everything I've been trying haven't been working
So basically No-ish
first place to start would be getting the toon shader going-- there's a few examples going around that use the Unlit node and cheat their way into reading light data
How would one cheat their way into reading light data?
there's a custom code node that can do it for URP
it will give you the direction and some shadowing information
as an aside I think it's hilarious that there's a huge number of Unity users requesting custom lighting, Unity themselves create hacky workarounds for custom lighting, and yet they still won't allow custom master nodes in Shader Graph because "it might break compatibility"

basically
So how do I put this custom function into my shader editor?
should all be in the blog post.
should do your fresnel bit
you might need to use the Tangent input depending on your mesh, and likewise having this be scaled by light value is important unless glowy hair is part of art direction ๐
Wow thanks so much
you can try lerping the tangent/bitangent into the normal to break up the highlight
@gleaming moss Is there a way that I can get the tangent from the uv map?
that's the shift trick I was talking about
you can lerp the normal and tangent or bitangent together with a value you get from a texture
I think it'll make more sense if I show you this:
yep, looks like a UV layout for hair cards
There is none
This is what I get by plugging the tangent of the uv map directly into the material output
you can actually just use the UV value directly to blend too
probably need to read the Blender documentation on the tangent node
what Blender is that
also are you using a normal map texture at all
It's blender 2.82 and no I'm not using a normal map or texture at all on the hair
the basic Unity bit should be right then
if there's no normal map it's probably to help figure out what's the tangent and what's the bitangent (loosely if the hair is growing up or down or side to side in the UV map)
you might want to use the tangent vector, since you might need to use the Tangent input depending on your mesh
(that's what using one vector or the other comes down to)
Using the tangent vector instead of the bitangent vector works
yep, looks like your hair is side-to-side rather than up-to-down
based on the strips
I've never used the bitangent vector node before. What does it do?
think of them as the X, Y, and Z vectors on the surface of the mesh
since that's the tangent, bitangent and normal vector respectively
if you're a visual thinker imagine those little colored bars in mesh viewers
Thanks!
anyone have a shader that makes dashed lines of objects outline?
left ones are orthographic view
@cursive rain Please don't multi-post. Pick one channel
im working on a custom cubemap skybox shader, because i want to be able to add things like a day/night cycle and blacklevel increases due to light pollution. How do i sample the cubemap? do i have to project the sphere's uv coords onto a cube, and if so, how would i do that?
What pipeline are you working in?
@outer whale
I have some for the standard pipeline. IDK how it varies for URP/HDRP.
standard i guess. i went with the default 3d project
Have you seen their standard cubemap skybox shader? And how it samples now?
no. how would i take a look at that?
I'd suggest starting with their standard cubemap shader. You can get all shader source here:
https://unity3d.com/get-unity/download/archive
the drop-down box will have an option for build in shaders. IIRC you're looking for "Skybox/Cubemap".
i have the standard unity license, i thought i didnt get source?
You don't get ENGINE source (particularly the c++ stuff), but they publish their built-in shaders. I don't think that's a licensing issue at all, as long as you're a legit unity user.
am i blind? im not seeing a link to shaders, or even anything about shaders
Windows or Mac?
What unity version?
Go to the version, then go to the windows or mac drop down box, and in the list select "Built in shaders"
oh. thx. derp on my part
got it working now. v.vertex.xyz for the win
im not the best with matrix math, how would i convert this to rotate around different axis?
{
float alpha = degrees * UNITY_PI / 180.0;
float sina, cosa;
sincos(alpha, sina, cosa);
float2x2 m = float2x2(cosa, -sina, sina, cosa);
return float3(mul(m, vertex.xz), vertex.y).xzy;
}```
preferably the X axis
simply changing the mul(m, vertex.xz), vertex.y to mul(m, vertex.yz), vertex.x doesnt change anything
hello, after enabling "log shader compilation" at Graphics settings, where can I find the compilation info?
Hey @regal stag , just wondering with the shadow stuff you posted on your twitter - did you ever get the cascades to work correctly?
Nevermind, Keyword seems to be _MAIN_LIGHT_SHADOWS_CASCADE, not _MAIN_LIGHT_SHADOW_CASCADE. Using this keyword the cascades work correctly
What's your question?
Shouldnt it be blue as a base and when i paint on the red channel come out red?
Had to remove the teamviewer ID ๐
it's a default plane from unity
your vertex color is likely white
or at least red
you can confirm by hooking up a constant into the blend factor
if i import a plane from blender is it black by default then?
offhand I think they'd be white since using vertex color as a tint is a pretty common practice
easiest method there is to set the color in Blender directly
Aah, yeah i had this idea to make foam on water using vertex paint. but since its behaving so wierd i wanted to test it in a controlled scene
perfectly sound idea in theory-- I think your mesh just doesn't have the data you expected. Merits of being explicit ๐
well i tried it to make it black first
and now it works ๐
Except for another little bug but that should be simple to fix
Aah, yeah i had this idea to make foam on water using vertex paint. but since its behaving so wierd i wanted to test it in a controlled scene
@dire jolt I do this, works great
Just need enough vertices and indeed the plane will be white by default
Hello guys ! I'm trying to experiment with SRP batcher on my custom SRP, but I can't create a simple shader that is SRP batcher compatible. I'm using Unity 2019.3.5f1, and it always says that unity_ObjectToWorld was found in another cbuffer than UnityPerDraw, even when it's not.
Here is the simple code that I'm trying to make compatible: https://pastecode.xyz/view/f0a56618
It's a simple Unity Unlit shader basically
I've got a shader question...
How do I make the shader not strech when I apply it?
I want it to be proportional.
How do I add a shader to a procedural generated map
@abstract estuary You need to be more specific on how the map is being generated, the material the map uses is what the shader can be applied to
Im using a spritesheet file that contains all the textures
https://i.imgur.com/uqZ1fUN.png
@steady schooner It's because you're using the UV as source of your noise, and the objects is stretched.
Either add ad tile/offset node to control the tiling of the UV, or use an input that is not dependent of the object scale, like worldPosition.xy
@abstract estuary Applying a shader is just applying a material with the assigned shader in it to your object.
Having no idea of what your generated map looks like and what you want to achieve visually doesn't help us to help you.
Wild guess : you're generating a map with square tiles ? Assign uvs corresponding to the tiles you want in your tilemap, and just use a regular shader on the material with the tilemap assigned in the main texture slot
Im not using a tilemap
This is how the map looks like currently
But it changes everytime I start the game since I use a random seed
Ok, so what's the question here ?
How do I add a shader to the water lol
Oh, so that's a totally different question now !
If you want to have a separate shader for you water, the water part of the terrain need to either be a separated mesh, or a submesh
Is there a way to modify the shader property variables and not have that saved permanently in the material property block?
Suppose I have an exposed variable ABC of range type(float), and I modify it via C# by SetFloat method. The modified value gets saved in the material file.
I don't want to have that saved.
Well, fortunately the answer is in your question : use MaterialPropertyBlock : https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html
Or, if you're accessing the material from code from a renderer, use Renderer.material and not Renderer.sharedMaterial
I am using image.Material, here image is the renderer (UI stuff).
but it ain't working unfortunately. :/
Oh, sad, it doesn't have the same behaviour as renderers.
You can still make by doing a clone of your material before modifying :
image.material = Instantiate(image.material); should work if I'm not wrong
Interesting. Lemme test and report back.
Well Well Well, it seems that's the solution ๐ thanks @amber saffron
I want to combine two render textures together using a shader, and send the result to the screen, how can I achieve something like that?
I have 2 cameras that render to a Render Texture
Do I need another camera to achieve something like that or I can do it without another camera?
Maybe the easiest is to draw a fullscreen quad on a third camera, that uses a shader combining your two textures ?
Thanks forgot I could do something like that lol
In a normal shader I can do this
Set the LightMode tag
Is there any way to do the same for a shader graph shader?
there is no way to edit the lightmode of a shader graph at the moment
Alright then I have an additional question
I'm using this, as it gives me the same result as a 'multipass shader'
the 'second' material here that I use as a second pass is very very basic
I don't think SG supports multiple shader passes
But is it possible to somehow combine a SG shader pass with a non-SG shader pass to make a 2-pass shader
The method in the screenshot works perfectly for me, the 'Test' material is a SG shader and the 'Test Outline' is a shader that was not made with SG, but I'm worried about the performance warning it's giving me
SG does not support custom passes right now. and there's no good way to do the second part that you asked -- the closest you can get is generating the final shader from the master node and modifying the passes there, but you would have to redo it for any change you make to the graph
Alright
And they say 'costs performance', do you know how expensive it really is? The second material is really just this
1 texture sampled and put on the model
The extra cost there is probably setting up the second material, whereas multipass would be the same material so it only has to set it up once
It's still two drawcalls
Makes sense
But, as far as I know, URP/LWRP will only use the first pass
So that warning message doesn't make sense for URP
You mean multipass shaders are not possible in URP?
They are possible, but Unity won't automatically draw the mesh multiple times for each pass in the shader
It will draw the mesh once with the first pass it finds that is valid
Whereas the built-in render pipeline will draw the mesh multiple times for each pass it finds
Ah makes sense, I was using a 2-pass shader in URP before and it was doing what you mentioned
but that was also what I wanted it to do so that's fine
I just wanted to make my first pass with SG and not with handwritten code
How about using keywords instead of passes?
Pretty sure you can define keywords in Shader Graph
And branch with them
I'm not sure how that would help in my case
You'd have to add some code to enable some OUTLINE keyword globally using Shader.EnableKeyword before drawing all the renderers again.
That does seem interesting, but where should the keyword enable happen then? Right now my frame debugger is like this
I have an outline prepass right here before opaques
that creates this render texture
which is then used in a post processing effect
Are you using a Render Objects feature to do that pass?
to draw an outline on the original object
uhm no
it's a ScriptableRendererFeature I made myself
like this
Oh okay, then you just enable the keyword before calling DrawRenderers
And disable it again afterwards
That seems like a really good idea ๐
I have no time to add it today, but I added some TODOs in my code, thank you very much!!
Ah but
I am using this
So passes with the tag "LightMode" = "Outline" will write to the render texture
how would that work then? Since I can't set the lightmode tag of a SG shader
My idea would involve rendering all renderers again, just with that keyword enabled.
So it wouldn't need its own LightMode.
Ah but then all objects in the scene will render to the render texture? Just with a different output (based on the keyword)
Yeah. You could reduce the amount of renderers by using a layer mask.
I would recommend using the new renderer layer mask. It's an option in the Renderer component and is separate from the game object layer system.
I've been using that layer option to do custom effects that can be applied to any renderer just by changing that layer. Like for a fresnel highlight effect, I made a transparent additive shader that just adds the fresnel highlight which is then drawn on top of the renderer after opaques. And the nice thing about the renderer layer mask is that you can choose multiple layers for one renderer, so you can easily stack effects.
Okay I'll try to use the new renderer layer mask!