#archived-shaders
1 messages ยท Page 35 of 1
Might also not be able to see it well as there's an Emission colour being applied on top. (Usually with Scene Color that would go into emission instead of Base Color, otherwise it would be shaded)
I tried some unity default meshes just to be sure. Same result. And the strength is 1. Actually it looks like this in the game view
from this "Color" values I would assume it should refract
Okay I see - it is refracting, it's just far to strong and the plane is also partially transparent (0.5 alpha)
At least it is somehow refracting the plane itself, but not the box below, which it should right?
Oh, I got what you mean with "too strong"! Just put it like down to 0.01 and I actually see some refraction going on, thanks for point that out! ๐
Yep sorry if I didn't make that clear
Nah all good, I would not have assumed that I had to go to a n/1000th to get the desired result ๐ wow thank god you pointed and it was easy as that ๐
Yeah it's because 0-1 is the range of the screen position node, that covers the entire screen.
So distorting with a range of 0-1 (or -1,1 in the case of these normals) is like, shifting the entire screen over. If that makes sense.
Ohhh, totally that makes sense. and a lot of things clearer now 
I do not think that the problem is how you decide if its outside the view frustum or not I think the problem is more that you then don't really use this information correctly to then cull you grass
yes I do
I decide if the object is in view or not, if it is render it, if not return and move to the next blade
That is very unspecific and can mean lots and just so you know you are allready in the rendering stage
what?
the only peice of extracted data from the dot product is "is this geometry object going to be in view when rendering or not"
a boolean
Is it possible to take the vertex displacement also as a normal map for the refraction calculation?
Or rather said, I am wondering, why I get this result, just not sure about whats happening under the hood
Refraction is working but also showing the cube as not refracted. Is that because of the transparency?
Yes, you'd want to keep the Alpha at 1 if you don't want to see the non-refracted cube
Oh boy, made so many shaders, but never did refraction, thanks a lot.
Okay, last one is the vertex to normal thing, but I try to figure it out
The Scene Color is like a snapshot of the camera after rendering opaque geometry. When you render your transparent plane, it's like you're projecting that texture onto the plane. If you use any actual transparency you'll end up blending between the camera and the distorted texture.
Thanks for clarification! Great description, understood that ๐
So basically I would have to take the scene color and offset them by the values I get from my vertex position offset basically?
Might be able to use the Normal From Height node on that offset, and distort using that.
Would I just use the Position Node to get it or the result of my calculation before i pass it into the vertex position?
You'd probably want to avoid connecting the vertex and fragment stages together, or you'll end up just doing the calculation twice. Either pass the offset through a Custom Interpolator : https://www.cyanilux.com/tutorials/intro-to-shader-graph/#custom-interpolators
Or since it's a flat plane here, should be able to extract it from the Position node. As when used in the fragment stage that would be the displaced position. In object space, the Y axis (G from Split) should be the offset.
There we go, position y as I was hoping just did the trick ๐ Thanks a lot!
As you are just here, may I ask you about a theory or rather possibility in shadergraph? Right now I have just a circular wave going from a vector3 position. Is there any option to like lerp this effect, so the waves actually will like emit at a position and stay and the new ones emit at the new position. Simple said, as if you drag your finger through water and generate little waves. I am afraid my circular generation is not helping in this case, just wondering if I can only with shadergraph create that effect like using the direcitonal vector and offset it or similar
Or if I have to use a texture that I update on the fly to generate the needed displacement
Not really no. One way to handle that kind of thing is spawning a bunch of circular particles, captured using an orthographic camera to a render texture target. Then pass that texture into shader. For example : https://www.patreon.com/posts/30490169
Hm, so basically I could use the emit on distance to draw particles that are being rendered on an extra layer and use that cameras render texture output to create a heightmap that I can then use to generate the normal map.
Yep
There may be other methods, like using a compute shader to generate that heightmap but I'm less familiar with that
Same. Did you find a solution / recent version of Unity which isn't broken?
Yeah never touched those myself, but thanks for helping with my issues! ๐
you are not listening but fine if you say that you have done everything correctly you could put all of the grass into chunks and call your culling algorithm on that which would help performance, but besides that the way you are doing grass is not great, in fact it is not good at all, I would do some chunking if thats even possible with the way you have it
I'm doing per object culling, and utilizing the chunks for animations so I don't do many control point manipulations
if I do it per chunk, then I'd already have calculated the blades, and just decide not to render it when chunk culling is called
I am going to render and calculate each blade anyway so why don't I skip it using a camera check
yes I know
no you don't
I do, lol, you are creating new geometry so you are allready going through every grass chunking wouldn't help, thats why I said if its even possible to make it work and besides if you really want some good optimal grass I would go and watch that video and forget about geometry shader cause they are shit, I mean lets face it what you are doing is creating grass then throwing it away, creating grass then throwing it away, creating grass then throwing it away, creating grass then throwing it away, creating grass then throwing it away, creating grass then throwing it away, creating grass then throwing it away, creating grass then throwing it away, creating grass then throwing it awayhttps://www.youtube.com/watch?v=Ibe1JBF5i5Y
In this 2021 Advanced Graphics Summit talk, graphics programmer Eric Wohllaib will discuss how they generate acres of grass within reasonable memory and performance limits, techniques for rendering and animating individual blades, and methods for making thousands of individual blades of grass look like a natural field.
Head to GDC Vault (http:/...
you do know that compute shaders can substitute geometry shaders
anyway I need to go, good luck with your grass!
that they're also using a geometry shader
theirs is much better, but the same approach
proving that you still don't know what you're talking about
I do not have time for this and to me you are just proving that you do not know what you are talking about seing that you are failing your grass culling, if you want to say something to me again, do it later I need to go now, anyway, I still wish you good luck with your grass and have a nice day
Thank you! Currently investigating stencils, I think that ought to solve my issue
Any idea if you can write to the stencil buffer from a shader graph shader?
@meager pelican Okay, got it to work! Thanks for the help ๐ The effect is the enemies line of sight
So, as far as stencil go,
- I created a shader that does nothing but assign a stencil value.
- I render my environment a second time and override the material with the stencil material to set the stencil value for all the environment
- I then render my line of sights 2x based on the stencil value (I needed different behaviour(binary) based on the layer)
If anybody more experienced sees anything redundant in how I handle things, please let me know
Hi there,
When you out a position from the Vert function, is that being transferred directly to the GPU, or is that just being sent to the Frag function? How is it being transferred? Would love to understand further. Thank you
Hey so if I have the diffuse gbuffer, the specular gbufffer, and a texture representing the lighting of the screen, how do I combine those correctly?
cuz if I just add the specular gbuffer and the diffuse gbuffer, the specular gbuffer tends to be non zero
resulting in washed out on diffuse surfaces
The diffuse and specular buffers (and the rest of the buffers) are supposed to be inputs into a lighting function that then outputs the final image. They aren't supposed to be combined, like multiplied or added together.
heck ok
cuz I already have the lighting I need to apply, but for my upscaler I rely on the gbuffer for the albedo color so I get full res textures with lower res lighting
is there a way for me to just get the albedo without requiring custom materials applied to objects?
question for a shader, I am rotating + tiling a texture. I wanted the shader to be united across all the sprites with screen position, but I am not sure where I add the screen postion node
this what I have
what I am trying to achieve + the tiling and rotation nodes
I am not sure what I am looking at and I what do you mean exactly with united?
oh woops, my apologies, its 2 sprites a triangle and a square
I was trying to get them to overlay the same texture across despite position or scale of the sprite itself, as if it was seamless
so if you scale the gameObject the sprite tiles and stays the same size?
the texture yes, it works while using a screen position node in the texture uv but I am unsure how to combine it with the rotation + tiling nodes (which scale the texture and rotates it on an angle)
without and with screeen position (
something like this you want?
essentially if I put 3 of the shader it looks like the same texture is scrolling between them
the tiling and offset nodes have a scrolling function attached already, should I multiply that with the screen position and then feed it into tiling?
with this the size of the texture stays the same and you can still tile and offset it
what exactly do you want to make do you want to make the offset change through time?
if so just plug the time node into the offset node
<@&502884371011731486> @trim pagoda
!ban 242264872405041152 bot
Pack#1970 was banned
Does anyone know how to use the new refract node with URP in 2022.2? The documentation doesn't any have useful examples.
Let's say I have a parent gameobject, and a bunch of children gameobjects with different models and materials. I want to alpha clip everything outside of the parent gameobject's bounding volume (sphere or box). How would I make a shader graph that allows me to clip all of the pixels of the children's gameobject renderings that are outside of the bounding volume? Should every child gameobject's renderer need a material/shader with a reference to the parent gameobject's position and bounding volume? Or am I missing something?
Wow, that might suck. Let's see...off the top of my head:
- you could pass in the AABB to the various shaders on the children (maybe a shader global if you just have one, but otherwise it will take unique material instances for each parent). The children could get the worldpos of the fragment, and do an intersection test with the AABB and discard the pixel if outside. Sounds inefficient as hell.
- You could pre-draw the AABB with a stencil-only shader. Do that for every parent. The children shaders would then only be allowed to draw a frag where the stencil intersected the stencil. But the stencil is basically 2D, so you might have to do some kind of depth testing.
The vert(), rasterization, and frag() are all already on the GPU, executing in shader stages.
OK, there's these things call "semantics" that are assigned to the data items in the "v2f" structure passed out of the vertex function to the frag function.
One of the required semantics is SV_POSITION (or POSITION). That value is "flagged" by the shader compiler as the requisite output of the vert...a clip space position for the rasterizer to use to rasterize all this math.
The vertex function and all the inputs and calculations for that are just in "pure math" in that they have no relation to the physical output device, pixels, etc. It's all math-land.
But between the vertex and the fragment stages...magic happens...and it all gets rasterized into the output resolution based on the values you pass out of the vertex function. The various cores are allocated then and assigned to pixels in "waves" of parallel processing, each having its own data from that v2f...interpolated values as applicable.
This is exactly what I was hoping to hear. Thanks for taking the time to answer. I don't have experience with stencil shaders so I will start there
Good. Just remember that stencil operations (for testing, not setting) are basically filters.
So the frag shader will never be called if the stencil test fails for a potential frag.
is there a way to make a shader only get the hue of the light?
im trying to have a shader with only two levels of brightness
(the lit part, and the shadow)
A few extra thoughts after sleeping on this and re-reading your question:
SG doesn't support stencils yet. You'd have to hand-write a shader.
If you can use a sphere as a bounding volume you only need to pass in a float4...xyz are the worldspace center of the sphere, and w could be the radius. Knowing the worldspace location of the fragment and doing a distance calc to the center of the bounding sphere, you can compare the distance to the radius. Might be fastest.
But you'd have to pass that float4 in uniquely for each parent to all children somehow. By having "parent-materials" or something. Maybe a lookup into an array of float4 parents could work too.
There are functions for converting RGB to HSV, and IIRC there's a node for that in Shader Graph. If not, you'll have to do the math (google it or check the docs on Shader graph's node...they might give you the math).
Don't forget about saturation along with hue.
Ok sorry if im not allowed to ask here instead after a while but I need some help porting broken URP shaders to my URP version
Here is one of the errors im getting, they are all pretty similar:
Shader error in 'CTI/URP LOD Bark Array': Did not find shader kernel 'LightweightFragmentMeta' to compile at line 453 (on d3d11)
The package is called Conifers [BOTD]
Id like to know what I should put instead of LightweightFragmentMeta, after searching on the github grep app i found a usage that hinted that I want UniversalFragmentMeta but that brings out more errors than before
BTW if you do import the package for testing make sure you import the included URP package (DONT install the 12.0 version that one TRIPLES my error count)
Im using unity version 2021.3.9f1 and URP version 12.1.7
i freaked around shader for a long time but still can find anyway to change alpha color
and i want emission is on top transparent in shader
how do i do them all?
just tick all of the boxes you need what is the problem
ok i have added the versions to my question if anyone needed them
I'm having an issue with a geometry shader of mine, it works perfectly fine on my home pc , but if i load it up on my laptop it doesn't draw anything at all.
maybe the integrated graphics on my laptop doesnt support geometry shaders (?)
i honestly have no clue
Home pc:
https://streamable.com/a871x3
laptop:
i exported the prefab / materials directly from my home pc so nothing should have changed
that animation looks sick
did you make this?
yeah might be its not supporting but wouldn't really be able to tell, but compute shaders have better compatibility in general and speed, but the problem might be something else dunno
hey so I have this shader code and the effect changes based on the view angle
I would also like to have it change over time
how can I add a time based component to this, i was thinking maybe of an addition (+) to "(viewAngleCustom * 2)" but how exactly?
i would love to use compute shaders but im using a mod to load custom assets into a game, which doesnt support compute shaders
im sure theres a way i could get the same effect without using compute shaders / geometry shaders but im not aware of it
the global shader variable _Time is likely what you want
there is also unity_DeltaTime
this is a float4 variable whos components are t/20, t, t * 2, t*3 respectively
i am less familiar with deltatime
hmm, how would you go about converting it from float4 to float2?
maybe try something like + float2( (_Time.y * _Speed).xx) ?
just do + _Time.xx or time.xy
What is speed?
Same error with that
Just .x or .y works tho
my bad just _Time.x
Gonna test things out see how it comes out
oh it was just a stand in for a variable, you can make it whatever value you want. i just figured you'd want to be able to control the speed of the effect
time is a vector
Thank you!
each component is basically just different speeds
_Time.y is unmodified
x = t/20
y = t
z = t * 2
w = t * 3
Hi I have two lights in my scene, directional light and point light, I am looking to access my point light's position so that I can use it to calculate diffuse lighting. I am wondering how to access the point light in either HLSL, or Shader Lab shortcuts, if anyone has a reference that I can look at would be helpful, thank you
_WorldSpaceLightSpacePos gives you what you need
specifically _WorldSpaceLightSpacePos1
Thank you @lunar valley I am able to access _WorldSpaceLightPos0, but not _WorldSpaceLightPos1, am I importing the wrong package? I am using #include "UnityCG.cginc" right now. Thank you
ok i spent a bit of time here are the errors
CTI/URP LOD BARK (look for 197)
half4 LitPassFragment(CTIVertexOutput IN) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
#if defined(LOD_FADE_CROSSFADE) && !defined(SHADER_API_GLES)
LODDitheringTransition(IN.positionCS.xyz, unity_LODFade.x);
#endif
SurfaceData surfaceData;
// Get the surface description / defined in "Includes/CTI LWRP Inputs.hlsl"
InitializeStandardLitSurfaceData(IN.occlusionVariation.y, IN.uv.xy, surfaceData);
// Add ambient occlusion from vertex input
surfaceData.occlusion *= IN.occlusionVariation.x;
InputData inputData;
InitializeInputData(IN, surfaceData.normalTS, inputData);
// Apply lighting
197 half4 color = LightweightFragmentPBR(inputData, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha); // THIS IS 197 <<<<<<<<<<<<<<
// Add fog
color.rgb = MixFog(color.rgb, inputData.fogCoord);
return color;
}
ENDHLSL
Not sure about Bending.hlsl but it has a function at line 57, and this is where the function is called in the two erroring scripts
Bark
CTIVertexOutput LitPassVertex(CTIVertexInput input)
{
CTIVertexOutput output = (CTIVertexOutput)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
CTI_AnimateVertex(
input,
float4(input.color.rg, input.texcoord1.xy), // animParams,
_BaseWindMultipliers
);
...
ok message is too long but basically there are a lot of errors and im not sure why, hopefully someone here knows how to read shaders and can help with this
btw sorry that i didnt post this all in one message i was busy doing other things at the same time
I tried that but i get an error
half4 colorHue = _LightColor0.RGBToHSV(new _LightColor0(0.9f, 0.7f, 0.1f, 1.0F), out H, out S, out V);
Hi, i want to create a shader which displays fractals(such as the mandelbrot set), while infinitely "zooming" in (scaling the coords) based on the mouse position.
What i'm wondering about is, does interpolation eventually become problematic due to the limitations of floats?
Henlo, Does anyone know how i could get the transform.right of an object as a vector3 in shadergraph like you can in code
you can pass over parameters to shadergraf like vectors floats and so on in a c# script
reference the material and then do material.setfloat, setVector... inside a c# script
hey so im following this basic shader tutorial to get shadows for 2d sprites in 3d, but for some reason the material comes up as pink and the material isnt working properly, the tutorial says its for URP and im using URP sooooo idk the problem
In this brief video tutorial, we'll take a look at how to get 2D sprites to display shadows and receive lighting in 3D similar to the Square Enix game Octopath Traveler.
Unity Default Sprite Shader: https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/Sprites-Diffuse.shader
Complete Shader: https://pastebin....
help is appreciated
whats the best way to get input from a full scene to shade stuff with? im trying to make an image bright and add shading effects to a minimap camera, but I cant figure out how to get input
So far i have tried outputting to a render texture (this step is for regular rendering of the minimap camera), and then using Graphics.Blit to apply a material using my shader to that render texture and throw it into a new render texture. For some reason, my basic unlit shader im using does not want to output correctly to my shaded render texture. If i change the material I am using (so one not using my shader), it works fine.
here is my shadergraph
so you render to a render texture, then you do your post prossesing with graphics.blit which has a different destination rd?
it might be pink because you got an error?
yep
public class MapCamera : MonoBehaviour
{
[SerializeField] private Texture unshaded_minimap;
[SerializeField] private RenderTexture shaded_minimap;
[SerializeField] private Material shader_material;
private void Update()
{
Graphics.Blit(unshaded_minimap, shaded_minimap, shader_material);
}
}
hm, I always use an image effect shader for things like that but tbh. not sure
how do i find that?
im on urp btw
ig that is made somewhat clear by shadergraph
but hdrp has it too
right click shader and select image effect shader if you are curious
is there a good way to get this as a shadergraph?
in URP , I'm using half4 UniversalFragmentPBR(InputData, SurfaceData) to get me the color in the fragment but I'm getting an error in android builds (vulkan targets) preventing me from building.
part of shader below
`
InputData inputData = (InputData)0;
inputData.positionWS = IN.worldPos;
inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal));
inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir);
inputData.shadowCoord = float4(0, 0, 0, 0);
inputData.fogCoord = IN.fogAndVertexLight.x;
inputData.vertexLighting = IN.fogAndVertexLight.yzw;
inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); // that was missing. would it change the way shadows behave in app? TODO check on main.
float3 sh = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS);
inputData.bakedGI = sh;
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos);
inputData.shadowMask = float4(0,0,0,0);
SurfaceData surface = (SurfaceData)0;
surface.albedo = l.Albedo;
surface.metallic = saturate(metallic);
surface.specular = specular;
surface.smoothness = saturate(l.Smoothness),
surface.occlusion = l.Occlusion,
surface.emission = l.Emission,
surface.alpha = saturate(l.Alpha);
surface.clearCoatMask = 0;
surface.clearCoatSmoothness = 1;
half4 color = UniversalFragmentPBR(inputData, surface);
`
Really stumped why the UniversalFragPBR is giving me internal error: argument pulled into unrelated predicate at line 77 (on vulkan)
You likely need to specify pass 0.
Graphics.Blit(unshaded_minimap, shaded_minimap, shader_material, 0);
The default is -1 (all passes). Shader graphs will generate multiple passes for other stuff (e.g. shadows, depthonly, etc), but you don't want to render them all to the screen, only the main forward pass.
To obtain source texture, Graphics.Blit sends it into texture reference _MainTex.
If this is for URP, you may also want to look into using a renderer feature instead.
Hey all, wondering if anyone has figured out a way to avoid a transparent shader with a vertex offset (vertex offset = shift along the surface normal * some_factor) causing a ghosting issue cause of color blending? I've tried manipulating the ndc coordinates to see if I can shift the ghosting effect back to the edge of the object but it only works on some viewing angles?
yeah i tried to do a renderer feature instead
it wasnt working
so what im trying to figure out now is what i did even more wrong
because none of my shaders are working
like for example @regal stag what would you expect this to do?
applied to a cube
just in case im doing it wrong somewhere here
It should look like the cube is invisible, assuming the Opaque Texture is enabled on the URP asset. Otherwise defaults to grey.
thank you
that was it
ok now to see if my renderer feature will work
hm render features still not working
what else have i messed up horribly
my render texture is just showing up like this
thats weird
testing with this shader graph
@regal stag btw are you still here? do you have any idea why my renderer feature wouldnt be working i can send more screenshots of configuration if you need it
and if you arent still here sorry for bothering you
im unfamiliar with common issues with shaders and you had info earlier
so i figured you might know this as well
Is there a way (preferable in shadergraph) to calculate the sharpness of an edge? Basically so that when two tris share an edge the edge gets a value of 0..1 based on the angle 0..180 of the two tris?
it looks like if i zoom out my minimap camera it shows that the pattern is is matching what is shown in the preview
but why are the trees messed up then
hm
oh i figured out what was wrong lol, ok now if anyone knows, how do i just make the scene brighter on the minimap camera, i have shader effects working now
rn minimap looking like this
this is why i was using a light before but i cant get the hacky light toggling method to work on URP and that thing was messy anyways, messed up the lighting on my trees
that's why i moved to shaders
this would be an ideal look for the minimap but i just added a light to get this soooooo
maybe using camera replacement shader, not sure if it'll work in urp though
already doing that
i dont know what effect to do to brighten it
will i end up needing plain shaders or can i use shadergraph?
unlit?
weird.. unlit should make it unaffected by any lighting and give the albedo/color instead...
what color is your fog? it seems unlikely but maybe it's the fog that make it looks darker
i dont have fog afaik
also
the unlit thing might not apply because of how im using camera shaders
basically instead of actually applying an override shader (thats not ACUTALLY a thing in URP afaik) it will take the camera output, then run it through a shader, and set that as the new camera output
i think thats the reason unlit wont work
but
seems like replacementshader is not working on urp.
you might want to check it here
https://forum.unity.com/threads/urp-replacement-shaders.877804/
already did this
like read it
yeah its using render features
hold on lemme fiddle with some stuff brb
ok im back
wait i have an idea
ok my idea worked kinda i just added post-processing
idk ill live with this for now
Btw dont get me wrong if i can find a way to have the minimap cam have perfect lighting and good shadows that would be very nice, as of now Im not even getting shadows on the minimap cam
what do you want some shading or shadows that are being castet
if yoi only want some shading you xan just do the dot product between the normals and light
At what point?
In other words, you're looking at a post-processing effect of the entire scene, already rendered, right? Otherwise you have no guarantee that the neighboring triangle is even drawn yet.
Ooo ok thats a good idea I will try that
But
How do i get the light
Also i learned what a normal is about 19 hours ago so if there is anything important to know about them other than what they are please tell me
Need a little help with some hlsl shaders(not a shader guy myself). Using this toon shader I found(second image is the code), and I want to apply Unity's built in fog over the top of the toon shader as my attempt(first image) does not work and the objects are still visible on top of the fog. Any help would be greatly appreciated!
Rather than a separate pass you'd want to combine them. Add the #pragma multi_compile_fog and place fog macros under the same struct/function in the toon shader. Shouldn't be too difficult as the parameter names look the same - though you may need to use a different number in the UNITY_FOG_COORDS macro if TEXCOORD2 is already being used for something else.
Awesome okay I shall try that, thanks for the quick reply!
It works, thank you!
_WorldSpaceLightPos0 will give you a directional light
How can i export materials from unity to blender?
I made a half dissolved cube and i want to export it
Hmmm how do i access that from a shader graph? Im not used to shader graph and the only thing ive done like that was main tex
Maybe if i create a vector3 input and set the reference to _WorldSpaceLightPos0
I do not think there is a light node or something so you will need to make a custom node, and get your light through there
Its a vector 3 right?
a vector3 works
K i will try that
Hi, dunno if it's a shadder issue or a VR issue but my skybox works fine in scene, but is void in VR
I guess I hadn't really thought about it much, I just had the thought and asked. Would it be possible to post-process something like this on just one mesh? I don't know much about shaders, just enough to do some basic stuff.
in the ForwardBase pass _WorldSpaceLightPos0 will give you a directional light
I dont know what that is, please clarify
im not sure what pipeline they were writing the shader in
but in the built in pipeline
lit shaders typically have two passes indicated by the tags
"LightMode" = "ForwardBase" and "ForwardAdd"
oh well then nevermind them since what I said doesn't apply
Ok so a vector3 with reference set as that will be fine?
If you know shadergraph
Also i saw your post earlier about it maybe being worth to learn builtin shaders first over urp shaders, and im just curious why that is in case i wanna get into writing code based shaders for more complicated effects
But from what i understand shadergraph can do a lot of effects i might need
Like im going to want to have ghostly models in my game and i already have a bit of a demo for that working
custom URP code shaders can be finicky, they aren't as well documented as writing shaders in the built in pipeline. But also you have to include alot of things to make the shader compatible with URP. Versus with the built in pipeline you could just write a shader and it will just work
and for some people this is totally fine. you don't need to learn how to code shaders manually if shadergraph allows you to do all that you want to do.
Could you give an example?
Also this if you know
hmm I suppose I'm wrong, looks like alot has changed
here
Does unity reconstruct the normals from depth at any point in the rendering process and can I access the texture somehow?
Is shader the solution if I wanna make multiple holographic effects for my cards (made of sprites?)
an unlit code example, 1 pass that works for the built in pipeline, 1 pass for URP
visual examples?
Like irl ccgs games
Yummy boilerplate code
Looks relatively simple tho
yeah looks like its simpler now
which is good
I remember it was pretty finicky to get it working
How long since you last looked?
Also are docs good now?
Oh
Yeah that would do it
Isnt that when urp came out or wayy earliee
but looks like im wrong
but the other points I said still apply, for instance if shadergraph works fine for you and you can still do everything you need/want to then no need to switch to code
Ye
just switching to code gives you more flexibility, and responsibility to an extent
as for the vector3 not sure if I follow
Well when you want to input the texture of the object you are shading you use _MainTex right
In shadergraph you make a texture reference
I want to make a scene brighter
But only on one camera and using a shadrr
I can link you to images
Hold on
Here
Someone suggested dot product light by the normal coords
And im not an expert on shading so that sounded reasonable
dot(normal, light) is typically how you do lighting yes
So thats why im after the light pos thing
Actually how do you use the output of the dot product
In this case
I have pixel color in and pixel color out as im assuming most shaders act
And i can throw stuff between there
Magic
Is this achieved with shaders for sprites?
dot(normal, light) returns a float, or a single value. its basically your "brightness" value, and for light you multiply that brightness by the light color which would usually be a float3
Ohhh so it creates a per pixel value yeah
I see
Before i was just trying to multiply the whole frame by a single float
And that wasnt looking too great
Yummy flat image essentially
Btw the light in that IS the light position right?
And how would i adjust the brightness of my lighting?
yes
And its the main directional light in the scene right? Or am i missimg something
Missing*
you just multiply the dot(n, l) by a value to control intensity
Thats what i figured but i wasnt sure because last time i tried to multiply every pixel it looked bad lol
well because you were doing the dot product incorectly
the normal vector is a direction
I wasnt doing any dot product
I just multiplied every pixel by a number
not light position
so for directional lights which are sort of "infinitly large lights" so to speak
the light direction will be constant
not a single number
but i.e. (0, 1, 0)
which is straight up
when it comes to shading point/spot lights its a little different
Yes unless you move them for a day night cycle
well constant in the sense that the light itself doesn't actually "move in space" so to speak
it just changes rotation
its a direction, not a position
my bad, did a piss poor job explaining it now since I forgot its actually light direction not light position
dot(normalDirection, lightDirection)
Is direction != rotation
sort of, yeah
well actually no
is it your rotation sort of
jesus, fumbling hard here lmao
but its alright
direction towards where the light is pointing
Anyone :p
i would say so
@prime shale btw is the ref still the same
yes
Ok
its still a vector3
well no the name would be light direction
if your trying to emulate directional lighting
if your doing point lights then some extra steps are needed to derive the light direction for point/spot lights
but at the end your still getting light direction
think about it also, directional lighting, its in the name itself
it comes from a specified direction
not position
So is it _WorldSpaceLightDir0 ??
Or am i not understanding or its a dofferent shorthand
Different
oh right we are still on _WorldSpaceLightPos, alright give me a second
so for directional lights
wait if this is a custom shader vector3 input why name it _WorldSpaceLightPos0?
_WorldSpaceLightPos0 comes from unity internally to get the light position that unity passes into the shader
you can just name it light direction
if you want to do directional lighting you can just simply have a vector3 named "_LightDirection" which can be used right in the dot product
feel like I lost you @distant dirge
and in your shader you would just set the _LightDirection variable to the transform.forward value of your directional light
||additionally some people would say you need to normalize() it which maps the direction to -1..1 but transform.forward is already normalized so no need to||
Yes
Thats what im looking for
does shadergraph actually provide that value though
_MainTex is an internal thing like i was talking about
Well im assuming how it works is exactly how _MainTex works
You set the input to be referrencing the internal thing you want
And then you can use it
But is that the value i want
Or something else
for getting light yes
for directional lights internally _WorldSpaceLightPos0 is already a direction
for saftey you can normalize them of course
and then plug that in to the dot product equation
Does unity reconstruct the normals from depth at any point in the rendering process and can I access the texture somehow?
for reconstructing normals from depth I don't think so, but at any point in the rendering process for unity yes there is a normals/depth passed always being used. however you can't access that same texture
unless if you enable the depth texture generation
if your on forward rendering mind you
@prime shale Thanks! that's unfortunate
what are possible reasons why shadergraph's preview wont update?
the preview is clearly completely wrong but no change I do to the graph will update the preview
hm changing tab and back fixed it, weird though 
@prime shale if you are still here, do i want a normal vector, normal from texture, or normal from height?
normal vector
you want to shade using the objects normals
the normals from texture/height are usually tangent space
and are meant to modify the object normals
screenshot?
vs if i just add a light
i think its so dark that it looses all the color detail
better comparison if i just brighten it a bit more
im confused on what your trying to make
minimap
this is the minimap with no effects at all, and just the amount of lighting i have atm
this is with effects back on
if there was a good way to i might want to just redraw everything differently but this is why i want alight
because it has color and just looks much nicer
?
right now
i just have a camera place above the player
and i set it to render using my shader
but since the scene is so dark it looses all detail
so its a post effect or is is rendering using a replacement shader?
replacement shaders dont work in urp afaik
so im using a renderer feature
where you create a new urp renderer object
and set some properties for it
and im using a blit where basically it takes the image after a certain rendering step
then applies my shader
then continues
and my shader looks like this rn
i think its technically a post effect tho yeah
I can see from the dot product that the result is completely black
is world space light pos not getting assigned?
i mean that is possible
I would assume so, since it not being assigned would mean that the light direction is (0, 0, 0)
so no light what so ever
lemme test\
yeah
just a sec
no something is working
if i disconnect the node
it just goes black
weirdly tho if i assign manually 0, 1, 0 or 0, -1, 0 it doesnt render anything either but the preview updates
but if i reconnect the worldspacelightpos
it goes back to those ss i sent
clamp the dot product
0..1
figured, but it'll help later on
btw is shaders even a viable way to do this?
for a minimap?
If you only want the current mesh, you can try passing a world-space-normal from vert stage to frag stage (or shader graph will do that for you if you pass one to a ddxy node) and use a ddy/ddx function to detect the changes from the previous pixels.
I suggest you dig into how it works on the net, maybe a youtube vid will explain the ddx and ddy functions, or something. But you'd probably do it all based on surface normals.
are you still here? or are you playing another game so it takes you a while to respond thats why :^)
im at work
alright
still confused exactly what your trying to do
so is this render feature rendering the shader, is it on the entire screen or rendering for every object
yeah then it makes no sense
any alternative solutions?
can't just simply put a multiply node when you sample the minimap texture to brighten it?
if it was an object shader then it'd make sense, but your doing it on the screen pulling the normal vector and trying to shade with lighting which I'm pretty certain is just a quad
if you wanted to actually shade the scene you'd need the scene normal buffer
then you can do some lighting stuff with that
but if you just wanted to brighten the minimap since its dark, why not just simply multiply the image by a brightness factor
if the image is HDR it should be able to do it just fine
i want to look into this maybe? how would i go about this
i already tried it
it looks the same as if i try to use the WorldSpaceLightPos0
because you were shading against the normals of the quad/triangle of the post effect
not the scene normals
as for how to sample the scene normals in URP I actually am not sure
hm
i think it really would be nicer if i could just render a bright directional light on only one camera
but the method i was using for that on builtin doesnt work in URP
and even on builtin it would mess up tree lighting
yeah
i have no clue how to get proper lighting for just the minimap tho
i think a lot of games just end up making a picture for the minimap
but i dont want to do that i think
sounds complicated
this is happening again and this time changing tab isnt uopdating the preview. My preview keeps getting frozen ๐ค
im working on an outline shader which works by adding an extra material with vertices scaled and masking it
i was wondering if there was a way of having it scale evenly?
also for more complex shapes this isnt going to work, so was also wondering if theres a better of effectively moving the vertex "away" effectively and evenly
Where are all my cap vertexes going when I apply a deformation to vertex positions?
when its flat they're all there, but as soon as I apply a deformation, it deletes most of them
and for some reason just makes a huge slope?
is unity helpfully doing something incredibly stupid and useless under the hood, optimizing it or something?
where are those huge planes coming from?
no such plane exists in the source
there were two nearly identical meshes stacked for no good reason ๐ฅ that was the problem
Anyone have a good resource for learning custom render textures from scratch?
I tried to make one last night and it...was not good
anyone else have a good idea for this problem?
seems like you are doing in wrong step
render the objects with the minimap camera using unlit shader as replacement shader, that way your object will be renderer with unlit shader in minimap camera
for "replacement shader" in URP, this could be useful (although quite a long work around, for something worth several lines of code in BiRP)
https://developer.arm.com/documentation/102487/0100/Migrating-custom-shaders-to-the-Universal-Render-Pipeline
i already tried this
the link you sent
it did not work
maybe i just dont understand how to use an unlit shader
should i just create a shadergraph as unlit shader and not change anything?
I think you can just use a material with shadergraph/unlit (or something)
seems like URP's "shader replacement" is not working in shader level, but it replace the material instead, and using layer to determine which material to replace (in BiRP, it conveniently uses shader tag)
Darn it, URP really makes something simple way more convoluted than it supposed to.
Anyone know why this happens to my screen when I move
yeah.......
but URP at the same time is really powerful
so i wanna keep using it
@tacit parcel wait so this is really weird
i put a unlit shader on a material
and set that material to a render objects renderer feature
as described in the link you sent
and i turned off post processing in the minimap camera
and it makes this weird part where the camera just cuts through to the regular camera
thats so weird
what the
i got this after some more fiddling
this is so weird
it would be so much nicer if i could just have a one camera light
did you turn on the depth texture in the urp settings?
are you using a orthographic camera?
transparent render queue?
in the material itself, bottom
change queue control from auto to useroverride
nice !
๐ค is it possible for a shader with multiple pass and a grab pass to be transparent?
My shader pass setup is like this
pass 1 -> render mesh
grabpass -> grab render mesh result to rendertexture
pass2 -> process rendertexture
they are working fine, but I'd like to make the shader/mesh transparent(alpha blended)
seems like it's impossible (at least without using additional grabpass or rendertexture) since my first pass need to be transparent.
But if I make it so, the process in pass 2 would be polluted by anything under the mesh
I like to use graphics.blit for something like that, and with that well, a blur shader
do you know the function graphic.blit? you can basically just apply post prossesing effects with that
well, that function takes in a source and a destination render texture and a material with a shader that does what you want it to do
Look it up, I often do my post prossesing effects with that 
Hi folks, I'm trying to use the Secondary Maps feature in a Material, but the alpha in my png is showing as black. But White color works as alpha. This happens with all textures I tried.
Shader is Standard > Opaque.
Texture imported to Show Alpha.
Render Pipeline > Built In
Any ideas whats going on?
found the answer. Color 128,128,128, is transparent.
Question: when using View Direction node, I'm getting this dark image by default. How can I get this colorful image as is in those Tutorials?
it probably doesn't matter the preview can be wonky sometimes
The preview colours will vary depending on if the project is in Gamma or Linear color space, but it will still work correctly either way.
Though in older versions of URP, the View Direction node was not normalised by default and in newer ones it is. You can use the View Vector node instead to obtain the older functionality.
Uh, you mean the smoothing effect? Did you follow a tutorial for this?
Does anyone know why this happens or how I can finally make my minimap brighter? Im gonna start working on other things today since ive been hyperfocused on minimap for so long but it would be nice to have the minimap working
There is a massive chain of reply messages you can follow upwards but if you need more info and dont wanna follow the chain please ping
Hey guys i imported ne axe with normals and diffuse and AO but i getting some kind of glitch on there how to fix it ?? im using URP ....... for better showing im boost rougness ...... idk whats going on in blender is everything working fine
okay i manage to fix it something was wrong with normal map
View direction is mostly forwards in the preview. If you abs it then it'll be mostly bright blue
They might also have depth * view direction
Is there an overdraw visualizer for Unity where you can see which transparent pixels have heavy overlap with other transparent pixels
hi! I have an issue with some materials in my game.. Whenever my character goes out of the camera's sight, my character's materials get instanced & a transparent material I applied on it becomes fully opaque again... Can instanced material be fully transparent? The alpha channel always go back to 255 when being instanced
team i need some help with my shader, can anyone explain why i cant connect the output of this multiply with the vector 3?
If you can't connect nodes that most commonly seems to be because of trying to use data from the fragment stage with nodes that go to a vertex stage block
oh so whats the vertex stage equivalent of a rectangle?
Rectangle node itself should work fine on both stages. Would help if you showed larger picture where we can see what the whole shader looks like
Rectangle Node
NOTE: This Node can only be used in the Fragment Shader Stage.
Couldn't tell you why tho!
Oh, my bad then
Looking at the generated code, it seems it uses partial dericatives so thats why it wont work for vertex shaders
Doing it like this works
dont think this works for mine because im feeding a gradient noise into the remap
Now they've freakishly amalgamated together
Don't use the gradient as the UV
Just replace the rectangle node with my node setup, but otherwise keep it like you originally had
im confused, what are the inputs to my absolute nodes then?
Just as they are in my setup
but you can see i do that here and i get the wrong output in the steps
These look quite different
I cropped out the noise node but anyway don't use noise as the UV
Unless you specifically want that
yeah i need the noise so that it moves the Y value of the position at the end :/
This is how you were doing it originally
oo it wasnt but it looks like its what i want let me give this a go ๐
perfect thanks so much!
Hi guys. I've been having this problem for hours and I can't figure out the damn way ShaderGraph works. I'm trying to create a mask to an already created blur material, but trying to move things XD and researching the little information on the internet, I came to this: it creates the mask but leaves the material with VERY strong edges and red color???? what's the point?
The hard edge is probably because of alpha clipping
You can disable it here, or change the threshold value
Yesssss, deactivating it seems to solve part of the problem, what happens now is that the mask doesn't work :/
You'll probably want the surface type to be transparent, if it's opaque
Can't spot any cause for the redness
It seems to be in transparent, these are the settings you have
Let's talk here, the hard edge is because your white mask, you should fade to black those edges, but maybe that's not the best way to do it, do you have an example of the effect you need?
I am doing some vertex deformation in shadergraph and I noticed that it interacts funny with SSAO.
Pictured left is deformation without recalculating normals, right is deformation with recalculating normals.
Should the recalculated normal version have the SSAO highlighting the vertexes so clearly?
the SSAO looks a lot better (albeit darker) on the mesh without recalculating the normals, but if I don't recalc the normals then the lighting goes wrong
could I be doing something wrong that is causing the very obvious SSAO faceting?
or is that just how SSAO works?
hm I guess i should import a very wavey mesh for comparison
Ok I think I know the right video, one sec
In this post-processing shader video for Unreal and Unity, I show how to create a filter that blurs the image by taking 7 samples and blending them together. Then I show how to use that same filter to apply sharpening to the final image. Next week, we'll use everything we've learned so far to create an underwater appearance.
Here's last week's...
But also I think you could get this same effect if you add a slider on the smoothness and applying it to the mask you already have
left is modeled, right is in-shader. It looks like SSAO itself is the problem and not the deformation shader?
messing with the values makes it look less terrible, though still somewhat faceted
close enough i guess
What is the name of the node in order to locate it?
I was able to fix the reddish color with the material set to opaque, instead of transparent. Now the only dilemma is the smoothness of those edges ๐ฆ
Im having difficulty deforming vertexes and fixing the normals after deforming them
the above works, but I am struggling to adapt it to meet my use case
my use case - I have a mask because I only want to affect SOME of the verts, not ALL of the verts
and the actual deformation itself is in world space position, not object space position
I cant figure out how to combine those two concepts
when I plug in my alterations, the normals dont get recalculated
the problem has something to do with the world space coordinates
but I cant figure out how to fix that
it has to be in world space
but the other one has to be in object space
I dont understand the problem
my guesses above are wrong
but I dont know what is right or how to fix it
this works
but this does not work
the only difference is the noise I am plugging into it is in world space instead of object space
but I cant have it be in object space
so how do I fix it
the problem appears to be with world space
now im not even sure if it IS actually working in the original
getting frustrated and fed up and my anxiety at failing to achieve this effect is causing me stomach pain
======
TLDR: how do I deform vertexes with a noise map that is based on world space position, but then recalculate the resulting deformed vertexes in object space?
So, I'm trying a simple background shader which simply put an image in the background
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = ComputeScreenPos(o.vertex);
o.uv.xy /= o.uv.w;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv * 8);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}```
But for some reason, the image looks distorted. Any clue on how to remove the distortion?
Forgot to add: the shader/material is assigned as skybox
Meshes drawn in the commandbuffer using drawrenderer are visible, but most of the trails are invisible. Can anyone tell me why it is doing this?
I'm keep creating trails from my footage.
Hey,
Unity says that "Undeclared identifier DepthSobel_float"
although it has been declared in the hlsl file.
What's happened here?
EdgeDetectionOutlinesIncluded.hlsl
#ifdef SOBELOUTLINES_INCLUDED
#define SOBELOUTLINES_INCLUDED
static float2 sobelSamplePoints[9] = {
float2(-1, 1), float2(0, 1), float2(1, 1),
float2(-1, 0), float2(0, 0), float2(1, 0),
float2(-1, -1), float2(0, -1), float2(1, -1)
};
static float sobelXMatrix[9] = {
1, 0, -1,
2, 0, -2,
1, 0, -1
};
static float sobelYMatrix[9] = {
1, 2, 1,
0, 0, 0,
1, -2, -1
};
void DepthSobel_float(float2 UV, float Thickness, out float Out) {
float2 sobel = 0;
[unroll] for (int i = 0; i < 9; i++)
{
float depth = SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV + sobelSamplePoints[i] * Thickness);
sobel += depth * float2(sobelXMatrix[i], sobelYMatrix[i]);
}
Out = length(sobel);
}
#endif
You've defined SOBELOUTLINES_INCLUDED inside of the check to see whether it's defined, it won't be defined at that point
Oh, thanks. That seems to have fixed it!
anyone knows what makes preview blank?
Rarely anything specific
If you can't see anything even when making sure you have all default values and a default preview mesh, then restarting the editor may help
I think every version has had it breaking under some circumstance
alr I'll try restarting first thanks
I tried to create this tornado like effect with shader graph 2d is it possible? if yes what should I put at the UV to recreate the swirl effect?
try the twirl node maybe? https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Twirl-Node.html
Hi!) Can someone explain me why i got red color instead of transparency in sprite with animated material. This problem occurs only if canvas in "screen space - overlay" mode
in shader graph, if I offset a uv channel it seems to offset every other uv channel at the same time
is there a way to offset UV's of only one uv channel at a time?
Hi, I'm trying to understand Custom material inspector but I can't find proper documentation about it, someone have some link to help me ?
I'm trying to make a custom inspector for my material and I need to have the dropdown menu for the basic "Surface Type", "Render Face" and the toggle "Alpha Clipping". Like in the basic Surface Options in the URP Lit.
i have a 2d pixel art texture i have a map for it thats white and black, i want the white part to be effected by a shader of my choice but not the black part, is that possible?
Has anyone tried to take Knife Entertainment's Sci Fi Hologram shader and use it with the URP? I may in the wrong location asking about this but the Sci Fi Hologram shader has custom shaders I want to use with the URP
A shader will always affect a whole mesh per-material
You can mask specific effects by texture using lerp, for example
my setup looks like this, was just wondering if it's possible to move uv's of only one of the maps
Sure, simply only the offset one in where you want it and use the normal one where you dont
It seams like you're already doing that you just havent actually offset it
ye, in the screenshot the offset is set to 0, but lemme show you how it looks when moved
left at offset 0, right on slight offset
what I wanted to do was only offset one UV set, which is set to only work on the planes where the eyes are
I have no idea what your shader does, all I can tell you is what the nodes you showed me do
It seams like you're only offsetting one, I dont know how you're blending it with the rest
the shader is setup like this:
I have 3 uv sets on the head object, 1 uv set on every other part of her
each of them is stacked on top of one another, with the alpha of the layer dictating what is shown
so when nothing is offset, everything seems to be working in order, but for some reason offsetting the 3rd UV set also seems to offset every other one by the same amount
oh wait
I think I see what could be the issue
when imported from Blender, the UV's are in the reverse order was wrong again
No idea if UV sets interact eith each other but you're not overriding anything, what you'd be doing here is sample the texture using a uv value you multiplied and added/subtracted something from
oh, I'm dumb, the actual reason for all that was that when creating extra UV maps on an object, it does a copy of uv's of all the faces, not only the ones selected
so that's why offsetting one looked like offsetting them all
thank you for taking your time to try helping me!
now it all looks a-ok
team how do i slow down the sine time value
coz in sin(x), to reduce the frequency i divide the x value
but ive tried that and got some weird results, dont know how to print values in shader graphs either
nvm it wokred
is it possible to round things inside of shaderlab?
of course, all shader languages support round floor ceil etc
ok cool, it just feels like i was writing it wrong so it wasn't making a difference
which is problematic for me because unity doesn't scream at me when i write an error in shaderlab. it just makes my textures magenta
Hello! I feel like this might be a stupid question, but if I make an Unlit shader graph, and in the color I just plug a float set to 0.5, why is the color of my object (188,188,188) and not (128,128,128), which is ~half of 255?
tldr; has to do with color spaces
gamma/linear
Well thank you very much! I just put a Colospace Conversion Node and got what I wanted!
pls help guys
I followed this tutorial https://www.youtube.com/watch?v=jAOqmx764dA and made a glitter shader. I didn't see any nodes or settings that are related to color, but when I apply the shader to an image, there's a yellow shade. How can I get a glitter shader that I can change color with?
Everyone loves glitter, but it gets everywhere. Luckily, we can just make a glitter shader instead. In this tutorial, learn how to use random noise colors (i.e. GIMP's Hurl filter) to make a glittery effect!
As a bonus, also learn how to flip the effect on its head to make a starry night shader!
โจ Based on a VERY GOOD UE4 tutorial b...
" didn't see any nodes or settings that are related to color"
There's a bunch of stuff related to color in that tutorial...
hello i need help. I'm following a tutorial but when I apply the sahder to my sprite it disappears and I don't know how to fix it.
https://www.youtube.com/watch?v=eD7LmXShYcs&ab_channel=Unity
In this video, we are demonstrating how you can create a stylized water shader in Shader Graph by using a combination of scrolling UV and noise patterns. We are also using 2D lights to make our water respond to the lighting.
๐ข Click here to see the entire 2D Shader Basics Playlist:
https://on.unity.com/36Ln4Nd
๐ด You can download the Assets we...
It looks like you're using the 2D renderer, but your shader graph is not created as a sprite graph
3D shaders won't render with the 2D renderer
ha i understand thank you very much
I redid the shader with the sprite graph but it still doesn't work
Then there's more problems
In your previous image you're adding to vertex world position, but the tutorial uses vertex object position
Make sure you follow it closely
I'm not sure I understand how I can use the vertex object position ?
It's the dropdown in your Position node
ha okay I actually missed it in the tutorial thank you very much for your help and your time
it works now 
Also you don't need to combine the channels of the texture sample 2d, just drag the top most pin into the base color and it works
Hi Every one!
If anyone knows about this question, please reply..... "How To Make Color palette To Change Object Material Color and decals texture at the same time using UI buttons in Unity"?
heya
I have a main texture that encodes X and Y values in R and G channels. What I'm trying to achieve is using these X,Y values from main texture get a pixel from another texture. (I'm not using shader graph, just trying to code it) I can't seem to get the pixel from another texture
I'm absolutely a newbie when it comes to shaders so please bear with me as I try to learn ๐
not entirely sure how to approach getting another texture's pixel colour value using x and y values
if it is even possible
It sounds like you're describing texture sampling by UV coordinates, which is probably the most common thing shaders do
What exactly is the intended effect, what render pipeline are you working in
I'm using URP
so the idea is
I have texture A which again has the coords for texture b
I've seen this video where they used this technique to switch characters clothing
without having to re-draw the character for each animation
its kinda hard to explain
you can swap anything in B and it affects stuff in A
An example might be helpful
Is it 2d or 3d?
Also, why code an URP shader by hand if you're newbie?
I've been told to use URP for shader related stuff. I've used unity bunch of times but shaders always felt like darkmagic
it is 2D
here let me send the images I'm using
You likely want to make sure that texture A is imported with sRGB disabled for this
oh? let me check
ah
URP shaders can be convoluted to code even if you know your way around shaders
It's recommended to use Shader Graph, or first learn the basics of shaders without URP
I see I'll give shader graphs a try after this
is there also a good resource for HLSL, Shader graph and just shader stuff in general
stuff like UV's, texels and stuff is bit confusing for me
I think I got it from here thanks @grizzled bolt and @regal stag for the help :)
update: yep made it work
As you've discovered, and with help from the above, it's possible.
It often isn't recommended, though. It's called a "dependent texture read" and it's a source of potential bottlenecks in shaders. This is because the 2nd texture read is dependent on getting the results of the first texture read in order to get the coordinates. So it has to WAIT quite a bit of time for the first read to finish before it can do the 2nd one. It cannot do them in parallel.
If you've only got a few of these, it might not be too bad, but if you're doing a lot of it you might wish to seek out alternative techniques. Like a flip-book switching of clothes instead.
Hey there, I was wondering if there was a way to change material variables by using code and having those variables only be changed on that one object. The furthest I got was finding something called Hybrid something V2 and using a Material Override Asset, but I can't figure out how to change the values in that asset with code.
you can reference the material and then use SetFloat SetColor SetVector and so on
@sinful canopy
IDK what pipeline you're in, but you can investigate Material Property Blocks.
They work per object
The other way is to duplicate the material to have unique ones per object. That works with SRP batcher.
I'm using the Universal Render Pipeline, and I did find the Material Property Block but I have no clue how it works, and the documentation I found didn't help me out.
Well, with urp you duplicate the mat. Usually.
How many unique instances do you need?
MPBs break SRP batching
A lot...
Is it possible to access per-vertex physics material properties through a shader?
Basically, I have a leaf shader graph the makes the game object's vertices wobble, and there are two variables I want to change. The reason I want to change them is the tree grows over time and while it's in the sapling state the leaves detach from the branches because of the wind strength. So what I want to do is make the float for the wind strength slowly increase as the tree grows. However, when I change the wind strength, all of the trees also change along. Here's an image to show what happens:
You can read gameobject scale and vertex color within shader graph without creating a material instance, pass the relevant data through them
So I can check the game object scale and then multiply that by the wind strength inside the shader graph?
Not multiply but do some kind of calculation.
Yes
Well, that should do it. I can't believe this was such a simple solution, I spent most of the day trying to figure this out. Thanks!
It did work, just had to do a bit of tweaking and add another float for some more control.
If that float is unique per material then I assume you're still using material instances anyway
It is not unique, it simply fixes a problem that arose.
Any of y'all know why does this do this?
whenever I'm close to the wall it sort of dither but I only want it to dither whenever the camera is close to the body
like this:
not an object
any way to fix this?
is this a post prossesing shader?
I can't really tell
I'm new at shaders
maybe this will help
it is HDRP lit
as I believe
multiple question, is the shader applied to the entire screen or does it only sit on a specific object, also what do you mean not an object what is it then?
it is set on the object
like on the body
and what do you mean not an object? whats not an object?
the pictures show the only the body dither
yeah and?
like camera not the object
as you can see in the picture
the black wall on the right
call that an object
it is close to the wall and it causes dither on the body for some reason
like a little one
or is that cause of hdrp stuff
so you only want it to dither when it is close to the capsule?
I want it to only do the dither when the camera is close to the body
the camera
you can theoretically pass over the distance between the capsule and the camera to the shader, through a script
wait how
Keep alpha clip threshold at 0.5
dither will not produce values between 0 and 1 so no point plugging anything into the threshold
You would instead plug your distance gradient to the In of Dither
However, for some reason dithering treats a value of 1 as half-transparent and 2 as fully opaque
.
how would I do that with
this
This is what I have that works
though this one fades anything beyond a world coordinate rather than by distance, you should be able to use it as reference to get the effect working in the first place
kk I'll try it out
what is the fadestart and wallfadeposition
hmm???
what do you have these set on
In my case the position is just 0,0,0 so it happens at world origin in z axis
StartEnd are 0 and 2 so the fade is 2 units wide
plus it still does the thing
vector 2?
which one is startend
yes
the waves are the problem
Looks correct
Before you had the whole mesh an uniform dither, but now there appears to be a gradient which is the goal
the waves appeared before
.
If your game window is zoomed in or out the dither pattern will get messed up visually
still does
I think it's cause of hdrp
gimme a sec I'll check
it's cool the way it works but I don't want it like that so I'll go back
still the issue is there tho
I'll turn off hdrp stuff
As long as you grasp how to utilize the Dither node with values it expects, then adding the kind of distance math you want becomes simple
You can also do the effect with alpha blended transparency first (without alpha clipping) and then convert it to a dithered type, as long as you use the remap as well
yeah it's not hdrp
whatever
I'll deal with it in the future
thanks for the time Spazi :)
you showed me a little some
I have a material created in C# via: var material = new Material(Shader.Find("Universal Render Pipeline/Lit")); . In the documentation, it says this shader has a property called "Alpha Clipping", but I can't figure out how to set that from C#. It seems like I need to call a method like material.SetFloat(prop_name, prop_value), but I don't know how to know what prop_name should be set to. Does anyone know how to find out all the properties a material supports? Or even just the name of this particular property?
Can look at the shader code. https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader
The URP/Lit shader does have an _AlphaClip property, though I imagine it's only for serialisation purposes / displaying toggle in material UI. For actually enabling it at runtime you'd want to use material.EnableKeyword("_ALPHATEST_ON"), as well as edit the _Cutoff property (material.SetFloat)
Though imo it would be better to create a material asset and instantiate that, otherwise the required variant may not be included in the build.
The first part makes sense and helps a lot. Just knowing where the source code for the shader is is very helpful. I don't understand the other part, though. What's a variant?
If you scroll down in the shader you'll see a bunch of #pragma shader_feature / multi_compile lines. They allow compiling the shader into multiple versions/variants with certain features turned on/off. That way if those features aren't needed the shader can perform better.
For multi_compile it's usually safe to toggle at runtime. But with shader_feature, unity will strip unused variants from the build. So toggling those keywords at runtime would cause the magenta error shader if it can't find the required variant.
I see why unity would want to do that, but that's definitely a big, weird foot gun. I guess I can make a base material that I clone off of programatically, but I don't love the idea of having half my material defined in code and half defined using checkboxes in the editor.
None the less, I appreciate the warning, and I think I understand what to do to avoid this problem.
are there any updated tutorials on how to do shader stuff with the node graph because I literally can't find any up to date tutorials ๐ญ
I have a shader that was made in blender that I wish to recreate (since porting is obviously not possible) in unity and I just cannot find any tutorials whatsoever that are up to date
nvm ๐
how do i get my blender shader to work in unity?
how do i get the top to look like the bottom (without the bones ofc)
You'll have to recreate the shader from scratch in unity, you cannot port shaders over from blender to unity IIRC
dang that sucks
ahhh unity's shader graph works nothing like blender's ๐ฅฒ
pain
would texture baking work for transparent materials?
does anyone know how to get this fog shader to work as a height fog shader?
A simple shader that allows you to bend a mesh
Next make it form a paper plane ๐
Can someone please guide me as in how can i make a shader which makes it looks like object has cracks on it .
I want a cube to look damaged when it is hit and number of cracks on it to increase with more hit , till it is eventually destroyed .
thanks ^^
If you want the actual edges of the cube to crack and not just the in-between you may want to actually crack it and modify the mesh on the CPU side. This makes it easier to move chunks of the cube and have them protrude properly with lighting and shadows. There's several ways to do this, research "destructible geometry" and even check the store for add-ons that do it for you, maybe there's even a free one.
If you're after "optical tricks" in a shader to not modify the mesh, but introduce cracks in the view/lighting perspective, you can investigate "Parallax Occlusion Mapping" and somehow generate a cracked texture that you apply and change over time. POM generates "fake geometry" inside of simpler geometry.
https://en.wikipedia.org/wiki/Parallax_occlusion_mapping
https://docs.unity3d.com/Packages/com.unity.shadergraph@12.0/manual/Parallax-Occlusion-Mapping-Node.html
So that's two basic techniques, and as far as generating the cracked-POM-texture, IDK you'll either generate it procedurally on the CPU/C# side or you'll use a few variations of "canned" flip-books that you create in a graphics editor.
Parallax occlusion mapping (POM) is an enhancement of the parallax mapping technique. Parallax occlusion mapping is used to procedurally create 3D definition in textured surfaces, using a displacement map (similar to a topography map) instead of through the generation of new geometry. This allows developers of 3D rendering applications to add ...
Thanks a ton , really appreciated
Another way I've done it is to generate several models of the cube in blender, each more cracked than the last. And I just swap them out at each stage. You could even have an array of them such that you have 5 versions of cracked cubes with each version having say 5 or whatever degrees of cracks. It's a pain to do the modeling, but it's worth the results and you won't get hung up in shaders. Or do it randomly, procedurally, in C#.
okioki
Thankss ^^
There's a lot of different visual styles for a cracking effect most of which use entirely different techniques
Maybe you just need a texture overlay of cracks that can spread
sorry , i dont know about it exactly , can u explain a bit more
The simplest way to do the effect is to overlay a texture with the cracks onto the base texture without the cracks with controlled strength
That's a boolean, not a colour property
uhh soo how can i use my shape and color it? ๐ฅน
Create the colour property again. You chose the wrong type
The multiply should work fine. Though you may want to Saturate before to make sure the values are between 0 and 1.
thank you. big fan of your work btw.
okioki
I would like to get some subsurface scattering going in my water, I am just very unsure how to do that so if anybody can point me in a direction would be great cause all of my try's have not been very successfull
Any ideas why my shader that uses a compute buffer works in the editor but not in a build?
RenderDoc just reports the buffer as not set
I'm setting it on the material, so I'm not sure what's going wrong
_material.SetBuffer(_computeBufferShaderPropertyId, _computeBuffer)
Odd, setting the buffer globally works.
My shaders features using depth break when the objects transform isnt the complete dafualt at thw world center, could the way I'm converting the distance to local space be the problem? ```glsl
float3 rayOrigin = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1));
float3 rayDirection = normalize(i.positionLS - rayOrigin);
//https://www.cyanilux.com/tutorials/depth/
float linearSceneDepth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screenPos)));
float fragmentEyeDepth = -i.positionVS.z;
float3 worldPos = _WorldSpaceCameraPos - ((i.viewDirVector / fragmentEyeDepth) * linearSceneDepth);
float3 localPos = mul(unity_WorldToObject, float4(worldPos, 1));
float actualDistance = distance(rayOrigin, localPos);
It seams logical to me but I'm afraid I've got no idea what I'm doing
Thanks in advance!
Why are you converting it to local space?
What type of depth are you trying to do?
It looks like you should be using all world-space. The camera position is world space to begin with.
I'm converting it so I can compare the results to a box intersection which I had done locally
Wait...
you're using past-tense in that sentence.
So you did the box BEFORE THIS and now you're doing something else.
yes!
Now I want it to be hidden behind other stuff
And I'm culling the front faces which wont allow it to be done by default
Let's say you're using a sphere now, and intersecting with the previous box.
The box's local space is not the sphere's local space.
Local space is object-space.
It's what you have in the model.
So the model has the origin, and all verts are relative to that for that model
right
So you can't do a distance calc between two object's local spaces, it won't mean anything.
Is it an axis aligned bounding box?
I think so
Thats why I thought I'd do it locally so I can just rotate the object (and all the other stuff just moves relative)
Not sure if thats how it works tho
You can project the box from world space locations to the objects local space, I suppose.
But right now I don't see a box, just ray-origin of camera.
Do you want me to share the whole code?
Or the part where I'm doing the box intersection?
That might help
First, what I'm confused by is why you're so insistent on object-space.
I mean, the objects transform contains translation, scale and rotation. Don't you want that all to be able to happen?
Yes
But once that happens, you're basically in world-space.
So do the distance calc in world space and have your math-box be world space.
But the function doesnt take rotation, how'd I do that?
What function?
Basically, once you're in world space it's already rotated.
The objectToWorld matrix does all that.
TRS = Translate, Rotate, Scale.
Is that how intersection functions work?
Intersection functions work on points, or whatever they're designed to work on. So you'd transform the data to the same-space (like a common denominator) and then do the intersection test.
It's easiest to work in world-space, particularly if you want to end up with a world-space distance result.
So I'd rotate, scale, and position it manually? (this is the one I'm using)```glsl
https://iquilezles.org/articles/boxfunctions/
// Calcs intersection and exit distances, and normal at intersection.
// The ray must be in box/object space. If you have multiple boxes all
// aligned to the same axis, you can precompute 1/rd. If you have
// multiple boxes but they are not alligned to each other, use the
// "Generic" box intersector bellow this one.
vec2 boxIntersection( in vec3 ro, in vec3 rd, in vec3 rad, out vec3 oN )
{
vec3 m = 1.0/rd;
vec3 n = m*ro;
vec3 k = abs(m)*rad;
vec3 t1 = -n - k;
vec3 t2 = -n + k;
float tN = max( max( t1.x, t1.y ), t1.z );
float tF = min( min( t2.x, t2.y ), t2.z );
if( tN>tF || tF<0.0) return vec2(-1.0); // no intersection
oN = -sign(rd)*step(t1.yzx,t1.xyz)*step(t1.zxy,t1.xyz);
return vec2( tN, tF );
}
I dont need a worldspace distance result, it just has to be in the same space I'm working with
OK.
I see what you're attempting.
The function expects a local ray and local box
You're taking cameraPos, and a vert/frag's worldPos and projecting them to local space with worldToObject()
Exactly, I should've explained that better
NP.
But remember the box has to be in THIS object's local space. Is it?
Yes
Would it help to have a routine that works in world-space for an AABB?
Maybe just for testing?
Sorry, I dont quite get the question
AABB is axis aligned bounding box.
So you're saying I should try see what happens if I'd have the box in worldspace?
It's easiest, IMO
Sure, I guess I'll try that
That routine would probably work as long as both spaces are the same space.
It can't really tell local space from world space, it's all just 3D numbers. XYZ coordinates.
I think the programmer was trying to say that they have to be same-space to make it work, and that makes sense.
In fact, local space is un-translated, un-rotated, un-scaled world-space. That's why your stuff is working at (0,0,0)
So should I apply rotation, position, and scale myself and take that as solution or make it work in worldspace and then in objectspace?
I'd do everything in worldspace which is what you get AFTER applying translate, rotation, scale to whatever they apply to. Including having your AABB in worldspace.
If you need an intersection test there's a ton on the net, just look for "AABB intersection test" or some such.
I can dig one up if I must, I used it in a ray-tracer.
Oh ok
Thank you!
Is it possible when I have Sprite A and Sprite B, to remove everything from part B from part A?
Google "Stencil buffer" but be aware that you'll have to draw B first even if you don't really draw it on screen and then draw it again later.
A would say to itself (I'll draw orange if I'm not intersecting the stencil from green).
Note that last I knew, shader graph doesn't support stencil operations yet.
ty
I made simple floor material in Blender, my question is how do I export it to unity in PBR Graph since half of the nodes I used in Blender are missing and im also noob :P
You should bake blender shaders to texture maps for everything that doesn't need to be done with shaders
For the rest you'll have to figure out the equivalent functionality
Basically I put Image node in the blender material somewhere, choose diffuse, disable direct and indirect and then bake it?
Pretty much
Is there a curve node in unity? Cant find one and googling isnt giving an answer
wanted to create something like this
there isn't. using these SDF functions https://iquilezles.org/articles/distfunctions2d/, you could do something similiar but even then, depending on the case Id not use shader, procedurally generated 3d meshes are the "default" way of doing curves in unity (line renderer could also be used)
I was going to try to go big by making leaves with a shader but it's seeming way more difficult than anticipated
I don't think curve node would get you far in rendering leaves either. You could use something like this https://www.shadertoy.com/view/MslfWn as a reference point, warning: it's really complicated code, making leaves via shader may not be good idea, not the easiest first shader project atleast
It's not my first shader project but I have only been using Unity for a few weeks
Just a suggestion out of the blue without knowing your full use-case:
Do yourself a favor and try it by making a double-sided quad (two quads, back to back) and map the UV values to a RGBA texture with a leaf on it. The alpha values are for using a simple alpha-cutout (alpha clipping threshold) shader. You can go nuts with leaves and shaders, but often, this is the easiest, IMO. You can implement a simple alpha clipped shader in shader graph, and randomize color variation and move verts in wind and stuff in the shader. Rather than trying to generate geometry in the shader or even procedurally. That's possible too, but often problematic.
Or not, it's up to you of course.
How do I make a shader that just clips out any pixels in the volume of its mesh renderer to the skybox?
What pipeline are you in?
The trick with what you want is that the skybox is drawn AFTER the opaques are drawn. So what you have to do is NOT DRAW where you don't want to, and let the skybox be drawn in the hole. That, or use stacked cameras where the first one is just the skybox. You can then have a background to "grab" later I suppose, but it's better to not draw what you don't want.
So you'd use a stencil. Draw your special mesh using a stencil and no color output (color masked out).
ALL YOUR OTHER SHADERS have to honor that stencil and not draw where you don't want them to.
That's one way.
Well, Iโve found a way. I use the built-in pipeline.
The only limitation is that transparent objects like particle systems wonโt appear
OK
The particle system is intersecting with the stencil, and it won't appear underneath it.
[The white rectangle outside the viewable area is meant to be a fake volumetric effect that should be visible in the cracks]
[Here's how it looks with the stencil and environment disabled]
Trying to make a noise effect go over a fill Image component that is controlled by a slider. Even if the fill image changes width, the noise should maintain aspect ratio. Right now, it's just strobing the whole thing and there's no individual noise pixels.
Sorry, I'm quite new to Unity's shader system, and I'm attempting to use a toon shader (from a tutorial) and apply a rim light effect (from another tutorial), but instead of getting the rim effect, I'm getting the opposite effect lmao.
It's a bit messy, but the top half is the toon shader, while the bottom half is the rim light effect
I do not know what you mean by volume in this context
the character has more vertices
created by the ice
look at his hammer
the shape is different after it is frozen
you can do something like that in a geometry shader
with shader graph?
I do not think so, no. You can do it in hlsl tho
in this gif I've recalculated the normals of the mesh ๐ค Is there a clear cut way I can test if ive done it correctly? Looking at it it looks 'right' but is there some way I can debug to know 100% garuntee its right?
just the R and B channels (without mesh deformation) look approximately correct? But how can I be sure?
Use Gizmos.DrawLine to iterate through the vertex data and draw a line coming from each vertex towards the normal to see it more accurately
Will do, thanks
is this where i can talk about sprite mask
i had this sprite mask but i cant see it when i play
but in the editor i can see it
i think i fixed it
Hey, anyone know the best way to achieve a radial gradient effect on a texture in Shader Graph? As if you were blurring the texture?
I wrote a script that does this but the lines it shows do not reflect the mesh's normals
I am changing the normals in the shader itself
is there some way I can force that change forward or make it realize this?
{
private Mesh mesh;
private Vector3[] normals;
private void Awake()
{
mesh = GetComponent<MeshFilter>().mesh;
normals = mesh.normals;
}
private void OnDrawGizmosSelected()
{
if (mesh == null) return;
Gizmos.color = Color.yellow;
for (int i = 0; i < mesh.vertexCount; i++)
{
Vector3 vertex = transform.TransformPoint(mesh.vertices[i]);
Vector3 normal = transform.TransformDirection(normals[i]);
if (normal == Vector3.zero) continue;
Gizmos.DrawRay(vertex, normal.normalized * 10f);
}
}
private void Update()
{
if (mesh == null) return;
for (int i = 0; i < mesh.vertexCount; i++)
{
Vector3 vertex = transform.TransformPoint(mesh.vertices[i]);
Vector3 normal = transform.TransformDirection(normals[i]);
if (normal == Vector3.zero) continue;
Debug.DrawRay(vertex, normal.normalized * 10f, Color.yellow, 5f);
}
}
}```
this is the script I am using to visualzie the mesh normals
but im getting the mesh normasl and not the material's shader's changes to the mesh normals after they get recalculated
why are there no good shader debugging tools? Trying to interpreter color values visually is so incredibly dumb and frustrating way to go about this
this is doing weird things and I don't know why and I cant find an easy way to diagnose exactly what is going wrong or how to fix it
getting extremely frustrated with it which is only making it harder to debug going into an infinite loop with no escape of failing to debug it and getting more frustrated by failing to debug it causing me to fail to debug it ๐ฅ
